108
108
#endif
109
109
"""
110
110
111
- def gen (grammer_path , output_path ):
112
- grammer_raw = open (grammer_path , "r" ).read ()
113
- grammer = json .loads (grammer_raw )
114
- del grammer_raw
115
-
111
+ def gen (core_grammer , glsl_grammer , output_path ):
116
112
output = open (output_path , "w" , buffering = 1024 ** 2 )
117
113
118
- builtins = [x for x in grammer ["operand_kinds" ] if x ["kind" ] == "BuiltIn" ][0 ]["enumerants" ]
119
- execution_modes = [x for x in grammer ["operand_kinds" ] if x ["kind" ] == "ExecutionMode" ][0 ]["enumerants" ]
120
- group_operations = [x for x in grammer ["operand_kinds" ] if x ["kind" ] == "GroupOperation" ][0 ]["enumerants" ]
114
+ builtins = [x for x in core_grammer ["operand_kinds" ] if x ["kind" ] == "BuiltIn" ][0 ]["enumerants" ]
115
+ execution_modes = [x for x in core_grammer ["operand_kinds" ] if x ["kind" ] == "ExecutionMode" ][0 ]["enumerants" ]
116
+ group_operations = [x for x in core_grammer ["operand_kinds" ] if x ["kind" ] == "GroupOperation" ][0 ]["enumerants" ]
121
117
122
118
with output as writer :
123
119
writer .write (head )
@@ -194,7 +190,7 @@ def gen(grammer_path, output_path):
194
190
writer .write ("}\n " )
195
191
196
192
writer .write ("\n //! Instructions\n " )
197
- for instruction in grammer ["instructions" ]:
193
+ for instruction in core_grammer ["instructions" ]:
198
194
if instruction ["opname" ].endswith ("INTEL" ): continue
199
195
200
196
match instruction ["class" ]:
@@ -219,6 +215,9 @@ def gen(grammer_path, output_path):
219
215
processInst (writer , instruction , result_ty = "uint32_t" ,prefered_op_ty = "uint32_t4" )
220
216
case _: processInst (writer , instruction )
221
217
case _: continue # TODO
218
+ for instruction in glsl_grammer ["instructions" ]:
219
+ instruction ["operands" ] = [{"kind" : "IdResultType" }] + instruction ["operands" ]
220
+ processInst (writer , instruction )
222
221
223
222
writer .write (foot )
224
223
@@ -266,7 +265,7 @@ def processInst(writer: io.TextIOWrapper,
266
265
conds .append ("(is_same_v<float16_t, T> || is_same_v<float32_t, T> || is_same_v<float64_t, T>)" )
267
266
break
268
267
else :
269
- if instruction ["class" ] == "Bit" :
268
+ if "class" in instruction and instruction ["class" ] == "Bit" :
270
269
conds .append ("(is_signed_v<T> || is_unsigned_v<T>)" )
271
270
272
271
if "operands" in instruction and instruction ["operands" ][0 ]["kind" ] == "IdResultType" :
@@ -321,7 +320,11 @@ def processInst(writer: io.TextIOWrapper,
321
320
if (not "typename T" in final_templates ) and (result_ty == "T" or op_ty == "T" ):
322
321
final_templates = ["typename T" ] + final_templates
323
322
args .append ("[[vk::ext_reference]] " + op_ty + " " + operand_name )
324
- case "'Value'" | "'Object'" | "'Comparator'" | "'Base'" | "'Insert'" :
323
+ case ("'a'" | "'b'" | "'c'" | "'x'" | "'y'" | "'z'" | "'i'" | "'v'" |
324
+ "'p'" | "'p0'" | "'p1'" | "'exp'" | "'minVal'" | "'maxVal'" | "'y_over_x'" |
325
+ "'edge'" | "'edge0'" | "'edge1'" | "'I'" | "'N'" | "'eta'" | "'sample'" |
326
+ "'degrees'" | "'radians'" | "'Nref'" | "'interpolant'" | "'offset'" |
327
+ "'Value'" | "'Object'" | "'Comparator'" | "'Base'" | "'Insert'" ):
325
328
if (not "typename T" in final_templates ) and (result_ty == "T" or op_ty == "T" ):
326
329
final_templates = ["typename T" ] + final_templates
327
330
args .append (op_ty + " " + operand_name )
@@ -366,8 +369,21 @@ def ignore(op_name):
366
369
367
370
parser = ArgumentParser (description = "Generate HLSL from SPIR-V instructions" )
368
371
parser .add_argument ("output" , type = str , help = "HLSL output file" )
369
- parser .add_argument ("--grammer" , required = False , type = str , help = "Input SPIR-V grammer JSON file" , default = os .path .join (script_dir_path , "../../include/spirv/unified1/spirv.core.grammar.json" ))
372
+ parser .add_argument ("--core-grammer" , required = False , type = str ,
373
+ help = "SPIR-V Core grammer JSON file" ,
374
+ default = os .path .join (script_dir_path , "../../include/spirv/unified1/spirv.core.grammar.json" ))
375
+ parser .add_argument ("--glsl-grammer" , required = False , type = str ,
376
+ help = "SPIR-V Extended GLSL.std.450 grammer JSON file" ,
377
+ default = os .path .join (script_dir_path , "../../include/spirv/unified1/extinst.glsl.std.450.grammar.json" ))
370
378
args = parser .parse_args ()
371
379
372
- gen (args .grammer , args .output )
380
+ grammer_raw = open (args .core_grammer , "r" ).read ()
381
+ core_grammer = json .loads (grammer_raw )
382
+ del grammer_raw
383
+
384
+ grammer_raw = open (args .glsl_grammer , "r" ).read ()
385
+ glsl_grammer = json .loads (grammer_raw )
386
+ del grammer_raw
387
+
388
+ gen (core_grammer , glsl_grammer , args .output )
373
389
0 commit comments