From ed0681164d78591148781d08934676bfec63f9da Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Thu, 25 Apr 2024 09:02:13 -0700 Subject: Keep const-ness in generic functions (#4028) * Keep const-ness in generic functions Closes #3834 The issue was that "const" variables inside of generic functions became non-const variables. This issue prevented some of GLSL texture functions from being called inside of generic functions. When `propagateConstExpr()` iterates the global functions, the generic functions had to be handled little differently. This commit allows the iteration to happen for the generic functions. * Adding an explantion of the test as a comment --- tests/bugs/gh-3834.slang | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/bugs/gh-3834.slang (limited to 'tests/bugs') diff --git a/tests/bugs/gh-3834.slang b/tests/bugs/gh-3834.slang new file mode 100644 index 000000000..1f0b2d3ba --- /dev/null +++ b/tests/bugs/gh-3834.slang @@ -0,0 +1,33 @@ +//TEST:SIMPLE(filecheck=CHECK): -stage compute -entry computeMain -target glsl -allow-glsl +//TEST:SIMPLE(filecheck=CHECK): -stage compute -entry computeMain -target glsl -allow-glsl -DUSE_GENERIC + +// This tests an issue that "const" variable was losing the +// const-ness when they are in a generic function + +uniform sampler2D uniform_sampler2D; +RWStructuredBuffer outputBuffer; + +#ifdef USE_GENERIC +__generic +#endif +vec4 MyFunc() +{ + //CHECK: const ivec2 offset0 + //CHECK: const ivec2 offset1 + const ivec2 offset0 = ivec2(0,0); + const ivec2 offset1 = ivec2(1,1); + const ivec2[4] offsets = { offset0, offset0, offset1, offset1 }; + return textureGatherOffsets(uniform_sampler2D, vec2(0), offsets); +} + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ +#ifdef USE_GENERIC + vec4 result = MyFunc(); +#else + vec4 result = MyFunc(); +#endif + + outputBuffer[0] = result[0]; +} -- cgit v1.2.3