Search
lxdream.org :: lxdream :: r827:d333f4248727
lxdream 0.9.1
released Jun 29
Download Now
changeset827:d333f4248727
parent826:69f2c9f1e608
child828:b42865f00fb5
authornkeynes
dateSun Aug 24 02:57:15 2008 +0000 (15 years ago)
Adjust the hclip when the horizontal scaler is active
src/pvr2/pvr2.h
src/pvr2/pvr2mem.c
src/pvr2/scene.c
1.1 --- a/src/pvr2/pvr2.h Sun Aug 24 02:43:28 2008 +0000
1.2 +++ b/src/pvr2/pvr2.h Sun Aug 24 02:57:15 2008 +0000
1.3 @@ -58,6 +58,8 @@
1.4 #define BS_PALM 0x00000080 /* ? */
1.5 #define BS_PALN 0x000000C0 /* ? */
1.6
1.7 +#define SCALER_HSCALE 0x00010000
1.8 +
1.9 #define PVR2_RAM_BASE 0x05000000
1.10 #define PVR2_RAM_BASE_INT 0x04000000
1.11 #define PVR2_RAM_SIZE (8 * 1024 * 1024)
1.12 @@ -129,7 +131,7 @@
1.13 /****************************** Frame Buffer *****************************/
1.14
1.15 /**
1.16 - * Write a block of data to an address in the DMA range (0x10000000 -
1.17 + * Write a block of data to an address in the DMA range (0x10000000 -
1.18 * 0x13FFFFFF), ie TA, YUV, or texture ram.
1.19 */
1.20 void pvr2_dma_write( sh4addr_t dest, unsigned char *src, uint32_t length );
1.21 @@ -153,7 +155,7 @@
1.22
1.23 /**
1.24 * Read a twiddled image from interleaved memory address space (aka 64-bit address
1.25 - * space), writing the image to the destination buffer in detwiddled format.
1.26 + * space), writing the image to the destination buffer in detwiddled format.
1.27 * Width and height must be powers of 2
1.28 * This version reads 4-bit pixels.
1.29 */
1.30 @@ -162,7 +164,7 @@
1.31
1.32 /**
1.33 * Read a twiddled image from interleaved memory address space (aka 64-bit address
1.34 - * space), writing the image to the destination buffer in detwiddled format.
1.35 + * space), writing the image to the destination buffer in detwiddled format.
1.36 * Width and height must be powers of 2
1.37 * This version reads 8-bit pixels.
1.38 */
1.39 @@ -170,21 +172,21 @@
1.40
1.41 /**
1.42 * Read a twiddled image from interleaved memory address space (aka 64-bit address
1.43 - * space), writing the image to the destination buffer in detwiddled format.
1.44 + * space), writing the image to the destination buffer in detwiddled format.
1.45 * Width and height must be powers of 2, and src must be 16-bit aligned.
1.46 * This version reads 16-bit pixels.
1.47 */
1.48 void pvr2_vram64_read_twiddled_16( unsigned char *dest, sh4addr_t src, uint32_t width, uint32_t height );
1.49
1.50 /**
1.51 - * Read an image from the interleaved memory address space (aka 64-bit address space)
1.52 + * Read an image from the interleaved memory address space (aka 64-bit address space)
1.53 * where the source and destination line sizes may differ. Note that both byte
1.54 * counts must be a multiple of 4, and the src address must be 32-bit aligned.
1.55 */
1.56 void pvr2_vram64_read_stride( unsigned char *dest, uint32_t dest_line_bytes, sh4addr_t srcaddr,
1.57 uint32_t src_line_bytes, uint32_t line_count );
1.58 /**
1.59 - * Dump a portion of vram to a stream from the interleaved memory address
1.60 + * Dump a portion of vram to a stream from the interleaved memory address
1.61 * space.
1.62 */
1.63 void pvr2_vram64_dump( sh4addr_t addr, uint32_t length, FILE *f );
1.64 @@ -195,7 +197,7 @@
1.65 *
1.66 * @param buffer A render buffer indicating the address to store to, and the
1.67 * format the data needs to be in.
1.68 - * @param backBuffer TRUE to flush the back buffer, FALSE for
1.69 + * @param backBuffer TRUE to flush the back buffer, FALSE for
1.70 * the front buffer.
1.71 */
1.72 void pvr2_render_buffer_copy_to_sh4( render_buffer_t buffer );
1.73 @@ -216,7 +218,7 @@
1.74 /**
1.75 * Find the first polygon or sprite context in the supplied buffer of TA
1.76 * data.
1.77 - * @return A pointer to the context, or NULL if it cannot be found
1.78 + * @return A pointer to the context, or NULL if it cannot be found
1.79 */
1.80 uint32_t *pvr2_ta_find_polygon_context( uint32_t *buf, uint32_t length );
1.81
1.82 @@ -298,7 +300,7 @@
1.83 * Flush all textures and delete. The cache will be non-functional until
1.84 * the next call to texcache_init(). This would typically be done if
1.85 * switching GL targets.
1.86 - */
1.87 + */
1.88 void texcache_shutdown( void );
1.89
1.90 /**
1.91 @@ -322,7 +324,7 @@
1.92 * multiple interpretations). We use the texture address as the primary
1.93 * index, but allow for multiple instances at each address. The texture
1.94 * will be bound to the GL_TEXTURE_2D target before being returned.
1.95 - *
1.96 + *
1.97 * If the texture has already been bound, return the ID to which it was
1.98 * bound. Otherwise obtain an unused texture ID and set it up appropriately.
1.99 */
2.1 --- a/src/pvr2/pvr2mem.c Sun Aug 24 02:43:28 2008 +0000
2.2 +++ b/src/pvr2/pvr2mem.c Sun Aug 24 02:57:15 2008 +0000
2.3 @@ -56,7 +56,7 @@
2.4 unsigned char *dest = mem_get_region(destaddr);
2.5 memcpy( dest, src, count );
2.6 }
2.7 - }
2.8 + }
2.9 }
2.10
2.11 void pvr2_vram64_write( sh4addr_t destaddr, unsigned char *src, uint32_t length )
2.12 @@ -77,7 +77,7 @@
2.13
2.14 banks[0] = ((uint32_t *)(video_base + ((destaddr & 0x007FFFF8) >>1)));
2.15 banks[1] = banks[0] + 0x100000;
2.16 - if( bank_flag )
2.17 + if( bank_flag )
2.18 banks[0]++;
2.19
2.20 /* Handle non-aligned start of source */
2.21 @@ -103,7 +103,7 @@
2.22 while( length-- > 0 ) {
2.23 *dest++ = *src++;
2.24 }
2.25 - }
2.26 + }
2.27 }
2.28
2.29 /**
2.30 @@ -111,7 +111,7 @@
2.31 * The destaddr must be 32-bit aligned, and both line_bytes and line_stride_bytes
2.32 * must be multiples of 4.
2.33 */
2.34 -void pvr2_vram64_write_stride( sh4addr_t destaddr, unsigned char *src, uint32_t line_bytes,
2.35 +void pvr2_vram64_write_stride( sh4addr_t destaddr, unsigned char *src, uint32_t line_bytes,
2.36 uint32_t line_stride_bytes, uint32_t line_count )
2.37 {
2.38 int bank_flag = (destaddr & 0x04) >> 2;
2.39 @@ -133,7 +133,7 @@
2.40
2.41 banks[0] = (uint32_t *)(video_base + (destaddr >>1));
2.42 banks[1] = banks[0] + 0x100000;
2.43 - if( bank_flag )
2.44 + if( bank_flag )
2.45 banks[0]++;
2.46
2.47 dwsrc = (uint32_t *)src;
2.48 @@ -148,7 +148,7 @@
2.49 banks[bank_flag]++;
2.50 bank_flag = !bank_flag;
2.51 }
2.52 - }
2.53 + }
2.54 }
2.55
2.56 /**
2.57 @@ -200,7 +200,7 @@
2.58 banks[bank_flag]++;
2.59 bank_flag = !bank_flag;
2.60 }
2.61 - }
2.62 + }
2.63 }
2.64
2.65
2.66 @@ -296,7 +296,7 @@
2.67 }
2.68
2.69 /**
2.70 - * Read an image from 64-bit vram stored as twiddled 4-bit pixels. The
2.71 + * Read an image from 64-bit vram stored as twiddled 4-bit pixels. The
2.72 * image is written out to the destination in detwiddled form.
2.73 * @param dest destination buffer, which must be at least width*height/2 in length
2.74 * @param srcaddr source address in vram
2.75 @@ -335,11 +335,11 @@
2.76 *wdest = *banks[0];
2.77 } else {
2.78 pvr2_vram64_detwiddle_4( wdest, banks, offset_flag, 0, 0, width, stride );
2.79 - }
2.80 + }
2.81 }
2.82
2.83 /**
2.84 - * Read an image from 64-bit vram stored as twiddled 8-bit pixels. The
2.85 + * Read an image from 64-bit vram stored as twiddled 8-bit pixels. The
2.86 * image is written out to the destination in detwiddled form.
2.87 * @param dest destination buffer, which must be at least width*height in length
2.88 * @param srcaddr source address in vram
2.89 @@ -377,11 +377,11 @@
2.90 *wdest = *banks[0];
2.91 } else {
2.92 pvr2_vram64_detwiddle_8( wdest, banks, offset_flag, 0, 0, width, width );
2.93 - }
2.94 + }
2.95 }
2.96
2.97 /**
2.98 - * Read an image from 64-bit vram stored as twiddled 16-bit pixels. The
2.99 + * Read an image from 64-bit vram stored as twiddled 16-bit pixels. The
2.100 * image is written out to the destination in detwiddled form.
2.101 * @param dest destination buffer, which must be at least width*height*2 in length
2.102 * @param srcaddr source address in vram (must be 16-bit aligned)
2.103 @@ -419,7 +419,7 @@
2.104 *wdest = *banks[0];
2.105 } else {
2.106 pvr2_vram64_detwiddle_16( wdest, banks, offset_flag, 0, 0, width, width );
2.107 - }
2.108 + }
2.109 }
2.110
2.111 void pvr2_vram_write_invert( sh4addr_t destaddr, unsigned char *src, uint32_t length, uint32_t line_length,
2.112 @@ -500,7 +500,7 @@
2.113 fclose(f);
2.114 }
2.115
2.116 -void pvr2_vram64_dump( sh4addr_t addr, uint32_t length, FILE *f )
2.117 +void pvr2_vram64_dump( sh4addr_t addr, uint32_t length, FILE *f )
2.118 {
2.119 unsigned char tmp[length];
2.120 pvr2_vram64_read( tmp, addr, length );
2.121 @@ -513,9 +513,11 @@
2.122 * Flush the indicated render buffer back to PVR. Caller is responsible for
2.123 * tracking whether there is actually anything in the buffer.
2.124 *
2.125 + * FIXME: Handle horizontal scaler
2.126 + *
2.127 * @param buffer A render buffer indicating the address to store to, and the
2.128 * format the data needs to be in.
2.129 - * @param backBuffer TRUE to flush the back buffer, FALSE for
2.130 + * @param backBuffer TRUE to flush the back buffer, FALSE for
2.131 * the front buffer.
2.132 */
2.133 void pvr2_render_buffer_copy_to_sh4( render_buffer_t buffer )
3.1 --- a/src/pvr2/scene.c Sun Aug 24 02:43:28 2008 +0000
3.2 +++ b/src/pvr2/scene.c Sun Aug 24 02:57:15 2008 +0000
3.3 @@ -1,7 +1,7 @@
3.4 /**
3.5 * $Id$
3.6 *
3.7 - * Manage the internal vertex/polygon buffers and scene data structure.
3.8 + * Manage the internal vertex/polygon buffers and scene data structure.
3.9 * Where possible this uses VBOs for the vertex + index data.
3.10 *
3.11 * Copyright (c) 2005 Nathan Keynes.
3.12 @@ -166,7 +166,7 @@
3.13 }
3.14
3.15 static struct polygon_struct *scene_add_polygon( pvraddr_t poly_idx, int vertex_count,
3.16 - gboolean is_modified )
3.17 + gboolean is_modified )
3.18 {
3.19 int vert_mul = is_modified ? 2 : 1;
3.20
3.21 @@ -199,8 +199,8 @@
3.22 * @param modify_offset Offset in 32-bit words to the tex/color data. 0 for
3.23 * the normal vertex, half the vertex length for the modified vertex.
3.24 */
3.25 -static void pvr2_decode_render_vertex( struct vertex_struct *vert, uint32_t poly1,
3.26 - uint32_t poly2, uint32_t *pvr2_data,
3.27 +static void pvr2_decode_render_vertex( struct vertex_struct *vert, uint32_t poly1,
3.28 + uint32_t poly2, uint32_t *pvr2_data,
3.29 int modify_offset )
3.30 {
3.31 gboolean force_alpha = !POLY2_ALPHA_ENABLE(poly2);
3.32 @@ -250,7 +250,7 @@
3.33 vert->offset_rgba[0] = 0.0;
3.34 vert->offset_rgba[1] = 0.0;
3.35 vert->offset_rgba[2] = 0.0;
3.36 - vert->offset_rgba[3] = 0.0;
3.37 + vert->offset_rgba[3] = 0.0;
3.38 }
3.39
3.40 if( force_alpha ) {
3.41 @@ -263,7 +263,7 @@
3.42 * Compute texture, colour, and z values for 1 or more result points by interpolating from
3.43 * a set of 3 input points. The result point(s) must define their x,y.
3.44 */
3.45 -static void scene_compute_vertexes( struct vertex_struct *result,
3.46 +static void scene_compute_vertexes( struct vertex_struct *result,
3.47 int result_count,
3.48 struct vertex_struct *input,
3.49 gboolean is_solid_shaded )
3.50 @@ -276,7 +276,7 @@
3.51
3.52 float detxy = ((sy) * (tx)) - ((ty) * (sx));
3.53 if( detxy == 0 ) {
3.54 - // If the input points fall on a line, they don't define a usable
3.55 + // If the input points fall on a line, they don't define a usable
3.56 // polygon - the PVR2 takes the last input point as the result in
3.57 // this case.
3.58 for( i=0; i<result_count; i++ ) {
3.59 @@ -305,7 +305,7 @@
3.60 if( rz > pvr2_scene.bounds[5] ) {
3.61 pvr2_scene.bounds[5] = rz;
3.62 } else if( rz < pvr2_scene.bounds[4] ) {
3.63 - pvr2_scene.bounds[4] = rz;
3.64 + pvr2_scene.bounds[4] = rz;
3.65 }
3.66 result[i].z = rz;
3.67 result[i].u = input[1].u + (t*tu) + (s*su);
3.68 @@ -360,7 +360,7 @@
3.69 }
3.70 }
3.71
3.72 -static void scene_add_quad_vertexes( pvraddr_t poly_idx, int vertex_length,
3.73 +static void scene_add_quad_vertexes( pvraddr_t poly_idx, int vertex_length,
3.74 gboolean is_modified )
3.75 {
3.76 struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[poly_idx];
3.77 @@ -369,7 +369,7 @@
3.78 unsigned int i;
3.79
3.80 if( poly->vertex_index == -1 ) {
3.81 - // Construct it locally and copy to the vertex buffer, as the VBO is
3.82 + // Construct it locally and copy to the vertex buffer, as the VBO is
3.83 // allowed to be horribly slow for reads (ie it could be direct-mapped
3.84 // vram).
3.85 struct vertex_struct quad[4];
3.86 @@ -524,7 +524,7 @@
3.87 }
3.88 }
3.89 }
3.90 - } while( 1 );
3.91 + } while( 1 );
3.92 }
3.93
3.94 static void scene_extract_background( void )
3.95 @@ -543,7 +543,7 @@
3.96 context_length = 5;
3.97 vertex_length <<= 1;
3.98 poly->mod_vertex_index = pvr2_scene.vertex_count + 4;
3.99 - pvr2_scene.vertex_count += 8;
3.100 + pvr2_scene.vertex_count += 8;
3.101 } else {
3.102 poly->mod_vertex_index = -1;
3.103 pvr2_scene.vertex_count += 4;
3.104 @@ -555,7 +555,7 @@
3.105 pvr2_scene.bkgnd_poly = poly;
3.106
3.107 struct vertex_struct base_vertexes[3];
3.108 - uint32_t *ptr = context + context_length;
3.109 + uint32_t *ptr = context + context_length;
3.110 for( i=0; i<3; i++ ) {
3.111 pvr2_decode_render_vertex( &base_vertexes[i], context[0], context[1],
3.112 ptr, 0 );
3.113 @@ -599,10 +599,10 @@
3.114
3.115 /**
3.116 * Extract the current scene into the rendering structures. We run two passes
3.117 - * - first pass extracts the polygons into pvr2_scene.poly_array (finding vertex counts),
3.118 + * - first pass extracts the polygons into pvr2_scene.poly_array (finding vertex counts),
3.119 * second pass extracts the vertex data into the VBO/vertex array.
3.120 *
3.121 - * Difficult to do in single pass as we don't generally know the size of a
3.122 + * Difficult to do in single pass as we don't generally know the size of a
3.123 * polygon for certain until we've seen all tiles containing it. It also means we
3.124 * can count the vertexes and allocate the appropriate size VBO.
3.125 *
3.126 @@ -619,6 +619,15 @@
3.127 pvr2_scene.bounds[3] = ((MMIO_READ( PVR2, RENDER_VCLIP ) >> 16) & 0x03FF) + 1;
3.128 pvr2_scene.bounds[4] = pvr2_scene.bounds[5] = MMIO_READF( PVR2, RENDER_FARCLIP );
3.129
3.130 + uint32_t scaler = MMIO_READ( PVR2, RENDER_SCALER );
3.131 + if( scaler & SCALER_HSCALE ) {
3.132 + /* If the horizontal scaler is in use, we're (in principle) supposed to
3.133 + * divide everything by 2. However in the interests of display quality,
3.134 + * instead we want to render to the unscaled resolution and downsample
3.135 + * only if/when required.
3.136 + */
3.137 + pvr2_scene.bounds[1] *= 2;
3.138 + }
3.139 uint32_t *tilebuffer = (uint32_t *)(video_base + MMIO_READ( PVR2, RENDER_TILEBASE ));
3.140 uint32_t *segment = tilebuffer;
3.141 pvr2_scene.segment_list = (struct tile_segment *)tilebuffer;
3.142 @@ -640,7 +649,7 @@
3.143 pvr2_scene.sort_mode = SORT_TILEFLAG;
3.144 }
3.145
3.146 - // Pass 1: Extract polygon list
3.147 + // Pass 1: Extract polygon list
3.148 uint32_t control;
3.149 int i;
3.150 do {
3.151 @@ -649,7 +658,7 @@
3.152 int tile_y = SEGMENT_Y(control);
3.153 if( tile_x > max_tile_x ) {
3.154 max_tile_x = tile_x;
3.155 - }
3.156 + }
3.157 if( tile_y > max_tile_y ) {
3.158 max_tile_y = tile_y;
3.159 }
3.160 @@ -709,7 +718,7 @@
3.161 for( j=0; j<poly->vertex_count; j++ ) {
3.162 struct vertex_struct *v = &pvr2_scene.vertex_array[poly->vertex_index+j];
3.163 fprintf( f, " %.5f %.5f %.5f, (%.5f,%.5f) %.5f,%.5f,%.5f,%.5f %.5f %.5f %.5f %.5f\n", v->x, v->y, v->z, v->u, v->v,
3.164 - v->rgba[0], v->rgba[1], v->rgba[2], v->rgba[3],
3.165 + v->rgba[0], v->rgba[1], v->rgba[2], v->rgba[3],
3.166 v->offset_rgba[0], v->offset_rgba[1], v->offset_rgba[2], v->offset_rgba[3] );
3.167 }
3.168 if( poly->mod_vertex_index != -1 ) {
3.169 @@ -717,7 +726,7 @@
3.170 for( j=0; j<poly->vertex_count; j++ ) {
3.171 struct vertex_struct *v = &pvr2_scene.vertex_array[poly->mod_vertex_index+j];
3.172 fprintf( f, " %.5f %.5f %.5f, (%.5f,%.5f) %.5f,%.5f,%.5f,%.5f %.5f %.5f %.5f %.5f\n", v->x, v->y, v->z, v->u, v->v,
3.173 - v->rgba[0], v->rgba[1], v->rgba[2], v->rgba[3],
3.174 + v->rgba[0], v->rgba[1], v->rgba[2], v->rgba[3],
3.175 v->offset_rgba[0], v->offset_rgba[1], v->offset_rgba[2], v->offset_rgba[3] );
3.176 }
3.177 }
.