From 612c8fd76cc2ea3a802b8e3f2f78e8208afe06bc Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Fri, 11 Oct 2024 18:54:27 -0700 Subject: [PATCH] Fix DX12 Capture transition state handling for MSAA --- DirectXTex/DirectXTexD3D12.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/DirectXTex/DirectXTexD3D12.cpp b/DirectXTex/DirectXTexD3D12.cpp index f6e48d67..eba8281c 100644 --- a/DirectXTex/DirectXTexD3D12.cpp +++ b/DirectXTex/DirectXTexD3D12.cpp @@ -217,8 +217,11 @@ namespace bufferDesc.SampleDesc.Count = 1; ComPtr copySource(pSource); + D3D12_RESOURCE_STATES beforeStateSource = beforeState; if (desc.SampleDesc.Count > 1) { + TransitionResource(commandList.Get(), pSource, beforeState, D3D12_RESOURCE_STATE_RESOLVE_SOURCE); + // MSAA content must be resolved before being copied to a staging texture auto descCopy = desc; descCopy.SampleDesc.Count = 1; @@ -230,7 +233,7 @@ namespace &defaultHeapProperties, D3D12_HEAP_FLAG_NONE, &descCopy, - D3D12_RESOURCE_STATE_COPY_DEST, + D3D12_RESOURCE_STATE_RESOLVE_DEST, nullptr, IID_GRAPHICS_PPV_ARGS(pTemp.GetAddressOf())); if (FAILED(hr)) @@ -267,6 +270,11 @@ namespace } copySource = pTemp; + beforeState = D3D12_RESOURCE_STATE_RESOLVE_DEST; + } + else + { + beforeStateSource = D3D12_RESOURCE_STATE_COPY_SOURCE; } // Create a staging texture @@ -283,7 +291,7 @@ namespace assert(*pStaging); // Transition the resource if necessary - TransitionResource(commandList.Get(), pSource, beforeState, D3D12_RESOURCE_STATE_COPY_SOURCE); + TransitionResource(commandList.Get(), copySource.Get(), beforeState, D3D12_RESOURCE_STATE_COPY_SOURCE); // Get the copy target location for (UINT j = 0; j < numberOfResources; ++j) @@ -293,8 +301,8 @@ namespace commandList->CopyTextureRegion(©Dest, 0, 0, 0, ©Src, nullptr); } - // Transition the resource to the next state - TransitionResource(commandList.Get(), pSource, D3D12_RESOURCE_STATE_COPY_SOURCE, afterState); + // Transition the source resource to the next state + TransitionResource(commandList.Get(), pSource, beforeStateSource, afterState); hr = commandList->Close(); if (FAILED(hr))