90ca4913 |
1 | /* |
2 | * (C) GraÅžvydas "notaz" Ignotas, 2011 |
3 | * |
4 | * This work is licensed under the terms of any of these licenses |
5 | * (at your option): |
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. |
9 | */ |
10 | |
11 | #include <stdio.h> |
50f9355a |
12 | #include <sys/mman.h> |
90ca4913 |
13 | |
652c6b8b |
14 | extern const unsigned char cmd_lengths[256]; |
15 | #define command_lengths cmd_lengths |
16 | |
b243416b |
17 | static unsigned int *ex_regs; |
9ee0fd5b |
18 | static int initialized; |
b243416b |
19 | |
20 | #define PCSX |
21 | #define SET_Ex(r, v) \ |
22 | ex_regs[r] = v |
23 | |
90ca4913 |
24 | #include "psx_gpu/psx_gpu.c" |
90ca4913 |
25 | #include "psx_gpu/psx_gpu_parse.c" |
62d7fa95 |
26 | #include "../gpulib/gpu.h" |
90ca4913 |
27 | |
28 | static psx_gpu_struct egpu __attribute__((aligned(256))); |
29 | |
b243416b |
30 | int do_cmd_list(uint32_t *list, int count, int *last_cmd) |
90ca4913 |
31 | { |
c1817bd9 |
32 | int ret; |
33 | |
34 | if (gpu.state.enhancement_active) |
35 | ret = gpu_parse_enhanced(&egpu, list, count * 4, (u32 *)last_cmd); |
36 | else |
37 | ret = gpu_parse(&egpu, list, count * 4, (u32 *)last_cmd); |
b243416b |
38 | |
39 | ex_regs[1] &= ~0x1ff; |
40 | ex_regs[1] |= egpu.texture_settings & 0x1ff; |
41 | return ret; |
90ca4913 |
42 | } |
43 | |
50f9355a |
44 | #define ENHANCEMENT_BUF_SIZE (1024 * 1024 * 2 * 4 + 4096) |
45 | |
9ee0fd5b |
46 | static void map_enhancement_buffer(void) |
90ca4913 |
47 | { |
9ee0fd5b |
48 | // currently we use 4x 1024*1024 buffers instead of single 2048*1024 |
49 | // to be able to reuse 1024-width code better (triangle setup, |
50 | // dithering phase, lines). |
51 | gpu.enhancement_bufer = gpu.mmap(ENHANCEMENT_BUF_SIZE); |
52 | if (gpu.enhancement_bufer == NULL) |
53 | fprintf(stderr, "failed to map enhancement buffer\n"); |
54 | egpu.enhancement_buf_ptr = gpu.enhancement_bufer; |
55 | } |
e929dec5 |
56 | |
9ee0fd5b |
57 | int renderer_init(void) |
58 | { |
59 | if (gpu.vram != NULL) { |
60 | initialize_psx_gpu(&egpu, gpu.vram); |
61 | initialized = 1; |
e929dec5 |
62 | } |
e929dec5 |
63 | |
9ee0fd5b |
64 | if (gpu.mmap != NULL && gpu.enhancement_bufer == NULL) |
65 | map_enhancement_buffer(); |
66 | |
67 | ex_regs = gpu.ex_regs; |
90ca4913 |
68 | return 0; |
69 | } |
70 | |
e929dec5 |
71 | void renderer_finish(void) |
72 | { |
50f9355a |
73 | if (gpu.enhancement_bufer != NULL) |
9ee0fd5b |
74 | gpu.munmap(gpu.enhancement_bufer, ENHANCEMENT_BUF_SIZE); |
e929dec5 |
75 | gpu.enhancement_bufer = NULL; |
76 | egpu.enhancement_buf_ptr = NULL; |
9ee0fd5b |
77 | initialized = 0; |
e929dec5 |
78 | } |
79 | |
50f9355a |
80 | static __attribute__((noinline)) void |
81 | sync_enhancement_buffers(int x, int y, int w, int h) |
82 | { |
83 | int xt = egpu.enhancement_x_threshold; |
84 | u16 *src, *dst; |
85 | int wb, i; |
86 | |
87 | w += x & 7; |
88 | x &= ~7; |
89 | w = (w + 7) & ~7; |
90 | if (y + h > 512) |
91 | h = 512 - y; |
92 | |
93 | for (i = 0; i < 4 && w > 0; i++) { |
94 | if (x < 512) { |
95 | wb = w; |
96 | if (x + w > 512) |
97 | wb = 512 - x; |
98 | src = gpu.vram + xt * i + y * 1024 + x; |
99 | dst = egpu.enhancement_buf_ptr + |
100 | (1024*1024 + xt * 2) * i + (y * 1024 + x) * 2; |
101 | scale2x_tiles8(dst, src, wb / 8, h); |
102 | } |
103 | |
104 | x -= xt; |
105 | if (x < 0) { |
106 | w += x; |
107 | x = 0; |
108 | } |
109 | } |
110 | } |
111 | |
90ca4913 |
112 | void renderer_sync_ecmds(uint32_t *ecmds) |
113 | { |
b243416b |
114 | gpu_parse(&egpu, ecmds + 1, 6 * 4, NULL); |
90ca4913 |
115 | } |
116 | |
05740673 |
117 | void renderer_update_caches(int x, int y, int w, int h) |
90ca4913 |
118 | { |
05740673 |
119 | update_texture_cache_region(&egpu, x, y, x + w - 1, y + h - 1); |
50f9355a |
120 | if (gpu.state.enhancement_active && !gpu.status.rgb24) |
121 | sync_enhancement_buffers(x, y, w, h); |
90ca4913 |
122 | } |
123 | |
124 | void renderer_flush_queues(void) |
125 | { |
126 | flush_render_block_buffer(&egpu); |
127 | } |
128 | |
5440b88e |
129 | void renderer_set_interlace(int enable, int is_odd) |
130 | { |
f1359c57 |
131 | egpu.render_mode &= ~(RENDER_INTERLACE_ENABLED|RENDER_INTERLACE_ODD); |
5440b88e |
132 | if (enable) |
f1359c57 |
133 | egpu.render_mode |= RENDER_INTERLACE_ENABLED; |
5440b88e |
134 | if (is_odd) |
f1359c57 |
135 | egpu.render_mode |= RENDER_INTERLACE_ODD; |
5440b88e |
136 | } |
137 | |
e929dec5 |
138 | void renderer_notify_res_change(void) |
139 | { |
50f9355a |
140 | // note: must keep it multiple of 8 |
e929dec5 |
141 | egpu.enhancement_x_threshold = gpu.screen.hres; |
142 | } |
143 | |
c1817bd9 |
144 | #include "../../frontend/plugin_lib.h" |
145 | |
90ca4913 |
146 | void renderer_set_config(const struct rearmed_cbs *cbs) |
147 | { |
50f9355a |
148 | static int enhancement_was_on; |
149 | |
c1817bd9 |
150 | disable_main_render = cbs->gpu_neon.enhancement_no_main; |
50f9355a |
151 | if (egpu.enhancement_buf_ptr != NULL && cbs->gpu_neon.enhancement_enable |
152 | && !enhancement_was_on) |
153 | { |
154 | sync_enhancement_buffers(0, 0, 1024, 512); |
155 | } |
156 | enhancement_was_on = cbs->gpu_neon.enhancement_enable; |
9ee0fd5b |
157 | |
158 | if (!initialized) { |
159 | initialize_psx_gpu(&egpu, gpu.vram); |
160 | initialized = 1; |
161 | } |
162 | |
163 | if (gpu.enhancement_bufer == NULL) |
164 | map_enhancement_buffer(); |
90ca4913 |
165 | } |