mesa: optimize get_local_param_pointer and program_local_parameters4fv
The idea is to: - eliminate the if statement that selects MaxLocalParams according to the shader type by moving it into the new on-demand initialization block - move allocation of local parameters into the on-demand initialization block Reviewed-by: Zoltán Böszörményi <zboszor@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8183>
This commit is contained in:
parent
bb3802b26f
commit
5336e41ac0
|
@ -287,26 +287,37 @@ get_current_program(struct gl_context* ctx, GLenum target, const char* caller)
|
|||
static GLboolean
|
||||
get_local_param_pointer(struct gl_context *ctx, const char *func,
|
||||
struct gl_program* prog, GLenum target,
|
||||
GLuint index, GLfloat **param)
|
||||
GLuint index, unsigned count, GLfloat **param)
|
||||
{
|
||||
GLuint maxParams;
|
||||
if (unlikely(index + count > prog->arb.MaxLocalParams)) {
|
||||
/* If arb.MaxLocalParams == 0, we need to do initialization. */
|
||||
if (!prog->arb.MaxLocalParams) {
|
||||
unsigned max;
|
||||
|
||||
if (target == GL_VERTEX_PROGRAM_ARB) {
|
||||
maxParams = ctx->Const.Program[MESA_SHADER_VERTEX].MaxLocalParams;
|
||||
} else {
|
||||
maxParams = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxLocalParams;
|
||||
}
|
||||
if (target == GL_VERTEX_PROGRAM_ARB)
|
||||
max = ctx->Const.Program[MESA_SHADER_VERTEX].MaxLocalParams;
|
||||
else
|
||||
max = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxLocalParams;
|
||||
|
||||
if (index >= maxParams) {
|
||||
_mesa_error(ctx, GL_INVALID_VALUE, "%s(index)", func);
|
||||
return GL_FALSE;
|
||||
}
|
||||
/* Allocate LocalParams. */
|
||||
if (!prog->arb.LocalParams) {
|
||||
prog->arb.LocalParams = rzalloc_array_size(prog, sizeof(float[4]),
|
||||
max);
|
||||
if (!prog->arb.LocalParams) {
|
||||
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
|
||||
return GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!prog->arb.LocalParams) {
|
||||
prog->arb.LocalParams = rzalloc_array_size(prog, sizeof(float[4]),
|
||||
maxParams);
|
||||
if (!prog->arb.LocalParams)
|
||||
/* Initialize MaxLocalParams. */
|
||||
prog->arb.MaxLocalParams = max;
|
||||
}
|
||||
|
||||
/* Check again after initializing MaxLocalParams. */
|
||||
if (index + count > prog->arb.MaxLocalParams) {
|
||||
_mesa_error(ctx, GL_INVALID_VALUE, "%s(index)", func);
|
||||
return GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
*param = prog->arb.LocalParams[index];
|
||||
|
@ -626,7 +637,7 @@ _mesa_ProgramLocalParameter4fARB(GLenum target, GLuint index,
|
|||
flush_vertices_for_program_constants(ctx, target);
|
||||
|
||||
if (get_local_param_pointer(ctx, "glProgramLocalParameterARB",
|
||||
prog, target, index, ¶m)) {
|
||||
prog, target, index, 1, ¶m)) {
|
||||
assert(index < MAX_PROGRAM_LOCAL_PARAMS);
|
||||
ASSIGN_4V(param, x, y, z, w);
|
||||
}
|
||||
|
@ -651,7 +662,7 @@ _mesa_NamedProgramLocalParameter4fEXT(GLuint program, GLenum target, GLuint inde
|
|||
}
|
||||
|
||||
if (get_local_param_pointer(ctx, "glNamedProgramLocalParameter4fEXT",
|
||||
prog, target, index, ¶m)) {
|
||||
prog, target, index, 1, ¶m)) {
|
||||
assert(index < MAX_PROGRAM_LOCAL_PARAMS);
|
||||
ASSIGN_4V(param, x, y, z, w);
|
||||
}
|
||||
|
@ -689,20 +700,8 @@ program_local_parameters4fv(struct gl_program* prog, GLuint index, GLsizei count
|
|||
}
|
||||
|
||||
if (get_local_param_pointer(ctx, caller,
|
||||
prog, prog->Target, index, &dest)) {
|
||||
GLuint maxParams = prog->Target == GL_FRAGMENT_PROGRAM_ARB ?
|
||||
ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxLocalParams :
|
||||
ctx->Const.Program[MESA_SHADER_VERTEX].MaxLocalParams;
|
||||
|
||||
if ((index + count) > maxParams) {
|
||||
_mesa_error(ctx, GL_INVALID_VALUE,
|
||||
"%s(index + count)",
|
||||
caller);
|
||||
return;
|
||||
}
|
||||
|
||||
prog, prog->Target, index, count, &dest))
|
||||
memcpy(dest, params, count * 4 * sizeof(GLfloat));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -789,7 +788,7 @@ _mesa_GetProgramLocalParameterfvARB(GLenum target, GLuint index,
|
|||
}
|
||||
|
||||
if (get_local_param_pointer(ctx, "glProgramLocalParameters4fvEXT",
|
||||
prog, target, index, ¶m)) {
|
||||
prog, target, index, 1, ¶m)) {
|
||||
COPY_4V(params, param);
|
||||
}
|
||||
}
|
||||
|
@ -808,7 +807,7 @@ _mesa_GetNamedProgramLocalParameterfvEXT(GLuint program, GLenum target, GLuint i
|
|||
}
|
||||
|
||||
if (get_local_param_pointer(ctx, "glGetNamedProgramLocalParameterfvEXT",
|
||||
prog, target, index, ¶m)) {
|
||||
prog, target, index, 1, ¶m)) {
|
||||
COPY_4V(params, param);
|
||||
}
|
||||
}
|
||||
|
@ -826,7 +825,7 @@ _mesa_GetProgramLocalParameterdvARB(GLenum target, GLuint index,
|
|||
}
|
||||
|
||||
if (get_local_param_pointer(ctx, "glProgramLocalParameters4fvEXT",
|
||||
prog, target, index, ¶m)) {
|
||||
prog, target, index, 1, ¶m)) {
|
||||
COPY_4V(params, param);
|
||||
}
|
||||
}
|
||||
|
@ -845,7 +844,7 @@ _mesa_GetNamedProgramLocalParameterdvEXT(GLuint program, GLenum target, GLuint i
|
|||
}
|
||||
|
||||
if (get_local_param_pointer(ctx, "glGetNamedProgramLocalParameterdvEXT",
|
||||
prog, target, index, ¶m)) {
|
||||
prog, target, index, 1, ¶m)) {
|
||||
COPY_4V(params, param);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2277,6 +2277,7 @@ struct gl_program
|
|||
* once it's allocated.
|
||||
*/
|
||||
GLfloat (*LocalParams)[4];
|
||||
unsigned MaxLocalParams;
|
||||
|
||||
/** Bitmask of which register files are read/written with indirect
|
||||
* addressing. Mask of (1 << PROGRAM_x) bits.
|
||||
|
|
Loading…
Reference in New Issue