gallium: refuse to create buffers larger than UINT32_MAX
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Thu, 5 Dec 2019 09:07:52 +0000 (10:07 +0100)
committerPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Mon, 16 Dec 2019 08:30:14 +0000 (09:30 +0100)
pipe_resource.width0 is 32 bits and hardware support for bigger buffer is
limited (eg: AMD hardware doesn't support buffer shader resources bigger
than 4GB).

Closes: https://gitlab.freedesktop.org/mesa/mesa/issues/2053
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2948>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2948>

src/mesa/state_tracker/st_cb_bufferobjects.c

index 6c20a57ef76d29eeb7b24a738393d4abaa7ef564..7776bf6ef914689813ecdc65f4db04132b40aee3 100644 (file)
@@ -289,6 +289,15 @@ bufferobj_data(struct gl_context *ctx,
    struct st_memory_object *st_mem_obj = st_memory_object(memObj);
    bool is_mapped = _mesa_bufferobj_mapped(obj, MAP_USER);
 
+   if (size > UINT32_MAX || offset > UINT32_MAX) {
+      /* pipe_resource.width0 is 32 bits only and increasing it
+       * to 64 bits doesn't make much sense since hw support
+       * for > 4GB resources is limited.
+       */
+      st_obj->Base.Size = 0;
+      return GL_FALSE;
+   }
+
    if (target != GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD &&
        size && st_obj->buffer &&
        st_obj->Base.Size == size &&