vrend: Ensure that buffer creation doesn't bleed into the texture allocation

If the bind flags are not correct then the default code path would try to
create a texture with PIPE_BUFFER as target. Reorder the checks to bail out
in this case after freeing the memory.

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
macos/master
Gert Wollny 5 years ago
parent 24f67de7a9
commit a156652047
  1. 11
      src/vrend_renderer.c

@ -6536,8 +6536,8 @@ int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *a
pipe_reference_init(&gr->base.reference, 1);
if (args->target == PIPE_BUFFER) {
if (args->bind == VIRGL_BIND_CUSTOM) {
assert(args->target == PIPE_BUFFER);
/* use iovec directly when attached */
gr->storage = VREND_RESOURCE_STORAGE_GUEST_ELSE_SYSTEM;
gr->ptr = malloc(args->width);
@ -6566,10 +6566,10 @@ int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *a
} else if (args->bind == VIRGL_BIND_COMMAND_ARGS) {
gr->target = GL_DRAW_INDIRECT_BUFFER;
vrend_create_buffer(gr, args->width);
} else if (args->target == PIPE_BUFFER && (args->bind == 0 || args->bind == VIRGL_BIND_SHADER_BUFFER)) {
} else if (args->bind == 0 || args->bind == VIRGL_BIND_SHADER_BUFFER) {
gr->target = GL_ARRAY_BUFFER_ARB;
vrend_create_buffer(gr, args->width);
} else if (args->target == PIPE_BUFFER && (args->bind & VIRGL_BIND_SAMPLER_VIEW)) {
} else if (args->bind & VIRGL_BIND_SAMPLER_VIEW) {
/*
* On Desktop we use GL_ARB_texture_buffer_object on GLES we use
* GL_EXT_texture_buffer (it is in the ANDRIOD extension pack).
@ -6585,6 +6585,11 @@ int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *a
gr->target = GL_PIXEL_PACK_BUFFER_ARB;
}
vrend_create_buffer(gr, args->width);
} else {
vrend_printf("%s: Illegal buffer binding flags 0x%x\n", __func__, args->bind);
FREE(gr);
return EINVAL;
}
} else {
int r = vrend_renderer_resource_allocate_texture(gr, image_oes);
if (r) {

Loading…
Cancel
Save