#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 } },
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);
}
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;
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);
}
struct pipe_resource res_template, *resource;
struct pipe_surface surf_template;
+ struct pipe_sampler_view sv_template;
assert(ctx);
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);
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,
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);
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;
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;
}
{
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);
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)
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);