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