Skip to content

Commit

Permalink
Background raster: Optimize a little, add more stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 2, 2025
1 parent e538b13 commit 6d5eced
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
14 changes: 7 additions & 7 deletions GPU/Common/DrawEngineCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,13 +1060,9 @@ void DrawEngineCommon::EnqueueDepthDraw(const DepthDraw &draw) {
}

// Returns true if we actually waited.
bool DrawEngineCommon::WaitForDepthPassFinish() {
void DrawEngineCommon::WaitForDepthPassFinish() {
{
std::lock_guard<std::mutex> lock(depthEnqueueMutex_);
if (!inDepthDrawPass_) {
_dbg_assert_(depthIndexCount_ == 0 && depthVertexCount_ == 0 && depthDraws_.empty());
return false;
}
// In case the depth raster thread is idle, we need to nudge it.
_dbg_assert_(!finishedSubmitting_);
finishedSubmitting_ = true;
Expand All @@ -1078,7 +1074,6 @@ bool DrawEngineCommon::WaitForDepthPassFinish() {
while (!finishedDrawing_) {
depthFinishCond_.wait(lock);
}
return true;
}

void DrawEngineCommon::FlushQueuedDepth() {
Expand All @@ -1087,7 +1082,8 @@ void DrawEngineCommon::FlushQueuedDepth() {
depthRasterPassStart_ = 0.0;
}

if (WaitForDepthPassFinish()) {
if (inDepthDrawPass_) {
WaitForDepthPassFinish();
// At this point, we know that the depth thread is paused.

// Reset queue
Expand All @@ -1114,10 +1110,14 @@ void DrawEngineCommon::DepthThreadFunc() {
{
std::unique_lock<std::mutex> lock(depthEnqueueMutex_);
if (depthDraws_.size() == curDraw_) {
gpuStats.numDepthThreadCaughtUp++;
// We've drawn all we can. Let's check if we're finished.
// If we reach here, we've drawn everything we can. And if that's the last
// that will come in this batch, we notify.
if (finishedSubmitting_) {
gpuStats.numDepthThreadFinished++;
gpuStats.numDepthDraws += (int)depthDraws_.size();

// lock.unlock(); // possible optimization?
std::lock_guard<std::mutex> flock(depthFinishMutex_);
finishedDrawing_ = true;
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/DrawEngineCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class DrawEngineCommon {
private:
// Internal implementation details.
void DepthThreadFunc();
bool WaitForDepthPassFinish();
void WaitForDepthPassFinish();

inline void EnqueueDepthDraw(const DepthDraw &draw);
inline void ProcessDepthDraw(const DepthDraw &draw);
Expand Down
6 changes: 6 additions & 0 deletions GPU/GPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ struct GPUStatistics {
numDepthRasterTooSmall = 0;
numDepthRasterZCulled = 0;
numDepthEarlyBoxCulled = 0;
numDepthThreadCaughtUp = 0;
numDepthThreadFinished = 0;
numDepthDraws = 0;
vertexGPUCycles = 0;
otherGPUCycles = 0;
}
Expand Down Expand Up @@ -169,6 +172,9 @@ struct GPUStatistics {
int numDepthRasterTooSmall;
int numDepthRasterZCulled;
int numDepthEarlyBoxCulled;
int numDepthThreadCaughtUp;
int numDepthThreadFinished;
int numDepthDraws;
// Flip count. Doesn't really belong here.
int numFlips;
};
Expand Down
7 changes: 6 additions & 1 deletion GPU/GPUCommonHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,9 @@ size_t GPUCommonHW::FormatGPUStatsCommon(char *buffer, size_t size) {
"Cpy: depth %d, color %d, reint %d, blend %d, self %d\n"
"GPU cycles: %d (%0.1f per vertex)\n"
"Z-rast: %0.2f+%0.2f+%0.2f (total %0.2f/%0.2f) ms\n"
"Z-rast: %d prim, %d nopix, %d small, %d earlysize, %d zcull, %d box\n%s",
"Z-rast: %d prim, %d nopix, %d small, %d earlysize, %d zcull, %d box\n"
"Z-rast: %d draws, %d thread caught up, %d thread finishes\n"
"%s",
gpuStats.msProcessingDisplayLists * 1000.0f,
gpuStats.numDrawSyncs,
gpuStats.numListSyncs,
Expand Down Expand Up @@ -1850,6 +1852,9 @@ size_t GPUCommonHW::FormatGPUStatsCommon(char *buffer, size_t size) {
gpuStats.numDepthRasterEarlySize,
gpuStats.numDepthRasterZCulled,
gpuStats.numDepthEarlyBoxCulled,
gpuStats.numDepthDraws,
gpuStats.numDepthThreadCaughtUp,
gpuStats.numDepthThreadFinished,
debugRecording_ ? "(debug-recording)" : ""
);
}

0 comments on commit 6d5eced

Please sign in to comment.