I finally have a solution!
For the sake of future generations, I will describe the details.
・Symptoms
MonoGame: After updating from Ver 3.8.0.1641 to 3.8.1.303, a mysterious exception appears.
The exception is output to VisualStudio’s OutPut Window, but the game does not stop and drawing is fine.
Exception thrown: ‘SharpDX.SharpDXException’ (in SharpDX.Direct3D11.dll)
Different GPUs behave differently
nVidia RTX 3060Ti : exception throw
nVidia GTX 1650 : no problem
・Solution
As taught by persn
In VS2022 Debug → Window → Exception Settings
SharpDX.SharpDXException in the Commond Language Runtine Exception setting.
Call Stack
SharpDX.Direct3D11.dll!SharpDX.Direct3D11.Device.CreateInputLayout(SharpDX.Direct3D11.InputElement[] inputElementDescsRef, int numElements, System.IntPtr shaderBytecodeWithInputSignatureRef, SharpDX.PointerSize bytecodeLength, SharpDX.Direct3D11.InputLayout inputLayoutOut)
SharpDX.Direct3D11.dll!SharpDX.Direct3D11.InputLayout.InputLayout(SharpDX.Direct3D11.Device device, byte[] shaderBytecode, SharpDX.Direct3D11.InputElement[] elements)
MonoGame.Framework.dll!Microsoft.Xna.Framework.Graphics.InputLayoutCache.GetOrCreate(Microsoft.Xna.Framework.Graphics.VertexBufferBindings vertexBuffers)
MonoGame.Framework.dll!Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformApplyState(bool applyShaders)
MonoGame.Framework.dll!Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformDrawIndexedPrimitives(Microsoft.Xna.Framework.Graphics.PrimitiveType primitiveType, int baseVertex, int startIndex, int primitiveCount)
MonoGame.Framework.dll!Microsoft.Xna.Framework.Graphics.GraphicsDevice.DrawIndexedPrimitives(Microsoft.Xna.Framework.Graphics.PrimitiveType primitiveType, int baseVertex, int startIndex, int primitiveCount)
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, PrimitiveNum);
Debugger Information
Exception thrown: 'SharpDX.SharpDXException' (in SharpDX.Direct3D11.dll)
HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: wrong parameter.
Following up, there seems to be no problem with the various settings before drawing.
Investigating the shaders, we find
I noticed a mistake in the Position semantics of VertexShader’s Input!
struct VS_INPUT_PNC
{
// float4 m_f4Pos : SV_POSITION; //exception throw
↓
float4 m_f4Pos : POSITION0; //ok
};
It was a small mistake, sorry.
Thanks for all your help!
in Japanese
やっと解決が出来ました!
後進の為に、詳細を記載しておきます。
・症状
MonoGame:Ver 3.8.0.1641 → 3.8.1.303 にアップデートすると、謎の例外が出るように。
例外はVisualStudioのOutPut Window に出力されるが、ゲームは止まらないし描画も問題ない。
例外がスローされました: ‘SharpDX.SharpDXException’ (SharpDX.Direct3D11.dll の中)
GPUによって挙動が違う
nVidia RTX 3060Ti :例外
nVidia GTX 1650 :問題なし
・解決方法
persn さん に教えてもらった、
VS2022のデバッグ → ウィンドウ → 例外設定にて、
Commond Language Runtine Exception の、SharpDX.SharpDXException にチェックを入れて調査
コールスタック
SharpDX.Direct3D11.dll!SharpDX.Direct3D11.Device.CreateInputLayout(SharpDX.Direct3D11.InputElement[] inputElementDescsRef, int numElements, System.IntPtr shaderBytecodeWithInputSignatureRef, SharpDX.PointerSize bytecodeLength, SharpDX.Direct3D11.InputLayout inputLayoutOut)
SharpDX.Direct3D11.dll!SharpDX.Direct3D11.InputLayout.InputLayout(SharpDX.Direct3D11.Device device, byte[] shaderBytecode, SharpDX.Direct3D11.InputElement[] elements)
MonoGame.Framework.dll!Microsoft.Xna.Framework.Graphics.InputLayoutCache.GetOrCreate(Microsoft.Xna.Framework.Graphics.VertexBufferBindings vertexBuffers)
MonoGame.Framework.dll!Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformApplyState(bool applyShaders)
MonoGame.Framework.dll!Microsoft.Xna.Framework.Graphics.GraphicsDevice.PlatformDrawIndexedPrimitives(Microsoft.Xna.Framework.Graphics.PrimitiveType primitiveType, int baseVertex, int startIndex, int primitiveCount)
MonoGame.Framework.dll!Microsoft.Xna.Framework.Graphics.GraphicsDevice.DrawIndexedPrimitives(Microsoft.Xna.Framework.Graphics.PrimitiveType primitiveType, int baseVertex, int startIndex, int primitiveCount)
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, PrimitiveNum);
デバッガー情報
例外がスローされました: 'SharpDX.SharpDXException' (SharpDX.Direct3D11.dll の中)
HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: パラメーターが間違っています。
追って行くと、描画前までの各種設定には問題が無さそう。
シェーダーを調査すると、
VertexShaderのInputのPositionセマンティクスの間違いに気がついた!
struct VS_INPUT_PNC
{
// float4 m_f4Pos : SV_POSITION; //例外
↓
float4 m_f4Pos : POSITION0; //ok
};
ちょっとしたミスでした、ゴメンネ!
助けてくださった皆様、有難う!