#include "brw_shader.h"
#include "brw_nir.h"
-#include "glsl/ir.h"
-#include "glsl/ir_uniform.h"
+#include "compiler/glsl/ir_uniform.h"
static void
brw_nir_setup_glsl_builtin_uniform(nir_variable *var,
const struct gl_program *prog,
struct brw_stage_prog_data *stage_prog_data,
- unsigned comps_per_unit)
+ bool is_scalar)
{
const nir_state_slot *const slots = var->state_slots;
assert(var->state_slots != NULL);
- unsigned uniform_index = var->data.driver_location * comps_per_unit;
+ unsigned uniform_index = var->data.driver_location / 4;
for (unsigned int i = 0; i < var->num_state_slots; i++) {
/* This state reference has already been setup by ir_to_mesa, but we'll
* get the same index back here.
* and move on to the next one. In vec4, we need to continue and pad
* it out to 4 components.
*/
- if (swiz == last_swiz && comps_per_unit == 1)
+ if (swiz == last_swiz && is_scalar)
break;
last_swiz = swiz;
brw_nir_setup_glsl_uniform(gl_shader_stage stage, nir_variable *var,
struct gl_shader_program *shader_prog,
struct brw_stage_prog_data *stage_prog_data,
- unsigned comps_per_unit)
+ bool is_scalar)
{
int namelen = strlen(var->name);
/* The data for our (non-builtin) uniforms is stored in a series of
- * gl_uniform_driver_storage structs for each subcomponent that
+ * gl_uniform_storage structs for each subcomponent that
* glGetUniformLocation() could name. We know it's been set up in the same
* order we'd walk the type, so walk the list of storage and find anything
* with our name, or the prefix of a component that starts with our name.
*/
- unsigned uniform_index = var->data.driver_location * comps_per_unit;
+ unsigned uniform_index = var->data.driver_location / 4;
for (unsigned u = 0; u < shader_prog->NumUniformStorage; u++) {
struct gl_uniform_storage *storage = &shader_prog->UniformStorage[u];
stage_prog_data->param[uniform_index++] = components++;
}
- /* Pad out with zeros if needed (only needed for vec4) */
- for (; i < comps_per_unit; i++) {
- static const gl_constant_value zero = { 0.0 };
- stage_prog_data->param[uniform_index++] = &zero;
+ if (!is_scalar) {
+ /* Pad out with zeros if needed (only needed for vec4) */
+ for (; i < 4; i++) {
+ static const gl_constant_value zero = { 0.0 };
+ stage_prog_data->param[uniform_index++] = &zero;
+ }
}
}
}
struct brw_stage_prog_data *stage_prog_data,
bool is_scalar)
{
- unsigned comps_per_unit = is_scalar ? 1 : 4;
-
nir_foreach_variable(var, &shader->uniforms) {
/* UBO's, atomics and samplers don't take up space in the
uniform file */
if (strncmp(var->name, "gl_", 3) == 0) {
brw_nir_setup_glsl_builtin_uniform(var, prog, stage_prog_data,
- comps_per_unit);
+ is_scalar);
} else {
brw_nir_setup_glsl_uniform(shader->stage, var, shader_prog,
- stage_prog_data, comps_per_unit);
+ stage_prog_data, is_scalar);
}
}
}