}
}
+/**
+ * This function is used to copy an array of pipe_vertex_buffer structures,
+ * while properly referencing the pipe_vertex_buffer::buffer member.
+ *
+ * \sa util_copy_framebuffer_state
+ */
static INLINE void util_copy_vertex_buffers(struct pipe_vertex_buffer *dst,
unsigned *dst_count,
const struct pipe_vertex_buffer *src,
{
unsigned i;
+ /* Reference the buffers of 'src' in 'dst'. */
for (i = 0; i < src_count; i++) {
pipe_resource_reference(&dst[i].buffer, src[i].buffer);
}
+ /* Unreference the rest of the buffers in 'dst'. */
for (; i < *dst_count; i++) {
pipe_resource_reference(&dst[i].buffer, NULL);
}
+ /* Update the size of 'dst' and copy over the other members
+ * of pipe_vertex_buffer. */
*dst_count = src_count;
memcpy(dst, src, src_count * sizeof(struct pipe_vertex_buffer));
}
struct u_upload_mgr {
struct pipe_context *pipe;
- unsigned default_size;
- unsigned alignment;
- unsigned bind;
-
- /* The active buffer:
- */
- struct pipe_resource *buffer;
- struct pipe_transfer *transfer;
- uint8_t *map;
- unsigned size;
- unsigned offset;
+ unsigned default_size; /* Minimum size of the upload buffer, in bytes. */
+ unsigned alignment; /* Alignment of each sub-allocation. */
+ unsigned bind; /* Bitmask of PIPE_BIND_* flags. */
+
+ struct pipe_resource *buffer; /* Upload buffer. */
+ struct pipe_transfer *transfer; /* Transfer object for the upload buffer. */
+ uint8_t *map; /* Pointer to the mapped upload buffer. */
+ unsigned size; /* Actual size of the upload buffer. */
+ unsigned offset; /* Aligned offset to the upload buffer, pointing
+ * at the first unused byte. */
};
*/
void u_upload_flush( struct u_upload_mgr *upload )
{
+ /* Unmap and unreference the upload buffer. */
if (upload->transfer) {
pipe_transfer_unmap(upload->pipe, upload->transfer);
upload->transfer = NULL;
{
unsigned size;
- /* Release old buffer, if present:
+ /* Release the old buffer, if present:
*/
u_upload_flush( upload );
if (upload->buffer == NULL)
goto fail;
+ /* Map the new buffer. */
upload->map = pipe_buffer_map(upload->pipe, upload->buffer,
PIPE_TRANSFER_WRITE, &upload->transfer);
unsigned alloc_offset = align(min_out_offset, upload->alignment);
unsigned offset;
+ /* Make sure we have enough space in the upload buffer
+ * for the sub-allocation. */
if (MAX2(upload->offset, alloc_offset) + alloc_size > upload->size) {
enum pipe_error ret = u_upload_alloc_buffer(upload,
alloc_offset + alloc_size);
assert(offset + size <= upload->buffer->width0);
assert(size);
+ /* Emit the return values: */
*ptr = upload->map + offset;
-
- /* Emit the return values:
- */
pipe_resource_reference( outbuf, upload->buffer );
*out_offset = offset;
+
upload->offset = offset + alloc_size;
return PIPE_OK;
}
struct pipe_resource;
+/**
+ * Create the upload manager.
+ *
+ * \param pipe Pipe driver.
+ * \param default_size Minimum size of the upload buffer, in bytes.
+ * \param alignment Alignment of each suballocation in the upload buffer.
+ * \param bind Bitmask of PIPE_BIND_* flags.
+ */
struct u_upload_mgr *u_upload_create( struct pipe_context *pipe,
unsigned default_size,
unsigned alignment,
unsigned bind );
+/**
+ * Destroy the upload manager.
+ */
void u_upload_destroy( struct u_upload_mgr *upload );
/* Unmap and release old buffer.