diff options
| author | Yong He <yonghe@outlook.com> | 2022-09-05 13:57:06 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-05 13:57:06 -0700 |
| commit | 61ff1ba8459d70cbc887040c530b5ce1a125ec77 (patch) | |
| tree | 6962102d59067920d2fe5aa869c49f065052f038 | |
| parent | c1ee977fb9cd093e58715fe0dea00942d92ef71a (diff) | |
Fix resource inout param specialization. (#2394)
Co-authored-by: Yong He <yhe@nvidia.com>
3 files changed, 41 insertions, 0 deletions
diff --git a/source/slang/slang-ir-specialize-resources.cpp b/source/slang/slang-ir-specialize-resources.cpp index 734315911..31e214e46 100644 --- a/source/slang/slang-ir-specialize-resources.cpp +++ b/source/slang/slang-ir-specialize-resources.cpp @@ -774,6 +774,7 @@ struct ResourceOutputSpecializationPass // `InOut<T>`. // IRInst* newParam = paramsBuilder.createParam(valueType); + newParam->insertBefore(param); param->transferDecorationsTo(newParam); // The start of the function body should assign diff --git a/tests/bugs/mutating/resource-specialization-inout.slang b/tests/bugs/mutating/resource-specialization-inout.slang new file mode 100644 index 000000000..541ecd8ac --- /dev/null +++ b/tests/bugs/mutating/resource-specialization-inout.slang @@ -0,0 +1,36 @@ +// Bug related to resource specialization on unused resource typed fields. + +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj + +//TEST_INPUT: Texture2D(size=4, content = one):name t2D +Texture2D t2D; + +struct MyType +{ + Texture2D tex; + int data; + [mutating] + void f(int val) + { + data += val; + } +} + +int test(int val) +{ + MyType t = {t2D, 0}; + t.f(val); + return t.data; +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer +RWStructuredBuffer<int> gOutputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + int tid = dispatchThreadID.x; + int inputVal = tid; + int outputVal = test(inputVal); + gOutputBuffer[tid] = outputVal; +}
\ No newline at end of file diff --git a/tests/bugs/mutating/resource-specialization-inout.slang.expected.txt b/tests/bugs/mutating/resource-specialization-inout.slang.expected.txt new file mode 100644 index 000000000..bc856dafa --- /dev/null +++ b/tests/bugs/mutating/resource-specialization-inout.slang.expected.txt @@ -0,0 +1,4 @@ +0 +1 +2 +3 |
