Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Comment thread
tagolog marked this conversation as resolved.

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<DXSADialect, DXSA_InterpolationMode, "interpolation_mode"> {
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<DXSADialect, DXSA_SystemValueName, "system_value_name"> {
let assemblyFormat = "$value";
}

//===----------------------------------------------------------------------===//
// DXSA op definitions
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -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
103 changes: 102 additions & 1 deletion mlir/lib/Target/DXSA/BinaryParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -619,7 +648,7 @@ class Parser {
}

FailureOr<OperandComponents> 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;
Expand Down Expand Up @@ -984,6 +1013,69 @@ class Parser {
return builder.buildDclInputPrimitive(*inputPrimitive, loc);
}

FailureOr<dxsa::InterpolationMode>
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<dxsa::SystemValueName> 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<Instruction> parseDclInputPs(uint32_t opcodeToken, Location loc) {
FailureOr<dxsa::InterpolationMode> interpolationMode =
parseInterpolationMode(opcodeToken, loc);
if (failed(interpolationMode))
return failure();
FailureOr<Operand> operand = parseOperand();
if (failed(operand))
return failure();
return builder.buildDclInputPs(*interpolationMode, *operand, loc);
}

FailureOr<Instruction> parseDclInputPsSiv(uint32_t opcodeToken,
Location loc) {
FailureOr<dxsa::InterpolationMode> interpolationMode =
parseInterpolationMode(opcodeToken, loc);
if (failed(interpolationMode))
return failure();
FailureOr<Operand> operand = parseOperand();
if (failed(operand))
return failure();
FailureOr<dxsa::SystemValueName> systemValueName =
parseSystemValueName(getLocation());
if (failed(systemValueName))
return failure();
return builder.buildDclInputPsSiv(*interpolationMode, *operand,
*systemValueName, loc);
}

FailureOr<Instruction> parseDclInputPsSgv(Location loc) {
FailureOr<Operand> operand = parseOperand();
if (failed(operand))
return failure();
FailureOr<dxsa::SystemValueName> systemValueName =
parseSystemValueName(getLocation());
if (failed(systemValueName))
return failure();
return builder.buildDclInputPsSgv(*operand, *systemValueName, loc);
}

OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
Instruction &out) {
FailureOr<Instruction> result;
Expand Down Expand Up @@ -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;
}
Expand Down
39 changes: 39 additions & 0 deletions mlir/test/Target/DXSA/dcl_input_ps.mlir
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 19 additions & 0 deletions mlir/test/Target/DXSA/dcl_input_ps_sgv.mlir
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 29 additions & 0 deletions mlir/test/Target/DXSA/dcl_input_ps_siv.mlir
Original file line number Diff line number Diff line change
@@ -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
}
Binary file added mlir/test/Target/DXSA/inputs/dcl_input_ps.bin
Binary file not shown.
Binary file added mlir/test/Target/DXSA/inputs/dcl_input_ps_sgv.bin
Binary file not shown.
Binary file added mlir/test/Target/DXSA/inputs/dcl_input_ps_siv.bin
Binary file not shown.