amerkoleci / Vortice.Windows

.NET bindings for Direct3D12, Direct3D11, WIC, Direct2D1, XInput, XAudio, X3DAudio, DXC, Direct3D9 and DirectInput.
MIT License
1.01k stars 73 forks source link

CreateBlendState1 Error - .NET 5.0 not supported. #295

Closed h1cks closed 2 years ago

h1cks commented 2 years ago

Updated my project to the latest vortice, CreateBlendState1 is throwing an error

Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Stack trace is

at Vortice.Direct3D11.BlendDescription1.__MarshalTo(__Native& ref) at Vortice.Direct3D11.ID3D11Device1.CreateBlendState1(BlendDescription1 blendStateDesc) at GraphicsCore.Insane3d.BlendStateList.AddState(ID3D11Device1 d3dDevice, String key, BlendDescription1 desc) in E:\Development\Pacific Strafe\GraphicsCore\Code\BlendStateList.cs:line 34 at Insane3D.RenderManager.CreateBlendStates(ID3D11Device1 d3dDevice) in E:\Development\Pacific Strafe\Pacific Strafe\Code\Core Classes\Managers\RenderManager.Configuration.cs:line 44 at Insane3D.RenderManager.InitialSetup(ID3D11Device1 d3dDevice, ID3D11DeviceContext1 deviceContext, GameManagerContainer gameManagerContainer, DirectXContainer directXContainer) in E:\Development\Pacific Strafe\Pacific Strafe\Code\Core Classes\Managers\RenderManager.cs:line 232 at Strafe.GameApplication.PreIntroGameData() in E:\Development\Pacific Strafe\Pacific Strafe\Code\Strafe Game Logic\GameApplication.GameStates.cs:line 482 at Strafe.GameApplication.ImmediateLevelDebug(ID3D11Device1 D3Ddevice) in E:\Development\Pacific Strafe\Pacific Strafe\Code\Strafe Game Logic\GameApplication.GameStates.cs:line 55 at Strafe.GameApplication.ApplicationMainLoop(ID3D11Device1 D3Ddevice) in E:\Development\Pacific Strafe\Pacific Strafe\Code\Strafe Game Logic\GameApplication.GameStates.cs:line 118 at Strafe.GameApplication.RenderCallback() in E:\Development\Pacific Strafe\Pacific Strafe\Code\Strafe Game Logic\GameApplication.GameStates.cs:line 44 at Insane3D.RenderLoop.Run(Control form, RenderCallback renderCallback, Boolean useApplicationDoEvents) in E:\Development\Pacific Strafe\Pacific Strafe\Code\Core Classes\Helpers\RenderLoop.cs:line 198 at Strafe.Program.Main(String[] args) in E:\Development\Pacific Strafe\Pacific Strafe\Code\Program.cs:line 83

The blendstate I created was:

   BlendDescription1 blendStateDescription_;
    blendStateDescription_ = new BlendDescription1()
    {
        AlphaToCoverageEnable = false
    };
    blendStateDescription_.RenderTarget[0].IsBlendEnabled = true;
    blendStateDescription_.RenderTarget[0].SourceBlend = Blend.SourceAlpha;
    blendStateDescription_.RenderTarget[0].DestinationBlend = Blend.InverseSourceAlpha; //
    blendStateDescription_.RenderTarget[0].BlendOperation = D3D11.BlendOperation.Add;
    blendStateDescription_.RenderTarget[0].SourceBlendAlpha = Blend.One; //Zero
    blendStateDescription_.RenderTarget[0].DestinationBlendAlpha = Blend.Zero;
    blendStateDescription_.RenderTarget[0].BlendOperationAlpha = D3D11.BlendOperation.Add;
    blendStateDescription_.RenderTarget[0].RenderTargetWriteMask = ColorWriteEnable.All;

Will close is this is a usage issue.

amerkoleci commented 2 years ago

Not sure what CompilerServices.Unsafe has to do with the issue, make sure you can create and example application so I can reproduce it

h1cks commented 2 years ago

I am running under .net 5.

Might up to 6.

h1cks commented 2 years ago

@amerkoleci Update: Moving from .NET 5 to 6 fixed it.

h1cks commented 2 years ago

@amerkoleci found the issue, I was running under .NET 5.0

The __MarshalTo looks like a .NET 6.0 function. I checked the stack and found "Feature not supported" on that function.

h1cks commented 2 years ago

Issue is .net 5.0 vs .net 6.0. Simply compiling my game under .net 5.0 I could reproduce.

Axiverse commented 2 years ago

The current targets are netstandard 2.0 and net 6.0. Idk if net 5.0 would try to use the netstandard library. Upgrading may be the best path.

amerkoleci commented 2 years ago

The current targets are netstandard 2.0 and net 6.0. Idk if net 5.0 would try to use the netstandard library. Upgrading may be the best path.

Totally agree

h1cks commented 2 years ago

I will update. More an issue of whether it can enforced minimum version of .net

SuRGeoNix commented 2 years ago

I remember facing this issue with .NET and I just had to upgrade the package System.Runtime.CompilerServices.Unsafe to ver.6.