[Mesa-dev] [PATCH 13/23] meta: Track VBO using gl_buffer_object instead of GL API object handle
Anuj Phogat
anuj.phogat at gmail.com
Tue Nov 10 10:42:50 PST 2015
On Mon, Nov 9, 2015 at 4:56 PM, Ian Romanick <idr at freedesktop.org> wrote:
> From: Ian Romanick <ian.d.romanick at intel.com>
>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> ---
> src/mesa/drivers/common/meta.c | 69 +++++++++++++++--------
> src/mesa/drivers/common/meta.h | 19 ++++---
> src/mesa/drivers/common/meta_blit.c | 11 ++--
> src/mesa/drivers/common/meta_generate_mipmap.c | 12 ++--
> src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c | 9 +--
> 5 files changed, 72 insertions(+), 48 deletions(-)
>
> diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
> index 8b9bccc..27b860f 100644
> --- a/src/mesa/drivers/common/meta.c
> +++ b/src/mesa/drivers/common/meta.c
> @@ -316,7 +316,7 @@ _mesa_meta_setup_blit_shader(struct gl_context *ctx,
> *
> * \param VAO Storage for vertex array object handle. If 0, a new VAO
> * will be created.
> - * \param VBO Storage for vertex buffer object handle. If 0, a new VBO
> + * \param buf_obj Storage for vertex buffer object pointer. If \c NULL, a new VBO
> * will be created. The new VBO will have storage for 4
> * \c vertex structures.
> * \param use_generic_attributes Should generic attributes 0 and 1 be used,
> @@ -334,24 +334,37 @@ _mesa_meta_setup_blit_shader(struct gl_context *ctx,
> */
> void
> _mesa_meta_setup_vertex_objects(struct gl_context *ctx,
> - GLuint *VAO, GLuint *VBO,
> + GLuint *VAO, struct gl_buffer_object **buf_obj,
> bool use_generic_attributes,
> unsigned vertex_size, unsigned texcoord_size,
> unsigned color_size)
> {
> + GLuint VBO;
> +
> if (*VAO == 0) {
> - assert(*VBO == 0);
> + assert(*buf_obj == NULL);
>
> /* create vertex array object */
> _mesa_GenVertexArrays(1, VAO);
> _mesa_BindVertexArray(*VAO);
>
> /* create vertex array buffer */
> - _mesa_GenBuffers(1, VBO);
> - _mesa_BindBuffer(GL_ARRAY_BUFFER, *VBO);
> + _mesa_GenBuffers(1, &VBO);
> + _mesa_BindBuffer(GL_ARRAY_BUFFER, VBO);
> + *buf_obj = _mesa_lookup_bufferobj(ctx, VBO);
> +
> + /* _mesa_lookup_bufferobj only returns NULL if name is 0. If the object
> + * does not yet exist (i.e., hasn't been bound) it will return a dummy
> + * object that you can't do anything with.
> + */
> + assert(*buf_obj != NULL && (*buf_obj)->Name == VBO);
> + assert(*buf_obj == ctx->Array.ArrayBufferObj);
> +
> _mesa_BufferData(GL_ARRAY_BUFFER, 4 * sizeof(struct vertex), NULL,
> GL_DYNAMIC_DRAW);
>
> + assert((*buf_obj)->Size == 4 * sizeof(struct vertex));
> +
> /* setup vertex arrays */
> if (use_generic_attributes) {
> assert(color_size == 0);
> @@ -1490,10 +1503,11 @@ _mesa_meta_setup_drawpix_texture(struct gl_context *ctx,
>
> void
> _mesa_meta_setup_ff_tnl_for_blit(struct gl_context *ctx,
> - GLuint *VAO, GLuint *VBO,
> + GLuint *VAO, struct gl_buffer_object **buf_obj,
> unsigned texcoord_size)
> {
> - _mesa_meta_setup_vertex_objects(ctx, VAO, VBO, false, 2, texcoord_size, 0);
> + _mesa_meta_setup_vertex_objects(ctx, VAO, buf_obj, false, 2, texcoord_size,
> + 0);
>
> /* setup projection matrix */
> _mesa_MatrixMode(GL_PROJECTION);
> @@ -1538,7 +1552,7 @@ meta_glsl_clear_init(struct gl_context *ctx, struct clear_state *clear)
> GLuint vs, fs;
> bool has_integer_textures;
>
> - _mesa_meta_setup_vertex_objects(ctx, &clear->VAO, &clear->VBO, true,
> + _mesa_meta_setup_vertex_objects(ctx, &clear->VAO, &clear->buf_obj, true,
> 3, 0, 0);
>
> if (clear->ShaderProg != 0)
> @@ -1626,8 +1640,8 @@ meta_glsl_clear_cleanup(struct clear_state *clear)
> return;
> _mesa_DeleteVertexArrays(1, &clear->VAO);
> clear->VAO = 0;
> - _mesa_DeleteBuffers(1, &clear->VBO);
> - clear->VBO = 0;
> + _mesa_DeleteBuffers(1, &clear->buf_obj->Name);
> + clear->buf_obj = NULL;
> _mesa_DeleteProgram(clear->ShaderProg);
> clear->ShaderProg = 0;
>
> @@ -1735,7 +1749,7 @@ meta_clear(struct gl_context *ctx, GLbitfield buffers, bool glsl)
> y1 = ((float) fb->_Ymax / fb->Height) * 2.0f - 1.0f;
> z = -invert_z(ctx->Depth.Clear);
> } else {
> - _mesa_meta_setup_vertex_objects(ctx, &clear->VAO, &clear->VBO, false,
> + _mesa_meta_setup_vertex_objects(ctx, &clear->VAO, &clear->buf_obj, false,
> 3, 0, 4);
>
> x0 = (float) fb->_Xmin;
> @@ -1819,7 +1833,8 @@ meta_clear(struct gl_context *ctx, GLbitfield buffers, bool glsl)
> }
>
> /* upload new vertex data */
> - _mesa_NamedBufferData(clear->VBO, sizeof(verts), verts, GL_DYNAMIC_DRAW);
> + _mesa_buffer_data(ctx, clear->buf_obj, GL_NONE, sizeof(verts), verts,
> + GL_DYNAMIC_DRAW, __func__);
>
> /* draw quad(s) */
> if (fb->MaxNumLayers > 0) {
> @@ -1865,7 +1880,7 @@ _mesa_meta_CopyPixels(struct gl_context *ctx, GLint srcX, GLint srcY,
> MESA_META_VERTEX |
> MESA_META_VIEWPORT));
>
> - _mesa_meta_setup_vertex_objects(ctx, ©pix->VAO, ©pix->VBO, false,
> + _mesa_meta_setup_vertex_objects(ctx, ©pix->VAO, ©pix->buf_obj, false,
> 3, 2, 0);
>
> /* Silence valgrind warnings about reading uninitialized stack. */
> @@ -1905,7 +1920,8 @@ _mesa_meta_CopyPixels(struct gl_context *ctx, GLint srcX, GLint srcY,
> verts[3].tex[1] = tex->Ttop;
>
> /* upload new vertex data */
> - _mesa_NamedBufferSubData(copypix->VBO, 0, sizeof(verts), verts);
> + _mesa_buffer_sub_data(ctx, copypix->buf_obj, 0, sizeof(verts), verts,
> + __func__);
> }
>
> _mesa_set_enable(ctx, tex->Target, GL_TRUE);
> @@ -1925,8 +1941,8 @@ meta_drawpix_cleanup(struct drawpix_state *drawpix)
> _mesa_DeleteVertexArrays(1, &drawpix->VAO);
> drawpix->VAO = 0;
>
> - _mesa_DeleteBuffers(1, &drawpix->VBO);
> - drawpix->VBO = 0;
> + _mesa_DeleteBuffers(1, &drawpix->buf_obj->Name);
> + drawpix->buf_obj = NULL;
> }
>
> if (drawpix->StencilFP != 0) {
> @@ -2186,7 +2202,7 @@ _mesa_meta_DrawPixels(struct gl_context *ctx,
>
> newTex = _mesa_meta_alloc_texture(tex, width, height, texIntFormat);
>
> - _mesa_meta_setup_vertex_objects(ctx, &drawpix->VAO, &drawpix->VBO, false,
> + _mesa_meta_setup_vertex_objects(ctx, &drawpix->VAO, &drawpix->buf_obj, false,
> 3, 2, 0);
>
> /* Silence valgrind warnings about reading uninitialized stack. */
> @@ -2223,7 +2239,8 @@ _mesa_meta_DrawPixels(struct gl_context *ctx,
> }
>
> /* upload new vertex data */
> - _mesa_NamedBufferData(drawpix->VBO, sizeof(verts), verts, GL_DYNAMIC_DRAW);
> + _mesa_buffer_data(ctx, drawpix->buf_obj, GL_NONE, sizeof(verts), verts,
> + GL_DYNAMIC_DRAW, __func__);
>
> /* set given unpack params */
> ctx->Unpack = *unpack;
> @@ -2378,7 +2395,7 @@ _mesa_meta_Bitmap(struct gl_context *ctx,
> MESA_META_VERTEX |
> MESA_META_VIEWPORT));
>
> - _mesa_meta_setup_vertex_objects(ctx, &bitmap->VAO, &bitmap->VBO, false,
> + _mesa_meta_setup_vertex_objects(ctx, &bitmap->VAO, &bitmap->buf_obj, false,
> 3, 2, 4);
>
> newTex = _mesa_meta_alloc_texture(tex, width, height, texIntFormat);
> @@ -2424,7 +2441,8 @@ _mesa_meta_Bitmap(struct gl_context *ctx,
> }
>
> /* upload new vertex data */
> - _mesa_NamedBufferSubData(bitmap->VBO, 0, sizeof(verts), verts);
> + _mesa_buffer_sub_data(ctx, bitmap->buf_obj, 0, sizeof(verts), verts,
> + __func__);
> }
>
> /* choose different foreground/background alpha values */
> @@ -2960,7 +2978,7 @@ meta_decompress_cleanup(struct decompress_state *decompress)
>
> if (decompress->VAO != 0) {
> _mesa_DeleteVertexArrays(1, &decompress->VAO);
> - _mesa_DeleteBuffers(1, &decompress->VBO);
> + _mesa_DeleteBuffers(1, &decompress->buf_obj->Name);
> }
>
> if (decompress->Sampler != 0)
> @@ -3080,12 +3098,14 @@ decompress_texture_image(struct gl_context *ctx,
> }
>
> if (use_glsl_version) {
> - _mesa_meta_setup_vertex_objects(ctx, &decompress->VAO, &decompress->VBO, true,
> + _mesa_meta_setup_vertex_objects(ctx, &decompress->VAO,
> + &decompress->buf_obj, true,
> 2, 4, 0);
>
> _mesa_meta_setup_blit_shader(ctx, target, false, &decompress->shaders);
> } else {
> - _mesa_meta_setup_ff_tnl_for_blit(ctx, &decompress->VAO, &decompress->VBO, 3);
> + _mesa_meta_setup_ff_tnl_for_blit(ctx, &decompress->VAO,
> + &decompress->buf_obj, 3);
> }
>
> if (!decompress->Sampler) {
> @@ -3129,7 +3149,8 @@ decompress_texture_image(struct gl_context *ctx,
> _mesa_set_viewport(ctx, 0, 0, 0, width, height);
>
> /* upload new vertex data */
> - _mesa_NamedBufferSubData(decompress->VBO, 0, sizeof(verts), verts);
> + _mesa_buffer_sub_data(ctx, decompress->buf_obj, 0, sizeof(verts), verts,
> + __func__);
>
> /* setup texture state */
> _mesa_BindTexture(target, texObj->Name);
> diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h
> index 0d3bf78..9ce5d12 100644
> --- a/src/mesa/drivers/common/meta.h
> +++ b/src/mesa/drivers/common/meta.h
> @@ -297,7 +297,7 @@ enum blit_msaa_shader {
> struct blit_state
> {
> GLuint VAO;
> - GLuint VBO;
> + struct gl_buffer_object *buf_obj;
> struct blit_shader_table shaders_with_depth;
> struct blit_shader_table shaders_without_depth;
> GLuint msaa_shaders[BLIT_MSAA_SHADER_COUNT];
> @@ -319,7 +319,7 @@ struct fb_tex_blit_state
> struct clear_state
> {
> GLuint VAO;
> - GLuint VBO;
> + struct gl_buffer_object *buf_obj;
> GLuint ShaderProg;
> GLint ColorLocation;
> GLint LayerLocation;
> @@ -336,7 +336,7 @@ struct clear_state
> struct copypix_state
> {
> GLuint VAO;
> - GLuint VBO;
> + struct gl_buffer_object *buf_obj;
> };
>
>
> @@ -346,7 +346,7 @@ struct copypix_state
> struct drawpix_state
> {
> GLuint VAO;
> - GLuint VBO;
> + struct gl_buffer_object *buf_obj;
>
> GLuint StencilFP; /**< Fragment program for drawing stencil images */
> GLuint DepthFP; /**< Fragment program for drawing depth images */
> @@ -359,7 +359,7 @@ struct drawpix_state
> struct bitmap_state
> {
> GLuint VAO;
> - GLuint VBO;
> + struct gl_buffer_object *buf_obj;
> struct temp_texture Tex; /**< separate texture from other meta ops */
> };
>
> @@ -369,7 +369,7 @@ struct bitmap_state
> struct gen_mipmap_state
> {
> GLuint VAO;
> - GLuint VBO;
> + struct gl_buffer_object *buf_obj;
> GLuint FBO;
> GLuint Sampler;
>
> @@ -393,7 +393,8 @@ struct decompress_state
> {
> GLuint VAO;
> struct decompress_fbo_state byteFBO, floatFBO;
> - GLuint VBO, Sampler;
> + struct gl_buffer_object *buf_obj;
> + GLuint Sampler;
>
> struct blit_shader_table shaders;
> };
> @@ -618,14 +619,14 @@ _mesa_meta_get_temp_depth_texture(struct gl_context *ctx);
>
> void
> _mesa_meta_setup_vertex_objects(struct gl_context *ctx,
> - GLuint *VAO, GLuint *VBO,
> + GLuint *VAO, struct gl_buffer_object **buf_obj,
> bool use_generic_attributes,
> unsigned vertex_size, unsigned texcoord_size,
> unsigned color_size);
>
> void
> _mesa_meta_setup_ff_tnl_for_blit(struct gl_context *ctx,
> - GLuint *VAO, GLuint *VBO,
> + GLuint *VAO, struct gl_buffer_object **buf_obj,
> unsigned texcoord_size);
>
> void
> diff --git a/src/mesa/drivers/common/meta_blit.c b/src/mesa/drivers/common/meta_blit.c
> index fafe312..1336b7c 100644
> --- a/src/mesa/drivers/common/meta_blit.c
> +++ b/src/mesa/drivers/common/meta_blit.c
> @@ -533,7 +533,7 @@ setup_glsl_blit_framebuffer(struct gl_context *ctx,
>
> texcoord_size = 2 + (src_rb->Depth > 1 ? 1 : 0);
>
> - _mesa_meta_setup_vertex_objects(ctx, &blit->VAO, &blit->VBO, true,
> + _mesa_meta_setup_vertex_objects(ctx, &blit->VAO, &blit->buf_obj, true,
> 2, texcoord_size, 0);
>
> if (is_target_multisample && is_filter_scaled_resolve && is_scaled_blit) {
> @@ -661,7 +661,7 @@ blitframebuffer_texture(struct gl_context *ctx,
> else {
> _mesa_meta_setup_ff_tnl_for_blit(ctx,
> &ctx->Meta->Blit.VAO,
> - &ctx->Meta->Blit.VBO,
> + &ctx->Meta->Blit.buf_obj,
> 2);
> }
>
> @@ -758,7 +758,8 @@ blitframebuffer_texture(struct gl_context *ctx,
> verts[3].tex[1] = t1;
> verts[3].tex[2] = readAtt->Zoffset;
>
> - _mesa_NamedBufferSubData(blit->VBO, 0, sizeof(verts), verts);
> + _mesa_buffer_sub_data(ctx, blit->buf_obj, 0, sizeof(verts), verts,
> + __func__);
> }
>
> /* setup viewport */
> @@ -978,8 +979,8 @@ _mesa_meta_glsl_blit_cleanup(struct blit_state *blit)
> if (blit->VAO) {
> _mesa_DeleteVertexArrays(1, &blit->VAO);
> blit->VAO = 0;
> - _mesa_DeleteBuffers(1, &blit->VBO);
> - blit->VBO = 0;
> + _mesa_DeleteBuffers(1, &blit->buf_obj->Name);
> + blit->buf_obj = NULL;
> }
>
> _mesa_meta_blit_shader_table_cleanup(&blit->shaders_with_depth);
> diff --git a/src/mesa/drivers/common/meta_generate_mipmap.c b/src/mesa/drivers/common/meta_generate_mipmap.c
> index 41feb48..7fb82e1 100644
> --- a/src/mesa/drivers/common/meta_generate_mipmap.c
> +++ b/src/mesa/drivers/common/meta_generate_mipmap.c
> @@ -126,8 +126,8 @@ _mesa_meta_glsl_generate_mipmap_cleanup(struct gen_mipmap_state *mipmap)
> return;
> _mesa_DeleteVertexArrays(1, &mipmap->VAO);
> mipmap->VAO = 0;
> - _mesa_DeleteBuffers(1, &mipmap->VBO);
> - mipmap->VBO = 0;
> + _mesa_DeleteBuffers(1, &mipmap->buf_obj->Name);
> + mipmap->buf_obj->Name = NULL;
>
> _mesa_meta_blit_shader_table_cleanup(&mipmap->shaders);
> }
> @@ -189,11 +189,11 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
> * GenerateMipmap function.
> */
> if (use_glsl_version) {
> - _mesa_meta_setup_vertex_objects(ctx, &mipmap->VAO, &mipmap->VBO, true,
> + _mesa_meta_setup_vertex_objects(ctx, &mipmap->VAO, &mipmap->buf_obj, true,
> 2, 4, 0);
> _mesa_meta_setup_blit_shader(ctx, target, false, &mipmap->shaders);
> } else {
> - _mesa_meta_setup_ff_tnl_for_blit(ctx, &mipmap->VAO, &mipmap->VBO, 3);
> + _mesa_meta_setup_ff_tnl_for_blit(ctx, &mipmap->VAO, &mipmap->buf_obj, 3);
> _mesa_set_enable(ctx, target, GL_TRUE);
> }
>
> @@ -328,8 +328,8 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
> verts[3].tex);
>
> /* upload vertex data */
> - _mesa_NamedBufferData(mipmap->VBO, sizeof(verts), verts,
> - GL_DYNAMIC_DRAW);
> + _mesa_buffer_data(ctx, mipmap->buf_obj, GL_NONE, sizeof(verts), verts,
> + GL_DYNAMIC_DRAW, __func__);
>
> _mesa_meta_bind_fbo_image(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, dstImage, layer);
>
> diff --git a/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c b/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c
> index ddb6826..619dda9 100644
> --- a/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c
> +++ b/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c
> @@ -279,7 +279,8 @@ setup_program(struct brw_context *brw, bool msaa_tex)
> char *fs_source;
> const struct sampler_and_fetch *sampler = &samplers[msaa_tex];
>
> - _mesa_meta_setup_vertex_objects(ctx, &blit->VAO, &blit->VBO, true, 2, 2, 0);
> + _mesa_meta_setup_vertex_objects(&brw->ctx, &blit->VAO, &blit->buf_obj, true,
> + 2, 2, 0);
>
> GLuint *prog_id = &brw->meta_stencil_blit_programs[msaa_tex];
>
> @@ -360,7 +361,7 @@ adjust_mip_level(const struct intel_mipmap_tree *mt,
> }
>
> static void
> -prepare_vertex_data(GLuint vbo)
> +prepare_vertex_data(struct gl_context *ctx, struct gl_buffer_object *buf_obj)
> {
> static const struct vertex verts[] = {
> { .x = -1.0f, .y = -1.0f },
> @@ -368,7 +369,7 @@ prepare_vertex_data(GLuint vbo)
> { .x = 1.0f, .y = 1.0f },
> { .x = -1.0f, .y = 1.0f } };
>
> - _mesa_NamedBufferSubData(vbo, 0, sizeof(verts), verts);
> + _mesa_buffer_sub_data(ctx, buf_obj, 0, sizeof(verts), verts, __func__);
> }
>
> static bool
> @@ -448,7 +449,7 @@ brw_meta_stencil_blit(struct brw_context *brw,
> _mesa_Uniform1i(_mesa_GetUniformLocation(prog, "dst_num_samples"),
> dst_mt->num_samples);
>
> - prepare_vertex_data(ctx->Meta->Blit.VBO);
> + prepare_vertex_data(ctx, ctx->Meta->Blit.buf_obj);
> _mesa_set_viewport(ctx, 0, dims.dst_x0, dims.dst_y0,
> dims.dst_x1 - dims.dst_x0, dims.dst_y1 - dims.dst_y0);
> _mesa_ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
> --
> 2.1.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
Reviewed-by: Anuj Phogat <anuj.phogat at gmail.com>
More information about the mesa-dev
mailing list