add MLIR → DXIL compute pipeline#409
Merged
makslevental merged 11 commits intomainfrom May 4, 2026
Merged
Conversation
9bd8b91 to
5c8025c
Compare
3a8b8e8 to
37e8a6b
Compare
37e8a6b to
d3ddedb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Full flow: MLIR (eudsl-python-extras matmul) → bare-ptr LLVM → lower_mlir_to_dxil (new C++ pass) → DXIL backend → metallib via
libmetalirconverter→ Metal dispatch with the top-level Argument Buffer encoded from the reflection data → results matchA @ B.DXILLowering.cpp— standalone LLVM IR rewrite:lowerMLIRToDXIL(Module &M)finds every function with"hlsl.shader"attr and rewrites it.Per-arg classification:
ptr addrspace(1)→UAVif any store else SRV,ptr addrspace(2)→SRV,<3 x i32>→ thread id.For each buffer arg: element type inferred from first GEP/load/ store;
@llvm.dx.resource.handlefrombindinginserted at entry, GEP+load chains rewritten torawbuffer.load+extractvalue 0, GEP+store chains torawbuffer.store.For
gid:extractelementwith constant indexK→@llvm.dx.thread.id(i32 K).Signature rewritten to
void ()via a fresh function with blocks spliced over and metadata/attrs copied.DXILHelper.cpp— new bindings:lower_mlir_to_dxil(module)— calls into the pass above.translate_llvm_to_dxil— runs the DirectX backend, emits aDXContainer.translate_dxil_to_metallib— returns (metallib_bytes, [(type, space, slot, top_level_offset, size_bytes, name), ...]) viaIRShaderReflectionso Python knows where each resource sits in the top-level Argument Buffer.IRShaderStageenum. LinksLLVMDirectXCodeGenet al. andlibmetalirconverter; force-loadsLLVMDirectXCodeGenso the static archive'sAsmPrinterTU is pulled into the CAPI dylib.mlir/dxil.py— re-exports the new bindings and addsadd_dxil_module_metadata/mark_as_dxil_compute_kernelhelpers.tests/test_matmul_dxil.py— 32x32 f32 matmul that runs the full pipeline. After lowering, encodes the top-level Argument Buffer from the reflection data (each slot a 24-byte{gpuAddress, resourceID=0, flags=length}descriptor), binds it atkIRArgumentBufferBindPoint = 2, callsuseResource:usage: on each buffer for residency, dispatches withnumthreads=(8,8,1), verifies againstA @ B.