diff options
Diffstat (limited to 'src/gallium/auxiliary/util/u_inlines.h')
-rw-r--r-- | src/gallium/auxiliary/util/u_inlines.h | 254 |
1 files changed, 145 insertions, 109 deletions
diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h index e7255e3baa..5361b3b1e8 100644 --- a/src/gallium/auxiliary/util/u_inlines.h +++ b/src/gallium/auxiliary/util/u_inlines.h @@ -34,6 +34,7 @@ #include "pipe/p_screen.h" #include "util/u_debug.h" #include "util/u_atomic.h" +#include "util/u_box.h" #ifdef __cplusplus @@ -95,8 +96,8 @@ pipe_buffer_reference(struct pipe_buffer **ptr, struct pipe_buffer *buf) assert(ptr); old_buf = *ptr; - if (pipe_reference(&(*ptr)->reference, &buf->reference)) - old_buf->screen->buffer_destroy(old_buf); + if (pipe_reference(&(*ptr)->base.reference, &buf->base.reference)) + old_buf->base.screen->resource_destroy(&old_buf->base); *ptr = buf; } @@ -106,7 +107,7 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) struct pipe_surface *old_surf = *ptr; if (pipe_reference(&(*ptr)->reference, &surf->reference)) - old_surf->texture->screen->tex_surface_destroy(old_surf); + old_surf->resource->screen->tex_surface_destroy(old_surf); *ptr = surf; } @@ -115,8 +116,18 @@ pipe_texture_reference(struct pipe_texture **ptr, struct pipe_texture *tex) { struct pipe_texture *old_tex = *ptr; + if (pipe_reference(&(*ptr)->base.reference, &tex->base.reference)) + old_tex->base.screen->resource_destroy(&old_tex->base); + *ptr = tex; +} + +static INLINE void +pipe_resource_reference(struct pipe_resource **ptr, struct pipe_resource *tex) +{ + struct pipe_resource *old_tex = *ptr; + if (pipe_reference(&(*ptr)->reference, &tex->reference)) - old_tex->screen->texture_destroy(old_tex); + old_tex->screen->resource_destroy(old_tex); *ptr = tex; } @@ -129,87 +140,116 @@ static INLINE struct pipe_buffer * pipe_buffer_create( struct pipe_screen *screen, unsigned alignment, unsigned usage, unsigned size ) { - return screen->buffer_create(screen, alignment, usage, size); + struct pipe_buffer buffer; + memset(&buffer, 0, sizeof buffer); + buffer.base.target = PIPE_RESOURCE_BUFFER; + buffer.base.format = PIPE_FORMAT_R8_UNORM; /* want TYPELESS or similar */ + buffer.base.usage = usage; + buffer.base.width0 = size; + buffer.base.height0 = 1; + buffer.base.depth0 = 1; + return (struct pipe_buffer *)screen->resource_create(screen, &buffer.base); } +#if 0 static INLINE struct pipe_buffer * pipe_user_buffer_create( struct pipe_screen *screen, void *ptr, unsigned size ) { return screen->user_buffer_create(screen, ptr, size); } +#endif static INLINE void * -pipe_buffer_map(struct pipe_screen *screen, - struct pipe_buffer *buf, - unsigned usage) +pipe_buffer_map_range(struct pipe_context *pipe, + struct pipe_buffer *buffer, + unsigned offset, + unsigned length, + unsigned usage, + struct pipe_transfer **transfer) { - if(screen->buffer_map_range) { - unsigned offset = 0; - unsigned length = buf->size; - return screen->buffer_map_range(screen, buf, offset, length, usage); - } - else - return screen->buffer_map(screen, buf, usage); + struct pipe_box box; + + assert(offset < buffer->base.width0); + assert(offset + length <= buffer->base.width0); + assert(length); + + u_box_1d(offset, length, &box); + + *transfer = pipe->get_transfer( pipe, + &buffer->base, + u_subresource(0, 0), + usage, + &box); + + if (*transfer == NULL) + return NULL; + + return pipe->transfer_map( pipe, *transfer ); } -static INLINE void -pipe_buffer_unmap(struct pipe_screen *screen, - struct pipe_buffer *buf) + +static INLINE void * +pipe_buffer_map(struct pipe_context *pipe, + struct pipe_buffer *buffer, + unsigned usage, + struct pipe_transfer **transfer) { - screen->buffer_unmap(screen, buf); + return pipe_buffer_map_range(pipe, buffer, usage, 0, buffer->base.width0, transfer); } -static INLINE void * -pipe_buffer_map_range(struct pipe_screen *screen, - struct pipe_buffer *buf, - unsigned offset, - unsigned length, - unsigned usage) + +static INLINE void +pipe_buffer_unmap(struct pipe_context *pipe, + struct pipe_buffer *buf, + struct pipe_transfer *transfer) { - assert(offset < buf->size); - assert(offset + length <= buf->size); - assert(length); - if(screen->buffer_map_range) - return screen->buffer_map_range(screen, buf, offset, length, usage); - else - return screen->buffer_map(screen, buf, usage); + if (transfer) { + pipe->transfer_unmap(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); + } } static INLINE void -pipe_buffer_flush_mapped_range(struct pipe_screen *screen, - struct pipe_buffer *buf, +pipe_buffer_flush_mapped_range(struct pipe_context *pipe, + struct pipe_transfer *transfer, unsigned offset, unsigned length) { - assert(offset < buf->size); - assert(offset + length <= buf->size); + struct pipe_box box; + assert(length); - if(screen->buffer_flush_mapped_range) - screen->buffer_flush_mapped_range(screen, buf, offset, length); + + u_box_1d(offset, length, &box); + + pipe->transfer_flush_region(pipe, transfer, &box); } static INLINE void -pipe_buffer_write(struct pipe_screen *screen, +pipe_buffer_write(struct pipe_context *pipe, struct pipe_buffer *buf, - unsigned offset, unsigned size, + unsigned offset, + unsigned size, const void *data) { - void *map; - - assert(offset < buf->size); - assert(offset + size <= buf->size); - assert(size); - - map = pipe_buffer_map_range(screen, buf, offset, size, - PIPE_BUFFER_USAGE_CPU_WRITE | - PIPE_BUFFER_USAGE_FLUSH_EXPLICIT | - PIPE_BUFFER_USAGE_DISCARD); - assert(map); - if(map) { - memcpy((uint8_t *)map + offset, data, size); - pipe_buffer_flush_mapped_range(screen, buf, offset, size); - pipe_buffer_unmap(screen, buf); - } + struct pipe_box box; + struct pipe_subresource subresource; + + subresource.face = 0; + subresource.level = 0; + + box.x = offset; + box.y = 0; + box.z = 0; + box.w = size; + box.h = 1; + box.d = 1; + + pipe->transfer_inline_write( pipe, + &buf->base, + subresource, + PIPE_TRANSFER_WRITE, + &box, + data); } /** @@ -219,86 +259,82 @@ pipe_buffer_write(struct pipe_screen *screen, * been written before. */ static INLINE void -pipe_buffer_write_nooverlap(struct pipe_screen *screen, +pipe_buffer_write_nooverlap(struct pipe_context *pipe, struct pipe_buffer *buf, unsigned offset, unsigned size, const void *data) { - void *map; - - assert(offset < buf->size); - assert(offset + size <= buf->size); - assert(size); - - map = pipe_buffer_map_range(screen, buf, offset, size, - PIPE_BUFFER_USAGE_CPU_WRITE | - PIPE_BUFFER_USAGE_FLUSH_EXPLICIT | - PIPE_BUFFER_USAGE_DISCARD | - PIPE_BUFFER_USAGE_UNSYNCHRONIZED); - assert(map); - if(map) { - memcpy((uint8_t *)map + offset, data, size); - pipe_buffer_flush_mapped_range(screen, buf, offset, size); - pipe_buffer_unmap(screen, buf); - } + struct pipe_box box; + struct pipe_subresource subresource; + + subresource.face = 0; + subresource.level = 0; + + box.x = offset; + box.y = 0; + box.z = 0; + box.w = size; + box.h = 1; + box.d = 1; + + pipe->transfer_inline_write(pipe, + &buf->base, + subresource, + (PIPE_TRANSFER_WRITE | + PIPE_TRANSFER_NOOVERWRITE), + &box, + data); } static INLINE void -pipe_buffer_read(struct pipe_screen *screen, +pipe_buffer_read(struct pipe_context *pipe, struct pipe_buffer *buf, unsigned offset, unsigned size, void *data) { - void *map; - - assert(offset < buf->size); - assert(offset + size <= buf->size); - assert(size); - - map = pipe_buffer_map_range(screen, buf, offset, size, PIPE_BUFFER_USAGE_CPU_READ); - assert(map); - if(map) { - memcpy(data, (const uint8_t *)map + offset, size); - pipe_buffer_unmap(screen, buf); - } + struct pipe_box box; + struct pipe_subresource subresource; + + subresource.face = 0; + subresource.level = 0; + + box.x = offset; + box.y = 0; + box.z = 0; + box.w = size; + box.h = 1; + box.d = 1; + + pipe->transfer_inline_read( pipe, + &buf->base, + subresource, + PIPE_TRANSFER_READ, + &box, + data); } static INLINE void * pipe_transfer_map( struct pipe_context *context, - struct pipe_transfer *transf ) + struct pipe_transfer *transfer ) { - return context->transfer_map(context, transf); + return context->transfer_map( context, transfer ); } static INLINE void pipe_transfer_unmap( struct pipe_context *context, - struct pipe_transfer *transf ) + struct pipe_transfer *transfer ) { - context->transfer_unmap(context, transf); + context->transfer_unmap( context, transfer ); } + static INLINE void -pipe_transfer_destroy( struct pipe_context *context, - struct pipe_transfer *transfer ) +pipe_transfer_destroy( struct pipe_context *context, + struct pipe_transfer *transfer ) { - context->tex_transfer_destroy(context, transfer); + context->transfer_destroy(context, transfer); } -static INLINE unsigned -pipe_transfer_buffer_flags( struct pipe_transfer *transf ) -{ - switch (transf->usage & PIPE_TRANSFER_READ_WRITE) { - case PIPE_TRANSFER_READ_WRITE: - return PIPE_BUFFER_USAGE_CPU_READ | PIPE_BUFFER_USAGE_CPU_WRITE; - case PIPE_TRANSFER_READ: - return PIPE_BUFFER_USAGE_CPU_READ; - case PIPE_TRANSFER_WRITE: - return PIPE_BUFFER_USAGE_CPU_WRITE; - default: - debug_assert(0); - return 0; - } -} #ifdef __cplusplus } |