-
Notifications
You must be signed in to change notification settings - Fork 2
[mlir][dxsa] Add dcl_function_body and dcl_function_table #134
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 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -719,4 +719,39 @@ def DXSA_DclOutput : DXSA_Op<"dcl_output"> { | |||||
| let assemblyFormat = "$operand attr-dict"; | ||||||
| } | ||||||
|
|
||||||
| def DXSA_DclFunctionBody : DXSA_Op<"dcl_function_body"> { | ||||||
| let summary = "declares a function body number"; | ||||||
| let description = [{ | ||||||
| The `dxsa.dcl_function_body` declares a unique function body whose index | ||||||
| will appear later in the program at `label #` or `dcl_function_table`. | ||||||
|
|
||||||
| Example: | ||||||
| ```mlir | ||||||
| dxsa.dcl_function_body 0 | ||||||
| ``` | ||||||
| }]; | ||||||
| let arguments = (ins I32Attr:$index); | ||||||
| let assemblyFormat = "$index attr-dict"; | ||||||
| } | ||||||
|
|
||||||
| def DXSA_DclFunctionTable : DXSA_Op<"dcl_function_table"> { | ||||||
| let summary = "declares a function table"; | ||||||
| let description = [{ | ||||||
| Declare a function table as a set of function bodies that have | ||||||
| been declared earlier. | ||||||
|
|
||||||
| This is like a C++ vtable except there is an entry per call site | ||||||
| for an interface instead of per method. | ||||||
|
|
||||||
| Example: | ||||||
| ```mlir | ||||||
| dxsa.dcl_function_body 0 | ||||||
| dxsa.dcl_function_body 1 | ||||||
| dxsa.dcl_function_table 0, <functions = [0, 1]> | ||||||
| ``` | ||||||
| }]; | ||||||
| let arguments = (ins I32Attr:$index, DenseI32ArrayAttr:$functions); | ||||||
|
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.
Suggested change
Contributor
Author
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. Done. |
||||||
| let assemblyFormat = "$index `,` `<` `functions` `=` $functions `>` attr-dict"; | ||||||
| } | ||||||
|
|
||||||
| #endif // DXSA_OPS | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -635,6 +635,17 @@ class DXBuilder { | |
| return dxsa::DclOutput::create(builder, loc, operand); | ||
| } | ||
|
|
||
| Instruction buildDclFunctionBody(uint32_t index, Location loc) { | ||
| return dxsa::DclFunctionBody::create(builder, loc, index); | ||
| } | ||
|
|
||
| Instruction buildDclFunctionTable(uint32_t index, ArrayRef<int32_t> functions, | ||
| Location loc) { | ||
| auto *ctx = builder.getContext(); | ||
| return dxsa::DclFunctionTable::create( | ||
| builder, loc, index, DenseI32ArrayAttr::get(ctx, functions)); | ||
| } | ||
|
|
||
| private: | ||
| MLIRContext *context; | ||
| ModuleOp module; | ||
|
|
@@ -1174,6 +1185,30 @@ class Parser { | |
| return builder.buildDclOutput(*operand, loc); | ||
| } | ||
|
|
||
| FailureOr<Instruction> parseDclFunctionBody(Location loc) { | ||
| auto index = parseToken(); | ||
| FAILURE_IF_FAILED(index); | ||
| return builder.buildDclFunctionBody(*index, loc); | ||
| } | ||
|
|
||
| FailureOr<Instruction> parseDclFunctionTable(Location loc) { | ||
| auto index = parseToken(); | ||
|
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. Extended length bit [31] for The spec says the regular 7-bit length field can overflow, in which case bit [31] is set and the real length lives in the next DWORD: d3d12TokenizedProgramFormat.hpp#L2486-L2490 DirectXShaderCompiler handles this explicitly ShaderBinary.cpp#L548-L558 Right now the parser ignores extended length bit for these opcodes and silently parses the next DWORD as function table identifier.
Contributor
Author
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. Good catch! Added handling of extended length token. |
||
| FAILURE_IF_FAILED(index); | ||
|
|
||
| auto numFunctions = parseToken(); | ||
| FAILURE_IF_FAILED(numFunctions); | ||
|
|
||
| SmallVector<int32_t, 16> functions; | ||
| functions.resize(*numFunctions); | ||
| for (uint32_t i = 0; i < *numFunctions; ++i) { | ||
| auto functionIndex = parseToken(); | ||
| FAILURE_IF_FAILED(functionIndex); | ||
| functions[i] = *functionIndex; | ||
| } | ||
|
|
||
| return builder.buildDclFunctionTable(*index, functions, loc); | ||
| } | ||
|
|
||
| OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc, | ||
| Instruction &out) { | ||
| FailureOr<Instruction> result; | ||
|
|
@@ -1220,6 +1255,12 @@ class Parser { | |
| case D3D10_SB_OPCODE_DCL_OUTPUT: | ||
| result = parseDclOutput(loc); | ||
| break; | ||
| case D3D11_SB_OPCODE_DCL_FUNCTION_BODY: | ||
| result = parseDclFunctionBody(loc); | ||
| break; | ||
| case D3D11_SB_OPCODE_DCL_FUNCTION_TABLE: | ||
| result = parseDclFunctionTable(loc); | ||
| break; | ||
| default: | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_function_body.bin | FileCheck %s | ||
| // | ||
| // CHECK-LABEL: module | ||
| // CHECK-NEXT: dxsa.dcl_function_body 1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_function_table.bin | FileCheck %s | ||
|
|
||
| // CHECK-LABEL: module | ||
| // CHECK-NEXT: dxsa.dcl_function_table 1, <functions = [0, 1]> |
|
asavonic marked this conversation as resolved.
|
Uh oh!
There was an error while loading. Please reload this page.
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.
This argument is positive by design, I vote to restrict it.
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.
Thank you. Added restriction.