Merge pull request #360 from Sergio0694/dev/fix-command-list-gc-holes
Fix GC holes in CommandList and GraphicsDevice execute logic
このコミットが含まれているのは:
2ファイル変更
+18
-8
検索条件に一致するファイルはありません
@@ -48,8 +48,8 @@ internal unsafe struct CommandList : IDisposable
|
||||
|
||||
device.GetCommandListAndAllocator(
|
||||
d3D12CommandListType,
|
||||
out *(ID3D12GraphicsCommandList**)Unsafe.AsPointer(ref this.d3D12GraphicsCommandList),
|
||||
out *(ID3D12CommandAllocator**)Unsafe.AsPointer(ref this.d3D12CommandAllocator));
|
||||
out this.d3D12GraphicsCommandList.GetPinnableReference(),
|
||||
out this.d3D12CommandAllocator.GetPinnableReference());
|
||||
|
||||
// Set the heap descriptor if the command list is not for copy operations
|
||||
if (d3D12CommandListType is not D3D12_COMMAND_LIST_TYPE_COPY)
|
||||
@@ -73,8 +73,8 @@ internal unsafe struct CommandList : IDisposable
|
||||
|
||||
device.GetCommandListAndAllocator(
|
||||
d3D12PipelineState,
|
||||
out *(ID3D12GraphicsCommandList**)Unsafe.AsPointer(ref this.d3D12GraphicsCommandList),
|
||||
out *(ID3D12CommandAllocator**)Unsafe.AsPointer(ref this.d3D12CommandAllocator));
|
||||
out this.d3D12GraphicsCommandList.GetPinnableReference(),
|
||||
out this.d3D12CommandAllocator.GetPinnableReference());
|
||||
|
||||
// Set the heap descriptor for the command list
|
||||
device.SetDescriptorHeapForCommandList(this.d3D12GraphicsCommandList);
|
||||
@@ -125,9 +125,13 @@ internal unsafe struct CommandList : IDisposable
|
||||
/// </summary>
|
||||
/// <returns>A double pointer to the current <see cref="ID3D12CommandList"/> object to execute.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly ID3D12CommandList** GetD3D12CommandListAddressOf()
|
||||
public readonly ref ID3D12CommandList* GetD3D12CommandListPinnableAddressOf()
|
||||
{
|
||||
return (ID3D12CommandList**)this.d3D12GraphicsCommandList.GetAddressOf();
|
||||
// This method should return a ref ID3D12CommandList*, so it can't just call this.d3D12GraphicsCommandList.GetPinnableReference().
|
||||
// That would return a ref ID3D12GraphicsCommandList*, and there's currently no way to cast that without wasting performance (ie.
|
||||
// a function pointer cast and calli is needed). Instead, we can reinterpret the reference to the field, and then just call
|
||||
// GetPinnableReference() on the new reference, which this time will return the ref ID3D12CommandList* we wanted.
|
||||
return ref Unsafe.As<ComPtr<ID3D12GraphicsCommandList>, ComPtr<ID3D12CommandList>>(ref Unsafe.AsRef(in this.d3D12GraphicsCommandList)).GetPinnableReference();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -67,7 +67,10 @@ unsafe partial class GraphicsDevice
|
||||
}
|
||||
|
||||
// Execute the command list
|
||||
d3D12CommandQueue->ExecuteCommandLists(1, commandList.GetD3D12CommandListAddressOf());
|
||||
fixed (ID3D12CommandList** d3D12CommandList = &commandList.GetD3D12CommandListPinnableAddressOf())
|
||||
{
|
||||
d3D12CommandQueue->ExecuteCommandLists(1, d3D12CommandList);
|
||||
}
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
ulong updatedFenceValue = Interlocked.Increment(ref d3D12FenceValue);
|
||||
@@ -98,7 +101,10 @@ unsafe partial class GraphicsDevice
|
||||
internal ValueTask ExecuteCommandListAsync(ref CommandList commandList)
|
||||
{
|
||||
// Execute the command list
|
||||
this.d3D12ComputeCommandQueue.Get()->ExecuteCommandLists(1, commandList.GetD3D12CommandListAddressOf());
|
||||
fixed (ID3D12CommandList** d3D12CommandList = &commandList.GetD3D12CommandListPinnableAddressOf())
|
||||
{
|
||||
this.d3D12ComputeCommandQueue.Get()->ExecuteCommandLists(1, d3D12CommandList);
|
||||
}
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
ulong updatedFenceValue = Interlocked.Increment(ref this.nextD3D12ComputeFenceValue);
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする