gallium/u_vbuf: avoid dereferencing NULL pointer

When I last time fixed this, I missed that continuing here would make us
leak pointers in the translate state, which is what made this avoid a
crash in the first place.

That's not great, we need to set *some* pointer in this case. The
obvious option would be NULL, but that means that the translate-code
also needs to support NULL-pointers here.

Instead, let's point to a small, static buffer that contains enough
zero-data for the largest possible vertex attribute. This avoids having
to add more NULL-checks.

Fixes: a8e8204b18 ("gallium/u_vbuf: support NULL-resources")
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7773>
This commit is contained in:
Erik Faye-Lund 2021-05-04 13:04:48 +02:00 committed by Marge Bot
parent c05e48308b
commit a2d091694f
3 changed files with 6 additions and 5 deletions

View file

@ -149,7 +149,6 @@ spec/!opengl 1.1/polygon-mode-offset/config 4: expected white pixel on left edge
spec/!opengl 1.1/polygon-mode-offset/config 4: expected white pixel on right edge: fail
spec/!opengl 1.1/polygon-mode-offset/config 4: expected white pixel on top edge: fail
spec/!opengl 1.1/polygon-offset: fail
spec/!opengl 1.1/ppgtt_memory_alignment: fail
spec/!opengl 1.1/read-front clear-front-first samples=16: skip
spec/!opengl 1.1/read-front clear-front-first samples=2: skip
spec/!opengl 1.1/read-front clear-front-first samples=32: skip
@ -4754,8 +4753,8 @@ wgl/wgl-sanity: skip
summary:
name: results
---- --------
pass: 13298
fail: 539
pass: 13299
fail: 538
crash: 68
skip: 4126
timeout: 0

View file

@ -437,8 +437,11 @@ u_vbuf_translate_buffers(struct u_vbuf *mgr, struct translate_key *key,
unsigned size = vb->stride ? num_vertices * vb->stride
: sizeof(double)*4;
if (!vb->buffer.resource)
if (!vb->buffer.resource) {
static uint64_t dummy_buf[4] = { 0 };
tr->set_buffer(tr, i, dummy_buf, 0, 0);
continue;
}
if (offset + size > vb->buffer.resource->width0) {
/* Don't try to map past end of buffer. This often happens when

View file

@ -42,7 +42,6 @@ spec@!opengl 1.1@polygon-mode,Fail
spec@!opengl 1.1@polygon-mode-facing,Fail
spec@!opengl 1.1@polygon-mode-offset,Fail
spec@!opengl 1.1@polygon-offset,Fail
spec@!opengl 1.1@ppgtt_memory_alignment,Crash
spec@!opengl 1.1@read-front,Fail
spec@!opengl 1.1@read-front clear-front-first,Fail
spec@!opengl 1.1@read-front clear-front-first samples=2,Fail