|
| 1 | +#--- source.hlsl |
| 2 | +[[vk::binding(0, 0)]] vk::SampledTexture2D<float4> SampledTexClamp : register(s0); |
| 3 | +[[vk::binding(1, 0)]] vk::SampledTexture2D<float4> SampledTexRepeat : register(s1); |
| 4 | +[[vk::binding(2, 0)]] RWBuffer<float4> Out : register(u0); |
| 5 | + |
| 6 | +[numthreads(1, 1, 1)] |
| 7 | +void main() { |
| 8 | + // Gather at (0.5, 0.5) on a 2x2 texture. |
| 9 | + // Texels used: (0,0), (1,0), (0,1), (1,1). |
| 10 | + // Gather returns a float4 containing the Red component of: |
| 11 | + // [ (0,1), (1,1), (1,0), (0,0) ] |
| 12 | + Out[0] = SampledTexClamp.Gather(float2(0.5, 0.5)); |
| 13 | + |
| 14 | + // Also test GatherRed explicitly (equivalent to Gather) |
| 15 | + Out[1] = SampledTexClamp.GatherRed(float2(0.5, 0.5)); |
| 16 | + |
| 17 | + // Also test GatherGreen |
| 18 | + Out[2] = SampledTexClamp.GatherGreen(float2(0.5, 0.5)); |
| 19 | + |
| 20 | + // Also test GatherBlue |
| 21 | + Out[3] = SampledTexClamp.GatherBlue(float2(0.5, 0.5)); |
| 22 | + |
| 23 | + // Also test GatherAlpha |
| 24 | + Out[4] = SampledTexClamp.GatherAlpha(float2(0.5, 0.5)); |
| 25 | + |
| 26 | + // Test sampler usage for all channels. |
| 27 | + float2 uv_outside = float2(1.5, 1.5); |
| 28 | + |
| 29 | + // Red |
| 30 | + Out[5] = SampledTexClamp.GatherRed(uv_outside); |
| 31 | + Out[6] = SampledTexRepeat.GatherRed(uv_outside); |
| 32 | + |
| 33 | + // Green |
| 34 | + Out[7] = SampledTexClamp.GatherGreen(uv_outside); |
| 35 | + Out[8] = SampledTexRepeat.GatherGreen(uv_outside); |
| 36 | + |
| 37 | + // Blue |
| 38 | + Out[9] = SampledTexClamp.GatherBlue(uv_outside); |
| 39 | + Out[10] = SampledTexRepeat.GatherBlue(uv_outside); |
| 40 | + |
| 41 | + // Alpha |
| 42 | + Out[11] = SampledTexClamp.GatherAlpha(uv_outside); |
| 43 | + Out[12] = SampledTexRepeat.GatherAlpha(uv_outside); |
| 44 | +} |
| 45 | + |
| 46 | +//--- pipeline.yaml |
| 47 | +--- |
| 48 | +Shaders: |
| 49 | + - Stage: Compute |
| 50 | + Entry: main |
| 51 | + DispatchSize: [1, 1, 1] |
| 52 | + |
| 53 | +Buffers: |
| 54 | + - Name: SampledTexClamp |
| 55 | + Format: Float32 |
| 56 | + Channels: 4 |
| 57 | + OutputProps: { Width: 2, Height: 2, Depth: 1 } |
| 58 | + Data: [ 1.0, 0.0, 0.0, 1.0, # Red (0,0) -> R=1, G=0, B=0, A=1 |
| 59 | + 0.0, 1.0, 0.0, 1.0, # Green (1,0) -> R=0, G=1, B=0, A=1 |
| 60 | + 0.0, 0.0, 1.0, 1.0, # Blue (0,1) -> R=0, G=0, B=1, A=1 |
| 61 | + 1.0, 1.0, 1.0, 0.5 ] # White (1,1) -> R=1, G=1, B=1, A=0.5 |
| 62 | + |
| 63 | + - Name: SampledTexRepeat |
| 64 | + Format: Float32 |
| 65 | + Channels: 4 |
| 66 | + OutputProps: { Width: 2, Height: 2, Depth: 1 } |
| 67 | + Data: [ 1.0, 0.0, 0.0, 1.0, # Red (0,0) -> R=1, G=0, B=0, A=1 |
| 68 | + 0.0, 1.0, 0.0, 1.0, # Green (1,0) -> R=0, G=1, B=0, A=1 |
| 69 | + 0.0, 0.0, 1.0, 1.0, # Blue (0,1) -> R=0, G=0, B=1, A=1 |
| 70 | + 1.0, 1.0, 1.0, 0.5 ] # White (1,1) -> R=1, G=1, B=1, A=0.5 |
| 71 | + |
| 72 | + - Name: Out |
| 73 | + Format: Float32 |
| 74 | + Channels: 4 |
| 75 | + FillSize: 208 # 13 * sizeof(float4) |
| 76 | + |
| 77 | + - Name: Expected |
| 78 | + Format: Float32 |
| 79 | + Channels: 4 |
| 80 | + Data: [ 0.0, 1.0, 0.0, 1.0, # 0: Gather (Red) (0.5, 0.5) |
| 81 | + 0.0, 1.0, 0.0, 1.0, # 1: GatherRed (0.5, 0.5) |
| 82 | + 0.0, 1.0, 1.0, 0.0, # 2: GatherGreen (0.5, 0.5) |
| 83 | + 1.0, 1.0, 0.0, 0.0, # 3: GatherBlue (0.5, 0.5) |
| 84 | + 1.0, 0.5, 1.0, 1.0, # 4: GatherAlpha (0.5, 0.5) |
| 85 | + 1.0, 1.0, 1.0, 1.0, # 5: Red Clamp (1.5, 1.5) -> (1,1) everywhere |
| 86 | + 0.0, 1.0, 0.0, 1.0, # 6: Red Repeat (1.5, 1.5) -> same as (0.5, 0.5) |
| 87 | + 1.0, 1.0, 1.0, 1.0, # 7: Green Clamp (1.5, 1.5) |
| 88 | + 0.0, 1.0, 1.0, 0.0, # 8: Green Repeat (1.5, 1.5) |
| 89 | + 1.0, 1.0, 1.0, 1.0, # 9: Blue Clamp (1.5, 1.5) |
| 90 | + 1.0, 1.0, 0.0, 0.0, # 10: Blue Repeat (1.5, 1.5) |
| 91 | + 0.5, 0.5, 0.5, 0.5, # 11: Alpha Clamp (1.5, 1.5) |
| 92 | + 1.0, 0.5, 1.0, 1.0 ] # 12: Alpha Repeat (1.5, 1.5) |
| 93 | + |
| 94 | +Samplers: |
| 95 | + - Name: SampledTexClamp |
| 96 | + MinFilter: Linear |
| 97 | + MagFilter: Linear |
| 98 | + Address: Clamp |
| 99 | + - Name: SampledTexRepeat |
| 100 | + Address: Repeat |
| 101 | + |
| 102 | +DescriptorSets: |
| 103 | + - Resources: |
| 104 | + - Name: SampledTexClamp |
| 105 | + Kind: SampledTexture2D |
| 106 | + DirectXBinding: { Register: 0, Space: 0 } |
| 107 | + VulkanBinding: { Binding: 0 } |
| 108 | + - Name: SampledTexRepeat |
| 109 | + Kind: SampledTexture2D |
| 110 | + DirectXBinding: { Register: 1, Space: 0 } |
| 111 | + VulkanBinding: { Binding: 1 } |
| 112 | + - Name: Out |
| 113 | + Kind: RWBuffer |
| 114 | + DirectXBinding: { Register: 0, Space: 0 } |
| 115 | + VulkanBinding: { Binding: 2 } |
| 116 | + |
| 117 | +Results: |
| 118 | + - Result: GatherTest |
| 119 | + Rule: BufferExact |
| 120 | + Actual: Out |
| 121 | + Expected: Expected |
| 122 | +... |
| 123 | +#--- end |
| 124 | + |
| 125 | +# Unimplemented: This is a Vulkan specific feature. |
| 126 | +# UNSUPPORTED: !Vulkan |
| 127 | + |
| 128 | +# Unimplemented: https://github.com/llvm/llvm-project/issues/181910 |
| 129 | +# XFAIL: Clang && Vulkan |
| 130 | + |
| 131 | +# RUN: split-file %s %t |
| 132 | +# RUN: %dxc_target -T cs_6_0 -Fo %t.o %t/source.hlsl |
| 133 | +# RUN: %offloader %t/pipeline.yaml %t.o |
0 commit comments