Skip to content

Commit 89a9082

Browse files
authored
[RootSignature] Add StaticSampler testing (#367)
This pr adds testing for using a `StaticSampler` to describe a `Sampler` resource. It checks both default and specified parameters are generated correctly. Resolves #261.
1 parent c2261a9 commit 89a9082

File tree

2 files changed

+227
-0
lines changed

2 files changed

+227
-0
lines changed
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
#--- source.hlsl
2+
3+
Texture2D<float4> In : register(t0);
4+
5+
SamplerState DefaultSampler: register(s0);
6+
SamplerState SpecifiedSampler: register(s1);
7+
8+
RWTexture2D<float4> DefaultOut : register(u1);
9+
RWTexture2D<float4> SpecifiedOut : register(u2);
10+
11+
#define RootSig \
12+
"DescriptorTable( " \
13+
" SRV(t0), " \
14+
" UAV(u1, numDescriptors = 2) " \
15+
"), " \
16+
"StaticSampler(s0), " \
17+
"StaticSampler(s1, " \
18+
" mipLODBias = -15.99, " \
19+
" minLOD = 32.0, " \
20+
" maxLOD = 32.0, " \
21+
" addressV = TEXTURE_ADDRESS_MIRROR, " \
22+
" filter = FILTER_MAXIMUM_MIN_MAG_MIP_POINT " \
23+
")"
24+
25+
[RootSignature(RootSig)]
26+
[numthreads(4,1,1)]
27+
void main(uint GI : SV_GroupIndex) {
28+
uint Width, Height;
29+
uint2 GID = {GI / 2, GI % 2};
30+
float2 UV = GID;
31+
float4 DefaultColor = In.Sample(DefaultSampler, UV);
32+
DefaultOut[GID.xy] = DefaultColor.bgra;
33+
34+
float4 SpecifiedColor = In.Sample(SpecifiedSampler, UV);
35+
SpecifiedOut[GID.xy] = SpecifiedColor.bgra;
36+
}
37+
38+
//--- pipeline.yaml
39+
---
40+
Shaders:
41+
- Stage: Compute
42+
Entry: main
43+
DispatchSize: [1, 1, 1]
44+
Buffers:
45+
- Name: In
46+
Format: Float32
47+
Channels: 4
48+
Data: [1.0, 0.0, 0.0, 1.0,
49+
0.0, 1.0, 0.0, 1.0,
50+
0.0, 0.0, 1.0, 1.0,
51+
1.0, 1.0, 0.0, 1.0]
52+
OutputProps:
53+
Height: 2
54+
Width: 2
55+
Depth: 16
56+
- Name: DefaultOut
57+
Format: Float32
58+
Channels: 4
59+
ZeroInitSize: 64
60+
OutputProps:
61+
Height: 2
62+
Width: 2
63+
Depth: 16
64+
- Name: SpecifiedOut
65+
Format: Float32
66+
Channels: 4
67+
ZeroInitSize: 64
68+
OutputProps:
69+
Height: 2
70+
Width: 2
71+
Depth: 16
72+
- Name: ExpectedDefaultOut
73+
Format: Float32
74+
Channels: 4
75+
Data: [0.25, 0.5, 0.5, 1,
76+
0.25, 0.5, 0.5, 1,
77+
0.25, 0.5, 0.5,
78+
1, 0.25, 0.5, 0.5, 1]
79+
OutputProps:
80+
Height: 2
81+
Width: 2
82+
Depth: 16
83+
## Modifying the LOD parameters does not affect the output. However,
84+
## the applied filter will output [0, 0, 1, 1, ... 0, 0, 1, 1] and then
85+
## setting addressV to mirror outputs [0, 0, 1, 1, ..., 1, 0, 0, 1] as shown
86+
## below
87+
- Name: ExpectedSpecifiedOut
88+
Format: Float32
89+
Channels: 4
90+
Data: [0, 0, 1, 1,
91+
0, 0, 1, 1,
92+
1, 0, 0, 1,
93+
1, 0, 0, 1 ]
94+
OutputProps:
95+
Height: 2
96+
Width: 2
97+
Depth: 16
98+
Results:
99+
- Result: DefaultTest
100+
Rule: BufferExact
101+
Actual: DefaultOut
102+
Expected: ExpectedDefaultOut
103+
- Result: SpecifiedTest
104+
Rule: BufferExact
105+
Actual: SpecifiedOut
106+
Expected: ExpectedSpecifiedOut
107+
DescriptorSets:
108+
- Resources:
109+
- Name: In
110+
Kind: Texture2D
111+
DirectXBinding:
112+
Register: 0
113+
Space: 0
114+
VulkanBinding:
115+
Binding: 0
116+
- Name: DefaultOut
117+
Kind: RWTexture2D
118+
DirectXBinding:
119+
Register: 1
120+
Space: 0
121+
VulkanBinding:
122+
Binding: 1
123+
- Name: SpecifiedOut
124+
Kind: RWTexture2D
125+
DirectXBinding:
126+
Register: 2
127+
Space: 0
128+
VulkanBinding:
129+
Binding: 2
130+
...
131+
#--- end
132+
133+
# Unsupported: https://github.com/llvm/llvm-project/issues/101558
134+
# XFAIL: Clang
135+
136+
# REQUIRES: DerivativesInCompute
137+
138+
# RUN: split-file %s %t
139+
# RUN: %dxc_target -T cs_6_6 -Fo %t.o %t/source.hlsl
140+
# RUN: %offloader %t/pipeline.yaml %t.o
141+
# RUN: obj2yaml %t.o | FileCheck %s --check-prefix=OBJ
142+
143+
## Root Signature Header
144+
# OBJ: - Name: RTS0
145+
# OBJ-NEXT: Size: 196
146+
# OBJ-NEXT: RootSignature:
147+
# OBJ-NEXT: Version: 2
148+
# OBJ-NEXT: NumRootParameters: 1
149+
# OBJ-NEXT: RootParametersOffset: 24
150+
# OBJ-NEXT: NumStaticSamplers: 2
151+
# OBJ-NEXT: StaticSamplersOffset: 92
152+
# OBJ-NEXT: Parameters:
153+
154+
## Descriptor Table
155+
# OBJ: - ParameterType: 0
156+
# OBJ-NEXT: ShaderVisibility: 0
157+
# OBJ-NEXT: Table:
158+
# OBJ-NEXT: NumRanges: 2
159+
# OBJ-NEXT: RangesOffset: 44
160+
# OBJ-NEXT: Ranges:
161+
162+
## SRV(t0)
163+
# OBJ: - RangeType: 0
164+
# OBJ-NEXT: NumDescriptors: 1
165+
# OBJ-NEXT: BaseShaderRegister: 0
166+
# OBJ-NEXT: RegisterSpace: 0
167+
# OBJ-NEXT: OffsetInDescriptorsFromTableStart: 4294967295
168+
169+
## UAV(u1, numDescriptors = 2)
170+
# OBJ-NEXT: - RangeType: 1
171+
# OBJ-NEXT: NumDescriptors: 2
172+
# OBJ-NEXT: BaseShaderRegister: 1
173+
# OBJ-NEXT: RegisterSpace: 0
174+
# OBJ-NEXT: OffsetInDescriptorsFromTableStart: 4294967295
175+
176+
# OBJ: Samplers:
177+
178+
## StaticSampler(s0)
179+
## Ensures the defaults are set as expected
180+
# OBJ-NEXT: - Filter: 85
181+
# OBJ-NEXT: AddressU: 1
182+
# OBJ-NEXT: AddressV: 1
183+
# OBJ-NEXT: AddressW: 1
184+
# OBJ-NEXT: MipLODBias: 0
185+
# OBJ-NEXT: MaxAnisotropy: 16
186+
# OBJ-NEXT: ComparisonFunc: 4
187+
# OBJ-NEXT: BorderColor: 2
188+
# OBJ-NEXT: MinLOD: 0
189+
# OBJ-NEXT: MaxLOD: 3.40282e+38
190+
# OBJ-NEXT: ShaderRegister: 0
191+
# OBJ-NEXT: RegisterSpace: 0
192+
# OBJ-NEXT: ShaderVisibility: 0
193+
194+
## StaticSampler(s1,
195+
## mipLODBias = -15.99,
196+
## minLOD = 32.0,
197+
## maxLOD = 32.0,
198+
## addressV = TEXTURE_ADDRESS_MIRROR,
199+
## filter = FILTER_MAXIMUM_MIN_MAG_MIP_POINT
200+
## )
201+
## Ensures the specified values are set as expected
202+
# OBJ: - Filter: 384
203+
# OBJ-NEXT: AddressU: 1
204+
# OBJ-NEXT: AddressV: 2
205+
# OBJ-NEXT: AddressW: 1
206+
# OBJ-NEXT: MipLODBias: -15.99
207+
# OBJ-NEXT: MaxAnisotropy: 16
208+
# OBJ-NEXT: ComparisonFunc: 4
209+
# OBJ-NEXT: BorderColor: 2
210+
# OBJ-NEXT: MinLOD: 32
211+
# OBJ-NEXT: MaxLOD: 32
212+
# OBJ-NEXT: ShaderRegister: 1
213+
# OBJ-NEXT: RegisterSpace: 0
214+
# OBJ-NEXT: ShaderVisibility: 0

test/lit.cfg.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
]
4949

5050

51+
def getHighestShaderModel(features):
52+
if features == None:
53+
return 6, 0
54+
sm = features.get("HighestShaderModel", 6.0)
55+
major, minor = str(sm).split(".")
56+
return int(major), int(minor)
57+
58+
5159
def setDeviceFeatures(config, device, compiler):
5260
API = device["API"]
5361
config.available_features.add(API)
@@ -74,6 +82,11 @@ def setDeviceFeatures(config, device, compiler):
7482

7583
config.available_features.add("%s-%s" % (compiler, API))
7684

85+
HighestShaderModel = getHighestShaderModel(device["Features"])
86+
if (6, 6) <= HighestShaderModel:
87+
# https://github.com/microsoft/DirectX-Specs/blob/master/d3d/HLSL_ShaderModel6_6.md#derivatives
88+
config.available_features.add("DerivativesInCompute")
89+
7790
if device["API"] == "DirectX":
7891
if device["Features"].get("Native16BitShaderOpsSupported", False):
7992
config.available_features.add("Int16")

0 commit comments

Comments
 (0)