summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/descriptor-handle/desc-handle-1.slang
blob: 407aee68440637c3436453640b33dc606398581c (plain)
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
//TEST:SIMPLE(filecheck=SPV): -target spirv

// SPV: OpDecorate %resourceHeap DescriptorSet 10
// SPV: OpAccessChain {{.*}} %resourceHeap
// SPV: OpImageSample

uniform StructuredBuffer<DescriptorHandle<Sampler2D>> t;
uniform DescriptorHandle<RWStructuredBuffer<float4>> buffer;

[vk::binding(0, 10)]
__DynamicResource<__DynamicResourceKind.General> resourceHeap[]; 

// A customized function that overrides the default behavior of fetch texture resources.
export T getDescriptorFromHandle<T:IOpaqueDescriptor>(DescriptorHandle<T> handleValue)
{
    __target_switch
    {
    case spirv:
        if (T.kind != DescriptorKind.ConstantBuffer && T.kind != DescriptorKind.StorageBuffer)
            return resourceHeap[((uint2)handleValue).x].asOpaqueDescriptor<T>();
        else
            return defaultGetDescriptorFromHandle(handleValue);
    default:
        return defaultGetDescriptorFromHandle(handleValue);
    }
}

[numthreads(1,1,1)]
void computeMain()
{
    buffer[0] = t[0]->SampleLevel(float2(0.0), 0.0);
}