Let's start with NV12, but anything else shouldn't be much of a problem any more.
c->used_layers |= 1 << layer;
c->layers[layer].fs = c->fs_video_buffer;
- sampler_views = buffer->get_sampler_views(buffer);
+ sampler_views = buffer->get_sampler_view_components(buffer);
for (i = 0; i < 3; ++i)
pipe_sampler_view_reference(&c->layers[layer].sampler_views[i], sampler_views[i]);
#include "vl_compositor.h"
#include "vl_mpeg12_decoder.h"
+const enum pipe_format const_resource_formats_YV12[3] = {
+ PIPE_FORMAT_R8_UNORM,
+ PIPE_FORMAT_R8_UNORM,
+ PIPE_FORMAT_R8_UNORM
+};
+
+const enum pipe_format const_resource_formats_NV12[3] = {
+ PIPE_FORMAT_R8_UNORM,
+ PIPE_FORMAT_R8G8_UNORM,
+ PIPE_FORMAT_NONE
+};
+
static void
vl_context_destroy(struct pipe_video_context *context)
{
enum pipe_video_chroma_format chroma_format,
unsigned width, unsigned height)
{
- const enum pipe_format resource_formats[3] = {
- PIPE_FORMAT_R8_UNORM,
- PIPE_FORMAT_R8_UNORM,
- PIPE_FORMAT_R8_UNORM
- };
-
struct vl_context *ctx = (struct vl_context*)context;
struct pipe_video_buffer *result;
unsigned buffer_width, buffer_height;
+ const enum pipe_format *resource_formats;
+
assert(context);
assert(width > 0 && height > 0);
- assert(buffer_format == PIPE_FORMAT_YV12);
+
+ switch(buffer_format) {
+ case PIPE_FORMAT_YV12:
+ resource_formats = const_resource_formats_YV12;
+ break;
+
+ case PIPE_FORMAT_NV12:
+ resource_formats = const_resource_formats_NV12;
+ break;
+
+ default:
+ assert(0);
+ return NULL;
+ }
buffer_width = ctx->pot_buffers ? util_next_power_of_two(width) : width;
buffer_height = ctx->pot_buffers ? util_next_power_of_two(height) : height;
struct pipe_sampler_state sampler;
struct pipe_blend_state blend;
struct pipe_rasterizer_state rs_state;
+ unsigned i;
assert(r);
if (!r->sampler_ycbcr)
goto error_sampler_ycbcr;
- memset(&blend, 0, sizeof blend);
- blend.independent_blend_enable = 0;
- blend.rt[0].blend_enable = 1;
- blend.rt[0].rgb_func = PIPE_BLEND_ADD;
- blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_SRC_ALPHA;
- blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
- blend.rt[0].alpha_func = PIPE_BLEND_ADD;
- blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_SRC_ALPHA;
- blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
- blend.logicop_enable = 0;
- blend.logicop_func = PIPE_LOGICOP_CLEAR;
- blend.rt[0].colormask = PIPE_MASK_RGBA;
- blend.dither = 0;
- r->blend_clear = r->pipe->create_blend_state(r->pipe, &blend);
- if (!r->blend_clear)
- goto error_blend_clear;
-
- blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ONE;
- blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
- r->blend_add = r->pipe->create_blend_state(r->pipe, &blend);
- if (!r->blend_add)
- goto error_blend_add;
+ for (i = 0; i < VL_MC_NUM_BLENDERS; ++i) {
+ memset(&blend, 0, sizeof blend);
+ blend.independent_blend_enable = 0;
+ blend.rt[0].blend_enable = 1;
+ blend.rt[0].rgb_func = PIPE_BLEND_ADD;
+ blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_SRC_ALPHA;
+ blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
+ blend.rt[0].alpha_func = PIPE_BLEND_ADD;
+ blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_SRC_ALPHA;
+ blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
+ blend.logicop_enable = 0;
+ blend.logicop_func = PIPE_LOGICOP_CLEAR;
+ blend.rt[0].colormask = i;
+ blend.dither = 0;
+ r->blend_clear[i] = r->pipe->create_blend_state(r->pipe, &blend);
+ if (!r->blend_clear[i])
+ goto error_blend;
+
+ blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ONE;
+ blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
+ r->blend_add[i] = r->pipe->create_blend_state(r->pipe, &blend);
+ if (!r->blend_add[i])
+ goto error_blend;
+ }
memset(&rs_state, 0, sizeof(rs_state));
/*rs_state.sprite_coord_enable */
return true;
error_rs_state:
- r->pipe->delete_blend_state(r->pipe, r->blend_add);
+error_blend:
+ for (i = 0; i < VL_MC_NUM_BLENDERS; ++i) {
+ if (r->blend_add[i])
+ r->pipe->delete_blend_state(r->pipe, r->blend_add[i]);
-error_blend_add:
- r->pipe->delete_blend_state(r->pipe, r->blend_clear);
+ if (r->blend_clear[i])
+ r->pipe->delete_blend_state(r->pipe, r->blend_clear[i]);
+ }
-error_blend_clear:
r->pipe->delete_sampler_state(r->pipe, r->sampler_ref);
error_sampler_ref:
static void
cleanup_pipe_state(struct vl_mc *r)
{
+ unsigned i;
+
assert(r);
r->pipe->delete_sampler_state(r->pipe, r->sampler_ref);
r->pipe->delete_sampler_state(r->pipe, r->sampler_ycbcr);
- r->pipe->delete_blend_state(r->pipe, r->blend_clear);
- r->pipe->delete_blend_state(r->pipe, r->blend_add);
+ for (i = 0; i < VL_MC_NUM_BLENDERS; ++i) {
+ r->pipe->delete_blend_state(r->pipe, r->blend_clear[i]);
+ r->pipe->delete_blend_state(r->pipe, r->blend_add[i]);
+ }
r->pipe->delete_rasterizer_state(r->pipe, r->rs_state);
}
}
bool
-vl_mc_init_buffer(struct vl_mc *renderer, struct vl_mc_buffer *buffer,
- struct pipe_sampler_view *source)
+vl_mc_init_buffer(struct vl_mc *renderer, struct vl_mc_buffer *buffer)
{
assert(renderer && buffer);
- assert(source);
buffer->renderer = renderer;
buffer->fb_state.nr_cbufs = 1;
buffer->fb_state.zsbuf = NULL;
- pipe_sampler_view_reference(&buffer->source, source);
-
return true;
}
vl_mc_cleanup_buffer(struct vl_mc_buffer *buffer)
{
assert(buffer);
-
- pipe_sampler_view_reference(&buffer->source, NULL);
}
void
}
static void
-prepare_pipe_4_rendering(struct vl_mc_buffer *buffer)
+prepare_pipe_4_rendering(struct vl_mc_buffer *buffer, unsigned mask)
{
struct vl_mc *renderer;
renderer->pipe->bind_rasterizer_state(renderer->pipe, renderer->rs_state);
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->bind_blend_state(renderer->pipe, renderer->blend_add[mask]);
+ else
+ renderer->pipe->bind_blend_state(renderer->pipe, renderer->blend_clear[mask]);
renderer->pipe->set_framebuffer_state(renderer->pipe, &buffer->fb_state);
renderer->pipe->set_viewport_state(renderer->pipe, &buffer->viewport);
assert(buffer && ref);
- prepare_pipe_4_rendering(buffer);
+ prepare_pipe_4_rendering(buffer, PIPE_MASK_R | PIPE_MASK_G | PIPE_MASK_B);
renderer = buffer->renderer;
util_draw_arrays_instanced(renderer->pipe, PIPE_PRIM_QUADS, 0, 4, 0,
renderer->buffer_width / MACROBLOCK_WIDTH *
renderer->buffer_height / MACROBLOCK_HEIGHT);
+
+ buffer->surface_cleared = true;
}
void
-vl_mc_render_ycbcr(struct vl_mc_buffer *buffer, unsigned num_instances)
+vl_mc_render_ycbcr(struct vl_mc_buffer *buffer, struct pipe_sampler_view *source,
+ unsigned component, unsigned num_instances)
{
struct vl_mc *renderer;
if (num_instances == 0)
return;
- prepare_pipe_4_rendering(buffer);
+ prepare_pipe_4_rendering(buffer, 1 << component);
renderer = buffer->renderer;
renderer->pipe->bind_vs_state(renderer->pipe, renderer->vs_ycbcr);
renderer->pipe->bind_fs_state(renderer->pipe, renderer->fs_ycbcr);
- renderer->pipe->set_fragment_sampler_views(renderer->pipe, 1, &buffer->source);
+ renderer->pipe->set_fragment_sampler_views(renderer->pipe, 1, &source);
renderer->pipe->bind_fragment_sampler_states(renderer->pipe, 1, &renderer->sampler_ycbcr);
util_draw_arrays_instanced(renderer->pipe, PIPE_PRIM_QUADS, 0, 4, 0, num_instances);
#include <pipe/p_state.h>
#include <pipe/p_video_state.h>
+#include "vl_defines.h"
#include "vl_types.h"
+#define VL_MC_NUM_BLENDERS (1 << VL_MAX_PLANES)
+
struct pipe_context;
struct vl_mc
void *rs_state;
- void *blend_clear, *blend_add;
+ void *blend_clear[VL_MC_NUM_BLENDERS];
+ void *blend_add[VL_MC_NUM_BLENDERS];
void *vs_ref, *vs_ycbcr;
void *fs_ref, *fs_ycbcr;
void *sampler_ref, *sampler_ycbcr;
struct pipe_viewport_state viewport;
struct pipe_framebuffer_state fb_state;
-
- struct pipe_sampler_view *source;
};
bool vl_mc_init(struct vl_mc *renderer, struct pipe_context *pipe,
void vl_mc_cleanup(struct vl_mc *renderer);
-bool vl_mc_init_buffer(struct vl_mc *renderer, struct vl_mc_buffer *buffer,
- struct pipe_sampler_view *source);
+bool vl_mc_init_buffer(struct vl_mc *renderer, struct vl_mc_buffer *buffer);
void vl_mc_cleanup_buffer(struct vl_mc_buffer *buffer);
void vl_mc_render_ref(struct vl_mc_buffer *buffer, struct pipe_sampler_view *ref);
-void vl_mc_render_ycbcr(struct vl_mc_buffer *buffer, unsigned num_instances);
+void vl_mc_render_ycbcr(struct vl_mc_buffer *buffer, struct pipe_sampler_view *source,
+ unsigned component, unsigned num_instances);
#endif /* vl_mc_h */
if (!buffer->zscan_source)
goto error_source;
- source = buffer->zscan_source->get_sampler_views(buffer->zscan_source);
+ source = buffer->zscan_source->get_sampler_view_planes(buffer->zscan_source);
if (!source)
goto error_sampler;
if (!buffer->idct_intermediate)
goto error_intermediate;
- idct_source_sv = buffer->idct_source->get_sampler_views(buffer->idct_source);
+ idct_source_sv = buffer->idct_source->get_sampler_view_planes(buffer->idct_source);
if (!idct_source_sv)
goto error_source_sv;
- idct_intermediate_sv = buffer->idct_intermediate->get_sampler_views(buffer->idct_intermediate);
+ idct_intermediate_sv = buffer->idct_intermediate->get_sampler_view_planes(buffer->idct_intermediate);
if (!idct_intermediate_sv)
goto error_intermediate_sv;
{
struct vl_mpeg12_decoder *dec;
enum pipe_format formats[3];
- struct pipe_sampler_view **mc_source_sv;
assert(buf);
if (!buf->mc_source)
goto error_mc_source;
- mc_source_sv = buf->mc_source->get_sampler_views(buf->mc_source);
- if (!mc_source_sv)
- goto error_mc_source_sv;
-
- if(!vl_mc_init_buffer(&dec->mc_y, &buf->mc[0], mc_source_sv[0]))
+ if(!vl_mc_init_buffer(&dec->mc_y, &buf->mc[0]))
goto error_mc_y;
- if(!vl_mc_init_buffer(&dec->mc_c, &buf->mc[1], mc_source_sv[1]))
+ if(!vl_mc_init_buffer(&dec->mc_c, &buf->mc[1]))
goto error_mc_cb;
- if(!vl_mc_init_buffer(&dec->mc_c, &buf->mc[2], mc_source_sv[2]))
+ if(!vl_mc_init_buffer(&dec->mc_c, &buf->mc[2]))
goto error_mc_cr;
return true;
vl_mc_cleanup_buffer(&buf->mc[0]);
error_mc_y:
-error_mc_source_sv:
buf->mc_source->destroy(buf->mc_source);
error_mc_source:
vl_vb_map(&buf->vertex_stream, dec->pipe);
- sampler_views = buf->zscan_source->get_sampler_views(buf->zscan_source);
+ sampler_views = buf->zscan_source->get_sampler_view_planes(buf->zscan_source);
assert(sampler_views);
struct vl_mpeg12_buffer *buf = (struct vl_mpeg12_buffer *)buffer;
struct vl_mpeg12_decoder *dec;
- struct pipe_sampler_view **sv[2];
+ struct pipe_sampler_view **sv[VL_MAX_REF_FRAMES], **mc_source_sv;
struct pipe_surface **surfaces;
struct pipe_vertex_buffer vb[3];
- unsigned i, j;
+ unsigned i, j, component;
+ unsigned nr_components;
assert(buf);
assert(dec);
for (i = 0; i < 2; ++i)
- sv[i] = refs[i] ? refs[i]->get_sampler_views(refs[i]) : NULL;
-
- surfaces = dst->get_surfaces(dst);
+ sv[i] = refs[i] ? refs[i]->get_sampler_view_planes(refs[i]) : NULL;
vb[0] = dec->quads;
vb[1] = dec->pos;
+ surfaces = dst->get_surfaces(dst);
+
dec->pipe->bind_vertex_elements_state(dec->pipe, dec->ves_mv);
for (i = 0; i < VL_MAX_PLANES; ++i) {
+ if (!surfaces[i]) continue;
+
vl_mc_set_surface(&buf->mc[i], surfaces[i]);
- for (j = 0; j < 2; ++j) {
- if (sv[j] == NULL) continue;
+ for (j = 0; j < VL_MAX_REF_FRAMES; ++j) {
+ if (!sv[j]) continue;
vb[2] = vl_vb_get_mv(&buf->vertex_stream, j);;
dec->pipe->set_vertex_buffers(dec->pipe, 3, vb);
dec->pipe->bind_vertex_elements_state(dec->pipe, dec->ves_ycbcr);
for (i = 0; i < VL_MAX_PLANES; ++i) {
- if (num_ycbcr_blocks[i] == 0) continue;
+ if (!num_ycbcr_blocks[i]) continue;
vb[1] = vl_vb_get_ycbcr(&buf->vertex_stream, i);
dec->pipe->set_vertex_buffers(dec->pipe, 2, vb);
if (dec->base.entrypoint <= PIPE_VIDEO_ENTRYPOINT_IDCT)
vl_idct_flush(i == 0 ? &dec->idct_y : &dec->idct_c, &buf->idct[i], num_ycbcr_blocks[i]);
+ }
+
+ mc_source_sv = buf->mc_source->get_sampler_view_planes(buf->mc_source);
+ for (i = 0, component = 0; i < VL_MAX_PLANES; ++i) {
+ if (!surfaces[i]) continue;
- vl_mc_render_ycbcr(&buf->mc[i], num_ycbcr_blocks[i]);
+ nr_components = util_format_get_nr_components(surfaces[i]->texture->format);
+ for (j = 0; j < nr_components; ++j, ++component) {
+ if (!num_ycbcr_blocks[i]) continue;
+
+ vb[1] = vl_vb_get_ycbcr(&buf->vertex_stream, component);
+ dec->pipe->set_vertex_buffers(dec->pipe, 2, vb);
+ vl_mc_render_ycbcr(&buf->mc[i], mc_source_sv[component], j, num_ycbcr_blocks[component]);
+ }
}
dec->pipe->flush(dec->pipe, fence);
#include "vl_video_buffer.h"
-static inline void
-adjust_swizzle(struct pipe_sampler_view *sv_templ)
-{
- if (util_format_get_nr_components(sv_templ->format) == 1) {
- sv_templ->swizzle_r = PIPE_SWIZZLE_RED;
- sv_templ->swizzle_g = PIPE_SWIZZLE_RED;
- sv_templ->swizzle_b = PIPE_SWIZZLE_RED;
- sv_templ->swizzle_a = PIPE_SWIZZLE_RED;
- }
-}
-
static void
vl_video_buffer_destroy(struct pipe_video_buffer *buffer)
{
for (i = 0; i < VL_MAX_PLANES; ++i) {
pipe_surface_reference(&buf->surfaces[i], NULL);
- pipe_sampler_view_reference(&buf->sampler_views[i], NULL);
+ pipe_sampler_view_reference(&buf->sampler_view_planes[i], NULL);
+ pipe_sampler_view_reference(&buf->sampler_view_components[i], NULL);
pipe_resource_reference(&buf->resources[i], NULL);
}
}
static struct pipe_sampler_view **
-vl_video_buffer_sampler_views(struct pipe_video_buffer *buffer)
+vl_video_buffer_sampler_view_planes(struct pipe_video_buffer *buffer)
{
struct vl_video_buffer *buf = (struct vl_video_buffer *)buffer;
struct pipe_sampler_view sv_templ;
pipe = buf->pipe;
for (i = 0; i < buf->num_planes; ++i ) {
- if (!buf->sampler_views[i]) {
+ if (!buf->sampler_view_planes[i]) {
memset(&sv_templ, 0, sizeof(sv_templ));
u_sampler_view_default_template(&sv_templ, buf->resources[i], buf->resources[i]->format);
- adjust_swizzle(&sv_templ);
- buf->sampler_views[i] = pipe->create_sampler_view(pipe, buf->resources[i], &sv_templ);
- if (!buf->sampler_views[i])
+
+ if (util_format_get_nr_components(buf->resources[i]->format) == 1)
+ sv_templ.swizzle_r = sv_templ.swizzle_g = sv_templ.swizzle_b = sv_templ.swizzle_a = PIPE_SWIZZLE_RED;
+
+ buf->sampler_view_planes[i] = pipe->create_sampler_view(pipe, buf->resources[i], &sv_templ);
+ if (!buf->sampler_view_planes[i])
goto error;
}
}
- return buf->sampler_views;
+ return buf->sampler_view_planes;
error:
for (i = 0; i < buf->num_planes; ++i )
- pipe_sampler_view_reference(&buf->sampler_views[i], NULL);
+ pipe_sampler_view_reference(&buf->sampler_view_planes[i], NULL);
+
+ return NULL;
+}
+
+static struct pipe_sampler_view **
+vl_video_buffer_sampler_view_components(struct pipe_video_buffer *buffer)
+{
+ struct vl_video_buffer *buf = (struct vl_video_buffer *)buffer;
+ struct pipe_sampler_view sv_templ;
+ struct pipe_context *pipe;
+ unsigned i, j, component;
+
+ assert(buf);
+
+ pipe = buf->pipe;
+
+ for (component = 0, i = 0; i < buf->num_planes; ++i ) {
+ unsigned nr_components = util_format_get_nr_components(buf->resources[i]->format);
+
+ for (j = 0; j < nr_components; ++j, ++component) {
+ assert(component < VL_MAX_PLANES);
+
+ if (!buf->sampler_view_components[component]) {
+ memset(&sv_templ, 0, sizeof(sv_templ));
+ u_sampler_view_default_template(&sv_templ, buf->resources[i], buf->resources[i]->format);
+ sv_templ.swizzle_r = sv_templ.swizzle_g = sv_templ.swizzle_b = PIPE_SWIZZLE_RED + j;
+ sv_templ.swizzle_a = PIPE_SWIZZLE_ONE;
+ buf->sampler_view_components[component] = pipe->create_sampler_view(pipe, buf->resources[i], &sv_templ);
+ if (!buf->sampler_view_components[component])
+ goto error;
+ }
+ }
+ }
+
+ return buf->sampler_view_components;
+
+error:
+ for (i = 0; i < VL_MAX_PLANES; ++i )
+ pipe_sampler_view_reference(&buf->sampler_view_components[i], NULL);
return NULL;
}
buffer = CALLOC_STRUCT(vl_video_buffer);
buffer->base.destroy = vl_video_buffer_destroy;
- buffer->base.get_sampler_views = vl_video_buffer_sampler_views;
+ buffer->base.get_sampler_view_planes = vl_video_buffer_sampler_view_planes;
+ buffer->base.get_sampler_view_components = vl_video_buffer_sampler_view_components;
buffer->base.get_surfaces = vl_video_buffer_surfaces;
buffer->pipe = pipe;
buffer->num_planes = 1;
struct pipe_context *pipe;
unsigned num_planes;
struct pipe_resource *resources[VL_MAX_PLANES];
- struct pipe_sampler_view *sampler_views[VL_MAX_PLANES];
+ struct pipe_sampler_view *sampler_view_planes[VL_MAX_PLANES];
+ struct pipe_sampler_view *sampler_view_components[VL_MAX_PLANES];
struct pipe_surface *surfaces[VL_MAX_PLANES];
};
/**
* get a individual sampler view for each plane
*/
- struct pipe_sampler_view **(*get_sampler_views)(struct pipe_video_buffer *buffer);
+ struct pipe_sampler_view **(*get_sampler_view_planes)(struct pipe_video_buffer *buffer);
+
+ /**
+ * get a individual sampler view for each component
+ */
+ struct pipe_sampler_view **(*get_sampler_view_components)(struct pipe_video_buffer *buffer);
/**
* get a individual surfaces for each plane
return VDP_STATUS_NO_IMPLEMENTATION;
}
- sampler_views = p_surf->video_buffer->get_sampler_views(p_surf->video_buffer);
+ sampler_views = p_surf->video_buffer->get_sampler_view_planes(p_surf->video_buffer);
if (!sampler_views)
return VDP_STATUS_RESOURCES;
surface_priv->decode_buffer = context_priv->decoder->create_buffer(context_priv->decoder);
surface_priv->mv_stride = surface_priv->decode_buffer->get_mv_stream_stride(surface_priv->decode_buffer);
- surface_priv->video_buffer = vpipe->create_buffer(vpipe, PIPE_FORMAT_YV12, //TODO
+ surface_priv->video_buffer = vpipe->create_buffer(vpipe, PIPE_FORMAT_NV12,
context_priv->decoder->chroma_format,
context_priv->decoder->width,
context_priv->decoder->height);