Can't create Effect through constructor from the bytecode compiled by mgfxc
rds1983 opened this issue · 3 comments
Prerequisites
- I have verified this issue is not present in the
develop
branch - I have searched open and closed issues to ensure it has not already been reported.
MonoGame Version
MonoGame 3.8.1.303
Which MonoGame platform are you using?
MonoGame Windows Desktop Application (mgwindowsdx)
Operating System
Windows
Description
Can't create Effect in the runtime through constructor from the bytecode compiled by mgfxc.
See attached sample.
The effect creation code:
_effect = new Effect(GraphicsDevice, effectBytes);
It throws the exception.
The file TestEffect.mgdx11 contains the effect bytecode.
It was compiled created using following command:
mgfxc "TestEffect.fx" "TestEffect.mgdx11" /Profile:DirectX_11
The bug reproduces with both develop
and 3.8.1.303 versions.
The bug doesnt reproduce with DesktopGL. But only with WindowsDX.
Steps to Reproduce
Minimal Example Repo
No response
Expected Behavior
There shouldn't be an exception.
Resulting Behavior
SharpDX.SharpDXException: 'HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.
Images
Further research revealed that the problem lies in the effect using technique with profiles vs_4_0
/ps_4_0
.
If I change them to vs_4_0_level_9_1
/ps_4_0_level_9_1
(like stock effects do), then the problem goes away.
However those profiles belong to Shader Model 2.0.
While vs_4_0
/ps_4_0
belong to Shader Model 4.0 and have way more features.
Moreover shouldn't Monogame.WindowsDX properly support Shader Model 4.0(DirectX 10+)?
Hence keeping the issue open.
p.s. more info is here: https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-models
I've located the problem at least. One needs to explicitly pass GraphicsProfile.HiDef when creating the GraphicsDeviceManager in order for SM4 shaders to properly load.
Still keeping the issue open as the exception is quite vague and doesnt say anything about using the wrong GraphicsProfile.
The default profile should probably be changed to HiDef. It was left at Reach for direct XNA compatibility for the Windows Phone platform that Microsoft was pushing at the time of release in 2011, hence the default window size of 800 by 480.
The HiDef profile is designed for the highest performance and largest available set of graphic features. Use the HiDef profile to target hardware with more enhanced graphic capabilities such as an Xbox 360 and a Windows-based computer with at least a DirectX 10 GPU. More specifically, the HiDef profile requires a GPU with Xbox 360-level capabilities such as multiple render targets (MRT), floating-point surface formats, and per-vertex texture fetching.
From https://learn.microsoft.com/en-us/previous-versions/windows/xna/ff604995(v=xnagamestudio.41)
At this point in time, with the change to .Net6+
, any platform requiring the Reach profile has been obsoleted by that change alone.
Thoughts @harry-cpp?