diff options
Diffstat (limited to 'src/gallium')
230 files changed, 6267 insertions, 6215 deletions
diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile index e1c3bc43a2..019554272d 100644 --- a/src/gallium/auxiliary/Makefile +++ b/src/gallium/auxiliary/Makefile @@ -64,6 +64,8 @@ C_SOURCES = \ pipebuffer/pb_bufmgr_pool.c \ pipebuffer/pb_bufmgr_slab.c \ pipebuffer/pb_validate.c \ + piperesource/rm_context.c \ + piperesource/rm_screen.c \ rbug/rbug_connection.c \ rbug/rbug_core.c \ rbug/rbug_texture.c \ @@ -125,9 +127,9 @@ C_SOURCES = \ util/u_surface.c \ util/u_texture.c \ util/u_tile.c \ - util/u_timed_winsys.c \ + util/u_transfer.c \ + util/u_resource.c \ util/u_upload_mgr.c \ - util/u_simple_screen.c \ target-helpers/wrap_screen.c # Disabling until pipe-video branch gets merged in diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index 4ed9e09c52..2747173755 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -620,7 +620,7 @@ cso_restore_vertex_samplers(struct cso_context *ctx) enum pipe_error cso_set_sampler_textures( struct cso_context *ctx, uint count, - struct pipe_texture **textures ) + struct pipe_resource **textures ) { uint i; diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h index a24077e009..18c2e43588 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.h +++ b/src/gallium/auxiliary/cso_cache/cso_context.h @@ -106,7 +106,7 @@ cso_single_vertex_sampler_done(struct cso_context *cso); enum pipe_error cso_set_sampler_textures( struct cso_context *cso, uint count, - struct pipe_texture **textures ); + struct pipe_resource **textures ); void cso_save_sampler_textures( struct cso_context *cso ); void cso_restore_sampler_textures( struct cso_context *cso ); diff --git a/src/gallium/auxiliary/draw/draw_pipe_aaline.c b/src/gallium/auxiliary/draw/draw_pipe_aaline.c index f4615064e6..ff29fe7456 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_aaline.c +++ b/src/gallium/auxiliary/draw/draw_pipe_aaline.c @@ -88,7 +88,7 @@ struct aaline_stage uint pos_slot; void *sampler_cso; - struct pipe_texture *texture; + struct pipe_resource *texture; struct pipe_sampler_view *sampler_view; uint num_samplers; uint num_sampler_views; @@ -396,7 +396,7 @@ aaline_create_texture(struct aaline_stage *aaline) { struct pipe_context *pipe = aaline->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_texture texTemp; + struct pipe_resource texTemp; struct pipe_sampler_view viewTempl; uint level; @@ -408,7 +408,7 @@ aaline_create_texture(struct aaline_stage *aaline) texTemp.height0 = 1 << MAX_TEXTURE_LEVEL; texTemp.depth0 = 1; - aaline->texture = screen->texture_create(screen, &texTemp); + aaline->texture = screen->resource_create(screen, &texTemp); if (!aaline->texture) return FALSE; @@ -428,16 +428,23 @@ aaline_create_texture(struct aaline_stage *aaline) */ for (level = 0; level <= MAX_TEXTURE_LEVEL; level++) { struct pipe_transfer *transfer; + struct pipe_box box; const uint size = u_minify(aaline->texture->width0, level); ubyte *data; uint i, j; assert(aaline->texture->width0 == aaline->texture->height0); + u_box_orgin_2d( size, size, &box ); + /* This texture is new, no need to flush. */ - transfer = pipe->get_tex_transfer(pipe, aaline->texture, 0, level, 0, - PIPE_TRANSFER_WRITE, 0, 0, size, size); + transfer = pipe->get_transfer(pipe, + aaline->texture, + u_subresource(0, level), + PIPE_TRANSFER_WRITE, + &box); + data = pipe->transfer_map(pipe, transfer); if (data == NULL) return FALSE; @@ -463,7 +470,7 @@ aaline_create_texture(struct aaline_stage *aaline) /* unmap */ pipe->transfer_unmap(pipe, transfer); - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } return TRUE; } @@ -746,7 +753,7 @@ aaline_destroy(struct draw_stage *stage) aaline->pipe->delete_sampler_state(aaline->pipe, aaline->sampler_cso); if (aaline->texture) - pipe_texture_reference(&aaline->texture, NULL); + pipe_resource_reference(&aaline->texture, NULL); if (aaline->sampler_view) { pipe_sampler_view_reference(&aaline->sampler_view, NULL); diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c index 794fd81d70..bd433deeca 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c @@ -75,7 +75,7 @@ struct pstip_stage struct draw_stage stage; void *sampler_cso; - struct pipe_texture *texture; + struct pipe_resource *texture; struct pipe_sampler_view *sampler_view; uint num_samplers; uint num_sampler_views; @@ -389,8 +389,8 @@ pstip_update_texture(struct pstip_stage *pstip) */ pipe->flush( pipe, PIPE_FLUSH_TEXTURE_CACHE, NULL ); - transfer = pipe->get_tex_transfer(pipe, pstip->texture, 0, 0, 0, - PIPE_TRANSFER_WRITE, 0, 0, 32, 32); + transfer = pipe_get_transfer(pipe, pstip->texture, 0, 0, 0, + PIPE_TRANSFER_WRITE, 0, 0, 32, 32); data = pipe->transfer_map(pipe, transfer); /* @@ -414,7 +414,7 @@ pstip_update_texture(struct pstip_stage *pstip) /* unmap */ pipe->transfer_unmap(pipe, transfer); - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } @@ -426,7 +426,7 @@ pstip_create_texture(struct pstip_stage *pstip) { struct pipe_context *pipe = pstip->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_texture texTemp; + struct pipe_resource texTemp; struct pipe_sampler_view viewTempl; memset(&texTemp, 0, sizeof(texTemp)); @@ -437,7 +437,7 @@ pstip_create_texture(struct pstip_stage *pstip) texTemp.height0 = 32; texTemp.depth0 = 1; - pstip->texture = screen->texture_create(screen, &texTemp); + pstip->texture = screen->resource_create(screen, &texTemp); if (pstip->texture == NULL) return FALSE; @@ -591,7 +591,7 @@ pstip_destroy(struct draw_stage *stage) pstip->pipe->delete_sampler_state(pstip->pipe, pstip->sampler_cso); - pipe_texture_reference(&pstip->texture, NULL); + pipe_resource_reference(&pstip->texture, NULL); if (pstip->sampler_view) { pipe_sampler_view_reference(&pstip->sampler_view, NULL); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c index bb76ad4c6b..0761e35f8e 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c @@ -51,7 +51,7 @@ */ void lp_sampler_static_state(struct lp_sampler_static_state *state, - const struct pipe_texture *texture, + const struct pipe_resource *texture, const struct pipe_sampler_state *sampler) { memset(state, 0, sizeof *state); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h index 92f3c57435..fcbf084baf 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h @@ -38,7 +38,7 @@ #include "gallivm/lp_bld.h" -struct pipe_texture; +struct pipe_resource; struct pipe_sampler_state; struct util_format_description; struct lp_type; @@ -48,7 +48,7 @@ struct lp_build_context; /** * Sampler static state. * - * These are the bits of state from pipe_texture and pipe_sampler_state that + * These are the bits of state from pipe_resource and pipe_sampler_state that * are embedded in the generated code. */ struct lp_sampler_static_state @@ -78,7 +78,7 @@ struct lp_sampler_static_state /** * Sampler dynamic state. * - * These are the bits of state from pipe_texture and pipe_sampler_state that + * These are the bits of state from pipe_resource and pipe_sampler_state that * are computed in runtime. * * There are obtained through callbacks, as we don't want to tie the texture @@ -130,7 +130,7 @@ struct lp_sampler_dynamic_state */ void lp_sampler_static_state(struct lp_sampler_static_state *state, - const struct pipe_texture *texture, + const struct pipe_resource *texture, const struct pipe_sampler_state *sampler); diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer.h b/src/gallium/auxiliary/pipebuffer/pb_buffer.h index 34b1b77df4..a6c50dcf0c 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_buffer.h +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer.h @@ -48,7 +48,6 @@ #include "util/u_debug.h" #include "util/u_inlines.h" #include "pipe/p_defines.h" -#include "pipe/p_state.h" #ifdef __cplusplus @@ -58,8 +57,23 @@ extern "C" { struct pb_vtbl; struct pb_validate; +struct pipe_fence_handle; +#define PB_USAGE_CPU_READ (1 << 0) +#define PB_USAGE_CPU_WRITE (1 << 1) +#define PB_USAGE_GPU_READ (1 << 2) +#define PB_USAGE_GPU_WRITE (1 << 3) +#define PB_USAGE_UNSYNCHRONIZED (1 << 10) +#define PB_USAGE_DONTBLOCK (1 << 9) + +#define PB_USAGE_CPU_READ_WRITE \ + ( PB_USAGE_CPU_READ | PB_USAGE_CPU_WRITE ) +#define PB_USAGE_GPU_READ_WRITE \ + ( PB_USAGE_GPU_READ | PB_USAGE_GPU_WRITE ) +#define PB_USAGE_WRITE \ + ( PB_USAGE_CPU_WRITE | PB_USAGE_GPU_WRITE ) + /** * Buffer description. * @@ -83,7 +97,14 @@ typedef unsigned pb_size; */ struct pb_buffer { - struct pipe_buffer base; + /* This used to be a pipe_buffer struct: + */ + struct { + struct pipe_reference reference; + unsigned size; + unsigned alignment; + unsigned usage; + } base; /** * Pointer to the virtual function table. @@ -106,7 +127,7 @@ struct pb_vtbl /** * Map the entire data store of a buffer object into the client's address. - * flags is bitmask of PIPE_BUFFER_FLAG_READ/WRITE. + * flags is bitmask of PB_USAGE_CPU_READ/WRITE. */ void *(*map)( struct pb_buffer *buf, unsigned flags ); @@ -138,23 +159,6 @@ struct pb_vtbl }; -static INLINE struct pipe_buffer * -pb_pipe_buffer( struct pb_buffer *pbuf ) -{ - assert(pbuf); - return &pbuf->base; -} - - -static INLINE struct pb_buffer * -pb_buffer( struct pipe_buffer *buf ) -{ - assert(buf); - /* Could add a magic cookie check on debug builds. - */ - return (struct pb_buffer *)buf; -} - /* Accessor functions for pb->vtbl: */ diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c index d97f749b6e..d6cf640582 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c @@ -135,7 +135,7 @@ struct fenced_buffer void *data; /** - * A bitmask of PIPE_BUFFER_USAGE_CPU/GPU_READ/WRITE describing the current + * A bitmask of PB_USAGE_CPU/GPU_READ/WRITE describing the current * buffer usage. */ unsigned flags; @@ -270,7 +270,7 @@ fenced_buffer_add_locked(struct fenced_manager *fenced_mgr, struct fenced_buffer *fenced_buf) { assert(pipe_is_referenced(&fenced_buf->base.base.reference)); - assert(fenced_buf->flags & PIPE_BUFFER_USAGE_GPU_READ_WRITE); + assert(fenced_buf->flags & PB_USAGE_GPU_READ_WRITE); assert(fenced_buf->fence); p_atomic_inc(&fenced_buf->base.base.reference.count); @@ -299,7 +299,7 @@ fenced_buffer_remove_locked(struct fenced_manager *fenced_mgr, assert(fenced_buf->mgr == fenced_mgr); ops->fence_reference(ops, &fenced_buf->fence, NULL); - fenced_buf->flags &= ~PIPE_BUFFER_USAGE_GPU_READ_WRITE; + fenced_buf->flags &= ~PB_USAGE_GPU_READ_WRITE; assert(fenced_buf->head.prev); assert(fenced_buf->head.next); @@ -377,7 +377,7 @@ fenced_buffer_finish_locked(struct fenced_manager *fenced_mgr, assert(!destroyed); - fenced_buf->flags &= ~PIPE_BUFFER_USAGE_GPU_READ_WRITE; + fenced_buf->flags &= ~PB_USAGE_GPU_READ_WRITE; ret = PIPE_OK; } @@ -624,7 +624,7 @@ fenced_buffer_copy_storage_to_gpu_locked(struct fenced_buffer *fenced_buf) assert(fenced_buf->data); assert(fenced_buf->buffer); - map = pb_map(fenced_buf->buffer, PIPE_BUFFER_USAGE_CPU_WRITE); + map = pb_map(fenced_buf->buffer, PB_USAGE_CPU_WRITE); if(!map) return PIPE_ERROR; @@ -644,7 +644,7 @@ fenced_buffer_copy_storage_to_cpu_locked(struct fenced_buffer *fenced_buf) assert(fenced_buf->data); assert(fenced_buf->buffer); - map = pb_map(fenced_buf->buffer, PIPE_BUFFER_USAGE_CPU_READ); + map = pb_map(fenced_buf->buffer, PB_USAGE_CPU_READ); if(!map) return PIPE_ERROR; @@ -683,24 +683,24 @@ fenced_buffer_map(struct pb_buffer *buf, pipe_mutex_lock(fenced_mgr->mutex); - assert(!(flags & PIPE_BUFFER_USAGE_GPU_READ_WRITE)); + assert(!(flags & PB_USAGE_GPU_READ_WRITE)); /* * Serialize writes. */ - while((fenced_buf->flags & PIPE_BUFFER_USAGE_GPU_WRITE) || - ((fenced_buf->flags & PIPE_BUFFER_USAGE_GPU_READ) && - (flags & PIPE_BUFFER_USAGE_CPU_WRITE))) { + while((fenced_buf->flags & PB_USAGE_GPU_WRITE) || + ((fenced_buf->flags & PB_USAGE_GPU_READ) && + (flags & PB_USAGE_CPU_WRITE))) { /* * Don't wait for the GPU to finish accessing it, if blocking is forbidden. */ - if((flags & PIPE_BUFFER_USAGE_DONTBLOCK) && + if((flags & PB_USAGE_DONTBLOCK) && ops->fence_signalled(ops, fenced_buf->fence, 0) != 0) { goto done; } - if (flags & PIPE_BUFFER_USAGE_UNSYNCHRONIZED) { + if (flags & PB_USAGE_UNSYNCHRONIZED) { break; } @@ -721,7 +721,7 @@ fenced_buffer_map(struct pb_buffer *buf, if(map) { ++fenced_buf->mapcount; - fenced_buf->flags |= flags & PIPE_BUFFER_USAGE_CPU_READ_WRITE; + fenced_buf->flags |= flags & PB_USAGE_CPU_READ_WRITE; } done: @@ -745,7 +745,7 @@ fenced_buffer_unmap(struct pb_buffer *buf) pb_unmap(fenced_buf->buffer); --fenced_buf->mapcount; if(!fenced_buf->mapcount) - fenced_buf->flags &= ~PIPE_BUFFER_USAGE_CPU_READ_WRITE; + fenced_buf->flags &= ~PB_USAGE_CPU_READ_WRITE; } pipe_mutex_unlock(fenced_mgr->mutex); @@ -771,9 +771,9 @@ fenced_buffer_validate(struct pb_buffer *buf, goto done; } - assert(flags & PIPE_BUFFER_USAGE_GPU_READ_WRITE); - assert(!(flags & ~PIPE_BUFFER_USAGE_GPU_READ_WRITE)); - flags &= PIPE_BUFFER_USAGE_GPU_READ_WRITE; + assert(flags & PB_USAGE_GPU_READ_WRITE); + assert(!(flags & ~PB_USAGE_GPU_READ_WRITE)); + flags &= PB_USAGE_GPU_READ_WRITE; /* Buffer cannot be validated in two different lists */ if(fenced_buf->vl && fenced_buf->vl != vl) { diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h index 0372f81d0a..004c2b939a 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.h @@ -59,7 +59,6 @@ extern "C" { #endif -struct pipe_buffer; struct pipe_fence_handle; diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c b/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c index 6bdce5fcb0..b706f429be 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_malloc.c @@ -135,9 +135,9 @@ pb_malloc_buffer_create(pb_size size, return NULL; pipe_reference_init(&buf->base.base.reference, 1); - buf->base.base.alignment = desc->alignment; buf->base.base.usage = desc->usage; buf->base.base.size = size; + buf->base.base.alignment = desc->alignment; buf->base.vtbl = &malloc_buffer_vtbl; buf->data = align_malloc(size, desc->alignment < sizeof(void*) ? sizeof(void*) : desc->alignment); diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr.h b/src/gallium/auxiliary/pipebuffer/pb_bufmgr.h index 06669917ff..cec2524da2 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr.h +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr.h @@ -60,7 +60,6 @@ extern "C" { struct pb_desc; -struct pipe_buffer; /** diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c index a5dbded2bc..0dc5b31a75 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c @@ -158,7 +158,7 @@ pb_debug_buffer_fill(struct pb_debug_buffer *buf) { uint8_t *map; - map = pb_map(buf->buffer, PIPE_BUFFER_USAGE_CPU_WRITE); + map = pb_map(buf->buffer, PB_USAGE_CPU_WRITE); assert(map); if(map) { fill_random_pattern(map, buf->underflow_size); @@ -180,8 +180,8 @@ pb_debug_buffer_check(struct pb_debug_buffer *buf) uint8_t *map; map = pb_map(buf->buffer, - PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_UNSYNCHRONIZED); + PB_USAGE_CPU_READ | + PB_USAGE_UNSYNCHRONIZED); assert(map); if(map) { boolean underflow, overflow; @@ -382,8 +382,8 @@ pb_debug_manager_create_buffer(struct pb_manager *_mgr, real_size = mgr->underflow_size + size + mgr->overflow_size; real_desc = *desc; - real_desc.usage |= PIPE_BUFFER_USAGE_CPU_WRITE; - real_desc.usage |= PIPE_BUFFER_USAGE_CPU_READ; + real_desc.usage |= PB_USAGE_CPU_WRITE; + real_desc.usage |= PB_USAGE_CPU_READ; buf->buffer = mgr->provider->create_buffer(mgr->provider, real_size, diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c index 63195715d6..faf7c35267 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c @@ -268,8 +268,8 @@ mm_bufmgr_create_from_buffer(struct pb_buffer *buffer, mm->buffer = buffer; mm->map = pb_map(mm->buffer, - PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE); + PB_USAGE_CPU_READ | + PB_USAGE_CPU_WRITE); if(!mm->map) goto failure; diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c index cb32d25136..31f1ebbeb7 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c @@ -150,7 +150,7 @@ pb_ondemand_buffer_instantiate(struct pb_ondemand_buffer *buf) if(!buf->buffer) return PIPE_ERROR_OUT_OF_MEMORY; - map = pb_map(buf->buffer, PIPE_BUFFER_USAGE_CPU_READ); + map = pb_map(buf->buffer, PB_USAGE_CPU_READ); if(!map) { pb_reference(&buf->buffer, NULL); return PIPE_ERROR; diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c index fea234ae8c..fdcce42878 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c @@ -284,8 +284,8 @@ pool_bufmgr_create(struct pb_manager *provider, goto failure; pool->map = pb_map(pool->buffer, - PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE); + PB_USAGE_CPU_READ | + PB_USAGE_CPU_WRITE); if(!pool->map) goto failure; diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c index 24e2820f88..7a3305aaf3 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c @@ -315,8 +315,8 @@ pb_slab_create(struct pb_slab_manager *mgr) /* Note down the slab virtual address. All mappings are accessed directly * through this address so it is required that the buffer is pinned. */ slab->virtual = pb_map(slab->bo, - PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE); + PB_USAGE_CPU_READ | + PB_USAGE_CPU_WRITE); if(!slab->virtual) { ret = PIPE_ERROR_OUT_OF_MEMORY; goto out_err1; diff --git a/src/gallium/auxiliary/pipebuffer/pb_validate.c b/src/gallium/auxiliary/pipebuffer/pb_validate.c index 903afc749d..b585422460 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_validate.c +++ b/src/gallium/auxiliary/pipebuffer/pb_validate.c @@ -69,9 +69,9 @@ pb_validate_add_buffer(struct pb_validate *vl, if(!buf) return PIPE_ERROR; - assert(flags & PIPE_BUFFER_USAGE_GPU_READ_WRITE); - assert(!(flags & ~PIPE_BUFFER_USAGE_GPU_READ_WRITE)); - flags &= PIPE_BUFFER_USAGE_GPU_READ_WRITE; + assert(flags & PB_USAGE_GPU_READ_WRITE); + assert(!(flags & ~PB_USAGE_GPU_READ_WRITE)); + flags &= PB_USAGE_GPU_READ_WRITE; /* We only need to store one reference for each buffer, so avoid storing * consecutive references for the same buffer. It might not be the most diff --git a/src/gallium/auxiliary/piperesource/rm.h b/src/gallium/auxiliary/piperesource/rm.h new file mode 100644 index 0000000000..71d936db73 --- /dev/null +++ b/src/gallium/auxiliary/piperesource/rm.h @@ -0,0 +1,18 @@ +#ifndef RM_PRIVATE_H +#define RM_PRIVATE_H + +#include "rm_public.h" + +struct rm_screen { + struct pipe_screen *screen; + struct rm_screen_callbacks cb; + unsigned default_buffer_alignment; +}; + +struct rm_context { + struct pipe_context *pipe; + struct rm_screen *rm_screen; /* ? */ + struct rm_context_callbacks cb; +}; + +#endif diff --git a/src/gallium/auxiliary/piperesource/rm_context.c b/src/gallium/auxiliary/piperesource/rm_context.c new file mode 100644 index 0000000000..6ecbcb65cb --- /dev/null +++ b/src/gallium/auxiliary/piperesource/rm_context.c @@ -0,0 +1,239 @@ +#include "rm.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" + +struct rm_transfer { + struct pipe_transfer base; + struct pipe_tex_transfer *tex_transfer; + struct pipe_buffer *buffer; + unsigned buffer_usage; +}; + +static INLINE struct rm_transfer *rm_transfer( struct pipe_transfer *t ) +{ + return (struct rm_transfer *)t; +} + +struct pipe_transfer *rm_get_transfer(struct rm_context *rm_ctx, + struct pipe_resource *resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box) +{ + struct rm_transfer *transfer; + struct rm_resource *rmr = rm_resource(resource); + + transfer = CALLOC_STRUCT(rm_transfer); + if (transfer == NULL) + return NULL; + + transfer->base.resource = resource; + + if (rmr->texture && box->depth == 1) { + transfer->tex_transfer = rm_ctx->cb.get_tex_transfer(rm_ctx->pipe, + rmr->texture, + sr.face, + sr.level, + box->z, + usage, + box->x, + box->y, + box->width, + box->height); + } + else if (rmr->texture && box->depth > 1) { + /* TBD. Nobody is using this yet, hopefully can migrate drivers + * to new interfaces before I have to implement some sort of a + * workaround here. + */ + assert(0); + } + else { + transfer->buffer = rm_resource(resource)->buffer; + transfer->buffer_usage = buffer_usage(usage); + } + + assert(transfer->buffer || transfer->tex_transfer); + return &transfer->base; +} + +void rm_transfer_destroy(struct rm_context *rm_ctx, + struct pipe_transfer *transfer) +{ + struct rm_transfer *rmt = rm_transfer(transfer); + + if (rmt->tex_transfer) + rm_ctx->cb.transfer_destroy( rm_ctx->pipe, rmt->tex_transfer ); + + FREE(rmt); +} + +void *rm_transfer_map( struct rm_context *rm_ctx, + struct pipe_transfer *transfer ) +{ + struct rm_transfer *rmt = rm_transfer(transfer); + + if (rmt->tex_transfer) { + return rm_ctx->cb.transfer_map( rm_ctx->pipe, + rmt->tex_transfer ); + } + else { + return rm_ctx->rm_screen->cb.buffer_map( rm_ctx->rm_screen->screen, + rmt->buffer, + rmt->buffer_usage ); + } +} + +/* If transfer was created with WRITE|FLUSH_EXPLICIT, only the + * regions specified with this call are guaranteed to be written to + * the resource. + */ +void rm_transfer_flush_region( struct rm_context *rm_ctx, + struct pipe_transfer *transfer, + const struct pipe_box *box) +{ + struct rm_transfer *rmt = rm_transfer(transfer); + + if (rmt->tex_transfer) { + /* no such action */ + } + else if (rm_ctx->rm_screen->cb.buffer_flush_mapped_range) { + rm_ctx->rm_screen->cb.buffer_flush_mapped_range( rm_ctx->rm_screen->screen, + rmt->buffer, + box->x, + box->width); + } + else { + /* no such action */ + } +} + +void rm_transfer_unmap( struct rm_context *rm_ctx, + struct pipe_transfer *transfer ) +{ + struct rm_transfer *rmt = rm_transfer(transfer); + + if (rmt->tex_transfer) { + rm_ctx->cb.transfer_unmap( rm_ctx->pipe, + rmt->tex_transfer ); + } + else { + struct pipe_buffer *buffer = rmt->buffer; + + rm_ctx->rm_screen->cb.buffer_unmap( rm_ctx->rm_screen->screen, + buffer ); + } +} + + +/* One-shot transfer operation with data supplied in a user + * pointer. XXX: strides?? + */ +void rm_transfer_inline_write( struct rm_context *rm_ctx, + struct pipe_resource *resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box, + const void *data ) +{ + struct pipe_transfer *transfer = NULL; + char *map = NULL; + + transfer = rm_get_transfer(rm_ctx, + resource, + sr, + usage, + box ); + if (transfer == NULL) + goto out; + + map = rm_transfer_map(rm_ctx, transfer); + if (map == NULL) + goto out; + + assert(box->depth == 1); /* XXX: fix me */ + + util_copy_rect(map, + resource->format, + transfer->stride, /* bytes? */ + 0, 0, + box->width, + box->height, + data, + box->width, /* bytes? texels? */ + 0, 0); + +out: + if (map) + rm_transfer_unmap(rm_ctx, transfer); + + if (transfer) + rm_transfer_destroy(rm_ctx, transfer); +} + + + +/* One-shot read transfer operation with data returned in a user + * pointer. XXX: strides?? + */ +void rm_transfer_inline_read( struct rm_context *rm_ctx, + struct pipe_resource *resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box, + void *data ) +{ + struct pipe_transfer *transfer = NULL; + char *map = NULL; + + transfer = rm_get_transfer(rm_ctx, + resource, + sr, + usage, + box ); + if (transfer == NULL) + goto out; + + map = rm_transfer_map(rm_ctx, transfer); + if (map == NULL) + goto out; + + assert(box->depth == 1); /* XXX: fix me */ + + util_copy_rect(data, + resource->format, + transfer->stride, /* bytes? */ + 0, 0, + box->width, + box->height, + map, + box->width, /* bytes? texels? */ + 0, 0); + + +out: + if (map) + rm_transfer_unmap(rm_ctx, transfer); + + if (transfer) + rm_transfer_destroy(rm_ctx, transfer); +} + + +struct rm_context * +rm_context_create( struct pipe_context *pipe, + struct rm_screen *rm_screen, + struct rm_context_callbacks *cb) +{ + struct rm_context *rm_context; + + rm_context = CALLOC_STRUCT(rm_context); + if (rm_context == NULL) + return NULL; + + rm_context->cb = *cb; + rm_context->rm_screen = rm_screen; + rm_context->pipe = pipe; + + return rm_context; +} diff --git a/src/gallium/auxiliary/piperesource/rm_public.h b/src/gallium/auxiliary/piperesource/rm_public.h new file mode 100644 index 0000000000..105bd2382a --- /dev/null +++ b/src/gallium/auxiliary/piperesource/rm_public.h @@ -0,0 +1,229 @@ +#ifndef RM_PUBLIC_H +#define RM_PUBLIC_H + +#include "pipe/p_state.h" + +/* Here are the old pipe_buffer and pipe_texture structs, almost as + * they were. Old pre-resources driver code that creates and + * manipulates these structs can be used to implement the new + * pipe_resource behaviour using this adaptor module. + */ +struct pipe_buffer +{ + struct pipe_reference reference; + struct rm_screen *screen; /* Note! */ + unsigned size; + unsigned alignment; + unsigned usage; +}; + + +struct pipe_texture +{ + struct pipe_reference reference; + struct rm_screen *screen; /* Note! */ + enum pipe_texture_target target; + enum pipe_format format; + unsigned width0; + unsigned height0; + unsigned depth0; + unsigned last_level:8; + unsigned nr_samples:8; + unsigned tex_usage; /**< bitmask of PIPE_TEXTURE_USAGE_* */ +}; + +/* Have to give the legacy transfer struct a new name to avoid + * conflicts. + */ +struct pipe_tex_transfer +{ + unsigned x; /**< x offset from start of texture image */ + unsigned y; /**< y offset from start of texture image */ + unsigned width; /**< logical width in pixels */ + unsigned height; /**< logical height in pixels */ + unsigned stride; /**< stride in bytes between rows of blocks */ + enum pipe_transfer_usage usage; /**< PIPE_TRANSFER_* */ + + struct pipe_texture *texture; /**< texture to transfer to/from */ + unsigned face; + unsigned level; + unsigned zslice; +}; + + +struct rm_resource { + struct pipe_resource base; + struct pipe_buffer *buffer; + struct pipe_texture *texture; +}; + +static INLINE struct rm_resource * +rm_resource( struct pipe_resource *resource ) +{ + return (struct rm_resource *)resource; +} + +static INLINE struct pipe_texture * +rm_texture( struct pipe_resource *resource ) +{ + return rm_resource(resource)->texture; +} + +static INLINE struct pipe_buffer * +rm_buffer( struct pipe_resource *resource ) +{ + return rm_resource(resource)->buffer; +} + + +struct rm_screen_callbacks { + struct pipe_texture * (*texture_create)(struct pipe_screen *, + const struct pipe_texture *templat); + + struct pipe_texture * (*texture_from_handle)(struct pipe_screen *, + const struct pipe_texture *templat, + struct winsys_handle *handle); + + boolean (*texture_get_handle)(struct pipe_screen *, + struct pipe_texture *tex, + struct winsys_handle *handle); + + + void (*texture_destroy)(struct pipe_screen *, + struct pipe_texture *pt); + + struct pipe_surface *(*get_tex_surface)(struct pipe_screen *, + struct pipe_texture *texture, + unsigned face, unsigned level, + unsigned zslice, + unsigned usage ); + + void (*tex_surface_destroy)(struct pipe_surface *); + + + /* Buffer functions: + */ + struct pipe_buffer *(*buffer_create)( struct pipe_screen *screen, + unsigned alignment, + unsigned usage, + unsigned size ); + + struct pipe_buffer *(*user_buffer_create)(struct pipe_screen *screen, + void *ptr, + unsigned bytes); + + void *(*buffer_map)( struct pipe_screen *screen, + struct pipe_buffer *buf, + unsigned usage ); + + void *(*buffer_map_range)( struct pipe_screen *screen, + struct pipe_buffer *buf, + unsigned offset, + unsigned length, + unsigned usage); + + void (*buffer_flush_mapped_range)( struct pipe_screen *screen, + struct pipe_buffer *buf, + unsigned offset, + unsigned length); + + void (*buffer_unmap)( struct pipe_screen *screen, + struct pipe_buffer *buf ); + + void (*buffer_destroy)( struct pipe_screen *screen, + struct pipe_buffer *buf ); +}; + + +struct rm_context_callbacks { + unsigned int (*is_texture_referenced)(struct pipe_context *pipe, + struct pipe_texture *texture, + unsigned face, unsigned level); + + unsigned int (*is_buffer_referenced)(struct pipe_context *pipe, + struct pipe_buffer *buf); + + struct pipe_tex_transfer *(*get_tex_transfer)(struct pipe_context *, + struct pipe_texture *texture, + unsigned face, unsigned level, + unsigned zslice, + enum pipe_transfer_usage usage, + unsigned x, unsigned y, + unsigned w, unsigned h); + + void (*transfer_destroy)(struct pipe_context *, + struct pipe_tex_transfer *); + + void *(*transfer_map)( struct pipe_context *, + struct pipe_tex_transfer *transfer ); + + void (*transfer_unmap)( struct pipe_context *, + struct pipe_tex_transfer *transfer ); +}; + + + +struct rm_screen * +rm_screen_create( struct pipe_screen *screen, + struct rm_screen_callbacks *callbacks, + unsigned default_buffer_alignment); + +struct rm_context * +rm_context_create( struct pipe_context *context, + struct rm_screen *rm_screen, + struct rm_context_callbacks *callbacks ); + + +/* This module implements the following new-style driver functions in + * terms of the old ones that are still present in most pipe drivers. + */ +struct pipe_resource *rm_resource_create(struct rm_screen *, + const struct pipe_resource *template); + +struct pipe_resource *rm_resource_from_handle(struct rm_screen *, + const struct pipe_resource *template, + struct winsys_handle *handle); + +boolean rm_resource_get_handle(struct rm_screen *, + struct pipe_resource *tex, + struct winsys_handle *handle); + + +void rm_resource_destroy(struct rm_screen *, + struct pipe_resource *pt); + +struct pipe_transfer *rm_get_transfer(struct rm_context *, + struct pipe_resource *resource, + struct pipe_subresource, + enum pipe_transfer_usage, + const struct pipe_box *); + +void rm_transfer_destroy(struct rm_context *, + struct pipe_transfer *); + +void *rm_transfer_map( struct rm_context *, + struct pipe_transfer *transfer ); + +void rm_transfer_flush_region( struct rm_context *, + struct pipe_transfer *transfer, + const struct pipe_box *); + +void rm_transfer_unmap( struct rm_context *, + struct pipe_transfer *transfer ); + + +void rm_transfer_inline_write( struct rm_context *, + struct pipe_resource *, + struct pipe_subresource, + enum pipe_transfer_usage, + const struct pipe_box *, + const void *data ); + +void rm_transfer_inline_read( struct rm_context *, + struct pipe_resource *, + struct pipe_subresource, + enum pipe_transfer_usage, + const struct pipe_box *, + void *data ); + +#endif diff --git a/src/gallium/auxiliary/piperesource/rm_screen.c b/src/gallium/auxiliary/piperesource/rm_screen.c new file mode 100644 index 0000000000..7169fc5567 --- /dev/null +++ b/src/gallium/auxiliary/piperesource/rm_screen.c @@ -0,0 +1,130 @@ + +#include "rm.h" +#include "util/u_inlines.h" +#include "util/u_memory.h" + +static void translate_template( const struct pipe_resource *template, + struct pipe_texture *tex ) +{ + tex->tex_usage = template->tex_usage; +} + +/* This module implements the following new-style driver functions in + * terms of the old ones that are still present in most pipe drivers. + */ +struct pipe_resource *rm_resource_create(struct rm_screen *rm_screen, + const struct pipe_resource *template) +{ + struct rm_resource *resource; + + resource = CALLOC_STRUCT(rm_resource); + if (resource == NULL) + goto fail; + + pipe_reference_init(&resource->base.reference, 1); + resource->base.screen = rm_screen->screen; + + if (template->target == PIPE_BUFFER) { + struct pipe_texture tex_template; + + translate_template(template, &tex_template); + + resource->texture = rm_screen->cb.texture_create(rm_screen->screen, + &tex_template); + if (resource->texture == NULL) + goto fail; + } + else { + resource->buffer = rm_screen->cb.buffer_create(rm_screen->screen, + rm_screen->default_buffer_alignment, + template->usage, + template->width0); + if (resource->buffer == NULL) + goto fail; + } + + return &resource->base; + +fail: + FREE(resource); + return NULL; +} + +struct pipe_resource *rm_resource_from_handle(struct rm_screen *rm_screen, + const struct pipe_resource *template, + struct winsys_handle *handle) +{ + struct rm_resource *resource; + struct pipe_texture tex_template; + + assert(template->target != PIPE_BUFFER); + + resource = CALLOC_STRUCT(rm_resource); + if (resource == NULL) + goto fail; + + translate_template(template, &tex_template); + + pipe_reference_init(&resource->base.reference, 1); + resource->base.screen = rm_screen->screen; + resource->texture = rm_screen->cb.texture_from_handle(rm_screen->screen, + &tex_template, + handle); + if (resource->texture == NULL) + goto fail; + + return &resource->base; + +fail: + FREE(resource); + return NULL; +} + +boolean rm_resource_get_handle(struct rm_screen *rm_screen, + struct pipe_resource *resource, + struct winsys_handle *handle) +{ + struct rm_resource *rmr = rm_resource(resource); + assert(rmr->texture); + return rm_screen->cb.texture_get_handle(rm_screen->screen, + rmr->texture, + handle); +} + + +void rm_resource_destroy(struct rm_screen *rm_screen, + struct pipe_resource *resource) +{ + struct rm_resource *rmr = rm_resource(resource); + + if (rmr->texture) { + rm_screen->cb.texture_destroy(rm_screen->screen, + rmr->texture); + } + + if (rmr->buffer) { + rm_screen->cb.buffer_destroy(rm_screen->screen, + rmr->buffer); + } + + FREE(rmr); +} + + +struct rm_screen * +rm_screen_create( struct pipe_screen *screen, + struct rm_screen_callbacks *cb, + unsigned default_buffer_alignment) +{ + struct rm_screen *rm_screen; + + rm_screen = CALLOC_STRUCT(rm_screen); + if (rm_screen == NULL) + return NULL; + + rm_screen->cb = *cb; + rm_screen->screen = screen; + rm_screen->default_buffer_alignment = default_buffer_alignment; + + return rm_screen; +} diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index cd95f85b63..82769ca2de 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -69,7 +69,7 @@ struct blit_state void *vs; void *fs[TGSI_WRITEMASK_XYZW + 1]; - struct pipe_buffer *vbuf; /**< quad vertices */ + struct pipe_resource *vbuf; /**< quad vertices */ unsigned vbuf_slot; float vertices[4][2][4]; /**< vertex/texcoords for quad */ @@ -167,7 +167,7 @@ util_destroy_blit(struct blit_state *ctx) if (ctx->fs[i]) pipe->delete_fs_state(pipe, ctx->fs[i]); - pipe_buffer_reference(&ctx->vbuf, NULL); + pipe_resource_reference(&ctx->vbuf, NULL); FREE(ctx); } @@ -236,7 +236,7 @@ setup_vertex_data_tex(struct blit_state *ctx, offset = get_next_slot( ctx ); - pipe_buffer_write_nooverlap(ctx->pipe->screen, ctx->vbuf, + pipe_buffer_write_nooverlap(ctx->pipe, ctx->vbuf, offset, sizeof(ctx->vertices), ctx->vertices); return offset; @@ -346,8 +346,8 @@ util_blit_pixels_writemask(struct blit_state *ctx, src->texture->target != PIPE_TEXTURE_2D || src->texture->last_level != 0) { - struct pipe_texture texTemp; - struct pipe_texture *tex; + struct pipe_resource texTemp; + struct pipe_resource *tex; struct pipe_sampler_view sv_templ; struct pipe_surface *texSurf; const int srcLeft = MIN2(srcX0, srcX1); @@ -376,7 +376,7 @@ util_blit_pixels_writemask(struct blit_state *ctx, texTemp.height0 = srcH; texTemp.depth0 = 1; - tex = screen->texture_create(screen, &texTemp); + tex = screen->resource_create(screen, &texTemp); if (!tex) return; @@ -540,7 +540,7 @@ util_blit_pixels(struct blit_state *ctx, */ void util_blit_flush( struct blit_state *ctx ) { - pipe_buffer_reference(&ctx->vbuf, NULL); + pipe_resource_reference(&ctx->vbuf, NULL); ctx->vbuf_slot = 0; } diff --git a/src/gallium/auxiliary/util/u_blit.h b/src/gallium/auxiliary/util/u_blit.h index 1ebe65b455..464ff9aace 100644 --- a/src/gallium/auxiliary/util/u_blit.h +++ b/src/gallium/auxiliary/util/u_blit.h @@ -37,7 +37,7 @@ extern "C" { struct pipe_context; struct pipe_surface; -struct pipe_texture; +struct pipe_resource; struct cso_context; diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c index 1692987e8e..b4a49b7213 100644 --- a/src/gallium/auxiliary/util/u_blitter.c +++ b/src/gallium/auxiliary/util/u_blitter.c @@ -56,7 +56,7 @@ struct blitter_context_priv struct blitter_context blitter; struct pipe_context *pipe; /**< pipe context */ - struct pipe_buffer *vbuf; /**< quad */ + struct pipe_resource *vbuf; /**< quad */ float vertices[4][2][4]; /**< {pos, color} or {pos, texcoord} */ @@ -259,7 +259,7 @@ void util_blitter_destroy(struct blitter_context *blitter) pipe_sampler_view_reference(&ctx->sampler_view, NULL); } - pipe_buffer_reference(&ctx->vbuf, NULL); + pipe_resource_reference(&ctx->vbuf, NULL); FREE(ctx); } @@ -451,7 +451,7 @@ static void blitter_draw_quad(struct blitter_context_priv *ctx) struct pipe_context *pipe = ctx->pipe; /* write vertices and draw them */ - pipe_buffer_write(pipe->screen, ctx->vbuf, + pipe_buffer_write(pipe, ctx->vbuf, 0, sizeof(ctx->vertices), ctx->vertices); util_draw_vertex_buffer(pipe, ctx->vbuf, 0, PIPE_PRIM_TRIANGLE_FAN, @@ -714,8 +714,8 @@ static void util_blitter_overlap_copy(struct blitter_context *blitter, struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_texture texTemp; - struct pipe_texture *texture; + struct pipe_resource texTemp; + struct pipe_resource *texture; struct pipe_surface *tex_surf; /* check whether the states are properly saved */ @@ -729,7 +729,7 @@ static void util_blitter_overlap_copy(struct blitter_context *blitter, texTemp.height0 = height; texTemp.depth0 = 1; - texture = screen->texture_create(screen, &texTemp); + texture = screen->resource_create(screen, &texTemp); if (!texture) return; @@ -747,7 +747,7 @@ static void util_blitter_overlap_copy(struct blitter_context *blitter, width, height, FALSE); pipe_surface_reference(&tex_surf, NULL); - pipe_texture_reference(&texture, NULL); + pipe_resource_reference(&texture, NULL); blitter_restore_CSOs(ctx); } diff --git a/src/gallium/auxiliary/util/u_box.h b/src/gallium/auxiliary/util/u_box.h new file mode 100644 index 0000000000..fe694a9899 --- /dev/null +++ b/src/gallium/auxiliary/util/u_box.h @@ -0,0 +1,73 @@ +#ifndef UTIL_BOX_INLINES_H +#define UTIL_BOX_INLINES_H + +#include "pipe/p_state.h" + +static INLINE +void u_box_1d( unsigned x, + unsigned w, + struct pipe_box *box ) +{ + box->x = x; + box->y = 0; + box->z = 0; + box->width = w; + box->height = 1; + box->depth = 1; +} + +static INLINE +void u_box_2d( unsigned x, + unsigned y, + unsigned w, + unsigned h, + struct pipe_box *box ) +{ + box->x = x; + box->y = y; + box->z = 0; + box->width = w; + box->height = h; + box->depth = 1; +} + +static INLINE +void u_box_orgin_2d( unsigned w, + unsigned h, + struct pipe_box *box ) +{ + box->x = 0; + box->y = 0; + box->z = 0; + box->width = w; + box->height = h; + box->depth = 1; +} + +static INLINE +void u_box_2d_zslice( unsigned x, + unsigned y, + unsigned z, + unsigned w, + unsigned h, + struct pipe_box *box ) +{ + box->x = x; + box->y = y; + box->z = z; + box->width = w; + box->height = h; + box->depth = 1; +} + +static INLINE +struct pipe_subresource u_subresource( unsigned face, + unsigned level ) +{ + struct pipe_subresource subresource; + subresource.face = face; + subresource.level = level; + return subresource; +} + +#endif diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c index e997cfa8a3..8373fe99e2 100644 --- a/src/gallium/auxiliary/util/u_debug.c +++ b/src/gallium/auxiliary/util/u_debug.c @@ -425,7 +425,7 @@ void debug_dump_surface(struct pipe_context *pipe, const char *prefix, struct pipe_surface *surface) { - struct pipe_texture *texture; + struct pipe_resource *texture; struct pipe_transfer *transfer; void *data; @@ -440,7 +440,7 @@ void debug_dump_surface(struct pipe_context *pipe, */ texture = surface->texture; - transfer = pipe->get_tex_transfer(pipe, texture, surface->face, + transfer = pipe_get_transfer(pipe, texture, surface->face, surface->level, surface->zslice, PIPE_TRANSFER_READ, 0, 0, surface->width, surface->height); @@ -452,20 +452,20 @@ void debug_dump_surface(struct pipe_context *pipe, debug_dump_image(prefix, texture->format, util_format_get_blocksize(texture->format), - util_format_get_nblocksx(texture->format, transfer->width), - util_format_get_nblocksy(texture->format, transfer->height), + util_format_get_nblocksx(texture->format, surface->width), + util_format_get_nblocksy(texture->format, surface->height), transfer->stride, data); pipe->transfer_unmap(pipe, transfer); error: - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } void debug_dump_texture(struct pipe_context *pipe, const char *prefix, - struct pipe_texture *texture) + struct pipe_resource *texture) { struct pipe_surface *surface; struct pipe_screen *screen; @@ -523,16 +523,16 @@ debug_dump_surface_bmp(struct pipe_context *pipe, { #ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT struct pipe_transfer *transfer; - struct pipe_texture *texture = surface->texture; + struct pipe_resource *texture = surface->texture; - transfer = pipe->get_tex_transfer(pipe, texture, surface->face, - surface->level, surface->zslice, - PIPE_TRANSFER_READ, 0, 0, surface->width, - surface->height); + transfer = pipe_get_transfer(pipe, texture, surface->face, + surface->level, surface->zslice, + PIPE_TRANSFER_READ, 0, 0, surface->width, + surface->height); debug_dump_transfer_bmp(pipe, filename, transfer); - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); #endif } @@ -547,17 +547,20 @@ debug_dump_transfer_bmp(struct pipe_context *pipe, if (!transfer) goto error1; - rgba = MALLOC(transfer->width*transfer->height*4*sizeof(float)); + rgba = MALLOC(transfer->box.width * + transfer->box.height * + transfer->box.depth * + 4*sizeof(float)); if(!rgba) goto error1; pipe_get_tile_rgba(pipe, transfer, 0, 0, - transfer->width, transfer->height, + transfer->box.width, transfer->box.height, rgba); debug_dump_float_rgba_bmp(filename, - transfer->width, transfer->height, - rgba, transfer->width); + transfer->box.width, transfer->box.height, + rgba, transfer->box.width); FREE(rgba); error1: diff --git a/src/gallium/auxiliary/util/u_debug.h b/src/gallium/auxiliary/util/u_debug.h index 98addeb372..b6d0b508e3 100644 --- a/src/gallium/auxiliary/util/u_debug.h +++ b/src/gallium/auxiliary/util/u_debug.h @@ -315,7 +315,7 @@ debug_memory_end(unsigned long beginning); struct pipe_context; struct pipe_surface; struct pipe_transfer; -struct pipe_texture; +struct pipe_resource; void debug_dump_image(const char *prefix, unsigned format, unsigned cpp, @@ -327,7 +327,7 @@ void debug_dump_surface(struct pipe_context *pipe, struct pipe_surface *surface); void debug_dump_texture(struct pipe_context *pipe, const char *prefix, - struct pipe_texture *texture); + struct pipe_resource *texture); void debug_dump_surface_bmp(struct pipe_context *pipe, const char *filename, struct pipe_surface *surface); diff --git a/src/gallium/auxiliary/util/u_draw_quad.c b/src/gallium/auxiliary/util/u_draw_quad.c index 8c194102bf..a6b9d0f19e 100644 --- a/src/gallium/auxiliary/util/u_draw_quad.c +++ b/src/gallium/auxiliary/util/u_draw_quad.c @@ -30,6 +30,7 @@ #include "pipe/p_defines.h" #include "util/u_inlines.h" #include "util/u_draw_quad.h" +#include "util/u_memory.h" /** @@ -38,7 +39,7 @@ */ void util_draw_vertex_buffer(struct pipe_context *pipe, - struct pipe_buffer *vbuf, + struct pipe_resource *vbuf, uint offset, uint prim_type, uint num_verts, @@ -66,60 +67,63 @@ util_draw_vertex_buffer(struct pipe_context *pipe, /** * Draw screen-aligned textured quad. - * Note: this function allocs/destroys a vertex buffer and isn't especially - * efficient. + * Note: this isn't especially efficient. */ void util_draw_texquad(struct pipe_context *pipe, float x0, float y0, float x1, float y1, float z) { - struct pipe_buffer *vbuf; - uint numAttribs = 2, vertexBytes, i, j; - - vertexBytes = 4 * (4 * numAttribs * sizeof(float)); - - /* XXX create one-time */ - vbuf = pipe_buffer_create(pipe->screen, 32, - PIPE_BUFFER_USAGE_VERTEX, vertexBytes); - if (vbuf) { - float *v = (float *) pipe_buffer_map(pipe->screen, vbuf, - PIPE_BUFFER_USAGE_CPU_WRITE); - if (v) { - /* - * Load vertex buffer - */ - for (i = j = 0; i < 4; i++) { - v[j + 2] = z; /* z */ - v[j + 3] = 1.0; /* w */ - v[j + 6] = 0.0; /* r */ - v[j + 7] = 1.0; /* q */ - j += 8; - } - - v[0] = x0; - v[1] = y0; - v[4] = 0.0; /*s*/ - v[5] = 0.0; /*t*/ - - v[8] = x1; - v[9] = y0; - v[12] = 1.0; - v[13] = 0.0; - - v[16] = x1; - v[17] = y1; - v[20] = 1.0; - v[21] = 1.0; - - v[24] = x0; - v[25] = y1; - v[28] = 0.0; - v[29] = 1.0; - - pipe_buffer_unmap(pipe->screen, vbuf); - util_draw_vertex_buffer(pipe, vbuf, 0, PIPE_PRIM_TRIANGLE_FAN, 4, 2); - } - - pipe_buffer_reference(&vbuf, NULL); + uint numAttribs = 2, i, j; + uint vertexBytes = 4 * (4 * numAttribs * sizeof(float)); + struct pipe_resource *vbuf = NULL; + uint *v = NULL; + + v = MALLOC(vertexBytes); + if (v == NULL) + goto out; + + /* + * Load vertex buffer + */ + for (i = j = 0; i < 4; i++) { + v[j + 2] = z; /* z */ + v[j + 3] = 1.0; /* w */ + v[j + 6] = 0.0; /* r */ + v[j + 7] = 1.0; /* q */ + j += 8; } + + v[0] = x0; + v[1] = y0; + v[4] = 0.0; /*s*/ + v[5] = 0.0; /*t*/ + + v[8] = x1; + v[9] = y0; + v[12] = 1.0; + v[13] = 0.0; + + v[16] = x1; + v[17] = y1; + v[20] = 1.0; + v[21] = 1.0; + + v[24] = x0; + v[25] = y1; + v[28] = 0.0; + v[29] = 1.0; + + vbuf = pipe_user_buffer_create(pipe->screen, v, vertexBytes, + PIPE_BUFFER_USAGE_VERTEX); + if (!vbuf) + goto out; + + util_draw_vertex_buffer(pipe, vbuf, 0, PIPE_PRIM_TRIANGLE_FAN, 4, 2); + +out: + if (vbuf) + pipe_resource_reference(&vbuf, NULL); + + if (v) + FREE(v); } diff --git a/src/gallium/auxiliary/util/u_draw_quad.h b/src/gallium/auxiliary/util/u_draw_quad.h index 00d3f5b715..42eb184428 100644 --- a/src/gallium/auxiliary/util/u_draw_quad.h +++ b/src/gallium/auxiliary/util/u_draw_quad.h @@ -33,11 +33,11 @@ extern "C" { #endif -struct pipe_buffer; +struct pipe_resource; extern void util_draw_vertex_buffer(struct pipe_context *pipe, - struct pipe_buffer *vbuf, uint offset, + struct pipe_resource *vbuf, uint offset, uint num_attribs, uint num_verts, uint prim_type); diff --git a/src/gallium/auxiliary/util/u_dump.h b/src/gallium/auxiliary/util/u_dump.h index 379f18ef38..bdc73ac47d 100644 --- a/src/gallium/auxiliary/util/u_dump.h +++ b/src/gallium/auxiliary/util/u_dump.h @@ -92,7 +92,7 @@ util_dump_tex_filter(unsigned value, boolean shortened); void util_dump_template(struct os_stream *stream, - const struct pipe_texture *templat); + const struct pipe_resource *templat); void util_dump_rasterizer_state(struct os_stream *stream, diff --git a/src/gallium/auxiliary/util/u_dump_state.c b/src/gallium/auxiliary/util/u_dump_state.c index 52cf3ef4ce..08557d5553 100644 --- a/src/gallium/auxiliary/util/u_dump_state.c +++ b/src/gallium/auxiliary/util/u_dump_state.c @@ -255,7 +255,7 @@ util_dump_enum_func(struct os_stream *stream, unsigned value) void -util_dump_template(struct os_stream *stream, const struct pipe_texture *templat) +util_dump_template(struct os_stream *stream, const struct pipe_resource *templat) { if(!templat) { util_dump_null(stream); @@ -653,16 +653,13 @@ util_dump_transfer(struct os_stream *stream, const struct pipe_transfer *state) util_dump_struct_begin(stream, "pipe_transfer"); - util_dump_member(stream, uint, state, width); - util_dump_member(stream, uint, state, height); + util_dump_member(stream, ptr, state, resource); +// util_dump_member(stream, uint, state, box); util_dump_member(stream, uint, state, stride); - util_dump_member(stream, uint, state, usage); + util_dump_member(stream, uint, state, slice_stride); - util_dump_member(stream, ptr, state, texture); - util_dump_member(stream, uint, state, face); - util_dump_member(stream, uint, state, level); - util_dump_member(stream, uint, state, zslice); +// util_dump_member(stream, ptr, state, data); util_dump_struct_end(stream); } diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index 61d64cff6d..689a5ab207 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -67,7 +67,7 @@ struct gen_mipmap_state void *vs; void *fs2d, *fsCube; - struct pipe_buffer *vbuf; /**< quad vertices */ + struct pipe_resource *vbuf; /**< quad vertices */ unsigned vbuf_slot; float vertices[4][2][4]; /**< vertex/texcoords for quad */ @@ -1115,7 +1115,7 @@ reduce_3d(enum pipe_format pformat, static void make_1d_mipmap(struct gen_mipmap_state *ctx, - struct pipe_texture *pt, + struct pipe_resource *pt, uint face, uint baseLevel, uint lastLevel) { struct pipe_context *pipe = ctx->pipe; @@ -1127,11 +1127,11 @@ make_1d_mipmap(struct gen_mipmap_state *ctx, struct pipe_transfer *srcTrans, *dstTrans; void *srcMap, *dstMap; - srcTrans = pipe->get_tex_transfer(pipe, pt, face, srcLevel, zslice, + srcTrans = pipe_get_transfer(pipe, pt, face, srcLevel, zslice, PIPE_TRANSFER_READ, 0, 0, u_minify(pt->width0, srcLevel), u_minify(pt->height0, srcLevel)); - dstTrans = pipe->get_tex_transfer(pipe, pt, face, dstLevel, zslice, + dstTrans = pipe_get_transfer(pipe, pt, face, dstLevel, zslice, PIPE_TRANSFER_WRITE, 0, 0, u_minify(pt->width0, dstLevel), u_minify(pt->height0, dstLevel)); @@ -1140,21 +1140,21 @@ make_1d_mipmap(struct gen_mipmap_state *ctx, dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans); reduce_1d(pt->format, - srcTrans->width, srcMap, - dstTrans->width, dstMap); + srcTrans->box.width, srcMap, + dstTrans->box.width, dstMap); pipe->transfer_unmap(pipe, srcTrans); pipe->transfer_unmap(pipe, dstTrans); - pipe->tex_transfer_destroy(pipe, srcTrans); - pipe->tex_transfer_destroy(pipe, dstTrans); + pipe->transfer_destroy(pipe, srcTrans); + pipe->transfer_destroy(pipe, dstTrans); } } static void make_2d_mipmap(struct gen_mipmap_state *ctx, - struct pipe_texture *pt, + struct pipe_resource *pt, uint face, uint baseLevel, uint lastLevel) { struct pipe_context *pipe = ctx->pipe; @@ -1169,36 +1169,36 @@ make_2d_mipmap(struct gen_mipmap_state *ctx, struct pipe_transfer *srcTrans, *dstTrans; ubyte *srcMap, *dstMap; - srcTrans = pipe->get_tex_transfer(pipe, pt, face, srcLevel, zslice, - PIPE_TRANSFER_READ, 0, 0, - u_minify(pt->width0, srcLevel), - u_minify(pt->height0, srcLevel)); - dstTrans = pipe->get_tex_transfer(pipe, pt, face, dstLevel, zslice, - PIPE_TRANSFER_WRITE, 0, 0, - u_minify(pt->width0, dstLevel), - u_minify(pt->height0, dstLevel)); + srcTrans = pipe_get_transfer(pipe, pt, face, srcLevel, zslice, + PIPE_TRANSFER_READ, 0, 0, + u_minify(pt->width0, srcLevel), + u_minify(pt->height0, srcLevel)); + dstTrans = pipe_get_transfer(pipe, pt, face, dstLevel, zslice, + PIPE_TRANSFER_WRITE, 0, 0, + u_minify(pt->width0, dstLevel), + u_minify(pt->height0, dstLevel)); srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans); dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans); reduce_2d(pt->format, - srcTrans->width, srcTrans->height, + srcTrans->box.width, srcTrans->box.height, srcTrans->stride, srcMap, - dstTrans->width, dstTrans->height, + dstTrans->box.width, dstTrans->box.height, dstTrans->stride, dstMap); pipe->transfer_unmap(pipe, srcTrans); pipe->transfer_unmap(pipe, dstTrans); - pipe->tex_transfer_destroy(pipe, srcTrans); - pipe->tex_transfer_destroy(pipe, dstTrans); + pipe->transfer_destroy(pipe, srcTrans); + pipe->transfer_destroy(pipe, dstTrans); } } static void make_3d_mipmap(struct gen_mipmap_state *ctx, - struct pipe_texture *pt, + struct pipe_resource *pt, uint face, uint baseLevel, uint lastLevel) { #if 0 @@ -1214,11 +1214,11 @@ make_3d_mipmap(struct gen_mipmap_state *ctx, struct pipe_transfer *srcTrans, *dstTrans; ubyte *srcMap, *dstMap; - srcTrans = pipe->get_tex_transfer(pipe, pt, face, srcLevel, zslice, + srcTrans = pipe->get_transfer(pipe, pt, face, srcLevel, zslice, PIPE_TRANSFER_READ, 0, 0, u_minify(pt->width0, srcLevel), u_minify(pt->height0, srcLevel)); - dstTrans = pipe->get_tex_transfer(pipe, pt, face, dstLevel, zslice, + dstTrans = pipe->get_transfer(pipe, pt, face, dstLevel, zslice, PIPE_TRANSFER_WRITE, 0, 0, u_minify(pt->width0, dstLevel), u_minify(pt->height0, dstLevel)); @@ -1235,8 +1235,8 @@ make_3d_mipmap(struct gen_mipmap_state *ctx, pipe->transfer_unmap(pipe, srcTrans); pipe->transfer_unmap(pipe, dstTrans); - pipe->tex_transfer_destroy(pipe, srcTrans); - pipe->tex_transfer_destroy(pipe, dstTrans); + pipe->transfer_destroy(pipe, srcTrans); + pipe->transfer_destroy(pipe, dstTrans); } #else (void) reduce_3d; @@ -1246,7 +1246,7 @@ make_3d_mipmap(struct gen_mipmap_state *ctx, static void fallback_gen_mipmap(struct gen_mipmap_state *ctx, - struct pipe_texture *pt, + struct pipe_resource *pt, uint face, uint baseLevel, uint lastLevel) { switch (pt->target) { @@ -1419,7 +1419,7 @@ set_vertex_data(struct gen_mipmap_state *ctx, offset = get_next_slot( ctx ); - pipe_buffer_write_nooverlap(ctx->pipe->screen, ctx->vbuf, + pipe_buffer_write_nooverlap(ctx->pipe, ctx->vbuf, offset, sizeof(ctx->vertices), ctx->vertices); return offset; @@ -1439,7 +1439,7 @@ util_destroy_gen_mipmap(struct gen_mipmap_state *ctx) pipe->delete_fs_state(pipe, ctx->fs2d); pipe->delete_fs_state(pipe, ctx->fsCube); - pipe_buffer_reference(&ctx->vbuf, NULL); + pipe_resource_reference(&ctx->vbuf, NULL); FREE(ctx); } @@ -1451,7 +1451,7 @@ util_destroy_gen_mipmap(struct gen_mipmap_state *ctx) */ void util_gen_mipmap_flush( struct gen_mipmap_state *ctx ) { - pipe_buffer_reference(&ctx->vbuf, NULL); + pipe_resource_reference(&ctx->vbuf, NULL); ctx->vbuf_slot = 0; } diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.h b/src/gallium/auxiliary/util/u_gen_mipmap.h index 35ac9daeaa..a7502b9982 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.h +++ b/src/gallium/auxiliary/util/u_gen_mipmap.h @@ -37,7 +37,7 @@ extern "C" { struct pipe_context; -struct pipe_texture; +struct pipe_resource; struct cso_context; struct gen_mipmap_state; diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h index e22ab188e1..f38f419d5a 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 @@ -87,18 +88,6 @@ pipe_reference(struct pipe_reference *ptr, struct pipe_reference *reference) return destroy; } -static INLINE void -pipe_buffer_reference(struct pipe_buffer **ptr, struct pipe_buffer *buf) -{ - struct pipe_buffer *old_buf; - - assert(ptr); - old_buf = *ptr; - - if (pipe_reference(&(*ptr)->reference, &buf->reference)) - old_buf->screen->buffer_destroy(old_buf); - *ptr = buf; -} static INLINE void pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) @@ -110,16 +99,18 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) *ptr = surf; } + static INLINE void -pipe_texture_reference(struct pipe_texture **ptr, struct pipe_texture *tex) +pipe_resource_reference(struct pipe_resource **ptr, struct pipe_resource *tex) { - struct pipe_texture *old_tex = *ptr; + 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->screen, old_tex); *ptr = tex; } + static INLINE void pipe_sampler_view_reference(struct pipe_sampler_view **ptr, struct pipe_sampler_view *view) { @@ -135,91 +126,113 @@ pipe_sampler_view_reference(struct pipe_sampler_view **ptr, struct pipe_sampler_ * Convenience wrappers for screen buffer functions. */ -static INLINE struct pipe_buffer * +static INLINE struct pipe_resource * pipe_buffer_create( struct pipe_screen *screen, unsigned alignment, unsigned usage, unsigned size ) { - return screen->buffer_create(screen, alignment, usage, size); + struct pipe_resource buffer; + memset(&buffer, 0, sizeof buffer); + buffer.target = PIPE_BUFFER; + buffer.format = PIPE_FORMAT_R8_UNORM; /* want TYPELESS or similar */ + buffer.usage = usage; + buffer.width0 = size; + buffer.height0 = 1; + buffer.depth0 = 1; + return screen->resource_create(screen, &buffer); } -static INLINE struct pipe_buffer * -pipe_user_buffer_create( struct pipe_screen *screen, void *ptr, unsigned size ) + +static INLINE struct pipe_resource * +pipe_user_buffer_create( struct pipe_screen *screen, void *ptr, unsigned size, + unsigned usage ) { - return screen->user_buffer_create(screen, ptr, size); + return screen->user_buffer_create(screen, ptr, size, usage); } 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_resource *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->width0); + assert(offset + length <= buffer->width0); + assert(length); + + u_box_1d(offset, length, &box); + + *transfer = pipe->get_transfer( pipe, + buffer, + 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_resource *buffer, + unsigned usage, + struct pipe_transfer **transfer) { - screen->buffer_unmap(screen, buf); + return pipe_buffer_map_range(pipe, buffer, 0, buffer->width0, usage, 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_resource *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, - struct pipe_buffer *buf, - unsigned offset, unsigned size, +pipe_buffer_write(struct pipe_context *pipe, + struct pipe_resource *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); - 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; + + u_box_1d(offset, size, &box); + + pipe->transfer_inline_write( pipe, + buf, + u_subresource(0,0), + PIPE_TRANSFER_WRITE, + &box, + data, + size, + 0); } /** @@ -229,86 +242,87 @@ pipe_buffer_write(struct pipe_screen *screen, * been written before. */ static INLINE void -pipe_buffer_write_nooverlap(struct pipe_screen *screen, - struct pipe_buffer *buf, +pipe_buffer_write_nooverlap(struct pipe_context *pipe, + struct pipe_resource *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; + + u_box_1d(offset, size, &box); + + pipe->transfer_inline_write(pipe, + buf, + u_subresource(0,0), + (PIPE_TRANSFER_WRITE | + PIPE_TRANSFER_NOOVERWRITE), + &box, + data, + 0, 0); } static INLINE void -pipe_buffer_read(struct pipe_screen *screen, - struct pipe_buffer *buf, - unsigned offset, unsigned size, +pipe_buffer_read(struct pipe_context *pipe, + struct pipe_resource *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_transfer *src_transfer; + ubyte *map; + + map = (ubyte *) pipe_buffer_map_range(pipe, + buf, + offset, size, + PIPE_TRANSFER_READ, + &src_transfer); + + if (map) + memcpy(data, map, size); + + pipe_buffer_unmap(pipe, buf, src_transfer); +} + +static INLINE struct pipe_transfer * +pipe_get_transfer( struct pipe_context *context, + struct pipe_resource *resource, + unsigned face, unsigned level, + unsigned zslice, + enum pipe_transfer_usage usage, + unsigned x, unsigned y, + unsigned w, unsigned h) +{ + struct pipe_box box; + u_box_2d_zslice( x, y, zslice, w, h, &box ); + return context->get_transfer( context, + resource, + u_subresource(face, level), + usage, + &box ); } 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 } diff --git a/src/gallium/auxiliary/util/u_rect.c b/src/gallium/auxiliary/util/u_rect.c index e73797f1b7..098cdfd58b 100644 --- a/src/gallium/auxiliary/util/u_rect.c +++ b/src/gallium/auxiliary/util/u_rect.c @@ -35,6 +35,7 @@ #include "pipe/p_context.h" #include "pipe/p_screen.h" #include "util/u_format.h" +#include "util/u_inlines.h" #include "util/u_rect.h" @@ -181,21 +182,21 @@ util_surface_copy(struct pipe_context *pipe, src_format = src->texture->format; dst_format = dst->texture->format; - src_trans = pipe->get_tex_transfer(pipe, - src->texture, - src->face, - src->level, - src->zslice, - PIPE_TRANSFER_READ, - src_x, src_y, w, h); - - dst_trans = pipe->get_tex_transfer(pipe, - dst->texture, - dst->face, - dst->level, - dst->zslice, - PIPE_TRANSFER_WRITE, - dst_x, dst_y, w, h); + src_trans = pipe_get_transfer(pipe, + src->texture, + src->face, + src->level, + src->zslice, + PIPE_TRANSFER_READ, + src_x, src_y, w, h); + + dst_trans = pipe_get_transfer(pipe, + dst->texture, + dst->face, + dst->level, + dst->zslice, + PIPE_TRANSFER_WRITE, + dst_x, dst_y, w, h); assert(util_format_get_blocksize(dst_format) == util_format_get_blocksize(src_format)); assert(util_format_get_blockwidth(dst_format) == util_format_get_blockwidth(src_format)); @@ -223,8 +224,8 @@ util_surface_copy(struct pipe_context *pipe, pipe->transfer_unmap(pipe, src_trans); pipe->transfer_unmap(pipe, dst_trans); - pipe->tex_transfer_destroy(pipe, src_trans); - pipe->tex_transfer_destroy(pipe, dst_trans); + pipe->transfer_destroy(pipe, src_trans); + pipe->transfer_destroy(pipe, dst_trans); } @@ -248,13 +249,13 @@ util_surface_fill(struct pipe_context *pipe, assert(dst->texture); if (!dst->texture) return; - dst_trans = pipe->get_tex_transfer(pipe, - dst->texture, - dst->face, - dst->level, - dst->zslice, - PIPE_TRANSFER_WRITE, - dstx, dsty, width, height); + dst_trans = pipe_get_transfer(pipe, + dst->texture, + dst->face, + dst->level, + dst->zslice, + PIPE_TRANSFER_WRITE, + dstx, dsty, width, height); dst_map = pipe->transfer_map(pipe, dst_trans); @@ -263,37 +264,38 @@ util_surface_fill(struct pipe_context *pipe, if (dst_map) { assert(dst_trans->stride > 0); - switch (util_format_get_blocksize(dst_trans->texture->format)) { + switch (util_format_get_blocksize(dst->texture->format)) { case 1: case 2: case 4: - util_fill_rect(dst_map, dst_trans->texture->format, dst_trans->stride, + util_fill_rect(dst_map, dst->texture->format, + dst_trans->stride, 0, 0, width, height, value); break; case 8: - { - /* expand the 4-byte clear value to an 8-byte value */ - ushort *row = (ushort *) dst_map; - ushort val0 = UBYTE_TO_USHORT((value >> 0) & 0xff); - ushort val1 = UBYTE_TO_USHORT((value >> 8) & 0xff); - ushort val2 = UBYTE_TO_USHORT((value >> 16) & 0xff); - ushort val3 = UBYTE_TO_USHORT((value >> 24) & 0xff); - unsigned i, j; - val0 = (val0 << 8) | val0; - val1 = (val1 << 8) | val1; - val2 = (val2 << 8) | val2; - val3 = (val3 << 8) | val3; - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - row[j*4+0] = val0; - row[j*4+1] = val1; - row[j*4+2] = val2; - row[j*4+3] = val3; - } - row += dst_trans->stride/2; - } - } - break; + { + /* expand the 4-byte clear value to an 8-byte value */ + ushort *row = (ushort *) dst_map; + ushort val0 = UBYTE_TO_USHORT((value >> 0) & 0xff); + ushort val1 = UBYTE_TO_USHORT((value >> 8) & 0xff); + ushort val2 = UBYTE_TO_USHORT((value >> 16) & 0xff); + ushort val3 = UBYTE_TO_USHORT((value >> 24) & 0xff); + unsigned i, j; + val0 = (val0 << 8) | val0; + val1 = (val1 << 8) | val1; + val2 = (val2 << 8) | val2; + val3 = (val3 << 8) | val3; + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + row[j*4+0] = val0; + row[j*4+1] = val1; + row[j*4+2] = val2; + row[j*4+3] = val3; + } + row += dst_trans->stride/2; + } + } + break; default: assert(0); break; @@ -301,5 +303,5 @@ util_surface_fill(struct pipe_context *pipe, } pipe->transfer_unmap(pipe, dst_trans); - pipe->tex_transfer_destroy(pipe, dst_trans); + pipe->transfer_destroy(pipe, dst_trans); } diff --git a/src/gallium/auxiliary/util/u_resource.c b/src/gallium/auxiliary/util/u_resource.c new file mode 100644 index 0000000000..e0fa2dc808 --- /dev/null +++ b/src/gallium/auxiliary/util/u_resource.c @@ -0,0 +1,97 @@ + + +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_transfer.h" + +static INLINE struct u_resource * +u_resource( struct pipe_resource *res ) +{ + return (struct u_resource *)res; +} + +boolean u_resource_get_handle_vtbl(struct pipe_screen *screen, + struct pipe_resource *resource, + struct winsys_handle *handle) +{ + struct u_resource *ur = u_resource(resource); + return ur->vtbl->resource_get_handle(screen, resource, handle); +} + +void u_resource_destroy_vtbl(struct pipe_screen *screen, + struct pipe_resource *resource) +{ + struct u_resource *ur = u_resource(resource); + ur->vtbl->resource_destroy(screen, resource); +} + +unsigned u_is_resource_referenced_vtbl( struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned face, unsigned level) +{ + struct u_resource *ur = u_resource(resource); + return ur->vtbl->is_resource_referenced(pipe, resource, face, level); +} + +struct pipe_transfer *u_get_transfer_vtbl(struct pipe_context *context, + struct pipe_resource *resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box) +{ + struct u_resource *ur = u_resource(resource); + return ur->vtbl->get_transfer(context, resource, sr, usage, box); +} + +void u_transfer_destroy_vtbl(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct u_resource *ur = u_resource(transfer->resource); + ur->vtbl->transfer_destroy(pipe, transfer); +} + +void *u_transfer_map_vtbl( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + struct u_resource *ur = u_resource(transfer->resource); + return ur->vtbl->transfer_map(pipe, transfer); +} + +void u_transfer_flush_region_vtbl( struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box) +{ + struct u_resource *ur = u_resource(transfer->resource); + ur->vtbl->transfer_flush_region(pipe, transfer, box); +} + +void u_transfer_unmap_vtbl( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + struct u_resource *ur = u_resource(transfer->resource); + ur->vtbl->transfer_unmap(pipe, transfer); +} + +void u_transfer_inline_write_vtbl( struct pipe_context *pipe, + struct pipe_resource *resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned slice_stride) +{ + struct u_resource *ur = u_resource(resource); + ur->vtbl->transfer_inline_write(pipe, + resource, + sr, + usage, + box, + data, + stride, + slice_stride); +} + + + + diff --git a/src/gallium/auxiliary/util/u_sampler.c b/src/gallium/auxiliary/util/u_sampler.c index 4d8f861ce4..e77f562ea2 100644 --- a/src/gallium/auxiliary/util/u_sampler.c +++ b/src/gallium/auxiliary/util/u_sampler.c @@ -32,7 +32,7 @@ static void default_template(struct pipe_sampler_view *view, - const struct pipe_texture *texture, + const struct pipe_resource *texture, enum pipe_format format, unsigned expand_green_blue) { @@ -77,7 +77,7 @@ default_template(struct pipe_sampler_view *view, void u_sampler_view_default_template(struct pipe_sampler_view *view, - const struct pipe_texture *texture, + const struct pipe_resource *texture, enum pipe_format format) { /* Expand to (0, 0, 0, 1) */ @@ -89,7 +89,7 @@ u_sampler_view_default_template(struct pipe_sampler_view *view, void u_sampler_view_default_dx9_template(struct pipe_sampler_view *view, - const struct pipe_texture *texture, + const struct pipe_resource *texture, enum pipe_format format) { /* Expand to (1, 1, 1, 1) */ diff --git a/src/gallium/auxiliary/util/u_sampler.h b/src/gallium/auxiliary/util/u_sampler.h index bdd061c851..f3dad7417e 100644 --- a/src/gallium/auxiliary/util/u_sampler.h +++ b/src/gallium/auxiliary/util/u_sampler.h @@ -41,12 +41,12 @@ extern "C" { void u_sampler_view_default_template(struct pipe_sampler_view *view, - const struct pipe_texture *texture, + const struct pipe_resource *texture, enum pipe_format format); void u_sampler_view_default_dx9_template(struct pipe_sampler_view *view, - const struct pipe_texture *texture, + const struct pipe_resource *texture, enum pipe_format format); diff --git a/src/gallium/auxiliary/util/u_simple_screen.c b/src/gallium/auxiliary/util/u_simple_screen.c deleted file mode 100644 index 9203cb6580..0000000000 --- a/src/gallium/auxiliary/util/u_simple_screen.c +++ /dev/null @@ -1,137 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include "u_simple_screen.h" - -#include "pipe/p_screen.h" -#include "pipe/p_state.h" -#include "util/u_simple_screen.h" - - -static struct pipe_buffer * -pass_buffer_create(struct pipe_screen *screen, - unsigned alignment, - unsigned usage, - unsigned size) -{ - struct pipe_buffer *buffer = - screen->winsys->buffer_create(screen->winsys, alignment, usage, size); - - buffer->screen = screen; - - return buffer; -} - -static struct pipe_buffer * -pass_user_buffer_create(struct pipe_screen *screen, - void *ptr, - unsigned bytes) -{ - struct pipe_buffer *buffer = - screen->winsys->user_buffer_create(screen->winsys, ptr, bytes); - - buffer->screen = screen; - - return buffer; -} - - - -static void * -pass_buffer_map(struct pipe_screen *screen, - struct pipe_buffer *buf, - unsigned usage) -{ - return screen->winsys->buffer_map(screen->winsys, buf, usage); -} - -static void -pass_buffer_unmap(struct pipe_screen *screen, - struct pipe_buffer *buf) -{ - screen->winsys->buffer_unmap(screen->winsys, buf); -} - -static void -pass_buffer_destroy(struct pipe_buffer *buf) -{ - buf->screen->winsys->buffer_destroy(buf); -} - - -static void -pass_flush_frontbuffer(struct pipe_screen *screen, - struct pipe_surface *surf, - void *context_private) -{ - screen->winsys->flush_frontbuffer(screen->winsys, surf, context_private); -} - -static void -pass_fence_reference(struct pipe_screen *screen, - struct pipe_fence_handle **ptr, - struct pipe_fence_handle *fence) -{ - screen->winsys->fence_reference(screen->winsys, ptr, fence); -} - -static int -pass_fence_signalled(struct pipe_screen *screen, - struct pipe_fence_handle *fence, - unsigned flag) -{ - return screen->winsys->fence_signalled(screen->winsys, fence, flag); -} - -static int -pass_fence_finish(struct pipe_screen *screen, - struct pipe_fence_handle *fence, - unsigned flag) -{ - return screen->winsys->fence_finish(screen->winsys, fence, flag); -} - -void -u_simple_screen_init(struct pipe_screen *screen) -{ - screen->buffer_create = pass_buffer_create; - screen->user_buffer_create = pass_user_buffer_create; - - screen->buffer_map = pass_buffer_map; - screen->buffer_unmap = pass_buffer_unmap; - screen->buffer_destroy = pass_buffer_destroy; - screen->flush_frontbuffer = pass_flush_frontbuffer; - screen->fence_reference = pass_fence_reference; - screen->fence_signalled = pass_fence_signalled; - screen->fence_finish = pass_fence_finish; -} - -const char * -u_simple_screen_winsys_name(struct pipe_screen *screen) -{ - return screen->winsys->get_name(screen->winsys); -} diff --git a/src/gallium/auxiliary/util/u_simple_screen.h b/src/gallium/auxiliary/util/u_simple_screen.h deleted file mode 100644 index bb3f5ba102..0000000000 --- a/src/gallium/auxiliary/util/u_simple_screen.h +++ /dev/null @@ -1,184 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef U_SIMPLE_SCREEN_H -#define U_SIMPLE_SCREEN_H - -#include "pipe/p_format.h" - -struct pipe_screen; -struct pipe_fence_handle; -struct pipe_surface; -struct pipe_buffer; - -/** - * Gallium3D drivers are (meant to be!) independent of both GL and the - * window system. The window system provides a buffer manager and a - * set of additional hooks for things like command buffer submission, - * etc. - * - * There clearly has to be some agreement between the window system - * driver and the hardware driver about the format of command buffers, - * etc. - */ -struct pipe_winsys -{ - void (*destroy)( struct pipe_winsys *ws ); - - /** Returns name of this winsys interface */ - const char *(*get_name)( struct pipe_winsys *ws ); - - /** - * Do any special operations to ensure buffer size is correct - */ - void (*update_buffer)( struct pipe_winsys *ws, - void *context_private ); - /** - * Do any special operations to ensure frontbuffer contents are - * displayed, eg copy fake frontbuffer. - */ - void (*flush_frontbuffer)( struct pipe_winsys *ws, - struct pipe_surface *surf, - void *context_private ); - - - /** - * Buffer management. Buffer attributes are mostly fixed over its lifetime. - * - * Remember that gallium gets to choose the interface it needs, and the - * window systems must then implement that interface (rather than the - * other way around...). - * - * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This - * usage argument is only an optimization hint, not a guarantee, therefore - * proper behavior must be observed in all circumstances. - * - * alignment indicates the client's alignment requirements, eg for - * SSE instructions. - */ - struct pipe_buffer *(*buffer_create)( struct pipe_winsys *ws, - unsigned alignment, - unsigned usage, - unsigned size ); - - /** - * Create a buffer that wraps user-space data. - * - * Effectively this schedules a delayed call to buffer_create - * followed by an upload of the data at *some point in the future*, - * or perhaps never. Basically the allocate/upload is delayed - * until the buffer is actually passed to hardware. - * - * The intention is to provide a quick way to turn regular data - * into a buffer, and secondly to avoid a copy operation if that - * data subsequently turns out to be only accessed by the CPU. - * - * Common example is OpenGL vertex buffers that are subsequently - * processed either by software TNL in the driver or by passing to - * hardware. - * - * XXX: What happens if the delayed call to buffer_create() fails? - * - * Note that ptr may be accessed at any time upto the time when the - * buffer is destroyed, so the data must not be freed before then. - */ - struct pipe_buffer *(*user_buffer_create)(struct pipe_winsys *ws, - void *ptr, - unsigned bytes); - - /** - * Allocate storage for a display target surface. - * - * Often surfaces which are meant to be blitted to the front screen (i.e., - * display targets) must be allocated with special characteristics, memory - * pools, or obtained directly from the windowing system. - * - * This callback is invoked by the pipe_screenwhen creating a texture marked - * with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET flag to get the underlying - * buffer storage. - */ - struct pipe_buffer *(*surface_buffer_create)(struct pipe_winsys *ws, - unsigned width, unsigned height, - enum pipe_format format, - unsigned usage, - unsigned tex_usage, - unsigned *stride); - - - /** - * Map the entire data store of a buffer object into the client's address. - * flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags. - */ - void *(*buffer_map)( struct pipe_winsys *ws, - struct pipe_buffer *buf, - unsigned usage ); - - void (*buffer_unmap)( struct pipe_winsys *ws, - struct pipe_buffer *buf ); - - void (*buffer_destroy)( struct pipe_buffer *buf ); - - - /** Set ptr = fence, with reference counting */ - void (*fence_reference)( struct pipe_winsys *ws, - struct pipe_fence_handle **ptr, - struct pipe_fence_handle *fence ); - - /** - * Checks whether the fence has been signalled. - * \param flags driver-specific meaning - * \return zero on success. - */ - int (*fence_signalled)( struct pipe_winsys *ws, - struct pipe_fence_handle *fence, - unsigned flag ); - - /** - * Wait for the fence to finish. - * \param flags driver-specific meaning - * \return zero on success. - */ - int (*fence_finish)( struct pipe_winsys *ws, - struct pipe_fence_handle *fence, - unsigned flag ); - -}; - -/** - * The following function initializes a simple passthrough screen. - * - * All the relevant screen function pointers will forwarded to the - * winsys. - */ -void u_simple_screen_init(struct pipe_screen *screen); - -/** - * Returns the name of the winsys associated with this screen. - */ -const char* u_simple_screen_winsys_name(struct pipe_screen *screen); - -#endif diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c index 33306bbc2a..e21e81dcd2 100644 --- a/src/gallium/auxiliary/util/u_surface.c +++ b/src/gallium/auxiliary/util/u_surface.c @@ -50,7 +50,7 @@ boolean util_create_rgba_surface(struct pipe_screen *screen, uint width, uint height, - struct pipe_texture **textureOut, + struct pipe_resource **textureOut, struct pipe_surface **surfaceOut) { static const enum pipe_format rgbaFormats[] = { @@ -62,7 +62,7 @@ util_create_rgba_surface(struct pipe_screen *screen, const uint target = PIPE_TEXTURE_2D; const uint usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; enum pipe_format format = PIPE_FORMAT_NONE; - struct pipe_texture templ; + struct pipe_resource templ; uint i; /* Choose surface format */ @@ -86,14 +86,14 @@ util_create_rgba_surface(struct pipe_screen *screen, templ.depth0 = 1; templ.tex_usage = usage; - *textureOut = screen->texture_create(screen, &templ); + *textureOut = screen->resource_create(screen, &templ); if (!*textureOut) return FALSE; /* create surface / view into texture */ *surfaceOut = screen->get_tex_surface(screen, *textureOut, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); if (!*surfaceOut) { - pipe_texture_reference(textureOut, NULL); + pipe_resource_reference(textureOut, NULL); return FALSE; } @@ -105,11 +105,11 @@ util_create_rgba_surface(struct pipe_screen *screen, * Release the surface and texture from util_create_rgba_surface(). */ void -util_destroy_rgba_surface(struct pipe_texture *texture, +util_destroy_rgba_surface(struct pipe_resource *texture, struct pipe_surface *surface) { pipe_surface_reference(&surface, NULL); - pipe_texture_reference(&texture, NULL); + pipe_resource_reference(&texture, NULL); } diff --git a/src/gallium/auxiliary/util/u_surface.h b/src/gallium/auxiliary/util/u_surface.h index 3c60df2c3e..6428c3f91c 100644 --- a/src/gallium/auxiliary/util/u_surface.h +++ b/src/gallium/auxiliary/util/u_surface.h @@ -53,12 +53,12 @@ util_same_surface(const struct pipe_surface *s1, const struct pipe_surface *s2) extern boolean util_create_rgba_surface(struct pipe_screen *screen, uint width, uint height, - struct pipe_texture **textureOut, + struct pipe_resource **textureOut, struct pipe_surface **surfaceOut); extern void -util_destroy_rgba_surface(struct pipe_texture *texture, +util_destroy_rgba_surface(struct pipe_resource *texture, struct pipe_surface *surface); diff --git a/src/gallium/auxiliary/util/u_tile.c b/src/gallium/auxiliary/util/u_tile.c index 82e44192aa..26bb4771b0 100644 --- a/src/gallium/auxiliary/util/u_tile.c +++ b/src/gallium/auxiliary/util/u_tile.c @@ -53,9 +53,9 @@ pipe_get_tile_raw(struct pipe_context *pipe, const void *src; if (dst_stride == 0) - dst_stride = util_format_get_stride(pt->texture->format, w); + dst_stride = util_format_get_stride(pt->resource->format, w); - if (pipe_clip_tile(x, y, &w, &h, pt)) + if (u_clip_tile(x, y, &w, &h, &pt->box)) return; src = pipe->transfer_map(pipe, pt); @@ -63,7 +63,7 @@ pipe_get_tile_raw(struct pipe_context *pipe, if(!src) return; - util_copy_rect(dst, pt->texture->format, dst_stride, 0, 0, w, h, src, pt->stride, x, y); + util_copy_rect(dst, pt->resource->format, dst_stride, 0, 0, w, h, src, pt->stride, x, y); pipe->transfer_unmap(pipe, pt); } @@ -79,12 +79,12 @@ pipe_put_tile_raw(struct pipe_context *pipe, const void *src, int src_stride) { void *dst; - enum pipe_format format = pt->texture->format; + enum pipe_format format = pt->resource->format; if (src_stride == 0) src_stride = util_format_get_stride(format, w); - if (pipe_clip_tile(x, y, &w, &h, pt)) + if (u_clip_tile(x, y, &w, &h, &pt->box)) return; dst = pipe->transfer_map(pipe, pt); @@ -1253,9 +1253,9 @@ pipe_get_tile_rgba(struct pipe_context *pipe, { unsigned dst_stride = w * 4; void *packed; - enum pipe_format format = pt->texture->format; + enum pipe_format format = pt->resource->format; - if (pipe_clip_tile(x, y, &w, &h, pt)) + if (u_clip_tile(x, y, &w, &h, &pt->box)) return; packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format)); @@ -1293,7 +1293,7 @@ pipe_get_tile_swizzle(struct pipe_context *pipe, uint i; float rgba01[6]; - if (pipe_clip_tile(x, y, &w, &h, pt)) { + if (u_clip_tile(x, y, &w, &h, &pt->box)) { return; } @@ -1345,9 +1345,9 @@ pipe_put_tile_rgba(struct pipe_context *pipe, { unsigned src_stride = w * 4; void *packed; - enum pipe_format format = pt->texture->format; + enum pipe_format format = pt->resource->format; - if (pipe_clip_tile(x, y, &w, &h, pt)) + if (u_clip_tile(x, y, &w, &h, &pt->box)) return; packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format)); @@ -1447,9 +1447,9 @@ pipe_get_tile_z(struct pipe_context *pipe, ubyte *map; uint *pDest = z; uint i, j; - enum pipe_format format = pt->texture->format; + enum pipe_format format = pt->resource->format; - if (pipe_clip_tile(x, y, &w, &h, pt)) + if (u_clip_tile(x, y, &w, &h, &pt->box)) return; map = (ubyte *)pipe->transfer_map(pipe, pt); @@ -1532,9 +1532,9 @@ pipe_put_tile_z(struct pipe_context *pipe, const uint *ptrc = zSrc; ubyte *map; uint i, j; - enum pipe_format format = pt->texture->format; + enum pipe_format format = pt->resource->format; - if (pipe_clip_tile(x, y, &w, &h, pt)) + if (u_clip_tile(x, y, &w, &h, &pt->box)) return; map = (ubyte *)pipe->transfer_map(pipe, pt); @@ -1557,7 +1557,7 @@ pipe_put_tile_z(struct pipe_context *pipe, case PIPE_FORMAT_Z24S8_UNORM: { uint *pDest = (uint *) (map + y * pt->stride + x*4); - assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE); + //assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { /* convert 32-bit Z to 24-bit Z, preserve stencil */ @@ -1584,7 +1584,7 @@ pipe_put_tile_z(struct pipe_context *pipe, case PIPE_FORMAT_S8Z24_UNORM: { uint *pDest = (uint *) (map + y * pt->stride + x*4); - assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE); + //assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { /* convert 32-bit Z to 24-bit Z, preserve stencil */ diff --git a/src/gallium/auxiliary/util/u_tile.h b/src/gallium/auxiliary/util/u_tile.h index 1d8ce7d8cb..986eee0743 100644 --- a/src/gallium/auxiliary/util/u_tile.h +++ b/src/gallium/auxiliary/util/u_tile.h @@ -32,22 +32,24 @@ struct pipe_transfer; - /** * Clip tile against transfer dims. + * + * XXX: this only clips width and height! + * * \return TRUE if tile is totally clipped, FALSE otherwise */ static INLINE boolean -pipe_clip_tile(uint x, uint y, uint *w, uint *h, const struct pipe_transfer *pt) +u_clip_tile(uint x, uint y, uint *w, uint *h, const struct pipe_box *box) { - if (x >= pt->width) + if (x >= box->width) return TRUE; - if (y >= pt->height) + if (y >= box->height) return TRUE; - if (x + *w > pt->width) - *w = pt->width - x; - if (y + *h > pt->height) - *h = pt->height - y; + if (x + *w > box->width) + *w = box->width - x; + if (y + *h > box->height) + *h = box->height - y; return FALSE; } diff --git a/src/gallium/auxiliary/util/u_timed_winsys.c b/src/gallium/auxiliary/util/u_timed_winsys.c deleted file mode 100644 index d88298bc14..0000000000 --- a/src/gallium/auxiliary/util/u_timed_winsys.c +++ /dev/null @@ -1,312 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * - **************************************************************************/ -/* - * Authors: Keith Whitwell <keithw-at-tungstengraphics-dot-com> - */ - -#include "pipe/p_state.h" -#include "util/u_simple_screen.h" -#include "u_timed_winsys.h" -#include "util/u_memory.h" -#include "os/os_time.h" - - -struct timed_winsys { - struct pipe_winsys base; - struct pipe_winsys *backend; - uint64_t last_dump; - struct { - const char *name_key; - double total; - unsigned calls; - } funcs[13]; -}; - - -static struct timed_winsys *timed_winsys( struct pipe_winsys *winsys ) -{ - return (struct timed_winsys *)winsys; -} - - -static void time_display( struct pipe_winsys *winsys ) -{ - struct timed_winsys *tws = timed_winsys(winsys); - unsigned i; - double overall = 0; - - for (i = 0; i < Elements(tws->funcs); i++) { - if (tws->funcs[i].name_key) { - debug_printf("*** %-25s %5.3fms (%d calls, avg %.3fms)\n", - tws->funcs[i].name_key, - tws->funcs[i].total, - tws->funcs[i].calls, - tws->funcs[i].total / tws->funcs[i].calls); - overall += tws->funcs[i].total; - tws->funcs[i].calls = 0; - tws->funcs[i].total = 0; - } - } - - debug_printf("*** %-25s %5.3fms\n", - "OVERALL WINSYS", - overall); -} - -static void time_finish( struct pipe_winsys *winsys, - long long startval, - unsigned idx, - const char *name ) -{ - struct timed_winsys *tws = timed_winsys(winsys); - int64_t endval = os_time_get(); - double elapsed = (endval - startval)/1000.0; - - if (endval - startval > 1000LL) - debug_printf("*** %s %.3f\n", name, elapsed ); - - assert( tws->funcs[idx].name_key == name || - tws->funcs[idx].name_key == NULL); - - tws->funcs[idx].name_key = name; - tws->funcs[idx].total += elapsed; - tws->funcs[idx].calls++; - - if (endval - tws->last_dump > 10LL * 1000LL * 1000LL) { - time_display( winsys ); - tws->last_dump = endval; - } -} - - -/* Pipe has no concept of pools, but the psb driver passes a flag that - * can be mapped onto pools in the backend. - */ -static struct pipe_buffer * -timed_buffer_create(struct pipe_winsys *winsys, - unsigned alignment, - unsigned usage, - unsigned size ) -{ - struct pipe_winsys *backend = timed_winsys(winsys)->backend; - int64_t start = os_time_get(); - - struct pipe_buffer *buf = - backend->buffer_create( backend, alignment, usage, size ); - - time_finish(winsys, start, 0, __FUNCTION__); - - return buf; -} - - - - -static struct pipe_buffer * -timed_user_buffer_create(struct pipe_winsys *winsys, - void *data, - unsigned bytes) -{ - struct pipe_winsys *backend = timed_winsys(winsys)->backend; - int64_t start = os_time_get(); - - struct pipe_buffer *buf = backend->user_buffer_create( backend, data, bytes ); - - time_finish(winsys, start, 1, __FUNCTION__); - - return buf; -} - - -static void * -timed_buffer_map(struct pipe_winsys *winsys, - struct pipe_buffer *buf, - unsigned flags) -{ - struct pipe_winsys *backend = timed_winsys(winsys)->backend; - int64_t start = os_time_get(); - - void *map = backend->buffer_map( backend, buf, flags ); - - time_finish(winsys, start, 2, __FUNCTION__); - - return map; -} - - -static void -timed_buffer_unmap(struct pipe_winsys *winsys, - struct pipe_buffer *buf) -{ - struct pipe_winsys *backend = timed_winsys(winsys)->backend; - int64_t start = os_time_get(); - - backend->buffer_unmap( backend, buf ); - - time_finish(winsys, start, 3, __FUNCTION__); -} - - -static void -timed_buffer_destroy(struct pipe_buffer *buf) -{ - struct pipe_winsys *winsys = buf->screen->winsys; - struct pipe_winsys *backend = timed_winsys(winsys)->backend; - int64_t start = os_time_get(); - - backend->buffer_destroy( buf ); - - time_finish(winsys, start, 4, __FUNCTION__); -} - - -static void -timed_flush_frontbuffer( struct pipe_winsys *winsys, - struct pipe_surface *surf, - void *context_private) -{ - struct pipe_winsys *backend = timed_winsys(winsys)->backend; - int64_t start = os_time_get(); - - backend->flush_frontbuffer( backend, surf, context_private ); - - time_finish(winsys, start, 5, __FUNCTION__); -} - - - - -static struct pipe_buffer * -timed_surface_buffer_create(struct pipe_winsys *winsys, - unsigned width, unsigned height, - enum pipe_format format, - unsigned usage, - unsigned tex_usage, - unsigned *stride) -{ - struct pipe_winsys *backend = timed_winsys(winsys)->backend; - int64_t start = os_time_get(); - - struct pipe_buffer *ret = backend->surface_buffer_create( backend, width, height, - format, usage, tex_usage, stride ); - - time_finish(winsys, start, 7, __FUNCTION__); - - return ret; -} - - -static const char * -timed_get_name( struct pipe_winsys *winsys ) -{ - struct pipe_winsys *backend = timed_winsys(winsys)->backend; - int64_t start = os_time_get(); - - const char *ret = backend->get_name( backend ); - - time_finish(winsys, start, 9, __FUNCTION__); - - return ret; -} - -static void -timed_fence_reference(struct pipe_winsys *winsys, - struct pipe_fence_handle **ptr, - struct pipe_fence_handle *fence) -{ - struct pipe_winsys *backend = timed_winsys(winsys)->backend; - int64_t start = os_time_get(); - - backend->fence_reference( backend, ptr, fence ); - - time_finish(winsys, start, 10, __FUNCTION__); -} - - -static int -timed_fence_signalled( struct pipe_winsys *winsys, - struct pipe_fence_handle *fence, - unsigned flag ) -{ - struct pipe_winsys *backend = timed_winsys(winsys)->backend; - int64_t start = os_time_get(); - - int ret = backend->fence_signalled( backend, fence, flag ); - - time_finish(winsys, start, 11, __FUNCTION__); - - return ret; -} - -static int -timed_fence_finish( struct pipe_winsys *winsys, - struct pipe_fence_handle *fence, - unsigned flag ) -{ - struct pipe_winsys *backend = timed_winsys(winsys)->backend; - int64_t start = os_time_get(); - - int ret = backend->fence_finish( backend, fence, flag ); - - time_finish(winsys, start, 12, __FUNCTION__); - - return ret; -} - -static void -timed_winsys_destroy( struct pipe_winsys *winsys ) -{ - struct pipe_winsys *backend = timed_winsys(winsys)->backend; - backend->destroy( backend ); - FREE(winsys); -} - - - -struct pipe_winsys *u_timed_winsys_create( struct pipe_winsys *backend ) -{ - struct timed_winsys *ws = CALLOC_STRUCT(timed_winsys); - - ws->base.user_buffer_create = timed_user_buffer_create; - ws->base.buffer_map = timed_buffer_map; - ws->base.buffer_unmap = timed_buffer_unmap; - ws->base.buffer_destroy = timed_buffer_destroy; - ws->base.buffer_create = timed_buffer_create; - ws->base.surface_buffer_create = timed_surface_buffer_create; - ws->base.flush_frontbuffer = timed_flush_frontbuffer; - ws->base.get_name = timed_get_name; - ws->base.fence_reference = timed_fence_reference; - ws->base.fence_signalled = timed_fence_signalled; - ws->base.fence_finish = timed_fence_finish; - ws->base.destroy = timed_winsys_destroy; - - ws->backend = backend; - - return &ws->base; -} - diff --git a/src/gallium/auxiliary/util/u_timed_winsys.h b/src/gallium/auxiliary/util/u_timed_winsys.h deleted file mode 100644 index 542365112d..0000000000 --- a/src/gallium/auxiliary/util/u_timed_winsys.h +++ /dev/null @@ -1,41 +0,0 @@ -/************************************************************************** - * - * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * - **************************************************************************/ -/* - * Authors: Keith Whitwell <keithw-at-tungstengraphics-dot-com> - */ - - -#ifndef U_TIMED_WINSYS_H -#define U_TIMED_WINSYS_H - - -struct pipe_winsys; -struct pipe_winsys *u_timed_winsys_create( struct pipe_winsys *backend ); - - -#endif diff --git a/src/gallium/auxiliary/util/u_transfer.c b/src/gallium/auxiliary/util/u_transfer.c new file mode 100644 index 0000000000..24a7873b34 --- /dev/null +++ b/src/gallium/auxiliary/util/u_transfer.c @@ -0,0 +1,106 @@ +#include "pipe/p_context.h" +#include "util/u_rect.h" +#include "util/u_inlines.h" +#include "util/u_transfer.h" +#include "util/u_memory.h" + +/* One-shot transfer operation with data supplied in a user + * pointer. XXX: strides?? + */ +void u_default_transfer_inline_write( struct pipe_context *pipe, + struct pipe_resource *resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned slice_stride) +{ + struct pipe_transfer *transfer = NULL; + uint8_t *map = NULL; + + transfer = pipe->get_transfer(pipe, + resource, + sr, + usage, + box ); + if (transfer == NULL) + goto out; + + map = pipe_transfer_map(pipe, transfer); + if (map == NULL) + goto out; + + assert(box->depth == 1); /* XXX: fix me */ + + util_copy_rect(map, + resource->format, + transfer->stride, /* bytes? */ + 0, 0, + box->width, + box->height, + data, + box->width, /* bytes? texels? */ + 0, 0); + +out: + if (map) + pipe_transfer_unmap(pipe, transfer); + + if (transfer) + pipe_transfer_destroy(pipe, transfer); +} + + +boolean u_default_resource_get_handle(struct pipe_screen *screen, + struct pipe_resource *resource, + struct winsys_handle *handle) +{ + return FALSE; +} + + + +void u_default_transfer_flush_region( struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box) +{ + /* This is a no-op implementation, nothing to do. + */ +} + +unsigned u_default_is_resource_referenced( struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned face, unsigned level) +{ + return 0; +} + +struct pipe_transfer * u_default_get_transfer(struct pipe_context *context, + struct pipe_resource *resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box) +{ + struct pipe_transfer *transfer = CALLOC_STRUCT(pipe_transfer); + if (transfer == NULL) + return NULL; + + transfer->resource = resource; + transfer->sr = sr; + transfer->usage = usage; + transfer->box = *box; + return transfer; +} + +void u_default_transfer_unmap( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ +} + +void u_default_transfer_destroy(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + FREE(transfer); +} + diff --git a/src/gallium/auxiliary/util/u_transfer.h b/src/gallium/auxiliary/util/u_transfer.h new file mode 100644 index 0000000000..4d67b85a25 --- /dev/null +++ b/src/gallium/auxiliary/util/u_transfer.h @@ -0,0 +1,145 @@ + +#ifndef U_TRANSFER_H +#define U_TRANSFER_H + +/* Fallback implementations for inline read/writes which just go back + * to the regular transfer behaviour. + */ +#include "pipe/p_state.h" + +struct pipe_context; + +boolean u_default_resource_get_handle(struct pipe_screen *screen, + struct pipe_resource *resource, + struct winsys_handle *handle); + +void u_default_transfer_inline_write( struct pipe_context *pipe, + struct pipe_resource *resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned slice_stride); + +void u_default_transfer_flush_region( struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box); + +unsigned u_default_is_resource_referenced( struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned face, unsigned level); + +struct pipe_transfer * u_default_get_transfer(struct pipe_context *context, + struct pipe_resource *resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box); + +void u_default_transfer_unmap( struct pipe_context *pipe, + struct pipe_transfer *transfer ); + +void u_default_transfer_destroy(struct pipe_context *pipe, + struct pipe_transfer *transfer); + + + +/* Useful helper to allow >1 implementation of resource functionality + * to exist in a single driver. This is intended to be transitionary! + */ +struct u_resource_vtbl { + + boolean (*resource_get_handle)(struct pipe_screen *, + struct pipe_resource *tex, + struct winsys_handle *handle); + + void (*resource_destroy)(struct pipe_screen *, + struct pipe_resource *pt); + + unsigned (*is_resource_referenced)(struct pipe_context *pipe, + struct pipe_resource *texture, + unsigned face, unsigned level); + + struct pipe_transfer *(*get_transfer)(struct pipe_context *, + struct pipe_resource *resource, + struct pipe_subresource, + enum pipe_transfer_usage, + const struct pipe_box *); + + void (*transfer_destroy)(struct pipe_context *, + struct pipe_transfer *); + + void *(*transfer_map)( struct pipe_context *, + struct pipe_transfer *transfer ); + + void (*transfer_flush_region)( struct pipe_context *, + struct pipe_transfer *transfer, + const struct pipe_box *); + + void (*transfer_unmap)( struct pipe_context *, + struct pipe_transfer *transfer ); + + void (*transfer_inline_write)( struct pipe_context *pipe, + struct pipe_resource *resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned slice_stride); +}; + + +struct u_resource { + struct pipe_resource b; + struct u_resource_vtbl *vtbl; +}; + + +boolean u_resource_get_handle_vtbl(struct pipe_screen *screen, + struct pipe_resource *resource, + struct winsys_handle *handle); + +void u_resource_destroy_vtbl(struct pipe_screen *screen, + struct pipe_resource *resource); + +unsigned u_is_resource_referenced_vtbl( struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned face, unsigned level); + +struct pipe_transfer *u_get_transfer_vtbl(struct pipe_context *context, + struct pipe_resource *resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box); + +void u_transfer_destroy_vtbl(struct pipe_context *pipe, + struct pipe_transfer *transfer); + +void *u_transfer_map_vtbl( struct pipe_context *pipe, + struct pipe_transfer *transfer ); + +void u_transfer_flush_region_vtbl( struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box); + +void u_transfer_unmap_vtbl( struct pipe_context *rm_ctx, + struct pipe_transfer *transfer ); + +void u_transfer_inline_write_vtbl( struct pipe_context *rm_ctx, + struct pipe_resource *resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned slice_stride); + + + + + + + + +#endif diff --git a/src/gallium/auxiliary/util/u_upload_mgr.c b/src/gallium/auxiliary/util/u_upload_mgr.c index 012b2ae233..ea17b74815 100644 --- a/src/gallium/auxiliary/util/u_upload_mgr.c +++ b/src/gallium/auxiliary/util/u_upload_mgr.c @@ -31,7 +31,7 @@ #include "pipe/p_defines.h" #include "util/u_inlines.h" -#include "pipe/p_screen.h" +#include "pipe/p_context.h" #include "util/u_memory.h" #include "util/u_math.h" @@ -39,7 +39,7 @@ struct u_upload_mgr { - struct pipe_screen *screen; + struct pipe_context *pipe; unsigned default_size; unsigned alignment; @@ -47,21 +47,21 @@ struct u_upload_mgr { /* The active buffer: */ - struct pipe_buffer *buffer; + struct pipe_resource *buffer; unsigned size; unsigned offset; }; -struct u_upload_mgr *u_upload_create( struct pipe_screen *screen, +struct u_upload_mgr *u_upload_create( struct pipe_context *pipe, unsigned default_size, unsigned alignment, unsigned usage ) { struct u_upload_mgr *upload = CALLOC_STRUCT( u_upload_mgr ); + upload->pipe = pipe; upload->default_size = default_size; - upload->screen = screen; upload->alignment = alignment; upload->usage = usage; upload->buffer = NULL; @@ -69,31 +69,44 @@ struct u_upload_mgr *u_upload_create( struct pipe_screen *screen, return upload; } - +/* Slightly specialized version of buffer_write designed to maximize + * chances of the driver consolidating successive writes into a single + * upload. + * + * dirty_size may be slightly greater than size to cope with + * alignment. We don't want to leave holes between succesively mapped + * regions as that may prevent the driver from consolidating uploads. + * + * Note that the 'data' pointer has probably come from the application + * and we cannot read even a byte past its end without risking + * segfaults, or at least complaints from valgrind.. + */ static INLINE enum pipe_error -my_buffer_write(struct pipe_screen *screen, - struct pipe_buffer *buf, +my_buffer_write(struct pipe_context *pipe, + struct pipe_resource *buf, unsigned offset, unsigned size, unsigned dirty_size, const void *data) { + struct pipe_transfer *transfer = NULL; uint8_t *map; - assert(offset < buf->size); - assert(offset + size <= buf->size); + assert(offset < buf->width0); + assert(offset + size <= buf->width0); assert(dirty_size >= 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); + map = pipe_buffer_map_range(pipe, buf, offset, size, + PIPE_TRANSFER_WRITE | + PIPE_TRANSFER_FLUSH_EXPLICIT | + PIPE_TRANSFER_DISCARD | + PIPE_TRANSFER_UNSYNCHRONIZED, + &transfer); if (map == NULL) return PIPE_ERROR_OUT_OF_MEMORY; memcpy(map + offset, data, size); - pipe_buffer_flush_mapped_range(screen, buf, offset, dirty_size); - pipe_buffer_unmap(screen, buf); + pipe_buffer_flush_mapped_range(pipe, transfer, offset, dirty_size); + pipe_buffer_unmap(pipe, buf, transfer); return PIPE_OK; } @@ -109,7 +122,7 @@ my_buffer_write(struct pipe_screen *screen, */ void u_upload_flush( struct u_upload_mgr *upload ) { - pipe_buffer_reference( &upload->buffer, NULL ); + pipe_resource_reference( &upload->buffer, NULL ); upload->size = 0; } @@ -135,7 +148,7 @@ u_upload_alloc_buffer( struct u_upload_mgr *upload, */ size = align(MAX2(upload->default_size, min_size), 4096); - upload->buffer = pipe_buffer_create( upload->screen, + upload->buffer = pipe_buffer_create( upload->pipe->screen, upload->alignment, upload->usage | PIPE_BUFFER_USAGE_CPU_WRITE, size ); @@ -149,7 +162,7 @@ u_upload_alloc_buffer( struct u_upload_mgr *upload, fail: if (upload->buffer) - pipe_buffer_reference( &upload->buffer, NULL ); + pipe_resource_reference( &upload->buffer, NULL ); return PIPE_ERROR_OUT_OF_MEMORY; } @@ -159,7 +172,7 @@ enum pipe_error u_upload_data( struct u_upload_mgr *upload, unsigned size, const void *data, unsigned *out_offset, - struct pipe_buffer **outbuf ) + struct pipe_resource **outbuf ) { unsigned alloc_size = align( size, upload->alignment ); enum pipe_error ret = PIPE_OK; @@ -172,7 +185,7 @@ enum pipe_error u_upload_data( struct u_upload_mgr *upload, /* Copy the data, using map_range if available: */ - ret = my_buffer_write( upload->screen, + ret = my_buffer_write( upload->pipe, upload->buffer, upload->offset, size, @@ -183,7 +196,7 @@ enum pipe_error u_upload_data( struct u_upload_mgr *upload, /* Emit the return values: */ - pipe_buffer_reference( outbuf, upload->buffer ); + pipe_resource_reference( outbuf, upload->buffer ); *out_offset = upload->offset; upload->offset += alloc_size; return PIPE_OK; @@ -198,15 +211,18 @@ enum pipe_error u_upload_data( struct u_upload_mgr *upload, enum pipe_error u_upload_buffer( struct u_upload_mgr *upload, unsigned offset, unsigned size, - struct pipe_buffer *inbuf, + struct pipe_resource *inbuf, unsigned *out_offset, - struct pipe_buffer **outbuf ) + struct pipe_resource **outbuf ) { enum pipe_error ret = PIPE_OK; + struct pipe_transfer *transfer = NULL; const char *map = NULL; - map = (const char *)pipe_buffer_map( - upload->screen, inbuf, PIPE_BUFFER_USAGE_CPU_READ ); + map = (const char *)pipe_buffer_map(upload->pipe, + inbuf, + PIPE_TRANSFER_READ, + &transfer); if (map == NULL) { ret = PIPE_ERROR_OUT_OF_MEMORY; @@ -226,7 +242,7 @@ enum pipe_error u_upload_buffer( struct u_upload_mgr *upload, done: if (map) - pipe_buffer_unmap( upload->screen, inbuf ); + pipe_buffer_unmap( upload->pipe, inbuf, transfer ); return ret; } diff --git a/src/gallium/auxiliary/util/u_upload_mgr.h b/src/gallium/auxiliary/util/u_upload_mgr.h index e158bed9d0..a124924fc8 100644 --- a/src/gallium/auxiliary/util/u_upload_mgr.h +++ b/src/gallium/auxiliary/util/u_upload_mgr.h @@ -35,11 +35,11 @@ #include "pipe/p_defines.h" struct pipe_screen; -struct pipe_buffer; +struct pipe_resource; struct u_upload_mgr; -struct u_upload_mgr *u_upload_create( struct pipe_screen *screen, +struct u_upload_mgr *u_upload_create( struct pipe_context *pipe, unsigned default_size, unsigned alignment, unsigned usage ); @@ -61,15 +61,15 @@ enum pipe_error u_upload_data( struct u_upload_mgr *upload, unsigned size, const void *data, unsigned *out_offset, - struct pipe_buffer **outbuf ); + struct pipe_resource **outbuf ); enum pipe_error u_upload_buffer( struct u_upload_mgr *upload, unsigned offset, unsigned size, - struct pipe_buffer *inbuf, + struct pipe_resource *inbuf, unsigned *out_offset, - struct pipe_buffer **outbuf ); + struct pipe_resource **outbuf ); diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c index beb4722901..fa6342d4e9 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c +++ b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c @@ -680,7 +680,7 @@ xfer_buffers_map(struct vl_mpeg12_mc_renderer *r) assert(r); for (i = 0; i < 3; ++i) { - r->tex_transfer[i] = r->pipe->get_tex_transfer + r->tex_transfer[i] = r->pipe->get_transfer ( r->pipe, r->textures.all[i], 0, 0, 0, PIPE_TRANSFER_WRITE, 0, 0, diff --git a/src/gallium/drivers/cell/ppu/cell_texture.c b/src/gallium/drivers/cell/ppu/cell_texture.c index 5b169afaf8..3036898a56 100644 --- a/src/gallium/drivers/cell/ppu/cell_texture.c +++ b/src/gallium/drivers/cell/ppu/cell_texture.c @@ -356,7 +356,7 @@ cell_tex_surface_destroy(struct pipe_surface *surf) * back out for glGetTexImage). */ static struct pipe_transfer * -cell_get_tex_transfer(struct pipe_context *ctx, +cell_get_transfer(struct pipe_context *ctx, struct pipe_texture *texture, unsigned face, unsigned level, unsigned zslice, enum pipe_transfer_usage usage, @@ -403,7 +403,7 @@ cell_get_tex_transfer(struct pipe_context *ctx, static void -cell_tex_transfer_destroy(struct pipe_context *ctx, struct pipe_transfer *t) +cell_transfer_destroy(struct pipe_context *ctx, struct pipe_transfer *t) { struct cell_transfer *transfer = cell_transfer(t); /* Effectively do the texture_update work here - if texture images @@ -567,8 +567,8 @@ cell_init_screen_texture_funcs(struct pipe_screen *screen) void cell_init_texture_transfer_funcs(struct cell_context *cell) { - cell->pipe.get_tex_transfer = cell_get_tex_transfer; - cell->pipe.tex_transfer_destroy = cell_tex_transfer_destroy; + cell->pipe.get_transfer = cell_get_transfer; + cell->pipe.transfer_destroy = cell_transfer_destroy; cell->pipe.transfer_map = cell_transfer_map; cell->pipe.transfer_unmap = cell_transfer_unmap; } diff --git a/src/gallium/drivers/failover/fo_context.c b/src/gallium/drivers/failover/fo_context.c index 659e40cbf0..12d8e14eb5 100644 --- a/src/gallium/drivers/failover/fo_context.c +++ b/src/gallium/drivers/failover/fo_context.c @@ -110,7 +110,7 @@ static void failover_draw_arrays( struct pipe_context *pipe, static unsigned int failover_is_texture_referenced( struct pipe_context *_pipe, - struct pipe_texture *texture, + struct pipe_resource *texture, unsigned face, unsigned level) { struct failover_context *failover = failover_context( _pipe ); diff --git a/src/gallium/drivers/failover/fo_state.c b/src/gallium/drivers/failover/fo_state.c index 25c6273570..726906ecc7 100644 --- a/src/gallium/drivers/failover/fo_state.c +++ b/src/gallium/drivers/failover/fo_state.c @@ -449,7 +449,7 @@ failover_delete_sampler_state(struct pipe_context *pipe, void *sampler) static struct pipe_sampler_view * failover_create_sampler_view(struct pipe_context *pipe, - struct pipe_texture *texture, + struct pipe_resource *texture, const struct pipe_sampler_view *templ) { struct fo_sampler_view *view = malloc(sizeof(struct fo_sampler_view)); diff --git a/src/gallium/drivers/i915/Makefile b/src/gallium/drivers/i915/Makefile index e33c74d02f..2cefe70850 100644 --- a/src/gallium/drivers/i915/Makefile +++ b/src/gallium/drivers/i915/Makefile @@ -5,7 +5,6 @@ LIBNAME = i915 C_SOURCES = \ i915_blit.c \ - i915_buffer.c \ i915_clear.c \ i915_flush.c \ i915_context.c \ @@ -20,7 +19,9 @@ C_SOURCES = \ i915_screen.c \ i915_prim_emit.c \ i915_prim_vbuf.c \ - i915_texture.c \ + i915_resource.c \ + i915_resource_texture.c \ + i915_resource_buffer.c \ i915_fpc_emit.c \ i915_fpc_translate.c \ i915_surface.c diff --git a/src/gallium/drivers/i915/SConscript b/src/gallium/drivers/i915/SConscript index 5a1c47c88d..7b69681096 100644 --- a/src/gallium/drivers/i915/SConscript +++ b/src/gallium/drivers/i915/SConscript @@ -6,7 +6,7 @@ i915 = env.ConvenienceLibrary( target = 'i915', source = [ 'i915_blit.c', - 'i915_buffer.c', + 'i915_resource_buffer.c', 'i915_clear.c', 'i915_context.c', 'i915_debug.c', @@ -24,7 +24,8 @@ i915 = env.ConvenienceLibrary( 'i915_state_immediate.c', 'i915_state_sampler.c', 'i915_surface.c', - 'i915_texture.c', + 'i915_resource.c', + 'i915_resource_texture.c', ]) Export('i915') diff --git a/src/gallium/drivers/i915/i915_buffer.c b/src/gallium/drivers/i915/i915_buffer.c deleted file mode 100644 index 0f76a59e93..0000000000 --- a/src/gallium/drivers/i915/i915_buffer.c +++ /dev/null @@ -1,138 +0,0 @@ -/************************************************************************** - * - * Copyright © 2009 Jakob Bornecrantz - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include "util/u_inlines.h" -#include "util/u_memory.h" -#include "i915_screen.h" -#include "i915_buffer.h" - -struct intel_buffer; - -struct i915_buffer -{ - struct pipe_buffer base; - - struct intel_buffer *ibuf; /** hw buffer */ - - void *data; /**< user and malloc data */ - boolean own; /**< we own the data incase of malloc */ -}; - -static INLINE struct i915_buffer * -i915_buffer(struct pipe_buffer *buffer) -{ - return (struct i915_buffer *)buffer; -} - -static struct pipe_buffer * -i915_buffer_create(struct pipe_screen *screen, - unsigned alignment, - unsigned usage, - unsigned size) -{ - struct i915_buffer *buf = CALLOC_STRUCT(i915_buffer); - - if (!buf) - return NULL; - - pipe_reference_init(&buf->base.reference, 1); - buf->base.alignment = alignment; - buf->base.screen = screen; - buf->base.usage = usage; - buf->base.size = size; - buf->data = MALLOC(size); - buf->own = TRUE; - - if (!buf->data) - goto err; - - return &buf->base; - -err: - FREE(buf); - return NULL; -} - -static struct pipe_buffer * -i915_user_buffer_create(struct pipe_screen *screen, - void *ptr, - unsigned bytes) -{ - struct i915_buffer *buf = CALLOC_STRUCT(i915_buffer); - - if (!buf) - return NULL; - - pipe_reference_init(&buf->base.reference, 1); - buf->base.alignment = 0; - buf->base.screen = screen; - buf->base.usage = 0; - buf->base.size = bytes; - buf->data = ptr; - buf->own = FALSE; - - return &buf->base; -} - -static void * -i915_buffer_map(struct pipe_screen *screen, - struct pipe_buffer *buffer, - unsigned usage) -{ - struct i915_buffer *buf = i915_buffer(buffer); - assert(!buf->ibuf); - return buf->data; -} - -static void -i915_buffer_unmap(struct pipe_screen *screen, - struct pipe_buffer *buffer) -{ - struct i915_buffer *buf = i915_buffer(buffer); - assert(!buf->ibuf); - (void) buf; -} - -static void -i915_buffer_destroy(struct pipe_buffer *buffer) -{ - struct i915_buffer *buf = i915_buffer(buffer); - assert(!buf->ibuf); - - if (buf->own) - FREE(buf->data); - FREE(buf); -} - -void i915_init_screen_buffer_functions(struct i915_screen *screen) -{ - screen->base.buffer_create = i915_buffer_create; - screen->base.user_buffer_create = i915_user_buffer_create; - screen->base.buffer_map = i915_buffer_map; - screen->base.buffer_map_range = NULL; - screen->base.buffer_flush_mapped_range = NULL; - screen->base.buffer_unmap = i915_buffer_unmap; - screen->base.buffer_destroy = i915_buffer_destroy; -} diff --git a/src/gallium/drivers/i915/i915_buffer.h b/src/gallium/drivers/i915/i915_buffer.h deleted file mode 100644 index 80fda7c62f..0000000000 --- a/src/gallium/drivers/i915/i915_buffer.h +++ /dev/null @@ -1,31 +0,0 @@ -/************************************************************************** - * - * Copyright © 2009 Jakob Bornecrantz - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef I915_BUFFER_H -#define I915_BUFFER_H - -void i915_init_screen_buffer_functions(struct i915_screen *screen); - -#endif diff --git a/src/gallium/drivers/i915/i915_context.c b/src/gallium/drivers/i915/i915_context.c index 130519ffa5..4ae5291115 100644 --- a/src/gallium/drivers/i915/i915_context.c +++ b/src/gallium/drivers/i915/i915_context.c @@ -28,7 +28,9 @@ #include "i915_context.h" #include "i915_state.h" #include "i915_screen.h" +#include "i915_surface.h" #include "i915_batch.h" +#include "i915_resource.h" #include "draw/draw_context.h" #include "pipe/p_defines.h" @@ -44,7 +46,7 @@ static void i915_draw_range_elements(struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned min_index, unsigned max_index, @@ -61,8 +63,7 @@ i915_draw_range_elements(struct pipe_context *pipe, * Map vertex buffers */ for (i = 0; i < i915->num_vertex_buffers; i++) { - void *buf = pipe_buffer_map(pipe->screen, i915->vertex_buffer[i].buffer, - PIPE_BUFFER_USAGE_CPU_READ); + void *buf = i915_buffer(i915->vertex_buffer[i].buffer)->data; draw_set_mapped_vertex_buffer(draw, i, buf); } @@ -70,8 +71,7 @@ i915_draw_range_elements(struct pipe_context *pipe, * Map index buffer, if present */ if (indexBuffer) { - void *mapped_indexes = pipe_buffer_map(pipe->screen, indexBuffer, - PIPE_BUFFER_USAGE_CPU_READ); + void *mapped_indexes = i915_buffer(indexBuffer)->data; draw_set_mapped_element_buffer_range(draw, indexSize, min_index, max_index, @@ -95,19 +95,17 @@ i915_draw_range_elements(struct pipe_context *pipe, * unmap vertex/index buffers */ for (i = 0; i < i915->num_vertex_buffers; i++) { - pipe_buffer_unmap(pipe->screen, i915->vertex_buffer[i].buffer); draw_set_mapped_vertex_buffer(draw, i, NULL); } if (indexBuffer) { - pipe_buffer_unmap(pipe->screen, indexBuffer); - draw_set_mapped_element_buffer_range(draw, 0, start, start + count - 1, NULL); + draw_set_mapped_element_buffer(draw, 0, NULL); } } static void i915_draw_elements(struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned prim, unsigned start, unsigned count) { @@ -125,37 +123,6 @@ i915_draw_arrays(struct pipe_context *pipe, } -/* - * Is referenced functions - */ - - -static unsigned int -i915_is_texture_referenced(struct pipe_context *pipe, - struct pipe_texture *texture, - unsigned face, unsigned level) -{ - /** - * FIXME: Return the corrent result. We can't alays return referenced - * since it causes a double flush within the vbo module. - */ -#if 0 - return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; -#else - return 0; -#endif -} - -static unsigned int -i915_is_buffer_referenced(struct pipe_context *pipe, - struct pipe_buffer *buf) -{ - /* - * Since we never expose hardware buffers to the state tracker - * they can never be referenced, so this isn't a lie - */ - return 0; -} /* @@ -204,9 +171,6 @@ i915_create_context(struct pipe_screen *screen, void *priv) i915->base.draw_elements = i915_draw_elements; i915->base.draw_range_elements = i915_draw_range_elements; - i915->base.is_texture_referenced = i915_is_texture_referenced; - i915->base.is_buffer_referenced = i915_is_buffer_referenced; - /* * Create drawing context and plug our rendering stage into it. */ @@ -221,7 +185,7 @@ i915_create_context(struct pipe_screen *screen, void *priv) i915_init_surface_functions(i915); i915_init_state_functions(i915); i915_init_flush_functions(i915); - i915_init_texture_functions(i915); + i915_init_resource_functions(i915); draw_install_aaline_stage(i915->draw, &i915->base); draw_install_aapoint_stage(i915->draw, &i915->base); diff --git a/src/gallium/drivers/i915/i915_context.h b/src/gallium/drivers/i915/i915_context.h index 5348f62ca7..fdfdfad258 100644 --- a/src/gallium/drivers/i915/i915_context.h +++ b/src/gallium/drivers/i915/i915_context.h @@ -192,35 +192,6 @@ struct i915_velems_state { struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS]; }; -#define I915_MAX_TEXTURE_2D_LEVELS 11 /* max 1024x1024 */ -#define I915_MAX_TEXTURE_3D_LEVELS 8 /* max 128x128x128 */ - -struct i915_texture { - struct pipe_texture base; - - /* Derived from the above: - */ - unsigned stride; - unsigned depth_stride; /* per-image on i945? */ - unsigned total_nblocksy; - - unsigned sw_tiled; /**< tiled with software flags */ - unsigned hw_tiled; /**< tiled with hardware fences */ - - unsigned nr_images[I915_MAX_TEXTURE_2D_LEVELS]; - - /* Explicitly store the offset of each image for each cube face or - * depth value. Pretty much have to accept that hardware formats - * are going to be so diverse that there is no unified way to - * compute the offsets of depth/cube images within a mipmap level, - * so have to store them as a lookup table: - */ - unsigned *image_offset[I915_MAX_TEXTURE_2D_LEVELS]; /**< array [depth] of offsets */ - - /* The data is held here: - */ - struct intel_buffer *buffer; -}; struct i915_context { @@ -243,7 +214,7 @@ struct i915_context struct pipe_stencil_ref stencil_ref; struct pipe_clip_state clip; /* XXX unneded */ - struct pipe_buffer *constants[PIPE_SHADER_TYPES]; + struct pipe_resource *constants[PIPE_SHADER_TYPES]; struct pipe_framebuffer_state framebuffer; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; @@ -333,10 +304,8 @@ void i915_clear( struct pipe_context *pipe, unsigned buffers, const float *rgba, /*********************************************************************** - * i915_surface.c: + * */ -void i915_init_surface_functions( struct i915_context *i915 ); - void i915_init_state_functions( struct i915_context *i915 ); void i915_init_flush_functions( struct i915_context *i915 ); void i915_init_string_functions( struct i915_context *i915 ); @@ -349,10 +318,6 @@ struct pipe_context *i915_create_context(struct pipe_screen *screen, void *priv); -/*********************************************************************** - * i915_texture.c - */ -void i915_init_texture_functions(struct i915_context *i915 ); /*********************************************************************** diff --git a/src/gallium/drivers/i915/i915_resource.c b/src/gallium/drivers/i915/i915_resource.c new file mode 100644 index 0000000000..499233ceb9 --- /dev/null +++ b/src/gallium/drivers/i915/i915_resource.c @@ -0,0 +1,51 @@ +#include "util/u_debug.h" + +#include "i915_resource.h" +#include "i915_context.h" +#include "i915_screen.h" + + +static struct pipe_resource * +i915_resource_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + if (template->target == PIPE_BUFFER) + return i915_buffer_create(screen, template); + else + return i915_texture_create(screen, template); + +} + +static struct pipe_resource * +i915_resource_from_handle(struct pipe_screen * screen, + const struct pipe_resource *template, + struct winsys_handle *whandle) +{ + if (template->target == PIPE_BUFFER) + return NULL; + else + return i915_texture_from_handle(screen, template, whandle); +} + + +void +i915_init_resource_functions(struct i915_context *i915 ) +{ + i915->base.is_resource_referenced = u_default_is_resource_referenced; + i915->base.get_transfer = u_get_transfer_vtbl; + i915->base.transfer_map = u_transfer_map_vtbl; + i915->base.transfer_flush_region = u_transfer_flush_region_vtbl; + i915->base.transfer_unmap = u_transfer_unmap_vtbl; + i915->base.transfer_destroy = u_transfer_destroy_vtbl; + i915->base.transfer_inline_write = u_transfer_inline_write_vtbl; +} + +void +i915_init_screen_resource_functions(struct i915_screen *is) +{ + is->base.resource_create = i915_resource_create; + is->base.resource_from_handle = i915_resource_from_handle; + is->base.resource_get_handle = u_resource_get_handle_vtbl; + is->base.resource_destroy = u_resource_destroy_vtbl; + is->base.user_buffer_create = i915_user_buffer_create; +} diff --git a/src/gallium/drivers/i915/i915_resource.h b/src/gallium/drivers/i915/i915_resource.h new file mode 100644 index 0000000000..5e01b36774 --- /dev/null +++ b/src/gallium/drivers/i915/i915_resource.h @@ -0,0 +1,114 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef I915_RESOURCE_H +#define I915_RESOURCE_H + +struct i915_screen; + +#include "util/u_transfer.h" +#include "util/u_debug.h" + + +struct i915_context; +struct i915_screen; + + +struct i915_buffer { + struct u_resource b; + uint8_t *data; + boolean free_on_destroy; +}; + +#define I915_MAX_TEXTURE_2D_LEVELS 11 /* max 1024x1024 */ +#define I915_MAX_TEXTURE_3D_LEVELS 8 /* max 128x128x128 */ + + + +struct i915_texture { + struct u_resource b; + + unsigned stride; + unsigned depth_stride; /* per-image on i945? */ + unsigned total_nblocksy; + + unsigned sw_tiled; /**< tiled with software flags */ + unsigned hw_tiled; /**< tiled with hardware fences */ + + unsigned nr_images[I915_MAX_TEXTURE_2D_LEVELS]; + + /* Explicitly store the offset of each image for each cube face or + * depth value. + */ + unsigned *image_offset[I915_MAX_TEXTURE_2D_LEVELS]; /**< array [depth] of offsets */ + + /* The data is held here: + */ + struct intel_buffer *buffer; +}; + +void i915_init_screen_resource_functions(struct i915_screen *is); +void i915_init_resource_functions(struct i915_context *i915 ); + +extern struct u_resource_vtbl i915_buffer_vtbl; +extern struct u_resource_vtbl i915_texture_vtbl; + +static INLINE struct i915_texture *i915_texture( struct pipe_resource *resource ) +{ + struct i915_texture *tex = (struct i915_texture *)resource; + assert(tex->b.vtbl == &i915_texture_vtbl); + return tex; +} + +static INLINE struct i915_buffer *i915_buffer( struct pipe_resource *resource ) +{ + struct i915_buffer *tex = (struct i915_buffer *)resource; + assert(tex->b.vtbl == &i915_buffer_vtbl); + return tex; +} + +struct pipe_resource * +i915_texture_create(struct pipe_screen *screen, + const struct pipe_resource *template); + +struct pipe_resource * +i915_texture_from_handle(struct pipe_screen * screen, + const struct pipe_resource *template, + struct winsys_handle *whandle); + + +struct pipe_resource * +i915_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned usage); + +struct pipe_resource * +i915_buffer_create(struct pipe_screen *screen, + const struct pipe_resource *template); + +#endif /* I915_RESOURCE_H */ diff --git a/src/gallium/drivers/i915/i915_resource_buffer.c b/src/gallium/drivers/i915/i915_resource_buffer.c new file mode 100644 index 0000000000..9dcd50cdee --- /dev/null +++ b/src/gallium/drivers/i915/i915_resource_buffer.c @@ -0,0 +1,160 @@ +/************************************************************************** + * + * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + /* + * Authors: + * Keith Whitwell <keith@tungstengraphics.com> + * Michel Dänzer <michel@tungstengraphics.com> + */ + +#include "pipe/p_context.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "i915_context.h" +#include "i915_resource.h" +#include "i915_screen.h" + + + +static boolean +i915_buffer_get_handle(struct pipe_screen *screen, + struct pipe_resource *resource, + struct winsys_handle *handle) +{ + return FALSE; +} + +static void +i915_buffer_destroy(struct pipe_screen *screen, + struct pipe_resource *resource) +{ + struct i915_buffer *buffer = i915_buffer(resource); + if (buffer->free_on_destroy) + align_free(buffer->data); + FREE(buffer); +} + + +static void * +i915_buffer_transfer_map( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + struct i915_buffer *buffer = i915_buffer(transfer->resource); + return buffer->data + transfer->box.x; +} + + +static void +i915_buffer_transfer_inline_write( struct pipe_context *rm_ctx, + struct pipe_resource *resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned slice_stride) +{ + struct i915_buffer *buffer = i915_buffer(resource); + + memcpy(buffer->data + box->x, + data, + box->width); +} + + +struct u_resource_vtbl i915_buffer_vtbl = +{ + i915_buffer_get_handle, /* get_handle */ + i915_buffer_destroy, /* resource_destroy */ + NULL, /* is_resource_referenced */ + u_default_get_transfer, /* get_transfer */ + u_default_transfer_destroy, /* transfer_destroy */ + i915_buffer_transfer_map, /* transfer_map */ + u_default_transfer_flush_region, /* transfer_flush_region */ + u_default_transfer_unmap, /* transfer_unmap */ + i915_buffer_transfer_inline_write /* transfer_inline_write */ +}; + + + +struct pipe_resource * +i915_buffer_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + struct i915_buffer *buf = CALLOC_STRUCT(i915_buffer); + + if (!buf) + return NULL; + + buf->b.b = *template; + buf->b.vtbl = &i915_buffer_vtbl; + pipe_reference_init(&buf->b.b.reference, 1); + buf->b.b.screen = screen; + + buf->data = MALLOC(template->width0); + buf->free_on_destroy = TRUE; + + if (!buf->data) + goto err; + + return &buf->b.b; + +err: + FREE(buf); + return NULL; +} + + + +struct pipe_resource * +i915_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned usage) +{ + struct i915_buffer *buf = CALLOC_STRUCT(i915_buffer); + + if (!buf) + return NULL; + + pipe_reference_init(&buf->b.b.reference, 1); + buf->b.vtbl = &i915_buffer_vtbl; + buf->b.b.screen = screen; + buf->b.b.format = PIPE_FORMAT_R8_UNORM; /* ?? */ + buf->b.b.usage = PIPE_BUFFER_USAGE_CPU_READ | usage; + buf->b.b.width0 = bytes; + buf->b.b.height0 = 1; + buf->b.b.depth0 = 1; + + buf->data = ptr; + buf->free_on_destroy = FALSE; + + return &buf->b.b; +} diff --git a/src/gallium/drivers/i915/i915_texture.c b/src/gallium/drivers/i915/i915_resource_texture.c index b252fb5330..2456511386 100644 --- a/src/gallium/drivers/i915/i915_texture.c +++ b/src/gallium/drivers/i915/i915_resource_texture.c @@ -39,7 +39,7 @@ #include "util/u_memory.h" #include "i915_context.h" -#include "i915_texture.h" +#include "i915_resource.h" #include "i915_screen.h" #include "intel_winsys.h" @@ -91,7 +91,7 @@ power_of_two(unsigned x) static void -i915_miptree_set_level_info(struct i915_texture *tex, +i915_texture_set_level_info(struct i915_texture *tex, unsigned level, unsigned nr_images, unsigned w, unsigned h, unsigned d) @@ -120,7 +120,7 @@ i915_miptree_set_level_info(struct i915_texture *tex, } static void -i915_miptree_set_image_offset(struct i915_texture *tex, +i915_texture_set_image_offset(struct i915_texture *tex, unsigned level, unsigned img, unsigned x, unsigned y) { if (img == 0 && level == 0) @@ -128,7 +128,7 @@ i915_miptree_set_image_offset(struct i915_texture *tex, assert(img < tex->nr_images[level]); - tex->image_offset[level][img] = y * tex->stride + x * util_format_get_blocksize(tex->base.format); + tex->image_offset[level][img] = y * tex->stride + x * util_format_get_blocksize(tex->b.b.format); /* printf("%s level %d img %d pos %d,%d image_offset %x\n", @@ -148,16 +148,16 @@ i915_miptree_set_image_offset(struct i915_texture *tex, static boolean i915_scanout_layout(struct i915_texture *tex) { - struct pipe_texture *pt = &tex->base; + struct pipe_resource *pt = &tex->b.b; if (pt->last_level > 0 || util_format_get_blocksize(pt->format) != 4) return FALSE; - i915_miptree_set_level_info(tex, 0, 1, + i915_texture_set_level_info(tex, 0, 1, pt->width0, pt->height0, 1); - i915_miptree_set_image_offset(tex, 0, 0, 0, 0); + i915_texture_set_image_offset(tex, 0, 0, 0, 0); if (pt->width0 >= 240) { tex->stride = power_of_two(util_format_get_stride(pt->format, pt->width0)); @@ -183,7 +183,7 @@ i915_scanout_layout(struct i915_texture *tex) static boolean i915_display_target_layout(struct i915_texture *tex) { - struct pipe_texture *pt = &tex->base; + struct pipe_resource *pt = &tex->b.b; if (pt->last_level > 0 || util_format_get_blocksize(pt->format) != 4) return FALSE; @@ -192,11 +192,11 @@ i915_display_target_layout(struct i915_texture *tex) if (pt->width0 < 240) return FALSE; - i915_miptree_set_level_info(tex, 0, 1, + i915_texture_set_level_info(tex, 0, 1, pt->width0, pt->height0, 1); - i915_miptree_set_image_offset(tex, 0, 0, 0, 0); + i915_texture_set_image_offset(tex, 0, 0, 0, 0); tex->stride = power_of_two(util_format_get_stride(pt->format, pt->width0)); tex->total_nblocksy = align(util_format_get_nblocksy(pt->format, pt->height0), 8); @@ -210,9 +210,9 @@ i915_display_target_layout(struct i915_texture *tex) } static void -i915_miptree_layout_2d(struct i915_texture *tex) +i915_texture_layout_2d(struct i915_texture *tex) { - struct pipe_texture *pt = &tex->base; + struct pipe_resource *pt = &tex->b.b; unsigned level; unsigned width = pt->width0; unsigned height = pt->height0; @@ -232,8 +232,8 @@ i915_miptree_layout_2d(struct i915_texture *tex) tex->total_nblocksy = 0; for (level = 0; level <= pt->last_level; level++) { - i915_miptree_set_level_info(tex, level, 1, width, height, 1); - i915_miptree_set_image_offset(tex, level, 0, 0, tex->total_nblocksy); + i915_texture_set_level_info(tex, level, 1, width, height, 1); + i915_texture_set_image_offset(tex, level, 0, 0, tex->total_nblocksy); nblocksy = align(MAX2(2, nblocksy), 2); @@ -246,9 +246,9 @@ i915_miptree_layout_2d(struct i915_texture *tex) } static void -i915_miptree_layout_3d(struct i915_texture *tex) +i915_texture_layout_3d(struct i915_texture *tex) { - struct pipe_texture *pt = &tex->base; + struct pipe_resource *pt = &tex->b.b; unsigned level; unsigned width = pt->width0; @@ -264,7 +264,7 @@ i915_miptree_layout_3d(struct i915_texture *tex) /* XXX: hardware expects/requires 9 levels at minimum. */ for (level = 0; level <= MAX2(8, pt->last_level); level++) { - i915_miptree_set_level_info(tex, level, depth, width, height, depth); + i915_texture_set_level_info(tex, level, depth, width, height, depth); stack_nblocksy += MAX2(2, nblocksy); @@ -278,7 +278,7 @@ i915_miptree_layout_3d(struct i915_texture *tex) for (level = 0; level <= pt->last_level; level++) { unsigned i; for (i = 0; i < depth; i++) - i915_miptree_set_image_offset(tex, level, i, 0, i * stack_nblocksy); + i915_texture_set_image_offset(tex, level, i, 0, i * stack_nblocksy); depth = u_minify(depth, 1); } @@ -291,9 +291,9 @@ i915_miptree_layout_3d(struct i915_texture *tex) } static void -i915_miptree_layout_cube(struct i915_texture *tex) +i915_texture_layout_cube(struct i915_texture *tex) { - struct pipe_texture *pt = &tex->base; + struct pipe_resource *pt = &tex->b.b; unsigned width = pt->width0, height = pt->height0; const unsigned nblocks = util_format_get_nblocksx(pt->format, pt->width0); unsigned level; @@ -306,7 +306,7 @@ i915_miptree_layout_cube(struct i915_texture *tex) tex->total_nblocksy = nblocks * 4; for (level = 0; level <= pt->last_level; level++) { - i915_miptree_set_level_info(tex, level, 6, width, height, 1); + i915_texture_set_level_info(tex, level, 6, width, height, 1); width /= 2; height /= 2; } @@ -317,7 +317,7 @@ i915_miptree_layout_cube(struct i915_texture *tex) unsigned d = nblocks; for (level = 0; level <= pt->last_level; level++) { - i915_miptree_set_image_offset(tex, level, face, x, y); + i915_texture_set_image_offset(tex, level, face, x, y); d >>= 1; x += step_offsets[face][0] * d; y += step_offsets[face][1] * d; @@ -326,20 +326,20 @@ i915_miptree_layout_cube(struct i915_texture *tex) } static boolean -i915_miptree_layout(struct i915_texture * tex) +i915_texture_layout(struct i915_texture * tex) { - struct pipe_texture *pt = &tex->base; + struct pipe_resource *pt = &tex->b.b; switch (pt->target) { case PIPE_TEXTURE_1D: case PIPE_TEXTURE_2D: - i915_miptree_layout_2d(tex); + i915_texture_layout_2d(tex); break; case PIPE_TEXTURE_3D: - i915_miptree_layout_3d(tex); + i915_texture_layout_3d(tex); break; case PIPE_TEXTURE_CUBE: - i915_miptree_layout_cube(tex); + i915_texture_layout_cube(tex); break; default: assert(0); @@ -356,9 +356,9 @@ i915_miptree_layout(struct i915_texture * tex) static void -i945_miptree_layout_2d(struct i915_texture *tex) +i945_texture_layout_2d(struct i915_texture *tex) { - struct pipe_texture *pt = &tex->base; + struct pipe_resource *pt = &tex->b.b; const int align_x = 2, align_y = 4; unsigned level; unsigned x = 0; @@ -369,12 +369,12 @@ i945_miptree_layout_2d(struct i915_texture *tex) unsigned nblocksy = util_format_get_nblocksy(pt->format, pt->height0); /* used for scanouts that need special layouts */ - if (tex->base.tex_usage & PIPE_TEXTURE_USAGE_SCANOUT) + if (tex->b.b.tex_usage & PIPE_TEXTURE_USAGE_SCANOUT) if (i915_scanout_layout(tex)) return; /* shared buffers needs to be compatible with X servers */ - if (tex->base.tex_usage & PIPE_TEXTURE_USAGE_SHARED) + if (tex->b.b.tex_usage & PIPE_TEXTURE_USAGE_SHARED) if (i915_display_target_layout(tex)) return; @@ -400,8 +400,8 @@ i945_miptree_layout_2d(struct i915_texture *tex) tex->total_nblocksy = 0; for (level = 0; level <= pt->last_level; level++) { - i915_miptree_set_level_info(tex, level, 1, width, height, 1); - i915_miptree_set_image_offset(tex, level, 0, x, y); + i915_texture_set_level_info(tex, level, 1, width, height, 1); + i915_texture_set_image_offset(tex, level, 0, x, y); nblocksy = align(nblocksy, align_y); @@ -427,9 +427,9 @@ i945_miptree_layout_2d(struct i915_texture *tex) } static void -i945_miptree_layout_3d(struct i915_texture *tex) +i945_texture_layout_3d(struct i915_texture *tex) { - struct pipe_texture *pt = &tex->base; + struct pipe_resource *pt = &tex->b.b; unsigned width = pt->width0; unsigned height = pt->height0; unsigned depth = pt->depth0; @@ -450,11 +450,11 @@ i945_miptree_layout_3d(struct i915_texture *tex) int y = 0; unsigned q, j; - i915_miptree_set_level_info(tex, level, depth, width, height, depth); + i915_texture_set_level_info(tex, level, depth, width, height, depth); for (q = 0; q < depth;) { for (j = 0; j < pack_x_nr && q < depth; j++, q++) { - i915_miptree_set_image_offset(tex, level, q, x, y + tex->total_nblocksy); + i915_texture_set_image_offset(tex, level, q, x, y + tex->total_nblocksy); x += pack_x_pitch; } @@ -482,9 +482,9 @@ i945_miptree_layout_3d(struct i915_texture *tex) } static void -i945_miptree_layout_cube(struct i915_texture *tex) +i945_texture_layout_cube(struct i915_texture *tex) { - struct pipe_texture *pt = &tex->base; + struct pipe_resource *pt = &tex->b.b; unsigned level; const unsigned nblocks = util_format_get_nblocksx(pt->format, pt->width0); @@ -516,7 +516,7 @@ i945_miptree_layout_cube(struct i915_texture *tex) /* Set all the levels to effectively occupy the whole rectangular region. */ for (level = 0; level <= pt->last_level; level++) { - i915_miptree_set_level_info(tex, level, 6, width, height, 1); + i915_texture_set_level_info(tex, level, 6, width, height, 1); width /= 2; height /= 2; } @@ -538,7 +538,7 @@ i945_miptree_layout_cube(struct i915_texture *tex) #endif for (level = 0; level <= pt->last_level; level++) { - i915_miptree_set_image_offset(tex, level, face, x, y); + i915_texture_set_image_offset(tex, level, face, x, y); d >>= 1; @@ -583,20 +583,20 @@ i945_miptree_layout_cube(struct i915_texture *tex) } static boolean -i945_miptree_layout(struct i915_texture * tex) +i945_texture_layout(struct i915_texture * tex) { - struct pipe_texture *pt = &tex->base; + struct pipe_resource *pt = &tex->b.b; switch (pt->target) { case PIPE_TEXTURE_1D: case PIPE_TEXTURE_2D: - i945_miptree_layout_2d(tex); + i945_texture_layout_2d(tex); break; case PIPE_TEXTURE_3D: - i945_miptree_layout_3d(tex); + i945_texture_layout_3d(tex); break; case PIPE_TEXTURE_CUBE: - i945_miptree_layout_cube(tex); + i945_texture_layout_cube(tex); break; default: assert(0); @@ -607,14 +607,115 @@ i945_miptree_layout(struct i915_texture * tex) } + /* * Screen texture functions */ -static struct pipe_texture * + +static boolean +i915_texture_get_handle(struct pipe_screen * screen, + struct pipe_resource *texture, + struct winsys_handle *whandle) +{ + struct i915_screen *is = i915_screen(screen); + struct i915_texture *tex = i915_texture(texture); + struct intel_winsys *iws = is->iws; + + return iws->buffer_get_handle(iws, tex->buffer, whandle, tex->stride); +} + + +static void +i915_texture_destroy(struct pipe_screen *screen, + struct pipe_resource *pt) +{ + struct i915_texture *tex = i915_texture(pt); + struct intel_winsys *iws = i915_screen(screen)->iws; + uint i; + + /* + DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); + */ + + iws->buffer_destroy(iws, tex->buffer); + + for (i = 0; i < Elements(tex->image_offset); i++) + if (tex->image_offset[i]) + FREE(tex->image_offset[i]); + + FREE(tex); +} + + + +static void * +i915_texture_transfer_map(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct pipe_resource *resource = transfer->resource; + struct i915_texture *tex = i915_texture(resource); + struct intel_winsys *iws = i915_screen(pipe->screen)->iws; + struct pipe_subresource sr = transfer->sr; + struct pipe_box *box = &transfer->box; + enum pipe_format format = resource->format; + unsigned offset; + char *map; + + if (resource->target == PIPE_TEXTURE_CUBE) { + offset = tex->image_offset[sr.level][sr.face]; + } + else if (resource->target == PIPE_TEXTURE_3D) { + offset = tex->image_offset[sr.level][box->z]; + } + else { + offset = tex->image_offset[sr.level][0]; + assert(sr.face == 0); + assert(box->z == 0); + } + + map = iws->buffer_map(iws, + tex->buffer, + (transfer->usage & PIPE_TRANSFER_WRITE) ? TRUE : FALSE); + if (map == NULL) + return NULL; + + return map + offset + + box->y / util_format_get_blockheight(format) * transfer->stride + + box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); +} + +static void +i915_texture_transfer_unmap(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct i915_texture *tex = i915_texture(transfer->resource); + struct intel_winsys *iws = i915_screen(tex->b.b.screen)->iws; + iws->buffer_unmap(iws, tex->buffer); +} + + + +struct u_resource_vtbl i915_texture_vtbl = +{ + i915_texture_get_handle, /* get_handle */ + i915_texture_destroy, /* resource_destroy */ + NULL, /* is_resource_referenced */ + u_default_get_transfer, /* get_transfer */ + u_default_transfer_destroy, /* transfer_destroy */ + i915_texture_transfer_map, /* transfer_map */ + u_default_transfer_flush_region, /* transfer_flush_region */ + i915_texture_transfer_unmap, /* transfer_unmap */ + u_default_transfer_inline_write /* transfer_inline_write */ +}; + + + + +struct pipe_resource * i915_texture_create(struct pipe_screen *screen, - const struct pipe_texture *templat) + const struct pipe_resource *template) { struct i915_screen *is = i915_screen(screen); struct intel_winsys *iws = is->iws; @@ -625,24 +726,23 @@ i915_texture_create(struct pipe_screen *screen, if (!tex) return NULL; - tex->base = *templat; - pipe_reference_init(&tex->base.reference, 1); - tex->base.screen = screen; + tex->b.b = *template; + tex->b.vtbl = &i915_texture_vtbl; + pipe_reference_init(&tex->b.b.reference, 1); + tex->b.b.screen = screen; if (is->is_i945) { - if (!i945_miptree_layout(tex)) + if (!i945_texture_layout(tex)) goto fail; } else { - if (!i915_miptree_layout(tex)) + if (!i915_texture_layout(tex)) goto fail; } tex_size = tex->stride * tex->total_nblocksy; - - /* for scanouts and cursors, cursors arn't scanouts */ - if (templat->tex_usage & PIPE_TEXTURE_USAGE_SCANOUT && templat->width0 != 64) + if ((template->tex_usage & PIPE_TEXTURE_USAGE_SCANOUT) && template->width0 != 64) buf_usage = INTEL_NEW_SCANOUT; else buf_usage = INTEL_NEW_TEXTURE; @@ -665,17 +765,17 @@ i915_texture_create(struct pipe_screen *screen, ws->buffer_unmap(ws, tex->buffer); #endif - return &tex->base; + return &tex->b.b; fail: FREE(tex); return NULL; } -static struct pipe_texture * +struct pipe_resource * i915_texture_from_handle(struct pipe_screen * screen, - const struct pipe_texture *templat, - struct winsys_handle *whandle) + const struct pipe_resource *template, + struct winsys_handle *whandle) { struct i915_screen *is = i915_screen(screen); struct i915_texture *tex; @@ -688,9 +788,9 @@ i915_texture_from_handle(struct pipe_screen * screen, buffer = iws->buffer_from_handle(iws, whandle, &stride); /* Only supports one type */ - if (templat->target != PIPE_TEXTURE_2D || - templat->last_level != 0 || - templat->depth0 != 1) { + if (template->target != PIPE_TEXTURE_2D || + template->last_level != 0 || + template->depth0 != 1) { return NULL; } @@ -698,204 +798,23 @@ i915_texture_from_handle(struct pipe_screen * screen, if (!tex) return NULL; - tex->base = *templat; - pipe_reference_init(&tex->base.reference, 1); - tex->base.screen = screen; + tex->b.b = *template; + tex->b.vtbl = &i915_texture_vtbl; + pipe_reference_init(&tex->b.b.reference, 1); + tex->b.b.screen = screen; tex->stride = stride; - i915_miptree_set_level_info(tex, 0, 1, templat->width0, templat->height0, 1); - i915_miptree_set_image_offset(tex, 0, 0, 0, 0); + i915_texture_set_level_info(tex, 0, 1, template->width0, template->height0, 1); + i915_texture_set_image_offset(tex, 0, 0, 0, 0); tex->buffer = buffer; - return &tex->base; -} - -static boolean -i915_texture_get_handle(struct pipe_screen * screen, - struct pipe_texture *texture, - struct winsys_handle *whandle) -{ - struct i915_screen *is = i915_screen(screen); - struct i915_texture *tex = (struct i915_texture *)texture; - struct intel_winsys *iws = is->iws; - - return iws->buffer_get_handle(iws, tex->buffer, whandle, tex->stride); -} - - -static void -i915_texture_destroy(struct pipe_texture *pt) -{ - struct i915_texture *tex = (struct i915_texture *)pt; - struct intel_winsys *iws = i915_screen(pt->screen)->iws; - uint i; - - /* - DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); - */ - - iws->buffer_destroy(iws, tex->buffer); - - for (i = 0; i < Elements(tex->image_offset); i++) - if (tex->image_offset[i]) - FREE(tex->image_offset[i]); - - FREE(tex); + return &tex->b.b; } -/* - * Screen surface functions - */ -static struct pipe_surface * -i915_get_tex_surface(struct pipe_screen *screen, - struct pipe_texture *pt, - unsigned face, unsigned level, unsigned zslice, - unsigned flags) -{ - struct i915_texture *tex = (struct i915_texture *)pt; - struct pipe_surface *ps; - unsigned offset; /* in bytes */ - if (pt->target == PIPE_TEXTURE_CUBE) { - offset = tex->image_offset[level][face]; - } - else if (pt->target == PIPE_TEXTURE_3D) { - offset = tex->image_offset[level][zslice]; - } - else { - offset = tex->image_offset[level][0]; - assert(face == 0); - assert(zslice == 0); - } - - ps = CALLOC_STRUCT(pipe_surface); - if (ps) { - pipe_reference_init(&ps->reference, 1); - pipe_texture_reference(&ps->texture, pt); - ps->format = pt->format; - ps->width = u_minify(pt->width0, level); - ps->height = u_minify(pt->height0, level); - ps->offset = offset; - ps->usage = flags; - } - return ps; -} - -static void -i915_tex_surface_destroy(struct pipe_surface *surf) -{ - pipe_texture_reference(&surf->texture, NULL); - FREE(surf); -} - - -/* - * Texture transfer functions - */ - - -static struct pipe_transfer * -i915_get_tex_transfer(struct pipe_context *pipe, - struct pipe_texture *texture, - unsigned face, unsigned level, unsigned zslice, - enum pipe_transfer_usage usage, unsigned x, unsigned y, - unsigned w, unsigned h) -{ - struct i915_texture *tex = (struct i915_texture *)texture; - struct i915_transfer *trans; - unsigned offset; /* in bytes */ - if (texture->target == PIPE_TEXTURE_CUBE) { - offset = tex->image_offset[level][face]; - } - else if (texture->target == PIPE_TEXTURE_3D) { - offset = tex->image_offset[level][zslice]; - } - else { - offset = tex->image_offset[level][0]; - assert(face == 0); - assert(zslice == 0); - } - - trans = CALLOC_STRUCT(i915_transfer); - if (trans) { - pipe_texture_reference(&trans->base.texture, texture); - trans->base.x = x; - trans->base.y = y; - trans->base.width = w; - trans->base.height = h; - trans->base.stride = tex->stride; - trans->offset = offset; - trans->base.usage = usage; - } - return &trans->base; -} - -static void * -i915_transfer_map(struct pipe_context *pipe, - struct pipe_transfer *transfer) -{ - struct i915_texture *tex = (struct i915_texture *)transfer->texture; - struct intel_winsys *iws = i915_screen(tex->base.screen)->iws; - char *map; - boolean write = FALSE; - enum pipe_format format = tex->base.format; - - if (transfer->usage & PIPE_TRANSFER_WRITE) - write = TRUE; - - map = iws->buffer_map(iws, tex->buffer, write); - if (map == NULL) - return NULL; - - return map + i915_transfer(transfer)->offset + - transfer->y / util_format_get_blockheight(format) * transfer->stride + - transfer->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); -} - -static void -i915_transfer_unmap(struct pipe_context *pipe, - struct pipe_transfer *transfer) -{ - struct i915_texture *tex = (struct i915_texture *)transfer->texture; - struct intel_winsys *iws = i915_screen(tex->base.screen)->iws; - iws->buffer_unmap(iws, tex->buffer); -} - -static void -i915_tex_transfer_destroy(struct pipe_context *pipe, - struct pipe_transfer *trans) -{ - pipe_texture_reference(&trans->texture, NULL); - FREE(trans); -} - - -/* - * Other texture functions - */ - -void -i915_init_texture_functions(struct i915_context *i915 ) -{ - i915->base.get_tex_transfer = i915_get_tex_transfer; - i915->base.transfer_map = i915_transfer_map; - i915->base.transfer_unmap = i915_transfer_unmap; - i915->base.tex_transfer_destroy = i915_tex_transfer_destroy; -} - -void -i915_init_screen_texture_functions(struct i915_screen *is) -{ - is->base.texture_create = i915_texture_create; - is->base.texture_from_handle = i915_texture_from_handle; - is->base.texture_get_handle = i915_texture_get_handle; - is->base.texture_destroy = i915_texture_destroy; - is->base.get_tex_surface = i915_get_tex_surface; - is->base.tex_surface_destroy = i915_tex_surface_destroy; -} diff --git a/src/gallium/drivers/i915/i915_screen.c b/src/gallium/drivers/i915/i915_screen.c index e5bf4a20bd..2f47bcc7dd 100644 --- a/src/gallium/drivers/i915/i915_screen.c +++ b/src/gallium/drivers/i915/i915_screen.c @@ -33,8 +33,8 @@ #include "i915_reg.h" #include "i915_context.h" #include "i915_screen.h" -#include "i915_buffer.h" -#include "i915_texture.h" +#include "i915_surface.h" +#include "i915_resource.h" #include "intel_winsys.h" @@ -304,8 +304,7 @@ i915_create_screen(struct intel_winsys *iws, uint pci_id) is->base.fence_signalled = i915_fence_signalled; is->base.fence_finish = i915_fence_finish; - i915_init_screen_texture_functions(is); - i915_init_screen_buffer_functions(is); + i915_init_screen_resource_functions(is); return &is->base; } diff --git a/src/gallium/drivers/i915/i915_state.c b/src/gallium/drivers/i915/i915_state.c index 0f7395246c..bc2f1b268a 100644 --- a/src/gallium/drivers/i915/i915_state.c +++ b/src/gallium/drivers/i915/i915_state.c @@ -39,6 +39,7 @@ #include "i915_reg.h" #include "i915_state_inlines.h" #include "i915_fpc.h" +#include "i915_resource.h" /* The i915 (and related graphics cores) do not support GL_CLAMP. The * Intel drivers for "other operating systems" implement GL_CLAMP as @@ -523,10 +524,10 @@ static void i915_delete_vs_state(struct pipe_context *pipe, void *shader) static void i915_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index, - struct pipe_buffer *buf) + struct pipe_resource *buf) { struct i915_context *i915 = i915_context(pipe); - struct pipe_screen *screen = pipe->screen; + struct i915_buffer *ir = i915_buffer(buf); draw_flush(i915->draw); assert(shader < PIPE_SHADER_TYPES); @@ -542,19 +543,14 @@ static void i915_set_constant_buffer(struct pipe_context *pipe, * N constants, leaving any extras from shader translation alone. */ if (buf) { - void *mapped; - if (buf->size && - (mapped = pipe_buffer_map(screen, buf, - PIPE_BUFFER_USAGE_CPU_READ))) { - memcpy(i915->current.constants[shader], mapped, buf->size); - pipe_buffer_unmap(screen, buf); - i915->current.num_user_constants[shader] - = buf->size / (4 * sizeof(float)); - } - else { - i915->current.num_user_constants[shader] = 0; - } + memcpy(i915->current.constants[shader], ir->data, ir->b.b.width0); + i915->current.num_user_constants[shader] = (ir->b.b.width0 / + 4 * sizeof(float)); } + else { + i915->current.num_user_constants[shader] = 0; + } + i915->dirty |= I915_NEW_CONSTANTS; } @@ -593,7 +589,7 @@ static void i915_set_fragment_sampler_views(struct pipe_context *pipe, static struct pipe_sampler_view * i915_create_sampler_view(struct pipe_context *pipe, - struct pipe_texture *texture, + struct pipe_resource *texture, const struct pipe_sampler_view *templ) { struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); @@ -602,7 +598,7 @@ i915_create_sampler_view(struct pipe_context *pipe, *view = *templ; view->reference.count = 1; view->texture = NULL; - pipe_texture_reference(&view->texture, texture); + pipe_resource_reference(&view->texture, texture); view->context = pipe; } @@ -614,7 +610,7 @@ static void i915_sampler_view_destroy(struct pipe_context *pipe, struct pipe_sampler_view *view) { - pipe_texture_reference(&view->texture, NULL); + pipe_resource_reference(&view->texture, NULL); FREE(view); } diff --git a/src/gallium/drivers/i915/i915_state_emit.c b/src/gallium/drivers/i915/i915_state_emit.c index d79c1ca0b2..ec2cd0e373 100644 --- a/src/gallium/drivers/i915/i915_state_emit.c +++ b/src/gallium/drivers/i915/i915_state_emit.c @@ -30,6 +30,7 @@ #include "i915_context.h" #include "i915_batch.h" #include "i915_reg.h" +#include "i915_resource.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" @@ -211,8 +212,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) if (cbuf_surface) { unsigned ctile = BUF_3D_USE_FENCE; - struct i915_texture *tex = (struct i915_texture *) - cbuf_surface->texture; + struct i915_texture *tex = i915_texture(cbuf_surface->texture); assert(tex); if (tex && tex->sw_tiled) { @@ -234,8 +234,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) */ if (depth_surface) { unsigned ztile = BUF_3D_USE_FENCE; - struct i915_texture *tex = (struct i915_texture *) - depth_surface->texture; + struct i915_texture *tex = i915_texture(depth_surface->texture); assert(tex); if (tex && tex->sw_tiled) { @@ -290,7 +289,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) OUT_BATCH(enabled); for (unit = 0; unit < I915_TEX_UNITS; unit++) { if (enabled & (1 << unit)) { - struct i915_texture *texture = (struct i915_texture *)i915->fragment_sampler_views[unit]->texture; + struct i915_texture *texture = i915_texture(i915->fragment_sampler_views[unit]->texture); struct intel_buffer *buf = texture->buffer; uint offset = 0; assert(buf); diff --git a/src/gallium/drivers/i915/i915_state_sampler.c b/src/gallium/drivers/i915/i915_state_sampler.c index d6da822549..26f947b2a0 100644 --- a/src/gallium/drivers/i915/i915_state_sampler.c +++ b/src/gallium/drivers/i915/i915_state_sampler.c @@ -32,6 +32,7 @@ #include "i915_context.h" #include "i915_reg.h" #include "i915_state.h" +#include "i915_resource.h" /* @@ -77,7 +78,7 @@ static void update_sampler(struct i915_context *i915, const struct i915_texture *tex, unsigned state[3] ) { - const struct pipe_texture *pt = &tex->base; + const struct pipe_resource *pt = &tex->b.b; unsigned minlod, lastlod; /* Need to do this after updating the maps, which call the @@ -149,7 +150,7 @@ void i915_update_samplers( struct i915_context *i915 ) /* determine unit enable/disable by looking for a bound texture */ /* could also examine the fragment program? */ if (i915->fragment_sampler_views[unit]) { - struct i915_texture *texture = (struct i915_texture *)i915->fragment_sampler_views[unit]->texture; + struct i915_texture *texture = i915_texture(i915->fragment_sampler_views[unit]->texture); update_sampler( i915, unit, @@ -230,7 +231,7 @@ i915_update_texture(struct i915_context *i915, const struct i915_sampler_state *sampler, uint state[6]) { - const struct pipe_texture *pt = &tex->base; + const struct pipe_resource *pt = &tex->b.b; uint format, pitch; const uint width = pt->width0, height = pt->height0, depth = pt->depth0; const uint num_levels = pt->last_level; @@ -288,7 +289,7 @@ i915_update_textures(struct i915_context *i915) /* determine unit enable/disable by looking for a bound texture */ /* could also examine the fragment program? */ if (i915->fragment_sampler_views[unit]) { - struct i915_texture *texture = (struct i915_texture *)i915->fragment_sampler_views[unit]->texture; + struct i915_texture *texture = i915_texture(i915->fragment_sampler_views[unit]->texture); i915_update_texture( i915, unit, diff --git a/src/gallium/drivers/i915/i915_surface.c b/src/gallium/drivers/i915/i915_surface.c index 1ff6b9f4c6..453437b809 100644 --- a/src/gallium/drivers/i915/i915_surface.c +++ b/src/gallium/drivers/i915/i915_surface.c @@ -25,10 +25,15 @@ * **************************************************************************/ -#include "i915_context.h" +#include "i915_surface.h" +#include "i915_resource.h" #include "i915_blit.h" +#include "i915_screen.h" #include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_math.h" #include "util/u_format.h" +#include "util/u_memory.h" /* Assumes all values are within bounds -- no checking at this level - @@ -41,10 +46,10 @@ i915_surface_copy(struct pipe_context *pipe, struct pipe_surface *src, unsigned srcx, unsigned srcy, unsigned width, unsigned height) { - struct i915_texture *dst_tex = (struct i915_texture *)dst->texture; - struct i915_texture *src_tex = (struct i915_texture *)src->texture; - struct pipe_texture *dpt = &dst_tex->base; - struct pipe_texture *spt = &src_tex->base; + struct i915_texture *dst_tex = i915_texture(dst->texture); + struct i915_texture *src_tex = i915_texture(src->texture); + struct pipe_resource *dpt = &dst_tex->b.b; + struct pipe_resource *spt = &src_tex->b.b; assert( dst != src ); assert( util_format_get_blocksize(dpt->format) == util_format_get_blocksize(spt->format) ); @@ -68,8 +73,8 @@ i915_surface_fill(struct pipe_context *pipe, unsigned dstx, unsigned dsty, unsigned width, unsigned height, unsigned value) { - struct i915_texture *tex = (struct i915_texture *)dst->texture; - struct pipe_texture *pt = &tex->base; + struct i915_texture *tex = i915_texture(dst->texture); + struct pipe_resource *pt = &tex->b.b; assert(util_format_get_blockwidth(pt->format) == 1); assert(util_format_get_blockheight(pt->format) == 1); @@ -84,9 +89,68 @@ i915_surface_fill(struct pipe_context *pipe, } +/* + * Screen surface functions + */ + + +static struct pipe_surface * +i915_get_tex_surface(struct pipe_screen *screen, + struct pipe_resource *pt, + unsigned face, unsigned level, unsigned zslice, + unsigned flags) +{ + struct i915_texture *tex = i915_texture(pt); + struct pipe_surface *ps; + unsigned offset; /* in bytes */ + + if (pt->target == PIPE_TEXTURE_CUBE) { + offset = tex->image_offset[level][face]; + } + else if (pt->target == PIPE_TEXTURE_3D) { + offset = tex->image_offset[level][zslice]; + } + else { + offset = tex->image_offset[level][0]; + assert(face == 0); + assert(zslice == 0); + } + + ps = CALLOC_STRUCT(pipe_surface); + if (ps) { + pipe_reference_init(&ps->reference, 1); + pipe_resource_reference(&ps->texture, pt); + ps->format = pt->format; + ps->width = u_minify(pt->width0, level); + ps->height = u_minify(pt->height0, level); + ps->offset = offset; + ps->usage = flags; + } + return ps; +} + +static void +i915_tex_surface_destroy(struct pipe_surface *surf) +{ + pipe_resource_reference(&surf->texture, NULL); + FREE(surf); +} + + +/* Probably going to make blits work on textures rather than surfaces. + */ void i915_init_surface_functions(struct i915_context *i915) { i915->base.surface_copy = i915_surface_copy; i915->base.surface_fill = i915_surface_fill; } + +/* No good reason for these to be in the screen. + */ +void +i915_init_screen_surface_functions(struct i915_screen *is) +{ + is->base.get_tex_surface = i915_get_tex_surface; + is->base.tex_surface_destroy = i915_tex_surface_destroy; +} diff --git a/src/gallium/drivers/i915/i915_texture.h b/src/gallium/drivers/i915/i915_surface.h index 51a1dd984c..448106d566 100644 --- a/src/gallium/drivers/i915/i915_texture.h +++ b/src/gallium/drivers/i915/i915_surface.h @@ -25,12 +25,14 @@ * **************************************************************************/ -#ifndef I915_TEXTURE_H -#define I915_TEXTURE_H +#ifndef I915_SURFACE_H +#define I915_SURFACE_H +struct i915_context; struct i915_screen; -extern void -i915_init_screen_texture_functions(struct i915_screen *is); +void i915_init_surface_functions( struct i915_context *i915 ); +void i915_init_screen_surface_functions( struct i915_screen *is ); -#endif /* I915_TEXTURE_H */ + +#endif /* I915_SCREEN_H */ diff --git a/src/gallium/drivers/i915/intel_winsys.h b/src/gallium/drivers/i915/intel_winsys.h index 00fd0c1efe..4bfbb6ac5d 100644 --- a/src/gallium/drivers/i915/intel_winsys.h +++ b/src/gallium/drivers/i915/intel_winsys.h @@ -131,7 +131,7 @@ struct intel_winsys { /** * Creates a buffer from a handle. - * Used to implement pipe_screen::texture_from_handle. + * Used to implement pipe_screen::resource_from_handle. * Also provides the stride information needed for the * texture via the stride argument. */ @@ -140,7 +140,7 @@ struct intel_winsys { unsigned *stride); /** - * Used to implement pipe_screen::texture_get_handle. + * Used to implement pipe_screen::resource_get_handle. * The winsys might need the stride information. */ boolean (*buffer_get_handle)(struct intel_winsys *iws, diff --git a/src/gallium/drivers/i965/Makefile b/src/gallium/drivers/i965/Makefile index 95fd3cd69b..86847eb8c7 100644 --- a/src/gallium/drivers/i965/Makefile +++ b/src/gallium/drivers/i965/Makefile @@ -46,7 +46,6 @@ C_SOURCES = \ brw_structs_dump.c \ brw_swtnl.c \ brw_urb.c \ - brw_util.c \ brw_vs.c \ brw_vs_emit.c \ brw_vs_state.c \ @@ -63,9 +62,9 @@ C_SOURCES = \ brw_wm_state.c \ brw_wm_surface_state.c \ brw_screen.c \ - brw_screen_buffers.c \ - brw_screen_tex_layout.c \ - brw_screen_texture.c \ + brw_resource_buffer.c \ + brw_resource_texture.c \ + brw_resource_texture_layout.c \ brw_screen_surface.c \ brw_batchbuffer.c \ brw_winsys_debug.c \ diff --git a/src/gallium/drivers/i965/SConscript b/src/gallium/drivers/i965/SConscript index 9c2faaf4b4..740eb773cd 100644 --- a/src/gallium/drivers/i965/SConscript +++ b/src/gallium/drivers/i965/SConscript @@ -53,7 +53,6 @@ i965 = env.ConvenienceLibrary( 'brw_state_upload.c', 'brw_swtnl.c', 'brw_urb.c', - 'brw_util.c', 'brw_vs.c', 'brw_vs_emit.c', 'brw_vs_state.c', diff --git a/src/gallium/drivers/i965/brw_context.h b/src/gallium/drivers/i965/brw_context.h index dab881fea2..94c9c443f0 100644 --- a/src/gallium/drivers/i965/brw_context.h +++ b/src/gallium/drivers/i965/brw_context.h @@ -561,8 +561,8 @@ struct brw_context struct pipe_stencil_ref stencil_ref; struct pipe_framebuffer_state fb; struct pipe_clip_state ucp; - struct pipe_buffer *vertex_constants; - struct pipe_buffer *fragment_constants; + struct pipe_resource *vertex_constants; + struct pipe_resource *fragment_constants; struct brw_blend_constant_color bcc; struct brw_cc1 cc1_stencil_ref; @@ -574,7 +574,7 @@ struct brw_context * * Updates are signaled by PIPE_NEW_INDEX_BUFFER. */ - struct pipe_buffer *index_buffer; + struct pipe_resource *index_buffer; unsigned index_size; /* Updates are signalled by PIPE_NEW_INDEX_RANGE: diff --git a/src/gallium/drivers/i965/brw_curbe.c b/src/gallium/drivers/i965/brw_curbe.c index 4b215a001c..323af16b14 100644 --- a/src/gallium/drivers/i965/brw_curbe.c +++ b/src/gallium/drivers/i965/brw_curbe.c @@ -160,7 +160,6 @@ static GLfloat fixed_plane[6][4] = { */ static enum pipe_error prepare_curbe_buffer(struct brw_context *brw) { - struct pipe_screen *screen = brw->base.screen; const GLuint sz = brw->curbe.total_size; const GLuint bufsz = sz * 16 * sizeof(GLfloat); enum pipe_error ret; @@ -196,15 +195,11 @@ static enum pipe_error prepare_curbe_buffer(struct brw_context *brw) nr_const = fs->info.file_max[TGSI_FILE_CONSTANT] + 1; /* nr_const = brw->wm.prog_data->nr_params; */ if (nr_const) { - const GLfloat *value = screen->buffer_map( screen, - brw->curr.fragment_constants, - PIPE_BUFFER_USAGE_CPU_READ); - - memcpy(&buf[offset], value, - nr_const * 4 * sizeof(float)); - - screen->buffer_unmap( screen, - brw->curr.fragment_constants ); + pipe_buffer_read( &brw->base, + brw->curr.fragment_constants, + 0, + nr_const * 4 * sizeof(float), + &buf[offset]); } } @@ -258,15 +253,14 @@ static enum pipe_error prepare_curbe_buffer(struct brw_context *brw) * buffer objects. If we want to keep on putting them into the * curbe, makes sense to treat constbuf's specially with malloc. */ - const GLfloat *value = screen->buffer_map( screen, - brw->curr.vertex_constants, - PIPE_BUFFER_USAGE_CPU_READ); /* XXX: what if user's constant buffer is too small? */ - memcpy(&buf[offset], value, nr_const * 4 * sizeof(float)); - - screen->buffer_unmap( screen, brw->curr.vertex_constants ); + pipe_buffer_read(&brw->base, + brw->curr.vertex_constants, + 0, + nr_const * 4 * sizeof(float), + &buf[offset]); } } diff --git a/src/gallium/drivers/i965/brw_draw.c b/src/gallium/drivers/i965/brw_draw.c index 9bad61ef72..a19d27b7cc 100644 --- a/src/gallium/drivers/i965/brw_draw.c +++ b/src/gallium/drivers/i965/brw_draw.c @@ -142,7 +142,7 @@ static int brw_emit_prim(struct brw_context *brw, */ static int try_draw_range_elements(struct brw_context *brw, - struct pipe_buffer *index_buffer, + struct pipe_resource *index_buffer, unsigned hw_prim, unsigned start, unsigned count) { @@ -178,7 +178,7 @@ try_draw_range_elements(struct brw_context *brw, static void brw_draw_range_elements(struct pipe_context *pipe, - struct pipe_buffer *index_buffer, + struct pipe_resource *index_buffer, unsigned index_size, unsigned min_index, unsigned max_index, @@ -201,7 +201,7 @@ brw_draw_range_elements(struct pipe_context *pipe, */ if (brw->curr.index_buffer != index_buffer || brw->curr.index_size != index_size) { - pipe_buffer_reference( &brw->curr.index_buffer, index_buffer ); + pipe_resource_reference( &brw->curr.index_buffer, index_buffer ); brw->curr.index_size = index_size; brw->state.dirty.mesa |= PIPE_NEW_INDEX_BUFFER; } @@ -232,7 +232,7 @@ brw_draw_range_elements(struct pipe_context *pipe, static void brw_draw_elements(struct pipe_context *pipe, - struct pipe_buffer *index_buffer, + struct pipe_resource *index_buffer, unsigned index_size, unsigned mode, unsigned start, unsigned count) @@ -263,14 +263,14 @@ boolean brw_draw_init( struct brw_context *brw ) /* Create helpers for uploading data in user buffers: */ - brw->vb.upload_vertex = u_upload_create( brw->base.screen, + brw->vb.upload_vertex = u_upload_create( &brw->base, 128 * 1024, 64, PIPE_BUFFER_USAGE_VERTEX ); if (brw->vb.upload_vertex == NULL) return FALSE; - brw->vb.upload_index = u_upload_create( brw->base.screen, + brw->vb.upload_index = u_upload_create( &brw->base, 32 * 1024, 64, PIPE_BUFFER_USAGE_INDEX ); diff --git a/src/gallium/drivers/i965/brw_draw_upload.c b/src/gallium/drivers/i965/brw_draw_upload.c index 0820ba20a0..337eee8cd9 100644 --- a/src/gallium/drivers/i965/brw_draw_upload.c +++ b/src/gallium/drivers/i965/brw_draw_upload.c @@ -38,6 +38,7 @@ #include "brw_screen.h" #include "brw_batchbuffer.h" #include "brw_debug.h" +#include "brw_resource.h" @@ -67,7 +68,7 @@ static int brw_prepare_vertices(struct brw_context *brw) for (i = 0; i < brw->curr.num_vertex_buffers; i++) { struct pipe_vertex_buffer *vb = &brw->curr.vertex_buffer[i]; struct brw_winsys_buffer *bo; - struct pipe_buffer *upload_buf = NULL; + struct pipe_resource *upload_buf = NULL; unsigned offset; if (BRW_DEBUG & DEBUG_VERTS) @@ -75,7 +76,7 @@ static int brw_prepare_vertices(struct brw_context *brw) __FUNCTION__, i, brw_buffer_is_user_buffer(vb->buffer), vb->buffer_offset, - vb->buffer->size, + vb->buffer->width0, vb->stride); if (brw_buffer_is_user_buffer(vb->buffer)) { @@ -85,8 +86,8 @@ static int brw_prepare_vertices(struct brw_context *brw) * add support for >1 constant buffer) instead. */ unsigned size = (vb->stride == 0 ? - vb->buffer->size - vb->buffer_offset : - MAX2(vb->buffer->size - vb->buffer_offset, + vb->buffer->width0 - vb->buffer_offset : + MAX2(vb->buffer->width0 - vb->buffer_offset, vb->stride * (max_index + 1 - min_index))); ret = u_upload_buffer( brw->vb.upload_vertex, @@ -123,7 +124,7 @@ static int brw_prepare_vertices(struct brw_context *brw) /* Don't need to retain this reference. We have a reference on * the underlying winsys buffer: */ - pipe_buffer_reference( &upload_buf, NULL ); + pipe_resource_reference( &upload_buf, NULL ); } brw->vb.nr_vb = i; @@ -226,8 +227,8 @@ const struct brw_tracked_state brw_vertices = { static int brw_prepare_indices(struct brw_context *brw) { - struct pipe_buffer *index_buffer = brw->curr.index_buffer; - struct pipe_buffer *upload_buf = NULL; + struct pipe_resource *index_buffer = brw->curr.index_buffer; + struct pipe_resource *upload_buf = NULL; struct brw_winsys_buffer *bo = NULL; GLuint offset; GLuint index_size; @@ -241,9 +242,9 @@ static int brw_prepare_indices(struct brw_context *brw) debug_printf("%s: index_size:%d index_buffer->size:%d\n", __FUNCTION__, brw->curr.index_size, - brw->curr.index_buffer->size); + brw->curr.index_buffer->width0); - ib_size = index_buffer->size; + ib_size = index_buffer->width0; index_size = brw->curr.index_size; /* Turn userbuffer into a proper hardware buffer? @@ -297,7 +298,7 @@ static int brw_prepare_indices(struct brw_context *brw) brw->state.dirty.brw |= BRW_NEW_INDEX_BUFFER; } - pipe_buffer_reference( &upload_buf, NULL ); + pipe_resource_reference( &upload_buf, NULL ); brw_add_validated_bo(brw, brw->ib.bo); return 0; } diff --git a/src/gallium/drivers/i965/brw_pipe_flush.c b/src/gallium/drivers/i965/brw_pipe_flush.c index fdc4814b22..fa2b64fd26 100644 --- a/src/gallium/drivers/i965/brw_pipe_flush.c +++ b/src/gallium/drivers/i965/brw_pipe_flush.c @@ -1,10 +1,11 @@ -#include "util/u_upload_mgr.h" - #include "brw_context.h" #include "brw_screen.h" #include "brw_batchbuffer.h" +#include "util/u_upload_mgr.h" + + /* All batchbuffer flushes must go through this function. @@ -46,35 +47,9 @@ brw_flush( struct pipe_context *pipe, *fence = NULL; } -static unsigned brw_is_buffer_referenced(struct pipe_context *pipe, - struct pipe_buffer *buffer) -{ - struct brw_context *brw = brw_context(pipe); - struct brw_screen *bscreen = brw_screen(brw->base.screen); - - return brw_is_buffer_referenced_by_bo( bscreen, - buffer, - brw->batch->buf ); -} - -static unsigned brw_is_texture_referenced(struct pipe_context *pipe, - struct pipe_texture *texture, - unsigned face, - unsigned level) -{ - struct brw_context *brw = brw_context(pipe); - struct brw_screen *bscreen = brw_screen(brw->base.screen); - - return brw_is_texture_referenced_by_bo( bscreen, - texture, face, level, - brw->batch->buf ); -} - void brw_pipe_flush_init( struct brw_context *brw ) { brw->base.flush = brw_flush; - brw->base.is_buffer_referenced = brw_is_buffer_referenced; - brw->base.is_texture_referenced = brw_is_texture_referenced; } diff --git a/src/gallium/drivers/i965/brw_pipe_sampler.c b/src/gallium/drivers/i965/brw_pipe_sampler.c index d2aa2bc9f3..3fe753ec42 100644 --- a/src/gallium/drivers/i965/brw_pipe_sampler.c +++ b/src/gallium/drivers/i965/brw_pipe_sampler.c @@ -214,7 +214,7 @@ static void brw_bind_vertex_sampler_state(struct pipe_context *pipe, static struct pipe_sampler_view * brw_create_sampler_view(struct pipe_context *pipe, - struct pipe_texture *texture, + struct pipe_resource *texture, const struct pipe_sampler_view *templ) { struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); @@ -223,7 +223,7 @@ brw_create_sampler_view(struct pipe_context *pipe, *view = *templ; view->reference.count = 1; view->texture = NULL; - pipe_texture_reference(&view->texture, texture); + pipe_resource_reference(&view->texture, texture); view->context = pipe; } @@ -235,7 +235,7 @@ static void brw_sampler_view_destroy(struct pipe_context *pipe, struct pipe_sampler_view *view) { - pipe_texture_reference(&view->texture, NULL); + pipe_resource_reference(&view->texture, NULL); FREE(view); } diff --git a/src/gallium/drivers/i965/brw_pipe_shader.c b/src/gallium/drivers/i965/brw_pipe_shader.c index fe445b9982..d9bee96c11 100644 --- a/src/gallium/drivers/i965/brw_pipe_shader.c +++ b/src/gallium/drivers/i965/brw_pipe_shader.c @@ -262,20 +262,20 @@ static void brw_delete_vs_state( struct pipe_context *pipe, void *prog ) static void brw_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index, - struct pipe_buffer *buf) + struct pipe_resource *buf) { struct brw_context *brw = brw_context(pipe); assert(index == 0); if (shader == PIPE_SHADER_FRAGMENT) { - pipe_buffer_reference( &brw->curr.fragment_constants, + pipe_resource_reference( &brw->curr.fragment_constants, buf ); brw->state.dirty.mesa |= PIPE_NEW_FRAGMENT_CONSTANTS; } else { - pipe_buffer_reference( &brw->curr.vertex_constants, + pipe_resource_reference( &brw->curr.vertex_constants, buf ); brw->state.dirty.mesa |= PIPE_NEW_VERTEX_CONSTANTS; @@ -298,6 +298,6 @@ void brw_pipe_shader_init( struct brw_context *brw ) void brw_pipe_shader_cleanup( struct brw_context *brw ) { - pipe_buffer_reference( &brw->curr.fragment_constants, NULL ); - pipe_buffer_reference( &brw->curr.vertex_constants, NULL ); + pipe_resource_reference( &brw->curr.fragment_constants, NULL ); + pipe_resource_reference( &brw->curr.vertex_constants, NULL ); } diff --git a/src/gallium/drivers/i965/brw_pipe_vertex.c b/src/gallium/drivers/i965/brw_pipe_vertex.c index d6a840857e..4a120a51da 100644 --- a/src/gallium/drivers/i965/brw_pipe_vertex.c +++ b/src/gallium/drivers/i965/brw_pipe_vertex.c @@ -259,11 +259,11 @@ static void brw_set_vertex_buffers(struct pipe_context *pipe, /* Adjust refcounts */ for (i = 0; i < count; i++) - pipe_buffer_reference(&brw->curr.vertex_buffer[i].buffer, + pipe_resource_reference(&brw->curr.vertex_buffer[i].buffer, buffers[i].buffer); for ( ; i < brw->curr.num_vertex_buffers; i++) - pipe_buffer_reference(&brw->curr.vertex_buffer[i].buffer, + pipe_resource_reference(&brw->curr.vertex_buffer[i].buffer, NULL); /* Copy remaining data */ diff --git a/src/gallium/drivers/i965/brw_resource.c b/src/gallium/drivers/i965/brw_resource.c new file mode 100644 index 0000000000..d601f42dd1 --- /dev/null +++ b/src/gallium/drivers/i965/brw_resource.c @@ -0,0 +1,50 @@ +#include "util/u_debug.h" + +#include "brw_resource.h" +#include "brw_context.h" +#include "brw_screen.h" + + +static struct pipe_resource * +brw_resource_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + if (template->target == PIPE_BUFFER) + return brw_buffer_create(screen, template); + else + return brw_resource_create(screen, template); + +} + +static struct pipe_resource * +brw_resource_from_handle(struct pipe_screen * screen, + const struct pipe_resource *template, + struct winsys_handle *whandle) +{ + if (template->target == PIPE_BUFFER) + return NULL; + else + return brw_texture_from_handle(screen, template, whandle); +} + + +void +brw_init_resource_functions(struct brw_context *brw ) +{ + brw->base.get_transfer = u_get_transfer_vtbl; + brw->base.transfer_map = u_transfer_map_vtbl; + brw->base.transfer_flush_region = u_transfer_flush_region_vtbl; + brw->base.transfer_unmap = u_transfer_unmap_vtbl; + brw->base.transfer_destroy = u_transfer_destroy_vtbl; + brw->base.transfer_inline_write = u_transfer_inline_write_vtbl; +} + +void +brw_init_screen_resource_functions(struct brw_screen *is) +{ + is->base.resource_create = brw_resource_create; + is->base.resource_from_handle = brw_resource_from_handle; + is->base.resource_get_handle = u_resource_get_handle_vtbl; + is->base.resource_destroy = u_resource_destroy_vtbl; + is->base.user_buffer_create = brw_user_buffer_create; +} diff --git a/src/gallium/drivers/i965/brw_resource.h b/src/gallium/drivers/i965/brw_resource.h new file mode 100644 index 0000000000..3390c270d4 --- /dev/null +++ b/src/gallium/drivers/i965/brw_resource.h @@ -0,0 +1,151 @@ +/************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef BRW_RESOURCE_H +#define BRW_RESOURCE_H + +struct brw_screen; + +#include "util/u_transfer.h" +#include "util/u_debug.h" + +#include "brw_screen.h" /* for brw_surface */ + +struct brw_context; +struct brw_screen; + + +struct brw_buffer { + struct u_resource b; + + /* One of either bo or user_buffer will be non-null, depending on + * whether this is a hardware or user buffer. + */ + struct brw_winsys_buffer *bo; + void *user_buffer; + + /* Mapped pointer?? + */ + void *ptr; +}; + +#define BRW_MAX_TEXTURE_2D_LEVELS 11 /* max 1024x1024 */ +#define BRW_MAX_TEXTURE_3D_LEVELS 8 /* max 128x128x128 */ + + + +struct brw_texture { + struct u_resource b; + struct brw_winsys_buffer *bo; + struct brw_surface_state ss; + + unsigned *image_offset[BRW_MAX_TEXTURE_2D_LEVELS]; + unsigned nr_images[BRW_MAX_TEXTURE_2D_LEVELS]; + unsigned level_offset[BRW_MAX_TEXTURE_2D_LEVELS]; + + boolean compressed; + unsigned brw_target; + unsigned pitch; + unsigned tiling; + unsigned cpp; + unsigned total_height; + + struct brw_surface views[2]; +}; + + +void brw_init_screen_resource_functions(struct brw_screen *is); +void brw_init_resource_functions(struct brw_context *brw ); + +extern struct u_resource_vtbl brw_buffer_vtbl; +extern struct u_resource_vtbl brw_texture_vtbl; + +static INLINE struct brw_texture *brw_texture( struct pipe_resource *resource ) +{ + struct brw_texture *tex = (struct brw_texture *)resource; + assert(tex->b.vtbl == &brw_texture_vtbl); + return tex; +} + +static INLINE struct brw_buffer *brw_buffer( struct pipe_resource *resource ) +{ + struct brw_buffer *tex = (struct brw_buffer *)resource; + assert(tex->b.vtbl == &brw_buffer_vtbl); + return tex; +} + +struct pipe_resource * +brw_texture_create(struct pipe_screen *screen, + const struct pipe_resource *template); + +struct pipe_resource * +brw_texture_from_handle(struct pipe_screen * screen, + const struct pipe_resource *template, + struct winsys_handle *whandle); + + +struct pipe_resource * +brw_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned usage); + +struct pipe_resource * +brw_buffer_create(struct pipe_screen *screen, + const struct pipe_resource *template); + + +/* +boolean +brw_is_format_supported( struct pipe_screen *screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags ); +*/ + +/* Pipe buffer helpers + */ +static INLINE boolean +brw_buffer_is_user_buffer( const struct pipe_resource *buf ) +{ + return ((const struct brw_buffer *)buf)->user_buffer != NULL; +} + + +/*********************************************************************** + * Internal functions + */ +GLboolean brw_texture_layout(struct brw_screen *brw_screen, + struct brw_texture *tex ); + +void brw_update_texture( struct brw_screen *brw_screen, + struct brw_texture *tex ); + + + +#endif /* BRW_RESOURCE_H */ diff --git a/src/gallium/drivers/i965/brw_resource_buffer.c b/src/gallium/drivers/i965/brw_resource_buffer.c new file mode 100644 index 0000000000..db5883e67b --- /dev/null +++ b/src/gallium/drivers/i965/brw_resource_buffer.c @@ -0,0 +1,205 @@ + +#include "util/u_memory.h" +#include "util/u_math.h" + +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" + +#include "brw_resource.h" +#include "brw_context.h" +#include "brw_batchbuffer.h" +#include "brw_winsys.h" + +static boolean +brw_buffer_get_handle(struct pipe_screen *screen, + struct pipe_resource *resource, + struct winsys_handle *handle) +{ + return FALSE; +} + + +static void +brw_buffer_destroy(struct pipe_screen *screen, + struct pipe_resource *resource) +{ + struct brw_buffer *buf = brw_buffer( resource ); + + bo_reference(&buf->bo, NULL); + FREE(buf); +} + + +static void * +brw_buffer_transfer_map( struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct brw_screen *bscreen = brw_screen(pipe->screen); + struct brw_winsys_screen *sws = bscreen->sws; + struct brw_buffer *buf = brw_buffer(transfer->resource); + unsigned offset = transfer->box.x; + unsigned length = transfer->box.width; + unsigned usage = transfer->usage; + uint8_t *map; + + if (buf->user_buffer) + map = buf->user_buffer; + else + map = sws->bo_map( buf->bo, + BRW_DATA_OTHER, + offset, + length, + (usage & PIPE_TRANSFER_WRITE) ? TRUE : FALSE, + (usage & PIPE_TRANSFER_DISCARD) ? TRUE : FALSE, + (usage & PIPE_TRANSFER_FLUSH_EXPLICIT) ? TRUE : FALSE); + + return map + offset; +} + + +static void +brw_buffer_transfer_flush_region( struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box) +{ + struct brw_screen *bscreen = brw_screen(pipe->screen); + struct brw_winsys_screen *sws = bscreen->sws; + struct brw_buffer *buf = brw_buffer(transfer->resource); + unsigned offset = box->x; + unsigned length = box->width; + + if (buf->user_buffer) + return; + + sws->bo_flush_range( buf->bo, + offset, + length ); +} + + +static void +brw_buffer_transfer_unmap( struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct brw_screen *bscreen = brw_screen(pipe->screen); + struct brw_winsys_screen *sws = bscreen->sws; + struct brw_buffer *buf = brw_buffer( transfer->resource ); + + if (buf->bo) + sws->bo_unmap(buf->bo); +} + + +static unsigned brw_buffer_is_referenced( struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned face, + unsigned level) +{ + struct brw_context *brw = brw_context(pipe); + struct brw_winsys_buffer *batch_bo = brw->batch->buf; + struct brw_buffer *buf = brw_buffer(resource); + + if (buf->bo == NULL) + return PIPE_UNREFERENCED; + + if (!brw_screen(pipe->screen)->sws->bo_references( batch_bo, buf->bo )) + return PIPE_UNREFERENCED; + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + + +struct u_resource_vtbl brw_buffer_vtbl = +{ + brw_buffer_get_handle, /* get_handle */ + brw_buffer_destroy, /* resource_destroy */ + brw_buffer_is_referenced, /* is_resource_referenced */ + u_default_get_transfer, /* get_transfer */ + u_default_transfer_destroy, /* transfer_destroy */ + brw_buffer_transfer_map, /* transfer_map */ + brw_buffer_transfer_flush_region, /* transfer_flush_region */ + brw_buffer_transfer_unmap, /* transfer_unmap */ + u_default_transfer_inline_write /* transfer_inline_write */ +}; + + +struct pipe_resource * +brw_buffer_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + struct brw_screen *bscreen = brw_screen(screen); + struct brw_winsys_screen *sws = bscreen->sws; + struct brw_buffer *buf; + unsigned buffer_type; + enum pipe_error ret; + + buf = CALLOC_STRUCT(brw_buffer); + if (!buf) + return NULL; + + buf->b.b = *template; + buf->b.vtbl = &brw_buffer_vtbl; + pipe_reference_init(&buf->b.b.reference, 1); + buf->b.b.screen = screen; + + switch (template->usage & (PIPE_BUFFER_USAGE_VERTEX | + PIPE_BUFFER_USAGE_INDEX | + PIPE_BUFFER_USAGE_PIXEL | + PIPE_BUFFER_USAGE_CONSTANT)) + { + case PIPE_BUFFER_USAGE_VERTEX: + case PIPE_BUFFER_USAGE_INDEX: + case (PIPE_BUFFER_USAGE_VERTEX|PIPE_BUFFER_USAGE_INDEX): + buffer_type = BRW_BUFFER_TYPE_VERTEX; + break; + + case PIPE_BUFFER_USAGE_PIXEL: + buffer_type = BRW_BUFFER_TYPE_PIXEL; + break; + + case PIPE_BUFFER_USAGE_CONSTANT: + buffer_type = BRW_BUFFER_TYPE_SHADER_CONSTANTS; + break; + + default: + buffer_type = BRW_BUFFER_TYPE_GENERIC; + break; + } + + ret = sws->bo_alloc( sws, buffer_type, + template->width0, + 64, /* alignment */ + &buf->bo ); + if (ret != PIPE_OK) + return NULL; + + return &buf->b.b; +} + + +struct pipe_resource * +brw_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned usage) +{ + struct brw_buffer *buf; + + buf = CALLOC_STRUCT(brw_buffer); + if (!buf) + return NULL; + + pipe_reference_init(&buf->b.b.reference, 1); + buf->b.vtbl = &brw_buffer_vtbl; + buf->b.b.screen = screen; + buf->b.b.format = PIPE_FORMAT_R8_UNORM; /* ?? */ + buf->b.b.usage = PIPE_BUFFER_USAGE_CPU_READ | usage; + buf->b.b.width0 = bytes; + buf->b.b.height0 = 1; + buf->b.b.depth0 = 1; + + buf->user_buffer = ptr; + + return &buf->b.b; +} diff --git a/src/gallium/drivers/i965/brw_screen_texture.c b/src/gallium/drivers/i965/brw_resource_texture.c index cadcb7cee2..023d863183 100644 --- a/src/gallium/drivers/i965/brw_screen_texture.c +++ b/src/gallium/drivers/i965/brw_resource_texture.c @@ -37,9 +37,26 @@ #include "brw_defines.h" #include "brw_structs.h" #include "brw_winsys.h" +#include "brw_batchbuffer.h" #include "brw_context.h" +#include "brw_resource.h" +/** + * Subclass of pipe_transfer + */ +struct brw_transfer +{ + struct pipe_transfer base; + + unsigned offset; +}; + +static INLINE struct brw_transfer * +brw_transfer(struct pipe_transfer *transfer) +{ + return (struct brw_transfer *)transfer; +} static GLuint translate_tex_target( unsigned target ) @@ -182,12 +199,153 @@ static GLuint translate_tex_format( enum pipe_format pf ) } +static boolean +brw_texture_get_handle(struct pipe_screen *screen, + struct pipe_resource *texture, + struct winsys_handle *whandle) +{ + struct brw_screen *bscreen = brw_screen(screen); + struct brw_texture *tex = brw_texture(texture); + unsigned stride; + + stride = tex->pitch * tex->cpp; + + return bscreen->sws->bo_get_handle(tex->bo, whandle, stride); +} + + + +static void brw_texture_destroy(struct pipe_screen *screen, + struct pipe_resource *pt) +{ + struct brw_texture *tex = brw_texture(pt); + bo_reference(&tex->bo, NULL); + FREE(pt); +} + + + + +static unsigned brw_texture_is_referenced( struct pipe_context *pipe, + struct pipe_resource *texture, + unsigned face, + unsigned level ) +{ + struct brw_context *brw = brw_context(pipe); + struct brw_screen *bscreen = brw_screen(pipe->screen); + struct brw_winsys_buffer *batch_bo = brw->batch->buf; + struct brw_texture *tex = brw_texture(texture); + struct brw_surface *surf; + int i; + + /* XXX: this is subject to false positives if the underlying + * texture BO is referenced, we can't tell whether the sub-region + * we care about participates in that. + */ + if (bscreen->sws->bo_references( batch_bo, tex->bo )) + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; + + /* Find any view on this texture for this face/level and see if it + * is referenced: + */ + for (i = 0; i < 2; i++) { + foreach (surf, &tex->views[i]) { + if (surf->bo == tex->bo) + continue; + + if (surf->id.bits.face != face || + surf->id.bits.level != level) + continue; + + if (bscreen->sws->bo_references( batch_bo, surf->bo)) + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; + } + } + + return PIPE_UNREFERENCED; +} + + +/* + * Transfer functions + */ + +static void * +brw_texture_transfer_map(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct pipe_resource *resource = transfer->resource; + struct brw_texture *tex = brw_texture(transfer->resource); + struct brw_winsys_screen *sws = brw_screen(pipe->screen)->sws; + struct pipe_subresource sr = transfer->sr; + struct pipe_box *box = &transfer->box; + enum pipe_format format = resource->format; + unsigned usage = transfer->usage; + unsigned offset; + char *map; + + if (resource->target == PIPE_TEXTURE_CUBE) { + offset = tex->image_offset[sr.level][sr.face]; + } + else if (resource->target == PIPE_TEXTURE_3D) { + offset = tex->image_offset[sr.level][box->z]; + } + else { + offset = tex->image_offset[sr.level][0]; + assert(sr.face == 0); + assert(box->z == 0); + } + + map = sws->bo_map(tex->bo, + BRW_DATA_OTHER, + 0, + tex->bo->size, + (usage & PIPE_TRANSFER_WRITE) ? TRUE : FALSE, + (usage & 0) ? TRUE : FALSE, + (usage & 0) ? TRUE : FALSE); + + if (!map) + return NULL; + + return map + offset + + box->y / util_format_get_blockheight(format) * transfer->stride + + box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); +} + +static void +brw_texture_transfer_unmap(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct brw_texture *tex = brw_texture(transfer->resource); + struct brw_winsys_screen *sws = brw_screen(pipe->screen)->sws; + + sws->bo_unmap(tex->bo); +} + + + +struct u_resource_vtbl brw_texture_vtbl = +{ + brw_texture_get_handle, /* get_handle */ + brw_texture_destroy, /* resource_destroy */ + brw_texture_is_referenced, /* is_resource_referenced */ + u_default_get_transfer, /* get_transfer */ + u_default_transfer_destroy, /* transfer_destroy */ + brw_texture_transfer_map, /* transfer_map */ + u_default_transfer_flush_region, /* transfer_flush_region */ + brw_texture_transfer_unmap, /* transfer_unmap */ + u_default_transfer_inline_write /* transfer_inline_write */ +}; -static struct pipe_texture *brw_texture_create( struct pipe_screen *screen, - const struct pipe_texture *templ ) + + + +struct pipe_resource * +brw_texture_create( struct pipe_screen *screen, + const struct pipe_resource *template ) { struct brw_screen *bscreen = brw_screen(screen); struct brw_texture *tex; @@ -199,14 +357,15 @@ static struct pipe_texture *brw_texture_create( struct pipe_screen *screen, if (tex == NULL) return NULL; - memcpy(&tex->base, templ, sizeof *templ); - pipe_reference_init(&tex->base.reference, 1); - tex->base.screen = screen; + tex->b.b = *template; + tex->b.vtbl = &brw_texture_vtbl; + pipe_reference_init(&tex->b.b.reference, 1); + tex->b.b.screen = screen; /* XXX: compressed textures need special treatment here */ - tex->cpp = util_format_get_blocksize(tex->base.format); - tex->compressed = util_format_is_compressed(tex->base.format); + tex->cpp = util_format_get_blocksize(tex->b.b.format); + tex->compressed = util_format_is_compressed(tex->b.b.format); make_empty_list(&tex->views[0]); make_empty_list(&tex->views[1]); @@ -217,7 +376,7 @@ static struct pipe_texture *brw_texture_create( struct pipe_screen *screen, !bscreen->no_tiling) { if (bscreen->chipset.is_965 && - util_format_is_depth_or_stencil(templ->format)) + util_format_is_depth_or_stencil(template->format)) tex->tiling = BRW_TILING_Y; else tex->tiling = BRW_TILING_X; @@ -227,13 +386,11 @@ static struct pipe_texture *brw_texture_create( struct pipe_screen *screen, } - - if (!brw_texture_layout( bscreen, tex )) goto fail; - if (templ->tex_usage & (PIPE_TEXTURE_USAGE_SCANOUT | + if (template->tex_usage & (PIPE_TEXTURE_USAGE_SCANOUT | PIPE_TEXTURE_USAGE_SHARED)) { buffer_type = BRW_BUFFER_TYPE_SCANOUT; } @@ -250,9 +407,9 @@ static struct pipe_texture *brw_texture_create( struct pipe_screen *screen, goto fail; tex->ss.ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW; - tex->ss.ss0.surface_type = translate_tex_target(tex->base.target); + tex->ss.ss0.surface_type = translate_tex_target(tex->b.b.target); - format = translate_tex_format(tex->base.format); + format = translate_tex_format(tex->b.b.format); assert(format != BRW_SURFACEFORMAT_INVALID); tex->ss.ss0.surface_format = format; @@ -264,9 +421,9 @@ static struct pipe_texture *brw_texture_create( struct pipe_screen *screen, /* XXX: what happens when tex->bo->offset changes??? */ tex->ss.ss1.base_addr = 0; /* reloc */ - tex->ss.ss2.mip_count = tex->base.last_level; - tex->ss.ss2.width = tex->base.width0 - 1; - tex->ss.ss2.height = tex->base.height0 - 1; + tex->ss.ss2.mip_count = tex->b.b.last_level; + tex->ss.ss2.width = tex->b.b.width0 - 1; + tex->ss.ss2.height = tex->b.b.height0 - 1; switch (tex->tiling) { case BRW_TILING_NONE: @@ -284,11 +441,11 @@ static struct pipe_texture *brw_texture_create( struct pipe_screen *screen, } tex->ss.ss3.pitch = (tex->pitch * tex->cpp) - 1; - tex->ss.ss3.depth = tex->base.depth0 - 1; + tex->ss.ss3.depth = tex->b.b.depth0 - 1; tex->ss.ss4.min_lod = 0; - if (tex->base.target == PIPE_TEXTURE_CUBE) { + if (tex->b.b.target == PIPE_TEXTURE_CUBE) { tex->ss.ss0.cube_pos_x = 1; tex->ss.ss0.cube_pos_y = 1; tex->ss.ss0.cube_pos_z = 1; @@ -297,7 +454,7 @@ static struct pipe_texture *brw_texture_create( struct pipe_screen *screen, tex->ss.ss0.cube_neg_z = 1; } - return &tex->base; + return &tex->b.b; fail: bo_reference(&tex->bo, NULL); @@ -305,9 +462,10 @@ fail: return NULL; } -static struct pipe_texture * + +struct pipe_resource * brw_texture_from_handle(struct pipe_screen *screen, - const struct pipe_texture *templ, + const struct pipe_resource *template, struct winsys_handle *whandle) { struct brw_screen *bscreen = brw_screen(screen); @@ -316,12 +474,12 @@ brw_texture_from_handle(struct pipe_screen *screen, unsigned tiling; unsigned pitch; - if (templ->target != PIPE_TEXTURE_2D || - templ->last_level != 0 || - templ->depth0 != 1) + if (template->target != PIPE_TEXTURE_2D || + template->last_level != 0 || + template->depth0 != 1) return NULL; - if (util_format_is_compressed(templ->format)) + if (util_format_is_compressed(template->format)) return NULL; tex = CALLOC_STRUCT(brw_texture); @@ -331,13 +489,14 @@ brw_texture_from_handle(struct pipe_screen *screen, if (bscreen->sws->bo_from_handle(bscreen->sws, whandle, &pitch, &tiling, &buffer) != PIPE_OK) goto fail; - memcpy(&tex->base, templ, sizeof *templ); - pipe_reference_init(&tex->base.reference, 1); - tex->base.screen = screen; + tex->b.b = *template; + tex->b.vtbl = &brw_texture_vtbl; + pipe_reference_init(&tex->b.b.reference, 1); + tex->b.b.screen = screen; /* XXX: cpp vs. blocksize */ - tex->cpp = util_format_get_blocksize(tex->base.format); + tex->cpp = util_format_get_blocksize(tex->b.b.format); tex->tiling = tiling; make_empty_list(&tex->views[0]); @@ -361,8 +520,8 @@ brw_texture_from_handle(struct pipe_screen *screen, #endif tex->ss.ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW; - tex->ss.ss0.surface_type = translate_tex_target(tex->base.target); - tex->ss.ss0.surface_format = translate_tex_format(tex->base.format); + tex->ss.ss0.surface_type = translate_tex_target(tex->b.b.target); + tex->ss.ss0.surface_format = translate_tex_format(tex->b.b.format); assert(tex->ss.ss0.surface_format != BRW_SURFACEFORMAT_INVALID); /* This is ok for all textures with channel width 8bit or less: @@ -373,9 +532,9 @@ brw_texture_from_handle(struct pipe_screen *screen, /* XXX: what happens when tex->bo->offset changes??? */ tex->ss.ss1.base_addr = 0; /* reloc */ - tex->ss.ss2.mip_count = tex->base.last_level; - tex->ss.ss2.width = tex->base.width0 - 1; - tex->ss.ss2.height = tex->base.height0 - 1; + tex->ss.ss2.mip_count = tex->b.b.last_level; + tex->ss.ss2.width = tex->b.b.width0 - 1; + tex->ss.ss2.height = tex->b.b.height0 - 1; switch (tex->tiling) { case BRW_TILING_NONE: @@ -393,187 +552,25 @@ brw_texture_from_handle(struct pipe_screen *screen, } tex->ss.ss3.pitch = (tex->pitch * tex->cpp) - 1; - tex->ss.ss3.depth = tex->base.depth0 - 1; + tex->ss.ss3.depth = tex->b.b.depth0 - 1; tex->ss.ss4.min_lod = 0; - return &tex->base; + return &tex->b.b; fail: FREE(tex); return NULL; } -static boolean -brw_texture_get_handle(struct pipe_screen *screen, - struct pipe_texture *texture, - struct winsys_handle *whandle) -{ - struct brw_screen *bscreen = brw_screen(screen); - struct brw_texture *tex = brw_texture(texture); - unsigned stride; - - stride = tex->pitch * tex->cpp; - - return bscreen->sws->bo_get_handle(tex->bo, whandle, stride); -} - - -static void brw_texture_destroy(struct pipe_texture *pt) -{ - struct brw_texture *tex = brw_texture(pt); - bo_reference(&tex->bo, NULL); - FREE(pt); -} - - -static boolean brw_is_format_supported( struct pipe_screen *screen, - enum pipe_format format, - enum pipe_texture_target target, - unsigned tex_usage, - unsigned geom_flags ) +#if 0 +boolean brw_is_format_supported( struct pipe_screen *screen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags ) { return translate_tex_format(format) != BRW_SURFACEFORMAT_INVALID; } - - -boolean brw_is_texture_referenced_by_bo( struct brw_screen *brw_screen, - struct pipe_texture *texture, - unsigned face, - unsigned level, - struct brw_winsys_buffer *bo ) -{ - struct brw_texture *tex = brw_texture(texture); - struct brw_surface *surf; - int i; - - /* XXX: this is subject to false positives if the underlying - * texture BO is referenced, we can't tell whether the sub-region - * we care about participates in that. - */ - if (brw_screen->sws->bo_references( bo, tex->bo )) - return TRUE; - - /* Find any view on this texture for this face/level and see if it - * is referenced: - */ - for (i = 0; i < 2; i++) { - foreach (surf, &tex->views[i]) { - if (surf->bo == tex->bo) - continue; - - if (surf->id.bits.face != face || - surf->id.bits.level != level) - continue; - - if (brw_screen->sws->bo_references( bo, surf->bo)) - return TRUE; - } - } - - return FALSE; -} - - -/* - * Transfer functions - */ - -static struct pipe_transfer* -brw_get_tex_transfer(struct pipe_context *pipe, - struct pipe_texture *texture, - unsigned face, unsigned level, unsigned zslice, - enum pipe_transfer_usage usage, unsigned x, unsigned y, - unsigned w, unsigned h) -{ - struct brw_texture *tex = brw_texture(texture); - struct brw_transfer *trans; - unsigned offset; /* in bytes */ - - if (texture->target == PIPE_TEXTURE_CUBE) { - offset = tex->image_offset[level][face]; - } else if (texture->target == PIPE_TEXTURE_3D) { - offset = tex->image_offset[level][zslice]; - } else { - offset = tex->image_offset[level][0]; - assert(face == 0); - assert(zslice == 0); - } - - trans = CALLOC_STRUCT(brw_transfer); - if (trans) { - pipe_texture_reference(&trans->base.texture, texture); - trans->base.x = x; - trans->base.y = y; - trans->base.width = w; - trans->base.height = h; - trans->base.stride = tex->pitch * tex->cpp; - trans->offset = offset; - trans->base.usage = usage; - } - return &trans->base; -} - -static void * -brw_transfer_map(struct pipe_context *pipe, - struct pipe_transfer *transfer) -{ - struct brw_texture *tex = brw_texture(transfer->texture); - struct brw_winsys_screen *sws = brw_screen(pipe->screen)->sws; - char *map; - unsigned usage = transfer->usage; - - map = sws->bo_map(tex->bo, - BRW_DATA_OTHER, - 0, - tex->bo->size, - (usage & PIPE_TRANSFER_WRITE) ? TRUE : FALSE, - (usage & 0) ? TRUE : FALSE, - (usage & 0) ? TRUE : FALSE); - - if (!map) - return NULL; - - /* XXX: blocksize and compressed textures - */ - return map + brw_transfer(transfer)->offset + - transfer->y /* / transfer->block.height */ * transfer->stride + - transfer->x /* / transfer->block.width */ * brw_texture(transfer->texture)->cpp; -} - -static void -brw_transfer_unmap(struct pipe_context *pipe, - struct pipe_transfer *transfer) -{ - struct brw_texture *tex = brw_texture(transfer->texture); - struct brw_winsys_screen *sws = brw_screen(pipe->screen)->sws; - - sws->bo_unmap(tex->bo); -} - -static void -brw_tex_transfer_destroy(struct pipe_context *pipe, - struct pipe_transfer *trans) -{ - pipe_texture_reference(&trans->texture, NULL); - FREE(trans); -} - - -void brw_tex_init( struct brw_context *brw ) -{ - brw->base.get_tex_transfer = brw_get_tex_transfer; - brw->base.transfer_map = brw_transfer_map; - brw->base.transfer_unmap = brw_transfer_unmap; - brw->base.tex_transfer_destroy = brw_tex_transfer_destroy; -} - -void brw_screen_tex_init( struct brw_screen *brw_screen ) -{ - brw_screen->base.is_format_supported = brw_is_format_supported; - brw_screen->base.texture_create = brw_texture_create; - brw_screen->base.texture_from_handle = brw_texture_from_handle; - brw_screen->base.texture_get_handle = brw_texture_get_handle; - brw_screen->base.texture_destroy = brw_texture_destroy; -} +#endif diff --git a/src/gallium/drivers/i965/brw_screen_tex_layout.c b/src/gallium/drivers/i965/brw_resource_texture_layout.c index 894f4bea40..2187bdd82c 100644 --- a/src/gallium/drivers/i965/brw_screen_tex_layout.c +++ b/src/gallium/drivers/i965/brw_resource_texture_layout.c @@ -30,7 +30,7 @@ #include "util/u_math.h" #include "util/u_memory.h" -#include "brw_screen.h" +#include "brw_resource.h" #include "brw_debug.h" #include "brw_winsys.h" @@ -143,14 +143,14 @@ static void brw_layout_2d( struct brw_texture *tex ) GLuint level; GLuint x = 0; GLuint y = 0; - GLuint width = tex->base.width0; - GLuint height = tex->base.height0; + GLuint width = tex->b.b.width0; + GLuint height = tex->b.b.height0; - tex->pitch = tex->base.width0; - brw_tex_alignment_unit(tex->base.format, &align_w, &align_h); + tex->pitch = tex->b.b.width0; + brw_tex_alignment_unit(tex->b.b.format, &align_w, &align_h); if (tex->compressed) { - tex->pitch = align(tex->base.width0, align_w); + tex->pitch = align(tex->b.b.width0, align_w); } /* May need to adjust pitch to accomodate the placement of @@ -158,15 +158,15 @@ static void brw_layout_2d( struct brw_texture *tex ) * constraints of mipmap placement push the right edge of the * 2nd mipmap out past the width of its parent. */ - if (tex->base.last_level > 0) { + if (tex->b.b.last_level > 0) { GLuint mip1_width; if (tex->compressed) { - mip1_width = (align(u_minify(tex->base.width0, 1), align_w) + - align(u_minify(tex->base.width0, 2), align_w)); + mip1_width = (align(u_minify(tex->b.b.width0, 1), align_w) + + align(u_minify(tex->b.b.width0, 2), align_w)); } else { - mip1_width = (align(u_minify(tex->base.width0, 1), align_w) + - u_minify(tex->base.width0, 2)); + mip1_width = (align(u_minify(tex->b.b.width0, 1), align_w) + + u_minify(tex->b.b.width0, 2)); } if (mip1_width > tex->pitch) { @@ -180,7 +180,7 @@ static void brw_layout_2d( struct brw_texture *tex ) tex->pitch = brw_tex_pitch_align (tex, tex->pitch); tex->total_height = 0; - for ( level = 0 ; level <= tex->base.last_level ; level++ ) { + for ( level = 0 ; level <= tex->b.b.last_level ; level++ ) { GLuint img_height; brw_tex_set_level_info(tex, level, 1, x, y, width, height, 1); @@ -218,28 +218,28 @@ brw_layout_cubemap_idgng( struct brw_texture *tex ) GLuint level; GLuint x = 0; GLuint y = 0; - GLuint width = tex->base.width0; - GLuint height = tex->base.height0; + GLuint width = tex->b.b.width0; + GLuint height = tex->b.b.height0; GLuint qpitch = 0; GLuint y_pitch = 0; - tex->pitch = tex->base.width0; - brw_tex_alignment_unit(tex->base.format, &align_w, &align_h); + tex->pitch = tex->b.b.width0; + brw_tex_alignment_unit(tex->b.b.format, &align_w, &align_h); y_pitch = align(height, align_h); if (tex->compressed) { - tex->pitch = align(tex->base.width0, align_w); + tex->pitch = align(tex->b.b.width0, align_w); } - if (tex->base.last_level != 0) { + if (tex->b.b.last_level != 0) { GLuint mip1_width; if (tex->compressed) { - mip1_width = (align(u_minify(tex->base.width0, 1), align_w) + - align(u_minify(tex->base.width0, 2), align_w)); + mip1_width = (align(u_minify(tex->b.b.width0, 1), align_w) + + align(u_minify(tex->b.b.width0, 2), align_w)); } else { - mip1_width = (align(u_minify(tex->base.width0, 1), align_w) + - u_minify(tex->base.width0, 2)); + mip1_width = (align(u_minify(tex->b.b.width0, 1), align_w) + + u_minify(tex->b.b.width0, 2)); } if (mip1_width > tex->pitch) { @@ -267,7 +267,7 @@ brw_layout_cubemap_idgng( struct brw_texture *tex ) 11 * align_h) * 6; } - for (level = 0; level <= tex->base.last_level; level++) { + for (level = 0; level <= tex->b.b.last_level; level++) { GLuint img_height; GLuint nr_images = 6; GLuint q = 0; @@ -300,9 +300,9 @@ brw_layout_cubemap_idgng( struct brw_texture *tex ) static boolean brw_layout_3d_cube( struct brw_texture *tex ) { - GLuint width = tex->base.width0; - GLuint height = tex->base.height0; - GLuint depth = tex->base.depth0; + GLuint width = tex->b.b.width0; + GLuint height = tex->b.b.height0; + GLuint depth = tex->b.b.depth0; GLuint pack_x_pitch, pack_x_nr; GLuint pack_y_pitch; GLuint level; @@ -310,21 +310,21 @@ brw_layout_3d_cube( struct brw_texture *tex ) GLuint align_w = 4; tex->total_height = 0; - brw_tex_alignment_unit(tex->base.format, &align_w, &align_h); + brw_tex_alignment_unit(tex->b.b.format, &align_w, &align_h); if (tex->compressed) { tex->pitch = align(width, align_w); pack_y_pitch = (height + 3) / 4; } else { - tex->pitch = brw_tex_pitch_align(tex, tex->base.width0); - pack_y_pitch = align(tex->base.height0, align_h); + tex->pitch = brw_tex_pitch_align(tex, tex->b.b.width0); + pack_y_pitch = align(tex->b.b.height0, align_h); } pack_x_pitch = width; pack_x_nr = 1; - for (level = 0 ; level <= tex->base.last_level ; level++) { - GLuint nr_images = tex->base.target == PIPE_TEXTURE_3D ? depth : 6; + for (level = 0 ; level <= tex->b.b.last_level ; level++) { + GLuint nr_images = tex->b.b.target == PIPE_TEXTURE_3D ? depth : 6; GLint x = 0; GLint y = 0; GLint q, j; @@ -375,7 +375,7 @@ brw_layout_3d_cube( struct brw_texture *tex ) * memory. As a result, the docs say in Surface Padding Requirements: * Sampling Engine Surfaces that two extra rows of padding are required. */ - if (tex->base.target == PIPE_TEXTURE_CUBE) + if (tex->b.b.target == PIPE_TEXTURE_CUBE) tex->total_height += 2; return TRUE; @@ -386,7 +386,7 @@ brw_layout_3d_cube( struct brw_texture *tex ) GLboolean brw_texture_layout(struct brw_screen *brw_screen, struct brw_texture *tex ) { - switch (tex->base.target) { + switch (tex->b.b.target) { case PIPE_TEXTURE_CUBE: if (brw_screen->chipset.is_igdng) brw_layout_cubemap_idgng( tex ); diff --git a/src/gallium/drivers/i965/brw_screen.c b/src/gallium/drivers/i965/brw_screen.c index cef83ffea8..692c17d3f4 100644 --- a/src/gallium/drivers/i965/brw_screen.c +++ b/src/gallium/drivers/i965/brw_screen.c @@ -35,6 +35,7 @@ #include "brw_screen.h" #include "brw_winsys.h" #include "brw_debug.h" +#include "brw_resource.h" #ifdef DEBUG static const struct debug_named_value debug_names[] = { @@ -406,9 +407,8 @@ brw_create_screen(struct brw_winsys_screen *sws, uint pci_id) bscreen->base.fence_signalled = brw_fence_signalled; bscreen->base.fence_finish = brw_fence_finish; - brw_screen_tex_init(bscreen); + brw_init_screen_resource_functions(bscreen); brw_screen_tex_surface_init(bscreen); - brw_screen_buffer_init(bscreen); bscreen->no_tiling = debug_get_option("BRW_NO_TILING", FALSE) != NULL; diff --git a/src/gallium/drivers/i965/brw_screen.h b/src/gallium/drivers/i965/brw_screen.h index e3a7c64d48..522a3bf899 100644 --- a/src/gallium/drivers/i965/brw_screen.h +++ b/src/gallium/drivers/i965/brw_screen.h @@ -48,30 +48,6 @@ struct brw_screen boolean no_tiling; }; -/** - * Subclass of pipe_transfer - */ -struct brw_transfer -{ - struct pipe_transfer base; - - unsigned offset; -}; - -struct brw_buffer -{ - struct pipe_buffer base; - - /* One of either bo or user_buffer will be non-null, depending on - * whether this is a hardware or user buffer. - */ - struct brw_winsys_buffer *bo; - void *user_buffer; - - /* Mapped pointer?? - */ - void *ptr; -}; union brw_surface_id { @@ -100,31 +76,6 @@ struct brw_surface }; -#define BRW_MAX_TEXTURE_2D_LEVELS 11 /* max 1024x1024 */ -#define BRW_MAX_TEXTURE_3D_LEVELS 8 /* max 128x128x128 */ - - -struct brw_texture -{ - struct pipe_texture base; - struct brw_winsys_buffer *bo; - struct brw_surface_state ss; - - unsigned *image_offset[BRW_MAX_TEXTURE_2D_LEVELS]; - unsigned nr_images[BRW_MAX_TEXTURE_2D_LEVELS]; - unsigned level_offset[BRW_MAX_TEXTURE_2D_LEVELS]; - - boolean compressed; - unsigned brw_target; - unsigned pitch; - unsigned tiling; - unsigned cpp; - unsigned total_height; - - struct brw_surface views[2]; -}; - - /* * Cast wrappers @@ -135,11 +86,6 @@ brw_screen(struct pipe_screen *pscreen) return (struct brw_screen *) pscreen; } -static INLINE struct brw_transfer * -brw_transfer(struct pipe_transfer *transfer) -{ - return (struct brw_transfer *)transfer; -} static INLINE struct brw_surface * brw_surface(struct pipe_surface *surface) @@ -147,60 +93,10 @@ brw_surface(struct pipe_surface *surface) return (struct brw_surface *)surface; } -static INLINE struct brw_buffer * -brw_buffer(struct pipe_buffer *buffer) -{ - return (struct brw_buffer *)buffer; -} - -static INLINE struct brw_texture * -brw_texture(struct pipe_texture *texture) -{ - return (struct brw_texture *)texture; -} - - -/* Pipe buffer helpers - */ -static INLINE boolean -brw_buffer_is_user_buffer( const struct pipe_buffer *buf ) -{ - return ((const struct brw_buffer *)buf)->user_buffer != NULL; -} - unsigned brw_surface_pitch( const struct pipe_surface *surface ); -/*********************************************************************** - * Internal functions - */ -GLboolean brw_texture_layout(struct brw_screen *brw_screen, - struct brw_texture *tex ); - -void brw_update_texture( struct brw_screen *brw_screen, - struct brw_texture *tex ); - - -/* brw_screen_texture.h - */ -struct brw_context; -void brw_tex_init( struct brw_context *brw ); -void brw_screen_tex_init( struct brw_screen *brw_screen ); void brw_screen_tex_surface_init( struct brw_screen *brw_screen ); -void brw_screen_buffer_init(struct brw_screen *brw_screen); - - -boolean brw_is_texture_referenced_by_bo( struct brw_screen *brw_screen, - struct pipe_texture *texture, - unsigned face, - unsigned level, - struct brw_winsys_buffer *bo ); - -boolean brw_is_buffer_referenced_by_bo( struct brw_screen *brw_screen, - struct pipe_buffer *buffer, - struct brw_winsys_buffer *bo ); - - #endif /* BRW_SCREEN_H */ diff --git a/src/gallium/drivers/i965/brw_screen_buffers.c b/src/gallium/drivers/i965/brw_screen_buffers.c deleted file mode 100644 index 0b38885f40..0000000000 --- a/src/gallium/drivers/i965/brw_screen_buffers.c +++ /dev/null @@ -1,202 +0,0 @@ - -#include "util/u_memory.h" -#include "util/u_math.h" - -#include "pipe/p_state.h" -#include "pipe/p_defines.h" -#include "util/u_inlines.h" - -#include "brw_screen.h" -#include "brw_winsys.h" - - - -static void * -brw_buffer_map_range( struct pipe_screen *screen, - struct pipe_buffer *buffer, - unsigned offset, - unsigned length, - unsigned usage ) -{ - struct brw_screen *bscreen = brw_screen(screen); - struct brw_winsys_screen *sws = bscreen->sws; - struct brw_buffer *buf = brw_buffer( buffer ); - - if (buf->user_buffer) - return buf->user_buffer; - - return sws->bo_map( buf->bo, - BRW_DATA_OTHER, - offset, - length, - (usage & PIPE_BUFFER_USAGE_CPU_WRITE) ? TRUE : FALSE, - (usage & PIPE_BUFFER_USAGE_DISCARD) ? TRUE : FALSE, - (usage & PIPE_BUFFER_USAGE_FLUSH_EXPLICIT) ? TRUE : FALSE); -} - -static void * -brw_buffer_map( struct pipe_screen *screen, - struct pipe_buffer *buffer, - unsigned usage ) -{ - struct brw_screen *bscreen = brw_screen(screen); - struct brw_winsys_screen *sws = bscreen->sws; - struct brw_buffer *buf = brw_buffer( buffer ); - - if (buf->user_buffer) - return buf->user_buffer; - - return sws->bo_map( buf->bo, - BRW_DATA_OTHER, - 0, - buf->base.size, - (usage & PIPE_BUFFER_USAGE_CPU_WRITE) ? TRUE : FALSE, - FALSE, - FALSE); -} - - -static void -brw_buffer_flush_mapped_range( struct pipe_screen *screen, - struct pipe_buffer *buffer, - unsigned offset, - unsigned length ) -{ - struct brw_screen *bscreen = brw_screen(screen); - struct brw_winsys_screen *sws = bscreen->sws; - struct brw_buffer *buf = brw_buffer( buffer ); - - if (buf->user_buffer) - return; - - sws->bo_flush_range( buf->bo, - offset, - length ); -} - - -static void -brw_buffer_unmap( struct pipe_screen *screen, - struct pipe_buffer *buffer ) -{ - struct brw_screen *bscreen = brw_screen(screen); - struct brw_winsys_screen *sws = bscreen->sws; - struct brw_buffer *buf = brw_buffer( buffer ); - - if (buf->bo) - sws->bo_unmap(buf->bo); -} - -static void -brw_buffer_destroy( struct pipe_buffer *buffer ) -{ - struct brw_buffer *buf = brw_buffer( buffer ); - - assert(!p_atomic_read(&buffer->reference.count)); - - bo_reference(&buf->bo, NULL); - FREE(buf); -} - - -static struct pipe_buffer * -brw_buffer_create(struct pipe_screen *screen, - unsigned alignment, - unsigned usage, - unsigned size) -{ - struct brw_screen *bscreen = brw_screen(screen); - struct brw_winsys_screen *sws = bscreen->sws; - struct brw_buffer *buf; - unsigned buffer_type; - enum pipe_error ret; - - buf = CALLOC_STRUCT(brw_buffer); - if (!buf) - return NULL; - - pipe_reference_init(&buf->base.reference, 1); - buf->base.screen = screen; - buf->base.alignment = alignment; - buf->base.usage = usage; - buf->base.size = size; - - switch (usage & (PIPE_BUFFER_USAGE_VERTEX | - PIPE_BUFFER_USAGE_INDEX | - PIPE_BUFFER_USAGE_PIXEL | - PIPE_BUFFER_USAGE_CONSTANT)) - { - case PIPE_BUFFER_USAGE_VERTEX: - case PIPE_BUFFER_USAGE_INDEX: - case (PIPE_BUFFER_USAGE_VERTEX|PIPE_BUFFER_USAGE_INDEX): - buffer_type = BRW_BUFFER_TYPE_VERTEX; - break; - - case PIPE_BUFFER_USAGE_PIXEL: - buffer_type = BRW_BUFFER_TYPE_PIXEL; - break; - - case PIPE_BUFFER_USAGE_CONSTANT: - buffer_type = BRW_BUFFER_TYPE_SHADER_CONSTANTS; - break; - - default: - buffer_type = BRW_BUFFER_TYPE_GENERIC; - break; - } - - ret = sws->bo_alloc( sws, buffer_type, - size, alignment, - &buf->bo ); - if (ret != PIPE_OK) - return NULL; - - return &buf->base; -} - - -static struct pipe_buffer * -brw_user_buffer_create(struct pipe_screen *screen, - void *ptr, - unsigned bytes) -{ - struct brw_buffer *buf; - - buf = CALLOC_STRUCT(brw_buffer); - if (!buf) - return NULL; - - buf->user_buffer = ptr; - - pipe_reference_init(&buf->base.reference, 1); - buf->base.screen = screen; - buf->base.alignment = 1; - buf->base.usage = 0; - buf->base.size = bytes; - - return &buf->base; -} - - -boolean brw_is_buffer_referenced_by_bo( struct brw_screen *brw_screen, - struct pipe_buffer *buffer, - struct brw_winsys_buffer *bo ) -{ - struct brw_buffer *buf = brw_buffer(buffer); - if (buf->bo == NULL) - return FALSE; - - return brw_screen->sws->bo_references( bo, buf->bo ); -} - - -void brw_screen_buffer_init(struct brw_screen *brw_screen) -{ - brw_screen->base.buffer_create = brw_buffer_create; - brw_screen->base.user_buffer_create = brw_user_buffer_create; - brw_screen->base.buffer_map = brw_buffer_map; - brw_screen->base.buffer_map_range = brw_buffer_map_range; - brw_screen->base.buffer_flush_mapped_range = brw_buffer_flush_mapped_range; - brw_screen->base.buffer_unmap = brw_buffer_unmap; - brw_screen->base.buffer_destroy = brw_buffer_destroy; -} diff --git a/src/gallium/drivers/i965/brw_screen_surface.c b/src/gallium/drivers/i965/brw_screen_surface.c index 904df813dd..f288fdbcd3 100644 --- a/src/gallium/drivers/i965/brw_screen_surface.c +++ b/src/gallium/drivers/i965/brw_screen_surface.c @@ -36,6 +36,7 @@ #include "pipe/p_screen.h" #include "brw_screen.h" #include "brw_defines.h" +#include "brw_resource.h" #include "brw_winsys.h" enum { @@ -138,9 +139,9 @@ static struct brw_surface *create_in_place_view( struct brw_screen *brw_screen, */ assert(id.bits.zslice == 0); - surface->base.format = tex->base.format; - surface->base.width = u_minify(tex->base.width0, id.bits.level); - surface->base.height = u_minify(tex->base.height0, id.bits.level); + surface->base.format = tex->b.b.format; + surface->base.width = u_minify(tex->b.b.width0, id.bits.level); + surface->base.height = u_minify(tex->b.b.height0, id.bits.level); surface->base.offset = tex->image_offset[id.bits.level][id.bits.face]; surface->base.usage = usage; surface->base.zslice = id.bits.zslice; @@ -152,7 +153,7 @@ static struct brw_surface *create_in_place_view( struct brw_screen *brw_screen, surface->tiling = tex->tiling; bo_reference( &surface->bo, tex->bo ); - pipe_texture_reference( &surface->base.texture, &tex->base ); + pipe_resource_reference( &surface->base.texture, &tex->b.b ); surface->ss.ss0.surface_format = tex->ss.ss0.surface_format; surface->ss.ss0.surface_type = BRW_SURFACE_2D; @@ -198,7 +199,7 @@ static struct brw_surface *create_in_place_view( struct brw_screen *brw_screen, /* Get a surface which is view into a texture */ static struct pipe_surface *brw_get_tex_surface(struct pipe_screen *screen, - struct pipe_texture *pt, + struct pipe_resource *pt, unsigned face, unsigned level, unsigned zslice, unsigned usage ) @@ -246,7 +247,7 @@ static void brw_tex_surface_destroy( struct pipe_surface *surf ) */ remove_from_list(surface); bo_reference(&surface->bo, NULL); - pipe_texture_reference( &surface->base.texture, NULL ); + pipe_resource_reference( &surface->base.texture, NULL ); FREE(surface); diff --git a/src/gallium/drivers/i965/brw_util.c b/src/gallium/drivers/i965/brw_util.c deleted file mode 100644 index 1fd2e29713..0000000000 --- a/src/gallium/drivers/i965/brw_util.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright (C) Intel Corp. 2006. All Rights Reserved. - Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to - develop this 3D driver. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice (including the - next paragraph) shall be included in all copies or substantial - portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - **********************************************************************/ - /* - * Authors: - * Keith Whitwell <keith@tungstengraphics.com> - */ - - - - - - diff --git a/src/gallium/drivers/i965/brw_vs_surface_state.c b/src/gallium/drivers/i965/brw_vs_surface_state.c index 004e3cb4e6..424bb0d0df 100644 --- a/src/gallium/drivers/i965/brw_vs_surface_state.c +++ b/src/gallium/drivers/i965/brw_vs_surface_state.c @@ -82,7 +82,7 @@ brw_update_vs_constant_surface( struct brw_context *brw, GLuint surf) { struct brw_surface_key key; - struct pipe_buffer *cb = brw->curr.vs_constants; + struct pipe_resource *cb = brw->curr.vs_constants; enum pipe_error ret; assert(surf == 0); diff --git a/src/gallium/drivers/i965/brw_wm.c b/src/gallium/drivers/i965/brw_wm.c index 7ed2378ec0..5d66e61fbc 100644 --- a/src/gallium/drivers/i965/brw_wm.c +++ b/src/gallium/drivers/i965/brw_wm.c @@ -35,6 +35,7 @@ #include "brw_wm.h" #include "brw_state.h" #include "brw_debug.h" +#include "brw_resource.h" #include "brw_pipe_rast.h" @@ -254,10 +255,10 @@ static void brw_wm_populate_key( struct brw_context *brw, for (i = 0; i < brw->curr.num_fragment_sampler_views; i++) { const struct brw_texture *tex = brw_texture(brw->curr.fragment_sampler_views[i]->texture); - if (tex->base.format == PIPE_FORMAT_UYVY) + if (tex->b.b.format == PIPE_FORMAT_UYVY) key->yuvtex_mask |= 1 << i; - if (tex->base.format == PIPE_FORMAT_YUYV) + if (tex->b.b.format == PIPE_FORMAT_YUYV) key->yuvtex_swap_mask |= 1 << i; /* XXX: shadow texture diff --git a/src/gallium/drivers/i965/brw_wm_constant_buffer.c b/src/gallium/drivers/i965/brw_wm_constant_buffer.c index 6434c6acf7..df5cd0398c 100644 --- a/src/gallium/drivers/i965/brw_wm_constant_buffer.c +++ b/src/gallium/drivers/i965/brw_wm_constant_buffer.c @@ -62,7 +62,7 @@ brw_update_wm_constant_surface( struct brw_context *brw, { struct brw_surface_key key; struct brw_fragment_shader *fp = brw->curr.fragment_shader; - struct pipe_buffer *cbuf = brw->curr.fragment_constants; + struct pipe_resource *cbuf = brw->curr.fragment_constants; int pitch = cbuf->size / (4 * sizeof(float)); enum pipe_error ret; diff --git a/src/gallium/drivers/i965/brw_wm_sampler_state.c b/src/gallium/drivers/i965/brw_wm_sampler_state.c index 3f18062c58..8406a1a9e2 100644 --- a/src/gallium/drivers/i965/brw_wm_sampler_state.c +++ b/src/gallium/drivers/i965/brw_wm_sampler_state.c @@ -35,7 +35,7 @@ #include "brw_context.h" #include "brw_state.h" #include "brw_defines.h" -#include "brw_screen.h" +#include "brw_resource.h" /* Samplers aren't strictly wm state from the hardware's perspective, @@ -94,7 +94,7 @@ brw_wm_sampler_populate_key(struct brw_context *brw, /* Cube-maps on 965 and later must use the same wrap mode for all 3 * coordinate dimensions. Futher, only CUBE and CLAMP are valid. */ - if (tex->base.target == PIPE_TEXTURE_CUBE) { + if (tex->b.b.target == PIPE_TEXTURE_CUBE) { if (FALSE && (sampler->ss0.min_filter != BRW_MAPFILTER_NEAREST || sampler->ss0.mag_filter != BRW_MAPFILTER_NEAREST)) { @@ -106,7 +106,7 @@ brw_wm_sampler_populate_key(struct brw_context *brw, entry->ss1.s_wrap_mode = BRW_TEXCOORDMODE_CLAMP; entry->ss1.t_wrap_mode = BRW_TEXCOORDMODE_CLAMP; } - } else if (tex->base.target == PIPE_TEXTURE_1D) { + } else if (tex->b.b.target == PIPE_TEXTURE_1D) { /* There's a bug in 1D texture sampling - it actually pays * attention to the wrap_t value, though it should not. * Override the wrap_t value here to GL_REPEAT to keep @@ -137,7 +137,7 @@ brw_wm_sampler_update_default_colors(struct brw_context *brw) sampler->border_color[0] }; - if (util_format_is_depth_or_stencil(tex->base.format)) { + if (util_format_is_depth_or_stencil(tex->b.b.format)) { bc = bordercolor; } else { diff --git a/src/gallium/drivers/i965/brw_wm_surface_state.c b/src/gallium/drivers/i965/brw_wm_surface_state.c index 2368ae3f80..0d80a0114a 100644 --- a/src/gallium/drivers/i965/brw_wm_surface_state.c +++ b/src/gallium/drivers/i965/brw_wm_surface_state.c @@ -34,7 +34,7 @@ #include "brw_batchbuffer.h" #include "brw_context.h" #include "brw_state.h" -#include "brw_screen.h" +#include "brw_resource.h" diff --git a/src/gallium/drivers/identity/id_context.c b/src/gallium/drivers/identity/id_context.c index 00a542215a..fc5aec0741 100644 --- a/src/gallium/drivers/identity/id_context.c +++ b/src/gallium/drivers/identity/id_context.c @@ -61,19 +61,19 @@ identity_draw_arrays(struct pipe_context *_pipe, static void identity_draw_elements(struct pipe_context *_pipe, - struct pipe_buffer *_indexBuffer, + struct pipe_resource *_indexResource, unsigned indexSize, unsigned prim, unsigned start, unsigned count) { struct identity_context *id_pipe = identity_context(_pipe); - struct identity_buffer *id_buffer = identity_buffer(_indexBuffer); + struct identity_resource *id_resource = identity_resource(_indexResource); struct pipe_context *pipe = id_pipe->pipe; - struct pipe_buffer *indexBuffer = id_buffer->buffer; + struct pipe_resource *indexResource = id_resource->resource; pipe->draw_elements(pipe, - indexBuffer, + indexResource, indexSize, prim, start, @@ -82,7 +82,7 @@ identity_draw_elements(struct pipe_context *_pipe, static void identity_draw_range_elements(struct pipe_context *_pipe, - struct pipe_buffer *_indexBuffer, + struct pipe_resource *_indexResource, unsigned indexSize, unsigned minIndex, unsigned maxIndex, @@ -91,12 +91,12 @@ identity_draw_range_elements(struct pipe_context *_pipe, unsigned count) { struct identity_context *id_pipe = identity_context(_pipe); - struct identity_buffer *id_buffer = identity_buffer(_indexBuffer); + struct identity_resource *id_resource = identity_resource(_indexResource); struct pipe_context *pipe = id_pipe->pipe; - struct pipe_buffer *indexBuffer = id_buffer->buffer; + struct pipe_resource *indexResource = id_resource->resource; pipe->draw_range_elements(pipe, - indexBuffer, + indexResource, indexSize, minIndex, maxIndex, @@ -450,23 +450,23 @@ static void identity_set_constant_buffer(struct pipe_context *_pipe, uint shader, uint index, - struct pipe_buffer *_buffer) + struct pipe_resource *_resource) { struct identity_context *id_pipe = identity_context(_pipe); struct pipe_context *pipe = id_pipe->pipe; - struct pipe_buffer *unwrapped_buffer; - struct pipe_buffer *buffer = NULL; + struct pipe_resource *unwrapped_resource; + struct pipe_resource *resource = NULL; /* XXX hmm? unwrap the input state */ - if (_buffer) { - unwrapped_buffer = identity_buffer_unwrap(_buffer); - buffer = unwrapped_buffer; + if (_resource) { + unwrapped_resource = identity_resource_unwrap(_resource); + resource = unwrapped_resource; } pipe->set_constant_buffer(pipe, shader, index, - buffer); + resource); } static void @@ -587,7 +587,7 @@ identity_set_vertex_buffers(struct pipe_context *_pipe, if (num_buffers) { memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers)); for (i = 0; i < num_buffers; i++) - unwrapped_buffers[i].buffer = identity_buffer_unwrap(_buffers[i].buffer); + unwrapped_buffers[i].buffer = identity_resource_unwrap(_buffers[i].buffer); buffers = unwrapped_buffers; } @@ -678,44 +678,31 @@ identity_flush(struct pipe_context *_pipe, } static unsigned int -identity_is_texture_referenced(struct pipe_context *_pipe, - struct pipe_texture *_texture, +identity_is_resource_referenced(struct pipe_context *_pipe, + struct pipe_resource *_resource, unsigned face, unsigned level) { struct identity_context *id_pipe = identity_context(_pipe); - struct identity_texture *id_texture = identity_texture(_texture); + struct identity_resource *id_resource = identity_resource(_resource); struct pipe_context *pipe = id_pipe->pipe; - struct pipe_texture *texture = id_texture->texture; + struct pipe_resource *texture = id_resource->resource; - return pipe->is_texture_referenced(pipe, + return pipe->is_resource_referenced(pipe, texture, face, level); } -static unsigned int -identity_is_buffer_referenced(struct pipe_context *_pipe, - struct pipe_buffer *_buffer) -{ - struct identity_context *id_pipe = identity_context(_pipe); - struct identity_buffer *id_buffer = identity_buffer(_buffer); - struct pipe_context *pipe = id_pipe->pipe; - struct pipe_buffer *buffer = id_buffer->buffer; - - return pipe->is_buffer_referenced(pipe, - buffer); -} - static struct pipe_sampler_view * identity_create_sampler_view(struct pipe_context *pipe, - struct pipe_texture *texture, + struct pipe_resource *texture, const struct pipe_sampler_view *templ) { struct identity_context *id_pipe = identity_context(pipe); - struct identity_texture *id_texture = identity_texture(texture); + struct identity_resource *id_resource = identity_resource(texture); struct pipe_context *pipe_unwrapped = id_pipe->pipe; - struct pipe_texture *texture_unwrapped = id_texture->texture; + struct pipe_resource *texture_unwrapped = id_resource->resource; struct identity_sampler_view *view = malloc(sizeof(struct identity_sampler_view)); view->sampler_view = pipe_unwrapped->create_sampler_view(pipe_unwrapped, @@ -725,7 +712,7 @@ identity_create_sampler_view(struct pipe_context *pipe, view->base = *templ; view->base.reference.count = 1; view->base.texture = NULL; - pipe_texture_reference(&view->base.texture, texture); + pipe_resource_reference(&view->base.texture, texture); view->base.context = pipe; return &view->base; @@ -743,47 +730,36 @@ identity_sampler_view_destroy(struct pipe_context *pipe, pipe_unwrapped->sampler_view_destroy(pipe_unwrapped, view_unwrapped); - pipe_texture_reference(&view->texture, NULL); + pipe_resource_reference(&view->texture, NULL); free(view); } - static struct pipe_transfer * -identity_context_get_tex_transfer(struct pipe_context *_context, - struct pipe_texture *_texture, - unsigned face, - unsigned level, - unsigned zslice, - enum pipe_transfer_usage usage, - unsigned x, - unsigned y, - unsigned w, - unsigned h) +identity_context_get_transfer(struct pipe_context *_context, + struct pipe_resource *_resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box) { struct identity_context *id_context = identity_context(_context); - struct identity_texture *id_texture = identity_texture(_texture); + struct identity_resource *id_resource = identity_resource(_resource); struct pipe_context *context = id_context->pipe; - struct pipe_texture *texture = id_texture->texture; + struct pipe_resource *texture = id_resource->resource; struct pipe_transfer *result; - result = context->get_tex_transfer(context, - texture, - face, - level, - zslice, - usage, - x, - y, - w, - h); + result = context->get_transfer(context, + texture, + sr, + usage, + box); if (result) - return identity_transfer_create(id_context, id_texture, result); + return identity_transfer_create(id_context, id_resource, result); return NULL; } static void -identity_context_tex_transfer_destroy(struct pipe_context *_pipe, +identity_context_transfer_destroy(struct pipe_context *_pipe, struct pipe_transfer *_transfer) { identity_transfer_destroy(identity_context(_pipe), @@ -803,6 +779,24 @@ identity_context_transfer_map(struct pipe_context *_context, transfer); } + + +static void +identity_context_transfer_flush_region( struct pipe_context *_context, + struct pipe_transfer *_transfer, + const struct pipe_box *box) +{ + struct identity_context *id_context = identity_context(_context); + struct identity_transfer *id_transfer = identity_transfer(_transfer); + struct pipe_context *context = id_context->pipe; + struct pipe_transfer *transfer = id_transfer->transfer; + + context->transfer_flush_region(context, + transfer, + box); +} + + static void identity_context_transfer_unmap(struct pipe_context *_context, struct pipe_transfer *_transfer) @@ -816,6 +810,33 @@ identity_context_transfer_unmap(struct pipe_context *_context, transfer); } + +static void +identity_context_transfer_inline_write( struct pipe_context *_context, + struct pipe_resource *_resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned slice_stride) +{ + struct identity_context *id_context = identity_context(_context); + struct identity_resource *id_resource = identity_resource(_resource); + struct pipe_context *context = id_context->pipe; + struct pipe_resource *texture = id_resource->resource; + + context->transfer_inline_write(context, + texture, + sr, + usage, + box, + data, + stride, + slice_stride); +} + + struct pipe_context * identity_context_create(struct pipe_screen *_screen, struct pipe_context *pipe) { @@ -878,14 +899,16 @@ identity_context_create(struct pipe_screen *_screen, struct pipe_context *pipe) id_pipe->base.surface_fill = identity_surface_fill; id_pipe->base.clear = identity_clear; id_pipe->base.flush = identity_flush; - id_pipe->base.is_texture_referenced = identity_is_texture_referenced; - id_pipe->base.is_buffer_referenced = identity_is_buffer_referenced; + id_pipe->base.is_resource_referenced = identity_is_resource_referenced; + id_pipe->base.is_resource_referenced = identity_is_resource_referenced; id_pipe->base.create_sampler_view = identity_create_sampler_view; id_pipe->base.sampler_view_destroy = identity_sampler_view_destroy; - id_pipe->base.get_tex_transfer = identity_context_get_tex_transfer; - id_pipe->base.tex_transfer_destroy = identity_context_tex_transfer_destroy; + id_pipe->base.get_transfer = identity_context_get_transfer; + id_pipe->base.transfer_destroy = identity_context_transfer_destroy; id_pipe->base.transfer_map = identity_context_transfer_map; id_pipe->base.transfer_unmap = identity_context_transfer_unmap; + id_pipe->base.transfer_flush_region = identity_context_transfer_flush_region; + id_pipe->base.transfer_inline_write = identity_context_transfer_inline_write; id_pipe->pipe = pipe; diff --git a/src/gallium/drivers/identity/id_objects.c b/src/gallium/drivers/identity/id_objects.c index d37fb0042e..eb54c11bdd 100644 --- a/src/gallium/drivers/identity/id_objects.c +++ b/src/gallium/drivers/identity/id_objects.c @@ -32,80 +32,46 @@ #include "id_objects.h" #include "id_context.h" -struct pipe_buffer * -identity_buffer_create(struct identity_screen *id_screen, - struct pipe_buffer *buffer) -{ - struct identity_buffer *id_buffer; - - if(!buffer) - goto error; - - assert(buffer->screen == id_screen->screen); - - id_buffer = CALLOC_STRUCT(identity_buffer); - if(!id_buffer) - goto error; - - memcpy(&id_buffer->base, buffer, sizeof(struct pipe_buffer)); - - pipe_reference_init(&id_buffer->base.reference, 1); - id_buffer->base.screen = &id_screen->base; - id_buffer->buffer = buffer; - - return &id_buffer->base; - -error: - pipe_buffer_reference(&buffer, NULL); - return NULL; -} - -void -identity_buffer_destroy(struct identity_buffer *id_buffer) -{ - pipe_buffer_reference(&id_buffer->buffer, NULL); - FREE(id_buffer); -} -struct pipe_texture * -identity_texture_create(struct identity_screen *id_screen, - struct pipe_texture *texture) +struct pipe_resource * +identity_resource_create(struct identity_screen *id_screen, + struct pipe_resource *resource) { - struct identity_texture *id_texture; + struct identity_resource *id_resource; - if(!texture) + if(!resource) goto error; - assert(texture->screen == id_screen->screen); + assert(resource->screen == id_screen->screen); - id_texture = CALLOC_STRUCT(identity_texture); - if(!id_texture) + id_resource = CALLOC_STRUCT(identity_resource); + if(!id_resource) goto error; - memcpy(&id_texture->base, texture, sizeof(struct pipe_texture)); + memcpy(&id_resource->base, resource, sizeof(struct pipe_resource)); - pipe_reference_init(&id_texture->base.reference, 1); - id_texture->base.screen = &id_screen->base; - id_texture->texture = texture; + pipe_reference_init(&id_resource->base.reference, 1); + id_resource->base.screen = &id_screen->base; + id_resource->resource = resource; - return &id_texture->base; + return &id_resource->base; error: - pipe_texture_reference(&texture, NULL); + pipe_resource_reference(&resource, NULL); return NULL; } void -identity_texture_destroy(struct identity_texture *id_texture) +identity_resource_destroy(struct identity_resource *id_resource) { - pipe_texture_reference(&id_texture->texture, NULL); - FREE(id_texture); + pipe_resource_reference(&id_resource->resource, NULL); + FREE(id_resource); } struct pipe_surface * -identity_surface_create(struct identity_texture *id_texture, +identity_surface_create(struct identity_resource *id_resource, struct pipe_surface *surface) { struct identity_surface *id_surface; @@ -113,7 +79,7 @@ identity_surface_create(struct identity_texture *id_texture, if(!surface) goto error; - assert(surface->texture == id_texture->texture); + assert(surface->texture == id_resource->resource); id_surface = CALLOC_STRUCT(identity_surface); if(!id_surface) @@ -123,7 +89,7 @@ identity_surface_create(struct identity_texture *id_texture, pipe_reference_init(&id_surface->base.reference, 1); id_surface->base.texture = NULL; - pipe_texture_reference(&id_surface->base.texture, &id_texture->base); + pipe_resource_reference(&id_surface->base.texture, &id_resource->base); id_surface->surface = surface; return &id_surface->base; @@ -136,7 +102,7 @@ error: void identity_surface_destroy(struct identity_surface *id_surface) { - pipe_texture_reference(&id_surface->base.texture, NULL); + pipe_resource_reference(&id_surface->base.texture, NULL); pipe_surface_reference(&id_surface->surface, NULL); FREE(id_surface); } @@ -144,7 +110,7 @@ identity_surface_destroy(struct identity_surface *id_surface) struct pipe_transfer * identity_transfer_create(struct identity_context *id_context, - struct identity_texture *id_texture, + struct identity_resource *id_resource, struct pipe_transfer *transfer) { struct identity_transfer *id_transfer; @@ -152,7 +118,7 @@ identity_transfer_create(struct identity_context *id_context, if(!transfer) goto error; - assert(transfer->texture == id_texture->texture); + assert(transfer->resource == id_resource->resource); id_transfer = CALLOC_STRUCT(identity_transfer); if(!id_transfer) @@ -160,16 +126,16 @@ identity_transfer_create(struct identity_context *id_context, memcpy(&id_transfer->base, transfer, sizeof(struct pipe_transfer)); - id_transfer->base.texture = NULL; + id_transfer->base.resource = NULL; id_transfer->transfer = transfer; - pipe_texture_reference(&id_transfer->base.texture, &id_texture->base); - assert(id_transfer->base.texture == &id_texture->base); + pipe_resource_reference(&id_transfer->base.resource, &id_resource->base); + assert(id_transfer->base.resource == &id_resource->base); return &id_transfer->base; error: - id_context->pipe->tex_transfer_destroy(id_context->pipe, transfer); + id_context->pipe->transfer_destroy(id_context->pipe, transfer); return NULL; } @@ -177,9 +143,9 @@ void identity_transfer_destroy(struct identity_context *id_context, struct identity_transfer *id_transfer) { - pipe_texture_reference(&id_transfer->base.texture, NULL); - id_context->pipe->tex_transfer_destroy(id_context->pipe, - id_transfer->transfer); + pipe_resource_reference(&id_transfer->base.resource, NULL); + id_context->pipe->transfer_destroy(id_context->pipe, + id_transfer->transfer); FREE(id_transfer); } diff --git a/src/gallium/drivers/identity/id_objects.h b/src/gallium/drivers/identity/id_objects.h index 9a07ebe8d7..89774a06e7 100644 --- a/src/gallium/drivers/identity/id_objects.h +++ b/src/gallium/drivers/identity/id_objects.h @@ -37,19 +37,12 @@ struct identity_context; -struct identity_buffer -{ - struct pipe_buffer base; - - struct pipe_buffer *buffer; -}; - -struct identity_texture +struct identity_resource { - struct pipe_texture base; + struct pipe_resource base; - struct pipe_texture *texture; + struct pipe_resource *resource; }; @@ -86,22 +79,14 @@ struct identity_video_surface }; -static INLINE struct identity_buffer * -identity_buffer(struct pipe_buffer *_buffer) -{ - if(!_buffer) - return NULL; - (void)identity_screen(_buffer->screen); - return (struct identity_buffer *)_buffer; -} -static INLINE struct identity_texture * -identity_texture(struct pipe_texture *_texture) +static INLINE struct identity_resource * +identity_resource(struct pipe_resource *_resource) { - if(!_texture) + if(!_resource) return NULL; - (void)identity_screen(_texture->screen); - return (struct identity_texture *)_texture; + (void)identity_screen(_resource->screen); + return (struct identity_resource *)_resource; } static INLINE struct identity_sampler_view * @@ -118,7 +103,7 @@ identity_surface(struct pipe_surface *_surface) { if(!_surface) return NULL; - (void)identity_texture(_surface->texture); + (void)identity_resource(_surface->texture); return (struct identity_surface *)_surface; } @@ -127,7 +112,7 @@ identity_transfer(struct pipe_transfer *_transfer) { if(!_transfer) return NULL; - (void)identity_texture(_transfer->texture); + (void)identity_resource(_transfer->resource); return (struct identity_transfer *)_transfer; } @@ -141,20 +126,12 @@ identity_video_surface(struct pipe_video_surface *_video_surface) return (struct identity_video_surface *)_video_surface; } -static INLINE struct pipe_buffer * -identity_buffer_unwrap(struct pipe_buffer *_buffer) +static INLINE struct pipe_resource * +identity_resource_unwrap(struct pipe_resource *_resource) { - if(!_buffer) + if(!_resource) return NULL; - return identity_buffer(_buffer)->buffer; -} - -static INLINE struct pipe_texture * -identity_texture_unwrap(struct pipe_texture *_texture) -{ - if(!_texture) - return NULL; - return identity_texture(_texture)->texture; + return identity_resource(_resource)->resource; } static INLINE struct pipe_sampler_view * @@ -183,22 +160,15 @@ identity_transfer_unwrap(struct pipe_transfer *_transfer) } -struct pipe_buffer * -identity_buffer_create(struct identity_screen *id_screen, - struct pipe_buffer *buffer); - -void -identity_buffer_destroy(struct identity_buffer *id_buffer); - -struct pipe_texture * -identity_texture_create(struct identity_screen *id_screen, - struct pipe_texture *texture); +struct pipe_resource * +identity_resource_create(struct identity_screen *id_screen, + struct pipe_resource *resource); void -identity_texture_destroy(struct identity_texture *id_texture); +identity_resource_destroy(struct identity_resource *id_resource); struct pipe_surface * -identity_surface_create(struct identity_texture *id_texture, +identity_surface_create(struct identity_resource *id_resource, struct pipe_surface *surface); void @@ -206,7 +176,7 @@ identity_surface_destroy(struct identity_surface *id_surface); struct pipe_transfer * identity_transfer_create(struct identity_context *id_context, - struct identity_texture *id_texture, + struct identity_resource *id_resource, struct pipe_transfer *transfer); void diff --git a/src/gallium/drivers/identity/id_screen.c b/src/gallium/drivers/identity/id_screen.c index 419b146578..52573b211f 100644 --- a/src/gallium/drivers/identity/id_screen.c +++ b/src/gallium/drivers/identity/id_screen.c @@ -118,75 +118,76 @@ identity_screen_context_create(struct pipe_screen *_screen, return NULL; } -static struct pipe_texture * -identity_screen_texture_create(struct pipe_screen *_screen, - const struct pipe_texture *templat) +static struct pipe_resource * +identity_screen_resource_create(struct pipe_screen *_screen, + const struct pipe_resource *templat) { struct identity_screen *id_screen = identity_screen(_screen); struct pipe_screen *screen = id_screen->screen; - struct pipe_texture *result; + struct pipe_resource *result; - result = screen->texture_create(screen, + result = screen->resource_create(screen, templat); if (result) - return identity_texture_create(id_screen, result); + return identity_resource_create(id_screen, result); return NULL; } -static struct pipe_texture * -identity_screen_texture_from_handle(struct pipe_screen *_screen, - const struct pipe_texture *templ, +static struct pipe_resource * +identity_screen_resource_from_handle(struct pipe_screen *_screen, + const struct pipe_resource *templ, struct winsys_handle *handle) { struct identity_screen *id_screen = identity_screen(_screen); struct pipe_screen *screen = id_screen->screen; - struct pipe_texture *result; + struct pipe_resource *result; /* TODO trace call */ - result = screen->texture_from_handle(screen, templ, handle); + result = screen->resource_from_handle(screen, templ, handle); - result = identity_texture_create(identity_screen(_screen), result); + result = identity_resource_create(identity_screen(_screen), result); return result; } static boolean -identity_screen_texture_get_handle(struct pipe_screen *_screen, - struct pipe_texture *_texture, +identity_screen_resource_get_handle(struct pipe_screen *_screen, + struct pipe_resource *_texture, struct winsys_handle *handle) { struct identity_screen *id_screen = identity_screen(_screen); - struct identity_texture *id_texture = identity_texture(_texture); + struct identity_resource *id_resource = identity_resource(_texture); struct pipe_screen *screen = id_screen->screen; - struct pipe_texture *texture = id_texture->texture; + struct pipe_resource *texture = id_resource->resource; /* TODO trace call */ - return screen->texture_get_handle(screen, texture, handle); + return screen->resource_get_handle(screen, texture, handle); } static void -identity_screen_texture_destroy(struct pipe_texture *_texture) +identity_screen_resource_destroy(struct pipe_screen *screen, + struct pipe_resource *_texture) { - identity_texture_destroy(identity_texture(_texture)); + identity_resource_destroy(identity_resource(_texture)); } static struct pipe_surface * identity_screen_get_tex_surface(struct pipe_screen *_screen, - struct pipe_texture *_texture, + struct pipe_resource *_texture, unsigned face, unsigned level, unsigned zslice, unsigned usage) { struct identity_screen *id_screen = identity_screen(_screen); - struct identity_texture *id_texture = identity_texture(_texture); + struct identity_resource *id_resource = identity_resource(_texture); struct pipe_screen *screen = id_screen->screen; - struct pipe_texture *texture = id_texture->texture; + struct pipe_resource *texture = id_resource->resource; struct pipe_surface *result; result = screen->get_tex_surface(screen, @@ -197,7 +198,7 @@ identity_screen_get_tex_surface(struct pipe_screen *_screen, usage); if (result) - return identity_surface_create(id_texture, result); + return identity_surface_create(id_resource, result); return NULL; } @@ -208,141 +209,28 @@ identity_screen_tex_surface_destroy(struct pipe_surface *_surface) } -static struct pipe_buffer * -identity_screen_buffer_create(struct pipe_screen *_screen, - unsigned alignment, - unsigned usage, - unsigned size) -{ - struct identity_screen *id_screen = identity_screen(_screen); - struct pipe_screen *screen = id_screen->screen; - struct pipe_buffer *result; - - result = screen->buffer_create(screen, - alignment, - usage, - size); - if (result) - return identity_buffer_create(id_screen, result); - return NULL; -} - -static struct pipe_buffer * +static struct pipe_resource * identity_screen_user_buffer_create(struct pipe_screen *_screen, void *ptr, - unsigned bytes) + unsigned bytes, + unsigned usage) { struct identity_screen *id_screen = identity_screen(_screen); struct pipe_screen *screen = id_screen->screen; - struct pipe_buffer *result; + struct pipe_resource *result; result = screen->user_buffer_create(screen, ptr, - bytes); + bytes, + usage); if (result) - return identity_buffer_create(id_screen, result); + return identity_resource_create(id_screen, result); return NULL; } -static void * -identity_screen_buffer_map(struct pipe_screen *_screen, - struct pipe_buffer *_buffer, - unsigned usage) -{ - struct identity_screen *id_screen = identity_screen(_screen); - struct identity_buffer *id_buffer = identity_buffer(_buffer); - struct pipe_screen *screen = id_screen->screen; - struct pipe_buffer *buffer = id_buffer->buffer; - - return screen->buffer_map(screen, - buffer, - usage); -} - -static void * -identity_screen_buffer_map_range(struct pipe_screen *_screen, - struct pipe_buffer *_buffer, - unsigned offset, - unsigned length, - unsigned usage) -{ - struct identity_screen *id_screen = identity_screen(_screen); - struct identity_buffer *id_buffer = identity_buffer(_buffer); - struct pipe_screen *screen = id_screen->screen; - struct pipe_buffer *buffer = id_buffer->buffer; - - return screen->buffer_map_range(screen, - buffer, - offset, - length, - usage); -} - -static void -identity_screen_buffer_flush_mapped_range(struct pipe_screen *_screen, - struct pipe_buffer *_buffer, - unsigned offset, - unsigned length) -{ - struct identity_screen *id_screen = identity_screen(_screen); - struct identity_buffer *id_buffer = identity_buffer(_buffer); - struct pipe_screen *screen = id_screen->screen; - struct pipe_buffer *buffer = id_buffer->buffer; - - screen->buffer_flush_mapped_range(screen, - buffer, - offset, - length); -} - -static void -identity_screen_buffer_unmap(struct pipe_screen *_screen, - struct pipe_buffer *_buffer) -{ - struct identity_screen *id_screen = identity_screen(_screen); - struct identity_buffer *id_buffer = identity_buffer(_buffer); - struct pipe_screen *screen = id_screen->screen; - struct pipe_buffer *buffer = id_buffer->buffer; - - screen->buffer_unmap(screen, - buffer); -} - -static void -identity_screen_buffer_destroy(struct pipe_buffer *_buffer) -{ - identity_buffer_destroy(identity_buffer(_buffer)); -} - -static struct pipe_video_surface * -identity_screen_video_surface_create(struct pipe_screen *_screen, - enum pipe_video_chroma_format chroma_format, - unsigned width, - unsigned height) -{ - struct identity_screen *id_screen = identity_screen(_screen); - struct pipe_screen *screen = id_screen->screen; - struct pipe_video_surface *result; - - result = screen->video_surface_create(screen, - chroma_format, - width, - height); - - if (result) { - return identity_video_surface_create(id_screen, result); - } - return NULL; -} - -static void -identity_screen_video_surface_destroy(struct pipe_video_surface *_vsfc) -{ - identity_video_surface_destroy(identity_video_surface(_vsfc)); -} static void identity_screen_flush_frontbuffer(struct pipe_screen *_screen, @@ -417,29 +305,13 @@ identity_screen_create(struct pipe_screen *screen) id_screen->base.get_paramf = identity_screen_get_paramf; id_screen->base.is_format_supported = identity_screen_is_format_supported; id_screen->base.context_create = identity_screen_context_create; - id_screen->base.texture_create = identity_screen_texture_create; - id_screen->base.texture_from_handle = identity_screen_texture_from_handle; - id_screen->base.texture_get_handle = identity_screen_texture_get_handle; - id_screen->base.texture_destroy = identity_screen_texture_destroy; + id_screen->base.resource_create = identity_screen_resource_create; + id_screen->base.resource_from_handle = identity_screen_resource_from_handle; + id_screen->base.resource_get_handle = identity_screen_resource_get_handle; + id_screen->base.resource_destroy = identity_screen_resource_destroy; id_screen->base.get_tex_surface = identity_screen_get_tex_surface; id_screen->base.tex_surface_destroy = identity_screen_tex_surface_destroy; - id_screen->base.buffer_create = identity_screen_buffer_create; id_screen->base.user_buffer_create = identity_screen_user_buffer_create; - if (screen->buffer_map) - id_screen->base.buffer_map = identity_screen_buffer_map; - if (screen->buffer_map_range) - id_screen->base.buffer_map_range = identity_screen_buffer_map_range; - if (screen->buffer_flush_mapped_range) - id_screen->base.buffer_flush_mapped_range = identity_screen_buffer_flush_mapped_range; - if (screen->buffer_unmap) - id_screen->base.buffer_unmap = identity_screen_buffer_unmap; - id_screen->base.buffer_destroy = identity_screen_buffer_destroy; - if (screen->video_surface_create) { - id_screen->base.video_surface_create = identity_screen_video_surface_create; - } - if (screen->video_surface_destroy) { - id_screen->base.video_surface_destroy = identity_screen_video_surface_destroy; - } id_screen->base.flush_frontbuffer = identity_screen_flush_frontbuffer; id_screen->base.fence_reference = identity_screen_fence_reference; id_screen->base.fence_signalled = identity_screen_fence_signalled; diff --git a/src/gallium/drivers/llvmpipe/Makefile b/src/gallium/drivers/llvmpipe/Makefile index 89c06ea3ad..0613e7a0fa 100644 --- a/src/gallium/drivers/llvmpipe/Makefile +++ b/src/gallium/drivers/llvmpipe/Makefile @@ -6,7 +6,6 @@ LIBNAME = llvmpipe DEFINES += -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS C_SOURCES = \ - lp_buffer.c \ lp_clear.c \ lp_context.c \ lp_draw_arrays.c \ diff --git a/src/gallium/drivers/llvmpipe/SConscript b/src/gallium/drivers/llvmpipe/SConscript index 13c1a13e87..47a0eea4bf 100644 --- a/src/gallium/drivers/llvmpipe/SConscript +++ b/src/gallium/drivers/llvmpipe/SConscript @@ -28,7 +28,6 @@ env.Depends('lp_tile_soa.c', [ llvmpipe = env.ConvenienceLibrary( target = 'llvmpipe', source = [ - 'lp_buffer.c', 'lp_clear.c', 'lp_context.c', 'lp_draw_arrays.c', diff --git a/src/gallium/drivers/llvmpipe/lp_buffer.c b/src/gallium/drivers/llvmpipe/lp_buffer.c deleted file mode 100644 index 6e0f37393e..0000000000 --- a/src/gallium/drivers/llvmpipe/lp_buffer.c +++ /dev/null @@ -1,118 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -#include "util/u_inlines.h" -#include "util/u_memory.h" -#include "util/u_math.h" - -#include "lp_screen.h" -#include "lp_buffer.h" - - -static void * -llvmpipe_buffer_map(struct pipe_screen *screen, - struct pipe_buffer *buf, - unsigned flags) -{ - struct llvmpipe_buffer *llvmpipe_buf = llvmpipe_buffer(buf); - return llvmpipe_buf->data; -} - - -static void -llvmpipe_buffer_unmap(struct pipe_screen *screen, - struct pipe_buffer *buf) -{ -} - - -static void -llvmpipe_buffer_destroy(struct pipe_buffer *buf) -{ - struct llvmpipe_buffer *sbuf = llvmpipe_buffer(buf); - - if (!sbuf->userBuffer) - align_free(sbuf->data); - - FREE(sbuf); -} - - -static struct pipe_buffer * -llvmpipe_buffer_create(struct pipe_screen *screen, - unsigned alignment, - unsigned usage, - unsigned size) -{ - struct llvmpipe_buffer *buffer = CALLOC_STRUCT(llvmpipe_buffer); - - pipe_reference_init(&buffer->base.reference, 1); - buffer->base.screen = screen; - buffer->base.alignment = MAX2(alignment, 16); - buffer->base.usage = usage; - buffer->base.size = size; - - buffer->data = align_malloc(size, alignment); - - return &buffer->base; -} - - -/** - * Create buffer which wraps user-space data. - */ -static struct pipe_buffer * -llvmpipe_user_buffer_create(struct pipe_screen *screen, - void *ptr, - unsigned bytes) -{ - struct llvmpipe_buffer *buffer; - - buffer = CALLOC_STRUCT(llvmpipe_buffer); - if(!buffer) - return NULL; - - pipe_reference_init(&buffer->base.reference, 1); - buffer->base.screen = screen; - buffer->base.size = bytes; - buffer->userBuffer = TRUE; - buffer->data = ptr; - - return &buffer->base; -} - - -void -llvmpipe_init_screen_buffer_funcs(struct pipe_screen *screen) -{ - screen->buffer_create = llvmpipe_buffer_create; - screen->user_buffer_create = llvmpipe_user_buffer_create; - screen->buffer_map = llvmpipe_buffer_map; - screen->buffer_unmap = llvmpipe_buffer_unmap; - screen->buffer_destroy = llvmpipe_buffer_destroy; -} diff --git a/src/gallium/drivers/llvmpipe/lp_buffer.h b/src/gallium/drivers/llvmpipe/lp_buffer.h deleted file mode 100644 index d6b8184a0b..0000000000 --- a/src/gallium/drivers/llvmpipe/lp_buffer.h +++ /dev/null @@ -1,55 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef LP_BUFFER_H -#define LP_BUFFER_H - -#include "pipe/p_compiler.h" -#include "pipe/p_state.h" - - -struct llvmpipe_buffer -{ - struct pipe_buffer base; - boolean userBuffer; /** Is this a user-space buffer? */ - void *data; -}; - - -/** Cast wrapper */ -static INLINE struct llvmpipe_buffer * -llvmpipe_buffer( struct pipe_buffer *buf ) -{ - return (struct llvmpipe_buffer *)buf; -} - - -void -llvmpipe_init_screen_buffer_funcs(struct pipe_screen *screen); - - -#endif /* LP_BUFFER_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_context.c b/src/gallium/drivers/llvmpipe/lp_context.c index 951a695f96..b7a8319693 100644 --- a/src/gallium/drivers/llvmpipe/lp_context.c +++ b/src/gallium/drivers/llvmpipe/lp_context.c @@ -77,29 +77,13 @@ static void llvmpipe_destroy( struct pipe_context *pipe ) for (i = 0; i < Elements(llvmpipe->constants); i++) { if (llvmpipe->constants[i]) { - pipe_buffer_reference(&llvmpipe->constants[i], NULL); + pipe_resource_reference(&llvmpipe->constants[i], NULL); } } align_free( llvmpipe ); } -static unsigned int -llvmpipe_is_texture_referenced( struct pipe_context *pipe, - struct pipe_texture *texture, - unsigned face, unsigned level) -{ - struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe ); - - return lp_setup_is_texture_referenced(llvmpipe->setup, texture); -} - -static unsigned int -llvmpipe_is_buffer_referenced( struct pipe_context *pipe, - struct pipe_buffer *buf) -{ - return PIPE_UNREFERENCED; -} struct pipe_context * llvmpipe_create_context( struct pipe_screen *screen, void *priv ) @@ -171,11 +155,9 @@ llvmpipe_create_context( struct pipe_screen *screen, void *priv ) llvmpipe->pipe.clear = llvmpipe_clear; llvmpipe->pipe.flush = llvmpipe_flush; - llvmpipe->pipe.is_texture_referenced = llvmpipe_is_texture_referenced; - llvmpipe->pipe.is_buffer_referenced = llvmpipe_is_buffer_referenced; llvmpipe_init_query_funcs( llvmpipe ); - llvmpipe_init_context_texture_funcs( &llvmpipe->pipe ); + llvmpipe_init_context_resource_funcs( &llvmpipe->pipe ); /* * Create drawing context and plug our rendering stage into it. diff --git a/src/gallium/drivers/llvmpipe/lp_context.h b/src/gallium/drivers/llvmpipe/lp_context.h index 71f991049e..4848101ffb 100644 --- a/src/gallium/drivers/llvmpipe/lp_context.h +++ b/src/gallium/drivers/llvmpipe/lp_context.h @@ -65,7 +65,7 @@ struct llvmpipe_context { struct pipe_blend_color blend_color; struct pipe_stencil_ref stencil_ref; struct pipe_clip_state clip; - struct pipe_buffer *constants[PIPE_SHADER_TYPES]; + struct pipe_resource *constants[PIPE_SHADER_TYPES]; struct pipe_framebuffer_state framebuffer; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; diff --git a/src/gallium/drivers/llvmpipe/lp_draw_arrays.c b/src/gallium/drivers/llvmpipe/lp_draw_arrays.c index 3dd68d5794..a9b8ba258b 100644 --- a/src/gallium/drivers/llvmpipe/lp_draw_arrays.c +++ b/src/gallium/drivers/llvmpipe/lp_draw_arrays.c @@ -35,7 +35,6 @@ #include "pipe/p_context.h" #include "util/u_prim.h" -#include "lp_buffer.h" #include "lp_context.h" #include "lp_state.h" @@ -58,7 +57,7 @@ llvmpipe_draw_arrays(struct pipe_context *pipe, unsigned mode, */ void llvmpipe_draw_range_elements(struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned min_index, unsigned max_index, @@ -75,13 +74,13 @@ llvmpipe_draw_range_elements(struct pipe_context *pipe, * Map vertex buffers */ for (i = 0; i < lp->num_vertex_buffers; i++) { - void *buf = llvmpipe_buffer(lp->vertex_buffer[i].buffer)->data; + void *buf = llvmpipe_resource(lp->vertex_buffer[i].buffer)->data; draw_set_mapped_vertex_buffer(draw, i, buf); } /* Map index buffer, if present */ if (indexBuffer) { - void *mapped_indexes = llvmpipe_buffer(indexBuffer)->data; + void *mapped_indexes = llvmpipe_resource(indexBuffer)->data; draw_set_mapped_element_buffer_range(draw, indexSize, min_index, max_index, @@ -117,7 +116,7 @@ llvmpipe_draw_range_elements(struct pipe_context *pipe, void llvmpipe_draw_elements(struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, unsigned count) { diff --git a/src/gallium/drivers/llvmpipe/lp_flush.c b/src/gallium/drivers/llvmpipe/lp_flush.c index 636d72a9bb..7d0abb33e9 100644 --- a/src/gallium/drivers/llvmpipe/lp_flush.c +++ b/src/gallium/drivers/llvmpipe/lp_flush.c @@ -103,7 +103,7 @@ llvmpipe_flush( struct pipe_context *pipe, */ boolean llvmpipe_flush_texture(struct pipe_context *pipe, - struct pipe_texture *texture, + struct pipe_resource *texture, unsigned face, unsigned level, unsigned flush_flags, @@ -114,7 +114,7 @@ llvmpipe_flush_texture(struct pipe_context *pipe, struct pipe_fence_handle *last_fence = NULL; unsigned referenced; - referenced = pipe->is_texture_referenced(pipe, texture, face, level); + referenced = pipe->is_resource_referenced(pipe, texture, face, level); if ((referenced & PIPE_REFERENCED_FOR_WRITE) || ((referenced & PIPE_REFERENCED_FOR_READ) && !read_only)) { diff --git a/src/gallium/drivers/llvmpipe/lp_flush.h b/src/gallium/drivers/llvmpipe/lp_flush.h index e13f57ccec..2375d22b85 100644 --- a/src/gallium/drivers/llvmpipe/lp_flush.h +++ b/src/gallium/drivers/llvmpipe/lp_flush.h @@ -38,7 +38,7 @@ void llvmpipe_flush(struct pipe_context *pipe, unsigned flags, boolean llvmpipe_flush_texture(struct pipe_context *pipe, - struct pipe_texture *texture, + struct pipe_resource *texture, unsigned face, unsigned level, unsigned flush_flags, diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c index 81ea11a16b..497bfb0994 100644 --- a/src/gallium/drivers/llvmpipe/lp_rast.c +++ b/src/gallium/drivers/llvmpipe/lp_rast.c @@ -67,13 +67,13 @@ lp_rast_begin( struct lp_rasterizer *rast, rast->cbuf[i].format = cbuf->texture->format; rast->cbuf[i].width = cbuf->width; rast->cbuf[i].height = cbuf->height; - rast->cbuf[i].stride = llvmpipe_texture_stride(cbuf->texture, cbuf->level); + rast->cbuf[i].stride = llvmpipe_resource_stride(cbuf->texture, cbuf->level); } if (write_zstencil) { struct pipe_surface *zsbuf = scene->fb.zsbuf; rast->zsbuf.map = scene->zsbuf_map; - rast->zsbuf.stride = llvmpipe_texture_stride(zsbuf->texture, zsbuf->level); + rast->zsbuf.stride = llvmpipe_resource_stride(zsbuf->texture, zsbuf->level); rast->zsbuf.blocksize = util_format_get_blocksize(zsbuf->texture->format); } diff --git a/src/gallium/drivers/llvmpipe/lp_scene.c b/src/gallium/drivers/llvmpipe/lp_scene.c index 681ce674d4..a8aab157ed 100644 --- a/src/gallium/drivers/llvmpipe/lp_scene.c +++ b/src/gallium/drivers/llvmpipe/lp_scene.c @@ -181,7 +181,7 @@ lp_scene_reset(struct lp_scene *scene ) struct texture_ref *ref, *next, *ref_list = &scene->textures; for (ref = ref_list->next; ref != ref_list; ref = next) { next = next_elem(ref); - pipe_texture_reference(&ref->texture, NULL); + pipe_resource_reference(&ref->texture, NULL); FREE(ref); } make_empty_list(ref_list); @@ -248,12 +248,12 @@ lp_scene_bin_size( const struct lp_scene *scene, unsigned x, unsigned y ) */ void lp_scene_texture_reference( struct lp_scene *scene, - struct pipe_texture *texture ) + struct pipe_resource *texture ) { struct texture_ref *ref = CALLOC_STRUCT(texture_ref); if (ref) { struct texture_ref *ref_list = &scene->textures; - pipe_texture_reference(&ref->texture, texture); + pipe_resource_reference(&ref->texture, texture); insert_at_tail(ref_list, ref); } } @@ -263,8 +263,8 @@ lp_scene_texture_reference( struct lp_scene *scene, * Does this scene have a reference to the given texture? */ boolean -lp_scene_is_texture_referenced( const struct lp_scene *scene, - const struct pipe_texture *texture ) +lp_scene_is_resource_referenced( const struct lp_scene *scene, + const struct pipe_resource *texture ) { const struct texture_ref *ref_list = &scene->textures; const struct texture_ref *ref; @@ -408,7 +408,7 @@ lp_scene_map_buffers( struct lp_scene *scene ) for (i = 0; i < scene->fb.nr_cbufs; i++) { cbuf = scene->fb.cbufs[i]; if (cbuf) { - scene->cbuf_map[i] = llvmpipe_texture_map(cbuf->texture, + scene->cbuf_map[i] = llvmpipe_resource_map(cbuf->texture, cbuf->face, cbuf->level, cbuf->zslice); @@ -421,7 +421,7 @@ lp_scene_map_buffers( struct lp_scene *scene ) */ zsbuf = scene->fb.zsbuf; if (zsbuf) { - scene->zsbuf_map = llvmpipe_texture_map(zsbuf->texture, + scene->zsbuf_map = llvmpipe_resource_map(zsbuf->texture, zsbuf->face, zsbuf->level, zsbuf->zslice); @@ -453,7 +453,7 @@ lp_scene_unmap_buffers( struct lp_scene *scene ) for (i = 0; i < scene->fb.nr_cbufs; i++) { if (scene->cbuf_map[i]) { struct pipe_surface *cbuf = scene->fb.cbufs[i]; - llvmpipe_texture_unmap(cbuf->texture, + llvmpipe_resource_unmap(cbuf->texture, cbuf->face, cbuf->level, cbuf->zslice); @@ -463,7 +463,7 @@ lp_scene_unmap_buffers( struct lp_scene *scene ) if (scene->zsbuf_map) { struct pipe_surface *zsbuf = scene->fb.zsbuf; - llvmpipe_texture_unmap(zsbuf->texture, + llvmpipe_resource_unmap(zsbuf->texture, zsbuf->face, zsbuf->level, zsbuf->zslice); diff --git a/src/gallium/drivers/llvmpipe/lp_scene.h b/src/gallium/drivers/llvmpipe/lp_scene.h index b602b1e8a0..a1fb8bf541 100644 --- a/src/gallium/drivers/llvmpipe/lp_scene.h +++ b/src/gallium/drivers/llvmpipe/lp_scene.h @@ -99,7 +99,7 @@ struct data_block_list { /** List of texture references */ struct texture_ref { - struct pipe_texture *texture; + struct pipe_resource *texture; struct texture_ref *prev, *next; /**< linked list w/ u_simple_list.h */ }; @@ -168,10 +168,10 @@ unsigned lp_scene_data_size( const struct lp_scene *scene ); unsigned lp_scene_bin_size( const struct lp_scene *scene, unsigned x, unsigned y ); void lp_scene_texture_reference( struct lp_scene *scene, - struct pipe_texture *texture ); + struct pipe_resource *texture ); -boolean lp_scene_is_texture_referenced( const struct lp_scene *scene, - const struct pipe_texture *texture ); +boolean lp_scene_is_resource_referenced( const struct lp_scene *scene, + const struct pipe_resource *texture ); /** diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c index f1bbc2092c..0614356833 100644 --- a/src/gallium/drivers/llvmpipe/lp_screen.c +++ b/src/gallium/drivers/llvmpipe/lp_screen.c @@ -32,7 +32,6 @@ #include "pipe/p_screen.h" #include "lp_texture.h" -#include "lp_buffer.h" #include "lp_fence.h" #include "lp_jit.h" #include "lp_screen.h" @@ -251,7 +250,7 @@ llvmpipe_flush_frontbuffer(struct pipe_screen *_screen, { struct llvmpipe_screen *screen = llvmpipe_screen(_screen); struct sw_winsys *winsys = screen->winsys; - struct llvmpipe_texture *texture = llvmpipe_texture(surface->texture); + struct llvmpipe_resource *texture = llvmpipe_resource(surface->texture); assert(texture->dt); if (texture->dt) @@ -304,8 +303,7 @@ llvmpipe_create_screen(struct sw_winsys *winsys) screen->base.context_create = llvmpipe_create_context; screen->base.flush_frontbuffer = llvmpipe_flush_frontbuffer; - llvmpipe_init_screen_texture_funcs(&screen->base); - llvmpipe_init_screen_buffer_funcs(&screen->base); + llvmpipe_init_screen_resource_funcs(&screen->base); llvmpipe_init_screen_fence_funcs(&screen->base); lp_jit_screen_init(screen); diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c index cd16b6b2d3..7080a0a996 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_setup.c @@ -39,7 +39,6 @@ #include "util/u_surface.h" #include "lp_scene.h" #include "lp_scene_queue.h" -#include "lp_buffer.h" #include "lp_texture.h" #include "lp_debug.h" #include "lp_fence.h" @@ -379,11 +378,11 @@ lp_setup_set_fs_functions( struct lp_setup_context *setup, void lp_setup_set_fs_constants(struct lp_setup_context *setup, - struct pipe_buffer *buffer) + struct pipe_resource *buffer) { LP_DBG(DEBUG_SETUP, "%s %p\n", __FUNCTION__, (void *) buffer); - pipe_buffer_reference(&setup->constants.current, buffer); + pipe_resource_reference(&setup->constants.current, buffer); setup->dirty |= LP_SETUP_NEW_CONSTANTS; } @@ -467,8 +466,8 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup, struct pipe_sampler_view *view = i < num ? views[i] : NULL; if(view) { - struct pipe_texture *tex = view->texture; - struct llvmpipe_texture *lp_tex = llvmpipe_texture(tex); + struct pipe_resource *tex = view->texture; + struct llvmpipe_resource *lp_tex = llvmpipe_resource(tex); struct lp_jit_texture *jit_tex; jit_tex = &setup->fs.current.jit_context.textures[i]; jit_tex->width = tex->width0; @@ -516,8 +515,8 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup, * being rendered and the current scene being built. */ unsigned -lp_setup_is_texture_referenced( const struct lp_setup_context *setup, - const struct pipe_texture *texture ) +lp_setup_is_resource_referenced( const struct lp_setup_context *setup, + const struct pipe_resource *texture ) { unsigned i; @@ -532,7 +531,7 @@ lp_setup_is_texture_referenced( const struct lp_setup_context *setup, /* check textures referenced by the scene */ for (i = 0; i < Elements(setup->scenes); i++) { - if (lp_scene_is_texture_referenced(setup->scenes[i], texture)) { + if (lp_scene_is_resource_referenced(setup->scenes[i], texture)) { return PIPE_REFERENCED_FOR_READ; } } @@ -593,11 +592,11 @@ lp_setup_update_state( struct lp_setup_context *setup ) } if(setup->dirty & LP_SETUP_NEW_CONSTANTS) { - struct pipe_buffer *buffer = setup->constants.current; + struct pipe_resource *buffer = setup->constants.current; if(buffer) { - unsigned current_size = buffer->size; - const void *current_data = llvmpipe_buffer(buffer)->data; + unsigned current_size = buffer->width0; + const void *current_data = llvmpipe_resource(buffer)->data; /* TODO: copy only the actually used constants? */ @@ -667,7 +666,7 @@ lp_setup_destroy( struct lp_setup_context *setup ) { reset_context( setup ); - pipe_buffer_reference(&setup->constants.current, NULL); + pipe_resource_reference(&setup->constants.current, NULL); /* free the scenes in the 'empty' queue */ while (1) { diff --git a/src/gallium/drivers/llvmpipe/lp_setup.h b/src/gallium/drivers/llvmpipe/lp_setup.h index 414eaec98d..85e2984b17 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.h +++ b/src/gallium/drivers/llvmpipe/lp_setup.h @@ -105,7 +105,7 @@ lp_setup_set_fs_functions( struct lp_setup_context *setup, void lp_setup_set_fs_constants(struct lp_setup_context *setup, - struct pipe_buffer *buffer); + struct pipe_resource *buffer); void @@ -126,8 +126,8 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup, struct pipe_sampler_view **views); unsigned -lp_setup_is_texture_referenced( const struct lp_setup_context *setup, - const struct pipe_texture *texture ); +lp_setup_is_resource_referenced( const struct lp_setup_context *setup, + const struct pipe_resource *texture ); void lp_setup_set_flatshade_first( struct lp_setup_context *setup, diff --git a/src/gallium/drivers/llvmpipe/lp_setup_context.h b/src/gallium/drivers/llvmpipe/lp_setup_context.h index 464fb36984..92c3087eaa 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup_context.h +++ b/src/gallium/drivers/llvmpipe/lp_setup_context.h @@ -115,7 +115,7 @@ struct lp_setup_context /** fragment shader constants */ struct { - struct pipe_buffer *current; + struct pipe_resource *current; unsigned stored_size; const void *stored_data; } constants; diff --git a/src/gallium/drivers/llvmpipe/lp_state.h b/src/gallium/drivers/llvmpipe/lp_state.h index be02e97648..21aff2fdb4 100644 --- a/src/gallium/drivers/llvmpipe/lp_state.h +++ b/src/gallium/drivers/llvmpipe/lp_state.h @@ -169,7 +169,7 @@ void llvmpipe_set_clip_state( struct pipe_context *, void llvmpipe_set_constant_buffer(struct pipe_context *, uint shader, uint index, - struct pipe_buffer *buf); + struct pipe_resource *buf); void *llvmpipe_create_fs_state(struct pipe_context *, const struct pipe_shader_state *); @@ -203,7 +203,7 @@ llvmpipe_set_vertex_sampler_views(struct pipe_context *, struct pipe_sampler_view * llvmpipe_create_sampler_view(struct pipe_context *pipe, - struct pipe_texture *texture, + struct pipe_resource *texture, const struct pipe_sampler_view *templ); void @@ -226,12 +226,12 @@ void llvmpipe_draw_arrays(struct pipe_context *pipe, unsigned mode, unsigned start, unsigned count); void llvmpipe_draw_elements(struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, unsigned count); void llvmpipe_draw_range_elements(struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned min_index, unsigned max_index, diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index a2ec8c3943..47c558cad7 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -85,7 +85,6 @@ #include "gallivm/lp_bld_swizzle.h" #include "gallivm/lp_bld_flow.h" #include "gallivm/lp_bld_debug.h" -#include "lp_buffer.h" #include "lp_context.h" #include "lp_debug.h" #include "lp_perf.h" @@ -1012,11 +1011,11 @@ llvmpipe_delete_fs_state(struct pipe_context *pipe, void *fs) void llvmpipe_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index, - struct pipe_buffer *constants) + struct pipe_resource *constants) { struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); - unsigned size = constants ? constants->size : 0; - const void *data = constants ? llvmpipe_buffer(constants)->data : NULL; + unsigned size = constants ? constants->width0 : 0; + const void *data = constants ? llvmpipe_resource(constants)->data : NULL; assert(shader < PIPE_SHADER_TYPES); assert(index == 0); @@ -1027,7 +1026,7 @@ llvmpipe_set_constant_buffer(struct pipe_context *pipe, draw_flush(llvmpipe->draw); /* note: reference counting */ - pipe_buffer_reference(&llvmpipe->constants[shader], constants); + pipe_resource_reference(&llvmpipe->constants[shader], constants); if(shader == PIPE_SHADER_VERTEX) { draw_set_mapped_constant_buffer(llvmpipe->draw, PIPE_SHADER_VERTEX, 0, diff --git a/src/gallium/drivers/llvmpipe/lp_state_sampler.c b/src/gallium/drivers/llvmpipe/lp_state_sampler.c index 2645441b58..3552ff50ce 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_sampler.c +++ b/src/gallium/drivers/llvmpipe/lp_state_sampler.c @@ -165,7 +165,7 @@ llvmpipe_set_vertex_sampler_views(struct pipe_context *pipe, struct pipe_sampler_view * llvmpipe_create_sampler_view(struct pipe_context *pipe, - struct pipe_texture *texture, + struct pipe_resource *texture, const struct pipe_sampler_view *templ) { struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); @@ -174,7 +174,7 @@ llvmpipe_create_sampler_view(struct pipe_context *pipe, *view = *templ; view->reference.count = 1; view->texture = NULL; - pipe_texture_reference(&view->texture, texture); + pipe_resource_reference(&view->texture, texture); view->context = pipe; } @@ -186,7 +186,7 @@ void llvmpipe_sampler_view_destroy(struct pipe_context *pipe, struct pipe_sampler_view *view) { - pipe_texture_reference(&view->texture, NULL); + pipe_resource_reference(&view->texture, NULL); FREE(view); } diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c index 93ad789c35..0cf90554b5 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture.c +++ b/src/gallium/drivers/llvmpipe/lp_texture.c @@ -37,11 +37,13 @@ #include "util/u_format.h" #include "util/u_math.h" #include "util/u_memory.h" +#include "util/u_transfer.h" #include "lp_context.h" #include "lp_screen.h" #include "lp_flush.h" #include "lp_texture.h" +#include "lp_setup.h" #include "lp_tile_size.h" #include "state_tracker/sw_winsys.h" @@ -51,10 +53,10 @@ * Simple, maximally packed layout. */ static boolean -llvmpipe_texture_layout(struct llvmpipe_screen *screen, - struct llvmpipe_texture *lpt) +llvmpipe_resource_layout(struct llvmpipe_screen *screen, + struct llvmpipe_resource *lpt) { - struct pipe_texture *pt = &lpt->base; + struct pipe_resource *pt = &lpt->base; unsigned level; unsigned width = pt->width0; unsigned height = pt->height0; @@ -92,7 +94,7 @@ llvmpipe_texture_layout(struct llvmpipe_screen *screen, static boolean llvmpipe_displaytarget_layout(struct llvmpipe_screen *screen, - struct llvmpipe_texture *lpt) + struct llvmpipe_resource *lpt) { struct sw_winsys *winsys = screen->winsys; @@ -113,12 +115,12 @@ llvmpipe_displaytarget_layout(struct llvmpipe_screen *screen, } -static struct pipe_texture * -llvmpipe_texture_create(struct pipe_screen *_screen, - const struct pipe_texture *templat) +static struct pipe_resource * +llvmpipe_resource_create(struct pipe_screen *_screen, + const struct pipe_resource *templat) { struct llvmpipe_screen *screen = llvmpipe_screen(_screen); - struct llvmpipe_texture *lpt = CALLOC_STRUCT(llvmpipe_texture); + struct llvmpipe_resource *lpt = CALLOC_STRUCT(llvmpipe_resource); if (!lpt) return NULL; @@ -133,7 +135,7 @@ llvmpipe_texture_create(struct pipe_screen *_screen, goto fail; } else { - if (!llvmpipe_texture_layout(screen, lpt)) + if (!llvmpipe_resource_layout(screen, lpt)) goto fail; } @@ -146,17 +148,18 @@ llvmpipe_texture_create(struct pipe_screen *_screen, static void -llvmpipe_texture_destroy(struct pipe_texture *pt) +llvmpipe_resource_destroy(struct pipe_screen *pscreen, + struct pipe_resource *pt) { - struct llvmpipe_screen *screen = llvmpipe_screen(pt->screen); - struct llvmpipe_texture *lpt = llvmpipe_texture(pt); + struct llvmpipe_screen *screen = llvmpipe_screen(pscreen); + struct llvmpipe_resource *lpt = llvmpipe_resource(pt); if (lpt->dt) { /* display target */ struct sw_winsys *winsys = screen->winsys; winsys->displaytarget_destroy(winsys, lpt->dt); } - else { + else if (!lpt->userBuffer) { /* regular texture */ align_free(lpt->data); } @@ -169,12 +172,12 @@ llvmpipe_texture_destroy(struct pipe_texture *pt) * Map a texture. Without any synchronization. */ void * -llvmpipe_texture_map(struct pipe_texture *texture, +llvmpipe_resource_map(struct pipe_resource *texture, unsigned face, unsigned level, unsigned zslice) { - struct llvmpipe_texture *lpt = llvmpipe_texture(texture); + struct llvmpipe_resource *lpt = llvmpipe_resource(texture); uint8_t *map; if (lpt->dt) { @@ -204,7 +207,7 @@ llvmpipe_texture_map(struct pipe_texture *texture, /* XXX shouldn't that rather be tex_height = align(u_minify(texture->height0, level), 2) - to account for alignment done in llvmpipe_texture_layout ? + to account for alignment done in llvmpipe_resource_layout ? */ if (texture->target == PIPE_TEXTURE_CUBE) { unsigned tex_height = u_minify(texture->height0, level); @@ -230,12 +233,12 @@ llvmpipe_texture_map(struct pipe_texture *texture, * Unmap a texture. Without any synchronization. */ void -llvmpipe_texture_unmap(struct pipe_texture *texture, +llvmpipe_resource_unmap(struct pipe_resource *texture, unsigned face, unsigned level, unsigned zslice) { - struct llvmpipe_texture *lpt = llvmpipe_texture(texture); + struct llvmpipe_resource *lpt = llvmpipe_resource(texture); if (lpt->dt) { /* display target */ @@ -281,12 +284,12 @@ llvmpipe_texture_from_handle(struct pipe_screen *screen, static boolean -llvmpipe_texture_get_handle(struct pipe_screen *screen, - struct pipe_texture *pt, +llvmpipe_resource_get_handle(struct pipe_screen *screen, + struct pipe_resource *pt, struct winsys_handle *whandle) { struct sw_winsys *winsys = llvmpipe_screen(screen)->winsys; - struct llvmpipe_texture *lpt = llvmpipe_texture(pt); + struct llvmpipe_resource *lpt = llvmpipe_resource(pt); assert(lpt->dt); if (!lpt->dt) @@ -298,11 +301,11 @@ llvmpipe_texture_get_handle(struct pipe_screen *screen, static struct pipe_surface * llvmpipe_get_tex_surface(struct pipe_screen *screen, - struct pipe_texture *pt, + struct pipe_resource *pt, unsigned face, unsigned level, unsigned zslice, unsigned usage) { - struct llvmpipe_texture *lpt = llvmpipe_texture(pt); + struct llvmpipe_resource *lpt = llvmpipe_resource(pt); struct pipe_surface *ps; assert(level <= pt->last_level); @@ -310,7 +313,7 @@ llvmpipe_get_tex_surface(struct pipe_screen *screen, ps = CALLOC_STRUCT(pipe_surface); if (ps) { pipe_reference_init(&ps->reference, 1); - pipe_texture_reference(&ps->texture, pt); + pipe_resource_reference(&ps->texture, pt); ps->format = pt->format; ps->width = u_minify(pt->width0, level); ps->height = u_minify(pt->height0, level); @@ -352,37 +355,31 @@ llvmpipe_tex_surface_destroy(struct pipe_surface *surf) * where it would happen. For llvmpipe, nothing to do. */ assert(surf->texture); - pipe_texture_reference(&surf->texture, NULL); + pipe_resource_reference(&surf->texture, NULL); FREE(surf); } static struct pipe_transfer * -llvmpipe_get_tex_transfer(struct pipe_context *pipe, - struct pipe_texture *texture, - unsigned face, unsigned level, unsigned zslice, - enum pipe_transfer_usage usage, - unsigned x, unsigned y, unsigned w, unsigned h) +llvmpipe_get_transfer(struct pipe_context *pipe, + struct pipe_resource *resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box) { - struct llvmpipe_texture *lptex = llvmpipe_texture(texture); + struct llvmpipe_resource *lptex = llvmpipe_resource(resource); struct llvmpipe_transfer *lpt; - assert(texture); - assert(level <= texture->last_level); + assert(resource); + assert(sr.level <= resource->last_level); lpt = CALLOC_STRUCT(llvmpipe_transfer); if (lpt) { struct pipe_transfer *pt = &lpt->base; - pipe_texture_reference(&pt->texture, texture); - pt->x = x; - pt->y = y; - pt->width = align(w, TILE_SIZE); - pt->height = align(h, TILE_SIZE); - pt->stride = lptex->stride[level]; + pipe_resource_reference(&pt->resource, resource); + pt->box = *box; + pt->stride = lptex->stride[sr.level]; pt->usage = usage; - pt->face = face; - pt->level = level; - pt->zslice = zslice; return pt; } @@ -391,15 +388,15 @@ llvmpipe_get_tex_transfer(struct pipe_context *pipe, static void -llvmpipe_tex_transfer_destroy(struct pipe_context *pipe, +llvmpipe_transfer_destroy(struct pipe_context *pipe, struct pipe_transfer *transfer) { /* Effectively do the texture_update work here - if texture images * needed post-processing to put them into hardware layout, this is * where it would happen. For llvmpipe, nothing to do. */ - assert (transfer->texture); - pipe_texture_reference(&transfer->texture, NULL); + assert (transfer->resource); + pipe_resource_reference(&transfer->resource, NULL); FREE(transfer); } @@ -410,11 +407,11 @@ llvmpipe_transfer_map( struct pipe_context *pipe, { struct llvmpipe_screen *screen = llvmpipe_screen(pipe->screen); ubyte *map; - struct llvmpipe_texture *lpt; + struct llvmpipe_resource *lpt; enum pipe_format format; - assert(transfer->texture); - lpt = llvmpipe_texture(transfer->texture); + assert(transfer->resource); + lpt = llvmpipe_resource(transfer->resource); format = lpt->base.format; /* @@ -422,14 +419,18 @@ llvmpipe_transfer_map( struct pipe_context *pipe, * context if necessary. */ llvmpipe_flush_texture(pipe, - transfer->texture, transfer->face, transfer->level, + transfer->resource, + transfer->sr.face, + transfer->sr.level, 0, /* flush_flags */ !(transfer->usage & PIPE_TRANSFER_WRITE), /* read_only */ TRUE, /* cpu_access */ FALSE); /* do_not_flush */ - map = llvmpipe_texture_map(transfer->texture, - transfer->face, transfer->level, transfer->zslice); + map = llvmpipe_resource_map(transfer->resource, + transfer->sr.face, + transfer->sr.level, + transfer->box.z); /* May want to different things here depending on read/write nature * of the map: @@ -441,8 +442,8 @@ llvmpipe_transfer_map( struct pipe_context *pipe, } map += - transfer->y / util_format_get_blockheight(format) * transfer->stride + - transfer->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); + transfer->box.y / util_format_get_blockheight(format) * transfer->stride + + transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); return map; } @@ -452,19 +453,65 @@ static void llvmpipe_transfer_unmap(struct pipe_context *pipe, struct pipe_transfer *transfer) { - assert(transfer->texture); + assert(transfer->resource); + + llvmpipe_resource_unmap(transfer->resource, + transfer->sr.face, + transfer->sr.level, + transfer->box.z); +} + +static unsigned int +llvmpipe_is_resource_referenced( struct pipe_context *pipe, + struct pipe_resource *presource, + unsigned face, unsigned level) +{ + struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe ); + + if (presource->target == PIPE_BUFFER) + return PIPE_UNREFERENCED; + + return lp_setup_is_resource_referenced(llvmpipe->setup, presource); +} + + + +/** + * Create buffer which wraps user-space data. + */ +static struct pipe_resource * +llvmpipe_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned usage) +{ + struct llvmpipe_resource *buffer; + + buffer = CALLOC_STRUCT(llvmpipe_resource); + if(!buffer) + return NULL; - llvmpipe_texture_unmap(transfer->texture, - transfer->face, transfer->level, transfer->zslice); + pipe_reference_init(&buffer->base.reference, 1); + buffer->base.screen = screen; + buffer->base.format = PIPE_FORMAT_R8_UNORM; /* ?? */ + buffer->base.usage = PIPE_BUFFER_USAGE_CPU_READ | usage; + buffer->base.width0 = bytes; + buffer->base.height0 = 1; + buffer->base.depth0 = 1; + buffer->userBuffer = TRUE; + buffer->data = ptr; + + return &buffer->base; } void -llvmpipe_init_screen_texture_funcs(struct pipe_screen *screen) +llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen) { - screen->texture_create = llvmpipe_texture_create; - screen->texture_destroy = llvmpipe_texture_destroy; - screen->texture_get_handle = llvmpipe_texture_get_handle; + screen->resource_create = llvmpipe_resource_create; + screen->resource_destroy = llvmpipe_resource_destroy; + screen->resource_get_handle = llvmpipe_resource_get_handle; + screen->user_buffer_create = llvmpipe_user_buffer_create; screen->get_tex_surface = llvmpipe_get_tex_surface; screen->tex_surface_destroy = llvmpipe_tex_surface_destroy; @@ -472,10 +519,14 @@ llvmpipe_init_screen_texture_funcs(struct pipe_screen *screen) void -llvmpipe_init_context_texture_funcs(struct pipe_context *pipe) +llvmpipe_init_context_resource_funcs(struct pipe_context *pipe) { - pipe->get_tex_transfer = llvmpipe_get_tex_transfer; - pipe->tex_transfer_destroy = llvmpipe_tex_transfer_destroy; + pipe->get_transfer = llvmpipe_get_transfer; + pipe->transfer_destroy = llvmpipe_transfer_destroy; pipe->transfer_map = llvmpipe_transfer_map; pipe->transfer_unmap = llvmpipe_transfer_unmap; + pipe->is_resource_referenced = llvmpipe_is_resource_referenced; + + pipe->transfer_flush_region = u_default_transfer_flush_region; + pipe->transfer_inline_write = u_default_transfer_inline_write; } diff --git a/src/gallium/drivers/llvmpipe/lp_texture.h b/src/gallium/drivers/llvmpipe/lp_texture.h index 2350c26e4f..ca67b5bdb0 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture.h +++ b/src/gallium/drivers/llvmpipe/lp_texture.h @@ -43,9 +43,9 @@ struct llvmpipe_context; struct sw_displaytarget; -struct llvmpipe_texture +struct llvmpipe_resource { - struct pipe_texture base; + struct pipe_resource base; unsigned long level_offset[LP_MAX_TEXTURE_2D_LEVELS]; unsigned stride[LP_MAX_TEXTURE_2D_LEVELS]; @@ -61,6 +61,7 @@ struct llvmpipe_texture */ void *data; + boolean userBuffer; /** Is this a user-space buffer? */ unsigned timestamp; }; @@ -74,17 +75,17 @@ struct llvmpipe_transfer /** cast wrappers */ -static INLINE struct llvmpipe_texture * -llvmpipe_texture(struct pipe_texture *pt) +static INLINE struct llvmpipe_resource * +llvmpipe_resource(struct pipe_resource *pt) { - return (struct llvmpipe_texture *) pt; + return (struct llvmpipe_resource *) pt; } -static INLINE const struct llvmpipe_texture * -llvmpipe_texture_const(const struct pipe_texture *pt) +static INLINE const struct llvmpipe_resource * +llvmpipe_resource_const(const struct pipe_resource *pt) { - return (const struct llvmpipe_texture *) pt; + return (const struct llvmpipe_resource *) pt; } @@ -95,32 +96,30 @@ llvmpipe_transfer(struct pipe_transfer *pt) } +void llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen); +void llvmpipe_init_context_resource_funcs(struct pipe_context *pipe); + static INLINE unsigned -llvmpipe_texture_stride(struct pipe_texture *texture, +llvmpipe_resource_stride(struct pipe_resource *texture, unsigned level) { - struct llvmpipe_texture *lpt = llvmpipe_texture(texture); + struct llvmpipe_resource *lpt = llvmpipe_resource(texture); assert(level < LP_MAX_TEXTURE_2D_LEVELS); return lpt->stride[level]; } void * -llvmpipe_texture_map(struct pipe_texture *texture, +llvmpipe_resource_map(struct pipe_resource *texture, unsigned face, unsigned level, unsigned zslice); void -llvmpipe_texture_unmap(struct pipe_texture *texture, +llvmpipe_resource_unmap(struct pipe_resource *texture, unsigned face, unsigned level, unsigned zslice); -extern void -llvmpipe_init_screen_texture_funcs(struct pipe_screen *screen); - -extern void -llvmpipe_init_context_texture_funcs(struct pipe_context *pipe); #endif /* LP_TEXTURE_H */ diff --git a/src/gallium/drivers/nv50/nv50_transfer.c b/src/gallium/drivers/nv50/nv50_transfer.c index 9eb223eca6..c30b787167 100644 --- a/src/gallium/drivers/nv50/nv50_transfer.c +++ b/src/gallium/drivers/nv50/nv50_transfer.c @@ -247,8 +247,8 @@ nv50_transfer_unmap(struct pipe_context *pcontext, struct pipe_transfer *ptx) void nv50_init_transfer_functions(struct nv50_context *nv50) { - nv50->pipe.get_tex_transfer = nv50_transfer_new; - nv50->pipe.tex_transfer_destroy = nv50_transfer_del; + nv50->pipe.get_transfer = nv50_transfer_new; + nv50->pipe.transfer_destroy = nv50_transfer_del; nv50->pipe.transfer_map = nv50_transfer_map; nv50->pipe.transfer_unmap = nv50_transfer_unmap; } diff --git a/src/gallium/drivers/nvfx/nvfx_transfer.c b/src/gallium/drivers/nvfx/nvfx_transfer.c index 409b354d58..b9124757e7 100644 --- a/src/gallium/drivers/nvfx/nvfx_transfer.c +++ b/src/gallium/drivers/nvfx/nvfx_transfer.c @@ -175,8 +175,15 @@ nvfx_transfer_unmap(struct pipe_context *pcontext, struct pipe_transfer *ptx) void nvfx_init_transfer_functions(struct nvfx_context *nvfx) { +<<<<<<< HEAD:src/gallium/drivers/nv30/nv30_transfer.c + nv30->pipe.get_transfer = nv30_transfer_new; + nv30->pipe.transfer_destroy = nv30_transfer_del; + nv30->pipe.transfer_map = nv30_transfer_map; + nv30->pipe.transfer_unmap = nv30_transfer_unmap; +======= nvfx->pipe.get_tex_transfer = nvfx_transfer_new; nvfx->pipe.tex_transfer_destroy = nvfx_transfer_del; nvfx->pipe.transfer_map = nvfx_transfer_map; nvfx->pipe.transfer_unmap = nvfx_transfer_unmap; +>>>>>>> origin/gallium-sampler-view:src/gallium/drivers/nvfx/nvfx_transfer.c } diff --git a/src/gallium/drivers/r300/r300_transfer.c b/src/gallium/drivers/r300/r300_transfer.c index 987a040698..fdac467347 100644 --- a/src/gallium/drivers/r300/r300_transfer.c +++ b/src/gallium/drivers/r300/r300_transfer.c @@ -38,7 +38,7 @@ struct r300_transfer { /* Pipe context. */ struct pipe_context *ctx; - /* Parameters of get_tex_transfer. */ + /* Parameters of get_transfer. */ unsigned x, y, level, zslice, face; /* Offset from start of buffer. */ @@ -120,7 +120,7 @@ static void r300_copy_into_tiled_texture(struct pipe_context *ctx, } static struct pipe_transfer* -r300_get_tex_transfer(struct pipe_context *ctx, +r300_get_transfer(struct pipe_context *ctx, struct pipe_texture *texture, unsigned face, unsigned level, unsigned zslice, enum pipe_transfer_usage usage, unsigned x, unsigned y, @@ -207,7 +207,7 @@ r300_get_tex_transfer(struct pipe_context *ctx, return &trans->transfer; } -static void r300_tex_transfer_destroy(struct pipe_context *ctx, +static void r300_transfer_destroy(struct pipe_context *ctx, struct pipe_transfer *trans) { struct r300_transfer *r300transfer = r300_transfer(trans); @@ -273,8 +273,8 @@ void r300_init_transfer_functions( struct r300_context *r300ctx ) { struct pipe_context *ctx = &r300ctx->context; - ctx->get_tex_transfer = r300_get_tex_transfer; - ctx->tex_transfer_destroy = r300_tex_transfer_destroy; + ctx->get_transfer = r300_get_transfer; + ctx->transfer_destroy = r300_transfer_destroy; ctx->transfer_map = r300_transfer_map; ctx->transfer_unmap = r300_transfer_unmap; } diff --git a/src/gallium/drivers/softpipe/Makefile b/src/gallium/drivers/softpipe/Makefile index 239655d628..83f3e4a19b 100644 --- a/src/gallium/drivers/softpipe/Makefile +++ b/src/gallium/drivers/softpipe/Makefile @@ -6,7 +6,6 @@ LIBNAME = softpipe C_SOURCES = \ sp_fs_exec.c \ sp_fs_sse.c \ - sp_buffer.c \ sp_clear.c \ sp_fence.c \ sp_flush.c \ @@ -33,7 +32,6 @@ C_SOURCES = \ sp_tex_sample.c \ sp_tex_tile_cache.c \ sp_tile_cache.c \ - sp_surface.c \ - sp_video_context.c + sp_surface.c include ../../Makefile.template diff --git a/src/gallium/drivers/softpipe/sp_buffer.c b/src/gallium/drivers/softpipe/sp_buffer.c deleted file mode 100644 index 8f39025086..0000000000 --- a/src/gallium/drivers/softpipe/sp_buffer.c +++ /dev/null @@ -1,118 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -#include "util/u_inlines.h" -#include "util/u_memory.h" -#include "util/u_math.h" - -#include "sp_screen.h" -#include "sp_buffer.h" - - -static void * -softpipe_buffer_map(struct pipe_screen *screen, - struct pipe_buffer *buf, - unsigned flags) -{ - struct softpipe_buffer *softpipe_buf = softpipe_buffer(buf); - return softpipe_buf->data; -} - - -static void -softpipe_buffer_unmap(struct pipe_screen *screen, - struct pipe_buffer *buf) -{ -} - - -static void -softpipe_buffer_destroy(struct pipe_buffer *buf) -{ - struct softpipe_buffer *sbuf = softpipe_buffer(buf); - - if (!sbuf->userBuffer) - align_free(sbuf->data); - - FREE(sbuf); -} - - -static struct pipe_buffer * -softpipe_buffer_create(struct pipe_screen *screen, - unsigned alignment, - unsigned usage, - unsigned size) -{ - struct softpipe_buffer *buffer = CALLOC_STRUCT(softpipe_buffer); - - pipe_reference_init(&buffer->base.reference, 1); - buffer->base.screen = screen; - buffer->base.alignment = MAX2(alignment, 16); - buffer->base.usage = usage; - buffer->base.size = size; - - buffer->data = align_malloc(size, alignment); - - return &buffer->base; -} - - -/** - * Create buffer which wraps user-space data. - */ -static struct pipe_buffer * -softpipe_user_buffer_create(struct pipe_screen *screen, - void *ptr, - unsigned bytes) -{ - struct softpipe_buffer *buffer; - - buffer = CALLOC_STRUCT(softpipe_buffer); - if(!buffer) - return NULL; - - pipe_reference_init(&buffer->base.reference, 1); - buffer->base.screen = screen; - buffer->base.size = bytes; - buffer->userBuffer = TRUE; - buffer->data = ptr; - - return &buffer->base; -} - - -void -softpipe_init_screen_buffer_funcs(struct pipe_screen *screen) -{ - screen->buffer_create = softpipe_buffer_create; - screen->user_buffer_create = softpipe_user_buffer_create; - screen->buffer_map = softpipe_buffer_map; - screen->buffer_unmap = softpipe_buffer_unmap; - screen->buffer_destroy = softpipe_buffer_destroy; -} diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c index 937a573092..d0c2978c24 100644 --- a/src/gallium/drivers/softpipe/sp_context.c +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -117,7 +117,7 @@ softpipe_destroy( struct pipe_context *pipe ) for (j = 0; j < PIPE_MAX_CONSTANT_BUFFERS; j++) { if (softpipe->constants[i][j]) { - pipe_buffer_reference(&softpipe->constants[i][j], NULL); + pipe_resource_reference(&softpipe->constants[i][j], NULL); } } } @@ -135,13 +135,16 @@ softpipe_destroy( struct pipe_context *pipe ) * return PIPE_UNREFERENCED */ static unsigned int -softpipe_is_texture_referenced( struct pipe_context *pipe, - struct pipe_texture *texture, +softpipe_is_resource_referenced( struct pipe_context *pipe, + struct pipe_resource *texture, unsigned face, unsigned level) { struct softpipe_context *softpipe = softpipe_context( pipe ); unsigned i; + if (texture->target == PIPE_BUFFER) + return PIPE_UNREFERENCED; + /* check if any of the bound drawing surfaces are this texture */ if (softpipe->dirty_render_cache) { for (i = 0; i < softpipe->framebuffer.nr_cbufs; i++) { @@ -172,12 +175,6 @@ softpipe_is_texture_referenced( struct pipe_context *pipe, } -static unsigned int -softpipe_is_buffer_referenced( struct pipe_context *pipe, - struct pipe_buffer *buf) -{ - return PIPE_UNREFERENCED; -} static void @@ -274,8 +271,7 @@ softpipe_create_context( struct pipe_screen *screen, softpipe->pipe.clear = softpipe_clear; softpipe->pipe.flush = softpipe_flush; - softpipe->pipe.is_texture_referenced = softpipe_is_texture_referenced; - softpipe->pipe.is_buffer_referenced = softpipe_is_buffer_referenced; + softpipe->pipe.is_resource_referenced = softpipe_is_resource_referenced; softpipe_init_query_funcs( softpipe ); softpipe_init_texture_funcs( &softpipe->pipe ); diff --git a/src/gallium/drivers/softpipe/sp_context.h b/src/gallium/drivers/softpipe/sp_context.h index 75e03c8ae6..be8f2cb3e0 100644 --- a/src/gallium/drivers/softpipe/sp_context.h +++ b/src/gallium/drivers/softpipe/sp_context.h @@ -66,7 +66,7 @@ struct softpipe_context { struct pipe_blend_color blend_color; struct pipe_stencil_ref stencil_ref; struct pipe_clip_state clip; - struct pipe_buffer *constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS]; + struct pipe_resource *constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS]; struct pipe_framebuffer_state framebuffer; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; diff --git a/src/gallium/drivers/softpipe/sp_draw_arrays.c b/src/gallium/drivers/softpipe/sp_draw_arrays.c index 7b77eb239f..461c9a6c4d 100644 --- a/src/gallium/drivers/softpipe/sp_draw_arrays.c +++ b/src/gallium/drivers/softpipe/sp_draw_arrays.c @@ -39,7 +39,7 @@ #include "sp_context.h" #include "sp_query.h" #include "sp_state.h" -#include "sp_buffer.h" +#include "sp_texture.h" #include "draw/draw_context.h" @@ -55,7 +55,7 @@ */ static void softpipe_draw_range_elements_instanced(struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned minIndex, unsigned maxIndex, @@ -85,7 +85,7 @@ softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode, void softpipe_draw_range_elements(struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned min_index, unsigned max_index, @@ -106,7 +106,7 @@ softpipe_draw_range_elements(struct pipe_context *pipe, void softpipe_draw_elements(struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, unsigned count) { @@ -144,7 +144,7 @@ softpipe_draw_arrays_instanced(struct pipe_context *pipe, void softpipe_draw_elements_instanced(struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, @@ -166,7 +166,7 @@ softpipe_draw_elements_instanced(struct pipe_context *pipe, static void softpipe_draw_range_elements_instanced(struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned minIndex, unsigned maxIndex, @@ -193,13 +193,13 @@ softpipe_draw_range_elements_instanced(struct pipe_context *pipe, /* Map vertex buffers */ for (i = 0; i < sp->num_vertex_buffers; i++) { - void *buf = softpipe_buffer(sp->vertex_buffer[i].buffer)->data; + void *buf = softpipe_resource(sp->vertex_buffer[i].buffer)->data; draw_set_mapped_vertex_buffer(draw, i, buf); } /* Map index buffer, if present */ if (indexBuffer) { - void *mapped_indexes = softpipe_buffer(indexBuffer)->data; + void *mapped_indexes = softpipe_resource(indexBuffer)->data; draw_set_mapped_element_buffer_range(draw, indexSize, minIndex, diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c index 757dc86128..32e6ccc5bf 100644 --- a/src/gallium/drivers/softpipe/sp_screen.c +++ b/src/gallium/drivers/softpipe/sp_screen.c @@ -35,7 +35,6 @@ #include "sp_texture.h" #include "sp_screen.h" #include "sp_context.h" -#include "sp_buffer.h" #include "sp_fence.h" #include "sp_public.h" @@ -208,7 +207,7 @@ softpipe_flush_frontbuffer(struct pipe_screen *_screen, { struct softpipe_screen *screen = softpipe_screen(_screen); struct sw_winsys *winsys = screen->winsys; - struct softpipe_texture *texture = softpipe_texture(surface->texture); + struct softpipe_resource *texture = softpipe_resource(surface->texture); assert(texture->dt); if (texture->dt) @@ -241,7 +240,6 @@ softpipe_create_screen(struct sw_winsys *winsys) screen->base.flush_frontbuffer = softpipe_flush_frontbuffer; softpipe_init_screen_texture_funcs(&screen->base); - softpipe_init_screen_buffer_funcs(&screen->base); softpipe_init_screen_fence_funcs(&screen->base); return &screen->base; diff --git a/src/gallium/drivers/softpipe/sp_state.h b/src/gallium/drivers/softpipe/sp_state.h index ade96b0fd4..3c04c8bb07 100644 --- a/src/gallium/drivers/softpipe/sp_state.h +++ b/src/gallium/drivers/softpipe/sp_state.h @@ -150,7 +150,7 @@ void softpipe_set_clip_state( struct pipe_context *, void softpipe_set_constant_buffer(struct pipe_context *, uint shader, uint index, - struct pipe_buffer *buf); + struct pipe_resource *buf); void *softpipe_create_fs_state(struct pipe_context *, const struct pipe_shader_state *); @@ -188,7 +188,7 @@ softpipe_set_vertex_sampler_views(struct pipe_context *, struct pipe_sampler_view * softpipe_create_sampler_view(struct pipe_context *pipe, - struct pipe_texture *texture, + struct pipe_resource *texture, const struct pipe_sampler_view *templ); void @@ -210,12 +210,12 @@ void softpipe_draw_arrays(struct pipe_context *pipe, unsigned mode, unsigned start, unsigned count); void softpipe_draw_elements(struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, unsigned count); void softpipe_draw_range_elements(struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned min_index, unsigned max_index, @@ -231,7 +231,7 @@ softpipe_draw_arrays_instanced(struct pipe_context *pipe, void softpipe_draw_elements_instanced(struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, diff --git a/src/gallium/drivers/softpipe/sp_state_derived.c b/src/gallium/drivers/softpipe/sp_state_derived.c index d2eda7324c..4c6d4909f5 100644 --- a/src/gallium/drivers/softpipe/sp_state_derived.c +++ b/src/gallium/drivers/softpipe/sp_state_derived.c @@ -202,7 +202,7 @@ update_tgsi_samplers( struct softpipe_context *softpipe ) for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { struct softpipe_tex_tile_cache *tc = softpipe->tex_cache[i]; if (tc->texture) { - struct softpipe_texture *spt = softpipe_texture(tc->texture); + struct softpipe_resource *spt = softpipe_resource(tc->texture); if (spt->timestamp != tc->timestamp) { sp_tex_tile_cache_validate_texture( tc ); /* @@ -217,7 +217,7 @@ update_tgsi_samplers( struct softpipe_context *softpipe ) struct softpipe_tex_tile_cache *tc = softpipe->vertex_tex_cache[i]; if (tc->texture) { - struct softpipe_texture *spt = softpipe_texture(tc->texture); + struct softpipe_resource *spt = softpipe_resource(tc->texture); if (spt->timestamp != tc->timestamp) { sp_tex_tile_cache_validate_texture(tc); diff --git a/src/gallium/drivers/softpipe/sp_state_fs.c b/src/gallium/drivers/softpipe/sp_state_fs.c index 2b089c2831..64d26c15d0 100644 --- a/src/gallium/drivers/softpipe/sp_state_fs.c +++ b/src/gallium/drivers/softpipe/sp_state_fs.c @@ -28,7 +28,7 @@ #include "sp_context.h" #include "sp_state.h" #include "sp_fs.h" -#include "sp_buffer.h" +#include "sp_texture.h" #include "pipe/p_defines.h" #include "util/u_memory.h" @@ -167,11 +167,11 @@ softpipe_delete_vs_state(struct pipe_context *pipe, void *vs) void softpipe_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index, - struct pipe_buffer *constants) + struct pipe_resource *constants) { struct softpipe_context *softpipe = softpipe_context(pipe); - unsigned size = constants ? constants->size : 0; - const void *data = constants ? softpipe_buffer(constants)->data : NULL; + unsigned size = constants ? constants->width0 : 0; + const void *data = constants ? softpipe_resource(constants)->data : NULL; assert(shader < PIPE_SHADER_TYPES); assert(index == 0); @@ -179,7 +179,7 @@ softpipe_set_constant_buffer(struct pipe_context *pipe, draw_flush(softpipe->draw); /* note: reference counting */ - pipe_buffer_reference(&softpipe->constants[shader][index], constants); + pipe_resource_reference(&softpipe->constants[shader][index], constants); if(shader == PIPE_SHADER_VERTEX) { draw_set_mapped_constant_buffer(softpipe->draw, PIPE_SHADER_VERTEX, index, diff --git a/src/gallium/drivers/softpipe/sp_state_sampler.c b/src/gallium/drivers/softpipe/sp_state_sampler.c index d501952bba..3dad118e8a 100644 --- a/src/gallium/drivers/softpipe/sp_state_sampler.c +++ b/src/gallium/drivers/softpipe/sp_state_sampler.c @@ -123,7 +123,7 @@ softpipe_bind_vertex_sampler_states(struct pipe_context *pipe, struct pipe_sampler_view * softpipe_create_sampler_view(struct pipe_context *pipe, - struct pipe_texture *texture, + struct pipe_resource *resource, const struct pipe_sampler_view *templ) { struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); @@ -132,7 +132,7 @@ softpipe_create_sampler_view(struct pipe_context *pipe, *view = *templ; view->reference.count = 1; view->texture = NULL; - pipe_texture_reference(&view->texture, texture); + pipe_resource_reference(&view->texture, resource); view->context = pipe; } @@ -144,7 +144,7 @@ void softpipe_sampler_view_destroy(struct pipe_context *pipe, struct pipe_sampler_view *view) { - pipe_texture_reference(&view->texture, NULL); + pipe_resource_reference(&view->texture, NULL); FREE(view); } @@ -223,10 +223,10 @@ softpipe_set_vertex_sampler_views(struct pipe_context *pipe, static struct sp_sampler_varient * get_sampler_varient( unsigned unit, struct sp_sampler *sampler, - struct pipe_texture *texture, + struct pipe_resource *resource, unsigned processor ) { - struct softpipe_texture *sp_texture = softpipe_texture(texture); + struct softpipe_resource *sp_texture = softpipe_resource(resource); struct sp_sampler_varient *v = NULL; union sp_sampler_key key; @@ -274,7 +274,7 @@ softpipe_reset_sampler_varients(struct softpipe_context *softpipe) */ for (i = 0; i <= softpipe->vs->max_sampler; i++) { if (softpipe->vertex_samplers[i]) { - struct pipe_texture *texture = NULL; + struct pipe_resource *texture = NULL; if (softpipe->vertex_sampler_views[i]) { texture = softpipe->vertex_sampler_views[i]->texture; @@ -294,7 +294,7 @@ softpipe_reset_sampler_varients(struct softpipe_context *softpipe) for (i = 0; i <= softpipe->fs->info.file_max[TGSI_FILE_SAMPLER]; i++) { if (softpipe->sampler[i]) { - struct pipe_texture *texture = NULL; + struct pipe_resource *texture = NULL; if (softpipe->sampler_views[i]) { texture = softpipe->sampler_views[i]->texture; diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.c b/src/gallium/drivers/softpipe/sp_tex_sample.c index fa9e19b282..ff83c66d8b 100644 --- a/src/gallium/drivers/softpipe/sp_tex_sample.c +++ b/src/gallium/drivers/softpipe/sp_tex_sample.c @@ -547,7 +547,7 @@ compute_lambda_1d(const struct sp_sampler_varient *samp, const float t[QUAD_SIZE], const float p[QUAD_SIZE]) { - const struct pipe_texture *texture = samp->texture; + const struct pipe_resource *texture = samp->texture; float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); float rho = MAX2(dsdx, dsdy) * texture->width0; @@ -562,7 +562,7 @@ compute_lambda_2d(const struct sp_sampler_varient *samp, const float t[QUAD_SIZE], const float p[QUAD_SIZE]) { - const struct pipe_texture *texture = samp->texture; + const struct pipe_resource *texture = samp->texture; float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); @@ -581,7 +581,7 @@ compute_lambda_3d(const struct sp_sampler_varient *samp, const float t[QUAD_SIZE], const float p[QUAD_SIZE]) { - const struct pipe_texture *texture = samp->texture; + const struct pipe_resource *texture = samp->texture; float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); @@ -651,7 +651,7 @@ static INLINE const float * get_texel_2d(const struct sp_sampler_varient *samp, union tex_tile_address addr, int x, int y) { - const struct pipe_texture *texture = samp->texture; + const struct pipe_resource *texture = samp->texture; unsigned level = addr.bits.level; if (x < 0 || x >= (int) u_minify(texture->width0, level) || @@ -744,7 +744,7 @@ static INLINE const float * get_texel_3d(const struct sp_sampler_varient *samp, union tex_tile_address addr, int x, int y, int z) { - const struct pipe_texture *texture = samp->texture; + const struct pipe_resource *texture = samp->texture; unsigned level = addr.bits.level; if (x < 0 || x >= (int) u_minify(texture->width0, level) || @@ -932,7 +932,7 @@ img_filter_1d_nearest(struct tgsi_sampler *tgsi_sampler, float rgba[NUM_CHANNELS][QUAD_SIZE]) { const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); - const struct pipe_texture *texture = samp->texture; + const struct pipe_resource *texture = samp->texture; unsigned level0, j; int width; int x[4]; @@ -968,7 +968,7 @@ img_filter_2d_nearest(struct tgsi_sampler *tgsi_sampler, float rgba[NUM_CHANNELS][QUAD_SIZE]) { const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); - const struct pipe_texture *texture = samp->texture; + const struct pipe_resource *texture = samp->texture; unsigned level0, j; int width, height; int x[4], y[4]; @@ -1016,7 +1016,7 @@ img_filter_cube_nearest(struct tgsi_sampler *tgsi_sampler, float rgba[NUM_CHANNELS][QUAD_SIZE]) { const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); - const struct pipe_texture *texture = samp->texture; + const struct pipe_resource *texture = samp->texture; const unsigned *faces = samp->faces; /* zero when not cube-mapping */ unsigned level0, j; int width, height; @@ -1056,7 +1056,7 @@ img_filter_3d_nearest(struct tgsi_sampler *tgsi_sampler, float rgba[NUM_CHANNELS][QUAD_SIZE]) { const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); - const struct pipe_texture *texture = samp->texture; + const struct pipe_resource *texture = samp->texture; unsigned level0, j; int width, height, depth; int x[4], y[4], z[4]; @@ -1098,7 +1098,7 @@ img_filter_1d_linear(struct tgsi_sampler *tgsi_sampler, float rgba[NUM_CHANNELS][QUAD_SIZE]) { const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); - const struct pipe_texture *texture = samp->texture; + const struct pipe_resource *texture = samp->texture; unsigned level0, j; int width; int x0[4], x1[4]; @@ -1138,7 +1138,7 @@ img_filter_2d_linear(struct tgsi_sampler *tgsi_sampler, float rgba[NUM_CHANNELS][QUAD_SIZE]) { const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); - const struct pipe_texture *texture = samp->texture; + const struct pipe_resource *texture = samp->texture; unsigned level0, j; int width, height; int x0[4], y0[4], x1[4], y1[4]; @@ -1185,7 +1185,7 @@ img_filter_cube_linear(struct tgsi_sampler *tgsi_sampler, float rgba[NUM_CHANNELS][QUAD_SIZE]) { const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); - const struct pipe_texture *texture = samp->texture; + const struct pipe_resource *texture = samp->texture; const unsigned *faces = samp->faces; /* zero when not cube-mapping */ unsigned level0, j; int width, height; @@ -1234,7 +1234,7 @@ img_filter_3d_linear(struct tgsi_sampler *tgsi_sampler, float rgba[NUM_CHANNELS][QUAD_SIZE]) { const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); - const struct pipe_texture *texture = samp->texture; + const struct pipe_resource *texture = samp->texture; unsigned level0, j; int width, height, depth; int x0[4], x1[4], y0[4], y1[4], z0[4], z1[4]; @@ -1310,7 +1310,7 @@ mip_filter_linear(struct tgsi_sampler *tgsi_sampler, float rgba[NUM_CHANNELS][QUAD_SIZE]) { struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); - const struct pipe_texture *texture = samp->texture; + const struct pipe_resource *texture = samp->texture; int level0; float lambda; float lod[QUAD_SIZE]; @@ -1373,7 +1373,7 @@ mip_filter_nearest(struct tgsi_sampler *tgsi_sampler, float rgba[NUM_CHANNELS][QUAD_SIZE]) { struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); - const struct pipe_texture *texture = samp->texture; + const struct pipe_resource *texture = samp->texture; float lambda; float lod[QUAD_SIZE]; @@ -1461,7 +1461,7 @@ mip_filter_linear_2d_linear_repeat_POT( float rgba[NUM_CHANNELS][QUAD_SIZE]) { struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); - const struct pipe_texture *texture = samp->texture; + const struct pipe_resource *texture = samp->texture; int level0; float lambda; float lod[QUAD_SIZE]; @@ -1867,7 +1867,7 @@ get_img_filter(const union sp_sampler_key key, void sp_sampler_varient_bind_texture( struct sp_sampler_varient *samp, struct softpipe_tex_tile_cache *tex_cache, - const struct pipe_texture *texture ) + const struct pipe_resource *texture ) { const struct pipe_sampler_state *sampler = samp->sampler; diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.h b/src/gallium/drivers/softpipe/sp_tex_sample.h index b6e66c998a..6114acf737 100644 --- a/src/gallium/drivers/softpipe/sp_tex_sample.h +++ b/src/gallium/drivers/softpipe/sp_tex_sample.h @@ -85,7 +85,7 @@ struct sp_sampler_varient /* Currently bound texture: */ - const struct pipe_texture *texture; + const struct pipe_resource *texture; struct softpipe_tex_tile_cache *cache; unsigned processor; @@ -129,7 +129,7 @@ sp_create_sampler_varient( const struct pipe_sampler_state *sampler, void sp_sampler_varient_bind_texture( struct sp_sampler_varient *varient, struct softpipe_tex_tile_cache *tex_cache, - const struct pipe_texture *tex ); + const struct pipe_resource *tex ); void sp_sampler_varient_destroy( struct sp_sampler_varient * ); diff --git a/src/gallium/drivers/softpipe/sp_tex_tile_cache.c b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c index 6594514c38..c79f5fb05a 100644 --- a/src/gallium/drivers/softpipe/sp_tex_tile_cache.c +++ b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c @@ -69,10 +69,10 @@ sp_destroy_tex_tile_cache(struct softpipe_tex_tile_cache *tc) /*assert(tc->entries[pos].x < 0);*/ } if (tc->transfer) { - tc->pipe->tex_transfer_destroy(tc->pipe, tc->transfer); + tc->pipe->transfer_destroy(tc->pipe, tc->transfer); } if (tc->tex_trans) { - tc->pipe->tex_transfer_destroy(tc->pipe, tc->tex_trans); + tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans); } FREE( tc ); @@ -122,13 +122,13 @@ void sp_tex_tile_cache_set_sampler_view(struct softpipe_tex_tile_cache *tc, struct pipe_sampler_view *view) { - struct pipe_texture *texture = view ? view->texture : NULL; + struct pipe_resource *texture = view ? view->texture : NULL; uint i; assert(!tc->transfer); if (tc->texture != texture) { - pipe_texture_reference(&tc->texture, texture); + pipe_resource_reference(&tc->texture, texture); if (tc->tex_trans) { if (tc->tex_trans_map) { @@ -136,7 +136,7 @@ sp_tex_tile_cache_set_sampler_view(struct softpipe_tex_tile_cache *tc, tc->tex_trans_map = NULL; } - tc->pipe->tex_transfer_destroy(tc->pipe, tc->tex_trans); + tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans); tc->tex_trans = NULL; } @@ -239,18 +239,18 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc, tc->tex_trans_map = NULL; } - tc->pipe->tex_transfer_destroy(tc->pipe, tc->tex_trans); + tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans); tc->tex_trans = NULL; } tc->tex_trans = - tc->pipe->get_tex_transfer(tc->pipe, tc->texture, - addr.bits.face, - addr.bits.level, - addr.bits.z, - PIPE_TRANSFER_READ, 0, 0, - u_minify(tc->texture->width0, addr.bits.level), - u_minify(tc->texture->height0, addr.bits.level)); + pipe_get_transfer(tc->pipe, tc->texture, + addr.bits.face, + addr.bits.level, + addr.bits.z, + PIPE_TRANSFER_READ, 0, 0, + u_minify(tc->texture->width0, addr.bits.level), + u_minify(tc->texture->height0, addr.bits.level)); tc->tex_trans_map = tc->pipe->transfer_map(tc->pipe, tc->tex_trans); diff --git a/src/gallium/drivers/softpipe/sp_tex_tile_cache.h b/src/gallium/drivers/softpipe/sp_tex_tile_cache.h index 12ae7ba12d..0794ffa0c5 100644 --- a/src/gallium/drivers/softpipe/sp_tex_tile_cache.h +++ b/src/gallium/drivers/softpipe/sp_tex_tile_cache.h @@ -74,7 +74,7 @@ struct softpipe_tex_tile_cache struct pipe_transfer *transfer; void *transfer_map; - struct pipe_texture *texture; /**< if caching a texture */ + struct pipe_resource *texture; /**< if caching a texture */ unsigned timestamp; struct softpipe_tex_cached_tile entries[NUM_ENTRIES]; diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c index f4983b7c8e..9d121e53d3 100644 --- a/src/gallium/drivers/softpipe/sp_texture.c +++ b/src/gallium/drivers/softpipe/sp_texture.c @@ -36,6 +36,7 @@ #include "util/u_format.h" #include "util/u_math.h" #include "util/u_memory.h" +#include "util/u_transfer.h" #include "sp_context.h" #include "sp_texture.h" @@ -49,10 +50,10 @@ * Use a simple, maximally packed layout. */ static boolean -softpipe_texture_layout(struct pipe_screen *screen, - struct softpipe_texture * spt) +softpipe_resource_layout(struct pipe_screen *screen, + struct softpipe_resource * spt) { - struct pipe_texture *pt = &spt->base; + struct pipe_resource *pt = &spt->base; unsigned level; unsigned width = pt->width0; unsigned height = pt->height0; @@ -84,7 +85,7 @@ softpipe_texture_layout(struct pipe_screen *screen, */ static boolean softpipe_displaytarget_layout(struct pipe_screen *screen, - struct softpipe_texture * spt) + struct softpipe_resource * spt) { struct sw_winsys *winsys = softpipe_screen(screen)->winsys; @@ -103,16 +104,18 @@ softpipe_displaytarget_layout(struct pipe_screen *screen, /** - * Create new pipe_texture given the template information. + * Create new pipe_resource given the template information. */ -static struct pipe_texture * -softpipe_texture_create(struct pipe_screen *screen, - const struct pipe_texture *template) +static struct pipe_resource * +softpipe_resource_create(struct pipe_screen *screen, + const struct pipe_resource *template) { - struct softpipe_texture *spt = CALLOC_STRUCT(softpipe_texture); + struct softpipe_resource *spt = CALLOC_STRUCT(softpipe_resource); if (!spt) return NULL; + assert(template->format != PIPE_FORMAT_NONE); + spt->base = *template; pipe_reference_init(&spt->base.reference, 1); spt->base.screen = screen; @@ -128,7 +131,7 @@ softpipe_texture_create(struct pipe_screen *screen, goto fail; } else { - if (!softpipe_texture_layout(screen, spt)) + if (!softpipe_resource_layout(screen, spt)) goto fail; } @@ -141,17 +144,18 @@ softpipe_texture_create(struct pipe_screen *screen, static void -softpipe_texture_destroy(struct pipe_texture *pt) +softpipe_resource_destroy(struct pipe_screen *pscreen, + struct pipe_resource *pt) { - struct softpipe_screen *screen = softpipe_screen(pt->screen); - struct softpipe_texture *spt = softpipe_texture(pt); + struct softpipe_screen *screen = softpipe_screen(pscreen); + struct softpipe_resource *spt = softpipe_resource(pt); if (spt->dt) { /* display target */ struct sw_winsys *winsys = screen->winsys; winsys->displaytarget_destroy(winsys, spt->dt); } - else { + else if (!spt->userBuffer) { /* regular texture */ align_free(spt->data); } @@ -160,13 +164,13 @@ softpipe_texture_destroy(struct pipe_texture *pt) } -static struct pipe_texture * -softpipe_texture_from_handle(struct pipe_screen *screen, - const struct pipe_texture *template, +static struct pipe_resource * +softpipe_resource_from_handle(struct pipe_screen *screen, + const struct pipe_resource *template, struct winsys_handle *whandle) { struct sw_winsys *winsys = softpipe_screen(screen)->winsys; - struct softpipe_texture *spt = CALLOC_STRUCT(softpipe_texture); + struct softpipe_resource *spt = CALLOC_STRUCT(softpipe_resource); if (!spt) return NULL; @@ -194,12 +198,12 @@ softpipe_texture_from_handle(struct pipe_screen *screen, static boolean -softpipe_texture_get_handle(struct pipe_screen *screen, - struct pipe_texture *pt, +softpipe_resource_get_handle(struct pipe_screen *screen, + struct pipe_resource *pt, struct winsys_handle *whandle) { struct sw_winsys *winsys = softpipe_screen(screen)->winsys; - struct softpipe_texture *spt = softpipe_texture(pt); + struct softpipe_resource *spt = softpipe_resource(pt); assert(spt->dt); if (!spt->dt) @@ -214,11 +218,11 @@ softpipe_texture_get_handle(struct pipe_screen *screen, */ static struct pipe_surface * softpipe_get_tex_surface(struct pipe_screen *screen, - struct pipe_texture *pt, + struct pipe_resource *pt, unsigned face, unsigned level, unsigned zslice, unsigned usage) { - struct softpipe_texture *spt = softpipe_texture(pt); + struct softpipe_resource *spt = softpipe_resource(pt); struct pipe_surface *ps; assert(level <= pt->last_level); @@ -226,7 +230,7 @@ softpipe_get_tex_surface(struct pipe_screen *screen, ps = CALLOC_STRUCT(pipe_surface); if (ps) { pipe_reference_init(&ps->reference, 1); - pipe_texture_reference(&ps->texture, pt); + pipe_resource_reference(&ps->texture, pt); ps->format = pt->format; ps->width = u_minify(pt->width0, level); ps->height = u_minify(pt->height0, level); @@ -285,7 +289,7 @@ softpipe_tex_surface_destroy(struct pipe_surface *surf) * where it would happen. For softpipe, nothing to do. */ assert(surf->texture); - pipe_texture_reference(&surf->texture, NULL); + pipe_resource_reference(&surf->texture, NULL); FREE(surf); } @@ -303,49 +307,53 @@ softpipe_tex_surface_destroy(struct pipe_surface *surf) * \param height height of region to read/write */ static struct pipe_transfer * -softpipe_get_tex_transfer(struct pipe_context *pipe, - struct pipe_texture *texture, - unsigned face, unsigned level, unsigned zslice, - enum pipe_transfer_usage usage, - unsigned x, unsigned y, unsigned w, unsigned h) +softpipe_get_transfer(struct pipe_context *pipe, + struct pipe_resource *resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box) { - struct softpipe_texture *sptex = softpipe_texture(texture); + struct softpipe_resource *sptex = softpipe_resource(resource); struct softpipe_transfer *spt; - assert(texture); - assert(level <= texture->last_level); + assert(resource); + assert(sr.level <= resource->last_level); /* make sure the requested region is in the image bounds */ - assert(x + w <= u_minify(texture->width0, level)); - assert(y + h <= u_minify(texture->height0, level)); + assert(box->x + box->width <= u_minify(resource->width0, sr.level)); + assert(box->y + box->height <= u_minify(resource->height0, sr.level)); + assert(box->z + box->depth <= u_minify(resource->depth0, sr.level)); spt = CALLOC_STRUCT(softpipe_transfer); if (spt) { struct pipe_transfer *pt = &spt->base; - int nblocksy = util_format_get_nblocksy(texture->format, u_minify(texture->height0, level)); - pipe_texture_reference(&pt->texture, texture); - pt->x = x; - pt->y = y; - pt->width = w; - pt->height = h; - pt->stride = sptex->stride[level]; + enum pipe_format format = resource->format; + int nblocksy = util_format_get_nblocksy(resource->format, + u_minify(resource->height0, sr.level)); + pipe_resource_reference(&pt->resource, resource); + pt->box = *box; + pt->stride = sptex->stride[sr.level]; pt->usage = usage; - pt->face = face; - pt->level = level; - pt->zslice = zslice; + //pt->face = face; + //pt->level = level; - spt->offset = sptex->level_offset[level]; + spt->offset = sptex->level_offset[sr.level]; - if (texture->target == PIPE_TEXTURE_CUBE) { - spt->offset += face * nblocksy * pt->stride; + if (resource->target == PIPE_TEXTURE_CUBE) { + spt->offset += sr.face * nblocksy * pt->stride; } - else if (texture->target == PIPE_TEXTURE_3D) { - spt->offset += zslice * nblocksy * pt->stride; + else if (resource->target == PIPE_TEXTURE_3D) { + spt->offset += box->z * nblocksy * pt->stride; } else { - assert(face == 0); - assert(zslice == 0); + assert(sr.face == 0); + assert(box->z == 0); } + + spt->offset += + box->y / util_format_get_blockheight(format) * spt->base.stride + + box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); + return pt; } return NULL; @@ -354,18 +362,13 @@ softpipe_get_tex_transfer(struct pipe_context *pipe, /** * Free a pipe_transfer object which was created with - * softpipe_get_tex_transfer(). + * softpipe_get_transfer(). */ static void -softpipe_tex_transfer_destroy(struct pipe_context *pipe, +softpipe_transfer_destroy(struct pipe_context *pipe, struct pipe_transfer *transfer) { - /* Effectively do the texture_update work here - if texture images - * needed post-processing to put them into hardware layout, this is - * where it would happen. For softpipe, nothing to do. - */ - assert (transfer->texture); - pipe_texture_reference(&transfer->texture, NULL); + pipe_resource_reference(&transfer->resource, NULL); FREE(transfer); } @@ -377,44 +380,26 @@ static void * softpipe_transfer_map( struct pipe_context *pipe, struct pipe_transfer *transfer ) { - ubyte *map, *xfer_map; - struct softpipe_texture *spt; - enum pipe_format format; - - assert(transfer->texture); - spt = softpipe_texture(transfer->texture); - format = transfer->texture->format; - - if (spt->dt) { - /* display target */ - struct sw_winsys *winsys = softpipe_screen(pipe->screen)->winsys; - - map = winsys->displaytarget_map(winsys, spt->dt, - pipe_transfer_buffer_flags(transfer)); - if (map == NULL) - return NULL; + struct softpipe_transfer *sp_transfer = softpipe_transfer(transfer); + struct softpipe_resource *sp_resource = softpipe_resource(transfer->resource); + struct sw_winsys *winsys = softpipe_screen(pipe->screen)->winsys; + uint8_t *map; + + /* resources backed by display target treated specially: + */ + if (sp_resource->dt) { + map = winsys->displaytarget_map(winsys, + sp_resource->dt, + transfer->usage); } else { - map = spt->data; - if (map == NULL) - return NULL; + map = sp_resource->data; } - /* May want to different things here depending on read/write nature - * of the map: - */ - if (transfer->texture && (transfer->usage & PIPE_TRANSFER_WRITE)) { - /* Do something to notify sharing contexts of a texture change. - * In softpipe, that would mean flushing the texture cache. - */ - softpipe_screen(pipe->screen)->timestamp++; - } - - xfer_map = map + softpipe_transfer(transfer)->offset + - transfer->y / util_format_get_blockheight(format) * transfer->stride + - transfer->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); - /*printf("map = %p xfer map = %p\n", map, xfer_map);*/ - return xfer_map; + if (map == NULL) + return NULL; + else + return map + sp_transfer->offset; } @@ -425,10 +410,10 @@ static void softpipe_transfer_unmap(struct pipe_context *pipe, struct pipe_transfer *transfer) { - struct softpipe_texture *spt; + struct softpipe_resource *spt; - assert(transfer->texture); - spt = softpipe_texture(transfer->texture); + assert(transfer->resource); + spt = softpipe_resource(transfer->resource); if (spt->dt) { /* display target */ @@ -442,81 +427,61 @@ softpipe_transfer_unmap(struct pipe_context *pipe, } } - -static struct pipe_video_surface* -softpipe_video_surface_create(struct pipe_screen *screen, - enum pipe_video_chroma_format chroma_format, - unsigned width, unsigned height) +/** + * Create buffer which wraps user-space data. + */ +static struct pipe_resource * +softpipe_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned usage) { - struct softpipe_video_surface *sp_vsfc; - struct pipe_texture template; - - assert(screen); - assert(width && height); + struct softpipe_resource *buffer; - sp_vsfc = CALLOC_STRUCT(softpipe_video_surface); - if (!sp_vsfc) + buffer = CALLOC_STRUCT(softpipe_resource); + if(!buffer) return NULL; - pipe_reference_init(&sp_vsfc->base.reference, 1); - sp_vsfc->base.screen = screen; - sp_vsfc->base.chroma_format = chroma_format; - /*sp_vsfc->base.surface_format = PIPE_VIDEO_SURFACE_FORMAT_VUYA;*/ - sp_vsfc->base.width = width; - sp_vsfc->base.height = height; - - memset(&template, 0, sizeof(struct pipe_texture)); - template.target = PIPE_TEXTURE_2D; - template.format = PIPE_FORMAT_B8G8R8X8_UNORM; - template.last_level = 0; - /* vl_mpeg12_mc_renderer expects this when it's initialized with pot_buffers=true */ - template.width0 = util_next_power_of_two(width); - template.height0 = util_next_power_of_two(height); - template.depth0 = 1; - template.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER | PIPE_TEXTURE_USAGE_RENDER_TARGET; - - sp_vsfc->tex = screen->texture_create(screen, &template); - if (!sp_vsfc->tex) { - FREE(sp_vsfc); - return NULL; - } - - return &sp_vsfc->base; + pipe_reference_init(&buffer->base.reference, 1); + buffer->base.screen = screen; + buffer->base.format = PIPE_FORMAT_R8_UNORM; /* ?? */ + buffer->base.usage = PIPE_BUFFER_USAGE_CPU_READ | usage; + buffer->base.width0 = bytes; + buffer->base.height0 = 1; + buffer->base.depth0 = 1; + buffer->userBuffer = TRUE; + buffer->data = ptr; + + return &buffer->base; } -static void -softpipe_video_surface_destroy(struct pipe_video_surface *vsfc) -{ - struct softpipe_video_surface *sp_vsfc = softpipe_video_surface(vsfc); - pipe_texture_reference(&sp_vsfc->tex, NULL); - FREE(sp_vsfc); -} void softpipe_init_texture_funcs(struct pipe_context *pipe) { - pipe->get_tex_transfer = softpipe_get_tex_transfer; - pipe->tex_transfer_destroy = softpipe_tex_transfer_destroy; + pipe->get_transfer = softpipe_get_transfer; + pipe->transfer_destroy = softpipe_transfer_destroy; pipe->transfer_map = softpipe_transfer_map; pipe->transfer_unmap = softpipe_transfer_unmap; + + pipe->transfer_flush_region = u_default_transfer_flush_region; + pipe->transfer_inline_write = u_default_transfer_inline_write; } void softpipe_init_screen_texture_funcs(struct pipe_screen *screen) { - screen->texture_create = softpipe_texture_create; - screen->texture_destroy = softpipe_texture_destroy; - screen->texture_from_handle = softpipe_texture_from_handle; - screen->texture_get_handle = softpipe_texture_get_handle; + screen->resource_create = softpipe_resource_create; + screen->resource_destroy = softpipe_resource_destroy; + screen->resource_from_handle = softpipe_resource_from_handle; + screen->resource_get_handle = softpipe_resource_get_handle; + screen->user_buffer_create = softpipe_user_buffer_create; screen->get_tex_surface = softpipe_get_tex_surface; screen->tex_surface_destroy = softpipe_tex_surface_destroy; - - screen->video_surface_create = softpipe_video_surface_create; - screen->video_surface_destroy = softpipe_video_surface_destroy; } diff --git a/src/gallium/drivers/softpipe/sp_texture.h b/src/gallium/drivers/softpipe/sp_texture.h index c0e6ba8a86..2477fbfbc5 100644 --- a/src/gallium/drivers/softpipe/sp_texture.h +++ b/src/gallium/drivers/softpipe/sp_texture.h @@ -42,27 +42,28 @@ struct pipe_screen; struct softpipe_context; -struct softpipe_texture +struct softpipe_resource { - struct pipe_texture base; + struct pipe_resource base; unsigned long level_offset[SP_MAX_TEXTURE_2D_LEVELS]; unsigned stride[SP_MAX_TEXTURE_2D_LEVELS]; /** - * Display target, for textures with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET - * usage. + * Display target, only valid for PIPE_TEXTURE_2D with the + * PIPE_TEXTURE_USAGE_DISPLAY_TARGET usage. */ struct sw_displaytarget *dt; /** - * Malloc'ed data for regular textures, or a mapping to dt above. + * Malloc'ed data for regular buffers and textures, or a mapping to dt above. */ void *data; /* True if texture images are power-of-two in all dimensions: */ boolean pot; + boolean userBuffer; unsigned timestamp; }; @@ -80,15 +81,15 @@ struct softpipe_video_surface /* The data is held here: */ - struct pipe_texture *tex; + struct pipe_resource *tex; }; /** cast wrappers */ -static INLINE struct softpipe_texture * -softpipe_texture(struct pipe_texture *pt) +static INLINE struct softpipe_resource * +softpipe_resource(struct pipe_resource *pt) { - return (struct softpipe_texture *) pt; + return (struct softpipe_resource *) pt; } static INLINE struct softpipe_transfer * diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.c b/src/gallium/drivers/softpipe/sp_tile_cache.c index 1c3c2667d7..dde9f0e1b9 100644 --- a/src/gallium/drivers/softpipe/sp_tile_cache.c +++ b/src/gallium/drivers/softpipe/sp_tile_cache.c @@ -121,7 +121,7 @@ sp_destroy_tile_cache(struct softpipe_tile_cache *tc) /*assert(tc->entries[pos].x < 0);*/ } if (tc->transfer) { - tc->pipe->tex_transfer_destroy(tc->pipe, tc->transfer); + tc->pipe->transfer_destroy(tc->pipe, tc->transfer); } FREE( tc ); @@ -146,17 +146,17 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, tc->transfer_map = NULL; } - pipe->tex_transfer_destroy(pipe, tc->transfer); + pipe->transfer_destroy(pipe, tc->transfer); tc->transfer = NULL; } tc->surface = ps; if (ps) { - tc->transfer = pipe->get_tex_transfer(pipe, ps->texture, ps->face, - ps->level, ps->zslice, - PIPE_TRANSFER_READ_WRITE, - 0, 0, ps->width, ps->height); + tc->transfer = pipe_get_transfer(pipe, ps->texture, ps->face, + ps->level, ps->zslice, + PIPE_TRANSFER_READ_WRITE, + 0, 0, ps->width, ps->height); tc->depth_stencil = (ps->format == PIPE_FORMAT_Z24S8_UNORM || ps->format == PIPE_FORMAT_Z24X8_UNORM || @@ -276,14 +276,14 @@ static void sp_tile_cache_flush_clear(struct softpipe_tile_cache *tc) { struct pipe_transfer *pt = tc->transfer; - const uint w = tc->transfer->width; - const uint h = tc->transfer->height; + const uint w = tc->transfer->box.width; + const uint h = tc->transfer->box.height; uint x, y; uint numCleared = 0; - assert(pt->texture); + assert(pt->resource); /* clear the scratch tile to the clear value */ - clear_tile(&tc->tile, pt->texture->format, tc->clear_val); + clear_tile(&tc->tile, pt->resource->format, tc->clear_val); /* push the tile to all positions marked as clear */ for (y = 0; y < h; y += TILE_SIZE) { @@ -372,7 +372,7 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc, if (addr.value != tile->addr.value) { - assert(pt->texture); + assert(pt->resource); if (tile->addr.bits.invalid == 0) { /* put dirty tile back in framebuffer */ if (tc->depth_stencil) { @@ -396,10 +396,10 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc, if (is_clear_flag_set(tc->clear_flags, addr)) { /* don't get tile from framebuffer, just clear it */ if (tc->depth_stencil) { - clear_tile(tile, pt->texture->format, tc->clear_val); + clear_tile(tile, pt->resource->format, tc->clear_val); } else { - clear_tile_rgba(tile, pt->texture->format, tc->clear_color); + clear_tile_rgba(tile, pt->resource->format, tc->clear_color); } clear_clear_flag(tc->clear_flags, addr); } diff --git a/src/gallium/drivers/svga/Makefile b/src/gallium/drivers/svga/Makefile index f361908187..27287793bd 100644 --- a/src/gallium/drivers/svga/Makefile +++ b/src/gallium/drivers/svga/Makefile @@ -27,8 +27,6 @@ C_SOURCES = \ svga_pipe_vertex.c \ svga_pipe_vs.c \ svga_screen.c \ - svga_screen_buffer.c \ - svga_screen_texture.c \ svga_screen_cache.c \ svga_state.c \ svga_state_need_swtnl.c \ @@ -45,7 +43,14 @@ C_SOURCES = \ svga_tgsi.c \ svga_tgsi_decl_sm20.c \ svga_tgsi_decl_sm30.c \ - svga_tgsi_insn.c + svga_tgsi_insn.c \ + svga_sampler_view.c \ + svga_surface.c \ + svga_resource.c \ + svga_resource_texture.c \ + svga_resource_buffer.c \ + svga_resource_buffer_upload.c + LIBRARY_INCLUDES = \ -I$(TOP)/src/gallium/drivers/svga/include diff --git a/src/gallium/drivers/svga/svga_cmd.c b/src/gallium/drivers/svga/svga_cmd.c index 04307d17fe..d58082cae3 100644 --- a/src/gallium/drivers/svga/svga_cmd.c +++ b/src/gallium/drivers/svga/svga_cmd.c @@ -31,8 +31,9 @@ */ #include "svga_winsys.h" -#include "svga_screen_buffer.h" -#include "svga_screen_texture.h" +#include "svga_resource_buffer.h" +#include "svga_resource_texture.h" +#include "svga_surface.h" #include "svga_cmd.h" /* @@ -423,7 +424,7 @@ SVGA3D_SurfaceDMA(struct svga_winsys_context *swc, const SVGA3dCopyBox *boxes, // IN uint32 numBoxes) // IN { - struct svga_texture *texture = svga_texture(st->base.texture); + struct svga_texture *texture = svga_texture(st->base.resource); SVGA3dCmdSurfaceDMA *cmd; SVGA3dCmdSurfaceDMASuffix *pSuffix; uint32 boxesSize = sizeof *boxes * numBoxes; @@ -454,8 +455,8 @@ SVGA3D_SurfaceDMA(struct svga_winsys_context *swc, cmd->guest.pitch = st->base.stride; swc->surface_relocation(swc, &cmd->host.sid, texture->handle, surface_flags); - cmd->host.face = st->base.face; /* PIPE_TEX_FACE_* and SVGA3D_CUBEFACE_* match */ - cmd->host.mipmap = st->base.level; + cmd->host.face = st->base.sr.face; /* PIPE_TEX_FACE_* and SVGA3D_CUBEFACE_* match */ + cmd->host.mipmap = st->base.sr.level; cmd->transfer = transfer; diff --git a/src/gallium/drivers/svga/svga_cmd.h b/src/gallium/drivers/svga/svga_cmd.h index da9fc4355f..0e568d78e6 100644 --- a/src/gallium/drivers/svga/svga_cmd.h +++ b/src/gallium/drivers/svga/svga_cmd.h @@ -41,7 +41,6 @@ #include "pipe/p_defines.h" -struct pipe_buffer; struct pipe_surface; struct svga_transfer; struct svga_winsys_context; diff --git a/src/gallium/drivers/svga/svga_context.c b/src/gallium/drivers/svga/svga_context.c index adb7840182..a6ffda0db6 100644 --- a/src/gallium/drivers/svga/svga_context.c +++ b/src/gallium/drivers/svga/svga_context.c @@ -34,8 +34,9 @@ #include "svga_context.h" #include "svga_screen.h" -#include "svga_screen_texture.h" -#include "svga_screen_buffer.h" +#include "svga_resource_texture.h" +#include "svga_resource_buffer.h" +#include "svga_resource.h" #include "svga_winsys.h" #include "svga_swtnl.h" #include "svga_draw.h" @@ -66,64 +67,11 @@ static void svga_destroy( struct pipe_context *pipe ) util_bitmask_destroy( svga->fs_bm ); for(shader = 0; shader < PIPE_SHADER_TYPES; ++shader) - pipe_buffer_reference( &svga->curr.cb[shader], NULL ); + pipe_resource_reference( &svga->curr.cb[shader], NULL ); FREE( svga ); } -static unsigned int -svga_is_texture_referenced( struct pipe_context *pipe, - struct pipe_texture *texture, - unsigned face, unsigned level) -{ - struct svga_texture *tex = svga_texture(texture); - struct svga_screen *ss = svga_screen(pipe->screen); - - /** - * The screen does not cache texture writes. - */ - - if (!tex->handle || ss->sws->surface_is_flushed(ss->sws, tex->handle)) - return PIPE_UNREFERENCED; - - /** - * sws->surface_is_flushed() does not distinguish between read references - * and write references. So assume a reference is both. - */ - - return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; -} - -static unsigned int -svga_is_buffer_referenced( struct pipe_context *pipe, - struct pipe_buffer *buf) - -{ - struct svga_screen *ss = svga_screen(pipe->screen); - struct svga_buffer *sbuf = svga_buffer(buf); - - /** - * XXX: Check this. - * The screen may cache buffer writes, but when we map, we map out - * of those cached writes, so we don't need to set a - * PIPE_REFERENCED_FOR_WRITE flag for cached buffers. - */ - - if (!sbuf->handle || ss->sws->surface_is_flushed(ss->sws, sbuf->handle)) - return PIPE_UNREFERENCED; - - /** - * sws->surface_is_flushed() does not distinguish between read references - * and write references. So assume a reference is both, - * however, we make an exception for index- and vertex buffers, to avoid - * a flush in st_bufferobj_get_subdata, during display list replay. - */ - - if (sbuf->base.usage & (PIPE_BUFFER_USAGE_VERTEX | PIPE_BUFFER_USAGE_INDEX)) - return PIPE_REFERENCED_FOR_READ; - - return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; -} struct pipe_context *svga_context_create( struct pipe_screen *screen, @@ -143,13 +91,11 @@ struct pipe_context *svga_context_create( struct pipe_screen *screen, svga->pipe.destroy = svga_destroy; svga->pipe.clear = svga_clear; - svga->pipe.is_texture_referenced = svga_is_texture_referenced; - svga->pipe.is_buffer_referenced = svga_is_buffer_referenced; - svga->swc = svgascreen->sws->context_create(svgascreen->sws); if(!svga->swc) goto no_swc; + svga_init_resource_functions(svga); svga_init_blend_functions(svga); svga_init_blit_functions(svga); svga_init_depth_stencil_functions(svga); @@ -164,7 +110,6 @@ struct pipe_context *svga_context_create( struct pipe_screen *screen, svga_init_constbuffer_functions(svga); svga_init_query_functions(svga); - svga_init_texture_functions(&svga->pipe); /* debug */ svga->debug.no_swtnl = debug_get_bool_option("SVGA_NO_SWTNL", FALSE); @@ -183,14 +128,14 @@ struct pipe_context *svga_context_create( struct pipe_screen *screen, if (svga->vs_bm == NULL) goto no_vs_bm; - svga->upload_ib = u_upload_create( svga->pipe.screen, + svga->upload_ib = u_upload_create( &svga->pipe, 32 * 1024, 16, PIPE_BUFFER_USAGE_INDEX ); if (svga->upload_ib == NULL) goto no_upload_ib; - svga->upload_vb = u_upload_create( svga->pipe.screen, + svga->upload_vb = u_upload_create( &svga->pipe, 128 * 1024, 16, PIPE_BUFFER_USAGE_VERTEX ); diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h index 1f66437dfe..9a46de643f 100644 --- a/src/gallium/drivers/svga/svga_context.h +++ b/src/gallium/drivers/svga/svga_context.h @@ -190,7 +190,7 @@ struct svga_state struct svga_vertex_shader *vs; struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS]; - struct pipe_buffer *cb[PIPE_SHADER_TYPES]; + struct pipe_resource *cb[PIPE_SHADER_TYPES]; struct pipe_framebuffer_state framebuffer; float depthscale; @@ -254,7 +254,7 @@ struct svga_hw_clear_state struct svga_hw_view_state { - struct pipe_texture *texture; + struct pipe_resource *texture; struct svga_sampler_view *v; unsigned min_lod; unsigned max_lod; diff --git a/src/gallium/drivers/svga/svga_draw.c b/src/gallium/drivers/svga/svga_draw.c index 8b7ca2e112..efc84d56bd 100644 --- a/src/gallium/drivers/svga/svga_draw.c +++ b/src/gallium/drivers/svga/svga_draw.c @@ -34,8 +34,9 @@ #include "svga_draw_private.h" #include "svga_debug.h" #include "svga_screen.h" -#include "svga_screen_buffer.h" -#include "svga_screen_texture.h" +#include "svga_resource_buffer.h" +#include "svga_resource_texture.h" +#include "svga_surface.h" #include "svga_winsys.h" #include "svga_cmd.h" @@ -65,16 +66,16 @@ void svga_hwtnl_destroy( struct svga_hwtnl *hwtnl ) for (i = 0; i < PIPE_PRIM_MAX; i++) { for (j = 0; j < IDX_CACHE_MAX; j++) { - pipe_buffer_reference( &hwtnl->index_cache[i][j].buffer, + pipe_resource_reference( &hwtnl->index_cache[i][j].buffer, NULL ); } } for (i = 0; i < hwtnl->cmd.vdecl_count; i++) - pipe_buffer_reference(&hwtnl->cmd.vdecl_vb[i], NULL); + pipe_resource_reference(&hwtnl->cmd.vdecl_vb[i], NULL); for (i = 0; i < hwtnl->cmd.prim_count; i++) - pipe_buffer_reference(&hwtnl->cmd.prim_ib[i], NULL); + pipe_resource_reference(&hwtnl->cmd.prim_ib[i], NULL); FREE(hwtnl); @@ -103,7 +104,7 @@ void svga_hwtnl_reset_vdecl( struct svga_hwtnl *hwtnl, assert(hwtnl->cmd.prim_count == 0); for (i = count; i < hwtnl->cmd.vdecl_count; i++) { - pipe_buffer_reference(&hwtnl->cmd.vdecl_vb[i], + pipe_resource_reference(&hwtnl->cmd.vdecl_vb[i], NULL); } @@ -112,9 +113,9 @@ void svga_hwtnl_reset_vdecl( struct svga_hwtnl *hwtnl, void svga_hwtnl_vdecl( struct svga_hwtnl *hwtnl, - unsigned i, - const SVGA3dVertexDecl *decl, - struct pipe_buffer *vb) + unsigned i, + const SVGA3dVertexDecl *decl, + struct pipe_resource *vb) { assert(hwtnl->cmd.prim_count == 0); @@ -122,8 +123,7 @@ void svga_hwtnl_vdecl( struct svga_hwtnl *hwtnl, hwtnl->cmd.vdecl[i] = *decl; - pipe_buffer_reference(&hwtnl->cmd.vdecl_vb[i], - vb); + pipe_resource_reference(&hwtnl->cmd.vdecl_vb[i], vb); } @@ -210,7 +210,7 @@ svga_hwtnl_flush( struct svga_hwtnl *hwtnl ) &prim[i].indexArray.surfaceId, ib_handle[i], PIPE_BUFFER_USAGE_GPU_READ); - pipe_buffer_reference(&hwtnl->cmd.prim_ib[i], NULL); + pipe_resource_reference(&hwtnl->cmd.prim_ib[i], NULL); } SVGA_FIFOCommitAll( swc ); @@ -232,7 +232,7 @@ enum pipe_error svga_hwtnl_prim( struct svga_hwtnl *hwtnl, const SVGA3dPrimitiveRange *range, unsigned min_index, unsigned max_index, - struct pipe_buffer *ib ) + struct pipe_resource *ib ) { int ret = PIPE_OK; @@ -240,8 +240,8 @@ enum pipe_error svga_hwtnl_prim( struct svga_hwtnl *hwtnl, { unsigned i; for (i = 0; i < hwtnl->cmd.vdecl_count; i++) { - struct pipe_buffer *vb = hwtnl->cmd.vdecl_vb[i]; - unsigned size = vb ? vb->size : 0; + struct pipe_resource *vb = hwtnl->cmd.vdecl_vb[i]; + unsigned size = vb ? vb->width0 : 0; unsigned offset = hwtnl->cmd.vdecl[i].array.offset; unsigned stride = hwtnl->cmd.vdecl[i].array.stride; unsigned index_bias = range->indexBias; @@ -324,7 +324,7 @@ enum pipe_error svga_hwtnl_prim( struct svga_hwtnl *hwtnl, assert(range->indexWidth == range->indexArray.stride); if(ib) { - unsigned size = ib->size; + unsigned size = ib->width0; unsigned offset = range->indexArray.offset; unsigned stride = range->indexArray.stride; unsigned count; @@ -375,7 +375,7 @@ enum pipe_error svga_hwtnl_prim( struct svga_hwtnl *hwtnl, hwtnl->cmd.prim[hwtnl->cmd.prim_count] = *range; - pipe_buffer_reference(&hwtnl->cmd.prim_ib[hwtnl->cmd.prim_count], ib); + pipe_resource_reference(&hwtnl->cmd.prim_ib[hwtnl->cmd.prim_count], ib); hwtnl->cmd.prim_count++; return ret; diff --git a/src/gallium/drivers/svga/svga_draw.h b/src/gallium/drivers/svga/svga_draw.h index 14553b17b5..81c7f8377d 100644 --- a/src/gallium/drivers/svga/svga_draw.h +++ b/src/gallium/drivers/svga/svga_draw.h @@ -34,7 +34,7 @@ struct svga_hwtnl; struct svga_winsys_context; struct svga_screen; struct svga_context; -struct pipe_buffer; +struct pipe_resource; struct u_upload_mgr; struct svga_hwtnl *svga_hwtnl_create( struct svga_context *svga, @@ -53,7 +53,7 @@ void svga_hwtnl_set_unfilled( struct svga_hwtnl *hwtnl, void svga_hwtnl_vdecl( struct svga_hwtnl *hwtnl, unsigned i, const SVGA3dVertexDecl *decl, - struct pipe_buffer *vb); + struct pipe_resource *vb); void svga_hwtnl_reset_vdecl( struct svga_hwtnl *hwtnl, unsigned count ); @@ -67,7 +67,7 @@ svga_hwtnl_draw_arrays( struct svga_hwtnl *hwtnl, enum pipe_error svga_hwtnl_draw_range_elements( struct svga_hwtnl *hwtnl, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned index_size, unsigned min_index, unsigned max_index, diff --git a/src/gallium/drivers/svga/svga_draw_arrays.c b/src/gallium/drivers/svga/svga_draw_arrays.c index 6192aa96b1..dc01a8c30a 100644 --- a/src/gallium/drivers/svga/svga_draw_arrays.c +++ b/src/gallium/drivers/svga/svga_draw_arrays.c @@ -43,40 +43,42 @@ static enum pipe_error generate_indices( struct svga_hwtnl *hwtnl, unsigned nr, unsigned index_size, u_generate_func generate, - struct pipe_buffer **out_buf ) + struct pipe_resource **out_buf ) { - struct pipe_screen *screen = hwtnl->svga->pipe.screen; + struct pipe_context *pipe = &hwtnl->svga->pipe; + struct pipe_transfer *transfer; unsigned size = index_size * nr; - struct pipe_buffer *dst = NULL; + struct pipe_resource *dst = NULL; void *dst_map = NULL; - dst = screen->buffer_create( screen, 32, - PIPE_BUFFER_USAGE_INDEX | - PIPE_BUFFER_USAGE_CPU_WRITE | - PIPE_BUFFER_USAGE_GPU_READ, - size ); + dst = pipe_buffer_create( pipe->screen, 32, + PIPE_BUFFER_USAGE_INDEX | + PIPE_BUFFER_USAGE_CPU_WRITE | + PIPE_BUFFER_USAGE_GPU_READ, + size ); if (dst == NULL) goto fail; - dst_map = pipe_buffer_map( screen, dst, PIPE_BUFFER_USAGE_CPU_WRITE ); + dst_map = pipe_buffer_map( pipe, dst, PIPE_BUFFER_USAGE_CPU_WRITE, + &transfer); if (dst_map == NULL) goto fail; generate( nr, dst_map ); - pipe_buffer_unmap( screen, dst ); + pipe_buffer_unmap( pipe, dst, transfer ); *out_buf = dst; return PIPE_OK; fail: if (dst_map) - screen->buffer_unmap( screen, dst ); + pipe_buffer_unmap( pipe, dst, transfer ); if (dst) - screen->buffer_destroy( dst ); - + pipe->screen->resource_destroy( pipe->screen, dst ); + return PIPE_ERROR_OUT_OF_MEMORY; } @@ -96,7 +98,7 @@ static enum pipe_error retrieve_or_generate_indices( struct svga_hwtnl *hwtnl, unsigned gen_nr, unsigned gen_size, u_generate_func generate, - struct pipe_buffer **out_buf ) + struct pipe_resource **out_buf ) { enum pipe_error ret = PIPE_OK; int i; @@ -107,7 +109,7 @@ static enum pipe_error retrieve_or_generate_indices( struct svga_hwtnl *hwtnl, { if (compare(hwtnl->index_cache[prim][i].gen_nr, gen_nr, gen_type)) { - pipe_buffer_reference( out_buf, + pipe_resource_reference( out_buf, hwtnl->index_cache[prim][i].buffer ); if (DBG) @@ -117,7 +119,7 @@ static enum pipe_error retrieve_or_generate_indices( struct svga_hwtnl *hwtnl, } else if (gen_type == U_GENERATE_REUSABLE) { - pipe_buffer_reference( &hwtnl->index_cache[prim][i].buffer, + pipe_resource_reference( &hwtnl->index_cache[prim][i].buffer, NULL ); if (DBG) @@ -149,7 +151,7 @@ static enum pipe_error retrieve_or_generate_indices( struct svga_hwtnl *hwtnl, assert (smallest != IDX_CACHE_MAX); - pipe_buffer_reference( &hwtnl->index_cache[prim][smallest].buffer, + pipe_resource_reference( &hwtnl->index_cache[prim][smallest].buffer, NULL ); if (DBG) @@ -171,7 +173,7 @@ static enum pipe_error retrieve_or_generate_indices( struct svga_hwtnl *hwtnl, hwtnl->index_cache[prim][i].generate = generate; hwtnl->index_cache[prim][i].gen_nr = gen_nr; - pipe_buffer_reference( &hwtnl->index_cache[prim][i].buffer, + pipe_resource_reference( &hwtnl->index_cache[prim][i].buffer, *out_buf ); if (DBG) @@ -259,7 +261,7 @@ svga_hwtnl_draw_arrays( struct svga_hwtnl *hwtnl, return simple_draw_arrays( hwtnl, gen_prim, start, count ); } else { - struct pipe_buffer *gen_buf = NULL; + struct pipe_resource *gen_buf = NULL; /* Need to draw as indexed primitive. * Potentially need to run the gen func to build an index buffer. @@ -288,7 +290,7 @@ svga_hwtnl_draw_arrays( struct svga_hwtnl *hwtnl, done: if (gen_buf) - pipe_buffer_reference( &gen_buf, NULL ); + pipe_resource_reference( &gen_buf, NULL ); return ret; } diff --git a/src/gallium/drivers/svga/svga_draw_elements.c b/src/gallium/drivers/svga/svga_draw_elements.c index e8097d82f1..e131686fd0 100644 --- a/src/gallium/drivers/svga/svga_draw_elements.c +++ b/src/gallium/drivers/svga/svga_draw_elements.c @@ -30,7 +30,7 @@ #include "svga_cmd.h" #include "svga_draw.h" #include "svga_draw_private.h" -#include "svga_screen_buffer.h" +#include "svga_resource_buffer.h" #include "svga_winsys.h" #include "svga_context.h" @@ -39,32 +39,34 @@ static enum pipe_error translate_indices( struct svga_hwtnl *hwtnl, - struct pipe_buffer *src, + struct pipe_resource *src, unsigned offset, unsigned nr, unsigned index_size, u_translate_func translate, - struct pipe_buffer **out_buf ) + struct pipe_resource **out_buf ) { - struct pipe_screen *screen = hwtnl->svga->pipe.screen; + struct pipe_context *pipe = &hwtnl->svga->pipe; + struct pipe_transfer *src_transfer = NULL; + struct pipe_transfer *dst_transfer = NULL; unsigned size = index_size * nr; const void *src_map = NULL; - struct pipe_buffer *dst = NULL; + struct pipe_resource *dst = NULL; void *dst_map = NULL; - dst = screen->buffer_create( screen, 32, - PIPE_BUFFER_USAGE_INDEX | - PIPE_BUFFER_USAGE_CPU_WRITE | - PIPE_BUFFER_USAGE_GPU_READ, - size ); + dst = pipe_buffer_create( pipe->screen, 32, + PIPE_BUFFER_USAGE_INDEX | + PIPE_BUFFER_USAGE_CPU_WRITE | + PIPE_BUFFER_USAGE_GPU_READ, + size ); if (dst == NULL) goto fail; - src_map = pipe_buffer_map( screen, src, PIPE_BUFFER_USAGE_CPU_READ ); + src_map = pipe_buffer_map( pipe, src, PIPE_BUFFER_USAGE_CPU_READ, &src_transfer ); if (src_map == NULL) goto fail; - dst_map = pipe_buffer_map( screen, dst, PIPE_BUFFER_USAGE_CPU_WRITE ); + dst_map = pipe_buffer_map( pipe, dst, PIPE_BUFFER_USAGE_CPU_WRITE, &dst_transfer ); if (dst_map == NULL) goto fail; @@ -72,21 +74,21 @@ translate_indices( struct svga_hwtnl *hwtnl, nr, dst_map ); - pipe_buffer_unmap( screen, src ); - pipe_buffer_unmap( screen, dst ); + pipe_buffer_unmap( pipe, src, src_transfer ); + pipe_buffer_unmap( pipe, dst, dst_transfer ); *out_buf = dst; return PIPE_OK; fail: if (src_map) - screen->buffer_unmap( screen, src ); + pipe_buffer_unmap( pipe, src, src_transfer ); if (dst_map) - screen->buffer_unmap( screen, dst ); + pipe_buffer_unmap( pipe, dst, dst_transfer ); if (dst) - screen->buffer_destroy( dst ); + pipe->screen->resource_destroy( pipe->screen, dst ); return PIPE_ERROR_OUT_OF_MEMORY; } @@ -97,7 +99,7 @@ fail: enum pipe_error svga_hwtnl_simple_draw_range_elements( struct svga_hwtnl *hwtnl, - struct pipe_buffer *index_buffer, + struct pipe_resource *index_buffer, unsigned index_size, unsigned min_index, unsigned max_index, @@ -106,7 +108,7 @@ svga_hwtnl_simple_draw_range_elements( struct svga_hwtnl *hwtnl, unsigned count, unsigned bias ) { - struct pipe_buffer *upload_buffer = NULL; + struct pipe_resource *upload_buffer = NULL; SVGA3dPrimitiveRange range; unsigned hw_prim; unsigned hw_count; @@ -120,7 +122,7 @@ svga_hwtnl_simple_draw_range_elements( struct svga_hwtnl *hwtnl, if (index_buffer && svga_buffer_is_user_buffer(index_buffer)) { - assert( index_buffer->size >= index_offset + count * index_size ); + assert( index_buffer->width0 >= index_offset + count * index_size ); ret = u_upload_buffer( hwtnl->upload_ib, index_offset, @@ -151,7 +153,7 @@ svga_hwtnl_simple_draw_range_elements( struct svga_hwtnl *hwtnl, done: if (upload_buffer) - pipe_buffer_reference( &upload_buffer, NULL ); + pipe_resource_reference( &upload_buffer, NULL ); return ret; } @@ -161,7 +163,7 @@ done: enum pipe_error svga_hwtnl_draw_range_elements( struct svga_hwtnl *hwtnl, - struct pipe_buffer *index_buffer, + struct pipe_resource *index_buffer, unsigned index_size, unsigned min_index, unsigned max_index, @@ -209,7 +211,7 @@ svga_hwtnl_draw_range_elements( struct svga_hwtnl *hwtnl, gen_prim, start, count, bias ); } else { - struct pipe_buffer *gen_buf = NULL; + struct pipe_resource *gen_buf = NULL; /* Need to allocate a new index buffer and run the translate * func to populate it. Could potentially cache this translated @@ -242,7 +244,7 @@ svga_hwtnl_draw_range_elements( struct svga_hwtnl *hwtnl, done: if (gen_buf) - pipe_buffer_reference( &gen_buf, NULL ); + pipe_resource_reference( &gen_buf, NULL ); return ret; } diff --git a/src/gallium/drivers/svga/svga_draw_private.h b/src/gallium/drivers/svga/svga_draw_private.h index 9aa40e1664..b6fcd6854c 100644 --- a/src/gallium/drivers/svga/svga_draw_private.h +++ b/src/gallium/drivers/svga/svga_draw_private.h @@ -90,7 +90,7 @@ struct index_cache { /* If non-null, this buffer is filled by calling * generate(nr, map(buffer)) */ - struct pipe_buffer *buffer; + struct pipe_resource *buffer; }; #define QSZ 32 @@ -99,11 +99,11 @@ struct draw_cmd { struct svga_winsys_context *swc; SVGA3dVertexDecl vdecl[SVGA3D_INPUTREG_MAX]; - struct pipe_buffer *vdecl_vb[SVGA3D_INPUTREG_MAX]; + struct pipe_resource *vdecl_vb[SVGA3D_INPUTREG_MAX]; unsigned vdecl_count; SVGA3dPrimitiveRange prim[QSZ]; - struct pipe_buffer *prim_ib[QSZ]; + struct pipe_resource *prim_ib[QSZ]; unsigned prim_count; unsigned min_index[QSZ]; unsigned max_index[QSZ]; @@ -141,11 +141,11 @@ svga_hwtnl_prim( struct svga_hwtnl *hwtnl, const SVGA3dPrimitiveRange *range, unsigned min_index, unsigned max_index, - struct pipe_buffer *ib ); + struct pipe_resource *ib ); enum pipe_error svga_hwtnl_simple_draw_range_elements( struct svga_hwtnl *hwtnl, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned index_size, unsigned min_index, unsigned max_index, diff --git a/src/gallium/drivers/svga/svga_pipe_blit.c b/src/gallium/drivers/svga/svga_pipe_blit.c index 4f575b06e6..889da29e28 100644 --- a/src/gallium/drivers/svga/svga_pipe_blit.c +++ b/src/gallium/drivers/svga/svga_pipe_blit.c @@ -23,10 +23,11 @@ * **********************************************************/ -#include "svga_screen_texture.h" +#include "svga_resource_texture.h" #include "svga_context.h" #include "svga_debug.h" #include "svga_cmd.h" +#include "svga_surface.h" #define FILE_DEBUG_FLAG DEBUG_BLIT diff --git a/src/gallium/drivers/svga/svga_pipe_clear.c b/src/gallium/drivers/svga/svga_pipe_clear.c index 8483a3fad7..b88425bb15 100644 --- a/src/gallium/drivers/svga/svga_pipe_clear.c +++ b/src/gallium/drivers/svga/svga_pipe_clear.c @@ -31,7 +31,7 @@ #include "svga_context.h" #include "svga_state.h" -#include "svga_screen_texture.h" +#include "svga_surface.h" static enum pipe_error diff --git a/src/gallium/drivers/svga/svga_pipe_constants.c b/src/gallium/drivers/svga/svga_pipe_constants.c index 73a0cd6b3a..2fa2142d07 100644 --- a/src/gallium/drivers/svga/svga_pipe_constants.c +++ b/src/gallium/drivers/svga/svga_pipe_constants.c @@ -45,14 +45,14 @@ struct svga_constbuf static void svga_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index, - struct pipe_buffer *buf) + struct pipe_resource *buf) { struct svga_context *svga = svga_context(pipe); assert(shader < PIPE_SHADER_TYPES); assert(index == 0); - pipe_buffer_reference( &svga->curr.cb[shader], + pipe_resource_reference( &svga->curr.cb[shader], buf ); if (shader == PIPE_SHADER_FRAGMENT) diff --git a/src/gallium/drivers/svga/svga_pipe_draw.c b/src/gallium/drivers/svga/svga_pipe_draw.c index f00cf23935..a05272b2e4 100644 --- a/src/gallium/drivers/svga/svga_pipe_draw.c +++ b/src/gallium/drivers/svga/svga_pipe_draw.c @@ -42,7 +42,7 @@ static enum pipe_error retry_draw_range_elements( struct svga_context *svga, - struct pipe_buffer *index_buffer, + struct pipe_resource *index_buffer, unsigned index_size, unsigned min_index, unsigned max_index, @@ -150,7 +150,7 @@ retry: static void svga_draw_range_elements( struct pipe_context *pipe, - struct pipe_buffer *index_buffer, + struct pipe_resource *index_buffer, unsigned index_size, unsigned min_index, unsigned max_index, @@ -224,7 +224,7 @@ svga_draw_range_elements( struct pipe_context *pipe, static void svga_draw_elements( struct pipe_context *pipe, - struct pipe_buffer *index_buffer, + struct pipe_resource *index_buffer, unsigned index_size, unsigned prim, unsigned start, unsigned count) { diff --git a/src/gallium/drivers/svga/svga_pipe_flush.c b/src/gallium/drivers/svga/svga_pipe_flush.c index 7fa2205ae5..ab243aa6ec 100644 --- a/src/gallium/drivers/svga/svga_pipe_flush.c +++ b/src/gallium/drivers/svga/svga_pipe_flush.c @@ -25,7 +25,7 @@ #include "pipe/p_defines.h" #include "svga_screen.h" -#include "svga_screen_texture.h" +#include "svga_surface.h" #include "svga_context.h" #include "svga_debug.h" diff --git a/src/gallium/drivers/svga/svga_pipe_misc.c b/src/gallium/drivers/svga/svga_pipe_misc.c index 95bf0e6f91..b27a92a2d6 100644 --- a/src/gallium/drivers/svga/svga_pipe_misc.c +++ b/src/gallium/drivers/svga/svga_pipe_misc.c @@ -28,7 +28,7 @@ #include "util/u_inlines.h" #include "svga_context.h" -#include "svga_screen_texture.h" +#include "svga_surface.h" static void svga_set_scissor_state( struct pipe_context *pipe, diff --git a/src/gallium/drivers/svga/svga_pipe_query.c b/src/gallium/drivers/svga/svga_pipe_query.c index 08283e3731..04397790b4 100644 --- a/src/gallium/drivers/svga/svga_pipe_query.c +++ b/src/gallium/drivers/svga/svga_pipe_query.c @@ -30,7 +30,7 @@ #include "svga_cmd.h" #include "svga_context.h" #include "svga_screen.h" -#include "svga_screen_buffer.h" +#include "svga_resource_buffer.h" #include "svga_winsys.h" #include "svga_debug.h" diff --git a/src/gallium/drivers/svga/svga_pipe_sampler.c b/src/gallium/drivers/svga/svga_pipe_sampler.c index 82d525ca33..f44a0e1325 100644 --- a/src/gallium/drivers/svga/svga_pipe_sampler.c +++ b/src/gallium/drivers/svga/svga_pipe_sampler.c @@ -30,7 +30,7 @@ #include "tgsi/tgsi_parse.h" #include "svga_context.h" -#include "svga_screen_texture.h" +#include "svga_resource_texture.h" #include "svga_debug.h" @@ -178,7 +178,7 @@ static void svga_delete_sampler_state(struct pipe_context *pipe, static struct pipe_sampler_view * svga_create_sampler_view(struct pipe_context *pipe, - struct pipe_texture *texture, + struct pipe_resource *texture, const struct pipe_sampler_view *templ) { struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); @@ -187,7 +187,7 @@ svga_create_sampler_view(struct pipe_context *pipe, *view = *templ; view->reference.count = 1; view->texture = NULL; - pipe_texture_reference(&view->texture, texture); + pipe_resource_reference(&view->texture, texture); view->context = pipe; } @@ -199,7 +199,7 @@ static void svga_sampler_view_destroy(struct pipe_context *pipe, struct pipe_sampler_view *view) { - pipe_texture_reference(&view->texture, NULL); + pipe_resource_reference(&view->texture, NULL); FREE(view); } diff --git a/src/gallium/drivers/svga/svga_pipe_vertex.c b/src/gallium/drivers/svga/svga_pipe_vertex.c index 1715a47fc6..23808ad08e 100644 --- a/src/gallium/drivers/svga/svga_pipe_vertex.c +++ b/src/gallium/drivers/svga/svga_pipe_vertex.c @@ -30,7 +30,7 @@ #include "tgsi/tgsi_parse.h" #include "svga_screen.h" -#include "svga_screen_buffer.h" +#include "svga_resource_buffer.h" #include "svga_context.h" @@ -49,13 +49,13 @@ static void svga_set_vertex_buffers(struct pipe_context *pipe, /* Adjust refcounts */ for (i = 0; i < count; i++) { - pipe_buffer_reference(&svga->curr.vb[i].buffer, buffers[i].buffer); + pipe_resource_reference(&svga->curr.vb[i].buffer, buffers[i].buffer); if (svga_buffer_is_user_buffer(buffers[i].buffer)) any_user_buffer = TRUE; } for ( ; i < svga->curr.num_vertex_buffers; i++) - pipe_buffer_reference(&svga->curr.vb[i].buffer, NULL); + pipe_resource_reference(&svga->curr.vb[i].buffer, NULL); /* Copy remaining data */ memcpy(svga->curr.vb, buffers, count * sizeof buffers[0]); @@ -102,7 +102,7 @@ void svga_cleanup_vertex_state( struct svga_context *svga ) unsigned i; for (i = 0 ; i < svga->curr.num_vertex_buffers; i++) - pipe_buffer_reference(&svga->curr.vb[i].buffer, NULL); + pipe_resource_reference(&svga->curr.vb[i].buffer, NULL); } diff --git a/src/gallium/drivers/svga/svga_resource.c b/src/gallium/drivers/svga/svga_resource.c new file mode 100644 index 0000000000..15258c1966 --- /dev/null +++ b/src/gallium/drivers/svga/svga_resource.c @@ -0,0 +1,55 @@ +#include "util/u_debug.h" + +#include "svga_resource.h" +#include "svga_resource_buffer.h" +#include "svga_resource_texture.h" +#include "svga_context.h" +#include "svga_screen.h" + + +static struct pipe_resource * +svga_resource_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + if (template->target == PIPE_BUFFER) + return svga_buffer_create(screen, template); + else + return svga_resource_create(screen, template); + +} + +static struct pipe_resource * +svga_resource_from_handle(struct pipe_screen * screen, + const struct pipe_resource *template, + struct winsys_handle *whandle) +{ + if (template->target == PIPE_BUFFER) + return NULL; + else + return svga_resource_from_handle(screen, template, whandle); +} + + +void +svga_init_resource_functions(struct svga_context *svga) +{ + svga->pipe.get_transfer = u_get_transfer_vtbl; + svga->pipe.transfer_map = u_transfer_map_vtbl; + svga->pipe.transfer_flush_region = u_transfer_flush_region_vtbl; + svga->pipe.transfer_unmap = u_transfer_unmap_vtbl; + svga->pipe.transfer_destroy = u_transfer_destroy_vtbl; + svga->pipe.transfer_inline_write = u_transfer_inline_write_vtbl; +} + +void +svga_init_screen_resource_functions(struct svga_screen *is) +{ + is->screen.resource_create = svga_resource_create; + is->screen.resource_from_handle = svga_resource_from_handle; + is->screen.resource_get_handle = u_resource_get_handle_vtbl; + is->screen.resource_destroy = u_resource_destroy_vtbl; + is->screen.user_buffer_create = svga_user_buffer_create; +} + + + diff --git a/src/gallium/drivers/softpipe/sp_buffer.h b/src/gallium/drivers/svga/svga_resource.h index 9d8e56a176..851e3b50ce 100644 --- a/src/gallium/drivers/softpipe/sp_buffer.h +++ b/src/gallium/drivers/svga/svga_resource.h @@ -1,8 +1,8 @@ /************************************************************************** - * - * Copyright 2009 VMware, Inc. + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. - * + * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including @@ -10,46 +10,34 @@ * distribute, sub license, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: - * + * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * + * **************************************************************************/ -#ifndef SP_BUFFER_H -#define SP_BUFFER_H +#ifndef SVGA_RESOURCE_H +#define SVGA_RESOURCE_H -#include "pipe/p_compiler.h" -#include "pipe/p_state.h" +struct svga_screen; +#include "util/u_debug.h" -struct softpipe_buffer -{ - struct pipe_buffer base; - boolean userBuffer; /** Is this a user-space buffer? */ - void *data; -}; +struct svga_context; +struct svga_screen; -/** Cast wrapper */ -static INLINE struct softpipe_buffer * -softpipe_buffer( struct pipe_buffer *buf ) -{ - return (struct softpipe_buffer *)buf; -} +void svga_init_screen_resource_functions(struct svga_screen *is); +void svga_init_resource_functions(struct svga_context *svga ); -void -softpipe_init_screen_buffer_funcs(struct pipe_screen *screen); - - -#endif /* SP_BUFFER_H */ +#endif /* SVGA_RESOURCE_H */ diff --git a/src/gallium/drivers/svga/svga_resource_buffer.c b/src/gallium/drivers/svga/svga_resource_buffer.c new file mode 100644 index 0000000000..b35abc007e --- /dev/null +++ b/src/gallium/drivers/svga/svga_resource_buffer.c @@ -0,0 +1,354 @@ +/********************************************************** + * Copyright 2008-2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +#include "svga_cmd.h" + +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "os/os_thread.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "svga_context.h" +#include "svga_screen.h" +#include "svga_resource_buffer.h" +#include "svga_resource_buffer_upload.h" +#include "svga_winsys.h" +#include "svga_debug.h" + + +/** + * Vertex and index buffers need hardware backing. Constant buffers + * do not. No other types of buffers currently supported. + */ +static INLINE boolean +svga_buffer_needs_hw_storage(unsigned usage) +{ + return usage & (PIPE_BUFFER_USAGE_VERTEX | PIPE_BUFFER_USAGE_INDEX); +} + + +static unsigned int +svga_buffer_is_referenced( struct pipe_context *pipe, + struct pipe_resource *buf, + unsigned face, unsigned level) +{ + struct svga_screen *ss = svga_screen(pipe->screen); + struct svga_buffer *sbuf = svga_buffer(buf); + + /** + * XXX: Check this. + * The screen may cache buffer writes, but when we map, we map out + * of those cached writes, so we don't need to set a + * PIPE_REFERENCED_FOR_WRITE flag for cached buffers. + */ + + if (!sbuf->handle || ss->sws->surface_is_flushed(ss->sws, sbuf->handle)) + return PIPE_UNREFERENCED; + + /** + * sws->surface_is_flushed() does not distinguish between read references + * and write references. So assume a reference is both, + * however, we make an exception for index- and vertex buffers, to avoid + * a flush in st_bufferobj_get_subdata, during display list replay. + */ + + if (sbuf->b.b.usage & (PIPE_BUFFER_USAGE_VERTEX | PIPE_BUFFER_USAGE_INDEX)) + return PIPE_REFERENCED_FOR_READ; + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + + + + + + +static void * +svga_buffer_map_range( struct pipe_screen *screen, + struct pipe_resource *buf, + unsigned offset, + unsigned length, + unsigned usage ) +{ + struct svga_screen *ss = svga_screen(screen); + struct svga_winsys_screen *sws = ss->sws; + struct svga_buffer *sbuf = svga_buffer( buf ); + void *map; + + if (!sbuf->swbuf && !sbuf->hwbuf) { + if (svga_buffer_create_hw_storage(ss, sbuf) != PIPE_OK) { + /* + * We can't create a hardware buffer big enough, so create a malloc + * buffer instead. + */ + debug_printf("%s: failed to allocate %u KB of DMA, splitting DMA transfers\n", + __FUNCTION__, + (sbuf->b.b.width0 + 1023)/1024); + + sbuf->swbuf = align_malloc(sbuf->b.b.width0, 16); + } + } + + if (sbuf->swbuf) { + /* User/malloc buffer */ + map = sbuf->swbuf; + } + else if (sbuf->hwbuf) { + map = sws->buffer_map(sws, sbuf->hwbuf, usage); + } + else { + map = NULL; + } + + if(map) { + pipe_mutex_lock(ss->swc_mutex); + + ++sbuf->map.count; + + if (usage & PIPE_TRANSFER_WRITE) { + assert(sbuf->map.count <= 1); + sbuf->map.writing = TRUE; + if (usage & PIPE_TRANSFER_FLUSH_EXPLICIT) + sbuf->map.flush_explicit = TRUE; + } + + pipe_mutex_unlock(ss->swc_mutex); + } + + return map; +} + + + +static void +svga_buffer_flush_mapped_range( struct pipe_screen *screen, + struct pipe_resource *buf, + unsigned offset, unsigned length) +{ + struct svga_buffer *sbuf = svga_buffer( buf ); + struct svga_screen *ss = svga_screen(screen); + + pipe_mutex_lock(ss->swc_mutex); + assert(sbuf->map.writing); + if(sbuf->map.writing) { + assert(sbuf->map.flush_explicit); + svga_buffer_add_range(sbuf, offset, offset + length); + } + pipe_mutex_unlock(ss->swc_mutex); +} + +static void +svga_buffer_unmap( struct pipe_screen *screen, + struct pipe_resource *buf) +{ + struct svga_screen *ss = svga_screen(screen); + struct svga_winsys_screen *sws = ss->sws; + struct svga_buffer *sbuf = svga_buffer( buf ); + + pipe_mutex_lock(ss->swc_mutex); + + assert(sbuf->map.count); + if(sbuf->map.count) + --sbuf->map.count; + + if(sbuf->hwbuf) + sws->buffer_unmap(sws, sbuf->hwbuf); + + if(sbuf->map.writing) { + if(!sbuf->map.flush_explicit) { + /* No mapped range was flushed -- flush the whole buffer */ + SVGA_DBG(DEBUG_DMA, "flushing the whole buffer\n"); + + svga_buffer_add_range(sbuf, 0, sbuf->b.b.width0); + } + + sbuf->map.writing = FALSE; + sbuf->map.flush_explicit = FALSE; + } + + pipe_mutex_unlock(ss->swc_mutex); +} + + + +static void +svga_buffer_destroy( struct pipe_screen *screen, + struct pipe_resource *buf ) +{ + struct svga_screen *ss = svga_screen(screen); + struct svga_buffer *sbuf = svga_buffer( buf ); + + assert(!p_atomic_read(&buf->reference.count)); + + assert(!sbuf->dma.pending); + + if(sbuf->handle) + svga_buffer_destroy_host_surface(ss, sbuf); + + if(sbuf->uploaded.buffer) + pipe_resource_reference(&sbuf->uploaded.buffer, NULL); + + if(sbuf->hwbuf) + svga_buffer_destroy_hw_storage(ss, sbuf); + + if(sbuf->swbuf && !sbuf->user) + align_free(sbuf->swbuf); + + FREE(sbuf); +} + + +/* Keep the original code more or less intact, implement transfers in + * terms of the old functions. + */ +static void * +svga_buffer_transfer_map( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + uint8_t *map = svga_buffer_map_range( pipe->screen, + transfer->resource, + transfer->box.x, + transfer->box.width, + transfer->usage ); + if (map == NULL) + return NULL; + + /* map_buffer() returned a pointer to the beginning of the buffer, + * but transfers are expected to return a pointer to just the + * region specified in the box. + */ + return map + transfer->box.x; +} + + + +static void svga_buffer_transfer_flush_region( struct pipe_context *pipe, + struct pipe_transfer *transfer, + const struct pipe_box *box) +{ + assert(box->x + box->width <= transfer->box.width); + + svga_buffer_flush_mapped_range(pipe->screen, + transfer->resource, + transfer->box.x + box->x, + box->width); +} + +static void svga_buffer_transfer_unmap( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + svga_buffer_unmap(pipe->screen, + transfer->resource); +} + + + + + + + +struct u_resource_vtbl svga_buffer_vtbl = +{ + u_default_resource_get_handle, /* get_handle */ + svga_buffer_destroy, /* resource_destroy */ + svga_buffer_is_referenced, /* is_resource_referenced */ + u_default_get_transfer, /* get_transfer */ + u_default_transfer_destroy, /* transfer_destroy */ + svga_buffer_transfer_map, /* transfer_map */ + svga_buffer_transfer_flush_region, /* transfer_flush_region */ + svga_buffer_transfer_unmap, /* transfer_unmap */ + u_default_transfer_inline_write /* transfer_inline_write */ +}; + + + +struct pipe_resource * +svga_buffer_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + struct svga_screen *ss = svga_screen(screen); + struct svga_buffer *sbuf; + + sbuf = CALLOC_STRUCT(svga_buffer); + if(!sbuf) + goto error1; + + sbuf->b.b = *template; + sbuf->b.vtbl = &svga_buffer_vtbl; + pipe_reference_init(&sbuf->b.b.reference, 1); + sbuf->b.b.screen = screen; + + if(svga_buffer_needs_hw_storage(template->usage)) { + if(svga_buffer_create_host_surface(ss, sbuf) != PIPE_OK) + goto error2; + } + else { + sbuf->swbuf = align_malloc(template->width0, 64); + if(!sbuf->swbuf) + goto error2; + } + + return &sbuf->b.b; + +error2: + FREE(sbuf); +error1: + return NULL; +} + +struct pipe_resource * +svga_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned usage) +{ + struct svga_buffer *sbuf; + + sbuf = CALLOC_STRUCT(svga_buffer); + if(!sbuf) + goto no_sbuf; + + pipe_reference_init(&sbuf->b.b.reference, 1); + sbuf->b.vtbl = &svga_buffer_vtbl; + sbuf->b.b.screen = screen; + sbuf->b.b.format = PIPE_FORMAT_R8_UNORM; /* ?? */ + sbuf->b.b.usage = PIPE_BUFFER_USAGE_CPU_READ | usage; + sbuf->b.b.width0 = bytes; + sbuf->b.b.height0 = 1; + sbuf->b.b.depth0 = 1; + + sbuf->swbuf = ptr; + sbuf->user = TRUE; + + return &sbuf->b.b; + +no_sbuf: + return NULL; +} + + + diff --git a/src/gallium/drivers/svga/svga_screen_buffer.h b/src/gallium/drivers/svga/svga_resource_buffer.h index 8c862fa62d..55e7321184 100644 --- a/src/gallium/drivers/svga/svga_screen_buffer.h +++ b/src/gallium/drivers/svga/svga_resource_buffer.h @@ -29,14 +29,13 @@ #include "pipe/p_compiler.h" #include "pipe/p_state.h" +#include "util/u_transfer.h" #include "util/u_double_list.h" #include "svga_screen_cache.h" -#define SVGA_BUFFER_MAGIC 0x344f9005 - /** * Maximum number of discontiguous ranges */ @@ -49,6 +48,8 @@ struct svga_winsys_buffer; struct svga_winsys_surface; +extern struct u_resource_vtbl svga_buffer_vtbl; + struct svga_buffer_range { unsigned start; @@ -61,12 +62,7 @@ struct svga_buffer_range */ struct svga_buffer { - struct pipe_buffer base; - - /** - * Marker to detect bad casts in runtime. - */ - uint32_t magic; + struct u_resource b; /** * Regular (non DMA'able) memory. @@ -138,7 +134,7 @@ struct svga_buffer * Information about uploaded version of user buffers. */ struct { - struct pipe_buffer *buffer; + struct pipe_resource *buffer; /** * We combine multiple user buffers into the same hardware buffer. This @@ -190,10 +186,10 @@ struct svga_buffer static INLINE struct svga_buffer * -svga_buffer(struct pipe_buffer *buffer) +svga_buffer(struct pipe_resource *buffer) { if (buffer) { - assert(((struct svga_buffer *)buffer)->magic == SVGA_BUFFER_MAGIC); + assert(((struct svga_buffer *)buffer)->b.vtbl == &svga_buffer_vtbl); return (struct svga_buffer *)buffer; } return NULL; @@ -205,14 +201,24 @@ svga_buffer(struct pipe_buffer *buffer) * decide to use an alternate upload path for these buffers. */ static INLINE boolean -svga_buffer_is_user_buffer( struct pipe_buffer *buffer ) +svga_buffer_is_user_buffer( struct pipe_resource *buffer ) { return svga_buffer(buffer)->user; } -void -svga_screen_init_buffer_functions(struct pipe_screen *screen); + + +struct pipe_resource * +svga_user_buffer_create(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned usage); + +struct pipe_resource * +svga_buffer_create(struct pipe_screen *screen, + const struct pipe_resource *template); + /** @@ -226,7 +232,7 @@ svga_screen_init_buffer_functions(struct pipe_screen *screen); */ struct svga_winsys_surface * svga_buffer_handle(struct svga_context *svga, - struct pipe_buffer *buf); + struct pipe_resource *buf); void svga_context_flush_buffers(struct svga_context *svga); diff --git a/src/gallium/drivers/svga/svga_resource_buffer_host.c b/src/gallium/drivers/svga/svga_resource_buffer_host.c new file mode 100644 index 0000000000..139597f9cb --- /dev/null +++ b/src/gallium/drivers/svga/svga_resource_buffer_host.c @@ -0,0 +1,2 @@ + + diff --git a/src/gallium/drivers/svga/svga_screen_buffer.c b/src/gallium/drivers/svga/svga_resource_buffer_upload.c index 1ff6a3a5b3..78fda66478 100644 --- a/src/gallium/drivers/svga/svga_screen_buffer.c +++ b/src/gallium/drivers/svga/svga_resource_buffer_upload.c @@ -34,88 +34,14 @@ #include "svga_context.h" #include "svga_screen.h" -#include "svga_screen_buffer.h" +#include "svga_resource_buffer.h" +#include "svga_resource_buffer_upload.h" #include "svga_winsys.h" #include "svga_debug.h" -/** - * Vertex and index buffers have to be treated slightly differently from - * regular guest memory regions because the SVGA device sees them as - * surfaces, and the state tracker can create/destroy without the pipe - * driver, therefore we must do the uploads from the vws. +/* Allocate a winsys_buffer (ie. DMA, aka GMR memory). */ -static INLINE boolean -svga_buffer_needs_hw_storage(unsigned usage) -{ - return usage & (PIPE_BUFFER_USAGE_VERTEX | PIPE_BUFFER_USAGE_INDEX); -} - - -static INLINE enum pipe_error -svga_buffer_create_host_surface(struct svga_screen *ss, - struct svga_buffer *sbuf) -{ - if(!sbuf->handle) { - sbuf->key.flags = 0; - - sbuf->key.format = SVGA3D_BUFFER; - if(sbuf->base.usage & PIPE_BUFFER_USAGE_VERTEX) - sbuf->key.flags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER; - if(sbuf->base.usage & PIPE_BUFFER_USAGE_INDEX) - sbuf->key.flags |= SVGA3D_SURFACE_HINT_INDEXBUFFER; - - sbuf->key.size.width = sbuf->base.size; - sbuf->key.size.height = 1; - sbuf->key.size.depth = 1; - - sbuf->key.numFaces = 1; - sbuf->key.numMipLevels = 1; - sbuf->key.cachable = 1; - - SVGA_DBG(DEBUG_DMA, "surface_create for buffer sz %d\n", sbuf->base.size); - - sbuf->handle = svga_screen_surface_create(ss, &sbuf->key); - if(!sbuf->handle) - return PIPE_ERROR_OUT_OF_MEMORY; - - /* Always set the discard flag on the first time the buffer is written - * as svga_screen_surface_create might have passed a recycled host - * buffer. - */ - sbuf->dma.flags.discard = TRUE; - - SVGA_DBG(DEBUG_DMA, " --> got sid %p sz %d (buffer)\n", sbuf->handle, sbuf->base.size); - } - - return PIPE_OK; -} - - -static INLINE void -svga_buffer_destroy_host_surface(struct svga_screen *ss, - struct svga_buffer *sbuf) -{ - if(sbuf->handle) { - SVGA_DBG(DEBUG_DMA, " ungrab sid %p sz %d\n", sbuf->handle, sbuf->base.size); - svga_screen_surface_destroy(ss, &sbuf->key, &sbuf->handle); - } -} - - -static INLINE void -svga_buffer_destroy_hw_storage(struct svga_screen *ss, struct svga_buffer *sbuf) -{ - struct svga_winsys_screen *sws = ss->sws; - - assert(!sbuf->map.count); - assert(sbuf->hwbuf); - if(sbuf->hwbuf) { - sws->buffer_destroy(sws, sbuf->hwbuf); - sbuf->hwbuf = NULL; - } -} - struct svga_winsys_buffer * svga_winsys_buffer_create( struct svga_screen *ss, unsigned alignment, @@ -142,21 +68,36 @@ svga_winsys_buffer_create( struct svga_screen *ss, } +void +svga_buffer_destroy_hw_storage(struct svga_screen *ss, struct svga_buffer *sbuf) +{ + struct svga_winsys_screen *sws = ss->sws; + + assert(!sbuf->map.count); + assert(sbuf->hwbuf); + if(sbuf->hwbuf) { + sws->buffer_destroy(sws, sbuf->hwbuf); + sbuf->hwbuf = NULL; + } +} + + + /** * Allocate DMA'ble storage for the buffer. * * Called before mapping a buffer. */ -static INLINE enum pipe_error +enum pipe_error svga_buffer_create_hw_storage(struct svga_screen *ss, struct svga_buffer *sbuf) { assert(!sbuf->user); if(!sbuf->hwbuf) { - unsigned alignment = sbuf->base.alignment; + unsigned alignment = 16; unsigned usage = 0; - unsigned size = sbuf->base.size; + unsigned size = sbuf->b.b.width0; sbuf->hwbuf = svga_winsys_buffer_create(ss, alignment, usage, size); if(!sbuf->hwbuf) @@ -169,6 +110,58 @@ svga_buffer_create_hw_storage(struct svga_screen *ss, } + +enum pipe_error +svga_buffer_create_host_surface(struct svga_screen *ss, + struct svga_buffer *sbuf) +{ + if(!sbuf->handle) { + sbuf->key.flags = 0; + + sbuf->key.format = SVGA3D_BUFFER; + if(sbuf->b.b.usage & PIPE_BUFFER_USAGE_VERTEX) + sbuf->key.flags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER; + if(sbuf->b.b.usage & PIPE_BUFFER_USAGE_INDEX) + sbuf->key.flags |= SVGA3D_SURFACE_HINT_INDEXBUFFER; + + sbuf->key.size.width = sbuf->b.b.width0; + sbuf->key.size.height = 1; + sbuf->key.size.depth = 1; + + sbuf->key.numFaces = 1; + sbuf->key.numMipLevels = 1; + sbuf->key.cachable = 1; + + SVGA_DBG(DEBUG_DMA, "surface_create for buffer sz %d\n", sbuf->b.b.width0); + + sbuf->handle = svga_screen_surface_create(ss, &sbuf->key); + if(!sbuf->handle) + return PIPE_ERROR_OUT_OF_MEMORY; + + /* Always set the discard flag on the first time the buffer is written + * as svga_screen_surface_create might have passed a recycled host + * buffer. + */ + sbuf->dma.flags.discard = TRUE; + + SVGA_DBG(DEBUG_DMA, " --> got sid %p sz %d (buffer)\n", sbuf->handle, sbuf->b.b.width0); + } + + return PIPE_OK; +} + + +void +svga_buffer_destroy_host_surface(struct svga_screen *ss, + struct svga_buffer *sbuf) +{ + if(sbuf->handle) { + SVGA_DBG(DEBUG_DMA, " ungrab sid %p sz %d\n", sbuf->handle, sbuf->b.b.width0); + svga_screen_surface_destroy(ss, &sbuf->key, &sbuf->handle); + } +} + + /** * Variant of SVGA3D_BufferDMA which leaves the copy box temporarily in blank. */ @@ -186,7 +179,7 @@ svga_buffer_upload_command(struct svga_context *svga, SVGA3dCmdSurfaceDMASuffix *pSuffix; unsigned region_flags; unsigned surface_flags; - struct pipe_buffer *dummy; + struct pipe_resource *dummy; if(transfer == SVGA3D_WRITE_HOST_VRAM) { region_flags = PIPE_BUFFER_USAGE_GPU_READ; @@ -224,11 +217,11 @@ svga_buffer_upload_command(struct svga_context *svga, /* Increment reference count */ dummy = NULL; - pipe_buffer_reference(&dummy, &sbuf->base); + pipe_resource_reference(&dummy, &sbuf->b.b); pSuffix = (SVGA3dCmdSurfaceDMASuffix *)((uint8_t*)cmd + sizeof *cmd + numBoxes * sizeof *boxes); pSuffix->suffixSize = sizeof *pSuffix; - pSuffix->maximumOffset = sbuf->base.size; + pSuffix->maximumOffset = sbuf->b.b.width0; pSuffix->flags = sbuf->dma.flags; SVGA_FIFOCommitAll(swc); @@ -291,11 +284,12 @@ svga_buffer_upload_flush(struct svga_context *svga, sbuf->dma.boxes = NULL; /* Decrement reference count */ - pipe_reference(&(sbuf->base.reference), NULL); + pipe_reference(&(sbuf->b.b.reference), NULL); sbuf = NULL; } + /** * Note a dirty range. * @@ -305,7 +299,7 @@ svga_buffer_upload_flush(struct svga_context *svga, * * We try to lump as many contiguous DMA transfers together as possible. */ -static void +void svga_buffer_add_range(struct svga_buffer *sbuf, unsigned start, unsigned end) @@ -330,7 +324,7 @@ svga_buffer_add_range(struct svga_buffer *sbuf, * Note that it is not this function task to care about overlapping ranges, * as the GMR was already given so it is too late to do anything. Situations * where overlapping ranges may pose a problem should be detected via - * pipe_context::is_buffer_referenced and the context that refers to the + * pipe_context::is_resource_referenced and the context that refers to the * buffer should be flushed. */ @@ -400,222 +394,6 @@ svga_buffer_add_range(struct svga_buffer *sbuf, } -static void * -svga_buffer_map_range( struct pipe_screen *screen, - struct pipe_buffer *buf, - unsigned offset, unsigned length, - unsigned usage ) -{ - struct svga_screen *ss = svga_screen(screen); - struct svga_winsys_screen *sws = ss->sws; - struct svga_buffer *sbuf = svga_buffer( buf ); - void *map; - - if (!sbuf->swbuf && !sbuf->hwbuf) { - if (svga_buffer_create_hw_storage(ss, sbuf) != PIPE_OK) { - /* - * We can't create a hardware buffer big enough, so create a malloc - * buffer instead. - */ - - debug_printf("%s: failed to allocate %u KB of DMA, splitting DMA transfers\n", - __FUNCTION__, - (sbuf->base.size + 1023)/1024); - - sbuf->swbuf = align_malloc(sbuf->base.size, sbuf->base.alignment); - } - } - - if (sbuf->swbuf) { - /* User/malloc buffer */ - map = sbuf->swbuf; - } - else if (sbuf->hwbuf) { - map = sws->buffer_map(sws, sbuf->hwbuf, usage); - } - else { - map = NULL; - } - - if(map) { - pipe_mutex_lock(ss->swc_mutex); - - ++sbuf->map.count; - - if (usage & PIPE_BUFFER_USAGE_CPU_WRITE) { - assert(sbuf->map.count <= 1); - sbuf->map.writing = TRUE; - if (usage & PIPE_BUFFER_USAGE_FLUSH_EXPLICIT) - sbuf->map.flush_explicit = TRUE; - } - - pipe_mutex_unlock(ss->swc_mutex); - } - - return map; -} - -static void -svga_buffer_flush_mapped_range( struct pipe_screen *screen, - struct pipe_buffer *buf, - unsigned offset, unsigned length) -{ - struct svga_buffer *sbuf = svga_buffer( buf ); - struct svga_screen *ss = svga_screen(screen); - - pipe_mutex_lock(ss->swc_mutex); - assert(sbuf->map.writing); - if(sbuf->map.writing) { - assert(sbuf->map.flush_explicit); - svga_buffer_add_range(sbuf, offset, offset + length); - } - pipe_mutex_unlock(ss->swc_mutex); -} - -static void -svga_buffer_unmap( struct pipe_screen *screen, - struct pipe_buffer *buf) -{ - struct svga_screen *ss = svga_screen(screen); - struct svga_winsys_screen *sws = ss->sws; - struct svga_buffer *sbuf = svga_buffer( buf ); - - pipe_mutex_lock(ss->swc_mutex); - - assert(sbuf->map.count); - if(sbuf->map.count) - --sbuf->map.count; - - if(sbuf->hwbuf) - sws->buffer_unmap(sws, sbuf->hwbuf); - - if(sbuf->map.writing) { - if(!sbuf->map.flush_explicit) { - /* No mapped range was flushed -- flush the whole buffer */ - SVGA_DBG(DEBUG_DMA, "flushing the whole buffer\n"); - - svga_buffer_add_range(sbuf, 0, sbuf->base.size); - } - - sbuf->map.writing = FALSE; - sbuf->map.flush_explicit = FALSE; - } - - pipe_mutex_unlock(ss->swc_mutex); -} - -static void -svga_buffer_destroy( struct pipe_buffer *buf ) -{ - struct svga_screen *ss = svga_screen(buf->screen); - struct svga_buffer *sbuf = svga_buffer( buf ); - - assert(!p_atomic_read(&buf->reference.count)); - - assert(!sbuf->dma.pending); - - if(sbuf->handle) - svga_buffer_destroy_host_surface(ss, sbuf); - - if(sbuf->uploaded.buffer) - pipe_buffer_reference(&sbuf->uploaded.buffer, NULL); - - if(sbuf->hwbuf) - svga_buffer_destroy_hw_storage(ss, sbuf); - - if(sbuf->swbuf && !sbuf->user) - align_free(sbuf->swbuf); - - FREE(sbuf); -} - -static struct pipe_buffer * -svga_buffer_create(struct pipe_screen *screen, - unsigned alignment, - unsigned usage, - unsigned size) -{ - struct svga_screen *ss = svga_screen(screen); - struct svga_buffer *sbuf; - - assert(size); - assert(alignment); - - sbuf = CALLOC_STRUCT(svga_buffer); - if(!sbuf) - goto error1; - - sbuf->magic = SVGA_BUFFER_MAGIC; - - pipe_reference_init(&sbuf->base.reference, 1); - sbuf->base.screen = screen; - sbuf->base.alignment = alignment; - sbuf->base.usage = usage; - sbuf->base.size = size; - - if(svga_buffer_needs_hw_storage(usage)) { - if(svga_buffer_create_host_surface(ss, sbuf) != PIPE_OK) - goto error2; - } - else { - if(alignment < sizeof(void*)) - alignment = sizeof(void*); - - usage |= PIPE_BUFFER_USAGE_CPU_READ_WRITE; - - sbuf->swbuf = align_malloc(size, alignment); - if(!sbuf->swbuf) - goto error2; - } - - return &sbuf->base; - -error2: - FREE(sbuf); -error1: - return NULL; -} - -static struct pipe_buffer * -svga_user_buffer_create(struct pipe_screen *screen, - void *ptr, - unsigned bytes) -{ - struct svga_buffer *sbuf; - - sbuf = CALLOC_STRUCT(svga_buffer); - if(!sbuf) - goto no_sbuf; - - sbuf->magic = SVGA_BUFFER_MAGIC; - - sbuf->swbuf = ptr; - sbuf->user = TRUE; - - pipe_reference_init(&sbuf->base.reference, 1); - sbuf->base.screen = screen; - sbuf->base.alignment = 1; - sbuf->base.usage = 0; - sbuf->base.size = bytes; - - return &sbuf->base; - -no_sbuf: - return NULL; -} - - -void -svga_screen_init_buffer_functions(struct pipe_screen *screen) -{ - screen->buffer_create = svga_buffer_create; - screen->user_buffer_create = svga_user_buffer_create; - screen->buffer_map_range = svga_buffer_map_range; - screen->buffer_flush_mapped_range = svga_buffer_flush_mapped_range; - screen->buffer_unmap = svga_buffer_unmap; - screen->buffer_destroy = svga_buffer_destroy; -} - /** * Copy the contents of the malloc buffer to a hardware buffer. @@ -645,7 +423,7 @@ svga_buffer_update_hw(struct svga_screen *ss, struct svga_buffer *sbuf) return PIPE_ERROR; } - memcpy(map, sbuf->swbuf, sbuf->base.size); + memcpy(map, sbuf->swbuf, sbuf->b.b.width0); ss->sws->buffer_unmap(ss->sws, sbuf->hwbuf); /* This user/malloc buffer is now indistinguishable from a gpu buffer */ @@ -710,8 +488,8 @@ svga_buffer_upload_piecewise(struct svga_screen *ss, offset, offset + size); map = sws->buffer_map(sws, hwbuf, - PIPE_BUFFER_USAGE_CPU_WRITE | - PIPE_BUFFER_USAGE_DISCARD); + PIPE_TRANSFER_WRITE | + PIPE_TRANSFER_DISCARD); assert(map); if (map) { memcpy(map, sbuf->swbuf, size); @@ -745,9 +523,14 @@ svga_buffer_upload_piecewise(struct svga_screen *ss, } + + +/* Get (or create/upload) the winsys surface handle so that we can + * refer to this buffer in fifo commands. + */ struct svga_winsys_surface * svga_buffer_handle(struct svga_context *svga, - struct pipe_buffer *buf) + struct pipe_resource *buf) { struct pipe_screen *screen = svga->pipe.screen; struct svga_screen *ss = svga_screen(screen); @@ -828,45 +611,6 @@ svga_buffer_handle(struct svga_context *svga, } -struct pipe_buffer * -svga_screen_buffer_wrap_surface(struct pipe_screen *screen, - enum SVGA3dSurfaceFormat format, - struct svga_winsys_surface *srf) -{ - struct pipe_buffer *buf; - struct svga_buffer *sbuf; - struct svga_winsys_screen *sws = svga_winsys_screen(screen); - - buf = svga_buffer_create(screen, 0, SVGA_BUFFER_USAGE_WRAPPED, 0); - if (!buf) - return NULL; - - sbuf = svga_buffer(buf); - - /* - * We are not the creator of this surface and therefore we must not - * cache it for reuse. Set the cacheable flag to zero in the key to - * prevent this. - */ - sbuf->key.format = format; - sbuf->key.cachable = 0; - sws->surface_reference(sws, &sbuf->handle, srf); - - return buf; -} - - -struct svga_winsys_surface * -svga_screen_buffer_get_winsys_surface(struct pipe_buffer *buffer) -{ - struct svga_winsys_screen *sws = svga_winsys_screen(buffer->screen); - struct svga_winsys_surface *vsurf = NULL; - - assert(svga_buffer(buffer)->key.cachable == 0); - svga_buffer(buffer)->key.cachable = 0; - sws->surface_reference(sws, &vsurf, svga_buffer(buffer)->handle); - return vsurf; -} void svga_context_flush_buffers(struct svga_context *svga) @@ -879,7 +623,7 @@ svga_context_flush_buffers(struct svga_context *svga) while(curr != &svga->dirty_buffers) { sbuf = LIST_ENTRY(struct svga_buffer, curr, head); - assert(p_atomic_read(&sbuf->base.reference.count) != 0); + assert(p_atomic_read(&sbuf->b.b.reference.count) != 0); assert(sbuf->dma.pending); svga_buffer_upload_flush(svga, sbuf); diff --git a/src/gallium/drivers/svga/svga_resource_buffer_upload.h b/src/gallium/drivers/svga/svga_resource_buffer_upload.h new file mode 100644 index 0000000000..11df306526 --- /dev/null +++ b/src/gallium/drivers/svga/svga_resource_buffer_upload.h @@ -0,0 +1,54 @@ +/********************************************************** + * Copyright 2008-2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +#ifndef SVGA_BUFFER_UPLOAD_H +#define SVGA_BUFFER_UPLOAD_H + + +void +svga_buffer_add_range(struct svga_buffer *sbuf, + unsigned start, + unsigned end); + +enum pipe_error +svga_buffer_create_hw_storage(struct svga_screen *ss, + struct svga_buffer *sbuf); + +void +svga_buffer_destroy_hw_storage(struct svga_screen *ss, + struct svga_buffer *sbuf); + +enum pipe_error +svga_buffer_create_host_surface(struct svga_screen *ss, + struct svga_buffer *sbuf); + +void +svga_buffer_destroy_host_surface(struct svga_screen *ss, + struct svga_buffer *sbuf); + + + + +#endif /* SVGA_BUFFER_H */ diff --git a/src/gallium/drivers/svga/svga_resource_texture.c b/src/gallium/drivers/svga/svga_resource_texture.c new file mode 100644 index 0000000000..a288aa589e --- /dev/null +++ b/src/gallium/drivers/svga/svga_resource_texture.c @@ -0,0 +1,635 @@ +/********************************************************** + * Copyright 2008-2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +#include "svga_cmd.h" + +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "os/os_thread.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "svga_screen.h" +#include "svga_context.h" +#include "svga_resource_texture.h" +#include "svga_resource_buffer.h" +#include "svga_sampler_view.h" +#include "svga_winsys.h" +#include "svga_debug.h" + +#include <util/u_string.h> + + +/* XXX: This isn't a real hardware flag, but just a hack for kernel to + * know about primary surfaces. Find a better way to accomplish this. + */ +#define SVGA3D_SURFACE_HINT_SCANOUT (1 << 9) + + +static unsigned int +svga_texture_is_referenced( struct pipe_context *pipe, + struct pipe_resource *texture, + unsigned face, unsigned level) +{ + struct svga_texture *tex = svga_texture(texture); + struct svga_screen *ss = svga_screen(pipe->screen); + + /** + * The screen does not cache texture writes. + */ + + if (!tex->handle || ss->sws->surface_is_flushed(ss->sws, tex->handle)) + return PIPE_UNREFERENCED; + + /** + * sws->surface_is_flushed() does not distinguish between read references + * and write references. So assume a reference is both. + */ + + return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE; +} + + + +/* + * Helper function and arrays + */ + +SVGA3dSurfaceFormat +svga_translate_format(enum pipe_format format) +{ + switch(format) { + + case PIPE_FORMAT_B8G8R8A8_UNORM: + return SVGA3D_A8R8G8B8; + case PIPE_FORMAT_B8G8R8X8_UNORM: + return SVGA3D_X8R8G8B8; + + /* Required for GL2.1: + */ + case PIPE_FORMAT_B8G8R8A8_SRGB: + return SVGA3D_A8R8G8B8; + + case PIPE_FORMAT_B5G6R5_UNORM: + return SVGA3D_R5G6B5; + case PIPE_FORMAT_B5G5R5A1_UNORM: + return SVGA3D_A1R5G5B5; + case PIPE_FORMAT_B4G4R4A4_UNORM: + return SVGA3D_A4R4G4B4; + + + /* XXX: Doesn't seem to work properly. + case PIPE_FORMAT_Z32_UNORM: + return SVGA3D_Z_D32; + */ + case PIPE_FORMAT_Z16_UNORM: + return SVGA3D_Z_D16; + case PIPE_FORMAT_S8Z24_UNORM: + return SVGA3D_Z_D24S8; + case PIPE_FORMAT_X8Z24_UNORM: + return SVGA3D_Z_D24X8; + + case PIPE_FORMAT_A8_UNORM: + return SVGA3D_ALPHA8; + case PIPE_FORMAT_L8_UNORM: + return SVGA3D_LUMINANCE8; + + case PIPE_FORMAT_DXT1_RGB: + case PIPE_FORMAT_DXT1_RGBA: + return SVGA3D_DXT1; + case PIPE_FORMAT_DXT3_RGBA: + return SVGA3D_DXT3; + case PIPE_FORMAT_DXT5_RGBA: + return SVGA3D_DXT5; + + default: + return SVGA3D_FORMAT_INVALID; + } +} + + +SVGA3dSurfaceFormat +svga_translate_format_render(enum pipe_format format) +{ + switch(format) { + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_Z32_UNORM: + case PIPE_FORMAT_Z16_UNORM: + case PIPE_FORMAT_L8_UNORM: + return svga_translate_format(format); + +#if 1 + /* For on host conversion */ + case PIPE_FORMAT_DXT1_RGB: + return SVGA3D_X8R8G8B8; + case PIPE_FORMAT_DXT1_RGBA: + case PIPE_FORMAT_DXT3_RGBA: + case PIPE_FORMAT_DXT5_RGBA: + return SVGA3D_A8R8G8B8; +#endif + + default: + return SVGA3D_FORMAT_INVALID; + } +} + + +static INLINE void +svga_transfer_dma_band(struct svga_transfer *st, + SVGA3dTransferType transfer, + unsigned y, unsigned h, unsigned srcy) +{ + struct svga_texture *texture = svga_texture(st->base.resource); + struct svga_screen *screen = svga_screen(texture->b.b.screen); + SVGA3dCopyBox box; + enum pipe_error ret; + + SVGA_DBG(DEBUG_DMA, "dma %s sid %p, face %u, (%u, %u, %u) - (%u, %u, %u), %ubpp\n", + transfer == SVGA3D_WRITE_HOST_VRAM ? "to" : "from", + texture->handle, + st->base.sr.face, + st->base.box.x, + y, + st->base.box.z, + st->base.box.x + st->base.box.width, + y + h, + st->base.box.z + 1, + util_format_get_blocksize(texture->b.b.format) * 8 / + (util_format_get_blockwidth(texture->b.b.format)*util_format_get_blockheight(texture->b.b.format))); + + box.x = st->base.box.x; + box.y = y; + box.z = st->base.box.z; + box.w = st->base.box.width; + box.h = h; + box.d = 1; + box.srcx = 0; + box.srcy = srcy; + box.srcz = 0; + + pipe_mutex_lock(screen->swc_mutex); + ret = SVGA3D_SurfaceDMA(screen->swc, st, transfer, &box, 1); + if(ret != PIPE_OK) { + screen->swc->flush(screen->swc, NULL); + ret = SVGA3D_SurfaceDMA(screen->swc, st, transfer, &box, 1); + assert(ret == PIPE_OK); + } + pipe_mutex_unlock(screen->swc_mutex); +} + + +static INLINE void +svga_transfer_dma(struct svga_transfer *st, + SVGA3dTransferType transfer) +{ + struct svga_texture *texture = svga_texture(st->base.resource); + struct svga_screen *screen = svga_screen(texture->b.b.screen); + struct svga_winsys_screen *sws = screen->sws; + struct pipe_fence_handle *fence = NULL; + + if (transfer == SVGA3D_READ_HOST_VRAM) { + SVGA_DBG(DEBUG_PERF, "%s: readback transfer\n", __FUNCTION__); + } + + + if(!st->swbuf) { + /* Do the DMA transfer in a single go */ + + svga_transfer_dma_band(st, transfer, st->base.box.y, st->base.box.height, 0); + + if(transfer == SVGA3D_READ_HOST_VRAM) { + svga_screen_flush(screen, &fence); + sws->fence_finish(sws, fence, 0); + sws->fence_reference(sws, &fence, NULL); + } + } + else { + unsigned y, h, srcy; + unsigned blockheight = util_format_get_blockheight(st->base.resource->format); + h = st->hw_nblocksy * blockheight; + srcy = 0; + for(y = 0; y < st->base.box.height; y += h) { + unsigned offset, length; + void *hw, *sw; + + if (y + h > st->base.box.height) + h = st->base.box.height - y; + + /* Transfer band must be aligned to pixel block boundaries */ + assert(y % blockheight == 0); + assert(h % blockheight == 0); + + offset = y * st->base.stride / blockheight; + length = h * st->base.stride / blockheight; + + sw = (uint8_t *)st->swbuf + offset; + + if(transfer == SVGA3D_WRITE_HOST_VRAM) { + /* Wait for the previous DMAs to complete */ + /* TODO: keep one DMA (at half the size) in the background */ + if(y) { + svga_screen_flush(screen, &fence); + sws->fence_finish(sws, fence, 0); + sws->fence_reference(sws, &fence, NULL); + } + + hw = sws->buffer_map(sws, st->hwbuf, PIPE_BUFFER_USAGE_CPU_WRITE); + assert(hw); + if(hw) { + memcpy(hw, sw, length); + sws->buffer_unmap(sws, st->hwbuf); + } + } + + svga_transfer_dma_band(st, transfer, y, h, srcy); + + if(transfer == SVGA3D_READ_HOST_VRAM) { + svga_screen_flush(screen, &fence); + sws->fence_finish(sws, fence, 0); + + hw = sws->buffer_map(sws, st->hwbuf, PIPE_BUFFER_USAGE_CPU_READ); + assert(hw); + if(hw) { + memcpy(sw, hw, length); + sws->buffer_unmap(sws, st->hwbuf); + } + } + } + } +} + + + + + +static boolean +svga_texture_get_handle(struct pipe_screen *screen, + struct pipe_resource *texture, + struct winsys_handle *whandle) +{ + struct svga_winsys_screen *sws = svga_winsys_screen(texture->screen); + unsigned stride; + + assert(svga_texture(texture)->key.cachable == 0); + svga_texture(texture)->key.cachable = 0; + stride = util_format_get_nblocksx(texture->format, texture->width0) * + util_format_get_blocksize(texture->format); + return sws->surface_get_handle(sws, svga_texture(texture)->handle, stride, whandle); +} + + +static void +svga_texture_destroy(struct pipe_screen *screen, + struct pipe_resource *pt) +{ + struct svga_screen *ss = svga_screen(screen); + struct svga_texture *tex = (struct svga_texture *)pt; + + ss->texture_timestamp++; + + svga_sampler_view_reference(&tex->cached_view, NULL); + + /* + DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); + */ + SVGA_DBG(DEBUG_DMA, "unref sid %p (texture)\n", tex->handle); + svga_screen_surface_destroy(ss, &tex->key, &tex->handle); + + FREE(tex); +} + + + + + + + +/* XXX: Still implementing this as if it was a screen function, but + * can now modify it to queue transfers on the context. + */ +static struct pipe_transfer * +svga_texture_get_transfer(struct pipe_context *pipe, + struct pipe_resource *texture, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box) +{ + struct svga_screen *ss = svga_screen(pipe->screen); + struct svga_winsys_screen *sws = ss->sws; + struct svga_transfer *st; + unsigned nblocksx = util_format_get_nblocksx(texture->format, box->width); + unsigned nblocksy = util_format_get_nblocksy(texture->format, box->height); + + /* We can't map texture storage directly */ + if (usage & PIPE_TRANSFER_MAP_DIRECTLY) + return NULL; + + st = CALLOC_STRUCT(svga_transfer); + if (!st) + return NULL; + + pipe_resource_reference(&st->base.resource, texture); + st->base.sr = sr; + st->base.usage = usage; + st->base.box = *box; + st->base.stride = nblocksx*util_format_get_blocksize(texture->format); + st->base.slice_stride = 0; + + st->hw_nblocksy = nblocksy; + + st->hwbuf = svga_winsys_buffer_create(ss, + 1, + 0, + st->hw_nblocksy*st->base.stride); + while(!st->hwbuf && (st->hw_nblocksy /= 2)) { + st->hwbuf = svga_winsys_buffer_create(ss, + 1, + 0, + st->hw_nblocksy*st->base.stride); + } + + if(!st->hwbuf) + goto no_hwbuf; + + if(st->hw_nblocksy < nblocksy) { + /* We couldn't allocate a hardware buffer big enough for the transfer, + * so allocate regular malloc memory instead */ + debug_printf("%s: failed to allocate %u KB of DMA, splitting into %u x %u KB DMA transfers\n", + __FUNCTION__, + (nblocksy*st->base.stride + 1023)/1024, + (nblocksy + st->hw_nblocksy - 1)/st->hw_nblocksy, + (st->hw_nblocksy*st->base.stride + 1023)/1024); + st->swbuf = MALLOC(nblocksy*st->base.stride); + if(!st->swbuf) + goto no_swbuf; + } + + if (usage & PIPE_TRANSFER_READ) + svga_transfer_dma(st, SVGA3D_READ_HOST_VRAM); + + return &st->base; + +no_swbuf: + sws->buffer_destroy(sws, st->hwbuf); +no_hwbuf: + FREE(st); + return NULL; +} + + +/* XXX: Still implementing this as if it was a screen function, but + * can now modify it to queue transfers on the context. + */ +static void * +svga_texture_transfer_map( struct pipe_context *pipe, + struct pipe_transfer *transfer ) +{ + struct svga_screen *ss = svga_screen(pipe->screen); + struct svga_winsys_screen *sws = ss->sws; + struct svga_transfer *st = svga_transfer(transfer); + + if(st->swbuf) + return st->swbuf; + else + /* The wait for read transfers already happened when svga_transfer_dma + * was called. */ + return sws->buffer_map(sws, st->hwbuf, transfer->usage); +} + + +/* XXX: Still implementing this as if it was a screen function, but + * can now modify it to queue transfers on the context. + */ +static void +svga_texture_transfer_unmap(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct svga_screen *ss = svga_screen(pipe->screen); + struct svga_winsys_screen *sws = ss->sws; + struct svga_transfer *st = svga_transfer(transfer); + + if(!st->swbuf) + sws->buffer_unmap(sws, st->hwbuf); +} + + +static void +svga_texture_transfer_destroy(struct pipe_context *pipe, + struct pipe_transfer *transfer) +{ + struct svga_texture *tex = svga_texture(transfer->resource); + struct svga_screen *ss = svga_screen(pipe->screen); + struct svga_winsys_screen *sws = ss->sws; + struct svga_transfer *st = svga_transfer(transfer); + + if (st->base.usage & PIPE_TRANSFER_WRITE) { + svga_transfer_dma(st, SVGA3D_WRITE_HOST_VRAM); + ss->texture_timestamp++; + tex->view_age[transfer->sr.level] = ++(tex->age); + tex->defined[transfer->sr.face][transfer->sr.level] = TRUE; + } + + pipe_resource_reference(&st->base.resource, NULL); + FREE(st->swbuf); + sws->buffer_destroy(sws, st->hwbuf); + FREE(st); +} + + + + + +struct u_resource_vtbl svga_texture_vtbl = +{ + svga_texture_get_handle, /* get_handle */ + svga_texture_destroy, /* resource_destroy */ + svga_texture_is_referenced, /* is_resource_referenced */ + svga_texture_get_transfer, /* get_transfer */ + svga_texture_transfer_destroy, /* transfer_destroy */ + svga_texture_transfer_map, /* transfer_map */ + u_default_transfer_flush_region, /* transfer_flush_region */ + svga_texture_transfer_unmap, /* transfer_unmap */ + u_default_transfer_inline_write /* transfer_inline_write */ +}; + + + + +struct pipe_resource * +svga_texture_create(struct pipe_screen *screen, + const struct pipe_resource *template) +{ + struct svga_screen *svgascreen = svga_screen(screen); + struct svga_texture *tex = CALLOC_STRUCT(svga_texture); + + if (!tex) + goto error1; + + tex->b.b = *template; + tex->b.vtbl = &svga_texture_vtbl; + pipe_reference_init(&tex->b.b.reference, 1); + tex->b.b.screen = screen; + + assert(template->last_level < SVGA_MAX_TEXTURE_LEVELS); + if(template->last_level >= SVGA_MAX_TEXTURE_LEVELS) + goto error2; + + tex->key.flags = 0; + tex->key.size.width = template->width0; + tex->key.size.height = template->height0; + tex->key.size.depth = template->depth0; + + if(template->target == PIPE_TEXTURE_CUBE) { + tex->key.flags |= SVGA3D_SURFACE_CUBEMAP; + tex->key.numFaces = 6; + } + else { + tex->key.numFaces = 1; + } + + tex->key.cachable = 1; + + if(template->tex_usage & PIPE_TEXTURE_USAGE_SAMPLER) + tex->key.flags |= SVGA3D_SURFACE_HINT_TEXTURE; + + if(template->tex_usage & PIPE_TEXTURE_USAGE_DISPLAY_TARGET) { + tex->key.cachable = 0; + } + + if(template->tex_usage & PIPE_TEXTURE_USAGE_SHARED) { + tex->key.cachable = 0; + } + + if(template->tex_usage & PIPE_TEXTURE_USAGE_SCANOUT) { + tex->key.flags |= SVGA3D_SURFACE_HINT_SCANOUT; + tex->key.cachable = 0; + } + + /* + * XXX: Never pass the SVGA3D_SURFACE_HINT_RENDERTARGET hint. Mesa cannot + * know beforehand whether a texture will be used as a rendertarget or not + * and it always requests PIPE_TEXTURE_USAGE_RENDER_TARGET, therefore + * passing the SVGA3D_SURFACE_HINT_RENDERTARGET here defeats its purpose. + */ +#if 0 + if((template->tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) && + !util_format_is_compressed(template->format)) + tex->key.flags |= SVGA3D_SURFACE_HINT_RENDERTARGET; +#endif + + if(template->tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL) + tex->key.flags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL; + + tex->key.numMipLevels = template->last_level + 1; + + tex->key.format = svga_translate_format(template->format); + if(tex->key.format == SVGA3D_FORMAT_INVALID) + goto error2; + + SVGA_DBG(DEBUG_DMA, "surface_create for texture\n", tex->handle); + tex->handle = svga_screen_surface_create(svgascreen, &tex->key); + if (tex->handle) + SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture)\n", tex->handle); + + return &tex->b.b; + +error2: + FREE(tex); +error1: + return NULL; +} + + + + +struct pipe_resource * +svga_texture_from_handle(struct pipe_screen *screen, + const struct pipe_resource *template, + struct winsys_handle *whandle) +{ + struct svga_winsys_screen *sws = svga_winsys_screen(screen); + struct svga_winsys_surface *srf; + struct svga_texture *tex; + enum SVGA3dSurfaceFormat format = 0; + assert(screen); + + /* Only supports one type */ + if (template->target != PIPE_TEXTURE_2D || + template->last_level != 0 || + template->depth0 != 1) { + return NULL; + } + + srf = sws->surface_from_handle(sws, whandle, &format); + + if (!srf) + return NULL; + + if (svga_translate_format(template->format) != format) { + unsigned f1 = svga_translate_format(template->format); + unsigned f2 = format; + + /* It's okay for XRGB and ARGB or depth with/out stencil to get mixed up */ + if ( !( (f1 == SVGA3D_X8R8G8B8 && f2 == SVGA3D_A8R8G8B8) || + (f1 == SVGA3D_A8R8G8B8 && f2 == SVGA3D_X8R8G8B8) || + (f1 == SVGA3D_Z_D24X8 && f2 == SVGA3D_Z_D24S8) ) ) { + debug_printf("%s wrong format %u != %u\n", __FUNCTION__, f1, f2); + return NULL; + } + } + + tex = CALLOC_STRUCT(svga_texture); + if (!tex) + return NULL; + + tex->b.b = *template; + tex->b.vtbl = &svga_texture_vtbl; + pipe_reference_init(&tex->b.b.reference, 1); + tex->b.b.screen = screen; + + if (format == SVGA3D_X8R8G8B8) + tex->b.b.format = PIPE_FORMAT_B8G8R8X8_UNORM; + else if (format == SVGA3D_A8R8G8B8) + tex->b.b.format = PIPE_FORMAT_B8G8R8A8_UNORM; + else { + /* ?? */ + } + + SVGA_DBG(DEBUG_DMA, "wrap surface sid %p\n", srf); + + tex->key.cachable = 0; + tex->handle = srf; + + return &tex->b.b; +} + diff --git a/src/gallium/drivers/svga/svga_screen_texture.h b/src/gallium/drivers/svga/svga_resource_texture.h index 96d035b12d..631937f2eb 100644 --- a/src/gallium/drivers/svga/svga_screen_texture.h +++ b/src/gallium/drivers/svga/svga_resource_texture.h @@ -30,6 +30,7 @@ #include "pipe/p_compiler.h" #include "pipe/p_state.h" #include "util/u_inlines.h" +#include "util/u_transfer.h" #include "svga_screen_cache.h" struct pipe_context; @@ -42,41 +43,12 @@ enum SVGA3dSurfaceFormat; #define SVGA_MAX_TEXTURE_LEVELS 16 -/** - * A sampler's view into a texture - * - * We currently cache one sampler view on - * the texture and in there by holding a reference - * from the texture to the sampler view. - * - * Because of this we can not hold a refernce to the - * texture from the sampler view. So the user - * of the sampler views must make sure that the - * texture has a reference take for as long as - * the sampler view is refrenced. - * - * Just unreferencing the sampler_view before the - * texture is enough. - */ -struct svga_sampler_view -{ - struct pipe_reference reference; - - struct pipe_texture *texture; - - int min_lod; - int max_lod; - - unsigned age; - - struct svga_host_surface_cache_key key; - struct svga_winsys_surface *handle; -}; +extern struct u_resource_vtbl svga_texture_vtbl; struct svga_texture { - struct pipe_texture base; + struct u_resource b; boolean defined[6][SVGA_MAX_TEXTURE_LEVELS]; @@ -106,21 +78,9 @@ struct svga_texture }; -struct svga_surface -{ - struct pipe_surface base; - - struct svga_host_surface_cache_key key; - struct svga_winsys_surface *handle; - - unsigned real_face; - unsigned real_level; - unsigned real_zslice; - - boolean dirty; -}; - +/* Note this is only used for texture (not buffer) transfers: + */ struct svga_transfer { struct pipe_transfer base; @@ -136,18 +96,13 @@ struct svga_transfer }; -static INLINE struct svga_texture * -svga_texture(struct pipe_texture *texture) +static INLINE struct svga_texture *svga_texture( struct pipe_resource *resource ) { - return (struct svga_texture *)texture; + struct svga_texture *tex = (struct svga_texture *)resource; + assert(tex == NULL || tex->b.vtbl == &svga_texture_vtbl); + return tex; } -static INLINE struct svga_surface * -svga_surface(struct pipe_surface *surface) -{ - assert(surface); - return (struct svga_surface *)surface; -} static INLINE struct svga_transfer * svga_transfer(struct pipe_transfer *transfer) @@ -156,38 +111,18 @@ svga_transfer(struct pipe_transfer *transfer) return (struct svga_transfer *)transfer; } -extern struct svga_sampler_view * -svga_get_tex_sampler_view(struct pipe_context *pipe, - struct pipe_texture *pt, - unsigned min_lod, unsigned max_lod); - -void -svga_validate_sampler_view(struct svga_context *svga, struct svga_sampler_view *v); - -void -svga_destroy_sampler_view_priv(struct svga_sampler_view *v); -static INLINE void -svga_sampler_view_reference(struct svga_sampler_view **ptr, struct svga_sampler_view *v) -{ - struct svga_sampler_view *old = *ptr; - - if (pipe_reference(&(*ptr)->reference, &v->reference)) - svga_destroy_sampler_view_priv(old); - *ptr = v; -} -extern void -svga_propagate_surface(struct pipe_context *pipe, struct pipe_surface *surf); +struct pipe_resource * +svga_texture_create(struct pipe_screen *screen, + const struct pipe_resource *template); -extern boolean -svga_surface_needs_propagation(struct pipe_surface *surf); +struct pipe_resource * +svga_texture_from_handle(struct pipe_screen * screen, + const struct pipe_resource *template, + struct winsys_handle *whandle); -extern void -svga_screen_init_texture_functions(struct pipe_screen *screen); -void -svga_init_texture_functions(struct pipe_context *pipe); enum SVGA3dSurfaceFormat svga_translate_format(enum pipe_format format); diff --git a/src/gallium/drivers/svga/svga_sampler_view.c b/src/gallium/drivers/svga/svga_sampler_view.c new file mode 100644 index 0000000000..0019b8b062 --- /dev/null +++ b/src/gallium/drivers/svga/svga_sampler_view.c @@ -0,0 +1,199 @@ +/********************************************************** + * Copyright 2008-2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +#include "svga_cmd.h" + +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "os/os_thread.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "svga_screen.h" +#include "svga_context.h" +#include "svga_resource_texture.h" +#include "svga_sampler_view.h" +#include "svga_winsys.h" +#include "svga_debug.h" +#include "svga_surface.h" + +#include <util/u_string.h> + + +struct svga_sampler_view * +svga_get_tex_sampler_view(struct pipe_context *pipe, + struct pipe_resource *pt, + unsigned min_lod, unsigned max_lod) +{ + struct svga_screen *ss = svga_screen(pt->screen); + struct svga_texture *tex = svga_texture(pt); + struct svga_sampler_view *sv = NULL; + SVGA3dSurfaceFormat format = svga_translate_format(pt->format); + boolean view = TRUE; + + assert(pt); + assert(min_lod >= 0); + assert(min_lod <= max_lod); + assert(max_lod <= pt->last_level); + + + /* Is a view needed */ + { + /* + * Can't control max lod. For first level views and when we only + * look at one level we disable mip filtering to achive the same + * results as a view. + */ + if (min_lod == 0 && max_lod >= pt->last_level) + view = FALSE; + + if (util_format_is_compressed(pt->format) && view) { + format = svga_translate_format_render(pt->format); + } + + if (ss->debug.no_sampler_view) + view = FALSE; + + if (ss->debug.force_sampler_view) + view = TRUE; + } + + /* First try the cache */ + if (view) { + pipe_mutex_lock(ss->tex_mutex); + if (tex->cached_view && + tex->cached_view->min_lod == min_lod && + tex->cached_view->max_lod == max_lod) { + svga_sampler_view_reference(&sv, tex->cached_view); + pipe_mutex_unlock(ss->tex_mutex); + SVGA_DBG(DEBUG_VIEWS, "svga: Sampler view: reuse %p, %u %u, last %u\n", + pt, min_lod, max_lod, pt->last_level); + svga_validate_sampler_view(svga_context(pipe), sv); + return sv; + } + pipe_mutex_unlock(ss->tex_mutex); + } + + sv = CALLOC_STRUCT(svga_sampler_view); + pipe_reference_init(&sv->reference, 1); + pipe_resource_reference(&sv->texture, pt); + sv->min_lod = min_lod; + sv->max_lod = max_lod; + + /* No view needed just use the whole texture */ + if (!view) { + SVGA_DBG(DEBUG_VIEWS, + "svga: Sampler view: no %p, mips %u..%u, nr %u, size (%ux%ux%u), last %u\n", + pt, min_lod, max_lod, + max_lod - min_lod + 1, + pt->width0, + pt->height0, + pt->depth0, + pt->last_level); + sv->key.cachable = 0; + sv->handle = tex->handle; + return sv; + } + + SVGA_DBG(DEBUG_VIEWS, + "svga: Sampler view: yes %p, mips %u..%u, nr %u, size (%ux%ux%u), last %u\n", + pt, min_lod, max_lod, + max_lod - min_lod + 1, + pt->width0, + pt->height0, + pt->depth0, + pt->last_level); + + sv->age = tex->age; + sv->handle = svga_texture_view_surface(pipe, tex, format, + min_lod, + max_lod - min_lod + 1, + -1, -1, + &sv->key); + + if (!sv->handle) { + assert(0); + sv->key.cachable = 0; + sv->handle = tex->handle; + return sv; + } + + pipe_mutex_lock(ss->tex_mutex); + svga_sampler_view_reference(&tex->cached_view, sv); + pipe_mutex_unlock(ss->tex_mutex); + + return sv; +} + +void +svga_validate_sampler_view(struct svga_context *svga, struct svga_sampler_view *v) +{ + struct svga_texture *tex = svga_texture(v->texture); + unsigned numFaces; + unsigned age = 0; + int i, k; + + assert(svga); + + if (v->handle == tex->handle) + return; + + age = tex->age; + + if(tex->b.b.target == PIPE_TEXTURE_CUBE) + numFaces = 6; + else + numFaces = 1; + + for (i = v->min_lod; i <= v->max_lod; i++) { + for (k = 0; k < numFaces; k++) { + if (v->age < tex->view_age[i]) + svga_texture_copy_handle(svga, NULL, + tex->handle, 0, 0, 0, i, k, + v->handle, 0, 0, 0, i - v->min_lod, k, + u_minify(tex->b.b.width0, i), + u_minify(tex->b.b.height0, i), + u_minify(tex->b.b.depth0, i)); + } + } + + v->age = age; +} + +void +svga_destroy_sampler_view_priv(struct svga_sampler_view *v) +{ + struct svga_texture *tex = svga_texture(v->texture); + + if(v->handle != tex->handle) { + struct svga_screen *ss = svga_screen(v->texture->screen); + SVGA_DBG(DEBUG_DMA, "unref sid %p (sampler view)\n", v->handle); + svga_screen_surface_destroy(ss, &v->key, &v->handle); + } + pipe_resource_reference(&v->texture, NULL); + FREE(v); +} diff --git a/src/gallium/drivers/svga/svga_sampler_view.h b/src/gallium/drivers/svga/svga_sampler_view.h new file mode 100644 index 0000000000..e64665f2e5 --- /dev/null +++ b/src/gallium/drivers/svga/svga_sampler_view.h @@ -0,0 +1,97 @@ +/********************************************************** + * Copyright 2008-2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +#ifndef SVGA_SAMPLER_VIEW_H +#define SVGA_SAMPLER_VIEW_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "svga_screen_cache.h" + +struct pipe_context; +struct pipe_screen; +struct svga_context; +struct svga_winsys_surface; +enum SVGA3dSurfaceFormat; + + +/** + * A sampler's view into a texture + * + * We currently cache one sampler view on + * the texture and in there by holding a reference + * from the texture to the sampler view. + * + * Because of this we can not hold a refernce to the + * texture from the sampler view. So the user + * of the sampler views must make sure that the + * texture has a reference take for as long as + * the sampler view is refrenced. + * + * Just unreferencing the sampler_view before the + * texture is enough. + */ +struct svga_sampler_view +{ + struct pipe_reference reference; + + struct pipe_resource *texture; + + int min_lod; + int max_lod; + + unsigned age; + + struct svga_host_surface_cache_key key; + struct svga_winsys_surface *handle; +}; + + + +extern struct svga_sampler_view * +svga_get_tex_sampler_view(struct pipe_context *pipe, + struct pipe_resource *pt, + unsigned min_lod, unsigned max_lod); + +void +svga_validate_sampler_view(struct svga_context *svga, struct svga_sampler_view *v); + +void +svga_destroy_sampler_view_priv(struct svga_sampler_view *v); + +static INLINE void +svga_sampler_view_reference(struct svga_sampler_view **ptr, struct svga_sampler_view *v) +{ + struct svga_sampler_view *old = *ptr; + + if (pipe_reference(&(*ptr)->reference, &v->reference)) + svga_destroy_sampler_view_priv(old); + *ptr = v; +} + + +#endif diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c index 6022c38cfc..f64d8c3a7b 100644 --- a/src/gallium/drivers/svga/svga_screen.c +++ b/src/gallium/drivers/svga/svga_screen.c @@ -31,8 +31,9 @@ #include "svga_winsys.h" #include "svga_context.h" #include "svga_screen.h" -#include "svga_screen_texture.h" -#include "svga_screen_buffer.h" +#include "svga_resource_texture.h" +#include "svga_resource_buffer.h" +#include "svga_resource.h" #include "svga_debug.h" #include "svga3d_shaderdefs.h" @@ -397,8 +398,7 @@ svga_screen_create(struct svga_winsys_screen *sws) screen->fence_finish = svga_fence_finish; svgascreen->sws = sws; - svga_screen_init_texture_functions(screen); - svga_screen_init_buffer_functions(screen); + svga_init_screen_resource_functions(svgascreen); svgascreen->use_ps30 = sws->get_cap(sws, SVGA3D_DEVCAP_FRAGMENT_SHADER_VERSION, &result) && diff --git a/src/gallium/drivers/svga/svga_screen_texture.c b/src/gallium/drivers/svga/svga_screen_texture.c deleted file mode 100644 index 4a058eda88..0000000000 --- a/src/gallium/drivers/svga/svga_screen_texture.c +++ /dev/null @@ -1,1097 +0,0 @@ -/********************************************************** - * Copyright 2008-2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - -#include "svga_cmd.h" - -#include "pipe/p_state.h" -#include "pipe/p_defines.h" -#include "util/u_inlines.h" -#include "os/os_thread.h" -#include "util/u_format.h" -#include "util/u_math.h" -#include "util/u_memory.h" - -#include "svga_screen.h" -#include "svga_context.h" -#include "svga_screen_texture.h" -#include "svga_screen_buffer.h" -#include "svga_winsys.h" -#include "svga_debug.h" -#include "svga_screen_buffer.h" - - -/* XXX: This isn't a real hardware flag, but just a hack for kernel to - * know about primary surfaces. Find a better way to accomplish this. - */ -#define SVGA3D_SURFACE_HINT_SCANOUT (1 << 9) - - -/* - * Helper function and arrays - */ - -SVGA3dSurfaceFormat -svga_translate_format(enum pipe_format format) -{ - switch(format) { - - case PIPE_FORMAT_B8G8R8A8_UNORM: - return SVGA3D_A8R8G8B8; - case PIPE_FORMAT_B8G8R8X8_UNORM: - return SVGA3D_X8R8G8B8; - - /* Required for GL2.1: - */ - case PIPE_FORMAT_B8G8R8A8_SRGB: - return SVGA3D_A8R8G8B8; - - case PIPE_FORMAT_B5G6R5_UNORM: - return SVGA3D_R5G6B5; - case PIPE_FORMAT_B5G5R5A1_UNORM: - return SVGA3D_A1R5G5B5; - case PIPE_FORMAT_B4G4R4A4_UNORM: - return SVGA3D_A4R4G4B4; - - - /* XXX: Doesn't seem to work properly. - case PIPE_FORMAT_Z32_UNORM: - return SVGA3D_Z_D32; - */ - case PIPE_FORMAT_Z16_UNORM: - return SVGA3D_Z_D16; - case PIPE_FORMAT_S8Z24_UNORM: - return SVGA3D_Z_D24S8; - case PIPE_FORMAT_X8Z24_UNORM: - return SVGA3D_Z_D24X8; - - case PIPE_FORMAT_A8_UNORM: - return SVGA3D_ALPHA8; - case PIPE_FORMAT_L8_UNORM: - return SVGA3D_LUMINANCE8; - - case PIPE_FORMAT_DXT1_RGB: - case PIPE_FORMAT_DXT1_RGBA: - return SVGA3D_DXT1; - case PIPE_FORMAT_DXT3_RGBA: - return SVGA3D_DXT3; - case PIPE_FORMAT_DXT5_RGBA: - return SVGA3D_DXT5; - - default: - return SVGA3D_FORMAT_INVALID; - } -} - - -SVGA3dSurfaceFormat -svga_translate_format_render(enum pipe_format format) -{ - switch(format) { - case PIPE_FORMAT_B8G8R8A8_UNORM: - case PIPE_FORMAT_B8G8R8X8_UNORM: - case PIPE_FORMAT_B5G5R5A1_UNORM: - case PIPE_FORMAT_B4G4R4A4_UNORM: - case PIPE_FORMAT_B5G6R5_UNORM: - case PIPE_FORMAT_S8Z24_UNORM: - case PIPE_FORMAT_X8Z24_UNORM: - case PIPE_FORMAT_Z32_UNORM: - case PIPE_FORMAT_Z16_UNORM: - case PIPE_FORMAT_L8_UNORM: - return svga_translate_format(format); - -#if 1 - /* For on host conversion */ - case PIPE_FORMAT_DXT1_RGB: - return SVGA3D_X8R8G8B8; - case PIPE_FORMAT_DXT1_RGBA: - case PIPE_FORMAT_DXT3_RGBA: - case PIPE_FORMAT_DXT5_RGBA: - return SVGA3D_A8R8G8B8; -#endif - - default: - return SVGA3D_FORMAT_INVALID; - } -} - - -static INLINE void -svga_transfer_dma_band(struct svga_transfer *st, - SVGA3dTransferType transfer, - unsigned y, unsigned h, unsigned srcy) -{ - struct svga_texture *texture = svga_texture(st->base.texture); - struct svga_screen *screen = svga_screen(texture->base.screen); - SVGA3dCopyBox box; - enum pipe_error ret; - - SVGA_DBG(DEBUG_DMA, "dma %s sid %p, face %u, (%u, %u, %u) - (%u, %u, %u), %ubpp\n", - transfer == SVGA3D_WRITE_HOST_VRAM ? "to" : "from", - texture->handle, - st->base.face, - st->base.x, - y, - st->base.zslice, - st->base.x + st->base.width, - y + h, - st->base.zslice + 1, - util_format_get_blocksize(texture->base.format)*8/ - (util_format_get_blockwidth(texture->base.format)*util_format_get_blockheight(texture->base.format))); - - box.x = st->base.x; - box.y = y; - box.z = st->base.zslice; - box.w = st->base.width; - box.h = h; - box.d = 1; - box.srcx = 0; - box.srcy = srcy; - box.srcz = 0; - - pipe_mutex_lock(screen->swc_mutex); - ret = SVGA3D_SurfaceDMA(screen->swc, st, transfer, &box, 1); - if(ret != PIPE_OK) { - screen->swc->flush(screen->swc, NULL); - ret = SVGA3D_SurfaceDMA(screen->swc, st, transfer, &box, 1); - assert(ret == PIPE_OK); - } - pipe_mutex_unlock(screen->swc_mutex); -} - - -static INLINE void -svga_transfer_dma(struct svga_transfer *st, - SVGA3dTransferType transfer) -{ - struct svga_texture *texture = svga_texture(st->base.texture); - struct svga_screen *screen = svga_screen(texture->base.screen); - struct svga_winsys_screen *sws = screen->sws; - struct pipe_fence_handle *fence = NULL; - - if (transfer == SVGA3D_READ_HOST_VRAM) { - SVGA_DBG(DEBUG_PERF, "%s: readback transfer\n", __FUNCTION__); - } - - - if(!st->swbuf) { - /* Do the DMA transfer in a single go */ - - svga_transfer_dma_band(st, transfer, st->base.y, st->base.height, 0); - - if(transfer == SVGA3D_READ_HOST_VRAM) { - svga_screen_flush(screen, &fence); - sws->fence_finish(sws, fence, 0); - sws->fence_reference(sws, &fence, NULL); - } - } - else { - unsigned y, h, srcy; - unsigned blockheight = util_format_get_blockheight(st->base.texture->format); - h = st->hw_nblocksy * blockheight; - srcy = 0; - for(y = 0; y < st->base.height; y += h) { - unsigned offset, length; - void *hw, *sw; - - if (y + h > st->base.height) - h = st->base.height - y; - - /* Transfer band must be aligned to pixel block boundaries */ - assert(y % blockheight == 0); - assert(h % blockheight == 0); - - offset = y * st->base.stride / blockheight; - length = h * st->base.stride / blockheight; - - sw = (uint8_t *)st->swbuf + offset; - - if(transfer == SVGA3D_WRITE_HOST_VRAM) { - /* Wait for the previous DMAs to complete */ - /* TODO: keep one DMA (at half the size) in the background */ - if(y) { - svga_screen_flush(screen, &fence); - sws->fence_finish(sws, fence, 0); - sws->fence_reference(sws, &fence, NULL); - } - - hw = sws->buffer_map(sws, st->hwbuf, PIPE_BUFFER_USAGE_CPU_WRITE); - assert(hw); - if(hw) { - memcpy(hw, sw, length); - sws->buffer_unmap(sws, st->hwbuf); - } - } - - svga_transfer_dma_band(st, transfer, y, h, srcy); - - if(transfer == SVGA3D_READ_HOST_VRAM) { - svga_screen_flush(screen, &fence); - sws->fence_finish(sws, fence, 0); - - hw = sws->buffer_map(sws, st->hwbuf, PIPE_BUFFER_USAGE_CPU_READ); - assert(hw); - if(hw) { - memcpy(sw, hw, length); - sws->buffer_unmap(sws, st->hwbuf); - } - } - } - } -} - - -static struct pipe_texture * -svga_texture_create(struct pipe_screen *screen, - const struct pipe_texture *templat) -{ - struct svga_screen *svgascreen = svga_screen(screen); - struct svga_texture *tex = CALLOC_STRUCT(svga_texture); - unsigned width, height, depth; - unsigned level; - - if (!tex) - goto error1; - - tex->base = *templat; - pipe_reference_init(&tex->base.reference, 1); - tex->base.screen = screen; - - assert(templat->last_level < SVGA_MAX_TEXTURE_LEVELS); - if(templat->last_level >= SVGA_MAX_TEXTURE_LEVELS) - goto error2; - - width = templat->width0; - height = templat->height0; - depth = templat->depth0; - for(level = 0; level <= templat->last_level; ++level) { - width = u_minify(width, 1); - height = u_minify(height, 1); - depth = u_minify(depth, 1); - } - - tex->key.flags = 0; - tex->key.size.width = templat->width0; - tex->key.size.height = templat->height0; - tex->key.size.depth = templat->depth0; - - if(templat->target == PIPE_TEXTURE_CUBE) { - tex->key.flags |= SVGA3D_SURFACE_CUBEMAP; - tex->key.numFaces = 6; - } - else { - tex->key.numFaces = 1; - } - - tex->key.cachable = 1; - - if(templat->tex_usage & PIPE_TEXTURE_USAGE_SAMPLER) - tex->key.flags |= SVGA3D_SURFACE_HINT_TEXTURE; - - if(templat->tex_usage & PIPE_TEXTURE_USAGE_DISPLAY_TARGET) { - tex->key.cachable = 0; - } - - if(templat->tex_usage & PIPE_TEXTURE_USAGE_SHARED) { - tex->key.cachable = 0; - } - - if(templat->tex_usage & PIPE_TEXTURE_USAGE_SCANOUT) { - tex->key.flags |= SVGA3D_SURFACE_HINT_SCANOUT; - tex->key.cachable = 0; - } - - /* - * XXX: Never pass the SVGA3D_SURFACE_HINT_RENDERTARGET hint. Mesa cannot - * know beforehand whether a texture will be used as a rendertarget or not - * and it always requests PIPE_TEXTURE_USAGE_RENDER_TARGET, therefore - * passing the SVGA3D_SURFACE_HINT_RENDERTARGET here defeats its purpose. - */ -#if 0 - if((templat->tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) && - !util_format_is_compressed(templat->format)) - tex->key.flags |= SVGA3D_SURFACE_HINT_RENDERTARGET; -#endif - - if(templat->tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL) - tex->key.flags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL; - - tex->key.numMipLevels = templat->last_level + 1; - - tex->key.format = svga_translate_format(templat->format); - if(tex->key.format == SVGA3D_FORMAT_INVALID) - goto error2; - - SVGA_DBG(DEBUG_DMA, "surface_create for texture\n", tex->handle); - tex->handle = svga_screen_surface_create(svgascreen, &tex->key); - if (tex->handle) - SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture)\n", tex->handle); - - return &tex->base; - -error2: - FREE(tex); -error1: - return NULL; -} - - - - - -static struct pipe_texture * -svga_screen_texture_from_handle(struct pipe_screen *screen, - const struct pipe_texture *base, - struct winsys_handle *whandle) -{ - struct svga_winsys_screen *sws = svga_winsys_screen(screen); - struct svga_winsys_surface *srf; - struct svga_texture *tex; - enum SVGA3dSurfaceFormat format = 0; - assert(screen); - - /* Only supports one type */ - if (base->target != PIPE_TEXTURE_2D || - base->last_level != 0 || - base->depth0 != 1) { - return NULL; - } - - srf = sws->surface_from_handle(sws, whandle, &format); - - if (!srf) - return NULL; - - if (svga_translate_format(base->format) != format) { - unsigned f1 = svga_translate_format(base->format); - unsigned f2 = format; - - /* It's okay for XRGB and ARGB or depth with/out stencil to get mixed up */ - if ( !( (f1 == SVGA3D_X8R8G8B8 && f2 == SVGA3D_A8R8G8B8) || - (f1 == SVGA3D_A8R8G8B8 && f2 == SVGA3D_X8R8G8B8) || - (f1 == SVGA3D_Z_D24X8 && f2 == SVGA3D_Z_D24S8) ) ) { - debug_printf("%s wrong format %u != %u\n", __FUNCTION__, f1, f2); - return NULL; - } - } - - tex = CALLOC_STRUCT(svga_texture); - if (!tex) - return NULL; - - tex->base = *base; - - - if (format == 1) - tex->base.format = PIPE_FORMAT_B8G8R8X8_UNORM; - else if (format == 2) - tex->base.format = PIPE_FORMAT_B8G8R8A8_UNORM; - - pipe_reference_init(&tex->base.reference, 1); - tex->base.screen = screen; - - SVGA_DBG(DEBUG_DMA, "wrap surface sid %p\n", srf); - - tex->key.cachable = 0; - tex->handle = srf; - - return &tex->base; -} - - -static boolean -svga_screen_texture_get_handle(struct pipe_screen *screen, - struct pipe_texture *texture, - struct winsys_handle *whandle) -{ - struct svga_winsys_screen *sws = svga_winsys_screen(texture->screen); - unsigned stride; - - assert(svga_texture(texture)->key.cachable == 0); - svga_texture(texture)->key.cachable = 0; - stride = util_format_get_nblocksx(texture->format, texture->width0) * - util_format_get_blocksize(texture->format); - return sws->surface_get_handle(sws, svga_texture(texture)->handle, stride, whandle); -} - - -static void -svga_texture_destroy(struct pipe_texture *pt) -{ - struct svga_screen *ss = svga_screen(pt->screen); - struct svga_texture *tex = (struct svga_texture *)pt; - - ss->texture_timestamp++; - - svga_sampler_view_reference(&tex->cached_view, NULL); - - /* - DBG("%s deleting %p\n", __FUNCTION__, (void *) tex); - */ - SVGA_DBG(DEBUG_DMA, "unref sid %p (texture)\n", tex->handle); - svga_screen_surface_destroy(ss, &tex->key, &tex->handle); - - FREE(tex); -} - - -static void -svga_texture_copy_handle(struct svga_context *svga, - struct svga_screen *ss, - struct svga_winsys_surface *src_handle, - unsigned src_x, unsigned src_y, unsigned src_z, - unsigned src_level, unsigned src_face, - struct svga_winsys_surface *dst_handle, - unsigned dst_x, unsigned dst_y, unsigned dst_z, - unsigned dst_level, unsigned dst_face, - unsigned width, unsigned height, unsigned depth) -{ - struct svga_surface dst, src; - enum pipe_error ret; - SVGA3dCopyBox box, *boxes; - - assert(svga || ss); - - src.handle = src_handle; - src.real_level = src_level; - src.real_face = src_face; - src.real_zslice = 0; - - dst.handle = dst_handle; - dst.real_level = dst_level; - dst.real_face = dst_face; - dst.real_zslice = 0; - - box.x = dst_x; - box.y = dst_y; - box.z = dst_z; - box.w = width; - box.h = height; - box.d = depth; - box.srcx = src_x; - box.srcy = src_y; - box.srcz = src_z; - -/* - SVGA_DBG(DEBUG_VIEWS, "mipcopy src: %p %u (%ux%ux%u), dst: %p %u (%ux%ux%u)\n", - src_handle, src_level, src_x, src_y, src_z, - dst_handle, dst_level, dst_x, dst_y, dst_z); -*/ - - if (svga) { - ret = SVGA3D_BeginSurfaceCopy(svga->swc, - &src.base, - &dst.base, - &boxes, 1); - if(ret != PIPE_OK) { - svga_context_flush(svga, NULL); - ret = SVGA3D_BeginSurfaceCopy(svga->swc, - &src.base, - &dst.base, - &boxes, 1); - assert(ret == PIPE_OK); - } - *boxes = box; - SVGA_FIFOCommitAll(svga->swc); - } else { - pipe_mutex_lock(ss->swc_mutex); - ret = SVGA3D_BeginSurfaceCopy(ss->swc, - &src.base, - &dst.base, - &boxes, 1); - if(ret != PIPE_OK) { - ss->swc->flush(ss->swc, NULL); - ret = SVGA3D_BeginSurfaceCopy(ss->swc, - &src.base, - &dst.base, - &boxes, 1); - assert(ret == PIPE_OK); - } - *boxes = box; - SVGA_FIFOCommitAll(ss->swc); - pipe_mutex_unlock(ss->swc_mutex); - } -} - -static struct svga_winsys_surface * -svga_texture_view_surface(struct pipe_context *pipe, - struct svga_texture *tex, - SVGA3dSurfaceFormat format, - unsigned start_mip, - unsigned num_mip, - int face_pick, - int zslice_pick, - struct svga_host_surface_cache_key *key) /* OUT */ -{ - struct svga_screen *ss = svga_screen(tex->base.screen); - struct svga_winsys_surface *handle; - uint32_t i, j; - unsigned z_offset = 0; - - SVGA_DBG(DEBUG_PERF, - "svga: Create surface view: face %d zslice %d mips %d..%d\n", - face_pick, zslice_pick, start_mip, start_mip+num_mip-1); - - key->flags = 0; - key->format = format; - key->numMipLevels = num_mip; - key->size.width = u_minify(tex->base.width0, start_mip); - key->size.height = u_minify(tex->base.height0, start_mip); - key->size.depth = zslice_pick < 0 ? u_minify(tex->base.depth0, start_mip) : 1; - key->cachable = 1; - assert(key->size.depth == 1); - - if(tex->base.target == PIPE_TEXTURE_CUBE && face_pick < 0) { - key->flags |= SVGA3D_SURFACE_CUBEMAP; - key->numFaces = 6; - } else { - key->numFaces = 1; - } - - if(key->format == SVGA3D_FORMAT_INVALID) { - key->cachable = 0; - return NULL; - } - - SVGA_DBG(DEBUG_DMA, "surface_create for texture view\n"); - handle = svga_screen_surface_create(ss, key); - if (!handle) { - key->cachable = 0; - return NULL; - } - - SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture view)\n", handle); - - if (face_pick < 0) - face_pick = 0; - - if (zslice_pick >= 0) - z_offset = zslice_pick; - - for (i = 0; i < key->numMipLevels; i++) { - for (j = 0; j < key->numFaces; j++) { - if(tex->defined[j + face_pick][i + start_mip]) { - unsigned depth = (zslice_pick < 0 ? - u_minify(tex->base.depth0, i + start_mip) : - 1); - - svga_texture_copy_handle(svga_context(pipe), - ss, - tex->handle, - 0, 0, z_offset, - i + start_mip, - j + face_pick, - handle, 0, 0, 0, i, j, - u_minify(tex->base.width0, i + start_mip), - u_minify(tex->base.height0, i + start_mip), - depth); - } - } - } - - return handle; -} - - -static struct pipe_surface * -svga_get_tex_surface(struct pipe_screen *screen, - struct pipe_texture *pt, - unsigned face, unsigned level, unsigned zslice, - unsigned flags) -{ - struct svga_texture *tex = svga_texture(pt); - struct svga_surface *s; - boolean render = flags & PIPE_BUFFER_USAGE_GPU_WRITE ? TRUE : FALSE; - boolean view = FALSE; - SVGA3dSurfaceFormat format; - - s = CALLOC_STRUCT(svga_surface); - if (!s) - return NULL; - - pipe_reference_init(&s->base.reference, 1); - pipe_texture_reference(&s->base.texture, pt); - s->base.format = pt->format; - s->base.width = u_minify(pt->width0, level); - s->base.height = u_minify(pt->height0, level); - s->base.usage = flags; - s->base.level = level; - s->base.face = face; - s->base.zslice = zslice; - - if (!render) - format = svga_translate_format(pt->format); - else - format = svga_translate_format_render(pt->format); - - assert(format != SVGA3D_FORMAT_INVALID); - assert(!(flags & PIPE_BUFFER_USAGE_CPU_READ_WRITE)); - - - if (svga_screen(screen)->debug.force_surface_view) - view = TRUE; - - /* Currently only used for compressed textures */ - if (render && - format != svga_translate_format(pt->format)) { - view = TRUE; - } - - if (level != 0 && - svga_screen(screen)->debug.force_level_surface_view) - view = TRUE; - - if (pt->target == PIPE_TEXTURE_3D) - view = TRUE; - - if (svga_screen(screen)->debug.no_surface_view) - view = FALSE; - - if (view) { - SVGA_DBG(DEBUG_VIEWS, "svga: Surface view: yes %p, level %u face %u z %u, %p\n", - pt, level, face, zslice, s); - - s->handle = svga_texture_view_surface(NULL, tex, format, level, 1, face, zslice, - &s->key); - s->real_face = 0; - s->real_level = 0; - s->real_zslice = 0; - } else { - SVGA_DBG(DEBUG_VIEWS, "svga: Surface view: no %p, level %u, face %u, z %u, %p\n", - pt, level, face, zslice, s); - - memset(&s->key, 0, sizeof s->key); - s->handle = tex->handle; - s->real_face = face; - s->real_level = level; - s->real_zslice = zslice; - } - - return &s->base; -} - - -static void -svga_tex_surface_destroy(struct pipe_surface *surf) -{ - struct svga_surface *s = svga_surface(surf); - struct svga_texture *t = svga_texture(surf->texture); - struct svga_screen *ss = svga_screen(surf->texture->screen); - - if(s->handle != t->handle) { - SVGA_DBG(DEBUG_DMA, "unref sid %p (tex surface)\n", s->handle); - svga_screen_surface_destroy(ss, &s->key, &s->handle); - } - - pipe_texture_reference(&surf->texture, NULL); - FREE(surf); -} - - -static INLINE void -svga_mark_surface_dirty(struct pipe_surface *surf) -{ - struct svga_surface *s = svga_surface(surf); - - if(!s->dirty) { - struct svga_texture *tex = svga_texture(surf->texture); - - s->dirty = TRUE; - - if (s->handle == tex->handle) - tex->defined[surf->face][surf->level] = TRUE; - else { - /* this will happen later in svga_propagate_surface */ - } - } -} - - -void svga_mark_surfaces_dirty(struct svga_context *svga) -{ - unsigned i; - - for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { - if (svga->curr.framebuffer.cbufs[i]) - svga_mark_surface_dirty(svga->curr.framebuffer.cbufs[i]); - } - if (svga->curr.framebuffer.zsbuf) - svga_mark_surface_dirty(svga->curr.framebuffer.zsbuf); -} - -/** - * Progagate any changes from surfaces to texture. - * pipe is optional context to inline the blit command in. - */ -void -svga_propagate_surface(struct pipe_context *pipe, struct pipe_surface *surf) -{ - struct svga_surface *s = svga_surface(surf); - struct svga_texture *tex = svga_texture(surf->texture); - struct svga_screen *ss = svga_screen(surf->texture->screen); - - if (!s->dirty) - return; - - s->dirty = FALSE; - ss->texture_timestamp++; - tex->view_age[surf->level] = ++(tex->age); - - if (s->handle != tex->handle) { - SVGA_DBG(DEBUG_VIEWS, "svga: Surface propagate: tex %p, level %u, from %p\n", tex, surf->level, surf); - svga_texture_copy_handle(svga_context(pipe), ss, - s->handle, 0, 0, 0, s->real_level, s->real_face, - tex->handle, 0, 0, surf->zslice, surf->level, surf->face, - u_minify(tex->base.width0, surf->level), - u_minify(tex->base.height0, surf->level), 1); - tex->defined[surf->face][surf->level] = TRUE; - } -} - -/** - * Check if we should call svga_propagate_surface on the surface. - */ -extern boolean -svga_surface_needs_propagation(struct pipe_surface *surf) -{ - struct svga_surface *s = svga_surface(surf); - struct svga_texture *tex = svga_texture(surf->texture); - - return s->dirty && s->handle != tex->handle; -} - -/* XXX: Still implementing this as if it was a screen function, but - * can now modify it to queue transfers on the context. - */ -static struct pipe_transfer * -svga_get_tex_transfer(struct pipe_context *pipe, - struct pipe_texture *texture, - unsigned face, unsigned level, unsigned zslice, - enum pipe_transfer_usage usage, unsigned x, unsigned y, - unsigned w, unsigned h) -{ - struct svga_screen *ss = svga_screen(pipe->screen); - struct svga_winsys_screen *sws = ss->sws; - struct svga_transfer *st; - unsigned nblocksx = util_format_get_nblocksx(texture->format, w); - unsigned nblocksy = util_format_get_nblocksy(texture->format, h); - - /* We can't map texture storage directly */ - if (usage & PIPE_TRANSFER_MAP_DIRECTLY) - return NULL; - - st = CALLOC_STRUCT(svga_transfer); - if (!st) - return NULL; - - st->base.x = x; - st->base.y = y; - st->base.width = w; - st->base.height = h; - st->base.stride = nblocksx*util_format_get_blocksize(texture->format); - st->base.usage = usage; - st->base.face = face; - st->base.level = level; - st->base.zslice = zslice; - - st->hw_nblocksy = nblocksy; - - st->hwbuf = svga_winsys_buffer_create(ss, - 1, - 0, - st->hw_nblocksy*st->base.stride); - while(!st->hwbuf && (st->hw_nblocksy /= 2)) { - st->hwbuf = svga_winsys_buffer_create(ss, - 1, - 0, - st->hw_nblocksy*st->base.stride); - } - - if(!st->hwbuf) - goto no_hwbuf; - - if(st->hw_nblocksy < nblocksy) { - /* We couldn't allocate a hardware buffer big enough for the transfer, - * so allocate regular malloc memory instead */ - debug_printf("%s: failed to allocate %u KB of DMA, splitting into %u x %u KB DMA transfers\n", - __FUNCTION__, - (nblocksy*st->base.stride + 1023)/1024, - (nblocksy + st->hw_nblocksy - 1)/st->hw_nblocksy, - (st->hw_nblocksy*st->base.stride + 1023)/1024); - st->swbuf = MALLOC(nblocksy*st->base.stride); - if(!st->swbuf) - goto no_swbuf; - } - - pipe_texture_reference(&st->base.texture, texture); - - if (usage & PIPE_TRANSFER_READ) - svga_transfer_dma(st, SVGA3D_READ_HOST_VRAM); - - return &st->base; - -no_swbuf: - sws->buffer_destroy(sws, st->hwbuf); -no_hwbuf: - FREE(st); - return NULL; -} - - -/* XXX: Still implementing this as if it was a screen function, but - * can now modify it to queue transfers on the context. - */ -static void * -svga_transfer_map( struct pipe_context *pipe, - struct pipe_transfer *transfer ) -{ - struct svga_screen *ss = svga_screen(pipe->screen); - struct svga_winsys_screen *sws = ss->sws; - struct svga_transfer *st = svga_transfer(transfer); - - if(st->swbuf) - return st->swbuf; - else - /* The wait for read transfers already happened when svga_transfer_dma - * was called. */ - return sws->buffer_map(sws, st->hwbuf, - pipe_transfer_buffer_flags(transfer)); -} - - -/* XXX: Still implementing this as if it was a screen function, but - * can now modify it to queue transfers on the context. - */ -static void -svga_transfer_unmap(struct pipe_context *pipe, - struct pipe_transfer *transfer) -{ - struct svga_screen *ss = svga_screen(pipe->screen); - struct svga_winsys_screen *sws = ss->sws; - struct svga_transfer *st = svga_transfer(transfer); - - if(!st->swbuf) - sws->buffer_unmap(sws, st->hwbuf); -} - - -static void -svga_tex_transfer_destroy(struct pipe_context *pipe, - struct pipe_transfer *transfer) -{ - struct svga_texture *tex = svga_texture(transfer->texture); - struct svga_screen *ss = svga_screen(pipe->screen); - struct svga_winsys_screen *sws = ss->sws; - struct svga_transfer *st = svga_transfer(transfer); - - if (st->base.usage & PIPE_TRANSFER_WRITE) { - svga_transfer_dma(st, SVGA3D_WRITE_HOST_VRAM); - ss->texture_timestamp++; - tex->view_age[transfer->level] = ++(tex->age); - tex->defined[transfer->face][transfer->level] = TRUE; - } - - pipe_texture_reference(&st->base.texture, NULL); - FREE(st->swbuf); - sws->buffer_destroy(sws, st->hwbuf); - FREE(st); -} - - -void -svga_init_texture_functions(struct pipe_context *pipe) -{ - pipe->get_tex_transfer = svga_get_tex_transfer; - pipe->transfer_map = svga_transfer_map; - pipe->transfer_unmap = svga_transfer_unmap; - pipe->tex_transfer_destroy = svga_tex_transfer_destroy; -} - - -void -svga_screen_init_texture_functions(struct pipe_screen *screen) -{ - screen->texture_create = svga_texture_create; - screen->texture_from_handle = svga_screen_texture_from_handle; - screen->texture_get_handle = svga_screen_texture_get_handle; - screen->texture_destroy = svga_texture_destroy; - screen->get_tex_surface = svga_get_tex_surface; - screen->tex_surface_destroy = svga_tex_surface_destroy; -} - -/*********************************************************************** - */ - -struct svga_sampler_view * -svga_get_tex_sampler_view(struct pipe_context *pipe, struct pipe_texture *pt, - unsigned min_lod, unsigned max_lod) -{ - struct svga_screen *ss = svga_screen(pt->screen); - struct svga_texture *tex = svga_texture(pt); - struct svga_sampler_view *sv = NULL; - SVGA3dSurfaceFormat format = svga_translate_format(pt->format); - boolean view = TRUE; - - assert(pt); - assert(min_lod >= 0); - assert(min_lod <= max_lod); - assert(max_lod <= pt->last_level); - - - /* Is a view needed */ - { - /* - * Can't control max lod. For first level views and when we only - * look at one level we disable mip filtering to achive the same - * results as a view. - */ - if (min_lod == 0 && max_lod >= pt->last_level) - view = FALSE; - - if (util_format_is_compressed(pt->format) && view) { - format = svga_translate_format_render(pt->format); - } - - if (ss->debug.no_sampler_view) - view = FALSE; - - if (ss->debug.force_sampler_view) - view = TRUE; - } - - /* First try the cache */ - if (view) { - pipe_mutex_lock(ss->tex_mutex); - if (tex->cached_view && - tex->cached_view->min_lod == min_lod && - tex->cached_view->max_lod == max_lod) { - svga_sampler_view_reference(&sv, tex->cached_view); - pipe_mutex_unlock(ss->tex_mutex); - SVGA_DBG(DEBUG_VIEWS, "svga: Sampler view: reuse %p, %u %u, last %u\n", - pt, min_lod, max_lod, pt->last_level); - svga_validate_sampler_view(svga_context(pipe), sv); - return sv; - } - pipe_mutex_unlock(ss->tex_mutex); - } - - sv = CALLOC_STRUCT(svga_sampler_view); - pipe_reference_init(&sv->reference, 1); - pipe_texture_reference(&sv->texture, pt); - sv->min_lod = min_lod; - sv->max_lod = max_lod; - - /* No view needed just use the whole texture */ - if (!view) { - SVGA_DBG(DEBUG_VIEWS, - "svga: Sampler view: no %p, mips %u..%u, nr %u, size (%ux%ux%u), last %u\n", - pt, min_lod, max_lod, - max_lod - min_lod + 1, - pt->width0, - pt->height0, - pt->depth0, - pt->last_level); - sv->key.cachable = 0; - sv->handle = tex->handle; - return sv; - } - - SVGA_DBG(DEBUG_VIEWS, - "svga: Sampler view: yes %p, mips %u..%u, nr %u, size (%ux%ux%u), last %u\n", - pt, min_lod, max_lod, - max_lod - min_lod + 1, - pt->width0, - pt->height0, - pt->depth0, - pt->last_level); - - sv->age = tex->age; - sv->handle = svga_texture_view_surface(pipe, tex, format, - min_lod, - max_lod - min_lod + 1, - -1, -1, - &sv->key); - - if (!sv->handle) { - assert(0); - sv->key.cachable = 0; - sv->handle = tex->handle; - return sv; - } - - pipe_mutex_lock(ss->tex_mutex); - svga_sampler_view_reference(&tex->cached_view, sv); - pipe_mutex_unlock(ss->tex_mutex); - - return sv; -} - -void -svga_validate_sampler_view(struct svga_context *svga, struct svga_sampler_view *v) -{ - struct svga_texture *tex = svga_texture(v->texture); - unsigned numFaces; - unsigned age = 0; - int i, k; - - assert(svga); - - if (v->handle == tex->handle) - return; - - age = tex->age; - - if(tex->base.target == PIPE_TEXTURE_CUBE) - numFaces = 6; - else - numFaces = 1; - - for (i = v->min_lod; i <= v->max_lod; i++) { - for (k = 0; k < numFaces; k++) { - if (v->age < tex->view_age[i]) - svga_texture_copy_handle(svga, NULL, - tex->handle, 0, 0, 0, i, k, - v->handle, 0, 0, 0, i - v->min_lod, k, - u_minify(tex->base.width0, i), - u_minify(tex->base.height0, i), - u_minify(tex->base.depth0, i)); - } - } - - v->age = age; -} - -void -svga_destroy_sampler_view_priv(struct svga_sampler_view *v) -{ - struct svga_texture *tex = svga_texture(v->texture); - - if(v->handle != tex->handle) { - struct svga_screen *ss = svga_screen(v->texture->screen); - SVGA_DBG(DEBUG_DMA, "unref sid %p (sampler view)\n", v->handle); - svga_screen_surface_destroy(ss, &v->key, &v->handle); - } - pipe_texture_reference(&v->texture, NULL); - FREE(v); -} diff --git a/src/gallium/drivers/svga/svga_state_constants.c b/src/gallium/drivers/svga/svga_state_constants.c index 493f78a990..558031592f 100644 --- a/src/gallium/drivers/svga/svga_state_constants.c +++ b/src/gallium/drivers/svga/svga_state_constants.c @@ -82,7 +82,7 @@ static int emit_consts( struct svga_context *svga, int offset, int unit ) { - struct pipe_screen *screen = svga->pipe.screen; + struct pipe_transfer *transfer = NULL; unsigned count; const float (*data)[4] = NULL; unsigned i; @@ -91,11 +91,12 @@ static int emit_consts( struct svga_context *svga, if (svga->curr.cb[unit] == NULL) goto done; - count = svga->curr.cb[unit]->size / (4 * sizeof(float)); + count = svga->curr.cb[unit]->width0 / (4 * sizeof(float)); - data = (const float (*)[4])pipe_buffer_map(screen, + data = (const float (*)[4])pipe_buffer_map(&svga->pipe, svga->curr.cb[unit], - PIPE_BUFFER_USAGE_CPU_READ); + PIPE_BUFFER_USAGE_CPU_READ, + &transfer); if (data == NULL) { ret = PIPE_ERROR_OUT_OF_MEMORY; goto done; @@ -109,7 +110,7 @@ static int emit_consts( struct svga_context *svga, done: if (data) - pipe_buffer_unmap(screen, svga->curr.cb[unit]); + pipe_buffer_unmap(&svga->pipe, svga->curr.cb[unit], transfer); return ret; } @@ -137,7 +138,7 @@ static int emit_fs_consts( struct svga_context *svga, for (i = 0; i < key->num_textures; i++) { if (key->tex[i].unnormalized) { - struct pipe_texture *tex = svga->curr.sampler_views[i]->texture; + struct pipe_resource *tex = svga->curr.sampler_views[i]->texture; float data[4]; data[0] = 1.0 / (float)tex->width0; diff --git a/src/gallium/drivers/svga/svga_state_tss.c b/src/gallium/drivers/svga/svga_state_tss.c index c08ec7c2e8..a8d9f6d5c1 100644 --- a/src/gallium/drivers/svga/svga_state_tss.c +++ b/src/gallium/drivers/svga/svga_state_tss.c @@ -27,7 +27,7 @@ #include "pipe/p_defines.h" #include "util/u_math.h" -#include "svga_screen_texture.h" +#include "svga_sampler_view.h" #include "svga_winsys.h" #include "svga_context.h" #include "svga_state.h" @@ -45,7 +45,7 @@ void svga_cleanup_tss_binding(struct svga_context *svga) svga_sampler_view_reference(&view->v, NULL); pipe_sampler_view_reference( &svga->curr.sampler_views[i], NULL ); - pipe_texture_reference( &view->texture, NULL ); + pipe_resource_reference( &view->texture, NULL ); view->dirty = 1; } @@ -77,7 +77,7 @@ update_tss_binding(struct svga_context *svga, for (i = 0; i < count; i++) { const struct svga_sampler_state *s = svga->curr.sampler[i]; struct svga_hw_view_state *view = &svga->state.hw_draw.views[i]; - struct pipe_texture *texture = NULL; + struct pipe_resource *texture = NULL; /* get min max lod */ if (svga->curr.sampler_views[i]) { @@ -94,7 +94,7 @@ update_tss_binding(struct svga_context *svga, view->max_lod != max_lod) { svga_sampler_view_reference(&view->v, NULL); - pipe_texture_reference( &view->texture, texture ); + pipe_resource_reference( &view->texture, texture ); view->dirty = TRUE; view->min_lod = min_lod; diff --git a/src/gallium/drivers/svga/svga_state_vdecl.c b/src/gallium/drivers/svga/svga_state_vdecl.c index f531e22304..3af7bf2b35 100644 --- a/src/gallium/drivers/svga/svga_state_vdecl.c +++ b/src/gallium/drivers/svga/svga_state_vdecl.c @@ -33,7 +33,7 @@ #include "svga_draw.h" #include "svga_tgsi.h" #include "svga_screen.h" -#include "svga_screen_buffer.h" +#include "svga_resource_buffer.h" #include "svga_hw_reg.h" @@ -59,8 +59,8 @@ upload_user_buffers( struct svga_context *svga ) if (!buffer->uploaded.buffer) { ret = u_upload_buffer( svga->upload_vb, 0, - buffer->base.size, - &buffer->base, + buffer->b.b.width0, + &buffer->b.b, &buffer->uploaded.offset, &buffer->uploaded.buffer ); if (ret) @@ -73,10 +73,10 @@ upload_user_buffers( struct svga_context *svga ) buffer, buffer->uploaded.buffer, buffer->uploaded.offset, - buffer->base.size); + buffer->b.b.width0); } - pipe_buffer_reference( &svga->curr.vb[i].buffer, buffer->uploaded.buffer ); + pipe_resource_reference( &svga->curr.vb[i].buffer, buffer->uploaded.buffer ); svga->curr.vb[i].buffer_offset = buffer->uploaded.offset; } } diff --git a/src/gallium/drivers/svga/svga_state_vs.c b/src/gallium/drivers/svga/svga_state_vs.c index 781f7bf533..e9ed0f9d4f 100644 --- a/src/gallium/drivers/svga/svga_state_vs.c +++ b/src/gallium/drivers/svga/svga_state_vs.c @@ -190,9 +190,11 @@ static int update_zero_stride( struct svga_context *svga, const struct pipe_vertex_element *vel = &svga->curr.velems->velem[i]; const struct pipe_vertex_buffer *vbuffer = &svga->curr.vb[ vel->vertex_buffer_index]; + if (vbuffer->stride == 0) { unsigned const_idx = svga->curr.num_zero_stride_vertex_elements; + struct pipe_transfer *transfer; struct translate *translate; struct translate_key key; void *mapped_buffer; @@ -218,19 +220,23 @@ static int update_zero_stride( struct svga_context *svga, assert(vel->src_offset == 0); - mapped_buffer = pipe_buffer_map_range(svga->pipe.screen, + mapped_buffer = pipe_buffer_map_range(&svga->pipe, vbuffer->buffer, vel->src_offset, util_format_get_blocksize(vel->src_format), - PIPE_BUFFER_USAGE_CPU_READ); + PIPE_BUFFER_USAGE_CPU_READ, + &transfer); + translate->set_buffer(translate, vel->vertex_buffer_index, mapped_buffer, vbuffer->stride); translate->run(translate, 0, 1, 0, svga->curr.zero_stride_constants); - pipe_buffer_unmap(svga->pipe.screen, - vbuffer->buffer); + pipe_buffer_unmap(&svga->pipe, + vbuffer->buffer, + transfer); + translate->release(translate); } } diff --git a/src/gallium/drivers/svga/svga_surface.c b/src/gallium/drivers/svga/svga_surface.c new file mode 100644 index 0000000000..6051eb4e07 --- /dev/null +++ b/src/gallium/drivers/svga/svga_surface.c @@ -0,0 +1,384 @@ +/********************************************************** + * Copyright 2008-2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +#include "svga_cmd.h" + +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "os/os_thread.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "svga_screen.h" +#include "svga_context.h" +#include "svga_resource_texture.h" +#include "svga_surface.h" +#include "svga_winsys.h" +#include "svga_debug.h" + +#include <util/u_string.h> + + +void +svga_texture_copy_handle(struct svga_context *svga, + struct svga_screen *ss, + struct svga_winsys_surface *src_handle, + unsigned src_x, unsigned src_y, unsigned src_z, + unsigned src_level, unsigned src_face, + struct svga_winsys_surface *dst_handle, + unsigned dst_x, unsigned dst_y, unsigned dst_z, + unsigned dst_level, unsigned dst_face, + unsigned width, unsigned height, unsigned depth) +{ + struct svga_surface dst, src; + enum pipe_error ret; + SVGA3dCopyBox box, *boxes; + + assert(svga || ss); + + src.handle = src_handle; + src.real_level = src_level; + src.real_face = src_face; + src.real_zslice = 0; + + dst.handle = dst_handle; + dst.real_level = dst_level; + dst.real_face = dst_face; + dst.real_zslice = 0; + + box.x = dst_x; + box.y = dst_y; + box.z = dst_z; + box.w = width; + box.h = height; + box.d = depth; + box.srcx = src_x; + box.srcy = src_y; + box.srcz = src_z; + +/* + SVGA_DBG(DEBUG_VIEWS, "mipcopy src: %p %u (%ux%ux%u), dst: %p %u (%ux%ux%u)\n", + src_handle, src_level, src_x, src_y, src_z, + dst_handle, dst_level, dst_x, dst_y, dst_z); +*/ + + if (svga) { + ret = SVGA3D_BeginSurfaceCopy(svga->swc, + &src.base, + &dst.base, + &boxes, 1); + if(ret != PIPE_OK) { + svga_context_flush(svga, NULL); + ret = SVGA3D_BeginSurfaceCopy(svga->swc, + &src.base, + &dst.base, + &boxes, 1); + assert(ret == PIPE_OK); + } + *boxes = box; + SVGA_FIFOCommitAll(svga->swc); + } else { + pipe_mutex_lock(ss->swc_mutex); + ret = SVGA3D_BeginSurfaceCopy(ss->swc, + &src.base, + &dst.base, + &boxes, 1); + if(ret != PIPE_OK) { + ss->swc->flush(ss->swc, NULL); + ret = SVGA3D_BeginSurfaceCopy(ss->swc, + &src.base, + &dst.base, + &boxes, 1); + assert(ret == PIPE_OK); + } + *boxes = box; + SVGA_FIFOCommitAll(ss->swc); + pipe_mutex_unlock(ss->swc_mutex); + } +} + + +struct svga_winsys_surface * +svga_texture_view_surface(struct pipe_context *pipe, + struct svga_texture *tex, + SVGA3dSurfaceFormat format, + unsigned start_mip, + unsigned num_mip, + int face_pick, + int zslice_pick, + struct svga_host_surface_cache_key *key) /* OUT */ +{ + struct svga_screen *ss = svga_screen(pipe->screen); + struct svga_winsys_surface *handle; + uint32_t i, j; + unsigned z_offset = 0; + + SVGA_DBG(DEBUG_PERF, + "svga: Create surface view: face %d zslice %d mips %d..%d\n", + face_pick, zslice_pick, start_mip, start_mip+num_mip-1); + + key->flags = 0; + key->format = format; + key->numMipLevels = num_mip; + key->size.width = u_minify(tex->b.b.width0, start_mip); + key->size.height = u_minify(tex->b.b.height0, start_mip); + key->size.depth = zslice_pick < 0 ? u_minify(tex->b.b.depth0, start_mip) : 1; + key->cachable = 1; + assert(key->size.depth == 1); + + if(tex->b.b.target == PIPE_TEXTURE_CUBE && face_pick < 0) { + key->flags |= SVGA3D_SURFACE_CUBEMAP; + key->numFaces = 6; + } else { + key->numFaces = 1; + } + + if(key->format == SVGA3D_FORMAT_INVALID) { + key->cachable = 0; + return NULL; + } + + SVGA_DBG(DEBUG_DMA, "surface_create for texture view\n"); + handle = svga_screen_surface_create(ss, key); + if (!handle) { + key->cachable = 0; + return NULL; + } + + SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture view)\n", handle); + + if (face_pick < 0) + face_pick = 0; + + if (zslice_pick >= 0) + z_offset = zslice_pick; + + for (i = 0; i < key->numMipLevels; i++) { + for (j = 0; j < key->numFaces; j++) { + if(tex->defined[j + face_pick][i + start_mip]) { + unsigned depth = (zslice_pick < 0 ? + u_minify(tex->b.b.depth0, i + start_mip) : + 1); + + svga_texture_copy_handle(svga_context(pipe), + ss, + tex->handle, + 0, 0, z_offset, + i + start_mip, + j + face_pick, + handle, 0, 0, 0, i, j, + u_minify(tex->b.b.width0, i + start_mip), + u_minify(tex->b.b.height0, i + start_mip), + depth); + } + } + } + + return handle; +} + + +static struct pipe_surface * +svga_get_tex_surface(struct pipe_screen *screen, + struct pipe_resource *pt, + unsigned face, unsigned level, unsigned zslice, + unsigned flags) +{ + struct svga_texture *tex = svga_texture(pt); + struct svga_surface *s; + boolean render = flags & PIPE_BUFFER_USAGE_GPU_WRITE ? TRUE : FALSE; + boolean view = FALSE; + SVGA3dSurfaceFormat format; + + s = CALLOC_STRUCT(svga_surface); + if (!s) + return NULL; + + pipe_reference_init(&s->base.reference, 1); + pipe_resource_reference(&s->base.texture, pt); + s->base.format = pt->format; + s->base.width = u_minify(pt->width0, level); + s->base.height = u_minify(pt->height0, level); + s->base.usage = flags; + s->base.level = level; + s->base.face = face; + s->base.zslice = zslice; + + if (!render) + format = svga_translate_format(pt->format); + else + format = svga_translate_format_render(pt->format); + + assert(format != SVGA3D_FORMAT_INVALID); + assert(!(flags & PIPE_BUFFER_USAGE_CPU_READ_WRITE)); + + + if (svga_screen(screen)->debug.force_surface_view) + view = TRUE; + + /* Currently only used for compressed textures */ + if (render && + format != svga_translate_format(pt->format)) { + view = TRUE; + } + + if (level != 0 && + svga_screen(screen)->debug.force_level_surface_view) + view = TRUE; + + if (pt->target == PIPE_TEXTURE_3D) + view = TRUE; + + if (svga_screen(screen)->debug.no_surface_view) + view = FALSE; + + if (view) { + SVGA_DBG(DEBUG_VIEWS, "svga: Surface view: yes %p, level %u face %u z %u, %p\n", + pt, level, face, zslice, s); + + s->handle = svga_texture_view_surface(NULL, tex, format, level, 1, face, zslice, + &s->key); + s->real_face = 0; + s->real_level = 0; + s->real_zslice = 0; + } else { + SVGA_DBG(DEBUG_VIEWS, "svga: Surface view: no %p, level %u, face %u, z %u, %p\n", + pt, level, face, zslice, s); + + memset(&s->key, 0, sizeof s->key); + s->handle = tex->handle; + s->real_face = face; + s->real_level = level; + s->real_zslice = zslice; + } + + return &s->base; +} + + +static void +svga_tex_surface_destroy(struct pipe_surface *surf) +{ + struct svga_surface *s = svga_surface(surf); + struct svga_texture *t = svga_texture(surf->texture); + struct svga_screen *ss = svga_screen(surf->texture->screen); + + if(s->handle != t->handle) { + SVGA_DBG(DEBUG_DMA, "unref sid %p (tex surface)\n", s->handle); + svga_screen_surface_destroy(ss, &s->key, &s->handle); + } + + pipe_resource_reference(&surf->texture, NULL); + FREE(surf); +} + + +static INLINE void +svga_mark_surface_dirty(struct pipe_surface *surf) +{ + struct svga_surface *s = svga_surface(surf); + + if(!s->dirty) { + struct svga_texture *tex = svga_texture(surf->texture); + + s->dirty = TRUE; + + if (s->handle == tex->handle) + tex->defined[surf->face][surf->level] = TRUE; + else { + /* this will happen later in svga_propagate_surface */ + } + } +} + + +void svga_mark_surfaces_dirty(struct svga_context *svga) +{ + unsigned i; + + for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + if (svga->curr.framebuffer.cbufs[i]) + svga_mark_surface_dirty(svga->curr.framebuffer.cbufs[i]); + } + if (svga->curr.framebuffer.zsbuf) + svga_mark_surface_dirty(svga->curr.framebuffer.zsbuf); +} + + +/** + * Progagate any changes from surfaces to texture. + * pipe is optional context to inline the blit command in. + */ +void +svga_propagate_surface(struct pipe_context *pipe, struct pipe_surface *surf) +{ + struct svga_surface *s = svga_surface(surf); + struct svga_texture *tex = svga_texture(surf->texture); + struct svga_screen *ss = svga_screen(surf->texture->screen); + + if (!s->dirty) + return; + + s->dirty = FALSE; + ss->texture_timestamp++; + tex->view_age[surf->level] = ++(tex->age); + + if (s->handle != tex->handle) { + SVGA_DBG(DEBUG_VIEWS, "svga: Surface propagate: tex %p, level %u, from %p\n", tex, surf->level, surf); + svga_texture_copy_handle(svga_context(pipe), ss, + s->handle, 0, 0, 0, s->real_level, s->real_face, + tex->handle, 0, 0, surf->zslice, surf->level, surf->face, + u_minify(tex->b.b.width0, surf->level), + u_minify(tex->b.b.height0, surf->level), 1); + tex->defined[surf->face][surf->level] = TRUE; + } +} + +/** + * Check if we should call svga_propagate_surface on the surface. + */ +boolean +svga_surface_needs_propagation(struct pipe_surface *surf) +{ + struct svga_surface *s = svga_surface(surf); + struct svga_texture *tex = svga_texture(surf->texture); + + return s->dirty && s->handle != tex->handle; +} + + + + + + +void +svga_screen_init_surface_functions(struct pipe_screen *screen) +{ + screen->get_tex_surface = svga_get_tex_surface; + screen->tex_surface_destroy = svga_tex_surface_destroy; +} + diff --git a/src/gallium/drivers/svga/svga_surface.h b/src/gallium/drivers/svga/svga_surface.h new file mode 100644 index 0000000000..b50ecdc994 --- /dev/null +++ b/src/gallium/drivers/svga/svga_surface.h @@ -0,0 +1,97 @@ +/********************************************************** + * Copyright 2008-2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +#ifndef SVGA_SURFACE_H +#define SVGA_SURFACE_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" +#include "svga_screen_cache.h" + +struct pipe_context; +struct pipe_screen; +struct svga_context; +struct svga_texture; +struct svga_winsys_surface; +enum SVGA3dSurfaceFormat; + + +struct svga_surface +{ + struct pipe_surface base; + + struct svga_host_surface_cache_key key; + struct svga_winsys_surface *handle; + + unsigned real_face; + unsigned real_level; + unsigned real_zslice; + + boolean dirty; +}; + + +extern void +svga_propagate_surface(struct pipe_context *pipe, struct pipe_surface *surf); + +extern boolean +svga_surface_needs_propagation(struct pipe_surface *surf); + +struct svga_winsys_surface * +svga_texture_view_surface(struct pipe_context *pipe, + struct svga_texture *tex, + SVGA3dSurfaceFormat format, + unsigned start_mip, + unsigned num_mip, + int face_pick, + int zslice_pick, + struct svga_host_surface_cache_key *key); /* OUT */ + + +void +svga_texture_copy_handle(struct svga_context *svga, + struct svga_screen *ss, + struct svga_winsys_surface *src_handle, + unsigned src_x, unsigned src_y, unsigned src_z, + unsigned src_level, unsigned src_face, + struct svga_winsys_surface *dst_handle, + unsigned dst_x, unsigned dst_y, unsigned dst_z, + unsigned dst_level, unsigned dst_face, + unsigned width, unsigned height, unsigned depth); + + +static INLINE struct svga_surface * +svga_surface(struct pipe_surface *surface) +{ + assert(surface); + return (struct svga_surface *)surface; +} + +void +svga_screen_init_surface_functions(struct pipe_screen *screen); + +#endif diff --git a/src/gallium/drivers/svga/svga_swtnl.h b/src/gallium/drivers/svga/svga_swtnl.h index 4882f26b17..096ed410b5 100644 --- a/src/gallium/drivers/svga/svga_swtnl.h +++ b/src/gallium/drivers/svga/svga_swtnl.h @@ -40,7 +40,7 @@ void svga_destroy_swtnl( struct svga_context *svga ); enum pipe_error svga_swtnl_draw_range_elements(struct svga_context *svga, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned min_index, unsigned max_index, diff --git a/src/gallium/drivers/svga/svga_swtnl_backend.c b/src/gallium/drivers/svga/svga_swtnl_backend.c index e9d7942fb5..29b1be1cc8 100644 --- a/src/gallium/drivers/svga/svga_swtnl_backend.c +++ b/src/gallium/drivers/svga/svga_swtnl_backend.c @@ -79,9 +79,9 @@ svga_vbuf_render_allocate_vertices( struct vbuf_render *render, new_vbuf = TRUE; if (new_vbuf) - pipe_buffer_reference(&svga_render->vbuf, NULL); + pipe_resource_reference(&svga_render->vbuf, NULL); if (new_ibuf) - pipe_buffer_reference(&svga_render->ibuf, NULL); + pipe_resource_reference(&svga_render->ibuf, NULL); if (!svga_render->vbuf) { svga_render->vbuf_size = MAX2(size, svga_render->vbuf_alloc_size); @@ -117,14 +117,14 @@ svga_vbuf_render_map_vertices( struct vbuf_render *render ) { struct svga_vbuf_render *svga_render = svga_vbuf_render(render); struct svga_context *svga = svga_render->svga; - struct pipe_screen *screen = svga->pipe.screen; - char *ptr = (char*)pipe_buffer_map(screen, + char *ptr = (char*)pipe_buffer_map(&svga->pipe, svga_render->vbuf, - PIPE_BUFFER_USAGE_CPU_WRITE | - PIPE_BUFFER_USAGE_FLUSH_EXPLICIT | - PIPE_BUFFER_USAGE_DISCARD | - PIPE_BUFFER_USAGE_UNSYNCHRONIZED); + PIPE_TRANSFER_WRITE | + PIPE_TRANSFER_FLUSH_EXPLICIT | + PIPE_TRANSFER_DISCARD | + PIPE_TRANSFER_UNSYNCHRONIZED, + &svga_render->vbuf_transfer); return ptr + svga_render->vbuf_offset; } @@ -135,14 +135,15 @@ svga_vbuf_render_unmap_vertices( struct vbuf_render *render, { struct svga_vbuf_render *svga_render = svga_vbuf_render(render); struct svga_context *svga = svga_render->svga; - struct pipe_screen *screen = svga->pipe.screen; unsigned offset, length; size_t used = svga_render->vertex_size * ((size_t)max_index + 1); offset = svga_render->vbuf_offset + svga_render->vertex_size * min_index; length = svga_render->vertex_size * (max_index + 1 - min_index); - pipe_buffer_flush_mapped_range(screen, svga_render->vbuf, offset, length); - pipe_buffer_unmap(screen, svga_render->vbuf); + pipe_buffer_flush_mapped_range(&svga->pipe, + svga_render->vbuf_transfer, + offset, length); + pipe_buffer_unmap(&svga->pipe, svga_render->vbuf, svga_render->vbuf_transfer); svga_render->min_index = min_index; svga_render->max_index = max_index; svga_render->vbuf_used = MAX2(svga_render->vbuf_used, used); @@ -255,7 +256,7 @@ svga_vbuf_render_draw( struct vbuf_render *render, assert(( svga_render->vbuf_offset - svga_render->vdecl_offset) % svga_render->vertex_size == 0); if (svga_render->ibuf_size < svga_render->ibuf_offset + size) - pipe_buffer_reference(&svga_render->ibuf, NULL); + pipe_resource_reference(&svga_render->ibuf, NULL); if (!svga_render->ibuf) { svga_render->ibuf_size = MAX2(size, svga_render->ibuf_alloc_size); @@ -266,8 +267,8 @@ svga_vbuf_render_draw( struct vbuf_render *render, svga_render->ibuf_offset = 0; } - pipe_buffer_write_nooverlap(screen, svga_render->ibuf, - svga_render->ibuf_offset, 2 * nr_indices, indices); + pipe_buffer_write_nooverlap(&svga->pipe, svga_render->ibuf, + svga_render->ibuf_offset, 2 * nr_indices, indices); /* off to hardware */ @@ -315,8 +316,8 @@ svga_vbuf_render_destroy( struct vbuf_render *render ) { struct svga_vbuf_render *svga_render = svga_vbuf_render(render); - pipe_buffer_reference(&svga_render->vbuf, NULL); - pipe_buffer_reference(&svga_render->ibuf, NULL); + pipe_resource_reference(&svga_render->vbuf, NULL); + pipe_resource_reference(&svga_render->ibuf, NULL); FREE(svga_render); } diff --git a/src/gallium/drivers/svga/svga_swtnl_draw.c b/src/gallium/drivers/svga/svga_swtnl_draw.c index da15be155c..ee12c9ac36 100644 --- a/src/gallium/drivers/svga/svga_swtnl_draw.c +++ b/src/gallium/drivers/svga/svga_swtnl_draw.c @@ -37,12 +37,15 @@ enum pipe_error svga_swtnl_draw_range_elements(struct svga_context *svga, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned min_index, unsigned max_index, unsigned prim, unsigned start, unsigned count) { + struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS]; + struct pipe_transfer *ib_transfer; + struct pipe_transfer *cb_transfer; struct draw_context *draw = svga->swtnl.draw; unsigned i; const void *map; @@ -64,17 +67,19 @@ svga_swtnl_draw_range_elements(struct svga_context *svga, * Map vertex buffers */ for (i = 0; i < svga->curr.num_vertex_buffers; i++) { - map = pipe_buffer_map(svga->pipe.screen, + map = pipe_buffer_map(&svga->pipe, svga->curr.vb[i].buffer, - PIPE_BUFFER_USAGE_CPU_READ); + PIPE_BUFFER_USAGE_CPU_READ, + &vb_transfer[i]); draw_set_mapped_vertex_buffer(draw, i, map); } /* Map index buffer, if present */ if (indexBuffer) { - map = pipe_buffer_map(svga->pipe.screen, indexBuffer, - PIPE_BUFFER_USAGE_CPU_READ); + map = pipe_buffer_map(&svga->pipe, indexBuffer, + PIPE_BUFFER_USAGE_CPU_READ, + &ib_transfer); draw_set_mapped_element_buffer_range(draw, indexSize, @@ -84,14 +89,15 @@ svga_swtnl_draw_range_elements(struct svga_context *svga, } if (svga->curr.cb[PIPE_SHADER_VERTEX]) { - map = pipe_buffer_map(svga->pipe.screen, + map = pipe_buffer_map(&svga->pipe, svga->curr.cb[PIPE_SHADER_VERTEX], - PIPE_BUFFER_USAGE_CPU_READ); + PIPE_BUFFER_USAGE_CPU_READ, + &cb_transfer); assert(map); draw_set_mapped_constant_buffer( draw, PIPE_SHADER_VERTEX, 0, map, - svga->curr.cb[PIPE_SHADER_VERTEX]->size); + svga->curr.cb[PIPE_SHADER_VERTEX]->width0); } draw_arrays(svga->swtnl.draw, prim, start, count); @@ -105,18 +111,20 @@ svga_swtnl_draw_range_elements(struct svga_context *svga, * unmap vertex/index buffers */ for (i = 0; i < svga->curr.num_vertex_buffers; i++) { - pipe_buffer_unmap(svga->pipe.screen, svga->curr.vb[i].buffer); + pipe_buffer_unmap(&svga->pipe, svga->curr.vb[i].buffer, + vb_transfer[i]); draw_set_mapped_vertex_buffer(draw, i, NULL); } if (indexBuffer) { - pipe_buffer_unmap(svga->pipe.screen, indexBuffer); + pipe_buffer_unmap(&svga->pipe, indexBuffer, ib_transfer); draw_set_mapped_element_buffer(draw, 0, NULL); } if (svga->curr.cb[PIPE_SHADER_VERTEX]) { - pipe_buffer_unmap(svga->pipe.screen, - svga->curr.cb[PIPE_SHADER_VERTEX]); + pipe_buffer_unmap(&svga->pipe, + svga->curr.cb[PIPE_SHADER_VERTEX], + cb_transfer); } return ret; diff --git a/src/gallium/drivers/svga/svga_swtnl_private.h b/src/gallium/drivers/svga/svga_swtnl_private.h index 9bbb42910f..8d08070843 100644 --- a/src/gallium/drivers/svga/svga_swtnl_private.h +++ b/src/gallium/drivers/svga/svga_swtnl_private.h @@ -45,8 +45,10 @@ struct svga_vbuf_render { unsigned prim; - struct pipe_buffer *vbuf; - struct pipe_buffer *ibuf; + struct pipe_resource *vbuf; + struct pipe_resource *ibuf; + struct pipe_transfer *vbuf_transfer; + struct pipe_transfer *ibuf_transfer; /* current size of buffer */ size_t vbuf_size; diff --git a/src/gallium/drivers/svga/svga_winsys.h b/src/gallium/drivers/svga/svga_winsys.h index d4bb176f9a..225c2ba55f 100644 --- a/src/gallium/drivers/svga/svga_winsys.h +++ b/src/gallium/drivers/svga/svga_winsys.h @@ -189,7 +189,7 @@ struct svga_winsys_screen /** * Creates a surface from a winsys handle. - * Used to implement pipe_screen::texture_from_handle. + * Used to implement pipe_screen::resource_from_handle. */ struct svga_winsys_surface * (*surface_from_handle)(struct svga_winsys_screen *sws, @@ -198,7 +198,7 @@ struct svga_winsys_screen /** * Get a winsys_handle from a surface. - * Used to implement pipe_screen::texture_get_handle. + * Used to implement pipe_screen::resource_get_handle. */ boolean (*surface_get_handle)(struct svga_winsys_screen *sws, @@ -225,10 +225,6 @@ struct svga_winsys_screen /** * Buffer management. Buffer attributes are mostly fixed over its lifetime. * - * Remember that gallium gets to choose the interface it needs, and the - * window systems must then implement that interface (rather than the - * other way around...). - * * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This * usage argument is only an optimization hint, not a guarantee, therefore * proper behavior must be observed in all circumstances. @@ -298,12 +294,12 @@ svga_screen_create(struct svga_winsys_screen *sws); struct svga_winsys_screen * svga_winsys_screen(struct pipe_screen *screen); -struct pipe_buffer * +struct pipe_resource * svga_screen_buffer_wrap_surface(struct pipe_screen *screen, enum SVGA3dSurfaceFormat format, struct svga_winsys_surface *srf); struct svga_winsys_surface * -svga_screen_buffer_get_winsys_surface(struct pipe_buffer *buffer); +svga_screen_buffer_get_winsys_surface(struct pipe_resource *buffer); #endif /* SVGA_WINSYS_H_ */ diff --git a/src/gallium/drivers/trace/Makefile b/src/gallium/drivers/trace/Makefile index dd6831c70a..78f6347dc7 100644 --- a/src/gallium/drivers/trace/Makefile +++ b/src/gallium/drivers/trace/Makefile @@ -4,7 +4,6 @@ include $(TOP)/configs/current LIBNAME = trace C_SOURCES = \ - tr_buffer.c \ tr_context.c \ tr_dump.c \ tr_dump_state.c \ diff --git a/src/gallium/drivers/trace/SConscript b/src/gallium/drivers/trace/SConscript index c1675d1c16..5f1fb17966 100644 --- a/src/gallium/drivers/trace/SConscript +++ b/src/gallium/drivers/trace/SConscript @@ -5,7 +5,6 @@ env = env.Clone() trace = env.ConvenienceLibrary( target = 'trace', source = [ - 'tr_buffer.c', 'tr_context.c', 'tr_drm.c', 'tr_dump.c', diff --git a/src/gallium/drivers/trace/tr_buffer.c b/src/gallium/drivers/trace/tr_buffer.c deleted file mode 100644 index fa2ac068eb..0000000000 --- a/src/gallium/drivers/trace/tr_buffer.c +++ /dev/null @@ -1,76 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -#include "util/u_inlines.h" -#include "util/u_memory.h" -#include "util/u_simple_list.h" - -#include "tr_buffer.h" - -struct pipe_buffer * -trace_buffer_create(struct trace_screen *tr_scr, - struct pipe_buffer *buffer) -{ - struct trace_buffer *tr_buf; - - if(!buffer) - goto error; - - assert(buffer->screen == tr_scr->screen); - - tr_buf = CALLOC_STRUCT(trace_buffer); - if(!tr_buf) - goto error; - - memcpy(&tr_buf->base, buffer, sizeof(struct pipe_buffer)); - - pipe_reference_init(&tr_buf->base.reference, 1); - tr_buf->base.screen = &tr_scr->base; - tr_buf->buffer = buffer; - - trace_screen_add_to_list(tr_scr, buffers, tr_buf); - - return &tr_buf->base; - -error: - pipe_buffer_reference(&buffer, NULL); - return NULL; -} - - -void -trace_buffer_destroy(struct trace_screen *tr_scr, - struct pipe_buffer *buffer) -{ - struct trace_buffer *tr_buf = trace_buffer(buffer); - - trace_screen_remove_from_list(tr_scr, buffers, tr_buf); - - pipe_buffer_reference(&tr_buf->buffer, NULL); - FREE(tr_buf); -} diff --git a/src/gallium/drivers/trace/tr_buffer.h b/src/gallium/drivers/trace/tr_buffer.h deleted file mode 100644 index 1a2d0b9aea..0000000000 --- a/src/gallium/drivers/trace/tr_buffer.h +++ /dev/null @@ -1,70 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef TR_BUFFER_H_ -#define TR_BUFFER_H_ - - -#include "pipe/p_compiler.h" -#include "pipe/p_state.h" - -#include "tr_screen.h" - - -struct trace_buffer -{ - struct pipe_buffer base; - - struct pipe_buffer *buffer; - - struct tr_list list; - - void *map; - boolean range_flushed; -}; - - -static INLINE struct trace_buffer * -trace_buffer(struct pipe_buffer *buffer) -{ - if(!buffer) - return NULL; - (void)trace_screen(buffer->screen); - return (struct trace_buffer *)buffer; -} - - -struct pipe_buffer * -trace_buffer_create(struct trace_screen *tr_scr, - struct pipe_buffer *buffer); - -void -trace_buffer_destroy(struct trace_screen *tr_scr, - struct pipe_buffer *buffer); - - -#endif diff --git a/src/gallium/drivers/trace/tr_context.c b/src/gallium/drivers/trace/tr_context.c index 5c24bd1f7d..09ee5a7d04 100644 --- a/src/gallium/drivers/trace/tr_context.c +++ b/src/gallium/drivers/trace/tr_context.c @@ -36,43 +36,26 @@ #include "tr_dump.h" #include "tr_dump_state.h" #include "tr_state.h" -#include "tr_buffer.h" #include "tr_screen.h" #include "tr_texture.h" -static INLINE struct pipe_buffer * -trace_buffer_unwrap(struct trace_context *tr_ctx, - struct pipe_buffer *buffer) -{ - struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen); - struct trace_buffer *tr_buf; - - if(!buffer) - return NULL; - tr_buf = trace_buffer(buffer); - assert(tr_buf->buffer); - assert(tr_buf->buffer->screen == tr_scr->screen); - (void) tr_scr; - return tr_buf->buffer; -} - -static INLINE struct pipe_texture * -trace_texture_unwrap(struct trace_context *tr_ctx, - struct pipe_texture *texture) +static INLINE struct pipe_resource * +trace_resource_unwrap(struct trace_context *tr_ctx, + struct pipe_resource *resource) { - struct trace_texture *tr_tex; + struct trace_resource *tr_tex; - if(!texture) + if(!resource) return NULL; - tr_tex = trace_texture(texture); + tr_tex = trace_resource(resource); - assert(tr_tex->texture); - return tr_tex->texture; + assert(tr_tex->resource); + return tr_tex->resource; } @@ -193,22 +176,20 @@ trace_context_draw_arrays(struct pipe_context *_pipe, static INLINE void trace_context_draw_elements(struct pipe_context *_pipe, - struct pipe_buffer *_indexBuffer, + struct pipe_resource *_indexBuffer, unsigned indexSize, unsigned mode, unsigned start, unsigned count) { struct trace_context *tr_ctx = trace_context(_pipe); - struct trace_buffer *tr_buf = trace_buffer(_indexBuffer); + struct trace_resource *tr_buf = trace_resource(_indexBuffer); struct pipe_context *pipe = tr_ctx->pipe; - struct pipe_buffer *indexBuffer = tr_buf->buffer; + struct pipe_resource *indexBuffer = tr_buf->resource; if (tr_ctx->curr.fs->disabled || tr_ctx->curr.vs->disabled) return; trace_context_draw_block(tr_ctx, 1); - trace_screen_user_buffer_update(_pipe->screen, indexBuffer); - trace_dump_call_begin("pipe_context", "draw_elements"); trace_dump_arg(ptr, pipe); @@ -228,7 +209,7 @@ trace_context_draw_elements(struct pipe_context *_pipe, static INLINE void trace_context_draw_range_elements(struct pipe_context *_pipe, - struct pipe_buffer *_indexBuffer, + struct pipe_resource *_indexBuffer, unsigned indexSize, unsigned minIndex, unsigned maxIndex, @@ -237,17 +218,15 @@ trace_context_draw_range_elements(struct pipe_context *_pipe, unsigned count) { struct trace_context *tr_ctx = trace_context(_pipe); - struct trace_buffer *tr_buf = trace_buffer(_indexBuffer); + struct trace_resource *tr_buf = trace_resource(_indexBuffer); struct pipe_context *pipe = tr_ctx->pipe; - struct pipe_buffer *indexBuffer = tr_buf->buffer; + struct pipe_resource *indexBuffer = tr_buf->resource; if (tr_ctx->curr.fs->disabled || tr_ctx->curr.vs->disabled) return; trace_context_draw_block(tr_ctx, 1); - trace_screen_user_buffer_update(_pipe->screen, indexBuffer); - trace_dump_call_begin("pipe_context", "draw_range_elements"); trace_dump_arg(ptr, pipe); @@ -897,14 +876,13 @@ trace_context_set_clip_state(struct pipe_context *_pipe, static INLINE void trace_context_set_constant_buffer(struct pipe_context *_pipe, uint shader, uint index, - struct pipe_buffer *buffer) + struct pipe_resource *buffer) { struct trace_context *tr_ctx = trace_context(_pipe); struct pipe_context *pipe = tr_ctx->pipe; if (buffer) { - trace_screen_user_buffer_update(_pipe->screen, buffer); - buffer = trace_buffer_unwrap(tr_ctx, buffer); + buffer = trace_resource_unwrap(tr_ctx, buffer); } trace_dump_call_begin("pipe_context", "set_constant_buffer"); @@ -933,11 +911,11 @@ trace_context_set_framebuffer_state(struct pipe_context *_pipe, tr_ctx->curr.nr_cbufs = state->nr_cbufs; for (i = 0; i < state->nr_cbufs; i++) if (state->cbufs[i]) - tr_ctx->curr.cbufs[i] = trace_texture(state->cbufs[i]->texture); + tr_ctx->curr.cbufs[i] = trace_resource(state->cbufs[i]->texture); else tr_ctx->curr.cbufs[i] = NULL; if (state->zsbuf) - tr_ctx->curr.zsbuf = trace_texture(state->zsbuf->texture); + tr_ctx->curr.zsbuf = trace_resource(state->zsbuf->texture); else tr_ctx->curr.zsbuf = NULL; } @@ -1018,13 +996,13 @@ trace_context_set_viewport_state(struct pipe_context *_pipe, static struct pipe_sampler_view * trace_create_sampler_view(struct pipe_context *_pipe, - struct pipe_texture *_texture, + struct pipe_resource *_resource, const struct pipe_sampler_view *templ) { struct trace_context *tr_ctx = trace_context(_pipe); - struct trace_texture *tr_tex = trace_texture(_texture); + struct trace_resource *tr_tex = trace_resource(_resource); struct pipe_context *pipe = tr_ctx->pipe; - struct pipe_texture *texture = tr_tex->texture; + struct pipe_resource *texture = tr_tex->resource; struct trace_sampler_view *result = CALLOC_STRUCT(trace_sampler_view); trace_dump_call_begin("pipe_context", "create_sampler_view"); @@ -1038,7 +1016,7 @@ trace_create_sampler_view(struct pipe_context *_pipe, result->base = *templ; result->base.reference.count = 1; result->base.texture = NULL; - pipe_texture_reference(&result->base.texture, _texture); + pipe_resource_reference(&result->base.texture, _resource); result->base.context = _pipe; trace_dump_ret(ptr, result); @@ -1067,7 +1045,7 @@ trace_sampler_view_destroy(struct pipe_context *_pipe, trace_dump_call_end(); - pipe_texture_reference(&_view->texture, NULL); + pipe_resource_reference(&_view->texture, NULL); FREE(_view); } @@ -1143,9 +1121,6 @@ trace_context_set_vertex_buffers(struct pipe_context *_pipe, struct pipe_context *pipe = tr_ctx->pipe; unsigned i; - for(i = 0; i < num_buffers; ++i) - trace_screen_user_buffer_update(_pipe->screen, buffers[i].buffer); - trace_dump_call_begin("pipe_context", "set_vertex_buffers"); trace_dump_arg(ptr, pipe); @@ -1159,7 +1134,7 @@ trace_context_set_vertex_buffers(struct pipe_context *_pipe, struct pipe_vertex_buffer *_buffers = malloc(num_buffers * sizeof(*_buffers)); memcpy(_buffers, buffers, num_buffers * sizeof(*_buffers)); for (i = 0; i < num_buffers; i++) - _buffers[i].buffer = trace_buffer_unwrap(tr_ctx, buffers[i].buffer); + _buffers[i].buffer = trace_resource_unwrap(tr_ctx, buffers[i].buffer); pipe->set_vertex_buffers(pipe, num_buffers, _buffers); free(_buffers); } else { @@ -1296,45 +1271,23 @@ trace_context_destroy(struct pipe_context *_pipe) } static unsigned int -trace_is_texture_referenced( struct pipe_context *_pipe, - struct pipe_texture *_texture, - unsigned face, unsigned level) +trace_is_resource_referenced( struct pipe_context *_pipe, + struct pipe_resource *_resource, + unsigned face, unsigned level) { struct trace_context *tr_ctx = trace_context(_pipe); - struct trace_texture *tr_tex = trace_texture(_texture); + struct trace_resource *tr_tex = trace_resource(_resource); struct pipe_context *pipe = tr_ctx->pipe; - struct pipe_texture *texture = tr_tex->texture; + struct pipe_resource *texture = tr_tex->resource; unsigned int referenced; - trace_dump_call_begin("pipe_context", "is_texture_referenced"); + trace_dump_call_begin("pipe_context", "is_resource_referenced"); trace_dump_arg(ptr, pipe); trace_dump_arg(ptr, texture); trace_dump_arg(uint, face); trace_dump_arg(uint, level); - referenced = pipe->is_texture_referenced(pipe, texture, face, level); - - trace_dump_ret(uint, referenced); - trace_dump_call_end(); - - return referenced; -} - -static unsigned int -trace_is_buffer_referenced( struct pipe_context *_pipe, - struct pipe_buffer *_buf) -{ - struct trace_context *tr_ctx = trace_context(_pipe); - struct trace_buffer *tr_buf = trace_buffer(_buf); - struct pipe_context *pipe = tr_ctx->pipe; - struct pipe_buffer *buf = tr_buf->buffer; - unsigned int referenced; - - trace_dump_call_begin("pipe_context", "is_buffer_referenced"); - trace_dump_arg(ptr, pipe); - trace_dump_arg(ptr, buf); - - referenced = pipe->is_buffer_referenced(pipe, buf); + referenced = pipe->is_resource_referenced(pipe, texture, face, level); trace_dump_ret(uint, referenced); trace_dump_call_end(); @@ -1349,37 +1302,35 @@ trace_is_buffer_referenced( struct pipe_context *_pipe, static struct pipe_transfer * -trace_context_get_tex_transfer(struct pipe_context *_context, - struct pipe_texture *_texture, - unsigned face, unsigned level, - unsigned zslice, - enum pipe_transfer_usage usage, - unsigned x, unsigned y, unsigned w, unsigned h) +trace_context_get_transfer(struct pipe_context *_context, + struct pipe_resource *_resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box) { struct trace_context *tr_context = trace_context(_context); - struct trace_texture *tr_tex = trace_texture(_texture); + struct trace_resource *tr_tex = trace_resource(_resource); struct pipe_context *context = tr_context->pipe; - struct pipe_texture *texture = tr_tex->texture; + struct pipe_resource *texture = tr_tex->resource; struct pipe_transfer *result = NULL; assert(texture->screen == context->screen); - trace_dump_call_begin("pipe_context", "get_tex_transfer"); + trace_dump_call_begin("pipe_context", "get_transfer"); trace_dump_arg(ptr, context); trace_dump_arg(ptr, texture); - trace_dump_arg(uint, face); - trace_dump_arg(uint, level); - trace_dump_arg(uint, zslice); + trace_dump_arg(uint, sr.face); + trace_dump_arg(uint, sr.level); trace_dump_arg(uint, usage); + trace_dump_arg(uint, box->x); + trace_dump_arg(uint, box->y); + trace_dump_arg(uint, box->z); + trace_dump_arg(uint, box->width); + trace_dump_arg(uint, box->height); + trace_dump_arg(uint, box->depth); - trace_dump_arg(uint, x); - trace_dump_arg(uint, y); - trace_dump_arg(uint, w); - trace_dump_arg(uint, h); - - result = context->get_tex_transfer(context, texture, face, level, zslice, usage, - x, y, w, h); + result = context->get_transfer(context, texture, sr, usage, box); trace_dump_ret(ptr, result); @@ -1393,7 +1344,7 @@ trace_context_get_tex_transfer(struct pipe_context *_context, static void -trace_context_tex_transfer_destroy(struct pipe_context *_context, +trace_context_transfer_destroy(struct pipe_context *_context, struct pipe_transfer *_transfer) { struct trace_context *tr_context = trace_context(_context); @@ -1401,7 +1352,7 @@ trace_context_tex_transfer_destroy(struct pipe_context *_context, struct pipe_context *context = tr_context->pipe; struct pipe_transfer *transfer = tr_trans->transfer; - trace_dump_call_begin("pipe_context", "tex_transfer_destroy"); + trace_dump_call_begin("pipe_context", "transfer_destroy"); trace_dump_arg(ptr, context); trace_dump_arg(ptr, transfer); @@ -1435,6 +1386,33 @@ trace_context_transfer_map(struct pipe_context *_context, static void +trace_context_transfer_flush_region( struct pipe_context *_context, + struct pipe_transfer *_transfer, + const struct pipe_box *box) +{ + struct trace_context *tr_context = trace_context(_context); + struct trace_transfer *tr_transfer = trace_transfer(_transfer); + struct pipe_context *context = tr_context->pipe; + struct pipe_transfer *transfer = tr_transfer->transfer; + + trace_dump_call_begin("pipe_context", "transfer_flush_region"); + + trace_dump_arg(ptr, context); + trace_dump_arg(ptr, transfer); + trace_dump_arg(uint, box->x); + trace_dump_arg(uint, box->y); + trace_dump_arg(uint, box->z); + trace_dump_arg(uint, box->width); + trace_dump_arg(uint, box->height); + trace_dump_arg(uint, box->depth); + trace_dump_call_end(); + + context->transfer_flush_region(context, + transfer, + box); +} + +static void trace_context_transfer_unmap(struct pipe_context *_context, struct pipe_transfer *_transfer) { @@ -1444,8 +1422,6 @@ trace_context_transfer_unmap(struct pipe_context *_context, struct pipe_transfer *transfer = tr_trans->transfer; if(tr_trans->map) { - size_t size = util_format_get_nblocksy(transfer->texture->format, transfer->height) * transfer->stride; - trace_dump_call_begin("pipe_context", "transfer_write"); trace_dump_arg(ptr, context); @@ -1457,12 +1433,16 @@ trace_context_transfer_unmap(struct pipe_context *_context, trace_dump_arg_end(); trace_dump_arg_begin("data"); - trace_dump_bytes(tr_trans->map, size); + trace_dump_box_bytes(tr_trans->map, + transfer->resource->format, + &transfer->box, + transfer->stride, + transfer->slice_stride); trace_dump_arg_end(); - trace_dump_arg_begin("size"); - trace_dump_uint(size); - trace_dump_arg_end(); +// trace_dump_arg_begin("size"); +// trace_dump_uint(size); +// trace_dump_arg_end(); trace_dump_call_end(); @@ -1472,6 +1452,57 @@ trace_context_transfer_unmap(struct pipe_context *_context, context->transfer_unmap(context, transfer); } + +static void +trace_context_transfer_inline_write(struct pipe_context *_context, + struct pipe_resource *_resource, + struct pipe_subresource sr, + enum pipe_transfer_usage usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned slice_stride) +{ + struct trace_context *tr_context = trace_context(_context); + struct trace_resource *tr_tex = trace_resource(_resource); + struct pipe_context *context = tr_context->pipe; + struct pipe_resource *resource = tr_tex->resource; + + assert(resource->screen == context->screen); + + trace_dump_call_begin("pipe_context", "transfer_inline_write"); + + trace_dump_arg(ptr, context); + trace_dump_arg(ptr, resource); + trace_dump_arg(uint, sr.face); + trace_dump_arg(uint, sr.level); + trace_dump_arg(uint, usage); + trace_dump_arg(uint, box->x); + trace_dump_arg(uint, box->y); + trace_dump_arg(uint, box->z); + trace_dump_arg(uint, box->width); + trace_dump_arg(uint, box->height); + trace_dump_arg(uint, box->depth); + trace_dump_arg(uint, stride); + trace_dump_arg(uint, slice_stride); + + trace_dump_arg_begin("data"); + trace_dump_box_bytes(data, + resource->format, + box, + stride, + slice_stride); + trace_dump_arg_end(); + + trace_dump_call_end(); + + context->transfer_inline_write(context, resource, + sr, usage, box, data, stride, slice_stride); +} + + + + static const struct debug_named_value rbug_blocker_flags[] = { {"before", 1}, {"after", 2}, @@ -1555,13 +1586,14 @@ trace_context_create(struct trace_screen *tr_scr, tr_ctx->base.surface_fill = trace_context_surface_fill; tr_ctx->base.clear = trace_context_clear; tr_ctx->base.flush = trace_context_flush; - tr_ctx->base.is_texture_referenced = trace_is_texture_referenced; - tr_ctx->base.is_buffer_referenced = trace_is_buffer_referenced; + tr_ctx->base.is_resource_referenced = trace_is_resource_referenced; - tr_ctx->base.get_tex_transfer = trace_context_get_tex_transfer; - tr_ctx->base.tex_transfer_destroy = trace_context_tex_transfer_destroy; + tr_ctx->base.get_transfer = trace_context_get_transfer; + tr_ctx->base.transfer_destroy = trace_context_transfer_destroy; tr_ctx->base.transfer_map = trace_context_transfer_map; tr_ctx->base.transfer_unmap = trace_context_transfer_unmap; + tr_ctx->base.transfer_flush_region = trace_context_transfer_flush_region; + tr_ctx->base.transfer_inline_write = trace_context_transfer_inline_write; tr_ctx->pipe = pipe; diff --git a/src/gallium/drivers/trace/tr_context.h b/src/gallium/drivers/trace/tr_context.h index feec9b6bbf..1b4121d80a 100644 --- a/src/gallium/drivers/trace/tr_context.h +++ b/src/gallium/drivers/trace/tr_context.h @@ -60,8 +60,8 @@ struct trace_context unsigned num_vert_sampler_views; unsigned nr_cbufs; - struct trace_texture *cbufs[PIPE_MAX_COLOR_BUFS]; - struct trace_texture *zsbuf; + struct trace_resource *cbufs[PIPE_MAX_COLOR_BUFS]; + struct trace_resource *zsbuf; } curr; struct { @@ -69,7 +69,7 @@ struct trace_context struct trace_shader *vs; struct trace_sampler_view *sampler_view; - struct trace_texture *surf; + struct trace_resource *surf; int blocker; } draw_rule; diff --git a/src/gallium/drivers/trace/tr_dump.c b/src/gallium/drivers/trace/tr_dump.c index 1affafdddc..19cf0de1d3 100644 --- a/src/gallium/drivers/trace/tr_dump.c +++ b/src/gallium/drivers/trace/tr_dump.c @@ -54,7 +54,6 @@ #include "tr_dump.h" #include "tr_screen.h" #include "tr_texture.h" -#include "tr_buffer.h" static struct os_stream *stream = NULL; @@ -471,6 +470,16 @@ void trace_dump_bytes(const void *data, trace_dump_writes("</bytes>"); } +void trace_dump_box_bytes(const void *data, + unsigned format, + const struct pipe_box *box, + unsigned stride, + unsigned slice_stride) +{ + //size_t size = util_format_get_nblocksy(transfer->resource->format, transfer->box.height) * transfer->stride; + +} + void trace_dump_string(const char *str) { if (!dumping) @@ -574,27 +583,15 @@ void trace_dump_ptr(const void *value) trace_dump_null(); } -void trace_dump_buffer_ptr(struct pipe_buffer *_buffer) -{ - if (!dumping) - return; - - if (_buffer) { - struct trace_buffer *tr_buf = trace_buffer(_buffer); - trace_dump_ptr(tr_buf->buffer); - } else { - trace_dump_null(); - } -} -void trace_dump_texture_ptr(struct pipe_texture *_texture) +void trace_dump_resource_ptr(struct pipe_resource *_resource) { if (!dumping) return; - if (_texture) { - struct trace_texture *tr_tex = trace_texture(_texture); - trace_dump_ptr(tr_tex->texture); + if (_resource) { + struct trace_resource *tr_resource = trace_resource(_resource); + trace_dump_ptr(tr_resource->resource); } else { trace_dump_null(); } diff --git a/src/gallium/drivers/trace/tr_dump.h b/src/gallium/drivers/trace/tr_dump.h index 32592bab12..4fa00e2f3d 100644 --- a/src/gallium/drivers/trace/tr_dump.h +++ b/src/gallium/drivers/trace/tr_dump.h @@ -36,11 +36,11 @@ #include "pipe/p_compiler.h" - struct pipe_buffer; struct pipe_texture; struct pipe_surface; struct pipe_transfer; +struct pipe_box; /* * Call before use. @@ -92,6 +92,11 @@ void trace_dump_int(long long int value); void trace_dump_uint(long long unsigned value); void trace_dump_float(double value); void trace_dump_bytes(const void *data, size_t size); +void trace_dump_box_bytes(const void *data, + unsigned format, + const struct pipe_box *box, + unsigned stride, + unsigned slice_stride); void trace_dump_string(const char *str); void trace_dump_enum(const char *value); void trace_dump_array_begin(void); @@ -105,8 +110,7 @@ void trace_dump_member_end(void); void trace_dump_null(void); void trace_dump_ptr(const void *value); /* will turn a wrapped object into the real one and dump ptr */ -void trace_dump_buffer_ptr(struct pipe_buffer *_buffer); -void trace_dump_texture_ptr(struct pipe_texture *_texture); +void trace_dump_resource_ptr(struct pipe_resource *_texture); void trace_dump_surface_ptr(struct pipe_surface *_surface); void trace_dump_transfer_ptr(struct pipe_transfer *_transfer); diff --git a/src/gallium/drivers/trace/tr_dump_state.c b/src/gallium/drivers/trace/tr_dump_state.c index f82dd01c69..8009ec1d08 100644 --- a/src/gallium/drivers/trace/tr_dump_state.c +++ b/src/gallium/drivers/trace/tr_dump_state.c @@ -44,7 +44,7 @@ void trace_dump_format(enum pipe_format format) } -void trace_dump_template(const struct pipe_texture *templat) +void trace_dump_template(const struct pipe_resource *templat) { if (!trace_dumping_enabled_locked()) return; @@ -428,16 +428,16 @@ void trace_dump_transfer(const struct pipe_transfer *state) trace_dump_struct_begin("pipe_transfer"); - trace_dump_member(uint, state, width); - trace_dump_member(uint, state, height); + trace_dump_member(uint, state, box.width); + trace_dump_member(uint, state, box.height); trace_dump_member(uint, state, stride); trace_dump_member(uint, state, usage); - trace_dump_member(ptr, state, texture); - trace_dump_member(uint, state, face); - trace_dump_member(uint, state, level); - trace_dump_member(uint, state, zslice); + trace_dump_member(ptr, state, resource); + trace_dump_member(uint, state, sr.face); + trace_dump_member(uint, state, sr.level); + trace_dump_member(uint, state, box.z); trace_dump_struct_end(); } @@ -458,7 +458,7 @@ void trace_dump_vertex_buffer(const struct pipe_vertex_buffer *state) trace_dump_member(uint, state, stride); trace_dump_member(uint, state, max_index); trace_dump_member(uint, state, buffer_offset); - trace_dump_member(buffer_ptr, state, buffer); + trace_dump_member(resource_ptr, state, buffer); trace_dump_struct_end(); } diff --git a/src/gallium/drivers/trace/tr_dump_state.h b/src/gallium/drivers/trace/tr_dump_state.h index 3400367d82..41f6263935 100644 --- a/src/gallium/drivers/trace/tr_dump_state.h +++ b/src/gallium/drivers/trace/tr_dump_state.h @@ -35,7 +35,7 @@ void trace_dump_format(enum pipe_format format); -void trace_dump_template(const struct pipe_texture *templat); +void trace_dump_template(const struct pipe_resource *templat); void trace_dump_rasterizer_state(const struct pipe_rasterizer_state *state); diff --git a/src/gallium/drivers/trace/tr_rbug.c b/src/gallium/drivers/trace/tr_rbug.c index 53ab8c686d..88ce4691ce 100644 --- a/src/gallium/drivers/trace/tr_rbug.c +++ b/src/gallium/drivers/trace/tr_rbug.c @@ -29,6 +29,7 @@ #include "os/os_thread.h" #include "util/u_format.h" #include "util/u_string.h" +#include "util/u_inlines.h" #include "util/u_memory.h" #include "util/u_simple_list.h" #include "util/u_network.h" @@ -38,7 +39,6 @@ #include "tr_dump.h" #include "tr_state.h" -#include "tr_buffer.h" #include "tr_texture.h" #include "rbug/rbug.h" @@ -150,7 +150,7 @@ static int trace_rbug_texture_list(struct trace_rbug *tr_rbug, struct rbug_header *header, uint32_t serial) { struct trace_screen *tr_scr = tr_rbug->tr_scr; - struct trace_texture *tr_tex = NULL; + struct trace_resource *tr_tex = NULL; struct tr_list *ptr; rbug_texture_t *texs; int i = 0; @@ -158,7 +158,7 @@ trace_rbug_texture_list(struct trace_rbug *tr_rbug, struct rbug_header *header, pipe_mutex_lock(tr_scr->list_mutex); texs = MALLOC(tr_scr->num_textures * sizeof(rbug_texture_t)); foreach(ptr, &tr_scr->textures) { - tr_tex = (struct trace_texture *)((char*)ptr - offsetof(struct trace_texture, list)); + tr_tex = (struct trace_resource *)((char*)ptr - offsetof(struct trace_resource, list)); texs[i++] = VOID2U64(tr_tex); } pipe_mutex_unlock(tr_scr->list_mutex); @@ -173,14 +173,14 @@ static int trace_rbug_texture_info(struct trace_rbug *tr_rbug, struct rbug_header *header, uint32_t serial) { struct trace_screen *tr_scr = tr_rbug->tr_scr; - struct trace_texture *tr_tex = NULL; + struct trace_resource *tr_tex = NULL; struct rbug_proto_texture_info *gpti = (struct rbug_proto_texture_info *)header; struct tr_list *ptr; - struct pipe_texture *t; + struct pipe_resource *t; pipe_mutex_lock(tr_scr->list_mutex); foreach(ptr, &tr_scr->textures) { - tr_tex = (struct trace_texture *)((char*)ptr - offsetof(struct trace_texture, list)); + tr_tex = (struct trace_resource *)((char*)ptr - offsetof(struct trace_resource, list)); if (gpti->texture == VOID2U64(tr_tex)) break; tr_tex = NULL; @@ -191,7 +191,7 @@ trace_rbug_texture_info(struct trace_rbug *tr_rbug, struct rbug_header *header, return -ESRCH; } - t = tr_tex->texture; + t = tr_tex->resource; rbug_send_texture_info_reply(tr_rbug->con, serial, t->target, t->format, &t->width0, 1, @@ -216,18 +216,18 @@ trace_rbug_texture_read(struct trace_rbug *tr_rbug, struct rbug_header *header, struct rbug_proto_texture_read *gptr = (struct rbug_proto_texture_read *)header; struct trace_screen *tr_scr = tr_rbug->tr_scr; - struct trace_texture *tr_tex = NULL; + struct trace_resource *tr_tex = NULL; struct tr_list *ptr; struct pipe_context *context = tr_scr->private_context; - struct pipe_texture *tex; + struct pipe_resource *tex; struct pipe_transfer *t; void *map; pipe_mutex_lock(tr_scr->list_mutex); foreach(ptr, &tr_scr->textures) { - tr_tex = (struct trace_texture *)((char*)ptr - offsetof(struct trace_texture, list)); + tr_tex = (struct trace_resource *)((char*)ptr - offsetof(struct trace_resource, list)); if (gptr->texture == VOID2U64(tr_tex)) break; tr_tex = NULL; @@ -238,8 +238,8 @@ trace_rbug_texture_read(struct trace_rbug *tr_rbug, struct rbug_header *header, return -ESRCH; } - tex = tr_tex->texture; - t = context->get_tex_transfer(context, tex, + tex = tr_tex->resource; + t = pipe_get_transfer(context, tex, gptr->face, gptr->level, gptr->zslice, PIPE_TRANSFER_READ, gptr->x, gptr->y, gptr->w, gptr->h); @@ -247,17 +247,18 @@ trace_rbug_texture_read(struct trace_rbug *tr_rbug, struct rbug_header *header, map = context->transfer_map(context, t); rbug_send_texture_read_reply(tr_rbug->con, serial, - t->texture->format, - util_format_get_blockwidth(t->texture->format), - util_format_get_blockheight(t->texture->format), - util_format_get_blocksize(t->texture->format), + t->resource->format, + util_format_get_blockwidth(t->resource->format), + util_format_get_blockheight(t->resource->format), + util_format_get_blocksize(t->resource->format), (uint8_t*)map, - t->stride * util_format_get_nblocksy(t->texture->format, t->height), + t->stride * util_format_get_nblocksy(t->resource->format, + t->box.height), t->stride, NULL); context->transfer_unmap(context, t); - context->tex_transfer_destroy(context, t); + context->transfer_destroy(context, t); pipe_mutex_unlock(tr_scr->list_mutex); diff --git a/src/gallium/drivers/trace/tr_screen.c b/src/gallium/drivers/trace/tr_screen.c index 25990bdac7..d7c5d42ac2 100644 --- a/src/gallium/drivers/trace/tr_screen.c +++ b/src/gallium/drivers/trace/tr_screen.c @@ -29,7 +29,6 @@ #include "util/u_memory.h" #include "util/u_simple_list.h" -#include "tr_buffer.h" #include "tr_dump.h" #include "tr_dump_state.h" #include "tr_texture.h" @@ -213,72 +212,73 @@ trace_screen_flush_frontbuffer(struct pipe_screen *_screen, */ -static struct pipe_texture * -trace_screen_texture_create(struct pipe_screen *_screen, - const struct pipe_texture *templat) +static struct pipe_resource * +trace_screen_resource_create(struct pipe_screen *_screen, + const struct pipe_resource *templat) { struct trace_screen *tr_scr = trace_screen(_screen); struct pipe_screen *screen = tr_scr->screen; - struct pipe_texture *result; + struct pipe_resource *result; - trace_dump_call_begin("pipe_screen", "texture_create"); + trace_dump_call_begin("pipe_screen", "resource_create"); trace_dump_arg(ptr, screen); trace_dump_arg(template, templat); - result = screen->texture_create(screen, templat); + result = screen->resource_create(screen, templat); trace_dump_ret(ptr, result); trace_dump_call_end(); - result = trace_texture_create(tr_scr, result); + result = trace_resource_create(tr_scr, result); return result; } -static struct pipe_texture * -trace_screen_texture_from_handle(struct pipe_screen *_screen, - const struct pipe_texture *templ, +static struct pipe_resource * +trace_screen_resource_from_handle(struct pipe_screen *_screen, + const struct pipe_resource *templ, struct winsys_handle *handle) { struct trace_screen *tr_screen = trace_screen(_screen); struct pipe_screen *screen = tr_screen->screen; - struct pipe_texture *result; + struct pipe_resource *result; /* TODO trace call */ - result = screen->texture_from_handle(screen, templ, handle); + result = screen->resource_from_handle(screen, templ, handle); - result = trace_texture_create(trace_screen(_screen), result); + result = trace_resource_create(trace_screen(_screen), result); return result; } static boolean -trace_screen_texture_get_handle(struct pipe_screen *_screen, - struct pipe_texture *_texture, +trace_screen_resource_get_handle(struct pipe_screen *_screen, + struct pipe_resource *_texture, struct winsys_handle *handle) { struct trace_screen *tr_screen = trace_screen(_screen); - struct trace_texture *tr_texture = trace_texture(_texture); + struct trace_resource *tr_texture = trace_resource(_texture); struct pipe_screen *screen = tr_screen->screen; - struct pipe_texture *texture = tr_texture->texture; + struct pipe_resource *texture = tr_texture->resource; /* TODO trace call */ - return screen->texture_get_handle(screen, texture, handle); + return screen->resource_get_handle(screen, texture, handle); } static void -trace_screen_texture_destroy(struct pipe_texture *_texture) +trace_screen_resource_destroy(struct pipe_screen *_screen, + struct pipe_resource *_texture) { - struct trace_screen *tr_scr = trace_screen(_texture->screen); - struct trace_texture *tr_tex = trace_texture(_texture); + struct trace_screen *tr_scr = trace_screen(_screen); + struct trace_resource *tr_tex = trace_resource(_texture); struct pipe_screen *screen = tr_scr->screen; - struct pipe_texture *texture = tr_tex->texture; + struct pipe_resource *texture = tr_tex->resource; assert(texture->screen == screen); @@ -289,7 +289,7 @@ trace_screen_texture_destroy(struct pipe_texture *_texture) trace_dump_call_end(); - trace_texture_destroy(tr_tex); + trace_resource_destroy(tr_scr, tr_tex); } @@ -300,15 +300,15 @@ trace_screen_texture_destroy(struct pipe_texture *_texture) static struct pipe_surface * trace_screen_get_tex_surface(struct pipe_screen *_screen, - struct pipe_texture *_texture, + struct pipe_resource *_texture, unsigned face, unsigned level, unsigned zslice, unsigned usage) { struct trace_screen *tr_scr = trace_screen(_screen); - struct trace_texture *tr_tex = trace_texture(_texture); + struct trace_resource *tr_tex = trace_resource(_texture); struct pipe_screen *screen = tr_scr->screen; - struct pipe_texture *texture = tr_tex->texture; + struct pipe_resource *texture = tr_tex->resource; struct pipe_surface *result = NULL; assert(texture->screen == screen); @@ -362,53 +362,15 @@ trace_screen_tex_surface_destroy(struct pipe_surface *_surface) - - -static struct pipe_buffer * -trace_screen_buffer_create(struct pipe_screen *_screen, - unsigned alignment, - unsigned usage, - unsigned size) -{ - struct trace_screen *tr_scr = trace_screen(_screen); - struct pipe_screen *screen = tr_scr->screen; - struct pipe_buffer *result; - - trace_dump_call_begin("pipe_screen", "buffer_create"); - - trace_dump_arg(ptr, screen); - trace_dump_arg(uint, alignment); - trace_dump_arg(uint, usage); - trace_dump_arg(uint, size); - - result = screen->buffer_create(screen, alignment, usage, size); - - trace_dump_ret(ptr, result); - - trace_dump_call_end(); - - /* Zero the buffer to avoid dumping uninitialized memory */ - if(result->usage & PIPE_BUFFER_USAGE_CPU_WRITE) { - void *map; - map = pipe_buffer_map(screen, result, PIPE_BUFFER_USAGE_CPU_WRITE); - if(map) { - memset(map, 0, result->size); - screen->buffer_unmap(screen, result); - } - } - - return trace_buffer_create(tr_scr, result); -} - - -static struct pipe_buffer * +static struct pipe_resource * trace_screen_user_buffer_create(struct pipe_screen *_screen, void *data, - unsigned size) + unsigned size, + unsigned usage) { struct trace_screen *tr_scr = trace_screen(_screen); struct pipe_screen *screen = tr_scr->screen; - struct pipe_buffer *result; + struct pipe_resource *result; trace_dump_call_begin("pipe_screen", "user_buffer_create"); @@ -417,8 +379,9 @@ trace_screen_user_buffer_create(struct pipe_screen *_screen, trace_dump_bytes(data, size); trace_dump_arg_end(); trace_dump_arg(uint, size); + trace_dump_arg(uint, usage); - result = screen->user_buffer_create(screen, data, size); + result = screen->user_buffer_create(screen, data, size, usage); trace_dump_ret(ptr, result); @@ -429,177 +392,10 @@ trace_screen_user_buffer_create(struct pipe_screen *_screen, result->usage |= TRACE_BUFFER_USAGE_USER; } - return trace_buffer_create(tr_scr, result); -} - - -/** - * This function is used to track if data has been changed on a user buffer - * without map/unmap being called. - */ -void -trace_screen_user_buffer_update(struct pipe_screen *_screen, - struct pipe_buffer *_buffer) -{ -#if 0 - struct trace_screen *tr_scr = trace_screen(_screen); - struct pipe_screen *screen = tr_scr->screen; - const void *map; - - if(buffer && buffer->usage & TRACE_BUFFER_USAGE_USER) { - map = screen->buffer_map(screen, buffer, PIPE_BUFFER_USAGE_CPU_READ); - if(map) { - trace_dump_call_begin("pipe_winsys", "buffer_write"); - - trace_dump_arg(ptr, screen); - - trace_dump_arg(ptr, buffer); - - trace_dump_arg_begin("data"); - trace_dump_bytes(map, buffer->size); - trace_dump_arg_end(); - - trace_dump_arg_begin("size"); - trace_dump_uint(buffer->size); - trace_dump_arg_end(); - - trace_dump_call_end(); - - screen->buffer_unmap(screen, buffer); - } - } -#endif -} - - -static void * -trace_screen_buffer_map(struct pipe_screen *_screen, - struct pipe_buffer *_buffer, - unsigned usage) -{ - struct trace_screen *tr_scr = trace_screen(_screen); - struct trace_buffer *tr_buf = trace_buffer(_buffer); - struct pipe_screen *screen = tr_scr->screen; - struct pipe_buffer *buffer = tr_buf->buffer; - void *map; - - assert(screen->buffer_map); - map = screen->buffer_map(screen, buffer, usage); - if(map) { - if(usage & PIPE_BUFFER_USAGE_CPU_WRITE) { - tr_buf->map = map; - } - } - - return map; -} - - -static void * -trace_screen_buffer_map_range(struct pipe_screen *_screen, - struct pipe_buffer *_buffer, - unsigned offset, - unsigned length, - unsigned usage) -{ - struct trace_screen *tr_scr = trace_screen(_screen); - struct trace_buffer *tr_buf = trace_buffer(_buffer); - struct pipe_screen *screen = tr_scr->screen; - struct pipe_buffer *buffer = tr_buf->buffer; - void *map; - - assert(screen->buffer_map_range); - map = screen->buffer_map_range(screen, buffer, offset, length, usage); - if(map) { - if(usage & PIPE_BUFFER_USAGE_CPU_WRITE) { - tr_buf->map = map; - } - } - - return map; -} - - -static void -buffer_write(struct pipe_screen *screen, - struct pipe_buffer *buffer, - unsigned offset, - const char *map, - unsigned size) -{ - assert(map); - - trace_dump_call_begin("pipe_screen", "buffer_write"); - - trace_dump_arg(ptr, screen); - - trace_dump_arg(ptr, buffer); - - trace_dump_arg(uint, offset); - - trace_dump_arg_begin("data"); - trace_dump_bytes(map + offset, size); - trace_dump_arg_end(); - - trace_dump_arg(uint, size); - - trace_dump_call_end(); - -} - - -static void -trace_screen_buffer_flush_mapped_range(struct pipe_screen *_screen, - struct pipe_buffer *_buffer, - unsigned offset, - unsigned length) -{ - struct trace_screen *tr_scr = trace_screen(_screen); - struct trace_buffer *tr_buf = trace_buffer(_buffer); - struct pipe_screen *screen = tr_scr->screen; - struct pipe_buffer *buffer = tr_buf->buffer; - - assert(tr_buf->map); - buffer_write(screen, buffer, offset, tr_buf->map, length); - tr_buf->range_flushed = TRUE; - screen->buffer_flush_mapped_range(screen, buffer, offset, length); + return trace_resource_create(tr_scr, result); } -static void -trace_screen_buffer_unmap(struct pipe_screen *_screen, - struct pipe_buffer *_buffer) -{ - struct trace_screen *tr_scr = trace_screen(_screen); - struct trace_buffer *tr_buf = trace_buffer(_buffer); - struct pipe_screen *screen = tr_scr->screen; - struct pipe_buffer *buffer = tr_buf->buffer; - - if (tr_buf->map && !tr_buf->range_flushed) - buffer_write(screen, buffer, 0, tr_buf->map, buffer->size); - tr_buf->map = NULL; - tr_buf->range_flushed = FALSE; - screen->buffer_unmap(screen, buffer); -} - - -static void -trace_screen_buffer_destroy(struct pipe_buffer *_buffer) -{ - struct trace_screen *tr_scr = trace_screen(_buffer->screen); - struct trace_buffer *tr_buf = trace_buffer(_buffer); - struct pipe_screen *screen = tr_scr->screen; - struct pipe_buffer *buffer = tr_buf->buffer; - - trace_dump_call_begin("pipe_screen", "buffer_destroy"); - - trace_dump_arg(ptr, screen); - trace_dump_arg(ptr, buffer); - - trace_dump_call_end(); - - trace_buffer_destroy(tr_scr, _buffer); -} /******************************************************************** @@ -769,23 +565,13 @@ trace_screen_create(struct pipe_screen *screen) tr_scr->base.is_format_supported = trace_screen_is_format_supported; assert(screen->context_create); tr_scr->base.context_create = trace_screen_context_create; - tr_scr->base.texture_create = trace_screen_texture_create; - tr_scr->base.texture_from_handle = trace_screen_texture_from_handle; - tr_scr->base.texture_get_handle = trace_screen_texture_get_handle; - tr_scr->base.texture_destroy = trace_screen_texture_destroy; + tr_scr->base.resource_create = trace_screen_resource_create; + tr_scr->base.resource_from_handle = trace_screen_resource_from_handle; + tr_scr->base.resource_get_handle = trace_screen_resource_get_handle; + tr_scr->base.resource_destroy = trace_screen_resource_destroy; tr_scr->base.get_tex_surface = trace_screen_get_tex_surface; tr_scr->base.tex_surface_destroy = trace_screen_tex_surface_destroy; - tr_scr->base.buffer_create = trace_screen_buffer_create; tr_scr->base.user_buffer_create = trace_screen_user_buffer_create; - if (screen->buffer_map) - tr_scr->base.buffer_map = trace_screen_buffer_map; - if (screen->buffer_map_range) - tr_scr->base.buffer_map_range = trace_screen_buffer_map_range; - if (screen->buffer_flush_mapped_range) - tr_scr->base.buffer_flush_mapped_range = trace_screen_buffer_flush_mapped_range; - if (screen->buffer_unmap) - tr_scr->base.buffer_unmap = trace_screen_buffer_unmap; - tr_scr->base.buffer_destroy = trace_screen_buffer_destroy; tr_scr->base.fence_reference = trace_screen_fence_reference; tr_scr->base.fence_signalled = trace_screen_fence_signalled; tr_scr->base.fence_finish = trace_screen_fence_finish; diff --git a/src/gallium/drivers/trace/tr_screen.h b/src/gallium/drivers/trace/tr_screen.h index 9bfbe72e2c..0d16ea4ec4 100644 --- a/src/gallium/drivers/trace/tr_screen.h +++ b/src/gallium/drivers/trace/tr_screen.h @@ -100,10 +100,6 @@ trace_enabled(void); struct trace_screen * trace_screen(struct pipe_screen *screen); -void -trace_screen_user_buffer_update(struct pipe_screen *screen, - struct pipe_buffer *buffer); - #define trace_screen_add_to_list(tr_scr, name, obj) \ do { \ pipe_mutex_lock(tr_scr->list_mutex); \ diff --git a/src/gallium/drivers/trace/tr_texture.c b/src/gallium/drivers/trace/tr_texture.c index d818e21bb8..1132dc9272 100644 --- a/src/gallium/drivers/trace/tr_texture.c +++ b/src/gallium/drivers/trace/tr_texture.c @@ -35,51 +35,50 @@ #include "tr_texture.h" -struct pipe_texture * -trace_texture_create(struct trace_screen *tr_scr, - struct pipe_texture *texture) +struct pipe_resource * +trace_resource_create(struct trace_screen *tr_scr, + struct pipe_resource *texture) { - struct trace_texture *tr_tex; + struct trace_resource *tr_tex; if(!texture) goto error; assert(texture->screen == tr_scr->screen); - tr_tex = CALLOC_STRUCT(trace_texture); + tr_tex = CALLOC_STRUCT(trace_resource); if(!tr_tex) goto error; - memcpy(&tr_tex->base, texture, sizeof(struct pipe_texture)); + memcpy(&tr_tex->base, texture, sizeof(struct pipe_resource)); pipe_reference_init(&tr_tex->base.reference, 1); tr_tex->base.screen = &tr_scr->base; - tr_tex->texture = texture; + tr_tex->resource = texture; trace_screen_add_to_list(tr_scr, textures, tr_tex); return &tr_tex->base; error: - pipe_texture_reference(&texture, NULL); + pipe_resource_reference(&texture, NULL); return NULL; } void -trace_texture_destroy(struct trace_texture *tr_tex) +trace_resource_destroy(struct trace_screen *tr_scr, + struct trace_resource *tr_tex) { - struct trace_screen *tr_scr = trace_screen(tr_tex->base.screen); - trace_screen_remove_from_list(tr_scr, textures, tr_tex); - pipe_texture_reference(&tr_tex->texture, NULL); + pipe_resource_reference(&tr_tex->resource, NULL); FREE(tr_tex); } struct pipe_surface * -trace_surface_create(struct trace_texture *tr_tex, +trace_surface_create(struct trace_resource *tr_tex, struct pipe_surface *surface) { struct trace_screen *tr_scr = trace_screen(tr_tex->base.screen); @@ -88,7 +87,7 @@ trace_surface_create(struct trace_texture *tr_tex, if(!surface) goto error; - assert(surface->texture == tr_tex->texture); + assert(surface->texture == tr_tex->resource); tr_surf = CALLOC_STRUCT(trace_surface); if(!tr_surf) @@ -98,7 +97,7 @@ trace_surface_create(struct trace_texture *tr_tex, pipe_reference_init(&tr_surf->base.reference, 1); tr_surf->base.texture = NULL; - pipe_texture_reference(&tr_surf->base.texture, &tr_tex->base); + pipe_resource_reference(&tr_surf->base.texture, &tr_tex->base); tr_surf->surface = surface; trace_screen_add_to_list(tr_scr, surfaces, tr_surf); @@ -118,7 +117,7 @@ trace_surface_destroy(struct trace_surface *tr_surf) trace_screen_remove_from_list(tr_scr, surfaces, tr_surf); - pipe_texture_reference(&tr_surf->base.texture, NULL); + pipe_resource_reference(&tr_surf->base.texture, NULL); pipe_surface_reference(&tr_surf->surface, NULL); FREE(tr_surf); } @@ -126,7 +125,7 @@ trace_surface_destroy(struct trace_surface *tr_surf) struct pipe_transfer * trace_transfer_create(struct trace_context *tr_ctx, - struct trace_texture *tr_tex, + struct trace_resource *tr_tex, struct pipe_transfer *transfer) { struct trace_screen *tr_scr = trace_screen(tr_tex->base.screen); @@ -135,7 +134,7 @@ trace_transfer_create(struct trace_context *tr_ctx, if(!transfer) goto error; - assert(transfer->texture == tr_tex->texture); + assert(transfer->resource == tr_tex->resource); tr_trans = CALLOC_STRUCT(trace_transfer); if(!tr_trans) @@ -143,18 +142,18 @@ trace_transfer_create(struct trace_context *tr_ctx, memcpy(&tr_trans->base, transfer, sizeof(struct pipe_transfer)); - tr_trans->base.texture = NULL; + tr_trans->base.resource = NULL; tr_trans->transfer = transfer; - pipe_texture_reference(&tr_trans->base.texture, &tr_tex->base); - assert(tr_trans->base.texture == &tr_tex->base); + pipe_resource_reference(&tr_trans->base.resource, &tr_tex->base); + assert(tr_trans->base.resource == &tr_tex->base); trace_screen_add_to_list(tr_scr, transfers, tr_trans); return &tr_trans->base; error: - tr_ctx->pipe->tex_transfer_destroy(tr_ctx->pipe, transfer); + tr_ctx->pipe->transfer_destroy(tr_ctx->pipe, transfer); return NULL; } @@ -169,8 +168,8 @@ trace_transfer_destroy(struct trace_context *tr_context, trace_screen_remove_from_list(tr_scr, transfers, tr_trans); - pipe_texture_reference(&tr_trans->base.texture, NULL); - context->tex_transfer_destroy(context, transfer); + pipe_resource_reference(&tr_trans->base.resource, NULL); + context->transfer_destroy(context, transfer); FREE(tr_trans); } diff --git a/src/gallium/drivers/trace/tr_texture.h b/src/gallium/drivers/trace/tr_texture.h index 66250465e4..6513995d50 100644 --- a/src/gallium/drivers/trace/tr_texture.h +++ b/src/gallium/drivers/trace/tr_texture.h @@ -36,11 +36,11 @@ struct trace_context; -struct trace_texture +struct trace_resource { - struct pipe_texture base; + struct pipe_resource base; - struct pipe_texture *texture; + struct pipe_resource *resource; struct tr_list list; }; @@ -77,13 +77,13 @@ struct trace_transfer }; -static INLINE struct trace_texture * -trace_texture(struct pipe_texture *texture) +static INLINE struct trace_resource * +trace_resource(struct pipe_resource *texture) { if(!texture) return NULL; (void)trace_screen(texture->screen); - return (struct trace_texture *)texture; + return (struct trace_resource *)texture; } @@ -92,7 +92,7 @@ trace_surface(struct pipe_surface *surface) { if(!surface) return NULL; - (void)trace_texture(surface->texture); + (void)trace_resource(surface->texture); return (struct trace_surface *)surface; } @@ -111,20 +111,21 @@ trace_transfer(struct pipe_transfer *transfer) { if(!transfer) return NULL; - (void)trace_texture(transfer->texture); + (void)trace_resource(transfer->resource); return (struct trace_transfer *)transfer; } -struct pipe_texture * -trace_texture_create(struct trace_screen *tr_scr, - struct pipe_texture *texture); +struct pipe_resource * +trace_resource_create(struct trace_screen *tr_scr, + struct pipe_resource *texture); void -trace_texture_destroy(struct trace_texture *tr_tex); +trace_resource_destroy(struct trace_screen *tr_scr, + struct trace_resource *tr_tex); struct pipe_surface * -trace_surface_create(struct trace_texture *tr_tex, +trace_surface_create(struct trace_resource *tr_tex, struct pipe_surface *surface); void @@ -132,7 +133,7 @@ trace_surface_destroy(struct trace_surface *tr_surf); struct pipe_transfer * trace_transfer_create(struct trace_context *tr_ctx, - struct trace_texture *tr_tex, + struct trace_resource *tr_tex, struct pipe_transfer *transfer); void diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h index d1b734a9f9..60fa6b32bc 100644 --- a/src/gallium/include/pipe/p_context.h +++ b/src/gallium/include/pipe/p_context.h @@ -65,7 +65,7 @@ struct pipe_context { unsigned mode, unsigned start, unsigned count); void (*draw_elements)( struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, unsigned count); @@ -77,7 +77,7 @@ struct pipe_context { unsigned instanceCount); void (*draw_elements_instanced)(struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, @@ -91,7 +91,7 @@ struct pipe_context { * module. */ void (*draw_range_elements)( struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexBuffer, unsigned indexSize, unsigned minIndex, unsigned maxIndex, @@ -200,7 +200,7 @@ struct pipe_context { void (*set_constant_buffer)( struct pipe_context *, uint shader, uint index, - struct pipe_buffer *buf ); + struct pipe_resource *buf ); void (*set_framebuffer_state)( struct pipe_context *, const struct pipe_framebuffer_state * ); @@ -291,27 +291,15 @@ struct pipe_context { * \param level mipmap level. * \return mask of PIPE_REFERENCED_FOR_READ/WRITE or PIPE_UNREFERENCED */ - unsigned int (*is_texture_referenced)(struct pipe_context *pipe, - struct pipe_texture *texture, - unsigned face, unsigned level); - - /** - * Check whether a buffer is referenced by an unflushed hw command. - * The state-tracker uses this function to avoid unnecessary flushes. - * It is safe (but wasteful) to always return - * PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE. - * \param pipe context whose unflushed hw commands will be checked. - * \param buf buffer to check. - * \return mask of PIPE_REFERENCED_FOR_READ/WRITE or PIPE_UNREFERENCED - */ - unsigned int (*is_buffer_referenced)(struct pipe_context *pipe, - struct pipe_buffer *buf); + unsigned int (*is_resource_referenced)(struct pipe_context *pipe, + struct pipe_resource *texture, + unsigned face, unsigned level); /** * Create a view on a texture to be used by a shader stage. */ struct pipe_sampler_view * (*create_sampler_view)(struct pipe_context *ctx, - struct pipe_texture *texture, + struct pipe_resource *texture, const struct pipe_sampler_view *templat); void (*sampler_view_destroy)(struct pipe_context *ctx, @@ -324,24 +312,42 @@ struct pipe_context { * Transfers are (by default) context-private and allow uploads to be * interleaved with */ - struct pipe_transfer *(*get_tex_transfer)(struct pipe_context *, - struct pipe_texture *texture, - unsigned face, unsigned level, - unsigned zslice, - enum pipe_transfer_usage usage, - unsigned x, unsigned y, - unsigned w, unsigned h); - - void (*tex_transfer_destroy)(struct pipe_context *, + struct pipe_transfer *(*get_transfer)(struct pipe_context *, + struct pipe_resource *resource, + struct pipe_subresource, + enum pipe_transfer_usage, + const struct pipe_box *); + + void (*transfer_destroy)(struct pipe_context *, struct pipe_transfer *); void *(*transfer_map)( struct pipe_context *, struct pipe_transfer *transfer ); + /* If transfer was created with WRITE|FLUSH_EXPLICIT, only the + * regions specified with this call are guaranteed to be written to + * the resource. + */ + void (*transfer_flush_region)( struct pipe_context *, + struct pipe_transfer *transfer, + const struct pipe_box *); + void (*transfer_unmap)( struct pipe_context *, struct pipe_transfer *transfer ); + /* One-shot transfer operation with data supplied in a user + * pointer. XXX: strides?? + */ + void (*transfer_inline_write)( struct pipe_context *, + struct pipe_resource *, + struct pipe_subresource, + enum pipe_transfer_usage, + const struct pipe_box *, + const void *data, + unsigned stride, + unsigned slice_stride); + }; diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index c1e291b9da..62e1401f07 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -137,10 +137,11 @@ enum pipe_error { /** Texture types */ enum pipe_texture_target { - PIPE_TEXTURE_1D = 0, - PIPE_TEXTURE_2D = 1, - PIPE_TEXTURE_3D = 2, - PIPE_TEXTURE_CUBE = 3, + PIPE_BUFFER = 0, + PIPE_TEXTURE_1D = 1, + PIPE_TEXTURE_2D = 2, + PIPE_TEXTURE_3D = 3, + PIPE_TEXTURE_CUBE = 4, PIPE_MAX_TEXTURE_TYPES }; @@ -208,10 +209,23 @@ enum pipe_texture_target { * Transfer object usage flags */ enum pipe_transfer_usage { + /** + * Resource contents read back (or accessed directly) at transfer + * create time. + */ PIPE_TRANSFER_READ = (1 << 0), + + /** + * Resource contents will be written back at transfer_destroy + * time (or modified as a result of being accessed directly). + */ PIPE_TRANSFER_WRITE = (1 << 1), - /** Read/modify/write */ + + /** + * Read/modify/write + */ PIPE_TRANSFER_READ_WRITE = PIPE_TRANSFER_READ | PIPE_TRANSFER_WRITE, + /** * The transfer should map the texture storage directly. The driver may * return NULL if that isn't possible, and the state tracker needs to cope @@ -221,7 +235,54 @@ enum pipe_transfer_usage { * does read/modify/write cycles on them directly, and a more complicated * path which uses minimal read and write transfers. */ - PIPE_TRANSFER_MAP_DIRECTLY = (1 << 2) + PIPE_TRANSFER_MAP_DIRECTLY = (1 << 2), + + /** + * Discards the memory within the mapped region. + * + * It should not be used with PIPE_TRANSFER_CPU_READ. + * + * See also: + * - OpenGL's ARB_map_buffer_range extension, MAP_INVALIDATE_RANGE_BIT flag. + * - Direct3D's D3DLOCK_DISCARD flag. + */ + PIPE_TRANSFER_DISCARD = (1 << 8), + + /** + * Fail if the resource cannot be mapped immediately. + * + * See also: + * - Direct3D's D3DLOCK_DONOTWAIT flag. + * - Mesa3D's MESA_MAP_NOWAIT_BIT flag. + * - WDDM's D3DDDICB_LOCKFLAGS.DonotWait flag. + */ + PIPE_TRANSFER_DONTBLOCK = (1 << 9), + + /** + * Do not attempt to synchronize pending operations on the resource when mapping. + * + * It should not be used with PIPE_TRANSFER_CPU_READ. + * + * See also: + * - OpenGL's ARB_map_buffer_range extension, MAP_UNSYNCHRONIZED_BIT flag. + * - Direct3D's D3DLOCK_NOOVERWRITE flag. + * - WDDM's D3DDDICB_LOCKFLAGS.IgnoreSync flag. + */ + PIPE_TRANSFER_UNSYNCHRONIZED = (1 << 10), + PIPE_TRANSFER_NOOVERWRITE = (1 << 10), /* are these really the same?? */ + + /** + * Written ranges will be notified later with + * pipe_context::transfer_flush_region. + * + * It should not be used with PIPE_TRANSFER_CPU_READ. + * + * See also: + * - pipe_context::transfer_flush_region + * - OpenGL's ARB_map_buffer_range extension, MAP_FLUSH_EXPLICIT_BIT flag. + */ + PIPE_TRANSFER_FLUSH_EXPLICIT = (1 << 11), + }; @@ -238,63 +299,6 @@ enum pipe_transfer_usage { #define PIPE_BUFFER_USAGE_INDEX (1 << 6) #define PIPE_BUFFER_USAGE_CONSTANT (1 << 7) -/* - * CPU access flags. - * - * These flags should only be used for texture transfers or when mapping - * buffers. - * - * Note that the PIPE_BUFFER_USAGE_CPU_xxx flags above are also used for - * mapping. Either PIPE_BUFFER_USAGE_CPU_READ or PIPE_BUFFER_USAGE_CPU_WRITE - * must be set. - */ - -/** - * Discards the memory within the mapped region. - * - * It should not be used with PIPE_BUFFER_USAGE_CPU_READ. - * - * See also: - * - OpenGL's ARB_map_buffer_range extension, MAP_INVALIDATE_RANGE_BIT flag. - * - Direct3D's D3DLOCK_DISCARD flag. - */ -#define PIPE_BUFFER_USAGE_DISCARD (1 << 8) - -/** - * Fail if the resource cannot be mapped immediately. - * - * See also: - * - Direct3D's D3DLOCK_DONOTWAIT flag. - * - Mesa3D's MESA_MAP_NOWAIT_BIT flag. - * - WDDM's D3DDDICB_LOCKFLAGS.DonotWait flag. - */ -#define PIPE_BUFFER_USAGE_DONTBLOCK (1 << 9) - -/** - * Do not attempt to synchronize pending operations on the resource when mapping. - * - * It should not be used with PIPE_BUFFER_USAGE_CPU_READ. - * - * See also: - * - OpenGL's ARB_map_buffer_range extension, MAP_UNSYNCHRONIZED_BIT flag. - * - Direct3D's D3DLOCK_NOOVERWRITE flag. - * - WDDM's D3DDDICB_LOCKFLAGS.IgnoreSync flag. - */ -#define PIPE_BUFFER_USAGE_UNSYNCHRONIZED (1 << 10) - -/** - * Written ranges will be notified later with - * pipe_screen::buffer_flush_mapped_range. - * - * It should not be used with PIPE_BUFFER_USAGE_CPU_READ. - * - * See also: - * - pipe_screen::buffer_flush_mapped_range - * - OpenGL's ARB_map_buffer_range extension, MAP_FLUSH_EXPLICIT_BIT flag. - */ -#define PIPE_BUFFER_USAGE_FLUSH_EXPLICIT (1 << 11) - -/** Pipe driver custom usage flags should be greater or equal to this value */ #define PIPE_BUFFER_USAGE_CUSTOM (1 << 16) /* Convenient shortcuts */ diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h index b7cb83abbe..cc9cebca6e 100644 --- a/src/gallium/include/pipe/p_screen.h +++ b/src/gallium/include/pipe/p_screen.h @@ -54,8 +54,8 @@ struct winsys_handle; /** Opaque type */ struct pipe_fence_handle; struct pipe_winsys; -struct pipe_buffer; struct pipe_texture; +struct pipe_resource; struct pipe_surface; struct pipe_video_surface; struct pipe_transfer; @@ -106,35 +106,36 @@ struct pipe_screen { /** * Create a new texture object, using the given template info. */ - struct pipe_texture * (*texture_create)(struct pipe_screen *, - const struct pipe_texture *templat); + struct pipe_resource * (*resource_create)(struct pipe_screen *, + const struct pipe_resource *template); /** * Create a texture from a winsys_handle. The handle is often created in * another process by first creating a pipe texture and then calling * texture_get_handle. */ - struct pipe_texture * (*texture_from_handle)(struct pipe_screen *, - const struct pipe_texture *templat, - struct winsys_handle *handle); + struct pipe_resource * (*resource_from_handle)(struct pipe_screen *, + const struct pipe_resource *template, + struct winsys_handle *handle); /** * Get a winsys_handle from a texture. Some platforms/winsys requires * that the texture is created with a special usage flag like * DISPLAYTARGET or PRIMARY. */ - boolean (*texture_get_handle)(struct pipe_screen *, - struct pipe_texture *tex, - struct winsys_handle *handle); + boolean (*resource_get_handle)(struct pipe_screen *, + struct pipe_resource *tex, + struct winsys_handle *handle); - void (*texture_destroy)(struct pipe_texture *pt); + void (*resource_destroy)(struct pipe_screen *, + struct pipe_resource *pt); /** Get a 2D surface which is a "view" into a texture * \param usage bitmaks of PIPE_BUFFER_USAGE_* read/write flags */ struct pipe_surface *(*get_tex_surface)(struct pipe_screen *, - struct pipe_texture *texture, + struct pipe_resource *resource, unsigned face, unsigned level, unsigned zslice, unsigned usage ); @@ -144,17 +145,6 @@ struct pipe_screen { /** - * Create a new buffer. - * \param alignment buffer start address alignment in bytes - * \param usage bitmask of PIPE_BUFFER_USAGE_x - * \param size size in bytes - */ - struct pipe_buffer *(*buffer_create)( struct pipe_screen *screen, - unsigned alignment, - unsigned usage, - unsigned size ); - - /** * Create a buffer that wraps user-space data. * * Effectively this schedules a delayed call to buffer_create @@ -175,65 +165,10 @@ struct pipe_screen { * Note that ptr may be accessed at any time upto the time when the * buffer is destroyed, so the data must not be freed before then. */ - struct pipe_buffer *(*user_buffer_create)(struct pipe_screen *screen, - void *ptr, - unsigned bytes); - - - - /** - * Map the entire data store of a buffer object into the client's address. - * flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags. - */ - void *(*buffer_map)( struct pipe_screen *screen, - struct pipe_buffer *buf, - unsigned usage ); - /** - * Map a subrange of the buffer data store into the client's address space. - * - * The returned pointer is always relative to buffer start, regardless of - * the specified range. This is different from the ARB_map_buffer_range - * semantics because we don't forbid multiple mappings of the same buffer - * (yet). - */ - void *(*buffer_map_range)( struct pipe_screen *screen, - struct pipe_buffer *buf, - unsigned offset, - unsigned length, - unsigned usage); - - /** - * Notify a range that was actually written into. - * - * Can only be used if the buffer was mapped with the - * PIPE_BUFFER_USAGE_CPU_WRITE and PIPE_BUFFER_USAGE_FLUSH_EXPLICIT flags - * set. - * - * The range is relative to the buffer start, regardless of the range - * specified to buffer_map_range. This is different from the - * ARB_map_buffer_range semantics because we don't forbid multiple mappings - * of the same buffer (yet). - * - */ - void (*buffer_flush_mapped_range)( struct pipe_screen *screen, - struct pipe_buffer *buf, - unsigned offset, - unsigned length); - - /** - * Unmap buffer. - * - * If the buffer was mapped with PIPE_BUFFER_USAGE_CPU_WRITE flag but not - * PIPE_BUFFER_USAGE_FLUSH_EXPLICIT then the pipe driver will - * assume that the whole buffer was written. This is mostly for backward - * compatibility purposes and may affect performance -- the state tracker - * should always specify exactly what got written while the buffer was - * mapped. - */ - void (*buffer_unmap)( struct pipe_screen *screen, - struct pipe_buffer *buf ); - - void (*buffer_destroy)( struct pipe_buffer *buf ); + struct pipe_resource *(*user_buffer_create)(struct pipe_screen *screen, + void *ptr, + unsigned bytes, + unsigned usage); /** * Create a video surface suitable for use as a decoding target by the diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 11072407d9..8ccce64894 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -71,19 +71,6 @@ struct pipe_reference }; -/** - * The driver will certainly subclass this to include actual memory - * management information. - */ -struct pipe_buffer -{ - struct pipe_reference reference; - unsigned size; - struct pipe_screen *screen; - unsigned alignment; - unsigned usage; -}; - /** * Primitive (point/line/tri) rasterization info @@ -285,20 +272,25 @@ struct pipe_sampler_state struct pipe_surface { struct pipe_reference reference; + struct pipe_resource *texture; /**< resource into which this is a view */ enum pipe_format format; + unsigned width; /**< logical width in pixels */ unsigned height; /**< logical height in pixels */ + unsigned layout; /**< PIPE_SURFACE_LAYOUT_x */ unsigned offset; /**< offset from start of buffer, in bytes */ unsigned usage; /**< bitmask of PIPE_BUFFER_USAGE_x */ unsigned zslice; - struct pipe_texture *texture; /**< texture into which this is a view */ unsigned face; unsigned level; }; + + + /** * A view into a texture that can be bound to a shader stage. */ @@ -306,7 +298,7 @@ struct pipe_sampler_view { struct pipe_reference reference; enum pipe_format format; /**< typed PIPE_FORMAT_x */ - struct pipe_texture *texture; /**< texture into which this is a view */ + struct pipe_resource *texture; /**< texture into which this is a view */ struct pipe_context *context; /**< context this view belongs to */ unsigned first_level:8; /**< first mipmap level */ unsigned last_level:8; /**< last mipmap level */ @@ -317,49 +309,59 @@ struct pipe_sampler_view }; -/** - * Transfer object. For data transfer to/from a texture. - */ -struct pipe_transfer +struct pipe_box { - unsigned x; /**< x offset from start of texture image */ - unsigned y; /**< y offset from start of texture image */ - unsigned width; /**< logical width in pixels */ - unsigned height; /**< logical height in pixels */ - unsigned stride; /**< stride in bytes between rows of blocks */ - enum pipe_transfer_usage usage; /**< PIPE_TRANSFER_* */ - - struct pipe_texture *texture; /**< texture to transfer to/from */ - unsigned face; - unsigned level; - unsigned zslice; + unsigned x; + unsigned y; + unsigned z; + unsigned width; + unsigned height; + unsigned depth; }; -/** - * Texture object. - */ -struct pipe_texture -{ - struct pipe_reference reference; +struct pipe_resource +{ + struct pipe_reference reference; + struct pipe_screen *screen; /**< screen that this texture belongs to */ enum pipe_texture_target target; /**< PIPE_TEXTURE_x */ enum pipe_format format; /**< PIPE_FORMAT_x */ unsigned width0; unsigned height0; unsigned depth0; - unsigned last_level:8; /**< Index of last mipmap level present/defined */ - unsigned nr_samples:8; /**< for multisampled surfaces, nr of samples */ + unsigned usage; /* xxx: unify with tex_usage */ unsigned tex_usage; /**< bitmask of PIPE_TEXTURE_USAGE_* */ +}; - struct pipe_screen *screen; /**< screen that this texture belongs to */ + +struct pipe_subresource +{ + unsigned face:16; + unsigned level:16; +}; + + +/** + * Transfer object. For data transfer to/from a texture. + */ +struct pipe_transfer +{ + struct pipe_resource *resource; /**< resource to transfer to/from */ + struct pipe_subresource sr; + enum pipe_transfer_usage usage; + struct pipe_box box; + unsigned stride; + unsigned slice_stride; + void *data; }; + /** * A vertex buffer. Typically, all the vertex data/attributes for * drawing something will be in one buffer. But it's also possible, for @@ -370,7 +372,7 @@ struct pipe_vertex_buffer unsigned stride; /**< stride to same attrib in next vertex, in bytes */ unsigned max_index; /**< number of vertices in this buffer */ unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */ - struct pipe_buffer *buffer; /**< the actual buffer */ + struct pipe_resource *buffer; /**< the actual buffer */ }; diff --git a/src/gallium/include/pipe/p_video_context.h b/src/gallium/include/pipe/p_video_context.h index 6ae31418fa..5d1ab47418 100644 --- a/src/gallium/include/pipe/p_video_context.h +++ b/src/gallium/include/pipe/p_video_context.h @@ -35,7 +35,6 @@ extern "C" { #include <pipe/p_video_state.h> struct pipe_screen; -struct pipe_buffer; struct pipe_surface; struct pipe_video_surface; struct pipe_macroblock; @@ -63,7 +62,7 @@ struct pipe_video_context /*@{*/ void (*decode_bitstream)(struct pipe_video_context *vpipe, unsigned num_bufs, - struct pipe_buffer **bitstream_buf); + struct pipe_resource **bitstream_buf); void (*decode_macroblocks)(struct pipe_video_context *vpipe, struct pipe_video_surface *past, diff --git a/src/gallium/include/pipe/p_video_state.h b/src/gallium/include/pipe/p_video_state.h index 77e22d0a56..2f2164ace7 100644 --- a/src/gallium/include/pipe/p_video_state.h +++ b/src/gallium/include/pipe/p_video_state.h @@ -171,10 +171,10 @@ struct pipe_mpeg12_picture_desc unsigned alternate_scan; unsigned full_pel_forward_vector; unsigned full_pel_backward_vector; - struct pipe_buffer *intra_quantizer_matrix; - struct pipe_buffer *non_intra_quantizer_matrix; - struct pipe_buffer *chroma_intra_quantizer_matrix; - struct pipe_buffer *chroma_non_intra_quantizer_matrix; + struct pipe_resource *intra_quantizer_matrix; + struct pipe_resource *non_intra_quantizer_matrix; + struct pipe_resource *chroma_intra_quantizer_matrix; + struct pipe_resource *chroma_non_intra_quantizer_matrix; }; #endif diff --git a/src/gallium/state_trackers/python/st_device.c b/src/gallium/state_trackers/python/st_device.c index 0d87c705e7..c09452f777 100644 --- a/src/gallium/state_trackers/python/st_device.c +++ b/src/gallium/state_trackers/python/st_device.c @@ -245,7 +245,7 @@ st_context_create(struct st_device *st_dev) st_ctx->default_texture = screen->texture_create( screen, &templat ); if(st_ctx->default_texture) { - transfer = screen->get_tex_transfer(screen, + transfer = screen->get_transfer(screen, st_ctx->default_texture, 0, 0, 0, PIPE_TRANSFER_WRITE, diff --git a/src/gallium/state_trackers/python/st_sample.c b/src/gallium/state_trackers/python/st_sample.c index e180815346..ea27275325 100644 --- a/src/gallium/state_trackers/python/st_sample.c +++ b/src/gallium/state_trackers/python/st_sample.c @@ -533,7 +533,7 @@ st_sample_surface(struct st_surface *surface, float *rgba) struct pipe_transfer *transfer; void *raw; - transfer = screen->get_tex_transfer(screen, + transfer = screen->get_transfer(screen, surface->texture, surface->face, surface->level, diff --git a/src/gallium/state_trackers/vega/api_filters.c b/src/gallium/state_trackers/vega/api_filters.c index 18e2cc1f25..01c9896edd 100644 --- a/src/gallium/state_trackers/vega/api_filters.c +++ b/src/gallium/state_trackers/vega/api_filters.c @@ -53,17 +53,17 @@ struct filter_info { const void *const_buffer; VGint const_buffer_len; VGTilingMode tiling_mode; - struct pipe_texture *extra_texture; + struct pipe_resource *extra_texture; }; -static INLINE struct pipe_texture *create_texture_1d(struct vg_context *ctx, +static INLINE struct pipe_resource *create_texture_1d(struct vg_context *ctx, const VGuint *color_data, const VGint color_data_len) { struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_texture *tex = 0; - struct pipe_texture templ; + struct pipe_resource *tex = 0; + struct pipe_resource templ; memset(&templ, 0, sizeof(templ)); templ.target = PIPE_TEXTURE_1D; @@ -74,18 +74,18 @@ static INLINE struct pipe_texture *create_texture_1d(struct vg_context *ctx, templ.depth0 = 1; templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER; - tex = screen->texture_create(screen, &templ); + tex = screen->resource_create(screen, &templ); { /* upload color_data */ struct pipe_transfer *transfer = - pipe->get_tex_transfer(pipe, tex, + pipe_get_transfer(pipe, tex, 0, 0, 0, PIPE_TRANSFER_READ_WRITE , 0, 0, tex->width0, tex->height0); void *map = pipe->transfer_map(pipe, transfer); memcpy(map, color_data, sizeof(VGint)*color_data_len); pipe->transfer_unmap(pipe, transfer); - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } return tex; @@ -147,11 +147,11 @@ static void setup_constant_buffer(struct vg_context *ctx, const void *buffer, VGint param_bytes) { struct pipe_context *pipe = ctx->pipe; - struct pipe_buffer **cbuf = &ctx->filter.buffer; + struct pipe_resource **cbuf = &ctx->filter.buffer; /* We always need to get a new buffer, to keep the drivers simple and * avoid gratuitous rendering synchronization. */ - pipe_buffer_reference(cbuf, NULL); + pipe_resource_reference(cbuf, NULL); *cbuf = pipe_buffer_create(pipe->screen, 16, PIPE_BUFFER_USAGE_CONSTANT, @@ -168,7 +168,7 @@ static void setup_constant_buffer(struct vg_context *ctx, const void *buffer, static void setup_samplers(struct vg_context *ctx, struct filter_info *info) { struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; - struct pipe_texture *textures[PIPE_MAX_SAMPLERS]; + struct pipe_resource *textures[PIPE_MAX_SAMPLERS]; struct pipe_sampler_state sampler[3]; int num_samplers = 0; int num_textures = 0; @@ -688,7 +688,7 @@ void vgLookup(VGImage dst, VGImage src, struct vg_image *d, *s; VGuint color_data[256]; VGint i; - struct pipe_texture *lut_texture; + struct pipe_resource *lut_texture; VGfloat buffer[4]; struct filter_info info; @@ -732,7 +732,7 @@ void vgLookup(VGImage dst, VGImage src, execute_filter(ctx, &info); - pipe_texture_reference(&lut_texture, NULL); + pipe_resource_reference(&lut_texture, NULL); } void vgLookupSingle(VGImage dst, VGImage src, @@ -743,7 +743,7 @@ void vgLookupSingle(VGImage dst, VGImage src, { struct vg_context *ctx = vg_current_context(); struct vg_image *d, *s; - struct pipe_texture *lut_texture; + struct pipe_resource *lut_texture; VGfloat buffer[4]; struct filter_info info; VGuint color_data[256]; @@ -801,5 +801,5 @@ void vgLookupSingle(VGImage dst, VGImage src, execute_filter(ctx, &info); - pipe_texture_reference(&lut_texture, NULL); + pipe_resource_reference(&lut_texture, NULL); } diff --git a/src/gallium/state_trackers/vega/api_images.c b/src/gallium/state_trackers/vega/api_images.c index fec473d9d2..6c7fd3b346 100644 --- a/src/gallium/state_trackers/vega/api_images.c +++ b/src/gallium/state_trackers/vega/api_images.c @@ -441,9 +441,9 @@ void vgReadPixels(void * data, VGint dataStride, { struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, strb->texture, 0, 0, 0, - PIPE_TRANSFER_READ, - 0, 0, width, height); + transfer = pipe_get_transfer(pipe, strb->texture, 0, 0, 0, + PIPE_TRANSFER_READ, + 0, 0, width, height); /* Do a row at a time to flip image data vertically */ for (i = 0; i < height; i++) { @@ -457,7 +457,7 @@ void vgReadPixels(void * data, VGint dataStride, dst += dataStride; } - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } } diff --git a/src/gallium/state_trackers/vega/api_masks.c b/src/gallium/state_trackers/vega/api_masks.c index 2f2d925252..eecae090a5 100644 --- a/src/gallium/state_trackers/vega/api_masks.c +++ b/src/gallium/state_trackers/vega/api_masks.c @@ -51,7 +51,7 @@ draw_clear_quad(struct vg_context *st, const VGfloat color[4]) { struct pipe_context *pipe = st->pipe; - struct pipe_buffer *buf; + struct pipe_resource *buf; VGuint i; /* positions */ @@ -81,7 +81,8 @@ draw_clear_quad(struct vg_context *st, /* put vertex data into vbuf */ buf = pipe_user_buffer_create(pipe->screen, st->clear.vertices, - sizeof(st->clear.vertices)); + sizeof(st->clear.vertices), + PIPE_BUFFER_USAGE_VERTEX); /* draw */ @@ -93,7 +94,7 @@ draw_clear_quad(struct vg_context *st, 4, /* verts */ 2); /* attribs/vert */ - pipe_buffer_reference(&buf, NULL); + pipe_resource_reference(&buf, NULL); } } diff --git a/src/gallium/state_trackers/vega/image.c b/src/gallium/state_trackers/vega/image.c index a71579cd26..2f55d80601 100644 --- a/src/gallium/state_trackers/vega/image.c +++ b/src/gallium/state_trackers/vega/image.c @@ -80,8 +80,8 @@ static INLINE void vg_sync_size(VGfloat *src_loc, VGfloat *dst_loc) static void vg_copy_texture(struct vg_context *ctx, - struct pipe_texture *dst, VGint dx, VGint dy, - struct pipe_texture *src, VGint sx, VGint sy, + struct pipe_resource *dst, VGint dx, VGint dy, + struct pipe_resource *src, VGint sx, VGint sy, VGint width, VGint height) { VGfloat dst_loc[4], src_loc[4]; @@ -216,9 +216,9 @@ void vg_copy_surface(struct vg_context *ctx, } -static struct pipe_texture *image_texture(struct vg_image *img) +static struct pipe_resource *image_texture(struct vg_image *img) { - struct pipe_texture *tex = img->texture; + struct pipe_resource *tex = img->texture; return tex; } @@ -249,7 +249,7 @@ struct vg_image * image_create(VGImageFormat format, struct vg_context *ctx = vg_current_context(); struct vg_image *image = CALLOC_STRUCT(vg_image); enum pipe_format pformat = vg_format_to_pipe(format); - struct pipe_texture pt, *newtex; + struct pipe_resource pt, *newtex; struct pipe_screen *screen = ctx->pipe->screen; vg_init_object(&image->base, ctx, VG_OBJECT_IMAGE); @@ -277,7 +277,7 @@ struct vg_image * image_create(VGImageFormat format, pt.depth0 = 1; pt.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER; - newtex = screen->texture_create(screen, &pt); + newtex = screen->resource_create(screen, &pt); debug_assert(newtex); @@ -345,7 +345,7 @@ void image_destroy(struct vg_image *img) array_destroy(img->children_array); } - pipe_texture_reference(&img->texture, NULL); + pipe_resource_reference(&img->texture, NULL); free(img); } @@ -379,7 +379,7 @@ void image_sub_data(struct vg_image *image, VGint i; struct vg_context *ctx = vg_current_context(); struct pipe_context *pipe = ctx->pipe; - struct pipe_texture *texture = image_texture(image); + struct pipe_resource *texture = image_texture(image); VGint xoffset = 0, yoffset = 0; if (x < 0) { @@ -412,7 +412,7 @@ void image_sub_data(struct vg_image *image, } { /* upload color_data */ - struct pipe_transfer *transfer = pipe->get_tex_transfer( + struct pipe_transfer *transfer = pipe_get_transfer( pipe, texture, 0, 0, 0, PIPE_TRANSFER_WRITE, 0, 0, texture->width0, texture->height0); src += (dataStride * yoffset); @@ -422,7 +422,7 @@ void image_sub_data(struct vg_image *image, y += yStep; src += dataStride; } - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } } @@ -443,7 +443,7 @@ void image_get_sub_data(struct vg_image * image, { struct pipe_transfer *transfer = - pipe->get_tex_transfer(pipe, + pipe_get_transfer(pipe, image->texture, 0, 0, 0, PIPE_TRANSFER_READ, 0, 0, @@ -460,7 +460,7 @@ void image_get_sub_data(struct vg_image * image, dst += dataStride; } - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } } @@ -479,7 +479,7 @@ struct vg_image * image_child_image(struct vg_image *parent, image->height = height; image->parent = parent; image->texture = 0; - pipe_texture_reference(&image->texture, + pipe_resource_reference(&image->texture, parent->texture); image->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; @@ -624,7 +624,7 @@ VGboolean vg_image_overlaps(struct vg_image *dst, } VGint image_bind_samplers(struct vg_image *img, struct pipe_sampler_state **samplers, - struct pipe_texture **textures) + struct pipe_resource **textures) { img->sampler.min_img_filter = image_sampler_filter(img->base.ctx); img->sampler.mag_img_filter = image_sampler_filter(img->base.ctx); diff --git a/src/gallium/state_trackers/vega/image.h b/src/gallium/state_trackers/vega/image.h index 78e17cffa6..8dcaf131b6 100644 --- a/src/gallium/state_trackers/vega/image.h +++ b/src/gallium/state_trackers/vega/image.h @@ -30,7 +30,7 @@ #include "vg_context.h" #include "pipe/p_state.h" -struct pipe_texture; +struct pipe_resource; struct array; struct vg_context; struct pipe_surface; @@ -43,7 +43,7 @@ struct vg_image { struct vg_image *parent; - struct pipe_texture *texture; + struct pipe_resource *texture; struct pipe_sampler_state sampler; struct array *children_array; @@ -89,7 +89,7 @@ void image_get_pixels(struct vg_image *dst, VGint dx, VGint dy, VGint width, VGint height); VGint image_bind_samplers(struct vg_image *dst, struct pipe_sampler_state **samplers, - struct pipe_texture **textures); + struct pipe_resource **textures); VGboolean vg_image_overlaps(struct vg_image *dst, struct vg_image *src); diff --git a/src/gallium/state_trackers/vega/mask.c b/src/gallium/state_trackers/vega/mask.c index 839dc19a3b..379e46b275 100644 --- a/src/gallium/state_trackers/vega/mask.c +++ b/src/gallium/state_trackers/vega/mask.c @@ -45,7 +45,7 @@ struct vg_mask_layer { VGint width; VGint height; - struct pipe_texture *texture; + struct pipe_resource *texture; }; static INLINE struct pipe_surface * @@ -217,7 +217,7 @@ static void setup_mask_framebuffer(struct pipe_surface *surf, static void setup_mask_operation(VGMaskOperation operation) { struct vg_context *ctx = vg_current_context(); - struct pipe_buffer **cbuf = &ctx->mask.cbuf; + struct pipe_resource **cbuf = &ctx->mask.cbuf; const VGint param_bytes = 4 * sizeof(VGfloat); const VGfloat ones[4] = {1.f, 1.f, 1.f, 1.f}; void *shader = 0; @@ -225,7 +225,7 @@ static void setup_mask_operation(VGMaskOperation operation) /* We always need to get a new buffer, to keep the drivers simple and * avoid gratuitous rendering synchronization. */ - pipe_buffer_reference(cbuf, NULL); + pipe_resource_reference(cbuf, NULL); *cbuf = pipe_buffer_create(ctx->pipe->screen, 1, PIPE_BUFFER_USAGE_CONSTANT, @@ -284,13 +284,13 @@ static void setup_mask_operation(VGMaskOperation operation) cso_set_fragment_shader_handle(ctx->cso_context, shader); } -static void setup_mask_samplers(struct pipe_texture *umask) +static void setup_mask_samplers(struct pipe_resource *umask) { struct vg_context *ctx = vg_current_context(); struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; - struct pipe_texture *textures[PIPE_MAX_SAMPLERS]; + struct pipe_resource *textures[PIPE_MAX_SAMPLERS]; struct st_framebuffer *fb_buffers = ctx->draw_buffer; - struct pipe_texture *uprev = NULL; + struct pipe_resource *uprev = NULL; struct pipe_sampler_state sampler; uprev = fb_buffers->blend_texture; @@ -320,13 +320,13 @@ static void setup_mask_samplers(struct pipe_texture *umask) static void setup_mask_fill(const VGfloat color[4]) { struct vg_context *ctx = vg_current_context(); - struct pipe_buffer **cbuf = &ctx->mask.cbuf; + struct pipe_resource **cbuf = &ctx->mask.cbuf; const VGint param_bytes = 4 * sizeof(VGfloat); /* We always need to get a new buffer, to keep the drivers simple and * avoid gratuitous rendering synchronization. */ - pipe_buffer_reference(cbuf, NULL); + pipe_resource_reference(cbuf, NULL); *cbuf = pipe_buffer_create(ctx->pipe->screen, 1, PIPE_BUFFER_USAGE_CONSTANT, @@ -411,7 +411,7 @@ static void surface_fill(struct pipe_surface *surf, } -static void mask_using_texture(struct pipe_texture *texture, +static void mask_using_texture(struct pipe_resource *texture, VGMaskOperation operation, VGint x, VGint y, VGint width, VGint height) @@ -483,7 +483,7 @@ struct vg_mask_layer * mask_layer_create(VGint width, VGint height) mask->height = height; { - struct pipe_texture pt; + struct pipe_resource pt; struct pipe_screen *screen = ctx->pipe->screen; memset(&pt, 0, sizeof(pt)); @@ -496,7 +496,7 @@ struct vg_mask_layer * mask_layer_create(VGint width, VGint height) pt.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER; pt.compressed = 0; - mask->texture = screen->texture_create(screen, &pt); + mask->texture = screen->resource_create(screen, &pt); } vg_context_add_object(ctx, VG_OBJECT_MASK, mask); @@ -509,7 +509,7 @@ void mask_layer_destroy(struct vg_mask_layer *layer) struct vg_context *ctx = vg_current_context(); vg_context_remove_object(ctx, VG_OBJECT_MASK, layer); - pipe_texture_release(&layer->texture); + pipe_resource_release(&layer->texture); free(layer); } @@ -672,7 +672,7 @@ void mask_fill(VGint x, VGint y, VGint width, VGint height, } VGint mask_bind_samplers(struct pipe_sampler_state **samplers, - struct pipe_texture **textures) + struct pipe_resource **textures) { struct vg_context *ctx = vg_current_context(); diff --git a/src/gallium/state_trackers/vega/mask.h b/src/gallium/state_trackers/vega/mask.h index 5eaaede0e3..1489257193 100644 --- a/src/gallium/state_trackers/vega/mask.h +++ b/src/gallium/state_trackers/vega/mask.h @@ -31,7 +31,7 @@ struct path; struct vg_image; -struct pipe_texture; +struct pipe_resource; struct vg_mask_layer *mask_layer_create(VGint width, VGint height); void mask_layer_destroy(struct vg_mask_layer *layer); @@ -63,6 +63,6 @@ void mask_fill(VGint x, VGint y, VGfloat value); VGint mask_bind_samplers(struct pipe_sampler_state **samplers, - struct pipe_texture **textures); + struct pipe_resource **textures); #endif diff --git a/src/gallium/state_trackers/vega/paint.c b/src/gallium/state_trackers/vega/paint.c index dc56b8c5f3..5c1482cb07 100644 --- a/src/gallium/state_trackers/vega/paint.c +++ b/src/gallium/state_trackers/vega/paint.c @@ -61,7 +61,7 @@ struct vg_paint { VGfloat vals[5]; VGint valsi[5]; } radial; - struct pipe_texture *texture; + struct pipe_resource *texture; struct pipe_sampler_state sampler; VGfloat *ramp_stops; @@ -72,13 +72,13 @@ struct vg_paint { } gradient; struct { - struct pipe_texture *texture; + struct pipe_resource *texture; VGTilingMode tiling_mode; struct pipe_sampler_state sampler; } pattern; /* XXX next 3 all unneded? */ - struct pipe_buffer *cbuf; + struct pipe_resource *cbuf; struct pipe_shader_state fs_state; void *fs; }; @@ -142,12 +142,12 @@ static INLINE void create_gradient_data(const VGfloat *ramp_stops, data[size-1] = last_color; } -static INLINE struct pipe_texture *create_gradient_texture(struct vg_paint *p) +static INLINE struct pipe_resource *create_gradient_texture(struct vg_paint *p) { struct pipe_context *pipe = p->base.ctx->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_texture *tex = 0; - struct pipe_texture templ; + struct pipe_resource *tex = 0; + struct pipe_resource templ; memset(&templ, 0, sizeof(templ)); templ.target = PIPE_TEXTURE_1D; @@ -158,16 +158,16 @@ static INLINE struct pipe_texture *create_gradient_texture(struct vg_paint *p) templ.depth0 = 1; templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER; - tex = screen->texture_create(screen, &templ); + tex = screen->resource_create(screen, &templ); { /* upload color_data */ struct pipe_transfer *transfer = - st_no_flush_get_tex_transfer(p->base.ctx, tex, 0, 0, 0, + st_no_flush_get_transfer(p->base.ctx, tex, 0, 0, 0, PIPE_TRANSFER_WRITE, 0, 0, 1024, 1); void *map = pipe->transfer_map(pipe, transfer); memcpy(map, p->gradient.color_data, sizeof(VGint)*1024); pipe->transfer_unmap(pipe, transfer); - pipe->tex_transfer_destroy(pipe, transfer); + pipe->transfer_destroy(pipe, transfer); } return tex; @@ -208,7 +208,7 @@ void paint_destroy(struct vg_paint *paint) { struct vg_context *ctx = paint->base.ctx; if (paint->pattern.texture) - pipe_texture_reference(&paint->pattern.texture, NULL); + pipe_resource_reference(&paint->pattern.texture, NULL); if (ctx) vg_context_remove_object(ctx, VG_OBJECT_PAINT, paint); @@ -395,7 +395,7 @@ void paint_set_ramp_stops(struct vg_paint *paint, const VGfloat *stops, 1024); if (paint->gradient.texture) { - pipe_texture_reference(&paint->gradient.texture, NULL); + pipe_resource_reference(&paint->gradient.texture, NULL); paint->gradient.texture = 0; } @@ -460,10 +460,10 @@ void paint_set_pattern(struct vg_paint *paint, struct vg_image *img) { if (paint->pattern.texture) - pipe_texture_reference(&paint->pattern.texture, NULL); + pipe_resource_reference(&paint->pattern.texture, NULL); paint->pattern.texture = 0; - pipe_texture_reference(&paint->pattern.texture, + pipe_resource_reference(&paint->pattern.texture, img->texture); } @@ -611,7 +611,7 @@ VGTilingMode paint_pattern_tiling(struct vg_paint *paint) } VGint paint_bind_samplers(struct vg_paint *paint, struct pipe_sampler_state **samplers, - struct pipe_texture **textures) + struct pipe_resource **textures) { struct vg_context *ctx = vg_current_context(); diff --git a/src/gallium/state_trackers/vega/paint.h b/src/gallium/state_trackers/vega/paint.h index 999b5c167c..cf9a701c35 100644 --- a/src/gallium/state_trackers/vega/paint.h +++ b/src/gallium/state_trackers/vega/paint.h @@ -35,7 +35,7 @@ struct vg_paint; struct vg_image; struct pipe_sampler_state; -struct pipe_texture; +struct pipe_resource; struct vg_paint *paint_create(struct vg_context *ctx); void paint_destroy(struct vg_paint *paint); @@ -108,7 +108,7 @@ VGboolean paint_color_ramp_premultiplied(struct vg_paint *paint); VGint paint_bind_samplers(struct vg_paint *paint, struct pipe_sampler_state **samplers, - struct pipe_texture **textures); + struct pipe_resource **textures); VGint paint_constant_buffer_size(struct vg_paint *paint); void paint_fill_constant_buffer(struct vg_paint *paint, diff --git a/src/gallium/state_trackers/vega/polygon.c b/src/gallium/state_trackers/vega/polygon.c index eef2c1eb87..ecfe7aaf31 100644 --- a/src/gallium/state_trackers/vega/polygon.c +++ b/src/gallium/state_trackers/vega/polygon.c @@ -58,7 +58,7 @@ struct polygon VGint num_verts; VGboolean dirty; - struct pipe_buffer *vbuf; + struct pipe_resource *vbuf; struct pipe_screen *screen; }; @@ -110,7 +110,7 @@ struct polygon * polygon_create_from_data(float *data, int size) void polygon_destroy(struct polygon *poly) { if (poly->vbuf) - pipe_buffer_reference(&poly->vbuf, NULL); + pipe_resource_reference(&poly->vbuf, NULL); free(poly->data); free(poly); @@ -272,13 +272,14 @@ static void draw_polygon(struct vg_context *ctx, if (poly->vbuf == NULL || poly->dirty) { if (poly->vbuf) { - pipe_buffer_reference(&poly->vbuf, + pipe_resource_reference(&poly->vbuf, NULL); } poly->screen = pipe->screen; poly->vbuf= pipe_user_buffer_create(poly->screen, poly->data, - vert_size); + vert_size, + PIPE_BUFFER_USAGE_VERTEX); poly->dirty = VG_FALSE; } diff --git a/src/gallium/state_trackers/vega/renderer.c b/src/gallium/state_trackers/vega/renderer.c index 47e8b470a1..415dd5e1a8 100644 --- a/src/gallium/state_trackers/vega/renderer.c +++ b/src/gallium/state_trackers/vega/renderer.c @@ -60,7 +60,7 @@ static void setup_shaders(struct renderer *ctx) ctx->fs = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D); } -static struct pipe_buffer * +static struct pipe_resource * setup_vertex_data(struct renderer *ctx, float x0, float y0, float x1, float y1, float z) { @@ -90,10 +90,11 @@ setup_vertex_data(struct renderer *ctx, return pipe_user_buffer_create( ctx->pipe->screen, ctx->vertices, - sizeof(ctx->vertices) ); + sizeof(ctx->vertices), + PIPE_BUFFER_USAGE_VERTEX); } -static struct pipe_buffer * +static struct pipe_resource * setup_vertex_data_tex(struct renderer *ctx, float x0, float y0, float x1, float y1, float s0, float t0, float s1, float t1, @@ -125,11 +126,12 @@ setup_vertex_data_tex(struct renderer *ctx, return pipe_user_buffer_create( ctx->pipe->screen, ctx->vertices, - sizeof(ctx->vertices) ); + sizeof(ctx->vertices), + PIPE_BUFFER_USAGE_VERTEX); } -static struct pipe_buffer * +static struct pipe_resource * setup_vertex_data_qtex(struct renderer *ctx, float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, @@ -162,7 +164,8 @@ setup_vertex_data_qtex(struct renderer *ctx, return pipe_user_buffer_create( ctx->pipe->screen, ctx->vertices, - sizeof(ctx->vertices) ); + sizeof(ctx->vertices), + PIPE_BUFFER_USAGE_VERTEX); } struct renderer * renderer_create(struct vg_context *owner) @@ -205,7 +208,7 @@ void renderer_draw_quad(struct renderer *r, VGfloat x2, VGfloat y2, VGfloat depth) { - struct pipe_buffer *buf; + struct pipe_resource *buf; buf = setup_vertex_data(r, x1, y1, x2, y2, depth); @@ -216,20 +219,20 @@ void renderer_draw_quad(struct renderer *r, 4, /* verts */ 2); /* attribs/vert */ - pipe_buffer_reference( &buf, + pipe_resource_reference( &buf, NULL ); } } void renderer_draw_texture(struct renderer *r, - struct pipe_texture *tex, + struct pipe_resource *tex, VGfloat x1offset, VGfloat y1offset, VGfloat x2offset, VGfloat y2offset, VGfloat x1, VGfloat y1, VGfloat x2, VGfloat y2) { struct pipe_context *pipe = r->pipe; - struct pipe_buffer *buf; + struct pipe_resource *buf; VGfloat s0, t0, s1, t1; assert(tex->width0 != 0); @@ -255,7 +258,7 @@ void renderer_draw_texture(struct renderer *r, 4, /* verts */ 2); /* attribs/vert */ - pipe_buffer_reference( &buf, + pipe_resource_reference( &buf, NULL ); } @@ -263,16 +266,16 @@ void renderer_draw_texture(struct renderer *r, } void renderer_copy_texture(struct renderer *ctx, - struct pipe_texture *src, + struct pipe_resource *src, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, - struct pipe_texture *dst, + struct pipe_resource *dst, VGfloat dx1, VGfloat dy1, VGfloat dx2, VGfloat dy2) { struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_buffer *buf; + struct pipe_resource *buf; struct pipe_surface *dst_surf = screen->get_tex_surface( screen, dst, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); @@ -378,7 +381,7 @@ void renderer_copy_texture(struct renderer *ctx, 4, /* verts */ 2); /* attribs/vert */ - pipe_buffer_reference( &buf, + pipe_resource_reference( &buf, NULL ); } @@ -405,8 +408,8 @@ void renderer_copy_surface(struct renderer *ctx, { struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_buffer *buf; - struct pipe_texture texTemp, *tex; + struct pipe_resource *buf; + struct pipe_resource texTemp, *tex; struct pipe_surface *texSurf; struct pipe_framebuffer_state fb; struct st_framebuffer *stfb = ctx->owner->draw_buffer; @@ -453,7 +456,7 @@ void renderer_copy_surface(struct renderer *ctx, texTemp.height0 = srcH; texTemp.depth0 = 1; - tex = screen->texture_create(screen, &texTemp); + tex = screen->resource_create(screen, &texTemp); if (!tex) return; @@ -544,7 +547,7 @@ void renderer_copy_surface(struct renderer *ctx, 4, /* verts */ 2); /* attribs/vert */ - pipe_buffer_reference( &buf, + pipe_resource_reference( &buf, NULL ); } @@ -558,11 +561,11 @@ void renderer_copy_surface(struct renderer *ctx, cso_restore_vertex_shader(ctx->cso); cso_restore_viewport(ctx->cso); - pipe_texture_reference(&tex, NULL); + pipe_resource_reference(&tex, NULL); } void renderer_texture_quad(struct renderer *r, - struct pipe_texture *tex, + struct pipe_resource *tex, VGfloat x1offset, VGfloat y1offset, VGfloat x2offset, VGfloat y2offset, VGfloat x1, VGfloat y1, @@ -571,7 +574,7 @@ void renderer_texture_quad(struct renderer *r, VGfloat x4, VGfloat y4) { struct pipe_context *pipe = r->pipe; - struct pipe_buffer *buf; + struct pipe_resource *buf; VGfloat s0, t0, s1, t1; assert(tex->width0 != 0); @@ -597,7 +600,7 @@ void renderer_texture_quad(struct renderer *r, 4, /* verts */ 2); /* attribs/vert */ - pipe_buffer_reference(&buf, + pipe_resource_reference(&buf, NULL); } diff --git a/src/gallium/state_trackers/vega/renderer.h b/src/gallium/state_trackers/vega/renderer.h index 990cd32c31..6afb3097f3 100644 --- a/src/gallium/state_trackers/vega/renderer.h +++ b/src/gallium/state_trackers/vega/renderer.h @@ -32,7 +32,7 @@ struct renderer; struct vg_context; -struct pipe_texture; +struct pipe_resource; struct pipe_surface; struct renderer *renderer_create(struct vg_context *owner); @@ -43,13 +43,13 @@ void renderer_draw_quad(struct renderer *, VGfloat x2, VGfloat y2, VGfloat depth); void renderer_draw_texture(struct renderer *, - struct pipe_texture *texture, + struct pipe_resource *texture, VGfloat x1offset, VGfloat y1offset, VGfloat x2offset, VGfloat y2offset, VGfloat x1, VGfloat y1, VGfloat x2, VGfloat y2); void renderer_texture_quad(struct renderer *, - struct pipe_texture *texture, + struct pipe_resource *texture, VGfloat x1offset, VGfloat y1offset, VGfloat x2offset, VGfloat y2offset, VGfloat x1, VGfloat y1, @@ -57,10 +57,10 @@ void renderer_texture_quad(struct renderer *, VGfloat x3, VGfloat y3, VGfloat x4, VGfloat y4); void renderer_copy_texture(struct renderer *r, - struct pipe_texture *src, + struct pipe_resource *src, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, - struct pipe_texture *dst, + struct pipe_resource *dst, VGfloat dx1, VGfloat dy1, VGfloat dx2, VGfloat dy2); void renderer_copy_surface(struct renderer *r, diff --git a/src/gallium/state_trackers/vega/shader.c b/src/gallium/state_trackers/vega/shader.c index 0e71a507bf..e1a3676612 100644 --- a/src/gallium/state_trackers/vega/shader.c +++ b/src/gallium/state_trackers/vega/shader.c @@ -51,7 +51,7 @@ struct shader { VGImageMode image_mode; float constants[MAX_CONSTANTS]; - struct pipe_buffer *cbuf; + struct pipe_resource *cbuf; struct pipe_shader_state fs_state; void *fs; }; @@ -96,7 +96,7 @@ static void setup_constant_buffer(struct shader *shader) { struct vg_context *ctx = shader->context; struct pipe_context *pipe = shader->context->pipe; - struct pipe_buffer **cbuf = &shader->cbuf; + struct pipe_resource **cbuf = &shader->cbuf; VGint param_bytes = paint_constant_buffer_size(shader->paint); float temp_buf[MAX_CONSTANTS]; @@ -106,12 +106,13 @@ static void setup_constant_buffer(struct shader *shader) if (*cbuf == NULL || memcmp(temp_buf, shader->constants, param_bytes) != 0) { - pipe_buffer_reference(cbuf, NULL); + pipe_resource_reference(cbuf, NULL); memcpy(shader->constants, temp_buf, param_bytes); *cbuf = pipe_user_buffer_create(pipe->screen, &shader->constants, - sizeof(shader->constants)); + sizeof(shader->constants), + PIPE_BUFFER_USAGE_VERTEX); } ctx->pipe->set_constant_buffer(ctx->pipe, PIPE_SHADER_FRAGMENT, 0, *cbuf); @@ -119,7 +120,7 @@ static void setup_constant_buffer(struct shader *shader) static VGint blend_bind_samplers(struct vg_context *ctx, struct pipe_sampler_state **samplers, - struct pipe_texture **textures) + struct pipe_resource **textures) { VGBlendMode bmode = ctx->state.vg.blend_mode; @@ -151,7 +152,7 @@ static VGint blend_bind_samplers(struct vg_context *ctx, static void setup_samplers(struct shader *shader) { struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; - struct pipe_texture *textures[PIPE_MAX_SAMPLERS]; + struct pipe_resource *textures[PIPE_MAX_SAMPLERS]; struct vg_context *ctx = shader->context; /* a little wonky: we use the num as a boolean that just says * whether any sampler/textures have been set. the actual numbering diff --git a/src/gallium/state_trackers/vega/st_inlines.h b/src/gallium/state_trackers/vega/st_inlines.h index 4d12a4efdd..7eaa67c76a 100644 --- a/src/gallium/state_trackers/vega/st_inlines.h +++ b/src/gallium/state_trackers/vega/st_inlines.h @@ -42,8 +42,8 @@ #include "pipe/p_state.h" static INLINE struct pipe_transfer * -st_cond_flush_get_tex_transfer(struct vg_context *st, - struct pipe_texture *pt, +st_cond_flush_get_transfer(struct vg_context *st, + struct pipe_resource *pt, unsigned int face, unsigned int level, unsigned int zslice, @@ -52,20 +52,14 @@ st_cond_flush_get_tex_transfer(struct vg_context *st, unsigned int w, unsigned int h) { struct pipe_context *pipe = st->pipe; - unsigned referenced = - pipe->is_texture_referenced(pipe, pt, face, level); - if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) || - (usage & PIPE_TRANSFER_WRITE))) - vgFlush(); - - return pipe->get_tex_transfer(pipe, pt, face, level, zslice, usage, - x, y, w, h); + return pipe_get_transfer(pipe, pt, face, level, zslice, usage, + x, y, w, h); } static INLINE struct pipe_transfer * -st_no_flush_get_tex_transfer(struct vg_context *st, - struct pipe_texture *pt, +st_no_flush_get_transfer(struct vg_context *st, + struct pipe_resource *pt, unsigned int face, unsigned int level, unsigned int zslice, @@ -75,82 +69,53 @@ st_no_flush_get_tex_transfer(struct vg_context *st, { struct pipe_context *pipe = st->pipe; - return pipe->get_tex_transfer(pipe, pt, face, level, - zslice, usage, x, y, w, h); -} - -static INLINE void * -st_cond_flush_pipe_buffer_map(struct vg_context *st, - struct pipe_buffer *buf, - unsigned int map_flags) -{ - struct pipe_context *pipe = st->pipe; - unsigned int referenced = pipe->is_buffer_referenced(pipe, buf); - - if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) || - (map_flags & PIPE_BUFFER_USAGE_CPU_WRITE))) - vgFlush(); - - return pipe_buffer_map(pipe->screen, buf, map_flags); -} - -static INLINE void * -st_no_flush_pipe_buffer_map(struct vg_context *st, - struct pipe_buffer *buf, - unsigned int map_flags) -{ - return pipe_buffer_map(st->pipe->screen, buf, map_flags); + return pipe_get_transfer(pipe, pt, face, level, + zslice, usage, x, y, w, h); } static INLINE void st_cond_flush_pipe_buffer_write(struct vg_context *st, - struct pipe_buffer *buf, + struct pipe_resource *buf, unsigned int offset, unsigned int size, const void * data) { struct pipe_context *pipe = st->pipe; - if (pipe->is_buffer_referenced(pipe, buf)) - vgFlush(); - - pipe_buffer_write(pipe->screen, buf, offset, size, data); + pipe_buffer_write(pipe, buf, offset, size, data); } static INLINE void st_no_flush_pipe_buffer_write(struct vg_context *st, - struct pipe_buffer *buf, + struct pipe_resource *buf, unsigned int offset, unsigned int size, const void * data) { - pipe_buffer_write(st->pipe->screen, buf, offset, size, data); + pipe_buffer_write(st->pipe, buf, offset, size, data); } static INLINE void st_cond_flush_pipe_buffer_read(struct vg_context *st, - struct pipe_buffer *buf, + struct pipe_resource *buf, unsigned int offset, unsigned int size, void * data) { struct pipe_context *pipe = st->pipe; - if (pipe->is_buffer_referenced(pipe, buf) & PIPE_REFERENCED_FOR_WRITE) - vgFlush(); - - pipe_buffer_read(pipe->screen, buf, offset, size, data); + pipe_buffer_read(pipe, buf, offset, size, data); } static INLINE void st_no_flush_pipe_buffer_read(struct vg_context *st, - struct pipe_buffer *buf, + struct pipe_resource *buf, unsigned int offset, unsigned int size, void * data) { - pipe_buffer_read(st->pipe->screen, buf, offset, size, data); + pipe_buffer_read(st->pipe, buf, offset, size, data); } #endif diff --git a/src/gallium/state_trackers/vega/vg_context.c b/src/gallium/state_trackers/vega/vg_context.c index 7769112a31..94e9ae5dad 100644 --- a/src/gallium/state_trackers/vega/vg_context.c +++ b/src/gallium/state_trackers/vega/vg_context.c @@ -131,8 +131,8 @@ struct vg_context * vg_create_context(struct pipe_context *pipe, void vg_destroy_context(struct vg_context *ctx) { - struct pipe_buffer **cbuf = &ctx->mask.cbuf; - struct pipe_buffer **vsbuf = &ctx->vs_const_buffer; + struct pipe_resource **cbuf = &ctx->mask.cbuf; + struct pipe_resource **vsbuf = &ctx->vs_const_buffer; util_destroy_blit(ctx->blit); renderer_destroy(ctx->renderer); @@ -141,10 +141,10 @@ void vg_destroy_context(struct vg_context *ctx) paint_destroy(ctx->default_paint); if (*cbuf) - pipe_buffer_reference(cbuf, NULL); + pipe_resource_reference(cbuf, NULL); if (*vsbuf) - pipe_buffer_reference(vsbuf, NULL); + pipe_resource_reference(vsbuf, NULL); if (ctx->clear.fs) { cso_delete_fragment_shader(ctx->cso_context, ctx->clear.fs); @@ -380,11 +380,11 @@ void vg_validate_state(struct vg_context *ctx) 2.f/fb->width, 2.f/fb->height, 1, 1, -1, -1, 0, 0 }; - struct pipe_buffer **cbuf = &ctx->vs_const_buffer; + struct pipe_resource **cbuf = &ctx->vs_const_buffer; vg_set_viewport(ctx, VEGA_Y0_BOTTOM); - pipe_buffer_reference(cbuf, NULL); + pipe_resource_reference(cbuf, NULL); *cbuf = pipe_buffer_create(ctx->pipe->screen, 16, PIPE_BUFFER_USAGE_CONSTANT, param_bytes); diff --git a/src/gallium/state_trackers/vega/vg_context.h b/src/gallium/state_trackers/vega/vg_context.h index 17c7d2ad1c..52c291fbce 100644 --- a/src/gallium/state_trackers/vega/vg_context.h +++ b/src/gallium/state_trackers/vega/vg_context.h @@ -46,7 +46,7 @@ struct vg_shader; struct st_renderbuffer { enum pipe_format format; struct pipe_surface *surface; - struct pipe_texture *texture; + struct pipe_resource *texture; VGint width, height; }; @@ -55,9 +55,9 @@ struct st_framebuffer { struct st_renderbuffer *strb; struct st_renderbuffer *dsrb; - struct pipe_texture *alpha_mask; + struct pipe_resource *alpha_mask; - struct pipe_texture *blend_texture; + struct pipe_resource *blend_texture; struct st_framebuffer_iface *iface; enum st_attachment_type strb_att; @@ -120,7 +120,7 @@ struct vg_context } clear; struct { - struct pipe_buffer *cbuf; + struct pipe_resource *cbuf; struct pipe_sampler_state sampler; struct vg_shader *union_fs; @@ -133,7 +133,7 @@ struct vg_context struct cso_context *cso_context; - struct pipe_buffer *stencil_quad; + struct pipe_resource *stencil_quad; VGfloat stencil_vertices[4][2][4]; struct renderer *renderer; @@ -142,7 +142,7 @@ struct vg_context struct pipe_sampler_state blend_sampler; struct { - struct pipe_buffer *buffer; + struct pipe_resource *buffer; void *color_matrix_fs; } filter; struct vg_paint *default_paint; @@ -152,7 +152,7 @@ struct vg_context struct vg_shader *plain_vs; struct vg_shader *clear_vs; struct vg_shader *texture_vs; - struct pipe_buffer *vs_const_buffer; + struct pipe_resource *vs_const_buffer; struct pipe_vertex_element velems[2]; }; diff --git a/src/gallium/state_trackers/vega/vg_tracker.c b/src/gallium/state_trackers/vega/vg_tracker.c index ea5c2ce41f..4e5921632e 100644 --- a/src/gallium/state_trackers/vega/vg_tracker.c +++ b/src/gallium/state_trackers/vega/vg_tracker.c @@ -39,11 +39,11 @@ /* advertise OpenVG support */ PUBLIC const int st_api_OpenVG = 1; -static struct pipe_texture * +static struct pipe_resource * create_texture(struct pipe_context *pipe, enum pipe_format format, VGint width, VGint height) { - struct pipe_texture templ; + struct pipe_resource templ; memset(&templ, 0, sizeof(templ)); @@ -68,7 +68,7 @@ create_texture(struct pipe_context *pipe, enum pipe_format format, PIPE_TEXTURE_USAGE_SAMPLER); } - return pipe->screen->texture_create(pipe->screen, &templ); + return pipe->screen->resource_create(pipe->screen, &templ); } /** @@ -107,7 +107,7 @@ st_renderbuffer_alloc_storage(struct vg_context * ctx, /* Free the old surface and texture */ pipe_surface_reference(&strb->surface, NULL); - pipe_texture_reference(&strb->texture, NULL); + pipe_resource_reference(&strb->texture, NULL); /* Probably need dedicated flags for surface usage too: @@ -206,7 +206,7 @@ static void setup_new_alpha_mask(struct vg_context *ctx, uint width, uint height) { struct pipe_context *pipe = ctx->pipe; - struct pipe_texture *old_texture = stfb->alpha_mask; + struct pipe_resource *old_texture = stfb->alpha_mask; /* we use PIPE_FORMAT_B8G8R8A8_UNORM because we want to render to @@ -218,7 +218,7 @@ static void setup_new_alpha_mask(struct vg_context *ctx, if (!stfb->alpha_mask) { if (old_texture) - pipe_texture_reference(&old_texture, NULL); + pipe_resource_reference(&old_texture, NULL); return; } @@ -265,7 +265,7 @@ static void setup_new_alpha_mask(struct vg_context *ctx, /* Free the old texture */ if (old_texture) - pipe_texture_reference(&old_texture, NULL); + pipe_resource_reference(&old_texture, NULL); } void st_resize_framebuffer(struct st_framebuffer *stfb, @@ -326,7 +326,7 @@ void st_resize_framebuffer(struct st_framebuffer *stfb, setup_new_alpha_mask(ctx, stfb, width, height); - pipe_texture_reference( &stfb->blend_texture, NULL ); + pipe_resource_reference( &stfb->blend_texture, NULL ); stfb->blend_texture = create_texture(ctx->pipe, PIPE_FORMAT_B8G8R8A8_UNORM, width, height); } @@ -338,11 +338,11 @@ void st_set_framebuffer_surface(struct st_framebuffer *stfb, /* unreference existing surfaces */ pipe_surface_reference( &rb->surface, NULL ); - pipe_texture_reference( &rb->texture, NULL ); + pipe_resource_reference( &rb->texture, NULL ); /* reference new ones */ pipe_surface_reference( &rb->surface, surf ); - pipe_texture_reference( &rb->texture, surf->texture ); + pipe_resource_reference( &rb->texture, surf->texture ); rb->width = surf->width; rb->height = surf->height; @@ -357,7 +357,7 @@ int st_get_framebuffer_surface(struct st_framebuffer *stfb, } int st_get_framebuffer_texture(struct st_framebuffer *stfb, - uint surfIndex, struct pipe_texture **tex) + uint surfIndex, struct pipe_resource **tex) { struct st_renderbuffer *rb = stfb->strb; *tex = rb->texture; diff --git a/src/gallium/state_trackers/vega/vg_tracker.h b/src/gallium/state_trackers/vega/vg_tracker.h index 165a6b7a33..c16d55fc34 100644 --- a/src/gallium/state_trackers/vega/vg_tracker.h +++ b/src/gallium/state_trackers/vega/vg_tracker.h @@ -90,7 +90,7 @@ int st_get_framebuffer_surface(struct st_framebuffer *stfb, PUBLIC int st_get_framebuffer_texture(struct st_framebuffer *stfb, - uint surfIndex, struct pipe_texture **tex); + uint surfIndex, struct pipe_resource **tex); PUBLIC void *st_framebuffer_private(struct st_framebuffer *stfb); diff --git a/src/gallium/state_trackers/xorg/xorg_crtc.c b/src/gallium/state_trackers/xorg/xorg_crtc.c index eef428232b..a811c829fc 100644 --- a/src/gallium/state_trackers/xorg/xorg_crtc.c +++ b/src/gallium/state_trackers/xorg/xorg_crtc.c @@ -220,7 +220,7 @@ crtc_load_cursor_argb_ga3d(xf86CrtcPtr crtc, CARD32 * image) crtcp->cursor_handle = whandle.handle; } - transfer = ms->ctx->get_tex_transfer(ms->ctx, crtcp->cursor_tex, + transfer = ms->ctx->get_transfer(ms->ctx, crtcp->cursor_tex, 0, 0, 0, PIPE_TRANSFER_WRITE, 0, 0, 64, 64); diff --git a/src/gallium/state_trackers/xorg/xorg_exa.c b/src/gallium/state_trackers/xorg/xorg_exa.c index 76e6411bb8..474f806324 100644 --- a/src/gallium/state_trackers/xorg/xorg_exa.c +++ b/src/gallium/state_trackers/xorg/xorg_exa.c @@ -188,7 +188,7 @@ ExaDownloadFromScreen(PixmapPtr pPix, int x, int y, int w, int h, char *dst, if (!priv || !priv->tex) return FALSE; - transfer = exa->pipe->get_tex_transfer(exa->pipe, priv->tex, 0, 0, 0, + transfer = exa->pipe->get_transfer(exa->pipe, priv->tex, 0, 0, 0, PIPE_TRANSFER_READ, x, y, w, h); if (!transfer) return FALSE; @@ -222,7 +222,7 @@ ExaUploadToScreen(PixmapPtr pPix, int x, int y, int w, int h, char *src, if (!priv || !priv->tex) return FALSE; - transfer = exa->pipe->get_tex_transfer(exa->pipe, priv->tex, 0, 0, 0, + transfer = exa->pipe->get_transfer(exa->pipe, priv->tex, 0, 0, 0, PIPE_TRANSFER_WRITE, x, y, w, h); if (!transfer) return FALSE; @@ -264,15 +264,20 @@ ExaPrepareAccess(PixmapPtr pPix, int index) assert(pPix->drawable.width <= priv->tex->width0); assert(pPix->drawable.height <= priv->tex->height0); + u_box_wh(&box, + pPix->drawable.width, + pPix->drawable.height); + priv->map_transfer = - exa->pipe->get_tex_transfer(exa->pipe, priv->tex, 0, 0, 0, + exa->pipe->get_transfer(exa->pipe, + priv->tex, + u_subresource(0, 0), #ifdef EXA_MIXED_PIXMAPS - PIPE_TRANSFER_MAP_DIRECTLY | + PIPE_TRANSFER_MAP_DIRECTLY | #endif - PIPE_TRANSFER_READ_WRITE, - 0, 0, - pPix->drawable.width, - pPix->drawable.height ); + PIPE_TRANSFER_READ_WRITE, + + &box ); if (!priv->map_transfer) #ifdef EXA_MIXED_PIXMAPS return FALSE; diff --git a/src/gallium/state_trackers/xorg/xorg_xv.c b/src/gallium/state_trackers/xorg/xorg_xv.c index 5efda6837d..936d58357b 100644 --- a/src/gallium/state_trackers/xorg/xorg_xv.c +++ b/src/gallium/state_trackers/xorg/xorg_xv.c @@ -311,15 +311,15 @@ copy_packed_data(ScrnInfoPtr pScrn, int yidx, uidx, vidx; int y_array_size = w * h; - ytrans = pipe->get_tex_transfer(pipe, dst[0], + ytrans = pipe->get_transfer(pipe, dst[0], 0, 0, 0, PIPE_TRANSFER_WRITE, left, top, w, h); - utrans = pipe->get_tex_transfer(pipe, dst[1], + utrans = pipe->get_transfer(pipe, dst[1], 0, 0, 0, PIPE_TRANSFER_WRITE, left, top, w, h); - vtrans = pipe->get_tex_transfer(pipe, dst[2], + vtrans = pipe->get_transfer(pipe, dst[2], 0, 0, 0, PIPE_TRANSFER_WRITE, left, top, w, h); diff --git a/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c b/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c index 716d4bacd3..33059c8b75 100644 --- a/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c +++ b/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c @@ -19,8 +19,8 @@ dri_surface_from_handle(struct drm_api *api, struct pipe_screen *pscreen, unsigned width, unsigned height, unsigned pitch) { struct pipe_surface *ps = NULL; - struct pipe_texture *pt = NULL; - struct pipe_texture tmpl; + struct pipe_resource *pt = NULL; + struct pipe_resource tmpl; struct winsys_handle whandle; memset(&tmpl, 0, sizeof(tmpl)); |