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 d421e77..4477f58 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 656381a..2903264 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 9b15e32..27651b3 100644 (file)
@@ -1643,6 +1643,7 @@ offsets = {
     "CopyImageSubDataNV": 1607,
     "ViewportSwizzleNV": 1608,
     "AlphaToCoverageDitherControlNV": 1609,
+    "InternalBufferSubDataCopyMESA": 1610,
 }
 
 functions = [
index c8116cf..40118d2 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 d129167..9a22d4d 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 6ff2830..7c29833 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 33778df..01422bb 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);