filename | test/testyuv.c |
changeset | 561:533f6b478071 |
prev | 288:a42f998226fb |
author | nkeynes |
date | Sun Oct 24 11:50:17 2010 +1000 (13 years ago) |
permissions | -rw-r--r-- |
last change | Set gl texture parameters at texture load time rather than render time. (This does mean that if the texture is used with variant parameters it will be loaded multiple times). 3-4% faster this way |
view | annotate | diff | log | raw |
1 /**
2 * $Id$
3 *
4 * Renderer test cases
5 *
6 * Copyright (c) 2006 Nathan Keynes.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18 #include <stdio.h>
19 #include "timer.h"
20 #include "testdata.h"
21 #include "pvr.h"
22 #include "lib.h"
23 #include "asic.h"
25 #define PVR_BASE 0xA05F8000
26 #define PVR_RESET (PVR_BASE+0x008)
27 #define YUV_ADDR (PVR_BASE+0x148)
28 #define YUV_CONFIG (PVR_BASE+0x14C)
29 #define YUV_STATUS (PVR_BASE+0x150)
30 #define TEXSIZE (PVR_BASE+0x0E4)
31 #define DISPLAY_MODE (PVR_BASE+0x044)
32 #define DISPLAY_ADDR1 (PVR_BASE+0x050)
33 #define DISPLAY_ADDR2 (PVR_BASE+0x054)
34 #define DISPLAY_SIZE (PVR_BASE+0x05C)
36 #define OBJ_START 0x00010000
37 #define OBJ_LENGTH 0x00010000
38 #define TILE_START 0x00060000
39 #define TILE_LENGTH 0x00010000
40 #define TILEMAP_ADDR 0x050B2C8
41 #define RENDER_ADDR 0x00600000
43 #define OBJCFG 0xA05F807C
44 #define ISPCFG 0xA05F8098
46 struct ta_config default_ta_config = { 0x00100002, GRID_SIZE(640,480), OBJ_START,
47 OBJ_START+OBJ_LENGTH, TILE_START+TILE_LENGTH,
48 TILE_START, TILE_START+TILE_LENGTH };
52 struct render_config default_render_config = { OBJ_START, TILEMAP_ADDR, RENDER_ADDR, 640, 480,
53 0x00000009, 0.0001f, 1.0f };
56 struct backplane {
57 uint32_t mode1, mode2, mode3;
58 float x1, y1, z1;
59 uint32_t col1;
60 float x2, y2, z2;
61 uint32_t col2;
62 float x3, y3, z3;
63 uint32_t col3;
64 };
67 #define START_BLEND 0
68 #define BG_COLOUR 0xFF808080
70 struct backplane default_backplane = { 0x90800000, 0x20800440, 0,
71 0.0, 0.0, 0.2, BG_COLOUR,
72 640.0, 0.0, 0.2, BG_COLOUR,
73 0.0, 480.0, 0.2, BG_COLOUR };
75 struct yuv_poly {
76 uint32_t poly[8];
77 struct {
78 uint32_t mode;
79 float x,y,z,u,v;
80 uint32_t colour;
81 uint32_t pad;
82 } vertex[4];
83 uint32_t end[8];
84 } test_yuv_poly = { { 0x808C010A, 0xE0000000, 0x2091A4F6, 0x1E000000, 0, 0, 0, 0 },
85 { { 0xE0000000, 0.0, 0.0, 2.0, 0.0, 0.0, 0xFFFFFFFF, 0 },
86 { 0xE0000000, 640.0, 0.0, 2.0, 0.625, 0.0, 0xFFFFFFFF, 0 },
87 { 0xE0000000, 0.0, 480.0, 2.0, 0.0, 0.9375, 0xFFFFFFFF, 0 },
88 { 0xF0000000, 640.0, 480.0, 2.0, 0.625, 0.9375, 0xFFFFFFFF, 0 } },
89 { 0,0,0,0,0,0,0,0 } };
94 int test_yuv( test_data_t test_case )
95 {
96 int i;
97 char tabuf[512];
98 char *p = DMA_ALIGN(&tabuf);
100 /* Check input */
101 test_data_block_t input = get_test_data(test_case, "input");
102 if( input == NULL ) {
103 fprintf( stderr, "Skipping test '%s' - no input\n", test_case->test_name );
104 return -1;
105 }
107 memset( (void *)(0xA5000000), 0xFE, 512000 );
109 pvr_init();
110 asic_clear();
112 fprintf( stdout, "Writing %d bytes\n", input->length );
113 long_write( YUV_CONFIG, 0x00001D14 );
114 long_write( YUV_ADDR, 0x00000000 );
115 timer_start();
116 uint32_t status1 = long_read( YUV_STATUS );
117 if( pvr_dma_write( 0x10800000, input->data, input->length, 0 ) != 0 ) {
118 return -1;
119 }
120 uint32_t timeus = timer_gettime_us();
121 uint32_t status2 = long_read( YUV_STATUS );
123 struct ta_config *config = &default_ta_config;
125 /* Send TA data */
126 asic_clear();
127 pvr_init();
128 ta_init(config);
129 memcpy( p, &test_yuv_poly, sizeof(test_yuv_poly) );
130 if( pvr_dma_write( 0x10000000, p, sizeof(test_yuv_poly), 0 ) != 0 ) {
131 return -1;
132 }
133 asic_wait( EVENT_PVR_OPAQUE_DONE );
134 if( asic_check( EVENT_PVR_PRIM_ALLOC_FAIL ) ||
135 asic_check( EVENT_PVR_MATRIX_ALLOC_FAIL ) ||
136 asic_check( EVENT_PVR_BAD_INPUT ) ) {
137 asic_dump(stderr);
138 return -1;
139 }
141 /* Write backplane (if any) */
142 uint32_t bgplane = pvr_get_objbuf_posn();
143 memcpy( (char *)(PVR_VRAM_BASE + bgplane), &default_backplane, sizeof(default_backplane) );
144 bgplane -= default_render_config.polybuf;
145 render_set_backplane( (bgplane << 1) | 0x01000000 );
147 /* Render the damn thing */
148 long_write( OBJCFG, 0x0027DF77 );
149 long_write( ISPCFG, 0x00800409 );
150 long_write( TEXSIZE, 0x0000000A );
151 pvr_build_tilemap2( TILEMAP_ADDR, config, 0x10000000 );
152 render_start( &default_render_config );
153 if( asic_wait( EVENT_PVR_RENDER_DONE ) == -1 ) {
154 fprintf( stderr, "Test render failed (timeout waiting for render)\n" );
155 asic_dump( stderr );
156 return -1;
157 }
159 asic_clear();
160 asic_wait( EVENT_RETRACE );
161 display_render( &default_render_config );
162 asic_clear();
163 asic_wait(EVENT_RETRACE);
164 asic_clear();
165 asic_wait(EVENT_RETRACE);
166 asic_clear();
167 asic_wait(EVENT_RETRACE);
168 asic_clear();
169 asic_wait(EVENT_RETRACE);
170 return 0;
171 }
173 int main( int argc, char *argv[] )
174 {
175 int test_cases = 0;
176 int test_failures = 0;
177 test_data_t test_data = load_test_dataset(stdin);
178 test_data_t test_case = test_data;
180 asic_mask_all();
181 pvr_init();
183 while( test_case != NULL ) {
184 test_cases++;
185 int result = test_yuv(test_case);
186 if( result != 0 ) {
187 test_failures++;
188 }
189 test_case = test_case->next;
190 }
191 free_test_dataset(test_data);
192 if( test_failures != 0 ) {
193 fprintf( stderr, "%d/%d test failures!\n", test_failures, test_cases );
194 return 1;
195 } else {
196 fprintf( stderr, "%d tests OK\n", test_cases );
197 return 0;
198 }
199 }
.