yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
b39ec87cc
master
1// struct-bit-cast-2.slang 2// Test bit casts for read across boundaries of scalar types. 3 4//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -emit-spirv-directly 5//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cpu -shaderobj 6//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cuda -shaderobj 7 8// Test that bit_cast works for bit-reinterpreting one struct type as another. 9 10struct Foo 11{ 12 uint16_t a; 13 uint16_t b; 14 uint32_t c; 15} 16 17struct Bar 18{ 19 uint64_t d; 20} 21 22 23//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer 24RWStructuredBuffer<int> outputBuffer; 25 26[numthreads(1, 1, 1)] 27void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) 28{ 29 Bar b = { 0x1122334455667788 }; 30 Foo f = reinterpret<Foo>(b); 31 // CHECK: 7788 32 outputBuffer[0] = f.a; 33 // CHECK: 5566 34 outputBuffer[1] = f.b; 35 // CHECK: 11223344 36 outputBuffer[2] = f.c; 37 38 uint8_t4 v = {0x10, 0x20, 0x30, 0x40}; 39 uint32_t u = reinterpret<uint32_t>(v); 40 41 // CHECK: 40302010 42 outputBuffer[3] = u; 43 int* ptr = reinterpret<int*>(b.d); 44 Foo f1 = reinterpret<Foo>(ptr); 45 // CHECK: 11223344 46 outputBuffer[4] = f1.c; 47}