diff options
author | Ian Romanick <[email protected]> | 2015-11-03 15:37:40 -0800 |
---|---|---|
committer | Ian Romanick <[email protected]> | 2015-11-24 11:50:29 -0800 |
commit | cb88260ec0d931c90302aa1af26627ff3857eda2 (patch) | |
tree | db05afdafdcadf16671d2bdf418b738e1fb262a2 | |
parent | e69c2746616dee4121d3a4a0f7e3127755df37e4 (diff) |
meta: Track VBO using gl_buffer_object instead of GL API object handle
Signed-off-by: Ian Romanick <[email protected]>
Reviewed-by: Anuj Phogat <[email protected]>
(cherry picked from commit 1035e00a815f0babddac0c6c43d01fd34f7e8a94)
-rw-r--r-- | src/mesa/drivers/common/meta.c | 69 | ||||
-rw-r--r-- | src/mesa/drivers/common/meta.h | 19 | ||||
-rw-r--r-- | src/mesa/drivers/common/meta_blit.c | 11 | ||||
-rw-r--r-- | src/mesa/drivers/common/meta_generate_mipmap.c | 12 | ||||
-rw-r--r-- | 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 0e48b9c870e..8de6a429daf 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); @@ -1488,10 +1501,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); @@ -1536,7 +1550,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) @@ -1624,8 +1638,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; @@ -1733,7 +1747,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; @@ -1817,7 +1831,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) { @@ -1863,7 +1878,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. */ @@ -1903,7 +1918,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); @@ -1923,8 +1939,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) { @@ -2184,7 +2200,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. */ @@ -2221,7 +2237,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; @@ -2376,7 +2393,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); @@ -2422,7 +2439,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 */ @@ -2958,7 +2976,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) @@ -3078,12 +3096,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) { @@ -3127,7 +3147,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 e56afb1e477..16247d772ac 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; }; @@ -616,14 +617,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 cb4ab2e5b97..1b7729dc84e 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 3c7110aaa6a..ce2a771924e 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_DeleteSamplers(1, &mipmap->Sampler); mipmap->Sampler = 0; @@ -192,11 +192,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); } @@ -331,8 +331,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 2f65124ed99..65f3bdd2376 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); |