[Mesa-dev] [PATCH 2/2] util/u_helpers: return correct number of bound buffers

Ilia Mirkin imirkin at alum.mit.edu
Wed Dec 9 11:21:23 PST 2015


On Wed, Dec 9, 2015 at 2:01 PM, Patrick Rudolph <siro at das-labor.org> wrote:
> Ok, first of all bind some buffers:
>
> pipe->set_vertex_buffers(pipe, 0, 1, &vtxbuf);
> pipe->set_vertex_buffers(pipe, 1, 1, &vtxbuf);
> pipe->set_vertex_buffers(pipe, 2, 1, &vtxbuf);
>
> num_vtxbufs is now 3 as it should be.
>
> Now you are unbinding buffers, one after another starting at slot 0:
> pipe->set_vertex_buffers(pipe, 0, 1, NULL);
>
> enabled_buffers = (1ull << num_vtxbufs) - 1 = 0x7;
> util_set_vertex_buffers_mask(...);
> enabled_buffers = 0x6;
> num_vtxbufs = util_last_bit(enabled_buffers) = 3
>
>
> pipe->set_vertex_buffers(pipe, 1, 1, NULL);
>
> enabled_buffers = (1ull << num_vtxbufs) - 1 = 0x7;
> util_set_vertex_buffers_mask(...);
> enabled_buffers = 0x5;
> num_vtxbufs = util_last_bit(enabled_buffers) = 3
>
>
> pipe->set_vertex_buffers(pipe, 2, 1, NULL);
>
> enabled_buffers = (1ull << num_vtxbufs) - 1 = 0x7;
> util_set_vertex_buffers_mask(...);
> enabled_buffers = 0x3;
> num_vtxbufs = util_last_bit(enabled_buffers) = 2
>
> There are no buffers bound any more, but num_vtxbufs is now 2 instead of
> 0.
>
> There would be no problem if you start at slot 2 going down to 0.
> There would be no problem if you unbind all buffers at once.
>
> I hope this clarifies the problem.

Right, thank you, yes it does. With a slightly fixed commit log
including a bit more justification, this is also

Reviewed-by: Ilia Mirkin <imirkin at alum.mit.edu>

Basically something mentioning that the current algorithm does not
account for pre-existing holes in the buffer list.


More information about the mesa-dev mailing list