forked from microsoft/DirectXShaderCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhcttest-system-values.py
311 lines (286 loc) · 10.8 KB
/
hcttest-system-values.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# Copyright (C) Microsoft Corporation. All rights reserved.
# This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details.
"""hcttest-system-values.py - Test all system values with each signature point through fxc.
Builds csv tables for the results for each shader model from 4.0 through 5.1.
"""
import re
SignaturePoints = [
# sig point, stage, tessfactors already present
('VSIn', 'vs', False),
('VSOut', 'vs', False),
('PCIn', 'hs', False),
('HSIn', 'hs', False),
('HSCPIn', 'hs', False),
('HSCPOut', 'hs', False),
('PCOut', 'hs', True ),
('DSIn', 'ds', True ),
('DSCPIn', 'ds', False),
('DSOut', 'ds', False),
('GSVIn', 'gs', False),
('GSIn', 'gs', False),
('GSOut', 'gs', False),
('PSIn', 'ps', False),
('PSOut', 'ps', False),
('CSIn', 'cs', False),
]
SysValues = """
VertexID
InstanceID
Position
RenderTargetArrayIndex
ViewportArrayIndex
ClipDistance
CullDistance
OutputControlPointID
DomainLocation
PrimitiveID
GSInstanceID
SampleIndex
IsFrontFace
Coverage
InnerCoverage
Target
Depth
DepthLessEqual
DepthGreaterEqual
StencilRef
DispatchThreadID
GroupID
GroupIndex
GroupThreadID
TessFactor
InsideTessFactor
""".split()
def run(cmd, output_filename=None):
import os
print(cmd)
if output_filename:
if os.path.isfile(output_filename):
os.unlink(output_filename)
with file(output_filename, 'wt') as f:
f.write('%s\n\n' % cmd)
ret = os.system(cmd + ' >> "%s" 2>&1' % output_filename)
output = ''
if os.path.isfile(output_filename):
with open(output_filename, 'rt') as f:
output = f.read()
return ret, output
else:
ret = os.system(cmd)
return ret, None
sig_examples = """
// Patch Constant signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// Arb 0 x 0 NONE float x
// SV_TessFactor 0 x 1 QUADEDGE float x
// SV_TessFactor 1 x 2 QUADEDGE float x
// SV_TessFactor 2 x 3 QUADEDGE float x
// SV_TessFactor 3 x 4 QUADEDGE float x
// SV_InsideTessFactor 0 x 5 QUADINT float x
// SV_InsideTessFactor 1 x 6 QUADINT float x
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// Arb 0 x 0 NONE float
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// Arb 0 x 0 NONE float x
"""
rxSigBegin = re.compile(r'^// (Input|Output|Patch Constant) signature:\s*$')
rxSigElementsBegin = re.compile(r'^// -------------------- ----- ------ -------- -------- ------- ------\s*$')
# // SV_Target 1 xyzw 1 TARGET float xyzw
rxSigElement = re.compile(r'^// ([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s*([^\s]+)?\s*$')
# Name, Index, Mask, Register, SysValue, Format, Used = m.groups()
# For now, ParseSigs just looks for a matching semantic name and reports whether it uses
# a separate register (unpacked) and whether it's treated as arbitrary.
def ParseSigs(text, semantic):
"return separate_reg, as_arb for matching semantic"
it = iter(text.splitlines())
sigtype = None
try:
while True:
line = it.next()
m = rxSigBegin.match(line)
if m:
sigtype = m.group(1)
continue
m = rxSigElementsBegin.match(line)
if m:
while True:
line = it.next()
m = rxSigElement.match(line)
if m:
Name, Index, Mask, Register, SysValue, Format, Used = m.groups()
if Name.lower() == semantic.lower():
try:
regnum = int(Register)
reg = False
except:
reg = True
arb = SysValue == 'NONE'
return reg, arb
except StopIteration:
pass
return None
# Internal error or validation error:
rxInternalError = re.compile(r"^(internal error:.*|error X8000:.*)$")
# error X4502: invalid ps input semantic 'Foo'
# error X4502: SV_Coverage input not supported on ps_4_0
# error X4502: SV_SampleIndex isn't supported on ps_4_0
# error X3514: SV_GSInstanceID is an invalid input semantic for geometry shader primitives, it must be its own parameter.
# error X3514: 'GSMain': input parameter 'tfactor' must have a geometry specifier
# also errors for unsupported shader models
# error X3660: cs_4_0 does not support interlocked operations
rxSemanticErrors = [
re.compile(r".*?\.hlsl.*?: error X4502: invalid .*? semantic '(\w+)'"),
re.compile(r".*?\.hlsl.*?: error X4502: (\w+) .*? supported on \w+"),
re.compile(r".*?\.hlsl.*?: error X3514: (\w+) is an invalid input semantic for geometry shader primitives, it must be its own parameter\."),
re.compile(r".*?\.hlsl.*?: error X3514: 'GSMain': input parameter '\w+' must have a geometry specifier"),
]
def map_gen(fn, *sequences):
"generator style map"
iters = map(iter, sequences)
while True:
yield fn(*map(next, iters))
def firstTrue(iterable):
"returns first non-False element, or None."
for it in iterable:
if it:
return it
def ParseSVError(text, semantic):
"return true if error is about illegal use of matching semantic"
for line in text.splitlines():
m = firstTrue(map_gen(lambda rx: rx.match(line), rxSemanticErrors))
if m:
if len(m.groups()) < 1 or m.group(1).lower() == semantic.lower():
return True
else:
m = rxInternalError.match(line)
if m:
print('#### Internal error detected!')
print(m.group(1))
return 'InternalError'
return False
# TODO: Fill in the correct error pattern
# error X4576: Non system-generated input signature parameter (Arb) cannot appear after a system generated value.
rxMustBeLastError = re.compile(r".*?\.hlsl.*?: error X4576: Non system-generated input signature parameter \(\w+\) cannot appear after a system generated value.")
def ParseSGVError(text, semantic):
"return true if error is about matching semantic having to be declared last"
for line in text.splitlines():
m = rxMustBeLastError.match(line)
if m:
return True
else:
m = rxInternalError.match(line)
if m:
print('#### Internal error detected!')
print(m.group(1))
return 'InternalError'
return False
hlsl_filename = os.abspath(os.path.join()
os.environ['HLSL_SRC_DIR'],
r'tools\clang\test\HLSL',
'system-values.hlsl'))
def main():
do('5_1')
do('5_0')
do('4_1')
do('4_0')
def do(sm):
import os, sys
# set up table:
table = [[None] * len(SignaturePoints) for sv in SysValues]
null_filename = 'output\\test_sv_null.txt'
for col, (sigpoint, stage, tfpresent) in enumerate(SignaturePoints):
entry = stage.upper() + 'Main'
target = stage + '_%s' % sm
# test arb support:
ret, output = run('fxc %s /E %s /T %s /D%s_Defs=Def_Arb(float,Arb1,Arb1)' %
(hlsl_filename, entry, target, sigpoint),
null_filename)
arb_supported = ret == 0
# iterate all system values
sysvalues = tfpresent and SysValues[:-2] or SysValues
for row, sv in enumerate(sysvalues):
output_filename = 'output\\test_sv_output_%s_%s_%s.txt' % (sm, sv, sigpoint)
separate_reg, as_arb, def_last, result = False, False, False, 'NotInSig'
ret, output = run('fxc %s /E %s /T %s /D%s_Defs=Def_%s' %
(hlsl_filename, entry, target, sigpoint, sv),
output_filename)
if ret:
# Failed, look for expected error message:
found = ParseSVError(output, 'SV_'+sv)
if found == 'InternalError':
table[row][col] = 'InternalError'
print('#### Internal error from ParseSVError - see "%s"' % output_filename)
elif not found:
table[row][col] = 'ParseSVError'
print('#### Error from ParseSVError - see "%s"' % output_filename)
else:
table[row][col] = 'NA'
if os.path.isfile(output_filename):
os.unlink(output_filename)
continue
parse_result = ParseSigs(output, 'SV_'+sv)
if parse_result:
separate_reg, as_arb = parse_result
if as_arb:
if separate_reg:
table[row][col] = 'Error: both as_arb and separate_reg set!'
print('#### Error from ParseSigs, both as_arb and separate_reg set - see "%s"' % output_filename)
continue
result = 'Arb'
else:
if separate_reg:
result = 'NotPacked'
else:
result = 'SV'
if os.path.isfile(output_filename):
os.unlink(output_filename)
else:
print('## Not in signature? See "%s"' % output_filename)
if arb_supported and not as_arb and not separate_reg:
output_filename = 'output\\test_sv_output_last_%s_%s_%s.txt' % (sm, sv, sigpoint)
# must system value be declared last? test by adding arb last if arb support
ret, output = run('fxc %s /E %s /T %s /D%s_Defs="Def_%s Def_Arb(float,Arb1,Arb1)"' %
(hlsl_filename, entry, target, sigpoint, sv),
output_filename)
if ret:
found = ParseSGVError(output, 'SV_'+sv)
if found == 'InternalError':
result += ' | InternalError found with ParseSGVError'
print('#### Internal error from ParseSGVError - see "%s"' % output_filename)
elif not found:
result += ' | ParseSGVError'
print('#### Error from ParseSGVError - see "%s"' % output_filename)
elif result == 'SV':
result = 'SGV'
if os.path.isfile(output_filename):
os.unlink(output_filename)
else:
result += ' | Error: last required detected, but not SV?'
print('#### Error: last required detected, but not SV? - see "%s"' % output_filename)
else:
if os.path.isfile(output_filename):
os.unlink(output_filename)
table[row][col] = result
for row in range(row+1, len(SysValues)):
table[row][col] = 'TessFactor'
def WriteTable(writefn, table):
writefn('Semantic,' + ','.join([sigpoint for sigpoint, stage, tfpresent in SignaturePoints]) + '\n')
for n, row in enumerate(table):
writefn((SysValues[n]) + ','.join(row) + '\n')
WriteTable(sys.stdout.write, table)
with open('fxc_sig_packing_table_%s.csv' % sm, 'wt') as f:
WriteTable(f.write, table)
if __name__ == '__main__':
main()