Skip to content

Commit 62108d3

Browse files
committed
[mlir][dxsa] Add dcl_constant_buffer, dcl_hs_fork_phase_instance_count, dcl_hs_join_phase_instance_count, dcl_hs_max_tessfactor, dcl_index_range, dcl_output_sgv, dcl_output_siv and dcl_tgsm_raw instructions
Example: dxsa.dcl_constant_buffer <type = constant_buffer, components = 4, swizzle = <x, y, z, w>, index = [0, 1]>, <immediateIndexed> dxsa.dcl_hs_fork_phase_instance_count 4 dxsa.dcl_hs_join_phase_instance_count 2 dxsa.dcl_hs_max_tessfactor 6.400000e+01 dxsa.dcl_index_range <type = input, components = 4, mask = <x, y, z, w>, index = [4]>, 6 dxsa.dcl_output_sgv <type = output, components = 4, mask = <x>, index = [0]>, <primitiveID> dxsa.dcl_output_siv <type = output, components = 4, mask = <x, y, z, w>, index = [0]>, <position> dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 1024 Signed-off-by: Vladimir Shiryaev <tagolog@users.noreply.github.com>
1 parent 014c7b3 commit 62108d3

25 files changed

Lines changed: 568 additions & 42 deletions

mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td

Lines changed: 210 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def DXSA_SystemValueName : I32EnumAttr<
252252

253253
def DXSA_SystemValueNameAttr :
254254
EnumAttr<DXSADialect, DXSA_SystemValueName, "system_value_name"> {
255-
let assemblyFormat = "$value";
255+
let assemblyFormat = "`<` $value `>`";
256256
}
257257

258258
//===----------------------------------------------------------------------===//
@@ -281,6 +281,65 @@ def DXSA_ComponentMaskAttr :
281281
let assemblyFormat = "`<` $value `>`";
282282
}
283283

