summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorDarren Wihandi <65404740+fairywreath@users.noreply.github.com>2025-01-24 16:13:16 -0500
committerGitHub <noreply@github.com>2025-01-24 13:13:16 -0800
commit0dd9076db2154d787f6e06b713721e877b746b83 (patch)
tree24f75b2c612fc0ee5a3ba8157c4d0dde7ff9a3a0 /source
parent92c9fffb95c92b0bc07eb1c656375928b5cd5c33 (diff)
Add bgra8 format (#6163)
* add brga8 format * add tests * minor fixes * cleanup * maybe fix broken quad control test * add missing xslang flag on test --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-diagnostic-defs.h7
-rw-r--r--source/slang/slang-emit-glsl.cpp26
-rw-r--r--source/slang/slang-emit-spirv.cpp11
-rw-r--r--source/slang/slang-emit-wgsl.cpp12
-rw-r--r--source/slang/slang-emit-wgsl.h2
5 files changed, 53 insertions, 5 deletions
diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h
index 37dfc8114..cf338edfa 100644
--- a/source/slang/slang-diagnostic-defs.h
+++ b/source/slang/slang-diagnostic-defs.h
@@ -1059,6 +1059,13 @@ DIAGNOSTIC(
explicitUniformLocation,
"Explicit binding of uniform locations is discouraged. Prefer 'ConstantBuffer<$0>' over "
"'uniform $0'")
+DIAGNOSTIC(
+ 31105,
+ Warning,
+ imageFormatUnsupportedByBackend,
+ "Image format '$0' is not explicitly supported by the $1 backend, using supported format '$2' "
+ "instead.")
+
DIAGNOSTIC(31120, Error, invalidAttributeTarget, "invalid syntax target for user defined attribute")
diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp
index b94f44690..61457d98e 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);
@@ -618,6 +631,18 @@ void GLSLSourceEmitter::_emitGLSLImageFormatModifier(IRInst* var, IRTextureType*
if (auto formatDecoration = var->findDecoration<IRFormatDecoration>())
{
auto format = formatDecoration->getFormat();
+ const auto formatInfo = getImageFormatInfo(format);
+ if (!isImageFormatSupportedByGLSL(format))
+ {
+ getSink()->diagnose(
+ SourceLoc(),
+ Diagnostics::imageFormatUnsupportedByBackend,
+ formatInfo.name,
+ "GLSL",
+ "unknown");
+ format = ImageFormat::unknown;
+ }
+
if (format == ImageFormat::unknown)
{
// If the user explicitly opts out of having a format, then
@@ -636,7 +661,6 @@ void GLSLSourceEmitter::_emitGLSLImageFormatModifier(IRInst* var, IRTextureType*
}
else
{
- auto formatInfo = getImageFormatInfo(format);
if (formatInfo.scalarType == SLANG_SCALAR_TYPE_UINT64 ||
formatInfo.scalarType == SLANG_SCALAR_TYPE_INT64)
{
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 951507ab9..7c2e80846 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -1901,7 +1901,7 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
}
}
- static SpvImageFormat getSpvImageFormat(IRTextureTypeBase* type)
+ SpvImageFormat getSpvImageFormat(IRTextureTypeBase* type)
{
ImageFormat imageFormat =
type->hasFormat() ? (ImageFormat)type->getFormat() : ImageFormat::unknown;
@@ -1992,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 30a7af938..ce60cc2a0 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
@@ -405,11 +405,19 @@ static const char* getWgslImageFormat(IRTextureTypeBase* type)
return "rgba32sint";
case ImageFormat::rgba32f:
return "rgba32float";
+ case ImageFormat::bgra8:
+ return "bgra8unorm";
case ImageFormat::unknown:
// 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 4e0c18821..714a722d7 100644
--- a/source/slang/slang-emit-wgsl.h
+++ b/source/slang/slang-emit-wgsl.h
@@ -71,6 +71,8 @@ private:
const IRIntegerValue& rowCountWGSL,
const IRIntegerValue& colCountWGSL);
+ const char* getWgslImageFormat(IRTextureTypeBase* type);
+
bool m_f16ExtensionEnabled = false;
};