Skip to content

Commit 0c66f6c

Browse files
committed
Assorted drive-by code cleanup
1 parent 6a5522b commit 0c66f6c

12 files changed

+36
-55
lines changed

GPU/Common/FramebufferManagerCommon.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,10 @@ void FramebufferManagerCommon::BlitFramebufferDepth(VirtualFramebuffer *src, Vir
471471
// Note: We prefer Blit ahead of Copy here, since at least on GL, Copy will always also copy stencil which we don't want. See #9740.
472472
if (gstate_c.Supports(GPU_SUPPORTS_FRAMEBUFFER_BLIT_TO_DEPTH)) {
473473
draw_->BlitFramebuffer(src->fbo, 0, 0, w, h, dst->fbo, 0, 0, w, h, Draw::FB_DEPTH_BIT, Draw::FB_BLIT_NEAREST, "BlitFramebufferDepth");
474-
RebindFramebuffer("BlitFramebufferDepth");
474+
RebindFramebuffer("After BlitFramebufferDepth");
475475
} else if (gstate_c.Supports(GPU_SUPPORTS_COPY_IMAGE)) {
476476
draw_->CopyFramebufferImage(src->fbo, 0, 0, 0, 0, dst->fbo, 0, 0, 0, 0, w, h, 1, Draw::FB_DEPTH_BIT, "BlitFramebufferDepth");
477-
RebindFramebuffer("BlitFramebufferDepth");
477+
RebindFramebuffer("After BlitFramebufferDepth");
478478
}
479479
dst->last_frame_depth_updated = gpuStats.numFlips;
480480
}
@@ -503,7 +503,7 @@ void FramebufferManagerCommon::NotifyRenderFramebufferUpdated(VirtualFramebuffer
503503
if (vfbFormatChanged) {
504504
textureCache_->NotifyFramebuffer(vfb, NOTIFY_FB_UPDATED);
505505
if (vfb->drawnFormat != vfb->format) {
506-
ReinterpretFramebufferFrom(vfb, vfb->drawnFormat);
506+
ReinterpretFramebuffer(vfb, vfb->drawnFormat, vfb->format);
507507
}
508508
}
509509

@@ -517,11 +517,15 @@ void FramebufferManagerCommon::NotifyRenderFramebufferUpdated(VirtualFramebuffer
517517
}
518518
}
519519

