yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

CopilotFix incorrect binding index assignment for StructuredBuffer and ByteAddressBuffer with DescriptorHandle (#8252)cd7da79f5

master
6.0 KiB168 linesraw
1//TEST:SIMPLE(filecheck=SAMPLER): -target spirv -stage compute -entry computeMain -DSAMPLER
2//TEST:SIMPLE(filecheck=COMBINED_IMAGE_SAMPLER): -target spirv -stage compute -entry computeMain -DCOMBINED_IMAGE_SAMPLER
3//TEST:SIMPLE(filecheck=SAMPLED_IMAGE): -target spirv -stage compute -entry computeMain -DSAMPLED_IMAGE
4//TEST:SIMPLE(filecheck=STORAGE_IMAGE): -target spirv -stage compute -entry computeMain -DSTORAGE_IMAGE
5//TEST:SIMPLE(filecheck=UNIFORM_TEXEL_BUFFER): -target spirv -stage compute -entry computeMain -DUNIFORM_TEXEL_BUFFER
6//TEST:SIMPLE(filecheck=STORAGE_TEXEL_BUFFER): -target spirv -stage compute -entry computeMain -DSTORAGE_TEXEL_BUFFER
7//TEST:SIMPLE(filecheck=UNIFORM_BUFFER): -target spirv -stage compute -entry computeMain -DUNIFORM_BUFFER
8//TEST:SIMPLE(filecheck=STORAGE_BUFFER): -target spirv -stage compute -entry computeMain -DSTORAGE_BUFFER
9//TEST:SIMPLE(filecheck=ACCELERATION_STRUCTURE): -target spirv -stage compute -entry computeMain -DACCELERATION_STRUCTURE
10//TEST:SIMPLE(filecheck=SAMPLED_IMAGE): -target spirv -stage compute -entry computeMain -DSAMPLED_IMAGE
11//TEST:SIMPLE(filecheck=MIX): -target spirv -stage compute -entry computeMain -DSAMPLER -DSTORAGE_TEXEL_BUFFER -DUNIFORM_BUFFER -DACCELERATION_STRUCTURE
12
13
14export T getDescriptorFromHandle<T : IOpaqueDescriptor>(DescriptorHandle<T> handleValue)
15{
16    return defaultGetDescriptorFromHandle(handleValue, BindlessDescriptorOptions.None);
17}
18
19// To intentionally fill up binding slots
20[[vk::binding(0, 1)]]
21RWTexture1D<float> t1;
22
23[[vk::binding(0, 2)]]
24RWTexture1D<float> t2;
25
26[[vk::binding(0, 4)]]
27RWTexture1D<float> t3;
28
29[[vk::binding(1, 4)]]
30Texture1D<float> t4;
31
32//MIX-DAG: OpDecorate %__slang_resource_heap{{.*}} Binding 0
33//MIX-DAG: OpDecorate %__slang_resource_heap{{.*}} Binding 5
34//MIX-DAG: OpDecorate %__slang_resource_heap{{.*}} Binding 6
35//MIX-DAG: OpDecorate %__slang_resource_heap{{.*}} Binding 7
36
37//MIX-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 1
38//MIX-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 2
39//MIX-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 3
40//MIX-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 4
41//MIX-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 8
42
43#ifdef SAMPLER
44//SAMPLER: OpDecorate %__slang_resource_heap{{.*}} Binding 0
45//SAMPLER-NEXT: OpDecorate %__slang_resource_heap{{.*}} DescriptorSet 3
46
47//SAMPLER-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 1
48//SAMPLER-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 2
49//SAMPLER-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 3
50//SAMPLER-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 4
51//SAMPLER-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 5
52//SAMPLER-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 6
53//SAMPLER-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 7
54//SAMPLER-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 8
55uniform SamplerState.Handle sampler;
56#endif
57
58#ifdef COMBINED_IMAGE_SAMPLER
59//COMBINED_IMAGE_SAMPLER: OpDecorate %__slang_resource_heap{{.*}} Binding 1
60//COMBINED_IMAGE_SAMPLER-NEXT: OpDecorate %__slang_resource_heap{{.*}} DescriptorSet 3
61uniform Sampler1DShadow.Handle combinedSampler;
62#endif
63
64#ifdef SAMPLED_IMAGE
65//SAMPLED_IMAGE: OpDecorate %__slang_resource_heap{{.*}} Binding 2
66//SAMPLED_IMAGE-NEXT: OpDecorate %__slang_resource_heap{{.*}} DescriptorSet 3
67uniform Texture1D<float>.Handle texture;
68#endif
69
70#ifdef STORAGE_IMAGE
71//STORAGE_IMAGE: OpDecorate %__slang_resource_heap{{.*}} Binding 3
72//STORAGE_IMAGE-NEXT: OpDecorate %__slang_resource_heap{{.*}} DescriptorSet 3
73uniform RWTexture1D<float>.Handle rwTexture1;
74uniform RWTexture2D<float>.Handle rwTexture2;
75#endif
76
77#ifdef UNIFORM_TEXEL_BUFFER
78//UNIFORM_TEXEL_BUFFER: OpDecorate %__slang_resource_heap{{.*}} Binding 4
79//UNIFORM_TEXEL_BUFFER-NEXT: OpDecorate %__slang_resource_heap{{.*}} DescriptorSet 3
80uniform Buffer<float>.Handle texelBuffer;
81#endif
82
83#ifdef STORAGE_TEXEL_BUFFER
84//STORAGE_TEXEL_BUFFER: OpDecorate %__slang_resource_heap{{.*}} Binding 5
85//STORAGE_TEXEL_BUFFER-NEXT: OpDecorate %__slang_resource_heap{{.*}} DescriptorSet 3
86uniform RWBuffer<float>.Handle rwTexelBuffer;
87#endif
88
89#ifdef UNIFORM_BUFFER
90//UNIFORM_BUFFER: OpDecorate %__slang_resource_heap{{.*}} Binding 6
91//UNIFORM_BUFFER-NEXT: OpDecorate %__slang_resource_heap{{.*}} DescriptorSet 3
92//UNIFORM_BUFFER: OpDecorate %__slang_resource_heap{{.*}} Binding 7
93//UNIFORM_BUFFER-NEXT: OpDecorate %__slang_resource_heap{{.*}} DescriptorSet 3
94struct Data
95{
96    float v;
97}
98uniform ConstantBuffer<Data>.Handle buffer1;
99uniform StructuredBuffer<float>.Handle buffer2;
100#endif
101
102#ifdef STORAGE_BUFFER
103//STORAGE_BUFFER: OpDecorate %__slang_resource_heap{{.*}} Binding 7
104//STORAGE_BUFFER-NEXT: OpDecorate %__slang_resource_heap{{.*}} DescriptorSet 3
105uniform RWStructuredBuffer<float>.Handle rwBuffer;
106#endif
107
108#ifdef ACCELERATION_STRUCTURE
109//ACCELERATION_STRUCTURE-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 8
110//ACCELERATION_STRUCTURE: OpConvertUToAccelerationStructureKHR
111uniform RaytracingAccelerationStructure.Handle rayAcceleration;
112#endif
113
114[numthreads(2,2,1)]
115[shader("compute")]
116void computeMain()
117{
118
119    t1[0] = t2[0] + t2[0] + t4[0];
120
121#ifdef SAMPLER
122    t1[2] = t4.Sample(sampler, 0);
123#endif
124
125#ifdef COMBINED_IMAGE_SAMPLER
126    t1[8] = combinedSampler.Sample(0);
127#endif
128
129#ifdef SAMPLED_IMAGE
130    t1[0] = texture[0];
131#endif
132
133#ifdef STORAGE_IMAGE
134    t1[11] = rwTexture1[0];
135    t1[12] = rwTexture2[0];
136#endif
137
138#ifdef UNIFORM_TEXEL_BUFFER
139    t1[10] = texelBuffer[0];
140#endif
141
142#ifdef STORAGE_TEXEL_BUFFER
143    t1[9] = rwTexelBuffer[0];
144#endif
145
146#ifdef UNIFORM_BUFFER
147    t1[4] = (*buffer1).v;
148    t1[6] = buffer2[0];
149#endif
150
151#ifdef STORAGE_BUFFER
152    t1[0] += rwBuffer[0];
153#endif
154
155#ifdef ACCELERATION_STRUCTURE
156    RayDesc ray;
157    ray.Origin = float3(0.1f, 0.1f, 0.0f);
158    ray.Direction = float3(0.0f, 0.0f, 1.0f);
159    ray.TMin = 0.0f;
160    ray.TMax = 100.0f;
161    RayQuery<RAY_FLAG_FORCE_NON_OPAQUE> rq;
162    rq.TraceRayInline(rayAcceleration, RAY_FLAG_FORCE_NON_OPAQUE, 0xff, ray);
163    bool proceed = rq.Proceed();
164    rq.CommitNonOpaqueTriangleHit();
165    rq.Abort();
166    t1[13] = (float)rq.RayFlags();
167#endif
168}