Skip to content

Commit

Permalink
Fix DX12 Capture transition state handling for MSAA
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Oct 12, 2024
1 parent 6ec5d2d commit 612c8fd
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions DirectXTex/DirectXTexD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,11 @@ namespace
bufferDesc.SampleDesc.Count = 1;

ComPtr<ID3D12Resource> 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;
Expand All @@ -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))
Expand Down Expand Up @@ -267,6 +270,11 @@ namespace
}

copySource = pTemp;
beforeState = D3D12_RESOURCE_STATE_RESOLVE_DEST;
}
else
{
beforeStateSource = D3D12_RESOURCE_STATE_COPY_SOURCE;
}

// Create a staging texture
Expand All @@ -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)
Expand All @@ -293,8 +301,8 @@ namespace
commandList->CopyTextureRegion(&copyDest, 0, 0, 0, &copySrc, 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))
Expand Down

0 comments on commit 612c8fd

Please sign in to comment.