diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2019-01-25 12:02:50 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-25 12:02:50 -0800 |
| commit | 41fde4b836dbab627f8643a5002b2b6dd0417211 (patch) | |
| tree | 1b1030137fc25403f4b414328dee72e08ea88344 /source | |
| parent | 027e4518ad52b39e4600fa1f94dcae6ce370519f (diff) | |
Fix GLSL translation of several Texture* operations (#800)
A user found that the `Texture2D<float2>.Load(...)` operation was not being compiled to GLSL properly, such that it returned a `vec4` instead of the expected `vec2`.
The GLSL texture-related functions always return (and take) 4-component vectors, and we already have infrastructure in `emit.cpp` for recognizing a `$z` operator in the GLSL intrinsic definition to stand in for an appropriate swizzle based on teh number of components in the texture result type.
This change just adds that `$z` operator to the GLSL code for several more texture operations (including `Load()`) that are defined on a `Texture*<T>` and that return `T`.
This change doesn't try to add additional GLSL translations for texture-related operations (e.g., additional variations like `SampleCmp` that we have defined in the stdlib but not given GLSL translations for). That work still needs to be done.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/core.meta.slang | 30 | ||||
| -rw-r--r-- | source/slang/core.meta.slang.h | 30 |
2 files changed, 26 insertions, 34 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 2ebc3e126..0e8458218 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -703,7 +703,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if (isMultisample) { sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; - sb << "__target_intrinsic(glsl, \"texelFetch($0, $1, $3)\")\n"; + sb << "__target_intrinsic(glsl, \"texelFetch($0, $1, $3)$z\")\n"; } else { @@ -717,7 +717,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) { sb << "$1, 0"; } - sb << ")\")\n"; + sb << ")$z\")\n"; } sb << "T Load("; sb << "int" << loadCoordCount << " location"; @@ -730,7 +730,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if (isMultisample) { sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; - sb << "__target_intrinsic(glsl, \"texelFetchOffset($0, $0, $1, $2)\")\n"; + sb << "__target_intrinsic(glsl, \"texelFetchOffset($0, $0, $1, $2)$z\")\n"; } else { @@ -744,7 +744,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) { sb << "$1, 0"; } - sb << ", $2)\")\n"; + sb << ", $2)$z\")\n"; } sb << "T Load("; sb << "int" << loadCoordCount << " location"; @@ -834,17 +834,13 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) { // `Sample()` - sb << "__target_intrinsic(glsl, \"texture($p, $2)\")\n"; - - // TODO: only enable if IR is being used? -// sb << "__intrinsic_op(sample)\n"; - + sb << "__target_intrinsic(glsl, \"texture($p, $2)$z\")\n"; sb << "T Sample(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location);\n"; if( baseShape != TextureFlavor::Shape::ShapeCube ) { - sb << "__target_intrinsic(glsl, \"textureOffset($p, $2, $3)\")\n"; + sb << "__target_intrinsic(glsl, \"textureOffset($p, $2, $3)$z\")\n"; sb << "T Sample(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; sb << "constexpr int" << kBaseTextureTypes[tt].coordCount << " offset);\n"; @@ -868,13 +864,13 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) // `SampleBias()` - sb << "__target_intrinsic(glsl, \"texture($p, $2, $3)\")\n"; + sb << "__target_intrinsic(glsl, \"texture($p, $2, $3)$z\")\n"; sb << "T SampleBias(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, float bias);\n"; if( baseShape != TextureFlavor::Shape::ShapeCube ) { - sb << "__target_intrinsic(glsl, \"textureOffset($p, $2, $3, $4)\")\n"; + sb << "__target_intrinsic(glsl, \"textureOffset($p, $2, $3, $4)$z\")\n"; sb << "T SampleBias(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, float bias, "; sb << "constexpr int" << kBaseTextureTypes[tt].coordCount << " offset);\n"; @@ -904,7 +900,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) } sb << "$3)"; - sb << ", 0.0)\")\n"; + sb << ", 0.0)$z\")\n"; } else if(arrCoordCount <= 3) { @@ -925,7 +921,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) // Construct gradients sb << ", vec" << baseCoordCount << "(0.0)"; sb << ", vec" << baseCoordCount << "(0.0)"; - sb << ")\")\n"; + sb << ")$z\")\n"; } sb << "float SampleCmpLevelZero(SamplerComparisonState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; @@ -953,7 +949,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) } - sb << "__target_intrinsic(glsl, \"textureGrad($p, $2, $3, $4)\")\n"; + sb << "__target_intrinsic(glsl, \"textureGrad($p, $2, $3, $4)$z\")\n"; // sb << "__intrinsic_op(sampleGrad)\n"; sb << "T SampleGrad(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; @@ -963,7 +959,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if( baseShape != TextureFlavor::Shape::ShapeCube ) { - sb << "__target_intrinsic(glsl, \"textureGradOffset($p, $2, $3, $4, $5)\")\n"; + sb << "__target_intrinsic(glsl, \"textureGradOffset($p, $2, $3, $4, $5)$z\")\n"; // sb << "__intrinsic_op(sampleGrad)\n"; sb << "T SampleGrad(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; @@ -981,7 +977,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if( baseShape != TextureFlavor::Shape::ShapeCube ) { - sb << "__target_intrinsic(glsl, \"textureLodOffset($p, $2, $3, $4)\")\n"; + sb << "__target_intrinsic(glsl, \"textureLodOffset($p, $2, $3, $4)$z\")\n"; sb << "T SampleLevel(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; sb << "float level, "; diff --git a/source/slang/core.meta.slang.h b/source/slang/core.meta.slang.h index b32d9454c..2cb0402f8 100644 --- a/source/slang/core.meta.slang.h +++ b/source/slang/core.meta.slang.h @@ -718,7 +718,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if (isMultisample) { sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; - sb << "__target_intrinsic(glsl, \"texelFetch($0, $1, $3)\")\n"; + sb << "__target_intrinsic(glsl, \"texelFetch($0, $1, $3)$z\")\n"; } else { @@ -732,7 +732,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) { sb << "$1, 0"; } - sb << ")\")\n"; + sb << ")$z\")\n"; } sb << "T Load("; sb << "int" << loadCoordCount << " location"; @@ -745,7 +745,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if (isMultisample) { sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)"; - sb << "__target_intrinsic(glsl, \"texelFetchOffset($0, $0, $1, $2)\")\n"; + sb << "__target_intrinsic(glsl, \"texelFetchOffset($0, $0, $1, $2)$z\")\n"; } else { @@ -759,7 +759,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) { sb << "$1, 0"; } - sb << ", $2)\")\n"; + sb << ", $2)$z\")\n"; } sb << "T Load("; sb << "int" << loadCoordCount << " location"; @@ -849,17 +849,13 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) { // `Sample()` - sb << "__target_intrinsic(glsl, \"texture($p, $2)\")\n"; - - // TODO: only enable if IR is being used? -// sb << "__intrinsic_op(sample)\n"; - + sb << "__target_intrinsic(glsl, \"texture($p, $2)$z\")\n"; sb << "T Sample(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location);\n"; if( baseShape != TextureFlavor::Shape::ShapeCube ) { - sb << "__target_intrinsic(glsl, \"textureOffset($p, $2, $3)\")\n"; + sb << "__target_intrinsic(glsl, \"textureOffset($p, $2, $3)$z\")\n"; sb << "T Sample(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; sb << "constexpr int" << kBaseTextureTypes[tt].coordCount << " offset);\n"; @@ -883,13 +879,13 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) // `SampleBias()` - sb << "__target_intrinsic(glsl, \"texture($p, $2, $3)\")\n"; + sb << "__target_intrinsic(glsl, \"texture($p, $2, $3)$z\")\n"; sb << "T SampleBias(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, float bias);\n"; if( baseShape != TextureFlavor::Shape::ShapeCube ) { - sb << "__target_intrinsic(glsl, \"textureOffset($p, $2, $3, $4)\")\n"; + sb << "__target_intrinsic(glsl, \"textureOffset($p, $2, $3, $4)$z\")\n"; sb << "T SampleBias(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, float bias, "; sb << "constexpr int" << kBaseTextureTypes[tt].coordCount << " offset);\n"; @@ -919,7 +915,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) } sb << "$3)"; - sb << ", 0.0)\")\n"; + sb << ", 0.0)$z\")\n"; } else if(arrCoordCount <= 3) { @@ -940,7 +936,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) // Construct gradients sb << ", vec" << baseCoordCount << "(0.0)"; sb << ", vec" << baseCoordCount << "(0.0)"; - sb << ")\")\n"; + sb << ")$z\")\n"; } sb << "float SampleCmpLevelZero(SamplerComparisonState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; @@ -968,7 +964,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) } - sb << "__target_intrinsic(glsl, \"textureGrad($p, $2, $3, $4)\")\n"; + sb << "__target_intrinsic(glsl, \"textureGrad($p, $2, $3, $4)$z\")\n"; // sb << "__intrinsic_op(sampleGrad)\n"; sb << "T SampleGrad(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; @@ -978,7 +974,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if( baseShape != TextureFlavor::Shape::ShapeCube ) { - sb << "__target_intrinsic(glsl, \"textureGradOffset($p, $2, $3, $4, $5)\")\n"; + sb << "__target_intrinsic(glsl, \"textureGradOffset($p, $2, $3, $4, $5)$z\")\n"; // sb << "__intrinsic_op(sampleGrad)\n"; sb << "T SampleGrad(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; @@ -996,7 +992,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if( baseShape != TextureFlavor::Shape::ShapeCube ) { - sb << "__target_intrinsic(glsl, \"textureLodOffset($p, $2, $3, $4)\")\n"; + sb << "__target_intrinsic(glsl, \"textureLodOffset($p, $2, $3, $4)$z\")\n"; sb << "T SampleLevel(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; sb << "float level, "; |
