[Mesa-dev] [PATCH 1/2] st/mesa: allow creating buffers of size = 0
Brian Paul
brianp at vmware.com
Mon Nov 14 07:28:01 PST 2011
OK, handling this in the st_draw.c code is trivial. That'll take care
of the piglit test. I'll have to follow-up later with other state
tracker changes for other cases.
-Brian
On 11/14/2011 08:13 AM, Jose Fonseca wrote:
> Is it really necessary to bother pipe drivers with zero size buffers?
>
> It looks like a useless corner case, which will cause all sort of implementations problems (e.g., malloc(0) may return NULL; kernel drivers will likely refuse 0 size buffers), so pipe drivers will need a lot of
>
> if (buffer->size == 0) {
> // don't do something stupid
> } else {
> // business as usual
> }
>
> I'd prefer see this be completely handled in the state tracker.
>
> Jose
>
>
> ----- Original Message -----
>> Calling glBufferData(size=0) is legal. Instead of no-oping it, go
>> ahead
>> and create a gallium buffer of size zero. This lets us avoid a bunch
>> of
>> NULL pointer checking elsewhere. In the case of a zero-sized VBO,
>> the
>> bounds checking we do later will prevent invalid memory accesses.
>> ---
>> src/mesa/state_tracker/st_cb_bufferobjects.c | 22
>> +++++++++-------------
>> 1 files changed, 9 insertions(+), 13 deletions(-)
>>
>> diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c
>> b/src/mesa/state_tracker/st_cb_bufferobjects.c
>> index adac92f..3abf029 100644
>> --- a/src/mesa/state_tracker/st_cb_bufferobjects.c
>> +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
>> @@ -221,21 +221,17 @@ st_bufferobj_data(struct gl_context *ctx,
>>
>> pipe_resource_reference(&st_obj->buffer, NULL );
>>
>> - if (size != 0) {
>> - st_obj->buffer = pipe_buffer_create(pipe->screen, bind,
>> - pipe_usage, size);
>> -
>> - if (!st_obj->buffer) {
>> - /* out of memory */
>> - st_obj->Base.Size = 0;
>> - return GL_FALSE;
>> - }
>> -
>> - if (data)
>> - pipe_buffer_write(pipe, st_obj->buffer, 0, size, data);
>> - return GL_TRUE;
>> + st_obj->buffer = pipe_buffer_create(pipe->screen, bind,
>> pipe_usage, size);
>> +
>> + if (!st_obj->buffer) {
>> + /* out of memory */
>> + st_obj->Base.Size = 0;
>> + return GL_FALSE;
>> }
>>
>> + if (data&& size> 0)
>> + pipe_buffer_write(pipe, st_obj->buffer, 0, size, data);
>> +
>> return GL_TRUE;
>> }
>>
>> --
>> 1.7.3.4
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>>
More information about the mesa-dev
mailing list