yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
b39ec87cc
master
1//TEST:SIMPLE(filecheck=CHECK): -target spirv 2//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -output-using-type -emit-spirv-directly 3 4// CHECK: %[[C0:[0-9A-Za-z_]+]] = OpSpecConstant %int 4 5// CHECK: %[[I1:[0-9A-Za-z_]+]] = OpConstant %int 1 6// CHECK: %[[COP0:[0-9A-Za-z_]+]] = OpSpecConstantOp %int BitwiseAnd %[[C0]] %[[I1]] 7// CHECK: %[[I2:[0-9A-Za-z_]+]] = OpConstant %int 2 8// CHECK: %[[COP1:[0-9A-Za-z_]+]] = OpSpecConstantOp %int BitwiseOr %[[COP0]] %[[I2]] 9// CHECK: %[[COP2:[0-9A-Za-z_]+]] = OpSpecConstantOp %int IAdd %[[I1]] %[[COP1]] 10// CHECK: %[[COP3:[0-9A-Za-z_]+]] = OpSpecConstantOp %int ShiftLeftLogical %[[C0]] %[[COP2]] 11// CHECK: %[[ARR_TYPE:[0-9A-Za-z_]+]] = OpTypeArray %float %[[COP3]] 12// CHECK: %[[PT_TYPE:[0-9A-Za-z_]+]] = OpTypePointer Function %[[ARR_TYPE]] 13 14[SpecializationConstant] 15const int constValue0 = 4; 16 17//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer 18RWStructuredBuffer<float> outputBuffer; 19 20static const int size = constValue0 << (1 + (constValue0 & 0x01 | 0x02)); // 4 << 3 = 32 21 22// This test is to verify that if two array has the same spec constant size, they are the same type. 23void func(out float buffer[constValue0 << (1 + (constValue0 & 0x01 | 0x02))], int idx) 24{ 25 for (uint i = 0; i < size; i++) 26 { 27 buffer[i] = i; 28 } 29} 30 31[shader("compute")] 32[numthreads(1, 1, 1)] 33void computeMain(uint tid:SV_DispatchThreadID) 34{ 35 float buffer[constValue0 << (1 + (constValue0 & 0x01 | 0x02))]; 36 // CHECK: OpVariable %[[PT_TYPE]] Function 37 38 func(buffer, tid); 39 40 float temp = buffer[0]; 41 for (uint i = 0; i < size; i++) 42 { 43 temp += buffer[i] * 2; 44 } 45 // Result will be (0 + size-1) * size = (0 + 31) * 32 * 2 = 992 46 outputBuffer[0] = temp; 47 // BUF: 992 48}