diff options
author | Jerome Glisse <jglisse@redhat.com> | 2010-02-23 21:04:11 +0100 |
---|---|---|
committer | Jerome Glisse <jglisse@redhat.com> | 2010-02-23 21:04:11 +0100 |
commit | 2b95f2ff980c7fc9eb9fb93d6a7be588807d6edb (patch) | |
tree | 2d2ae9e079553abc63aa101ff6d6e70281cf7d88 | |
parent | 6cdfb7ad904a6bdd02f902fea97d5bae58d36890 (diff) |
convert vs input to resource atom
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | r600_atom.c | 60 | ||||
-rw-r--r-- | r600_batch.c | 77 | ||||
-rw-r--r-- | r600_winsys.h | 50 | ||||
-rw-r--r-- | test.c | 53 |
5 files changed, 126 insertions, 117 deletions
@@ -1,4 +1,5 @@ -OBJECTS = radeon.o mode.o test.o r700_atom.o r600_winsys.o r600_atom.o r600_batch.o +OBJECTS = radeon.o mode.o test.o r700_atom.o r600_winsys.o r600_atom.o\ + r600_batch.o r600_clear.o CFLAGS = -g3 -O0 -std=gnu99 -I/usr/include/drm LDFLAGS = -ldrm -ldrm_radeon DEPS = radeon.h diff --git a/r600_atom.c b/r600_atom.c index 930490b..0956f91 100644 --- a/r600_atom.c +++ b/r600_atom.c @@ -526,7 +526,7 @@ fprintf(stderr, "%s %d pkts\n", __func__, atom->npkts); } /* - * r600_fs_shader + * fragment shader */ int r600_fs_shader_emit(struct r600_winsys *rdev, struct r600_atom *atom, @@ -587,6 +587,59 @@ fprintf(stderr, "%s %d pkts\n", __func__, atom->npkts); return 0; } +/* + * vertex shader input + */ +int r600_shader_resource_emit(struct r600_winsys *rdev, + struct r600_atom *atom, + void *data, + struct radeon_ib *ib) +{ + struct drm_r600_shader_resource *shader_resource = atom->state; + int i; + + for (i = 0; i < shader_resource->nresource; i++) { + atom->pkts[i * 11 + 10] = radeon_ib_reloc(ib, atom->bo[i], RADEON_GEM_DOMAIN_GTT); + } + return radeon_ib_copy(ib, atom->pkts, atom->npkts); +} + +int r600_shader_resource_create(struct r600_winsys *rdev, struct r600_atom *atom, void *data) +{ + struct drm_r600_shader_resource *shader_resource; + u32 ninputs; + int r, i; + + shader_resource = malloc(sizeof(struct drm_r600_shader_resource)); + if (shader_resource == NULL) + return -ENOMEM; + memcpy(shader_resource, data, sizeof(struct drm_r600_shader_resource)); + atom->state = shader_resource; + for (i = 0, atom->nbo = 0; i < shader_resource->nresource; i++, atom->nbo++) { + atom->bo[i] = radeon_bo_lookup(rdev, shader_resource->resource[i].handle); + atom->flags[i] = 0x01000000; + if (atom->bo[i] == NULL) + return -EINVAL; + } + atom->nflushes = atom->nbo; + for (i = 0; i < shader_resource->nresource; i++) { + /* SET_RESOURCE */ + atom->pkts[atom->npkts++] = PKT3(PKT3_SET_RESOURCE, 7); + atom->pkts[atom->npkts++] = (shader_resource->resource[i].resource_id + 160) * 7; + atom->pkts[atom->npkts++] = shader_resource->resource[i].sq_vtx_constant_word0; + atom->pkts[atom->npkts++] = shader_resource->resource[i].sq_vtx_constant_word1; + atom->pkts[atom->npkts++] = shader_resource->resource[i].sq_vtx_constant_word2; + atom->pkts[atom->npkts++] = shader_resource->resource[i].sq_vtx_constant_word3; + atom->pkts[atom->npkts++] = shader_resource->resource[i].sq_vtx_constant_word4; + atom->pkts[atom->npkts++] = shader_resource->resource[i].sq_vtx_constant_word5; + atom->pkts[atom->npkts++] = shader_resource->resource[i].sq_vtx_constant_word6; + atom->pkts[atom->npkts++] = PKT3(PKT3_NOP, 0); + atom->pkts[atom->npkts++] = 0x00000000; + } +fprintf(stderr, "%s %d pkts\n", __func__, atom->npkts); + return 0; +} + int r600_draw_cmd_size(struct drm_r600_batch *batch) { switch (G_0287F0_SOURCE_SELECT(batch->vgt_draw_initiator)) { @@ -618,3 +671,8 @@ int r600_draw_cmd_emit(struct radeon_ib *ib, struct drm_r600_batch *batch) return 0; } } + +void *r600_atom_state(struct r600_atom *atom) +{ + return atom->state; +} diff --git a/r600_batch.c b/r600_batch.c index 3c4ef58..4eff704 100644 --- a/r600_batch.c +++ b/r600_batch.c @@ -31,6 +31,8 @@ int r600_vs_shader_emit(struct r600_winsys *rdev, struct r600_atom *atom, void * int r600_vs_shader_create(struct r600_winsys *rdev, struct r600_atom *atom, void *data); int r600_fs_shader_emit(struct r600_winsys *rdev, struct r600_atom *atom, void *data, struct radeon_ib *ib); int r600_fs_shader_create(struct r600_winsys *rdev, struct r600_atom *atom, void *data); +int r600_shader_resource_emit(struct r600_winsys *rdev, struct r600_atom *atom, void *data, struct radeon_ib *ib); +int r600_shader_resource_create(struct r600_winsys *rdev, struct r600_atom *atom, void *data); /* * helpers functions @@ -93,7 +95,6 @@ static int r600_batch_alloc(struct r600_batch **batch) INIT_LIST_HEAD(&rbatch->pre_flushes); INIT_LIST_HEAD(&rbatch->post_flushes); rbatch->nemit_atoms = 0; - rbatch->nfs_resources = 0; *batch = rbatch; return 0; } @@ -101,35 +102,6 @@ static int r600_batch_alloc(struct r600_batch **batch) /* * r600_batches */ -static int r600_batches_fs_resource_is_present(struct r600_winsys *rdev, - struct r600_batches *batches, - struct drm_r600_vs_buffer *buffer) -{ - int i; - - for (i = 0; i < batches->nfs_resources; i++) { - if (!memcmp(&batches->fs_resource[i], buffer, sizeof(struct drm_r600_vs_buffer))) { - buffer->resource_id = i; - return 1; - } - } - return 0; -} - -static int r600_batches_fs_resource_add(struct r600_winsys *rdev, - struct r600_batches *batches, - struct drm_r600_vs_buffer *buffer) -{ - int i = batches->nfs_resources++; - - buffer->resource_id = i; - memcpy(&batches->fs_resource[i].drm, buffer, sizeof(struct drm_r600_vs_buffer)); - batches->fs_resource[i].bo = radeon_bo_lookup(rdev, buffer->handle); - if (batches->fs_resource[i].bo == NULL) - return -EINVAL; - return 0; -} - static void r600_batches_clear_locked(struct r600_winsys *rdev, struct r600_batches *batches) { struct r600_batch *batch, *n; @@ -138,7 +110,7 @@ static void r600_batches_clear_locked(struct r600_winsys *rdev, struct r600_batc list_for_each_entry_safe(batch, n, &batches->batches, list) { for (i = 0; i < R600_BATCH_NATOMS; i++) { if (batch->atoms[i]) - r600_atom_put(batch->atoms[i]); + r600_atom_destroy(batch->atoms[i]); } r600_atom_flush_cleanup(&batch->pre_flushes); r600_atom_flush_cleanup(&batch->post_flushes); @@ -146,10 +118,6 @@ static void r600_batches_clear_locked(struct r600_winsys *rdev, struct r600_batc free(batch); } INIT_LIST_HEAD(&batches->batches); - for (i = 0; i < batches->nfs_resources; i++) { - radeon_bo_unref(batches->fs_resource[i].bo); - } - batches->nfs_resources = 0; r700_batches_states_default(rdev, batches); batches->npkts = batches->ib->cpkts; } @@ -160,16 +128,6 @@ static int r600_batches_flush_locked(struct r600_winsys *rdev, struct r600_batch struct r600_atom_flush *flush; int r, i; - for (i = 0; i < batches->nfs_resources; i++) { - r600_emit_resources(rdev, batches->ib, batches->fs_resource[i].bo, - (batches->fs_resource[i].drm.resource_id + 160) * 7, - batches->fs_resource[i].drm.sq_vtx_constant_word0, - radeon_bo_size(batches->fs_resource[i].bo) - - batches->fs_resource[i].drm.sq_vtx_constant_word0, - batches->fs_resource[i].drm.sq_vtx_constant_word2, - batches->fs_resource[i].drm.sq_vtx_constant_word3, - 0, 0, 0xC0000000); - } list_for_each_entry(batch, &batches->batches, list) { list_for_each_entry(flush, &batch->pre_flushes, list) { r600_emit_flush(rdev, batches->ib, flush->bo, flush->flags); @@ -209,13 +167,12 @@ int r600_batches_queue(struct r600_winsys *rdev, struct r600_request *rq) r = r600_batch_alloc(&rbatch); if (r) return r; - memcpy(&rbatch->inputs, &batch->inputs, sizeof(struct r600_vs_input)); i = 0; if (batch->blend == NULL || batch->cb_cntl == NULL || batch->rasterizer == NULL || batch->viewport == NULL || batch->framebuffer == NULL || batch->dsa == NULL || batch->vs_shader == NULL || batch->fs_shader == NULL || - batch->scissor == NULL) { + batch->scissor == NULL || batch->vs_resource == NULL) { free(rbatch); fprintf(stderr, "invalid batch\n"); return -EINVAL; @@ -230,6 +187,7 @@ int r600_batches_queue(struct r600_winsys *rdev, struct r600_request *rq) rbatch->atoms[i++] = batch->dsa; rbatch->atoms[i++] = batch->vs_constants; rbatch->atoms[i++] = batch->ps_constants; + rbatch->atoms[i++] = batch->vs_resource; rbatch->atoms[i++] = batch->framebuffer; memcpy(&rbatch->drm, batch, sizeof(struct drm_r600_batch)); reprocess: @@ -240,13 +198,6 @@ reprocess: /* flush + wait until = 5dw */ rbatch->npkts += 5; rbatch->npkts += r600_draw_cmd_size(batch); - for (i = 0; i < rbatch->inputs.drm.nbuffers; i++) { - if (!r600_batches_fs_resource_is_present(rdev, batches, &rbatch->inputs.drm.buffers[i])) { - rbatch->nfs_resources += 1; - rbatch->inputs.drm.buffers[i].resource_id = -1; - } - } - rbatch->npkts += rbatch->nfs_resources * 18; for (i = 0; i < R600_BATCH_NATOMS; i++) { if (rbatch->atoms[i]) { for (j = 0; j < rbatch->atoms[i]->nbo; j++) { @@ -284,20 +235,13 @@ reprocess: } } r600_winsys_set_bo_list(rdev, rq->nbo, rq->bo); - for (i = 0; i < rbatch->inputs.drm.nbuffers; i++) { - if (rbatch->inputs.drm.buffers[i].resource_id == -1) { - r = r600_batches_fs_resource_add(rdev, batches, &rbatch->inputs.drm.buffers[i]); - if (r) - goto out_err; - } - } batches->npkts += rbatch->npkts; list_add_tail(&rbatch->list, &batches->batches); return 0; out_err: for (i = 0; i < R600_BATCH_NATOMS; i++) { if (rbatch->atoms[i]) - r600_atom_put(rbatch->atoms[i]); + r600_atom_destroy(rbatch->atoms[i]); } free(rbatch); return r; @@ -368,8 +312,10 @@ static struct r600_atom_funcs _r600_atom_funcs[] = { &r600_dsa_create, &r600_atom_emit_default}, {R600_ATOM_VS_SHADER, sizeof(struct drm_r600_vs_shader), &r600_vs_shader_create, &r600_vs_shader_emit}, - {R600_ATOM_PS_SHADER, sizeof(struct drm_r600_fs_shader), + {R600_ATOM_FS_SHADER, sizeof(struct drm_r600_fs_shader), &r600_fs_shader_create, &r600_fs_shader_emit}, + {R600_ATOM_SHADER_RESOURCE, sizeof(struct drm_r600_shader_resource), + &r600_shader_resource_create, &r600_shader_resource_emit}, }; struct r600_atom *r600_atom_create(struct r600_winsys *rdev, struct r600_request *rq) @@ -398,7 +344,7 @@ struct r600_atom *r600_atom_create(struct r600_winsys *rdev, struct r600_request atom->type = rq->type; r = _r600_atom_funcs[rq->type].create(rdev, atom, rq->data); if (r) { - r600_atom_put(atom); + r600_atom_destroy(atom); return NULL; } return atom; @@ -458,7 +404,7 @@ void r600_winsys_set_bo_list(struct r600_winsys *rdev, u32 nbo, struct radeon_bo rdev->nbo = nbo; } -void r600_atom_put(struct r600_atom *atom) +struct r600_atom *r600_atom_destroy(struct r600_atom *atom) { int i; @@ -467,4 +413,5 @@ void r600_atom_put(struct r600_atom *atom) } free(atom->state); free(atom); + return NULL; } diff --git a/r600_winsys.h b/r600_winsys.h index bf162e5..c70b558 100644 --- a/r600_winsys.h +++ b/r600_winsys.h @@ -27,17 +27,18 @@ typedef uint8_t u8; struct r600_winsys; struct r600_atom; -#define R600_ATOM_FRAMEBUFFER 1 -#define R600_ATOM_RASTERIZER 2 -#define R600_ATOM_CB_CNTL 3 -#define R600_ATOM_VIEWPORT 4 -#define R600_ATOM_SCISSOR 5 -#define R600_ATOM_BLEND 6 -#define R600_ATOM_CONSTANTS 7 -#define R600_ATOM_DSA 8 -#define R600_ATOM_VS_SHADER 9 -#define R600_ATOM_PS_SHADER 10 -#define R600_BATCH_NATOMS 11 +#define R600_ATOM_FRAMEBUFFER 1 +#define R600_ATOM_RASTERIZER 2 +#define R600_ATOM_CB_CNTL 3 +#define R600_ATOM_VIEWPORT 4 +#define R600_ATOM_SCISSOR 5 +#define R600_ATOM_BLEND 6 +#define R600_ATOM_CONSTANTS 7 +#define R600_ATOM_DSA 8 +#define R600_ATOM_VS_SHADER 9 +#define R600_ATOM_FS_SHADER 10 +#define R600_ATOM_SHADER_RESOURCE 11 +#define R600_BATCH_NATOMS 12 struct drm_r600_surface { u32 width; @@ -190,27 +191,21 @@ struct drm_r600_fs_shader { u32 offset; }; -struct drm_r600_vs_buffer { +struct drm_r600_resource { u32 handle; u32 resource_id; u32 sq_vtx_constant_word0; + u32 sq_vtx_constant_word1; u32 sq_vtx_constant_word2; u32 sq_vtx_constant_word3; + u32 sq_vtx_constant_word4; + u32 sq_vtx_constant_word5; + u32 sq_vtx_constant_word6; }; -struct drm_r600_vs_element { - u32 buffer_id; - u32 semantic; - u32 sq_vtx_word0; - u32 sq_vtx_word1; - u32 sq_vtx_word2; -}; - -struct drm_r600_vs_input { - u32 nelements; - u32 nbuffers; - struct drm_r600_vs_element elements[32]; - struct drm_r600_vs_buffer buffers[32]; +struct drm_r600_shader_resource { + u32 nresource; + struct drm_r600_resource resource[32]; }; struct drm_r600_batch { @@ -225,7 +220,7 @@ struct drm_r600_batch { struct r600_atom *dsa; struct r600_atom *vs_shader; struct r600_atom *fs_shader; - struct drm_r600_vs_input inputs; + struct r600_atom *vs_resource; u32 vgt_primitive_type; u32 vgt_dma_index_type; u32 vgt_dma_num_instances; @@ -240,10 +235,11 @@ struct r600_request { struct radeon_bo *bo[32]; }; +extern void *r600_atom_state(struct r600_atom *atom); extern int r600_batches_queue(struct r600_winsys*, struct r600_request*); extern int r600_batches_flush(struct r600_winsys*); extern struct r600_atom *r600_atom_create(struct r600_winsys*, struct r600_request*); -extern void r600_atom_destroy(struct r600_atom *atom); +extern struct r600_atom *r600_atom_destroy(struct r600_atom *atom); struct pipe_screen *r600_create_screen(struct r600_winsys *r600_winsys, struct radeon_bo_manager *bom); @@ -104,6 +104,7 @@ int r600_tri_flat(struct radeon *radeon) struct drm_r600_scissor scissor; struct drm_r600_constants vs_constants; struct drm_r600_vs_shader vs_shader; + struct drm_r600_shader_resource vs_resource; struct drm_r600_fs_shader ps_shader; struct drm_r600_batch batch; struct radeon_bo *vbo1; @@ -272,7 +273,7 @@ int r600_tri_flat(struct radeon *radeon) vs_shader.input_gpr[1] = 2; vs_shader.noutputs = 1; vs_shader.output_semantic[0] = 4; - vs_shader.sq_pgm_resources_vs = 0x00000106; + vs_shader.sq_pgm_resources_vs = 0x00000006; vs_shader.ndwords = 64; vs_shader.handle = vs->handle; vs_shader.offset = 0; @@ -293,31 +294,37 @@ int r600_tri_flat(struct radeon *radeon) ps_shader.offset = 0; rq.bo[0] = ps; rq.nbo = 1; - rq.type = R600_ATOM_PS_SHADER; + rq.type = R600_ATOM_FS_SHADER; rq.data = &ps_shader; batch.fs_shader = r600_atom_create(rdev, &rq); - /* inputs */ - batch.inputs.nelements = 2; - batch.inputs.nbuffers = 2; - batch.inputs.buffers[0].handle = vbo1->handle; - batch.inputs.buffers[0].sq_vtx_constant_word0 = 0x00000000; - batch.inputs.buffers[0].sq_vtx_constant_word2 = 0x03001C00; - batch.inputs.buffers[0].sq_vtx_constant_word3 = 0x00000001; - batch.inputs.buffers[1].handle = vbo1->handle; - batch.inputs.buffers[1].sq_vtx_constant_word0 = 0x0000000C; - batch.inputs.buffers[1].sq_vtx_constant_word2 = 0x02301C00; - batch.inputs.buffers[1].sq_vtx_constant_word3 = 0x00000001; - batch.inputs.elements[0].buffer_id = 0; - batch.inputs.elements[0].semantic = 1; - batch.inputs.elements[0].sq_vtx_word0 = 0x7C000000; - batch.inputs.elements[0].sq_vtx_word1 = 0x1C351000; - batch.inputs.elements[0].sq_vtx_word2 = 0x00080000; - batch.inputs.elements[1].buffer_id = 1; - batch.inputs.elements[1].semantic = 2; - batch.inputs.elements[1].sq_vtx_word0 = 0x7C000000; - batch.inputs.elements[1].sq_vtx_word1 = 0x18ED1000; - batch.inputs.elements[1].sq_vtx_word2 = 0x00080000; + vs_resource.nresource = 2; + vs_resource.resource[0].handle = vbo1->handle; + vs_resource.resource[0].resource_id = 0; + vs_resource.resource[0].sq_vtx_constant_word0 = 0x00000000; + vs_resource.resource[0].sq_vtx_constant_word1 = vbo1->size; + vs_resource.resource[0].sq_vtx_constant_word2 = 0x03001C00; + vs_resource.resource[0].sq_vtx_constant_word3 = 0x00000001; + vs_resource.resource[0].sq_vtx_constant_word4 = 0x00000000; + vs_resource.resource[0].sq_vtx_constant_word5 = 0x00000000; + vs_resource.resource[0].sq_vtx_constant_word6 = 0xC0000000; + vs_resource.resource[1].handle = vbo1->handle; + vs_resource.resource[1].resource_id = 1; + vs_resource.resource[1].sq_vtx_constant_word0 = 0x0000000C; + vs_resource.resource[1].sq_vtx_constant_word1 = vbo1->size - 0xC; + vs_resource.resource[1].sq_vtx_constant_word2 = 0x02301C00; + vs_resource.resource[1].sq_vtx_constant_word3 = 0x00000001; + vs_resource.resource[1].sq_vtx_constant_word4 = 0x00000000; + vs_resource.resource[1].sq_vtx_constant_word5 = 0x00000000; + vs_resource.resource[1].sq_vtx_constant_word6 = 0xC0000000; + rq.bo[0] = vbo1; + rq.bo[1] = vbo1; + rq.nbo = 2; + rq.type = R600_ATOM_SHADER_RESOURCE; + rq.data = &vs_resource; + batch.vs_resource = r600_atom_create(rdev, &rq); + + batch.vgt_primitive_type = 5; batch.vgt_dma_index_type = 0; batch.vgt_dma_num_instances = 1; |