forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep const-ness in generic functions (shader-slang#4028)
* Keep const-ness in generic functions Closes shader-slang#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
- Loading branch information
1 parent
366a947
commit ed06811
Showing
3 changed files
with
59 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<float> outputBuffer; | ||
|
||
#ifdef USE_GENERIC | ||
__generic<T:__BuiltinArithmeticType> | ||
#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<float>(); | ||
#else | ||
vec4 result = MyFunc(); | ||
#endif | ||
|
||
outputBuffer[0] = result[0]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters