-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
FramebufferManagerCommon.cpp
3396 lines (2938 loc) · 135 KB
/
FramebufferManagerCommon.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <algorithm>
#include <sstream>
#include <cmath>
#include "Common/GPU/thin3d.h"
#include "Common/GPU/OpenGL/GLFeatures.h"
#include "Common/Data/Collections/TinySet.h"
#include "Common/Data/Convert/ColorConv.h"
#include "Common/Data/Text/I18n.h"
#include "Common/LogReporting.h"
#include "Common/Math/lin/matrix4x4.h"
#include "Common/Math/math_util.h"
#include "Common/System/Display.h"
#include "Common/System/OSD.h"
#include "Common/VR/PPSSPPVR.h"
#include "Common/CommonTypes.h"
#include "Common/StringUtils.h"
#include "Core/Config.h"
#include "Core/ConfigValues.h"
#include "Core/Core.h"
#include "Core/CoreParameter.h"
#include "Core/Debugger/MemBlockInfo.h"
#include "Core/MIPS/MIPS.h"
#include "GPU/Common/DrawEngineCommon.h"
#include "GPU/Common/FramebufferManagerCommon.h"
#include "GPU/Common/PostShader.h"
#include "GPU/Common/PresentationCommon.h"
#include "GPU/Common/TextureCacheCommon.h"
#include "GPU/Common/ReinterpretFramebuffer.h"
#include "GPU/Debugger/Debugger.h"
#include "GPU/Debugger/Record.h"
#include "GPU/Debugger/Stepping.h"
#include "GPU/GPUInterface.h"
#include "GPU/GPUState.h"
static size_t FormatFramebufferName(const VirtualFramebuffer *vfb, char *tag, size_t len) {
return snprintf(tag, len, "FB_%08x_%08x_%dx%d_%s", vfb->fb_address, vfb->z_address, vfb->bufferWidth, vfb->bufferHeight, GeBufferFormatToString(vfb->fb_format));
}
FramebufferManagerCommon::FramebufferManagerCommon(Draw::DrawContext *draw)
: draw_(draw), draw2D_(draw_) {
presentation_ = new PresentationCommon(draw);
}
FramebufferManagerCommon::~FramebufferManagerCommon() {
DeviceLost();
DecimateFBOs();
for (auto vfb : vfbs_) {
DestroyFramebuf(vfb);
}
vfbs_.clear();
for (auto &tempFB : tempFBOs_) {
tempFB.second.fbo->Release();
}
tempFBOs_.clear();
// Do the same for ReadFramebuffersToMemory's VFBs
for (auto vfb : bvfbs_) {
DestroyFramebuf(vfb);
}
bvfbs_.clear();
delete presentation_;
delete[] convBuf_;
}
void FramebufferManagerCommon::Init(int msaaLevel) {
// We may need to override the render size if the shader is upscaling or SSAA.
NotifyDisplayResized();
NotifyRenderResized(msaaLevel);
}
bool FramebufferManagerCommon::UpdateRenderSize(int msaaLevel) {
const bool newRender = renderWidth_ != (float)PSP_CoreParameter().renderWidth || renderHeight_ != (float)PSP_CoreParameter().renderHeight || msaaLevel_ != msaaLevel;
int effectiveBloomHack = g_Config.iBloomHack;
if (PSP_CoreParameter().compat.flags().ForceLowerResolutionForEffectsOn) {
effectiveBloomHack = 3;
} else if (PSP_CoreParameter().compat.flags().ForceLowerResolutionForEffectsOff) {
effectiveBloomHack = 0;
}
bool newBuffered = !g_Config.bSkipBufferEffects;
const bool newSettings = bloomHack_ != effectiveBloomHack || useBufferedRendering_ != newBuffered;
renderWidth_ = (float)PSP_CoreParameter().renderWidth;
renderHeight_ = (float)PSP_CoreParameter().renderHeight;
renderScaleFactor_ = (float)PSP_CoreParameter().renderScaleFactor;
msaaLevel_ = msaaLevel;
bloomHack_ = effectiveBloomHack;
useBufferedRendering_ = newBuffered;
presentation_->UpdateRenderSize(renderWidth_, renderHeight_);
return newRender || newSettings;
}
void FramebufferManagerCommon::CheckPostShaders() {
if (updatePostShaders_) {
presentation_->UpdatePostShader();
updatePostShaders_ = false;
}
}
void FramebufferManagerCommon::BeginFrame() {
DecimateFBOs();
currentRenderVfb_ = nullptr;
}
void FramebufferManagerCommon::SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format) {
displayFramebufPtr_ = framebuf & 0x3FFFFFFF;
if (Memory::IsVRAMAddress(displayFramebufPtr_))
displayFramebufPtr_ = framebuf & 0x041FFFFF;
displayStride_ = stride;
displayFormat_ = format;
GPUDebug::NotifyDisplay(framebuf, stride, format);
GPURecord::NotifyDisplay(framebuf, stride, format);
}
VirtualFramebuffer *FramebufferManagerCommon::GetVFBAt(u32 addr) const {
addr &= 0x3FFFFFFF;
if (Memory::IsVRAMAddress(addr))
addr &= 0x041FFFFF;
VirtualFramebuffer *match = nullptr;
for (auto vfb : vfbs_) {
if (vfb->fb_address == addr) {
// Could check w too but whatever (actually, might very well make sense to do so, depending on context).
if (!match || vfb->last_frame_render > match->last_frame_render) {
match = vfb;
}
}
}
return match;
}
VirtualFramebuffer *FramebufferManagerCommon::GetExactVFB(u32 addr, int stride, GEBufferFormat format) const {
addr &= 0x3FFFFFFF;
if (Memory::IsVRAMAddress(addr))
addr &= 0x041FFFFF;
VirtualFramebuffer *newest = nullptr;
for (auto vfb : vfbs_) {
if (vfb->fb_address == addr && vfb->fb_stride == stride && vfb->fb_format == format) {
if (newest) {
if (vfb->colorBindSeq > newest->colorBindSeq) {
newest = vfb;
}
} else {
newest = vfb;
}
}
}
return newest;
}
VirtualFramebuffer *FramebufferManagerCommon::ResolveVFB(u32 addr, int stride, GEBufferFormat format) {
addr &= 0x3FFFFFFF;
if (Memory::IsVRAMAddress(addr))
addr &= 0x041FFFFF;
// Find the newest one matching addr and stride.
VirtualFramebuffer *newest = nullptr;
for (auto vfb : vfbs_) {
if (vfb->fb_address == addr && vfb->FbStrideInBytes() == stride * BufferFormatBytesPerPixel(format)) {
if (newest) {
if (vfb->colorBindSeq > newest->colorBindSeq) {
newest = vfb;
}
} else {
newest = vfb;
}
}
}
if (newest && newest->fb_format != format) {
WARN_LOG_ONCE(resolvevfb, G3D, "ResolveVFB: Resolving from %s to %s at %08x/%d", GeBufferFormatToString(newest->fb_format), GeBufferFormatToString(format), addr, stride);
return ResolveFramebufferColorToFormat(newest, format);
}
return newest;
}
VirtualFramebuffer *FramebufferManagerCommon::GetDisplayVFB() {
return GetExactVFB(displayFramebufPtr_, displayStride_, displayFormat_);
}
// Heuristics to figure out the size of FBO to create.
// TODO: Possibly differentiate on whether through mode is used (since in through mode, viewport is meaningless?)
void FramebufferManagerCommon::EstimateDrawingSize(u32 fb_address, int fb_stride, GEBufferFormat fb_format, int viewport_width, int viewport_height, int region_width, int region_height, int scissor_width, int scissor_height, int &drawing_width, int &drawing_height) {
static const int MAX_FRAMEBUF_HEIGHT = 512;
// Games don't always set any of these. Take the greatest parameter that looks valid based on stride.
if (viewport_width > 4 && viewport_width <= fb_stride && viewport_height > 0) {
drawing_width = viewport_width;
drawing_height = viewport_height;
// Some games specify a viewport with 0.5, but don't have VRAM for 273. 480x272 is the buffer size.
if (viewport_width == 481 && region_width == 480 && viewport_height == 273 && region_height == 272) {
drawing_width = 480;
drawing_height = 272;
}
// Sometimes region is set larger than the VRAM for the framebuffer.
// However, in one game it's correctly set as a larger height (see #7277) with the same width.
// A bit of a hack, but we try to handle that unusual case here.
if (region_width <= fb_stride && (region_width > drawing_width || (region_width == drawing_width && region_height > drawing_height)) && region_height <= MAX_FRAMEBUF_HEIGHT) {
drawing_width = region_width;
drawing_height = std::max(drawing_height, region_height);
}
// Scissor is often set to a subsection of the framebuffer, so we pay the least attention to it.
if (scissor_width <= fb_stride && scissor_width > drawing_width && scissor_height <= MAX_FRAMEBUF_HEIGHT) {
drawing_width = scissor_width;
drawing_height = std::max(drawing_height, scissor_height);
}
} else {
// If viewport wasn't valid, let's just take the greatest anything regardless of stride.
drawing_width = std::min(std::max(region_width, scissor_width), fb_stride);
drawing_height = std::max(region_height, scissor_height);
}
if (scissor_width == 481 && region_width == 480 && scissor_height == 273 && region_height == 272) {
drawing_width = 480;
drawing_height = 272;
}
// Assume no buffer is > 512 tall, it couldn't be textured or displayed fully if so.
if (drawing_height >= MAX_FRAMEBUF_HEIGHT) {
if (region_height < MAX_FRAMEBUF_HEIGHT) {
drawing_height = region_height;
} else if (scissor_height < MAX_FRAMEBUF_HEIGHT) {
drawing_height = scissor_height;
}
}
if (viewport_width != region_width) {
// The majority of the time, these are equal. If not, let's check what we know.
u32 nearest_address = 0xFFFFFFFF;
for (auto vfb : vfbs_) {
const u32 other_address = vfb->fb_address;
if (other_address > fb_address && other_address < nearest_address) {
nearest_address = other_address;
}
}
// Unless the game is using overlapping buffers, the next buffer should be far enough away.
// This catches some cases where we can know this.
// Hmm. The problem is that we could only catch it for the first of two buffers...
const u32 bpp = BufferFormatBytesPerPixel(fb_format);
int avail_height = (nearest_address - fb_address) / (fb_stride * bpp);
if (avail_height < drawing_height && avail_height == region_height) {
drawing_width = std::min(region_width, fb_stride);
drawing_height = avail_height;
}
// Some games draw buffers interleaved, with a high stride/region/scissor but default viewport.
if (fb_stride == 1024 && region_width == 1024 && scissor_width == 1024) {
drawing_width = 1024;
}
}
bool margin = false;
// Let's check if we're in a stride gap of a full-size framebuffer.
for (auto vfb : vfbs_) {
if (fb_address == vfb->fb_address) {
continue;
}
if (vfb->fb_stride != 512) {
continue;
}
int vfb_stride_in_bytes = BufferFormatBytesPerPixel(vfb->fb_format) * vfb->fb_stride;
int stride_in_bytes = BufferFormatBytesPerPixel(fb_format) * fb_stride;
if (stride_in_bytes != vfb_stride_in_bytes) {
// Mismatching stride in bytes, not interesting
continue;
}
if (fb_address > vfb->fb_address && fb_address < vfb->fb_address + vfb_stride_in_bytes) {
// Candidate!
if (vfb->height == drawing_height) {
// Might have a margin texture! Fix the drawing width if it's too large.
int width_in_bytes = vfb->fb_address + vfb_stride_in_bytes - fb_address;
int width_in_pixels = width_in_bytes / BufferFormatBytesPerPixel(fb_format);
// Final check
if (width_in_pixels <= 32) {
drawing_width = std::min(drawing_width, width_in_pixels);
margin = true;
// Don't really need to keep looking.
break;
}
}
}
}
DEBUG_LOG(G3D, "Est: %08x V: %ix%i, R: %ix%i, S: %ix%i, STR: %i, THR:%i, Z:%08x = %ix%i %s", fb_address, viewport_width,viewport_height, region_width, region_height, scissor_width, scissor_height, fb_stride, gstate.isModeThrough(), gstate.isDepthWriteEnabled() ? gstate.getDepthBufAddress() : 0, drawing_width, drawing_height, margin ? " (margin!)" : "");
}
void GetFramebufferHeuristicInputs(FramebufferHeuristicParams *params, const GPUgstate &gstate) {
// GetFramebufferHeuristicInputs is only called from rendering, and thus, it's VRAM.
params->fb_address = gstate.getFrameBufRawAddress() | 0x04000000;
params->fb_stride = gstate.FrameBufStride();
params->z_address = gstate.getDepthBufRawAddress() | 0x04000000;
params->z_stride = gstate.DepthBufStride();
if (params->z_address == params->fb_address) {
// Probably indicates that the game doesn't care about Z for this VFB.
// Let's avoid matching it for Z copies and other shenanigans.
params->z_address = 0;
params->z_stride = 0;
}
params->fb_format = gstate_c.framebufFormat;
params->isClearingDepth = gstate.isModeClear() && gstate.isClearModeDepthMask();
// Technically, it may write depth later, but we're trying to detect it only when it's really true.
if (gstate.isModeClear()) {
// Not quite seeing how this makes sense..
params->isWritingDepth = !gstate.isClearModeDepthMask() && gstate.isDepthWriteEnabled();
} else {
params->isWritingDepth = gstate.isDepthWriteEnabled();
}
params->isDrawing = !gstate.isModeClear() || !gstate.isClearModeColorMask() || !gstate.isClearModeAlphaMask();
params->isModeThrough = gstate.isModeThrough();
const bool alphaBlending = gstate.isAlphaBlendEnabled();
const bool logicOpBlending = gstate.isLogicOpEnabled() && gstate.getLogicOp() != GE_LOGIC_CLEAR && gstate.getLogicOp() != GE_LOGIC_COPY;
params->isBlending = alphaBlending || logicOpBlending;
// Viewport-X1 and Y1 are not the upper left corner, but half the width/height. A bit confusing.
float vpx = gstate.getViewportXScale();
float vpy = gstate.getViewportYScale();
// Work around problem in F1 Grand Prix, where it draws in through mode with a bogus viewport.
// We set bad values to 0 which causes the framebuffer size heuristic to rely on the other parameters instead.
if (std::isnan(vpx) || vpx > 10000000.0f) {
vpx = 0.f;
}
if (std::isnan(vpy) || vpy > 10000000.0f) {
vpy = 0.f;
}
params->viewportWidth = (int)(fabsf(vpx) * 2.0f);
params->viewportHeight = (int)(fabsf(vpy) * 2.0f);
params->regionWidth = gstate.getRegionX2() + 1;
params->regionHeight = gstate.getRegionY2() + 1;
params->scissorLeft = gstate.getScissorX1();
params->scissorTop = gstate.getScissorY1();
params->scissorRight = gstate.getScissorX2() + 1;
params->scissorBottom = gstate.getScissorY2() + 1;
if (gstate.getRegionRateX() != 0x100 || gstate.getRegionRateY() != 0x100) {
WARN_LOG_REPORT_ONCE(regionRate, G3D, "Drawing region rate add non-zero: %04x, %04x of %04x, %04x", gstate.getRegionRateX(), gstate.getRegionRateY(), gstate.getRegionX2(), gstate.getRegionY2());
}
}
static void ApplyKillzoneFramebufferSplit(FramebufferHeuristicParams *params, int *drawing_width);
VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(FramebufferHeuristicParams ¶ms, u32 skipDrawReason) {
gstate_c.Clean(DIRTY_FRAMEBUF);
// Collect all parameters. This whole function has really become a cesspool of heuristics...
// but it appears that's what it takes, unless we emulate VRAM layout more accurately somehow.
// As there are no clear "framebuffer width" and "framebuffer height" registers,
// we need to infer the size of the current framebuffer somehow.
int drawing_width, drawing_height;
EstimateDrawingSize(params.fb_address, std::max(params.fb_stride, (u16)4), params.fb_format, params.viewportWidth, params.viewportHeight, params.regionWidth, params.regionHeight, params.scissorRight, params.scissorBottom, drawing_width, drawing_height);
if (params.fb_address == params.z_address) {
// Most likely Z will not be used in this pass, as that would wreak havoc (undefined behavior for sure)
// We probably don't need to do anything about that, but let's log it.
WARN_LOG_ONCE(color_equal_z, G3D, "Framebuffer bound with color addr == z addr, likely will not use Z in this pass: %08x", params.fb_address);
}
// Compatibility hack for Killzone, see issue #6207.
if (PSP_CoreParameter().compat.flags().SplitFramebufferMargin && params.fb_format == GE_FORMAT_8888) {
ApplyKillzoneFramebufferSplit(¶ms, &drawing_width);
} else {
gstate_c.SetCurRTOffset(0, 0);
}
// Find a matching framebuffer.
VirtualFramebuffer *vfb = nullptr;
for (auto v : vfbs_) {
const u32 bpp = BufferFormatBytesPerPixel(v->fb_format);
if (params.fb_address == v->fb_address && params.fb_format == v->fb_format && params.fb_stride == v->fb_stride) {
vfb = v;
if (vfb->z_address == 0 && vfb->z_stride == 0 && params.z_stride != 0) {
// Got one that was created by CreateRAMFramebuffer. Since it has no depth buffer,
// we just recreate it immediately.
ResizeFramebufFBO(vfb, vfb->width, vfb->height, true);
}
// Keep track, but this isn't really used.
vfb->z_stride = params.z_stride;
// Heuristic: In throughmode, a higher height could be used. Let's avoid shrinking the buffer.
if (params.isModeThrough && (int)vfb->width <= params.fb_stride) {
vfb->width = std::max((int)vfb->width, drawing_width);
vfb->height = std::max((int)vfb->height, drawing_height);
} else {
vfb->width = drawing_width;
vfb->height = drawing_height;
}
break;
} else if (!PSP_CoreParameter().compat.flags().DisallowFramebufferAtOffset && v->fb_stride == params.fb_stride && v->fb_format == params.fb_format && !PSP_CoreParameter().compat.flags().SplitFramebufferMargin) {
u32 v_fb_first_line_end_ptr = v->fb_address + v->fb_stride * bpp;
u32 v_fb_end_ptr = v->fb_address + v->fb_stride * v->height * bpp;
if (params.fb_address > v->fb_address && params.fb_address < v_fb_first_line_end_ptr) {
const int x_offset = (params.fb_address - v->fb_address) / bpp;
if (x_offset < params.fb_stride && v->height >= drawing_height) {
// Pretty certainly a pure render-to-X-offset.
WARN_LOG_REPORT_ONCE(renderoffset, HLE, "Rendering to framebuffer offset at %08x +%dx%d (stride %d)", v->fb_address, x_offset, 0, v->fb_stride);
vfb = v;
gstate_c.SetCurRTOffset(x_offset, 0);
vfb->width = std::max((int)vfb->width, x_offset + drawing_width);
// To prevent the newSize code from being confused.
drawing_width += x_offset;
break;
}
} else {
// We ignore this match.
// TODO: We can allow X/Y overlaps too, but haven't seen any so safer to not.
}
}
}
if (vfb) {
bool resized = false;
if ((drawing_width != vfb->bufferWidth || drawing_height != vfb->bufferHeight)) {
// Even if it's not newly wrong, if this is larger we need to resize up.
if (vfb->width > vfb->bufferWidth || vfb->height > vfb->bufferHeight) {
ResizeFramebufFBO(vfb, vfb->width, vfb->height);
resized = true;
} else if (vfb->newWidth != drawing_width || vfb->newHeight != drawing_height) {
// If it's newly wrong, or changing every frame, just keep track.
vfb->newWidth = drawing_width;
vfb->newHeight = drawing_height;
vfb->lastFrameNewSize = gpuStats.numFlips;
} else if (vfb->lastFrameNewSize + FBO_OLD_AGE < gpuStats.numFlips) {
// Okay, it's changed for a while (and stayed that way.) Let's start over.
// But only if we really need to, to avoid blinking.
bool needsRecreate = vfb->bufferWidth > params.fb_stride;
needsRecreate = needsRecreate || vfb->newWidth > vfb->bufferWidth || vfb->newWidth * 2 < vfb->bufferWidth;
needsRecreate = needsRecreate || vfb->newHeight > vfb->bufferHeight || vfb->newHeight * 2 < vfb->bufferHeight;
// Whether we resize or not, change the size parameters so we stop detecting a resize.
// It might be larger if all drawing has been in throughmode.
vfb->width = drawing_width;
vfb->height = drawing_height;
if (needsRecreate) {
ResizeFramebufFBO(vfb, vfb->width, vfb->height, true);
resized = true;
// Let's discard this information, might be wrong now.
vfb->safeWidth = 0;
vfb->safeHeight = 0;
}
}
} else {
// It's not different, let's keep track of that too.
vfb->lastFrameNewSize = gpuStats.numFlips;
}
if (!resized && renderScaleFactor_ != 1 && vfb->renderScaleFactor == 1) {
// Might be time to change this framebuffer - have we used depth?
if ((vfb->usageFlags & FB_USAGE_COLOR_MIXED_DEPTH) && !PSP_CoreParameter().compat.flags().ForceLowerResolutionForEffectsOn) {
ResizeFramebufFBO(vfb, vfb->width, vfb->height, true);
_assert_(vfb->renderScaleFactor != 1);
}
}
}
// None found? Create one.
if (!vfb) {
gstate_c.usingDepth = false; // reset depth buffer tracking
vfb = new VirtualFramebuffer{};
vfb->fbo = nullptr;
vfb->fb_address = params.fb_address;
vfb->fb_stride = params.fb_stride;
vfb->z_address = params.z_address;
vfb->z_stride = params.z_stride;
// The other width/height parameters are set in ResizeFramebufFBO below.
vfb->width = drawing_width;
vfb->height = drawing_height;
vfb->newWidth = drawing_width;
vfb->newHeight = drawing_height;
vfb->lastFrameNewSize = gpuStats.numFlips;
vfb->fb_format = params.fb_format;
vfb->usageFlags = FB_USAGE_RENDER_COLOR;
u32 colorByteSize = vfb->BufferByteSize(RASTER_COLOR);
if (Memory::IsVRAMAddress(params.fb_address) && params.fb_address + colorByteSize > framebufRangeEnd_) {
framebufRangeEnd_ = params.fb_address + colorByteSize;
}
// This is where we actually create the framebuffer. The true is "force".
ResizeFramebufFBO(vfb, drawing_width, drawing_height, true);
NotifyRenderFramebufferCreated(vfb);
// Note that we do not even think about depth right now. That'll be handled
// on the first depth access, which will call SetDepthFramebuffer.
CopyToColorFromOverlappingFramebuffers(vfb);
SetColorUpdated(vfb, skipDrawReason);
INFO_LOG(FRAMEBUF, "Creating FBO for %08x (z: %08x) : %d x %d x %s", vfb->fb_address, vfb->z_address, vfb->width, vfb->height, GeBufferFormatToString(vfb->fb_format));
vfb->last_frame_render = gpuStats.numFlips;
frameLastFramebufUsed_ = gpuStats.numFlips;
vfbs_.push_back(vfb);
currentRenderVfb_ = vfb;
// Assume that if we're clearing right when switching to a new framebuffer, we don't need to upload.
if (useBufferedRendering_ && params.isDrawing) {
gpu->PerformWriteColorFromMemory(params.fb_address, colorByteSize);
// Alpha was already done by PerformWriteColorFromMemory.
PerformWriteStencilFromMemory(params.fb_address, colorByteSize, WriteStencil::STENCIL_IS_ZERO | WriteStencil::IGNORE_ALPHA);
// TODO: Is it worth trying to upload the depth buffer (only if it wasn't copied above..?)
}
DiscardFramebufferCopy();
// We already have it!
} else if (vfb != currentRenderVfb_) {
// Use it as a render target.
DEBUG_LOG(FRAMEBUF, "Switching render target to FBO for %08x: %d x %d x %d ", vfb->fb_address, vfb->width, vfb->height, vfb->fb_format);
vfb->usageFlags |= FB_USAGE_RENDER_COLOR;
vfb->last_frame_render = gpuStats.numFlips;
frameLastFramebufUsed_ = gpuStats.numFlips;
vfb->dirtyAfterDisplay = true;
if ((skipDrawReason & SKIPDRAW_SKIPFRAME) == 0)
vfb->reallyDirtyAfterDisplay = true;
VirtualFramebuffer *prev = currentRenderVfb_;
currentRenderVfb_ = vfb;
NotifyRenderFramebufferSwitched(prev, vfb, params.isClearingDepth);
CopyToColorFromOverlappingFramebuffers(vfb);
gstate_c.usingDepth = false; // reset depth buffer tracking
DiscardFramebufferCopy();
} else {
// Something changed, but we still got the same framebuffer we were already rendering to.
// Might not be a lot to do here, we check in NotifyRenderFramebufferUpdated
vfb->last_frame_render = gpuStats.numFlips;
frameLastFramebufUsed_ = gpuStats.numFlips;
vfb->dirtyAfterDisplay = true;
if ((skipDrawReason & SKIPDRAW_SKIPFRAME) == 0)
vfb->reallyDirtyAfterDisplay = true;
NotifyRenderFramebufferUpdated(vfb);
}
vfb->colorBindSeq = GetBindSeqCount();
gstate_c.curRTWidth = vfb->width;
gstate_c.curRTHeight = vfb->height;
gstate_c.curRTRenderWidth = vfb->renderWidth;
gstate_c.curRTRenderHeight = vfb->renderHeight;
return vfb;
}
// Called on the first use of depth in a render pass.
void FramebufferManagerCommon::SetDepthFrameBuffer(bool isClearingDepth) {
if (!currentRenderVfb_) {
return;
}
// First time use of this framebuffer's depth buffer.
bool newlyUsingDepth = (currentRenderVfb_->usageFlags & FB_USAGE_RENDER_DEPTH) == 0;
currentRenderVfb_->usageFlags |= FB_USAGE_RENDER_DEPTH;
uint32_t boundDepthBuffer = gstate.getDepthBufRawAddress() | 0x04000000;
uint32_t boundDepthStride = gstate.DepthBufStride();
if (currentRenderVfb_->z_address != boundDepthBuffer || currentRenderVfb_->z_stride != boundDepthStride) {
if (currentRenderVfb_->fb_address == boundDepthBuffer) {
// Disallow setting depth buffer to the same address as the color buffer, usually means it's not used.
WARN_LOG_N_TIMES(z_reassign, 5, G3D, "Ignoring color matching depth buffer at %08x", boundDepthBuffer);
boundDepthBuffer = 0;
boundDepthStride = 0;
}
WARN_LOG_N_TIMES(z_reassign, 5, G3D, "Framebuffer at %08x/%d has switched associated depth buffer from %08x to %08x, updating.",
currentRenderVfb_->fb_address, currentRenderVfb_->fb_stride, currentRenderVfb_->z_address, boundDepthBuffer);
// Technically, here we should copy away the depth buffer to another framebuffer that uses that z_address, or maybe
// even write it back to RAM. However, this is rare. Silent Hill is one example, see #16126.
currentRenderVfb_->z_address = boundDepthBuffer;
// Update the stride in case it changed.
currentRenderVfb_->z_stride = boundDepthStride;
if (currentRenderVfb_->fbo) {
char tag[128];
FormatFramebufferName(currentRenderVfb_, tag, sizeof(tag));
currentRenderVfb_->fbo->UpdateTag(tag);
}
}
// If this first draw call is anything other than a clear, "resolve" the depth buffer,
// by copying from any overlapping buffers with fresher content.
if (!isClearingDepth && useBufferedRendering_) {
CopyToDepthFromOverlappingFramebuffers(currentRenderVfb_);
// Need to upload the first line of depth buffers, for Burnout Dominator lens flares. See issue #11100 and comments to #16081.
// Might make this more generic and upload the whole depth buffer if we find it's needed for something.
if (newlyUsingDepth && draw_->GetDeviceCaps().fragmentShaderDepthWriteSupported) {
// Sanity check the depth buffer pointer.
if (Memory::IsValidRange(currentRenderVfb_->z_address, currentRenderVfb_->width * 2)) {
const u16 *src = (const u16 *)Memory::GetPointerUnchecked(currentRenderVfb_->z_address);
DrawPixels(currentRenderVfb_, 0, 0, (const u8 *)src, GE_FORMAT_DEPTH16, currentRenderVfb_->z_stride, currentRenderVfb_->width, currentRenderVfb_->height, RASTER_DEPTH, "Depth Upload");
}
}
}
currentRenderVfb_->depthBindSeq = GetBindSeqCount();
}
struct CopySource {
VirtualFramebuffer *vfb;
RasterChannel channel;
int xOffset;
int yOffset;
int seq() const {
return channel == RASTER_DEPTH ? vfb->depthBindSeq : vfb->colorBindSeq;
}
bool operator < (const CopySource &other) const {
return seq() < other.seq();
}
};
// Not sure if it's more profitable to always do these copies with raster (which may screw up early-Z due to explicit depth buffer write)
// or to use image copies when possible (which may make it easier for the driver to preserve early-Z, but on the other hand, will cost additional memory
// bandwidth on tilers due to the load operation, which we might otherwise be able to skip).
void FramebufferManagerCommon::CopyToDepthFromOverlappingFramebuffers(VirtualFramebuffer *dest) {
std::vector<CopySource> sources;
for (auto src : vfbs_) {
if (src == dest)
continue;
if (src->fb_address == dest->z_address && src->fb_stride == dest->z_stride && src->fb_format == GE_FORMAT_565) {
if (src->colorBindSeq > dest->depthBindSeq) {
// Source has newer data than the current buffer, use it.
sources.push_back(CopySource{ src, RASTER_COLOR, 0, 0 });
}
} else if (src->z_address == dest->z_address && src->z_stride == dest->z_stride && src->depthBindSeq > dest->depthBindSeq) {
sources.push_back(CopySource{ src, RASTER_DEPTH, 0, 0 });
} else {
// TODO: Do more detailed overlap checks here.
}
}
std::sort(sources.begin(), sources.end());
// TODO: A full copy will overwrite anything else. So we can eliminate
// anything that comes before such a copy.
// For now, let's just do the last thing, if there are multiple.
// for (auto &source : sources) {
if (!sources.empty()) {
draw_->Invalidate(InvalidationFlags::CACHED_RENDER_STATE);
auto &source = sources.back();
if (source.channel == RASTER_DEPTH) {
// Good old depth->depth copy.
BlitFramebufferDepth(source.vfb, dest);
gpuStats.numDepthCopies++;
dest->last_frame_depth_updated = gpuStats.numFlips;
} else if (source.channel == RASTER_COLOR && draw_->GetDeviceCaps().fragmentShaderDepthWriteSupported) {
VirtualFramebuffer *src = source.vfb;
if (src->fb_format != GE_FORMAT_565) {
WARN_LOG_ONCE(not565, G3D, "fb_format of buffer at %08x not 565 as expected", src->fb_address);
}
// Really hate to do this, but tracking the depth swizzle state across multiple
// copies is not easy.
Draw2DShader shader = DRAW2D_565_TO_DEPTH;
if (PSP_CoreParameter().compat.flags().DeswizzleDepth) {
shader = DRAW2D_565_TO_DEPTH_DESWIZZLE;
}
gpuStats.numReinterpretCopies++;
src->usageFlags |= FB_USAGE_COLOR_MIXED_DEPTH;
dest->usageFlags |= FB_USAGE_COLOR_MIXED_DEPTH;
// Copying color to depth.
BlitUsingRaster(
src->fbo, 0.0f, 0.0f, src->renderWidth, src->renderHeight,
dest->fbo, 0.0f, 0.0f, src->renderWidth, src->renderHeight,
false, dest->renderScaleFactor, Get2DPipeline(shader), "565_to_depth");
}
}
gstate_c.Dirty(DIRTY_ALL_RENDER_STATE);
}
// Can't easily dynamically create these strings, we just pass along the pointer.
static const char *reinterpretStrings[4][4] = {
{
"self_reinterpret_565",
"reinterpret_565_to_5551",
"reinterpret_565_to_4444",
"reinterpret_565_to_8888",
},
{
"reinterpret_5551_to_565",
"self_reinterpret_5551",
"reinterpret_5551_to_4444",
"reinterpret_5551_to_8888",
},
{
"reinterpret_4444_to_565",
"reinterpret_4444_to_5551",
"self_reinterpret_4444",
"reinterpret_4444_to_8888",
},
{
"reinterpret_8888_to_565",
"reinterpret_8888_to_5551",
"reinterpret_8888_to_4444",
"self_reinterpret_8888",
},
};
// Call this after the target has been bound for rendering. For color, raster is probably always going to win over blits/copies.
void FramebufferManagerCommon::CopyToColorFromOverlappingFramebuffers(VirtualFramebuffer *dst) {
if (!useBufferedRendering_) {
return;
}
std::vector<CopySource> sources;
for (auto src : vfbs_) {
// Discard old and equal potential inputs.
if (src == dst || src->colorBindSeq < dst->colorBindSeq) {
continue;
}
if (src->fb_address == dst->fb_address && src->fb_stride == dst->fb_stride) {
// Another render target at the exact same location but gotta be a different format or a different stride, otherwise
// it would be the same, and should have been detected in DoSetRenderFrameBuffer.
if (src->fb_format != dst->fb_format) {
// This will result in reinterpret later, if both formats are 16-bit.
sources.push_back(CopySource{ src, RASTER_COLOR, 0, 0 });
} else {
// This shouldn't happen anymore. I think when it happened last, we still had
// lax stride checking when video was incoming, and a resize happened causing a duplicate.
}
} else if (src->fb_stride == dst->fb_stride && src->fb_format == dst->fb_format) {
u32 bytesPerPixel = BufferFormatBytesPerPixel(src->fb_format);
u32 strideInBytes = src->fb_stride * bytesPerPixel; // Same for both src and dest
u32 srcColorStart = src->fb_address;
u32 srcFirstLineEnd = src->fb_address + strideInBytes;
u32 srcColorEnd = strideInBytes * src->height;
u32 dstColorStart = dst->fb_address;
u32 dstFirstLineEnd = dst->fb_address + strideInBytes;
u32 dstColorEnd = strideInBytes * dst->height;
// Initially we'll only allow pure horizontal and vertical overlap,
// to reduce the risk for false positives. We can allow diagonal overlap too if needed
// in the future.
// Check for potential vertical overlap, like in Juiced 2.
int xOffset = 0;
int yOffset = 0;
// TODO: Get rid of the compatibility flag check.
if ((dstColorStart - srcColorStart) % strideInBytes == 0
&& PSP_CoreParameter().compat.flags().AllowLargeFBTextureOffsets) {
// Buffers are aligned.
yOffset = ((int)dstColorStart - (int)srcColorStart) / strideInBytes;
if (yOffset <= -(int)src->height) {
// Not overlapping
continue;
} else if (yOffset >= dst->height) {
// Not overlapping
continue;
}
} else {
// Buffers not stride-aligned - ignoring for now.
// This is where we'll add the horizontal offset for GoW.
continue;
}
sources.push_back(CopySource{ src, RASTER_COLOR, xOffset, yOffset });
} else if (src->fb_address == dst->fb_address && src->FbStrideInBytes() == dst->FbStrideInBytes()) {
if (src->fb_stride == dst->fb_stride * 2) {
// Reinterpret from 16-bit to 32-bit.
sources.push_back(CopySource{ src, RASTER_COLOR, 0, 0 });
} else if (src->fb_stride * 2 == dst->fb_stride) {
// Reinterpret from 32-bit to 16-bit.
sources.push_back(CopySource{ src, RASTER_COLOR, 0, 0 });
} else {
// 16-to-16 reinterpret, should have been caught above already.
_assert_msg_(false, "Reinterpret: Shouldn't get here");
}
}
}
std::sort(sources.begin(), sources.end());
draw_->Invalidate(InvalidationFlags::CACHED_RENDER_STATE);
bool tookActions = false;
// TODO: Only do the latest one.
for (const CopySource &source : sources) {
VirtualFramebuffer *src = source.vfb;
// Copy a rectangle from the original to the new buffer.
// Yes, we mean to look at src->width/height for the dest rectangle.
// TODO: Try to bound the blit using gstate_c.vertBounds like depal does.
int srcWidth = src->width * src->renderScaleFactor;
int srcHeight = src->height * src->renderScaleFactor;
int dstWidth = src->width * dst->renderScaleFactor;
int dstHeight = src->height * dst->renderScaleFactor;
int dstX1 = -source.xOffset * dst->renderScaleFactor;
int dstY1 = -source.yOffset * dst->renderScaleFactor;
int dstX2 = dstX1 + dstWidth;
int dstY2 = dstY1 + dstHeight;
if (source.channel == RASTER_COLOR) {
Draw2DPipeline *pipeline = nullptr;
const char *pass_name = "N/A";
if (src->fb_format == dst->fb_format) {
gpuStats.numColorCopies++;
pipeline = Get2DPipeline(DRAW2D_COPY_COLOR);
pass_name = "copy_color";
} else {
if (PSP_CoreParameter().compat.flags().BlueToAlpha) {
WARN_LOG_ONCE(bta, G3D, "WARNING: Reinterpret encountered with BlueToAlpha on");
}
// Reinterpret!
WARN_LOG_N_TIMES(reint, 5, G3D, "Reinterpret detected from %08x_%s to %08x_%s",
src->fb_address, GeBufferFormatToString(src->fb_format),
dst->fb_address, GeBufferFormatToString(dst->fb_format));
float scaleFactorX = 1.0f;
pipeline = GetReinterpretPipeline(src->fb_format, dst->fb_format, &scaleFactorX);
dstX1 *= scaleFactorX;
dstX2 *= scaleFactorX;
pass_name = reinterpretStrings[(int)src->fb_format][(int)dst->fb_format];
gpuStats.numReinterpretCopies++;
}
if (pipeline) {
tookActions = true;
// OK we have the pipeline, now just do the blit.
BlitUsingRaster(src->fbo, 0.0f, 0.0f, srcWidth, srcHeight,
dst->fbo, dstX1, dstY1, dstX2, dstY2, false, dst->renderScaleFactor, pipeline, pass_name);
}
}
}
if (currentRenderVfb_ && dst != currentRenderVfb_ && tookActions) {
// Will probably just change the name of the current renderpass, since one was started by the reinterpret itself.
draw_->BindFramebufferAsRenderTarget(currentRenderVfb_->fbo, { Draw::RPAction::KEEP, Draw::RPAction::KEEP, Draw::RPAction::KEEP }, "After Reinterpret");
}
shaderManager_->DirtyLastShader();
textureCache_->ForgetLastTexture();
}
Draw2DPipeline *FramebufferManagerCommon::GetReinterpretPipeline(GEBufferFormat from, GEBufferFormat to, float *scaleFactorX) {
if (from == to) {
*scaleFactorX = 1.0f;
return Get2DPipeline(DRAW2D_COPY_COLOR);
}
if (IsBufferFormat16Bit(from) && !IsBufferFormat16Bit(to)) {
// We halve the X coordinates in the destination framebuffer.
// The shader will collect two pixels worth of input data and merge into one.
*scaleFactorX = 0.5f;
} else if (!IsBufferFormat16Bit(from) && IsBufferFormat16Bit(to)) {
// We double the X coordinates in the destination framebuffer.
// The shader will sample and depending on the X coordinate & 1, use the upper or lower bits.
*scaleFactorX = 2.0f;
} else {
*scaleFactorX = 1.0f;
}
Draw2DPipeline *pipeline = reinterpretFromTo_[(int)from][(int)to];
if (!pipeline) {
pipeline = draw2D_.Create2DPipeline([=](ShaderWriter &shaderWriter) -> Draw2DPipelineInfo {
return GenerateReinterpretFragmentShader(shaderWriter, from, to);
});
reinterpretFromTo_[(int)from][(int)to] = pipeline;
}
return pipeline;
}
void FramebufferManagerCommon::DestroyFramebuf(VirtualFramebuffer *v) {
// Notify the texture cache of both the color and depth buffers.
textureCache_->NotifyFramebuffer(v, NOTIFY_FB_DESTROYED);
if (v->fbo) {
v->fbo->Release();
v->fbo = nullptr;
}
// Wipe some pointers
DiscardFramebufferCopy();
if (currentRenderVfb_ == v)
currentRenderVfb_ = nullptr;
if (displayFramebuf_ == v)
displayFramebuf_ = nullptr;
if (prevDisplayFramebuf_ == v)
prevDisplayFramebuf_ = nullptr;
if (prevPrevDisplayFramebuf_ == v)
prevPrevDisplayFramebuf_ = nullptr;
delete v;
}
void FramebufferManagerCommon::BlitFramebufferDepth(VirtualFramebuffer *src, VirtualFramebuffer *dst) {
_dbg_assert_(src && dst);
_dbg_assert_(src != dst);
// Check that the depth address is even the same before actually blitting.
bool matchingDepthBuffer = src->z_address == dst->z_address && src->z_stride != 0 && dst->z_stride != 0;
bool matchingSize = (src->width == dst->width || (src->width == 512 && dst->width == 480) || (src->width == 480 && dst->width == 512)) && src->height == dst->height;
if (!matchingDepthBuffer || !matchingSize) {
return;
}
// Copy depth value from the previously bound framebuffer to the current one.
bool hasNewerDepth = src->last_frame_depth_render != 0 && src->last_frame_depth_render >= dst->last_frame_depth_updated;
if (!src->fbo || !dst->fbo || !useBufferedRendering_ || !hasNewerDepth) {
// If depth wasn't updated, then we're at least "two degrees" away from the data.
// This is an optimization: it probably doesn't need to be copied in this case.
return;
}
bool useCopy = draw_->GetDeviceCaps().framebufferSeparateDepthCopySupported || (!draw_->GetDeviceCaps().framebufferDepthBlitSupported && draw_->GetDeviceCaps().framebufferCopySupported);
bool useBlit = draw_->GetDeviceCaps().framebufferDepthBlitSupported;
bool useRaster = draw_->GetDeviceCaps().fragmentShaderDepthWriteSupported && draw_->GetDeviceCaps().textureDepthSupported;
if (src->fbo->MultiSampleLevel() > 0 && dst->fbo->MultiSampleLevel() > 0) {
// If multisampling, we want to copy depth properly so we get all the samples, to avoid aliased edges.
// Can be seen in the fire in Jeanne D'arc, for example.
if (useRaster && useCopy) {
useRaster = false;
}
}
int w = std::min(src->renderWidth, dst->renderWidth);
int h = std::min(src->renderHeight, dst->renderHeight);
// Some GPUs can copy depth but only if stencil gets to come along for the ride. We only want to use this if there is no blit functionality.
if (useRaster) {
BlitUsingRaster(src->fbo, 0, 0, w, h, dst->fbo, 0, 0, w, h, false, dst->renderScaleFactor, Get2DPipeline(Draw2DShader::DRAW2D_COPY_DEPTH), "BlitDepthRaster");
} else if (useCopy) {
draw_->CopyFramebufferImage(src->fbo, 0, 0, 0, 0, dst->fbo, 0, 0, 0, 0, w, h, 1, Draw::FB_DEPTH_BIT, "CopyFramebufferDepth");
RebindFramebuffer("After BlitFramebufferDepth");
} else if (useBlit) {
// We'll accept whether we get a separate depth blit or not...
draw_->BlitFramebuffer(src->fbo, 0, 0, w, h, dst->fbo, 0, 0, w, h, Draw::FB_DEPTH_BIT, Draw::FB_BLIT_NEAREST, "BlitFramebufferDepth");
RebindFramebuffer("After BlitFramebufferDepth");
}
draw_->Invalidate(InvalidationFlags::CACHED_RENDER_STATE);
}
void FramebufferManagerCommon::NotifyRenderFramebufferCreated(VirtualFramebuffer *vfb) {
if (!useBufferedRendering_) {
// Let's ignore rendering to targets that have not (yet) been displayed.
gstate_c.skipDrawReason |= SKIPDRAW_NON_DISPLAYED_FB;
} else if (currentRenderVfb_) {
DownloadFramebufferOnSwitch(currentRenderVfb_);
}