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

Support SPIRV -> DXIL #4969

Closed
iwubcode opened this issue Jan 26, 2023 · 6 comments
Closed

Support SPIRV -> DXIL #4969

iwubcode opened this issue Jan 26, 2023 · 6 comments
Labels
question Question or inquiry

Comments

@iwubcode
Copy link

iwubcode commented Jan 26, 2023

Apologies if I missed this, I looked around and didn't see this already.

Would like to request converting from SPIRV -> DXIL . From what I understand there is already functionality that supports the opposite.

Currently working on a project that takes GLSL and converts to SPIRV then generates HLSL off of that so that it can then compile that HLSL into formats that DX11 and DX12 can leverage. This happens in realtime due to how our software works. It would be much more efficient to go directly from SPIRV to DXIL but no systems seem to support this (we currently use SPIRV-Cross).

@Keenuts Keenuts added the question Question or inquiry label Jan 26, 2023
@Keenuts
Copy link
Collaborator

Keenuts commented Jan 26, 2023

Hello!

This won't be the goal of this compiler, since we really focus on HLSL -> some IR translation, but you might want to look into mesa, apparently they have a SPIRV->DXIL library which receives patches, just unsure of the support level:

@Keenuts Keenuts closed this as completed Jan 26, 2023
@iwubcode
Copy link
Author

@Keenuts - thank you. Can this be raised internally that there is at least some interest to do this work? The Godot game engine used Mesa godotengine/godot#70315 and they said that was better than the alternative (Spirv-cross) but it still uses an intermediate layer "NIR".

Given that SPIRV and DXIL are the two main modern solutions, surely other teams are also running into this hurdle. But seems like there isn't much interest from projects that work on this sort of work (see HansKristian-Work/dxil-spirv#103 ).

I will look into Mesa as an option. Thank you for your time!

@Keenuts
Copy link
Collaborator

Keenuts commented Jan 26, 2023

Hello again!
Not speaking for Microsoft, but AFAIK, from our team point-of-view, we have no immediate interest in building/maintaining a new tool to do this at the moment, sorry 😊

@kasperk81
Copy link

seeing number of people waiting for stuff like virtio-win/kvm-guest-drivers-windows#943, it is frustrating that SPIRV to DXIL direct translation does not exist. if

  • there are < 500 commands/constructs/instructions/whatever on both sides; DXIL and SPIRV
  • a compiler knows how to go from IR -> either sides

then compiler knows a whole lot than it's letting on. making a lookup table for all commands combined we are talking about 1000 function pointers (some map directly 1:1, others map to a wrapper)? worth spending time here in one place rather than telling everyone out in the wild to coin the whole thing.

such mapping will also help testing https://devblogs.microsoft.com/directx/directx-adopting-spir-v/ down the road, so it's a win-win

@Keenuts
Copy link
Collaborator

Keenuts commented Jan 2, 2025

Hi,

  • there are < 500 commands/constructs/instructions/whatever on both sides; DXIL and SPIRV

Not sure what you are referring to with the 500 commands. Translating DXIL to SPIR-V is not just a matter of mapping one instructions to another. It would require modifying the control flow, understanding SPV-VK extensions and transform those to DX equivalent, and modifying resource access as both language handle those differently.

  • a compiler knows how to go from IR -> either sides

DXC does not uses the same path for both DXIL and SPIR-V.
SPIR-V is lowered directly from the AST, skipping LLVM IR, while DXIL goes through a more normal path. Hence only common points we have between the 2 paths is either HLSL or the AST, and both are very high-level, and completely lost once we have SPIR-V. Hence, adding a path converting SPIR-V to DXIL would be a whole new thing, hence reusing DXC for this matter is not helping.

And last bit, VirtioGPU on Windows is not just a matter of translating DXIL to SPIR-V, but also translating a guest Win32 app 3D call (Possibly DX9, DX12, Vk or even OpenGL) into virgl commands so it can be translated again into something the host can support (maybe the host only supports OpenGL).

@kasperk81
Copy link

@Keenuts thanks for the clarification! I’ll admit, I’m not an expert in this area. The linked blog post vaguely stated that building the SPIR-V environment for DirectX will take several years. I was curious why this would take so long, especially considering that DXC appears to provide a lot of prior art. Now I understand that it’s essentially a ground-up development effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or inquiry
Projects
None yet
Development

No branches or pull requests

3 participants