buffer->vertex_bufs.individual.quad.buffer_offset = idct->quad.buffer_offset;
pipe_resource_reference(&buffer->vertex_bufs.individual.quad.buffer, idct->quad.buffer);
- buffer->vertex_bufs.individual.pos = vl_vb_create_buffer(idct->pipe, idct->max_blocks, idct->vertex_buffer_stride);
+ buffer->vertex_bufs.individual.pos = vl_vb_init(
+ &buffer->blocks, idct->pipe, idct->max_blocks, 2,
+ idct->vertex_buffer_stride);
if(buffer->vertex_bufs.individual.pos.buffer == NULL)
return false;
- if (!vl_vb_init(&buffer->blocks, idct->max_blocks, 2))
- return false;
-
return true;
}
);
buffer->texels = idct->pipe->transfer_map(idct->pipe, buffer->tex_transfer);
+
+ vl_vb_map(&buffer->blocks, idct->pipe);
}
void
idct->pipe->transfer_unmap(idct->pipe, buffer->tex_transfer);
idct->pipe->transfer_destroy(idct->pipe, buffer->tex_transfer);
+ vl_vb_unmap(&buffer->blocks, idct->pipe);
}
void
vl_idct_flush(struct vl_idct *idct, struct vl_idct_buffer *buffer)
{
- struct pipe_transfer *vec_transfer;
- void *vectors;
unsigned num_verts;
assert(idct);
- vectors = pipe_buffer_map
- (
- idct->pipe,
- buffer->vertex_bufs.individual.pos.buffer,
- PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
- &vec_transfer
- );
-
- num_verts = vl_vb_upload(&buffer->blocks, vectors);
-
- pipe_buffer_unmap(idct->pipe, buffer->vertex_bufs.individual.pos.buffer, vec_transfer);
+ num_verts = vl_vb_restart(&buffer->blocks);
if(num_verts > 0) {
VS_O_MV3
};
-static const unsigned const_mbtype_config[VL_NUM_MACROBLOCK_TYPES][2] = {
- [VL_MACROBLOCK_TYPE_INTRA] = { 0, 0 },
- [VL_MACROBLOCK_TYPE_FWD_FRAME_PRED] = { 1, 1 },
- [VL_MACROBLOCK_TYPE_FWD_FIELD_PRED] = { 1, 2 },
- [VL_MACROBLOCK_TYPE_BKWD_FRAME_PRED] = { 1, 1 },
- [VL_MACROBLOCK_TYPE_BKWD_FIELD_PRED] = { 1, 2 },
- [VL_MACROBLOCK_TYPE_BI_FRAME_PRED] = { 2, 1 },
- [VL_MACROBLOCK_TYPE_BI_FIELD_PRED] = { 2, 2 }
-};
-
static void *
create_vert_shader(struct vl_mpeg12_mc_renderer *r)
{
stride = vl_vb_element_helper(&vertex_elems[VS_I_VPOS], 9, 1);
- r->vertex_bufs.individual.pos = vl_vb_create_buffer(
- r->pipe, r->macroblocks_per_batch, stride);
+ r->vertex_bufs.individual.pos = vl_vb_init(
+ &r->pos, r->pipe, r->macroblocks_per_batch,
+ sizeof(struct vertex_stream_0) / sizeof(float),
+ stride);
for (i = 0; i < 4; ++i) {
/* motion vector 0..4 element */
vertex_elems[VS_I_MV0 + i].src_format = PIPE_FORMAT_R32G32_FLOAT;
stride = vl_vb_element_helper(&vertex_elems[VS_I_MV0 + i], 1, i + 2);
- r->vertex_bufs.individual.mv[i] = vl_vb_create_buffer(
- r->pipe, r->macroblocks_per_batch, stride);
+ r->vertex_bufs.individual.mv[i] = vl_vb_init(
+ &r->mv[i], r->pipe, r->macroblocks_per_batch,
+ sizeof(struct vertex2f) / sizeof(float),
+ stride);
}
r->vertex_elems_state = r->pipe->create_vertex_elements_state(
if (r->vs == NULL || r->fs == NULL)
return false;
- if (!vl_vb_init(&r->pos, r->macroblocks_per_batch, sizeof(struct vertex_stream_0) / sizeof(float)))
- return false;
-
- for (i = 0; i < 4; ++i) {
- if (!vl_vb_init(&r->mv[i], r->macroblocks_per_batch, sizeof(struct vertex2f) / sizeof(float)))
- return false;
- }
-
return true;
}
r->pipe->delete_vertex_elements_state(r->pipe, r->vertex_elems_state);
}
-static void
-upload_vertex_stream(struct vl_mpeg12_mc_renderer *r)
-{
- struct vertex_stream_0 *pos;
- struct vertex2f *mv[4];
-
- struct pipe_transfer *buf_transfer[5];
-
- unsigned i, j;
-
- assert(r);
-
- pos = (struct vertex_stream_0 *)pipe_buffer_map
- (
- r->pipe,
- r->vertex_bufs.individual.pos.buffer,
- PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
- &buf_transfer[0]
- );
-
- for (i = 0; i < 4; ++i)
- mv[i] = (struct vertex2f *)pipe_buffer_map
- (
- r->pipe,
- r->vertex_bufs.individual.mv[i].buffer,
- PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
- &buf_transfer[i + 1]
- );
-
- vl_vb_upload(&r->pos, pos);
- for (j = 0; j < 4; ++j)
- vl_vb_upload(&r->mv[j], mv[j]);
-
- pipe_buffer_unmap(r->pipe, r->vertex_bufs.individual.pos.buffer, buf_transfer[0]);
- for (i = 0; i < 4; ++i)
- pipe_buffer_unmap(r->pipe, r->vertex_bufs.individual.mv[i].buffer, buf_transfer[i + 1]);
-}
-
static struct pipe_sampler_view
*find_or_create_sampler_view(struct vl_mpeg12_mc_renderer *r, struct pipe_surface *surface)
{
void
vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer)
{
+ unsigned i;
+
assert(renderer);
assert(renderer->num_macroblocks <= renderer->macroblocks_per_batch);
vl_idct_flush(&renderer->idct_chroma, &renderer->idct_cr);
vl_idct_flush(&renderer->idct_chroma, &renderer->idct_cb);
- upload_vertex_stream(renderer);
+ vl_vb_unmap(&renderer->pos, renderer->pipe);
+ vl_vb_restart(&renderer->pos);
+ for(i = 0; i < 4; ++i) {
+ vl_vb_unmap(&renderer->mv[i], renderer->pipe);
+ vl_vb_restart(&renderer->mv[i]);
+ }
renderer->fb_state.cbufs[0] = renderer->surface;
renderer->pipe->bind_rasterizer_state(renderer->pipe, renderer->rs_state);
vl_idct_map_buffers(&renderer->idct_chroma, &renderer->idct_cr);
vl_idct_map_buffers(&renderer->idct_chroma, &renderer->idct_cb);
+ vl_vb_map(&renderer->pos, renderer->pipe);
+ for(i = 0; i < 4; ++i)
+ vl_vb_map(&renderer->mv[i], renderer->pipe);
+
renderer->num_macroblocks = 0;
}
VL_MPEG12_MC_RENDERER_BUFFER_PICTURE /* Larger batches, more memory */
};
-enum VL_MACROBLOCK_TYPE
-{
- VL_MACROBLOCK_TYPE_INTRA,
- VL_MACROBLOCK_TYPE_FWD_FRAME_PRED,
- VL_MACROBLOCK_TYPE_FWD_FIELD_PRED,
- VL_MACROBLOCK_TYPE_BKWD_FRAME_PRED,
- VL_MACROBLOCK_TYPE_BKWD_FIELD_PRED,
- VL_MACROBLOCK_TYPE_BI_FRAME_PRED,
- VL_MACROBLOCK_TYPE_BI_FIELD_PRED,
-
- VL_NUM_MACROBLOCK_TYPES
-};
-
struct vl_mpeg12_mc_renderer
{
struct pipe_context *pipe;
return element;
}
-struct pipe_vertex_buffer
-vl_vb_create_buffer(struct pipe_context *pipe, unsigned max_blocks, unsigned stride)
-{
- struct pipe_vertex_buffer buf;
-
- buf.stride = stride;
- buf.max_index = 4 * max_blocks - 1;
- buf.buffer_offset = 0;
- buf.buffer = pipe_buffer_create
- (
- pipe->screen,
- PIPE_BIND_VERTEX_BUFFER,
- stride * 4 * max_blocks
- );
-
- return buf;
-}
-
unsigned
vl_vb_element_helper(struct pipe_vertex_element* elements, unsigned num_elements,
unsigned vertex_buffer_index)
return offset;
}
-bool
-vl_vb_init(struct vl_vertex_buffer *buffer, unsigned max_blocks, unsigned num_elements)
+struct pipe_vertex_buffer
+vl_vb_init(struct vl_vertex_buffer *buffer, struct pipe_context *pipe,
+ unsigned max_blocks, unsigned num_elements, unsigned stride)
{
+ struct pipe_vertex_buffer buf;
+
assert(buffer);
buffer->num_verts = 0;
buffer->num_elements = num_elements;
- buffer->buffer = MALLOC(max_blocks * num_elements * sizeof(float) * 4);
- return buffer->buffer != NULL;
+
+ buf.stride = stride;
+ buf.max_index = 4 * max_blocks - 1;
+ buf.buffer_offset = 0;
+ buf.buffer = pipe_buffer_create
+ (
+ pipe->screen,
+ PIPE_BIND_VERTEX_BUFFER,
+ stride * 4 * max_blocks
+ );
+
+ pipe_resource_reference(&buffer->resource, buf.buffer);
+
+ vl_vb_map(buffer, pipe);
+
+ return buf;
}
-unsigned
-vl_vb_upload(struct vl_vertex_buffer *buffer, void *dst)
+void
+vl_vb_map(struct vl_vertex_buffer *buffer, struct pipe_context *pipe)
{
- unsigned todo;
+ assert(buffer && pipe);
- assert(buffer);
+ buffer->vectors = pipe_buffer_map
+ (
+ pipe,
+ buffer->resource,
+ PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
+ &buffer->transfer
+ );
+}
- todo = buffer->num_verts;
- buffer->num_verts = 0;
+void
+vl_vb_unmap(struct vl_vertex_buffer *buffer, struct pipe_context *pipe)
+{
+ assert(buffer && pipe);
- if(todo)
- memcpy(dst, buffer->buffer, sizeof(float) * buffer->num_elements * todo);
+ pipe_buffer_unmap(pipe, buffer->resource, buffer->transfer);
+}
+
+unsigned
+vl_vb_restart(struct vl_vertex_buffer *buffer)
+{
+ assert(buffer);
+ unsigned todo = buffer->num_verts;
+ buffer->num_verts = 0;
return todo;
}
{
assert(buffer);
- FREE(buffer->buffer);
+ pipe_resource_reference(&buffer->resource, NULL);
}
{
unsigned num_verts;
unsigned num_elements;
- float *buffer;
+ struct pipe_resource *resource;
+ struct pipe_transfer *transfer;
+ float *vectors;
};
struct pipe_vertex_buffer vl_vb_upload_quads(struct pipe_context *pipe, unsigned max_blocks);
struct pipe_vertex_element vl_vb_get_quad_vertex_element();
-struct pipe_vertex_buffer vl_vb_create_buffer(struct pipe_context *pipe, unsigned max_blocks, unsigned stride);
-
unsigned vl_vb_element_helper(struct pipe_vertex_element* elements, unsigned num_elements,
unsigned vertex_buffer_index);
-bool vl_vb_init(struct vl_vertex_buffer *buffer, unsigned max_blocks, unsigned num_elements);
+struct pipe_vertex_buffer vl_vb_init(struct vl_vertex_buffer *buffer,
+ struct pipe_context *pipe,
+ unsigned max_blocks, unsigned num_elements,
+ unsigned stride);
+
+void vl_vb_map(struct vl_vertex_buffer *buffer, struct pipe_context *pipe);
static inline void
vl_vb_add_block(struct vl_vertex_buffer *buffer, float *elements)
assert(buffer);
for(i = 0; i < 4; ++i) {
- pos = buffer->buffer + buffer->num_verts * buffer->num_elements;
+ pos = buffer->vectors + buffer->num_verts * buffer->num_elements;
memcpy(pos, elements, sizeof(float) * buffer->num_elements);
buffer->num_verts++;
}
}
-unsigned vl_vb_upload(struct vl_vertex_buffer *buffer, void *dst);
+void vl_vb_unmap(struct vl_vertex_buffer *buffer, struct pipe_context *pipe);
+
+unsigned vl_vb_restart(struct vl_vertex_buffer *buffer);
void vl_vb_cleanup(struct vl_vertex_buffer *buffer);