diff options
author | Zack Rusin <[email protected]> | 2013-06-27 20:40:10 -0400 |
---|---|---|
committer | Zack Rusin <[email protected]> | 2013-06-28 05:21:20 -0400 |
commit | 1c2e5c223da28cdffe156b6b430fcdf638909021 (patch) | |
tree | f86833cf8b5b43134231309cc75932da000de080 /src/gallium/auxiliary/translate/translate_generic.c | |
parent | df4ab7974a825bf686f9dfa3474f3648e9a3ca66 (diff) |
draw/translate: fix instancing
We were incorrectly computing the buffer offset when using the
instances. The buffer offset is always equal to:
start_instance * stride + (instance_num / instance_divisor) *
stride
We were completely ignoring the start instance quite
often producing instances that completely wrong, e.g. if
start instance = 5, instance divisor = 2, then on the first
iteration it should be:
5 * stride, not (5/2) * stride as we'd have currently, and if
start instance = 1, instance divisor = 3, then on the first
iteration it should be:
1 * stride, not 0 as we'd have.
This fixes it and adjusts all the code to the changes.
Signed-off-by: Zack Rusin <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/translate/translate_generic.c')
-rw-r--r-- | src/gallium/auxiliary/translate/translate_generic.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/gallium/auxiliary/translate/translate_generic.c b/src/gallium/auxiliary/translate/translate_generic.c index 894c1684813..96e35b0eb41 100644 --- a/src/gallium/auxiliary/translate/translate_generic.c +++ b/src/gallium/auxiliary/translate/translate_generic.c @@ -607,6 +607,7 @@ static emit_func get_emit_func( enum pipe_format format ) static ALWAYS_INLINE void PIPE_CDECL generic_run_one( struct translate_generic *tg, unsigned elt, + unsigned start_instance, unsigned instance_id, void *vert ) { @@ -623,7 +624,9 @@ static ALWAYS_INLINE void PIPE_CDECL generic_run_one( struct translate_generic * int copy_size; if (tg->attrib[attr].instance_divisor) { - index = instance_id / tg->attrib[attr].instance_divisor; + index = start_instance; + index += (instance_id - start_instance) / + tg->attrib[attr].instance_divisor; /* XXX we need to clamp the index here too, but to a * per-array max value, not the draw->pt.max_index value * that's being given to us via translate->set_buffer(). @@ -674,6 +677,7 @@ static ALWAYS_INLINE void PIPE_CDECL generic_run_one( struct translate_generic * static void PIPE_CDECL generic_run_elts( struct translate *translate, const unsigned *elts, unsigned count, + unsigned start_instance, unsigned instance_id, void *output_buffer ) { @@ -682,7 +686,7 @@ static void PIPE_CDECL generic_run_elts( struct translate *translate, unsigned i; for (i = 0; i < count; i++) { - generic_run_one(tg, *elts++, instance_id, vert); + generic_run_one(tg, *elts++, start_instance, instance_id, vert); vert += tg->translate.key.output_stride; } } @@ -690,6 +694,7 @@ static void PIPE_CDECL generic_run_elts( struct translate *translate, static void PIPE_CDECL generic_run_elts16( struct translate *translate, const uint16_t *elts, unsigned count, + unsigned start_instance, unsigned instance_id, void *output_buffer ) { @@ -698,7 +703,7 @@ static void PIPE_CDECL generic_run_elts16( struct translate *translate, unsigned i; for (i = 0; i < count; i++) { - generic_run_one(tg, *elts++, instance_id, vert); + generic_run_one(tg, *elts++, start_instance, instance_id, vert); vert += tg->translate.key.output_stride; } } @@ -706,6 +711,7 @@ static void PIPE_CDECL generic_run_elts16( struct translate *translate, static void PIPE_CDECL generic_run_elts8( struct translate *translate, const uint8_t *elts, unsigned count, + unsigned start_instance, unsigned instance_id, void *output_buffer ) { @@ -714,7 +720,7 @@ static void PIPE_CDECL generic_run_elts8( struct translate *translate, unsigned i; for (i = 0; i < count; i++) { - generic_run_one(tg, *elts++, instance_id, vert); + generic_run_one(tg, *elts++, start_instance, instance_id, vert); vert += tg->translate.key.output_stride; } } @@ -722,6 +728,7 @@ static void PIPE_CDECL generic_run_elts8( struct translate *translate, static void PIPE_CDECL generic_run( struct translate *translate, unsigned start, unsigned count, + unsigned start_instance, unsigned instance_id, void *output_buffer ) { @@ -730,7 +737,7 @@ static void PIPE_CDECL generic_run( struct translate *translate, unsigned i; for (i = 0; i < count; i++) { - generic_run_one(tg, start + i, instance_id, vert); + generic_run_one(tg, start + i, start_instance, instance_id, vert); vert += tg->translate.key.output_stride; } } |