frontend: update libpicofe, fix missed callbacks
[pcsx_rearmed.git] / plugins / gpu_neon / psx_gpu / psx_gpu.h
CommitLineData
75e28f62
E
1/*
2 * Copyright (C) 2011 Gilead Kutnick "Exophase" <exophase@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 */
14
15#ifndef PSX_GPU_H
16#define PSX_GPU_H
17
2d658c89 18#define MAX_SPANS 512
19#define MAX_BLOCKS 64
20#define MAX_BLOCKS_PER_ROW 128
21
22#define SPAN_DATA_BLOCKS_SIZE 32
23
ee060c58 24#define AHACK_TEXTURE_ADJ_U (1 << 0)
25#define AHACK_TEXTURE_ADJ_V (1 << 1)
26
2d658c89 27#ifndef __ASSEMBLER__
28
a4021361 29#include "vector_types.h"
30
ee060c58 31#ifndef unlikely
32#define unlikely(x) __builtin_expect((x), 0)
33#endif
34
f4ce97e1 35#define sign_extend_11bit(value) \
36 (((s32)((value) << 21)) >> 21)
37
75e28f62
E
38typedef enum
39{
40 PRIMITIVE_TYPE_TRIANGLE = 0,
41 PRIMITIVE_TYPE_SPRITE = 1,
42 PRIMITIVE_TYPE_LINE = 2,
43 PRIMITIVE_TYPE_UNKNOWN = 3
44} primitive_type_enum;
45
46typedef enum
47{
48 TEXTURE_MODE_4BPP = 0,
49 TEXTURE_MODE_8BPP = 1,
50 TEXTURE_MODE_16BPP = 2
51} texture_mode_enum;
52
53typedef enum
54{
55 BLEND_MODE_AVERAGE = 0,
56 BLEND_MODE_ADD = 1,
57 BLEND_MODE_SUBTRACT = 2,
58 BLEND_MODE_ADD_FOURTH = 3
59} blend_mode_enum;
60
61typedef enum
62{
63 RENDER_FLAGS_MODULATE_TEXELS = 0x1,
64 RENDER_FLAGS_BLEND = 0x2,
65 RENDER_FLAGS_TEXTURE_MAP = 0x4,
66 RENDER_FLAGS_QUAD = 0x8,
67 RENDER_FLAGS_SHADE = 0x10,
68} render_flags_enum;
69
70typedef enum
71{
72 RENDER_STATE_DITHER = 0x8,
73 RENDER_STATE_MASK_EVALUATE = 0x20,
74} render_state_enum;
75
69b09c0d
E
76typedef enum
77{
78 RENDER_INTERLACE_ENABLED = 0x1,
f1359c57 79 RENDER_INTERLACE_ODD = 0x2,
f1359c57 80} render_mode_enum;
69b09c0d 81
75e28f62
E
82typedef struct
83{
84 u16 left_x;
85 u16 num_blocks;
86 u16 right_mask;
87 u16 y;
88} edge_data_struct;
89
b0d96051 90// 64 (72) bytes total
75e28f62
E
91typedef struct
92{
93 // 16 bytes
94 union
95 {
96 vec_8x16u uv;
97 vec_8x16u texels;
98 vec_8x16u draw_mask;
99 };
100
101 // 24 bytes
102 union
103 {
104 struct
105 {
106 vec_8x8u r;
107 vec_8x8u g;
108 vec_8x8u b;
109 };
110
111 vec_8x16u pixels;
112 };
113
b0d96051 114 // 8 (16) bytes
75e28f62
E
115 u32 draw_mask_bits;
116 u16 *fb_ptr;
117
118 // 16 bytes
119 vec_8x16u dither_offsets;
120} block_struct;
121
75e28f62
E
122typedef struct render_block_handler_struct render_block_handler_struct;
123
124typedef struct
125{
126 // 144 bytes
127 vec_8x16u test_mask;
128
129 vec_4x32u uvrg;
130 vec_4x32u uvrg_dx;
131 vec_4x32u uvrg_dy;
132
133 vec_4x32u u_block_span;
134 vec_4x32u v_block_span;
135 vec_4x32u r_block_span;
136 vec_4x32u g_block_span;
137 vec_4x32u b_block_span;
138
75e28f62
E
139 u32 b;
140 u32 b_dy;
141
142 u32 triangle_area;
143
144 u32 texture_window_settings;
145 u32 current_texture_mask;
146 u32 viewport_mask;
147 u32 dirty_textures_4bpp_mask;
148 u32 dirty_textures_8bpp_mask;
149 u32 dirty_textures_8bpp_alternate_mask;
150
151 u32 triangle_color;
75e28f62
E
152 u32 dither_table[4];
153
154 struct render_block_handler_struct *render_block_handler;
155 void *texture_page_ptr;
3867c6ef 156 void *texture_page_base;
75e28f62
E
157 u16 *clut_ptr;
158 u16 *vram_ptr;
c1817bd9 159 u16 *vram_out_ptr;
75e28f62 160
2da2fc76 161 u32 uvrgb_phase;
162
75e28f62
E
163 u16 render_state_base;
164 u16 render_state;
165
166 u16 num_spans;
167 u16 num_blocks;
168
75e28f62
E
169 s16 viewport_start_x;
170 s16 viewport_start_y;
171 s16 viewport_end_x;
172 s16 viewport_end_y;
173
174 u16 mask_msb;
175
75e28f62
E
176 u8 triangle_winding;
177
178 u8 display_area_draw_enable;
179
180 u8 current_texture_page;
181 u8 last_8bpp_texture_page;
182
183 u8 texture_mask_width;
184 u8 texture_mask_height;
185 u8 texture_window_x;
186 u8 texture_window_y;
187
188 u8 primitive_type;
f1359c57 189 u8 render_mode;
75e28f62 190
c6063f89 191 s16 offset_x;
192 s16 offset_y;
193
194 u16 clut_settings;
195 u16 texture_settings;
196
ed0fd81d 197 u32 *reciprocal_table_ptr;
198
c1817bd9 199 // enhancement stuff
0b4038f8 200 u16 *enhancement_buf_ptr; // main alloc
201 u16 *enhancement_current_buf_ptr; // offset into above, 4 bufs
ee060c58 202 u32 hacks_active; // AHACK_TEXTURE_ADJ_U ...
0b4038f8 203 u32 saved_hres;
c1817bd9 204 s16 saved_viewport_start_x;
205 s16 saved_viewport_start_y;
206 s16 saved_viewport_end_x;
207 s16 saved_viewport_end_y;
2da2fc76 208 struct psx_gpu_scanout {
209 u16 x, y, w, h;
210 } enhancement_scanouts[4]; // 0-3 specifying which buf to use
211 u16 enhancement_scanout_eselect; // eviction selector
212 u16 enhancement_current_buf;
c1817bd9 213
ed8077c5 214 u32 allow_dithering:1;
215 u32 force_dithering:1;
6ab6ab97 216 u32 hack_disable_main:1;
217 u32 hack_texture_adj:1;
218
75e28f62 219 // Align up to 64 byte boundary to keep the upcoming buffers cache line
c1817bd9 220 // aligned, also make reachable with single immediate addition
db2804fb 221 u8 reserved_a[68 + 9*4 - 9*sizeof(void *)];
222
223 // space for saving regs on c call to flush_render_block_buffer() and asm
224 u32 saved_tmp[48 / sizeof(u32)];
225 u32 saved_q4_q7[64 / sizeof(u32)];
75e28f62
E
226
227 // 8KB
228 block_struct blocks[MAX_BLOCKS_PER_ROW];
229
230 // 14336 bytes
231 vec_4x32u span_uvrg_offset[MAX_SPANS];
232 edge_data_struct span_edge_data[MAX_SPANS];
233 u32 span_b_offset[MAX_SPANS];
234
75e28f62
E
235 u8 texture_4bpp_cache[32][256 * 256];
236 u8 texture_8bpp_even_cache[16][256 * 256];
237 u8 texture_8bpp_odd_cache[16][256 * 256];
75e28f62
E
238} psx_gpu_struct;
239
240typedef struct __attribute__((aligned(16)))
241{
242 u8 u;
243 u8 v;
244
245 u8 r;
246 u8 g;
247 u8 b;
248
249 u8 reserved[3];
250
251 s16 x;
252 s16 y;
a4021361 253
254 u32 padding;
75e28f62
E
255} vertex_struct;
256
f4ce97e1 257typedef struct
258{
259 vertex_struct *vertexes[3];
260 s16 offset_x;
261 s16 offset_y;
262} prepared_triangle;
263
75e28f62
E
264void render_block_fill(psx_gpu_struct *psx_gpu, u32 color, u32 x, u32 y,
265 u32 width, u32 height);
266void render_block_copy(psx_gpu_struct *psx_gpu, u16 *source, u32 x, u32 y,
267 u32 width, u32 height, u32 pitch);
268void render_block_move(psx_gpu_struct *psx_gpu, u32 source_x, u32 source_y,
269 u32 dest_x, u32 dest_y, u32 width, u32 height);
270
271void render_triangle(psx_gpu_struct *psx_gpu, vertex_struct *vertexes,
272 u32 flags);
273void render_sprite(psx_gpu_struct *psx_gpu, s32 x, s32 y, u32 u, u32 v,
1cec4719 274 s32 *width, s32 *height, u32 flags, u32 color);
75e28f62 275void render_line(psx_gpu_struct *gpu, vertex_struct *vertexes, u32 flags,
3b3dee71 276 u32 color, int double_resolution);
75e28f62
E
277
278u32 texture_region_mask(s32 x1, s32 y1, s32 x2, s32 y2);
279
a2cb152a 280void update_texture_8bpp_cache(psx_gpu_struct *psx_gpu);
75e28f62
E
281void flush_render_block_buffer(psx_gpu_struct *psx_gpu);
282
ee060c58 283void setup_blocks_uv_adj_hack(psx_gpu_struct *psx_gpu, block_struct *block,
284 edge_data_struct *span_edge_data, vec_4x32u *span_uvrg_offset);
285
e8c0e0bb 286void initialize_psx_gpu(psx_gpu_struct *psx_gpu, u16 *vram);
90ac6fed 287u32 gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size,
8412166f 288 s32 *cpu_cycles_sum_out, s32 *cpu_cycles_last, u32 *last_command);
75e28f62
E
289
290void triangle_benchmark(psx_gpu_struct *psx_gpu);
291
a4021361 292void compute_all_gradients(psx_gpu_struct * __restrict__ psx_gpu,
293 const vertex_struct * __restrict__ a, const vertex_struct * __restrict__ b,
294 const vertex_struct * __restrict__ c);
295
2d658c89 296#endif // __ASSEMBLER__
297#endif // PSX_GPU_H