summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2023-07-26 16:33:48 +0000
committerGitHub <noreply@github.com>2023-07-26 09:33:48 -0700
commitc61775e634a6a52772de60e68ba6d50751d8b790 (patch)
tree17e645be935f26f15f4ddc114fbe025f958fbfb0 /source
parentd47d54928f46f1c869c8cca5cf67b310fd18cb1d (diff)
Add GatherCmp* for texture objects (#3024)
The translation to GLSL is incomplete as intrinsics only exist for some combination of comparison and channel (just channel 0) Closes https://github.com/shader-slang/slang/issues/3021
Diffstat (limited to 'source')
-rw-r--r--source/slang/core.meta.slang56
1 files changed, 45 insertions, 11 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang
index afb14dc4a..ddb81fd87 100644
--- a/source/slang/core.meta.slang
+++ b/source/slang/core.meta.slang
@@ -2176,50 +2176,83 @@ struct TextureTypeInfo
{ 2, "Blue" },
{ 3, "Alpha" },
};
+ enum Cmp
+ { NotCmp,
+ Cmp
+ };
+ for(auto cmp : {NotCmp, Cmp})
for(auto kk : kGatherComponets)
{
+ auto samplerOrComparisonSampler = cmp == Cmp ? "SamplerComparisonState s, " : samplerStateParam;
+
auto componentIndex = kk.componentIndex;
auto componentName = kk.componentName;
auto outputType = cc.outputType;
+ const auto cmpName = cmp == Cmp ? "Cmp" : "";
+ const auto cmpValueParam = cmp == Cmp ? "float compareValue, " : "";
+ const auto cmpValueParamEnd = cmp == Cmp ? ", float compareValue" : "";
+ const auto supportsGLSL = componentIndex == 0 || cmp == NotCmp;
+
EMIT_LINE_DIRECTIVE();
- sb << "__target_intrinsic(glsl, \"textureGather($p, $2, " << componentIndex << ")\")\n";
- if (base.coordCount == 2)
+ if(supportsGLSL)
+ {
+ if(cmp == Cmp)
+ sb << "__target_intrinsic(glsl, \"textureGather($p, $2, $3)\")\n";
+ else
+ sb << "__target_intrinsic(glsl, \"textureGather($p, $2, " << componentIndex << ")\")\n";
+ }
+ if (base.coordCount == 2 && cmp == NotCmp)
{
- // Gather only works on 2D in CUDA
+ // Gather only works on 2D in CUDA without comparison
// "It is based on the base type of DataType except when readMode is equal to cudaReadModeNormalizedFloat (see Texture Reference API), in which case it is always float4."
sb << "__target_intrinsic(cuda, \"tex2Dgather<$T0>($0, ($2).x, ($2).y, " << componentIndex << ")\")\n";
}
if (isReadOnly)
sb << "[__readNone]\n";
- sb << outputType << " Gather" << componentName << "(" << samplerStateParam;
- sb << "float" << base.coordCount + isArray << " location);\n";
+ sb << outputType << " Gather" << cmpName << componentName << "(" << samplerOrComparisonSampler;
+ sb << "float" << base.coordCount + isArray << " location" << cmpValueParamEnd << ");\n";
if (isReadOnly)
sb << "[__readNone]\n";
EMIT_LINE_DIRECTIVE();
- sb << "__target_intrinsic(glsl, \"textureGatherOffset($p, $2, $3, " << componentIndex << ")\")\n";
- sb << outputType << " Gather" << componentName << "(" << samplerStateParam;
+ if(supportsGLSL)
+ {
+ if(cmp == Cmp)
+ sb << "__target_intrinsic(glsl, \"textureGatherOffset($p, $2, $3, $4)\")\n";
+ else
+ sb << "__target_intrinsic(glsl, \"textureGatherOffset($p, $2, $3, " << componentIndex << ")\")\n";
+ }
+ sb << outputType << " Gather" << cmpName << componentName << "(" << samplerOrComparisonSampler;
sb << "float" << base.coordCount + isArray << " location, ";
+ sb << cmpValueParam;
sb << "constexpr int" << base.coordCount << " offset);\n";
if (isReadOnly)
sb << "[__readNone]\n";
EMIT_LINE_DIRECTIVE();
- sb << outputType << " Gather" << componentName << "(" << samplerStateParam;
+ sb << outputType << " Gather" << cmpName << componentName << "(" << samplerOrComparisonSampler;
sb << "float" << base.coordCount + isArray << " location, ";
+ sb << cmpValueParam;
sb << "constexpr int" << base.coordCount << " offset, ";
sb << "out uint status);\n";
if (isReadOnly)
sb << "[__readNone]\n";
EMIT_LINE_DIRECTIVE();
- sb << "__target_intrinsic(glsl, \"textureGatherOffsets($p, $2, int" << base.coordCount << "[]($3, $4, $5, $6), " << componentIndex << ")\")\n";
- sb << outputType << " Gather" << componentName << "(" << samplerStateParam;
+ if(supportsGLSL)
+ {
+ if(cmp == Cmp)
+ sb << "__target_intrinsic(glsl, \"textureGatherOffsets($p, $2, $3, ivec" << base.coordCount << "[]($4, $5, $6, $7))\")\n";
+ else
+ sb << "__target_intrinsic(glsl, \"textureGatherOffsets($p, $2, ivec" << base.coordCount << "[]($3, $4, $5, $6), " << componentIndex << ")\")\n";
+ }
+ sb << outputType << " Gather" << cmpName << componentName << "(" << samplerOrComparisonSampler;
sb << "float" << base.coordCount + isArray << " location, ";
+ sb << cmpValueParam;
sb << "int" << base.coordCount << " offset1, ";
sb << "int" << base.coordCount << " offset2, ";
sb << "int" << base.coordCount << " offset3, ";
@@ -2228,8 +2261,9 @@ struct TextureTypeInfo
if (isReadOnly)
sb << "[__readNone]\n";
EMIT_LINE_DIRECTIVE();
- sb << outputType << " Gather" << componentName << "(" << samplerStateParam;
+ sb << outputType << " Gather" << cmpName << componentName << "(" << samplerOrComparisonSampler;
sb << "float" << base.coordCount + isArray << " location, ";
+ sb << cmpValueParam;
sb << "int" << base.coordCount << " offset1, ";
sb << "int" << base.coordCount << " offset2, ";
sb << "int" << base.coordCount << " offset3, ";