Exemplo n.º 1
0
static void
build_color_shaders(struct nir_shader **out_vs,
                    struct nir_shader **out_fs,
                    uint32_t frag_output)
{
	nir_builder vs_b;
	nir_builder fs_b;

	nir_builder_init_simple_shader(&vs_b, NULL, MESA_SHADER_VERTEX, NULL);
	nir_builder_init_simple_shader(&fs_b, NULL, MESA_SHADER_FRAGMENT, NULL);

	vs_b.shader->info.name = ralloc_strdup(vs_b.shader, "meta_clear_color_vs");
	fs_b.shader->info.name = ralloc_strdup(fs_b.shader, "meta_clear_color_fs");

	const struct glsl_type *position_type = glsl_vec4_type();
	const struct glsl_type *color_type = glsl_vec4_type();

	nir_variable *vs_in_pos =
		nir_variable_create(vs_b.shader, nir_var_shader_in, position_type,
				    "a_position");
	vs_in_pos->data.location = VERT_ATTRIB_GENERIC0;

	nir_variable *vs_out_pos =
		nir_variable_create(vs_b.shader, nir_var_shader_out, position_type,
				    "gl_Position");
	vs_out_pos->data.location = VARYING_SLOT_POS;

	nir_variable *vs_in_color =
		nir_variable_create(vs_b.shader, nir_var_shader_in, color_type,
				    "a_color");
	vs_in_color->data.location = VERT_ATTRIB_GENERIC1;

	nir_variable *vs_out_color =
		nir_variable_create(vs_b.shader, nir_var_shader_out, color_type,
				    "v_color");
	vs_out_color->data.location = VARYING_SLOT_VAR0;
	vs_out_color->data.interpolation = INTERP_MODE_FLAT;

	nir_variable *fs_in_color =
		nir_variable_create(fs_b.shader, nir_var_shader_in, color_type,
				    "v_color");
	fs_in_color->data.location = vs_out_color->data.location;
	fs_in_color->data.interpolation = vs_out_color->data.interpolation;

	nir_variable *fs_out_color =
		nir_variable_create(fs_b.shader, nir_var_shader_out, color_type,
				    "f_color");
	fs_out_color->data.location = FRAG_RESULT_DATA0 + frag_output;

	nir_copy_var(&vs_b, vs_out_pos, vs_in_pos);
	nir_copy_var(&vs_b, vs_out_color, vs_in_color);
	nir_copy_var(&fs_b, fs_out_color, fs_in_color);

	*out_vs = vs_b.shader;
	*out_fs = fs_b.shader;
}
Exemplo n.º 2
0
static void
brw_blorp_params_get_clear_kernel(struct brw_context *brw,
                                  struct brw_blorp_params *params,
                                  bool use_replicated_data)
{
    struct brw_blorp_const_color_prog_key blorp_key;
    memset(&blorp_key, 0, sizeof(blorp_key));
    blorp_key.use_simd16_replicated_data = use_replicated_data;

    if (brw_search_cache(&brw->cache, BRW_CACHE_BLORP_PROG,
                         &blorp_key, sizeof(blorp_key),
                         &params->wm_prog_kernel, &params->wm_prog_data))
        return;

    void *mem_ctx = ralloc_context(NULL);

    nir_builder b;
    nir_builder_init_simple_shader(&b, NULL, MESA_SHADER_FRAGMENT, NULL);
    b.shader->info.name = ralloc_strdup(b.shader, "BLORP-clear");

    nir_variable *v_color = nir_variable_create(b.shader, nir_var_shader_in,
                            glsl_vec4_type(), "v_color");
    v_color->data.location = VARYING_SLOT_VAR0;
    v_color->data.interpolation = INTERP_MODE_FLAT;

    nir_variable *frag_color = nir_variable_create(b.shader, nir_var_shader_out,
                               glsl_vec4_type(),
                               "gl_FragColor");
    frag_color->data.location = FRAG_RESULT_COLOR;

    nir_copy_var(&b, frag_color, v_color);

    struct brw_wm_prog_key wm_key;
    brw_blorp_init_wm_prog_key(&wm_key);

    struct brw_blorp_prog_data prog_data;
    unsigned program_size;
    const unsigned *program =
        brw_blorp_compile_nir_shader(brw, b.shader, &wm_key, use_replicated_data,
                                     &prog_data, &program_size);

    brw_upload_cache(&brw->cache, BRW_CACHE_BLORP_PROG,
                     &blorp_key, sizeof(blorp_key),
                     program, program_size,
                     &prog_data, sizeof(prog_data),
                     &params->wm_prog_kernel, &params->wm_prog_data);

    ralloc_free(mem_ctx);
}
Exemplo n.º 3
0
/* passthrough vertex shader */
static nir_shader *
build_nir_vs(void)
{
	const struct glsl_type *vec4 = glsl_vec4_type();

	nir_builder b;
	nir_variable *a_position;
	nir_variable *v_position;

	nir_builder_init_simple_shader(&b, NULL, MESA_SHADER_VERTEX, NULL);
	b.shader->info.name = ralloc_strdup(b.shader, "meta_depth_decomp_vs");

	a_position = nir_variable_create(b.shader, nir_var_shader_in, vec4,
					 "a_position");
	a_position->data.location = VERT_ATTRIB_GENERIC0;

	v_position = nir_variable_create(b.shader, nir_var_shader_out, vec4,
					 "gl_Position");
	v_position->data.location = VARYING_SLOT_POS;

	nir_copy_var(&b, v_position, a_position);

	return b.shader;
}