284+
//===----------------------------------------------------------------------===//
285+
// DXSA ComponentName enum (distinct from ComponentMask which is a bit mask)
286+
//===----------------------------------------------------------------------===//
287+
288+
def DXSA_ComponentName_X : I32EnumAttrCase<"x", 0>;
289+
def DXSA_ComponentName_Y : I32EnumAttrCase<"y", 1>;
290+
def DXSA_ComponentName_Z : I32EnumAttrCase<"z", 2>;
291+
def DXSA_ComponentName_W : I32EnumAttrCase<"w", 3>;
292+
293+
def DXSA_ComponentName : I32EnumAttr<
294+
"ComponentName", "single x/y/z/w component", [
295+
DXSA_ComponentName_X,
296+
DXSA_ComponentName_Y,
297+
DXSA_ComponentName_Z,
298+
DXSA_ComponentName_W
299+
]> {
300+
let cppNamespace = "::mlir::dxsa";
301+
let genSpecializedAttr = 0;
302+
}
303+
304+
def DXSA_ComponentNameAttr :
305+
EnumAttr<DXSADialect, DXSA_ComponentName, "component_name"> {
306+
let assemblyFormat = "`<` $value `>`";
307+
}
308+
309+
//===----------------------------------------------------------------------===//
310+
// DXSA ComponentSwizzle attribute — ordered component mapping
311+
// (each component picks one of x/y/z/w from the source, components may repeat)
312+
//===----------------------------------------------------------------------===//
313+
314+
def DXSA_ComponentSwizzleAttr : AttrDef<DXSADialect, "ComponentSwizzle"> {
315+
let mnemonic = "component_swizzle";
316+
let summary = "component swizzle (each component picks one of x, y, z, w)";
317+
let parameters = (ins
318+
EnumParameter<DXSA_ComponentName>:$x,
319+
EnumParameter<DXSA_ComponentName>:$y,
320+
EnumParameter<DXSA_ComponentName>:$z,
321+
EnumParameter<DXSA_ComponentName>:$w);
322+
let assemblyFormat = "`<` $x `,` $y `,` $z `,` $w `>`";
323+
}
324+
325+
def DXSA_ConstantBufferAccessPattern_ImmediateIndexed : I32EnumAttrCase<"immediateIndexed", 0>;
326+
def DXSA_ConstantBufferAccessPattern_DynamicIndexed : I32EnumAttrCase<"dynamicIndexed", 1>;
327+
328+
def DXSA_ConstantBufferAccessPattern : I32EnumAttr<
329+
"ConstantBufferAccessPattern", "constant buffer access pattern", [
330+
DXSA_ConstantBufferAccessPattern_ImmediateIndexed,
331+
DXSA_ConstantBufferAccessPattern_DynamicIndexed
332+
]> {
333+
let cppNamespace = "::mlir::dxsa";
334+
let genSpecializedAttr = 0;
335+
}
336+
337+
def DXSA_ConstantBufferAccessPatternAttr :
338+
EnumAttr<DXSADialect, DXSA_ConstantBufferAccessPattern,
339+
"constant_buffer_access_pattern"> {
340+
let assemblyFormat = "`<` $value `>`";
341+
}
342+
284343
//===----------------------------------------------------------------------===//
285344
// DXSA op definitions
286345
//===----------------------------------------------------------------------===//
@@ -461,27 +520,25 @@ def DXSA_InlineOperandAttr : AttrDef<DXSADialect, "InlineOperand"> {
461520
let mnemonic = "inline_operand";
462521
let summary = "inline operand of an instruction";
463522
let description = [{
464-
The `#dxsa.inline_operand` attribute carries a fully decoded operand token
523+
The `#dxsa.inline_operand` attribute carries a fully decoded operand token.
465524

466-
Example:
525+
Examples:
467526

468527
```mlir
469528
dxsa.dcl_output <type = output, components = 4, mask = <x, y, z, w>, index = [0]>
529+
dxsa.dcl_constant_buffer <type = constant_buffer, components = 4, swizzle = <x, y, z, w>, index = [0, 1]>, <immediateIndexed>
470530
dxsa.dcl_output <type = output_depth, components = 1>
471531
```
472532
}];
473533
let parameters = (ins
474534
EnumParameter<DXSA_InlineOperandType>:$type,
475535
"uint32_t":$components,
476536
OptionalParameter<"::mlir::dxsa::ComponentMaskAttr">:$mask,
537+
OptionalParameter<"::mlir::dxsa::ComponentSwizzleAttr">:$swizzle,
538+
OptionalParameter<"::mlir::dxsa::ComponentNameAttr">:$select,
477539
OptionalParameter<"::mlir::DenseI64ArrayAttr">:$index);
478-
let assemblyFormat = [{
479-
`<` `type` `=` $type
480-
`,` `components` `=` $components
481-
(`,` `mask` `=` $mask^)?
482-
(`,` `index` `=` $index^)?
483-
`>`
484-
}];
540+
let assemblyFormat = "`<` struct(params) `>`";
541+
let genVerifyDecl = 1;
485542
}
486543

