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 31 Foo f = bit_cast<Foo>(b); 32 // CHECK: 7788 33 outputBuffer[0] = f.a; 34 // CHECK: 5566 35 outputBuffer[1] = f.b; 36 // CHECK: 11223344 37 outputBuffer[2] = f.c; 38 39 uint8_t4 v = {0x10, 0x20, 0x30, 0x40}; 40 uint32_t u = bit_cast<uint32_t>(v); 41 42 // CHECK: 40302010 43 outputBuffer[3] = u; 44 45 int* ptr = bit_cast<int*>(b.d); 46 Foo f1 = bit_cast<Foo>(ptr); 47 // CHECK: 11223344 48 outputBuffer[4] = f1.c; 49}