Repository navigation
Expand file tree
/
Copy pathrt64.patch
More file actions
4051 lines (3904 loc) · 219 KB
/
Copy pathrt64.patch
File metadata and controls
4051 lines (3904 loc) · 219 KB
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
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 79dfc38..6467e67 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -327,6 +327,7 @@ set (SOURCES
"${PROJECT_SOURCE_DIR}/src/gbi/rt64_gbi_f3d.cpp"
"${PROJECT_SOURCE_DIR}/src/gbi/rt64_gbi_f3dex.cpp"
"${PROJECT_SOURCE_DIR}/src/gbi/rt64_gbi_f3dex2.cpp"
+ "${PROJECT_SOURCE_DIR}/src/gbi/rt64_gbi_f3dex2cbfd.cpp"
"${PROJECT_SOURCE_DIR}/src/gbi/rt64_gbi_f3dgolden.cpp"
"${PROJECT_SOURCE_DIR}/src/gbi/rt64_gbi_f3dpd.cpp"
"${PROJECT_SOURCE_DIR}/src/gbi/rt64_gbi_f3dwave.cpp"
@@ -359,6 +360,7 @@ set (SOURCES
"${PROJECT_SOURCE_DIR}/src/hle/rt64_projection.cpp"
"${PROJECT_SOURCE_DIR}/src/hle/rt64_rdp.cpp"
"${PROJECT_SOURCE_DIR}/src/hle/rt64_rdp_tmem.cpp"
+ "${PROJECT_SOURCE_DIR}/src/hle/rt64_rice_hash.cpp"
"${PROJECT_SOURCE_DIR}/src/hle/rt64_rigid_body.cpp"
"${PROJECT_SOURCE_DIR}/src/hle/rt64_rsp.cpp"
"${PROJECT_SOURCE_DIR}/src/hle/rt64_state.cpp"
@@ -518,6 +520,7 @@ build_compute_shader(rt64 "src/shaders/FbWriteDepthCS.hlsl")
build_compute_shader(rt64 "src/shaders/FbWriteDepthCS.hlsl" "src/shaders/FbWriteDepthCSMS.hlsl" "-D MULTISAMPLING")
build_compute_shader(rt64 "src/shaders/GaussianFilterRGB3x3CS.hlsl")
build_compute_shader(rt64 "src/shaders/BoxFilterCS.hlsl")
+build_compute_shader(rt64 "src/shaders/ConkerBlurCS.hlsl")
build_compute_shader(rt64 "src/shaders/BicubicScalingCS.hlsl")
build_compute_shader(rt64 "src/shaders/HistogramAverageCS.hlsl")
build_compute_shader(rt64 "src/shaders/HistogramClearCS.hlsl")
diff --git a/include/rt64_extended_gbi.h b/include/rt64_extended_gbi.h
index d387090..094290e 100644
--- a/include/rt64_extended_gbi.h
+++ b/include/rt64_extended_gbi.h
@@ -80,7 +80,9 @@
#define G_EX_SETVERTEXSEGMENT_V1 0x000031
#define G_EX_SETTEXCOORDWRAPPOINT_V1 0x000032
#define G_EX_SETRECTASPECT_V1 0x000033
-#define G_EX_MAX 0x000034
+#define G_EX_CONKERBLURFRAMEBUFFER_V1 0x000034 // Conker: see gEXConkerBlurFramebuffer
+#define G_EX_CONKERFOCUSPLACED_V1 0x000035 // Conker: see gEXConkerFocusPlaced
+#define G_EX_MAX 0x000036
#define G_EX_ORIGIN_NONE 0x800
#define G_EX_ORIGIN_LEFT 0x0
@@ -113,6 +115,9 @@
#define G_EX_ASPECT_AUTO 0x0
#define G_EX_ASPECT_STRETCH 0x1
#define G_EX_ASPECT_ADJUST 0x2
+// Stretched to the width like G_EX_ASPECT_STRETCH, and scaled as much vertically about the
+// middle of the scissor, keeping the rect's proportions (its top and bottom are cropped).
+#define G_EX_ASPECT_ZOOM 0x3
#define G_EX_VERTEX_POSITION 0x0
#define G_EX_VERTEX_VELOCITY 0x1
@@ -579,4 +584,30 @@ typedef union {
PARAM(aspect, 2, 0) \
)
+// Conker: once the frame's last framebuffer pair drawing into the color image at address (24 bits) is drawn, its high
+// resolution picture is blurred, by strength (8 bits) quarters of an N64 pixel. A copy of the frame blurred this way
+// stays as sharp as the high resolution picture and as wide as the widened view: the pause menu's background (Conker's
+// own blurs its copy on the CPU, in RDRAM, where it's the N64's 320 pixels and only the 4:3 view).
+#define gEXConkerBlurFramebuffer(cmd, address, strength) \
+ G_EX_COMMAND1(cmd, \
+ PARAM(RT64_EXTENDED_OPCODE, 8, 24) | PARAM(G_EX_CONKERBLURFRAMEBUFFER_V1, 24, 0), \
+ PARAM(strength, 8, 24) | PARAM(address, 24, 0) \
+ )
+
+// Conker: netplay's "my view only" redraws each shown view elsewhere in the frame and moves its rectangles with it
+// (rt64_conker_view_focus.h). Some 2D of a view can't simply be moved: the bazooka's tinted copy of the frame, strips
+// copied from where the view is drawn. The display list gives it twice: placed for each place the view may be drawn,
+// and as the game draws it. Until mode 0 (or a display list starts), the rectangles that follow are:
+// - mode 1, placed: for the view at x, y (pixels of the frame, where the game draws it), drawn where it is drawn at
+// `layouts` (one bit: G_EX_CONKER_FOCUS_WHOLE, _TOP or _BOTTOM). Drawn as they are, only while it's drawn there.
+// - mode 2, the game's own: drawn as ever, unless the view at x, y is drawn at one of `layouts` (bits), the placed ones.
+#define G_EX_CONKER_FOCUS_WHOLE 0x1
+#define G_EX_CONKER_FOCUS_TOP 0x2
+#define G_EX_CONKER_FOCUS_BOTTOM 0x4
+#define gEXConkerFocusPlaced(cmd, mode, layouts, x, y) \
+ G_EX_COMMAND1(cmd, \
+ PARAM(RT64_EXTENDED_OPCODE, 8, 24) | PARAM(G_EX_CONKERFOCUSPLACED_V1, 24, 0), \
+ PARAM(mode, 2, 30) | PARAM(layouts, 3, 24) | PARAM(x, 10, 8) | PARAM(y, 8, 0) \
+ )
+
#endif // RT64_EXTENDED_GBI
diff --git a/src/common/rt64_common.h b/src/common/rt64_common.h
index f79adbf..e40a61d 100644
--- a/src/common/rt64_common.h
+++ b/src/common/rt64_common.h
@@ -70,6 +70,18 @@ namespace RT64 {
int x, y, w, h;
};
+ // How far (10.2 fixed point) a projection's scissor may fall short of its framebuffer pair's scissor on each
+ // side and still count as covering the whole width, for the widescreen viewport and projection adjustment.
+ // Conker's 3D scissor stops 2 pixels short of each edge of the frame, and a full-frame rectangle drawn in the
+ // same pair would otherwise put its 3D back in the 4:3 area.
+ constexpr int32_t CoversWidthSlack = 4 * 4;
+
+ // The same for a 3D view's viewport, which may fall further short: Conker's split-screen multiplayer draws each
+ // player's view 32 pixels in from each edge, and the top view shares its pair with full-frame drawing, so with
+ // the rects' slack only the bottom view was widened. Rects keep the smaller slack, so 2D a little inside the
+ // frame isn't stretched to the widened edges.
+ constexpr int32_t CoversWidthViewportSlack = 40 * 4;
+
struct FixedRect {
int32_t ulx;
int32_t uly;
diff --git a/src/common/rt64_conker_view_focus.h b/src/common/rt64_conker_view_focus.h
new file mode 100644
index 0000000..168a50c
--- /dev/null
+++ b/src/common/rt64_conker_view_focus.h
@@ -0,0 +1,195 @@
+//
+// RT64
+//
+
+// Conker: netplay's "my view only", drawn anew (the host's netplay/view.cpp). While it's on, this machine's players'
+// views of the split screen are each drawn across a part of the frame of their own instead of their part of the
+// split, and the other views aren't drawn: one player's view across the whole frame, two players' views across the
+// top and bottom halves. Each view's viewport and scissor are moved and stretched with it (RSP::setViewport,
+// RDP::setScissor; a smaller one inside the view goes to the same place in the stretched view), and its projection
+// is scaled by as much as the stretch isn't uniform (ProjectionProcessor), so nothing is stretched: a view made
+// relatively taller shows more of the scene up and down, one made relatively wider more of it across. The widescreen
+// widening then widens each like any view across the frame's width. The other views' viewports are collapsed to
+// nothing and their scissors emptied, which also leaves out their 2D. Rectangles in pixels of the frame, which is
+// frameWidth by frameHeight. Only the renderer changes: the game's memory doesn't (its Render to RAM is off in
+// netplay), so it can't desync.
+
+#pragma once
+
+#include <algorithm>
+#include <cmath>
+
+#include "common/rt64_common.h"
+
+
+namespace RT64 {
+ // One focused view: where the game draws it (src), and where it's drawn instead.
+ struct ConkerFocusView {
+ float srcLeft = 0.0f, srcTop = 0.0f, srcRight = 0.0f, srcBottom = 0.0f;
+ float left = 0.0f, top = 0.0f, right = 0.0f, bottom = 0.0f;
+ };
+
+ constexpr int ConkerMaxFocusViews = 2;
+
+ struct ConkerViewFocus {
+ bool on = false;
+ int count = 0;
+ ConkerFocusView views[ConkerMaxFocusViews];
+ float frameWidth = 0.0f, frameHeight = 0.0f;
+ uint32_t ownImages[2] = {};
+ };
+
+ // Set by the game's host each frame (defined in rt64_vi_renderer.cpp): `count` views (1 or 2), each 8 floats in
+ // `rects`, its rectangle in the split then where it's drawn (left, top, right, bottom). ownImages: the
+ // addresses of two images as wide as the frame that aren't it (0 for none), the game's own copies of it (the
+ // pause menu's picture, which is also the depth image: its clear covers the whole frame, left alone anyway).
+ void setViewFocusRedraw(bool on, int count, const float *rects, float frameWidth, float frameHeight,
+ uint32_t ownImage0, uint32_t ownImage1);
+ ConkerViewFocus conkerViewFocus();
+
+ // Whether the focus applies to what's drawn now: only to the frame itself, an image as wide as the frame.
+ // The game also draws into small images of its own (a shadow's silhouette, 64 pixels wide), which the
+ // frame's views have nothing to do with, and into copies of the frame as wide as it (the pause menu's
+ // picture: tiles of the frame across all of it, which moved with the views, or left out, left the picture
+ // as it was in memory, stripes of colour behind the menu).
+ inline bool conkerFocusApplies(const ConkerViewFocus &f, uint16_t colorImageWidth, uint32_t colorImageAddress) {
+ if (!f.on || (f.count <= 0) || (f.frameWidth <= 0.0f) || (colorImageWidth != uint16_t(f.frameWidth))) {
+ return false;
+ }
+ for (uint32_t image : f.ownImages) {
+ if ((image != 0) && ((image & 0x00FFFFFF) == (colorImageAddress & 0x00FFFFFF))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ // A point of a focused view, where it goes in the frame: the view stretched to where it's drawn.
+ inline float conkerMapX(const ConkerFocusView &v, float x) { return v.left + (x - v.srcLeft) * (v.right - v.left) / (v.srcRight - v.srcLeft); }
+ inline float conkerMapY(const ConkerFocusView &v, float y) { return v.top + (y - v.srcTop) * (v.bottom - v.top) / (v.srcBottom - v.srcTop); }
+
+ // How much a focused view's projection is scaled across and down so what's drawn keeps its shape, from how much
+ // more it's stretched across than down (k). Alone across the frame it keeps its width of the scene and is made
+ // taller or shorter by k (a 2-player half, 1.26 / 2.04, about 0.62: more of the scene up and down; a quarter,
+ // about 1: unchanged). With two views, one made relatively wider (a quarter across half the frame, 2.04 / 1.0) is
+ // met halfway (`halfway`): by the square root of k across and down, more of the scene across and less up and
+ // down, rather than a band cut from the middle of it or a view twice as wide (which the widescreen widening
+ // would make wider again).
+ inline void conkerFocusScale(const ConkerFocusView &v, bool halfway, float &xScale, float &yScale) {
+ const float stretchX = (v.right - v.left) / (v.srcRight - v.srcLeft);
+ const float stretchY = (v.bottom - v.top) / (v.srcBottom - v.srcTop);
+ const float k = stretchX / stretchY;
+ if (!std::isfinite(k) || (k <= 0.0f) || (k <= 1.0f) || !halfway) {
+ xScale = 1.0f;
+ yScale = std::isfinite(k) && (k > 0.0f) ? k : 1.0f;
+ return;
+ }
+
+ const float root = std::sqrt(k);
+ xScale = 1.0f / root;
+ yScale = root;
+ }
+
+ // Where a rectangle (in pixels) stands: the whole frame (left alone), a focused view (`index`: moved with it),
+ // or another view (not drawn). Judged by its middle, so a view's own slightly different edges match.
+ enum class ConkerViewPart { Whole, Focused, Other };
+
+ inline ConkerViewPart conkerViewPart(const ConkerViewFocus &f, float left, float top, float right, float bottom, int &index, float slack = 0.0f) {
+ if (((right - left) >= 0.9f * f.frameWidth) && ((bottom - top) >= 0.9f * f.frameHeight)) {
+ return ConkerViewPart::Whole;
+ }
+ const float middleX = (left + right) / 2.0f;
+ const float middleY = (top + bottom) / 2.0f;
+ for (int i = 0; i < f.count; i++) {
+ const ConkerFocusView &v = f.views[i];
+ if ((middleX >= v.srcLeft - slack) && (middleX <= v.srcRight + slack) && (middleY >= v.srcTop - slack) && (middleY <= v.srcBottom + slack)) {
+ index = i;
+ return ConkerViewPart::Focused;
+ }
+ }
+ return ConkerViewPart::Other;
+ }
+
+ // Whether the focused view at x, y (pixels of the frame, where the game draws it) is drawn at one of `layouts`
+ // (gEXConkerFocusPlaced's bits): alone, across the whole frame (1); or the first of two, the top half (2); or
+ // the second, the bottom half (4).
+ inline bool conkerViewDrawnAt(const ConkerViewFocus &f, float x, float y, uint8_t layouts) {
+ int index = 0;
+ if (conkerViewPart(f, x, y, x, y, index) != ConkerViewPart::Focused) {
+ return false;
+ }
+ const uint8_t layout = (f.count == 1) ? 0x1 : (index == 0) ? 0x2 : 0x4;
+ return (layouts & layout) != 0;
+ }
+
+ // A rectangle of the frame's 2D (quarter pixels), moved with its focused view: false if it isn't drawn. Only moved,
+ // never scaled: the game draws a split screen's 2D at full size.
+ // - At the line between the top and bottom views (within 3 pixels of it): shared by the views. With one view
+ // focused it's moved down to the bottom of the frame, all of it by as much so it keeps together: the match timer
+ // in the middle of the frame, War's and Beach's team scores beside it, Heist's row of every player's $$$. With
+ // two it stays on the line, which is where the two halves meet.
+ // - Its middle outside the focused views: another's, left out (a piece on the line between views belongs to the
+ // one its middle is in, as Heist's $$$ rows).
+ // - Covering most of its view in fill mode (its clears, color and depth): all of where the view is drawn.
+ // - Otherwise its view's: moved as far as the view's nearest edges move, across and down. Its middle in the
+ // first 30% of the view's width goes with the left edge, past 70% with the right, otherwise with the middle
+ // (wide, so centered text such as "0 (1st)" moves whole); the same down. Kept inside where the view is drawn.
+ inline bool conkerMoveRect(const ConkerViewFocus &f, bool fillMode, FixedRect &rect) {
+ const float left = rect.ulx / 4.0f, top = rect.uly / 4.0f, right = rect.lrx / 4.0f, bottom = rect.lry / 4.0f;
+ if ((right - left >= 0.9f * f.frameWidth) && (bottom - top >= 0.9f * f.frameHeight)) {
+ return true;
+ }
+ const float splitLine = f.frameHeight / 2.0f;
+ const bool split = (f.views[0].srcBottom - f.views[0].srcTop) < 0.75f * f.frameHeight;
+ float moveX = 0.0f, moveY = 0.0f;
+ const float nearLine = 3.0f;
+ int index = 0;
+ if (split && (top < splitLine + nearLine) && (bottom > splitLine - nearLine)) {
+ if (f.count == 1) {
+ const float margin = 6.0f;
+ const float sharedHalfHeight = 6.0f;
+ moveY = (f.frameHeight - margin) - (splitLine + sharedHalfHeight);
+ }
+ }
+ else if (conkerViewPart(f, left, top, right, bottom, index, 1.0f) != ConkerViewPart::Focused) {
+ return false;
+ }
+ else {
+ const ConkerFocusView &v = f.views[index];
+ const float viewWidth = v.srcRight - v.srcLeft;
+ const float viewHeight = v.srcBottom - v.srcTop;
+ if (fillMode && (right - left >= 0.8f * viewWidth) && (bottom - top >= 0.8f * viewHeight)) {
+ rect.ulx = int32_t(v.left * 4.0f);
+ rect.uly = int32_t(v.top * 4.0f);
+ rect.lrx = int32_t(v.right * 4.0f);
+ rect.lry = int32_t(v.bottom * 4.0f);
+ return true;
+ }
+
+ auto edgeMove = [](float middle, float srcStart, float srcEnd, float start, float end) {
+ const float share = (middle - srcStart) / (srcEnd - srcStart);
+ if (share < 0.3f) return start - srcStart;
+ if (share > 0.7f) return end - srcEnd;
+ return (start + end) / 2.0f - (srcStart + srcEnd) / 2.0f;
+ };
+ moveX = edgeMove((left + right) / 2.0f, v.srcLeft, v.srcRight, v.left, v.right);
+ moveY = edgeMove((top + bottom) / 2.0f, v.srcTop, v.srcBottom, v.top, v.bottom);
+ // Kept inside where the view is drawn (a piece hanging over the view's edge would go past it), where it
+ // fits in it at all.
+ const float inset = 2.0f;
+ if ((right - left) <= (v.right - v.left) - 2.0f * inset) {
+ moveX = std::clamp(moveX, (v.left + inset) - left, (v.right - inset) - right);
+ }
+ if ((bottom - top) <= (v.bottom - v.top) - 2.0f * inset) {
+ moveY = std::clamp(moveY, (v.top + inset) - top, (v.bottom - inset) - bottom);
+ }
+ }
+ const int32_t dx = int32_t(std::lround(moveX * 4.0f));
+ const int32_t dy = int32_t(std::lround(moveY * 4.0f));
+ rect.ulx += dx;
+ rect.lrx += dx;
+ rect.uly += dy;
+ rect.lry += dy;
+ return true;
+ }
+};
diff --git a/src/common/rt64_fblog.h b/src/common/rt64_fblog.h
new file mode 100644
index 0000000..c9dd621
--- /dev/null
+++ b/src/common/rt64_fblog.h
@@ -0,0 +1,80 @@
+//
+// RT64
+//
+
+// TEMP-DEBUG (Conker): a log of what happens to framebuffers, depth and widening, for the
+// widescreen door clipping. Off unless CONKER_RT64_FBLOG is set. It then logs 2 frames out of
+// every 150 (about every 5 seconds), 40 times, to rt64_fb_log.txt in the working directory.
+// Frames are workload submission frames: the same number on the game's side (hle) and on the
+// renderer's side, which run on different threads.
+
+#pragma once
+
+#include <cstdarg>
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+#include <mutex>
+
+namespace RT64 {
+ namespace FbLog {
+ constexpr uint64_t Period = 150;
+ constexpr uint64_t FramesPerCapture = 2;
+ constexpr uint64_t Captures = 40;
+
+ inline bool enabled() {
+ static const bool on = (std::getenv("CONKER_RT64_FBLOG") != nullptr);
+ return on;
+ }
+
+ inline bool frameLogged(uint64_t frame) {
+ return enabled() && ((frame % Period) < FramesPerCapture) && ((frame / Period) < Captures);
+ }
+
+ // The frame being processed on this thread, for code that doesn't know its workload.
+ inline uint64_t &threadFrame() {
+ thread_local uint64_t frame = UINT64_MAX;
+ return frame;
+ }
+
+ // Which side this thread is: "hle" (the game's display lists, and the native render to
+ // RDRAM) or "hires" (the widened picture on screen).
+ inline const char *&threadSide() {
+ thread_local const char *side = "?";
+ return side;
+ }
+
+ inline void setThreadFrame(uint64_t frame, const char *side = nullptr) {
+ threadFrame() = frame;
+ if (side != nullptr) {
+ threadSide() = side;
+ }
+ }
+
+ inline bool threadActive() {
+ return (threadFrame() != UINT64_MAX) && frameLogged(threadFrame());
+ }
+
+ inline void print(const char *fmt, ...) {
+ static std::mutex mutex;
+ static FILE *file = nullptr;
+ std::lock_guard<std::mutex> lock(mutex);
+ if (file == nullptr) {
+ file = std::fopen("rt64_fb_log.txt", "w");
+ if (file == nullptr) {
+ return;
+ }
+ }
+
+ va_list args;
+ va_start(args, fmt);
+ std::vfprintf(file, fmt, args);
+ va_end(args);
+ std::fputc('\n', file);
+ std::fflush(file);
+ }
+ };
+};
+
+#define RT64_FBLOG_RECT(r) (r).ulx, (r).uly, (r).lrx, (r).lry
+#define RT64_FBLOG_RECT_FMT "(%d,%d)-(%d,%d)"
diff --git a/src/common/rt64_hlslpp.h b/src/common/rt64_hlslpp.h
index 1450565..032ed28 100644
--- a/src/common/rt64_hlslpp.h
+++ b/src/common/rt64_hlslpp.h
@@ -10,4 +10,8 @@
#define HLSLPP_SCALAR
#endif
+// The scalar implementation uses labs() without including <stdlib.h>, which recent
+// macOS SDKs no longer bring in through <math.h>.
+#include <stdlib.h>
+
#include "hlsl++.h"
\ No newline at end of file
diff --git a/src/common/rt64_replacement_database.cpp b/src/common/rt64_replacement_database.cpp
index 9f331c9..1d3f107 100644
--- a/src/common/rt64_replacement_database.cpp
+++ b/src/common/rt64_replacement_database.cpp
@@ -145,7 +145,7 @@ namespace RT64 {
}
}
- void ReplacementDatabase::resolvePaths(const FileSystem *fileSystem, uint32_t fileSystemIndex, std::unordered_map<uint64_t, ReplacementResolvedPath> &resolvedPathMap, bool onlyDDS, std::vector<uint64_t> *hashesMissing, std::unordered_set<std::string> *pathsToPreload) {
+ void ReplacementDatabase::resolvePaths(const FileSystem *fileSystem, uint32_t fileSystemIndex, std::unordered_map<uint64_t, ReplacementResolvedPath> &resolvedPathMap, bool onlyDDS, std::vector<uint64_t> *hashesMissing, std::unordered_set<std::string> *pathsToPreload, std::unordered_map<std::string, ReplacementResolvedPath> *ricePathMap) {
std::unordered_map<std::string, std::string> autoPathMap;
for (const std::string &relativePath : *fileSystem) {
const std::filesystem::path relativePathFs = std::filesystem::u8path(relativePath);
@@ -172,6 +172,19 @@ namespace RT64 {
}
}
+ if ((ricePathMap != nullptr) && (config.autoPath == ReplacementAutoPath::Rice)) {
+ const ReplacementTexture defaultTexture;
+ for (const auto &[riceHash, relativePath] : autoPathMap) {
+ ReplacementResolvedPath &resolvedPath = (*ricePathMap)[riceHash];
+ resolvedPath.fileSystemIndex = fileSystemIndex;
+ resolvedPath.relativePath = relativePath;
+ resolvedPath.originalOperation = defaultTexture.operation;
+ resolvedPath.originalShift = defaultTexture.shift;
+ resolvedPath.resolvedOperation = resolveOperation(relativePath, defaultTexture.operation);
+ resolvedPath.resolvedShift = resolveShift(relativePath, defaultTexture.shift);
+ }
+ }
+
auto addResolvedPath = [&](uint64_t hash, const std::string &relativePath, ReplacementOperation operation, ReplacementShift shift) {
// Do not modify the entry if it's already in the map.
if (resolvedPathMap.find(hash) != resolvedPathMap.end()) {
diff --git a/src/common/rt64_replacement_database.h b/src/common/rt64_replacement_database.h
index 3f74ea2..3988595 100644
--- a/src/common/rt64_replacement_database.h
+++ b/src/common/rt64_replacement_database.h
@@ -126,7 +126,9 @@ namespace RT64 {
void buildHashMaps();
ReplacementOperation resolveOperation(const std::string &relativePath, ReplacementOperation operation);
ReplacementShift resolveShift(const std::string &relativePath, ReplacementShift shift);
- void resolvePaths(const FileSystem *fileSystem, uint32_t fileSystemIndex, std::unordered_map<uint64_t, ReplacementResolvedPath> &resolvedPathMap, bool onlyDDS, std::vector<uint64_t> *hashesMissing = nullptr, std::unordered_set<std::string> *pathsToPreload = nullptr);
+ // With ricePathMap, a database whose auto path is Rice also gives each file found by its Rice hash, resolved as an
+ // entry without a path would be: for textures matched by their Rice hash as they're loaded (hle/rt64_rice_hash.h).
+ void resolvePaths(const FileSystem *fileSystem, uint32_t fileSystemIndex, std::unordered_map<uint64_t, ReplacementResolvedPath> &resolvedPathMap, bool onlyDDS, std::vector<uint64_t> *hashesMissing = nullptr, std::unordered_set<std::string> *pathsToPreload = nullptr, std::unordered_map<std::string, ReplacementResolvedPath> *ricePathMap = nullptr);
void resolveOperations(std::unordered_map<uint64_t, ReplacementResolvedPath> &resolvedPathMap);
void resolveShifts(std::unordered_map<uint64_t, ReplacementResolvedPath> &resolvedPathMap);
static uint64_t stringToHash(const std::string &str);
diff --git a/src/gbi/rt64_gbi.cpp b/src/gbi/rt64_gbi.cpp
index 7006549..4984e7c 100644
--- a/src/gbi/rt64_gbi.cpp
+++ b/src/gbi/rt64_gbi.cpp
@@ -13,6 +13,7 @@
#include "rt64_gbi_f3dpd.h"
#include "rt64_gbi_f3dex.h"
#include "rt64_gbi_f3dex2.h"
+#include "rt64_gbi_f3dex2cbfd.h"
#include "rt64_gbi_f3dwave.h"
#include "rt64_gbi_f3dzex2.h"
#include "rt64_gbi_l3dex2.h"
@@ -110,6 +111,8 @@ namespace RT64 {
const GBIInstance F3DLX2_FIFO_2_08_REJ = { "F3DLX2.fifo 2.08.Rej", GBIUCode::F3DEX2, { true, false, true, false, false } }; // Needs confirmation.
const GBIInstance F3DEX2_FIFO_2_08_CRUISN = { "F3DEX2.fifo 2.08 (Cruis'n Exotica)", GBIUCode::Unknown, { false, false, false, false, false } }; // Needs confirmation.
const GBIInstance F3DEX2_FIFO_2_08_PL = { "F3DEX2.fifo 2.08 (POSLIGHT)", GBIUCode::F3DEX2, { false, false, false, false, true } };
+ const GBIInstance F3DEXBG_NON_FIFO_2_08 = { "F3DEXBG.NoN fifo 2.08 (Conker's Bad Fur Day)", GBIUCode::F3DEX2CBFD, { false, true, false, false, false } };
+ const GBIInstance F3DEX_NON_FIFO_2_08_CBFD = { "F3DEX.NoN fifo 2.08 (Conker's Bad Fur Day)", GBIUCode::F3DEX2CBFD, { false, true, false, false, false } };
const GBIInstance F3DEX2_XBUS_2_05 = { "F3DEX2.xbus 2.05", GBIUCode::F3DEX2, { false, false, false, false, false } }; // Needs confirmation.
const GBIInstance F3DEX2_XBUS_2_07 = { "F3DEX2.xbus 2.07", GBIUCode::F3DEX2, { false, false, false, false, false } }; // Needs confirmation.
const GBIInstance F3DLX2_XBUS_2_07_REJ = { "F3DLX2.xbus 2.07.Rej", GBIUCode::F3DEX2, { true, false, true, false, false } }; // Needs confirmation.
@@ -160,7 +163,7 @@ namespace RT64 {
//
// Length Hash Known instances
//
- static std::array<GBISegment, 94> textSegments = {
+ static std::array<GBISegment, 96> textSegments = {
GBISegment{ 0x1408, 0x9C0926F5E466BE70ULL, { &F3D_SDK_E } }, // Needs confirmation.
GBISegment{ 0x1400, 0x34EAA6E921BCF1B2ULL, { &F3D_SDK_F, &F3D_SDK_UNKNOWN_G, &F3D_SDK_UNKNOWN_H } }, // Needs confirmation.
GBISegment{ 0x1408, 0x3E05E9BBE814C700ULL, { &F3D_FIFO_SDK_E } }, // Needs confirmation.
@@ -211,6 +214,8 @@ namespace RT64 {
GBISegment{ 0x1390, 0x0B8FE363267ADCB4ULL, { &F3DEX2_FIFO_2_06 } },
GBISegment{ 0x1390, 0x8C1C9814E75E1B4BULL, { &F3DEX2_FIFO_2_07 } },
GBISegment{ 0x1390, 0xCF55FAE288BFE48DULL, { &F3DEX2_FIFO_2_08 } }, // Needs confirmation.
+ GBISegment{ 0x1390, 0xEFF7E499684E95B2ULL, { &F3DEXBG_NON_FIFO_2_08 } },
+ GBISegment{ 0x1390, 0x5B76BAEB4121C82CULL, { &F3DEX_NON_FIFO_2_08_CBFD } },
GBISegment{ 0x1188, 0xB9FBB8E71F72B596ULL, { &F3DEX2_FIFO_2_08_REJ } }, // Needs confirmation.
GBISegment{ 0x1188, 0x5235C026EC14B4FBULL, { &F3DLX2_FIFO_2_08_REJ } }, // Needs confirmation.
GBISegment{ 0x1378, 0xC2AE06B691610132ULL, { &F3DEX2_FIFO_2_08_CRUISN } }, // Needs confirmation.
@@ -257,7 +262,7 @@ namespace RT64 {
GBISegment{ 0x10B0, 0xE8028E4BC6529E6EULL, { &ZSORTP_0_33 } }, // Needs confirmation.
};
- static std::array<GBISegment, 105> dataSegments = {
+ static std::array<GBISegment, 107> dataSegments = {
GBISegment{ 0x800, 0xEEB10D73400213B3ULL, { &F3D_SDK_E } }, // Needs confirmation.
GBISegment{ 0x800, 0x49651E384B48F694ULL, { &F3D_SDK_F } }, // Needs confirmation.
GBISegment{ 0x800, 0x1A736198F90E81C5ULL, { &F3D_SDK_UNKNOWN_G } }, // Needs confirmation.
@@ -318,6 +323,8 @@ namespace RT64 {
GBISegment{ 0x410, 0x47BA278DD7DB79EBULL, { &F3DLX2_FIFO_2_06_REJ } }, // Needs confirmation.
GBISegment{ 0x420, 0xF8649121FAB40A06ULL, { &F3DEX2_FIFO_2_07 } },
GBISegment{ 0x420, 0x3D4CAB9C82AD3772ULL, { &F3DEX2_FIFO_2_08 } }, // Needs confirmation.
+ GBISegment{ 0x420, 0xAD59E246BCF1B2C2ULL, { &F3DEXBG_NON_FIFO_2_08 } },
+ GBISegment{ 0x420, 0xD6FA1415D3E78D13ULL, { &F3DEX_NON_FIFO_2_08_CBFD } },
GBISegment{ 0x410, 0x14F9D11C0F58AFB5ULL, { &F3DEX2_FIFO_2_08_REJ } }, // Needs confirmation.
GBISegment{ 0x410, 0x25A00931C3C2A573ULL, { &F3DLX2_FIFO_2_08_REJ } }, // Needs confirmation.
GBISegment{ 0x420, 0xD381B0139965EE5CULL, { &F3DEX2_FIFO_2_08_CRUISN } }, // Needs confirmation.
@@ -499,6 +506,9 @@ namespace RT64 {
case GBIUCode::L3DEX2:
GBI_L3DEX2::setup(&gbi);
break;
+ case GBIUCode::F3DEX2CBFD:
+ GBI_F3DEX2CBFD::setup(&gbi);
+ break;
default:
assert(false && "Unknown UCode.");
break;
diff --git a/src/gbi/rt64_gbi.h b/src/gbi/rt64_gbi.h
index 69c35d2..bcea8ec 100644
--- a/src/gbi/rt64_gbi.h
+++ b/src/gbi/rt64_gbi.h
@@ -28,6 +28,7 @@ namespace RT64 {
S2DEX,
S2DEX2,
L3DEX2,
+ F3DEX2CBFD,
Count
};
diff --git a/src/gbi/rt64_gbi_extended.cpp b/src/gbi/rt64_gbi_extended.cpp
index 20c0d4d..5f0b85d 100644
--- a/src/gbi/rt64_gbi_extended.cpp
+++ b/src/gbi/rt64_gbi_extended.cpp
@@ -331,6 +331,16 @@ namespace RT64 {
state->rdp->setRectAspect(aspect);
}
+ void conkerBlurFramebufferV1(State *state, DisplayList **dl) {
+ const uint32_t address = (*dl)->p1(0, 24);
+ const uint8_t strength = (*dl)->p1(24, 8);
+ state->setConkerBlurFramebuffer(address, strength);
+ }
+
+ void conkerFocusPlacedV1(State *state, DisplayList **dl) {
+ state->rdp->setConkerFocusPlaced((*dl)->p1(30, 2), (*dl)->p1(24, 3), (*dl)->p1(8, 10), (*dl)->p1(0, 8));
+ }
+
void noOpHook(State *state, DisplayList **dl) {
uint32_t magicNumber = (*dl)->p0(0, 24);
if (magicNumber == RT64_HOOK_MAGIC_NUMBER) {
@@ -439,6 +449,8 @@ namespace RT64 {
Map[G_EX_SETVERTEXSEGMENT_V1] = &setVertexSegmentV1;
Map[G_EX_SETTEXCOORDWRAPPOINT_V1] = &setTexcoordWrapPointV1;
Map[G_EX_SETRECTASPECT_V1] = &setRectAspectV1;
+ Map[G_EX_CONKERBLURFRAMEBUFFER_V1] = &conkerBlurFramebufferV1;
+ Map[G_EX_CONKERFOCUSPLACED_V1] = &conkerFocusPlacedV1;
MapInitialized = true;
}
}
diff --git a/src/gbi/rt64_gbi_f3dex2cbfd.cpp b/src/gbi/rt64_gbi_f3dex2cbfd.cpp
new file mode 100644
index 0000000..96768bb
--- /dev/null
+++ b/src/gbi/rt64_gbi_f3dex2cbfd.cpp
@@ -0,0 +1,123 @@
+//
+// RT64
+//
+// Conker's Bad Fur Day's modified F3DEX2, based on GLideN64's F3DEX2CBFD.
+// Commands not listed here behave as in F3DEX2.
+//
+
+#include "rt64_gbi_f3dex2cbfd.h"
+
+#include "hle/rt64_interpreter.h"
+
+#include "rt64_f3d.h"
+#include "rt64_gbi_f3dex2.h"
+
+namespace RT64 {
+ namespace GBI_F3DEX2CBFD {
+ // The game's G_LIGHTING and G_TEXTURE_GEN are kept aside: lighting is computed into the
+ // vertex colours on the CPU (RSP::lightVerticesCBFD), so the shaders must not light them
+ // again, and texture generation, which needs the normals the shaders can't see (they're
+ // held apart from the vertices, and the colours hold the lighting), is computed into the
+ // vertices' texture coordinates on the CPU too (RSP::textureGenVerticesCBFD).
+ void geometryMode(State *state, DisplayList **dl) {
+ RSP *rsp = state->rsp.get();
+ const uint32_t offMask = (*dl)->p0(0, 24);
+ const uint32_t onMask = (*dl)->w1;
+ const uint32_t current = rsp->geometryModeStack[rsp->geometryModeStackSize - 1];
+ const uint32_t previous = current | (rsp->cbfd.lighting ? G_LIGHTING : 0) |
+ (rsp->cbfd.textureGen ? G_TEXTURE_GEN : 0) | (rsp->cbfd.textureGenLinear ? G_TEXTURE_GEN_LINEAR : 0);
+ const uint32_t requested = (previous & offMask) | onMask;
+ rsp->cbfd.lighting = (requested & G_LIGHTING) != 0;
+ rsp->cbfd.textureGen = (requested & G_TEXTURE_GEN) != 0;
+ rsp->cbfd.textureGenLinear = (requested & G_TEXTURE_GEN_LINEAR) != 0;
+ rsp->modifyGeometryMode(0, requested & ~(G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR));
+ }
+
+ void vertex(State *state, DisplayList **dl) {
+ uint8_t vtxCount = (*dl)->p0(12, 8);
+ state->rsp->setVertexCBFD((*dl)->w1, vtxCount, (*dl)->p0(1, 7) - vtxCount);
+ }
+
+ void moveWord(State *state, DisplayList **dl) {
+ switch ((*dl)->p0(16, 8)) {
+ case G_MW_NUMLIGHT:
+ state->rsp->cbfd.lightCount = (*dl)->w1 / 48;
+ break;
+ case F3DEX2CBFD_G_MW_COORD_MOD:
+ state->rsp->setCoordModCBFD((*dl)->w0, (*dl)->w1);
+ break;
+ default:
+ GBI_F3DEX2::moveWord(state, dl);
+ break;
+ }
+ }
+
+ void moveMem(State *state, DisplayList **dl) {
+ switch ((*dl)->p0(0, 8)) {
+ case F3DEX2_G_MV_VIEWPORT:
+ state->rsp->setViewport((*dl)->w1);
+ break;
+ case F3DEX2_G_MV_LIGHT: {
+ const uint32_t offset = (*dl)->p0(5, 14);
+ const uint32_t n = offset / 48;
+ if (n < 2) {
+ state->rsp->setLookAt(n, (*dl)->w1);
+ }
+ else {
+ state->rsp->setLightCBFD(n - 2, (*dl)->w1);
+ }
+
+ break;
+ }
+ case F3DEX2CBFD_G_MV_NORMALES:
+ state->rsp->cbfd.normalBase = state->rsp->fromSegmentedMasked((*dl)->w1);
+ break;
+ default:
+ break;
+ }
+ }
+
+ // The microcode reuses G_LOAD_UCODE to switch to its advanced lighting mode.
+ void switchLightingMode(State *state, DisplayList **dl) {
+ state->rsp->cbfd.advancedLighting = true;
+ }
+
+ void tri4(State *state, DisplayList **dl) {
+ const uint32_t w0 = (*dl)->w0;
+ const uint32_t w1 = (*dl)->w1;
+ auto field = [](uint32_t w, uint32_t shift, uint32_t bits) { return (w >> shift) & ((1U << bits) - 1); };
+ const uint32_t v[12] = {
+ field(w0, 23, 5), field(w0, 18, 5), (field(w0, 15, 3) << 2) | field(w1, 30, 2),
+ field(w0, 10, 5), field(w0, 5, 5), field(w0, 0, 5),
+ field(w1, 25, 5), field(w1, 20, 5), field(w1, 15, 5),
+ field(w1, 10, 5), field(w1, 5, 5), field(w1, 0, 5),
+ };
+
+ for (int t = 0; t < 4; t++) {
+ const uint32_t a = v[t * 3 + 0], b = v[t * 3 + 1], c = v[t * 3 + 2];
+ // Unused slots repeat an index.
+ if ((a != b) && (b != c) && (a != c)) {
+ state->rsp->drawIndexedTri(a, b, c);
+ }
+ }
+ }
+
+ void reset(State *state) {
+ state->rsp->setClipRatioAll(2U);
+ state->rsp->cbfd.advancedLighting = false;
+ }
+
+ void setup(GBI *gbi) {
+ GBI_F3DEX2::setup(gbi);
+ gbi->resetFromTask = &reset;
+ gbi->map[F3DEX2_G_GEOMETRYMODE] = &geometryMode;
+ gbi->map[F3DEX2_G_VTX] = &vertex;
+ gbi->map[F3DEX2_G_MOVEWORD] = &moveWord;
+ gbi->map[F3DEX2_G_MOVEMEM] = &moveMem;
+ gbi->map[F3DEX2_G_LOAD_UCODE] = &switchLightingMode;
+ for (uint32_t i = 0; i < 16; i++) {
+ gbi->map[F3DEX2CBFD_G_TRI4 + i] = &tri4;
+ }
+ }
+ }
+};
diff --git a/src/gbi/rt64_gbi_f3dex2cbfd.h b/src/gbi/rt64_gbi_f3dex2cbfd.h
new file mode 100644
index 0000000..99ef5c2
--- /dev/null
+++ b/src/gbi/rt64_gbi_f3dex2cbfd.h
@@ -0,0 +1,20 @@
+//
+// RT64
+//
+
+#pragma once
+
+#include "rt64_gbi.h"
+
+// Conker's Bad Fur Day's modified F3DEX2: F3DEX2 with a different lighting
+// model (point lights, per-vertex normals held apart from the vertices, a
+// coordinate modifier) and a four-triangle command.
+#define F3DEX2CBFD_G_TRI4 0x10
+#define F3DEX2CBFD_G_MV_NORMALES 14
+#define F3DEX2CBFD_G_MW_COORD_MOD 0x10
+
+namespace RT64 {
+ namespace GBI_F3DEX2CBFD {
+ void setup(GBI *gbi);
+ };
+};
diff --git a/src/hle/rt64_application.cpp b/src/hle/rt64_application.cpp
index ee8bc1f..3e2aa3a 100644
--- a/src/hle/rt64_application.cpp
+++ b/src/hle/rt64_application.cpp
@@ -245,6 +245,11 @@ namespace RT64 {
// We don't know yet what driver will fix the issue for RDNA4, so if it's newer than BrokenRDNA4DriverD3D12, we only force Vulkan if it's in Automatic mode.
forceVulkanForCompatibility = true;
}
+ else if (device->getCapabilities().uma) {
+ // Integrated AMD graphics (sharing system memory) crashed at start in D3D12: a Ryzen 5 5560U (Vega) failed to create
+ // its render targets and upload buffers, and nothing got drawn. Vulkan runs on the same machine, so it's the automatic choice here.
+ forceVulkanForCompatibility = true;
+ }
else {
// Wireframe artifacts have been reported when using a high-precision color format on RDNA3 GPUs in D3D12. The workaround is to switch to Vulkan if this is the case.
const bool isRX7 = deviceDescription.name.find("AMD Radeon RX 7") != std::string::npos;
@@ -524,6 +529,10 @@ namespace RT64 {
state->updateScreen(core.decodeVI(), false);
}
+ void Application::presentAgain() {
+ state->presentAgain();
+ }
+
void Application::destroyShaderCache() {
workloadQueue->waitForWorkloadId(state->workloadId);
presentQueue->waitForPresentId(state->presentId);
diff --git a/src/hle/rt64_application.h b/src/hle/rt64_application.h
index 6c83fe0..8555308 100644
--- a/src/hle/rt64_application.h
+++ b/src/hle/rt64_application.h
@@ -156,6 +156,8 @@ namespace RT64 {
SetupResult setup(uint32_t threadId);
void processDisplayLists(uint8_t *memory, uint32_t dlStartAddress, uint32_t dlEndAddress, bool isHLE);
void updateScreen();
+ // Presents the last frame again, as it is (the UI drawn over it anew), while the game draws none.
+ void presentAgain();
void destroyShaderCache();
void updateMultisampling();
void end();
diff --git a/src/hle/rt64_framebuffer_manager.cpp b/src/hle/rt64_framebuffer_manager.cpp
index d7caa12..2043064 100644
--- a/src/hle/rt64_framebuffer_manager.cpp
+++ b/src/hle/rt64_framebuffer_manager.cpp
@@ -4,6 +4,8 @@
#include "rt64_framebuffer_manager.h"
+#include "common/rt64_fblog.h"
+
#include <cassert>
#include <algorithm>
@@ -91,6 +93,12 @@ namespace RT64 {
RenderTargetManager &targetManager, const ShaderLibrary *shaderLibrary)
{
auto it = framebuffers.find(op.writeChanges.address);
+ if (FbLog::threadActive()) {
+ FbLog::print("[%s %llu] writeChanges (RDRAM upload) to fb 0x%08X: %s", FbLog::threadSide(), (unsigned long long)(FbLog::threadFrame()), op.writeChanges.address,
+ (it == framebuffers.end()) ? "no fb" : ((it->second.lastWriteType == Framebuffer::Type::None) ? "skipped, lastWriteType None" :
+ ((it->second.lastWriteType == Framebuffer::Type::Depth) ? "into the DEPTH target" : "into the color target")));
+ }
+
if ((it != framebuffers.end()) && (it->second.lastWriteType != Framebuffer::Type::None)) {
const FramebufferChange *fbChange = fbChangePool.get(op.writeChanges.id);
assert(fbChange != nullptr);
@@ -174,6 +182,12 @@ namespace RT64 {
tileCopy.readDepthFromStorage = true;
}
}
+
+ if (FbLog::threadActive()) {
+ FbLog::print("[%s %llu] tileCopy setup id %llu fb 0x%08X (w %u h %u everUsedAsDepth %d) tile (%u,%u)-(%u,%u) -> scaled left %u top %u size %ux%u, rt %ux%u misalign %u, readColorFromStorage %d readDepthFromStorage %d",
+ FbLog::threadSide(), (unsigned long long)(FbLog::threadFrame()), (unsigned long long)(tileCopy.id), fbIt->second.addressStart, fbIt->second.width, fbIt->second.height, fbIt->second.everUsedAsDepth,
+ fbTile.left, fbTile.top, fbTile.right, fbTile.bottom, tileCopy.left, tileCopy.top, tileWidth, tileHeight, rtWidth, rtHeight, rtMisalignX, tileCopy.readColorFromStorage, tileCopy.readDepthFromStorage);
+ }
}
void FramebufferManager::createTileCopyRecord(RenderWorker *renderWorker, const FramebufferOperation &op, const FramebufferStorage &fbStorage,
@@ -198,6 +212,13 @@ namespace RT64 {
}
}
+ if (FbLog::threadActive()) {
+ const FixedRect &r = fbIt->second.lastWriteRect;
+ FbLog::print("[%s %llu] tileCopy record id %llu fb 0x%08X lastWriteType %d lastWriteRect " RT64_FBLOG_RECT_FMT " colorTarget %ux%u%s",
+ FbLog::threadSide(), (unsigned long long)(FbLog::threadFrame()), (unsigned long long)(tileCopy.id), fbIt->second.addressStart, int(fbIt->second.lastWriteType), RT64_FBLOG_RECT(r),
+ colorTarget.width, colorTarget.height, (fbIt->second.lastWriteType == Framebuffer::Type::Depth) ? ": copies depth to color, then discards the fb's last write" : "");
+ }
+
// Copy from depth target if the last write was a depth buffer.
if (fbIt->second.lastWriteType == Framebuffer::Type::Depth) {
RenderTargetKey depthTargetKey(fbIt->second.addressStart, fbIt->second.width, fbIt->second.siz, Framebuffer::Type::Depth);
@@ -795,8 +816,10 @@ namespace RT64 {
continue;
}
- // Only reuse exact matches.
- if ((tileCopy.textureWidth == textureWidth) && (tileCopy.textureHeight == textureHeight)) {
+ // Only reuse exact matches. Compared with the size asked for, unscaled: textureWidth and textureHeight are
+ // scaled by the resolution, so with any scale but 1 they never matched, and a new copy (a texture and a
+ // framebuffer, never freed) was made at every request.
+ if ((tileCopy.requestWidth == textureWidth) && (tileCopy.requestHeight == textureHeight)) {
tileCopy.usedWidth = width;
tileCopy.usedHeight = height;
tileCopy.usedTimestamp = usedTimestamp;
@@ -807,6 +830,8 @@ namespace RT64 {
// Make a new tile with a new Id.
TileCopy &tileCopy = tileCopies[++newId];
tileCopy.id = newId;
+ tileCopy.requestWidth = textureWidth;
+ tileCopy.requestHeight = textureHeight;
tileCopy.usedWidth = width;
tileCopy.usedHeight = height;
tileCopy.usedTimestamp = usedTimestamp;
@@ -908,6 +933,11 @@ namespace RT64 {
auto it = framebuffers.begin();
while (it != framebuffers.end()) {
if ((&it->second != changedFb) && (it->second.overlaps(addressStart, addressEnd))) {
+ if (FbLog::threadActive()) {
+ FbLog::print("[%s %llu] changeRAM: fb 0x%08X wrote 0x%08X-0x%08X, overlapping fb 0x%08X-0x%08X (w %u h %u), which is marked rdramChanged",
+ FbLog::threadSide(), (unsigned long long)(FbLog::threadFrame()), changedFb->addressStart, addressStart, addressEnd, it->second.addressStart, it->second.addressEnd, it->second.width, it->second.height);
+ }
+
it->second.rdramChanged = true;
}
diff --git a/src/hle/rt64_framebuffer_manager.h b/src/hle/rt64_framebuffer_manager.h
index 8d36b51..fd6cf90 100644
--- a/src/hle/rt64_framebuffer_manager.h
+++ b/src/hle/rt64_framebuffer_manager.h
@@ -85,6 +85,10 @@ namespace RT64 {
uint32_t usedWidth = 0;
uint32_t usedHeight = 0;
uint64_t usedTimestamp = 0;
+ // The size findTileCopyId was asked for, made a multiple as the texture is (unscaled: textureWidth and
+ // textureHeight are the scaled texture's, set when it's made), so a copy can be found again by it.
+ uint32_t requestWidth = 0;
+ uint32_t requestHeight = 0;
bool ulScaleS = true;
bool ulScaleT = true;
interop::uint2 texelShift = { 0, 0 };
diff --git a/src/hle/rt64_framebuffer_pair.cpp b/src/hle/rt64_framebuffer_pair.cpp
index c944393..f611522 100644
--- a/src/hle/rt64_framebuffer_pair.cpp
+++ b/src/hle/rt64_framebuffer_pair.cpp
@@ -69,6 +69,48 @@ namespace RT64 {
return (gameCallCount == 0) && startFbOperations.empty() && endFbOperations.empty();
}
+ FixedRect FramebufferPair::wideningScissor() const {
+ if (scissorRect.isNull()) {
+ return scissorRect;
+ }
+
+ // The pair's scissor without its projections of fill rects only.
+ FixedRect drawnScissor;
+ drawnScissor.reset();
+ bool fillsLeftOut = false;
+ for (uint32_t p = 0; p < projectionCount; p++) {
+ const Projection &proj = projections[p];
+ if (proj.scissorRect.isNull()) {
+ continue;
+ }
+
+ bool fillsOnly = (proj.type == Projection::Type::Rectangle) && (proj.gameCallCount > 0);
+ for (uint32_t c = 0; fillsOnly && (c < proj.gameCallCount); c++) {
+ fillsOnly = (proj.gameCalls[c].callDesc.otherMode.cycleType() == G_CYC_FILL);
+ }
+
+ if (fillsOnly) {
+ fillsLeftOut = true;
+ }
+ else {
+ drawnScissor.merge(proj.scissorRect);
+ }
+ }
+
+ if (!fillsLeftOut || drawnScissor.isNull()) {
+ return scissorRect;
+ }
+
+ const bool reachesLeft = (drawnScissor.ulx <= scissorRect.ulx + CoversWidthSlack);
+ const bool reachesRight = (drawnScissor.lrx >= scissorRect.lrx - CoversWidthSlack);
+ const bool wideEnough = (int64_t(drawnScissor.lrx - drawnScissor.ulx) * 10) >= (int64_t(scissorRect.lrx - scissorRect.ulx) * 4);
+ if ((reachesLeft != reachesRight) && wideEnough) {
+ return drawnScissor;
+ }
+
+ return scissorRect;
+ }
+
bool FramebufferPair::earlyPresentCandidate() const {
// Some games might use screen framebuffers as temporary output for some operations that are clearly
// not intended to be presented to the user. This function includes some cases commonly found in games.
diff --git a/src/hle/rt64_framebuffer_pair.h b/src/hle/rt64_framebuffer_pair.h
index 60b0fa4..6c80bb6 100644
--- a/src/hle/rt64_framebuffer_pair.h
+++ b/src/hle/rt64_framebuffer_pair.h
@@ -60,5 +60,13 @@ namespace RT64 {
int changeProjection(uint32_t transformsIndex, Projection::Type type);
bool isEmpty() const;
bool earlyPresentCandidate() const;
+
+ // The scissor a viewport is compared with to tell whether it's widened (FramebufferRenderer and
+ // ProjectionProcessor, which must agree). Usually the pair's own. In split screen (Conker, issue #78)
+ // the first player's view shares its pair with the frame's clear, a fill across the whole frame, so
+ // its view didn't cover the pair's scissor and wasn't widened, though the other views (each in a pair
+ // of its own) were. Leaving out projections of fill rects only, the rest's scissor is used when it's a
+ // split-screen view: reaching one side of the frame but not the other, at least 40% of its width.
+ FixedRect wideningScissor() const;
};
};
\ No newline at end of file
diff --git a/src/hle/rt64_game_frame.cpp b/src/hle/rt64_game_frame.cpp
index 87392d0..58560a3 100644
--- a/src/hle/rt64_game_frame.cpp
+++ b/src/hle/rt64_game_frame.cpp
@@ -10,6 +10,28 @@
#include "xxHash/xxh3.h"
namespace RT64 {
+ // Whether two projections are drawn in parts of the frame apart from each other: a split screen's views, each
+ // player's own. Their cameras can be alike (the same projection, the view in the model matrices), and paired with
+ // each other they were drawn from between two players' cameras for a frame, the level culled for one of them.
+ static bool areScissorsApart(const FixedRect &first, const FixedRect &second) {
+ if (first.isNull() || second.isNull()) {
+ return false;
+ }
+
+ return first.intersection(second).isEmpty();
+ }
+
+ // Whether two scenes are drawn in different places, for pairing them with last frame's: apart (above), or one of
+ // them with no scissor at all (a scene that drew nothing scissored) and the other with one. Such a scene was
+ // paired with player 2's last frame before player 2's own was, and player 2's camera jittered between frames.
+ static bool areScenesPlacedApart(const FixedRect &first, const FixedRect &second) {
+ if (first.isNull() != second.isNull()) {
+ return true;
+ }
+
+ return areScissorsApart(first, second);
+ }
+
// GameFrame
bool GameFrame::areFramebufferPairsCompatible(const WorkloadQueue &workloadQueue, const GameIndices::FramebufferPair &first, const GameIndices::FramebufferPair &second) {
@@ -55,6 +77,10 @@ namespace RT64 {
const Workload &cmpWorkload = workloadQueue.workloads[firstProj.workloadIndex];
const FramebufferPair &cmpFbPair = cmpWorkload.fbPairs[firstProj.fbPairIndex];
const Projection &cmpProj = cmpFbPair.projections[firstProj.projectionIndex];
+ if (areScissorsApart(cmpProj.scissorRect, fbProj.scissorRect)) {
+ return false;
+ }
+
const interop::float4x4 &cmpViewMatrix = cmpWorkload.drawData.viewTransforms[cmpProj.transformsIndex];
const interop::float4x4 &fbViewMatrix = workload.drawData.viewTransforms[fbProj.transformsIndex];
const float viewMatrixDiff = matrixDifference(cmpViewMatrix, fbViewMatrix);
@@ -296,7 +322,11 @@ namespace RT64 {
prevWorkloadMap = &prevFrame.frameMap.workloads[workloadMap.prevWorkloadIndex];
}
- // Match the transforms linearly in the order they were submitted.
+ // Match the transforms linearly in the order they were submitted. An ID with a different number of
+ // transforms than last frame can't be paired in order: each transform after the first one added or removed
+ // would be paired with its neighbour's, and the model would fly apart for a frame (Conker's characters,
+ // cut into chunks differently as their animation changes). Each is paired with last frame's closest instead
+ // (alignTransforms). Matching none of them made the whole model snap each time (issue #76).
ModifiedBuffers modifiedBuffers;
auto curIt = curWorkload.transformIdMap.begin();
auto prevIt = prevWorkload.transformIdMap.begin();
@@ -309,9 +339,31 @@ namespace RT64 {
prevIt++;
}
else {
- matchTransform(curWorkload, prevWorkload, curWorkloadMap, prevWorkloadMap, curIt->second, prevIt->second, modifiedBuffers);
- curIt++;
- prevIt++;
+ const uint32_t id = curIt->first;
+ const size_t curCount = curWorkload.transformIdMap.count(id);