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
1018 B32 linesraw
1//TEST:SIMPLE(filecheck=SPV): -target spirv
2
3// SPV: OpDecorate %resourceHeap DescriptorSet 10
4// SPV: OpAccessChain {{.*}} %resourceHeap
5// SPV: OpImageSample
6
7uniform StructuredBuffer<DescriptorHandle<Sampler2D>> t;
8uniform DescriptorHandle<RWStructuredBuffer<float4>> buffer;
9
10[vk::binding(0, 10)]
11__DynamicResource<__DynamicResourceKind.General> resourceHeap[]; 
12
13// A customized function that overrides the default behavior of fetch texture resources.
14export T getDescriptorFromHandle<T:IOpaqueDescriptor>(DescriptorHandle<T> handleValue)
15{
16    __target_switch
17    {
18    case spirv:
19        if (T.kind != DescriptorKind.ConstantBuffer && T.kind != DescriptorKind.StorageBuffer)
20            return resourceHeap[((uint2)handleValue).x].asOpaqueDescriptor<T>();
21        else
22            return defaultGetDescriptorFromHandle(handleValue);
23    default:
24        return defaultGetDescriptorFromHandle(handleValue);
25    }
26}
27
28[numthreads(1,1,1)]
29void computeMain()
30{
31    buffer[0] = t[0]->SampleLevel(float2(0.0), 0.0);
32}