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 32 5// CHECK: %[[I2:[0-9A-Za-z_]+]] = OpConstant %int 2 6// CHECK: %[[COP0:[0-9A-Za-z_]+]] = OpSpecConstantOp %int SDiv %[[C0]] %[[I2]] 7// CHECK: %[[COP1:[0-9A-Za-z_]+]] = OpSpecConstantOp %int ShiftRightArithmetic %[[C0]] %[[I2]] 8// CHECK: %[[COP2:[0-9A-Za-z_]+]] = OpSpecConstantOp %int IAdd %[[COP0]] %[[COP1]] 9// CHECK: %[[ARR_TYPE:[0-9A-Za-z_]+]] = OpTypeArray %float %[[COP2]] 10// CHECK: %[[PT_TYPE:[0-9A-Za-z_]+]] = OpTypePointer Function %[[ARR_TYPE]] 11 12[SpecializationConstant] 13const int constValue0 = 32; 14 15//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name=outputBuffer 16RWStructuredBuffer<float> outputBuffer; 17 18static float g_buffer[constValue0 / 2 + (constValue0 >> 2)]; 19 20[shader("compute")] 21[numthreads(1, 1, 1)] 22void computeMain() 23{ 24 float buffer[constValue0 / 2 + (constValue0 >> 2)]; 25 // CHECK: OpVariable %[[PT_TYPE]] Function 26 27 static const int size = constValue0 / 2 + (constValue0 >> 2); // 16 + 8 = 24 28 for (uint i = 0; i < size; i++) 29 { 30 buffer[i] = i; 31 g_buffer[i] = i * 2; 32 } 33 34 float temp1 = 0.0f; 35 float temp2 = 0.0f; 36 for (uint i = 0; i < size; i++) 37 { 38 temp1 += buffer[i] * 2; 39 temp2 += g_buffer[i]; 40 } 41 42 // Result will be (0 + size-1) * size = (0 + 23) * 24 = 552 43 outputBuffer[0] = temp1; 44 // BUF: 552 45 46 outputBuffer[1] = temp2; 47 // BUF-NEXT: 552 48}