vbo: remove gl_context dereferences when we can just subtract the pointer

vbo_exec_context and vbo_save_context are inside gl_context.

Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7901>
This commit is contained in:
Marek Olšák 2020-11-29 02:22:06 -05:00 committed by Marge Bot
parent 03e7c93b82
commit d0bc10affb
8 changed files with 58 additions and 33 deletions

View file

@ -43,7 +43,6 @@ extern "C" {
#endif
struct gl_context;
struct vbo_module;
/**
* Max number of primitives (number of glBegin/End pairs) per VBO.
@ -81,7 +80,6 @@ struct vbo_exec_copied_vtx {
struct vbo_exec_context
{
struct gl_context *ctx;
GLvertexformat vtxfmt;
GLvertexformat vtxfmt_noop;
@ -134,7 +132,6 @@ struct vbo_save_copied_vtx {
};
struct vbo_save_context {
struct gl_context *ctx;
GLvertexformat vtxfmt;
GLvertexformat vtxfmt_noop; /**< Used if out_of_memory is true */

View file

@ -113,8 +113,6 @@ vbo_exec_init(struct gl_context *ctx, bool use_buffer_objects)
{
struct vbo_exec_context *exec = &vbo_context(ctx)->exec;
exec->ctx = ctx;
vbo_exec_vtx_init(exec, use_buffer_objects);
ctx->Driver.NeedFlush = 0;

View file

@ -81,11 +81,12 @@ vbo_exec_wrap_buffers(struct vbo_exec_context *exec)
exec->vtx.buffer_ptr = exec->vtx.buffer_map;
}
else {
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
struct _mesa_prim *last_prim = &exec->vtx.prim[exec->vtx.prim_count - 1];
const GLuint last_begin = last_prim->begin;
GLuint last_count;
if (_mesa_inside_begin_end(exec->ctx)) {
if (_mesa_inside_begin_end(ctx)) {
last_prim->count = exec->vtx.vert_count - last_prim->start;
}
@ -120,8 +121,8 @@ vbo_exec_wrap_buffers(struct vbo_exec_context *exec)
*/
assert(exec->vtx.prim_count == 0);
if (_mesa_inside_begin_end(exec->ctx)) {
exec->vtx.prim[0].mode = exec->ctx->Driver.CurrentExecPrimitive;
if (_mesa_inside_begin_end(ctx)) {
exec->vtx.prim[0].mode = ctx->Driver.CurrentExecPrimitive;
exec->vtx.prim[0].begin = 0;
exec->vtx.prim[0].end = 0;
exec->vtx.prim[0].start = 0;
@ -175,7 +176,7 @@ vbo_exec_vtx_wrap(struct vbo_exec_context *exec)
static void
vbo_exec_copy_to_current(struct vbo_exec_context *exec)
{
struct gl_context *ctx = exec->ctx;
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
struct vbo_context *vbo = vbo_context(ctx);
GLbitfield64 enabled = exec->vtx.enabled & (~BITFIELD64_BIT(VBO_ATTRIB_POS));
@ -253,7 +254,7 @@ static void
vbo_exec_wrap_upgrade_vertex(struct vbo_exec_context *exec,
GLuint attr, GLuint newSize, GLenum newType)
{
struct gl_context *ctx = exec->ctx;
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
struct vbo_context *vbo = vbo_context(ctx);
const GLint lastcount = exec->vtx.vert_count;
fi_type *old_attrptr[VBO_ATTRIB_MAX];
@ -674,7 +675,7 @@ vbo_exec_Materialfv(GLenum face, GLenum pname, const GLfloat *params)
static void
vbo_exec_FlushVertices_internal(struct vbo_exec_context *exec, unsigned flags)
{
struct gl_context *ctx = exec->ctx;
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
if (flags & FLUSH_STORED_VERTICES) {
if (exec->vtx.vert_count) {
@ -874,10 +875,11 @@ try_vbo_merge(struct vbo_exec_context *exec)
vbo_try_prim_conversion(cur);
if (exec->vtx.prim_count >= 2) {
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
struct _mesa_prim *prev = &exec->vtx.prim[exec->vtx.prim_count - 2];
assert(prev == cur - 1);
if (vbo_merge_draws(exec->ctx, false, prev, cur))
if (vbo_merge_draws(ctx, false, prev, cur))
exec->vtx.prim_count--; /* drop the last primitive */
}
}
@ -979,7 +981,7 @@ vbo_exec_PrimitiveRestartNV(void)
static void
vbo_exec_vtxfmt_init(struct vbo_exec_context *exec)
{
struct gl_context *ctx = exec->ctx;
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
GLvertexformat *vfmt = &exec->vtxfmt;
#define NAME_AE(x) _ae_##x
@ -1011,7 +1013,7 @@ vbo_reset_all_attr(struct vbo_exec_context *exec)
void
vbo_exec_vtx_init(struct vbo_exec_context *exec, bool use_buffer_objects)
{
struct gl_context *ctx = exec->ctx;
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
if (use_buffer_objects) {
/* Use buffer objects for immediate mode. */
@ -1042,7 +1044,7 @@ void
vbo_exec_vtx_destroy(struct vbo_exec_context *exec)
{
/* using a real VBO for vertex data */
struct gl_context *ctx = exec->ctx;
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
/* True VBOs should already be unmapped
*/

View file

@ -68,12 +68,13 @@ vbo_exec_debug_verts(struct vbo_exec_context *exec)
static GLuint
vbo_exec_copy_vertices(struct vbo_exec_context *exec)
{
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
struct _mesa_prim *last_prim = &exec->vtx.prim[exec->vtx.prim_count - 1];
const GLuint sz = exec->vtx.vertex_size;
fi_type *dst = exec->vtx.copied.buffer;
const fi_type *src = exec->vtx.buffer_map + last_prim->start * sz;
return vbo_copy_vertices(exec->ctx, exec->ctx->Driver.CurrentExecPrimitive,
return vbo_copy_vertices(ctx, ctx->Driver.CurrentExecPrimitive,
last_prim, sz, false, dst, src);
}
@ -151,7 +152,7 @@ static void
vbo_exec_vtx_unmap(struct vbo_exec_context *exec)
{
if (exec->vtx.bufferobj) {
struct gl_context *ctx = exec->ctx;
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
if (ctx->Driver.FlushMappedBufferRange &&
!ctx->Extensions.ARB_buffer_storage) {
@ -169,7 +170,7 @@ vbo_exec_vtx_unmap(struct vbo_exec_context *exec)
exec->vtx.buffer_used += (exec->vtx.buffer_ptr -
exec->vtx.buffer_map) * sizeof(float);
assert(exec->vtx.buffer_used <= exec->ctx->Const.glBeginEndBufferSize);
assert(exec->vtx.buffer_used <= ctx->Const.glBeginEndBufferSize);
assert(exec->vtx.buffer_ptr != NULL);
ctx->Driver.UnmapBuffer(ctx, exec->vtx.bufferobj, MAP_INTERNAL);
@ -182,7 +183,9 @@ vbo_exec_vtx_unmap(struct vbo_exec_context *exec)
static bool
vbo_exec_buffer_has_space(struct vbo_exec_context *exec)
{
return exec->ctx->Const.glBeginEndBufferSize > exec->vtx.buffer_used + 1024;
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
return ctx->Const.glBeginEndBufferSize > exec->vtx.buffer_used + 1024;
}
@ -192,7 +195,7 @@ vbo_exec_buffer_has_space(struct vbo_exec_context *exec)
void
vbo_exec_vtx_map(struct vbo_exec_context *exec)
{
struct gl_context *ctx = exec->ctx;
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
const GLenum usage = GL_STREAM_DRAW_ARB;
GLenum accessRange = GL_MAP_WRITE_BIT | /* for MapBufferRange */
GL_MAP_UNSYNCHRONIZED_BIT;
@ -293,8 +296,10 @@ vbo_exec_vtx_map(struct vbo_exec_context *exec)
void
vbo_exec_vtx_flush(struct vbo_exec_context *exec)
{
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
/* Only unmap if persistent mappings are unsupported. */
bool persistent_mapping = exec->ctx->Extensions.ARB_buffer_storage &&
bool persistent_mapping = ctx->Extensions.ARB_buffer_storage &&
exec->vtx.bufferobj &&
exec->vtx.buffer_map;
@ -307,8 +312,6 @@ vbo_exec_vtx_flush(struct vbo_exec_context *exec)
exec->vtx.copied.nr = vbo_exec_copy_vertices(exec);
if (exec->vtx.copied.nr != exec->vtx.vert_count) {
struct gl_context *ctx = exec->ctx;
/* Prepare and set the exec draws internal VAO for drawing. */
vbo_exec_bind_arrays(ctx);

View file

@ -31,6 +31,7 @@
#include "math/m_eval.h"
#include "main/dispatch.h"
#include "vbo_exec.h"
#include "vbo_private.h"
static void clear_active_eval1( struct vbo_exec_context *exec, GLuint attr )
@ -67,7 +68,7 @@ static void set_active_eval2( struct vbo_exec_context *exec, GLuint attr, GLuint
void vbo_exec_eval_update( struct vbo_exec_context *exec )
{
struct gl_context *ctx = exec->ctx;
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
GLuint attr;
/* Vertex program maps have priority over conventional attribs */
@ -124,6 +125,7 @@ void vbo_exec_eval_update( struct vbo_exec_context *exec )
void vbo_exec_do_EvalCoord1f(struct vbo_exec_context *exec, GLfloat u)
{
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
GLuint attr;
for (attr = 1; attr <= VBO_ATTRIB_TEX7; attr++) {
@ -159,9 +161,9 @@ void vbo_exec_do_EvalCoord1f(struct vbo_exec_context *exec, GLfloat u)
map->Order);
if (exec->eval.map1[0].sz == 4)
CALL_Vertex4fv(exec->ctx->CurrentServerDispatch, ( vertex ));
CALL_Vertex4fv(ctx->CurrentServerDispatch, ( vertex ));
else
CALL_Vertex3fv(exec->ctx->CurrentServerDispatch, ( vertex ));
CALL_Vertex3fv(ctx->CurrentServerDispatch, ( vertex ));
}
}
@ -170,6 +172,7 @@ void vbo_exec_do_EvalCoord1f(struct vbo_exec_context *exec, GLfloat u)
void vbo_exec_do_EvalCoord2f( struct vbo_exec_context *exec,
GLfloat u, GLfloat v )
{
struct gl_context *ctx = gl_context_from_vbo_exec(exec);
GLuint attr;
for (attr = 1; attr <= VBO_ATTRIB_TEX7; attr++) {
@ -204,7 +207,7 @@ void vbo_exec_do_EvalCoord2f( struct vbo_exec_context *exec,
ASSIGN_4V(vertex, 0, 0, 0, 1);
if (exec->ctx->Eval.AutoNormal) {
if (ctx->Eval.AutoNormal) {
fi_type normal[4];
GLfloat du[4], dv[4];
@ -239,9 +242,9 @@ void vbo_exec_do_EvalCoord2f( struct vbo_exec_context *exec,
}
if (exec->vtx.attr[VBO_ATTRIB_POS].size == 4)
CALL_Vertex4fv(exec->ctx->CurrentServerDispatch, ( vertex ));
CALL_Vertex4fv(ctx->CurrentServerDispatch, ( vertex ));
else
CALL_Vertex3fv(exec->ctx->CurrentServerDispatch, ( vertex ));
CALL_Vertex3fv(ctx->CurrentServerDispatch, ( vertex ));
}
}

View file

@ -55,6 +55,30 @@ vbo_context_const(const struct gl_context *ctx)
}
static inline struct gl_context *
gl_context_from_vbo_exec(struct vbo_exec_context *exec)
{
struct gl_context *ctx = NULL;
return container_of(exec, ctx, vbo_context.exec);
}
static inline const struct gl_context *
gl_context_from_vbo_exec_const(const struct vbo_exec_context *exec)
{
struct gl_context *ctx = NULL;
return container_of(exec, ctx, vbo_context.exec);
}
static inline struct gl_context *
gl_context_from_vbo_save(struct vbo_save_context *save)
{
struct gl_context *ctx = NULL;
return container_of(save, ctx, vbo_context.save);
}
/**
* Array to apply the fixed function material aliasing map to
* an attribute value used in vbo processing inputs to an attribute
@ -151,7 +175,7 @@ vbo_get_default_vals_as_union(GLenum format)
static inline unsigned
vbo_compute_max_verts(const struct vbo_exec_context *exec)
{
unsigned n = (exec->ctx->Const.glBeginEndBufferSize -
unsigned n = (gl_context_from_vbo_exec_const(exec)->Const.glBeginEndBufferSize -
exec->vtx.buffer_used) /
(exec->vtx.vertex_size * sizeof(GLfloat));
if (n == 0)

View file

@ -40,8 +40,6 @@ void vbo_save_init( struct gl_context *ctx )
struct vbo_context *vbo = vbo_context(ctx);
struct vbo_save_context *save = &vbo->save;
save->ctx = ctx;
vbo_save_api_init( save );
for (gl_vertex_processing_mode vpm = VP_MODE_FF; vpm < VP_MODE_MAX; ++vpm)

View file

@ -1772,7 +1772,7 @@ current_init(struct gl_context *ctx)
void
vbo_save_api_init(struct vbo_save_context *save)
{
struct gl_context *ctx = save->ctx;
struct gl_context *ctx = gl_context_from_vbo_save(save);
save->opcode_vertex_list =
_mesa_dlist_alloc_opcode(ctx,