From 902d1a50a312350c908f5486f3a0b597f0bec525 Mon Sep 17 00:00:00 2001 From: routersys Date: Fri, 17 Jul 2026 08:26:57 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E5=89=B2=E5=BD=93=E3=83=87=E3=82=A3?= =?UTF-8?q?=E3=82=B9=E3=82=AF=E3=83=AA=E3=83=97=E3=82=BF=E3=81=AE=E8=BF=94?= =?UTF-8?q?=E5=8D=B4=E3=82=92=E7=84=A1=E8=A6=96=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ID3D12DescriptorHandleAllocator.cs | 9 +++++++- .../InteropServicesTests.Sharing.cs | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12DescriptorHandleAllocator.cs b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12DescriptorHandleAllocator.cs index 3afef990..dd1b884f 100644 --- a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12DescriptorHandleAllocator.cs +++ b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12DescriptorHandleAllocator.cs @@ -108,6 +108,13 @@ internal unsafe struct ID3D12DescriptorHandleAllocator : IDisposable /// The returned value. public void Return(in ID3D12ResourceDescriptorHandles d3D12ResourceDescriptorHandles) { + if (d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandle.ptr == 0 && + d3D12ResourceDescriptorHandles.D3D12GpuDescriptorHandle.ptr == 0 && + d3D12ResourceDescriptorHandles.D3D12CpuDescriptorHandleNonShaderVisible.ptr == 0) + { + return; + } + lock (this.d3D12DescriptorHandlePairs) { default(InvalidOperationException).ThrowIf(this.size >= DescriptorsPerHeap); @@ -129,4 +136,4 @@ internal unsafe struct ID3D12DescriptorHandleAllocator : IDisposable this.d3D12DescriptorHeap.Dispose(); this.d3D12DescriptorHeapNonShaderVisible.Dispose(); } -} \ No newline at end of file +} diff --git a/tests/ComputeSharp.Tests/InteropServicesTests.Sharing.cs b/tests/ComputeSharp.Tests/InteropServicesTests.Sharing.cs index 2e9c323e..175a5790 100644 --- a/tests/ComputeSharp.Tests/InteropServicesTests.Sharing.cs +++ b/tests/ComputeSharp.Tests/InteropServicesTests.Sharing.cs @@ -2,6 +2,7 @@ using System; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; +using ComputeSharp.Graphics.Commands.Interop; using ComputeSharp.Interop; using ComputeSharp.Tests.Attributes; using ComputeSharp.Tests.Extensions; @@ -16,6 +17,26 @@ public unsafe partial class InteropServicesTests [DllImport("kernel32", ExactSpelling = true)] private static extern int CloseHandle(nint hObject); + [CombinatorialTestMethod] + [AllDevices] + public void DescriptorHandleAllocator_DefaultReturnIsIgnoredAndDuplicateReturnThrows(Device device) + { + ID3D12DescriptorHandleAllocator allocator = new(device.Get().D3D12Device); + + try + { + allocator.Return(default); + allocator.Rent(out ID3D12ResourceDescriptorHandles handles); + allocator.Return(in handles); + + Assert.ThrowsExactly(() => allocator.Return(in handles)); + } + finally + { + allocator.Dispose(); + } + } + [CombinatorialTestMethod] [AllDevices] public void SharedReadWriteTexture2D_ComputeShaderRoundTrip(Device device)