mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-06 01:50:38 +00:00
D3D12 Pixel History state tracking.
* For capture resources, use the actual resource state at the time of the event rather than a hardcoded state. * When hardcoded RT source state was used, on UAV events attempting to transition a texture which was not created with the RTV flag from that state caused a device removal. * Includes a fix provided by Jake to ApplyBarriers that caused an incorrect state to be returned in this usage.
This commit is contained in:
committed by
Jake Turner
parent
9f4f0e6aa1
commit
dbfd1287cf
@@ -692,7 +692,7 @@ void D3D12ResourceManager::ApplyBarriers(BarrierSet &barriers,
|
||||
|
||||
auto it = states.find(id);
|
||||
if(it == states.end())
|
||||
return;
|
||||
continue;
|
||||
|
||||
SubresourceStateVector &st = it->second;
|
||||
|
||||
@@ -726,7 +726,7 @@ void D3D12ResourceManager::ApplyBarriers(BarrierSet &barriers,
|
||||
|
||||
auto it = states.find(id);
|
||||
if(it == states.end())
|
||||
return;
|
||||
continue;
|
||||
|
||||
SubresourceStateVector &st = it->second;
|
||||
|
||||
|
||||
@@ -698,6 +698,30 @@ protected:
|
||||
return targetIndex;
|
||||
}
|
||||
|
||||
D3D12_RESOURCE_STATES GetImageState(ID3D12Resource *target, uint32_t planeSlice,
|
||||
D3D12_RESOURCE_STATES fallback)
|
||||
{
|
||||
RDCASSERTMSG("This function is not meant for use with the non-capture resources.",
|
||||
target != m_CallbackInfo.colorImage && target != m_CallbackInfo.dsImage);
|
||||
|
||||
D3D12CommandData &cmdData = *m_pDevice->GetQueue()->GetCommandData();
|
||||
SubresourceStateVector targetStates =
|
||||
cmdData.m_BakedCmdListInfo[cmdData.m_LastCmdListID].GetState(m_pDevice, GetResID(target));
|
||||
|
||||
uint32_t baseMip = m_CallbackInfo.targetSubresource.mip;
|
||||
uint32_t baseSlice = m_CallbackInfo.targetSubresource.slice;
|
||||
|
||||
uint32_t subresource =
|
||||
D3D12CalcSubresource(baseMip, baseSlice, planeSlice, m_CallbackInfo.targetDesc.MipLevels,
|
||||
m_CallbackInfo.targetDesc.DepthOrArraySize);
|
||||
|
||||
if(targetStates.size() > subresource && targetStates[subresource].IsStates())
|
||||
{
|
||||
return targetStates[subresource].ToStates();
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
WrappedID3D12Device *m_pDevice;
|
||||
D3D12PixelHistoryShaderCache *m_ShaderCache;
|
||||
D3D12PixelHistoryCallbackInfo m_CallbackInfo;
|
||||
@@ -1093,18 +1117,20 @@ private:
|
||||
targetCopyParams.sample = m_CallbackInfo.targetSubresource.sample;
|
||||
targetCopyParams.mip = m_CallbackInfo.targetSubresource.mip;
|
||||
targetCopyParams.arraySlice = m_CallbackInfo.targetSubresource.slice;
|
||||
targetCopyParams.srcImageState = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
||||
targetCopyParams.multisampled = (m_CallbackInfo.targetDesc.SampleDesc.Count != 1);
|
||||
D3D12_RESOURCE_STATES fallback = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
||||
if(IsDepthFormat(m_CallbackInfo.targetDesc, m_CallbackInfo.compType))
|
||||
{
|
||||
targetCopyParams.srcImageState = m_SavedState.dsv.GetDSV().Flags & D3D12_DSV_FLAG_READ_ONLY_DEPTH
|
||||
? D3D12_RESOURCE_STATE_DEPTH_READ
|
||||
: D3D12_RESOURCE_STATE_DEPTH_WRITE;
|
||||
fallback = m_SavedState.dsv.GetDSV().Flags & D3D12_DSV_FLAG_READ_ONLY_DEPTH
|
||||
? D3D12_RESOURCE_STATE_DEPTH_READ
|
||||
: D3D12_RESOURCE_STATE_DEPTH_WRITE;
|
||||
targetCopyParams.srcImageFormat = GetDepthSRVFormat(m_CallbackInfo.targetDesc.Format, 0);
|
||||
targetCopyParams.depthcopy = true;
|
||||
targetCopyParams.copyFormat = GetDepthCopyFormat(m_CallbackInfo.targetDesc.Format);
|
||||
offset += offsetof(struct D3D12PixelHistoryValue, depth);
|
||||
}
|
||||
targetCopyParams.srcImageState =
|
||||
GetImageState(m_CallbackInfo.targetImage, targetCopyParams.planeSlice, fallback);
|
||||
|
||||
CopyImagePixel(cmd, targetCopyParams, offset);
|
||||
|
||||
@@ -1115,10 +1141,11 @@ private:
|
||||
GetDepthSRVFormat(m_CallbackInfo.targetImage->GetDesc().Format, 1);
|
||||
stencilCopyParams.copyFormat = DXGI_FORMAT_R8_TYPELESS;
|
||||
stencilCopyParams.planeSlice = 1;
|
||||
fallback = m_SavedState.dsv.GetDSV().Flags & D3D12_DSV_FLAG_READ_ONLY_STENCIL
|
||||
? D3D12_RESOURCE_STATE_DEPTH_READ
|
||||
: D3D12_RESOURCE_STATE_DEPTH_WRITE;
|
||||
stencilCopyParams.srcImageState =
|
||||
m_SavedState.dsv.GetDSV().Flags & D3D12_DSV_FLAG_READ_ONLY_STENCIL
|
||||
? D3D12_RESOURCE_STATE_DEPTH_READ
|
||||
: D3D12_RESOURCE_STATE_DEPTH_WRITE;
|
||||
GetImageState(m_CallbackInfo.targetImage, stencilCopyParams.planeSlice, fallback);
|
||||
CopyImagePixel(cmd, stencilCopyParams, offset + sizeof(float));
|
||||
}
|
||||
|
||||
@@ -1143,9 +1170,10 @@ private:
|
||||
depthCopyParams.srcImageFormat = GetDepthSRVFormat(depthFormat, 0);
|
||||
depthCopyParams.copyFormat = GetDepthCopyFormat(depthFormat);
|
||||
depthCopyParams.depthcopy = true;
|
||||
depthCopyParams.srcImageState = m_SavedState.dsv.GetDSV().Flags & D3D12_DSV_FLAG_READ_ONLY_DEPTH
|
||||
? D3D12_RESOURCE_STATE_DEPTH_READ
|
||||
: D3D12_RESOURCE_STATE_DEPTH_WRITE;
|
||||
fallback = m_SavedState.dsv.GetDSV().Flags & D3D12_DSV_FLAG_READ_ONLY_DEPTH
|
||||
? D3D12_RESOURCE_STATE_DEPTH_READ
|
||||
: D3D12_RESOURCE_STATE_DEPTH_WRITE;
|
||||
depthCopyParams.srcImageState = GetImageState(depthImage, depthCopyParams.planeSlice, fallback);
|
||||
CopyImagePixel(cmd, depthCopyParams, offset + offsetof(struct D3D12PixelHistoryValue, depth));
|
||||
|
||||
if(IsDepthAndStencilFormat(depthFormat))
|
||||
@@ -1153,10 +1181,11 @@ private:
|
||||
depthCopyParams.srcImageFormat = GetDepthSRVFormat(depthFormat, 1);
|
||||
depthCopyParams.copyFormat = DXGI_FORMAT_R8_TYPELESS;
|
||||
depthCopyParams.planeSlice = 1;
|
||||
fallback = m_SavedState.dsv.GetDSV().Flags & D3D12_DSV_FLAG_READ_ONLY_STENCIL
|
||||
? D3D12_RESOURCE_STATE_DEPTH_READ
|
||||
: D3D12_RESOURCE_STATE_DEPTH_WRITE;
|
||||
depthCopyParams.srcImageState =
|
||||
m_SavedState.dsv.GetDSV().Flags & D3D12_DSV_FLAG_READ_ONLY_STENCIL
|
||||
? D3D12_RESOURCE_STATE_DEPTH_READ
|
||||
: D3D12_RESOURCE_STATE_DEPTH_WRITE;
|
||||
GetImageState(depthImage, depthCopyParams.planeSlice, fallback);
|
||||
CopyImagePixel(cmd, depthCopyParams,
|
||||
offset + offsetof(struct D3D12PixelHistoryValue, stencil));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user