Commit | Line | Data |
---|---|---|
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 | ||
18 | typedef enum | |
19 | { | |
20 | PRIMITIVE_TYPE_TRIANGLE = 0, | |
21 | PRIMITIVE_TYPE_SPRITE = 1, | |
22 | PRIMITIVE_TYPE_LINE = 2, | |
23 | PRIMITIVE_TYPE_UNKNOWN = 3 | |
24 | } primitive_type_enum; | |
25 | ||
26 | typedef enum | |
27 | { | |
28 | TEXTURE_MODE_4BPP = 0, | |
29 | TEXTURE_MODE_8BPP = 1, | |
30 | TEXTURE_MODE_16BPP = 2 | |
31 | } texture_mode_enum; | |
32 | ||
33 | typedef enum | |
34 | { | |
35 | BLEND_MODE_AVERAGE = 0, | |
36 | BLEND_MODE_ADD = 1, | |
37 | BLEND_MODE_SUBTRACT = 2, | |
38 | BLEND_MODE_ADD_FOURTH = 3 | |
39 | } blend_mode_enum; | |
40 | ||
41 | typedef enum | |
42 | { | |
43 | RENDER_FLAGS_MODULATE_TEXELS = 0x1, | |
44 | RENDER_FLAGS_BLEND = 0x2, | |
45 | RENDER_FLAGS_TEXTURE_MAP = 0x4, | |
46 | RENDER_FLAGS_QUAD = 0x8, | |
47 | RENDER_FLAGS_SHADE = 0x10, | |
48 | } render_flags_enum; | |
49 | ||
50 | typedef enum | |
51 | { | |
52 | RENDER_STATE_DITHER = 0x8, | |
53 | RENDER_STATE_MASK_EVALUATE = 0x20, | |
54 | } render_state_enum; | |
55 | ||
69b09c0d E |
56 | typedef enum |
57 | { | |
58 | RENDER_INTERLACE_ENABLED = 0x1, | |
f1359c57 | 59 | RENDER_INTERLACE_ODD = 0x2, |
f1359c57 | 60 | } render_mode_enum; |
69b09c0d | 61 | |
75e28f62 E |
62 | typedef struct |
63 | { | |
64 | u16 left_x; | |
65 | u16 num_blocks; | |
66 | u16 right_mask; | |
67 | u16 y; | |
68 | } edge_data_struct; | |
69 | ||
70 | // 64 bytes total | |
71 | typedef struct | |
72 | { | |
73 | // 16 bytes | |
74 | union | |
75 | { | |
76 | vec_8x16u uv; | |
77 | vec_8x16u texels; | |
78 | vec_8x16u draw_mask; | |
79 | }; | |
80 | ||
81 | // 24 bytes | |
82 | union | |
83 | { | |
84 | struct | |
85 | { | |
86 | vec_8x8u r; | |
87 | vec_8x8u g; | |
88 | vec_8x8u b; | |
89 | }; | |
90 | ||
91 | vec_8x16u pixels; | |
92 | }; | |
93 | ||
94 | // 8 bytes | |
95 | u32 draw_mask_bits; | |
96 | u16 *fb_ptr; | |
97 | ||
98 | // 16 bytes | |
99 | vec_8x16u dither_offsets; | |
100 | } block_struct; | |
101 | ||
102 | #define MAX_SPANS 512 | |
103 | #define MAX_BLOCKS 64 | |
104 | #define MAX_BLOCKS_PER_ROW 128 | |
105 | ||
106 | #define SPAN_DATA_BLOCKS_SIZE 32 | |
107 | ||
108 | typedef struct render_block_handler_struct render_block_handler_struct; | |
109 | ||
110 | typedef struct | |
111 | { | |
112 | // 144 bytes | |
113 | vec_8x16u test_mask; | |
114 | ||
115 | vec_4x32u uvrg; | |
116 | vec_4x32u uvrg_dx; | |
117 | vec_4x32u uvrg_dy; | |
118 | ||
119 | vec_4x32u u_block_span; | |
120 | vec_4x32u v_block_span; | |
121 | vec_4x32u r_block_span; | |
122 | vec_4x32u g_block_span; | |
123 | vec_4x32u b_block_span; | |
124 | ||
75e28f62 E |
125 | u32 b; |
126 | u32 b_dy; | |
127 | ||
128 | u32 triangle_area; | |
129 | ||
130 | u32 texture_window_settings; | |
131 | u32 current_texture_mask; | |
132 | u32 viewport_mask; | |
133 | u32 dirty_textures_4bpp_mask; | |
134 | u32 dirty_textures_8bpp_mask; | |
135 | u32 dirty_textures_8bpp_alternate_mask; | |
136 | ||
137 | u32 triangle_color; | |
75e28f62 E |
138 | u32 dither_table[4]; |
139 | ||
c6063f89 | 140 | u32 uvrgb_phase; |
141 | ||
75e28f62 E |
142 | struct render_block_handler_struct *render_block_handler; |
143 | void *texture_page_ptr; | |
3867c6ef | 144 | void *texture_page_base; |
75e28f62 E |
145 | u16 *clut_ptr; |
146 | u16 *vram_ptr; | |
c1817bd9 | 147 | u16 *vram_out_ptr; |
75e28f62 | 148 | |
75e28f62 E |
149 | u16 render_state_base; |
150 | u16 render_state; | |
151 | ||
152 | u16 num_spans; | |
153 | u16 num_blocks; | |
154 | ||
75e28f62 E |
155 | s16 viewport_start_x; |
156 | s16 viewport_start_y; | |
157 | s16 viewport_end_x; | |
158 | s16 viewport_end_y; | |
159 | ||
160 | u16 mask_msb; | |
161 | ||
75e28f62 E |
162 | u8 triangle_winding; |
163 | ||
164 | u8 display_area_draw_enable; | |
165 | ||
166 | u8 current_texture_page; | |
167 | u8 last_8bpp_texture_page; | |
168 | ||
169 | u8 texture_mask_width; | |
170 | u8 texture_mask_height; | |
171 | u8 texture_window_x; | |
172 | u8 texture_window_y; | |
173 | ||
174 | u8 primitive_type; | |
f1359c57 | 175 | u8 render_mode; |
75e28f62 | 176 | |
c6063f89 | 177 | s16 offset_x; |
178 | s16 offset_y; | |
179 | ||
180 | u16 clut_settings; | |
181 | u16 texture_settings; | |
182 | ||
ed0fd81d | 183 | u32 *reciprocal_table_ptr; |
184 | ||
c1817bd9 | 185 | // enhancement stuff |
186 | u16 *enhancement_buf_ptr; | |
e929dec5 | 187 | u16 *enhancement_current_buf_ptr; |
188 | u32 enhancement_x_threshold; | |
c1817bd9 | 189 | s16 saved_viewport_start_x; |
190 | s16 saved_viewport_start_y; | |
191 | s16 saved_viewport_end_x; | |
192 | s16 saved_viewport_end_y; | |
7956599f | 193 | u8 enhancement_buf_by_x16[64]; |
c1817bd9 | 194 | |
75e28f62 | 195 | // Align up to 64 byte boundary to keep the upcoming buffers cache line |
c1817bd9 | 196 | // aligned, also make reachable with single immediate addition |
ed0fd81d | 197 | u8 reserved_a[160]; |
75e28f62 E |
198 | |
199 | // 8KB | |
200 | block_struct blocks[MAX_BLOCKS_PER_ROW]; | |
201 | ||
202 | // 14336 bytes | |
203 | vec_4x32u span_uvrg_offset[MAX_SPANS]; | |
204 | edge_data_struct span_edge_data[MAX_SPANS]; | |
205 | u32 span_b_offset[MAX_SPANS]; | |
206 | ||
75e28f62 E |
207 | u8 texture_4bpp_cache[32][256 * 256]; |
208 | u8 texture_8bpp_even_cache[16][256 * 256]; | |
209 | u8 texture_8bpp_odd_cache[16][256 * 256]; | |
75e28f62 E |
210 | } psx_gpu_struct; |
211 | ||
212 | typedef struct __attribute__((aligned(16))) | |
213 | { | |
214 | u8 u; | |
215 | u8 v; | |
216 | ||
217 | u8 r; | |
218 | u8 g; | |
219 | u8 b; | |
220 | ||
221 | u8 reserved[3]; | |
222 | ||
223 | s16 x; | |
224 | s16 y; | |
225 | } vertex_struct; | |
226 | ||
227 | void render_block_fill(psx_gpu_struct *psx_gpu, u32 color, u32 x, u32 y, | |
228 | u32 width, u32 height); | |
229 | void render_block_copy(psx_gpu_struct *psx_gpu, u16 *source, u32 x, u32 y, | |
230 | u32 width, u32 height, u32 pitch); | |
231 | void render_block_move(psx_gpu_struct *psx_gpu, u32 source_x, u32 source_y, | |
232 | u32 dest_x, u32 dest_y, u32 width, u32 height); | |
233 | ||
234 | void render_triangle(psx_gpu_struct *psx_gpu, vertex_struct *vertexes, | |
235 | u32 flags); | |
236 | void render_sprite(psx_gpu_struct *psx_gpu, s32 x, s32 y, u32 u, u32 v, | |
237 | s32 width, s32 height, u32 flags, u32 color); | |
238 | void render_line(psx_gpu_struct *gpu, vertex_struct *vertexes, u32 flags, | |
3b3dee71 | 239 | u32 color, int double_resolution); |
75e28f62 E |
240 | |
241 | u32 texture_region_mask(s32 x1, s32 y1, s32 x2, s32 y2); | |
242 | ||
243 | void flush_render_block_buffer(psx_gpu_struct *psx_gpu); | |
244 | ||
e8c0e0bb | 245 | void initialize_psx_gpu(psx_gpu_struct *psx_gpu, u16 *vram); |
b243416b | 246 | u32 gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size, u32 *last_command); |
75e28f62 E |
247 | |
248 | void triangle_benchmark(psx_gpu_struct *psx_gpu); | |
249 | ||
250 | #endif | |
251 |