diff --git a/source/slang/slang-ast-support-types.h b/source/slang/slang-ast-support-types.h index a7bbef7af3..1d3de9c546 100644 --- a/source/slang/slang-ast-support-types.h +++ b/source/slang/slang-ast-support-types.h @@ -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 diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp index f6e3212b68..61457d98e5 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -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); @@ -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(), diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index c78efe8dcf..7c2e80846d 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -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: @@ -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; } } diff --git a/source/slang/slang-emit-wgsl.cpp b/source/slang/slang-emit-wgsl.cpp index 1eb7aabf55..ce60cc2a0e 100644 --- a/source/slang/slang-emit-wgsl.cpp +++ b/source/slang/slang-emit-wgsl.cpp @@ -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 @@ -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"; } } diff --git a/source/slang/slang-emit-wgsl.h b/source/slang/slang-emit-wgsl.h index 4e0c18821d..714a722d7d 100644 --- a/source/slang/slang-emit-wgsl.h +++ b/source/slang/slang-emit-wgsl.h @@ -71,6 +71,8 @@ class WGSLSourceEmitter : public CLikeSourceEmitter const IRIntegerValue& rowCountWGSL, const IRIntegerValue& colCountWGSL); + const char* getWgslImageFormat(IRTextureTypeBase* type); + bool m_f16ExtensionEnabled = false; }; diff --git a/source/slang/slang-syntax.cpp b/source/slang/slang-syntax.cpp index 9170d30ab6..6fdd5088a6 100644 --- a/source/slang/slang-syntax.cpp +++ b/source/slang/slang-syntax.cpp @@ -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(); diff --git a/tests/diagnostics/image-format-unsupported-by-backend.slang b/tests/diagnostics/image-format-unsupported-by-backend.slang index a9455e76e9..270c2b63e2 100644 --- a/tests/diagnostics/image-format-unsupported-by-backend.slang +++ b/tests/diagnostics/image-format-unsupported-by-backend.slang @@ -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 outputTexture; +// CHECK_WGSL: warning 31105{{.*}}rg8 +[format("rg8")] +RWTexture2D 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); }