Search
lxdream.org :: lxdream :: r213:da6b1904f67b
lxdream 0.9.1
released Jun 29
Download Now
changeset213:da6b1904f67b
parent212:8b77a7e6b6f0
child214:7a6501b74fbc
authornkeynes
dateFri Aug 18 09:33:19 2006 +0000 (14 years ago)
Initial rendering tests (no support for result comparison yet)
test/Makefile
test/pvr.c
test/pvr.h
test/testrend.c
1.1 --- a/test/Makefile Fri Aug 18 09:32:32 2006 +0000
1.2 +++ b/test/Makefile Fri Aug 18 09:33:19 2006 +0000
1.3 @@ -85,6 +85,10 @@
1.4 $(SH4CC) $(SH4LDFLAGS) $^ -o $@ $(SH4LIBS)
1.5 $(SH4OBJCOPY) testta testta.bin
1.6
1.7 +testrend: crt0.so $(SHARED_OBJECTS) testrend.so pvr.so dmac.so asic.so lib.so testdata.so
1.8 + $(SH4CC) $(SH4LDFLAGS) $^ -o $@ $(SH4LIBS)
1.9 + $(SH4OBJCOPY) testrend testrend.bin
1.10 +
1.11 readdata: crt0.so readdata.so
1.12 $(SH4CC) $(SH4LDFLAGS) $^ -o $@ $(SH4LIBS)
1.13
2.1 --- a/test/pvr.c Fri Aug 18 09:32:32 2006 +0000
2.2 +++ b/test/pvr.c Fri Aug 18 09:33:19 2006 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: pvr.c,v 1.2 2006-08-02 04:13:15 nkeynes Exp $
2.6 + * $Id: pvr.c,v 1.3 2006-08-18 09:33:19 nkeynes Exp $
2.7 *
2.8 * PVR support code
2.9 *
2.10 @@ -30,8 +30,26 @@
2.11 #define TA_OBJPOSN (PVR_BASE+0x138)
2.12 #define TA_SIZE (PVR_BASE+0x13C)
2.13 #define TA_TILECFG (PVR_BASE+0x140)
2.14 +#define TA_REINIT (PVR_BASE+0x160)
2.15 #define TA_PLISTSTART (PVR_BASE+0x164)
2.16
2.17 +#define RENDER_START (PVR_BASE+0x014)
2.18 +#define RENDER_POLYBASE (PVR_BASE+0x020)
2.19 +#define RENDER_TILEBASE (PVR_BASE+0x02C)
2.20 +#define RENDER_MODE (PVR_BASE+0x048)
2.21 +#define RENDER_SIZE (PVR_BASE+0x04C)
2.22 +#define RENDER_ADDR1 (PVR_BASE+0x060)
2.23 +#define RENDER_ADDR2 (PVR_BASE+0x064)
2.24 +#define RENDER_HCLIP (PVR_BASE+0x068)
2.25 +#define RENDER_VCLIP (PVR_BASE+0x06C)
2.26 +#define RENDER_NEARCLIP (PVR_BASE+0x078)
2.27 +#define RENDER_FARCLIP (PVR_BASE+0x088)
2.28 +#define RENDER_BGPLANE (PVR_BASE+0x08C)
2.29 +
2.30 +#define DISPLAY_MODE (PVR_BASE+0x044)
2.31 +#define DISPLAY_ADDR1 (PVR_BASE+0x050)
2.32 +#define DISPLAY_ADDR2 (PVR_BASE+0x054)
2.33 +#define DISPLAY_SIZE (PVR_BASE+0x05C
2.34
2.35 void ta_dump_regs( FILE *f )
2.36 {
2.37 @@ -59,11 +77,21 @@
2.38 long_write( TA_INIT, 0x80000000 );
2.39 }
2.40
2.41 +void ta_reinit( )
2.42 +{
2.43 + long_write( TA_REINIT, 0x80000000 );
2.44 +}
2.45 +
2.46 int pvr_get_objbuf_size( )
2.47 {
2.48 return long_read( TA_OBJPOSN ) - long_read( TA_OBJSTART );
2.49 }
2.50
2.51 +int pvr_get_objbuf_posn( )
2.52 +{
2.53 + return long_read( TA_OBJPOSN );
2.54 +}
2.55 +
2.56 int pvr_get_plist_posn( )
2.57 {
2.58 unsigned int addr = long_read( TA_TILEPOSN ) << 2;
2.59 @@ -108,6 +136,138 @@
2.60 fwrite_dump( f, buf, length );
2.61 }
2.62
2.63 +static int ta_tile_sizes[4] = { 0, 32, 64, 128 };
2.64 +#define TILE_SIZE(cfg, tile) ta_tile_sizes[((((cfg->ta_cfg) >> (4*tile))&0x03))]
2.65 +#define TILE_ENABLED(cfg, tile) ((((cfg->ta_cfg) >> (4*tile))&0x03) != 0)
2.66 +void pvr_compute_tilematrix_addr( int *tile_ptrs, struct ta_config *config ) {
2.67 + int tile_sizes[5], i;
2.68 + int hsegs = (config->grid_size & 0xFFFF)+1;
2.69 + int vsegs = (config->grid_size >> 16) + 1;
2.70 + for( i=0; i<5; i++ ) {
2.71 + tile_sizes[i] = TILE_SIZE(config,i);
2.72 + }
2.73 + tile_ptrs[0] = config->tile_start;
2.74 + tile_ptrs[1] = tile_ptrs[0] + (hsegs*vsegs*tile_sizes[0]);
2.75 + tile_ptrs[2] = tile_ptrs[1] + (hsegs*vsegs*tile_sizes[1]);
2.76 + tile_ptrs[3] = tile_ptrs[2] + (hsegs*vsegs*tile_sizes[2]);
2.77 + tile_ptrs[4] = tile_ptrs[3] + (hsegs*vsegs*tile_sizes[3]);
2.78 +}
2.79 +
2.80 +static uint32_t *pvr_compute_tile_ptrs( uint32_t *target, struct ta_config *config, int x, int y )
2.81 +{
2.82 + int i;
2.83 + int cfg = config->ta_cfg;
2.84 + int hsegs = (config->grid_size & 0xFFFF)+1;
2.85 + int vsegs = (config->grid_size >> 16) + 1;
2.86 + int tilematrix = config->tile_start;
2.87 + for( i=0; i<5; i++ ) {
2.88 + if( cfg & 0x03 ) {
2.89 + int tile_size = ta_tile_sizes[cfg&0x03];
2.90 + *target++ = tilematrix + (((y*hsegs)+x)*tile_size);
2.91 + tilematrix += hsegs*vsegs*tile_size;
2.92 + } else {
2.93 + *target++ = 0x80000000;
2.94 + }
2.95 + cfg = cfg >> 4;
2.96 + }
2.97 + return target;
2.98 +}
2.99 +
2.100 +void pvr_build_tilemap1( uint32_t addr, struct ta_config *config, uint32_t control_word )
2.101 +{
2.102 + uint32_t *dest = (uint32_t *)(PVR_VRAM_BASE+addr);
2.103 + int w = (config->grid_size & 0x0000FFFF) + 1;
2.104 + int h = (config->grid_size >> 16) + 1;
2.105 +
2.106 + int x,y;
2.107 + memset( (char *)(dest-18), 0, 18*4 );
2.108 + *dest++ = 0x10000000;
2.109 + *dest++ = 0x80000000;
2.110 + *dest++ = 0x80000000;
2.111 + *dest++ = 0x80000000;
2.112 + *dest++ = 0x80000000;
2.113 + *dest++ = 0x80000000;
2.114 + for( x=0; x<w; x++ ) {
2.115 + for( y=0; y<h; y++ ) {
2.116 + *dest++ = control_word | (y << 8) | (x << 2);
2.117 + dest = pvr_compute_tile_ptrs(dest, config, x, y);
2.118 + }
2.119 + }
2.120 + dest[-6] |= 0x80000000; /* End-of-render */
2.121 +}
2.122 +
2.123 +void pvr_build_tilemap2( uint32_t addr, struct ta_config *config, uint32_t control_word )
2.124 +{
2.125 + uint32_t *dest = (uint32_t *)(PVR_VRAM_BASE+addr);
2.126 + int w = (config->grid_size & 0x0000FFFF) + 1;
2.127 + int h = (config->grid_size >> 16) + 1;
2.128 +
2.129 + int x,y;
2.130 + *dest++ = 0x10000000;
2.131 + *dest++ = 0x80000000;
2.132 + *dest++ = 0x80000000;
2.133 + *dest++ = 0x80000000;
2.134 + *dest++ = 0x80000000;
2.135 + *dest++ = 0x80000000;
2.136 + for( x=0; x<w; x++ ) {
2.137 + for( y=0; y<h; y++ ) {
2.138 + *dest++ = 0x40000000;
2.139 + *dest++ = 0x80000000;
2.140 + *dest++ = 0x80000000;
2.141 + *dest++ = 0x80000000;
2.142 + *dest++ = 0x80000000;
2.143 + *dest++ = 0x80000000;
2.144 + *dest++ = control_word | (y << 8) | (x << 2);
2.145 + dest = pvr_compute_tile_ptrs(dest, config, x, y);
2.146 + }
2.147 + }
2.148 + dest[-6] |= 0x80000000; /* End-of-render */
2.149 +}
2.150 +
2.151 +void render_set_backplane( uint32_t mode )
2.152 +{
2.153 + long_write( RENDER_BGPLANE, mode );
2.154 +}
2.155 +
2.156 +int get_line_size( struct render_config *config )
2.157 +{
2.158 + int modulo = config->width;
2.159 + switch( config->mode & 0x07 ) {
2.160 + case 4:
2.161 + modulo *= 3; /* ??? */
2.162 + break;
2.163 + case 5:
2.164 + case 6:
2.165 + modulo *= 4;
2.166 + break;
2.167 + default:
2.168 + modulo *= 2;
2.169 + }
2.170 + return modulo;
2.171 +}
2.172 +
2.173 +void render_start( struct render_config *config )
2.174 +{
2.175 + int modulo = get_line_size( config );
2.176 + long_write( RENDER_POLYBASE, config->polybuf );
2.177 + long_write( RENDER_TILEBASE, config->tilemap );
2.178 + long_write( RENDER_ADDR1, config->render_addr );
2.179 + long_write( RENDER_SIZE, modulo >> 3 );
2.180 + long_write( RENDER_ADDR2, config->render_addr + modulo ); /* Not used? */
2.181 + long_write( RENDER_HCLIP, (config->width - 1) << 16 );
2.182 + long_write( RENDER_VCLIP, (config->height - 1) << 16 );
2.183 + long_write( RENDER_MODE, config->mode );
2.184 + float_write( RENDER_FARCLIP, config->farclip );
2.185 + float_write( RENDER_NEARCLIP, config->nearclip );
2.186 + long_write( RENDER_START, 0xFFFFFFFF );
2.187 +}
2.188 +
2.189 +void display_render( struct render_config *config )
2.190 +{
2.191 + long_write( DISPLAY_ADDR1, config->render_addr );
2.192 + long_write( DISPLAY_ADDR2, config->render_addr + get_line_size(config) );
2.193 +}
2.194 +
2.195 /************** Stolen from TATEST *************/
2.196
2.197 static unsigned int three_d_params[] = {
3.1 --- a/test/pvr.h Fri Aug 18 09:32:32 2006 +0000
3.2 +++ b/test/pvr.h Fri Aug 18 09:33:19 2006 +0000
3.3 @@ -1,5 +1,5 @@
3.4 /**
3.5 - * $Id: pvr.h,v 1.2 2006-08-02 04:13:15 nkeynes Exp $
3.6 + * $Id: pvr.h,v 1.3 2006-08-18 09:33:19 nkeynes Exp $
3.7 *
3.8 * PVR support code
3.9 *
3.10 @@ -145,8 +145,25 @@
3.11 unsigned int plist_start;
3.12 };
3.13
3.14 +struct render_config {
3.15 + unsigned int polybuf;
3.16 + unsigned int tilemap;
3.17 + unsigned int render_addr;
3.18 + unsigned int width, height;
3.19 + unsigned int mode;
3.20 + float farclip, nearclip;
3.21 +};
3.22 +
3.23 void ta_init( struct ta_config *config );
3.24 +void ta_reinit();
3.25 void pvr_dump_objbuf( FILE *f );
3.26 void pvr_dump_tilebuf( FILE *f );
3.27 int pvr_get_objbuf_size();
3.28 +int pvr_get_objbuf_posn();
3.29 int pvr_get_plist_posn();
3.30 +void render_set_backplane( unsigned int mode );
3.31 +void render_start( struct render_config *config );
3.32 +void display_render( struct render_config *config );
3.33 +void pvr_build_tilemap1( unsigned int addr, struct ta_config *config, unsigned int control_word );
3.34 +
3.35 +void pvr_build_tilemap2( unsigned int addr, struct ta_config *config, unsigned int control_word );
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/test/testrend.c Fri Aug 18 09:33:19 2006 +0000
4.3 @@ -0,0 +1,134 @@
4.4 +/**
4.5 + * $Id: testrend.c,v 1.1 2006-08-18 09:33:19 nkeynes Exp $
4.6 + *
4.7 + * Renderer test cases
4.8 + *
4.9 + * Copyright (c) 2006 Nathan Keynes.
4.10 + *
4.11 + * This program is free software; you can redistribute it and/or modify
4.12 + * it under the terms of the GNU General Public License as published by
4.13 + * the Free Software Foundation; either version 2 of the License, or
4.14 + * (at your option) any later version.
4.15 + *
4.16 + * This program is distributed in the hope that it will be useful,
4.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.19 + * GNU General Public License for more details.
4.20 + */
4.21 +#include <stdio.h>
4.22 +#include "testdata.h"
4.23 +#include "pvr.h"
4.24 +#include "lib.h"
4.25 +#include "asic.h"
4.26 +
4.27 +#define OBJ_START 0x00010000
4.28 +#define OBJ_LENGTH 0x00010000
4.29 +#define TILE_START 0x00060000
4.30 +#define TILE_LENGTH 0x00010000
4.31 +#define TILEMAP_ADDR 0x050B2C8
4.32 +#define RENDER_ADDR 0x00600000
4.33 +
4.34 +struct ta_config default_ta_config = { 0x00111111, GRID_SIZE(640,480), OBJ_START,
4.35 + OBJ_START+OBJ_LENGTH, TILE_START+TILE_LENGTH,
4.36 + TILE_START, TILE_START+TILE_LENGTH };
4.37 +
4.38 +struct render_config default_render_config = { TILEMAP_ADDR, RENDER_ADDR, 640, 480,
4.39 + 0x00000009, 0.2, 1.0 };
4.40 +
4.41 +int test_render( test_data_t test_case )
4.42 +{
4.43 + int i;
4.44 +
4.45 + /* Check input */
4.46 + test_data_block_t input = get_test_data(test_case, "input");
4.47 + test_data_block_t event = get_test_data(test_case, "event");
4.48 + test_data_block_t backplane = get_test_data(test_case, "backplane");
4.49 + if( input == NULL ) {
4.50 + fprintf( stderr, "Skipping test '%s' - no input\n", test_case->test_name );
4.51 + return -1;
4.52 + }
4.53 + if( event == NULL ) {
4.54 + fprintf( stderr, "Skipping test '%s' - no event list\n", test_case->test_name );
4.55 + }
4.56 +
4.57 + test_data_block_t config_data = get_test_data( test_case, "config" );
4.58 + struct ta_config *config = &default_ta_config;
4.59 + if( config_data != NULL ) {
4.60 + if( config_data->length != sizeof(struct ta_config) ) {
4.61 + fprintf( stderr, "Invalid config data length %d - aborting test %s\n",
4.62 + config_data->length, test_case->test_name );
4.63 + return -1;
4.64 + }
4.65 + config = (struct ta_config *)config_data->data;
4.66 + }
4.67 +
4.68 + /* Send TA data */
4.69 + asic_clear();
4.70 + pvr_init();
4.71 + ta_init(config);
4.72 + default_render_config.polybuf = config->obj_start & 0x00F00000;
4.73 + if( pvr_dma_write( 0x10000000, input->data, input->length, 0 ) == -1 ) {
4.74 + return -1;
4.75 + }
4.76 +
4.77 + /* Wait for events */
4.78 + for( i=0; i<event->length; i++ ) {
4.79 + if( asic_wait( event->data[i] ) == -1 ) {
4.80 + fprintf( stderr, "Test %s: failed (Timeout waiting for event %d)\n",
4.81 + test_case->test_name, event->data[i] );
4.82 + asic_dump( stderr );
4.83 + return -1;
4.84 + }
4.85 + }
4.86 +
4.87 + /* Write backplane (if any) */
4.88 + if( backplane != NULL ) {
4.89 + uint32_t bgplane = pvr_get_objbuf_posn();
4.90 + memcpy( (char *)(PVR_VRAM_BASE + bgplane), backplane->data, backplane->length );
4.91 + bgplane -= default_render_config.polybuf;
4.92 + render_set_backplane( (bgplane << 1) | 0x01000000 );
4.93 + } else {
4.94 + render_set_backplane( 0 );
4.95 + }
4.96 + /* Setup the tilemap */
4.97 + pvr_build_tilemap1( TILEMAP_ADDR, config, 0x20000000 );
4.98 + render_start( &default_render_config );
4.99 + if( asic_wait( EVENT_PVR_RENDER_DONE ) == -1 ) {
4.100 + fprintf( stderr, "Test %s: failed (timeout waiting for render)\n",
4.101 + test_case->test_name );
4.102 + asic_dump( stderr );
4.103 + return -1;
4.104 + }
4.105 + asic_wait( EVENT_RETRACE );
4.106 + display_render( &default_render_config );
4.107 + return 0;
4.108 +
4.109 +}
4.110 +
4.111 +int main( int argc, char *argv[] )
4.112 +{
4.113 + int test_cases = 0;
4.114 + int test_failures = 0;
4.115 + test_data_t test_data = load_test_dataset(stdin);
4.116 + test_data_t test_case = test_data;
4.117 +
4.118 + asic_mask_all();
4.119 + pvr_init();
4.120 +
4.121 + while( test_case != NULL ) {
4.122 + test_cases++;
4.123 + int result = test_render(test_case);
4.124 + if( result != 0 ) {
4.125 + test_failures++;
4.126 + }
4.127 + test_case = test_case->next;
4.128 + }
4.129 + free_test_dataset(test_data);
4.130 + if( test_failures != 0 ) {
4.131 + fprintf( stderr, "%d/%d test failures!\n", test_failures, test_cases );
4.132 + return 1;
4.133 + } else {
4.134 + fprintf( stderr, "%d tests OK\n", test_cases );
4.135 + return 0;
4.136 + }
4.137 +}
.