diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-07-17 16:38:18 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-17 16:38:18 -0400 |
| commit | 975c5db3f0a71bc93369a321318e7d3b43001ff5 (patch) | |
| tree | 858ff3f6510ffdb178d68f9b417007a4361ef35e | |
| parent | ee755589356f77ef0a01540ba464f9a87d16fce4 (diff) | |
Disable specializing function calls if they have a struct param, that contains an array (#1448)
* This code is disabled, it was part of the optimization `Specialize function calls involving array arguments. (#1389)` on github.
It is disabled here because it causes a problem when a struct is passed to a function that contains a structured buffer *and* an array. It is specialized on the struct type, and so those types become parameters to the function. If the struct contains a structured buffer this is a problem on GLSL/VK based targets because currently structured buffers cannot be function parameters.
The fix for now is to just disable this optimization.
* Fix typo in name of test expected values.
| -rw-r--r-- | source/slang/slang-ir-specialize-resources.cpp | 12 | ||||
| -rw-r--r-- | tests/bugs/specialize-function-array-args.slang | 41 | ||||
| -rw-r--r-- | tests/bugs/specialize-function-array-args.slang.expected.txt | 4 |
3 files changed, 57 insertions, 0 deletions
diff --git a/source/slang/slang-ir-specialize-resources.cpp b/source/slang/slang-ir-specialize-resources.cpp index 60439abeb..2d84cfd8c 100644 --- a/source/slang/slang-ir-specialize-resources.cpp +++ b/source/slang/slang-ir-specialize-resources.cpp @@ -230,8 +230,20 @@ struct ResourceParameterSpecializationContext return true; if(as<IRByteAddressBufferTypeBase>(type)) return true; + +#if 0 + // This code is disabled, and is part of the optimization `Specialize function calls involving array arguments. (#1389)` on github. + // + // It is disabled here because it causes a problem when a struct is passed to a function that contains a structured buffer *and* + // an array. It is specialized on the struct type, and so those types become parameters to the function. + // If the struct contains a structured buffer this is a problem on GLSL/VK based targets because currently + // structured buffers cannot be function parameters. + // + // The fix for now is to just disable this optimization. + if (isStructTypeWithArray(type)) return true; +#endif } // For now, we will not treat any other parameters as diff --git a/tests/bugs/specialize-function-array-args.slang b/tests/bugs/specialize-function-array-args.slang new file mode 100644 index 000000000..6b7ec44b4 --- /dev/null +++ b/tests/bugs/specialize-function-array-args.slang @@ -0,0 +1,41 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST(compute,vulkan):COMPARE_COMPUTE_EX:-vk -slang -compute + +// When a function is passed a parameter that contains an array, it specialized it as a performance +// improvement for VK. If the struct contained a structured buffer, though it meant that the +// function was specialized to have the structured buffer passed as a parameter. For GLSL/VK based +// targets Slang cannot pass StructuredBuffer types and so would subsequently fail in +// GLSLSourceEmitter::emitSimpleTypeImpl when trying to output the StructuredBuffer type as a parameter +// +// This test, checks that when passing a struct with an array and structured buffer +// code functions as expected. + +struct Params +{ + RWStructuredBuffer<int> buffer; + int a[2]; +}; + +//TEST_INPUT:ubuffer(data=[9 9 9 9], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +//TEST_INPUT:ubuffer(data=[1 2 3 4], stride=4):name=anotherBuffer +RWStructuredBuffer<int> anotherBuffer; +// +int doSomething(Params params, int v) +{ + return params.a[v & 1] - v; +} + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + Params params; + params.buffer = anotherBuffer; + params.a[0] = 1; + params.a[1] = 2; + + int tid = int(dispatchThreadID.x); + + outputBuffer[tid] = doSomething(params, tid); +}
\ No newline at end of file diff --git a/tests/bugs/specialize-function-array-args.slang.expected.txt b/tests/bugs/specialize-function-array-args.slang.expected.txt new file mode 100644 index 000000000..93f39a7aa --- /dev/null +++ b/tests/bugs/specialize-function-array-args.slang.expected.txt @@ -0,0 +1,4 @@ +1 +1 +FFFFFFFF +FFFFFFFF |
