From 3d5546600fb4c585b6f6f6dcdb5e122698d1225e Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 5 Mar 2019 14:53:44 -0500 Subject: Hotfix/texture2d gather (#876) * First pass test to see if GatherRed works. * Add support for generating R_Float32 textures. * Set default texture format. * * Alter the texture2d-gather to work with a R_Float32 texture * Add support for scalar Texture2d types with GatherXXX in stdlib * Remove some left over commented out test code from texture2d-gather.hlsl --- source/slang/core.meta.slang | 19 ++++++++++++------- source/slang/core.meta.slang.h | 21 +++++++++++++-------- 2 files changed, 25 insertions(+), 15 deletions(-) (limited to 'source') diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 0c2b70e10..f3e57b90b 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -1001,8 +1001,12 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) static const struct { char const* genericPrefix; char const* elementType; + char const* outputType; } kGatherExtensionCases[] = { - { "__generic", "vector" }, + { "__generic", "vector", "vector" }, + { "", "float", "vector" }, + { "", "int" , "vector"}, + { "", "uint", "vector"}, // TODO: need a case here for scalars `T`, but also // need to ensure that case doesn't accidentally match @@ -1022,7 +1026,6 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) sb << "<" << cc.elementType << " >"; sb << "\n{\n"; - // `Gather` // (tricky because it returns a 4-vector of the element type // of the texture components...) @@ -1046,27 +1049,29 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) auto componentIndex = kk.componentIndex; auto componentName = kk.componentName; + auto outputType = cc.outputType; + EMIT_LINE_DIRECTIVE(); sb << "__target_intrinsic(glsl, \"textureGather($p, $2, " << componentIndex << ")\")\n"; - sb << "vector Gather" << componentName << "(SamplerState s, "; + sb << outputType << " Gather" << componentName << "(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount << " location);\n"; EMIT_LINE_DIRECTIVE(); sb << "__target_intrinsic(glsl, \"textureGatherOffset($p, $2, $3, " << componentIndex << ")\")\n"; - sb << "vector Gather" << componentName << "(SamplerState s, "; + sb << outputType << " Gather" << componentName << "(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount << " location, "; sb << "constexpr int" << kBaseTextureTypes[tt].coordCount << " offset);\n"; EMIT_LINE_DIRECTIVE(); - sb << "vector Gather" << componentName << "(SamplerState s, "; + sb << outputType << " Gather" << componentName << "(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount << " location, "; sb << "constexpr int" << kBaseTextureTypes[tt].coordCount << " offset, "; sb << "out uint status);\n"; EMIT_LINE_DIRECTIVE(); sb << "__target_intrinsic(glsl, \"textureGatherOffsets($p, $2, int" << kBaseTextureTypes[tt].coordCount << "[]($3, $4, $5, $6), " << componentIndex << ")\")\n"; - sb << "vector Gather" << componentName << "(SamplerState s, "; + sb << outputType << " Gather" << componentName << "(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount << " location, "; sb << "int" << kBaseTextureTypes[tt].coordCount << " offset1, "; sb << "int" << kBaseTextureTypes[tt].coordCount << " offset2, "; @@ -1074,7 +1079,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) sb << "int" << kBaseTextureTypes[tt].coordCount << " offset4);\n"; EMIT_LINE_DIRECTIVE(); - sb << "vector Gather" << componentName << "(SamplerState s, "; + sb << outputType << " Gather" << componentName << "(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount << " location, "; sb << "int" << kBaseTextureTypes[tt].coordCount << " offset1, "; sb << "int" << kBaseTextureTypes[tt].coordCount << " offset2, "; diff --git a/source/slang/core.meta.slang.h b/source/slang/core.meta.slang.h index 25feb0005..2ae45a01c 100644 --- a/source/slang/core.meta.slang.h +++ b/source/slang/core.meta.slang.h @@ -1019,8 +1019,12 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) static const struct { char const* genericPrefix; char const* elementType; + char const* outputType; } kGatherExtensionCases[] = { - { "__generic", "vector" }, + { "__generic", "vector", "vector" }, + { "", "float", "vector" }, + { "", "int" , "vector"}, + { "", "uint", "vector"}, // TODO: need a case here for scalars `T`, but also // need to ensure that case doesn't accidentally match @@ -1040,7 +1044,6 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) sb << "<" << cc.elementType << " >"; sb << "\n{\n"; - // `Gather` // (tricky because it returns a 4-vector of the element type // of the texture components...) @@ -1064,27 +1067,29 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) auto componentIndex = kk.componentIndex; auto componentName = kk.componentName; + auto outputType = cc.outputType; + EMIT_LINE_DIRECTIVE(); sb << "__target_intrinsic(glsl, \"textureGather($p, $2, " << componentIndex << ")\")\n"; - sb << "vector Gather" << componentName << "(SamplerState s, "; + sb << outputType << " Gather" << componentName << "(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount << " location);\n"; EMIT_LINE_DIRECTIVE(); sb << "__target_intrinsic(glsl, \"textureGatherOffset($p, $2, $3, " << componentIndex << ")\")\n"; - sb << "vector Gather" << componentName << "(SamplerState s, "; + sb << outputType << " Gather" << componentName << "(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount << " location, "; sb << "constexpr int" << kBaseTextureTypes[tt].coordCount << " offset);\n"; EMIT_LINE_DIRECTIVE(); - sb << "vector Gather" << componentName << "(SamplerState s, "; + sb << outputType << " Gather" << componentName << "(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount << " location, "; sb << "constexpr int" << kBaseTextureTypes[tt].coordCount << " offset, "; sb << "out uint status);\n"; EMIT_LINE_DIRECTIVE(); sb << "__target_intrinsic(glsl, \"textureGatherOffsets($p, $2, int" << kBaseTextureTypes[tt].coordCount << "[]($3, $4, $5, $6), " << componentIndex << ")\")\n"; - sb << "vector Gather" << componentName << "(SamplerState s, "; + sb << outputType << " Gather" << componentName << "(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount << " location, "; sb << "int" << kBaseTextureTypes[tt].coordCount << " offset1, "; sb << "int" << kBaseTextureTypes[tt].coordCount << " offset2, "; @@ -1092,7 +1097,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) sb << "int" << kBaseTextureTypes[tt].coordCount << " offset4);\n"; EMIT_LINE_DIRECTIVE(); - sb << "vector Gather" << componentName << "(SamplerState s, "; + sb << outputType << " Gather" << componentName << "(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount << " location, "; sb << "int" << kBaseTextureTypes[tt].coordCount << " offset1, "; sb << "int" << kBaseTextureTypes[tt].coordCount << " offset2, "; @@ -1197,7 +1202,7 @@ for (auto op : binaryOps) sb << "__intrinsic_op(" << int(op.opCode) << ") matrix<" << resultType << ",N,M> operator" << op.opName << "(" << leftQual << "matrix<" << leftType << ",N,M> left, " << rightType << " right);\n"; } } -SLANG_RAW("#line 1182 \"core.meta.slang\"") +SLANG_RAW("#line 1187 \"core.meta.slang\"") SLANG_RAW("\n") SLANG_RAW("\n") SLANG_RAW("// Operators to apply to `enum` types\n") -- cgit v1.2.3