diff --git a/mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td b/mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td index 38daffa7cae3..74b850a7ed7c 100644 --- a/mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td +++ b/mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td @@ -163,6 +163,96 @@ def DXSA_InputPrimitiveAttr : let assemblyFormat = "$value"; } +def DXSA_InterpolationMode_Constant : I32EnumAttrCase<"constant", 1>; +def DXSA_InterpolationMode_Linear : I32EnumAttrCase<"linear", 2>; +def DXSA_InterpolationMode_LinearCentroid : I32EnumAttrCase<"linearCentroid", 3>; +def DXSA_InterpolationMode_LinearNoPerspective : I32EnumAttrCase<"linearNoPerspective", 4>; +def DXSA_InterpolationMode_LinearNoPerspectiveCentroid : I32EnumAttrCase<"linearNoPerspectiveCentroid", 5>; +def DXSA_InterpolationMode_LinearSample : I32EnumAttrCase<"linearSample", 6>; +def DXSA_InterpolationMode_LinearNoPerspectiveSample : I32EnumAttrCase<"linearNoPerspectiveSample", 7>; + +def DXSA_InterpolationMode : I32EnumAttr< + "InterpolationMode", "pixel shader interpolation mode", [ + DXSA_InterpolationMode_Constant, + DXSA_InterpolationMode_Linear, + DXSA_InterpolationMode_LinearCentroid, + DXSA_InterpolationMode_LinearNoPerspective, + DXSA_InterpolationMode_LinearNoPerspectiveCentroid, + DXSA_InterpolationMode_LinearSample, + DXSA_InterpolationMode_LinearNoPerspectiveSample + ]> { + let cppNamespace = "::mlir::dxsa"; + let genSpecializedAttr = 0; +} + +def DXSA_InterpolationModeAttr : + EnumAttr { + let assemblyFormat = "$value"; +} + +def DXSA_SystemValueName_Position : I32EnumAttrCase<"position", 1>; +def DXSA_SystemValueName_ClipDistance : I32EnumAttrCase<"clipDistance", 2>; +def DXSA_SystemValueName_CullDistance : I32EnumAttrCase<"cullDistance", 3>; +def DXSA_SystemValueName_RenderTargetArrayIndex : I32EnumAttrCase<"renderTargetArrayIndex", 4>; +def DXSA_SystemValueName_ViewportArrayIndex : I32EnumAttrCase<"viewportArrayIndex", 5>; +def DXSA_SystemValueName_VertexId : I32EnumAttrCase<"vertexID", 6>; +def DXSA_SystemValueName_PrimitiveId : I32EnumAttrCase<"primitiveID", 7>; +def DXSA_SystemValueName_InstanceId : I32EnumAttrCase<"instanceID", 8>; +def DXSA_SystemValueName_IsFrontFace : I32EnumAttrCase<"isFrontFace", 9>; +def DXSA_SystemValueName_SampleIndex : I32EnumAttrCase<"sampleIndex", 10>; +def DXSA_SystemValueName_FinalQuadUeq0EdgeTessFactor : I32EnumAttrCase<"finalQuadUeq0EdgeTessFactor", 11>; +def DXSA_SystemValueName_FinalQuadVeq0EdgeTessFactor : I32EnumAttrCase<"finalQuadVeq0EdgeTessFactor", 12>; +def DXSA_SystemValueName_FinalQuadUeq1EdgeTessFactor : I32EnumAttrCase<"finalQuadUeq1EdgeTessFactor", 13>; +def DXSA_SystemValueName_FinalQuadVeq1EdgeTessFactor : I32EnumAttrCase<"finalQuadVeq1EdgeTessFactor", 14>; +def DXSA_SystemValueName_FinalQuadUInsideTessFactor : I32EnumAttrCase<"finalQuadUInsideTessFactor", 15>; +def DXSA_SystemValueName_FinalQuadVInsideTessFactor : I32EnumAttrCase<"finalQuadVInsideTessFactor", 16>; +def DXSA_SystemValueName_FinalTriUeq0EdgeTessFactor : I32EnumAttrCase<"finalTriUeq0EdgeTessFactor", 17>; +def DXSA_SystemValueName_FinalTriVeq0EdgeTessFactor : I32EnumAttrCase<"finalTriVeq0EdgeTessFactor", 18>; +def DXSA_SystemValueName_FinalTriWeq0EdgeTessFactor : I32EnumAttrCase<"finalTriWeq0EdgeTessFactor", 19>; +def DXSA_SystemValueName_FinalTriInsideTessFactor : I32EnumAttrCase<"finalTriInsideTessFactor", 20>; +def DXSA_SystemValueName_FinalLineDetailTessFactor : I32EnumAttrCase<"finalLineDetailTessFactor", 21>; +def DXSA_SystemValueName_FinalLineDensityTessFactor : I32EnumAttrCase<"finalLineDensityTessFactor", 22>; +def DXSA_SystemValueName_Barycentrics : I32EnumAttrCase<"barycentrics", 23>; +def DXSA_SystemValueName_ShadingRate : I32EnumAttrCase<"shadingRate", 24>; +def DXSA_SystemValueName_CullPrimitive : I32EnumAttrCase<"cullPrimitive", 25>; + +def DXSA_SystemValueName : I32EnumAttr< + "SystemValueName", "DXBC system interpreted/generated value name", [ + DXSA_SystemValueName_Position, + DXSA_SystemValueName_ClipDistance, + DXSA_SystemValueName_CullDistance, + DXSA_SystemValueName_RenderTargetArrayIndex, + DXSA_SystemValueName_ViewportArrayIndex, + DXSA_SystemValueName_VertexId, + DXSA_SystemValueName_PrimitiveId, + DXSA_SystemValueName_InstanceId, + DXSA_SystemValueName_IsFrontFace, + DXSA_SystemValueName_SampleIndex, + DXSA_SystemValueName_FinalQuadUeq0EdgeTessFactor, + DXSA_SystemValueName_FinalQuadVeq0EdgeTessFactor, + DXSA_SystemValueName_FinalQuadUeq1EdgeTessFactor, + DXSA_SystemValueName_FinalQuadVeq1EdgeTessFactor, + DXSA_SystemValueName_FinalQuadUInsideTessFactor, + DXSA_SystemValueName_FinalQuadVInsideTessFactor, + DXSA_SystemValueName_FinalTriUeq0EdgeTessFactor, + DXSA_SystemValueName_FinalTriVeq0EdgeTessFactor, + DXSA_SystemValueName_FinalTriWeq0EdgeTessFactor, + DXSA_SystemValueName_FinalTriInsideTessFactor, + DXSA_SystemValueName_FinalLineDetailTessFactor, + DXSA_SystemValueName_FinalLineDensityTessFactor, + DXSA_SystemValueName_Barycentrics, + DXSA_SystemValueName_ShadingRate, + DXSA_SystemValueName_CullPrimitive + ]> { + let cppNamespace = "::mlir::dxsa"; + let genSpecializedAttr = 0; +} + +def DXSA_SystemValueNameAttr : + EnumAttr { + let assemblyFormat = "$value"; +} + //===----------------------------------------------------------------------===// // DXSA op definitions //===----------------------------------------------------------------------===// @@ -391,4 +481,57 @@ def DXSA_DclInputPrimitive : DXSA_Op<"dcl_input_primitive"> { let assemblyFormat = "$type attr-dict"; } +def DXSA_DclInputPs : DXSA_Op<"dcl_input_ps"> { + let summary = "declares a pixel shader input"; + let description = [{ + The `dxsa.dcl_input_ps` operation declares a pixel shader input + with the given attribute interpolation mode. + + Example: + + ```mlir + dxsa.dcl_input_ps linear %v0 + ``` + }]; + let arguments = (ins DXSA_InterpolationModeAttr:$mode, + DXSA_OperandType:$operand); + let assemblyFormat = "$mode $operand attr-dict"; +} + +def DXSA_DclInputPsSiv : DXSA_Op<"dcl_input_ps_siv"> { + let summary = "declares a pixel shader system-interpreted input"; + let description = [{ + The `dxsa.dcl_input_ps_siv` operation declares a pixel shader input + that receives a System Interpreted Value, with the given attribute + interpolation mode. + + Example: + + ```mlir + dxsa.dcl_input_ps_siv linear %v0, position + ``` + }]; + let arguments = (ins DXSA_InterpolationModeAttr:$mode, + DXSA_OperandType:$operand, + DXSA_SystemValueNameAttr:$name); + let assemblyFormat = "$mode $operand `,` $name attr-dict"; +} + +def DXSA_DclInputPsSgv : DXSA_Op<"dcl_input_ps_sgv"> { + let summary = "declares a pixel shader system-generated input"; + let description = [{ + The `dxsa.dcl_input_ps_sgv` operation declares a pixel shader input + that receives a System Generated Value. + + Example: + + ```mlir + dxsa.dcl_input_ps_sgv %v0, sampleIndex + ``` + }]; + let arguments = (ins DXSA_OperandType:$operand, + DXSA_SystemValueNameAttr:$name); + let assemblyFormat = "$operand `,` $name attr-dict"; +} + #endif // DXSA_OPS diff --git a/mlir/lib/Target/DXSA/BinaryParser.cpp b/mlir/lib/Target/DXSA/BinaryParser.cpp index 2258046f6ed9..c45a616a5648 100644 --- a/mlir/lib/Target/DXSA/BinaryParser.cpp +++ b/mlir/lib/Target/DXSA/BinaryParser.cpp @@ -568,6 +568,35 @@ class DXBuilder { return dxsa::DclInputPrimitive::create(builder, loc, inputPrimitiveAttr); } + Instruction buildDclInputPs(dxsa::InterpolationMode interpolationMode, + Operand operand, Location loc) { + auto interpolationModeAttr = dxsa::InterpolationModeAttr::get( + builder.getContext(), interpolationMode); + return dxsa::DclInputPs::create(builder, loc, interpolationModeAttr, + operand); + } + + Instruction buildDclInputPsSiv(dxsa::InterpolationMode interpolationMode, + Operand operand, + dxsa::SystemValueName systemValueName, + Location loc) { + auto interpolationModeAttr = dxsa::InterpolationModeAttr::get( + builder.getContext(), interpolationMode); + auto systemValueNameAttr = + dxsa::SystemValueNameAttr::get(builder.getContext(), systemValueName); + return dxsa::DclInputPsSiv::create(builder, loc, interpolationModeAttr, + operand, systemValueNameAttr); + } + + Instruction buildDclInputPsSgv(Operand operand, + dxsa::SystemValueName systemValueName, + Location loc) { + auto systemValueNameAttr = + dxsa::SystemValueNameAttr::get(builder.getContext(), systemValueName); + return dxsa::DclInputPsSgv::create(builder, loc, operand, + systemValueNameAttr); + } + private: MLIRContext *context; ModuleOp module; @@ -619,7 +648,7 @@ class Parser { } FailureOr parseOperandComponents(uint32_t token) { - OperandComponents components; + OperandComponents components{}; switch (DECODE_D3D10_SB_OPERAND_NUM_COMPONENTS(token)) { case D3D10_SB_OPERAND_0_COMPONENT: { components.num = 0; @@ -984,6 +1013,69 @@ class Parser { return builder.buildDclInputPrimitive(*inputPrimitive, loc); } + FailureOr + parseInterpolationMode(uint32_t opcodeToken, Location loc) { + auto rawInterpolationMode = + DECODE_D3D10_SB_INPUT_INTERPOLATION_MODE(opcodeToken); + auto interpolationMode = + dxsa::symbolizeInterpolationMode(rawInterpolationMode); + if (!interpolationMode) + return emitError(loc, "unknown interpolation mode: ") + << rawInterpolationMode; + return *interpolationMode; + } + + FailureOr parseSystemValueName(Location loc) { + Token nameToken = parseToken(); + if (failed(nameToken)) + return failure(); + auto rawSystemValueName = DECODE_D3D10_SB_NAME(*nameToken); + auto systemValueName = dxsa::symbolizeSystemValueName(rawSystemValueName); + if (!systemValueName) + return emitError(loc, "unknown system value name: ") + << rawSystemValueName; + return *systemValueName; + } + + FailureOr parseDclInputPs(uint32_t opcodeToken, Location loc) { + FailureOr interpolationMode = + parseInterpolationMode(opcodeToken, loc); + if (failed(interpolationMode)) + return failure(); + FailureOr operand = parseOperand(); + if (failed(operand)) + return failure(); + return builder.buildDclInputPs(*interpolationMode, *operand, loc); + } + + FailureOr parseDclInputPsSiv(uint32_t opcodeToken, + Location loc) { + FailureOr interpolationMode = + parseInterpolationMode(opcodeToken, loc); + if (failed(interpolationMode)) + return failure(); + FailureOr operand = parseOperand(); + if (failed(operand)) + return failure(); + FailureOr systemValueName = + parseSystemValueName(getLocation()); + if (failed(systemValueName)) + return failure(); + return builder.buildDclInputPsSiv(*interpolationMode, *operand, + *systemValueName, loc); + } + + FailureOr parseDclInputPsSgv(Location loc) { + FailureOr operand = parseOperand(); + if (failed(operand)) + return failure(); + FailureOr systemValueName = + parseSystemValueName(getLocation()); + if (failed(systemValueName)) + return failure(); + return builder.buildDclInputPsSgv(*operand, *systemValueName, loc); + } + OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc, Instruction &out) { FailureOr result; @@ -1015,6 +1107,15 @@ class Parser { case D3D10_SB_OPCODE_DCL_GS_INPUT_PRIMITIVE: result = parseDclInputPrimitive(opcodeToken, loc); break; + case D3D10_SB_OPCODE_DCL_INPUT_PS: + result = parseDclInputPs(opcodeToken, loc); + break; + case D3D10_SB_OPCODE_DCL_INPUT_PS_SIV: + result = parseDclInputPsSiv(opcodeToken, loc); + break; + case D3D10_SB_OPCODE_DCL_INPUT_PS_SGV: + result = parseDclInputPsSgv(loc); + break; default: return std::nullopt; } diff --git a/mlir/test/Target/DXSA/dcl_input_ps.mlir b/mlir/test/Target/DXSA/dcl_input_ps.mlir new file mode 100644 index 000000000000..60a1797c99c3 --- /dev/null +++ b/mlir/test/Target/DXSA/dcl_input_ps.mlir @@ -0,0 +1,39 @@ +// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_input_ps.bin | FileCheck %s + +// CHECK-LABEL: module +module { + // dcl_input_ps constant v0.x + // CHECK: %0 = dxsa.index.imm {imm = 0 : i32} + // CHECK-NEXT: %1 = dxsa.operand %0 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32} + // CHECK-NEXT: dxsa.dcl_input_ps constant %1 + + // dcl_input_ps linear v1.x + // CHECK-NEXT: %2 = dxsa.index.imm {imm = 1 : i32} + // CHECK-NEXT: %3 = dxsa.operand %2 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32} + // CHECK-NEXT: dxsa.dcl_input_ps linear %3 + + // dcl_input_ps linearCentroid v2.x + // CHECK-NEXT: %4 = dxsa.index.imm {imm = 2 : i32} + // CHECK-NEXT: %5 = dxsa.operand %4 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32} + // CHECK-NEXT: dxsa.dcl_input_ps linearCentroid %5 + + // dcl_input_ps linearNoPerspective v3.x + // CHECK-NEXT: %6 = dxsa.index.imm {imm = 3 : i32} + // CHECK-NEXT: %7 = dxsa.operand %6 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32} + // CHECK-NEXT: dxsa.dcl_input_ps linearNoPerspective %7 + + // dcl_input_ps linearNoPerspectiveCentroid v4.x + // CHECK-NEXT: %8 = dxsa.index.imm {imm = 4 : i32} + // CHECK-NEXT: %9 = dxsa.operand %8 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32} + // CHECK-NEXT: dxsa.dcl_input_ps linearNoPerspectiveCentroid %9 + + // dcl_input_ps linearSample v5.x + // CHECK-NEXT: %10 = dxsa.index.imm {imm = 5 : i32} + // CHECK-NEXT: %11 = dxsa.operand %10 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32} + // CHECK-NEXT: dxsa.dcl_input_ps linearSample %11 + + // dcl_input_ps linearNoPerspectiveSample v6.x + // CHECK-NEXT: %12 = dxsa.index.imm {imm = 6 : i32} + // CHECK-NEXT: %13 = dxsa.operand %12 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32} + // CHECK-NEXT: dxsa.dcl_input_ps linearNoPerspectiveSample %13 +} diff --git a/mlir/test/Target/DXSA/dcl_input_ps_sgv.mlir b/mlir/test/Target/DXSA/dcl_input_ps_sgv.mlir new file mode 100644 index 000000000000..7b3b4abcf427 --- /dev/null +++ b/mlir/test/Target/DXSA/dcl_input_ps_sgv.mlir @@ -0,0 +1,19 @@ +// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_input_ps_sgv.bin | FileCheck %s + +// CHECK-LABEL: module +module { + // dcl_input_ps_sgv v0.x, primitiveID + // CHECK: %0 = dxsa.index.imm {imm = 0 : i32} + // CHECK-NEXT: %1 = dxsa.operand %0 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32} + // CHECK-NEXT: dxsa.dcl_input_ps_sgv %1, primitiveID + + // dcl_input_ps_sgv v1.x, isFrontFace + // CHECK-NEXT: %2 = dxsa.index.imm {imm = 1 : i32} + // CHECK-NEXT: %3 = dxsa.operand %2 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32} + // CHECK-NEXT: dxsa.dcl_input_ps_sgv %3, isFrontFace + + // dcl_input_ps_sgv v2.x, sampleIndex + // CHECK-NEXT: %4 = dxsa.index.imm {imm = 2 : i32} + // CHECK-NEXT: %5 = dxsa.operand %4 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32} + // CHECK-NEXT: dxsa.dcl_input_ps_sgv %5, sampleIndex +} diff --git a/mlir/test/Target/DXSA/dcl_input_ps_siv.mlir b/mlir/test/Target/DXSA/dcl_input_ps_siv.mlir new file mode 100644 index 000000000000..24c542847833 --- /dev/null +++ b/mlir/test/Target/DXSA/dcl_input_ps_siv.mlir @@ -0,0 +1,29 @@ +// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_input_ps_siv.bin | FileCheck %s + +// CHECK-LABEL: module +module { + // dcl_input_ps_siv linear v0.x, position + // CHECK: %0 = dxsa.index.imm {imm = 0 : i32} + // CHECK-NEXT: %1 = dxsa.operand %0 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32} + // CHECK-NEXT: dxsa.dcl_input_ps_siv linear %1, position + + // dcl_input_ps_siv linear v1.x, clipDistance + // CHECK-NEXT: %2 = dxsa.index.imm {imm = 1 : i32} + // CHECK-NEXT: %3 = dxsa.operand %2 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32} + // CHECK-NEXT: dxsa.dcl_input_ps_siv linear %3, clipDistance + + // dcl_input_ps_siv linear v2.x, cullDistance + // CHECK-NEXT: %4 = dxsa.index.imm {imm = 2 : i32} + // CHECK-NEXT: %5 = dxsa.operand %4 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32} + // CHECK-NEXT: dxsa.dcl_input_ps_siv linear %5, cullDistance + + // dcl_input_ps_siv linear v3.x, renderTargetArrayIndex + // CHECK-NEXT: %6 = dxsa.index.imm {imm = 3 : i32} + // CHECK-NEXT: %7 = dxsa.operand %6 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32} + // CHECK-NEXT: dxsa.dcl_input_ps_siv linear %7, renderTargetArrayIndex + + // dcl_input_ps_siv linear v4.x, viewportArrayIndex + // CHECK-NEXT: %8 = dxsa.index.imm {imm = 4 : i32} + // CHECK-NEXT: %9 = dxsa.operand %8 {mask = 16 : i32, num_components = 4 : i32, type = 1 : i32} + // CHECK-NEXT: dxsa.dcl_input_ps_siv linear %9, viewportArrayIndex +} diff --git a/mlir/test/Target/DXSA/inputs/dcl_input_ps.bin b/mlir/test/Target/DXSA/inputs/dcl_input_ps.bin new file mode 100644 index 000000000000..87b327afc4a2 Binary files /dev/null and b/mlir/test/Target/DXSA/inputs/dcl_input_ps.bin differ diff --git a/mlir/test/Target/DXSA/inputs/dcl_input_ps_sgv.bin b/mlir/test/Target/DXSA/inputs/dcl_input_ps_sgv.bin new file mode 100644 index 000000000000..7a697e293c3a Binary files /dev/null and b/mlir/test/Target/DXSA/inputs/dcl_input_ps_sgv.bin differ diff --git a/mlir/test/Target/DXSA/inputs/dcl_input_ps_siv.bin b/mlir/test/Target/DXSA/inputs/dcl_input_ps_siv.bin new file mode 100644 index 000000000000..0e9c2fd1028b Binary files /dev/null and b/mlir/test/Target/DXSA/inputs/dcl_input_ps_siv.bin differ