yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
db44c1b73
master
1//TEST:SIMPLE(filecheck=CHECK): -target spirv -stage compute -entry computeMain 2//TEST:SIMPLE(filecheck=CHECK): -target spirv -stage compute -entry computeMain -DIS_DEFAULT 3 4// To intentionally fill up binding slots 5[[vk::binding(0, 1)]] 6RWTexture1D<float> t1; 7 8[[vk::binding(0, 2)]] 9RWTexture1D<float> t2; 10 11[[vk::binding(0, 4)]] 12RWTexture1D<float> t3; 13 14[[vk::binding(1, 4)]] 15Texture1D<float> t4; 16 17//CHECK-DAG: OpDecorate %__slang_resource_heap{{.*}} Binding 0 18//CHECK-DAG: OpDecorate %__slang_resource_heap{{.*}} Binding 1 19//CHECK-DAG: OpDecorate %__slang_resource_heap{{.*}} Binding 2 20//CHECK-DAG: OpConvertUToAccelerationStructureKHR 21 22//CHECK-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 3 23//CHECK-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 4 24//CHECK-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 5 25//CHECK-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 6 26//CHECK-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 7 27//CHECK-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 8 28//CHECK-NOT: OpDecorate %__slang_resource_heap{{.*}} Binding 9 29 30#ifndef IS_DEFAULT 31export T getDescriptorFromHandle<T:IOpaqueDescriptor>(DescriptorHandle<T> handleValue) 32{ 33 return defaultGetDescriptorFromHandle(handleValue, BindlessDescriptorOptions.VkMutable); 34} 35#endif 36 37uniform SamplerState.Handle sampler; 38uniform Sampler1DShadow.Handle combinedSampler; 39uniform Texture1D<float>.Handle texture; 40uniform RWTexture1D<float>.Handle rwTexture1; 41uniform RWTexture2D<float>.Handle rwTexture2; 42uniform Buffer<float>.Handle texelBuffer; 43uniform RWBuffer<float>.Handle rwTexelBuffer; 44 45struct Data 46{ 47 float v; 48} 49uniform ConstantBuffer<Data>.Handle buffer1; 50uniform StructuredBuffer<float>.Handle buffer2; 51uniform RWStructuredBuffer<float>.Handle rwBuffer; 52uniform RaytracingAccelerationStructure.Handle rayAcceleration; 53 54[numthreads(2,2,1)] 55[shader("compute")] 56void computeMain() 57{ 58 59 t1[0] = t2[0] + t2[0] + t4[0]; 60 t1[2] = t4.Sample(sampler, 0); 61 t1[8] = combinedSampler.Sample(0); 62 t1[0] = texture[0]; 63 t1[11] = rwTexture1[0]; 64 t1[12] = rwTexture2[0]; 65 t1[10] = texelBuffer[0]; 66 t1[9] = rwTexelBuffer[0]; 67 t1[4] = (*buffer1).v; 68 t1[6] = buffer2[0]; 69 t1[0] += rwBuffer[0]; 70 71 RayDesc ray; 72 ray.Origin = float3(0.1f, 0.1f, 0.0f); 73 ray.Direction = float3(0.0f, 0.0f, 1.0f); 74 ray.TMin = 0.0f; 75 ray.TMax = 100.0f; 76 RayQuery<RAY_FLAG_FORCE_NON_OPAQUE> rq; 77 rq.TraceRayInline(rayAcceleration, RAY_FLAG_FORCE_NON_OPAQUE, 0xff, ray); 78 bool proceed = rq.Proceed(); 79 rq.CommitNonOpaqueTriangleHit(); 80 rq.Abort(); 81 t1[13] = (float)rq.RayFlags(); 82 83}