summaryrefslogtreecommitdiff
path: root/glamor/glamor_vbo.c
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2014-01-06 09:29:57 +0800
committerEric Anholt <eric@anholt.net>2014-03-10 13:57:21 -0700
commitd310d566b18e55bce27301e9ac78a7894d5194dd (patch)
tree4f49c3caa123776608ee551b180162fed831f791 /glamor/glamor_vbo.c
parentffc8423077d8b5af36ab59f59e4e18109586aec9 (diff)
glamor: Extract the streamed vertex data code used by Render.
We should be uploading any vertex data using this kind of upload style, since it saves a bunch of extra copies of our vertex data. v2: - Add a simple comment about what the function does. - Use get_vbo_space()'s return in trapezoids, instead of dereffing glamor_priv->vb (by Markus Wick). - Fix the double-unmapping by moving put_vbo_space() outside of flush_composite_rects(). - Remove the rest of the composite_vbo_offset usage, and just always use get_vbo_space()'s return value. v3: - Fix failure to put_vbo_space in traps when no prims were generated. - Unbind the VBO from put_vbo_space(). Keeps callers from forgetting to do so. v4: - Split out some changes into the previous 3 commits while trying to track down a regression. - Fix regression due to rebase fail where glamor_priv->vbo_offset wasn't incremented. v5: - Fix GLES2 VBO sizing. - Add a comment about resize behavior. - Move glamor_vbo.c init code to glamor_vbo.c from glamor_render.c. (Derived from Markus's changes, but the GLES2 fix dropped almost all of the code in the functions). v6: - Drop the initial BufferData on GLES2 (it happens at put() time). - Don't forget to set vbo_offset to the size on GLES2. - Use char * instead of void * in the cast to return the vbo_offset. - Resize the default FBO to 512kb, to be similar to previous behavior. +1.66124% +/- 0.284223% (n=679) on aa10text. Signed-off-by: Eric Anholt <eric@anholt.net> Reviewed-by: Markus Wick <markus at selfnet.de>
Diffstat (limited to 'glamor/glamor_vbo.c')
-rw-r--r--glamor/glamor_vbo.c137
1 files changed, 137 insertions, 0 deletions
diff --git a/glamor/glamor_vbo.c b/glamor/glamor_vbo.c
new file mode 100644
index 000000000..78c9033f6
--- /dev/null
+++ b/glamor/glamor_vbo.c
@@ -0,0 +1,137 @@
+/*
+ * Copyright © 2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/**
+ * @file glamor_vbo.c
+ *
+ * Helpers for managing streamed vertex bufffers used in glamor.
+ */
+
+#include "glamor_priv.h"
+
+/** Default size of the VBO, in bytes.
+ *
+ * If a single request is larger than this size, we'll resize the VBO
+ * and return an appropriate mapping, but we'll resize back down after
+ * that to avoid hogging that memory forever. We don't anticipate
+ * normal usage actually requiring larger VBO sizes.
+ */
+#define GLAMOR_VBO_SIZE (512 * 1024)
+
+/**
+ * Returns a pointer to @size bytes of VBO storage, which should be
+ * accessed by the GL using vbo_offset within the VBO.
+ */
+void *
+glamor_get_vbo_space(ScreenPtr screen, unsigned size, char **vbo_offset)
+{
+ glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
+ void *data;
+
+ glamor_get_context(glamor_priv);
+
+ glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo);
+
+ if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+ if (glamor_priv->vbo_size < glamor_priv->vbo_offset + size) {
+ glamor_priv->vbo_size = MAX(GLAMOR_VBO_SIZE, size);
+ glamor_priv->vbo_offset = 0;
+ glBufferData(GL_ARRAY_BUFFER,
+ glamor_priv->vbo_size, NULL, GL_STREAM_DRAW);
+ }
+
+ data = glMapBufferRange(GL_ARRAY_BUFFER,
+ glamor_priv->vbo_offset,
+ size,
+ GL_MAP_WRITE_BIT |
+ GL_MAP_UNSYNCHRONIZED_BIT |
+ GL_MAP_INVALIDATE_RANGE_BIT);
+ assert(data != NULL);
+ *vbo_offset = (char *)(uintptr_t)glamor_priv->vbo_offset;
+ glamor_priv->vbo_offset += size;
+ } else {
+ /* Return a pointer to the statically allocated non-VBO
+ * memory. We'll upload it through glBufferData() later.
+ */
+ if (glamor_priv->vbo_size < size) {
+ glamor_priv->vbo_size = MAX(GLAMOR_VBO_SIZE, size);
+ free(glamor_priv->vb);
+ glamor_priv->vb = XNFalloc(size);
+ }
+ *vbo_offset = NULL;
+ /* We point to the start of glamor_priv->vb every time, and
+ * the vbo_offset determines the size of the glBufferData().
+ */
+ glamor_priv->vbo_offset = size;
+ data = glamor_priv->vb;
+ }
+
+ glamor_put_context(glamor_priv);
+
+ return data;
+}
+
+void
+glamor_put_vbo_space(ScreenPtr screen)
+{
+ glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
+
+ glamor_get_context(glamor_priv);
+
+ if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+ glUnmapBuffer(GL_ARRAY_BUFFER);
+ } else {
+ glBufferData(GL_ARRAY_BUFFER, glamor_priv->vbo_offset,
+ glamor_priv->vb, GL_DYNAMIC_DRAW);
+ }
+
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+
+ glamor_put_context(glamor_priv);
+}
+
+void
+glamor_init_vbo(ScreenPtr screen)
+{
+ glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
+
+ glamor_get_context(glamor_priv);
+
+ glGenBuffers(1, &glamor_priv->vbo);
+
+ glamor_put_context(glamor_priv);
+}
+
+void
+glamor_fini_vbo(ScreenPtr screen)
+{
+ glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
+
+ glamor_get_context(glamor_priv);
+
+ glDeleteBuffers(1, &glamor_priv->vbo);
+ if (glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP)
+ free(glamor_priv->vb);
+
+ glamor_put_context(glamor_priv);
+}