diff options
Diffstat (limited to 'src/mesa/program')
-rw-r--r-- | src/mesa/program/ir_to_mesa.cpp | 9 | ||||
-rw-r--r-- | src/mesa/program/prog_execute.c | 6 | ||||
-rw-r--r-- | src/mesa/program/prog_opt_constant_fold.c | 3 | ||||
-rw-r--r-- | src/mesa/program/prog_parameter.c | 52 | ||||
-rw-r--r-- | src/mesa/program/prog_parameter.h | 9 | ||||
-rw-r--r-- | src/mesa/program/prog_parameter_layout.c | 21 | ||||
-rw-r--r-- | src/mesa/program/prog_print.c | 4 | ||||
-rw-r--r-- | src/mesa/program/prog_statevars.c | 3 | ||||
-rw-r--r-- | src/mesa/program/prog_to_nir.c | 3 | ||||
-rw-r--r-- | src/mesa/program/program_parse.y | 2 |
10 files changed, 78 insertions, 34 deletions
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 29025d1c177..f26eddc9000 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -2452,7 +2452,7 @@ add_uniform_to_shader::visit_field(const glsl_type *type, const char *name, for (unsigned i = 0; i < num_params; i++) { unsigned comps = 4; _mesa_add_parameter(params, PROGRAM_UNIFORM, name, comps, - type->gl_type, NULL, NULL); + type->gl_type, NULL, NULL, true); } /* The first part of the uniform that's processed determines the base @@ -2582,9 +2582,10 @@ _mesa_associate_uniform_storage(struct gl_context *ctx, break; } + unsigned pvo = params->ParameterValueOffset[i]; _mesa_uniform_attach_driver_storage(storage, dmul * columns, dmul, format, - ¶ms->ParameterValues[i]); + ¶ms->ParameterValues[pvo]); /* When a bindless sampler/image is bound to a texture/image unit, we * have to overwrite the constant value by the resident handle @@ -2601,11 +2602,11 @@ _mesa_associate_uniform_storage(struct gl_context *ctx, if (storage->type->without_array()->is_sampler()) { assert(unit >= 0 && unit < prog->sh.NumBindlessSamplers); prog->sh.BindlessSamplers[unit].data = - ¶ms->ParameterValues[i] + j; + ¶ms->ParameterValues[pvo] + 4 * j; } else if (storage->type->without_array()->is_image()) { assert(unit >= 0 && unit < prog->sh.NumBindlessImages); prog->sh.BindlessImages[unit].data = - ¶ms->ParameterValues[i] + j; + ¶ms->ParameterValues[pvo] + 4 * j; } } } diff --git a/src/mesa/program/prog_execute.c b/src/mesa/program/prog_execute.c index 2c77538c2af..b5a7a692aeb 100644 --- a/src/mesa/program/prog_execute.c +++ b/src/mesa/program/prog_execute.c @@ -117,11 +117,13 @@ get_src_register_pointer(const struct prog_src_register *source, /* Fallthrough */ case PROGRAM_CONSTANT: /* Fallthrough */ - case PROGRAM_UNIFORM: + case PROGRAM_UNIFORM: { if (reg >= (GLint) prog->Parameters->NumParameters) return ZeroVec; - return (GLfloat *) prog->Parameters->ParameterValues[reg]; + unsigned pvo = prog->Parameters->ParameterValueOffset[reg]; + return (GLfloat *) prog->Parameters->ParameterValues + pvo; + } case PROGRAM_SYSTEM_VALUE: assert(reg < (GLint) ARRAY_SIZE(machine->SystemValues)); return machine->SystemValues[reg]; diff --git a/src/mesa/program/prog_opt_constant_fold.c b/src/mesa/program/prog_opt_constant_fold.c index ba4a954186a..638bdbd1507 100644 --- a/src/mesa/program/prog_opt_constant_fold.c +++ b/src/mesa/program/prog_opt_constant_fold.c @@ -90,8 +90,9 @@ src_regs_are_same(const struct prog_src_register *a, static void get_value(struct gl_program *prog, struct prog_src_register *r, float *data) { + unsigned pvo = prog->Parameters->ParameterValueOffset[r->Index]; const gl_constant_value *const value = - prog->Parameters->ParameterValues[r->Index]; + prog->Parameters->ParameterValues + pvo; data[0] = value[GET_SWZ(r->Swizzle, 0)].f; data[1] = value[GET_SWZ(r->Swizzle, 1)].f; diff --git a/src/mesa/program/prog_parameter.c b/src/mesa/program/prog_parameter.c index 6b6599d7453..af9bb37cd5c 100644 --- a/src/mesa/program/prog_parameter.c +++ b/src/mesa/program/prog_parameter.c @@ -66,11 +66,13 @@ lookup_parameter_constant(const struct gl_program_parameter_list *list, for (i = 0; i < list->NumParameters; i++) { if (list->Parameters[i].Type == PROGRAM_CONSTANT) { + unsigned offset = list->ParameterValueOffset[i]; + if (!swizzleOut) { /* swizzle not allowed */ GLuint j, match = 0; for (j = 0; j < vSize; j++) { - if (v[j].u == list->ParameterValues[i][j].u) + if (v[j].u == list->ParameterValues[offset + j].u) match++; } if (match == vSize) { @@ -84,7 +86,7 @@ lookup_parameter_constant(const struct gl_program_parameter_list *list, /* look for v[0] anywhere within float[4] value */ GLuint j; for (j = 0; j < list->Parameters[i].Size; j++) { - if (list->ParameterValues[i][j].u == v[0].u) { + if (list->ParameterValues[offset + j].u == v[0].u) { /* found it */ *posOut = i; *swizzleOut = MAKE_SWIZZLE4(j, j, j, j); @@ -97,13 +99,13 @@ lookup_parameter_constant(const struct gl_program_parameter_list *list, GLuint swz[4]; GLuint match = 0, j, k; for (j = 0; j < vSize; j++) { - if (v[j].u == list->ParameterValues[i][j].u) { + if (v[j].u == list->ParameterValues[offset + j].u) { swz[j] = j; match++; } else { for (k = 0; k < list->Parameters[i].Size; k++) { - if (v[j].u == list->ParameterValues[i][k].u) { + if (v[j].u == list->ParameterValues[offset + k].u) { swz[j] = k; match++; break; @@ -149,7 +151,9 @@ _mesa_new_parameter_list_sized(unsigned size) p->Parameters = (struct gl_program_parameter *) calloc(size, sizeof(struct gl_program_parameter)); - p->ParameterValues = (gl_constant_value (*)[4]) + p->ParameterValueOffset = (unsigned *) calloc(size, sizeof(unsigned)); + + p->ParameterValues = (gl_constant_value *) _mesa_align_malloc(size * 4 *sizeof(gl_constant_value), 16); @@ -203,7 +207,11 @@ _mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList, realloc(paramList->Parameters, paramList->Size * sizeof(struct gl_program_parameter)); - paramList->ParameterValues = (gl_constant_value (*)[4]) + paramList->ParameterValueOffset = + realloc(paramList->ParameterValueOffset, + paramList->Size * sizeof(unsigned)); + + paramList->ParameterValues = (gl_constant_value *) _mesa_align_realloc(paramList->ParameterValues, /* old buf */ oldNum * 4 * sizeof(gl_constant_value),/* old sz */ paramList->Size*4*sizeof(gl_constant_value),/*new*/ @@ -232,14 +240,17 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList, gl_register_file type, const char *name, GLuint size, GLenum datatype, const gl_constant_value *values, - const gl_state_index16 state[STATE_LENGTH]) + const gl_state_index16 state[STATE_LENGTH], + bool pad_and_align) { assert(0 < size && size <=4); const GLuint oldNum = paramList->NumParameters; + unsigned oldValNum = pad_and_align ? + align(paramList->NumParameterValues, 4) : paramList->NumParameterValues; _mesa_reserve_parameter_storage(paramList, 1); - if (!paramList->Parameters || + if (!paramList->Parameters || !paramList->ParameterValueOffset || !paramList->ParameterValues) { /* out of memory */ paramList->NumParameters = 0; @@ -249,6 +260,9 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList, paramList->NumParameters = oldNum + 1; + unsigned pad = pad_and_align ? align(size, 4) : size; + paramList->NumParameterValues = oldValNum + pad; + memset(¶mList->Parameters[oldNum], 0, sizeof(struct gl_program_parameter)); @@ -258,19 +272,26 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList, p->Size = size; p->DataType = datatype; + paramList->ParameterValueOffset[oldNum] = oldValNum; if (values) { if (size >= 4) { - COPY_4V(paramList->ParameterValues[oldNum], values); + COPY_4V(paramList->ParameterValues + oldValNum, values); } else { /* copy 1, 2 or 3 values */ assert(size < 4); - for (unsigned j = 0; j < size; j++) { - paramList->ParameterValues[oldNum][j].f = values[j].f; + unsigned j; + for (j = 0; j < size; j++) { + paramList->ParameterValues[oldValNum + j].f = values[j].f; + } + + /* Zero out padding (if any) to avoid valgrind errors */ + for (; j < pad; j++) { + paramList->ParameterValues[oldValNum + j].f = 0; } } } else { for (unsigned j = 0; j < 4; j++) { - paramList->ParameterValues[oldNum][j].f = 0; + paramList->ParameterValues[oldValNum + j].f = 0; } } @@ -316,9 +337,10 @@ _mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList, if (size == 1 && swizzleOut) { for (pos = 0; pos < (GLint) paramList->NumParameters; pos++) { struct gl_program_parameter *p = paramList->Parameters + pos; + unsigned offset = paramList->ParameterValueOffset[pos]; if (p->Type == PROGRAM_CONSTANT && p->Size + size <= 4) { /* ok, found room */ - gl_constant_value *pVal = paramList->ParameterValues[pos]; + gl_constant_value *pVal = paramList->ParameterValues + offset; GLuint swz = p->Size; /* 1, 2 or 3 for Y, Z, W */ pVal[p->Size] = values[0]; p->Size++; @@ -330,7 +352,7 @@ _mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList, /* add a new parameter to store this constant */ pos = _mesa_add_parameter(paramList, PROGRAM_CONSTANT, NULL, - size, datatype, values, NULL); + size, datatype, values, NULL, true); if (pos >= 0 && swizzleOut) { if (size == 1) *swizzleOut = SWIZZLE_XXXX; @@ -369,7 +391,7 @@ _mesa_add_state_reference(struct gl_program_parameter_list *paramList, name = _mesa_program_state_string(stateTokens); index = _mesa_add_parameter(paramList, PROGRAM_STATE_VAR, name, - size, GL_NONE, NULL, stateTokens); + size, GL_NONE, NULL, stateTokens, true); paramList->StateFlags |= _mesa_program_state_flags(stateTokens); /* free name string here since we duplicated it in add_parameter() */ diff --git a/src/mesa/program/prog_parameter.h b/src/mesa/program/prog_parameter.h index 41b3fe838a8..83eb0c5613a 100644 --- a/src/mesa/program/prog_parameter.h +++ b/src/mesa/program/prog_parameter.h @@ -82,9 +82,11 @@ struct gl_program_parameter struct gl_program_parameter_list { GLuint Size; /**< allocated size of Parameters, ParameterValues */ - GLuint NumParameters; /**< number of parameters in arrays */ + GLuint NumParameters; /**< number of used parameters in array */ + unsigned NumParameterValues; /**< number of used parameter values array */ struct gl_program_parameter *Parameters; /**< Array [Size] */ - gl_constant_value (*ParameterValues)[4]; /**< Array [Size] of constant[4] */ + unsigned *ParameterValueOffset; + gl_constant_value *ParameterValues; /**< Array [Size] of gl_constant_value */ GLbitfield StateFlags; /**< _NEW_* flags indicating which state changes might invalidate ParameterValues[] */ }; @@ -108,7 +110,8 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList, gl_register_file type, const char *name, GLuint size, GLenum datatype, const gl_constant_value *values, - const gl_state_index16 state[STATE_LENGTH]); + const gl_state_index16 state[STATE_LENGTH], + bool pad_and_align); extern GLint _mesa_add_typed_unnamed_constant(struct gl_program_parameter_list *paramList, diff --git a/src/mesa/program/prog_parameter_layout.c b/src/mesa/program/prog_parameter_layout.c index 282a367ad04..d28a6675c06 100644 --- a/src/mesa/program/prog_parameter_layout.c +++ b/src/mesa/program/prog_parameter_layout.c @@ -92,10 +92,20 @@ copy_indirect_accessed_array(struct gl_program_parameter_list *src, assert(j == dst->NumParameters); /* copy src parameter [i] to dest parameter [j] */ - memcpy(& dst->Parameters[j], curr, + memcpy(&dst->Parameters[j], curr, sizeof(dst->Parameters[j])); - memcpy(dst->ParameterValues[j], src->ParameterValues[i], - sizeof(GLfloat) * 4); + + dst->ParameterValueOffset[j] = dst->NumParameterValues; + + gl_constant_value *pv_dst = + dst->ParameterValues + dst->ParameterValueOffset[j]; + gl_constant_value *pv_src = + src->ParameterValues + src->ParameterValueOffset[i]; + + memcpy(pv_dst, pv_src, MIN2(src->Parameters[i].Size, 4) * + sizeof(GLfloat)); + dst->NumParameterValues += MIN2(dst->Parameters[j].Size, 4); + /* Pointer to the string name was copied. Null-out src param name * to prevent double free later. @@ -183,8 +193,9 @@ _mesa_layout_parameters(struct asm_parser_state *state) switch (p->Type) { case PROGRAM_CONSTANT: { - const gl_constant_value *const v = - state->prog->Parameters->ParameterValues[idx]; + unsigned pvo = state->prog->Parameters->ParameterValueOffset[idx]; + const gl_constant_value *const v = + state->prog->Parameters->ParameterValues + pvo; inst->Base.SrcReg[i].Index = _mesa_add_unnamed_constant(layout, v, p->Size, & swizzle); diff --git a/src/mesa/program/prog_print.c b/src/mesa/program/prog_print.c index b273bbf4c86..e8d087c506b 100644 --- a/src/mesa/program/prog_print.c +++ b/src/mesa/program/prog_print.c @@ -931,7 +931,9 @@ _mesa_fprint_parameter_list(FILE *f, fprintf(f, "dirty state flags: 0x%x\n", list->StateFlags); for (i = 0; i < list->NumParameters; i++){ struct gl_program_parameter *param = list->Parameters + i; - const GLfloat *v = (GLfloat *) list->ParameterValues[i]; + unsigned pvo = list->ParameterValueOffset[i]; + const GLfloat *v = (GLfloat *) list->ParameterValues + pvo; + fprintf(f, "param[%d] sz=%d %s %s = {%.3g, %.3g, %.3g, %.3g}", i, param->Size, _mesa_register_file_name(list->Parameters[i].Type), diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c index e7fa72ce10e..4d7f388cfb0 100644 --- a/src/mesa/program/prog_statevars.c +++ b/src/mesa/program/prog_statevars.c @@ -1076,9 +1076,10 @@ _mesa_load_state_parameters(struct gl_context *ctx, for (i = 0; i < paramList->NumParameters; i++) { if (paramList->Parameters[i].Type == PROGRAM_STATE_VAR) { + unsigned pvo = paramList->ParameterValueOffset[i]; _mesa_fetch_state(ctx, paramList->Parameters[i].StateIndexes, - ¶mList->ParameterValues[i][0]); + paramList->ParameterValues + pvo); } } } diff --git a/src/mesa/program/prog_to_nir.c b/src/mesa/program/prog_to_nir.c index 851b3f2e5ea..b49616c0cf9 100644 --- a/src/mesa/program/prog_to_nir.c +++ b/src/mesa/program/prog_to_nir.c @@ -161,7 +161,8 @@ ptn_get_src(struct ptn_compile *c, const struct prog_src_register *prog_src) case PROGRAM_CONSTANT: if ((c->prog->arb.IndirectRegisterFiles & (1 << PROGRAM_CONSTANT)) == 0) { - float *v = (float *) plist->ParameterValues[prog_src->Index]; + unsigned pvo = plist->ParameterValueOffset[prog_src->Index]; + float *v = (float *) plist->ParameterValues + pvo; src.src = nir_src_for_ssa(nir_imm_vec4(b, v[0], v[1], v[2], v[3])); break; } diff --git a/src/mesa/program/program_parse.y b/src/mesa/program/program_parse.y index 8adbbf0ac5b..9b63764f752 100644 --- a/src/mesa/program/program_parse.y +++ b/src/mesa/program/program_parse.y @@ -2307,7 +2307,7 @@ int add_state_reference(struct gl_program_parameter_list *param_list, name = _mesa_program_state_string(tokens); index = _mesa_add_parameter(param_list, PROGRAM_STATE_VAR, name, - size, GL_NONE, NULL, tokens); + size, GL_NONE, NULL, tokens, true); param_list->StateFlags |= _mesa_program_state_flags(tokens); /* free name string here since we duplicated it in add_parameter() */ |