Commit 5336e41a authored by Marek Olšák's avatar Marek Olšák Committed by Marge Bot

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's avatarZoltán Böszörményi <zboszor@gmail.com>
Part-of: <mesa/mesa!8183>
parent bb3802b2
......@@ -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 (target == GL_VERTEX_PROGRAM_ARB) {
maxParams = ctx->Const.Program[MESA_SHADER_VERTEX].MaxLocalParams;
} else {
maxParams = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxLocalParams;
}
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)
max = ctx->Const.Program[MESA_SHADER_VERTEX].MaxLocalParams;
else
max = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxLocalParams;
/* 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 (index >= maxParams) {
_mesa_error(ctx, GL_INVALID_VALUE, "%s(index)", func);
return GL_FALSE;
}
/* Initialize MaxLocalParams. */
prog->arb.MaxLocalParams = max;
}
if (!prog->arb.LocalParams) {
prog->arb.LocalParams = rzalloc_array_size(prog, sizeof(float[4]),
maxParams);
if (!prog->arb.LocalParams)
/* 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, &param)) {
prog, target, index, 1, &param)) {
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, &param)) {
prog, target, index, 1, &param)) {
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, &param)) {
prog, target, index, 1, &param)) {
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, &param)) {
prog, target, index, 1, &param)) {
COPY_4V(params, param);
}
}
......@@ -826,7 +825,7 @@ _mesa_GetProgramLocalParameterdvARB(GLenum target, GLuint index,
}
if (get_local_param_pointer(ctx, "glProgramLocalParameters4fvEXT",
prog, target, index, &param)) {
prog, target, index, 1, &param)) {
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, &param)) {
prog, target, index, 1, &param)) {
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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment