Created
October 14, 2023 17:00
-
-
Save lostmsu/a967d68f4a787e99dfe35d977720d1d6 to your computer and use it in GitHub Desktop.
reproduces wglDXOpenDeviceNV ERROR_OPEN_FAILED inside Sandbox with NVidia GPU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ComponentModel; | |
using System.Runtime.InteropServices; | |
using SharpDX.Direct3D11; | |
using Silk.NET.Core.Contexts; | |
using Silk.NET.GLFW; | |
using Silk.NET.OpenGL; | |
using Silk.NET.WGL; | |
using Silk.NET.WGL.Extensions.NV; | |
using Silk.NET.Windowing; | |
var window = Window.Create(WindowOptions.Default with { | |
Title = "Silk.NET DXInterop Test", | |
Size = new(1280, 720) | |
}); | |
window.Load += () => { | |
var gl = GL.GetApi(window); | |
var wgl = new WGL(gl.Context); | |
unsafe { | |
var glfw = Glfw.GetApi(); | |
var context = new LamdaNativeContext(glfw.GetProcAddress); | |
var dxInterop = new NVDXInterop(context); | |
int? index = args.Length > 0 ? int.Parse(args[0]) : null; | |
Console.WriteLine($"{gl.GetStringS(StringName.Renderer)}\n#{index}\n"); | |
using var factory = new SharpDX.DXGI.Factory1(); | |
Device device; | |
var adapters = factory.Adapters; | |
if (index is { } i) adapters = new[] { adapters[i] }; | |
Console.WriteLine($"Adapters: #{index} of {adapters.Length}"); | |
foreach (var adapter in adapters) { | |
Console.WriteLine($"{adapter.Description.Description}"); | |
device = new(adapter, DeviceCreationFlags.BgraSupport); | |
Marshal.SetLastSystemError(0); | |
Marshal.SetLastPInvokeError(0); | |
nint handle = dxInterop.DxopenDevice((void*)device.NativePointer); | |
if (handle == 0) { | |
int error = Marshal.GetLastSystemError(); | |
if (error == 0) error = Marshal.GetLastPInvokeError(); | |
device.Dispose(); | |
Console.Error.WriteLine($"{error}: {new Win32Exception(error).Message}"); | |
} else { | |
Console.WriteLine($"OK: {handle}"); | |
break; | |
} | |
Console.WriteLine(); | |
} | |
window.Close(); | |
} | |
}; | |
window.Run(); | |
window.Dispose(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework> | |
<RootNamespace>GLDX_Sandbox</RootNamespace> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="SharpDX.Direct3D11" Version="4.2.0" /> | |
<PackageReference Include="Silk.NET.OpenGL" Version="2.17.1" /> | |
<PackageReference Include="Silk.NET.WGL.Extensions.NV" Version="2.17.1" /> | |
<PackageReference Include="Silk.NET.Windowing.Glfw" Version="2.17.1" /> | |
</ItemGroup> | |
</Project> |
Prints:
NVIDIA GeForce RTX 3090
-1073282962: Unknown error (0xc007006e)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires .NET 6 desktop runtime and the latest vcredist_x64 be installed inside the Sandbox.