487544
def DXSA_DclGlobalFlags : DXSA_Op<"dcl_global_flags"> {
@@ -657,7 +714,7 @@ def DXSA_DclInputPsSiv : DXSA_Op<"dcl_input_ps_siv"> {
657714
Example:
658715

659716
```mlir
660-
dxsa.dcl_input_ps_siv linear %v0, position
717+
dxsa.dcl_input_ps_siv linear %v0, <position>
661718
```
662719
}];
663720
let arguments = (ins DXSA_InterpolationModeAttr:$mode,
@@ -675,7 +732,7 @@ def DXSA_DclInputPsSgv : DXSA_Op<"dcl_input_ps_sgv"> {
675732
Example:
676733

677734
```mlir
678-
dxsa.dcl_input_ps_sgv %v0, sampleIndex
735+
dxsa.dcl_input_ps_sgv %v0, <sampleIndex>
679736
```
680737
}];
681738
let arguments = (ins DXSA_OperandType:$operand,
@@ -719,4 +776,145 @@ def DXSA_DclOutput : DXSA_Op<"dcl_output"> {
719776
let assemblyFormat = "$operand attr-dict";
720777
}
721778

779+
def DXSA_DclOutputSiv : DXSA_Op<"dcl_output_siv"> {
780+
let summary = "declares a shader output carrying a System Interpreted Value";
781+
let description = [{
782+
The `dxsa.dcl_output_siv` operation declares an output register that
783+
represents a System Interpreted Value (e.g. `position`, `clipDistance`).
784+
785+
Example:
786+
787+
```mlir
788+
dxsa.dcl_output_siv <type = output, components = 4, mask = <x, y, z, w>, index = [3]>, <position>
789+
```
790+
}];
791+
let arguments = (ins DXSA_InlineOperandAttr:$operand,
792+
DXSA_SystemValueNameAttr:$name);
793+
let assemblyFormat = "$operand `,` $name attr-dict";
794+
}
795+
796+
def DXSA_DclConstantBuffer : DXSA_Op<"dcl_constant_buffer"> {
797+
let summary = "declares a constant buffer";
798+
let description = [{
799+
The `dxsa.dcl_constant_buffer` operation declares a constant buffer
800+
together with its access pattern.
801+
802+
Example:
803+
804+
```mlir
805+
dxsa.dcl_constant_buffer <type = constant_buffer, components = 4, swizzle = <x, y, z, w>, index = [3, 128]>, <dynamicIndexed>
806+
```
807+
}];
808+
let arguments = (ins DXSA_InlineOperandAttr:$operand,
809+
DXSA_ConstantBufferAccessPatternAttr:$access_pattern);
810+
let assemblyFormat = "$operand `,` $access_pattern attr-dict";
811+
}
812+
813+
def DXSA_DclHsMaxTessfactor : DXSA_Op<"dcl_hs_max_tessfactor"> {
814+
let summary = "declares the maximum tessellation factor for a hull shader";
815+
let description = [{
816+
The `dxsa.dcl_hs_max_tessfactor` operation declares the maximum
817+
tessellation factor produced by the hull shader as a 32-bit float.
818+
819+
Example:
820+
821+
```mlir
822+
dxsa.dcl_hs_max_tessfactor 6.400000e+01
823+
```
824+
}];
825+
let arguments = (ins F32Attr:$max_tess_factor);
826+
let assemblyFormat = "$max_tess_factor attr-dict";
827+
let hasVerifier = 1;
828+
}
829+
830+
def DXSA_DclHsForkPhaseInstanceCount :
831+
DXSA_Op<"dcl_hs_fork_phase_instance_count"> {
832+
let summary = "declares the hull shader fork phase instance count";
833+
let description = [{
834+
The `dxsa.dcl_hs_fork_phase_instance_count` operation declares the
835+
number of instances of the current hull shader fork phase program
836+
to execute.
837+
838+
Example:
839+
840+
```mlir
841+
dxsa.dcl_hs_fork_phase_instance_count 4
842+
```
843+
}];
844+
let arguments = (ins ConfinedAttr<I32Attr, [IntPositive]>:$count);
845+
let assemblyFormat = "$count attr-dict";
846+
}
847+
848+
def DXSA_DclHsJoinPhaseInstanceCount :
849+
DXSA_Op<"dcl_hs_join_phase_instance_count"> {
850+
let summary = "declares the hull shader join phase instance count";
851+
let description = [{
852+
The `dxsa.dcl_hs_join_phase_instance_count` operation declares the
853+
number of instances of the current hull shader join phase program
854+
to execute.
855+
856+
Example:
857+
858+
```mlir
859+
dxsa.dcl_hs_join_phase_instance_count 2
860+
```
861+
}];
862+
let arguments = (ins ConfinedAttr<I32Attr, [IntPositive]>:$count);
863+
let assemblyFormat = "$count attr-dict";
864+
}
865+
866+
def DXSA_DclIndexRange : DXSA_Op<"dcl_index_range"> {
867+
let summary = "declares a range of input/output registers to be indexed";
868+
let description = [{
869+
The `dxsa.dcl_index_range` operation declares a range of contiguous
870+
input or output registers that may be referenced by dynamic indexing
871+
in shader code.
872+
873+
Example:
874+
875+
```mlir
876+
dxsa.dcl_index_range <type = input, components = 4, mask = <x, y, z, w>, index = [1]>, 3
877+
```
878+
}];
879+
let arguments = (ins DXSA_InlineOperandAttr:$operand,
880+
ConfinedAttr<I32Attr, [IntPositive]>:$count);
881+
let assemblyFormat = "$operand `,` $count attr-dict";
882+
}
883+
884+
def DXSA_DclTgsmRaw : DXSA_Op<"dcl_tgsm_raw"> {
885+
let summary = "declares raw thread group shared memory";
886+
let description = [{
887+
The `dxsa.dcl_tgsm_raw` operation declares a region of untyped thread
888+
group shared memory of the given byte count.
889+
890+
Example:
891+
892+
```mlir
893+
dxsa.dcl_tgsm_raw <type = thread_group_shared_memory, components = 0, index = [0]>, 1024
894+
```
895+
}];
896+
let arguments = (ins DXSA_InlineOperandAttr:$operand,
897+
ConfinedAttr<I32Attr,
898+
[IntPositive, IntMaxValue<32768>]>:$byte_count);
899+
let assemblyFormat = "$operand `,` $byte_count attr-dict";
900+
let hasVerifier = 1;
901+
}
902+
903+
def DXSA_DclOutputSgv : DXSA_Op<"dcl_output_sgv"> {
904+
let summary = "declares a shader output carrying a System Generated Value";
905+
let description = [{
906+
The `dxsa.dcl_output_sgv` operation declares an output register that
907+
represents a System Generated Value.
908+
909+
Example:
910+
911+
```mlir
912+
dxsa.dcl_output_sgv <type = output, components = 1, mask = <x>, index = [4]>, <primitiveID>
913+
```
914+
}];
915+
let arguments = (ins DXSA_InlineOperandAttr:$operand,
916+
DXSA_SystemValueNameAttr:$name);
917+
let assemblyFormat = "$operand `,` $name attr-dict";
918+
}
919+
722920
#endif // DXSA_OPS

mlir/lib/Dialect/DXSA/IR/DXSA.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,52 @@ void DXSADialect::initialize() {
4141
#define GET_OP_CLASSES
4242
#include "mlir/Dialect/DXSA/IR/DXSAOps.cpp.inc"
4343

44+
//===----------------------------------------------------------------------===//
45+
// Op verifiers
46+
//===----------------------------------------------------------------------===//
47+
48+
LogicalResult DclTgsmRaw::verify() {
49+
auto byteCount = getByteCount();
50+
if (byteCount % 4 != 0)
51+
return emitOpError("byte count must be a multiple of 4, got ") << byteCount;
52+
return success();
53+
}
54+
55+
LogicalResult DclHsMaxTessfactor::verify() {
56+
// Reject NaN, Inf, and anything outside [1.0, 64.0].
57+
auto value = getMaxTessFactorAttr().getValue();
58+
if (!value.isFinite() || value < llvm::APFloat(1.0f) ||
59+
value > llvm::APFloat(64.0f))
60+
return emitOpError("max tessellation factor must be in [1.0, 64.0], got ")
61+
<< value.convertToFloat();
62+
return success();
63+
}
64+
65+
//===----------------------------------------------------------------------===//
66+
// Attribute verifiers
67+
//===----------------------------------------------------------------------===//
68+
69+
LogicalResult
70+
InlineOperandAttr::verify(function_ref<InFlightDiagnostic()> emitError,
71+
::mlir::dxsa::InlineOperandType /*type*/,
72+
uint32_t components,
73+
::mlir::dxsa::ComponentMaskAttr mask,
74+
::mlir::dxsa::ComponentSwizzleAttr swizzle,
75+
::mlir::dxsa::ComponentNameAttr select,
76+
::mlir::DenseI64ArrayAttr /*index*/) {
77+
// mask / swizzle / select are the three mutually-exclusive 4-component
78+
// selection modes. Operands with 0 or 1 components carry none of them.
79+
auto set = (mask ? 1 : 0) + (swizzle ? 1 : 0) + (select ? 1 : 0);
80+
if (set > 1)
81+
return emitError() << "at most one of 'mask', 'swizzle', 'select' may "
82+
"be set on an operand";
83+
if (components != 4 && set != 0)
84+
return emitError() << "component selection mode is only valid on a "
85+
"4-component operand, got "
86+
<< components << " components";
87+
return success();
88+
}
89+
4490
//===----------------------------------------------------------------------===//
4591
// TableGen'd attribute method definitions
4692
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)