void nir_setup_inputs(nir_shader *shader);
void nir_setup_outputs(nir_shader *shader);
void nir_setup_uniforms(nir_shader *shader);
- void nir_setup_uniform(nir_variable *var);
- void nir_setup_builtin_uniform(nir_variable *var);
void nir_emit_system_values(nir_shader *shader);
void nir_emit_impl(nir_function_impl *impl);
void nir_emit_cf_list(exec_list *list);
uniforms = shader->num_uniforms;
if (shader_prog) {
+ brw_nir_setup_glsl_uniforms(shader, shader_prog, prog,
+ stage_prog_data, true);
+
foreach_list_typed(nir_variable, var, node, &shader->uniforms) {
/* UBO's and atomics don't take up space in the uniform file */
if (var->interface_type != NULL || var->type->contains_atomic())
continue;
- if (strncmp(var->name, "gl_", 3) == 0)
- nir_setup_builtin_uniform(var);
- else
- nir_setup_uniform(var);
if(type_size_scalar(var->type) > 0)
param_size[var->data.driver_location] = type_size_scalar(var->type);
}
}
}
-void
-fs_visitor::nir_setup_uniform(nir_variable *var)
-{
- 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
- * 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 index = var->data.driver_location;
- for (unsigned u = 0; u < shader_prog->NumUniformStorage; u++) {
- struct gl_uniform_storage *storage = &shader_prog->UniformStorage[u];
-
- if (storage->builtin)
- continue;
-
- if (strncmp(var->name, storage->name, namelen) != 0 ||
- (storage->name[namelen] != 0 &&
- storage->name[namelen] != '.' &&
- storage->name[namelen] != '[')) {
- continue;
- }
-
- if (storage->type->is_image()) {
- brw_setup_image_uniform_values(stage, stage_prog_data,
- index, storage);
- } else {
- unsigned slots = storage->type->component_slots();
- if (storage->array_elements)
- slots *= storage->array_elements;
-
- for (unsigned i = 0; i < slots; i++) {
- stage_prog_data->param[index++] = &storage->storage[i];
- }
- }
- }
-}
-
-void
-fs_visitor::nir_setup_builtin_uniform(nir_variable *var)
-{
- const nir_state_slot *const slots = var->state_slots;
- assert(var->state_slots != NULL);
-
- unsigned uniform_index = var->data.driver_location;
- 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.
- */
- int index = _mesa_add_state_reference(this->prog->Parameters,
- (gl_state_index *)slots[i].tokens);
-
- /* Add each of the unique swizzles of the element as a parameter.
- * This'll end up matching the expected layout of the
- * array/matrix/structure we're trying to fill in.
- */
- int last_swiz = -1;
- for (unsigned int j = 0; j < 4; j++) {
- int swiz = GET_SWZ(slots[i].swizzle, j);
- if (swiz == last_swiz)
- break;
- last_swiz = swiz;
-
- stage_prog_data->param[uniform_index++] =
- &prog->Parameters->ParameterValues[index][swiz];
- }
- }
-}
-
static bool
emit_system_values_block(nir_block *block, void *void_visitor)
{
enum glsl_base_type brw_glsl_base_type_for_nir_type(nir_alu_type type);
+void brw_nir_setup_glsl_uniforms(nir_shader *shader,
+ struct gl_shader_program *shader_prog,
+ const struct gl_program *prog,
+ struct brw_stage_prog_data *stage_prog_data,
+ bool is_scalar);
+
void brw_nir_setup_arb_uniforms(nir_shader *shader, struct gl_program *prog,
struct brw_stage_prog_data *stage_prog_data);
#include "brw_shader.h"
#include "brw_nir.h"
+#include "glsl/ir.h"
+#include "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)
+{
+ const nir_state_slot *const slots = var->state_slots;
+ assert(var->state_slots != NULL);
+
+ unsigned uniform_index = var->data.driver_location * comps_per_unit;
+ 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.
+ */
+ int index = _mesa_add_state_reference(prog->Parameters,
+ (gl_state_index *)slots[i].tokens);
+
+ /* Add each of the unique swizzles of the element as a parameter.
+ * This'll end up matching the expected layout of the
+ * array/matrix/structure we're trying to fill in.
+ */
+ int last_swiz = -1;
+ for (unsigned j = 0; j < 4; j++) {
+ int swiz = GET_SWZ(slots[i].swizzle, j);
+
+ /* If we hit a pair of identical swizzles, this means we've hit the
+ * end of the builtin variable. In scalar mode, we should just quit
+ * 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)
+ break;
+
+ last_swiz = swiz;
+
+ stage_prog_data->param[uniform_index++] =
+ &prog->Parameters->ParameterValues[index][swiz];
+ }
+ }
+}
+
+static void
+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)
+{
+ 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
+ * 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;
+ for (unsigned u = 0; u < shader_prog->NumUniformStorage; u++) {
+ struct gl_uniform_storage *storage = &shader_prog->UniformStorage[u];
+
+ if (storage->builtin)
+ continue;
+
+ if (strncmp(var->name, storage->name, namelen) != 0 ||
+ (storage->name[namelen] != 0 &&
+ storage->name[namelen] != '.' &&
+ storage->name[namelen] != '[')) {
+ continue;
+ }
+
+ if (storage->type->is_image()) {
+ brw_setup_image_uniform_values(stage, stage_prog_data,
+ uniform_index, storage);
+ } else {
+ gl_constant_value *components = storage->storage;
+ unsigned vector_count = (MAX2(storage->array_elements, 1) *
+ storage->type->matrix_columns);
+ unsigned vector_size = storage->type->vector_elements;
+
+ for (unsigned s = 0; s < vector_count; s++) {
+ unsigned i;
+ for (i = 0; i < vector_size; i++) {
+ 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;
+ }
+ }
+ }
+ }
+}
+
+void
+brw_nir_setup_glsl_uniforms(nir_shader *shader,
+ struct gl_shader_program *shader_prog,
+ const struct gl_program *prog,
+ struct brw_stage_prog_data *stage_prog_data,
+ bool is_scalar)
+{
+ unsigned comps_per_unit = is_scalar ? 1 : 4;
+
+ foreach_list_typed(nir_variable, var, node, &shader->uniforms) {
+ /* UBO's, atomics and samplers don't take up space in the
+ uniform file */
+ if (var->interface_type != NULL || var->type->contains_atomic())
+ continue;
+
+ if (strncmp(var->name, "gl_", 3) == 0) {
+ brw_nir_setup_glsl_builtin_uniform(var, prog, stage_prog_data,
+ comps_per_unit);
+ } else {
+ brw_nir_setup_glsl_uniform(shader->stage, var, shader_prog,
+ stage_prog_data, comps_per_unit);
+ }
+ }
+}
void
brw_nir_setup_arb_uniforms(nir_shader *shader, struct gl_program *prog,
virtual void emit_nir_code();
virtual void nir_setup_inputs(nir_shader *shader);
virtual void nir_setup_uniforms(nir_shader *shader);
- virtual void nir_setup_uniform(nir_variable *var);
- virtual void nir_setup_builtin_uniform(nir_variable *var);
virtual void nir_setup_system_value_intrinsic(nir_intrinsic_instr *instr);
virtual void nir_setup_system_values(nir_shader *shader);
virtual void nir_emit_impl(nir_function_impl *impl);
uniforms = shader->num_uniforms;
if (shader_prog) {
+ brw_nir_setup_glsl_uniforms(shader, shader_prog, prog,
+ stage_prog_data, false);
+
foreach_list_typed(nir_variable, var, node, &shader->uniforms) {
/* UBO's, atomics and samplers don't take up space in the
uniform file */
}
uniform_size[var->data.driver_location] = type_size_vec4(var->type);
-
- if (strncmp(var->name, "gl_", 3) == 0)
- nir_setup_builtin_uniform(var);
- else
- nir_setup_uniform(var);
}
} else {
brw_nir_setup_arb_uniforms(shader, prog, stage_prog_data);
}
}
-void
-vec4_visitor::nir_setup_uniform(nir_variable *var)
-{
- 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
- * 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 index = var->data.driver_location * 4;
- for (unsigned u = 0; u < shader_prog->NumUniformStorage; u++) {
- struct gl_uniform_storage *storage = &shader_prog->UniformStorage[u];
-
- if (storage->builtin)
- continue;
-
- if (strncmp(var->name, storage->name, namelen) != 0 ||
- (storage->name[namelen] != 0 &&
- storage->name[namelen] != '.' &&
- storage->name[namelen] != '[')) {
- continue;
- }
-
- gl_constant_value *components = storage->storage;
- unsigned vector_count = (MAX2(storage->array_elements, 1) *
- storage->type->matrix_columns);
-
- for (unsigned s = 0; s < vector_count; s++) {
- int i;
- for (i = 0; i < storage->type->vector_elements; i++) {
- stage_prog_data->param[index++] = components++;
- }
- for (; i < 4; i++) {
- static const gl_constant_value zero = { 0.0 };
- stage_prog_data->param[index++] = &zero;
- }
- }
- }
-}
-
-void
-vec4_visitor::nir_setup_builtin_uniform(nir_variable *var)
-{
- const nir_state_slot *const slots = var->state_slots;
- assert(var->state_slots != NULL);
-
- 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. We can reference
- * ParameterValues directly, since unlike brw_fs.cpp, we never
- * add new state references during compile.
- */
- int index = _mesa_add_state_reference(prog->Parameters,
- (gl_state_index *)slots[i].tokens);
- gl_constant_value *values =
- &prog->Parameters->ParameterValues[index][0];
-
- for (unsigned j = 0; j < 4; j++)
- stage_prog_data->param[uniform_index++] =
- &values[GET_SWZ(slots[i].swizzle, j)];
- }
-}
-
void
vec4_visitor::nir_emit_impl(nir_function_impl *impl)
{