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 | #include <stdio.h> | |
16 | #include <stdlib.h> | |
17 | ||
18 | #include "SDL.h" | |
19 | #include "common.h" | |
20 | ||
21 | extern u32 span_pixels; | |
22 | extern u32 span_pixel_blocks; | |
23 | extern u32 span_pixel_blocks_unaligned; | |
24 | extern u32 spans; | |
25 | extern u32 triangles; | |
26 | extern u32 sprites; | |
27 | extern u32 sprites_4bpp; | |
28 | extern u32 sprites_8bpp; | |
29 | extern u32 sprites_16bpp; | |
30 | extern u32 sprites_untextured; | |
31 | extern u32 sprite_blocks; | |
32 | extern u32 lines; | |
33 | extern u32 texels_4bpp; | |
34 | extern u32 texels_8bpp; | |
35 | extern u32 texels_16bpp; | |
36 | extern u32 texel_blocks_4bpp; | |
37 | extern u32 texel_blocks_8bpp; | |
38 | extern u32 texel_blocks_16bpp; | |
39 | extern u32 texel_blocks_untextured; | |
40 | extern u32 blend_blocks; | |
41 | extern u32 untextured_pixels; | |
42 | extern u32 blend_pixels; | |
43 | extern u32 transparent_pixels; | |
44 | extern u32 render_buffer_flushes; | |
45 | extern u32 state_changes; | |
46 | extern u32 trivial_rejects; | |
47 | extern u32 left_split_triangles; | |
48 | extern u32 flat_triangles; | |
49 | extern u32 clipped_triangles; | |
50 | extern u32 zero_block_spans; | |
51 | extern u32 texture_cache_loads; | |
52 | extern u32 false_modulated_triangles; | |
53 | extern u32 false_modulated_sprites; | |
54 | ||
55 | static u32 mismatches; | |
56 | ||
57 | typedef struct | |
58 | { | |
59 | u16 vram[1024 * 512]; | |
60 | u32 gpu_register[15]; | |
61 | u32 status; | |
62 | } gpu_dump_struct; | |
63 | ||
64 | static gpu_dump_struct state; | |
65 | ||
66 | psx_gpu_struct __attribute__((aligned(256))) _psx_gpu; | |
67 | ||
68 | #define percent_of(numerator, denominator) \ | |
69 | ((((double)(numerator)) / (denominator)) * 100.0) \ | |
70 | ||
71 | void clear_stats(void) | |
72 | { | |
73 | triangles = 0; | |
74 | sprites = 0; | |
75 | sprites_4bpp = 0; | |
76 | sprites_8bpp = 0; | |
77 | sprites_16bpp = 0; | |
78 | sprites_untextured = 0; | |
79 | sprite_blocks = 0; | |
80 | lines = 0; | |
81 | span_pixels = 0; | |
82 | span_pixel_blocks = 0; | |
83 | span_pixel_blocks_unaligned = 0; | |
84 | spans = 0; | |
85 | texels_4bpp = 0; | |
86 | texels_8bpp = 0; | |
87 | texels_16bpp = 0; | |
88 | texel_blocks_untextured = 0; | |
89 | texel_blocks_4bpp = 0; | |
90 | texel_blocks_8bpp = 0; | |
91 | texel_blocks_16bpp = 0; | |
92 | blend_blocks = 0; | |
93 | untextured_pixels = 0; | |
94 | blend_pixels = 0; | |
95 | transparent_pixels = 0; | |
96 | render_buffer_flushes = 0; | |
97 | state_changes = 0; | |
98 | trivial_rejects = 0; | |
99 | left_split_triangles = 0; | |
100 | flat_triangles = 0; | |
101 | clipped_triangles = 0; | |
102 | zero_block_spans = 0; | |
103 | texture_cache_loads = 0; | |
104 | false_modulated_triangles = 0; | |
105 | false_modulated_sprites = 0; | |
106 | } | |
107 | ||
108 | void update_screen(psx_gpu_struct *psx_gpu, SDL_Surface *screen) | |
109 | { | |
110 | u32 x, y; | |
111 | ||
112 | for(y = 0; y < 512; y++) | |
113 | { | |
114 | for(x = 0; x < 1024; x++) | |
115 | { | |
116 | u32 pixel = psx_gpu->vram_ptr[(y * 1024) + x]; | |
117 | ((u32 *)screen->pixels)[(y * 1024) + x] = | |
118 | ((pixel & 0x1F) << (16 + 3)) | | |
119 | (((pixel >> 5) & 0x1F) << (8 + 3)) | | |
120 | (((pixel >> 10) & 0x1F) << 3); | |
121 | } | |
122 | } | |
123 | ||
124 | SDL_Flip(screen); | |
125 | } | |
126 | ||
127 | #ifdef PANDORA_BUILD | |
128 | ||
129 | #include <fcntl.h> | |
130 | #include <linux/fb.h> | |
131 | #include <sys/mman.h> | |
132 | #include <sys/ioctl.h> | |
133 | ||
134 | #endif | |
135 | ||
136 | int main(int argc, char *argv[]) | |
137 | { | |
138 | psx_gpu_struct *psx_gpu = &_psx_gpu; | |
139 | SDL_Surface *screen; | |
140 | SDL_Event event; | |
141 | ||
142 | u32 *list; | |
143 | int size; | |
144 | FILE *state_file; | |
145 | FILE *list_file; | |
146 | u32 no_display = 0; | |
147 | ||
148 | if((argc != 3) && (argc != 4)) | |
149 | { | |
150 | printf("usage:\n%s <state> <list>\n", argv[0]); | |
151 | return 1; | |
152 | } | |
153 | ||
154 | if((argc == 4) && !strcmp(argv[3], "-n")) | |
155 | no_display = 1; | |
156 | ||
157 | state_file = fopen(argv[1], "rb"); | |
158 | fread(&state, 1, sizeof(gpu_dump_struct), state_file); | |
159 | fclose(state_file); | |
160 | ||
161 | list_file = fopen(argv[2], "rb"); | |
162 | ||
163 | fseek(list_file, 0, SEEK_END); | |
164 | size = ftell(list_file); | |
165 | fseek(list_file, 0, SEEK_SET); | |
166 | //size = 0; | |
167 | ||
168 | list = malloc(size); | |
169 | fread(list, 1, size, list_file); | |
170 | fclose(list_file); | |
171 | ||
172 | if(no_display == 0) | |
173 | { | |
174 | SDL_Init(SDL_INIT_EVERYTHING); | |
175 | screen = SDL_SetVideoMode(1024, 512, 32, 0); | |
176 | } | |
177 | ||
178 | initialize_psx_gpu(psx_gpu); | |
179 | ||
180 | #ifdef PANDORA_BUILD | |
181 | system("ofbset -fb /dev/fb1 -mem 6291456 -en 0"); | |
182 | u32 fbdev_handle = open("/dev/fb1", O_RDWR); | |
183 | psx_gpu->vram_ptr = (mmap((void *)0x50000000, 1024 * 1024 * 2, PROT_READ | PROT_WRITE, | |
184 | MAP_SHARED | 0xA0000000, fbdev_handle, 0)); | |
185 | psx_gpu->vram_ptr += 64; | |
186 | #endif | |
187 | ||
188 | ||
189 | ||
190 | #ifdef PANDORA_BUILD | |
191 | //triangle_benchmark(psx_gpu); | |
192 | //return 0; | |
193 | #endif | |
194 | ||
195 | #ifdef FULL_COMPARE_MODE | |
196 | psx_gpu->pixel_count_mode = 1; | |
197 | psx_gpu->pixel_compare_mode = 0; | |
198 | memcpy(psx_gpu->vram_ptr, state.vram, 1024 * 512 * 2); | |
199 | //render_block_fill(psx_gpu, 0, 0, 0, 1024, 512); | |
200 | gpu_parse(psx_gpu, list, size); | |
201 | ||
202 | psx_gpu->pixel_count_mode = 0; | |
203 | psx_gpu->pixel_compare_mode = 1; | |
204 | memcpy(psx_gpu->compare_vram, state.vram, 1024 * 512 * 2); | |
205 | memcpy(psx_gpu->vram_ptr, state.vram, 1024 * 512 * 2); | |
206 | //render_block_fill(psx_gpu, 0, 0, 0, 1024, 512); | |
207 | clear_stats(); | |
208 | gpu_parse(psx_gpu, list, size); | |
209 | flush_render_block_buffer(psx_gpu); | |
210 | #else | |
211 | memcpy(psx_gpu->vram_ptr, state.vram, 1024 * 512 * 2); | |
212 | ||
213 | psx_gpu->pixel_count_mode = 0; | |
214 | psx_gpu->pixel_compare_mode = 0; | |
215 | ||
216 | clear_stats(); | |
217 | ||
218 | #ifdef PANDORA_BUILD | |
219 | init_counter(); | |
220 | #endif | |
221 | ||
222 | gpu_parse(psx_gpu, list, size); | |
223 | flush_render_block_buffer(psx_gpu); | |
224 | ||
225 | clear_stats(); | |
226 | ||
227 | #ifdef PANDORA_BUILD | |
228 | u32 cycles = get_counter(); | |
229 | #endif | |
230 | ||
231 | gpu_parse(psx_gpu, list, size); | |
232 | flush_render_block_buffer(psx_gpu); | |
233 | ||
234 | printf("%s: ", argv[1]); | |
235 | #ifdef PANDORA_BUILD | |
236 | u32 cycles_elapsed = get_counter() - cycles; | |
237 | ||
238 | printf("%d\n", cycles_elapsed); | |
239 | #endif | |
240 | ||
241 | #if 1 | |
242 | u32 i; | |
243 | ||
244 | for(i = 0; i < 1024 * 512; i++) | |
245 | { | |
246 | if((psx_gpu->vram_ptr[i] & 0x7FFF) != (state.vram[i] & 0x7FFF)) | |
247 | { | |
248 | printf("(%d %d %d) vs (%d %d %d) at (%d %d)\n", | |
249 | psx_gpu->vram_ptr[i] & 0x1F, | |
250 | (psx_gpu->vram_ptr[i] >> 5) & 0x1F, | |
251 | (psx_gpu->vram_ptr[i] >> 10) & 0x1F, | |
252 | state.vram[i] & 0x1F, | |
253 | (state.vram[i] >> 5) & 0x1F, | |
254 | (state.vram[i] >> 10) & 0x1F, i % 1024, i / 1024); | |
255 | ||
256 | mismatches++; | |
257 | } | |
258 | else | |
259 | { | |
260 | psx_gpu->vram_ptr[i] = | |
261 | ((psx_gpu->vram_ptr[i] & 0x1F) / 4) | | |
262 | ((((psx_gpu->vram_ptr[i] >> 5) & 0x1F) / 4) << 5) | | |
263 | ((((psx_gpu->vram_ptr[i] >> 10) & 0x1F) / 4) << 10); | |
264 | } | |
265 | } | |
266 | #endif | |
267 | #endif | |
268 | ||
269 | #if 0 | |
270 | printf("\n"); | |
271 | printf(" %d pixels, %d pixel blocks (%d unaligned), %d spans\n" | |
272 | " (%lf pixels per block (%lf unaligned, r %lf), %lf pixels per span),\n" | |
273 | " %lf blocks per span (%lf per non-zero span), %lf overdraw)\n\n", | |
274 | span_pixels, span_pixel_blocks, span_pixel_blocks_unaligned, spans, | |
275 | (double)span_pixels / span_pixel_blocks, | |
276 | (double)span_pixels / span_pixel_blocks_unaligned, | |
277 | (double)span_pixel_blocks / span_pixel_blocks_unaligned, | |
278 | (double)span_pixels / spans, | |
279 | (double)span_pixel_blocks / spans, | |
280 | (double)span_pixel_blocks / (spans - zero_block_spans), | |
281 | (double)span_pixels / | |
282 | ((psx_gpu->viewport_end_x - psx_gpu->viewport_start_x) * | |
283 | (psx_gpu->viewport_end_y - psx_gpu->viewport_start_y))); | |
284 | ||
285 | printf(" %d triangles (%d false modulated)\n" | |
286 | " (%d trivial rejects, %lf%% flat, %lf%% left split, %lf%% clipped)\n" | |
287 | " (%lf pixels per triangle, %lf rows per triangle)\n\n", | |
288 | triangles, false_modulated_triangles, trivial_rejects, | |
289 | percent_of(flat_triangles, triangles), | |
290 | percent_of(left_split_triangles, triangles), | |
291 | percent_of(clipped_triangles, triangles), | |
292 | (double)span_pixels / triangles, | |
293 | (double)spans / triangles); | |
294 | ||
295 | printf(" Block data:\n"); | |
296 | printf(" %7d 4bpp texel blocks (%lf%%)\n", texel_blocks_4bpp, | |
297 | percent_of(texel_blocks_4bpp, span_pixel_blocks)); | |
298 | printf(" %7d 8bpp texel blocks (%lf%%)\n", texel_blocks_8bpp, | |
299 | percent_of(texel_blocks_8bpp, span_pixel_blocks)); | |
300 | printf(" %7d 16bpp texel blocks (%lf%%)\n", texel_blocks_16bpp, | |
301 | percent_of(texel_blocks_16bpp, span_pixel_blocks)); | |
302 | printf(" %7d untextured blocks (%lf%%)\n", texel_blocks_untextured, | |
303 | percent_of(texel_blocks_untextured, span_pixel_blocks)); | |
304 | printf(" %7d sprite blocks (%lf%%)\n", sprite_blocks, | |
305 | percent_of(sprite_blocks, span_pixel_blocks)); | |
306 | printf(" %7d blended blocks (%lf%%)\n", blend_blocks, | |
307 | percent_of(blend_blocks, span_pixel_blocks)); | |
308 | printf("\n"); | |
309 | printf(" %lf blocks per render buffer flush\n", (double)span_pixel_blocks / | |
310 | render_buffer_flushes); | |
311 | printf(" %d zero block spans\n", zero_block_spans); | |
312 | printf(" %d state changes, %d texture cache loads\n", state_changes, | |
313 | texture_cache_loads); | |
314 | if(sprites) | |
315 | { | |
316 | printf(" %d sprites\n" | |
317 | " 4bpp: %lf%%\n" | |
318 | " 8bpp: %lf%%\n" | |
319 | " 16bpp: %lf%%\n" | |
320 | " untextured: %lf%%\n", | |
321 | sprites, percent_of(sprites_4bpp, sprites), | |
322 | percent_of(sprites_8bpp, sprites), percent_of(sprites_16bpp, sprites), | |
323 | percent_of(sprites_untextured, sprites)); | |
324 | } | |
325 | printf("\n"); | |
326 | printf(" %d mismatches\n\n\n", mismatches); | |
327 | #endif | |
328 | ||
329 | fflush(stdout); | |
330 | ||
331 | if(no_display == 0) | |
332 | { | |
333 | while(1) | |
334 | { | |
335 | update_screen(psx_gpu, screen); | |
336 | ||
337 | if(SDL_PollEvent(&event)) | |
338 | { | |
339 | if((event.type == SDL_QUIT) || | |
340 | ((event.type == SDL_KEYDOWN) && | |
341 | (event.key.keysym.sym == SDLK_ESCAPE))) | |
342 | { | |
343 | break; | |
344 | } | |
345 | } | |
346 | ||
347 | SDL_Delay(20); | |
348 | } | |
349 | } | |
350 | ||
351 | return (mismatches != 0); | |
352 | } |