Replace MojoShader with ShaderConductor#7345
Replace MojoShader with ShaderConductor#7345cpt-max wants to merge 32 commits intoMonoGame:developfrom
Conversation
… and matrix transpose
MonoGame 3.8 Release
Update master
Fix Missing Android Package
…ines for EffectProcessor.
…arameter updating when uniform buffers are not available.
|
Yeah, I did not test on Mac and the DX unit tests don't work for me, as it always fails to create the DX device. If somebody can give me a hint how to fix that? |
|
I set it up on a Mac to fix the failing unit tests. It's all good now. |
|
On Mac the OpenGL version is currently always 2.1, which means no SM 4 or 5. It's almost certainly related to this. |
If the device is created with debug flags (DeviceCreationFlags.Debug), you need a feature installed called |
|
Thanks for you reply @deccer. I already had the Graphics Tools installed. Looking into it a bit more, the device creation fails because it's trying to create a reference device. If I change it to a regular hardware device, it works. |
|
For people wanting to try this PR, it's best to use PR #7352 instead. It fully contains this PR, but it has a few additional fixes. Maintaining multiple branches takes some extra time, so I'll only update this branch, if I know it's really needed. |
|
This is awesome! I took a stab at migrating my fairly shader-heavy project, and it works well. Migrating takes a bit of effort though. I also noticed some peculiarities with ShaderConductor:
|
|
Thanks for your feedback @minimalism, very much appreciated.
Yeah, a bit of a monkey job. Some automation would be nice.
Can you tell me which BlockOnUIThread is not called anymore, that used to be called. I don't think I removed/circumvented any of those. Which GL call is failing exactly?
That's almost certainly a bug in DirectXShaderCompiler or SPIRV-Cross. If you can send me a crashing shader, I should be able to find out where the crash is happening, and open an issue in the respective repository. Both projects are quite active. I reported a crashing bug before and it was fixed a few weeks later.
I'll see if I can find out more about that in my next ShaderConductor debugging session.
Thanks, will add those to the migration document.
Alright, sounds like something for DirectXShaderCompiler. If the HLSL->DXIL compilation can handle omitting those semantics (not sure if it does) than the HLSL->SPIRV should also handle it. |
The GL calls in PlatformInitialize (and PlatformClear) in ConstantBuffer.OpenGL.cs. On my device, when calling these methods from a background thread GL.GenBuffers will always return -1 and CheckGLError will always throw 1282.
Sure, this digitalrune shader reproduces the error for me: https://gist.github.com/minimalism/d27e1b20274f0aa646235a9d061401ea PS Note that this shader also exhibits one of the issues I mentioned above, where the VS outputs { TEXCOORD, SV_POSITION } but the PS parameter list only accepts { TEXCOORD }. This worked in Mojoshader. It compiles fine in ShaderConductor but doesn't seem to render anything to screen. Hope this is useful :) |
That makes sense, for every ConstantBuffer a uniform buffer object is created. MojoShader didn't need those. I'll just wrap a BlockOnUIThread around these calls then. |
|
I updated #7352
You only mentioned that matrix parameters have to be passed row by row. Do you mean that MojoShader accepted SV_POSITION as a pixel shader parameter, but ShaderConductor doesn't? |
|
Nice! I see they've already merged a fix for the error message error, that will save some frustration for future users no doubt. I'll test the shader on background thread thing even though it's questionable if this practice should really be supported...
This situation is what I tried to describe when I said that the pixel shaders needs to receive the SV_POSITION semantic, whereas in MojoShader it was sufficient to just return it from the VS. |
The PR is now updated and contains this fix.
I'm pretty sure content loading from multiple threads was already supported in XNA, so MonoGame should do it too.
I just tested this with a very simple vertex and pixel shader. I don't have that problem. It makes no difference if SV_POSITION is part of the pixel shader parameters or not. Maybe it only shows in more complex shaders, or it has been fixed in the new version.
This too I can't reproduce. It works fine for me. Could the update have fixed this too? |
|
This Pr looks amazing don't give it up! |
|
Closing this PR, as it's contained in #7533 |
MojoShader is limited to DX9, OpenGL 2 and GLSL 110. ShaderConductor can still target those versions, but it can also target the newest versions of DX, OpenGL and GLSL. This means shader model 4 and 5 are now also available for OpenGL. Here are more details about the supported shader models and shader stages.
Right now ShaderConductor is only used for converting HLSL to GLSL/ESSL, but it can also output DXIL for DX12, SPIR-V for Vulkan, or MSL for Metal, so this can be considered a first step towards supporting those platforms.
Here I list all the things I found so far when migrating shaders from MojoShader to ShaderConductor. Perhaps somebody wants to look into tools to help automate this process?
If you have some projects that target OpenGL, it would be great if you can test this PR, even if it only uses default shaders, as those have also been converted.
MojoShader has not yet been removed, and you can actually mix and match Mojo and Conductor shaders in the same project. To switch a shader back to Mojo you just add the MOJO define to the effect processor in the MGCB editor. This should help isolate problems with this PR. Maybe it makes sense to keep Mojo alive this way until MonoGame 4 is out?
MonoGame.Effect.Compiler now includes three C++ dlls which have been compiled from this ShaderConductor fork, which adds reflection support, plus a few little tweaks.
Those dll's should eventually be moved to the ThirdParty/Dependencies folder.
This PR also contains #7242. The reason for this is that supporting those new shader stages for OpenGL is the main reason I did all of this in the first place, and it safes me a little bit of time this way, so it's probably best to merge that PR first.
Anyone wanting to try out this branch, please use #7533 instead. It fully contains this branch and is kept up to date.