2 * (C) GraÅžvydas "notaz" Ignotas, 2011
4 * This work is licensed under the terms of any of these licenses
6 * - GNU GPL, version 2 or later.
7 * - GNU LGPL, version 2.1 or later.
8 * See the COPYING file in the top-level directory.
14 extern const unsigned char cmd_lengths[256];
15 #define command_lengths cmd_lengths
17 static unsigned int *ex_regs;
20 #define SET_Ex(r, v) \
23 #include "psx_gpu/psx_gpu.c"
24 #include "psx_gpu/psx_gpu_parse.c"
25 #include "../gpulib/gpu.h"
27 static psx_gpu_struct egpu __attribute__((aligned(256)));
29 int do_cmd_list(uint32_t *list, int count, int *last_cmd)
33 if (gpu.state.enhancement_active)
34 ret = gpu_parse_enhanced(&egpu, list, count * 4, (u32 *)last_cmd);
36 ret = gpu_parse(&egpu, list, count * 4, (u32 *)last_cmd);
39 ex_regs[1] |= egpu.texture_settings & 0x1ff;
43 #define ENHANCEMENT_BUF_SIZE (1024 * 1024 * 2 * 4 + 4096)
45 int renderer_init(void)
47 initialize_psx_gpu(&egpu, gpu.vram);
48 ex_regs = gpu.ex_regs;
50 if (gpu.enhancement_bufer == NULL) {
51 // currently we use 4x 1024*1024 buffers instead of single 2048*1024
52 // to be able to reuse 1024-width code better (triangle setup,
53 // dithering phase, lines).
54 gpu.enhancement_bufer = mmap(NULL, ENHANCEMENT_BUF_SIZE,
55 PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
56 if (gpu.enhancement_bufer == MAP_FAILED) {
57 printf("OOM for enhancement buffer\n");
58 gpu.enhancement_bufer = NULL;
61 egpu.enhancement_buf_ptr = gpu.enhancement_bufer;
66 void renderer_finish(void)
68 if (gpu.enhancement_bufer != NULL)
69 munmap(gpu.enhancement_bufer, ENHANCEMENT_BUF_SIZE);
70 gpu.enhancement_bufer = NULL;
71 egpu.enhancement_buf_ptr = NULL;
74 static __attribute__((noinline)) void
75 sync_enhancement_buffers(int x, int y, int w, int h)
77 int xt = egpu.enhancement_x_threshold;
87 for (i = 0; i < 4 && w > 0; i++) {
92 src = gpu.vram + xt * i + y * 1024 + x;
93 dst = egpu.enhancement_buf_ptr +
94 (1024*1024 + xt * 2) * i + (y * 1024 + x) * 2;
95 scale2x_tiles8(dst, src, wb / 8, h);
106 void renderer_sync_ecmds(uint32_t *ecmds)
108 gpu_parse(&egpu, ecmds + 1, 6 * 4, NULL);
111 void renderer_update_caches(int x, int y, int w, int h)
113 update_texture_cache_region(&egpu, x, y, x + w - 1, y + h - 1);
114 if (gpu.state.enhancement_active && !gpu.status.rgb24)
115 sync_enhancement_buffers(x, y, w, h);
118 void renderer_flush_queues(void)
120 flush_render_block_buffer(&egpu);
123 void renderer_set_interlace(int enable, int is_odd)
125 egpu.render_mode &= ~(RENDER_INTERLACE_ENABLED|RENDER_INTERLACE_ODD);
127 egpu.render_mode |= RENDER_INTERLACE_ENABLED;
129 egpu.render_mode |= RENDER_INTERLACE_ODD;
132 void renderer_notify_res_change(void)
134 // note: must keep it multiple of 8
135 egpu.enhancement_x_threshold = gpu.screen.hres;
138 #include "../../frontend/plugin_lib.h"
140 void renderer_set_config(const struct rearmed_cbs *cbs)
142 static int enhancement_was_on;
144 disable_main_render = cbs->gpu_neon.enhancement_no_main;
145 if (egpu.enhancement_buf_ptr != NULL && cbs->gpu_neon.enhancement_enable
146 && !enhancement_was_on)
148 sync_enhancement_buffers(0, 0, 1024, 512);
150 enhancement_was_on = cbs->gpu_neon.enhancement_enable;