yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
da5cf478c
master
1// This test checks that kIROp_StructuredBufferLoad and similar instructions 2// are not movable. 3 4//TEST:SIMPLE(filecheck=CHECK): -entry computeMain -stage compute -target hlsl 5 6[[vk::binding(0, 0)]] 7StructuredBuffer<float> gSomeData; 8 9[[vk::binding(1, 0)]] 10RWTexture2D<float4> gResultImage; 11 12struct PushConstants 13{ 14 bool bufferHasOnlyOneElement; 15}; 16 17[[vk::push_constant]] 18ConstantBuffer<PushConstants> gPushConstants; 19 20float loadDataConditionTrue() 21{ 22 return gSomeData[0]; 23} 24 25float loadDataConditionFalse() 26{ 27 return gSomeData[1]; 28} 29 30[ForceInline] 31float getDataDependingOnCondition(bool condition) 32{ 33 if (condition) 34 { 35 return loadDataConditionTrue(); 36 } 37 else 38 { 39 return loadDataConditionFalse(); 40 } 41 42 return 0.0; 43} 44 45[numthreads(1,1,1)] 46void computeMain() 47{ 48 // CHECK: if 49 // CHECK: loadDataConditionTrue 50 // CHECK: else 51 // CHECK: loadDataConditionFalse 52 float v = getDataDependingOnCondition(gPushConstants.bufferHasOnlyOneElement); 53 54 int2 pixelIndex = int2(0); 55 gResultImage[pixelIndex] = float4(v, v, v, 1.0); 56}