prog/nir: Simplify some load/store operations
Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
@@ -525,6 +525,12 @@ nir_ssa_for_alu_src(nir_builder *build, nir_alu_instr *instr, unsigned srcn)
|
|||||||
return nir_imov_alu(build, *src, num_components);
|
return nir_imov_alu(build, *src, num_components);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline nir_ssa_def *
|
||||||
|
nir_load_reg(nir_builder *build, nir_register *reg)
|
||||||
|
{
|
||||||
|
return nir_ssa_for_src(build, nir_src_for_reg(reg), reg->num_components);
|
||||||
|
}
|
||||||
|
|
||||||
static inline nir_ssa_def *
|
static inline nir_ssa_def *
|
||||||
nir_load_var(nir_builder *build, nir_variable *var)
|
nir_load_var(nir_builder *build, nir_variable *var)
|
||||||
{
|
{
|
||||||
|
@@ -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);
|
assert(prog_src->Index >= 0 && prog_src->Index < VARYING_SLOT_MAX);
|
||||||
|
|
||||||
nir_intrinsic_instr *load =
|
nir_variable *var = c->input_vars[prog_src->Index];
|
||||||
nir_intrinsic_instr_create(b->shader, nir_intrinsic_load_var);
|
src.src = nir_src_for_ssa(nir_load_var(b, 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);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PROGRAM_STATE_VAR:
|
case PROGRAM_STATE_VAR:
|
||||||
@@ -861,27 +854,17 @@ ptn_add_output_stores(struct ptn_compile *c)
|
|||||||
nir_builder *b = &c->build;
|
nir_builder *b = &c->build;
|
||||||
|
|
||||||
nir_foreach_variable(var, &b->shader->outputs) {
|
nir_foreach_variable(var, &b->shader->outputs) {
|
||||||
nir_intrinsic_instr *store =
|
nir_ssa_def *src = nir_load_reg(b, c->output_regs[var->data.location]);
|
||||||
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]);
|
|
||||||
|
|
||||||
if (c->prog->Target == GL_FRAGMENT_PROGRAM_ARB &&
|
if (c->prog->Target == GL_FRAGMENT_PROGRAM_ARB &&
|
||||||
var->data.location == FRAG_RESULT_DEPTH) {
|
var->data.location == FRAG_RESULT_DEPTH) {
|
||||||
/* result.depth has this strange convention of being the .z component of
|
/* 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
|
* a vec4 with undefined .xyw components. We resolve it to a scalar, to
|
||||||
* match GLSL's gl_FragDepth and the expectations of most backends.
|
* match GLSL's gl_FragDepth and the expectations of most backends.
|
||||||
*/
|
*/
|
||||||
nir_alu_src alu_src = { NIR_SRC_INIT };
|
src = nir_channel(b, src, 2);
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
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();
|
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_variable *fullvar =
|
||||||
nir_local_variable_create(b->impl, glsl_vec4_type(),
|
nir_local_variable_create(b->impl, glsl_vec4_type(),
|
||||||
"fogcoord_tmp");
|
"fogcoord_tmp");
|
||||||
nir_intrinsic_instr *store =
|
|
||||||
nir_intrinsic_instr_create(shader, nir_intrinsic_store_var);
|
nir_store_var(b, fullvar,
|
||||||
store->num_components = 4;
|
nir_vec4(b, nir_load_var(b, var),
|
||||||
nir_intrinsic_set_write_mask(store, WRITEMASK_XYZW);
|
nir_imm_float(b, 0.0),
|
||||||
store->variables[0] = nir_deref_var_create(store, fullvar);
|
nir_imm_float(b, 0.0),
|
||||||
store->src[0] = nir_src_for_ssa(f001);
|
nir_imm_float(b, 1.0)),
|
||||||
nir_builder_instr_insert(b, &store->instr);
|
WRITEMASK_XYZW);
|
||||||
|
|
||||||
/* We inserted the real input into the list so the driver has real
|
/* 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
|
* inputs, but we set c->input_vars[i] to the temporary so we use
|
||||||
|
Reference in New Issue
Block a user