From 4169320f416bce0fea1993b1e7fc4cfedebb9509 Mon Sep 17 00:00:00 2001 From: arturo Date: Thu, 14 Sep 2023 17:09:11 +0200 Subject: [PATCH] Fix DX11 shared textures Right now creating a texture from a native texture with D3D11_RESOURCE_MISC_SHARED_NTHANDLE will fail unless it is also D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX. This combination is recomended but not mandatory acording to the specification: https://learn.microsoft.com/en-us/windows/win32/api/d3d11/ne-d3d11-d3d11_resource_misc_flag --- .../Direct3D/Texture.Direct3D.cs | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/sources/engine/Stride.Graphics/Direct3D/Texture.Direct3D.cs b/sources/engine/Stride.Graphics/Direct3D/Texture.Direct3D.cs index 791be0e28f..c20cde0913 100644 --- a/sources/engine/Stride.Graphics/Direct3D/Texture.Direct3D.cs +++ b/sources/engine/Stride.Graphics/Direct3D/Texture.Direct3D.cs @@ -175,25 +175,26 @@ private void InitializeFromImpl(DataBox[] dataBoxes = null) NativeRenderTargetView = GetRenderTargetView(ViewType, ArraySlice, MipLevel); NativeDepthStencilView = GetDepthStencilView(out HasStencil); - switch (textureDescription.Options) + if (textureDescription.Options == TextureOptions.None) { - case TextureOptions.None: - SharedHandle = IntPtr.Zero; - break; - case TextureOptions.Shared: - var sharedResource = NativeDeviceChild.QueryInterface(); - SharedHandle = sharedResource.SharedHandle; - break; + SharedHandle = IntPtr.Zero; + } #if STRIDE_GRAPHICS_API_DIRECT3D11 - case TextureOptions.SharedNthandle | TextureOptions.SharedKeyedmutex: - var sharedResource1 = NativeDeviceChild.QueryInterface(); - var uniqueName = "Stride:" + Guid.NewGuid().ToString(); - SharedHandle = sharedResource1.CreateSharedHandle(uniqueName, SharpDX.DXGI.SharedResourceFlags.Write); - SharedNtHandleName = uniqueName; - break; + else if ((textureDescription.Options & TextureOptions.SharedNthandle) != 0) + { + var sharedResource1 = NativeDeviceChild.QueryInterface(); + var uniqueName = "Stride:" + Guid.NewGuid().ToString(); + SharedHandle = sharedResource1.CreateSharedHandle(uniqueName, SharpDX.DXGI.SharedResourceFlags.Write); + SharedNtHandleName = uniqueName; + } #endif - default: - throw new ArgumentOutOfRangeException("textureDescription.Options"); + else if ((textureDescription.Options & TextureOptions.Shared) != 0) { + var sharedResource = NativeDeviceChild.QueryInterface(); + SharedHandle = sharedResource.SharedHandle; + } + else + { + throw new ArgumentOutOfRangeException("textureDescription.Options"); } }