diff options
| author | Yong He <yonghe@outlook.com> | 2025-01-10 10:57:04 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-10 10:57:04 -0800 |
| commit | 5290c580632cfb56847b863a32dc020a21d1c93e (patch) | |
| tree | 4c543f28d13f62a1dc3293b76151dda7585743ab /tests/language-feature | |
| parent | 4cfae806a6f9c0203ce44c4ce04df5ad66cdc8a2 (diff) | |
Initial implementation of SP#015 `DescriptorHandle<T>`. (#6028)
* Initial implementation of `ResourcePtr<T>`.
* Update docs
* Fix build error.
* Add more discussion.
* Update documentation.
* Update TOC.
* Fix.
* Fix.
* Add test case for custom `getResourceFromBindlessHandle`.
* Add namehint to generated descriptor heap param.
* Fix.
* Fix.
* format code
* Rename to `DescriptorHandle`, and add `T.Handle` alias.
* Fix compiler error.
* Fix.
* Fix build.
* Renames.
* Fix documentation.
* Documentation fix.
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'tests/language-feature')
4 files changed, 103 insertions, 0 deletions
diff --git a/tests/language-feature/descriptor-handle/desc-handle-0.slang b/tests/language-feature/descriptor-handle/desc-handle-0.slang new file mode 100644 index 000000000..67f452cfc --- /dev/null +++ b/tests/language-feature/descriptor-handle/desc-handle-0.slang @@ -0,0 +1,22 @@ +//TEST:SIMPLE(filecheck=CUDA): -target cuda -entry computeMain -stage compute +//TEST:SIMPLE(filecheck=MTL): -target metallib -entry computeMain -profile cs_6_6 +//TEST:SIMPLE(filecheck=HLSL): -target hlsl -entry computeMain -profile cs_6_6 +//TEST:SIMPLE(filecheck=DXIL): -target dxil -entry computeMain -profile cs_6_6 +//TEST:SIMPLE(filecheck=SPV): -target spirv + +// SPV: OpImageSample +// HLSL: ResourceDescriptorHeap[{{.*}}] +// HLSL: SamplerDescriptorHeap[{{.*}}] +// HLSL: SampleLevel +// DXIL: computeMain +// CUDA: computeMain +// MTL: define void @computeMain + +uniform StructuredBuffer<DescriptorHandle<Sampler2D>> t; +uniform DescriptorHandle<RWStructuredBuffer<float4>> buffer; + +[numthreads(1,1,1)] +void computeMain() +{ + buffer[0] = t[0]->SampleLevel(float2(0.0), 0.0); +}
\ No newline at end of file diff --git a/tests/language-feature/descriptor-handle/desc-handle-1.slang b/tests/language-feature/descriptor-handle/desc-handle-1.slang new file mode 100644 index 000000000..0621f4a84 --- /dev/null +++ b/tests/language-feature/descriptor-handle/desc-handle-1.slang @@ -0,0 +1,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.Buffer) + 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); +}
\ No newline at end of file diff --git a/tests/language-feature/descriptor-handle/desc-handle-2.slang b/tests/language-feature/descriptor-handle/desc-handle-2.slang new file mode 100644 index 000000000..fa7f73b31 --- /dev/null +++ b/tests/language-feature/descriptor-handle/desc-handle-2.slang @@ -0,0 +1,14 @@ +//TEST:SIMPLE(filecheck=SPV): -target spirv -bindless-space-index 101 + +// SPV: OpDecorate %__slang_resource_heap{{.*}} Binding 0 +// SPV: OpDecorate %__slang_resource_heap{{.*}} DescriptorSet 101 +// SPV: OpImageSample + +uniform StructuredBuffer<DescriptorHandle<Sampler2D>> t; +uniform DescriptorHandle<RWStructuredBuffer<float4>> buffer; + +[numthreads(1,1,1)] +void computeMain() +{ + (*buffer)[0] = t[0].SampleLevel(float2(0.0), 0.0); +}
\ No newline at end of file diff --git a/tests/language-feature/descriptor-handle/desc-handle-3.slang b/tests/language-feature/descriptor-handle/desc-handle-3.slang new file mode 100644 index 000000000..5b9263026 --- /dev/null +++ b/tests/language-feature/descriptor-handle/desc-handle-3.slang @@ -0,0 +1,35 @@ +//TEST:SIMPLE(filecheck=MTL): -target metal +//TEST:SIMPLE(filecheck=MTLLIB): -target metallib +//TEST:SIMPLE(filecheck=CUDA): -target cuda -entry computeMain -stage compute +//TEST:SIMPLE(filecheck=PTX): -target ptx -entry computeMain -stage compute +//TEST:SIMPLE(filecheck=SPV): -target spirv -entry computeMain -stage compute -emit-spirv-via-glsl +//TEST:SIMPLE(filecheck=GLSL): -target glsl -entry computeMain -stage compute +//TEST:SIMPLE(filecheck=HLSL): -target hlsl -entry computeMain -profile cs_6_6 +//TEST:SIMPLE(filecheck=DXIL): -target dxil -entry computeMain -profile cs_6_6 +//TEST:SIMPLE(filecheck=SPV): -target spirv + +// SPV-DAG: %[[REG:[A-Za-z_0-9]+]] = OpAccessChain{{.*}}NonUniform +// SPV-DAG: %[[TEX:[A-Za-z_0-9]+]] = OpLoad {{.*}} %[[REG]] +// SPV-DAG: OpImageSampleExplicitLod {{.*}} %[[TEX]] + +// HLSL: ResourceDescriptorHeap[NonUniformResourceIndex +// HLSL: SamplerDescriptorHeap[NonUniformResourceIndex( + +// DXIL: define void @computeMain() + +// GLSL: _slang_resource_heap{{[0-9_]+}}[nonuniformEXT + +// MTL: void computeMain +// MTLLIB: @computeMain + +// CUDA: tex2DLod +// PTX: computeMain + +uniform StructuredBuffer<Sampler2D.Handle> t; +uniform RWStructuredBuffer<float4>.Handle buffer; + +[numthreads(4,1,1)] +void computeMain(int3 id : SV_DispatchThreadID) +{ + (*buffer)[0] = nonuniform(t[id.x]).SampleLevel(float2(0.0), 0.0); +}
\ No newline at end of file |
