Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed state transitions for MSAA ScreenGrab #267

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Src/ScreenGrab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,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 @@ -136,7 +139,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 @@ -166,6 +169,11 @@ namespace
}

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

// Create a staging texture
Expand All @@ -191,7 +199,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
D3D12_PLACED_SUBRESOURCE_FOOTPRINT bufferFootprint = {};
Expand All @@ -207,8 +215,8 @@ namespace
// Copy the texture
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
Loading