summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/r600/r600_translate.c
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2011-02-07 02:00:56 +0100
committerMarek Olšák <[email protected]>2011-02-07 02:46:17 +0100
commitaa8a2224a3df111a1613f0baefebc00883e1b70b (patch)
treee09c1f779a1e22a0e561a5cd039f3bbcac31c5b1 /src/gallium/drivers/r600/r600_translate.c
parent975320ab76f5c247f6ed4dab80627173845200d0 (diff)
r600g: use the new vertex buffer manager
Diffstat (limited to 'src/gallium/drivers/r600/r600_translate.c')
-rw-r--r--src/gallium/drivers/r600/r600_translate.c169
1 files changed, 2 insertions, 167 deletions
diff --git a/src/gallium/drivers/r600/r600_translate.c b/src/gallium/drivers/r600/r600_translate.c
index 68429b99d01..a980eac95e0 100644
--- a/src/gallium/drivers/r600/r600_translate.c
+++ b/src/gallium/drivers/r600/r600_translate.c
@@ -23,176 +23,11 @@
* Authors: Dave Airlie <[email protected]>
*/
-#include "translate/translate_cache.h"
-#include "translate/translate.h"
-#include <pipebuffer/pb_buffer.h>
#include <util/u_index_modify.h>
+#include "util/u_inlines.h"
#include "util/u_upload_mgr.h"
#include "r600_pipe.h"
-void r600_begin_vertex_translate(struct r600_pipe_context *rctx,
- int min_index, int max_index)
-{
- struct pipe_context *pipe = &rctx->context;
- struct translate_key key = {0};
- struct translate_element *te;
- unsigned tr_elem_index[PIPE_MAX_ATTRIBS] = {0};
- struct translate *tr;
- struct r600_vertex_element *ve = rctx->vertex_elements;
- boolean vb_translated[PIPE_MAX_ATTRIBS] = {0};
- uint8_t *vb_map[PIPE_MAX_ATTRIBS] = {0}, *out_map;
- struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS] = {0};
- struct pipe_resource *out_buffer = NULL;
- unsigned i, num_verts, out_offset;
- struct pipe_vertex_element new_velems[PIPE_MAX_ATTRIBS];
- boolean flushed;
-
- /* Initialize the translate key, i.e. the recipe how vertices should be
- * translated. */
- for (i = 0; i < ve->count; i++) {
- enum pipe_format output_format = ve->hw_format[i];
- unsigned output_format_size = ve->hw_format_size[i];
-
- /* Check for support. */
- if (ve->elements[i].src_format == ve->hw_format[i]) {
- continue;
- }
-
- /* Workaround for translate: output floats instead of halfs. */
- switch (output_format) {
- case PIPE_FORMAT_R16_FLOAT:
- output_format = PIPE_FORMAT_R32_FLOAT;
- output_format_size = 4;
- break;
- case PIPE_FORMAT_R16G16_FLOAT:
- output_format = PIPE_FORMAT_R32G32_FLOAT;
- output_format_size = 8;
- break;
- case PIPE_FORMAT_R16G16B16_FLOAT:
- output_format = PIPE_FORMAT_R32G32B32_FLOAT;
- output_format_size = 12;
- break;
- case PIPE_FORMAT_R16G16B16A16_FLOAT:
- output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
- output_format_size = 16;
- break;
- default:;
- }
-
- /* Add this vertex element. */
- te = &key.element[key.nr_elements];
- /*te->type;
- te->instance_divisor;*/
- te->input_buffer = ve->elements[i].vertex_buffer_index;
- te->input_format = ve->elements[i].src_format;
- te->input_offset = ve->elements[i].src_offset;
- te->output_format = output_format;
- te->output_offset = key.output_stride;
-
- key.output_stride += output_format_size;
- vb_translated[ve->elements[i].vertex_buffer_index] = TRUE;
- tr_elem_index[i] = key.nr_elements;
- key.nr_elements++;
- }
-
- /* Get a translate object. */
- tr = translate_cache_find(rctx->tran.translate_cache, &key);
-
- /* Map buffers we want to translate. */
- for (i = 0; i < rctx->nvertex_buffers; i++) {
- if (vb_translated[i]) {
- struct pipe_vertex_buffer *vb = &rctx->vertex_buffer[i];
-
- vb_map[i] = pipe_buffer_map(pipe, vb->buffer,
- PIPE_TRANSFER_READ, &vb_transfer[i]);
-
- tr->set_buffer(tr, i,
- vb_map[i] + vb->buffer_offset + vb->stride * min_index,
- vb->stride, ~0);
- }
- }
-
- /* Create and map the output buffer. */
- num_verts = max_index + 1 - min_index;
-
- u_upload_alloc(rctx->upload_vb,
- key.output_stride * min_index,
- key.output_stride * num_verts,
- &out_offset, &out_buffer, &flushed,
- (void**)&out_map);
-
- out_offset -= key.output_stride * min_index;
-
- /* Translate. */
- tr->run(tr, 0, num_verts, 0, out_map);
-
- /* Unmap all buffers. */
- for (i = 0; i < rctx->nvertex_buffers; i++) {
- if (vb_translated[i]) {
- pipe_buffer_unmap(pipe, vb_transfer[i]);
- }
- }
-
- /* Find the first free slot. */
- rctx->tran.vb_slot = ~0;
- for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
- if (!rctx->vertex_buffer[i].buffer) {
- rctx->tran.vb_slot = i;
-
- if (i >= rctx->nvertex_buffers) {
- rctx->nreal_vertex_buffers = i+1;
- }
- break;
- }
- }
-
- if (rctx->tran.vb_slot != ~0) {
- /* Setup the new vertex buffer. */
- pipe_resource_reference(&rctx->real_vertex_buffer[rctx->tran.vb_slot], out_buffer);
- rctx->vertex_buffer[rctx->tran.vb_slot].buffer_offset = out_offset;
- rctx->vertex_buffer[rctx->tran.vb_slot].stride = key.output_stride;
-
- /* Setup new vertex elements. */
- for (i = 0; i < ve->count; i++) {
- if (vb_translated[ve->elements[i].vertex_buffer_index]) {
- te = &key.element[tr_elem_index[i]];
- new_velems[i].instance_divisor = ve->elements[i].instance_divisor;
- new_velems[i].src_format = te->output_format;
- new_velems[i].src_offset = te->output_offset;
- new_velems[i].vertex_buffer_index = rctx->tran.vb_slot;
- } else {
- memcpy(&new_velems[i], &ve->elements[i],
- sizeof(struct pipe_vertex_element));
- }
- }
-
- rctx->tran.saved_velems = rctx->vertex_elements;
- rctx->tran.new_velems =
- pipe->create_vertex_elements_state(pipe, ve->count, new_velems);
- pipe->bind_vertex_elements_state(pipe, rctx->tran.new_velems);
- }
-
- pipe_resource_reference(&out_buffer, NULL);
-}
-
-void r600_end_vertex_translate(struct r600_pipe_context *rctx)
-{
- struct pipe_context *pipe = &rctx->context;
-
- if (rctx->tran.new_velems == NULL) {
- return;
- }
-
- /* Restore vertex elements. */
- pipe->bind_vertex_elements_state(pipe, rctx->tran.saved_velems);
- rctx->tran.saved_velems = NULL;
- pipe->delete_vertex_elements_state(pipe, rctx->tran.new_velems);
- rctx->tran.new_velems = NULL;
-
- /* Delete the now-unused VBO. */
- pipe_resource_reference(&rctx->real_vertex_buffer[rctx->tran.vb_slot], NULL);
- rctx->nreal_vertex_buffers = rctx->nvertex_buffers;
-}
void r600_translate_index_buffer(struct r600_pipe_context *r600,
struct pipe_resource **index_buffer,
@@ -206,7 +41,7 @@ void r600_translate_index_buffer(struct r600_pipe_context *r600,
switch (*index_size) {
case 1:
- u_upload_alloc(r600->upload_vb, 0, count * 2,
+ u_upload_alloc(r600->upload_ib, 0, count * 2,
&out_offset, &out_buffer, &flushed, &ptr);
util_shorten_ubyte_elts_to_userptr(