diff options
author | Ian Romanick <[email protected]> | 2015-11-03 15:37:40 -0800 |
---|---|---|
committer | Ian Romanick <[email protected]> | 2015-11-24 11:31:29 -0800 |
commit | 1035e00a815f0babddac0c6c43d01fd34f7e8a94 (patch) | |
tree | bac2ecfdebd5e7e6932e585ab8619d75ae97c78f | |
parent | 3b5a7d450dea9bfadf1d72338f4418c87340805b (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]>
-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 798639f7069..939f8c3837e 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); @@ -1501,10 +1514,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); @@ -1549,7 +1563,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) @@ -1637,8 +1651,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; @@ -1746,7 +1760,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; @@ -1830,7 +1844,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) { @@ -1876,7 +1891,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. */ @@ -1916,7 +1931,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); @@ -1936,8 +1952,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) { @@ -2197,7 +2213,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. */ @@ -2234,7 +2250,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; @@ -2389,7 +2406,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); @@ -2435,7 +2452,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 */ @@ -2971,7 +2989,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) @@ -3091,12 +3109,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) { @@ -3140,7 +3160,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 48607d40e75..6df76ae6f3d 100644 --- a/src/mesa/drivers/common/meta.h +++ b/src/mesa/drivers/common/meta.h @@ -300,7 +300,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]; @@ -322,7 +322,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; @@ -339,7 +339,7 @@ struct clear_state struct copypix_state { GLuint VAO; - GLuint VBO; + struct gl_buffer_object *buf_obj; }; @@ -349,7 +349,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 */ @@ -362,7 +362,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 */ }; @@ -372,7 +372,7 @@ struct bitmap_state struct gen_mipmap_state { GLuint VAO; - GLuint VBO; + struct gl_buffer_object *buf_obj; GLuint FBO; GLuint Sampler; @@ -396,7 +396,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; }; @@ -621,14 +622,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 84c81309019..37b06bcda40 100644 --- a/src/mesa/drivers/common/meta_blit.c +++ b/src/mesa/drivers/common/meta_blit.c @@ -565,7 +565,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) { @@ -693,7 +693,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); } @@ -790,7 +790,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 */ @@ -1010,8 +1011,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 28fc5ebe812..97a4297c2f6 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; @@ -196,11 +196,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); } @@ -335,8 +335,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 8f7b0725a2a..dc07379fabf 100644 --- a/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c +++ b/src/mesa/drivers/dri/i965/brw_meta_stencil_blit.c @@ -286,7 +286,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]; @@ -372,7 +373,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 }, @@ -380,7 +381,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 @@ -460,7 +461,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); |