From 5294ac62236bf05e1eaaca3399e539c28c0ccc4c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christian=20K=C3=B6nig?= Date: Sat, 16 Apr 2011 13:40:19 +0200 Subject: [PATCH] [g3dvl] move mc fb and viewport handling into buffer object --- src/gallium/auxiliary/vl/vl_mpeg12_decoder.c | 9 +-- .../auxiliary/vl/vl_mpeg12_mc_renderer.c | 74 ++++++++++++------- .../auxiliary/vl/vl_mpeg12_mc_renderer.h | 16 ++-- 3 files changed, 58 insertions(+), 41 deletions(-) diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c index 9e89730a23d..64127cf2d69 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c +++ b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c @@ -480,16 +480,13 @@ vl_mpeg12_decoder_flush_buffer(struct pipe_video_decode_buffer *buffer, dec->pipe->set_vertex_buffers(dec->pipe, 2, buf->vertex_bufs.all); for (i = 0; i < VL_MAX_PLANES; ++i) { - bool first = true; - - vl_mc_set_surface(i == 0 ? &dec->mc_y : &dec->mc_c, surfaces[i]); + vl_mc_set_surface(&buf->mc[i], surfaces[i]); for (j = 0; j < 2; ++j) { if (sv[j] == NULL) continue; dec->pipe->bind_vertex_elements_state(dec->pipe, dec->ves_mv[j]); - vl_mc_render_ref(&buf->mc[i], sv[j][i], first, ne_start, ne_num, e_start, e_num); - first = false; + vl_mc_render_ref(&buf->mc[i], sv[j][i], ne_start, ne_num, e_start, e_num); } dec->pipe->bind_blend_state(dec->pipe, dec->blend); @@ -498,7 +495,7 @@ vl_mpeg12_decoder_flush_buffer(struct pipe_video_decode_buffer *buffer, if (dec->base.entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT) vl_idct_flush(i == 0 ? &dec->idct_y : &dec->idct_c, &buf->idct[i], ne_num); - vl_mc_render_ycbcr(&buf->mc[i], first, ne_start, ne_num); + vl_mc_render_ycbcr(&buf->mc[i], ne_start, ne_num); } dec->pipe->flush(dec->pipe, fence); diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c index 65909a57b26..8102aed838e 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c +++ b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c @@ -366,16 +366,6 @@ init_pipe_state(struct vl_mpeg12_mc_renderer *r) assert(r); - r->viewport.scale[2] = 1; - r->viewport.scale[3] = 1; - r->viewport.translate[0] = 0; - r->viewport.translate[1] = 0; - r->viewport.translate[2] = 0; - r->viewport.translate[3] = 0; - - r->fb_state.nr_cbufs = 1; - r->fb_state.zsbuf = NULL; - memset(&sampler, 0, sizeof(sampler)); sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; @@ -563,6 +553,16 @@ vl_mc_init_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_mc_bu buffer->renderer = renderer; + buffer->viewport.scale[2] = 1; + buffer->viewport.scale[3] = 1; + buffer->viewport.translate[0] = 0; + buffer->viewport.translate[1] = 0; + buffer->viewport.translate[2] = 0; + buffer->viewport.translate[3] = 0; + + buffer->fb_state.nr_cbufs = 1; + buffer->fb_state.zsbuf = NULL; + pipe_sampler_view_reference(&buffer->source, source); return true; @@ -577,21 +577,43 @@ vl_mc_cleanup_buffer(struct vl_mpeg12_mc_buffer *buffer) } void -vl_mc_set_surface(struct vl_mpeg12_mc_renderer *renderer, struct pipe_surface *surface) +vl_mc_set_surface(struct vl_mpeg12_mc_buffer *buffer, struct pipe_surface *surface) +{ + assert(buffer && surface); + + buffer->surface_cleared = false; + + buffer->viewport.scale[0] = surface->width; + buffer->viewport.scale[1] = surface->height; + + buffer->fb_state.width = surface->width; + buffer->fb_state.height = surface->height; + buffer->fb_state.cbufs[0] = surface; +} + +static void +prepare_pipe_4_rendering(struct vl_mpeg12_mc_buffer *buffer) { - assert(renderer && surface); + struct vl_mpeg12_mc_renderer *renderer; + + assert(buffer); - renderer->viewport.scale[0] = surface->width; - renderer->viewport.scale[1] = surface->height; + renderer = buffer->renderer; + renderer->pipe->bind_rasterizer_state(renderer->pipe, renderer->rs_state); - renderer->fb_state.width = surface->width; - renderer->fb_state.height = surface->height; - renderer->fb_state.cbufs[0] = surface; + if (buffer->surface_cleared) + renderer->pipe->bind_blend_state(renderer->pipe, renderer->blend_add); + else { + renderer->pipe->bind_blend_state(renderer->pipe, renderer->blend_clear); + buffer->surface_cleared = true; + } + + renderer->pipe->set_framebuffer_state(renderer->pipe, &buffer->fb_state); + renderer->pipe->set_viewport_state(renderer->pipe, &buffer->viewport); } void -vl_mc_render_ref(struct vl_mpeg12_mc_buffer *buffer, - struct pipe_sampler_view *ref, bool first, +vl_mc_render_ref(struct vl_mpeg12_mc_buffer *buffer, struct pipe_sampler_view *ref, unsigned not_empty_start_instance, unsigned not_empty_num_instances, unsigned empty_start_instance, unsigned empty_num_instances) { @@ -602,11 +624,9 @@ vl_mc_render_ref(struct vl_mpeg12_mc_buffer *buffer, if (not_empty_num_instances == 0 && empty_num_instances == 0) return; + prepare_pipe_4_rendering(buffer); + renderer = buffer->renderer; - renderer->pipe->bind_rasterizer_state(renderer->pipe, renderer->rs_state); - renderer->pipe->set_framebuffer_state(renderer->pipe, &renderer->fb_state); - renderer->pipe->set_viewport_state(renderer->pipe, &renderer->viewport); - renderer->pipe->bind_blend_state(renderer->pipe, first ? renderer->blend_clear : renderer->blend_add); renderer->pipe->bind_vs_state(renderer->pipe, renderer->vs_ref); renderer->pipe->bind_fs_state(renderer->pipe, renderer->fs_ref); @@ -624,7 +644,7 @@ vl_mc_render_ref(struct vl_mpeg12_mc_buffer *buffer, } void -vl_mc_render_ycbcr(struct vl_mpeg12_mc_buffer *buffer, bool first, +vl_mc_render_ycbcr(struct vl_mpeg12_mc_buffer *buffer, unsigned not_empty_start_instance, unsigned not_empty_num_instances) { struct vl_mpeg12_mc_renderer *renderer; @@ -634,11 +654,9 @@ vl_mc_render_ycbcr(struct vl_mpeg12_mc_buffer *buffer, bool first, if (not_empty_num_instances == 0) return; + prepare_pipe_4_rendering(buffer); + renderer = buffer->renderer; - renderer->pipe->bind_rasterizer_state(renderer->pipe, renderer->rs_state); - renderer->pipe->set_framebuffer_state(renderer->pipe, &renderer->fb_state); - renderer->pipe->set_viewport_state(renderer->pipe, &renderer->viewport); - renderer->pipe->bind_blend_state(renderer->pipe, first ? renderer->blend_clear : renderer->blend_add); renderer->pipe->bind_vs_state(renderer->pipe, renderer->vs_ycbcr); renderer->pipe->bind_fs_state(renderer->pipe, renderer->fs_ycbcr); diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h index d6561369e28..f67f97a71fc 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h +++ b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h @@ -41,9 +41,6 @@ struct vl_mpeg12_mc_renderer unsigned buffer_width; unsigned buffer_height; - struct pipe_viewport_state viewport; - struct pipe_framebuffer_state fb_state; - void *rs_state; void *blend_clear, *blend_add; @@ -57,6 +54,12 @@ struct vl_mpeg12_mc_renderer struct vl_mpeg12_mc_buffer { struct vl_mpeg12_mc_renderer *renderer; + + bool surface_cleared; + + struct pipe_viewport_state viewport; + struct pipe_framebuffer_state fb_state; + struct pipe_sampler_view *source; }; @@ -70,14 +73,13 @@ bool vl_mc_init_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_ void vl_mc_cleanup_buffer(struct vl_mpeg12_mc_buffer *buffer); -void vl_mc_set_surface(struct vl_mpeg12_mc_renderer *renderer, struct pipe_surface *surface); +void vl_mc_set_surface(struct vl_mpeg12_mc_buffer *buffer, struct pipe_surface *surface); -void vl_mc_render_ref(struct vl_mpeg12_mc_buffer *buffer, - struct pipe_sampler_view *ref, bool first, +void vl_mc_render_ref(struct vl_mpeg12_mc_buffer *buffer, struct pipe_sampler_view *ref, unsigned not_empty_start_instance, unsigned not_empty_num_instances, unsigned empty_start_instance, unsigned empty_num_instances); -void vl_mc_render_ycbcr(struct vl_mpeg12_mc_buffer *buffer, bool first, +void vl_mc_render_ycbcr(struct vl_mpeg12_mc_buffer *buffer, unsigned not_empty_start_instance, unsigned not_empty_num_instances); #endif /* vl_mpeg12_mc_renderer_h */ -- 2.30.2