Search
lxdream.org :: lxdream :: r161:408b9210395f
lxdream 0.9.1
released Jun 29
Download Now
changeset161:408b9210395f
parent160:17c4c0e4f9ce
child162:f7781f928f7e
authornkeynes
dateSun Jun 18 11:57:05 2006 +0000 (14 years ago)
Implement render buffer invalidation
src/pvr2/pvr2.c
src/pvr2/pvr2.h
src/pvr2/render.c
1.1 --- a/src/pvr2/pvr2.c Sun Jun 18 11:55:25 2006 +0000
1.2 +++ b/src/pvr2/pvr2.c Sun Jun 18 11:57:05 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: pvr2.c,v 1.26 2006-06-15 10:33:08 nkeynes Exp $
1.6 + * $Id: pvr2.c,v 1.27 2006-06-18 11:57:05 nkeynes Exp $
1.7 *
1.8 * PVR2 (Video) Core module implementation and MMIO registers.
1.9 *
1.10 @@ -36,6 +36,8 @@
1.11
1.12 void pvr2_display_frame( void );
1.13
1.14 +int colour_format_bytes[] = { 2, 2, 2, 1, 3, 4, 1, 1 };
1.15 +
1.16 struct dreamcast_module pvr2_module = { "PVR2", pvr2_init, pvr2_reset, NULL,
1.17 pvr2_run_slice, NULL,
1.18 pvr2_save_state, pvr2_load_state };
1.19 @@ -155,50 +157,51 @@
1.20 int vid_ppl = ((dispsize & DISPSIZE_PPL)) + 1;
1.21 gboolean bEnabled = (dispmode & DISPMODE_DE) && (vidcfg & DISPCFG_VO ) ? TRUE : FALSE;
1.22 gboolean interlaced = (vidcfg & DISPCFG_I ? TRUE : FALSE);
1.23 - if( bEnabled ) {
1.24 - video_buffer_t buffer = &video_buffer[video_buffer_idx];
1.25 - video_buffer_idx = !video_buffer_idx;
1.26 - video_buffer_t last = &video_buffer[video_buffer_idx];
1.27 - buffer->rowstride = (vid_ppl + vid_stride) << 2;
1.28 - buffer->data = video_base + MMIO_READ( PVR2, DISPADDR1 );
1.29 - buffer->vres = vid_lpf;
1.30 - if( interlaced ) buffer->vres <<= 1;
1.31 - switch( (dispmode & DISPMODE_COL) >> 2 ) {
1.32 - case 0:
1.33 - buffer->colour_format = COLFMT_ARGB1555;
1.34 - buffer->hres = vid_ppl << 1;
1.35 - break;
1.36 - case 1:
1.37 - buffer->colour_format = COLFMT_RGB565;
1.38 - buffer->hres = vid_ppl << 1;
1.39 - break;
1.40 - case 2:
1.41 - buffer->colour_format = COLFMT_RGB888;
1.42 - buffer->hres = (vid_ppl << 2) / 3;
1.43 - break;
1.44 - case 3:
1.45 - buffer->colour_format = COLFMT_ARGB8888;
1.46 - buffer->hres = vid_ppl;
1.47 - break;
1.48 + video_buffer_t buffer = &video_buffer[video_buffer_idx];
1.49 + video_buffer_idx = !video_buffer_idx;
1.50 + video_buffer_t last = &video_buffer[video_buffer_idx];
1.51 + buffer->rowstride = (vid_ppl + vid_stride) << 2;
1.52 + buffer->data = video_base + MMIO_READ( PVR2, DISPADDR1 );
1.53 + buffer->vres = vid_lpf;
1.54 + if( interlaced ) buffer->vres <<= 1;
1.55 + switch( (dispmode & DISPMODE_COL) >> 2 ) {
1.56 + case 0:
1.57 + buffer->colour_format = COLFMT_ARGB1555;
1.58 + buffer->hres = vid_ppl << 1;
1.59 + break;
1.60 + case 1:
1.61 + buffer->colour_format = COLFMT_RGB565;
1.62 + buffer->hres = vid_ppl << 1;
1.63 + break;
1.64 + case 2:
1.65 + buffer->colour_format = COLFMT_RGB888;
1.66 + buffer->hres = (vid_ppl << 2) / 3;
1.67 + break;
1.68 + case 3:
1.69 + buffer->colour_format = COLFMT_ARGB8888;
1.70 + buffer->hres = vid_ppl;
1.71 + break;
1.72 + }
1.73 +
1.74 + if( buffer->hres <=8 )
1.75 + buffer->hres = 640;
1.76 + if( buffer->vres <=8 )
1.77 + buffer->vres = 480;
1.78 + if( display_driver != NULL ) {
1.79 + if( buffer->hres != last->hres ||
1.80 + buffer->vres != last->vres ||
1.81 + buffer->colour_format != last->colour_format) {
1.82 + display_driver->set_display_format( buffer->hres, buffer->vres,
1.83 + buffer->colour_format );
1.84 }
1.85 -
1.86 - if( display_driver != NULL ) {
1.87 - if( buffer->hres != last->hres ||
1.88 - buffer->vres != last->vres ||
1.89 - buffer->colour_format != last->colour_format) {
1.90 - display_driver->set_display_format( buffer->hres, buffer->vres,
1.91 - buffer->colour_format );
1.92 - }
1.93 - if( MMIO_READ( PVR2, DISPCFG2 ) & 0x08 ) { /* Blanked */
1.94 - uint32_t colour = MMIO_READ( PVR2, DISPBORDER );
1.95 - display_driver->display_blank_frame( colour );
1.96 - } else if( !pvr2_render_display_frame( PVR2_RAM_BASE + display_addr ) ) {
1.97 - display_driver->display_frame( buffer );
1.98 - }
1.99 + if( !bEnabled ) {
1.100 + display_driver->display_blank_frame( 0 );
1.101 + } else if( MMIO_READ( PVR2, DISPCFG2 ) & 0x08 ) { /* Blanked */
1.102 + uint32_t colour = MMIO_READ( PVR2, DISPBORDER );
1.103 + display_driver->display_blank_frame( colour );
1.104 + } else if( !pvr2_render_display_frame( PVR2_RAM_BASE + display_addr ) ) {
1.105 + display_driver->display_frame( buffer );
1.106 }
1.107 - } else {
1.108 - video_buffer_idx = 0;
1.109 - video_buffer[0].hres = video_buffer[0].vres = 0;
1.110 }
1.111 pvr2_state.frame_count++;
1.112 }
2.1 --- a/src/pvr2/pvr2.h Sun Jun 18 11:55:25 2006 +0000
2.2 +++ b/src/pvr2/pvr2.h Sun Jun 18 11:57:05 2006 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: pvr2.h,v 1.13 2006-05-15 08:28:52 nkeynes Exp $
2.6 + * $Id: pvr2.h,v 1.14 2006-06-18 11:57:05 nkeynes Exp $
2.7 *
2.8 * PVR2 (video chip) functions and macros.
2.9 *
2.10 @@ -139,6 +139,11 @@
2.11 gboolean pvr2_render_init( void );
2.12
2.13 /**
2.14 + * Invalidate any caching on the supplied SH4 address
2.15 + */
2.16 +gboolean pvr2_render_invalidate( sh4addr_t addr );
2.17 +
2.18 +/**
2.19 * Render the current scene stored in PVR ram to the GL back buffer.
2.20 */
2.21 void pvr2_render_scene( void );
3.1 --- a/src/pvr2/render.c Sun Jun 18 11:55:25 2006 +0000
3.2 +++ b/src/pvr2/render.c Sun Jun 18 11:57:05 2006 +0000
3.3 @@ -1,5 +1,5 @@
3.4 /**
3.5 - * $Id: render.c,v 1.8 2006-05-15 08:28:52 nkeynes Exp $
3.6 + * $Id: render.c,v 1.9 2006-06-18 11:57:05 nkeynes Exp $
3.7 *
3.8 * PVR2 Renderer support. This is where the real work happens.
3.9 *
3.10 @@ -60,7 +60,8 @@
3.11 * to fetch the bits back to vram.
3.12 */
3.13 typedef struct pvr2_render_buffer {
3.14 - uint32_t render_addr; /* The actual address rendered to in pvr ram */
3.15 + sh4addr_t render_addr; /* The actual address rendered to in pvr ram */
3.16 + uint32_t size; /* Length of rendering region in bytes */
3.17 int width, height;
3.18 int colour_format;
3.19 } *pvr2_render_buffer_t;
3.20 @@ -176,6 +177,31 @@
3.21 }
3.22
3.23 /**
3.24 + * Invalidate any caching on the supplied address. Specifically, if it falls
3.25 + * within either the front buffer or back buffer, flush the buffer back to
3.26 + * PVR2 ram (note that front buffer flush may be corrupt under some
3.27 + * circumstances).
3.28 + */
3.29 +gboolean pvr2_render_invalidate( sh4addr_t address )
3.30 +{
3.31 + address = address & 0x1FFFFFFF;
3.32 + if( front_buffer.render_addr != -1 &&
3.33 + front_buffer.render_addr <= address &&
3.34 + (front_buffer.render_addr + front_buffer.size) > address ) {
3.35 + pvr2_render_copy_to_sh4( &front_buffer, FALSE );
3.36 + front_buffer.render_addr = -1;
3.37 + return TRUE;
3.38 + } else if( back_buffer.render_addr != -1 &&
3.39 + back_buffer.render_addr <= address &&
3.40 + (back_buffer.render_addr + back_buffer.size) > address ) {
3.41 + pvr2_render_copy_to_sh4( &back_buffer, TRUE );
3.42 + back_buffer.render_addr = -1;
3.43 + return TRUE;
3.44 + }
3.45 + return FALSE;
3.46 +}
3.47 +
3.48 +/**
3.49 * Display a rendered frame if one is available.
3.50 * @param address An address in PVR ram (0500000 range).
3.51 * @return TRUE if a frame was available to be displayed, otherwise false.
3.52 @@ -235,6 +261,7 @@
3.53 back_buffer.width = width;
3.54 back_buffer.height = height;
3.55 back_buffer.colour_format = colour_format;
3.56 + back_buffer.size = width * height * colour_format_bytes[colour_format];
3.57
3.58 /* Setup the display model */
3.59 glDrawBuffer(GL_BACK);
3.60 @@ -243,7 +270,7 @@
3.61 glViewport( 0, 0, width, height );
3.62 glMatrixMode(GL_PROJECTION);
3.63 glLoadIdentity();
3.64 - glOrtho( 0, width, height, 0, bgplanez, -1 );
3.65 + glOrtho( 0, width, height, 0, bgplanez, -10 );
3.66 glMatrixMode(GL_MODELVIEW);
3.67 glLoadIdentity();
3.68 glCullFace( GL_BACK );
.