Skip to content

Commit 612c8fd

Browse files
committed
Fix DX12 Capture transition state handling for MSAA
1 parent 6ec5d2d commit 612c8fd

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

DirectXTex/DirectXTexD3D12.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,11 @@ namespace
217217
bufferDesc.SampleDesc.Count = 1;
218218

219219
ComPtr<ID3D12Resource> copySource(pSource);
220+
D3D12_RESOURCE_STATES beforeStateSource = beforeState;
220221
if (desc.SampleDesc.Count > 1)
221222
{
223+
TransitionResource(commandList.Get(), pSource, beforeState, D3D12_RESOURCE_STATE_RESOLVE_SOURCE);
224+
222225
// MSAA content must be resolved before being copied to a staging texture
223226
auto descCopy = desc;
224227
descCopy.SampleDesc.Count = 1;
@@ -230,7 +233,7 @@ namespace
230233
&defaultHeapProperties,
231234
D3D12_HEAP_FLAG_NONE,
232235
&descCopy,
233-
D3D12_RESOURCE_STATE_COPY_DEST,
236+
D3D12_RESOURCE_STATE_RESOLVE_DEST,
234237
nullptr,
235238
IID_GRAPHICS_PPV_ARGS(pTemp.GetAddressOf()));
236239
if (FAILED(hr))
@@ -267,6 +270,11 @@ namespace
267270
}
268271

269272
copySource = pTemp;
273+
beforeState = D3D12_RESOURCE_STATE_RESOLVE_DEST;
274+
}
275+
else
276+
{
277+
beforeStateSource = D3D12_RESOURCE_STATE_COPY_SOURCE;
270278
}
271279

272280
// Create a staging texture
@@ -283,7 +291,7 @@ namespace
283291
assert(*pStaging);
284292

285293
// Transition the resource if necessary
286-
TransitionResource(commandList.Get(), pSource, beforeState, D3D12_RESOURCE_STATE_COPY_SOURCE);
294+
TransitionResource(commandList.Get(), copySource.Get(), beforeState, D3D12_RESOURCE_STATE_COPY_SOURCE);
287295

288296
// Get the copy target location
289297
for (UINT j = 0; j < numberOfResources; ++j)
@@ -293,8 +301,8 @@ namespace
293301
commandList->CopyTextureRegion(&copyDest, 0, 0, 0, &copySrc, nullptr);
294302
}
295303

296-
// Transition the resource to the next state
297-
TransitionResource(commandList.Get(), pSource, D3D12_RESOURCE_STATE_COPY_SOURCE, afterState);
304+
// Transition the source resource to the next state
305+
TransitionResource(commandList.Get(), pSource, beforeStateSource, afterState);
298306

299307
hr = commandList->Close();
300308
if (FAILED(hr))

0 commit comments

Comments
 (0)