Module: Mesa Branch: pipe-video Commit: da3c6dd099786d20906b5a16288887b80cd8ad29 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=da3c6dd099786d20906b5a16288887b80cd8ad29
Author: Christian König <deathsim...@vodafone.de> Date: Thu Mar 24 21:24:58 2011 +0100 [g3dvl] move sampler views for reference frames into context --- src/gallium/auxiliary/vl/vl_mpeg12_context.c | 21 ++++- src/gallium/auxiliary/vl/vl_mpeg12_context.h | 1 + src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c | 88 +++++++--------------- src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h | 4 +- 4 files changed, 46 insertions(+), 68 deletions(-) diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_context.c b/src/gallium/auxiliary/vl/vl_mpeg12_context.c index 4c0188c..39429df 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_context.c +++ b/src/gallium/auxiliary/vl/vl_mpeg12_context.c @@ -37,6 +37,7 @@ #include <util/u_rect.h> #include <util/u_video.h> #include <util/u_surface.h> +#include <util/u_sampler.h> static const unsigned const_empty_block_mask_420[3][2][2] = { { { 0x20, 0x10 }, { 0x08, 0x04 } }, @@ -94,6 +95,7 @@ vl_mpeg12_buffer_destroy(struct pipe_video_buffer *buffer) vl_idct_cleanup_buffer(&ctx->idct_cr, &buf->idct_cr); vl_mpeg12_mc_cleanup_buffer(&buf->mc); pipe_surface_reference(&buf->surface, NULL); + pipe_sampler_view_reference(&buf->sampler_view, NULL); FREE(buf); } @@ -164,7 +166,7 @@ vl_mpeg12_buffer_flush(struct pipe_video_buffer *buffer, struct vl_mpeg12_buffer *past = (struct vl_mpeg12_buffer *)refs[0]; struct vl_mpeg12_buffer *future = (struct vl_mpeg12_buffer *)refs[1]; - struct pipe_surface *surf_refs[2]; + struct pipe_sampler_view *sv_refs[2]; unsigned ne_start, ne_num, e_start, e_num; struct vl_mpeg12_context *ctx; @@ -181,11 +183,11 @@ vl_mpeg12_buffer_flush(struct pipe_video_buffer *buffer, vl_idct_flush(&ctx->idct_cr, &buf->idct_cr, ne_num); vl_idct_flush(&ctx->idct_cb, &buf->idct_cb, ne_num); - surf_refs[0] = past ? past->surface : NULL; - surf_refs[1] = future ? future->surface : NULL; + sv_refs[0] = past ? past->sampler_view : NULL; + sv_refs[1] = future ? future->sampler_view : NULL; vl_mpeg12_mc_renderer_flush(&ctx->mc_renderer, &buf->mc, - buf->surface, surf_refs, + buf->surface, sv_refs, ne_start, ne_num, e_start, e_num, fence); } @@ -258,6 +260,7 @@ vl_mpeg12_create_buffer(struct pipe_video_context *vpipe) struct pipe_resource res_template, *resource; struct pipe_surface surf_template; + struct pipe_sampler_view sv_template; assert(ctx); @@ -293,12 +296,20 @@ vl_mpeg12_create_buffer(struct pipe_video_context *vpipe) surf_template.format = resource->format; surf_template.usage = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; buffer->surface = ctx->pipe->create_surface(ctx->pipe, resource, &surf_template); - pipe_resource_reference(&resource, NULL); if (!buffer->surface) { FREE(buffer); return NULL; } + u_sampler_view_default_template(&sv_template, resource, resource->format); + buffer->sampler_view = ctx->pipe->create_sampler_view(ctx->pipe, resource, &sv_template); + if (!buffer->sampler_view) { + FREE(buffer); + return NULL; + } + + pipe_resource_reference(&resource, NULL); + buffer->vertex_bufs.individual.quad.stride = ctx->quads.stride; buffer->vertex_bufs.individual.quad.buffer_offset = ctx->quads.buffer_offset; pipe_resource_reference(&buffer->vertex_bufs.individual.quad.buffer, ctx->quads.buffer); diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_context.h b/src/gallium/auxiliary/vl/vl_mpeg12_context.h index 7269fa9..e4236ad 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_context.h +++ b/src/gallium/auxiliary/vl/vl_mpeg12_context.h @@ -63,6 +63,7 @@ struct vl_mpeg12_buffer { struct pipe_video_buffer base; struct pipe_surface *surface; + struct pipe_sampler_view *sampler_view; struct vl_vertex_buffer vertex_stream; diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c index 2f2c787..218ff5d 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c +++ b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c @@ -444,48 +444,6 @@ cleanup_pipe_state(struct vl_mpeg12_mc_renderer *r) r->pipe->delete_rasterizer_state(r->pipe, r->rs_state); } -static struct pipe_sampler_view -*find_or_create_sampler_view(struct vl_mpeg12_mc_renderer *r, struct pipe_surface *surface) -{ - struct pipe_sampler_view *sampler_view; - assert(r); - assert(surface); - - sampler_view = (struct pipe_sampler_view*)util_keymap_lookup(r->texview_map, &surface); - if (!sampler_view) { - struct pipe_sampler_view templat; - boolean added_to_map; - - u_sampler_view_default_template(&templat, surface->texture, - surface->texture->format); - sampler_view = r->pipe->create_sampler_view(r->pipe, surface->texture, - &templat); - if (!sampler_view) - return NULL; - - added_to_map = util_keymap_insert(r->texview_map, &surface, - sampler_view, r->pipe); - assert(added_to_map); - } - - return sampler_view; -} - -static void -texview_map_delete(const struct keymap *map, - const void *key, void *data, - void *user) -{ - struct pipe_sampler_view *sv = (struct pipe_sampler_view*)data; - - assert(map); - assert(key); - assert(data); - assert(user); - - pipe_sampler_view_reference(&sv, NULL); -} - bool vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer, struct pipe_context *pipe, @@ -493,6 +451,9 @@ vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer, unsigned buffer_height, enum pipe_video_chroma_format chroma_format) { + struct pipe_resource tex_templ, *tex_dummy; + struct pipe_sampler_view sampler_view; + assert(renderer); assert(pipe); @@ -503,11 +464,6 @@ vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer, renderer->buffer_height = buffer_height; renderer->chroma_format = chroma_format; - renderer->texview_map = util_new_keymap(sizeof(struct pipe_surface*), -1, - texview_map_delete); - if (!renderer->texview_map) - return false; - if (!init_pipe_state(renderer)) goto error_pipe_state; @@ -517,13 +473,30 @@ vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer, if (renderer->vs == NULL || renderer->fs == NULL) goto error_shaders; + /* create a dummy sampler */ + memset(&tex_templ, 0, sizeof(tex_templ)); + tex_templ.bind = PIPE_BIND_SAMPLER_VIEW; + tex_templ.flags = 0; + + tex_templ.target = PIPE_TEXTURE_2D; + tex_templ.format = PIPE_FORMAT_R8_SNORM; + tex_templ.width0 = 1; + tex_templ.height0 = 1; + tex_templ.depth0 = 1; + tex_templ.array_size = 1; + tex_templ.last_level = 0; + tex_templ.usage = PIPE_USAGE_STATIC; + tex_dummy = pipe->screen->resource_create(pipe->screen, &tex_templ); + + u_sampler_view_default_template(&sampler_view, tex_dummy, tex_dummy->format); + renderer->dummy = pipe->create_sampler_view(pipe, tex_dummy, &sampler_view); + return true; error_shaders: cleanup_pipe_state(renderer); error_pipe_state: - util_delete_keymap(renderer->texview_map, renderer->pipe); return false; } @@ -532,7 +505,8 @@ vl_mpeg12_mc_renderer_cleanup(struct vl_mpeg12_mc_renderer *renderer) { assert(renderer); - util_delete_keymap(renderer->texview_map, renderer->pipe); + pipe_sampler_view_reference(&renderer->dummy, NULL); + cleanup_pipe_state(renderer); renderer->pipe->delete_vs_state(renderer->pipe, renderer->vs); @@ -583,7 +557,7 @@ vl_mpeg12_mc_cleanup_buffer(struct vl_mpeg12_mc_buffer *buffer) void vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_mc_buffer *buffer, - struct pipe_surface *surface, struct pipe_surface *ref[2], + struct pipe_surface *surface, struct pipe_sampler_view *ref[2], unsigned not_empty_start_instance, unsigned not_empty_num_instances, unsigned empty_start_instance, unsigned empty_num_instances, struct pipe_fence_handle **fence) @@ -598,17 +572,9 @@ vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mp renderer->pipe->set_framebuffer_state(renderer->pipe, &renderer->fb_state); renderer->pipe->set_viewport_state(renderer->pipe, &renderer->viewport); - if (ref[0]) { - buffer->sampler_views.individual.ref[0] = find_or_create_sampler_view(renderer, ref[0]); - } else { - buffer->sampler_views.individual.ref[0] = find_or_create_sampler_view(renderer, surface); - } - - if (ref[1]) { - buffer->sampler_views.individual.ref[1] = find_or_create_sampler_view(renderer, ref[1]); - } else { - buffer->sampler_views.individual.ref[1] = find_or_create_sampler_view(renderer, surface); - } + /* if no reference frame provided use a dummy sampler instead */ + buffer->sampler_views.individual.ref[0] = ref[0] ? ref[0] : renderer->dummy; + buffer->sampler_views.individual.ref[1] = ref[1] ? ref[1] : renderer->dummy; renderer->pipe->set_fragment_sampler_views(renderer->pipe, 5, buffer->sampler_views.all); renderer->pipe->bind_fragment_sampler_states(renderer->pipe, 5, renderer->samplers.all); diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h index fa81c77..29a548e 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h +++ b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h @@ -57,7 +57,7 @@ struct vl_mpeg12_mc_renderer struct { void *y, *cb, *cr, *ref[2]; } individual; } samplers; - struct keymap *texview_map; + struct pipe_sampler_view *dummy; }; struct vl_mpeg12_mc_buffer @@ -89,7 +89,7 @@ bool vl_mpeg12_mc_init_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_ void vl_mpeg12_mc_cleanup_buffer(struct vl_mpeg12_mc_buffer *buffer); void vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_mc_buffer *buffer, - struct pipe_surface *surface, struct pipe_surface *ref[2], + struct pipe_surface *surface, struct pipe_sampler_view *ref[2], unsigned not_empty_start_instance, unsigned not_empty_num_instances, unsigned empty_start_instance, unsigned empty_num_instances, struct pipe_fence_handle **fence); _______________________________________________ mesa-commit mailing list mesa-commit@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-commit