yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
a6deb5ed8
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//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer 5RWStructuredBuffer<float> outputBuffer; 6 7// `OpSpecConstantOp` can only contain integer operations when targeting Vulkan SPIRV, not floating-point operations. 8// This test checks that floating-point operations that strictly contain specialization constant variables are not declared with `OpSpecContantOp`, 9// while integer operations that strictly contain specializaton constant operands are declared as `OpSpecConstantOp`. 10 11// CHECK-DAG: OpSpecConstant %float 1 12// CHECK-DAG: OpSpecConstant %ulong 256 13// CHECK-DAG: OpSpecConstant %float 100 14 15// CHECK-NOT: OpSpecConstantOp {{.*}} FAdd 16// CHECK-NOT: OpSpecConstantOp {{.*}} FSub 17// CHECK-NOT: OpSpecConstantOp {{.*}} FMul 18// CHECK-NOT: OpSpecConstantOp {{.*}} FDiv 19// CHECK-NOT: OpSpecConstantOp {{.*}} SpvOpConvertUToF 20// CHECK-NOT: OpSpecConstantOp {{.*}} SpvOpConvertFToU 21 22[[SpecializationConstant]] 23const float X = 1.0; 24[[SpecializationConstant]] 25const uint64_t Y = 256; 26[[SpecializationConstant]] 27const float Z = 100.0; 28 29int func1() 30{ 31 // Test float-to-float and int-to-int conversions. 32 int a = int(Y); 33 half b = half(X); 34 int16_t c = int16_t(Y); 35 36 // Test comparisons. 37 if (X < 2.0) 38 { 39 a = 3; 40 } 41 else if (X > 5.0) 42 { 43 a = 5; 44 } 45 46 if (Y < 200) 47 { 48 b = 2.0h; 49 } 50 else if (Y > 500) 51 { 52 b = 5.0h; 53 } 54 55 return a + int(b) + int(c); 56} 57 58float func2() 59{ 60 // Test floating-point arithmetic. 61 float a = X + Z; 62 a += (X - Z); 63 a += (X * Z); 64 a += (X / Z); 65 66 return a; 67} 68 69float func3() 70{ 71 // Test float-to-int and int-to-float conversions. 72 int a = int(Z) * 2; 73 return float(Y) + float(a); 74} 75 76[shader("compute")] 77[numthreads(1, 1, 1)] 78void computeMain() 79{ 80 // BUF: 818.01 81 outputBuffer[0] = float(func1()) + func2() + func3(); 82}