summaryrefslogtreecommitdiffstats
path: root/src/mesa/program/prog_to_nir.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2018-03-19 13:43:35 -0700
committerJason Ekstrand <[email protected]>2018-04-05 13:20:39 -0700
commite85b95269e49036402c3a8204450707eb6111d15 (patch)
tree9406d684bcdf3c115f33d677ebc585057437adda /src/mesa/program/prog_to_nir.c
parentc7dd59b06d93e6820189e2d1e087c0811707ee07 (diff)
prog/nir: Simplify some load/store operations
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/mesa/program/prog_to_nir.c')
-rw-r--r--src/mesa/program/prog_to_nir.c53
1 files changed, 13 insertions, 40 deletions
diff --git a/src/mesa/program/prog_to_nir.c b/src/mesa/program/prog_to_nir.c
index b49616c0cf9..3ee44ce489e 100644
--- a/src/mesa/program/prog_to_nir.c
+++ b/src/mesa/program/prog_to_nir.c
@@ -136,15 +136,8 @@ ptn_get_src(struct ptn_compile *c, const struct prog_src_register *prog_src)
assert(prog_src->Index >= 0 && prog_src->Index < VARYING_SLOT_MAX);
- nir_intrinsic_instr *load =
- nir_intrinsic_instr_create(b->shader, nir_intrinsic_load_var);
- load->num_components = 4;
- load->variables[0] = nir_deref_var_create(load, c->input_vars[prog_src->Index]);
-
- nir_ssa_dest_init(&load->instr, &load->dest, 4, 32, NULL);
- nir_builder_instr_insert(b, &load->instr);
-
- src.src = nir_src_for_ssa(&load->dest.ssa);
+ nir_variable *var = c->input_vars[prog_src->Index];
+ src.src = nir_src_for_ssa(nir_load_var(b, var));
break;
}
case PROGRAM_STATE_VAR:
@@ -861,27 +854,17 @@ ptn_add_output_stores(struct ptn_compile *c)
nir_builder *b = &c->build;
nir_foreach_variable(var, &b->shader->outputs) {
- nir_intrinsic_instr *store =
- nir_intrinsic_instr_create(b->shader, nir_intrinsic_store_var);
- store->num_components = glsl_get_vector_elements(var->type);
- nir_intrinsic_set_write_mask(store, (1 << store->num_components) - 1);
- store->variables[0] =
- nir_deref_var_create(store, c->output_vars[var->data.location]);
-
+ nir_ssa_def *src = nir_load_reg(b, c->output_regs[var->data.location]);
if (c->prog->Target == GL_FRAGMENT_PROGRAM_ARB &&
var->data.location == FRAG_RESULT_DEPTH) {
/* result.depth has this strange convention of being the .z component of
* a vec4 with undefined .xyw components. We resolve it to a scalar, to
* match GLSL's gl_FragDepth and the expectations of most backends.
*/
- nir_alu_src alu_src = { NIR_SRC_INIT };
- alu_src.src = nir_src_for_reg(c->output_regs[FRAG_RESULT_DEPTH]);
- alu_src.swizzle[0] = SWIZZLE_Z;
- store->src[0] = nir_src_for_ssa(nir_fmov_alu(b, alu_src, 1));
- } else {
- store->src[0].reg.reg = c->output_regs[var->data.location];
+ src = nir_channel(b, src, 2);
}
- nir_builder_instr_insert(b, &store->instr);
+ unsigned num_components = glsl_get_vector_elements(var->type);
+ nir_store_var(b, var, src, (1 << num_components) - 1);
}
}
@@ -914,26 +897,16 @@ setup_registers_and_variables(struct ptn_compile *c)
*/
var->type = glsl_float_type();
- nir_intrinsic_instr *load_x =
- nir_intrinsic_instr_create(shader, nir_intrinsic_load_var);
- load_x->num_components = 1;
- load_x->variables[0] = nir_deref_var_create(load_x, var);
- nir_ssa_dest_init(&load_x->instr, &load_x->dest, 1, 32, NULL);
- nir_builder_instr_insert(b, &load_x->instr);
-
- nir_ssa_def *f001 = nir_vec4(b, &load_x->dest.ssa, nir_imm_float(b, 0.0),
- nir_imm_float(b, 0.0), nir_imm_float(b, 1.0));
-
nir_variable *fullvar =
nir_local_variable_create(b->impl, glsl_vec4_type(),
"fogcoord_tmp");
- nir_intrinsic_instr *store =
- nir_intrinsic_instr_create(shader, nir_intrinsic_store_var);
- store->num_components = 4;
- nir_intrinsic_set_write_mask(store, WRITEMASK_XYZW);
- store->variables[0] = nir_deref_var_create(store, fullvar);
- store->src[0] = nir_src_for_ssa(f001);
- nir_builder_instr_insert(b, &store->instr);
+
+ nir_store_var(b, fullvar,
+ nir_vec4(b, nir_load_var(b, var),
+ nir_imm_float(b, 0.0),
+ nir_imm_float(b, 0.0),
+ nir_imm_float(b, 1.0)),
+ WRITEMASK_XYZW);
/* We inserted the real input into the list so the driver has real
* inputs, but we set c->input_vars[i] to the temporary so we use