-
Notifications
You must be signed in to change notification settings - Fork 2
[mlir][dxsa] Add root dxsa.module #155
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -420,15 +420,23 @@ static dxsa::ComponentMask decodeComponentMask(uint32_t rawComponentMask) { | |
|
|
||
| class DXBuilder { | ||
| public: | ||
| DXBuilder(MLIRContext *context, StringAttr name) | ||
| : context(context), | ||
| module(ModuleOp::create(builder, FileLineColLoc::get(name, 0, 0))), | ||
| builder(module.getRegion()) {} | ||
| explicit DXBuilder(MLIRContext *context) | ||
| : context(context), builder(context) {} | ||
|
|
||
| using Index = mlir::Value; | ||
| using Operand = mlir::Value; | ||
| using Instruction = mlir::Operation *; | ||
| using Module = mlir::ModuleOp; | ||
| using Module = mlir::dxsa::ModuleOp; | ||
|
|
||
| Module createModule(mlir::dxsa::ProgramTypeAttr programType, | ||
| mlir::dxsa::ShaderVersionAttr shaderVersion, | ||
| Location loc) { | ||
| OperationState state(loc, Module::getOperationName()); | ||
| Module::build(builder, state, programType, shaderVersion); | ||
| auto module = cast<Module>(Operation::create(state)); | ||
| builder.setInsertionPointToStart(&module.getBody().front()); | ||
| return module; | ||
| } | ||
|
|
||
| Index buildIndexImm32(int32_t imm, FileLineColLoc loc) { | ||
| Operation *op = | ||
|
|
@@ -523,10 +531,6 @@ class DXBuilder { | |
| builder.getStringAttr(name)); | ||
| } | ||
|
|
||
| Module buildModule(ArrayRef<Instruction> instructions, FileLineColLoc loc) { | ||
| return module; | ||
| } | ||
|
|
||
| Instruction buildDclGlobalFlags(dxsa::GlobalFlags flags, Location loc) { | ||
| auto flagsAttr = dxsa::GlobalFlagsAttr::get(builder.getContext(), flags); | ||
| return dxsa::DclGlobalFlags::create(builder, loc, flagsAttr); | ||
|
|
@@ -706,7 +710,6 @@ class DXBuilder { | |
|
|
||
| private: | ||
| MLIRContext *context; | ||
| ModuleOp module; | ||
| OpBuilder builder; | ||
| }; | ||
|
|
||
|
|
@@ -1530,15 +1533,60 @@ class Parser { | |
|
|
||
| FailureOr<Module> parseModule() { | ||
| FileLineColLoc loc = getLocation(0); | ||
| std::vector<Instruction> instructions; | ||
| auto header = parseProgramHeader(); | ||
| FAILURE_IF_FAILED(header); | ||
| mlir::dxsa::ProgramTypeAttr programType; | ||
| mlir::dxsa::ShaderVersionAttr shaderVersion; | ||
| if (*header) { | ||
| programType = | ||
| mlir::dxsa::ProgramTypeAttr::get(name.getContext(), (*header)->type); | ||
| shaderVersion = mlir::dxsa::ShaderVersionAttr::get( | ||
| name.getContext(), (*header)->major, (*header)->minor); | ||
| } | ||
| auto module = builder.createModule(programType, shaderVersion, loc); | ||
| while (currentTokenOffset < buffer.size()) { | ||
| FailureOr<Instruction> inst = parseInstruction(); | ||
| if (failed(inst)) { | ||
| return failure(); | ||
| } | ||
| instructions.push_back(*inst); | ||
| } | ||
| return builder.buildModule(instructions, loc); | ||
| return module; | ||
| } | ||
|
|
||
| struct ProgramHeader { | ||
| mlir::dxsa::ProgramType type; | ||
| uint8_t major; | ||
| uint8_t minor; | ||
| }; | ||
|
|
||
| /// If the buffer begins with a tokenized-program header (VersionToken + | ||
| /// LengthToken), decode and consume both tokens and return the program type | ||
| /// and shader model. Otherwise return without touching the parser current | ||
| /// position. | ||
| FailureOr<std::optional<ProgramHeader>> parseProgramHeader() { | ||
| constexpr size_t headerSize = 2 * sizeof(uint32_t); | ||
| if (currentTokenOffset + headerSize > buffer.size()) | ||
| return std::optional<ProgramHeader>{}; | ||
|
|
||
| auto versionToken = support::endian::read<uint32_t>( | ||
| buffer.begin() + currentTokenOffset, endianness::little); | ||
| if (DECODE_D3D10_SB_TOKENIZED_INSTRUCTION_LENGTH(versionToken) != 0) | ||
|
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. If we expect |
||
| return std::optional<ProgramHeader>{}; | ||
|
|
||
| auto rawType = static_cast<uint32_t>( | ||
|
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. This seems concise to me: |
||
| DECODE_D3D10_SB_TOKENIZED_PROGRAM_TYPE(versionToken)); | ||
| auto programType = dxsa::symbolizeProgramType(rawType); | ||
| if (!programType) | ||
| return std::optional<ProgramHeader>{}; | ||
|
|
||
| auto major = static_cast<uint8_t>( | ||
| DECODE_D3D10_SB_TOKENIZED_PROGRAM_MAJOR_VERSION(versionToken)); | ||
| auto minor = static_cast<uint8_t>( | ||
| DECODE_D3D10_SB_TOKENIZED_PROGRAM_MINOR_VERSION(versionToken)); | ||
|
|
||
| FAILURE_IF_FAILED(parseToken()); // VersionToken | ||
| FAILURE_IF_FAILED(parseToken()); // LengthToken | ||
| return std::optional<ProgramHeader>{{*programType, major, minor}}; | ||
| } | ||
|
|
||
| LogicalResult verifyInstructionLength(size_t beginOffset, uint32_t length) { | ||
|
|
@@ -1558,8 +1606,8 @@ class Parser { | |
| }; | ||
|
|
||
| namespace mlir::dxsa { | ||
| OwningOpRef<ModuleOp> importDxsaBinaryToModule(llvm::SourceMgr &source, | ||
| MLIRContext *context) { | ||
| OwningOpRef<ModuleOp> deserialize(llvm::SourceMgr &source, | ||
| MLIRContext *context) { | ||
|
|
||
| if (source.getNumBuffers() != 1) { | ||
| emitError(UnknownLoc::get(context), "one source file should be provided"); | ||
|
|
@@ -1575,7 +1623,7 @@ OwningOpRef<ModuleOp> importDxsaBinaryToModule(llvm::SourceMgr &source, | |
| context->allowUnregisteredDialects(); | ||
| context->loadAllAvailableDialects(); | ||
|
|
||
| DXBuilder builder(context, name); | ||
| DXBuilder builder(context); | ||
| Parser parser(builder, name, buffer); | ||
| FailureOr<ModuleOp> mod = parser.parseModule(); | ||
| if (failed(mod)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| // RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_constant_buffer.bin | FileCheck %s | ||
|
|
||
| // CHECK: module { | ||
| // CHECK: dxsa.module { | ||
| // CHECK-NEXT: dxsa.dcl_constant_buffer <id = 0, size = 1>, <immediateIndexed> | ||
| // CHECK-NEXT: dxsa.dcl_constant_buffer <id = 0, size = 4, lbound = 0, ubound = 3, space = 1>, <dynamicIndexed> | ||
| // CHECK-NEXT: } |
Uh oh!
There was an error while loading. Please reload this page.