Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fairywreath committed Jan 23, 2025
1 parent 026ef3d commit 30c782b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 33 deletions.
2 changes: 0 additions & 2 deletions source/slang/slang-ast-support-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ const ImageFormatInfo& getImageFormatInfo(ImageFormat format);
bool findImageFormatByName(const UnownedStringSlice& name, ImageFormat* outFormat);
bool findVkImageFormatByName(const UnownedStringSlice& name, ImageFormat* outFormat);

bool isImageFormatSupportedByGLSLAndSPIRV(ImageFormat format);

char const* getGLSLNameForImageFormat(ImageFormat format);

// TODO(tfoley): We should ditch this enumeration
Expand Down
15 changes: 14 additions & 1 deletion source/slang/slang-emit-glsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,19 @@ void GLSLSourceEmitter::_emitGLSLParameterGroup(
m_writer->emit(";\n");
}

static bool isImageFormatSupportedByGLSL(ImageFormat format)
{
switch (format)
{
case ImageFormat::bgra8:
// These are formats Slang accept, but are not explicitly supported in GLSL.
return false;
default:
return true;
}
};


void GLSLSourceEmitter::_emitGLSLImageFormatModifier(IRInst* var, IRTextureType* resourceType)
{
SLANG_UNUSED(resourceType);
Expand All @@ -619,7 +632,7 @@ void GLSLSourceEmitter::_emitGLSLImageFormatModifier(IRInst* var, IRTextureType*
{
auto format = formatDecoration->getFormat();
const auto formatInfo = getImageFormatInfo(format);
if (!isImageFormatSupportedByGLSLAndSPIRV(format))
if (!isImageFormatSupportedByGLSL(format))
{
getSink()->diagnose(
SourceLoc(),
Expand Down
21 changes: 8 additions & 13 deletions source/slang/slang-emit-spirv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1905,18 +1905,6 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
{
ImageFormat imageFormat =
type->hasFormat() ? (ImageFormat)type->getFormat() : ImageFormat::unknown;
const auto imageFormatInfo = getImageFormatInfo(imageFormat);
if (!isImageFormatSupportedByGLSLAndSPIRV(imageFormat))
{
m_sink->diagnose(
SourceLoc(),
Diagnostics::imageFormatUnsupportedByBackend,
imageFormatInfo.name,
"SPIRV",
"unknown");
imageFormat = ImageFormat::unknown;
}

switch (imageFormat)
{
case ImageFormat::unknown:
Expand Down Expand Up @@ -2004,7 +1992,14 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
case ImageFormat::r64i:
return SpvImageFormatR64i;
default:
SLANG_UNIMPLEMENTED_X("unknown image format for spirv emit");
const auto imageFormatInfo = getImageFormatInfo(imageFormat);
m_sink->diagnose(
SourceLoc(),
Diagnostics::imageFormatUnsupportedByBackend,
imageFormatInfo.name,
"SPIRV",
"unknown");
return SpvImageFormatUnknown;
}
}

Expand Down
10 changes: 8 additions & 2 deletions source/slang/slang-emit-wgsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ void WGSLSourceEmitter::emit(const AddressSpace addressSpace)
}
}

static const char* getWgslImageFormat(IRTextureTypeBase* type)
const char* WGSLSourceEmitter::getWgslImageFormat(IRTextureTypeBase* type)
{
// You can find the supported WGSL texel format from the URL:
// https://www.w3.org/TR/WGSL/#storage-texel-formats
Expand Down Expand Up @@ -411,7 +411,13 @@ static const char* getWgslImageFormat(IRTextureTypeBase* type)
// Unlike SPIR-V, WGSL doesn't have a texel format for "unknown".
return "rgba32float";
default:
// We may need to print a warning for types WGSL doesn't support
const auto imageFormatInfo = getImageFormatInfo(imageFormat);
getSink()->diagnose(
SourceLoc(),
Diagnostics::imageFormatUnsupportedByBackend,
imageFormatInfo.name,
"WGSL",
"rgba32float");
return "rgba32float";
}
}
Expand Down
2 changes: 2 additions & 0 deletions source/slang/slang-emit-wgsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class WGSLSourceEmitter : public CLikeSourceEmitter
const IRIntegerValue& rowCountWGSL,
const IRIntegerValue& colCountWGSL);

const char* getWgslImageFormat(IRTextureTypeBase* type);

bool m_f16ExtensionEnabled = false;
};

Expand Down
12 changes: 0 additions & 12 deletions source/slang/slang-syntax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,18 +1146,6 @@ bool findVkImageFormatByName(const UnownedStringSlice& name, ImageFormat* outFor
return findImageFormatByName(name, outFormat);
}

bool isImageFormatSupportedByGLSLAndSPIRV(ImageFormat format)
{
switch (format)
{
case ImageFormat::bgra8:
// These are formats Slang accept, but are not explicitly supported in GLSL and SPIRV.
return false;
default:
return true;
}
};

char const* getGLSLNameForImageFormat(ImageFormat format)
{
return kImageFormatInfos[Index(format)].name.begin();
Expand Down
12 changes: 9 additions & 3 deletions tests/diagnostics/image-format-unsupported-by-backend.slang
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK_SPIRV): -target spirv
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK_SPIRV): -target glsl
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK_GLSL): -target glsl
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK_WGSL): -target wgsl

// CHECK_SPIRV: warning 31105
// CHECK_GLSL: warning 31105
// CHECK_SPIRV: warning 31105{{.*}}bgra8
// CHECK_GLSL: warning 31105{{.*}}bgra8
[format("bgra8")]
RWTexture2D<float4> outputTexture;

// CHECK_WGSL: warning 31105{{.*}}rg8
[format("rg8")]
RWTexture2D<float4> outputTexture2;

[numthreads(8, 8, 1)]
void main(uint3 threadID : SV_DispatchThreadID)
{
outputTexture[threadID.xy] = float4(1.0, 1.0, 1.0, 1.0);
outputTexture2[threadID.xy] = float4(1.0, 1.0, 1.0, 1.0);
}

0 comments on commit 30c782b

Please sign in to comment.