Ejemplo n.º 1
0
/* emit 0, 0, 0, 1 */
static nir_shader *
build_nir_fs(void)
{
	const struct glsl_type *vec4 = glsl_vec4_type();
	nir_builder b;
	nir_variable *f_color; /* vec4, fragment output color */

	nir_builder_init_simple_shader(&b, NULL, MESA_SHADER_FRAGMENT, NULL);
	b.shader->info.name = ralloc_asprintf(b.shader,
					       "meta_resolve_fs");

	f_color = nir_variable_create(b.shader, nir_var_shader_out, vec4,
				      "f_color");
	f_color->data.location = FRAG_RESULT_DATA0;
	nir_store_var(&b, f_color, nir_imm_vec4(&b, 0.0, 0.0, 0.0, 1.0), 0xf);

	return b.shader;
}
Ejemplo n.º 2
0
/* see emit_wpos_adjustment() in st_mesa_to_tgsi.c */
static void
emit_wpos_adjustment(lower_wpos_ytransform_state *state,
                     nir_intrinsic_instr *intr,
                     bool invert, float adjX, float adjY[2])
{
    nir_builder *b = &state->b;
    nir_variable *fragcoord = intr->variables[0]->var;
    nir_ssa_def *wpostrans, *wpos_temp, *wpos_temp_y, *wpos_input;

    assert(intr->dest.is_ssa);

    b->cursor = nir_before_instr(&intr->instr);

    wpostrans = get_transform(state);
    wpos_input = nir_load_var(b, fragcoord);

    /* First, apply the coordinate shift: */
    if (adjX || adjY[0] || adjY[1]) {
        if (adjY[0] != adjY[1]) {
            /* Adjust the y coordinate by adjY[1] or adjY[0] respectively
             * depending on whether inversion is actually going to be applied
             * or not, which is determined by testing against the inversion
             * state variable used below, which will be either +1 or -1.
             */
            nir_ssa_def *adj_temp;

            adj_temp = nir_cmp(b,
                               nir_channel(b, wpostrans, invert ? 2 : 0),
                               nir_imm_vec4(b, adjX, adjY[0], 0.0f, 0.0f),
                               nir_imm_vec4(b, adjX, adjY[1], 0.0f, 0.0f));

            wpos_temp = nir_fadd(b, wpos_input, adj_temp);
        } else {
            wpos_temp = nir_fadd(b,
                                 wpos_input,
                                 nir_imm_vec4(b, adjX, adjY[0], 0.0f, 0.0f));
        }
        wpos_input = wpos_temp;
    } else {
        /* MOV wpos_temp, input[wpos]
         */
        wpos_temp = wpos_input;
    }

    /* Now the conditional y flip: STATE_FB_WPOS_Y_TRANSFORM.xy/zw will be
     * inversion/identity, or the other way around if we're drawing to an FBO.
     */
    if (invert) {
        /* wpos_temp.y = wpos_input * wpostrans.xxxx + wpostrans.yyyy */
        wpos_temp_y = nir_fadd(b, nir_fmul(b, nir_channel(b, wpos_temp, 1),
                                           nir_channel(b, wpostrans, 0)),
                               nir_channel(b, wpostrans, 1));
    } else {
        /* wpos_temp.y = wpos_input * wpostrans.zzzz + wpostrans.wwww */
        wpos_temp_y = nir_fadd(b, nir_fmul(b, nir_channel(b, wpos_temp, 1),
                                           nir_channel(b, wpostrans, 2)),
                               nir_channel(b, wpostrans, 3));
    }

    wpos_temp = nir_vec4(b,
                         nir_channel(b, wpos_temp, 0),
                         wpos_temp_y,
                         nir_channel(b, wpos_temp, 2),
                         nir_channel(b, wpos_temp, 3));

    nir_ssa_def_rewrite_uses(&intr->dest.ssa, nir_src_for_ssa(wpos_temp));
}