-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Use sequence numbers instead of a tracking array for depth buffers #15854
Merged
+22
−81
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,12 +71,6 @@ FramebufferManagerCommon::~FramebufferManagerCommon() { | |
} | ||
bvfbs_.clear(); | ||
|
||
// Shouldn't be anything left here in theory, but just in case... | ||
for (auto trackedDepth : trackedDepthBuffers_) { | ||
delete trackedDepth; | ||
} | ||
trackedDepthBuffers_.clear(); | ||
|
||
delete presentation_; | ||
} | ||
|
||
|
@@ -375,17 +369,11 @@ VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(const Frame | |
// Lookup in the depth tracking to find which VFB has the latest version of this Z buffer. | ||
// Then bind it in color-to-depth mode. | ||
// | ||
// We are going to do this by having a special render mode where we take color and move to | ||
// We do this by having a special render mode where we take color and move to | ||
// depth in the fragment shader, and set color writes to off. | ||
// | ||
// We'll need a special fragment shader flag to convert color to depth. | ||
|
||
for (auto &depth : this->trackedDepthBuffers_) { | ||
if (depth->z_address == params.fb_address && depth->z_stride == params.fb_stride) { | ||
// Found the matching depth buffer. Use this vfb. | ||
vfb = depth->vfb; | ||
} | ||
} | ||
// We use a special fragment shader flag to convert color to depth. | ||
vfb = GetLatestDepthBufferAt(params.fb_address /* !!! */, params.fb_stride); | ||
} | ||
|
||
gstate_c.SetFramebufferRenderMode(mode); | ||
|
@@ -453,14 +441,13 @@ VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(const Frame | |
|
||
// Looks up by z_address, so if one is found here and not have last pointers equal to this one, | ||
// there is another one. | ||
TrackedDepthBuffer *prevDepth = GetOrCreateTrackedDepthBuffer(vfb); | ||
VirtualFramebuffer *prevDepth = GetLatestDepthBufferAt(vfb->z_address, vfb->z_stride); | ||
|
||
// We might already want to copy depth, in case this is a temp buffer. See #7810. | ||
if (prevDepth->vfb != vfb) { | ||
if (!params.isClearingDepth && prevDepth->vfb) { | ||
BlitFramebufferDepth(prevDepth->vfb, vfb); | ||
if (prevDepth != vfb) { | ||
if (!params.isClearingDepth && prevDepth) { | ||
BlitFramebufferDepth(prevDepth, vfb); | ||
} | ||
prevDepth->vfb = vfb; | ||
} | ||
|
||
SetColorUpdated(vfb, skipDrawReason); | ||
|
@@ -558,13 +545,6 @@ void FramebufferManagerCommon::DestroyFramebuf(VirtualFramebuffer *v) { | |
if (prevPrevDisplayFramebuf_ == v) | ||
prevPrevDisplayFramebuf_ = nullptr; | ||
|
||
// Remove any depth buffer tracking related to this vfb. | ||
for (auto it = trackedDepthBuffers_.begin(); it != trackedDepthBuffers_.end(); it++) { | ||
if ((*it)->vfb == v) { | ||
(*it)->vfb = nullptr; // Mark for deletion in the next Decimate | ||
} | ||
} | ||
|
||
delete v; | ||
} | ||
|
||
|
@@ -626,32 +606,16 @@ void FramebufferManagerCommon::BlitFramebufferDepth(VirtualFramebuffer *src, Vir | |
dst->last_frame_depth_updated = gpuStats.numFlips; | ||
} | ||
|
||
TrackedDepthBuffer *FramebufferManagerCommon::GetOrCreateTrackedDepthBuffer(VirtualFramebuffer *vfb) { | ||
for (auto tracked : trackedDepthBuffers_) { | ||
// Disable tracking if color of the new vfb is clashing with tracked depth. | ||
if (vfb->fb_address == tracked->z_address) { | ||
tracked->vfb = nullptr; // this is checked for. Cheaper than deleting. | ||
continue; | ||
} | ||
|
||
if (vfb->z_address == tracked->z_address) { | ||
if (vfb->z_stride == tracked->z_stride) { | ||
return tracked; | ||
} else { | ||
// Stride has changed, mark as bad. | ||
tracked->vfb = nullptr; | ||
} | ||
VirtualFramebuffer *FramebufferManagerCommon::GetLatestDepthBufferAt(u32 z_address, u16 z_stride) { | ||
int maxSeq = -1; | ||
VirtualFramebuffer *latestDepth = nullptr; | ||
for (auto vfb : vfbs_) { | ||
if (vfb->z_address == z_address && vfb->z_stride == z_stride && vfb->depthBindSeq > maxSeq) { | ||
maxSeq = vfb->depthBindSeq; | ||
latestDepth = vfb; | ||
} | ||
} | ||
|
||
TrackedDepthBuffer *tracked = new TrackedDepthBuffer(); | ||
tracked->vfb = vfb; | ||
tracked->z_address = vfb->z_address; | ||
tracked->z_stride = vfb->z_stride; | ||
|
||
trackedDepthBuffers_.push_back(tracked); | ||
|
||
return tracked; | ||
return latestDepth; | ||
} | ||
|
||
void FramebufferManagerCommon::NotifyRenderFramebufferCreated(VirtualFramebuffer *vfb) { | ||
|
@@ -703,14 +667,14 @@ void FramebufferManagerCommon::NotifyRenderFramebufferSwitched(VirtualFramebuffe | |
shaderManager_->DirtyLastShader(); | ||
|
||
// Copy depth between the framebuffers, if the z_address is the same (checked inside.) | ||
TrackedDepthBuffer *prevDepth = GetOrCreateTrackedDepthBuffer(vfb); | ||
VirtualFramebuffer * prevDepth = GetLatestDepthBufferAt(vfb->z_address, vfb->z_stride); | ||
|
||
// We might already want to copy depth, in case this is a temp buffer. See #7810. | ||
if (prevDepth->vfb != vfb) { | ||
if (!isClearingDepth && prevDepth->vfb) { | ||
BlitFramebufferDepth(prevDepth->vfb, vfb); | ||
if (prevDepth != vfb) { | ||
if (!isClearingDepth && prevDepth) { | ||
BlitFramebufferDepth(prevDepth, vfb); | ||
} | ||
prevDepth->vfb = vfb; | ||
prevDepth = vfb; | ||
} | ||
|
||
if (vfb->drawnFormat != vfb->format) { | ||
|
@@ -1234,16 +1198,6 @@ void FramebufferManagerCommon::DecimateFBOs() { | |
bvfbs_.erase(bvfbs_.begin() + i--); | ||
} | ||
} | ||
|
||
// Also clean up the TrackedDepthBuffer array... | ||
for (auto it = trackedDepthBuffers_.begin(); it != trackedDepthBuffers_.end();) { | ||
if ((*it)->vfb == nullptr) { | ||
delete *it; | ||
it = trackedDepthBuffers_.erase(it); | ||
} else { | ||
it++; | ||
} | ||
} | ||
} | ||
|
||
// Requires width/height to be set already. | ||
|
@@ -2220,6 +2174,7 @@ void FramebufferManagerCommon::ReadFramebufferToMemory(VirtualFramebuffer *vfb, | |
// We'll pseudo-blit framebuffers here to get a resized version of vfb. | ||
if (gameUsesSequentialCopies_) { | ||
// Ignore the x/y/etc., read the entire thing. | ||
// TODO: What game did we need this for? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC, Grand Knights Historia was one of them but I think there were a few. It was because some games would memcpy regions in strips, or many smaller regions from a larger framebuffer. -[Unknown] |
||
x = 0; | ||
y = 0; | ||
w = vfb->width; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This looks as much like "important, fb was intentional here" as "TODO, gotta change something here."
-[Unknown]