Skip to content

Commit

Permalink
Add D3D12 pixel history depth bounds test.
Browse files Browse the repository at this point in the history
* Copied from the Vulkan implementation.
  • Loading branch information
jristic authored and Zorro666 committed Jan 2, 2024
1 parent 71a5d3d commit 3d5ce05
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions renderdoc/driver/d3d12/d3d12_pixelhistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,19 @@ struct D3D12TestsFailedCallback : public D3D12PixelHistoryCallback
uint32_t eventFlags = CalculateEventFlags(pipeState);
m_EventFlags[eid] = eventFlags;

WrappedID3D12PipelineState *origPSO =
m_pDevice->GetResourceManager()->GetCurrentAs<WrappedID3D12PipelineState>(pipeState.pipe);
if(origPSO == NULL)
RDCERR("Failed to retrieve original PSO for pixel history.");

D3D12_EXPANDED_PIPELINE_STATE_STREAM_DESC pipeDesc;
origPSO->Fill(pipeDesc);

if(pipeDesc.DepthStencilState.DepthBoundsTestEnable)
m_EventDepthBounds[eid] = {pipeState.depthBoundsMin, pipeState.depthBoundsMax};
else
m_EventDepthBounds[eid] = {};

// TODO: figure out if the shader has early fragments tests turned on,
// based on the currently bound fragment shader.
bool earlyFragmentTests = false;
Expand Down Expand Up @@ -1311,6 +1324,13 @@ struct D3D12TestsFailedCallback : public D3D12PixelHistoryCallback
RDCERR("Can't find event flags for event %u", eventId);
return it->second;
}
rdcpair<float, float> GetEventDepthBounds(uint32_t eventId)
{
auto it = m_EventDepthBounds.find(eventId);
if(it == m_EventDepthBounds.end())
RDCERR("Can't find event flags for event %u", eventId);
return it->second;
}

void FetchOcclusionResults()
{
Expand Down Expand Up @@ -1765,6 +1785,7 @@ struct D3D12TestsFailedCallback : public D3D12PixelHistoryCallback
rdcarray<uint32_t> m_Events;
// Key is event ID, value is the flags for that event.
std::map<uint32_t, uint32_t> m_EventFlags;
std::map<uint32_t, rdcpair<float, float>> m_EventDepthBounds;
// Key is a pair <Base pipeline, pipeline flags>
std::map<rdcpair<ResourceId, uint32_t>, ID3D12PipelineState *> m_PipeCache;
// Key: pair <event ID, test>
Expand Down Expand Up @@ -3056,6 +3077,13 @@ rdcarray<PixelModification> D3D12Replay::PixelHistory(rdcarray<EventUsage> event

if(!passed)
history[h].depthTestFailed = true;

rdcpair<float, float> depthBounds = tfCb->GetEventDepthBounds(history[h].eventId);

if((history[h].preMod.depth < depthBounds.first ||
history[h].preMod.depth > depthBounds.second) &&
depthBounds.second > depthBounds.first)
history[h].depthBoundsFailed = true;
}
}
}
Expand Down

0 comments on commit 3d5ce05

Please sign in to comment.