Skip to content
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

DirectX IR #4302

Open
Skepfyr opened this issue Jul 30, 2019 · 7 comments
Open

DirectX IR #4302

Skepfyr opened this issue Jul 30, 2019 · 7 comments
Labels
area: naga back-end Outputs of naga shader conversion help required We need community help to make this happen. naga Shader Translator type: enhancement New feature or request

Comments

@Skepfyr
Copy link

Skepfyr commented Jul 30, 2019

DirectX 12, like Metal (#4), uses LLVM bitcode as its low-level representation which is actually quite well documented (DXIL). However, the diagram at the top of that documentation suggests we probably want to be targeting their high level IR (DXIR), which as far as I can tell is almost completly undocumented 😞, although is also LLVM IR.
The optimisations done between DXIR and DXIL are:

  • optimize function parameter copies
  • inline functions
  • allocate and transform shader signatures
  • lower matrices, optimizing intermediate storage
  • linearize multi-dimensional arrays and user-defined type accesses
  • scalarize vectors

Which don't sound particularly fun, or reasonable, to implement, although it might be possible. This will involve linking to some part of the DirectXShaderCompiler, which shouldn't be too hard as it all currently builds (after jumping through every hoop) to a load of static libraries, once we've worked out which libraries we need.

Their compiler also can output back out to SPIR-V and they have a HLSL to SPIR-V feature map, which should come in handy.

@Skepfyr
Copy link
Author

Skepfyr commented Aug 2, 2019

Some information about DXIL vs DXIR:
microsoft/DirectXShaderCompiler#2389

@kvark kvark added help required We need community help to make this happen. area: naga back-end Outputs of naga shader conversion labels Mar 6, 2020
@Lectem
Copy link

Lectem commented Jul 9, 2020

Note that the DXIL document ( https://github.com/Microsoft/DirectXShaderCompiler/blob/master/docs/DXIL.rst#introduction ) says

Microsoft will publicly document DXIL and DXIR to attract domain language implementers and spur innovation.

Is releasing the DXIR specification still planned ?

@Skepfyr
Copy link
Author

Skepfyr commented Jul 17, 2020

So as far as I can tell, no unless we bug them a lot or write it ourselves. The only guidance we've got is that issue I opened a while ago. Something else I worked out a while ago is that if we did produce DXIR we would need to ship dxcompiler in some form as it doesn't come with windows, which could cause some interesting licensing problems.

@kvark
Copy link
Member

kvark commented Oct 30, 2020

Here is the code in Mesa fork that Microsoft develops, it takes Mesa IR and targets DXIL (derived from LLVM 3.7 IR) without linking to LLVM. We should take it and develop our backend.

Edit: reading about http://www.jlekstrand.net/jason/projects/mesa/nir-notes/

@jrmuizel
Copy link
Contributor

Having llvm bit code writing abilities could be useful targeting metal as well.

@seanbaxter
Copy link

DXIR has been formally disowned now:
microsoft/DirectXShaderCompiler@61c6573

I'm working on using the dxc llvm fork to emit DXIL from C++. However the code is extremely buggy, and a lot of the MS-written passes expect constructs coming in from the high-level HL/DXIR collection of types. If you try emitting DXIL intrinsics (like @dx.op.load/store/sample) and running the provided passes to perform inlining, scalarization, array flattening etc, stuff breaks. So I hack a lot on what they proivde. MS doesn't answer issues related to this. I think people who really want this working should get together and figure a way forward, because it's real hard to do this as an individual.

@kvark
Copy link
Member

kvark commented Feb 9, 2021

Latest matrix discussion. Thank you @seanbaxter for sharing the knowledge!

MatusT referenced this issue in MatusT/naga May 4, 2021
@teoxoy teoxoy mentioned this issue May 2, 2022
6 tasks
@cwfitzgerald cwfitzgerald added the naga Shader Translator label Oct 25, 2023
@cwfitzgerald cwfitzgerald transferred this issue from gfx-rs/naga Oct 25, 2023
@teoxoy teoxoy added type: enhancement New feature or request and removed kind: feature labels Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: naga back-end Outputs of naga shader conversion help required We need community help to make this happen. naga Shader Translator type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants