yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
4485cf3ea
master
1//TEST:SIMPLE(filecheck=CHECK_GLSL): -allow-glsl -stage compute -entry computeMain -target glsl -DTARGET_GLSL 2//TEST:SIMPLE(filecheck=CHECK_SPV): -allow-glsl -stage compute -entry computeMain -target spirv -emit-spirv-directly -DTARGET_SPIRV 3//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl 4//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl -emit-spirv-directly 5#version 430 6 7//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name=outputBuffer 8buffer MyBlockName 9{ 10 uint data[2]; 11} outputBuffer; 12 13// CHECK_GLSL-DAG: void main( 14// CHECK_SPV-DAG: OpEntryPoint 15 16//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0], stride=4):name=one 17layout(binding = 1, offset = 12) uniform atomic_uint one; 18bool testSetterAndGetter() 19{ 20 return true 21 22// CHECK_GLSL-DAG: atomicExchange 23// CHECK_SPV-DAG: OpAtomicExchange 24 && atomicCounterExchange(one, 1) == 0 25 26// CHECK_GLSL-DAG: atomicExchange 27// no idea how to check the spirv reliabley... 28 && atomicCounter(one) == 1 29 && atomicCounterExchange(one, 5) == 1 30 && atomicCounter(one) == 5 31 ; 32} 33 34bool counterAsParam(atomic_uint param) 35{ 36 return true 37 && atomicCounterExchange(param, 5) != 100 38 39// CHECK_GLSL-DAG: atomicAdd( 40// CHECK_SPV-DAG: OpAtomicIAdd 41 && atomicCounterIncrement(param) == 5 42 && atomicCounter(param) == 6 43 ; 44} 45 46// GLSL_CHECK-LABEL: bool testAtomicUint 47// SPV_CHECK-LABEL: testAtomicUint 48bool testAtomicUint() 49{ 50// ensure the code emits for `one` index into [3] for 12/4 51// CHECK_GLSL-DAG: {{.*}}_data_{{.*}}[3]{{.*}} 52 return true 53 54 && atomicCounterExchange(one, 5) != 100 55// CHECK_GLSL-DAG: atomicAdd( 56// CHECK_SPV-DAG: OpAtomicIIncrement 57 && atomicCounterIncrement(one) == 5 58 && atomicCounter(one) == 6 59 60 && atomicCounterExchange(one, 5) != 100 61// CHECK_GLSL-DAG: atomicExchange( 62// CHECK_SPV-DAG: OpAtomicIDecrement 63 && atomicCounterDecrement(one) == 4 64 65 && atomicCounterExchange(one, 5) != 100 66// CHECK_GLSL-DAG: atomicAdd( 67 && atomicCounterAdd(one, 1) == 5 68 && atomicCounter(one) == 6 69 70 && atomicCounterExchange(one, 5) != 100 71// CHECK_GLSL-DAG: atomicExchange 72// CHECK_SPV-DAG: OpAtomicISub 73 && atomicCounterSubtract(one, 1) == 5 74 && atomicCounter(one) == 4 75 76 && atomicCounterExchange(one, 5) != 100 77// CHECK_GLSL-DAG: atomicMin( 78// CHECK_SPV-DAG: OpAtomicUMin 79 && atomicCounterMin(one, 1) == 5 80 && atomicCounter(one) == 1 81 82 && atomicCounterExchange(one, 5) != 100 83// CHECK_GLSL-DAG: atomicMax( 84// CHECK_SPV-DAG: OpAtomicUMax 85 && atomicCounterMax(one, 1) == 5 86 && atomicCounter(one) == 5 87 88// CHECK_GLSL-DAG: atomicAnd( 89// CHECK_SPV: OpAtomicAnd 90 && atomicCounterExchange(one, 5) != 100 91 && atomicCounterAnd(one, 2) == 5 92 && atomicCounter(one) == 0 93 94// CHECK_GLSL-DAG: atomicOr( 95// CHECK_SPV-DAG: OpAtomicOr 96 && atomicCounterExchange(one, 5) != 100 97 && atomicCounterOr(one, 8) == 5 98 && atomicCounter(one) == 13 99 100// CHECK_GLSL-DAG: atomicXor( 101// CHECK_SPV-DAG: OpAtomicXor 102 && atomicCounterExchange(one, 5) != 100 103 && atomicCounterXor(one, 4) == 5 104 && atomicCounter(one) == 1 105 106// CHECK_GLSL-DAG: atomicCompSwap( 107// CHECK_SPV-DAG: OpAtomicCompareExchange 108 && atomicCounterExchange(one, 5) != 100 109 && atomicCounterCompSwap(one, 5, 3) == 5 110 && atomicCounter(one) == 3 111 112// CHECK_GLSL-DAG: atomicCompSwap( 113// CHECK_SPV-DAG: OpAtomicCompareExchange 114 && atomicCounterExchange(one, 5) != 100 115 && atomicCounterCompSwap(one, 5, 3) == 5 116 && atomicCounter(one) == 3 117 118 && counterAsParam(one); 119 ; 120} 121 122void computeMain() 123{ 124 outputBuffer.data[0] = true 125 && testSetterAndGetter() 126 ; 127 outputBuffer.data[1] = true 128 && testAtomicUint() 129 ; 130 // BUF: 1 131 // BUF-NEXT: 1 132}