forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal-type-param2.slang
62 lines (53 loc) · 1.74 KB
/
global-type-param2.slang
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//DISABLED_TEST(smoke,compute):COMPARE_COMPUTE:
//TEST_INPUT: ubuffer(data=[0], stride=4):out,name outputBuffer
//TEST_INPUT: cbuffer(data=[0.5 0 0 0], stride=4):name existingBuffer
//__disabled__TEST_INPUT: object(type=Impl):name impl
//TEST_INPUT: root_constants(data=[1.0], stride=4):name impl.base
//TEST_INPUT: Texture2D(size=4, content = zero):name tex1
//TEST_INPUT: Texture2D(size=4, content = one):name impl.tex
//TEST_INPUT: Sampler:name sampler
//TEST_INPUT: Sampler:name impl.sampler
//TEST_INPUT: type Impl
/* Testing this scenario:
The ProgramLayout before specializeIRForEntryPoint() has no global cbuffer
allocated because the program before specialization does not define any
global uniform variables.
However, after specialization, we find ourselves needing a global constant
buffer. The compiler should allocate the next available constant buffer slot
(here c1 because c0 is already used by the explicit cbuffer decl `existingBuffer`)
for the newly generated global constant buffer.
*/
RWStructuredBuffer<float> outputBuffer;
interface IBase
{
float compute();
}
struct Impl : IBase
{
float base; // = 1.0
Texture2D tex;
SamplerState sampler;
float compute()
{
return tex.SampleLevel(sampler, float2(0.0), 0.0).x + base;
}
};
// at binding c0:
cbuffer existingBuffer
{
float base0; // = 0.5
}
Texture2D tex1; // = 0.0
SamplerState sampler;
[numthreads(1, 1, 1)]
void computeMain<
TImpl : IBase>(
uniform ParameterBlock<TImpl> impl,
uint3 dispatchThreadID : SV_DispatchThreadID)
{
uint tid = dispatchThreadID.x;
float b0 = tex1.SampleLevel(sampler, float2(0.0), 0.0).x + base0; // = 0.5
float outVal = impl.compute(); // = 2.0
outVal = b0 / outVal; // = 0.25
outputBuffer[tid] = outVal;
}