#include "brw_nir.h"
#include "brw_shader.h"
-#include "glsl/nir/glsl_to_nir.h"
-#include "glsl/nir/nir_builder.h"
+#include "compiler/nir/glsl_to_nir.h"
+#include "compiler/nir/nir_builder.h"
#include "program/prog_to_nir.h"
static bool
};
static bool
-add_const_offset_to_base(nir_block *block, void *closure)
+add_const_offset_to_base_block(nir_block *block, void *closure)
{
struct add_const_offset_to_base_params *params = closure;
nir_builder *b = ¶ms->b;
}
}
return true;
+}
+
+static void
+add_const_offset_to_base(nir_shader *nir, nir_variable_mode mode)
+{
+ struct add_const_offset_to_base_params params = { .mode = mode };
+ nir_foreach_function(nir, f) {
+ if (f->impl) {
+ nir_builder_init(¶ms.b, f->impl);
+ nir_foreach_block(f->impl, add_const_offset_to_base_block, ¶ms);
+ }
+ }
}
static bool
const struct brw_device_info *devinfo,
bool is_scalar)
{
- struct add_const_offset_to_base_params params = {
- .mode = nir_var_shader_in
- };
-
switch (nir->stage) {
case MESA_SHADER_VERTEX:
/* Start with the location of the variable's base. */
*/
nir_lower_io(nir, nir_var_shader_in, type_size_vec4);
+ /* This pass needs actual constants */
+ nir_opt_constant_folding(nir);
+
+ add_const_offset_to_base(nir, nir_var_shader_in);
+
if (is_scalar) {
/* Finally, translate VERT_ATTRIB_* values into the actual registers.
*
*/
GLbitfield64 inputs_read = nir->info.inputs_read;
- /* This pass needs actual constants */
- nir_opt_constant_folding(nir);
-
- nir_foreach_overload(nir, overload) {
- if (overload->impl) {
- nir_builder_init(¶ms.b, overload->impl);
- nir_foreach_block(overload->impl, add_const_offset_to_base, ¶ms);
- nir_foreach_block(overload->impl, remap_vs_attrs, &inputs_read);
+ nir_foreach_function(nir, function) {
+ if (function->impl) {
+ nir_foreach_block(function->impl, remap_vs_attrs, &inputs_read);
}
}
}
/* This pass needs actual constants */
nir_opt_constant_folding(nir);
- nir_foreach_overload(nir, overload) {
- if (overload->impl) {
- nir_builder_init(¶ms.b, overload->impl);
- nir_foreach_block(overload->impl, add_const_offset_to_base, ¶ms);
- nir_foreach_block(overload->impl, remap_inputs_with_vue_map,
+ add_const_offset_to_base(nir, nir_var_shader_in);
+
+ nir_foreach_function(nir, function) {
+ if (function->impl) {
+ nir_foreach_block(function->impl, remap_inputs_with_vue_map,
&input_vue_map);
}
}
/* This pass needs actual constants */
nir_opt_constant_folding(nir);
- nir_foreach_overload(nir, overload) {
- if (overload->impl) {
- nir_builder_init(¶ms.b, overload->impl);
- nir_foreach_block(overload->impl, add_const_offset_to_base, ¶ms);
- nir_builder_init(&state.b, overload->impl);
- nir_foreach_block(overload->impl, remap_patch_urb_offsets, &state);
+ add_const_offset_to_base(nir, nir_var_shader_in);
+
+ nir_foreach_function(nir, function) {
+ if (function->impl) {
+ nir_builder_init(&state.b, function->impl);
+ nir_foreach_block(function->impl, remap_patch_urb_offsets, &state);
}
}
break;
}
break;
case MESA_SHADER_TESS_CTRL: {
- struct add_const_offset_to_base_params params = {
- .mode = nir_var_shader_out
- };
-
struct remap_patch_urb_offsets_state state;
brw_compute_tess_vue_map(&state.vue_map, nir->info.outputs_written,
nir->info.patch_outputs_written);
/* This pass needs actual constants */
nir_opt_constant_folding(nir);
- nir_foreach_overload(nir, overload) {
- if (overload->impl) {
- nir_builder_init(¶ms.b, overload->impl);
- nir_foreach_block(overload->impl, add_const_offset_to_base, ¶ms);
- nir_builder_init(&state.b, overload->impl);
- nir_foreach_block(overload->impl, remap_patch_urb_offsets, &state);
+ add_const_offset_to_base(nir, nir_var_shader_out);
+
+ nir_foreach_function(nir, function) {
+ if (function->impl) {
+ nir_builder_init(&state.b, function->impl);
+ nir_foreach_block(function->impl, remap_patch_urb_offsets, &state);
}
}
break;
}
}
-#include "util/debug.h"
+#define OPT(pass, ...) ({ \
+ bool this_progress = false; \
+ NIR_PASS(this_progress, nir, pass, ##__VA_ARGS__); \
+ if (this_progress) \
+ progress = true; \
+ this_progress; \
+})
-static bool
-should_clone_nir()
-{
- static int should_clone = -1;
- if (should_clone < 1)
- should_clone = env_var_as_boolean("NIR_TEST_CLONE", false);
-
- return should_clone;
-}
-
-#define _OPT(do_pass) (({ \
- bool this_progress = true; \
- do_pass \
- nir_validate_shader(nir); \
- if (should_clone_nir()) { \
- nir_shader *clone = nir_shader_clone(ralloc_parent(nir), nir); \
- ralloc_free(nir); \
- nir = clone; \
- } \
- this_progress; \
-}))
-
-#define OPT(pass, ...) _OPT( \
- nir_metadata_set_validation_flag(nir); \
- this_progress = pass(nir ,##__VA_ARGS__); \
- if (this_progress) { \
- progress = true; \
- nir_metadata_check_validation_flag(nir); \
- } \
-)
-
-#define OPT_V(pass, ...) _OPT( \
- pass(nir, ##__VA_ARGS__); \
-)
+#define OPT_V(pass, ...) NIR_PASS_V(nir, pass, ##__VA_ARGS__)
static nir_shader *
nir_optimize(nir_shader *nir, bool is_scalar)
nir = nir_optimize(nir, is_scalar);
+ if (is_scalar) {
+ OPT_V(nir_lower_load_const_to_scalar);
+ }
+
/* Lower a bunch of stuff */
OPT_V(nir_lower_var_copies);
return nir;
}
-/* Lowers inputs, outputs, uniforms, and samplers for i965
- *
- * This function does all of the standard lowering prior to post-processing.
- * The lowering done is highly gen, stage, and backend-specific. The
- * shader_prog parameter is optional and is used only for lowering sampler
- * derefs and atomics for GLSL shaders.
- */
+/** Lower input and output loads and stores for i965. */
nir_shader *
-brw_lower_nir(nir_shader *nir,
- const struct brw_device_info *devinfo,
- const struct gl_shader_program *shader_prog,
- bool is_scalar)
+brw_nir_lower_io(nir_shader *nir,
+ const struct brw_device_info *devinfo,
+ bool is_scalar)
{
bool progress; /* Written by OPT and OPT_V */
(void)progress;
OPT_V(brw_nir_lower_inputs, devinfo, is_scalar);
OPT_V(brw_nir_lower_outputs, devinfo, is_scalar);
- OPT_V(brw_nir_lower_uniforms, is_scalar);
OPT_V(nir_lower_io, nir_var_all, is_scalar ? type_size_scalar : type_size_vec4);
- if (shader_prog) {
- OPT_V(nir_lower_samplers, shader_prog);
- }
-
- OPT(nir_lower_system_values);
-
- if (shader_prog) {
- OPT_V(nir_lower_atomics, shader_prog);
- }
-
return nir_optimize(nir, is_scalar);
}
if (unlikely(debug_enabled)) {
/* Re-index SSA defs so we print more sensible numbers. */
- nir_foreach_overload(nir, overload) {
- if (overload->impl)
- nir_index_ssa_defs(overload->impl);
+ nir_foreach_function(nir, function) {
+ if (function->impl)
+ nir_index_ssa_defs(function->impl);
}
fprintf(stderr, "NIR (SSA form) for %s shader:\n",
(void)progress;
nir = brw_preprocess_nir(nir, is_scalar);
- nir = brw_lower_nir(nir, devinfo, shader_prog, is_scalar);
+
+ OPT(nir_lower_system_values);
+ OPT_V(brw_nir_lower_uniforms, is_scalar);
+
+ if (shader_prog) {
+ OPT_V(nir_lower_samplers, shader_prog);
+ OPT_V(nir_lower_atomics, shader_prog);
+ }
+
+ if (nir->stage != MESA_SHADER_TESS_CTRL &&
+ nir->stage != MESA_SHADER_TESS_EVAL) {
+ nir = brw_nir_lower_io(nir, devinfo, is_scalar);
+ }
return nir;
}