summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/r300
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2012-04-24 21:14:44 +0200
committerMarek Olšák <[email protected]>2012-04-30 01:14:28 +0200
commitbf469f4edc60bd1c5fd770cb231b8d5ab801427f (patch)
tree74a5142a56ed68728d35cba02283e5f118ec6ea3 /src/gallium/drivers/r300
parent43995c9470dd38cf80a60a169f5875de6798863f (diff)
gallium: add void *user_buffer in pipe_index_buffer
Adapted drivers: i915, llvmpipe, r300, r600, radeonsi, softpipe. User index buffers have been disabled in nv30, nv50, nvc0 and svga to keep things working.
Diffstat (limited to 'src/gallium/drivers/r300')
-rw-r--r--src/gallium/drivers/r300/r300_context.h3
-rw-r--r--src/gallium/drivers/r300/r300_render.c47
-rw-r--r--src/gallium/drivers/r300/r300_render_translate.c25
-rw-r--r--src/gallium/drivers/r300/r300_screen_buffer.c2
-rw-r--r--src/gallium/drivers/r300/r300_screen_buffer.h2
5 files changed, 41 insertions, 38 deletions
diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h
index ca57a5c7857..b58f514c358 100644
--- a/src/gallium/drivers/r300/r300_context.h
+++ b/src/gallium/drivers/r300/r300_context.h
@@ -692,7 +692,8 @@ void r300_stop_query(struct r300_context *r300);
/* r300_render_translate.c */
void r300_translate_index_buffer(struct r300_context *r300,
- struct pipe_resource **index_buffer,
+ struct pipe_index_buffer *ib,
+ struct pipe_resource **out_index_buffer,
unsigned *index_size, unsigned index_offset,
unsigned *start, unsigned count);
diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c
index 76165f51a1b..56f480d3358 100644
--- a/src/gallium/drivers/r300/r300_render.c
+++ b/src/gallium/drivers/r300/r300_render.c
@@ -508,9 +508,9 @@ static void r300_emit_draw_elements(struct r300_context *r300,
static void r300_draw_elements_immediate(struct r300_context *r300,
const struct pipe_draw_info *info)
{
- uint8_t *ptr1;
- uint16_t *ptr2;
- uint32_t *ptr4;
+ const uint8_t *ptr1;
+ const uint16_t *ptr2;
+ const uint32_t *ptr4;
unsigned index_size = r300->index_buffer.index_size;
unsigned i, count_dwords = index_size == 4 ? info->count :
(info->count + 1) / 2;
@@ -529,7 +529,7 @@ static void r300_draw_elements_immediate(struct r300_context *r300,
switch (index_size) {
case 1:
- ptr1 = r300->index_buffer.buffer->user_ptr;
+ ptr1 = (uint8_t*)r300->index_buffer.user_buffer;
ptr1 += info->start;
OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (info->count << 16) |
@@ -553,7 +553,7 @@ static void r300_draw_elements_immediate(struct r300_context *r300,
break;
case 2:
- ptr2 = (uint16_t*)r300->index_buffer.buffer->user_ptr;
+ ptr2 = (uint16_t*)r300->index_buffer.user_buffer;
ptr2 += info->start;
OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (info->count << 16) |
@@ -572,7 +572,7 @@ static void r300_draw_elements_immediate(struct r300_context *r300,
break;
case 4:
- ptr4 = (uint32_t*)r300->index_buffer.buffer->user_ptr;
+ ptr4 = (uint32_t*)r300->index_buffer.user_buffer;
ptr4 += info->start;
OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (info->count << 16) |
@@ -606,15 +606,15 @@ static void r300_draw_elements(struct r300_context *r300,
uint16_t indices3[3];
if (info->index_bias && !r300->screen->caps.is_r500) {
- r300_split_index_bias(r300, info->index_bias, &buffer_offset, &index_offset);
+ r300_split_index_bias(r300, info->index_bias, &buffer_offset,
+ &index_offset);
}
- r300_translate_index_buffer(r300, &indexBuffer, &indexSize, index_offset,
- &start, count);
+ r300_translate_index_buffer(r300, &r300->index_buffer, &indexBuffer,
+ &indexSize, index_offset, &start, count);
/* Fallback for misaligned ushort indices. */
- if (indexSize == 2 && (start & 1) &&
- !indexBuffer->user_ptr) {
+ if (indexSize == 2 && (start & 1) && indexBuffer) {
/* If we got here, then orgIndexBuffer == indexBuffer. */
uint16_t *ptr = r300->rws->buffer_map(r300_resource(orgIndexBuffer)->cs_buf,
r300->cs,
@@ -632,10 +632,10 @@ static void r300_draw_elements(struct r300_context *r300,
}
r300->rws->buffer_unmap(r300_resource(orgIndexBuffer)->cs_buf);
} else {
- if (indexBuffer->user_ptr)
+ if (r300->index_buffer.user_buffer)
r300_upload_index_buffer(r300, &indexBuffer, indexSize,
&start, count,
- indexBuffer->user_ptr);
+ r300->index_buffer.user_buffer);
}
/* 19 dwords for emit_draw_elements. Give up if the function fails. */
@@ -795,7 +795,7 @@ static void r300_draw_vbo(struct pipe_context* pipe,
struct r300_context* r300 = r300_context(pipe);
struct pipe_draw_info info = *dinfo;
- info.indexed = info.indexed && r300->index_buffer.buffer;
+ info.indexed = info.indexed;
if (r300->skip_rendering ||
!u_trim_pipe_prim(info.mode, &info.count)) {
@@ -824,7 +824,7 @@ static void r300_draw_vbo(struct pipe_context* pipe,
if (info.instance_count <= 1) {
if (info.count <= 8 &&
- r300->index_buffer.buffer->user_ptr) {
+ r300->index_buffer.user_buffer) {
r300_draw_elements_immediate(r300, &info);
} else {
r300_draw_elements(r300, &info, -1);
@@ -858,8 +858,8 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe,
struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS];
struct pipe_transfer *ib_transfer = NULL;
int i;
- void *indices = NULL;
- boolean indexed = info->indexed && r300->index_buffer.buffer;
+ const void *indices = NULL;
+ boolean indexed = info->indexed;
if (r300->skip_rendering) {
return;
@@ -887,9 +887,13 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe,
}
if (indexed) {
- indices = pipe_buffer_map(pipe, r300->index_buffer.buffer,
- PIPE_TRANSFER_READ |
- PIPE_TRANSFER_UNSYNCHRONIZED, &ib_transfer);
+ if (r300->index_buffer.user_buffer) {
+ indices = r300->index_buffer.user_buffer;
+ } else {
+ indices = pipe_buffer_map(pipe, r300->index_buffer.buffer,
+ PIPE_TRANSFER_READ |
+ PIPE_TRANSFER_UNSYNCHRONIZED, &ib_transfer);
+ }
}
draw_set_mapped_index_buffer(r300->draw, indices);
@@ -909,7 +913,8 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe,
}
if (indexed) {
- pipe_buffer_unmap(pipe, ib_transfer);
+ if (ib_transfer)
+ pipe_buffer_unmap(pipe, ib_transfer);
draw_set_mapped_index_buffer(r300->draw, NULL);
}
}
diff --git a/src/gallium/drivers/r300/r300_render_translate.c b/src/gallium/drivers/r300/r300_render_translate.c
index 022e8a7fc70..caeeec05909 100644
--- a/src/gallium/drivers/r300/r300_render_translate.c
+++ b/src/gallium/drivers/r300/r300_render_translate.c
@@ -26,55 +26,52 @@
void r300_translate_index_buffer(struct r300_context *r300,
- struct pipe_resource **index_buffer,
+ struct pipe_index_buffer *ib,
+ struct pipe_resource **out_buffer,
unsigned *index_size, unsigned index_offset,
unsigned *start, unsigned count)
{
- struct pipe_resource *out_buffer = NULL;
unsigned out_offset;
void *ptr;
switch (*index_size) {
case 1:
+ *out_buffer = NULL;
u_upload_alloc(r300->uploader, 0, count * 2,
- &out_offset, &out_buffer, &ptr);
+ &out_offset, out_buffer, &ptr);
util_shorten_ubyte_elts_to_userptr(
- &r300->context, *index_buffer, index_offset,
+ &r300->context, ib, index_offset,
*start, count, ptr);
- *index_buffer = NULL;
- pipe_resource_reference(index_buffer, out_buffer);
*index_size = 2;
*start = out_offset / 2;
break;
case 2:
if (index_offset) {
+ *out_buffer = NULL;
u_upload_alloc(r300->uploader, 0, count * 2,
- &out_offset, &out_buffer, &ptr);
+ &out_offset, out_buffer, &ptr);
- util_rebuild_ushort_elts_to_userptr(&r300->context, *index_buffer,
+ util_rebuild_ushort_elts_to_userptr(&r300->context, ib,
index_offset, *start,
count, ptr);
- *index_buffer = NULL;
- pipe_resource_reference(index_buffer, out_buffer);
*start = out_offset / 2;
}
break;
case 4:
if (index_offset) {
+ *out_buffer = NULL;
u_upload_alloc(r300->uploader, 0, count * 4,
- &out_offset, &out_buffer, &ptr);
+ &out_offset, out_buffer, &ptr);
- util_rebuild_uint_elts_to_userptr(&r300->context, *index_buffer,
+ util_rebuild_uint_elts_to_userptr(&r300->context, ib,
index_offset, *start,
count, ptr);
- *index_buffer = NULL;
- pipe_resource_reference(index_buffer, out_buffer);
*start = out_offset / 4;
}
break;
diff --git a/src/gallium/drivers/r300/r300_screen_buffer.c b/src/gallium/drivers/r300/r300_screen_buffer.c
index d05c9149287..b7deb5f49a5 100644
--- a/src/gallium/drivers/r300/r300_screen_buffer.c
+++ b/src/gallium/drivers/r300/r300_screen_buffer.c
@@ -35,7 +35,7 @@
void r300_upload_index_buffer(struct r300_context *r300,
struct pipe_resource **index_buffer,
unsigned index_size, unsigned *start,
- unsigned count, uint8_t *ptr)
+ unsigned count, const uint8_t *ptr)
{
unsigned index_offset;
diff --git a/src/gallium/drivers/r300/r300_screen_buffer.h b/src/gallium/drivers/r300/r300_screen_buffer.h
index 360ec509cc5..482b6e424ed 100644
--- a/src/gallium/drivers/r300/r300_screen_buffer.h
+++ b/src/gallium/drivers/r300/r300_screen_buffer.h
@@ -39,7 +39,7 @@
void r300_upload_index_buffer(struct r300_context *r300,
struct pipe_resource **index_buffer,
unsigned index_size, unsigned *start,
- unsigned count, uint8_t *ptr);
+ unsigned count, const uint8_t *ptr);
struct pipe_resource *r300_buffer_create(struct pipe_screen *screen,
const struct pipe_resource *templ);