/
rsx_intf.cpp
979 lines (885 loc) · 25.7 KB
/
rsx_intf.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
#include "rsx/rsx_intf.h"
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "boolean.h"
#include "libretro.h"
#include "beetle_psx_globals.h"
#include "libretro_cbs.h"
#include "libretro_options.h"
#include "mednafen/mednafen.h"
#include "mednafen/psx/gpu.h"
#include "mednafen/settings.h"
#ifdef RSX_DUMP
#include "rsx_dump.h"
#endif
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
#include "rsx_lib_gl.h"
#endif
#if defined(HAVE_VULKAN)
#include "rsx_lib_vulkan.h"
#endif
extern bool fast_pal;
extern unsigned int image_height;
static enum rsx_renderer_type rsx_type = RSX_SOFTWARE;
static bool gl_initialized = false;
static bool vk_initialized = false;
// GPU reset defaults
static int rsx_width_mode = WIDTH_MODE_256;
static int rsx_height_mode = HEIGHT_MODE_240;
static bool rsx_soft_open(bool is_pal)
{
content_is_pal = is_pal;
return true;
}
void rsx_intf_set_environment(retro_environment_t cb)
{
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_set_environment(cb);
#endif
break;
}
}
void rsx_intf_set_video_refresh(retro_video_refresh_t cb)
{
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_set_video_refresh(cb);
#endif
break;
}
}
void rsx_intf_get_system_av_info(struct retro_system_av_info *info)
{
switch (rsx_type)
{
case RSX_SOFTWARE:
{
int first_visible_scanline = MDFN_GetSettingI(content_is_pal ? "psx.slstartp" : "psx.slstart");
int last_visible_scanline = MDFN_GetSettingI(content_is_pal ? "psx.slendp" : "psx.slend");
int manual_height = last_visible_scanline - first_visible_scanline + 1;
/* Compensate height in smart/dynamic crop mode to keep proper aspect ratio */
if (crop_overscan == 2 && image_height && manual_height > image_height)
{
first_visible_scanline = 0;
last_visible_scanline = first_visible_scanline + image_height - 1;
}
memset(info, 0, sizeof(*info));
info->timing.fps = rsx_common_get_timing_fps();
info->timing.sample_rate = SOUND_FREQUENCY;
info->geometry.base_width = MEDNAFEN_CORE_GEOMETRY_BASE_W;
info->geometry.base_height = MEDNAFEN_CORE_GEOMETRY_BASE_H;
info->geometry.max_width = MEDNAFEN_CORE_GEOMETRY_MAX_W << psx_gpu_upscale_shift;
info->geometry.max_height = MEDNAFEN_CORE_GEOMETRY_MAX_H << psx_gpu_upscale_shift;
info->geometry.aspect_ratio = rsx_common_get_aspect_ratio(content_is_pal, crop_overscan,
first_visible_scanline, last_visible_scanline,
aspect_ratio_setting, false, widescreen_hack, widescreen_hack_aspect_ratio_setting);
break;
}
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_get_system_av_info(info);
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_get_system_av_info(info);
#endif
break;
}
}
enum rsx_renderer_type rsx_intf_is_type(void)
{
return rsx_type;
}
inline void rsx_intf_dump_init(void)
{
#if defined(RSX_DUMP)
{
const char *env = getenv("RSX_DUMP");
if (env)
rsx_dump_init(env);
}
#endif
}
bool rsx_intf_open(bool is_pal, bool force_software)
{
struct retro_variable var = {0};
bool software_selected = false;
vk_initialized = false;
gl_initialized = false;
enum force_renderer_type force_type = AUTO;
var.key = BEETLE_OPT(renderer);
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (!strcmp(var.value, "software") || force_software)
software_selected = true;
else if (!strcmp(var.value, "hardware_gl"))
force_type = FORCE_OPENGL;
else if (!strcmp(var.value, "hardware_vk"))
force_type = FORCE_VULKAN;
}
else
{
/* If 'BEETLE_OPT(renderer)' option is not found, then
* we are running in software mode */
software_selected = true;
}
if (!software_selected)
{
/* Check for any hardware renderer forces before performing auto sequence */
if (force_type == FORCE_VULKAN)
{
#if defined (HAVE_VULKAN)
if (rsx_vulkan_open(is_pal))
{
rsx_type = RSX_VULKAN;
vk_initialized = true;
rsx_intf_dump_init();
return true;
}
else
{
MDFND_DispMessage(3, RETRO_LOG_ERROR,
RETRO_MESSAGE_TARGET_ALL, RETRO_MESSAGE_TYPE_NOTIFICATION,
"Could not force Vulkan renderer. Falling back to software renderer.");
goto soft;
}
#else
MDFND_DispMessage(3, RETRO_LOG_ERROR,
RETRO_MESSAGE_TARGET_ALL, RETRO_MESSAGE_TYPE_NOTIFICATION,
"Attempted to force Vulkan renderer, but core was built without it. Falling back to software renderer.");
goto soft;
#endif
}
else if (force_type == FORCE_OPENGL)
{
#if defined (HAVE_OPENGL) || defined(HAVE_OPENGLES)
if (rsx_gl_open(is_pal))
{
rsx_type = RSX_OPENGL;
gl_initialized = true;
rsx_intf_dump_init();
return true;
}
else
{
MDFND_DispMessage(3, RETRO_LOG_ERROR,
RETRO_MESSAGE_TARGET_ALL, RETRO_MESSAGE_TYPE_NOTIFICATION,
"Could not force OpenGL renderer. Falling back to software renderer.");
goto soft;
}
#else
MDFND_DispMessage(3, RETRO_LOG_ERROR,
RETRO_MESSAGE_TARGET_ALL, RETRO_MESSAGE_TYPE_NOTIFICATION,
"Attempted to force OpenGL renderer, but core was built without it. Falling back to software renderer.");
goto soft;
#endif
}
/* End forces section */
unsigned preferred = 0; // This will be set to RETRO_HW_CONTEXT_DUMMY if GET_PREFERRED_HW_RENDER is not supported by frontend
if (!environ_cb(RETRO_ENVIRONMENT_GET_PREFERRED_HW_RENDER, &preferred))
{
preferred = RETRO_HW_CONTEXT_DUMMY;
}
/* If GET_PREFERRED_HW_RENDER is not supported by frontend, then we just go
* down the list attempting to open a hardware renderer until we get one */
#if defined(HAVE_VULKAN)
if ((preferred == RETRO_HW_CONTEXT_DUMMY ||
preferred == RETRO_HW_CONTEXT_VULKAN)
&& rsx_vulkan_open(is_pal))
{
rsx_type = RSX_VULKAN;
vk_initialized = true;
rsx_intf_dump_init();
return true;
}
#endif
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
if ((preferred == RETRO_HW_CONTEXT_DUMMY ||
preferred == RETRO_HW_CONTEXT_OPENGL ||
preferred == RETRO_HW_CONTEXT_OPENGL_CORE)
&& rsx_gl_open(is_pal))
{
rsx_type = RSX_OPENGL;
gl_initialized = true;
rsx_intf_dump_init();
return true;
}
#endif
if (preferred == RETRO_HW_CONTEXT_DUMMY)
MDFND_DispMessage(3, RETRO_LOG_ERROR,
RETRO_MESSAGE_TARGET_ALL, RETRO_MESSAGE_TYPE_NOTIFICATION,
"No hardware renderers could be opened. Falling back to software renderer.");
else
MDFND_DispMessage(3, RETRO_LOG_ERROR,
RETRO_MESSAGE_TARGET_ALL, RETRO_MESSAGE_TYPE_NOTIFICATION,
"Unable to find or open hardware renderer for frontend preferred hardware context. Falling back to software renderer.");
}
soft:
// rsx_soft_open(is_pal) always returns true
if (rsx_soft_open(is_pal))
{
rsx_type = RSX_SOFTWARE;
rsx_intf_dump_init();
return true;
}
/* Note: fallback will result in the software renderer running at
* 1x internal resolution instead of the user configured setting
* because of the check_variables startup sequence in libretro.cpp;
* this is a good thing since emulation would likely slow to a crawl
* if the user had >2x IR for hardware rendering and that setting was
* retroactively applied that to software rendering fallback
*/
return false;
}
void rsx_intf_close(void)
{
#if defined(RSX_DUMP)
rsx_dump_deinit();
#endif
#if defined(HAVE_VULKAN)
if (rsx_type != RSX_SOFTWARE && vk_initialized)
return;
#endif
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
if (rsx_type != RSX_SOFTWARE && gl_initialized)
{
rsx_gl_close();
return;
}
#endif
}
void rsx_intf_refresh_variables(void)
{
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_refresh_variables();
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_refresh_variables();
#endif
break;
}
}
void rsx_intf_prepare_frame(void)
{
#ifdef RSX_DUMP
rsx_dump_prepare_frame();
#endif
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_prepare_frame();
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_prepare_frame();
#endif
break;
}
}
void rsx_intf_finalize_frame(const void *fb, unsigned width,
unsigned height, unsigned pitch)
{
#ifdef RSX_DUMP
rsx_dump_finalize_frame();
#endif
switch (rsx_type)
{
case RSX_SOFTWARE:
video_cb(fb, width, height, pitch);
break;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_finalize_frame(fb, width, height, pitch);
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_finalize_frame(fb, width, height, pitch);
#endif
break;
}
}
void rsx_intf_set_tex_window(uint8_t tww, uint8_t twh,
uint8_t twx, uint8_t twy)
{
#ifdef RSX_DUMP
rsx_dump_set_tex_window(tww, twh, twx, twy);
#endif
switch (rsx_type)
{
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_set_tex_window(tww, twh, twx, twy);
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_set_tex_window(tww, twh, twx, twy);
#endif
break;
default:
break;
}
}
void rsx_intf_set_mask_setting(uint32_t mask_set_or, uint32_t mask_eval_and)
{
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
break;
case RSX_VULKAN:
/* TODO/FIXME */
break;
}
}
void rsx_intf_set_draw_offset(int16_t x, int16_t y)
{
#ifdef RSX_DUMP
rsx_dump_set_draw_offset(x, y);
#endif
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_set_draw_offset(x, y);
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_set_draw_offset(x, y);
#endif
break;
}
}
void rsx_intf_set_draw_area(uint16_t x0, uint16_t y0,
uint16_t x1, uint16_t y1)
{
#ifdef RSX_DUMP
rsx_dump_set_draw_area(x0, y0, x1, y1);
#endif
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_set_draw_area(x0, y0, x1, y1);
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_set_draw_area(x0, y0, x1, y1);
#endif
break;
}
}
void rsx_intf_set_vram_framebuffer_coords(uint32_t xstart, uint32_t ystart)
{
#ifdef RSX_DUMP
rsx_dump_set_vram_framebuffer_coords(xstart, ystart);
#endif
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_set_vram_framebuffer_coords(xstart, ystart);
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_set_vram_framebuffer_coords(xstart, ystart);
#endif
break;
}
}
void rsx_intf_set_horizontal_display_range(uint16_t x1, uint16_t x2)
{
#ifdef RSX_DUMP
rsx_dump_set_horizontal_display_range(x1, x2);
#endif
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_set_horizontal_display_range(x1, x2);
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_set_horizontal_display_range(x1, x2);
#endif
break;
}
}
void rsx_intf_set_vertical_display_range(uint16_t y1, uint16_t y2)
{
#ifdef RSX_DUMP
rsx_dump_set_vertical_display_range(y1, y2);
#endif
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_set_vertical_display_range(y1, y2);
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_set_vertical_display_range(y1, y2);
#endif
break;
}
}
void rsx_intf_set_display_mode(bool depth_24bpp,
bool is_pal,
bool is_480i,
int width_mode)
{
#ifdef RSX_DUMP
rsx_dump_set_display_mode(depth_24bpp, is_pal, is_480i, width_mode);
#endif
// Is this check accurate for 240i timing? May need to be fixed later
if (currently_interlaced != is_480i)
{
currently_interlaced = is_480i;
interlace_setting_dirty = true;
}
// Also verify if this is accurate for 240i
if ((rsx_width_mode != width_mode) || (rsx_height_mode != (int)is_480i))
{
rsx_width_mode = width_mode;
rsx_height_mode = (int)is_480i;
aspect_ratio_dirty = true;
}
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_set_display_mode(depth_24bpp, is_pal, is_480i, width_mode);
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_set_display_mode(depth_24bpp, is_pal, is_480i, width_mode);
#endif
break;
}
}
void rsx_intf_push_triangle(
float p0x, float p0y, float p0w,
float p1x, float p1y, float p1w,
float p2x, float p2y, float p2w,
uint32_t c0,
uint32_t c1,
uint32_t c2,
uint16_t t0x, uint16_t t0y,
uint16_t t1x, uint16_t t1y,
uint16_t t2x, uint16_t t2y,
uint16_t min_u, uint16_t min_v,
uint16_t max_u, uint16_t max_v,
uint16_t texpage_x, uint16_t texpage_y,
uint16_t clut_x, uint16_t clut_y,
uint8_t texture_blend_mode,
uint8_t depth_shift,
bool dither,
int blend_mode,
uint32_t mask_test,
uint32_t set_mask)
{
#ifdef RSX_DUMP
const rsx_dump_vertex vertices[3] = {
{ p0x, p0y, p0w, c0, t0x, t0y },
{ p1x, p1y, p1w, c1, t1x, t1y },
{ p2x, p2y, p2w, c2, t2x, t2y },
};
const rsx_render_state state = {
texpage_x, texpage_y, clut_x, clut_y, texture_blend_mode, depth_shift, dither, blend_mode,
mask_test, set_mask,
};
rsx_dump_triangle(vertices, &state);
#endif
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_push_triangle(p0x, p0y, p0w, p1x, p1y, p1w, p2x, p2y, p2w,
c0, c1, c2, t0x, t0y, t1x, t1y, t2x, t2y,
min_u, min_v, max_u, max_v,
texpage_x, texpage_y, clut_x, clut_y,
texture_blend_mode,
depth_shift,
dither,
blend_mode, mask_test != 0, set_mask != 0);
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_push_triangle(p0x, p0y, p0w, p1x, p1y, p1w, p2x, p2y, p2w,
c0, c1, c2, t0x, t0y, t1x, t1y, t2x, t2y,
min_u, min_v, max_u, max_v,
texpage_x, texpage_y, clut_x, clut_y,
texture_blend_mode,
depth_shift,
dither,
blend_mode, mask_test != 0, set_mask != 0);
#endif
break;
}
}
void rsx_intf_push_quad(
float p0x, float p0y, float p0w,
float p1x, float p1y, float p1w,
float p2x, float p2y, float p2w,
float p3x, float p3y, float p3w,
uint32_t c0, uint32_t c1, uint32_t c2, uint32_t c3,
uint16_t t0x, uint16_t t0y,
uint16_t t1x, uint16_t t1y,
uint16_t t2x, uint16_t t2y,
uint16_t t3x, uint16_t t3y,
uint16_t min_u, uint16_t min_v,
uint16_t max_u, uint16_t max_v,
uint16_t texpage_x, uint16_t texpage_y,
uint16_t clut_x, uint16_t clut_y,
uint8_t texture_blend_mode,
uint8_t depth_shift,
bool dither,
int blend_mode,
uint32_t mask_test,
uint32_t set_mask,
bool is_sprite,
bool may_be_2d)
{
#ifdef RSX_DUMP
const rsx_dump_vertex vertices[4] = {
{ p0x, p0y, p0w, c0, t0x, t0y },
{ p1x, p1y, p1w, c1, t1x, t1y },
{ p2x, p2y, p2w, c2, t2x, t2y },
{ p3x, p3y, p3w, c3, t3x, t3y },
};
const rsx_render_state state = {
texpage_x, texpage_y, clut_x, clut_y, texture_blend_mode, depth_shift, dither, blend_mode,
mask_test, set_mask,
};
rsx_dump_quad(vertices, &state);
#endif
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_push_quad(p0x, p0y, p0w, p1x, p1y, p1w, p2x, p2y, p2w, p3x, p3y, p3w,
c0, c1, c2, c3,
t0x, t0y, t1x, t1y, t2x, t2y, t3x, t3y,
min_u, min_v, max_u, max_v,
texpage_x, texpage_y, clut_x, clut_y,
texture_blend_mode,
depth_shift,
dither,
blend_mode, mask_test != 0, set_mask != 0);
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_push_quad(p0x, p0y, p0w, p1x, p1y, p1w, p2x, p2y, p2w, p3x, p3y, p3w,
c0, c1, c2, c3,
t0x, t0y, t1x, t1y, t2x, t2y, t3x, t3y,
min_u, min_v, max_u, max_v,
texpage_x, texpage_y, clut_x, clut_y,
texture_blend_mode,
depth_shift,
dither,
blend_mode, mask_test != 0, set_mask != 0, is_sprite, may_be_2d);
#endif
break;
}
}
void rsx_intf_push_line(int16_t p0x, int16_t p0y,
int16_t p1x, int16_t p1y,
uint32_t c0, uint32_t c1,
bool dither,
int blend_mode,
uint32_t mask_test,
uint32_t set_mask)
{
#ifdef RSX_DUMP
const rsx_dump_line_data line = {
p0x, p0y, p1x, p1y, c0, c1, dither, blend_mode,
mask_test != 0, set_mask != 0,
};
rsx_dump_line(&line);
#endif
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_push_line(p0x, p0y, p1x, p1y, c0, c1, dither, blend_mode, mask_test != 0, set_mask != 0);
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_push_line(p0x, p0y, p1x, p1y, c0, c1, dither, blend_mode, mask_test != 0, set_mask != 0);
#endif
break;
}
}
bool rsx_intf_read_vram(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t *vram)
{
switch (rsx_type)
{
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
return rsx_vulkan_read_vram(x, y, w, h, vram);
#endif
break;
default:
break;
}
return false;
}
void rsx_intf_load_image(uint16_t x, uint16_t y,
uint16_t w, uint16_t h,
uint16_t *vram, uint32_t mask_test, uint32_t set_mask)
{
#ifdef RSX_DUMP
rsx_dump_load_image(x, y, w, h, vram, mask_test != 0, set_mask != 0);
#endif
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_load_image(x, y, w, h, vram, mask_test, set_mask);
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_load_image(x, y, w, h, vram, mask_test, set_mask);
#endif
break;
}
}
void rsx_intf_fill_rect(uint32_t color,
uint16_t x, uint16_t y,
uint16_t w, uint16_t h)
{
#ifdef RSX_DUMP
rsx_dump_fill_rect(color, x, y, w, h);
#endif
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_fill_rect(color, x, y, w, h);
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_fill_rect(color, x, y, w, h);
#endif
break;
}
}
void rsx_intf_copy_rect(uint16_t src_x, uint16_t src_y,
uint16_t dst_x, uint16_t dst_y,
uint16_t w, uint16_t h,
uint32_t mask_test, uint32_t set_mask)
{
#ifdef RSX_DUMP
rsx_dump_copy_rect(src_x, src_y, dst_x, dst_y, w, h, mask_test != 0, set_mask != 0);
#endif
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_copy_rect(src_x, src_y, dst_x, dst_y,
w, h, mask_test, set_mask);
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_copy_rect(src_x, src_y, dst_x, dst_y, w, h, mask_test, set_mask);
#endif
break;
}
}
bool rsx_intf_has_software_renderer(void)
{
switch (rsx_type)
{
case RSX_SOFTWARE:
return true;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
return rsx_gl_has_software_renderer();
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
return rsx_vulkan_has_software_renderer();
#else
break;
#endif
}
return false;
}
void rsx_intf_toggle_display(bool status)
{
#ifdef RSX_DUMP
rsx_dump_toggle_display(status);
#endif
switch (rsx_type)
{
case RSX_SOFTWARE:
break;
case RSX_OPENGL:
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
rsx_gl_toggle_display(status);
#endif
break;
case RSX_VULKAN:
#if defined(HAVE_VULKAN)
rsx_vulkan_toggle_display(status);
#endif
break;
}
}
double rsx_common_get_timing_fps(void)
{
bool pal_timings = content_is_pal && !fast_pal;
if (core_timing_fps_mode == FORCE_PROGRESSIVE_TIMING)
return (pal_timings ? FPS_PAL_NONINTERLACED : FPS_NTSC_NONINTERLACED);
else if (core_timing_fps_mode == FORCE_INTERLACED_TIMING)
return (pal_timings ? FPS_PAL_INTERLACED : FPS_NTSC_INTERLACED);
//else AUTO_TOGGLE_TIMING
return (pal_timings ?
(currently_interlaced ? FPS_PAL_INTERLACED : FPS_PAL_NONINTERLACED) :
(currently_interlaced ? FPS_NTSC_INTERLACED : FPS_NTSC_NONINTERLACED));
}
float rsx_common_get_aspect_ratio(bool pal_content, int crop_overscan,
int first_visible_scanline, int last_visible_scanline,
int aspect_ratio_setting, bool vram_override, bool widescreen_override,
int widescreen_hack_aspect_ratio_setting)
{
// Current assumptions
// A fixed percentage of width is cropped when crop_overscan isn't 0
// aspect_ratio_setting is one of the following:
// 0 - Corrected
// 1 - Uncorrected (1:1 PAR)
// 2 - Force 4:3 (traditionally what Beetle PSX has done prior to adding in this setting)
// 3 - Force NTSC (get corrected NTSC aspect ratio even with PAL games)
// Aspect ratio overrides - VRAM and widescreen take precedence
if (vram_override)
return 2.0 / 1.0;
if (widescreen_override)
switch(widescreen_hack_aspect_ratio_setting)
{
case 0:
return (16.0 / 10.0);
case 1:
return (16.0 / 9.0);
case 2:
return (18.0 / 9.0);
case 3:
return (19.0 / 9.0);
case 4:
return (20.0 / 9.0);
case 5:
return (/*21.0 / 9.0*/ 64.0 / 27.0);
case 6:
return (32.0 / 9.0);
}
float ar = (4.0 / 3.0);
if (aspect_ratio_setting == 0) // Corrected
{
// Calculate horizontal scaling in terms of gpu clock cycles
ar *= (crop_overscan ? (2560.0 / 2800.0) : 1.0);
// Calculate vertical scaling in terms of visible scanline count
int num_vis_scanlines = last_visible_scanline - first_visible_scanline + 1;
ar *= (pal_content ? (288.0 / num_vis_scanlines) : (240.0 / num_vis_scanlines));
return ar;
}
else if (aspect_ratio_setting == 1) // Uncorrected
{
int width_base = 0;
switch (rsx_width_mode)
{
case WIDTH_MODE_256:
width_base = crop_overscan ? 256 : 280;
break;
case WIDTH_MODE_320:
width_base = crop_overscan ? 320 : 350;
break;
case WIDTH_MODE_512:
width_base = crop_overscan ? 512 : 560;
break;
case WIDTH_MODE_640:
width_base = crop_overscan ? 640 : 700;
break;
case WIDTH_MODE_368:
// Probably slightly off because of rounding, see libretro.cpp comments
width_base = crop_overscan ? 366 : 400;
break;
}
double height_base = (last_visible_scanline - first_visible_scanline + 1) *
(rsx_height_mode == HEIGHT_MODE_480 ? 2.0 : 1.0);
// Calculate aspect ratio as quotient of raw native framebuffer width and height
return width_base / height_base;
}
else if (aspect_ratio_setting == 3) // Force NTSC
{
ar *= (crop_overscan ? (2560.0 / 2800.0) : 1.0);
int num_vis_scanlines = last_visible_scanline - first_visible_scanline + 1;
ar *= (240.0 / num_vis_scanlines);
return ar;
}
return ar; // 4:3
}