mesa: add glInternalBufferSubDataCopyMESA for glthread
authorMarek Olšák <marek.olsak@amd.com>
Sat, 7 Mar 2020 01:19:11 +0000 (20:19 -0500)
committerMarge Bot <eric+marge@anholt.net>
Thu, 30 Apr 2020 22:01:55 +0000 (22:01 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4314>

src/mapi/glapi/gen/gl_API.xml
src/mapi/glapi/gen/gl_marshal.py
src/mapi/glapi/gen/static_data.py
src/mesa/main/bufferobj.c
src/mesa/main/bufferobj.h
src/mesa/main/tests/dispatch_sanity.cpp
src/mesa/state_tracker/st_cb_bufferobjects.c

index d421e778091b1b82ae08c2e30d94f24afcbc46df..4477f5833e34fdb1a266132cee3d0dcc1ee9899e 100644 (file)
     </function>
 </category>
 
+<category name="GL_MESA_internal_functions">
+    <!-- Internal function for glthread to implement BufferSubData as a GPU copy. -->
+    <function name="InternalBufferSubDataCopyMESA" es2="2.0">
+        <param name="srcBuffer" type="GLintptr"/> <!-- "struct gl_buffer_object *" really -->
+        <param name="srcOffset" type="GLuint"/>
+        <param name="dstTargetOrName" type="GLuint"/>
+        <param name="dstOffset" type="GLintptr"/>
+        <param name="size" type="GLsizeiptr"/>
+        <param name="named" type="GLboolean"/>
+        <param name="ext_dsa" type="GLboolean"/>
+    </function>
+</category>
+
 <xi:include href="OES_EGL_image.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
 <xi:include href="EXT_EGL_image_storage.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
 
index 656381a0513af0f994e9df420336ccc684cc0ff0..29032645fce3ad13b0d372d2f3f462da5a077c42 100644 (file)
@@ -32,6 +32,7 @@ import sys
 header = """
 #include "api_exec.h"
 #include "glthread_marshal.h"
+#include "bufferobj.h"
 #include "dispatch.h"
 
 #define COMPAT (ctx->API != API_OPENGL_CORE)
index 9b15e329be9049ec1dc2fe5aca88c6f1a7050d01..27651b3efefd45df2bb6f5bcc4076edba4231103 100644 (file)
@@ -1643,6 +1643,7 @@ offsets = {
     "CopyImageSubDataNV": 1607,
     "ViewportSwizzleNV": 1608,
     "AlphaToCoverageDitherControlNV": 1609,
+    "InternalBufferSubDataCopyMESA": 1610,
 }
 
 functions = [
index c8116cfda5331df4dfb37003ee3a2a8ec40d6ba6..40118d261b933c40cb0b71e774f6b68e6c2ec3e1 100644 (file)
@@ -3159,6 +3159,47 @@ _mesa_CopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer,
                         "glCopyNamedBufferSubData");
 }
 
+void GLAPIENTRY
+_mesa_InternalBufferSubDataCopyMESA(GLintptr srcBuffer, GLuint srcOffset,
+                                    GLuint dstTargetOrName, GLintptr dstOffset,
+                                    GLsizeiptr size, GLboolean named,
+                                    GLboolean ext_dsa)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_buffer_object *src = (struct gl_buffer_object *)srcBuffer;
+   struct gl_buffer_object *dst;
+   const char *func;
+
+   /* Handle behavior for all 3 variants. */
+   if (named && ext_dsa) {
+      func = "glNamedBufferSubDataEXT";
+      dst = _mesa_lookup_bufferobj(ctx, dstTargetOrName);
+      if (!_mesa_handle_bind_buffer_gen(ctx, dstTargetOrName, &dst, func))
+         goto done;
+   } else if (named) {
+      func = "glNamedBufferSubData";
+      dst = _mesa_lookup_bufferobj_err(ctx, dstTargetOrName, func);
+      if (!dst)
+         goto done;
+   } else {
+      assert(!ext_dsa);
+      func = "glBufferSubData";
+      dst = get_buffer(ctx, func, dstTargetOrName, GL_INVALID_OPERATION);
+      if (!dst)
+         goto done;
+   }
+
+   if (!validate_buffer_sub_data(ctx, dst, dstOffset, size, func))
+      goto done; /* the error is already set */
+
+   dst->MinMaxCacheDirty = true;
+   ctx->Driver.CopyBufferSubData(ctx, src, dst, srcOffset, dstOffset, size);
+
+done:
+   /* The caller passes the reference to this function, so unreference it. */
+   _mesa_reference_buffer_object(ctx, &src, NULL);
+}
+
 static bool
 validate_map_buffer_range(struct gl_context *ctx,
                           struct gl_buffer_object *bufObj, GLintptr offset,
index d1291677222b3d1fdee538f840acb9c2ce63a1d4..9a22d4de4406e690891c29d96f98b2f799d12a75 100644 (file)
@@ -359,6 +359,11 @@ void GLAPIENTRY
 _mesa_CopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer,
                              GLintptr readOffset, GLintptr writeOffset,
                              GLsizeiptr size);
+void GLAPIENTRY
+_mesa_InternalBufferSubDataCopyMESA(GLintptr srcBuffer, GLuint srcOffset,
+                                    GLuint dstTargetOrName, GLintptr dstOffset,
+                                    GLsizeiptr size, GLboolean named,
+                                    GLboolean ext_dsa);
 
 void * GLAPIENTRY
 _mesa_MapBufferRange_no_error(GLenum target, GLintptr offset,
index 6ff28309c6d34b483d6d1fdd0e1d3e5a659ce7bd..7c29833131a28275313be9f6ec94aeab90ddf0aa 100644 (file)
@@ -1442,6 +1442,8 @@ const struct function common_desktop_functions_possible[] = {
    /* GL_NV_viewport_swizzle */
    { "glViewportSwizzleNV", 11, -1 },
 
+   { "glInternalBufferSubDataCopyMESA", 11, -1 },
+
    { NULL, 0, -1 }
 };
 
@@ -2457,6 +2459,8 @@ const struct function gles2_functions_possible[] = {
    /* GL_KHR_parallel_shader_compile */
    { "glMaxShaderCompilerThreadsKHR", 20, -1 },
 
+   { "glInternalBufferSubDataCopyMESA", 20, -1 },
+
    { NULL, 0, -1 }
 };
 
index 33778df0afa83b423d3d0567028745619c76b706..01422bb7908fc5b1cbdea592540fb79a2edb179c 100644 (file)
@@ -605,7 +605,7 @@ st_copy_buffer_subdata(struct gl_context *ctx,
 
    /* buffer should not already be mapped */
    assert(!_mesa_check_disallowed_mapping(src));
-   assert(!_mesa_check_disallowed_mapping(dst));
+   /* dst can be mapped, just not the same range as the target range */
 
    u_box_1d(readOffset, size, &box);