From 70e656b4ebdd3cd2962ce66544ae9af349ecd59a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 29 Jan 2011 13:49:41 +0100 Subject: [PATCH] r600g: fix vertex format fallback This fixes: - piglit/draw-vertices - piglit/draw-vertices-half-float --- src/gallium/drivers/r600/r600_asm.c | 8 +----- src/gallium/drivers/r600/r600_blit.c | 2 +- src/gallium/drivers/r600/r600_pipe.h | 4 ++- src/gallium/drivers/r600/r600_state_common.c | 29 ++++++++++++++++++-- src/gallium/drivers/r600/r600_translate.c | 22 +++++++++------ 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index 9cdd10f9876..3b0d01b8720 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -1889,7 +1889,7 @@ static void r600_vertex_data_type(enum pipe_format pformat, unsigned *format, } switch (desc->channel[i].type) { - /* Half-floats, floats, doubles */ + /* Half-floats, floats, ints */ case UTIL_FORMAT_TYPE_FLOAT: switch (desc->channel[i].size) { case 16: @@ -1901,8 +1901,6 @@ static void r600_vertex_data_type(enum pipe_format pformat, unsigned *format, *format = FMT_16_16_FLOAT; break; case 3: - *format = FMT_16_16_16_FLOAT; - break; case 4: *format = FMT_16_16_16_16_FLOAT; break; @@ -1942,8 +1940,6 @@ static void r600_vertex_data_type(enum pipe_format pformat, unsigned *format, *format = FMT_8_8; break; case 3: - // *format = FMT_8_8_8; /* fails piglit draw-vertices test */ - // break; case 4: *format = FMT_8_8_8_8; break; @@ -1958,8 +1954,6 @@ static void r600_vertex_data_type(enum pipe_format pformat, unsigned *format, *format = FMT_16_16; break; case 3: - // *format = FMT_16_16_16; /* fails piglit draw-vertices test */ - // break; case 4: *format = FMT_16_16_16_16; break; diff --git a/src/gallium/drivers/r600/r600_blit.c b/src/gallium/drivers/r600/r600_blit.c index b9ec9592e35..b487182e3aa 100644 --- a/src/gallium/drivers/r600/r600_blit.c +++ b/src/gallium/drivers/r600/r600_blit.c @@ -53,7 +53,7 @@ static void r600_blitter_begin(struct pipe_context *ctx, enum r600_blitter_op op if (rctx->states[R600_PIPE_STATE_CLIP]) { util_blitter_save_clip(rctx->blitter, &rctx->clip); } - util_blitter_save_vertex_buffers(rctx->blitter, rctx->nvertex_buffer, rctx->vertex_buffer); + util_blitter_save_vertex_buffers(rctx->blitter, rctx->nvertex_buffers, rctx->vertex_buffer); rctx->vertex_elements = NULL; diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h index 360ee2af1fc..301888abc78 100644 --- a/src/gallium/drivers/r600/r600_pipe.h +++ b/src/gallium/drivers/r600/r600_pipe.h @@ -125,6 +125,7 @@ struct r600_translate_context { struct translate_cache *translate_cache; /* The vertex buffer slot containing the translated buffer. */ unsigned vb_slot; + void *saved_velems; void *new_velems; }; @@ -145,7 +146,8 @@ struct r600_pipe_context { struct pipe_index_buffer index_buffer; struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; struct pipe_resource *real_vertex_buffer[PIPE_MAX_ATTRIBS]; - unsigned nvertex_buffer; + unsigned nvertex_buffers; + unsigned nreal_vertex_buffers; /* with the translated vertex buffer */ unsigned cb_target_mask; /* for saving when using blitter */ struct pipe_stencil_ref stencil_ref; diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c index 409a07bda17..4a2c7fe935c 100644 --- a/src/gallium/drivers/r600/r600_state_common.c +++ b/src/gallium/drivers/r600/r600_state_common.c @@ -205,7 +205,7 @@ void r600_set_vertex_buffers(struct pipe_context *ctx, unsigned count, } } - for (; i < rctx->nvertex_buffer; i++) { + for (; i < rctx->nreal_vertex_buffers; i++) { pipe_resource_reference(&rctx->vertex_buffer[i].buffer, NULL); pipe_resource_reference(&rctx->real_vertex_buffer[i], NULL); @@ -219,7 +219,8 @@ void r600_set_vertex_buffers(struct pipe_context *ctx, unsigned count, memcpy(rctx->vertex_buffer, buffers, sizeof(struct pipe_vertex_buffer) * count); - rctx->nvertex_buffer = count; + rctx->nvertex_buffers = count; + rctx->nreal_vertex_buffers = count; rctx->vb_max_index = max_index; } @@ -252,6 +253,28 @@ void *r600_create_vertex_elements(struct pipe_context *ctx, FORMAT_REPLACE(R64G64_FLOAT, R32G32_FLOAT); FORMAT_REPLACE(R64G64B64_FLOAT, R32G32B32_FLOAT); FORMAT_REPLACE(R64G64B64A64_FLOAT, R32G32B32A32_FLOAT); + + /* r600 doesn't seem to support 32_*SCALED, these formats + * aren't in D3D10 either. */ + FORMAT_REPLACE(R32_UNORM, R32_FLOAT); + FORMAT_REPLACE(R32G32_UNORM, R32G32_FLOAT); + FORMAT_REPLACE(R32G32B32_UNORM, R32G32B32_FLOAT); + FORMAT_REPLACE(R32G32B32A32_UNORM, R32G32B32A32_FLOAT); + + FORMAT_REPLACE(R32_USCALED, R32_FLOAT); + FORMAT_REPLACE(R32G32_USCALED, R32G32_FLOAT); + FORMAT_REPLACE(R32G32B32_USCALED, R32G32B32_FLOAT); + FORMAT_REPLACE(R32G32B32A32_USCALED,R32G32B32A32_FLOAT); + + FORMAT_REPLACE(R32_SNORM, R32_FLOAT); + FORMAT_REPLACE(R32G32_SNORM, R32G32_FLOAT); + FORMAT_REPLACE(R32G32B32_SNORM, R32G32B32_FLOAT); + FORMAT_REPLACE(R32G32B32A32_SNORM, R32G32B32A32_FLOAT); + + FORMAT_REPLACE(R32_SSCALED, R32_FLOAT); + FORMAT_REPLACE(R32G32_SSCALED, R32G32_FLOAT); + FORMAT_REPLACE(R32G32B32_SSCALED, R32G32B32_FLOAT); + FORMAT_REPLACE(R32G32B32A32_SSCALED,R32G32B32A32_FLOAT); default:; } v->incompatible_layout = @@ -426,7 +449,7 @@ static void r600_vertex_buffer_update(struct r600_pipe_context *rctx) rctx->nvs_resource = rctx->vertex_elements->count; } else { /* bind vertex buffer once */ - rctx->nvs_resource = rctx->nvertex_buffer; + rctx->nvs_resource = rctx->nreal_vertex_buffers; } for (i = 0 ; i < rctx->nvs_resource; i++) { diff --git a/src/gallium/drivers/r600/r600_translate.c b/src/gallium/drivers/r600/r600_translate.c index f80fa7af941..5f63af59ccc 100644 --- a/src/gallium/drivers/r600/r600_translate.c +++ b/src/gallium/drivers/r600/r600_translate.c @@ -98,14 +98,14 @@ void r600_begin_vertex_translate(struct r600_pipe_context *rctx) tr = translate_cache_find(rctx->tran.translate_cache, &key); /* Map buffers we want to translate. */ - for (i = 0; i < rctx->nvertex_buffer; i++) { + 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->stride, vb->max_index); + tr->set_buffer(tr, i, vb_map[i], vb->stride, ~0); } } @@ -123,7 +123,7 @@ void r600_begin_vertex_translate(struct r600_pipe_context *rctx) tr->run(tr, 0, num_verts, 0, out_map); /* Unmap all buffers. */ - for (i = 0; i < rctx->nvertex_buffer; i++) { + for (i = 0; i < rctx->nvertex_buffers; i++) { if (vb_translated[i]) { pipe_buffer_unmap(pipe, vb_transfer[i]); } @@ -136,11 +136,14 @@ void r600_begin_vertex_translate(struct r600_pipe_context *rctx) struct pipe_vertex_buffer *vb = &rctx->vertex_buffer[i]; if (!vb->buffer) { - pipe_resource_reference(&vb->buffer, out_buffer); + pipe_resource_reference(&rctx->real_vertex_buffer[i], out_buffer); vb->buffer_offset = 0; - vb->max_index = num_verts - 1; vb->stride = key.output_stride; rctx->tran.vb_slot = i; + + if (i >= rctx->nvertex_buffers) { + rctx->nreal_vertex_buffers = i+1; + } break; } } @@ -159,6 +162,7 @@ void r600_begin_vertex_translate(struct r600_pipe_context *rctx) } } + rctx->tran.saved_velems = rctx->vertex_elements; tmp = pipe->create_vertex_elements_state(pipe, ve->count, new_velems); pipe->bind_vertex_elements_state(pipe, tmp); rctx->tran.new_velems = tmp; @@ -174,11 +178,14 @@ void r600_end_vertex_translate(struct r600_pipe_context *rctx) 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->vertex_buffer[rctx->tran.vb_slot].buffer, NULL); + 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, @@ -192,8 +199,5 @@ void r600_translate_index_buffer(struct r600_pipe_context *r600, *index_size = 2; *start = 0; break; - case 2: - case 4: - break; } } -- 2.30.2