introduce an abstraction layer between kernel bos and the winsys BOs.
this is to allow plugging in pb manager with minimal disruption to pipe driver.
radeon_state_init(rstate, rscreen->rw, R600_STATE_CB0, cb, 0);
rtex = (struct r600_resource_texture*)state->cbufs[cb]->texture;
rbuffer = &rtex->resource;
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], rbuffer->bo);
rstate->placement[0] = RADEON_GEM_DOMAIN_VRAM;
rstate->nbo = 1;
pitch = (rtex->pitch[level] / rtex->bpt) / 8 - 1;
rtex->depth = 1;
rbuffer = &rtex->resource;
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], rbuffer->bo);
rstate->nbo = 1;
rstate->placement[0] = RADEON_GEM_DOMAIN_VRAM;
level = state->zsbuf->level;
if (r) {
return;
}
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, tmp->uncompressed);
- rstate->bo[1] = radeon_bo_incref(rscreen->rw, tmp->uncompressed);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], tmp->uncompressed);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[1], tmp->uncompressed);
} else {
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
- rstate->bo[1] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[1], rbuffer->bo);
}
rstate->nbo = 2;
rstate->placement[0] = RADEON_GEM_DOMAIN_GTT;
struct r600_screen *rscreen = rctx->screen;
radeon_state_init(vs_resource, rscreen->rw, R600_STATE_RESOURCE, id, R600_SHADER_VS);
- vs_resource->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+
+ radeon_ws_bo_reference(rscreen->rw, &vs_resource->bo[0], rbuffer->bo);
vs_resource->nbo = 1;
vs_resource->states[EG_PS_RESOURCE__RESOURCE0_WORD0] = offset;
- vs_resource->states[EG_PS_RESOURCE__RESOURCE0_WORD1] = rbuffer->bo->size - offset - 1;
+ vs_resource->states[EG_PS_RESOURCE__RESOURCE0_WORD1] = rbuffer->size - offset - 1;
vs_resource->states[EG_PS_RESOURCE__RESOURCE0_WORD2] = S_030008_STRIDE(stride) |
S_030008_DATA_FORMAT(format);
vs_resource->states[EG_PS_RESOURCE__RESOURCE0_WORD3] = S_03000C_DST_SEL_X(V_03000C_SQ_SEL_X) |
draw->draw.states[EG_DRAW__VGT_DRAW_INITIATOR] = vgt_draw_initiator;
draw->draw.states[EG_DRAW__VGT_DMA_BASE] = draw->index_buffer_offset;
if (rbuffer) {
- draw->draw.bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &draw->draw.bo[0], rbuffer->bo);
draw->draw.placement[0] = RADEON_GEM_DOMAIN_GTT;
draw->draw.placement[1] = RADEON_GEM_DOMAIN_GTT;
draw->draw.nbo = 1;
state->states[EG_PS_SHADER__SQ_PGM_EXPORTS_PS] = exports_ps;
state->states[EG_PS_SHADER__SPI_BARYC_CNTL] = S_0286E0_PERSP_CENTROID_ENA(1) |
S_0286E0_LINEAR_CENTROID_ENA(1);
- state->bo[0] = radeon_bo_incref(rscreen->rw, rpshader->bo);
+ radeon_ws_bo_reference(rscreen->rw, &state->bo[0], rpshader->bo);
state->nbo = 1;
state->placement[0] = RADEON_GEM_DOMAIN_GTT;
return radeon_state_pm4(state);
state->states[EG_VS_SHADER__SPI_VS_OUT_CONFIG] = S_0286C4_VS_EXPORT_COUNT(rshader->noutput - 2);
state->states[EG_VS_SHADER__SQ_PGM_RESOURCES_VS] = S_028860_NUM_GPRS(rshader->bc.ngpr) |
S_028860_STACK_SIZE(rshader->bc.nstack);
- state->bo[0] = radeon_bo_incref(rscreen->rw, rpshader->bo);
- state->bo[1] = radeon_bo_incref(rscreen->rw, rpshader->bo);
+ radeon_ws_bo_reference(rscreen->rw, &state->bo[0], rpshader->bo);
+ radeon_ws_bo_reference(rscreen->rw, &state->bo[1], rpshader->bo);
state->nbo = 2;
state->placement[0] = RADEON_GEM_DOMAIN_GTT;
state->placement[2] = RADEON_GEM_DOMAIN_GTT;
format = r600_translate_colorformat(rtexture->resource.base.b.format);
swap = r600_translate_colorswap(rtexture->resource.base.b.format);
if (desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) {
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, rtexture->uncompressed);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], rtexture->uncompressed);
rstate->placement[0] = RADEON_GEM_DOMAIN_GTT;
rstate->nbo = 1;
color_info = 0;
} else {
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], rbuffer->bo);
rstate->placement[0] = RADEON_GEM_DOMAIN_GTT;
rstate->nbo = 1;
color_info = S_028C70_SOURCE_FORMAT(1);
rstate->states[EG_DB__DB_DEPTH_VIEW] = 0x00000000;
rstate->states[EG_DB__DB_DEPTH_SIZE] = S_028058_PITCH_TILE_MAX(pitch);
rstate->states[EG_DB__DB_DEPTH_SLICE] = S_02805C_SLICE_TILE_MAX(slice);
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], rbuffer->bo);
rstate->placement[0] = RADEON_GEM_DOMAIN_GTT;
rstate->nbo = 1;
rstate->states[EG_VS_CBUF__ALU_CONST_BUFFER_SIZE_VS_0] = size;
rstate->states[EG_VS_CBUF__ALU_CONST_CACHE_VS_0] = 0;
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], rbuffer->bo);
rstate->nbo = 1;
rstate->placement[0] = RADEON_GEM_DOMAIN_VRAM;
if (radeon_state_pm4(rstate))
static int r600_blit_state_vs_resources(struct r600_screen *rscreen, struct r600_blit_states *bstates)
{
struct radeon_state *rstate;
- struct radeon_bo *bo;
+ struct radeon_ws_bo *bo;
+ void *data;
u32 vbo[] = {
0xBF800000, 0xBF800000, 0x3F800000, 0x3F800000,
0x3F000000, 0x3F000000, 0x3F000000, 0x00000000,
};
/* simple shader */
- bo = radeon_bo(rscreen->rw, 0, 128, 4096, NULL);
+ bo = radeon_ws_bo(rscreen->rw, 128, 4096);
if (bo == NULL) {
return -ENOMEM;
}
- if (radeon_bo_map(rscreen->rw, bo)) {
- radeon_bo_decref(rscreen->rw, bo);
+ data = radeon_ws_bo_map(rscreen->rw, bo);
+ if (!data) {
+ radeon_ws_bo_reference(rscreen->rw, &bo, NULL);
return -ENOMEM;
}
- memcpy(bo->data, vbo, 128);
- radeon_bo_unmap(rscreen->rw, bo);
+ memcpy(data, vbo, 128);
+ radeon_ws_bo_unmap(rscreen->rw, bo);
rstate = &bstates->vs_resource0;
radeon_state_init(rstate, rscreen->rw, R600_STATE_RESOURCE, 0, R600_SHADER_VS);
rstate->states[R600_VS_RESOURCE__RESOURCE160_WORD4] = 0x00000000;
rstate->states[R600_VS_RESOURCE__RESOURCE160_WORD5] = 0x00000000;
rstate->states[R600_VS_RESOURCE__RESOURCE160_WORD6] = 0xC0000000;
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], bo);
rstate->nbo = 1;
rstate->placement[0] = RADEON_GEM_DOMAIN_GTT;
if (radeon_state_pm4(rstate)) {
static void r600_blit_state_vs_shader(struct r600_screen *rscreen, struct radeon_state *rstate)
{
- struct radeon_bo *bo;
+ struct radeon_ws_bo *bo;
+ void *data;
u32 shader_bc_r600[] = {
0x00000004, 0x81000400,
0x00000008, 0xA01C0000,
};
/* simple shader */
- bo = radeon_bo(rscreen->rw, 0, 128, 4096, NULL);
+ bo = radeon_ws_bo(rscreen->rw, 128, 4096);
if (bo == NULL) {
return;
}
- if (radeon_bo_map(rscreen->rw, bo)) {
- radeon_bo_decref(rscreen->rw, bo);
+ data = radeon_ws_bo_map(rscreen->rw, bo);
+ if (!data) {
+ radeon_ws_bo_reference(rscreen->rw, &bo, NULL);
return;
}
switch (rscreen->chip_class) {
case R600:
- memcpy(bo->data, shader_bc_r600, 128);
+ memcpy(data, shader_bc_r600, 128);
break;
case R700:
- memcpy(bo->data, shader_bc_r700, 128);
+ memcpy(data, shader_bc_r700, 128);
break;
default:
R600_ERR("unsupported chip family\n");
- radeon_bo_unmap(rscreen->rw, bo);
- radeon_bo_decref(rscreen->rw, bo);
+ radeon_ws_bo_unmap(rscreen->rw, bo);
+ radeon_ws_bo_reference(rscreen->rw, &bo, NULL);
return;
}
- radeon_bo_unmap(rscreen->rw, bo);
+ radeon_ws_bo_unmap(rscreen->rw, bo);
radeon_state_init(rstate, rscreen->rw, R600_STATE_SHADER, 0, R600_SHADER_VS);
rstate->states[R600_VS_SHADER__SQ_PGM_RESOURCES_VS] = 0x00000005;
rstate->bo[0] = bo;
- rstate->bo[1] = radeon_bo_incref(rscreen->rw, bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[1], bo);
rstate->nbo = 2;
rstate->placement[0] = RADEON_GEM_DOMAIN_GTT;
rstate->placement[2] = RADEON_GEM_DOMAIN_GTT;
static void r600_blit_state_ps_shader(struct r600_screen *rscreen, struct radeon_state *rstate)
{
- struct radeon_bo *bo;
+ struct radeon_ws_bo *bo;
+ void *data;
u32 shader_bc_r600[] = {
0x00000002, 0xA00C0000,
0xC0008000, 0x94200688,
};
/* simple shader */
- bo = radeon_bo(rscreen->rw, 0, 128, 4096, NULL);
+ bo = radeon_ws_bo(rscreen->rw, 128, 4096);
if (bo == NULL) {
return;
}
- if (radeon_bo_map(rscreen->rw, bo)) {
- radeon_bo_decref(rscreen->rw, bo);
+ data = radeon_ws_bo_map(rscreen->rw, bo);
+ if (!data) {
+ radeon_ws_bo_reference(rscreen->rw, &bo, NULL);
return;
}
switch (rscreen->chip_class) {
case R600:
- memcpy(bo->data, shader_bc_r600, 48);
+ memcpy(data, shader_bc_r600, 48);
break;
case R700:
- memcpy(bo->data, shader_bc_r700, 48);
+ memcpy(data, shader_bc_r700, 48);
break;
default:
R600_ERR("unsupported chip family\n");
- radeon_bo_unmap(rscreen->rw, bo);
- radeon_bo_decref(rscreen->rw, bo);
+ radeon_ws_bo_unmap(rscreen->rw, bo);
+ radeon_ws_bo_reference(rscreen->rw, &bo, NULL);
return;
}
- radeon_bo_unmap(rscreen->rw, bo);
+ radeon_ws_bo_unmap(rscreen->rw, bo);
radeon_state_init(rstate, rscreen->rw, R600_STATE_SHADER, 0, R600_SHADER_PS);
{
struct r600_screen *rscreen = r600_screen(screen);
struct r600_resource *rbuffer;
- struct radeon_bo *bo;
+ struct radeon_ws_bo *bo;
struct pb_desc desc;
/* XXX We probably want a different alignment for buffers and textures. */
unsigned alignment = 4096;
pipe_reference_init(&rbuffer->base.b.reference, 1);
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;
return &rbuffer->base.b;
}
rbuffer->domain = r600_domain_from_usage(rbuffer->base.b.bind);
- bo = radeon_bo(rscreen->rw, 0, rbuffer->base.b.width0, alignment, NULL);
+ bo = radeon_ws_bo(rscreen->rw, rbuffer->base.b.width0, alignment);
if (bo == NULL) {
FREE(rbuffer);
return NULL;
struct r600_resource *rbuffer;
struct r600_screen *rscreen = r600_screen(screen);
struct pipe_resource templ;
+ void *data;
memset(&templ, 0, sizeof(struct pipe_resource));
templ.target = PIPE_BUFFER;
if (rbuffer == NULL) {
return NULL;
}
- radeon_bo_map(rscreen->rw, rbuffer->bo);
- memcpy(rbuffer->bo->data, ptr, bytes);
- radeon_bo_unmap(rscreen->rw, rbuffer->bo);
+ data = radeon_ws_bo_map(rscreen->rw, rbuffer->bo);
+ memcpy(data, ptr, bytes);
+ radeon_ws_bo_unmap(rscreen->rw, rbuffer->bo);
return &rbuffer->base.b;
}
rbuffer->pb = NULL;
}
if (rbuffer->bo) {
- radeon_bo_decref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rbuffer->bo, NULL);
}
memset(rbuffer, 0, sizeof(struct r600_resource));
FREE(rbuffer);
struct r600_resource *rbuffer = (struct r600_resource*)transfer->resource;
struct r600_screen *rscreen = r600_screen(pipe->screen);
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_WRITE) {
write = 1;
}
- if (radeon_bo_map(rscreen->rw, rbuffer->bo)) {
+ data = radeon_ws_bo_map(rscreen->rw, rbuffer->bo);
+ if (!data)
return NULL;
- }
- return (uint8_t*)rbuffer->bo->data + transfer->box.x;
+
+ return (uint8_t*)data + transfer->box.x;
}
static void r600_buffer_transfer_unmap(struct pipe_context *pipe,
if (rbuffer->pb) {
pb_unmap(rbuffer->pb);
} else {
- radeon_bo_unmap(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_unmap(rscreen->rw, rbuffer->bo);
}
}
{
struct radeon *rw = (struct radeon*)screen->winsys;
struct r600_resource *rbuffer;
- struct radeon_bo *bo = NULL;
+ struct radeon_ws_bo *bo = NULL;
- bo = radeon_bo(rw, whandle->handle, 0, 0, NULL);
+ bo = radeon_ws_bo_handle(rw, whandle->handle);
if (bo == NULL) {
return NULL;
}
rbuffer = CALLOC_STRUCT(r600_resource);
if (rbuffer == NULL) {
- radeon_bo_decref(rw, bo);
+ radeon_ws_bo_reference(rw, &bo, NULL);
return NULL;
}
boolean flushed;
unsigned state;
/* The buffer where query results are stored. */
- struct radeon_bo *buffer;
+ struct radeon_ws_bo *buffer;
unsigned buffer_size;
/* linked list of queries */
struct list_head list;
unsigned type;
struct radeon_state rstate[R600_MAX_RSTATE];
struct r600_shader shader;
- struct radeon_bo *bo;
+ struct radeon_ws_bo *bo;
unsigned nrstate;
};
radeon_state_init(rstate, rscreen->rw, R600_STATE_CB0 + cb, 0, 0);
rtex = (struct r600_resource_texture*)state->cbufs[cb]->texture;
rbuffer = &rtex->resource;
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], rbuffer->bo);
rstate->placement[0] = RADEON_GEM_DOMAIN_GTT;
rstate->nbo = 1;
pitch = (rtex->pitch[level] / rtex->bpt) / 8 - 1;
rtex->depth = 1;
rbuffer = &rtex->resource;
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], rbuffer->bo);
rstate->nbo = 1;
rstate->placement[0] = RADEON_GEM_DOMAIN_VRAM;
level = state->zsbuf->level;
if (r) {
return;
}
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, tmp->uncompressed);
- rstate->bo[1] = radeon_bo_incref(rscreen->rw, tmp->uncompressed);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], tmp->uncompressed);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[1], tmp->uncompressed);
} else {
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
- rstate->bo[1] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[1], rbuffer->bo);
}
rstate->nbo = 2;
rstate->placement[0] = RADEON_GEM_DOMAIN_GTT;
struct r600_screen *rscreen = rctx->screen;
radeon_state_init(vs_resource, rscreen->rw, R600_STATE_RESOURCE, id, R600_SHADER_VS);
- vs_resource->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &vs_resource->bo[0], rbuffer->bo);
vs_resource->nbo = 1;
vs_resource->states[R600_PS_RESOURCE__RESOURCE0_WORD0] = offset;
- vs_resource->states[R600_PS_RESOURCE__RESOURCE0_WORD1] = rbuffer->bo->size - offset - 1;
+ vs_resource->states[R600_PS_RESOURCE__RESOURCE0_WORD1] = rbuffer->size - offset - 1;
vs_resource->states[R600_PS_RESOURCE__RESOURCE0_WORD2] = S_038008_STRIDE(stride) |
S_038008_DATA_FORMAT(format);
vs_resource->states[R600_PS_RESOURCE__RESOURCE0_WORD3] = 0x00000000;
draw->draw.states[R600_DRAW__VGT_DRAW_INITIATOR] = vgt_draw_initiator;
draw->draw.states[R600_DRAW__VGT_DMA_BASE] = draw->index_buffer_offset;
if (rbuffer) {
- draw->draw.bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &draw->draw.bo[0], rbuffer->bo);
draw->draw.placement[0] = RADEON_GEM_DOMAIN_GTT;
draw->draw.placement[1] = RADEON_GEM_DOMAIN_GTT;
draw->draw.nbo = 1;
state->states[R600_PS_SHADER__SQ_PGM_RESOURCES_PS] = S_028868_NUM_GPRS(rshader->bc.ngpr) |
S_028868_STACK_SIZE(rshader->bc.nstack);
state->states[R600_PS_SHADER__SQ_PGM_EXPORTS_PS] = exports_ps;
- state->bo[0] = radeon_bo_incref(rscreen->rw, rpshader->bo);
+ radeon_ws_bo_reference(rscreen->rw, &state->bo[0], rpshader->bo);
state->nbo = 1;
state->placement[0] = RADEON_GEM_DOMAIN_GTT;
return radeon_state_pm4(state);
state->states[R600_VS_SHADER__SPI_VS_OUT_CONFIG] = S_0286C4_VS_EXPORT_COUNT(rshader->noutput - 2);
state->states[R600_VS_SHADER__SQ_PGM_RESOURCES_VS] = S_028868_NUM_GPRS(rshader->bc.ngpr) |
S_028868_STACK_SIZE(rshader->bc.nstack);
- state->bo[0] = radeon_bo_incref(rscreen->rw, rpshader->bo);
- state->bo[1] = radeon_bo_incref(rscreen->rw, rpshader->bo);
+ radeon_ws_bo_reference(rscreen->rw, &state->bo[0], rpshader->bo);
+ radeon_ws_bo_reference(rscreen->rw, &state->bo[1], rpshader->bo);
state->nbo = 2;
state->placement[0] = RADEON_GEM_DOMAIN_GTT;
state->placement[2] = RADEON_GEM_DOMAIN_GTT;
format = r600_translate_colorformat(rtexture->resource.base.b.format);
swap = r600_translate_colorswap(rtexture->resource.base.b.format);
if (desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) {
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, rtexture->uncompressed);
- rstate->bo[1] = radeon_bo_incref(rscreen->rw, rtexture->uncompressed);
- rstate->bo[2] = radeon_bo_incref(rscreen->rw, rtexture->uncompressed);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], rtexture->uncompressed);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[1], rtexture->uncompressed);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[2], rtexture->uncompressed);
rstate->placement[0] = RADEON_GEM_DOMAIN_GTT;
rstate->placement[2] = RADEON_GEM_DOMAIN_GTT;
rstate->placement[4] = RADEON_GEM_DOMAIN_GTT;
rstate->nbo = 3;
color_info = 0;
} else {
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
- rstate->bo[1] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
- rstate->bo[2] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[1], rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[2], rbuffer->bo);
rstate->placement[0] = RADEON_GEM_DOMAIN_GTT;
rstate->placement[2] = RADEON_GEM_DOMAIN_GTT;
rstate->placement[4] = RADEON_GEM_DOMAIN_GTT;
rstate->states[R600_DB__DB_PREFETCH_LIMIT] = (rtexture->height[level] / 8) -1;
rstate->states[R600_DB__DB_DEPTH_SIZE] = S_028000_PITCH_TILE_MAX(pitch) |
S_028000_SLICE_TILE_MAX(slice);
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], rbuffer->bo);
rstate->placement[0] = RADEON_GEM_DOMAIN_GTT;
rstate->nbo = 1;
rstate->states[R600_VS_CBUF__ALU_CONST_BUFFER_SIZE_VS_0] = size;
rstate->states[R600_VS_CBUF__ALU_CONST_CACHE_VS_0] = 0;
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], rbuffer->bo);
rstate->nbo = 1;
rstate->placement[0] = RADEON_GEM_DOMAIN_VRAM;
if (radeon_state_pm4(rstate))
radeon_state_fini(rstate);
radeon_state_init(rstate, rscreen->rw, R600_STATE_QUERY_BEGIN, 0, 0);
rstate->states[R600_QUERY__OFFSET] = rquery->num_results;
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, rquery->buffer);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], rquery->buffer);
rstate->nbo = 1;
rstate->placement[0] = RADEON_GEM_DOMAIN_GTT;
if (radeon_state_pm4(rstate)) {
radeon_state_fini(rstate);
radeon_state_init(rstate, rscreen->rw, R600_STATE_QUERY_END, 0, 0);
rstate->states[R600_QUERY__OFFSET] = rquery->num_results + 8;
- rstate->bo[0] = radeon_bo_incref(rscreen->rw, rquery->buffer);
+ radeon_ws_bo_reference(rscreen->rw, &rstate->bo[0], rquery->buffer);
rstate->nbo = 1;
rstate->placement[0] = RADEON_GEM_DOMAIN_GTT;
if (radeon_state_pm4(rstate)) {
q->type = query_type;
q->buffer_size = 4096;
- q->buffer = radeon_bo(rscreen->rw, 0, q->buffer_size, 1, NULL);
+ q->buffer = radeon_ws_bo(rscreen->rw, q->buffer_size, 1);
if (!q->buffer) {
FREE(q);
return NULL;
struct r600_screen *rscreen = r600_screen(ctx->screen);
struct r600_query *q = r600_query(query);
- radeon_bo_decref(rscreen->rw, q->buffer);
+ radeon_ws_bo_reference(rscreen->rw, &q->buffer, NULL);
LIST_DEL(&q->list);
FREE(query);
}
u32 *results;
int i;
- radeon_bo_wait(rscreen->rw, rquery->buffer);
- radeon_bo_map(rscreen->rw, rquery->buffer);
- results = rquery->buffer->data;
+ radeon_ws_bo_wait(rscreen->rw, rquery->buffer);
+ results = radeon_ws_bo_map(rscreen->rw, rquery->buffer);
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;
rquery->result += end - start;
}
}
- radeon_bo_unmap(rscreen->rw, rquery->buffer);
+ radeon_ws_bo_unmap(rscreen->rw, rquery->buffer);
rquery->num_results = 0;
}
*/
struct r600_resource {
struct u_resource base;
- struct radeon_bo *bo;
+ struct radeon_ws_bo *bo;
u32 domain;
u32 flink;
struct pb_buffer *pb;
+ u32 size;
};
struct r600_resource_texture {
unsigned tile_type;
unsigned depth;
unsigned dirty;
- struct radeon_bo *uncompressed;
+ struct radeon_ws_bo *uncompressed;
struct radeon_state scissor[PIPE_MAX_TEXTURE_LEVELS];
struct radeon_state cb[8][PIPE_MAX_TEXTURE_LEVELS];
struct radeon_state db[PIPE_MAX_TEXTURE_LEVELS];
struct r600_context *rctx = r600_context(ctx);
struct r600_shader *rshader = &rpshader->shader;
int r;
+ void *data;
/* copy new shader */
- radeon_bo_decref(rscreen->rw, rpshader->bo);
+ radeon_ws_bo_reference(rscreen->rw, &rpshader->bo, NULL);
rpshader->bo = NULL;
- rpshader->bo = radeon_bo(rscreen->rw, 0, rshader->bc.ndw * 4,
- 4096, NULL);
+ rpshader->bo = radeon_ws_bo(rscreen->rw, rshader->bc.ndw * 4,
+ 4096);
if (rpshader->bo == NULL) {
return -ENOMEM;
}
- radeon_bo_map(rscreen->rw, rpshader->bo);
- memcpy(rpshader->bo->data, rshader->bc.bytecode, rshader->bc.ndw * 4);
- radeon_bo_unmap(rscreen->rw, rpshader->bo);
+ data = radeon_ws_bo_map(rscreen->rw, rpshader->bo);
+ memcpy(data, rshader->bc.bytecode, rshader->bc.ndw * 4);
+ radeon_ws_bo_unmap(rscreen->rw, rpshader->bo);
/* build state */
rshader->flat_shade = rctx->flat_shade;
switch (rshader->processor_type) {
rtex = (struct r600_resource_texture*)surf->texture;
rbuffer = &rtex->resource;
/* just need to the bo to the flush list */
- flush->bo[i] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &flush->bo[i], rbuffer->bo);
flush->placement[i] = RADEON_GEM_DOMAIN_VRAM;
}
flush->nbo = rctx->framebuffer->state.framebuffer.nr_cbufs;
rtex = (struct r600_resource_texture*)surf->texture;
rbuffer = &rtex->resource;
/* just need to the bo to the flush list */
- flush->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
+ radeon_ws_bo_reference(rscreen->rw, &flush->bo[0], rbuffer->bo);
flush->placement[0] = RADEON_GEM_DOMAIN_VRAM;
flush->nbo = 1;
/* FIXME alignment 4096 enought ? too much ? */
resource->domain = r600_domain_from_usage(resource->base.b.bind);
- resource->bo = radeon_bo(radeon, 0, rtex->size, 4096, NULL);
+ resource->size = rtex->size;
+ resource->bo = radeon_ws_bo(radeon, rtex->size, 4096);
if (resource->bo == NULL) {
FREE(rtex);
return NULL;
struct radeon *radeon = (struct radeon *)screen->winsys;
if (resource->bo) {
- radeon_bo_decref(radeon, resource->bo);
+ radeon_ws_bo_reference(radeon, &resource->bo, NULL);
}
if (rtex->uncompressed) {
- radeon_bo_decref(radeon, rtex->uncompressed);
+ radeon_ws_bo_reference(radeon, &rtex->uncompressed, NULL);
}
r600_texture_destroy_state(ptex);
FREE(rtex);
struct radeon *rw = (struct radeon*)screen->winsys;
struct r600_resource_texture *rtex;
struct r600_resource *resource;
- struct radeon_bo *bo = NULL;
+ struct radeon_ws_bo *bo = NULL;
/* Support only 2D textures without mipmaps */
if ((templ->target != PIPE_TEXTURE_2D && templ->target != PIPE_TEXTURE_RECT) ||
if (rtex == NULL)
return NULL;
- bo = radeon_bo(rw, whandle->handle, 0, 0, NULL);
+ bo = radeon_ws_bo_handle(rw, whandle->handle);
if (bo == NULL) {
FREE(rtex);
return NULL;
{
struct r600_screen *rscreen = r600_screen(ctx->screen);
struct r600_transfer *rtransfer = (struct r600_transfer*)transfer;
- struct radeon_bo *bo;
+ struct radeon_ws_bo *bo;
enum pipe_format format = transfer->resource->format;
struct radeon *radeon = (struct radeon *)ctx->screen->winsys;
struct r600_resource_texture *rtex;
transfer->box.y / util_format_get_blockheight(format) * transfer->stride +
transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
}
- if (radeon_bo_map(radeon, bo)) {
+ map = radeon_ws_bo_map(radeon, bo);
+ if (!map) {
return NULL;
}
- radeon_bo_wait(radeon, bo);
+ radeon_ws_bo_wait(radeon, bo);
- map = bo->data;
return map + offset;
}
struct r600_transfer *rtransfer = (struct r600_transfer*)transfer;
struct radeon *radeon = (struct radeon *)ctx->screen->winsys;
struct r600_resource_texture *rtex;
- struct radeon_bo *bo;
+ struct radeon_ws_bo *bo;
if (rtransfer->linear_texture) {
bo = ((struct r600_resource *)rtransfer->linear_texture)->bo;
bo = ((struct r600_resource *)transfer->resource)->bo;
}
}
- radeon_bo_unmap(radeon, bo);
+ radeon_ws_bo_unmap(radeon, bo);
}
struct u_resource_vtbl r600_texture_vtbl =
/* allocate uncompressed texture */
if (rtexture->uncompressed == NULL) {
- rtexture->uncompressed = radeon_bo(rscreen->rw, 0, rtexture->size, 4096, NULL);
+ rtexture->uncompressed = radeon_ws_bo(rscreen->rw, rtexture->size, 4096);
if (rtexture->uncompressed == NULL) {
return -ENOMEM;
}
enum radeon_family radeon_get_family(struct radeon *rw);
-/*
- * radeon object functions
- */
-struct radeon_bo {
- unsigned refcount;
- unsigned handle;
- unsigned size;
- unsigned alignment;
- unsigned map_count;
- void *data;
-};
-struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle,
- unsigned size, unsigned alignment, void *ptr);
-int radeon_bo_map(struct radeon *radeon, struct radeon_bo *bo);
-void radeon_bo_unmap(struct radeon *radeon, struct radeon_bo *bo);
-struct radeon_bo *radeon_bo_incref(struct radeon *radeon, struct radeon_bo *bo);
-struct radeon_bo *radeon_bo_decref(struct radeon *radeon, struct radeon_bo *bo);
-int radeon_bo_wait(struct radeon *radeon, struct radeon_bo *bo);
+/* lowlevel WS bo */
+struct radeon_ws_bo;
+struct radeon_ws_bo *radeon_ws_bo(struct radeon *radeon,
+ unsigned size, unsigned alignment);
+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_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);
+int radeon_ws_bo_wait(struct radeon *radeon, struct radeon_ws_bo *bo);
struct radeon_stype_info;
/*
u32 pm4_crc;
u32 pm4[128];
unsigned nbo;
- struct radeon_bo *bo[4];
+ struct radeon_ws_bo *bo[4];
unsigned nreloc;
unsigned reloc_pm4_id[8];
unsigned reloc_bo_id[8];
radeon_bo.c \
radeon_pciid.c \
radeon.c \
- r600_drm.c
+ r600_drm.c \
+ radeon_ws_bo.c
LIBRARY_INCLUDES = -I$(TOP)/src/gallium/drivers/r600 \
$(shell pkg-config libdrm --cflags-only-I)
return radeon_new(drmfd, 0);
}
-boolean r600_buffer_get_handle(struct radeon *rw,
- struct pipe_resource *buf,
- struct winsys_handle *whandle)
-{
- struct drm_gem_flink flink;
- struct r600_resource* rbuffer = (struct r600_resource*)buf;
-
- if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) {
- if (!rbuffer->flink) {
- flink.handle = rbuffer->bo->handle;
-
- if (ioctl(rw->fd, DRM_IOCTL_GEM_FLINK, &flink)) {
- return FALSE;
- }
-
- rbuffer->flink = flink.name;
- }
- whandle->handle = rbuffer->flink;
- } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) {
- whandle->handle = rbuffer->bo->handle;
- }
- return TRUE;
-}
r = radeon_state_reloc(state, state->cpm4, regs[id + i].bo_id);
if (r)
return r;
- state->pm4[state->cpm4++] = state->bo[regs[id + i].bo_id]->handle;
+ state->pm4[state->cpm4++] = state->bo[regs[id + i].bo_id]->bo->handle;
}
}
return 0;
r = radeon_state_reloc(state, state->cpm4, regs[id + i].bo_id);
if (r)
return r;
- state->pm4[state->cpm4++] = state->bo[regs[id + i].bo_id]->handle;
+ state->pm4[state->cpm4++] = state->bo[regs[id + i].bo_id]->bo->handle;
}
}
return 0;
r = radeon_state_reloc(state, state->cpm4, regs[id + i].bo_id);
if (r)
return r;
- state->pm4[state->cpm4++] = state->bo[regs[id + i].bo_id]->handle;
+ state->pm4[state->cpm4++] = state->bo[regs[id + i].bo_id]->bo->handle;
}
}
return 0;
r = radeon_state_reloc(state, state->cpm4, regs[id + i].bo_id);
if (r)
return r;
- state->pm4[state->cpm4++] = state->bo[regs[id + i].bo_id]->handle;
+ state->pm4[state->cpm4++] = state->bo[regs[id + i].bo_id]->bo->handle;
}
}
return 0;
}
}
for (i = 0; i < state->nreloc; i++) {
- size = (state->bo[state->reloc_bo_id[i]]->size + 255) >> 8;
+ size = (state->bo[state->reloc_bo_id[i]]->bo->size + 255) >> 8;
state->pm4[state->cpm4++] = PKT3(PKT3_SURFACE_SYNC, 3);
if (bufs_are_cbs)
flags |= S_0085F0_CB0_DEST_BASE_ENA(1 << i);
state->pm4[state->cpm4++] = 0x0000000A;
state->pm4[state->cpm4++] = PKT3(PKT3_NOP, 0);
state->reloc_pm4_id[i] = state->cpm4;
- state->pm4[state->cpm4++] = state->bo[state->reloc_bo_id[i]]->handle;
+ state->pm4[state->cpm4++] = state->bo[state->reloc_bo_id[i]]->bo->handle;
}
}
r = radeon_state_reloc(state, state->cpm4, 0);
if (r)
return r;
- state->pm4[state->cpm4++] = state->bo[0]->handle;
+ state->pm4[state->cpm4++] = state->bo[0]->bo->handle;
return 0;
}
r = radeon_state_reloc(state, state->cpm4, 0);
if (r)
return r;
- state->pm4[state->cpm4++] = state->bo[0]->handle;
+ state->pm4[state->cpm4++] = state->bo[0]->bo->handle;
return 0;
}
r = radeon_state_reloc(state, state->cpm4, 0);
if (r)
return r;
- state->pm4[state->cpm4++] = state->bo[0]->handle;
+ state->pm4[state->cpm4++] = state->bo[0]->bo->handle;
} else {
state->pm4[state->cpm4++] = PKT3(PKT3_DRAW_INDEX_AUTO, 1);
state->pm4[state->cpm4++] = state->states[R600_DRAW__VGT_NUM_INDICES];
r = radeon_state_reloc(state, state->cpm4, 0);
if (r)
return r;
- state->pm4[state->cpm4++] = state->bo[0]->handle;
+ state->pm4[state->cpm4++] = state->bo[0]->bo->handle;
if (type == 2) {
state->pm4[state->cpm4++] = PKT3(PKT3_NOP, 0);
r = radeon_state_reloc(state, state->cpm4, 1);
if (r)
return r;
- state->pm4[state->cpm4++] = state->bo[1]->handle;
+ state->pm4[state->cpm4++] = state->bo[1]->bo->handle;
}
return 0;
}
}
bo->size = size;
bo->handle = handle;
- bo->refcount = 1;
+ pipe_reference_init(&bo->reference, 1);
bo->alignment = alignment;
if (handle) {
if (ptr) {
if (radeon_bo_map(radeon, bo)) {
fprintf(stderr, "%s failed to copy data into bo\n", __func__);
- return radeon_bo_decref(radeon, bo);
+ radeon_bo_reference(radeon, &bo, NULL);
+ return bo;
}
memcpy(bo->data, ptr, size);
radeon_bo_unmap(radeon, bo);
bo->data = NULL;
}
-struct radeon_bo *radeon_bo_incref(struct radeon *radeon, struct radeon_bo *bo)
-{
- bo->refcount++;
- return bo;
-}
-
-struct radeon_bo *radeon_bo_decref(struct radeon *radeon, struct radeon_bo *bo)
+static void radeon_bo_destroy(struct radeon *radeon, struct radeon_bo *bo)
{
struct drm_gem_close args;
- if (bo == NULL)
- return NULL;
- if (--bo->refcount > 0) {
- return NULL;
- }
-
- if (bo->map_count) {
- munmap(bo->data, bo->size);
- }
memset(&args, 0, sizeof(args));
args.handle = bo->handle;
drmIoctl(radeon->fd, DRM_IOCTL_GEM_CLOSE, &args);
memset(bo, 0, sizeof(struct radeon_bo));
free(bo);
- return NULL;
+}
+
+void radeon_bo_reference(struct radeon *radeon,
+ struct radeon_bo **dst,
+ struct radeon_bo *src)
+{
+ struct radeon_bo *old = *dst;
+ if (pipe_reference(&(*dst)->reference, &src->reference)) {
+ radeon_bo_destroy(radeon, old);
+ }
+ *dst = src;
}
int radeon_bo_wait(struct radeon *radeon, struct radeon_bo *bo)
#include "radeon_drm.h"
#include "bof.h"
-static int radeon_ctx_set_bo_new(struct radeon_ctx *ctx, struct radeon_bo *bo)
+static int radeon_ctx_set_bo_new(struct radeon_ctx *ctx, struct radeon_ws_bo *bo)
{
if (ctx->nbo >= RADEON_CTX_MAX_PM4)
return -EBUSY;
- ctx->bo[ctx->nbo] = radeon_bo_incref(ctx->radeon, bo);
+ radeon_ws_bo_reference(ctx->radeon, &ctx->bo[ctx->nbo], bo);
ctx->nbo++;
return 0;
}
-static struct radeon_bo *radeon_ctx_get_bo(struct radeon_ctx *ctx, unsigned reloc)
+static struct radeon_ws_bo *radeon_ctx_get_bo(struct radeon_ctx *ctx, unsigned reloc)
{
struct radeon_cs_reloc *greloc;
unsigned i;
+ struct radeon_ws_bo *bo;
greloc = (void *)(((u8 *)ctx->reloc) + reloc * 4);
for (i = 0; i < ctx->nbo; i++) {
- if (ctx->bo[i]->handle == greloc->handle) {
- return radeon_bo_incref(ctx->radeon, ctx->bo[i]);
+ if (ctx->bo[i]->bo->handle == greloc->handle) {
+ radeon_ws_bo_reference(ctx->radeon, &bo, ctx->bo[i]);
+ return bo;
}
}
fprintf(stderr, "%s no bo for reloc[%d 0x%08X] %d\n", __func__, reloc, greloc->handle, ctx->nbo);
placement[1] = 0;
greloc = (void *)(((u8 *)ctx->reloc) + reloc * 4);
for (i = 0; i < ctx->nbo; i++) {
- if (ctx->bo[i]->handle == greloc->handle) {
+ if (ctx->bo[i]->bo->handle == greloc->handle) {
placement[0] = greloc->read_domain | greloc->write_domain;
placement[1] = placement[0];
return;
void radeon_ctx_clear(struct radeon_ctx *ctx)
{
for (int i = 0; i < ctx->nbo; i++) {
- ctx->bo[i] = radeon_bo_decref(ctx->radeon, ctx->bo[i]);
+ radeon_ws_bo_reference(ctx->radeon, &ctx->bo[i], NULL);
}
ctx->ndwords = RADEON_CTX_MAX_PM4;
ctx->cdwords = 0;
return;
for (i = 0; i < ctx->nbo; i++) {
- ctx->bo[i] = radeon_bo_decref(ctx->radeon, ctx->bo[i]);
+ radeon_ws_bo_reference(ctx->radeon, &ctx->bo[i], NULL);
}
ctx->radeon = radeon_decref(ctx->radeon);
free(ctx->bo);
return r;
}
-static int radeon_ctx_reloc(struct radeon_ctx *ctx, struct radeon_bo *bo,
+static int radeon_ctx_reloc(struct radeon_ctx *ctx, struct radeon_ws_bo *bo,
unsigned id, unsigned *placement)
{
unsigned i;
for (i = 0; i < ctx->nreloc; i++) {
- if (ctx->reloc[i].handle == bo->handle) {
+ if (ctx->reloc[i].handle == bo->bo->handle) {
ctx->pm4[id] = i * sizeof(struct radeon_cs_reloc) / 4;
return 0;
}
if (ctx->nreloc >= RADEON_CTX_MAX_PM4) {
return -EBUSY;
}
- ctx->reloc[ctx->nreloc].handle = bo->handle;
+ ctx->reloc[ctx->nreloc].handle = bo->bo->handle;
ctx->reloc[ctx->nreloc].read_domain = placement[0] | placement [1];
ctx->reloc[ctx->nreloc].write_domain = placement[0] | placement [1];
ctx->reloc[ctx->nreloc].flags = 0;
{
bof_t *bcs, *blob, *array, *bo, *size, *handle, *device_id, *root;
unsigned i;
+ void *data;
root = device_id = bcs = blob = array = bo = size = handle = NULL;
root = bof_object();
bo = bof_object();
if (bo == NULL)
goto out_err;
- size = bof_int32(ctx->bo[i]->size);
+ size = bof_int32(ctx->bo[i]->bo->size);
if (size == NULL)
goto out_err;
if (bof_object_set(bo, "size", size))
goto out_err;
bof_decref(size);
size = NULL;
- handle = bof_int32(ctx->bo[i]->handle);
+ handle = bof_int32(ctx->bo[i]->bo->handle);
if (handle == NULL)
goto out_err;
if (bof_object_set(bo, "handle", handle))
goto out_err;
bof_decref(handle);
handle = NULL;
- radeon_bo_map(ctx->radeon, ctx->bo[i]);
- blob = bof_blob(ctx->bo[i]->size, ctx->bo[i]->data);
- radeon_bo_unmap(ctx->radeon, ctx->bo[i]);
+ data = radeon_ws_bo_map(ctx->radeon, ctx->bo[i]);
+ blob = bof_blob(ctx->bo[i]->bo->size, data);
+ radeon_ws_bo_unmap(ctx->radeon, ctx->bo[i]);
if (blob == NULL)
goto out_err;
if (bof_object_set(bo, "data", blob))
#include <errno.h>
#include "radeon.h"
+#include "pipe/p_compiler.h"
+#include "util/u_inlines.h"
+#include "pipe/p_defines.h"
+
struct radeon;
struct radeon_ctx;
+
/*
* radeon functions
*/
char name[64];
};
+struct radeon_bo {
+ struct pipe_reference reference;
+ unsigned handle;
+ unsigned size;
+ unsigned alignment;
+ unsigned map_count;
+ void *data;
+};
+
struct radeon_sub_type {
int shader_type;
const struct radeon_register *regs;
unsigned nreloc;
struct radeon_cs_reloc *reloc;
unsigned nbo;
- struct radeon_bo **bo;
+ struct radeon_ws_bo **bo;
};
struct radeon {
unsigned max_states;
};
+struct radeon_ws_bo {
+ struct pipe_reference reference;
+ struct radeon_bo *bo;
+};
+
extern struct radeon *radeon_new(int fd, unsigned device);
extern struct radeon *radeon_incref(struct radeon *radeon);
extern struct radeon *radeon_decref(struct radeon *radeon);
*/
extern int radeon_draw_pm4(struct radeon_draw *draw);
+/* bo */
+struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle,
+ unsigned size, unsigned alignment, void *ptr);
+int radeon_bo_map(struct radeon *radeon, struct radeon_bo *bo);
+void radeon_bo_unmap(struct radeon *radeon, struct radeon_bo *bo);
+void radeon_bo_reference(struct radeon *radeon, struct radeon_bo **dst,
+ struct radeon_bo *src);
+int radeon_bo_wait(struct radeon *radeon, struct radeon_bo *bo);
+
#endif
if (state == NULL)
return NULL;
for (i = 0; i < state->nbo; i++) {
- state->bo[i] = radeon_bo_decref(state->radeon, state->bo[i]);
+ radeon_ws_bo_reference(state->radeon, &state->bo[i], NULL);
}
memset(state, 0, sizeof(struct radeon_state));
}
--- /dev/null
+#include <malloc.h>
+#include "radeon_priv.h"
+
+struct radeon_ws_bo *radeon_ws_bo(struct radeon *radeon,
+ unsigned size, unsigned alignment)
+{
+ struct radeon_ws_bo *ws_bo = calloc(1, sizeof(struct radeon_ws_bo));
+
+ 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);
+ return ws_bo;
+}
+
+struct radeon_ws_bo *radeon_ws_bo_handle(struct radeon *radeon,
+ unsigned handle)
+{
+ struct radeon_ws_bo *ws_bo = calloc(1, sizeof(struct radeon_ws_bo));
+
+ ws_bo->bo = radeon_bo(radeon, handle, 0, 0, NULL);
+ if (!ws_bo->bo) {
+ free(ws_bo);
+ return NULL;
+ }
+ pipe_reference_init(&ws_bo->reference, 1);
+ return ws_bo;
+}
+
+void *radeon_ws_bo_map(struct radeon *radeon, struct radeon_ws_bo *bo)
+{
+ 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);
+}
+
+static void radeon_ws_bo_destroy(struct radeon *radeon, struct radeon_ws_bo *bo)
+{
+ radeon_bo_reference(radeon, &bo->bo, NULL);
+ free(bo);
+}
+
+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);
+ }
+ *dst = src;
+}
+
+int radeon_ws_bo_wait(struct radeon *radeon, struct radeon_ws_bo *bo)
+{
+ return radeon_bo_wait(radeon, bo->bo);
+}