struct gl_program_parameter_list *params)
{
blob_write_uint32(metadata, params->NumParameters);
+ blob_write_uint32(metadata, params->NumParameterValues);
uint32_t i = 0;
while (i < params->NumParameters) {
}
blob_write_bytes(metadata, params->ParameterValues,
- sizeof(gl_constant_value) * 4 * params->NumParameters);
+ sizeof(gl_constant_value) * params->NumParameterValues);
+
+ blob_write_bytes(metadata, params->ParameterValueOffset,
+ sizeof(uint32_t) * params->NumParameters);
blob_write_uint32(metadata, params->StateFlags);
}
gl_state_index16 state_indexes[STATE_LENGTH];
uint32_t i = 0;
uint32_t num_parameters = blob_read_uint32(metadata);
+ uint32_t num_parameters_values = blob_read_uint32(metadata);
_mesa_reserve_parameter_storage(params, num_parameters);
while (i < num_parameters) {
sizeof(state_indexes));
_mesa_add_parameter(params, type, name, size, data_type,
- NULL, state_indexes);
+ NULL, state_indexes, false);
i++;
}
blob_copy_bytes(metadata, (uint8_t *) params->ParameterValues,
- sizeof(gl_constant_value) * 4 * params->NumParameters);
+ sizeof(gl_constant_value) * num_parameters_values);
+
+ blob_copy_bytes(metadata, (uint8_t *) params->ParameterValueOffset,
+ sizeof(uint32_t) * num_parameters);
params->StateFlags = blob_read_uint32(metadata);
}
*/
case PROGRAM_CONSTANT:
case PROGRAM_STATE_VAR:
- case PROGRAM_UNIFORM:
- src = i915_emit_param4fv(p,
- &program->Parameters->ParameterValues[source->Index][0].f);
+ case PROGRAM_UNIFORM: {
+ struct gl_program_parameter_list *params = program->Parameters;
+ unsigned offset = params->ParameterValueOffset[source->Index];
+ src = i915_emit_param4fv(p, ¶ms->ParameterValues[offset].f);
break;
-
+ }
default:
i915_program_error(p, "Bad source->File: %d", source->File);
return 0;
case BRW_PARAM_DOMAIN_PARAMETER: {
unsigned idx = BRW_PARAM_PARAMETER_IDX(param);
+ unsigned offset = prog->Parameters->ParameterValueOffset[idx];
unsigned comp = BRW_PARAM_PARAMETER_COMP(param);
assert(idx < prog->Parameters->NumParameters);
- return prog->Parameters->ParameterValues[idx][comp].u;
+ return prog->Parameters->ParameterValues[offset + comp].u;
}
case BRW_PARAM_DOMAIN_UNIFORM: {
}
for(pi = 0; pi < paramList->NumParameters; pi++) {
+ unsigned pvo = paramList->ParameterValueOffset[pi];
+
switch(paramList->Parameters[pi].Type) {
case PROGRAM_STATE_VAR:
//fprintf(stderr, "%s", vp->Parameters->Parameters[pi].Name);
case PROGRAM_CONSTANT:
- *fcmd++ = paramList->ParameterValues[pi][0].f;
- *fcmd++ = paramList->ParameterValues[pi][1].f;
- *fcmd++ = paramList->ParameterValues[pi][2].f;
- *fcmd++ = paramList->ParameterValues[pi][3].f;
+ *fcmd++ = paramList->ParameterValues[pvo + 0].f;
+ *fcmd++ = paramList->ParameterValues[pvo + 1].f;
+ *fcmd++ = paramList->ParameterValues[pvo + 2].f;
+ *fcmd++ = paramList->ParameterValues[pvo + 3].f;
break;
default:
_mesa_problem(NULL, "Bad param type in %s", __func__);
printf("Program %d %s shader parameters:\n",
shProg->Name, _mesa_shader_stage_to_string(i));
for (unsigned j = 0; j < prog->Parameters->NumParameters; j++) {
- printf("%s: %p %f %f %f %f\n",
+ unsigned pvo = prog->Parameters->ParameterValueOffset[j];
+ printf("%s: %u %p %f %f %f %f\n",
prog->Parameters->Parameters[j].Name,
- prog->Parameters->ParameterValues[j],
- prog->Parameters->ParameterValues[j][0].f,
- prog->Parameters->ParameterValues[j][1].f,
- prog->Parameters->ParameterValues[j][2].f,
- prog->Parameters->ParameterValues[j][3].f);
+ pvo,
+ prog->Parameters->ParameterValues + pvo,
+ prog->Parameters->ParameterValues[pvo].f,
+ prog->Parameters->ParameterValues[pvo + 1].f,
+ prog->Parameters->ParameterValues[pvo + 2].f,
+ prog->Parameters->ParameterValues[pvo + 3].f);
}
}
fflush(stdout);
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
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
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;
}
}
}
/* 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];
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;
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) {
/* 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);
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;
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);
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*/
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;
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));
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;
}
}
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++;
/* 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;
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() */
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[] */
};
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,
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.
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);
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),
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);
}
}
}
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;
}
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() */
}
for (i = 0; i < program->Parameters->NumParameters; i++) {
+ unsigned pvo = program->Parameters->ParameterValueOffset[i];
+
switch (program->Parameters->Parameters[i].Type) {
case PROGRAM_STATE_VAR:
case PROGRAM_UNIFORM:
case PROGRAM_CONSTANT:
t->constants[i] =
ureg_DECL_immediate(ureg,
- (const float*)program->Parameters->ParameterValues[i],
+ (const float*)program->Parameters->ParameterValues + pvo,
4);
break;
default:
/* we always have the ATI_fs constants, and the fog params */
for (i = 0; i < MAX_NUM_FRAGMENT_CONSTANTS_ATI; i++) {
_mesa_add_parameter(prog->Parameters, PROGRAM_UNIFORM,
- NULL, 4, GL_FLOAT, NULL, NULL);
+ NULL, 4, GL_FLOAT, NULL, NULL, true);
}
_mesa_add_state_reference(prog->Parameters, fog_params_state);
_mesa_add_state_reference(prog->Parameters, fog_color);
unsigned c;
for (c = 0; c < MAX_NUM_FRAGMENT_CONSTANTS_ATI; c++) {
+ unsigned offset = params->ParameterValueOffset[c];
if (ati_fs->LocalConstDef & (1 << c))
- memcpy(params->ParameterValues[c],
+ memcpy(params->ParameterValues + offset,
ati_fs->Constants[c], sizeof(GLfloat) * 4);
else
- memcpy(params->ParameterValues[c],
+ memcpy(params->ParameterValues + offset,
st->ctx->ATIFragmentShader.GlobalConstants[c], sizeof(GLfloat) * 4);
}
}
t->num_constants = proginfo->Parameters->NumParameters;
for (i = 0; i < proginfo->Parameters->NumParameters; i++) {
+ unsigned pvo = proginfo->Parameters->ParameterValueOffset[i];
+
switch (proginfo->Parameters->Parameters[i].Type) {
case PROGRAM_STATE_VAR:
case PROGRAM_UNIFORM:
t->constants[i] = ureg_DECL_constant(ureg, i);
else
t->constants[i] = emit_immediate(t,
- proginfo->Parameters->ParameterValues[i],
+ proginfo->Parameters->ParameterValues + pvo,
proginfo->Parameters->Parameters[i].DataType,
4);
break;
}
for (i = 0; i < program->Parameters->NumParameters; i++) {
+ unsigned pvo = program->Parameters->ParameterValueOffset[i];
+
switch (program->Parameters->Parameters[i].Type) {
case PROGRAM_STATE_VAR:
case PROGRAM_UNIFORM:
*/
case PROGRAM_CONSTANT:
if (program->arb.IndirectRegisterFiles & PROGRAM_ANY_CONST)
- t->constants[i] = ureg_DECL_constant(ureg, i);
+ t->constants[i] = ureg_DECL_constant( ureg, i );
else
- t->constants[i] =
+ t->constants[i] =
ureg_DECL_immediate(ureg,
(const float *)
- program->Parameters->ParameterValues[i],
+ program->Parameters->ParameterValues + pvo,
4);
break;
default: