g3dvl: extend the functionality of the compositor
[mesa.git] / src / gallium / auxiliary / vl / vl_vertex_buffers.c
index 212ace7512a70fab07f181f0f55502c90d7cd445..e2665a5cfdede84af1faa7019c6fb895651c508e 100644 (file)
  **************************************************************************/
 
 #include <assert.h>
-#include <util/u_format.h>
+#include "util/u_format.h"
 #include "vl_vertex_buffers.h"
 #include "vl_types.h"
 
-struct vl_ycbcr_vertex_stream
-{
-   uint8_t x;
-   uint8_t y;
-   uint8_t intra;
-   uint8_t field;
-};
-
-struct vl_mv_vertex_stream
-{
-   struct vertex4s mv[2];
-};
-
 /* vertices for a quad covering a block */
 static const struct vertex2f block_quad[4] = {
    {0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}
@@ -181,9 +168,12 @@ vl_vb_get_ves_ycbcr(struct pipe_context *pipe)
    /* Position element */
    vertex_elems[VS_I_VPOS].src_format = PIPE_FORMAT_R8G8B8A8_USCALED;
 
-   vl_vb_element_helper(&vertex_elems[VS_I_VPOS], 1, 1);
+   /* block num element */
+   vertex_elems[VS_I_BLOCK_NUM].src_format = PIPE_FORMAT_R32_FLOAT;
+
+   vl_vb_element_helper(&vertex_elems[VS_I_VPOS], 2, 1);
 
-   return pipe->create_vertex_elements_state(pipe, 2, vertex_elems);
+   return pipe->create_vertex_elements_state(pipe, 3, vertex_elems);
 }
 
 void *
@@ -212,7 +202,7 @@ vl_vb_get_ves_mv(struct pipe_context *pipe)
    return pipe->create_vertex_elements_state(pipe, NUM_VS_INPUTS, vertex_elems);
 }
 
-void
+bool
 vl_vb_init(struct vl_vertex_buffer *buffer, struct pipe_context *pipe,
            unsigned width, unsigned height)
 {
@@ -226,14 +216,15 @@ vl_vb_init(struct vl_vertex_buffer *buffer, struct pipe_context *pipe,
    size = width * height;
 
    for (i = 0; i < VL_MAX_PLANES; ++i) {
-      buffer->ycbcr[i].num_instances = 0;
       buffer->ycbcr[i].resource = pipe_buffer_create
       (
          pipe->screen,
          PIPE_BIND_VERTEX_BUFFER,
          PIPE_USAGE_STREAM,
-         sizeof(struct vl_ycbcr_vertex_stream) * size * 4
+         sizeof(struct vl_ycbcr_block) * size * 4
       );
+      if (!buffer->ycbcr[i].resource)
+         goto error_ycbcr;
    }
 
    for (i = 0; i < VL_MAX_REF_FRAMES; ++i) {
@@ -242,11 +233,29 @@ vl_vb_init(struct vl_vertex_buffer *buffer, struct pipe_context *pipe,
          pipe->screen,
          PIPE_BIND_VERTEX_BUFFER,
          PIPE_USAGE_STREAM,
-         sizeof(struct vl_mv_vertex_stream) * size
+         sizeof(struct vl_motionvector) * size
       );
+      if (!buffer->mv[i].resource)
+         goto error_mv;
    }
 
    vl_vb_map(buffer, pipe);
+   return true;
+
+error_mv:
+   for (i = 0; i < VL_MAX_PLANES; ++i)
+      pipe_resource_reference(&buffer->mv[i].resource, NULL);
+
+error_ycbcr:
+   for (i = 0; i < VL_MAX_PLANES; ++i)
+      pipe_resource_reference(&buffer->ycbcr[i].resource, NULL);
+   return false;
+}
+
+unsigned
+vl_vb_attributes_per_plock(struct vl_vertex_buffer *buffer)
+{
+   return 1;
 }
 
 struct pipe_vertex_buffer
@@ -256,7 +265,7 @@ vl_vb_get_ycbcr(struct vl_vertex_buffer *buffer, int component)
 
    assert(buffer);
 
-   buf.stride = sizeof(struct vl_ycbcr_vertex_stream);
+   buf.stride = sizeof(struct vl_ycbcr_block);
    buf.buffer_offset = 0;
    buf.buffer = buffer->ycbcr[component].resource;
 
@@ -270,7 +279,7 @@ vl_vb_get_mv(struct vl_vertex_buffer *buffer, int motionvector)
 
    assert(buffer);
 
-   buf.stride = sizeof(struct vl_mv_vertex_stream);
+   buf.stride = sizeof(struct vl_motionvector);
    buf.buffer_offset = 0;
    buf.buffer = buffer->mv[motionvector].resource;
 
@@ -306,57 +315,30 @@ vl_vb_map(struct vl_vertex_buffer *buffer, struct pipe_context *pipe)
 
 }
 
