From 7c1fcc41be15b6d648f84c8c1870a3a00575a48f Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 17 Sep 2010 12:47:49 +1000 Subject: [PATCH] r600g: move constant buffer creation behind winsys abstraction. this paves the way for moving to pb bufmgrs now. --- src/gallium/drivers/r600/r600_blit.c | 12 +++--- src/gallium/drivers/r600/r600_buffer.c | 33 ++--------------- src/gallium/drivers/r600/r600_query.c | 4 +- src/gallium/drivers/r600/r600_resource.h | 1 - src/gallium/drivers/r600/r600_screen.c | 1 + src/gallium/drivers/r600/r600_shader.c | 4 +- src/gallium/drivers/r600/r600_texture.c | 6 +-- src/gallium/drivers/r600/radeon.h | 7 +++- src/gallium/winsys/r600/drm/radeon.c | 5 +++ src/gallium/winsys/r600/drm/radeon_ctx.c | 2 +- src/gallium/winsys/r600/drm/radeon_priv.h | 2 + src/gallium/winsys/r600/drm/radeon_ws_bo.c | 43 +++++++++++++++++----- 12 files changed, 65 insertions(+), 55 deletions(-) diff --git a/src/gallium/drivers/r600/r600_blit.c b/src/gallium/drivers/r600/r600_blit.c index 0e061c25f77..54fbc50bbc4 100644 --- a/src/gallium/drivers/r600/r600_blit.c +++ b/src/gallium/drivers/r600/r600_blit.c @@ -179,11 +179,11 @@ static int r600_blit_state_vs_resources(struct r600_screen *rscreen, struct r600 }; /* simple shader */ - bo = radeon_ws_bo(rscreen->rw, 128, 4096); + bo = radeon_ws_bo(rscreen->rw, 128, 4096, 0); if (bo == NULL) { return -ENOMEM; } - data = radeon_ws_bo_map(rscreen->rw, bo); + data = radeon_ws_bo_map(rscreen->rw, bo, 0, NULL); if (!data) { radeon_ws_bo_reference(rscreen->rw, &bo, NULL); return -ENOMEM; @@ -274,11 +274,11 @@ static void r600_blit_state_vs_shader(struct r600_screen *rscreen, struct radeon }; /* simple shader */ - bo = radeon_ws_bo(rscreen->rw, 128, 4096); + bo = radeon_ws_bo(rscreen->rw, 128, 4096, 0); if (bo == NULL) { return; } - data = radeon_ws_bo_map(rscreen->rw, bo); + data = radeon_ws_bo_map(rscreen->rw, bo, 0, NULL); if (!data) { radeon_ws_bo_reference(rscreen->rw, &bo, NULL); return; @@ -338,11 +338,11 @@ static void r600_blit_state_ps_shader(struct r600_screen *rscreen, struct radeon }; /* simple shader */ - bo = radeon_ws_bo(rscreen->rw, 128, 4096); + bo = radeon_ws_bo(rscreen->rw, 128, 4096, 0); if (bo == NULL) { return; } - data = radeon_ws_bo_map(rscreen->rw, bo); + data = radeon_ws_bo_map(rscreen->rw, bo, 0, NULL); if (!data) { radeon_ws_bo_reference(rscreen->rw, &bo, NULL); return; diff --git a/src/gallium/drivers/r600/r600_buffer.c b/src/gallium/drivers/r600/r600_buffer.c index 37abf42d34f..a38c013e167 100644 --- a/src/gallium/drivers/r600/r600_buffer.c +++ b/src/gallium/drivers/r600/r600_buffer.c @@ -69,7 +69,6 @@ struct pipe_resource *r600_buffer_create(struct pipe_screen *screen, struct r600_screen *rscreen = r600_screen(screen); struct r600_resource *rbuffer; struct radeon_ws_bo *bo; - struct pb_desc desc; /* XXX We probably want a different alignment for buffers and textures. */ unsigned alignment = 4096; @@ -82,19 +81,8 @@ struct pipe_resource *r600_buffer_create(struct pipe_screen *screen, rbuffer->base.b.screen = screen; rbuffer->base.vtbl = &r600_buffer_vtbl; rbuffer->size = rbuffer->base.b.width0; - if ((rscreen->use_mem_constant == FALSE) && (rbuffer->base.b.bind & PIPE_BIND_CONSTANT_BUFFER)) { - desc.alignment = alignment; - desc.usage = rbuffer->base.b.bind; - rbuffer->pb = pb_malloc_buffer_create(rbuffer->base.b.width0, - &desc); - if (rbuffer->pb == NULL) { - free(rbuffer); - return NULL; - } - return &rbuffer->base.b; - } rbuffer->domain = r600_domain_from_usage(rbuffer->base.b.bind); - bo = radeon_ws_bo(rscreen->rw, rbuffer->base.b.width0, alignment); + bo = radeon_ws_bo(rscreen->rw, rbuffer->base.b.width0, alignment, rbuffer->base.b.bind); if (bo == NULL) { FREE(rbuffer); return NULL; @@ -125,7 +113,7 @@ struct pipe_resource *r600_user_buffer_create(struct pipe_screen *screen, if (rbuffer == NULL) { return NULL; } - data = radeon_ws_bo_map(rscreen->rw, rbuffer->bo); + data = radeon_ws_bo_map(rscreen->rw, rbuffer->bo, 0, NULL); memcpy(data, ptr, bytes); radeon_ws_bo_unmap(rscreen->rw, rbuffer->bo); return &rbuffer->base.b; @@ -137,15 +125,9 @@ static void r600_buffer_destroy(struct pipe_screen *screen, struct r600_resource *rbuffer = (struct r600_resource*)buf; struct r600_screen *rscreen = r600_screen(screen); - if (rbuffer->pb) { - pipe_reference_init(&rbuffer->pb->base.reference, 0); - pb_destroy(rbuffer->pb); - rbuffer->pb = NULL; - } if (rbuffer->bo) { radeon_ws_bo_reference(rscreen->rw, &rbuffer->bo, NULL); } - memset(rbuffer, 0, sizeof(struct r600_resource)); FREE(rbuffer); } @@ -157,16 +139,13 @@ static void *r600_buffer_transfer_map(struct pipe_context *pipe, int write = 0; uint8_t *data; - if (rbuffer->pb) { - return (uint8_t*)pb_map(rbuffer->pb, transfer->usage, NULL) + transfer->box.x; - } if (transfer->usage & PIPE_TRANSFER_DONTBLOCK) { /* FIXME */ } if (transfer->usage & PIPE_TRANSFER_WRITE) { write = 1; } - data = radeon_ws_bo_map(rscreen->rw, rbuffer->bo); + data = radeon_ws_bo_map(rscreen->rw, rbuffer->bo, transfer->usage, r600_context(pipe)); if (!data) return NULL; @@ -179,11 +158,7 @@ static void r600_buffer_transfer_unmap(struct pipe_context *pipe, struct r600_resource *rbuffer = (struct r600_resource*)transfer->resource; struct r600_screen *rscreen = r600_screen(pipe->screen); - if (rbuffer->pb) { - pb_unmap(rbuffer->pb); - } else { - radeon_ws_bo_unmap(rscreen->rw, rbuffer->bo); - } + radeon_ws_bo_unmap(rscreen->rw, rbuffer->bo); } static void r600_buffer_transfer_flush_region(struct pipe_context *pipe, diff --git a/src/gallium/drivers/r600/r600_query.c b/src/gallium/drivers/r600/r600_query.c index 922d7ace130..12900cce114 100644 --- a/src/gallium/drivers/r600/r600_query.c +++ b/src/gallium/drivers/r600/r600_query.c @@ -79,7 +79,7 @@ static struct pipe_query *r600_create_query(struct pipe_context *ctx, unsigned q q->type = query_type; q->buffer_size = 4096; - q->buffer = radeon_ws_bo(rscreen->rw, q->buffer_size, 1); + q->buffer = radeon_ws_bo(rscreen->rw, q->buffer_size, 1, 0); if (!q->buffer) { FREE(q); return NULL; @@ -109,7 +109,7 @@ static void r600_query_result(struct pipe_context *ctx, struct r600_query *rquer int i; radeon_ws_bo_wait(rscreen->rw, rquery->buffer); - results = radeon_ws_bo_map(rscreen->rw, rquery->buffer); + results = radeon_ws_bo_map(rscreen->rw, rquery->buffer, 0, r600_context(ctx)); for (i = 0; i < rquery->num_results; i += 4) { start = (u64)results[i] | (u64)results[i + 1] << 32; end = (u64)results[i + 2] | (u64)results[i + 3] << 32; diff --git a/src/gallium/drivers/r600/r600_resource.h b/src/gallium/drivers/r600/r600_resource.h index 8a110b1b72a..ff05afbc302 100644 --- a/src/gallium/drivers/r600/r600_resource.h +++ b/src/gallium/drivers/r600/r600_resource.h @@ -37,7 +37,6 @@ struct r600_resource { struct radeon_ws_bo *bo; u32 domain; u32 flink; - struct pb_buffer *pb; u32 size; }; diff --git a/src/gallium/drivers/r600/r600_screen.c b/src/gallium/drivers/r600/r600_screen.c index 19d1005e771..1d8612c21d4 100644 --- a/src/gallium/drivers/r600/r600_screen.c +++ b/src/gallium/drivers/r600/r600_screen.c @@ -277,6 +277,7 @@ struct pipe_screen *r600_screen_create(struct radeon *rw) FREE(rscreen); return NULL; } + radeon_set_mem_constant(rw, rscreen->use_mem_constant); rscreen->rw = rw; rscreen->screen.winsys = (struct pipe_winsys*)rw; rscreen->screen.destroy = r600_destroy_screen; diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c index 10f6d016a38..4da6850b0a9 100644 --- a/src/gallium/drivers/r600/r600_shader.c +++ b/src/gallium/drivers/r600/r600_shader.c @@ -163,11 +163,11 @@ static int r600_pipe_shader(struct pipe_context *ctx, struct r600_context_state radeon_ws_bo_reference(rscreen->rw, &rpshader->bo, NULL); rpshader->bo = NULL; rpshader->bo = radeon_ws_bo(rscreen->rw, rshader->bc.ndw * 4, - 4096); + 4096, 0); if (rpshader->bo == NULL) { return -ENOMEM; } - data = radeon_ws_bo_map(rscreen->rw, rpshader->bo); + data = radeon_ws_bo_map(rscreen->rw, rpshader->bo, 0, rctx); memcpy(data, rshader->bc.bytecode, rshader->bc.ndw * 4); radeon_ws_bo_unmap(rscreen->rw, rpshader->bo); /* build state */ diff --git a/src/gallium/drivers/r600/r600_texture.c b/src/gallium/drivers/r600/r600_texture.c index 4fa8cf47099..efc5f820659 100644 --- a/src/gallium/drivers/r600/r600_texture.c +++ b/src/gallium/drivers/r600/r600_texture.c @@ -121,7 +121,7 @@ struct pipe_resource *r600_texture_create(struct pipe_screen *screen, /* FIXME alignment 4096 enought ? too much ? */ resource->domain = r600_domain_from_usage(resource->base.b.bind); resource->size = rtex->size; - resource->bo = radeon_ws_bo(radeon, rtex->size, 4096); + resource->bo = radeon_ws_bo(radeon, rtex->size, 4096, 0); if (resource->bo == NULL) { FREE(rtex); return NULL; @@ -344,7 +344,7 @@ void* r600_texture_transfer_map(struct pipe_context *ctx, transfer->box.y / util_format_get_blockheight(format) * transfer->stride + transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); } - map = radeon_ws_bo_map(radeon, bo); + map = radeon_ws_bo_map(radeon, bo, 0, r600_context(ctx)); if (!map) { return NULL; } @@ -655,7 +655,7 @@ int r600_texture_from_depth(struct pipe_context *ctx, struct r600_resource_textu /* allocate uncompressed texture */ if (rtexture->uncompressed == NULL) { - rtexture->uncompressed = radeon_ws_bo(rscreen->rw, rtexture->size, 4096); + rtexture->uncompressed = radeon_ws_bo(rscreen->rw, rtexture->size, 4096, 0); if (rtexture->uncompressed == NULL) { return -ENOMEM; } diff --git a/src/gallium/drivers/r600/radeon.h b/src/gallium/drivers/r600/radeon.h index be28ad19ff6..36bfb747b51 100644 --- a/src/gallium/drivers/r600/radeon.h +++ b/src/gallium/drivers/r600/radeon.h @@ -21,6 +21,8 @@ #include +#include + typedef uint64_t u64; typedef uint32_t u32; typedef uint16_t u16; @@ -86,14 +88,15 @@ enum { }; enum radeon_family radeon_get_family(struct radeon *rw); +void radeon_set_mem_constant(struct radeon *radeon, boolean state); /* lowlevel WS bo */ struct radeon_ws_bo; struct radeon_ws_bo *radeon_ws_bo(struct radeon *radeon, - unsigned size, unsigned alignment); + unsigned size, unsigned alignment, unsigned usage); struct radeon_ws_bo *radeon_ws_bo_handle(struct radeon *radeon, unsigned handle); -void *radeon_ws_bo_map(struct radeon *radeon, struct radeon_ws_bo *bo); +void *radeon_ws_bo_map(struct radeon *radeon, struct radeon_ws_bo *bo, unsigned usage, void *ctx); void radeon_ws_bo_unmap(struct radeon *radeon, struct radeon_ws_bo *bo); void radeon_ws_bo_reference(struct radeon *radeon, struct radeon_ws_bo **dst, struct radeon_ws_bo *src); diff --git a/src/gallium/winsys/r600/drm/radeon.c b/src/gallium/winsys/r600/drm/radeon.c index ccf60605ed8..2135b07ab63 100644 --- a/src/gallium/winsys/r600/drm/radeon.c +++ b/src/gallium/winsys/r600/drm/radeon.c @@ -29,6 +29,11 @@ enum radeon_family radeon_get_family(struct radeon *radeon) return radeon->family; } +void radeon_set_mem_constant(struct radeon *radeon, boolean state) +{ + radeon->use_mem_constant = state; +} + static int radeon_get_device(struct radeon *radeon) { struct drm_radeon_info info; diff --git a/src/gallium/winsys/r600/drm/radeon_ctx.c b/src/gallium/winsys/r600/drm/radeon_ctx.c index d6e58451b85..a57163be03e 100644 --- a/src/gallium/winsys/r600/drm/radeon_ctx.c +++ b/src/gallium/winsys/r600/drm/radeon_ctx.c @@ -360,7 +360,7 @@ void radeon_ctx_dump_bof(struct radeon_ctx *ctx, const char *file) goto out_err; bof_decref(handle); handle = NULL; - data = radeon_ws_bo_map(ctx->radeon, ctx->bo[i]); + data = radeon_ws_bo_map(ctx->radeon, ctx->bo[i], 0, NULL); blob = bof_blob(ctx->bo[i]->bo->size, data); radeon_ws_bo_unmap(ctx->radeon, ctx->bo[i]); if (blob == NULL) diff --git a/src/gallium/winsys/r600/drm/radeon_priv.h b/src/gallium/winsys/r600/drm/radeon_priv.h index 6bd8d9850f5..49fe1a6ead1 100644 --- a/src/gallium/winsys/r600/drm/radeon_priv.h +++ b/src/gallium/winsys/r600/drm/radeon_priv.h @@ -86,11 +86,13 @@ struct radeon { unsigned nstype; struct radeon_stype_info *stype; unsigned max_states; + boolean use_mem_constant; /* true for evergreen */ }; struct radeon_ws_bo { struct pipe_reference reference; struct radeon_bo *bo; + struct pb_buffer *pb; }; extern struct radeon *radeon_new(int fd, unsigned device); diff --git a/src/gallium/winsys/r600/drm/radeon_ws_bo.c b/src/gallium/winsys/r600/drm/radeon_ws_bo.c index c789f8780f9..422e298a8db 100644 --- a/src/gallium/winsys/r600/drm/radeon_ws_bo.c +++ b/src/gallium/winsys/r600/drm/radeon_ws_bo.c @@ -1,15 +1,28 @@ #include +#include +#include #include "radeon_priv.h" struct radeon_ws_bo *radeon_ws_bo(struct radeon *radeon, - unsigned size, unsigned alignment) + unsigned size, unsigned alignment, unsigned usage) { struct radeon_ws_bo *ws_bo = calloc(1, sizeof(struct radeon_ws_bo)); + struct pb_desc desc; - ws_bo->bo = radeon_bo(radeon, 0, size, alignment, NULL); - if (!ws_bo->bo) { - free(ws_bo); - return NULL; + if (radeon->use_mem_constant && (usage & PIPE_BIND_CONSTANT_BUFFER)) { + desc.alignment = alignment; + desc.usage = usage; + ws_bo->pb = pb_malloc_buffer_create(size, &desc); + if (ws_bo->pb == NULL) { + free(ws_bo); + return NULL; + } + } else { + ws_bo->bo = radeon_bo(radeon, 0, size, alignment, NULL); + if (!ws_bo->bo) { + free(ws_bo); + return NULL; + } } pipe_reference_init(&ws_bo->reference, 1); @@ -30,20 +43,28 @@ struct radeon_ws_bo *radeon_ws_bo_handle(struct radeon *radeon, return ws_bo; } -void *radeon_ws_bo_map(struct radeon *radeon, struct radeon_ws_bo *bo) +void *radeon_ws_bo_map(struct radeon *radeon, struct radeon_ws_bo *bo, unsigned usage, void *ctx) { + if (bo->pb) + return pb_map(bo->pb, usage, ctx); radeon_bo_map(radeon, bo->bo); return bo->bo->data; } void radeon_ws_bo_unmap(struct radeon *radeon, struct radeon_ws_bo *bo) { - radeon_bo_unmap(radeon, bo->bo); + if (bo->pb) + pb_unmap(bo->pb); + else + radeon_bo_unmap(radeon, bo->bo); } static void radeon_ws_bo_destroy(struct radeon *radeon, struct radeon_ws_bo *bo) { - radeon_bo_reference(radeon, &bo->bo, NULL); + if (bo->pb) + pb_reference(&bo->pb, NULL); + else + radeon_bo_reference(radeon, &bo->bo, NULL); free(bo); } @@ -51,6 +72,7 @@ void radeon_ws_bo_reference(struct radeon *radeon, struct radeon_ws_bo **dst, struct radeon_ws_bo *src) { struct radeon_ws_bo *old = *dst; + if (pipe_reference(&(*dst)->reference, &src->reference)) { radeon_ws_bo_destroy(radeon, old); } @@ -59,5 +81,8 @@ void radeon_ws_bo_reference(struct radeon *radeon, struct radeon_ws_bo **dst, int radeon_ws_bo_wait(struct radeon *radeon, struct radeon_ws_bo *bo) { - return radeon_bo_wait(radeon, bo->bo); + if (bo->pb) + return 0; + else + return radeon_bo_wait(radeon, bo->bo); } -- 2.30.2