520-
void FramebufferManagerCommon::ReinterpretFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat oldFormat) {
520+
void FramebufferManagerCommon::ReinterpretFramebuffer(VirtualFramebuffer *vfb, GEBufferFormat oldFormat, GEBufferFormat newFormat) {
521521
if (!useBufferedRendering_ || !vfb->fbo) {
522522
return;
523523
}
524524

525+
_assert_(newFormat != oldFormat);
526+
// The caller is responsible for updating the format.
527+
_assert_(newFormat == vfb->format);
528+
525529
ShaderLanguage lang = draw_->GetShaderLanguageDesc().shaderLanguage;
526530

527531
bool doReinterpret = PSP_CoreParameter().compat.flags().ReinterpretFramebuffers &&
@@ -549,10 +553,6 @@ void FramebufferManagerCommon::ReinterpretFramebufferFrom(VirtualFramebuffer *vf
549553
return;
550554
}
551555

552-
GEBufferFormat newFormat = vfb->format;
553-
554-
_assert_(newFormat != oldFormat);
555-
556556
// We only reinterpret between 16 - bit formats, for now.
557557
if (!IsGeBufferFormat16BitColor(oldFormat) || !IsGeBufferFormat16BitColor(newFormat)) {
558558
// 16->32 and 32->16 will require some more specialized shaders.
@@ -671,8 +671,9 @@ void FramebufferManagerCommon::NotifyRenderFramebufferSwitched(VirtualFramebuffe
671671
}
672672
}
673673
}
674+
674675
if (vfb->drawnFormat != vfb->format) {
675-
ReinterpretFramebufferFrom(vfb, vfb->drawnFormat);
676+
ReinterpretFramebuffer(vfb, vfb->drawnFormat, vfb->format);
676677
}
677678

678679
if (useBufferedRendering_) {
@@ -839,10 +840,8 @@ bool FramebufferManagerCommon::BindFramebufferAsColorTexture(int stage, VirtualF
839840

840841
// currentRenderVfb_ will always be set when this is called, except from the GE debugger.
841842
// Let's just not bother with the copy in that case.
842-
bool skipCopy = (flags & BINDFBCOLOR_MAY_COPY) == 0;
843-
if (GPUStepping::IsStepping()) {
844-
skipCopy = true;
845-
}
843+
bool skipCopy = !(flags & BINDFBCOLOR_MAY_COPY) || GPUStepping::IsStepping();
844+
846845
// Currently rendering to this framebuffer. Need to make a copy.
847846
if (!skipCopy && framebuffer == currentRenderVfb_) {
848847
// TODO: Maybe merge with bvfbs_? Not sure if those could be packing, and they're created at a different size.
@@ -870,7 +869,6 @@ bool FramebufferManagerCommon::BindFramebufferAsColorTexture(int stage, VirtualF
870869
gstate_c.skipDrawReason |= SKIPDRAW_BAD_FB_TEXTURE;
871870
return false;
872871
}
873-
874872
}
875873

876874
void FramebufferManagerCommon::CopyFramebufferForColorTexture(VirtualFramebuffer *dst, VirtualFramebuffer *src, int flags) {
@@ -996,6 +994,8 @@ void FramebufferManagerCommon::DrawFramebufferToOutput(const u8 *srcPixels, GEBu
996994

997995
// PresentationCommon sets all kinds of state, we can't rely on anything.
998996
gstate_c.Dirty(DIRTY_ALL);
997+
998+
currentRenderVfb_ = nullptr;
999999
}
10001000

10011001
void FramebufferManagerCommon::DownloadFramebufferOnSwitch(VirtualFramebuffer *vfb) {
@@ -1747,10 +1747,10 @@ bool FramebufferManagerCommon::NotifyBlockTransferBefore(u32 dstBasePtr, int dst
17471747
BlitFramebuffer(dstBuffer, dstX, dstY, srcBuffer, srcX, srcY, dstWidth, dstHeight, bpp, "Blit_IntraBufferBlockTransfer");
17481748
RebindFramebuffer("rebind after intra block transfer");
17491749
SetColorUpdated(dstBuffer, skipDrawReason);
1750-
return true;
1750+
return true; // Skip the memory copy.
17511751
} else {
17521752
// Ignore, nothing to do. Tales of Phantasia X does this by accident.
1753-
return true;
1753+
return true; // Skip the memory copy.
17541754
}
17551755
} else {
17561756
WARN_LOG_N_TIMES(dstnotsrc, 100, G3D, "Inter-buffer block transfer %08x (x:%d y:%d stride:%d) -> %08x (x:%d y:%d stride:%d) (%dx%d %dbpp)",

GPU/Common/FramebufferManagerCommon.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
// Official git repository and contact information can be found at
1616
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
1717

18+
// TODO: We now have the tools in thin3d to nearly eliminate the backend-specific framebuffer managers.
19+
// Here's a list of functionality to unify into FramebufferManagerCommon:
20+
// * DrawActiveTexture
21+
// * BlitFramebuffer
22+
// * StencilBuffer*.cpp
23+
//
24+
// Also, in TextureCache we should be able to unify texture-based depal.
25+
1826
#pragma once
1927

2028
#include <set>
@@ -131,7 +139,7 @@ void GetFramebufferHeuristicInputs(FramebufferHeuristicParams *params, const GPU
131139
enum BindFramebufferColorFlags {
132140
BINDFBCOLOR_SKIP_COPY = 0,
133141
BINDFBCOLOR_MAY_COPY = 1,
134-
BINDFBCOLOR_MAY_COPY_WITH_UV = 3,
142+
BINDFBCOLOR_MAY_COPY_WITH_UV = 3, // includes BINDFBCOLOR_MAY_COPY
135143
BINDFBCOLOR_APPLY_TEX_OFFSET = 4,
136144
// Used when rendering to a temporary surface (e.g. not the current render target.)
137145
BINDFBCOLOR_FORCE_SELF = 8,
@@ -322,7 +330,7 @@ class FramebufferManagerCommon {
322330
const std::vector<VirtualFramebuffer *> &Framebuffers() {
323331
return vfbs_;
324332
}
325-
void ReinterpretFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat old);
333+
void ReinterpretFramebuffer(VirtualFramebuffer *vfb, GEBufferFormat oldFormat, GEBufferFormat newFormat);
326334

327335
protected:
328336
virtual void PackFramebufferSync_(VirtualFramebuffer *vfb, int x, int y, int w, int h);
@@ -356,7 +364,7 @@ class FramebufferManagerCommon {
356364
void DownloadFramebufferOnSwitch(VirtualFramebuffer *vfb);
357365
void FindTransferFramebuffers(VirtualFramebuffer *&dstBuffer, VirtualFramebuffer *&srcBuffer, u32 dstBasePtr, int dstStride, int &dstX, int &dstY, u32 srcBasePtr, int srcStride, int &srcX, int &srcY, int &srcWidth, int &srcHeight, int &dstWidth, int &dstHeight, int bpp);
358366
VirtualFramebuffer *FindDownloadTempBuffer(VirtualFramebuffer *vfb);
359-
virtual void UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb) = 0;
367+
virtual void UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb) {}
360368

361369
VirtualFramebuffer *CreateRAMFramebuffer(uint32_t fbAddress, int width, int height, int stride, GEBufferFormat format);
362370

GPU/Common/TextureCacheCommon.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,10 +958,9 @@ void TextureCacheCommon::SetTextureFramebuffer(const AttachCandidate &candidate)
958958
FramebufferMatchInfo fbInfo = candidate.match;
959959

960960
if (candidate.match.reinterpret) {
961-
// TODO: Kinda ugly, maybe switch direction of the call?
962961
GEBufferFormat oldFormat = candidate.fb->format;
963962
candidate.fb->format = candidate.match.reinterpretTo;
964-
framebufferManager_->ReinterpretFramebufferFrom(candidate.fb, oldFormat);
963+
framebufferManager_->ReinterpretFramebuffer(candidate.fb, oldFormat, candidate.match.reinterpretTo);
965964
}
966965

967966
_dbg_assert_msg_(framebuffer != nullptr, "Framebuffer must not be null.");

GPU/D3D11/FramebufferManagerD3D11.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,6 @@ static void CopyPixelDepthOnly(u32 *dstp, const u32 *srcp, size_t c) {
277277
}
278278
}
279279

280-
void FramebufferManagerD3D11::UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb) {
281-
// Nothing to do here.
282-
}
283-
284280
void FramebufferManagerD3D11::SimpleBlit(
285281
Draw::Framebuffer *dest, float destX1, float destY1, float destX2, float destY2,
286282
Draw::Framebuffer *src, float srcX1, float srcY1, float srcX2, float srcY2, bool linearFilter) {

GPU/D3D11/FramebufferManagerD3D11.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ class FramebufferManagerD3D11 : public FramebufferManagerCommon {
5454
// Used by ReadFramebufferToMemory and later framebuffer block copies
5555
void BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int dstY, VirtualFramebuffer *src, int srcX, int srcY, int w, int h, int bpp, const char *tag) override;
5656

57-
void UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb) override;
58-
5957
private:
6058
void Bind2DShader() override;
6159
void PackDepthbuffer(VirtualFramebuffer *vfb, int x, int y, int w, int h);

GPU/D3D11/TextureCacheD3D11.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ void TextureCacheD3D11::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer,
412412
shaderApply.Shade();
413413

414414
context_->PSSetShaderResources(0, 1, &nullTexture); // Make D3D11 validation happy. Really of no consequence since we rebind anyway.
415-
framebufferManagerD3D11_->RebindFramebuffer("RebindFramebuffer - ApplyTextureFramebuffer");
415+
framebufferManager_->RebindFramebuffer("RebindFramebuffer - ApplyTextureFramebuffer");
416416
draw_->BindFramebufferAsTexture(depalFBO, 0, Draw::FB_COLOR_BIT, 0);
417417

418418
const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16);
@@ -422,8 +422,8 @@ void TextureCacheD3D11::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer,
422422
gstate_c.SetTextureFullAlpha(alphaStatus == TexCacheEntry::STATUS_ALPHA_FULL);
423423
} else {
424424
gstate_c.SetTextureFullAlpha(gstate.getTextureFormat() == GE_TFMT_5650);
425-
framebufferManagerD3D11_->RebindFramebuffer("RebindFramebuffer - ApplyTextureFramebuffer");
426-
framebufferManagerD3D11_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET);
425+
framebufferManager_->RebindFramebuffer("RebindFramebuffer - ApplyTextureFramebuffer");
426+
framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET);
427427
}
428428

429429
SamplerCacheKey samplerKey = GetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight);

