mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 15:38:09 +02:00
r600g: move constant buffer creation behind winsys abstraction.
this paves the way for moving to pb bufmgrs now.
This commit is contained in:
parent
0dbcf3b014
commit
7c1fcc41be
12 changed files with 65 additions and 55 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ struct r600_resource {
|
|||
struct radeon_ws_bo *bo;
|
||||
u32 domain;
|
||||
u32 flink;
|
||||
struct pb_buffer *pb;
|
||||
u32 size;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <pipe/p_compiler.h>
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -1,15 +1,28 @@
|
|||
#include <malloc.h>
|
||||
#include <pipe/p_screen.h>
|
||||
#include <pipebuffer/pb_bufmgr.h>
|
||||
#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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue