summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerome Glisse <jglisse@redhat.com>2010-04-17 19:50:05 +0200
committerJerome Glisse <jglisse@redhat.com>2010-04-17 19:50:05 +0200
commit929087aace202bbd8396ccd406010839016e2a9b (patch)
treee25a12005a81e112e095c1e5870ab8bd3828a035
parentf8832974cf62e0394bc6ec30d091fc1150073a56 (diff)
radeondb: cleanup ctx & bo infrastructure
ctx are now like other state and are refcounted, it's up to the user to carefully avoid changing already supplied state. Also use own bo infrastructure to make things cleaner. Signed-off-by: Jerome Glisse <jglisse@redhat.com>
-rw-r--r--src/Makefile.am2
-rw-r--r--src/mode.c9
-rw-r--r--src/r600.h1
-rw-r--r--src/r600_ctx.c200
-rw-r--r--src/radeon.c107
-rw-r--r--src/radeon.h34
-rw-r--r--src/radeon_bo.c170
-rw-r--r--src/radeon_bof.c52
-rw-r--r--src/radeon_ctx.c436
-rw-r--r--src/radeon_draw.c37
-rw-r--r--src/radeon_json.c22
-rw-r--r--src/radeon_pciid.c2
-rw-r--r--src/radeon_priv.h56
-rw-r--r--src/radeon_reg.c1
-rw-r--r--src/radeon_state.c9
-rw-r--r--src/radeondb.c81
16 files changed, 695 insertions, 524 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 1d25b46..0e01d60 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -29,7 +29,7 @@ noinst_HEADER = radeon.h radeon_priv.h r600_states.h mode.h
radeondb_SOURCES = radeondb.c bof.c radeon_pciid.c radeon_ctx.c radeon_bof.c\
radeon_json.c r600_state.c r600_ctx.c mode.c radeon.c radeon_state.c\
- radeon_draw.c radeon_pci.c radeon_reg.c rs600_reg.c
+ radeon_draw.c radeon_bo.c radeon_pci.c radeon_reg.c rs600_reg.c
radeondb_LDADD = $(LIBJANSSON_LIBS) $(LIBDRM_LIBS) $(LIBDRM_RADEON_LIBS) $(PCIACCESS_LIBS)
rs600_reg.c: ../json/rs600.json ../tools/rdb.c
diff --git a/src/mode.c b/src/mode.c
index 5458cbe..9811cdc 100644
--- a/src/mode.c
+++ b/src/mode.c
@@ -101,8 +101,7 @@ setmode:
mode->height = mode->info.vdisplay;
mode->pitch = mode->info.hdisplay * mode->bpp;
mode->size = mode->pitch * mode->info.vdisplay;
- mode->bo = radeon_bo_open(radeon->bom, 0, mode->size, 0,
- RADEON_GEM_DOMAIN_VRAM, 0);
+ mode->bo = radeon_bo(radeon, 0, mode->size, 4096, NULL);
if (mode->bo == NULL) {
fprintf(stderr, "failed to create fb: %s\n", strerror(errno));
goto out;
@@ -133,7 +132,7 @@ out:
mode->fb_id = 0;
}
if (r && mode->bo) {
- mode->bo = radeon_bo_unref(mode->bo);
+ mode->bo = radeon_bo_decref(radeon, mode->bo);
}
drmModeFreeResources(resources);
return r;
@@ -146,8 +145,8 @@ void radeon_mode_cleanup(struct radeon *radeon)
radeon->mode.fb_id = 0;
}
if (radeon->mode.bo) {
- radeon_bo_unmap(radeon->mode.bo);
- radeon->mode.bo = radeon_bo_unref(radeon->mode.bo);
+ radeon_bo_unmap(radeon, radeon->mode.bo);
+ radeon->mode.bo = radeon_bo_decref(radeon, radeon->mode.bo);
}
drmDropMaster(radeon->fd);
}
diff --git a/src/r600.h b/src/r600.h
index 177805a..f020d2c 100644
--- a/src/r600.h
+++ b/src/r600.h
@@ -31,7 +31,6 @@
#include <string.h>
#include <errno.h>
#include "xf86drm.h"
-#include "radeon_bo.h"
#include "radeon_drm.h"
#include "r600_winsys.h"
diff --git a/src/r600_ctx.c b/src/r600_ctx.c
index 5f1fdff..c1d588c 100644
--- a/src/r600_ctx.c
+++ b/src/r600_ctx.c
@@ -28,10 +28,15 @@
#include "radeon_priv.h"
#include "r600d.h"
+struct cs_parse {
+ struct radeon_ctx *ctx;
+ struct radeon_draw *draw;
+};
+
struct cs_packet3 {
unsigned op;
char name[64];
- int (*parse)(struct radeon_ctx *ctx);
+ int (*parse)(struct cs_parse *cs);
};
int r600_ctx_next_reloc(struct radeon_ctx *ctx, unsigned *reloc)
@@ -51,15 +56,15 @@ int r600_ctx_next_reloc(struct radeon_ctx *ctx, unsigned *reloc)
return 0;
}
-static int r600_bof_ctx_new_draw(struct radeon_ctx *ctx)
+static int r600_bof_ctx_new_draw(struct cs_parse *cs)
{
struct radeon_draw *draw;
unsigned i, j;
int r;
- draw = ctx->cdraw;
+ draw = cs->draw;
if (draw->state[R600_DB] == NULL) {
- draw->state[R600_DB] = radeon_state(ctx->radeon, R600_DB_TYPE, R600_DB);
+ draw->state[R600_DB] = radeon_state(cs->ctx->radeon, R600_DB_TYPE, R600_DB);
if (draw->state[R600_DB] == NULL)
return -ENOMEM;
}
@@ -68,7 +73,7 @@ static int r600_bof_ctx_new_draw(struct radeon_ctx *ctx)
draw->state[R600_VS_SHADER]->nbo = 2;
draw->state[R600_PS_SHADER]->nbo = 1;
if (draw->state[R600_DB]->bo[0] == NULL) {
- draw->state[R600_DB]->bo[0] = radeon_object_incref(draw->state[R600_CB0]->bo[0]);
+ draw->state[R600_DB]->bo[0] = radeon_bo_incref(cs->ctx->radeon, draw->state[R600_CB0]->bo[0]);
draw->state[R600_DB]->states[R600_DB__DB_DEPTH_SIZE] =
draw->state[R600_CB0]->states[R600_CB0__CB_COLOR0_SIZE];
draw->state[R600_DB]->states[R600_DB__DB_DEPTH_VIEW] =
@@ -77,17 +82,17 @@ static int r600_bof_ctx_new_draw(struct radeon_ctx *ctx)
draw->state[R600_DB]->placement[1] = draw->state[R600_CB0]->placement[1];
}
if (draw->state[R600_CB0]->bo[1] == NULL) {
- draw->state[R600_CB0]->bo[1] = radeon_object_incref(draw->state[R600_CB0]->bo[0]);
+ draw->state[R600_CB0]->bo[1] = radeon_bo_incref(cs->ctx->radeon, draw->state[R600_CB0]->bo[0]);
draw->state[R600_CB0]->placement[2] = draw->state[R600_CB0]->placement[0];
draw->state[R600_CB0]->placement[3] = draw->state[R600_CB0]->placement[1];
}
if (draw->state[R600_CB0]->bo[2] == NULL) {
- draw->state[R600_CB0]->bo[2] = radeon_object_incref(draw->state[R600_CB0]->bo[0]);
+ draw->state[R600_CB0]->bo[2] = radeon_bo_incref(cs->ctx->radeon, draw->state[R600_CB0]->bo[0]);
draw->state[R600_CB0]->placement[4] = draw->state[R600_CB0]->placement[0];
draw->state[R600_CB0]->placement[5] = draw->state[R600_CB0]->placement[1];
}
if (draw->state[R600_VS_SHADER]->bo[1] == NULL) {
- draw->state[R600_VS_SHADER]->bo[1] = radeon_object_incref(draw->state[R600_VS_SHADER]->bo[0]);
+ draw->state[R600_VS_SHADER]->bo[1] = radeon_bo_incref(cs->ctx->radeon, draw->state[R600_VS_SHADER]->bo[0]);
draw->state[R600_VS_SHADER]->placement[2] = draw->state[R600_VS_SHADER]->placement[0];
draw->state[R600_VS_SHADER]->placement[3] = draw->state[R600_VS_SHADER]->placement[1];
}
@@ -96,191 +101,192 @@ static int r600_bof_ctx_new_draw(struct radeon_ctx *ctx)
for (j = 0; j < draw->state[i]->nbo; j++) {
if (draw->state[i]->bo[j] == NULL) {
fprintf(stderr, "%s missing bo %d for state %s\n",
- __func__, j, ctx->radeon->type[i].name);
+ __func__, j, cs->ctx->radeon->type[i].name);
return -EINVAL;
}
}
}
}
- draw = radeon_draw_duplicate(ctx->cdraw);
+ draw = radeon_draw_duplicate(cs->draw);
if (draw == NULL) {
return -ENOMEM;
}
draw->state[R600_DRAW] = radeon_state_decref(draw->state[R600_DRAW]);
- r = radeon_ctx_set_draw_new(ctx, draw);
+ r = radeon_ctx_set_draw_new(cs->ctx, cs->draw);
if (r) {
radeon_draw_decref(draw);
return r;
}
+ cs->draw = draw;
return 0;
}
-static int cs_set_config_reg(struct radeon_ctx *ctx)
+static int cs_set_config_reg(struct cs_parse *cs)
{
unsigned i, count, base;
int r;
- count = PKT_COUNT_G(ctx->pm4[ctx->id]);
- base = (ctx->pm4[ctx->id + 1] + 0x2000) << 2;
+ count = PKT_COUNT_G(cs->ctx->pm4[cs->ctx->id]);
+ base = (cs->ctx->pm4[cs->ctx->id + 1] + 0x2000) << 2;
for (i = 0; i < count; i++, base += 4) {
- r = radeon_ctx_draw_set_reg(ctx, base, ctx->pm4[ctx->id + 2 + i]);
+ r = radeon_draw_ctx_set_reg(cs->draw, cs->ctx, base, cs->ctx->pm4[cs->ctx->id + 2 + i]);
if (r && r != -EINVAL)
return r;
}
return 0;
}
-static int cs_set_context_reg(struct radeon_ctx *ctx)
+static int cs_set_context_reg(struct cs_parse *cs)
{
unsigned i, count, base;
int r;
- count = PKT_COUNT_G(ctx->pm4[ctx->id]);
- base = (ctx->pm4[ctx->id + 1] + 0xA000) << 2;
+ count = PKT_COUNT_G(cs->ctx->pm4[cs->ctx->id]);
+ base = (cs->ctx->pm4[cs->ctx->id + 1] + 0xA000) << 2;
for (i = 0; i < count; i++, base += 4) {
- r = radeon_ctx_draw_set_reg(ctx, base, ctx->pm4[ctx->id + 2 + i]);
+ r = radeon_draw_ctx_set_reg(cs->draw, cs->ctx, base, cs->ctx->pm4[cs->ctx->id + 2 + i]);
if (r && r != -EINVAL)
return r;
}
return 0;
}
-static int cs_draw_auto(struct radeon_ctx *ctx)
+static int cs_draw_auto(struct cs_parse *cs)
{
int r;
- r = radeon_ctx_draw_set_reg(ctx, R_008970_VGT_NUM_INDICES, ctx->pm4[ctx->id + 1]);
+ r = radeon_draw_ctx_set_reg(cs->draw, cs->ctx, R_008970_VGT_NUM_INDICES, cs->ctx->pm4[cs->ctx->id + 1]);
if (r)
return r;
- r = radeon_ctx_draw_set_reg(ctx, R_0287F0_VGT_DRAW_INITIATOR, ctx->pm4[ctx->id + 2]);
+ r = radeon_draw_ctx_set_reg(cs->draw, cs->ctx, R_0287F0_VGT_DRAW_INITIATOR, cs->ctx->pm4[cs->ctx->id + 2]);
if (r)
return r;
- return r600_bof_ctx_new_draw(ctx);
+ return r600_bof_ctx_new_draw(cs);
}
-static int cs_draw_index(struct radeon_ctx *ctx)
+static int cs_draw_index(struct cs_parse *cs)
{
int r;
- r = radeon_ctx_draw_set_reg(ctx, R_0287E4_VGT_DMA_BASE_HI, ctx->pm4[ctx->id + 2]);
+ r = radeon_draw_ctx_set_reg(cs->draw, cs->ctx, R_0287E4_VGT_DMA_BASE_HI, cs->ctx->pm4[cs->ctx->id + 2]);
if (r)
return r;
- r = radeon_ctx_draw_set_reg(ctx, R_0287E8_VGT_DMA_BASE, ctx->pm4[ctx->id + 1]);
+ r = radeon_draw_ctx_set_reg(cs->draw, cs->ctx, R_0287E8_VGT_DMA_BASE, cs->ctx->pm4[cs->ctx->id + 1]);
if (r)
return r;
- r = radeon_ctx_draw_set_reg(ctx, R_008970_VGT_NUM_INDICES, ctx->pm4[ctx->id + 3]);
+ r = radeon_draw_ctx_set_reg(cs->draw, cs->ctx, R_008970_VGT_NUM_INDICES, cs->ctx->pm4[cs->ctx->id + 3]);
if (r)
return r;
- r = radeon_ctx_draw_set_reg(ctx, R_0287F0_VGT_DRAW_INITIATOR, ctx->pm4[ctx->id + 4]);
+ r = radeon_draw_ctx_set_reg(cs->draw, cs->ctx, R_0287F0_VGT_DRAW_INITIATOR, cs->ctx->pm4[cs->ctx->id + 4]);
if (r)
return r;
- ctx->cdraw->state[R600_DRAW]->nbo = 1;
- return r600_bof_ctx_new_draw(ctx);
+ cs->draw->state[R600_DRAW]->nbo = 1;
+ return r600_bof_ctx_new_draw(cs);
}
-static int cs_draw_index_immd(struct radeon_ctx *ctx)
+static int cs_draw_index_immd(struct cs_parse *cs)
{
unsigned i;
int r;
- r = radeon_ctx_draw_set_reg(ctx, R_008970_VGT_NUM_INDICES, ctx->pm4[ctx->id + 1]);
+ r = radeon_draw_ctx_set_reg(cs->draw, cs->ctx, R_008970_VGT_NUM_INDICES, cs->ctx->pm4[cs->ctx->id + 1]);
if (r)
return r;
- r = radeon_ctx_draw_set_reg(ctx, R_0287F0_VGT_DRAW_INITIATOR, ctx->pm4[ctx->id + 2]);
+ r = radeon_draw_ctx_set_reg(cs->draw, cs->ctx, R_0287F0_VGT_DRAW_INITIATOR, cs->ctx->pm4[cs->ctx->id + 2]);
if (r)
return r;
- ctx->cdraw->state[R600_DRAW]->nimmd = PKT_COUNT_G(ctx->pm4[ctx->id]) - 1;
- ctx->cdraw->state[R600_DRAW]->immd = calloc(1, ctx->cdraw->state[R600_DRAW]->nimmd * 4);
- if (ctx->cdraw->state[R600_DRAW]->immd == NULL)
+ cs->draw->state[R600_DRAW]->nimmd = PKT_COUNT_G(cs->ctx->pm4[cs->ctx->id]) - 1;
+ cs->draw->state[R600_DRAW]->immd = calloc(1, cs->draw->state[R600_DRAW]->nimmd * 4);
+ if (cs->draw->state[R600_DRAW]->immd == NULL)
return -ENOMEM;
- for (i = 0; i < ctx->cdraw->state[R600_DRAW]->nimmd; i++) {
- ctx->cdraw->state[R600_DRAW]->immd[i] = ctx->pm4[ctx->id + 3 + i];
+ for (i = 0; i < cs->draw->state[R600_DRAW]->nimmd; i++) {
+ cs->draw->state[R600_DRAW]->immd[i] = cs->ctx->pm4[cs->ctx->id + 3 + i];
}
- return r600_bof_ctx_new_draw(ctx);
+ return r600_bof_ctx_new_draw(cs);
}
-static int cs_set_alu_const(struct radeon_ctx *ctx)
+static int cs_set_alu_const(struct cs_parse *cs)
{
unsigned i, count, offset;
int r;
- count = PKT_COUNT_G(ctx->pm4[ctx->id]);
- offset = (ctx->pm4[ctx->id + 1] << 2) + R_030000_SQ_ALU_CONSTANT0_0;
+ count = PKT_COUNT_G(cs->ctx->pm4[cs->ctx->id]);
+ offset = (cs->ctx->pm4[cs->ctx->id + 1] << 2) + R_030000_SQ_ALU_CONSTANT0_0;
for (i = 0; i < count; i++, offset += 4) {
- r = radeon_ctx_draw_set_reg(ctx, offset, ctx->pm4[ctx->id + 2 + i]);
+ r = radeon_draw_ctx_set_reg(cs->draw, cs->ctx, offset, cs->ctx->pm4[cs->ctx->id + 2 + i]);
if (r)
return r;
}
return 0;
}
-static int cs_set_sampler(struct radeon_ctx *ctx)
+static int cs_set_sampler(struct cs_parse *cs)
{
unsigned i, count, offset;
int r;
- count = PKT_COUNT_G(ctx->pm4[ctx->id]);
- offset = (ctx->pm4[ctx->id + 1] << 2) + R_03C000_SQ_TEX_SAMPLER_WORD0_0;
+ count = PKT_COUNT_G(cs->ctx->pm4[cs->ctx->id]);
+ offset = (cs->ctx->pm4[cs->ctx->id + 1] << 2) + R_03C000_SQ_TEX_SAMPLER_WORD0_0;
for (i = 0; i < count; i++, offset += 4) {
- r = radeon_ctx_draw_set_reg(ctx, offset, ctx->pm4[ctx->id + 2 + i]);
+ r = radeon_draw_ctx_set_reg(cs->draw, cs->ctx, offset, cs->ctx->pm4[cs->ctx->id + 2 + i]);
if (r)
return r;
}
return 0;
}
-static int cs_set_resource(struct radeon_ctx *ctx)
+static int cs_set_resource(struct cs_parse *cs)
{
unsigned i, count, offset, typeid, stateid, id, reloc;
struct radeon_state *state;
- struct radeon_object *bo;
+ struct radeon_bo *bo;
int r;
- count = PKT_COUNT_G(ctx->pm4[ctx->id]);
- offset = (ctx->pm4[ctx->id + 1] << 2) + R_038000_SQ_TEX_RESOURCE_WORD0_0;
+ count = PKT_COUNT_G(cs->ctx->pm4[cs->ctx->id]);
+ offset = (cs->ctx->pm4[cs->ctx->id + 1] << 2) + R_038000_SQ_TEX_RESOURCE_WORD0_0;
for (i = 0; i < count; i++, offset += 4) {
- r = radeon_ctx_draw_set_reg(ctx, offset, ctx->pm4[ctx->id + 2 + i]);
+ r = radeon_draw_ctx_set_reg(cs->draw, cs->ctx, offset, cs->ctx->pm4[cs->ctx->id + 2 + i]);
if (r)
return r;
- radeon_reg_id(ctx->radeon, offset, &typeid, &stateid, &id);
- state = ctx->cdraw->state[stateid];
+ radeon_reg_id(cs->ctx->radeon, offset, &typeid, &stateid, &id);
+ state = cs->draw->state[stateid];
if (id == 6) {
- switch (G_038018_TYPE(ctx->pm4[ctx->id + 2 + i])) {
+ switch (G_038018_TYPE(cs->ctx->pm4[cs->ctx->id + 2 + i])) {
case 2:
- r = radeon_ctx_next_reloc(ctx, &reloc);
+ r = radeon_ctx_next_reloc(cs->ctx, &reloc);
if (r)
return r;
- bo = radeon_ctx_get_bo(ctx, reloc);
+ bo = radeon_ctx_get_bo(cs->ctx, reloc);
if (bo == NULL)
return -ENOMEM;
- radeon_object_decref(state->bo[0]);
- ctx->cdraw->state[stateid]->bo[0] = bo;
- radeon_ctx_get_placement(ctx, reloc, &ctx->cdraw->state[stateid]->placement[0]);
- r = radeon_ctx_next_reloc(ctx, &reloc);
+ radeon_bo_decref(cs->ctx->radeon, state->bo[0]);
+ cs->draw->state[stateid]->bo[0] = bo;
+ radeon_ctx_get_placement(cs->ctx, reloc, &cs->draw->state[stateid]->placement[0]);
+ r = radeon_ctx_next_reloc(cs->ctx, &reloc);
if (r)
return r;
- bo = radeon_ctx_get_bo(ctx, reloc);
+ bo = radeon_ctx_get_bo(cs->ctx, reloc);
if (bo == NULL)
return -ENOMEM;
- radeon_object_decref(state->bo[1]);
- ctx->cdraw->state[stateid]->bo[1] = bo;
- radeon_ctx_get_placement(ctx, reloc, &ctx->cdraw->state[stateid]->placement[2]);
+ radeon_bo_decref(cs->ctx->radeon, state->bo[1]);
+ cs->draw->state[stateid]->bo[1] = bo;
+ radeon_ctx_get_placement(cs->ctx, reloc, &cs->draw->state[stateid]->placement[2]);
state->nbo = 2;
break;
case 3:
- r = radeon_ctx_next_reloc(ctx, &reloc);
+ r = radeon_ctx_next_reloc(cs->ctx, &reloc);
if (r)
return r;
- bo = radeon_ctx_get_bo(ctx, reloc);
+ bo = radeon_ctx_get_bo(cs->ctx, reloc);
if (bo == NULL)
return -ENOMEM;
- radeon_object_decref(state->bo[0]);
- ctx->cdraw->state[stateid]->bo[0] = bo;
- radeon_ctx_get_placement(ctx, reloc, &ctx->cdraw->state[stateid]->placement[0]);
+ radeon_bo_decref(cs->ctx->radeon, state->bo[0]);
+ cs->draw->state[stateid]->bo[0] = bo;
+ radeon_ctx_get_placement(cs->ctx, reloc, &cs->draw->state[stateid]->placement[0]);
state->nbo = 1;
break;
default:
- ctx->cdraw->state[stateid] = radeon_state_decref(state);
+ cs->draw->state[stateid] = radeon_state_decref(state);
break;
}
}
@@ -288,17 +294,17 @@ static int cs_set_resource(struct radeon_ctx *ctx)
return 0;
}
-static int cs_index_type(struct radeon_ctx *ctx)
+static int cs_index_type(struct cs_parse *cs)
{
- return radeon_ctx_draw_set_reg(ctx, R_028A7C_VGT_DMA_INDEX_TYPE, ctx->pm4[ctx->id + 1]);
+ return radeon_draw_ctx_set_reg(cs->draw, cs->ctx, R_028A7C_VGT_DMA_INDEX_TYPE, cs->ctx->pm4[cs->ctx->id + 1]);
}
-static int cs_num_instances(struct radeon_ctx *ctx)
+static int cs_num_instances(struct cs_parse *cs)
{
- return radeon_ctx_draw_set_reg(ctx, R_028A88_VGT_DMA_NUM_INSTANCES, ctx->pm4[ctx->id + 1]);
+ return radeon_draw_ctx_set_reg(cs->draw, cs->ctx, R_028A88_VGT_DMA_NUM_INSTANCES, cs->ctx->pm4[cs->ctx->id + 1]);
}
-static int cs_nop(struct radeon_ctx *ctx)
+static int cs_nop(struct cs_parse *cs)
{
return 0;
}
@@ -344,46 +350,50 @@ struct cs_packet3 r600_packet3[] = {
{0x73, "SURFACE_BASE_UPDATE", &cs_nop},
};
-static int cs_packet3_ctx(struct radeon_ctx *ctx, unsigned op)
+static int cs_packet3_ctx(struct cs_parse *cs, unsigned op)
{
unsigned i;
for (i = 0; i < (sizeof(r600_packet3)/sizeof(r600_packet3[0])); i++) {
if (r600_packet3[i].op == op) {
if (r600_packet3[i].parse)
- return r600_packet3[i].parse(ctx);
+ return r600_packet3[i].parse(cs);
}
}
fprintf(stderr, "%s Unknown packet 3 0x%02X at %d\n",
- __func__, op, ctx->id);
+ __func__, op, cs->ctx->id);
return 0;
}
int r600_ctx_draw(struct radeon_ctx *ctx)
{
+ struct cs_parse cs;
unsigned type, count, index, i, op;
int r;
- ctx->id = 0;
+ cs.ctx = ctx;
+ cs.draw = radeon_draw(ctx->radeon);
+ cs.ctx->id = 0;
do {
- type = PKT_TYPE_G(ctx->pm4[ctx->id]);
- count = PKT_COUNT_G(ctx->pm4[ctx->id]);
- ctx->next_id = ctx->id + count + 2;
+ type = PKT_TYPE_G(cs.ctx->pm4[cs.ctx->id]);
+ count = PKT_COUNT_G(cs.ctx->pm4[cs.ctx->id]);
+ cs.ctx->next_id = cs.ctx->id + count + 2;
switch (type) {
case 2:
count = 0;
break;
case 0:
- index = PKT0_BASE_INDEX_G(ctx->pm4[ctx->id]) << 2;
+ index = PKT0_BASE_INDEX_G(cs.ctx->pm4[cs.ctx->id]) << 2;
for (i = 0; i <= count; i++, index += 4) {
- r = radeon_ctx_draw_set_reg(ctx, index, ctx->pm4[ctx->id + i + 1]);
- if (r)
+ r = radeon_draw_ctx_set_reg(cs.draw, ctx, index, cs.ctx->pm4[cs.ctx->id + i + 1]);
+ if (r) {
return r;
+ }
}
break;
case 3:
- op = PKT3_IT_OPCODE_G(ctx->pm4[ctx->id]);
- r = cs_packet3_ctx(ctx, op);
+ op = PKT3_IT_OPCODE_G(cs.ctx->pm4[cs.ctx->id]);
+ r = cs_packet3_ctx(&cs, op);
if (r) {
fprintf(stderr, "%s error parsing 0x%02X packet3\n", __func__, op);
return r;
@@ -391,16 +401,12 @@ int r600_ctx_draw(struct radeon_ctx *ctx)
break;
default:
fprintf(stderr, "(%s:%d) Unknown packet type %d at %d\n",
- __func__, __LINE__, type, ctx->id);
+ __func__, __LINE__, type, cs.ctx->id);
return -EINVAL;
}
- ctx->id = ctx->next_id;
- } while (ctx->id < ctx->cpm4);
- if (ctx->cdraw->state[R600_DRAW] == NULL) {
- ctx->ndraw--;
- ctx->draw[ctx->ndraw] = radeon_draw_decref(ctx->draw[ctx->ndraw]);
- ctx->cdraw = ctx->draw[ctx->ndraw - 1];
- }
+ cs.ctx->id = cs.ctx->next_id;
+ } while (cs.ctx->id < cs.ctx->cpm4);
+ radeon_draw_decref(cs.draw);
return 0;
}
@@ -468,7 +474,7 @@ int r600_ctx_get_dst_surface(struct radeon_ctx *ctx, struct radeon_surface *dst)
dst->height = dst->height / dst->pitch;
tmp = state->states[R600_CB0__CB_COLOR0_INFO];
dst->bpe = r600_format_bpe(G_0280A0_FORMAT(tmp));
- dst->bo = state->bo[0]->bo;
+ dst->bo = state->bo[0];
if ((dst->height * dst->pitch * dst->bpe) >= state->bo[0]->size) {
dst->height = state->bo[0]->size / (dst->pitch * dst->bpe);
}
diff --git a/src/radeon.c b/src/radeon.c
index 2873fa2..090910f 100644
--- a/src/radeon.c
+++ b/src/radeon.c
@@ -22,9 +22,8 @@
#include <string.h>
#include <errno.h>
#include "xf86drm.h"
-#include "radeon_bo_gem.h"
-#include "radeon_cs_gem.h"
#include "radeon_priv.h"
+#include "radeon_drm.h"
#include "r600d.h"
int radeon_get_device(struct radeon *radeon)
@@ -68,16 +67,6 @@ struct radeon *radeon_new(int fd, unsigned device)
fprintf(stderr, "Unknown chipset 0x%04X\n", radeon->device);
return radeon_decref(radeon);
}
- radeon->csm = radeon_cs_manager_gem_ctor(radeon->fd);
- if (radeon->csm == NULL) {
- fprintf(stderr, "Failed to create CS manager\n");
- return radeon_decref(radeon);
- }
- radeon->bom = radeon_bo_manager_gem_ctor(radeon->fd);
- if (radeon->bom == NULL) {
- fprintf(stderr, "Failed to create BO manager\n");
- return radeon_decref(radeon);
- }
switch (radeon->family) {
case CHIP_R600:
case CHIP_RV610:
@@ -160,53 +149,16 @@ struct radeon *radeon_decref(struct radeon *radeon)
if (radeon->mmio)
pci_device_unmap_range(radeon->dev, radeon->mmio, radeon->mmio_size);
radeon_mode_cleanup(radeon);
- radeon_bo_manager_gem_dtor(radeon->bom);
- radeon_cs_manager_gem_dtor(radeon->csm);
drmClose(radeon->fd);
free(radeon);
return NULL;
}
-void memset_bo(struct radeon_bo *bo, u32 value)
-{
- u32 *ptr;
- int r;
-
- r = radeon_bo_map(bo, 1);
- if (r) {
- fprintf(stderr, "Failed to map buffer\n");
- perror(NULL);
- return;
- }
- ptr = (u32*)bo->ptr;
- for (r = 0; r < (bo->size / 4); r++)
- ptr[r] = value;
- radeon_bo_unmap(bo);
-}
-
-void memcpy_bo(struct radeon_bo *bo, u32 *src, u32 size)
-{
- u32 *ptr, tmp;
- int r;
-
- r = radeon_bo_map(bo, 1);
- if (r) {
- fprintf(stderr, "Failed to map buffer\n");
- perror(NULL);
- return;
- }
- ptr = (u32*)bo->ptr;
- for (r = 0; r < size; r++)
- ptr[r] = src[r];
- for (r = 0; r < size; r++)
- ptr[r] = src[r];
- for (r = 0, tmp = 0; r < size; r++)
- tmp += ptr[r];
- radeon_bo_unmap(bo);
-}
-
-void radeon_blit(struct radeon_surface *dst, struct radeon_surface *src,
- unsigned sx, unsigned sy, unsigned dx, unsigned dy,
+void radeon_blit(struct radeon *radeon,
+ struct radeon_surface *dst,
+ struct radeon_surface *src,
+ unsigned sx, unsigned sy,
+ unsigned dx, unsigned dy,
unsigned w, unsigned h)
{
unsigned y;
@@ -226,12 +178,12 @@ void radeon_blit(struct radeon_surface *dst, struct radeon_surface *src,
h = dst->height - dy;
if (!w || !h)
return;
- if (radeon_bo_map(dst->bo, 1))
+ if (radeon_bo_map(radeon, dst->bo))
return;
- if (radeon_bo_map(src->bo, 0))
+ if (radeon_bo_map(radeon, src->bo))
return;
- sptr = src->bo->ptr;
- dptr = dst->bo->ptr;
+ sptr = src->bo->data;
+ dptr = dst->bo->data;
sptr = &sptr[(sy * src->pitch + sx) * src->bpe];
dptr = &dptr[(dy * dst->pitch + dx) * dst->bpe];
for (y = 0; y < h; y++) {
@@ -239,34 +191,8 @@ void radeon_blit(struct radeon_surface *dst, struct radeon_surface *src,
dptr += dst->pitch * dst->bpe;
sptr += src->pitch * src->bpe;
}
- radeon_bo_unmap(dst->bo);
- radeon_bo_unmap(src->bo);
-}
-
-int radeon_flush(struct radeon *radeon)
-{
- struct radeon_ctx *ctx = radeon->ctx;
- unsigned i;
- int r;
-
- free(ctx->pm4);
- ctx->pm4 = malloc(ctx->cpm4 * 4);
- if (ctx->pm4 == NULL)
- return -EINVAL;
- for (i = 0, ctx->id = 0; i < ctx->nstate; i++) {
- r = radeon_ctx_state_schedule(ctx, ctx->state[i]);
- if (r)
- return r;
- }
- if (ctx->id != ctx->cpm4) {
- fprintf(stderr, "%s miss predicted pm4 size %d for %d\n",
- __func__, ctx->cpm4, ctx->id);
- return -EINVAL;
- }
- r = radeon_ctx_submit(ctx);
- radeon_ctx_destroy(ctx);
- radeon->ctx = radeon_ctx(radeon, 0);
- return r;
+ radeon_bo_unmap(radeon, dst->bo);
+ radeon_bo_unmap(radeon, src->bo);
}
int radeon_reg_id(struct radeon *radeon, unsigned offset, unsigned *typeid, unsigned *stateid, unsigned *id)
@@ -313,6 +239,7 @@ unsigned radeon_type_from_id(struct radeon *radeon, unsigned id)
return -1;
}
+#if 0
int radeon_schedule_draw(struct radeon *radeon, struct radeon_draw *draw)
{
struct radeon_ctx *ctx = radeon->ctx;
@@ -323,7 +250,7 @@ int radeon_schedule_draw(struct radeon *radeon, struct radeon_draw *draw)
int r = 0;
if (ctx == NULL) {
- ctx = radeon_ctx(radeon, 0);
+ ctx = radeon_ctx(radeon);
if (ctx == NULL)
return -ENOMEM;
radeon->ctx = ctx;
@@ -347,10 +274,7 @@ reprocess:
if (nstate) {
if (pdraw && pdraw->state[i]) {
ostate = pdraw->state[i];
- if (ostate->pm4_crc == nstate->pm4_crc) {
-// ctx->state[cstate++] = nstate;
-// cpm4 += nstate->cpm4;
- } else {
+ if (ostate->pm4_crc != nstate->pm4_crc) {
ctx->state[cstate++] = nstate;
cpm4 += nstate->cpm4;
}
@@ -382,3 +306,4 @@ reprocess:
out_err:
return r;
}
+#endif
diff --git a/src/radeon.h b/src/radeon.h
index 806d85c..a749564 100644
--- a/src/radeon.h
+++ b/src/radeon.h
@@ -17,15 +17,17 @@
#ifndef RADEON_H
#define RADEON_H
-#include "radeon_bo.h"
-
#define RADEON_CTX_MAX_PM4 (64 * 1024 / 4)
+#include <stdint.h>
+
typedef uint64_t u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
+struct radeon;
+
enum radeon_family {
CHIP_UNKNOWN,
CHIP_R100,
@@ -78,18 +80,21 @@ enum radeon_family {
/*
* radeon object functions
*/
-struct radeon_object {
+struct radeon_bo {
unsigned refcount;
unsigned handle;
unsigned size;
- unsigned *data;
- struct radeon_bo *bo;
+ unsigned alignment;
+ unsigned map_count;
+ void *data;
};
-
-extern struct radeon_object *radeon_object(struct radeon_bo *bo, unsigned handle,
- unsigned size, void *ptr);
-extern struct radeon_object *radeon_object_incref(struct radeon_object *object);
-extern struct radeon_object *radeon_object_decref(struct radeon_object *object);
+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);
/*
* states functions
@@ -108,7 +113,7 @@ struct radeon_state {
u32 nimmd;
u32 *immd;
unsigned nbo;
- struct radeon_object *bo[4];
+ struct radeon_bo *bo[4];
unsigned nreloc;
unsigned reloc_pm4_id[8];
unsigned reloc_bo_id[8];
@@ -138,7 +143,12 @@ extern struct radeon_draw *radeon_draw_decref(struct radeon_draw *draw);
extern int radeon_draw_set(struct radeon_draw *draw, struct radeon_state *state);
extern int radeon_draw_check(struct radeon_draw *draw);
-int radeon_flush(struct radeon *radeon);
+extern struct radeon_ctx *radeon_ctx_decref(struct radeon_ctx *ctx);
+extern struct radeon_ctx *radeon_ctx_incref(struct radeon_ctx *ctx);
+extern int radeon_ctx_set_draw(struct radeon_ctx *ctx, struct radeon_draw *draw);
+extern int radeon_ctx_set_draw_new(struct radeon_ctx *ctx, struct radeon_draw *draw);
+extern int radeon_ctx_pm4(struct radeon_ctx *ctx);
+int radeon_ctx_submit(struct radeon_ctx *ctx);
/*
* R600/R700
diff --git a/src/radeon_bo.c b/src/radeon_bo.c
new file mode 100644
index 0000000..32134b6
--- /dev/null
+++ b/src/radeon_bo.c
@@ -0,0 +1,170 @@
+/*
+ * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
+ *
+ * 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
+ * on 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
+ * THE AUTHOR(S) AND/OR THEIR 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:
+ * Jerome Glisse
+ */
+#define _FILE_OFFSET_BITS 64
+#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include "radeon_priv.h"
+#include "xf86drm.h"
+#include "radeon_drm.h"
+
+struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle,
+ unsigned size, unsigned alignment, void *ptr)
+{
+ struct radeon_bo *bo;
+ int r;
+
+ bo = calloc(1, sizeof(*bo));
+ if (bo == NULL) {
+ return NULL;
+ }
+ bo->size = size;
+ bo->handle = handle;
+ bo->refcount = 1;
+ bo->alignment = alignment;
+
+ if (handle) {
+ struct drm_gem_open open_arg;
+
+ memset(&open_arg, 0, sizeof(open_arg));
+ open_arg.name = handle;
+ r = drmIoctl(radeon->fd, DRM_IOCTL_GEM_OPEN, &open_arg);
+ if (r != 0) {
+ free(bo);
+ return NULL;
+ }
+ bo->handle = open_arg.handle;
+ } else {
+ struct drm_radeon_gem_create args;
+
+ args.size = size;
+ args.alignment = alignment;
+ args.initial_domain = RADEON_GEM_DOMAIN_CPU;
+ args.flags = 0;
+ args.handle = 0;
+ r = drmCommandWriteRead(radeon->fd, DRM_RADEON_GEM_CREATE,
+ &args, sizeof(args));
+ bo->handle = args.handle;
+ if (r) {
+ fprintf(stderr, "Failed to allocate :\n");
+ fprintf(stderr, " size : %d bytes\n", size);
+ fprintf(stderr, " alignment : %d bytes\n", alignment);
+ free(bo);
+ return NULL;
+ }
+ }
+ 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);
+ }
+ memcpy(bo->data, ptr, size);
+ radeon_bo_unmap(radeon, bo);
+ }
+ return bo;
+}
+
+int radeon_bo_map(struct radeon *radeon, struct radeon_bo *bo)
+{
+ struct drm_radeon_gem_mmap args;
+ void *ptr;
+ int r;
+
+ if (bo->map_count++ != 0) {
+ return 0;
+ }
+ /* Zero out args to make valgrind happy */
+ memset(&args, 0, sizeof(args));
+ args.handle = bo->handle;
+ args.offset = 0;
+ args.size = (uint64_t)bo->size;
+ r = drmCommandWriteRead(radeon->fd, DRM_RADEON_GEM_MMAP,
+ &args, sizeof(args));
+ if (r) {
+ fprintf(stderr, "error mapping %p 0x%08X (error = %d)\n",
+ bo, bo->handle, r);
+ return r;
+ }
+ ptr = mmap(0, args.size, PROT_READ|PROT_WRITE, MAP_SHARED, radeon->fd, args.addr_ptr);
+ if (ptr == MAP_FAILED) {
+ fprintf(stderr, "%s failed to map bo\n", __func__);
+ return -errno;
+ }
+ bo->data = ptr;
+ return 0;
+}
+
+void radeon_bo_unmap(struct radeon *radeon, struct radeon_bo *bo)
+{
+ if (--bo->map_count > 0) {
+ return;
+ }
+ munmap(bo->data, bo->size);
+ 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)
+{
+ struct drm_gem_close args;
+
+ if (bo == NULL)
+ return NULL;
+ if (--bo->refcount > 0) {
+ return NULL;
+ }
+
+ 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;
+}
+
+int radeon_bo_wait(struct radeon *radeon, struct radeon_bo *bo)
+{
+ struct drm_radeon_gem_wait_idle args;
+ int ret;
+
+ /* Zero out args to make valgrind happy */
+ memset(&args, 0, sizeof(args));
+ args.handle = bo->handle;
+ do {
+ ret = drmCommandWriteRead(radeon->fd, DRM_RADEON_GEM_WAIT_IDLE,
+ &args, sizeof(args));
+ } while (ret == -EBUSY);
+ return ret;
+}
diff --git a/src/radeon_bof.c b/src/radeon_bof.c
index 9f1e7ea..fca7ff8 100644
--- a/src/radeon_bof.c
+++ b/src/radeon_bof.c
@@ -27,17 +27,25 @@
#include <jansson.h>
#include "radeon_priv.h"
-struct radeon_ctx *radeon_ctx_load_bof(const char *filename)
+struct bof_handle_match {
+ unsigned bhandle;
+ unsigned nhandle;
+};
+
+struct radeon_ctx *radeon_ctx_load_bof(struct radeon *radeon, const char *filename)
{
struct radeon_ctx *ctx;
- unsigned i, device, size, handle;
- struct radeon_object *object;
+ unsigned i, device, size, handle, j;
+ struct radeon_bo *object;
bof_t *tmp, *bo, *array;
bof_t *bctx;
+ struct radeon_cs_reloc *reloc;
+ struct bof_handle_match *hmatch = NULL;
int r;
bctx = bof_load_file(filename);
if (bctx == NULL) {
+ fprintf(stderr, "%s failed to load %s\n", __func__, filename);
return NULL;
}
/* device */
@@ -47,8 +55,9 @@ struct radeon_ctx *radeon_ctx_load_bof(const char *filename)
goto out_err;
}
device = bof_int32_value(tmp);
- ctx = radeon_ctx(NULL, device);
+ ctx = radeon_ctx(radeon);
if (ctx == NULL) {
+ fprintf(stderr, "%s failed to create context\n", __func__);
goto out_err;
}
/* pm4 */
@@ -69,11 +78,13 @@ struct radeon_ctx *radeon_ctx_load_bof(const char *filename)
r = -EINVAL;
goto out_err;
}
- ctx->reloc_ndw = bof_blob_size(tmp) / 4;
+ ctx->nreloc = bof_blob_size(tmp) / sizeof(struct radeon_cs_reloc);
ctx->reloc = copy_object(bof_blob_value(tmp), bof_blob_size(tmp));
if (ctx->reloc == NULL) {
+ fprintf(stderr, "%s failed to allocate reloc\n", __func__);
goto out_err;
}
+ reloc = ctx->reloc;
/* bo */
array = bof_object_get(bctx, "bo");
if (array == NULL) {
@@ -81,6 +92,13 @@ struct radeon_ctx *radeon_ctx_load_bof(const char *filename)
r = -EINVAL;
goto out_err;
}
+ if (bof_array_size(array) < ctx->nreloc)
+ ctx->nreloc = bof_array_size(array);
+ hmatch = calloc(2, sizeof(struct bof_handle_match) * bof_array_size(array));
+ if (hmatch == NULL) {
+ r = -ENOMEM;
+ goto out_err;
+ }
for (i = 0; i < bof_array_size(array); i++) {
bo = bof_array_get(array, i);
if (bo == NULL) {
@@ -104,17 +122,29 @@ struct radeon_ctx *radeon_ctx_load_bof(const char *filename)
fprintf(stderr, "can't get %d bo data from %p of %p\n", i, bo, array);
goto out_err;
}
- object = radeon_object(NULL, handle, size,
- bof_blob_value(tmp));
- if (object == NULL)
+ object = radeon_bo(radeon, 0, size, 4096, bof_blob_value(tmp));
+ if (object == NULL) {
+ fprintf(stderr, "%s failed to allocate bo (%d)\n", __func__, size);
goto out_err;
- if (radeon_ctx_set_object_new(ctx, object, -1))
+ }
+ if (radeon_ctx_set_bo_new(ctx, object))
goto out_err;
+ hmatch[i].bhandle = handle;
+ hmatch[i].nhandle = object->handle;
+ }
+ for (i = 0; i < ctx->nreloc; i++) {
+ for (j = 0; j < ctx->nbo; j++) {
+ if (ctx->reloc[i].handle == hmatch[j].bhandle) {
+ ctx->reloc[i].handle = hmatch[j].nhandle;
+ break;
+ }
+ }
}
+ free(hmatch);
bof_decref(bctx);
return ctx;
out_err:
+ free(hmatch);
bof_decref(bctx);
- radeon_ctx_destroy(ctx);
- return NULL;
+ return radeon_ctx_decref(ctx);
}
diff --git a/src/radeon_ctx.c b/src/radeon_ctx.c
index 4e0ba56..1188b09 100644
--- a/src/radeon_ctx.c
+++ b/src/radeon_ctx.c
@@ -24,56 +24,33 @@
* Jerome Glisse
*/
#include <stdlib.h>
+#include <string.h>
#include "radeon_priv.h"
+#include "radeon_drm.h"
-#pragma pack(1)
-struct cs_reloc_gem {
- uint32_t handle;
- uint32_t read_domain;
- uint32_t write_domain;
- uint32_t flags;
-};
-#pragma pack()
-
-int radeon_ctx_set_object_new(struct radeon_ctx *ctx,
- struct radeon_object *bo,
- int id)
+int radeon_ctx_set_bo_new(struct radeon_ctx *ctx, struct radeon_bo *bo)
{
void *ptr;
- ptr = realloc(ctx->bo, sizeof(struct radeon_ctx_bo) * (ctx->nbo + 1));
+ ptr = realloc(ctx->bo, sizeof(struct radeon_bo) * (ctx->nbo + 1));
if (ptr == NULL) {
return -ENOMEM;
}
ctx->bo = ptr;
- ctx->bo[ctx->nbo].bo = bo;
- ctx->bo[ctx->nbo].id = id;
+ ctx->bo[ctx->nbo] = bo;
ctx->nbo++;
return 0;
}
-struct radeon_object *radeon_ctx_get_object(struct radeon_ctx *ctx, unsigned handle)
-{
- unsigned i;
-
- for (i = 0; i < ctx->nbo; i++) {
- if (ctx->bo[i].bo->handle == handle) {
- return radeon_object_incref(ctx->bo[i].bo);
- }
- }
- return NULL;
-}
-
-struct radeon_object *radeon_ctx_get_bo(struct radeon_ctx *ctx, unsigned reloc)
+struct radeon_bo *radeon_ctx_get_bo(struct radeon_ctx *ctx, unsigned reloc)
{
- struct cs_reloc_gem *greloc;
+ struct radeon_cs_reloc *greloc;
unsigned i;
- greloc = (struct cs_reloc_gem *)&ctx->reloc[reloc];
+ greloc = (void *)(((u8 *)ctx->reloc) + reloc * 4);
for (i = 0; i < ctx->nbo; i++) {
- if (ctx->bo[i].bo->handle == greloc->handle) {
- ctx->bo[i].id = reloc;
- return radeon_object_incref(ctx->bo[i].bo);
+ if (ctx->bo[i]->handle == greloc->handle) {
+ return radeon_bo_incref(ctx->radeon, ctx->bo[i]);
}
}
fprintf(stderr, "%s no bo for reloc[%d 0x%08X] %d\n", __func__, reloc, greloc->handle, ctx->nbo);
@@ -82,14 +59,14 @@ struct radeon_object *radeon_ctx_get_bo(struct radeon_ctx *ctx, unsigned reloc)
void radeon_ctx_get_placement(struct radeon_ctx *ctx, unsigned reloc, u32 *placement)
{
- struct cs_reloc_gem *greloc;
+ struct radeon_cs_reloc *greloc;
unsigned i;
placement[0] = 0;
placement[1] = 0;
- greloc = (struct cs_reloc_gem *)&ctx->reloc[reloc];
+ greloc = (void *)(((u8 *)ctx->reloc) + reloc * 4);
for (i = 0; i < ctx->nbo; i++) {
- if (ctx->bo[i].bo->handle == greloc->handle) {
+ if (ctx->bo[i]->handle == greloc->handle) {
placement[0] = greloc->read_domain | greloc->write_domain;
placement[1] = placement[0];
return;
@@ -97,45 +74,52 @@ void radeon_ctx_get_placement(struct radeon_ctx *ctx, unsigned reloc, u32 *place
}
}
-struct radeon_ctx *radeon_ctx(struct radeon *radeon, unsigned device)
+struct radeon_ctx *radeon_ctx(struct radeon *radeon)
{
struct radeon_ctx *ctx;
+ if (radeon == NULL)
+ return NULL;
ctx = calloc(1, sizeof(*ctx));
if (ctx == NULL)
return NULL;
ctx->radeon = radeon_incref(radeon);
- if (radeon == NULL) {
- ctx->radeon = radeon_new(-1, device);
- if (ctx->radeon == NULL) {
- free(ctx);
- return NULL;
- }
- }
return ctx;
}
-void radeon_ctx_destroy(struct radeon_ctx *ctx)
+struct radeon_ctx *radeon_ctx_incref(struct radeon_ctx *ctx)
+{
+ ctx->refcount++;
+ return ctx;
+}
+
+struct radeon_ctx *radeon_ctx_decref(struct radeon_ctx *ctx)
{
unsigned i;
+ if (ctx == NULL)
+ return NULL;
+ if (--ctx->refcount > 0) {
+ return NULL;
+ }
+
for (i = 0; i < ctx->ndraw; i++) {
ctx->draw[i] = radeon_draw_decref(ctx->draw[i]);
}
for (i = 0; i < ctx->nbo; i++) {
- ctx->bo[i].bo = radeon_object_decref(ctx->bo[i].bo);
+ ctx->bo[i] = radeon_bo_decref(ctx->radeon, ctx->bo[i]);
}
- radeon_decref(ctx->radeon);
+ ctx->radeon = radeon_decref(ctx->radeon);
free(ctx->draw);
free(ctx->bo);
free(ctx->pm4);
free(ctx->reloc);
memset(ctx, 0, sizeof(*ctx));
free(ctx);
+ return NULL;
}
-static int radeon_ctx_state_bo(struct radeon_ctx *ctx,
- struct radeon_state *state)
+static int radeon_ctx_state_bo(struct radeon_ctx *ctx, struct radeon_state *state)
{
unsigned i, j;
int r;
@@ -144,12 +128,12 @@ static int radeon_ctx_state_bo(struct radeon_ctx *ctx,
return 0;
for (i = 0; i < state->nbo; i++) {
for (j = 0; j < ctx->nbo; j++) {
- if (state->bo[i] == ctx->bo[j].bo)
+ if (state->bo[i] == ctx->bo[j])
break;
}
if (j == ctx->nbo) {
- radeon_object_incref(state->bo[i]);
- r = radeon_ctx_set_object_new(ctx, state->bo[i], -1);
+ radeon_bo_incref(ctx->radeon, state->bo[i]);
+ r = radeon_ctx_set_bo_new(ctx, state->bo[i]);
if (r)
return r;
}
@@ -157,95 +141,87 @@ static int radeon_ctx_state_bo(struct radeon_ctx *ctx,
return 0;
}
-int radeon_ctx_set_draw_new(struct radeon_ctx *ctx, struct radeon_draw *draw)
-{
- struct radeon_draw **ndraw;
- unsigned i;
- int r;
-
- ndraw = realloc(ctx->draw, sizeof(void*) * (ctx->ndraw + 1));
- if (ndraw == NULL)
- return -ENOMEM;
- ctx->draw = ndraw;
- for (i = 0; i < draw->nstate; i++) {
- r = radeon_ctx_state_bo(ctx, draw->state[i]);
- if (r)
- return r;
- }
- ctx->draw[ctx->ndraw++] = draw;
- ctx->cdraw = draw;
- return 0;
-}
-
-struct radeon_object *radeon_object(struct radeon_bo *bo, unsigned handle,
- unsigned size, void *ptr)
-{
- struct radeon_object *object;
-
- object = calloc(1, sizeof(*object));
- if (object == NULL)
- return NULL;
- object->data = calloc(1, size);
- if (object->data == NULL) {
- return NULL;
- }
- object->size = size;
- object->handle = handle;
- object->bo = bo;
- object->refcount = 1;
- if (ptr)
- memcpy(object->data, ptr, size);
- return object;
-}
-
-struct radeon_object *radeon_object_incref(struct radeon_object *object)
-{
- object->refcount++;
- return object;
-}
-
-struct radeon_object *radeon_object_decref(struct radeon_object *object)
+static void radeon_ctx_dump_bof(struct radeon_ctx *ctx)
{
- if (object == NULL)
- return NULL;
- if (--object->refcount > 0) {
- return NULL;
- }
- free(object->data);
- object->data = NULL;
- object->bo = radeon_bo_unref(object->bo);
- free(object);
- return NULL;
-}
-
-int radeon_ctx_allocate_bo(struct radeon_ctx *ctx)
-{
- struct radeon *radeon = ctx->radeon;
- struct radeon_object *bo;
- struct cs_reloc_gem *greloc;
+ bof_t *bcs, *blob, *array, *bo, *size, *handle, *device_id, *root;
+ char tmp[256];
unsigned i;
+ root = device_id = bcs = blob = array = bo = size = handle = NULL;
+ root = bof_object();
+ if (root == NULL)
+ goto out_err;
+ device_id = bof_int32(ctx->radeon->device);
+ if (device_id == NULL)
+ return;
+ if (bof_object_set(root, "device_id", device_id))
+ goto out_err;
+ bof_decref(device_id);
+ device_id = NULL;
+ /* dump relocs */
+ blob = bof_blob(ctx->nreloc * 16, ctx->reloc);
+ if (blob == NULL)
+ goto out_err;
+ if (bof_object_set(root, "reloc", blob))
+ goto out_err;
+ bof_decref(blob);
+ blob = NULL;
+ /* dump cs */
+ blob = bof_blob(ctx->cpm4 * 4, ctx->pm4);
+ if (blob == NULL)
+ goto out_err;
+ if (bof_object_set(root, "pm4", blob))
+ goto out_err;
+ bof_decref(blob);
+ blob = NULL;
+ /* dump bo */
+ array = bof_array();
+ if (array == NULL)
+ goto out_err;
for (i = 0; i < ctx->nbo; i++) {
- bo = ctx->bo[i].bo;
- bo->bo = radeon_bo_open(radeon->bom, 0, bo->size, 0,
- RADEON_GEM_DOMAIN_VRAM | RADEON_GEM_DOMAIN_GTT, 0);
- if (bo->bo == NULL) {
- return -ENOMEM;
- }
- radeon_bo_map(bo->bo, 1);
- memcpy(bo->bo->ptr, bo->data, bo->size);
- radeon_bo_unmap(bo->bo);
- }
- for (i = 0; i < ctx->nbo; i++) {
- if (ctx->bo[i].id >= 0) {
- greloc = (struct cs_reloc_gem *)&ctx->reloc[ctx->bo[i].id];
- greloc->handle = ctx->bo[i].bo->bo->handle;
- }
- }
- for (i = 0; i < ctx->nbo; i++) {
- ctx->bo[i].bo->handle = ctx->bo[i].bo->bo->handle;
+ bo = bof_object();
+ if (bo == NULL)
+ goto out_err;
+ size = bof_int32(ctx->bo[i]->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);
+ 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]);
+ if (blob == NULL)
+ goto out_err;
+ if (bof_object_set(bo, "data", blob))
+ goto out_err;
+ bof_decref(blob);
+ blob = NULL;
+ if (bof_array_append(array, bo))
+ goto out_err;
+ bof_decref(bo);
+ bo = NULL;
}
- return 0;
+ if (bof_object_set(root, "bo", array))
+ goto out_err;
+ sprintf(tmp, "d-0x%04X.bof", ctx->radeon->device);
+ bof_dump_file(root, tmp);
+out_err:
+ bof_decref(blob);
+ bof_decref(array);
+ bof_decref(bo);
+ bof_decref(size);
+ bof_decref(handle);
+ bof_decref(device_id);
+ bof_decref(root);
}
int radeon_ctx_submit(struct radeon_ctx *ctx)
@@ -256,7 +232,6 @@ int radeon_ctx_submit(struct radeon_ctx *ctx)
int r = 0;
#if 0
- printf("reloc %d %d %d pm4 %d\n", ctx->reloc_ndw, ctx->reloc_ndw / 4, ctx->nbo, ctx->cpm4);
for (r = 0; r < ctx->cpm4; r++) {
fprintf(stderr, "0x%08X\n", ctx->pm4[r]);
}
@@ -267,7 +242,7 @@ int radeon_ctx_submit(struct radeon_ctx *ctx)
chunks[0].length_dw = ctx->cpm4;
chunks[0].chunk_data = (uint64_t)(uintptr_t)ctx->pm4;
chunks[1].chunk_id = RADEON_CHUNK_ID_RELOCS;
- chunks[1].length_dw = ctx->reloc_ndw;
+ chunks[1].length_dw = ctx->nreloc * sizeof(struct radeon_cs_reloc) / 4;
chunks[1].chunk_data = (uint64_t)(uintptr_t)ctx->reloc;
chunk_array[0] = (uint64_t)(uintptr_t)&chunks[0];
chunk_array[1] = (uint64_t)(uintptr_t)&chunks[1];
@@ -283,39 +258,28 @@ int radeon_ctx_draw(struct radeon_ctx *ctx)
return ctx->radeon->asic->ctx_draw(ctx);
}
-int radeon_ctx_reloc(struct radeon_ctx *ctx, struct radeon_object *bo,
+int radeon_ctx_reloc(struct radeon_ctx *ctx, struct radeon_bo *bo,
unsigned id, unsigned *placement)
{
unsigned i;
- void *ptr;
- struct cs_reloc_gem *greloc;
+ struct radeon_cs_reloc *ptr;
- for (i = 0; i < ctx->nbo; i++) {
- if (ctx->bo[i].bo == bo) {
- if (ctx->bo[i].id >= 0) {
- ctx->pm4[id] = ctx->bo[i].id;
- return 0;
- }
- break;
+ for (i = 0; i < ctx->nreloc; i++) {
+ if (ctx->reloc[i].handle == bo->handle) {
+ ctx->pm4[id] = i * sizeof(struct radeon_cs_reloc) / 4;
+ return 0;
}
}
- if (i == ctx->nbo) {
- fprintf(stderr, "%s bo %p 0x%08X unknown to context\n",
- __func__, bo, bo->handle);
- return -EINVAL;
- }
- ptr = realloc(ctx->reloc, sizeof(struct cs_reloc_gem) + ctx->reloc_ndw *4);
+ ptr = realloc(ctx->reloc, sizeof(struct radeon_cs_reloc) * (ctx->nreloc + 1));
if (ptr == NULL)
return -ENOMEM;
ctx->reloc = ptr;
- greloc = (struct cs_reloc_gem *)&ctx->reloc[ctx->reloc_ndw];
- greloc->handle = bo->bo->handle;
- greloc->read_domain = placement[0] | placement [1];
- greloc->write_domain = placement[0] | placement [1];
- greloc->flags = 0;
- ctx->bo[i].id = ctx->reloc_ndw;
- ctx->pm4[id] = ctx->bo[i].id;
- ctx->reloc_ndw += sizeof(struct cs_reloc_gem) / 4;
+ ptr[ctx->nreloc].handle = bo->handle;
+ ptr[ctx->nreloc].read_domain = placement[0] | placement [1];
+ ptr[ctx->nreloc].write_domain = placement[0] | placement [1];
+ ptr[ctx->nreloc].flags = 0;
+ ctx->pm4[id] = ctx->nreloc * sizeof(struct radeon_cs_reloc) / 4;
+ ctx->nreloc++;
return 0;
}
@@ -341,73 +305,113 @@ int radeon_ctx_state_schedule(struct radeon_ctx *ctx, struct radeon_state *state
ctx->id += state->cpm4;
return 0;
}
-#if 0
-int radeon_ctx_draw_schedule(struct radeon_ctx *ctx, unsigned id)
+
+void *copy_object(void *ptr, unsigned size)
{
- struct radeon_draw *draw;
- unsigned i;
- int r;
+ void *copy;
- draw = ctx->draw[id];
- for (i = 0; i < draw->nstate; i++) {
- r = radeon_ctx_state_schedule(ctx, draw->state[i]);
- if (r)
- return r;
- }
- return 0;
+ copy = calloc(1, size);
+ if (copy == NULL)
+ return NULL;
+ memcpy(copy, ptr, size);
+ return copy;
}
-#endif
-int radeon_ctx_draw_set_reg(struct radeon_ctx *ctx, unsigned offset, u32 value)
+
+int radeon_ctx_set_draw_new(struct radeon_ctx *ctx, struct radeon_draw *draw)
{
- struct radeon_draw *draw;
- struct radeon *radeon = ctx->radeon;
- struct radeon_object *bo;
- unsigned id, stateid, typeid, boid, reloc;
- int r;
+ struct radeon_draw *pdraw = NULL;
+ struct radeon_draw **ndraw;
+ struct radeon_state *nstate, *ostate;
+ unsigned cpm4, i, cstate;
+ void *tmp;
+ int r = 0;
- draw = ctx->cdraw;
- if (draw == NULL) {
- draw = radeon_draw(ctx->radeon);
- if (draw == NULL)
- return -ENOMEM;
- r = radeon_ctx_set_draw_new(ctx, draw);
- if (r) {
- radeon_draw_decref(draw);
+ ndraw = realloc(ctx->draw, sizeof(void*) * (ctx->ndraw + 1));
+ if (ndraw == NULL)
+ return -ENOMEM;
+ ctx->draw = ndraw;
+ for (i = 0; i < draw->nstate; i++) {
+ r = radeon_ctx_state_bo(ctx, draw->state[i]);
+ if (r)
return r;
- }
}
- r = radeon_reg_id(radeon, offset, &typeid, &stateid, &id);
- if (r) {
+ r = radeon_draw_check(draw);
+ if (r)
return r;
+ if (draw->cpm4 >= RADEON_CTX_MAX_PM4) {
+ fprintf(stderr, "%s single draw too big %d, max %d\n",
+ __func__, draw->cpm4, RADEON_CTX_MAX_PM4);
+ return -EINVAL;
}
- if (draw->state[stateid] == NULL) {
- draw->state[stateid] = radeon_state(radeon, typeid, stateid);
- if (draw->state[stateid] == NULL)
- return -ENOMEM;
- };
- draw->state[stateid]->states[id] = value;
- if (radeon->type[typeid].regs[id].need_reloc) {
- r = radeon_ctx_next_reloc(ctx, &reloc);
- if (r)
- return r;
- bo = radeon_ctx_get_bo(ctx, reloc);
- if (bo == NULL)
- return -ENOMEM;
- boid = radeon->type[typeid].regs[id].bo_id;
- radeon_object_decref(draw->state[stateid]->bo[boid]);
- draw->state[stateid]->bo[boid] = bo;
- radeon_ctx_get_placement(ctx, reloc, &draw->state[stateid]->placement[boid * 2]);
+ tmp = realloc(ctx->state, (ctx->nstate + draw->nstate) * sizeof(void*));
+ if (tmp == NULL)
+ return -ENOMEM;
+ ctx->state = tmp;
+ pdraw = ctx->cdraw;
+ for (i = 0, cpm4 = 0, cstate = ctx->nstate; i < draw->nstate - 1; i++) {
+ nstate = draw->state[i];
+ if (nstate) {
+ if (pdraw && pdraw->state[i]) {
+ ostate = pdraw->state[i];
+ if (ostate->pm4_crc != nstate->pm4_crc) {
+ ctx->state[cstate++] = nstate;
+ cpm4 += nstate->cpm4;
+ }
+ } else {
+ ctx->state[cstate++] = nstate;
+ cpm4 += nstate->cpm4;
+ }
+ }
+ }
+ /* The last state is the draw state always add it */
+ if (draw->state[i] == NULL) {
+ fprintf(stderr, "%s no draw command\n", __func__);
+ return -EINVAL;
+ }
+ ctx->state[cstate++] = draw->state[i];
+ cpm4 += draw->state[i]->cpm4;
+ if ((ctx->draw_cpm4 + cpm4) > RADEON_CTX_MAX_PM4) {
+ /* need to flush */
+ return -EBUSY;
}
+ ctx->draw_cpm4 += cpm4;
+ ctx->nstate = cstate;
+ ctx->draw[ctx->ndraw++] = draw;
+ ctx->cdraw = draw;
return 0;
}
-void *copy_object(void *ptr, unsigned size)
+int radeon_ctx_set_draw(struct radeon_ctx *ctx, struct radeon_draw *draw)
{
- void *copy;
+ int r;
- copy = calloc(1, size);
- if (copy == NULL)
- return NULL;
- memcpy(copy, ptr, size);
- return copy;
+ radeon_draw_incref(draw);
+ r = radeon_ctx_set_draw_new(ctx, draw);
+ if (r)
+ radeon_draw_decref(draw);
+ return r;
+}
+
+int radeon_ctx_pm4(struct radeon_ctx *ctx)
+{
+ unsigned i;
+ int r;
+
+ free(ctx->pm4);
+ ctx->cpm4 = 0;
+ ctx->pm4 = malloc(ctx->draw_cpm4 * 4);
+ if (ctx->pm4 == NULL)
+ return -EINVAL;
+ for (i = 0, ctx->id = 0; i < ctx->nstate; i++) {
+ r = radeon_ctx_state_schedule(ctx, ctx->state[i]);
+ if (r)
+ return r;
+ }
+ if (ctx->id != ctx->draw_cpm4) {
+ fprintf(stderr, "%s miss predicted pm4 size %d for %d\n",
+ __func__, ctx->draw_cpm4, ctx->id);
+ return -EINVAL;
+ }
+ ctx->cpm4 = ctx->draw_cpm4;
+ return 0;
}
diff --git a/src/radeon_draw.c b/src/radeon_draw.c
index 660b77c..4be8555 100644
--- a/src/radeon_draw.c
+++ b/src/radeon_draw.c
@@ -91,7 +91,11 @@ int radeon_draw_set(struct radeon_draw *draw, struct radeon_state *state)
int radeon_draw_check(struct radeon_draw *draw)
{
unsigned i;
+ int r;
+ r = radeon_draw_pm4(draw);
+ if (r)
+ return r;
for (i = 0, draw->cpm4 = 0; i < draw->nstate; i++) {
if (draw->state[i]) {
draw->cpm4 += draw->state[i]->cpm4;
@@ -132,3 +136,36 @@ int radeon_draw_pm4(struct radeon_draw *draw)
}
return 0;
}
+
+int radeon_draw_ctx_set_reg(struct radeon_draw *draw, struct radeon_ctx *ctx, unsigned offset, u32 value)
+{
+ struct radeon *radeon = draw->radeon;
+ struct radeon_bo *bo;
+ unsigned id, stateid, typeid, boid, reloc;
+ int r;
+
+ r = radeon_reg_id(radeon, offset, &typeid, &stateid, &id);
+ if (r) {
+ return r;
+ }
+ if (draw->state[stateid] == NULL) {
+ draw->state[stateid] = radeon_state(radeon, typeid, stateid);
+ if (draw->state[stateid] == NULL)
+ return -ENOMEM;
+ };
+ draw->state[stateid]->states[id] = value;
+ if (radeon->type[typeid].regs[id].need_reloc) {
+ r = radeon_ctx_next_reloc(ctx, &reloc);
+ if (r)
+ return r;
+ bo = radeon_ctx_get_bo(ctx, reloc);
+ if (bo == NULL)
+ return -ENOMEM;
+ boid = radeon->type[typeid].regs[id].bo_id;
+ radeon_bo_decref(ctx->radeon, draw->state[stateid]->bo[boid]);
+ draw->state[stateid]->bo[boid] = bo;
+ radeon_ctx_get_placement(ctx, reloc, &draw->state[stateid]->placement[boid * 2]);
+ }
+ return 0;
+}
+
diff --git a/src/radeon_json.c b/src/radeon_json.c
index b29e632..8b8c0ab 100644
--- a/src/radeon_json.c
+++ b/src/radeon_json.c
@@ -24,6 +24,7 @@
* Jerome Glisse
*/
#include <stdlib.h>
+#include <string.h>
#include <jansson.h>
#include "radeon_priv.h"
@@ -250,7 +251,7 @@ struct radeon_state *radeon_state_load_json(struct radeon_ctx *ctx,
state->placement[i * 2 + 0] = strtoul(json_string_value(value), NULL, 0);
value = json_array_get(placement, 1);
state->placement[i * 2 + 1] = strtoul(json_string_value(value), NULL, 0);
- state->bo[i] = radeon_ctx_get_object(ctx, handle);
+// state->bo[i] = radeon_ctx_get_object(ctx, handle);
if (state->bo[i] == NULL) {
return radeon_state_decref(state);
}
@@ -288,7 +289,7 @@ struct radeon_draw *radeon_draw_load_json(struct radeon_ctx *ctx,
return 0;
}
-struct radeon_ctx *radeon_ctx_load_json(const char *filename)
+struct radeon_ctx *radeon_ctx_load_json(struct radeon *radeon, const char *filename)
{
struct radeon_ctx_json jctx;
unsigned device;
@@ -310,7 +311,7 @@ struct radeon_ctx *radeon_ctx_load_json(const char *filename)
goto out_err;
}
device = json_integer_value(tmp);
- jctx.ctx = radeon_ctx(NULL, device);
+ jctx.ctx = radeon_ctx(radeon);
if (jctx.ctx == NULL) {
goto out_err;
}
@@ -319,21 +320,16 @@ struct radeon_ctx *radeon_ctx_load_json(const char *filename)
fprintf(stderr, "no bof_file\n");
goto out_err;
}
- jctx.bof_ctx = radeon_ctx_load_bof(json_string_value(tmp));
+ jctx.bof_ctx = radeon_ctx_load_bof(radeon, json_string_value(tmp));
if (jctx.bof_ctx == NULL) {
goto out_err;
}
- jctx.ctx->bo = calloc(1, sizeof(struct radeon_ctx_bo) * jctx.bof_ctx->nbo);
+ jctx.ctx->bo = calloc(1, sizeof(struct radeon_bo) * jctx.bof_ctx->nbo);
if (jctx.ctx->bo == NULL) {
goto out_err;
}
jctx.ctx->nbo = jctx.bof_ctx->nbo;
- memcpy(jctx.ctx->bo, jctx.bof_ctx->bo, sizeof(struct radeon_ctx_bo*) * jctx.ctx->nbo);
- for (i = 0; i < jctx.ctx->nbo; i++) {
- radeon_object_incref(jctx.ctx->bo[i].bo);
- jctx.ctx->bo[i].id = -1;
- }
- radeon_ctx_destroy(jctx.bof_ctx);
+ radeon_ctx_decref(jctx.bof_ctx);
array = json_object_get(jctx.jctx, "draw");
if (array == NULL || !json_is_array(array)) {
goto out_err;
@@ -352,8 +348,8 @@ struct radeon_ctx *radeon_ctx_load_json(const char *filename)
json_decref(jctx.jctx);
return jctx.ctx;
out_err:
- radeon_ctx_destroy(jctx.bof_ctx);
- radeon_ctx_destroy(jctx.ctx);
+ radeon_ctx_decref(jctx.bof_ctx);
+ radeon_ctx_decref(jctx.ctx);
json_decref(jctx.jctx);
return NULL;
}
diff --git a/src/radeon_pciid.c b/src/radeon_pciid.c
index 33d3c7f..dd6156d 100644
--- a/src/radeon_pciid.c
+++ b/src/radeon_pciid.c
@@ -24,7 +24,7 @@
* Jerome Glisse
*/
#include <stdlib.h>
-#include "radeon.h"
+#include "radeon_priv.h"
struct pci_id {
unsigned vendor;
diff --git a/src/radeon_priv.h b/src/radeon_priv.h
index 6d04687..6fac0d0 100644
--- a/src/radeon_priv.h
+++ b/src/radeon_priv.h
@@ -20,8 +20,6 @@
#include <stdint.h>
#include "xf86drm.h"
#include "xf86drmMode.h"
-#include "radeon_bo.h"
-#include "radeon_cs.h"
#include <errno.h>
#include <jansson.h>
#include <pciaccess.h>
@@ -78,8 +76,11 @@ struct radeon_surface {
unsigned width;
unsigned height;
};
-void radeon_blit(struct radeon_surface *dst, struct radeon_surface *src,
- unsigned sx, unsigned sy, unsigned dx, unsigned dy,
+void radeon_blit(struct radeon *radeon,
+ struct radeon_surface *dst,
+ struct radeon_surface *src,
+ unsigned sx, unsigned sy,
+ unsigned dx, unsigned dy,
unsigned w, unsigned h);
/*
@@ -110,15 +111,12 @@ struct radeon {
int fd;
int refcount;
struct radeon_mode mode;
- struct radeon_bo_manager *bom;
- struct radeon_cs_manager *csm;
unsigned device;
unsigned family;
unsigned nstate;
unsigned ntype;
const struct radeon_type *type;
const struct radeon_asic *asic;
- struct radeon_ctx *ctx;
struct pci_device *dev;
unsigned char * volatile mmio;
pciaddr_t mmio_base;
@@ -139,21 +137,27 @@ extern int radeon_schedule_draw(struct radeon *radeon, struct radeon_draw *draw)
/*
* radeon context functions
*/
-struct radeon_ctx_bo {
- int id;
- struct radeon_object *bo;
+#pragma pack(1)
+struct radeon_cs_reloc {
+ uint32_t handle;
+ uint32_t read_domain;
+ uint32_t write_domain;
+ uint32_t flags;
};
+#pragma pack()
struct radeon_ctx {
+ int refcount;
struct radeon *radeon;
u32 *pm4;
u32 cpm4;
+ u32 draw_cpm4;
unsigned id;
unsigned next_id;
- u32 *reloc;
- u32 reloc_ndw;
+ unsigned nreloc;
+ struct radeon_cs_reloc *reloc;
unsigned nbo;
- struct radeon_ctx_bo *bo;
+ struct radeon_bo **bo;
unsigned ndraw;
struct radeon_draw *cdraw;
struct radeon_draw **draw;
@@ -161,29 +165,20 @@ struct radeon_ctx {
struct radeon_state **state;
};
-extern struct radeon_ctx *radeon_ctx(struct radeon *radeon, unsigned device);
-extern void radeon_ctx_destroy(struct radeon_ctx *ctx);
-extern int radeon_ctx_set_object_new(struct radeon_ctx *ctx,
- struct radeon_object *bo,
- int id);
-extern struct radeon_object *radeon_ctx_get_object(struct radeon_ctx *ctx, unsigned handle);
-extern struct radeon_object *radeon_ctx_get_bo(struct radeon_ctx *ctx, unsigned reloc);
+extern struct radeon_ctx *radeon_ctx(struct radeon *radeon);
+extern int radeon_ctx_set_bo_new(struct radeon_ctx *ctx, struct radeon_bo *bo);
+extern struct radeon_bo *radeon_ctx_get_bo(struct radeon_ctx *ctx, unsigned reloc);
extern void radeon_ctx_get_placement(struct radeon_ctx *ctx, unsigned reloc, u32 *placement);
-extern int radeon_ctx_allocate_bo(struct radeon_ctx *ctx);
-extern int radeon_ctx_submit(struct radeon_ctx *ctx);
-extern int radeon_ctx_draw(struct radeon_ctx *ctx);
extern int radeon_ctx_set_draw_new(struct radeon_ctx *ctx, struct radeon_draw *draw);
-extern int radeon_ctx_state_schedule(struct radeon_ctx *ctx, struct radeon_state *state);
-extern int radeon_ctx_draw_schedule(struct radeon_ctx *ctx, unsigned id);
-extern int radeon_ctx_draw_set_reg(struct radeon_ctx *ctx, unsigned offset, u32 value);
+extern int radeon_ctx_draw(struct radeon_ctx *ctx);
/*
* r600/r700 context functions
*/
extern int r600_init(struct radeon *radeon);
extern int r600_ctx_draw(struct radeon_ctx *ctx);
-extern int r600_ctx_get_dst_surface(struct radeon_ctx *ctx, struct radeon_surface *dst);
extern int r600_ctx_next_reloc(struct radeon_ctx *ctx, unsigned *reloc);
+extern int r600_ctx_get_dst_surface(struct radeon_ctx *ctx, struct radeon_surface *dst);
/*
* radeon state functions
@@ -200,11 +195,12 @@ extern int radeon_state_reloc(struct radeon_state *state, unsigned id, unsigned
*/
extern struct radeon_draw *radeon_draw_duplicate(struct radeon_draw *draw);
extern int radeon_draw_pm4(struct radeon_draw *draw);
+extern int radeon_draw_ctx_set_reg(struct radeon_draw *draw, struct radeon_ctx *ctx, unsigned offset, u32 value);
/*
* bof functions
*/
-extern struct radeon_ctx *radeon_ctx_load_bof(const char *filename);
+extern struct radeon_ctx *radeon_ctx_load_bof(struct radeon *radeon, const char *filename);
/*
* json functions
@@ -216,15 +212,13 @@ struct radeon_ctx_json {
json_t *jctx;
};
extern int radeon_ctx_dump_json(struct radeon_ctx *ctx, const char *filename);
-extern struct radeon_ctx *radeon_ctx_load_json(const char *filename);
+extern struct radeon_ctx *radeon_ctx_load_json(struct radeon *radeon, const char *filename);
extern json_t *radeon_json_load_draw(struct radeon_draw *draw);
/*
* helpers
*/
extern void *copy_object(void *ptr, unsigned size);
-extern void memset_bo(struct radeon_bo *bo, u32 value);
-extern void memcpy_bo(struct radeon_bo *bo, u32 *src, u32 size);
extern u32 radeon_mmio_rd32(struct radeon *radeon, u32 offset);
extern void radeon_mmio_wr32(struct radeon *radeon, u32 offset, u32 value);
diff --git a/src/radeon_reg.c b/src/radeon_reg.c
index 77631c3..781794b 100644
--- a/src/radeon_reg.c
+++ b/src/radeon_reg.c
@@ -23,6 +23,7 @@
* Authors:
* Jerome Glisse
*/
+#include <string.h>
#include "radeon_priv.h"
#include "radeon_reg.h"
diff --git a/src/radeon_state.c b/src/radeon_state.c
index 6cba23d..d501282 100644
--- a/src/radeon_state.c
+++ b/src/radeon_state.c
@@ -78,7 +78,7 @@ struct radeon_state *radeon_state_duplicate(struct radeon_state *state)
memcpy(nstate->reloc_bo_id, state->reloc_bo_id, 8 * 4);
memcpy(nstate->bo_dirty, state->bo_dirty, 4 * 4);
for (i = 0; i < state->nbo; i++) {
- nstate->bo[i] = radeon_object_incref(state->bo[i]);
+ nstate->bo[i] = radeon_bo_incref(state->radeon, state->bo[i]);
}
return nstate;
}
@@ -99,7 +99,7 @@ struct radeon_state *radeon_state_decref(struct radeon_state *state)
return NULL;
}
for (i = 0; i < state->nbo; i++) {
- state->bo[i] = radeon_object_decref(state->bo[i]);
+ state->bo[i] = radeon_bo_decref(state->radeon, state->bo[i]);
}
free(state->immd);
free(state->states);
@@ -146,11 +146,12 @@ int radeon_state_pm4(struct radeon_state *state)
{
int r;
- if (state == NULL)
+ if (state == NULL || state->cpm4)
return 0;
- state->cpm4 = 0;
r = state->radeon->type[state->type].pm4(state);
if (r) {
+ fprintf(stderr, "%s failed to build PM4 for state(%d %d)\n",
+ __func__, state->type, state->id);
return r;
}
state->pm4_crc = crc32(state->pm4, state->cpm4 * 4);
diff --git a/src/radeondb.c b/src/radeondb.c
index 6d3dd74..850d7c3 100644
--- a/src/radeondb.c
+++ b/src/radeondb.c
@@ -25,6 +25,7 @@
*/
#include "config.h"
#include <stdlib.h>
+#include <string.h>
#include <errno.h>
#include <getopt.h>
#include <jansson.h>
@@ -102,14 +103,14 @@ static int play(const char *file)
return -1;
}
/* setup framebuffer surface */
- memset_bo(radeon->mode.bo, 0x000000FF);
+// memset_bo(radeon->mode.bo, 0x000000FF);
dst.bo = radeon->mode.bo;
dst.width = radeon->mode.pitch / 4;
dst.pitch = radeon->mode.pitch / 4;
dst.bpe = 4;
dst.height = radeon->mode.height;
/* load bof */
- ctx = radeon_ctx_load_bof(file);
+ ctx = radeon_ctx_load_bof(radeon, file);
if (ctx == NULL) {
fprintf(stderr, "failed to read bof file %s\n", file);
r = -EINVAL;
@@ -120,42 +121,42 @@ static int play(const char *file)
r = -EINVAL;
goto out;
}
- radeon_decref(ctx->radeon);
- ctx->radeon = radeon_incref(radeon);
r = radeon_ctx_draw(ctx);
if (r) {
fprintf(stderr, "failed to reconstruct draw sequences from %s\n", file);
goto out;
}
- if (radeon_ctx_allocate_bo(ctx)) {
- ctx->radeon = NULL;
- r = -EINVAL;
- goto out;
- }
if (radeon_ctx_get_dst_surface(ctx, &src)) {
ctx->radeon = NULL;
r = -EINVAL;
goto out;
}
- radeon_blit(&dst, &src, 0, 0, 0, 0, src.width, src.height);
+ radeon_blit(radeon, &dst, &src, 0, 0, 0, 0, src.width, src.height);
getchar();
r = radeon_ctx_submit(ctx);
- radeon_bo_wait(src.bo);
- radeon_blit(&dst, &src, 0, 0, 0, 0, src.width, src.height);
+ radeon_bo_wait(radeon, src.bo);
+ radeon_blit(radeon, &dst, &src, 0, 0, 0, 0, src.width, src.height);
getchar();
- ctx->radeon = NULL;
out:
- radeon_ctx_destroy(ctx);
+ ctx = radeon_ctx_decref(ctx);
radeon_decref(radeon);
return r;
}
static int dump(const char *file)
{
+ struct radeon *radeon;
struct radeon_ctx *ctx;
unsigned i;
+ int fd;
- ctx = radeon_ctx_load_bof(file);
+ fd = radeon_open_fd();
+ if (fd < 0) {
+ fprintf(stderr, "failed to open radeon drm device\n");
+ return -1;
+ }
+ radeon = radeon_new(fd, 0);
+ ctx = radeon_ctx_load_bof(radeon, file);
if (ctx == NULL) {
fprintf(stderr, "failed to read bof file %s\n", file);
return -1;
@@ -185,14 +186,14 @@ static int json(const char *file)
return -1;
}
/* setup framebuffer surface */
- memset_bo(radeon->mode.bo, 0x000000FF);
+// memset_bo(radeon->mode.bo, 0x000000FF);
dst.bo = radeon->mode.bo;
dst.width = radeon->mode.pitch / 4;
dst.pitch = radeon->mode.pitch / 4;
dst.bpe = 4;
dst.height = radeon->mode.height;
/* load bof */
- ctx = radeon_ctx_load_bof(file);
+ ctx = radeon_ctx_load_bof(radeon, file);
if (ctx == NULL) {
fprintf(stderr, "failed to read bof file %s\n", file);
r = -EINVAL;
@@ -203,16 +204,14 @@ static int json(const char *file)
r = -EINVAL;
goto out;
}
- radeon_decref(ctx->radeon);
- ctx->radeon = radeon_incref(radeon);
r = radeon_ctx_draw(ctx);
if (r) {
fprintf(stderr, "failed to reconstruct draw sequences from %s\n", file);
goto out;
}
- if (radeon_ctx_allocate_bo(ctx)) {
- ctx->radeon = NULL;
- r = -EINVAL;
+ r = radeon_ctx_pm4(ctx);
+ if (r) {
+ fprintf(stderr, "failed to reconstruct pm4 sequences from %s\n", file);
goto out;
}
if (radeon_ctx_get_dst_surface(ctx, &src)) {
@@ -220,28 +219,17 @@ static int json(const char *file)
r = -EINVAL;
goto out;
}
- radeon_blit(&dst, &src, 0, 0, 0, 0, src.width, src.height);
- for (unsigned i = 0; i < ctx->ndraw; i++) {
- if (radeon_draw_pm4(ctx->draw[i])) {
- fprintf(stderr, "failed to pm4 %d\n", i);
- goto out;
- }
- if (radeon_schedule_draw(radeon, ctx->draw[i])) {
- fprintf(stderr, "failed to schedule %d\n", i);
- goto out;
- }
- }
- if (radeon_flush(radeon)) {
+ radeon_blit(radeon, &dst, &src, 0, 0, 0, 0, src.width, src.height);
+ if (radeon_ctx_submit(ctx)) {
fprintf(stderr, "failed to flush\n");
goto out;
}
getchar();
- radeon_bo_wait(src.bo);
- radeon_blit(&dst, &src, 0, 0, 0, 0, src.width, src.height);
+ radeon_bo_wait(radeon, src.bo);
+ radeon_blit(radeon, &dst, &src, 0, 0, 0, 0, src.width, src.height);
getchar();
- ctx->radeon = NULL;
out:
- radeon_ctx_destroy(ctx);
+ ctx = radeon_ctx_decref(ctx);
radeon_decref(radeon);
return r;
}
@@ -249,12 +237,23 @@ out:
static int conv(const char *file)
{
struct radeon_ctx *ctx = NULL;
+ struct radeon *radeon;
char *tmp;
char name[256];
- int r;
+ int r, fd;
+ fd = radeon_open_fd();
+ if (fd < 0) {
+ fprintf(stderr, "failed to open radeon drm device\n");
+ return -1;
+ }
+ radeon = radeon_new(fd, 0);
+ if (radeon == NULL) {
+ fprintf(stderr, "failed to initialize radeon\n");
+ return -1;
+ }
/* load bof */
- ctx = radeon_ctx_load_bof(file);
+ ctx = radeon_ctx_load_bof(radeon, file);
if (ctx == NULL) {
fprintf(stderr, "failed to read bof file %s\n", file);
return -EINVAL;
@@ -271,6 +270,6 @@ static int conv(const char *file)
*tmp = 0;
sprintf(name, "%sjson", file);
r = radeon_ctx_dump_json(ctx, name);
- radeon_ctx_destroy(ctx);
+ ctx = radeon_ctx_decref(ctx);
return r;
}