yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

kaizhangNVFix the sign-extending issue in right shift (#3820)57f514d09

master
1.2 KiB26 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cuda -compute -output-using-type
2//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -output-using-type
3//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cpu -compute -output-using-type
4
5// CHECK: 9223372036854775808
6// CHECK: 1
7// CHECK: 18446744073709551615
8
9// This tests exhibits a bug in constant folding in which the right shift
10// operator unconditionally performs sign-extension.
11
12//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=8):out,name=outputBuffer
13RWStructuredBuffer<uint64_t> outputBuffer;
14
15[numthreads(1, 1, 1)]
16void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
17{
18    const uint64_t topBitSet = 0x8000000000000000ull;
19    const uint64_t bottomBitSet = topBitSet >> 63;
20    const uint64_t allBitsSet = int64_t(topBitSet) >> 63; // expect sign-extending which will set all bits.
21    const uint64_t noBitsSet = topBitSet >> 64; // This exhibits undefined behaviour, as the compiler shifts right by at least the number of bits in the first operand
22    outputBuffer[0] = topBitSet;
23    outputBuffer[1] = bottomBitSet;
24    outputBuffer[2] = allBitsSet;
25    outputBuffer[3] = noBitsSet;
26}