yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
5ec41675d
master
1//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-cuda -compute -shaderobj -output-using-type 2//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-dx12 -compute -profile cs_6_0 -shaderobj -output-using-type 3 4// Test CUDA Gather runtime behavior - compare with known gather pattern 5// tex2Dgather samples 4 texels in 2x2 pattern around coordinate 6 7//TEST_INPUT: Texture2D(size=4, content = one):name testTexture 8// Create a 4x4 texture with 1.0 values - simple but non-zero to verify gather works 9Texture2D<float4> testTexture; 10 11//TEST_INPUT: Sampler:name samplerState 12SamplerState samplerState; 13 14//TEST_INPUT: ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer 15RWStructuredBuffer<float> outputBuffer; 16 17[numthreads(1, 1, 1)] 18void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 19{ 20 // Simple gather test - sample at center of 2x2 region 21 // This should gather from texels (0,0), (1,0), (0,1), (1,1) 22 float2 coords = float2(0.75, 0.75); // Between texels for gather 23 24 // Test basic gather - should return 4 values in specific order 25 float4 gathered = testTexture.GatherRed(samplerState, coords); 26 27 // Store the gathered values 28 outputBuffer[0] = gathered.x; // Should be consistent pattern 29 outputBuffer[1] = gathered.y; 30 outputBuffer[2] = gathered.z; 31 outputBuffer[3] = gathered.w; 32 33 // Also test that gather actually works by using texture coordinates 34 // as the texture values (coord-based pattern) 35 int2 texelCoord = int2(dispatchThreadID.xy); 36 float coordValue = float(texelCoord.x + texelCoord.y * 4); // Create pattern: 0,1,2,3,4,5,6,7... 37 38 // Store marker value like CUDA reference (42) 39 outputBuffer[4] = 42.0; // Marker to verify test is working 40 41 // Test another gather position 42 float4 gathered2 = testTexture.GatherRed(samplerState, float2(1.25, 1.25)); 43 outputBuffer[5] = gathered2.x; 44 outputBuffer[6] = gathered2.y; 45 outputBuffer[7] = gathered2.z; 46 outputBuffer[8] = gathered2.w; 47} 48 49// Test results - texture filled with 1.0 values 50// CHECK: 1.0 51// CHECK-NEXT: 1.0 52// CHECK-NEXT: 1.0 53// CHECK-NEXT: 1.0 54// CHECK-NEXT: 42.0 55// CHECK-NEXT: 1.0 56// CHECK-NEXT: 1.0 57// CHECK-NEXT: 1.0 58// CHECK-NEXT: 1.0