Skip to content

Commit

Permalink
GE Debugger: Fix some crashes while stepping.
Browse files Browse the repository at this point in the history
Mostly on Vulkan, but possibly on other backends.
  • Loading branch information
unknownbrackets committed Dec 22, 2017
1 parent 554a85e commit 2031b2e
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions GPU/Common/FramebufferCommon.cpp
Expand Up @@ -1967,8 +1967,11 @@ bool FramebufferManagerCommon::GetDepthbuffer(u32 fb_address, int fb_stride, u32
} else { } else {
buffer.Allocate(w, h, GPU_DBG_FORMAT_FLOAT, flipY); buffer.Allocate(w, h, GPU_DBG_FORMAT_FLOAT, flipY);
} }
draw_->CopyFramebufferToMemorySync(vfb->fbo, Draw::FB_DEPTH_BIT, 0, 0, w, h, Draw::DataFormat::D32F, buffer.GetData(), w); // No need to free on failure, that's the caller's job (it likely will reuse a buffer.)
return true; bool retval = draw_->CopyFramebufferToMemorySync(vfb->fbo, Draw::FB_DEPTH_BIT, 0, 0, w, h, Draw::DataFormat::D32F, buffer.GetData(), w);
// That may have unbound the framebuffer, rebind to avoid crashes when debugging.
RebindFramebuffer();
return retval;
} }


bool FramebufferManagerCommon::GetStencilbuffer(u32 fb_address, int fb_stride, GPUDebugBuffer &buffer) { bool FramebufferManagerCommon::GetStencilbuffer(u32 fb_address, int fb_stride, GPUDebugBuffer &buffer) {
Expand All @@ -1993,21 +1996,22 @@ bool FramebufferManagerCommon::GetStencilbuffer(u32 fb_address, int fb_stride, G
} }


bool flipY = (g_Config.iGPUBackend == GPU_BACKEND_OPENGL && !useBufferedRendering_) ? true : false; bool flipY = (g_Config.iGPUBackend == GPU_BACKEND_OPENGL && !useBufferedRendering_) ? true : false;
// No need to free on failure, the caller/destructor will do that. Usually this is a reused buffer, anyway.
buffer.Allocate(w, h, GPU_DBG_FORMAT_8BIT, flipY); buffer.Allocate(w, h, GPU_DBG_FORMAT_8BIT, flipY);
if (draw_->CopyFramebufferToMemorySync(vfb->fbo, Draw::FB_STENCIL_BIT, 0, 0, w,h, Draw::DataFormat::S8, buffer.GetData(), w)) { bool retval = draw_->CopyFramebufferToMemorySync(vfb->fbo, Draw::FB_STENCIL_BIT, 0, 0, w,h, Draw::DataFormat::S8, buffer.GetData(), w);
return true; // That may have unbound the framebuffer, rebind to avoid crashes when debugging.
} else { RebindFramebuffer();
buffer.Free(); return retval;
return false;
}
} }


bool FramebufferManagerCommon::GetOutputFramebuffer(GPUDebugBuffer &buffer) { bool FramebufferManagerCommon::GetOutputFramebuffer(GPUDebugBuffer &buffer) {
int w, h; int w, h;
draw_->GetFramebufferDimensions(nullptr, &w, &h); draw_->GetFramebufferDimensions(nullptr, &w, &h);
buffer.Allocate(w, h, GE_FORMAT_8888, false, true); buffer.Allocate(w, h, GE_FORMAT_8888, false, true);
draw_->CopyFramebufferToMemorySync(nullptr, Draw::FB_COLOR_BIT, 0, 0, w, h, Draw::DataFormat::R8G8B8A8_UNORM, buffer.GetData(), w); bool retval = draw_->CopyFramebufferToMemorySync(nullptr, Draw::FB_COLOR_BIT, 0, 0, w, h, Draw::DataFormat::R8G8B8A8_UNORM, buffer.GetData(), w);
return true; // That may have unbound the framebuffer, rebind to avoid crashes when debugging.
RebindFramebuffer();
return retval;
} }


// This function takes an already correctly-sized framebuffer and packs it into RAM. // This function takes an already correctly-sized framebuffer and packs it into RAM.
Expand Down Expand Up @@ -2110,7 +2114,7 @@ void FramebufferManagerCommon::RebindFramebuffer() {
if (currentRenderVfb_ && currentRenderVfb_->fbo) { if (currentRenderVfb_ && currentRenderVfb_->fbo) {
draw_->BindFramebufferAsRenderTarget(currentRenderVfb_->fbo, { Draw::RPAction::KEEP, Draw::RPAction::KEEP }); draw_->BindFramebufferAsRenderTarget(currentRenderVfb_->fbo, { Draw::RPAction::KEEP, Draw::RPAction::KEEP });
} else { } else {
// Should this even happen? // Should this even happen? It could while debugging, but maybe we can just skip binding at all.
draw_->BindFramebufferAsRenderTarget(nullptr, { Draw::RPAction::KEEP, Draw::RPAction::KEEP }); draw_->BindFramebufferAsRenderTarget(nullptr, { Draw::RPAction::KEEP, Draw::RPAction::KEEP });
} }
gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE); gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE);
Expand Down

0 comments on commit 2031b2e

Please sign in to comment.