-
Notifications
You must be signed in to change notification settings - Fork 2
Dxsa mlir dcl constant buffer and other ops #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dxsa-mlir
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| #include "mlir/IR/Location.h" | ||
| #include "llvm/ADT/ArrayRef.h" | ||
| #include "llvm/ADT/SmallVector.h" | ||
| #include "llvm/ADT/bit.h" | ||
| #include "llvm/Support/Debug.h" | ||
| #include "llvm/Support/DebugLog.h" | ||
| #include "llvm/Support/Endian.h" | ||
|
|
@@ -30,6 +31,10 @@ using UINT = unsigned int; | |
| using namespace mlir; | ||
| using namespace llvm; | ||
|
|
||
| #define FAILURE_IF_FAILED(RES) \ | ||
| if (failed(RES)) \ | ||
| return failure(); | ||
|
|
||
| enum OpcodeClass { | ||
| D3D10_SB_FLOAT_OP, | ||
| D3D10_SB_INT_OP, | ||
|
|
@@ -400,11 +405,23 @@ struct OperandComponents { | |
| }; | ||
| }; | ||
|
|
||
| static dxsa::ComponentMask decodeComponentMask(uint32_t rawComponentMask) { | ||
| auto componentMask = static_cast<dxsa::ComponentMask>(0); | ||
| if (rawComponentMask & D3D10_SB_OPERAND_4_COMPONENT_MASK_X) | ||
| componentMask |= dxsa::ComponentMask::x; | ||
| if (rawComponentMask & D3D10_SB_OPERAND_4_COMPONENT_MASK_Y) | ||
| componentMask |= dxsa::ComponentMask::y; | ||
| if (rawComponentMask & D3D10_SB_OPERAND_4_COMPONENT_MASK_Z) | ||
| componentMask |= dxsa::ComponentMask::z; | ||
| if (rawComponentMask & D3D10_SB_OPERAND_4_COMPONENT_MASK_W) | ||
| componentMask |= dxsa::ComponentMask::w; | ||
| return componentMask; | ||
| } | ||
|
|
||
| class DXBuilder { | ||
| public: | ||
| DXBuilder(MLIRContext *context, StringAttr name) | ||
| : context(context), | ||
| module(ModuleOp::create(builder, FileLineColLoc::get(name, 0, 0))), | ||
| DXBuilder(MLIRContext * /*context*/, StringAttr name) | ||
| : module(ModuleOp::create(builder, FileLineColLoc::get(name, 0, 0))), | ||
| builder(module.getRegion()) {} | ||
|
|
||
| using Index = mlir::Value; | ||
|
|
@@ -597,8 +614,104 @@ class DXBuilder { | |
| systemValueNameAttr); | ||
| } | ||
|
|
||
| dxsa::InlineOperandAttr | ||
| buildInlineOperandAttr(dxsa::InlineOperandType operandType, | ||
| const OperandComponents &comp, | ||
| ArrayRef<int64_t> indexArray) { | ||
| auto *ctx = builder.getContext(); | ||
| dxsa::ComponentMaskAttr maskAttr; | ||
| dxsa::ComponentSwizzleAttr swizzleAttr; | ||
| dxsa::ComponentNameAttr selectAttr; | ||
| switch (comp.kind) { | ||
| case OperandComponentsKind::None: | ||
| break; | ||
| case OperandComponentsKind::Mask: | ||
| maskAttr = | ||
| dxsa::ComponentMaskAttr::get(ctx, decodeComponentMask(comp.mask)); | ||
| break; | ||
| case OperandComponentsKind::Swizzle: | ||
| swizzleAttr = dxsa::ComponentSwizzleAttr::get( | ||
| ctx, static_cast<dxsa::ComponentName>(comp.swizzle[0]), | ||
| static_cast<dxsa::ComponentName>(comp.swizzle[1]), | ||
| static_cast<dxsa::ComponentName>(comp.swizzle[2]), | ||
| static_cast<dxsa::ComponentName>(comp.swizzle[3])); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use |
||
| break; | ||
| case OperandComponentsKind::One: | ||
| selectAttr = dxsa::ComponentNameAttr::get( | ||
| ctx, static_cast<dxsa::ComponentName>(comp.one)); | ||
| break; | ||
| } | ||
| auto indexAttr = indexArray.empty() | ||
| ? DenseI64ArrayAttr() | ||
| : DenseI64ArrayAttr::get(ctx, indexArray); | ||
| return dxsa::InlineOperandAttr::get(ctx, operandType, comp.num, maskAttr, | ||
| swizzleAttr, selectAttr, indexAttr); | ||
| } | ||
|
|
||
| Instruction buildDclInput(dxsa::InlineOperandAttr operand, Location loc) { | ||
| return dxsa::DclInput::create(builder, loc, operand); | ||
| } | ||
|
|
||
| Instruction buildDclOutput(dxsa::InlineOperandAttr operand, Location loc) { | ||
| return dxsa::DclOutput::create(builder, loc, operand); | ||
| } | ||
|
|
||
| Instruction | ||
| buildDclConstantBuffer(dxsa::InlineOperandAttr operand, | ||
| dxsa::ConstantBufferAccessPattern accessPattern, | ||
| Location loc) { | ||
| auto accessPatternAttr = dxsa::ConstantBufferAccessPatternAttr::get( | ||
| builder.getContext(), accessPattern); | ||
| return dxsa::DclConstantBuffer::create(builder, loc, operand, | ||
| accessPatternAttr); | ||
| } | ||
|
|
||
| Instruction buildDclTgsmRaw(dxsa::InlineOperandAttr operand, | ||
| uint32_t byteCount, Location loc) { | ||
| return dxsa::DclTgsmRaw::create(builder, loc, operand, | ||
| builder.getI32IntegerAttr(byteCount)); | ||
| } | ||
|
|
||
| Instruction buildDclIndexRange(dxsa::InlineOperandAttr operand, | ||
| uint32_t count, Location loc) { | ||
| return dxsa::DclIndexRange::create(builder, loc, operand, | ||
| builder.getI32IntegerAttr(count)); | ||
| } | ||
|
|
||
| Instruction buildDclHsMaxTessfactor(float maxTessFactor, Location loc) { | ||
| return dxsa::DclHsMaxTessfactor::create( | ||
| builder, loc, builder.getF32FloatAttr(maxTessFactor)); | ||
| } | ||
|
|
||
| Instruction buildDclHsForkPhaseInstanceCount(uint32_t count, Location loc) { | ||
| return dxsa::DclHsForkPhaseInstanceCount::create( | ||
| builder, loc, builder.getI32IntegerAttr(count)); | ||
| } | ||
|
|
||
| Instruction buildDclHsJoinPhaseInstanceCount(uint32_t count, Location loc) { | ||
| return dxsa::DclHsJoinPhaseInstanceCount::create( | ||
| builder, loc, builder.getI32IntegerAttr(count)); | ||
| } | ||
|
|
||
| Instruction buildDclOutputSiv(dxsa::InlineOperandAttr operand, | ||
| dxsa::SystemValueName systemValueName, | ||
| Location loc) { | ||
| auto systemValueNameAttr = | ||
| dxsa::SystemValueNameAttr::get(builder.getContext(), systemValueName); | ||
| return dxsa::DclOutputSiv::create(builder, loc, operand, | ||
| systemValueNameAttr); | ||
| } | ||
|
|
||
| Instruction buildDclOutputSgv(dxsa::InlineOperandAttr operand, | ||
| dxsa::SystemValueName systemValueName, | ||
| Location loc) { | ||
| auto systemValueNameAttr = | ||
| dxsa::SystemValueNameAttr::get(builder.getContext(), systemValueName); | ||
| return dxsa::DclOutputSgv::create(builder, loc, operand, | ||
| systemValueNameAttr); | ||
| } | ||
|
|
||
| private: | ||
| MLIRContext *context; | ||
| ModuleOp module; | ||
| OpBuilder builder; | ||
| }; | ||
|
|
@@ -1076,6 +1189,121 @@ class Parser { | |
| return builder.buildDclInputPsSgv(*operand, *systemValueName, loc); | ||
| } | ||
|
|
||
| FailureOr<dxsa::InlineOperandAttr> parseInlineOperand() { | ||
| auto token = parseToken(); | ||
| FAILURE_IF_FAILED(token); | ||
|
|
||
| auto rawOperandType = DECODE_D3D10_SB_OPERAND_TYPE(*token); | ||
| auto isExtended = DECODE_IS_D3D10_SB_OPERAND_EXTENDED(*token); | ||
| auto loc = getLocation(); | ||
|
|
||
| if (isImmOperand(*token)) | ||
| return emitError(loc, "immediate operand is not supported yet"); | ||
|
|
||
| auto type = dxsa::symbolizeInlineOperandType(rawOperandType); | ||
| if (!type) | ||
| return emitError(loc, "unknown operand type: ") << rawOperandType; | ||
|
|
||
| auto components = parseOperandComponents(*token); | ||
| FAILURE_IF_FAILED(components); | ||
|
|
||
| auto indexTypes = parseOperandIndexTypes(*token); | ||
| FAILURE_IF_FAILED(indexTypes); | ||
|
|
||
| if (isExtended) | ||
| return emitError(loc, "extended operand tokens are not yet supported in " | ||
| "inline operand attribute"); | ||
|
|
||
| SmallVector<int64_t, 3> indices; | ||
| for (auto indexType : *indexTypes) { | ||
| if (indexType != D3D10_SB_OPERAND_INDEX_IMMEDIATE32) | ||
| return emitError(getLocation(), "unsupported index representation: ") | ||
| << indexType; | ||
| auto value = parseToken(); | ||
| FAILURE_IF_FAILED(value); | ||
| indices.push_back(static_cast<int32_t>(*value)); | ||
| } | ||
|
|
||
| return builder.buildInlineOperandAttr(*type, *components, indices); | ||
| } | ||
|
|
||
| FailureOr<Instruction> parseDclInput(Location loc) { | ||
| auto operand = parseInlineOperand(); | ||
| FAILURE_IF_FAILED(operand); | ||
| return builder.buildDclInput(*operand, loc); | ||
| } | ||
|
|
||
| FailureOr<Instruction> parseDclOutput(Location loc) { | ||
| auto operand = parseInlineOperand(); | ||
| FAILURE_IF_FAILED(operand); | ||
| return builder.buildDclOutput(*operand, loc); | ||
| } | ||
|
|
||
| FailureOr<Instruction> parseDclConstantBuffer(uint32_t opcodeToken, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For Shader Model 5.1 and later, constant buffer opcode is followed by 3 operands: range, size and index. |
||
| Location loc) { | ||
| auto rawAccessPattern = | ||
| DECODE_D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN(opcodeToken); | ||
| auto accessPattern = | ||
| dxsa::symbolizeConstantBufferAccessPattern(rawAccessPattern); | ||
| if (!accessPattern) | ||
| return emitError(loc, "unknown constant buffer access pattern: ") | ||
| << rawAccessPattern; | ||
| auto operand = parseInlineOperand(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The operand for |
||
| FAILURE_IF_FAILED(operand); | ||
| return builder.buildDclConstantBuffer(*operand, *accessPattern, loc); | ||
| } | ||
|
|
||
| FailureOr<Instruction> parseDclTgsmRaw(Location loc) { | ||
| auto operand = parseInlineOperand(); | ||
| FAILURE_IF_FAILED(operand); | ||
| auto byteCount = parseToken(); | ||
| FAILURE_IF_FAILED(byteCount); | ||
| return builder.buildDclTgsmRaw(*operand, *byteCount, loc); | ||
| } | ||
|
|
||
| FailureOr<Instruction> parseDclIndexRange(Location loc) { | ||
| auto operand = parseInlineOperand(); | ||
| FAILURE_IF_FAILED(operand); | ||
| auto count = parseToken(); | ||
| FAILURE_IF_FAILED(count); | ||
| return builder.buildDclIndexRange(*operand, *count, loc); | ||
| } | ||
|
|
||
| FailureOr<Instruction> parseDclHsMaxTessfactor(Location loc) { | ||
| auto token = parseToken(); | ||
| FAILURE_IF_FAILED(token); | ||
| float maxTessFactor = llvm::bit_cast<float>(*token); | ||
| return builder.buildDclHsMaxTessfactor(maxTessFactor, loc); | ||
| } | ||
|
|
||
| FailureOr<Instruction> parseDclHsForkPhaseInstanceCount(Location loc) { | ||
| auto count = parseToken(); | ||
| FAILURE_IF_FAILED(count); | ||
| return builder.buildDclHsForkPhaseInstanceCount(*count, loc); | ||
| } | ||
|
|
||
| FailureOr<Instruction> parseDclHsJoinPhaseInstanceCount(Location loc) { | ||
| auto count = parseToken(); | ||
| FAILURE_IF_FAILED(count); | ||
| return builder.buildDclHsJoinPhaseInstanceCount(*count, loc); | ||
| } | ||
|
|
||
| FailureOr<Instruction> parseDclOutputSiv(Location loc) { | ||
| auto operand = parseInlineOperand(); | ||
| FAILURE_IF_FAILED(operand); | ||
| auto name = parseSystemValueName(getLocation()); | ||
| FAILURE_IF_FAILED(name); | ||
| return builder.buildDclOutputSiv(*operand, *name, loc); | ||
| } | ||
|
|
||
| FailureOr<Instruction> parseDclOutputSgv(Location loc) { | ||
| auto operand = parseInlineOperand(); | ||
| FAILURE_IF_FAILED(operand); | ||
| auto name = parseSystemValueName(getLocation()); | ||
| FAILURE_IF_FAILED(name); | ||
| return builder.buildDclOutputSgv(*operand, *name, loc); | ||
| } | ||
|
|
||
| OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc, | ||
| Instruction &out) { | ||
| FailureOr<Instruction> result; | ||
|
|
@@ -1116,6 +1344,36 @@ class Parser { | |
| case D3D10_SB_OPCODE_DCL_INPUT_PS_SGV: | ||
| result = parseDclInputPsSgv(loc); | ||
| break; | ||
| case D3D10_SB_OPCODE_DCL_INPUT: | ||
| result = parseDclInput(loc); | ||
| break; | ||
| case D3D10_SB_OPCODE_DCL_OUTPUT: | ||
| result = parseDclOutput(loc); | ||
| break; | ||
| case D3D10_SB_OPCODE_DCL_OUTPUT_SIV: | ||
| result = parseDclOutputSiv(loc); | ||
| break; | ||
| case D3D10_SB_OPCODE_DCL_OUTPUT_SGV: | ||
| result = parseDclOutputSgv(loc); | ||
| break; | ||
| case D3D10_SB_OPCODE_DCL_CONSTANT_BUFFER: | ||
| result = parseDclConstantBuffer(opcodeToken, loc); | ||
| break; | ||
| case D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_RAW: | ||
| result = parseDclTgsmRaw(loc); | ||
| break; | ||
| case D3D10_SB_OPCODE_DCL_INDEX_RANGE: | ||
| result = parseDclIndexRange(loc); | ||
| break; | ||
| case D3D11_SB_OPCODE_DCL_HS_MAX_TESSFACTOR: | ||
| result = parseDclHsMaxTessfactor(loc); | ||
| break; | ||
| case D3D11_SB_OPCODE_DCL_HS_FORK_PHASE_INSTANCE_COUNT: | ||
| result = parseDclHsForkPhaseInstanceCount(loc); | ||
| break; | ||
| case D3D11_SB_OPCODE_DCL_HS_JOIN_PHASE_INSTANCE_COUNT: | ||
| result = parseDclHsJoinPhaseInstanceCount(loc); | ||
| break; | ||
| default: | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_constant_buffer.bin | FileCheck %s | ||
|
|
||
| // CHECK: module { | ||
| // CHECK-NEXT: dxsa.dcl_constant_buffer <type = constant_buffer, components = 4, swizzle = <x, y, z, w>, index = [0, 1]>, <immediateIndexed> | ||
| // CHECK-NEXT: dxsa.dcl_constant_buffer <type = constant_buffer, components = 4, swizzle = <x, y, z, w>, index = [3, 128]>, <dynamicIndexed> | ||
| // CHECK-NEXT: } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_hs_fork_phase_instance_count.bin | FileCheck %s | ||
|
|
||
| // CHECK: module { | ||
| // CHECK-NEXT: dxsa.dcl_hs_fork_phase_instance_count 4 | ||
| // CHECK-NEXT: } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_hs_join_phase_instance_count.bin | FileCheck %s | ||
|
|
||
| // CHECK: module { | ||
| // CHECK-NEXT: dxsa.dcl_hs_join_phase_instance_count 2 | ||
| // CHECK-NEXT: } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_hs_max_tessfactor.bin | FileCheck %s | ||
|
|
||
| // CHECK: module { | ||
| // CHECK-NEXT: dxsa.dcl_hs_max_tessfactor 1.550000e+01 | ||
| // CHECK-NEXT: } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we verify that components can only be 0, 1, or 4?