yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
b39ec87cc
master
1//TEST:COMPARE_COMPUTE(filecheck-buffer=BUF): -vk -output-using-type -emit-spirv-directly 2//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer 3RWStructuredBuffer<int32_t> outputBuffer; 4 5//TEST_INPUT:set input = ubuffer(data=[0xC0A0], stride=4) 6RWStructuredBuffer<uint32_t> input; 7 8[shader("compute")] 9[numthreads(1, 1, 1)] 10void computeMain( 11 uint3 tid : SV_DispatchThreadID) 12{ 13 uint16_t a = uint16_t(input[0] & 0xFFFF); 14 int16_t b = bit_cast<int16_t>(a); 15 16 outputBuffer[0] = bitfieldExtract(a, 14, 2); 17 outputBuffer[1] = bitfieldExtract(b, 13, 3); // 0b110, with sign extend, it will be 0xFFFFFFFE => -2 18 // BUF: 3 19 // BUF: -2 20 21 uint8_t c = uint8_t(input[0] & 0xFF); 22 int8_t d = bit_cast<int8_t>(c); 23 24 outputBuffer[2] = bitfieldExtract(c, 5, 3); // b101 = 5 25 outputBuffer[3] = bitfieldExtract(d, 5, 3); // 0b101, with sign extend, it will be 0xFFFFFFFD => -3 26 // BUF: 5 27 // BUF: -3 28 29 outputBuffer[4] = bitfieldInsert(a, 0x03U, 8, 2); // 0xC3A0 = 50080 (unsigned) 30 outputBuffer[5] = bitfieldInsert(b, 0x03, 8, 2); // 0xC3A0 = -15456 (signed) 31 // BUF: 50080 32 // BUF: -15456 33 34 outputBuffer[6] = bitfieldInsert(c, 0x03U, 3, 2); // 0xB8 = 184 (unsigned) 35 outputBuffer[7] = bitfieldInsert(d, 0x03, 3, 2); // 0xB8 = -72 (signed) 36 // BUF: 184 37 // BUF: -72 38}