GPU/Directx9/FramebufferManagerDX9.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,6 @@ static const D3DVERTEXELEMENT9 g_FramebufferVertexElements[] = {
259259
return offscreen;
260260
}
261261

262-
void FramebufferManagerDX9::UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb) {
263-
// Nothing to do here.
264-
}
265-
266262
void FramebufferManagerDX9::BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int dstY, VirtualFramebuffer *src, int srcX, int srcY, int w, int h, int bpp, const char *tag) {
267263
if (!dst->fbo || !src->fbo || !useBufferedRendering_) {
268264
// This can happen if we recently switched from non-buffered.

GPU/Directx9/FramebufferManagerDX9.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ class FramebufferManagerDX9 : public FramebufferManagerCommon {
6565
// Used by ReadFramebufferToMemory and later framebuffer block copies
6666
void BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int dstY, VirtualFramebuffer *src, int srcX, int srcY, int w, int h, int bpp, const char *tag) override;
6767

68-
void UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb) override;
69-
7068
private:
7169
void PackFramebufferSync_(VirtualFramebuffer *vfb, int x, int y, int w, int h) override;
7270
void PackDepthbuffer(VirtualFramebuffer *vfb, int x, int y, int w, int h);

GPU/GPUCommon.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,6 +2721,8 @@ bool GPUCommon::PerformMemoryCopy(u32 dest, u32 src, int size) {
27212721
// Track stray copies of a framebuffer in RAM. MotoGP does this.
27222722
if (framebufferManager_->MayIntersectFramebuffer(src) || framebufferManager_->MayIntersectFramebuffer(dest)) {
27232723
if (!framebufferManager_->NotifyFramebufferCopy(src, dest, size, false, gstate_c.skipDrawReason)) {
2724+
// TODO: What? Why would a game copy between the mirrors? This check seems entirely
2725+
// superfluous.
27242726
// We use a little hack for Download/Upload using a VRAM mirror.
27252727
// Since they're identical we don't need to copy.
27262728
if (!Memory::IsVRAMAddress(dest) || (dest ^ 0x00400000) != src) {

GPU/Vulkan/DrawEngineVulkan.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ void DrawEngineVulkan::DoFlush() {
803803
}
804804

805805
PROFILE_THIS_SCOPE("updatestate");
806+
806807
if (textureNeedsApply) {
807808
textureCache_->ApplyTexture();
808809
textureCache_->GetVulkanHandles(imageView, sampler);
@@ -860,8 +861,6 @@ void DrawEngineVulkan::DoFlush() {
860861
UpdateUBOs(frame);
861862

862863
VkDescriptorSet ds = GetOrCreateDescriptorSet(imageView, sampler, baseBuf, lightBuf, boneBuf, tess);
863-
{
864-
PROFILE_THIS_SCOPE("renderman_q");
865864

866865
const uint32_t dynamicUBOOffsets[3] = {
867866
baseUBOOffset, lightUBOOffset, boneUBOOffset,
@@ -870,13 +869,13 @@ void DrawEngineVulkan::DoFlush() {
870869
int stride = dec_->GetDecVtxFmt().stride;
871870

872871
if (useElements) {
873-
if (!ibuf)
872+
if (!ibuf) {
874873
ibOffset = (uint32_t)frame->pushIndex->Push(decIndex, sizeof(uint16_t) * indexGen.VertexCount(), &ibuf);
874+
}
875875
renderManager->DrawIndexed(pipelineLayout_, ds, ARRAY_SIZE(dynamicUBOOffsets), dynamicUBOOffsets, vbuf, vbOffset, ibuf, ibOffset, vertexCount, 1, VK_INDEX_TYPE_UINT16);
876876
} else {
877877
renderManager->Draw(pipelineLayout_, ds, ARRAY_SIZE(dynamicUBOOffsets), dynamicUBOOffsets, vbuf, vbOffset, vertexCount);
878878
}
879-
}
880879
} else {
881880
PROFILE_THIS_SCOPE("soft");
882881
// Decode to "decoded"

0 commit comments

Comments
 (0)