Skip to content

Commit

Permalink
Require GL_EXT_samplerless_texture_functions only if needed
Browse files Browse the repository at this point in the history
This extension is only necessary when using texture functions
on non-combined texture/samplers.

Fixes shader-slang#5518
  • Loading branch information
cheneym2 committed Nov 8, 2024
1 parent 64c6cb1 commit 7ec5661
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/slang/slang-core-module-textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ void TextureTypeInfo::writeGetDimensionFunctions()
glsl << ", ($" << aa++ << " = textureQueryLevels($0))";
}
};
glsl << "if (isCombined != 0) { __requireGLSLExtension(\"GL_EXT_samplerless_texture_functions\"); }\n";
glsl << "if (access == " << kCoreModule_ResourceAccessReadOnly
<< ") __intrinsic_asm \"";
emitIntrinsic(toSlice("textureSize"), !isMultisample);
Expand Down Expand Up @@ -491,7 +492,6 @@ void TextureTypeInfo::writeGetDimensionFunctions()
}

sb << " __glsl_version(450)\n";
sb << " __glsl_extension(GL_EXT_samplerless_texture_functions)\n";

sb << " [require(cpp";
if (glsl.getLength())
Expand Down
18 changes: 18 additions & 0 deletions tests/bugs/gh-5518.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//TEST:SIMPLE(filecheck=GLSL): -profile spirv_1_5+fragment -entry fragmentMain -target glsl

// Ensure that the use of combined samplers does not needlessly require
// GL_EXT_samplerless_texture_functions

// GLSL-NOT: #extension GL_EXT_samplerless_texture_functions : require

layout(binding=1) Sampler3D sampler;

[shader("fragment")]
float4 fragmentMain() : SV_Target
{
int sizeX;
int sizeY;
int sizeZ;
sampler.GetDimensions(sizeX, sizeY, sizeZ);
return float4(sizeX, sizeY, sizeZ, 1.0);
}

0 comments on commit 7ec5661

Please sign in to comment.