-void vl_vb_add_ycbcr(struct vl_vertex_buffer *buffer,
-                     unsigned component, unsigned x, unsigned y,
-                     bool intra, enum pipe_mpeg12_dct_type type)
+struct vl_ycbcr_block *
+vl_vb_get_ycbcr_stream(struct vl_vertex_buffer *buffer, int component)
 {
-   struct vl_ycbcr_vertex_stream *stream;
-
    assert(buffer);
-   assert(buffer->ycbcr[component].num_instances < buffer->width * buffer->height * 4);
+   assert(component < VL_MAX_PLANES);
 
-   stream = buffer->ycbcr[component].vertex_stream++;
-   stream->x = x;
-   stream->y = y;
-   stream->intra = intra;
-   stream->field = type == PIPE_MPEG12_DCT_TYPE_FIELD;
-
-   buffer->ycbcr[component].num_instances++;
+   return buffer->ycbcr[component].vertex_stream;
 }
 
-static void
-get_motion_vectors(enum pipe_mpeg12_motion_type mo_type, struct pipe_motionvector *src, struct vertex4s dst[2])
+unsigned
+vl_vb_get_mv_stream_stride(struct vl_vertex_buffer *buffer)
 {
-   if (mo_type == PIPE_MPEG12_MOTION_TYPE_FRAME) {
-      dst[0].x = dst[1].x = src->top.x;
-      dst[0].y = dst[1].y = src->top.y;
-      dst[0].z = dst[1].z = 0;
-
-   } else {
-      dst[0].x = src->top.x;
-      dst[0].y = src->top.y;
-      dst[0].z = src->top.field_select ? 3 : 1;
-
-      dst[1].x = src->bottom.x;
-      dst[1].y = src->bottom.y;
-      dst[1].z = src->bottom.field_select ? 3 : 1;
-   }
+   assert(buffer);
 
-   dst[0].w = src->top.wheight;
-   dst[1].w = src->bottom.wheight;
+   return buffer->width;
 }
 
-void
-vl_vb_add_block(struct vl_vertex_buffer *buffer, struct pipe_mpeg12_macroblock *mb)
+struct vl_motionvector *
+vl_vb_get_mv_stream(struct vl_vertex_buffer *buffer, int ref_frame)
 {
-   unsigned mv_pos;
-
    assert(buffer);
-   assert(mb);
+   assert(ref_frame < VL_MAX_REF_FRAMES);
 
-   mv_pos = mb->mbx + mb->mby * buffer->width;
-   get_motion_vectors(mb->mo_type, &mb->mv[0], buffer->mv[0].vertex_stream[mv_pos].mv);
-   get_motion_vectors(mb->mo_type, &mb->mv[1], buffer->mv[1].vertex_stream[mv_pos].mv);
+   return buffer->mv[ref_frame].vertex_stream;
 }
 
 void
@@ -375,18 +357,6 @@ vl_vb_unmap(struct vl_vertex_buffer *buffer, struct pipe_context *pipe)
    }
 }
 
-unsigned
-vl_vb_restart(struct vl_vertex_buffer *buffer, int component)
-{
-   unsigned num_instances;
-
-   assert(buffer);
-
-   num_instances = buffer->ycbcr[component].num_instances;
-   buffer->ycbcr[component].num_instances = 0;
-   return num_instances;
-}
-
 void
 vl_vb_cleanup(struct vl_vertex_buffer *buffer)
 {