diff options
3 files changed, 51 insertions, 0 deletions
diff --git a/source/slang/slang-ir-explicit-global-context.cpp b/source/slang/slang-ir-explicit-global-context.cpp index 68f23461b..8f11bce2c 100644 --- a/source/slang/slang-ir-explicit-global-context.cpp +++ b/source/slang/slang-ir-explicit-global-context.cpp @@ -270,6 +270,15 @@ struct IntroduceExplicitGlobalContextPass // globalUniformsParam->insertBefore(firstOrdinary); } + else + { + // The nature of our current ABI for entry points on CPU/CUDA + // means that we need an explicit parameter to be *declared* + // for the global uniforms, even if it is never used. + // + auto placeholderParam = builder.createParam(builder.getRawPointerType()); + placeholderParam->insertBefore(firstOrdinary); + } // The `KernelContext` to use inside the entry point // will be a local variable declared in the first block. diff --git a/tests/language-feature/shader-params/entry-point-uniform-params.slang b/tests/language-feature/shader-params/entry-point-uniform-params.slang new file mode 100644 index 000000000..b94fc4556 --- /dev/null +++ b/tests/language-feature/shader-params/entry-point-uniform-params.slang @@ -0,0 +1,38 @@ +// entry-point-uniform-params.slang + +//TEST(compute):COMPARE_COMPUTE: +//TEST(compute):COMPARE_COMPUTE:-cuda +//TEST(compute):COMPARE_COMPUTE:-cpu + +// Test that a shader can be written that +// only uses entry point `uniform` parameters, +// without any global parameters. + +struct Data +{ + int a; + int b; +} + +int test(int val, int a, int b) +{ + return a*(val+1) + b*(val+2); +} + +[numthreads(4, 1, 1)] +[shader("compute")] +void computeMain( + +//TEST_INPUT:cbuffer(data=[256 1]):name=d + uniform Data d, + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer + uniform RWStructuredBuffer<int> outputBuffer, + + uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + int inVal = tid; + int outVal = test(inVal, d.a, d.b); + outputBuffer[tid] = outVal; +} diff --git a/tests/language-feature/shader-params/entry-point-uniform-params.slang.expected.txt b/tests/language-feature/shader-params/entry-point-uniform-params.slang.expected.txt new file mode 100644 index 000000000..4cf6581b3 --- /dev/null +++ b/tests/language-feature/shader-params/entry-point-uniform-params.slang.expected.txt @@ -0,0 +1,4 @@ +102 +203 +304 +405 |
