Skip to content

DirectX fatal error on almost every method on x86 #731

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

Closed
lindexi opened this issue Dec 23, 2021 · 5 comments · Fixed by #734
Closed

DirectX fatal error on almost every method on x86 #731

lindexi opened this issue Dec 23, 2021 · 5 comments · Fixed by #734
Assignees
Labels
Milestone

Comments

@lindexi
Copy link
Member

lindexi commented Dec 23, 2021

Summary

Running the code with x86 PlatformTarget will fatal error:

using D3D11 = Silk.NET.Direct3D11;
using D3D9 = Silk.NET.Direct3D9;
using DXGI = Silk.NET.DXGI;

            var width = 1000;
            var height = 1000;

            var texture2DDesc = new D3D11.Texture2DDesc()
            {
                BindFlags = (uint) (D3D11.BindFlag.BindRenderTarget | D3D11.BindFlag.BindShaderResource),
                Format = DXGI.Format.FormatB8G8R8A8Unorm,
                Width = (uint) width,
                Height = (uint) height,
                MipLevels = 1,
                SampleDesc = new DXGI.SampleDesc(1, 0),
                Usage = D3D11.Usage.UsageDefault,
                MiscFlags = (uint) D3D11.ResourceMiscFlag.ResourceMiscShared,
                // The D3D11_RESOURCE_MISC_FLAG cannot be used when creating resources with D3D11_CPU_ACCESS flags.
                CPUAccessFlags = 0, //(uint) D3D11.CpuAccessFlag.None,
                ArraySize = 1
            };

            D3D11.ID3D11Device* pD3D11Device;
            D3D11.ID3D11DeviceContext* pD3D11DeviceContext;
            D3DFeatureLevel pD3DFeatureLevel = default;
            D3D11.D3D11 d3D11 = D3D11.D3D11.GetApi();

            var hr = d3D11.CreateDevice((DXGI.IDXGIAdapter*) IntPtr.Zero, D3DDriverType.D3DDriverTypeHardware,
                Software: 0,
                Flags: (uint) D3D11.CreateDeviceFlag.CreateDeviceBgraSupport,
                (D3DFeatureLevel*) IntPtr.Zero,
                FeatureLevels: 0, // D3DFeatureLevel 的长度
                SDKVersion: 7,
                (D3D11.ID3D11Device**) &pD3D11Device,
                ref pD3DFeatureLevel,
                (D3D11.ID3D11DeviceContext**) &pD3D11DeviceContext
            );

Steps to reproduce

  • Platform: Desktop
  • Framework Version: ALL
  • API: DirectX
  • API Version: All

Demo: https://github.com/lindexi/lindexi_gd/tree/cf6880ecd807f19d54da45566ac56bd23016ce18/RawluharkewalQeaninanel/RawluharkewalQeaninanel

Comments

The main reason is the Cdecl and Stdcall issues, such as the code:

((delegate* unmanaged[Cdecl]<ID3D11Device*, BufferDesc*, SubresourceData*, ID3D11Buffer**, int>)LpVtbl[3])(@this, pDesc, pInitialData, ppBufferPtr);

We should not use Cdecl key word, because the DirectX define is __stdcall.

#define STDMETHOD(method)        virtual COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE method
#define STDMETHOD_(type,method)  virtual COM_DECLSPEC_NOTHROW type STDMETHODCALLTYPE method
#define STDMETHODV(method)       virtual COM_DECLSPEC_NOTHROW HRESULT STDMETHODVCALLTYPE method
#define STDMETHODV_(type,method) virtual COM_DECLSPEC_NOTHROW type STDMETHODVCALLTYPE method

#define STDMETHODCALLTYPE       __stdcall

We must update all the DirectX method call with Stdcall

See #583 #663

@lindexi lindexi added the bug Something isn't working label Dec 23, 2021
lindexi added a commit to lindexi/lindexi_gd that referenced this issue Dec 23, 2021
@Perksey
Copy link
Member

Perksey commented Dec 23, 2021

I'll attempt to fix this, but note that D3D9 is one of two of our bindings that are explicitly unsupported on x86.

If the fix proves to difficult this'll probably have to be community-championed or sponsored work using the GitHub Sponsors mechanism, as I fear it's just going to be easier to drop x86 support.

Again, I'll give it a shot, but don't expect much. Not going to the moon and back for x86.

@lindexi
Copy link
Member Author

lindexi commented Dec 24, 2021

Thank you, @Perksey

And can I add the WPF control demo with Silk.NET DirectX ?

See #441

@Perksey
Copy link
Member

Perksey commented Dec 24, 2021

This isn’t something we officially support today.

@lindexi
Copy link
Member Author

lindexi commented Dec 24, 2021

Thank you @Perksey

@lindexi
Copy link
Member Author

lindexi commented Jan 8, 2022

Thank you @Perksey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants