Skip to content

Commit 7bc29c0

Browse files
authored
Port remaining SampledTexture2D tests (#1075)
Part of microsoft/DirectXShaderCompiler#7979 The tests are originally from `Texture2D`. Verified every test ported for `SampledTexture2D`
1 parent 757cf5b commit 7bc29c0

13 files changed

Lines changed: 1632 additions & 0 deletions
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#--- source.hlsl
2+
struct VSInput {
3+
float3 Pos : POSITION;
4+
};
5+
6+
struct VSOutput {
7+
float4 Pos : SV_POSITION;
8+
};
9+
10+
VSOutput mainVS(VSInput input) {
11+
VSOutput output;
12+
output.Pos = float4(input.Pos, 1.0f);
13+
return output;
14+
}
15+
16+
[[vk::binding(0, 0)]] vk::SampledTexture2D<float4> SampledTex : register(s0);
17+
[[vk::binding(1, 0)]] RWBuffer<float> Out : register(u0);
18+
19+
float4 mainPS(VSOutput input) : SV_Target {
20+
// Use SV_Position (pixel coordinates) to simulate the grid logic.
21+
// Input position is [-1, 1], mapped to viewport 2x2.
22+
// Pixel centers will be at (0.5, 0.5), (1.5, 0.5), etc.
23+
uint2 GTid = (uint2)input.Pos.xy;
24+
25+
// Case 1: Derivative = 0.5. Texture Size = 4.
26+
// LOD = log2(0.5 * 4) = 1.0
27+
float2 uv0 = 0.25 + float2(GTid.xy) * 0.5;
28+
29+
// Case 2: Derivative = 2.0. Texture Size = 4.
30+
// LOD = log2(2.0 * 4) = 3.0.
31+
// Note: Since the texture has 3 mip levels (0, 1, 2),
32+
// the clamped LOD will be 2.0.
33+
float2 uv1 = 0.25 + float2(GTid.xy) * 2.0;
34+
35+
float lod0 = SampledTex.CalculateLevelOfDetail(uv0);
36+
float lod1 = SampledTex.CalculateLevelOfDetail(uv1);
37+
float lod2 = SampledTex.CalculateLevelOfDetailUnclamped(uv0);
38+
float lod3 = SampledTex.CalculateLevelOfDetailUnclamped(uv1);
39+
40+
if (all(GTid.xy == 0)) {
41+
Out[0] = lod0;
42+
Out[1] = lod1;
43+
Out[2] = lod2;
44+
Out[3] = lod3;
45+
}
46+
return float4(0, 0, 0, 0);
47+
}
48+
49+
//--- pipeline.yaml
50+
---
51+
Shaders:
52+
- Stage: Vertex
53+
Entry: mainVS
54+
- Stage: Pixel
55+
Entry: mainPS
56+
57+
Buffers:
58+
- Name: SampledTex
59+
Format: Float32
60+
Channels: 4
61+
OutputProps: { Width: 4, Height: 4, Depth: 1, MipLevels: 3 }
62+
FillSize: 336 # (16+4+1)*16
63+
64+
- Name: Out
65+
Format: Float32
66+
Channels: 1
67+
FillSize: 16 # 4 * sizeof(float)
68+
69+
- Name: Expected
70+
Format: Float32
71+
Channels: 1
72+
Data: [ 1.0, 2.0, 1.0, 3.0 ]
73+
74+
- Name: RT
75+
Format: Float32
76+
Channels: 4
77+
FillSize: 64
78+
OutputProps: { Width: 2, Height: 2, Depth: 1 }
79+
80+
- Name: VB
81+
Format: Float32
82+
Channels: 3
83+
Data: [-1.0, -1.0, 0.0,
84+
3.0, -1.0, 0.0,
85+
-1.0, 3.0, 0.0]
86+
87+
Bindings:
88+
VertexBuffer: VB
89+
VertexAttributes:
90+
- Format: Float32
91+
Channels: 3
92+
Offset: 0
93+
Name: POSITION
94+
RenderTarget: RT
95+
96+
Samplers:
97+
- Name: SampledTex
98+
MinFilter: Linear
99+
MagFilter: Linear
100+
Address: Clamp
101+
102+
DescriptorSets:
103+
- Resources:
104+
- Name: SampledTex
105+
Kind: SampledTexture2D
106+
DirectXBinding: { Register: 0, Space: 0 }
107+
VulkanBinding: { Binding: 0 }
108+
- Name: Out
109+
Kind: RWBuffer
110+
DirectXBinding: { Register: 0, Space: 0 }
111+
VulkanBinding: { Binding: 1 }
112+
113+
Results:
114+
- Result: LODTest
115+
Rule: BufferFloatULP
116+
Actual: Out
117+
Expected: Expected
118+
ULPT: 1
119+
...
120+
#--- end
121+
122+
# Unimplemented: This is a Vulkan specific feature.
123+
# UNSUPPORTED: !Vulkan
124+
125+
# Unimplemented: https://github.com/llvm/llvm-project/issues/181910
126+
# XFAIL: Clang && Vulkan
127+
128+
# RUN: split-file %s %t
129+
# RUN: %dxc_target -T vs_6_6 -E mainVS -Fo %t-vs.o %t/source.hlsl
130+
# RUN: %dxc_target -T ps_6_6 -E mainPS -Fo %t-ps.o %t/source.hlsl
131+
# RUN: %offloader %t/pipeline.yaml %t-vs.o %t-ps.o
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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

Comments
 (0)