aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/gallium/auxiliary
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2012-01-06 19:47:46 +0100
committerMarc Haesen <marc@hc-consult.be>2012-01-06 19:47:46 +0100
commit2d52fd67e716caae85bce150b01bc5c284b12de7 (patch)
tree2a641392a6affe99603cbaf169c1ab5173879d27 /mesalib/src/gallium/auxiliary
parentd515b895dc5151d102f33b577cafbf63473bbafa (diff)
parent7e9f4ea970e8f7008c212d7d3918a974eb0066da (diff)
downloadvcxsrv-2d52fd67e716caae85bce150b01bc5c284b12de7.tar.gz
vcxsrv-2d52fd67e716caae85bce150b01bc5c284b12de7.tar.bz2
vcxsrv-2d52fd67e716caae85bce150b01bc5c284b12de7.zip
Merge remote-tracking branch 'origin/released'
Conflicts: mesalib/src/glsl/link_uniforms.cpp mesalib/src/mesa/drivers/dri/common/drisw_util.c
Diffstat (limited to 'mesalib/src/gallium/auxiliary')
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_blitter.c65
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_blitter.h18
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_debug.h5
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_dump.h2
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_dump_state.c32
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_format.h22
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_format_latc.c7
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_format_pack.py2
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_format_parse.py3
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_format_rgtc.c11
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_format_table.py12
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_inlines.h7
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_tile.c28
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_upload_mgr.c19
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_upload_mgr.h7
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_vbuf.c557
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_vbuf.h2
17 files changed, 601 insertions, 198 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_blitter.c b/mesalib/src/gallium/auxiliary/util/u_blitter.c
index 3c501814e..80fdfe0a9 100644
--- a/mesalib/src/gallium/auxiliary/util/u_blitter.c
+++ b/mesalib/src/gallium/auxiliary/util/u_blitter.c
@@ -850,6 +850,43 @@ boolean is_overlap(unsigned sx1, unsigned sx2, unsigned sy1, unsigned sy2,
return sx1 < dx2 && sx2 > dx1 && sy1 < dy2 && sy2 > dy1;
}
+void util_blitter_default_dst_texture(struct pipe_surface *dst_templ,
+ struct pipe_resource *dst,
+ unsigned dstlevel,
+ unsigned dstz,
+ const struct pipe_box *srcbox)
+{
+ memset(dst_templ, 0, sizeof(*dst_templ));
+ dst_templ->format = dst->format;
+ if (util_format_is_depth_or_stencil(dst->format)) {
+ dst_templ->usage = PIPE_BIND_DEPTH_STENCIL;
+ } else {
+ dst_templ->usage = PIPE_BIND_RENDER_TARGET;
+ }
+ dst_templ->format = util_format_linear(dst->format);
+ dst_templ->u.tex.level = dstlevel;
+ dst_templ->u.tex.first_layer = dstz;
+ dst_templ->u.tex.last_layer = dstz + srcbox->depth - 1;
+}
+
+void util_blitter_default_src_texture(struct pipe_sampler_view *src_templ,
+ struct pipe_resource *src,
+ unsigned srclevel)
+{
+ memset(src_templ, 0, sizeof(*src_templ));
+ src_templ->format = util_format_linear(src->format);
+ src_templ->u.tex.first_level = srclevel;
+ src_templ->u.tex.last_level = srclevel;
+ src_templ->u.tex.first_layer = 0;
+ src_templ->u.tex.last_layer =
+ src->target == PIPE_TEXTURE_3D ? src->depth0 - 1
+ : src->array_size - 1;
+ src_templ->swizzle_r = PIPE_SWIZZLE_RED;
+ src_templ->swizzle_g = PIPE_SWIZZLE_GREEN;
+ src_templ->swizzle_b = PIPE_SWIZZLE_BLUE;
+ src_templ->swizzle_a = PIPE_SWIZZLE_ALPHA;
+}
+
void util_blitter_copy_texture(struct blitter_context *blitter,
struct pipe_resource *dst,
unsigned dstlevel,
@@ -862,8 +899,8 @@ void util_blitter_copy_texture(struct blitter_context *blitter,
struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter;
struct pipe_context *pipe = ctx->base.pipe;
struct pipe_screen *screen = pipe->screen;
- struct pipe_surface *dstsurf, surf_templ;
- struct pipe_sampler_view viewTempl, *view;
+ struct pipe_surface *dst_view, dst_templ;
+ struct pipe_sampler_view src_templ, *src_view;
unsigned bind;
boolean is_stencil, is_depth;
@@ -898,27 +935,19 @@ void util_blitter_copy_texture(struct blitter_context *blitter,
}
/* Initialize the surface. */
- memset(&surf_templ, 0, sizeof(surf_templ));
- u_surface_default_template(&surf_templ, dst, bind);
- surf_templ.format = util_format_linear(dst->format);
- surf_templ.u.tex.level = dstlevel;
- surf_templ.u.tex.first_layer = dstz;
- surf_templ.u.tex.last_layer = dstz + srcbox->depth - 1;
- dstsurf = pipe->create_surface(pipe, dst, &surf_templ);
+ util_blitter_default_dst_texture(&dst_templ, dst, dstlevel, dstz, srcbox);
+ dst_view = pipe->create_surface(pipe, dst, &dst_templ);
/* Initialize the sampler view. */
- u_sampler_view_default_template(&viewTempl, src,
- util_format_linear(src->format));
- viewTempl.u.tex.first_level = srclevel;
- viewTempl.u.tex.last_level = srclevel;
- view = pipe->create_sampler_view(pipe, src, &viewTempl);
+ util_blitter_default_src_texture(&src_templ, src, srclevel);
+ src_view = pipe->create_sampler_view(pipe, src, &src_templ);
/* Copy. */
- util_blitter_copy_texture_view(blitter, dstsurf, dstx, dsty, view, srcbox,
- src->width0, src->height0);
+ util_blitter_copy_texture_view(blitter, dst_view, dstx, dsty, src_view,
+ srcbox, src->width0, src->height0);
- pipe_surface_reference(&dstsurf, NULL);
- pipe_sampler_view_reference(&view, NULL);
+ pipe_surface_reference(&dst_view, NULL);
+ pipe_sampler_view_reference(&src_view, NULL);
}
void util_blitter_copy_texture_view(struct blitter_context *blitter,
diff --git a/mesalib/src/gallium/auxiliary/util/u_blitter.h b/mesalib/src/gallium/auxiliary/util/u_blitter.h
index f605a7e7a..4dd64c516 100644
--- a/mesalib/src/gallium/auxiliary/util/u_blitter.h
+++ b/mesalib/src/gallium/auxiliary/util/u_blitter.h
@@ -218,6 +218,24 @@ void util_blitter_copy_texture_view(struct blitter_context *blitter,
unsigned src_width0, unsigned src_height0);
/**
+ * Helper function to initialize a view for copy_texture_view.
+ * The parameters must match copy_texture_view.
+ */
+void util_blitter_default_dst_texture(struct pipe_surface *dst_templ,
+ struct pipe_resource *dst,
+ unsigned dstlevel,
+ unsigned dstz,
+ const struct pipe_box *srcbox);
+
+/**
+ * Helper function to initialize a view for copy_texture_view.
+ * The parameters must match copy_texture_view.
+ */
+void util_blitter_default_src_texture(struct pipe_sampler_view *src_templ,
+ struct pipe_resource *src,
+ unsigned srclevel);
+
+/**
* Copy data from one buffer to another using the Stream Output functionality.
* Some alignment is required, otherwise software fallback is used.
*/
diff --git a/mesalib/src/gallium/auxiliary/util/u_debug.h b/mesalib/src/gallium/auxiliary/util/u_debug.h
index b5ea40506..cbea35830 100644
--- a/mesalib/src/gallium/auxiliary/util/u_debug.h
+++ b/mesalib/src/gallium/auxiliary/util/u_debug.h
@@ -91,8 +91,11 @@ debug_printf(const char *format, ...)
(void) format; /* silence warning */
#endif
}
+#else /* is Haiku */
+/* Haiku provides debug_printf in libroot with OS.h */
+#include <OS.h>
+#endif
-#endif /* !PIPE_OS_HAIKU */
/*
* ... isn't portable so we need to pass arguments in parentheses.
diff --git a/mesalib/src/gallium/auxiliary/util/u_dump.h b/mesalib/src/gallium/auxiliary/util/u_dump.h
index 3890b3bdd..87d84bead 100644
--- a/mesalib/src/gallium/auxiliary/util/u_dump.h
+++ b/mesalib/src/gallium/auxiliary/util/u_dump.h
@@ -162,6 +162,8 @@ void
util_dump_vertex_element(FILE *stream,
const struct pipe_vertex_element *state);
+void
+util_dump_draw_info(FILE *stream, const struct pipe_draw_info *state);
/* FIXME: Move the other debug_dump_xxx functions out of u_debug.h into here. */
diff --git a/mesalib/src/gallium/auxiliary/util/u_dump_state.c b/mesalib/src/gallium/auxiliary/util/u_dump_state.c
index 91f4aae69..e44c6194c 100644
--- a/mesalib/src/gallium/auxiliary/util/u_dump_state.c
+++ b/mesalib/src/gallium/auxiliary/util/u_dump_state.c
@@ -725,3 +725,35 @@ util_dump_vertex_element(FILE *stream, const struct pipe_vertex_element *state)
util_dump_struct_end(stream);
}
+
+
+void
+util_dump_draw_info(FILE *stream, const struct pipe_draw_info *state)
+{
+ if(!state) {
+ util_dump_null(stream);
+ return;
+ }
+
+ util_dump_struct_begin(stream, "pipe_draw_info");
+
+ util_dump_member(stream, bool, state, indexed);
+
+ util_dump_member(stream, uint, state, mode);
+ util_dump_member(stream, uint, state, start);
+ util_dump_member(stream, uint, state, count);
+
+ util_dump_member(stream, uint, state, start_instance);
+ util_dump_member(stream, uint, state, instance_count);
+
+ util_dump_member(stream, int, state, index_bias);
+ util_dump_member(stream, uint, state, min_index);
+ util_dump_member(stream, uint, state, max_index);
+
+ util_dump_member(stream, bool, state, primitive_restart);
+ util_dump_member(stream, uint, state, restart_index);
+
+ util_dump_member(stream, ptr, state, count_from_stream_output);
+
+ util_dump_struct_end(stream);
+}
diff --git a/mesalib/src/gallium/auxiliary/util/u_format.h b/mesalib/src/gallium/auxiliary/util/u_format.h
index 9694c9034..874ea7eb1 100644
--- a/mesalib/src/gallium/auxiliary/util/u_format.h
+++ b/mesalib/src/gallium/auxiliary/util/u_format.h
@@ -254,7 +254,7 @@ struct util_format_description
/**
* Fetch a single pixel (i, j) from a block.
*
- * Only defined for non-depth-stencil formats.
+ * Only defined for non-depth-stencil and non-integer formats.
*/
void
(*fetch_rgba_float)(float *dst,
@@ -358,6 +358,26 @@ struct util_format_description
(*pack_rgba_sint)(uint8_t *dst, unsigned dst_stride,
const int *src, unsigned src_stride,
unsigned width, unsigned height);
+
+ /**
+ * Fetch a single pixel (i, j) from a block.
+ *
+ * Only defined for unsigned (pure) integer formats.
+ */
+ void
+ (*fetch_rgba_uint)(uint32_t *dst,
+ const uint8_t *src,
+ unsigned i, unsigned j);
+
+ /**
+ * Fetch a single pixel (i, j) from a block.
+ *
+ * Only defined for signed (pure) integer formats.
+ */
+ void
+ (*fetch_rgba_sint)(int32_t *dst,
+ const uint8_t *src,
+ unsigned i, unsigned j);
};
diff --git a/mesalib/src/gallium/auxiliary/util/u_format_latc.c b/mesalib/src/gallium/auxiliary/util/u_format_latc.c
index 113a793e2..20feb241e 100644
--- a/mesalib/src/gallium/auxiliary/util/u_format_latc.c
+++ b/mesalib/src/gallium/auxiliary/util/u_format_latc.c
@@ -47,6 +47,9 @@ util_format_latc1_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsi
(void) u_format_signed_encode_rgtc_ubyte;
u_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 1);
+ dst[1] = dst[0];
+ dst[2] = dst[0];
+ dst[3] = 255;
}
void
@@ -173,7 +176,9 @@ void
util_format_latc2_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
{
u_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 2);
- u_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, dst + 1, 2);
+ dst[1] = dst[0];
+ dst[2] = dst[0];
+ u_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, dst + 3, 2);
}
void
diff --git a/mesalib/src/gallium/auxiliary/util/u_format_pack.py b/mesalib/src/gallium/auxiliary/util/u_format_pack.py
index fff409fb7..0b3a890d5 100644
--- a/mesalib/src/gallium/auxiliary/util/u_format_pack.py
+++ b/mesalib/src/gallium/auxiliary/util/u_format_pack.py
@@ -686,6 +686,7 @@ def generate(formats):
generate_format_unpack(format, channel, native_type, suffix)
generate_format_pack(format, channel, native_type, suffix)
+ generate_format_fetch(format, channel, native_type, suffix)
channel = Channel(SIGNED, False, True, 32)
native_type = 'int'
@@ -699,6 +700,7 @@ def generate(formats):
generate_format_unpack(format, channel, native_type, suffix)
generate_format_pack(format, channel, native_type, suffix)
+ generate_format_fetch(format, channel, native_type, suffix)
native_type = 'unsigned'
suffix = 'unsigned'
diff --git a/mesalib/src/gallium/auxiliary/util/u_format_parse.py b/mesalib/src/gallium/auxiliary/util/u_format_parse.py
index 73a4bcb21..3a39e5ba5 100644
--- a/mesalib/src/gallium/auxiliary/util/u_format_parse.py
+++ b/mesalib/src/gallium/auxiliary/util/u_format_parse.py
@@ -196,10 +196,11 @@ class Format:
def inv_swizzles(self):
'''Return an array[4] of inverse swizzle terms'''
+ '''Only pick the first matching value to avoid l8 getting blue and i8 getting alpha'''
inv_swizzle = [None]*4
for i in range(4):
swizzle = self.swizzles[i]
- if swizzle < 4:
+ if swizzle < 4 and inv_swizzle[swizzle] == None:
inv_swizzle[swizzle] = i
return inv_swizzle
diff --git a/mesalib/src/gallium/auxiliary/util/u_format_rgtc.c b/mesalib/src/gallium/auxiliary/util/u_format_rgtc.c
index 2371bab1e..ff04e37b5 100644
--- a/mesalib/src/gallium/auxiliary/util/u_format_rgtc.c
+++ b/mesalib/src/gallium/auxiliary/util/u_format_rgtc.c
@@ -42,6 +42,9 @@ void
util_format_rgtc1_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
{
u_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 1);
+ dst[1] = 0;
+ dst[2] = 0;
+ dst[3] = 255;
}
void
@@ -58,6 +61,9 @@ util_format_rgtc1_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride
for(i = 0; i < bw; ++i) {
uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*comps;
u_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 1);
+ dst[1] = 0;
+ dst[2] = 0;
+ dst[3] = 255;
}
}
src += block_size;
@@ -229,6 +235,8 @@ util_format_rgtc2_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsi
{
u_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 2);
u_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, dst + 1, 2);
+ dst[2] = 0;
+ dst[3] = 255;
}
void
@@ -246,7 +254,8 @@ util_format_rgtc2_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride
uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*comps;
u_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 2);
u_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, dst + 1, 2);
-
+ dst[2] = 0;
+ dst[3] = 255;
}
}
src += block_size;
diff --git a/mesalib/src/gallium/auxiliary/util/u_format_table.py b/mesalib/src/gallium/auxiliary/util/u_format_table.py
index 07beb3872..8edb50523 100644
--- a/mesalib/src/gallium/auxiliary/util/u_format_table.py
+++ b/mesalib/src/gallium/auxiliary/util/u_format_table.py
@@ -169,17 +169,23 @@ def write_format_table(formats):
print " &util_format_%s_unpack_unsigned, /* unpack_rgba_uint */" % format.short_name()
print " &util_format_%s_pack_unsigned, /* pack_rgba_uint */" % format.short_name()
print " &util_format_%s_unpack_signed, /* unpack_rgba_sint */" % format.short_name()
- print " &util_format_%s_pack_signed /* pack_rgba_sint */" % format.short_name()
+ print " &util_format_%s_pack_signed, /* pack_rgba_sint */" % format.short_name()
+ print " &util_format_%s_fetch_unsigned, /* fetch_rgba_uint */" % format.short_name()
+ print " NULL /* fetch_rgba_sint */"
elif format.colorspace != ZS and format.channels[0].pure == True and format.channels[0].type == SIGNED:
print " &util_format_%s_unpack_unsigned, /* unpack_rgba_uint */" % format.short_name()
print " &util_format_%s_pack_unsigned, /* pack_rgba_uint */" % format.short_name()
print " &util_format_%s_unpack_signed, /* unpack_rgba_sint */" % format.short_name()
- print " &util_format_%s_pack_signed /* pack_rgba_sint */" % format.short_name()
+ print " &util_format_%s_pack_signed, /* pack_rgba_sint */" % format.short_name()
+ print " NULL, /* fetch_rgba_uint */"
+ print " &util_format_%s_fetch_signed /* fetch_rgba_sint */" % format.short_name()
else:
print " NULL, /* unpack_rgba_uint */"
print " NULL, /* pack_rgba_uint */"
print " NULL, /* unpack_rgba_sint */"
- print " NULL /* pack_rgba_sint */"
+ print " NULL, /* pack_rgba_sint */"
+ print " NULL, /* fetch_rgba_uint */"
+ print " NULL /* fetch_rgba_sint */"
print "};"
print
diff --git a/mesalib/src/gallium/auxiliary/util/u_inlines.h b/mesalib/src/gallium/auxiliary/util/u_inlines.h
index 44283909a..9660cdc6e 100644
--- a/mesalib/src/gallium/auxiliary/util/u_inlines.h
+++ b/mesalib/src/gallium/auxiliary/util/u_inlines.h
@@ -252,10 +252,7 @@ pipe_buffer_map_range(struct pipe_context *pipe,
return NULL;
}
- /* Match old screen->buffer_map_range() behaviour, return pointer
- * to where the beginning of the buffer would be:
- */
- return (void *)((char *)map - offset);
+ return map;
}
@@ -374,7 +371,7 @@ pipe_buffer_read(struct pipe_context *pipe,
&src_transfer);
if (map)
- memcpy(data, map + offset, size);
+ memcpy(data, map, size);
pipe_buffer_unmap(pipe, src_transfer);
}
diff --git a/mesalib/src/gallium/auxiliary/util/u_tile.c b/mesalib/src/gallium/auxiliary/util/u_tile.c
index 02bdb731d..ea4b91f95 100644
--- a/mesalib/src/gallium/auxiliary/util/u_tile.c
+++ b/mesalib/src/gallium/auxiliary/util/u_tile.c
@@ -344,6 +344,31 @@ z32f_x24s8_get_tile_rgba(const float *src,
}
}
+/*** PIPE_FORMAT_X32_S8X24_UINT ***/
+
+/**
+ * Return S component as four uint32_t in [0..255]. Z part ignored.
+ */
+static void
+x32_s8_get_tile_rgba(const unsigned *src,
+ unsigned w, unsigned h,
+ float *p,
+ unsigned dst_stride)
+{
+ unsigned i, j;
+
+ for (i = 0; i < h; i++) {
+ float *pRow = p;
+ for (j = 0; j < w; j++, pRow += 4) {
+ src++;
+ pRow[0] =
+ pRow[1] =
+ pRow[2] =
+ pRow[3] = (float)(*src++ & 0xff);
+ }
+ p += dst_stride;
+ }
+}
void
pipe_tile_raw_to_rgba(enum pipe_format format,
@@ -381,6 +406,9 @@ pipe_tile_raw_to_rgba(enum pipe_format format,
case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
z32f_x24s8_get_tile_rgba((float *) src, w, h, dst, dst_stride);
break;
+ case PIPE_FORMAT_X32_S8X24_UINT:
+ x32_s8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
+ break;
default:
util_format_read_4f(format,
dst, dst_stride * sizeof(float),
diff --git a/mesalib/src/gallium/auxiliary/util/u_upload_mgr.c b/mesalib/src/gallium/auxiliary/util/u_upload_mgr.c
index a2319d0c4..b4b4c91f1 100644
--- a/mesalib/src/gallium/auxiliary/util/u_upload_mgr.c
+++ b/mesalib/src/gallium/auxiliary/util/u_upload_mgr.c
@@ -158,7 +158,6 @@ enum pipe_error u_upload_alloc( struct u_upload_mgr *upload,
unsigned size,
unsigned *out_offset,
struct pipe_resource **outbuf,
- boolean *flushed,
void **ptr )
{
unsigned alloc_size = align( size, upload->alignment );
@@ -172,10 +171,6 @@ enum pipe_error u_upload_alloc( struct u_upload_mgr *upload,
alloc_offset + alloc_size);
if (ret != PIPE_OK)
return ret;
-
- *flushed = TRUE;
- } else {
- *flushed = FALSE;
}
offset = MAX2(upload->offset, alloc_offset);
@@ -192,6 +187,8 @@ enum pipe_error u_upload_alloc( struct u_upload_mgr *upload,
*ptr = NULL;
return PIPE_ERROR_OUT_OF_MEMORY;
}
+
+ upload->map -= offset;
}
assert(offset < upload->buffer->width0);
@@ -212,12 +209,11 @@ enum pipe_error u_upload_data( struct u_upload_mgr *upload,
unsigned size,
const void *data,
unsigned *out_offset,
- struct pipe_resource **outbuf,
- boolean *flushed )
+ struct pipe_resource **outbuf)
{
uint8_t *ptr;
enum pipe_error ret = u_upload_alloc(upload, min_out_offset, size,
- out_offset, outbuf, flushed,
+ out_offset, outbuf,
(void**)&ptr);
if (ret != PIPE_OK)
return ret;
@@ -238,8 +234,7 @@ enum pipe_error u_upload_buffer( struct u_upload_mgr *upload,
unsigned size,
struct pipe_resource *inbuf,
unsigned *out_offset,
- struct pipe_resource **outbuf,
- boolean *flushed )
+ struct pipe_resource **outbuf)
{
enum pipe_error ret = PIPE_OK;
struct pipe_transfer *transfer = NULL;
@@ -261,9 +256,9 @@ enum pipe_error u_upload_buffer( struct u_upload_mgr *upload,
ret = u_upload_data( upload,
min_out_offset,
size,
- map + offset,
+ map,
out_offset,
- outbuf, flushed );
+ outbuf);
pipe_buffer_unmap( upload->pipe, transfer );
diff --git a/mesalib/src/gallium/auxiliary/util/u_upload_mgr.h b/mesalib/src/gallium/auxiliary/util/u_upload_mgr.h
index 989151398..b50d3f32c 100644
--- a/mesalib/src/gallium/auxiliary/util/u_upload_mgr.h
+++ b/mesalib/src/gallium/auxiliary/util/u_upload_mgr.h
@@ -94,7 +94,6 @@ enum pipe_error u_upload_alloc( struct u_upload_mgr *upload,
unsigned size,
unsigned *out_offset,
struct pipe_resource **outbuf,
- boolean *flushed,
void **ptr );
@@ -109,8 +108,7 @@ enum pipe_error u_upload_data( struct u_upload_mgr *upload,
unsigned size,
const void *data,
unsigned *out_offset,
- struct pipe_resource **outbuf,
- boolean *flushed );
+ struct pipe_resource **outbuf);
/**
@@ -125,8 +123,7 @@ enum pipe_error u_upload_buffer( struct u_upload_mgr *upload,
unsigned size,
struct pipe_resource *inbuf,
unsigned *out_offset,
- struct pipe_resource **outbuf,
- boolean *flushed );
+ struct pipe_resource **outbuf);
diff --git a/mesalib/src/gallium/auxiliary/util/u_vbuf.c b/mesalib/src/gallium/auxiliary/util/u_vbuf.c
index 5b0e26e30..711ad10e8 100644
--- a/mesalib/src/gallium/auxiliary/util/u_vbuf.c
+++ b/mesalib/src/gallium/auxiliary/util/u_vbuf.c
@@ -27,12 +27,15 @@
#include "util/u_vbuf.h"
+#include "util/u_dump.h"
#include "util/u_format.h"
#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_upload_mgr.h"
#include "translate/translate.h"
#include "translate/translate_cache.h"
+#include "cso_cache/cso_cache.h"
+#include "cso_cache/cso_hash.h"
struct u_vbuf_elements {
unsigned count;
@@ -54,10 +57,18 @@ struct u_vbuf_elements {
boolean incompatible_layout_elem[PIPE_MAX_ATTRIBS];
};
+enum {
+ VB_VERTEX = 0,
+ VB_INSTANCE = 1,
+ VB_CONST = 2,
+ VB_NUM = 3
+};
+
struct u_vbuf_priv {
struct u_vbuf b;
struct pipe_context *pipe;
struct translate_cache *translate_cache;
+ struct cso_cache *cso_cache;
/* Vertex element state bound by the state tracker. */
void *saved_ve;
@@ -71,7 +82,7 @@ struct u_vbuf_priv {
void *fallback_ve;
/* The vertex buffer slot index where translated vertices have been
* stored in. */
- unsigned fallback_vb_slot;
+ unsigned fallback_vbs[VB_NUM];
/* When binding the fallback vertex element state, we don't want to
* change saved_ve and ve. This is set to TRUE in such cases. */
boolean ve_binding_lock;
@@ -123,8 +134,9 @@ u_vbuf_create(struct pipe_context *pipe,
struct u_vbuf_priv *mgr = CALLOC_STRUCT(u_vbuf_priv);
mgr->pipe = pipe;
+ mgr->cso_cache = cso_cache_create();
mgr->translate_cache = translate_cache_create();
- mgr->fallback_vb_slot = ~0;
+ memset(mgr->fallback_vbs, ~0, sizeof(mgr->fallback_vbs));
mgr->b.uploader = u_upload_create(pipe, upload_buffer_size,
upload_buffer_alignment,
@@ -138,6 +150,46 @@ u_vbuf_create(struct pipe_context *pipe,
return &mgr->b;
}
+/* XXX I had to fork this off of cso_context. */
+static void *
+u_vbuf_pipe_set_vertex_elements(struct u_vbuf_priv *mgr,
+ unsigned count,
+ const struct pipe_vertex_element *states)
+{
+ unsigned key_size, hash_key;
+ struct cso_hash_iter iter;
+ void *handle;
+ struct cso_velems_state velems_state;
+
+ /* need to include the count into the stored state data too. */
+ key_size = sizeof(struct pipe_vertex_element) * count + sizeof(unsigned);
+ velems_state.count = count;
+ memcpy(velems_state.velems, states,
+ sizeof(struct pipe_vertex_element) * count);
+ hash_key = cso_construct_key((void*)&velems_state, key_size);
+ iter = cso_find_state_template(mgr->cso_cache, hash_key, CSO_VELEMENTS,
+ (void*)&velems_state, key_size);
+
+ if (cso_hash_iter_is_null(iter)) {
+ struct cso_velements *cso = MALLOC_STRUCT(cso_velements);
+ memcpy(&cso->state, &velems_state, key_size);
+ cso->data =
+ mgr->pipe->create_vertex_elements_state(mgr->pipe, count,
+ &cso->state.velems[0]);
+ cso->delete_state =
+ (cso_state_callback)mgr->pipe->delete_vertex_elements_state;
+ cso->context = mgr->pipe;
+
+ iter = cso_insert_state(mgr->cso_cache, hash_key, CSO_VELEMENTS, cso);
+ handle = cso->data;
+ } else {
+ handle = ((struct cso_velements *)cso_hash_iter_data(iter))->data;
+ }
+
+ mgr->pipe->bind_vertex_elements_state(mgr->pipe, handle);
+ return handle;
+}
+
void u_vbuf_destroy(struct u_vbuf *mgrb)
{
struct u_vbuf_priv *mgr = (struct u_vbuf_priv*)mgrb;
@@ -152,15 +204,136 @@ void u_vbuf_destroy(struct u_vbuf *mgrb)
translate_cache_destroy(mgr->translate_cache);
u_upload_destroy(mgr->b.uploader);
+ cso_cache_delete(mgr->cso_cache);
FREE(mgr);
}
+static void
+u_vbuf_translate_buffers(struct u_vbuf_priv *mgr, struct translate_key *key,
+ unsigned vb_mask, unsigned out_vb,
+ int start_vertex, unsigned num_vertices,
+ int start_index, unsigned num_indices, int min_index,
+ bool unroll_indices)
+{
+ struct translate *tr;
+ struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS] = {0};
+ struct pipe_resource *out_buffer = NULL;
+ uint8_t *out_map;
+ unsigned i, out_offset;
+
+ /* Get a translate object. */
+ tr = translate_cache_find(mgr->translate_cache, key);
+
+ /* Map buffers we want to translate. */
+ for (i = 0; i < mgr->b.nr_vertex_buffers; i++) {
+ if (vb_mask & (1 << i)) {
+ struct pipe_vertex_buffer *vb = &mgr->b.vertex_buffer[i];
+ unsigned offset = vb->buffer_offset + vb->stride * start_vertex;
+ uint8_t *map;
+
+ if (u_vbuf_resource(vb->buffer)->user_ptr) {
+ map = u_vbuf_resource(vb->buffer)->user_ptr + offset;
+ } else {
+ unsigned size = vb->stride ? num_vertices * vb->stride
+ : sizeof(double)*4;
+
+ if (offset+size > vb->buffer->width0) {
+ size = vb->buffer->width0 - offset;
+ }
+
+ map = pipe_buffer_map_range(mgr->pipe, vb->buffer, offset, size,
+ PIPE_TRANSFER_READ, &vb_transfer[i]);
+ }
+
+ /* Subtract min_index so that indexing with the index buffer works. */
+ if (unroll_indices) {
+ map -= vb->stride * min_index;
+ }
+
+ tr->set_buffer(tr, i, map, vb->stride, ~0);
+ }
+ }
+
+ /* Translate. */
+ if (unroll_indices) {
+ struct pipe_index_buffer *ib = &mgr->b.index_buffer;
+ struct pipe_transfer *transfer = NULL;
+ unsigned offset = ib->offset + start_index * ib->index_size;
+ uint8_t *map;
+
+ assert(ib->buffer && ib->index_size);
-static unsigned u_vbuf_get_free_real_vb_slot(struct u_vbuf_priv *mgr)
+ if (u_vbuf_resource(ib->buffer)->user_ptr) {
+ map = u_vbuf_resource(ib->buffer)->user_ptr + offset;
+ } else {
+ map = pipe_buffer_map_range(mgr->pipe, ib->buffer, offset,
+ num_indices * ib->index_size,
+ PIPE_TRANSFER_READ, &transfer);
+ }
+
+ /* Create and map the output buffer. */
+ u_upload_alloc(mgr->b.uploader, 0,
+ key->output_stride * num_indices,
+ &out_offset, &out_buffer,
+ (void**)&out_map);
+
+ switch (ib->index_size) {
+ case 4:
+ tr->run_elts(tr, (unsigned*)map, num_indices, 0, out_map);
+ break;
+ case 2:
+ tr->run_elts16(tr, (uint16_t*)map, num_indices, 0, out_map);
+ break;
+ case 1:
+ tr->run_elts8(tr, map, num_indices, 0, out_map);
+ break;
+ }
+
+ if (transfer) {
+ pipe_buffer_unmap(mgr->pipe, transfer);
+ }
+ } else {
+ /* Create and map the output buffer. */
+ u_upload_alloc(mgr->b.uploader,
+ key->output_stride * start_vertex,
+ key->output_stride * num_vertices,
+ &out_offset, &out_buffer,
+ (void**)&out_map);
+
+ out_offset -= key->output_stride * start_vertex;
+
+ tr->run(tr, 0, num_vertices, 0, out_map);
+ }
+
+ /* Unmap all buffers. */
+ for (i = 0; i < mgr->b.nr_vertex_buffers; i++) {
+ if (vb_transfer[i]) {
+ pipe_buffer_unmap(mgr->pipe, vb_transfer[i]);
+ }
+ }
+
+ /* Setup the new vertex buffer. */
+ mgr->b.real_vertex_buffer[out_vb].buffer_offset = out_offset;
+ mgr->b.real_vertex_buffer[out_vb].stride = key->output_stride;
+
+ /* Move the buffer reference. */
+ pipe_resource_reference(
+ &mgr->b.real_vertex_buffer[out_vb].buffer, NULL);
+ mgr->b.real_vertex_buffer[out_vb].buffer = out_buffer;
+}
+
+static boolean
+u_vbuf_translate_find_free_vb_slots(struct u_vbuf_priv *mgr,
+ unsigned mask[VB_NUM])
{
- unsigned i, nr = mgr->ve->count;
+ unsigned i, type;
+ unsigned nr = mgr->ve->count;
boolean used_vb[PIPE_MAX_ATTRIBS] = {0};
+ unsigned fallback_vbs[VB_NUM];
+
+ memset(fallback_vbs, ~0, sizeof(fallback_vbs));
+ /* Mark used vertex buffers as... used. */
for (i = 0; i < nr; i++) {
if (!mgr->ve->incompatible_layout_elem[i]) {
unsigned index = mgr->ve->ve[i].vertex_buffer_index;
@@ -171,179 +344,199 @@ static unsigned u_vbuf_get_free_real_vb_slot(struct u_vbuf_priv *mgr)
}
}
- for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
- if (!used_vb[i]) {
- if (i >= mgr->b.nr_real_vertex_buffers) {
- mgr->b.nr_real_vertex_buffers = i+1;
+ /* Find free slots for each type if needed. */
+ i = 0;
+ for (type = 0; type < VB_NUM; type++) {
+ if (mask[type]) {
+ for (; i < PIPE_MAX_ATTRIBS; i++) {
+ if (!used_vb[i]) {
+ /*printf("found slot=%i for type=%i\n", i, type);*/
+ fallback_vbs[type] = i;
+ i++;
+ if (i > mgr->b.nr_real_vertex_buffers) {
+ mgr->b.nr_real_vertex_buffers = i;
+ }
+ break;
+ }
+ }
+ if (i == PIPE_MAX_ATTRIBS) {
+ /* fail, reset the number to its original value */
+ mgr->b.nr_real_vertex_buffers = mgr->b.nr_vertex_buffers;
+ return FALSE;
}
- return i;
}
}
- return ~0;
+
+ memcpy(mgr->fallback_vbs, fallback_vbs, sizeof(fallback_vbs));
+ return TRUE;
}
-static void
+static boolean
u_vbuf_translate_begin(struct u_vbuf_priv *mgr,
- int min_index, int max_index)
+ int start_vertex, unsigned num_vertices,
+ int start_instance, unsigned num_instances,
+ int start_index, unsigned num_indices, int min_index,
+ bool unroll_indices)
{
- struct translate_key key;
- struct translate_element *te;
- unsigned tr_elem_index[PIPE_MAX_ATTRIBS];
- struct translate *tr;
- boolean vb_translated[PIPE_MAX_ATTRIBS] = {0};
- uint8_t *out_map;
- struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS] = {0};
- struct pipe_resource *out_buffer = NULL;
- unsigned i, num_verts, out_offset;
- boolean upload_flushed = FALSE;
+ unsigned mask[VB_NUM] = {0};
+ struct translate_key key[VB_NUM];
+ unsigned elem_index[VB_NUM][PIPE_MAX_ATTRIBS]; /* ... into key.elements */
+ unsigned i, type;
+
+ int start[VB_NUM] = {
+ start_vertex, /* VERTEX */
+ start_instance, /* INSTANCE */
+ 0 /* CONST */
+ };
+
+ unsigned num[VB_NUM] = {
+ num_vertices, /* VERTEX */
+ num_instances, /* INSTANCE */
+ 1 /* CONST */
+ };
+
+ memset(key, 0, sizeof(key));
+ memset(elem_index, ~0, sizeof(elem_index));
+
+ /* See if there are vertex attribs of each type to translate and
+ * which ones. */
+ for (i = 0; i < mgr->ve->count; i++) {
+ unsigned vb_index = mgr->ve->ve[i].vertex_buffer_index;
- memset(&key, 0, sizeof(key));
- memset(tr_elem_index, 0xff, sizeof(tr_elem_index));
+ if (!mgr->b.vertex_buffer[vb_index].stride) {
+ if (!mgr->ve->incompatible_layout_elem[i] &&
+ !mgr->incompatible_vb[vb_index]) {
+ continue;
+ }
+ mask[VB_CONST] |= 1 << vb_index;
+ } else if (mgr->ve->ve[i].instance_divisor) {
+ if (!mgr->ve->incompatible_layout_elem[i] &&
+ !mgr->incompatible_vb[vb_index]) {
+ continue;
+ }
+ mask[VB_INSTANCE] |= 1 << vb_index;
+ } else {
+ if (!unroll_indices &&
+ !mgr->ve->incompatible_layout_elem[i] &&
+ !mgr->incompatible_vb[vb_index]) {
+ continue;
+ }
+ mask[VB_VERTEX] |= 1 << vb_index;
+ }
+ }
- /* Get a new vertex buffer slot. */
- mgr->fallback_vb_slot = u_vbuf_get_free_real_vb_slot(mgr);
+ assert(mask[VB_VERTEX] || mask[VB_INSTANCE] || mask[VB_CONST]);
- if (mgr->fallback_vb_slot == ~0) {
- return; /* XXX error, not enough attribs */
+ /* Find free vertex buffer slots. */
+ if (!u_vbuf_translate_find_free_vb_slots(mgr, mask)) {
+ return FALSE;
}
- /* Initialize the description of how vertices should be translated. */
+ /* Initialize the translate keys. */
for (i = 0; i < mgr->ve->count; i++) {
- enum pipe_format output_format = mgr->ve->native_format[i];
- unsigned output_format_size = mgr->ve->native_format_size[i];
+ struct translate_key *k;
+ struct translate_element *te;
+ unsigned bit, vb_index = mgr->ve->ve[i].vertex_buffer_index;
+ bit = 1 << vb_index;
- /* Check for support. */
if (!mgr->ve->incompatible_layout_elem[i] &&
- !mgr->incompatible_vb[mgr->ve->ve[i].vertex_buffer_index]) {
+ !mgr->incompatible_vb[vb_index] &&
+ (!unroll_indices || !(mask[VB_VERTEX] & bit))) {
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:;
+ /* Set type to what we will translate.
+ * Whether vertex, instance, or constant attribs. */
+ for (type = 0; type < VB_NUM; type++) {
+ if (mask[type] & bit) {
+ break;
+ }
}
+ assert(type < VB_NUM);
+ assert(translate_is_output_format_supported(mgr->ve->native_format[i]));
+ /*printf("velem=%i type=%i\n", i, type);*/
+
+ /* Add the vertex element. */
+ k = &key[type];
+ elem_index[type][i] = k->nr_elements;
- /* Add this vertex element. */
- te = &key.element[key.nr_elements];
+ te = &k->element[k->nr_elements];
te->type = TRANSLATE_ELEMENT_NORMAL;
te->instance_divisor = 0;
- te->input_buffer = mgr->ve->ve[i].vertex_buffer_index;
+ te->input_buffer = vb_index;
te->input_format = mgr->ve->ve[i].src_format;
te->input_offset = mgr->ve->ve[i].src_offset;
- te->output_format = output_format;
- te->output_offset = key.output_stride;
+ te->output_format = mgr->ve->native_format[i];
+ te->output_offset = k->output_stride;
- key.output_stride += output_format_size;
- vb_translated[mgr->ve->ve[i].vertex_buffer_index] = TRUE;
- tr_elem_index[i] = key.nr_elements;
- key.nr_elements++;
+ k->output_stride += mgr->ve->native_format_size[i];
+ k->nr_elements++;
}
- /* Get a translate object. */
- tr = translate_cache_find(mgr->translate_cache, &key);
-
- /* Map buffers we want to translate. */
- for (i = 0; i < mgr->b.nr_vertex_buffers; i++) {
- if (vb_translated[i]) {
- struct pipe_vertex_buffer *vb = &mgr->b.vertex_buffer[i];
-
- uint8_t *map = pipe_buffer_map(mgr->pipe, vb->buffer,
- PIPE_TRANSFER_READ, &vb_transfer[i]);
-
- tr->set_buffer(tr, i,
- map + 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(mgr->b.uploader,
- key.output_stride * min_index,
- key.output_stride * num_verts,
- &out_offset, &out_buffer, &upload_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 < mgr->b.nr_vertex_buffers; i++) {
- if (vb_translated[i]) {
- pipe_buffer_unmap(mgr->pipe, vb_transfer[i]);
+ /* Translate buffers. */
+ for (type = 0; type < VB_NUM; type++) {
+ if (key[type].nr_elements) {
+ u_vbuf_translate_buffers(mgr, &key[type], mask[type],
+ mgr->fallback_vbs[type],
+ start[type], num[type],
+ start_index, num_indices, min_index,
+ unroll_indices && type == VB_VERTEX);
+
+ /* Fixup the stride for constant attribs. */
+ if (type == VB_CONST) {
+ mgr->b.real_vertex_buffer[mgr->fallback_vbs[VB_CONST]].stride = 0;
+ }
}
}
- /* Setup the new vertex buffer. */
- mgr->b.real_vertex_buffer[mgr->fallback_vb_slot].buffer_offset = out_offset;
- mgr->b.real_vertex_buffer[mgr->fallback_vb_slot].stride = key.output_stride;
-
- /* Move the buffer reference. */
- pipe_resource_reference(
- &mgr->b.real_vertex_buffer[mgr->fallback_vb_slot].buffer, NULL);
- mgr->b.real_vertex_buffer[mgr->fallback_vb_slot].buffer = out_buffer;
- out_buffer = NULL;
-
/* Setup new vertex elements. */
for (i = 0; i < mgr->ve->count; i++) {
- if (tr_elem_index[i] < key.nr_elements) {
- te = &key.element[tr_elem_index[i]];
- mgr->fallback_velems[i].instance_divisor = mgr->ve->ve[i].instance_divisor;
- mgr->fallback_velems[i].src_format = te->output_format;
- mgr->fallback_velems[i].src_offset = te->output_offset;
- mgr->fallback_velems[i].vertex_buffer_index = mgr->fallback_vb_slot;
- } else {
+ for (type = 0; type < VB_NUM; type++) {
+ if (elem_index[type][i] < key[type].nr_elements) {
+ struct translate_element *te = &key[type].element[elem_index[type][i]];
+ mgr->fallback_velems[i].instance_divisor = mgr->ve->ve[i].instance_divisor;
+ mgr->fallback_velems[i].src_format = te->output_format;
+ mgr->fallback_velems[i].src_offset = te->output_offset;
+ mgr->fallback_velems[i].vertex_buffer_index = mgr->fallback_vbs[type];
+
+ /* elem_index[type][i] can only be set for one type. */
+ assert(type > VB_INSTANCE || elem_index[type+1][i] == ~0);
+ assert(type > VB_VERTEX || elem_index[type+2][i] == ~0);
+ break;
+ }
+ }
+ /* No translating, just copy the original vertex element over. */
+ if (type == VB_NUM) {
memcpy(&mgr->fallback_velems[i], &mgr->ve->ve[i],
sizeof(struct pipe_vertex_element));
}
}
-
- mgr->fallback_ve =
- mgr->pipe->create_vertex_elements_state(mgr->pipe, mgr->ve->count,
- mgr->fallback_velems);
-
/* Preserve saved_ve. */
mgr->ve_binding_lock = TRUE;
- mgr->pipe->bind_vertex_elements_state(mgr->pipe, mgr->fallback_ve);
+ mgr->fallback_ve = u_vbuf_pipe_set_vertex_elements(mgr, mgr->ve->count,
+ mgr->fallback_velems);
mgr->ve_binding_lock = FALSE;
+ return TRUE;
}
static void u_vbuf_translate_end(struct u_vbuf_priv *mgr)
{
- if (mgr->fallback_ve == NULL) {
- return;
- }
+ unsigned i;
/* Restore vertex elements. */
/* Note that saved_ve will be overwritten in bind_vertex_elements_state. */
mgr->pipe->bind_vertex_elements_state(mgr->pipe, mgr->saved_ve);
- mgr->pipe->delete_vertex_elements_state(mgr->pipe, mgr->fallback_ve);
mgr->fallback_ve = NULL;
- /* Delete the now-unused VBO. */
- pipe_resource_reference(&mgr->b.real_vertex_buffer[mgr->fallback_vb_slot].buffer,
- NULL);
- mgr->fallback_vb_slot = ~0;
+ /* Unreference the now-unused VBOs. */
+ for (i = 0; i < VB_NUM; i++) {
+ unsigned vb = mgr->fallback_vbs[i];
+ if (vb != ~0) {
+ pipe_resource_reference(&mgr->b.real_vertex_buffer[vb].buffer, NULL);
+ mgr->fallback_vbs[i] = ~0;
+ }
+ }
mgr->b.nr_real_vertex_buffers = mgr->b.nr_vertex_buffers;
}
@@ -554,11 +747,10 @@ void u_vbuf_set_index_buffer(struct u_vbuf *mgr,
static void
u_vbuf_upload_buffers(struct u_vbuf_priv *mgr,
- int min_index, int max_index,
- unsigned instance_count)
+ int start_vertex, unsigned num_vertices,
+ int start_instance, unsigned num_instances)
{
unsigned i;
- unsigned count = max_index + 1 - min_index;
unsigned nr_velems = mgr->ve->count;
unsigned nr_vbufs = mgr->b.nr_vertex_buffers;
struct pipe_vertex_element *velems =
@@ -573,8 +765,10 @@ u_vbuf_upload_buffers(struct u_vbuf_priv *mgr,
struct pipe_vertex_buffer *vb = &mgr->b.vertex_buffer[index];
unsigned instance_div, first, size;
- /* Skip the buffer generated by translate. */
- if (index == mgr->fallback_vb_slot) {
+ /* Skip the buffers generated by translate. */
+ if (index == mgr->fallback_vbs[VB_VERTEX] ||
+ index == mgr->fallback_vbs[VB_INSTANCE] ||
+ index == mgr->fallback_vbs[VB_CONST]) {
continue;
}
@@ -592,12 +786,13 @@ u_vbuf_upload_buffers(struct u_vbuf_priv *mgr,
size = mgr->ve->src_format_size[i];
} else if (instance_div) {
/* Per-instance attrib. */
- unsigned count = (instance_count + instance_div - 1) / instance_div;
+ unsigned count = (num_instances + instance_div - 1) / instance_div;
+ first += vb->stride * start_instance;
size = vb->stride * (count - 1) + mgr->ve->src_format_size[i];
} else {
/* Per-vertex attrib. */
- first += vb->stride * min_index;
- size = vb->stride * (count - 1) + mgr->ve->src_format_size[i];
+ first += vb->stride * start_vertex;
+ size = vb->stride * (num_vertices - 1) + mgr->ve->src_format_size[i];
}
/* Update offsets. */
@@ -615,7 +810,6 @@ u_vbuf_upload_buffers(struct u_vbuf_priv *mgr,
/* Upload buffers. */
for (i = 0; i < nr_vbufs; i++) {
unsigned start, end = end_offset[i];
- boolean flushed;
struct pipe_vertex_buffer *real_vb;
uint8_t *ptr;
@@ -630,7 +824,7 @@ u_vbuf_upload_buffers(struct u_vbuf_priv *mgr,
ptr = u_vbuf_resource(mgr->b.vertex_buffer[i].buffer)->user_ptr;
u_upload_data(mgr->b.uploader, start, end - start, ptr + start,
- &real_vb->buffer_offset, &real_vb->buffer, &flushed);
+ &real_vb->buffer_offset, &real_vb->buffer);
real_vb->buffer_offset -= start;
}
@@ -819,10 +1013,12 @@ static void u_vbuf_get_minmax_index(struct pipe_context *pipe,
enum u_vbuf_return_flags
u_vbuf_draw_begin(struct u_vbuf *mgrb,
- const struct pipe_draw_info *info)
+ struct pipe_draw_info *info)
{
struct u_vbuf_priv *mgr = (struct u_vbuf_priv*)mgrb;
- int min_index, max_index;
+ int start_vertex, min_index;
+ unsigned num_vertices;
+ bool unroll_indices = false;
if (!mgr->incompatible_vb_layout &&
!mgr->ve->incompatible_layout &&
@@ -831,32 +1027,95 @@ u_vbuf_draw_begin(struct u_vbuf *mgrb,
}
if (info->indexed) {
+ int max_index;
+ bool index_bounds_valid = false;
+
if (info->max_index != ~0) {
- min_index = info->min_index + info->index_bias;
- max_index = info->max_index + info->index_bias;
+ min_index = info->min_index;
+ max_index = info->max_index;
+ index_bounds_valid = true;
} else if (u_vbuf_need_minmax_index(mgr)) {
u_vbuf_get_minmax_index(mgr->pipe, &mgr->b.index_buffer, info,
&min_index, &max_index);
- min_index += info->index_bias;
- max_index += info->index_bias;
+ index_bounds_valid = true;
+ }
+
+ /* If the index bounds are valid, it means some upload or translation
+ * of per-vertex attribs will be performed. */
+ if (index_bounds_valid) {
+ assert(min_index <= max_index);
+
+ start_vertex = min_index + info->index_bias;
+ num_vertices = max_index + 1 - min_index;
+
+ /* Primitive restart doesn't work when unrolling indices.
+ * We would have to break this drawing operation into several ones. */
+ /* Use some heuristic to see if unrolling indices improves
+ * performance. */
+ if (!info->primitive_restart &&
+ num_vertices > info->count*2 &&
+ num_vertices-info->count > 32) {
+ /*printf("num_vertices=%i count=%i\n", num_vertices, info->count);*/
+ unroll_indices = true;
+ }
} else {
+ /* Nothing to do for per-vertex attribs. */
+ start_vertex = 0;
+ num_vertices = 0;
min_index = 0;
- max_index = 0;
}
} else {
- min_index = info->start;
- max_index = info->start + info->count - 1;
+ start_vertex = info->start;
+ num_vertices = info->count;
+ min_index = 0;
}
/* Translate vertices with non-native layouts or formats. */
- if (mgr->incompatible_vb_layout || mgr->ve->incompatible_layout) {
- u_vbuf_translate_begin(mgr, min_index, max_index);
+ if (unroll_indices ||
+ mgr->incompatible_vb_layout ||
+ mgr->ve->incompatible_layout) {
+ /* XXX check the return value */
+ u_vbuf_translate_begin(mgr, start_vertex, num_vertices,
+ info->start_instance, info->instance_count,
+ info->start, info->count, min_index,
+ unroll_indices);
}
/* Upload user buffers. */
if (mgr->any_user_vbs) {
- u_vbuf_upload_buffers(mgr, min_index, max_index, info->instance_count);
+ u_vbuf_upload_buffers(mgr, start_vertex, num_vertices,
+ info->start_instance, info->instance_count);
+ }
+
+ /*
+ if (unroll_indices) {
+ printf("unrolling indices: start_vertex = %i, num_vertices = %i\n",
+ start_vertex, num_vertices);
+ util_dump_draw_info(stdout, info);
+ printf("\n");
}
+
+ unsigned i;
+ for (i = 0; i < mgr->b.nr_vertex_buffers; i++) {
+ printf("input %i: ", i);
+ util_dump_vertex_buffer(stdout, mgr->b.vertex_buffer+i);
+ printf("\n");
+ }
+ for (i = 0; i < mgr->b.nr_real_vertex_buffers; i++) {
+ printf("real %i: ", i);
+ util_dump_vertex_buffer(stdout, mgr->b.real_vertex_buffer+i);
+ printf("\n");
+ }
+ */
+
+ if (unroll_indices) {
+ info->indexed = FALSE;
+ info->index_bias = 0;
+ info->min_index = 0;
+ info->max_index = info->count - 1;
+ info->start = 0;
+ }
+
return U_VBUF_BUFFERS_UPDATED;
}
diff --git a/mesalib/src/gallium/auxiliary/util/u_vbuf.h b/mesalib/src/gallium/auxiliary/util/u_vbuf.h
index 57b93ddea..3669c9b87 100644
--- a/mesalib/src/gallium/auxiliary/util/u_vbuf.h
+++ b/mesalib/src/gallium/auxiliary/util/u_vbuf.h
@@ -130,7 +130,7 @@ void u_vbuf_set_index_buffer(struct u_vbuf *mgr,
const struct pipe_index_buffer *ib);
enum u_vbuf_return_flags u_vbuf_draw_begin(struct u_vbuf *mgr,
- const struct pipe_draw_info *info);
+ struct pipe_draw_info *info);
unsigned u_vbuf_draw_max_vertex_count(struct u_vbuf *mgr);