diff options
| author | Julius Ikkala <julius.ikkala@gmail.com> | 2025-05-22 22:10:42 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-22 22:10:42 +0300 |
| commit | ce238dd878038bf857968931773cc9b10f3b225d (patch) | |
| tree | 2e29a5191fff5eb85a5a7895fd68b7b285bcb198 /tests | |
| parent | 27c6e9b01f7386263bde90e16812be46327015c2 (diff) | |
Make sizeof(T) & alignof(T) of generic types work as compile-time constants (#7213)
* Make sizeof(generic) work as compile-time constant
* format code
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/hlsl-intrinsic/size-of/size-of-compile-time.slang | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/hlsl-intrinsic/size-of/size-of-compile-time.slang b/tests/hlsl-intrinsic/size-of/size-of-compile-time.slang new file mode 100644 index 000000000..64e2f640b --- /dev/null +++ b/tests/hlsl-intrinsic/size-of/size-of-compile-time.slang @@ -0,0 +1,41 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cpu -compute -shaderobj +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-slang -compute -shaderobj +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-slang -compute -dx12 -shaderobj +//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -compute -shaderobj +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-cuda -compute -shaderobj + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer + +RWStructuredBuffer<int> outputBuffer; + +struct Thing<T> +{ + uint8_t data[sizeof(T)]; +}; + +struct AlignThing<T> +{ + uint8_t data[alignof(T)]; +}; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + const int idx = asint(dispatchThreadID.x); + + int size = 0; + + switch (idx) + { + case 0: size = sizeof(Thing<float>); break; + case 1: size = sizeof(Thing<float3>); break; + case 2: size = sizeof(AlignThing<float>); break; + case 3: size = sizeof(AlignThing<float3>); break; + } + + // CHECK: 4 + // CHECK-NEXT: C + // CHECK: 4 + // CHECK-NEXT: 4 + outputBuffer[idx] = size; +} |
