yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
fdef653ab
master
1//TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry fragmentMain -stage fragment -emit-spirv-via-glsl 2//TEST:SIMPLE(filecheck=SPIRV):-target spirv -entry fragmentMain -stage fragment 3//DISABLED_TEST:SIMPLE(filecheck=SPIRV):-target spirv-assembly -entry fragmentMain -stage fragment -DENABLE_CLAMP -emit-spirv-directly 4//DISABLED_TEST:SIMPLE(filecheck=DXIL):-target dxil-assembly -entry fragmentMain -stage fragment 5//TEST:SIMPLE(filecheck=HLSL):-target hlsl -entry fragmentMain -stage fragment 6 7// TODO: The SPIRV test is fine locally, but seems to lead to an impossible to debug hang in CI 8 9//DISABLED_TEST:SIMPLE:-target spirv-assembly -entry fragmentMain -stage fragment 10//DISABLED_TEST:SIMPLE:-target dxil-assembly -entry fragmentMain -stage fragment 11//DISABLED_TEST:SIMPLE:-target hlsl -entry fragmentMain -stage fragment 12 13// In order to make sure that all of the data produced in each 14// query is referenced (and thus cannot be DCE'd away), we maintain 15// single accumulator that will have the bits of each query result 16// mixed into it. 17 18void accumulate(inout uint r, uint u) 19{ 20 r = r ^ u; 21} 22 23void accumulate(inout uint r, bool b) 24{ 25 accumulate(r, uint(b)); 26} 27 28void accumulate(inout uint r, uint2 u) 29{ 30 accumulate(r, u.x); 31 accumulate(r, u.y); 32} 33 34void accumulate(inout uint r, uint3 u) 35{ 36 accumulate(r, u.x); 37 accumulate(r, u.y); 38 accumulate(r, u.z); 39} 40 41void accumulate(inout uint r, TextureFootprint2D f) 42{ 43 accumulate(r, f.anchor); 44 accumulate(r, f.offset); 45 accumulate(r, f.mask); 46 accumulate(r, f.lod); 47 accumulate(r, f.granularity); 48 accumulate(r, f.isSingleLevel); 49} 50 51uniform Texture2D texture; 52uniform SamplerState sampler; 53uniform RWStructuredBuffer<uint> outputBuffer; 54 55cbuffer Uniforms 56{ 57 uniform float2 coords; 58 uniform uint granularity; 59}; 60 61void fragmentMain( 62 float v : VARYING) 63{ 64 uint index = uint(v); 65 uint r = 0; 66 67 accumulate(r, texture.queryFootprintCoarse(granularity, sampler, coords)); 68 69// SPIRV: OpExtension "SPV_NV_shader_image_footprint" 70// SPIRV: OpImageSampleFootprintNV 71 72// HLSL: NvFootprintCoarse 73 74 outputBuffer[index] = r; 75} 76