nir/builder: Add a name format arg to nir_builder_init_simple_shader().

This cleans up a bunch of gross sprintfs and keeps the caller from needing
to remember to ralloc_strdup.  I added a couple of '"%s", name ? name :
""' to radv where I didn't fully trace through whether a non-null name was
being passed in.

I also took the liberty of adding a basic name to a few shaders (pan_blit,
unit tests)

Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7323>
This commit is contained in:
Eric Anholt
2020-10-26 11:37:25 -07:00
parent 5f992802f5
commit eda3e4e055
39 changed files with 122 additions and 172 deletions

View File

@@ -548,8 +548,7 @@ radv_meta_build_nir_vs_generate_vertices(void)
nir_variable *v_position;
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "meta_vs_gen_verts");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, NULL, "meta_vs_gen_verts");
nir_ssa_def *outvec = radv_meta_gen_rect_vertices(&b);
@@ -565,9 +564,7 @@ radv_meta_build_nir_vs_generate_vertices(void)
nir_shader *
radv_meta_build_nir_fs_noop(void)
{
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL);
b.shader->info.name = ralloc_asprintf(b.shader,
"meta_noop_fs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL, "meta_noop_fs");
return b.shader;
}

View File

@@ -42,8 +42,7 @@ static nir_shader *
build_nir_vertex_shader(void)
{
const struct glsl_type *vec4 = glsl_vec4_type();
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "meta_blit_vs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, NULL, "meta_blit_vs");
nir_variable *pos_out = nir_variable_create(b.shader, nir_var_shader_out,
vec4, "gl_Position");
@@ -107,12 +106,8 @@ build_nir_vertex_shader(void)
static nir_shader *
build_nir_copy_fragment_shader(enum glsl_sampler_dim tex_dim)
{
char shader_name[64];
const struct glsl_type *vec4 = glsl_vec4_type();
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL);
sprintf(shader_name, "meta_blit_fs.%d", tex_dim);
b.shader->info.name = ralloc_strdup(b.shader, shader_name);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL, "meta_blit_fs.%d", tex_dim);
nir_variable *tex_pos_in = nir_variable_create(b.shader, nir_var_shader_in,
vec4, "v_tex_pos");
@@ -163,12 +158,8 @@ build_nir_copy_fragment_shader(enum glsl_sampler_dim tex_dim)
static nir_shader *
build_nir_copy_fragment_shader_depth(enum glsl_sampler_dim tex_dim)
{
char shader_name[64];
const struct glsl_type *vec4 = glsl_vec4_type();
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL);
sprintf(shader_name, "meta_blit_depth_fs.%d", tex_dim);
b.shader->info.name = ralloc_strdup(b.shader, shader_name);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL, "meta_blit_depth_fs.%d", tex_dim);
nir_variable *tex_pos_in = nir_variable_create(b.shader, nir_var_shader_in,
vec4, "v_tex_pos");
@@ -219,12 +210,8 @@ build_nir_copy_fragment_shader_depth(enum glsl_sampler_dim tex_dim)
static nir_shader *
build_nir_copy_fragment_shader_stencil(enum glsl_sampler_dim tex_dim)
{
char shader_name[64];
const struct glsl_type *vec4 = glsl_vec4_type();
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL);
sprintf(shader_name, "meta_blit_stencil_fs.%d", tex_dim);
b.shader->info.name = ralloc_strdup(b.shader, shader_name);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL, "meta_blit_stencil_fs.%d", tex_dim);
nir_variable *tex_pos_in = nir_variable_create(b.shader, nir_var_shader_in,
vec4, "v_tex_pos");

View File

@@ -428,8 +428,7 @@ build_nir_vertex_shader(void)
{
const struct glsl_type *vec4 = glsl_vec4_type();
const struct glsl_type *vec2 = glsl_vector_type(GLSL_TYPE_FLOAT, 2);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "meta_blit2d_vs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, NULL, "meta_blit2d_vs");
nir_variable *pos_out = nir_variable_create(b.shader, nir_var_shader_out,
vec4, "gl_Position");
@@ -601,8 +600,7 @@ build_nir_copy_fragment_shader(struct radv_device *device,
{
const struct glsl_type *vec4 = glsl_vec4_type();
const struct glsl_type *vec2 = glsl_vector_type(GLSL_TYPE_FLOAT, 2);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL);
b.shader->info.name = ralloc_strdup(b.shader, name);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL, "%s", name);
nir_variable *tex_pos_in = nir_variable_create(b.shader, nir_var_shader_in,
vec2, "v_tex_pos");
@@ -628,8 +626,7 @@ build_nir_copy_fragment_shader_depth(struct radv_device *device,
{
const struct glsl_type *vec4 = glsl_vec4_type();
const struct glsl_type *vec2 = glsl_vector_type(GLSL_TYPE_FLOAT, 2);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL);
b.shader->info.name = ralloc_strdup(b.shader, name);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL, "%s", name);
nir_variable *tex_pos_in = nir_variable_create(b.shader, nir_var_shader_in,
vec2, "v_tex_pos");
@@ -655,8 +652,7 @@ build_nir_copy_fragment_shader_stencil(struct radv_device *device,
{
const struct glsl_type *vec4 = glsl_vec4_type();
const struct glsl_type *vec2 = glsl_vector_type(GLSL_TYPE_FLOAT, 2);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL);
b.shader->info.name = ralloc_strdup(b.shader, name);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL, "%s", name);
nir_variable *tex_pos_in = nir_variable_create(b.shader, nir_var_shader_in,
vec2, "v_tex_pos");

View File

@@ -7,8 +7,8 @@
static nir_shader *
build_buffer_fill_shader(struct radv_device *dev)
{
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "meta_buffer_fill");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL,
"meta_buffer_fill");
b.shader->info.cs.local_size[0] = 64;
b.shader->info.cs.local_size[1] = 1;
b.shader->info.cs.local_size[2] = 1;
@@ -53,8 +53,8 @@ build_buffer_fill_shader(struct radv_device *dev)
static nir_shader *
build_buffer_copy_shader(struct radv_device *dev)
{
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "meta_buffer_copy");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL,
"meta_buffer_copy");
b.shader->info.cs.local_size[0] = 64;
b.shader->info.cs.local_size[1] = 1;
b.shader->info.cs.local_size[2] = 1;

View File

@@ -43,8 +43,7 @@ build_nir_itob_compute_shader(struct radv_device *dev, bool is_3d)
const struct glsl_type *img_type = glsl_image_type(GLSL_SAMPLER_DIM_BUF,
false,
GLSL_TYPE_FLOAT);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, is_3d ? "meta_itob_cs_3d" : "meta_itob_cs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL, is_3d ? "meta_itob_cs_3d" : "meta_itob_cs");
b.shader->info.cs.local_size[0] = 16;
b.shader->info.cs.local_size[1] = 16;
b.shader->info.cs.local_size[2] = 1;
@@ -271,8 +270,7 @@ build_nir_btoi_compute_shader(struct radv_device *dev, bool is_3d)
const struct glsl_type *img_type = glsl_image_type(dim,
false,
GLSL_TYPE_FLOAT);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, is_3d ? "meta_btoi_cs_3d" : "meta_btoi_cs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL, is_3d ? "meta_btoi_cs_3d" : "meta_btoi_cs");
b.shader->info.cs.local_size[0] = 16;
b.shader->info.cs.local_size[1] = 16;
b.shader->info.cs.local_size[2] = 1;
@@ -492,8 +490,7 @@ build_nir_btoi_r32g32b32_compute_shader(struct radv_device *dev)
const struct glsl_type *img_type = glsl_image_type(GLSL_SAMPLER_DIM_BUF,
false,
GLSL_TYPE_FLOAT);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "meta_btoi_r32g32b32_cs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL, "meta_btoi_r32g32b32_cs");
b.shader->info.cs.local_size[0] = 16;
b.shader->info.cs.local_size[1] = 16;
b.shader->info.cs.local_size[2] = 1;
@@ -699,8 +696,7 @@ build_nir_itoi_compute_shader(struct radv_device *dev, bool is_3d)
const struct glsl_type *img_type = glsl_image_type(dim,
false,
GLSL_TYPE_FLOAT);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, is_3d ? "meta_itoi_cs_3d" : "meta_itoi_cs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL, is_3d ? "meta_itoi_cs_3d" : "meta_itoi_cs");
b.shader->info.cs.local_size[0] = 16;
b.shader->info.cs.local_size[1] = 16;
b.shader->info.cs.local_size[2] = 1;
@@ -915,8 +911,7 @@ build_nir_itoi_r32g32b32_compute_shader(struct radv_device *dev)
const struct glsl_type *img_type = glsl_image_type(GLSL_SAMPLER_DIM_BUF,
false,
GLSL_TYPE_FLOAT);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "meta_itoi_r32g32b32_cs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL, "meta_itoi_r32g32b32_cs");
b.shader->info.cs.local_size[0] = 16;
b.shader->info.cs.local_size[1] = 16;
b.shader->info.cs.local_size[2] = 1;
@@ -1125,8 +1120,7 @@ build_nir_cleari_compute_shader(struct radv_device *dev, bool is_3d)
const struct glsl_type *img_type = glsl_image_type(dim,
false,
GLSL_TYPE_FLOAT);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, is_3d ? "meta_cleari_cs_3d" : "meta_cleari_cs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL, is_3d ? "meta_cleari_cs_3d" : "meta_cleari_cs");
b.shader->info.cs.local_size[0] = 16;
b.shader->info.cs.local_size[1] = 16;
b.shader->info.cs.local_size[2] = 1;
@@ -1316,8 +1310,7 @@ build_nir_cleari_r32g32b32_compute_shader(struct radv_device *dev)
const struct glsl_type *img_type = glsl_image_type(GLSL_SAMPLER_DIM_BUF,
false,
GLSL_TYPE_FLOAT);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "meta_cleari_r32g32b32_cs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL, "meta_cleari_r32g32b32_cs");
b.shader->info.cs.local_size[0] = 16;
b.shader->info.cs.local_size[1] = 16;
b.shader->info.cs.local_size[2] = 1;

View File

@@ -40,11 +40,8 @@ build_color_shaders(struct nir_shader **out_vs,
struct nir_shader **out_fs,
uint32_t frag_output)
{
nir_builder vs_b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, NULL);
nir_builder fs_b = nir_builder_init_simple_shader(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");
nir_builder vs_b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, NULL, "meta_clear_color_vs");
nir_builder fs_b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL, "meta_clear_color_fs");
const struct glsl_type *position_type = glsl_vec4_type();
const struct glsl_type *color_type = glsl_vec4_type();
@@ -504,15 +501,13 @@ build_depthstencil_shader(struct nir_shader **out_vs,
struct nir_shader **out_fs,
bool unrestricted)
{
nir_builder vs_b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, NULL);
nir_builder fs_b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL);
vs_b.shader->info.name = ralloc_strdup(vs_b.shader,
nir_builder vs_b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, NULL,
unrestricted ? "meta_clear_depthstencil_unrestricted_vs"
: "meta_clear_depthstencil_vs");
fs_b.shader->info.name = ralloc_strdup(fs_b.shader,
nir_builder fs_b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL,
unrestricted ? "meta_clear_depthstencil_unrestricted_fs"
: "meta_clear_depthstencil_fs");
const struct glsl_type *position_out_type = glsl_vec4_type();
nir_variable *vs_out_pos =
@@ -1161,8 +1156,7 @@ radv_fast_clear_depth(struct radv_cmd_buffer *cmd_buffer,
static nir_shader *
build_clear_htile_mask_shader()
{
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "meta_clear_htile_mask");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL, "meta_clear_htile_mask");
b.shader->info.cs.local_size[0] = 64;
b.shader->info.cs.local_size[1] = 1;
b.shader->info.cs.local_size[2] = 1;

View File

@@ -40,8 +40,7 @@ build_dcc_decompress_compute_shader(struct radv_device *dev)
false,
GLSL_TYPE_FLOAT);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "dcc_decompress_compute");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL, "dcc_decompress_compute");
/* We need at least 16/16/1 to cover an entire DCC block in a single workgroup. */
b.shader->info.cs.local_size[0] = 16;

View File

@@ -29,7 +29,6 @@
static nir_shader *
build_fmask_expand_compute_shader(struct radv_device *device, int samples)
{
char name[64];
const struct glsl_type *type =
glsl_sampler_type(GLSL_SAMPLER_DIM_MS, false, false,
GLSL_TYPE_FLOAT);
@@ -37,10 +36,7 @@ build_fmask_expand_compute_shader(struct radv_device *device, int samples)
glsl_image_type(GLSL_SAMPLER_DIM_MS, false,
GLSL_TYPE_FLOAT);
snprintf(name, 64, "meta_fmask_expand_cs-%d", samples);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, name);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL, "meta_fmask_expand_cs-%d", samples);
b.shader->info.cs.local_size[0] = 16;
b.shader->info.cs.local_size[1] = 16;
b.shader->info.cs.local_size[2] = 1;

View File

@@ -37,9 +37,7 @@ build_nir_fs(void)
const struct glsl_type *vec4 = glsl_vec4_type();
nir_variable *f_color; /* vec4, fragment output color */
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL);
b.shader->info.name = ralloc_asprintf(b.shader,
"meta_resolve_fs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL, "meta_resolve_fs");
f_color = nir_variable_create(b.shader, nir_var_shader_out, vec4,
"f_color");

View File

@@ -67,7 +67,6 @@ static nir_ssa_def *radv_meta_build_resolve_srgb_conversion(nir_builder *b,
static nir_shader *
build_resolve_compute_shader(struct radv_device *dev, bool is_integer, bool is_srgb, int samples)
{
char name[64];
const struct glsl_type *sampler_type = glsl_sampler_type(GLSL_SAMPLER_DIM_MS,
false,
false,
@@ -75,9 +74,10 @@ build_resolve_compute_shader(struct radv_device *dev, bool is_integer, bool is_s
const struct glsl_type *img_type = glsl_image_type(GLSL_SAMPLER_DIM_2D,
false,
GLSL_TYPE_FLOAT);
snprintf(name, 64, "meta_resolve_cs-%d-%s", samples, is_integer ? "int" : (is_srgb ? "srgb" : "float"));
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, name);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL,
"meta_resolve_cs-%d-%s",
samples,
is_integer ? "int" : (is_srgb ? "srgb" : "float"));
b.shader->info.cs.local_size[0] = 16;
b.shader->info.cs.local_size[1] = 16;
b.shader->info.cs.local_size[2] = 1;
@@ -165,7 +165,6 @@ build_depth_stencil_resolve_compute_shader(struct radv_device *dev, int samples,
int index,
VkResolveModeFlagBits resolve_mode)
{
char name[64];
const struct glsl_type *sampler_type = glsl_sampler_type(GLSL_SAMPLER_DIM_MS,
false,
false,
@@ -173,12 +172,11 @@ build_depth_stencil_resolve_compute_shader(struct radv_device *dev, int samples,
const struct glsl_type *img_type = glsl_image_type(GLSL_SAMPLER_DIM_2D,
false,
GLSL_TYPE_FLOAT);
snprintf(name, 64, "meta_resolve_cs_%s-%s-%d",
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL,
"meta_resolve_cs_%s-%s-%d",
index == DEPTH_RESOLVE ? "depth" : "stencil",
get_resolve_mode_str(resolve_mode), samples);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, name);
b.shader->info.cs.local_size[0] = 16;
b.shader->info.cs.local_size[1] = 16;
b.shader->info.cs.local_size[2] = 1;

View File

@@ -35,8 +35,7 @@ static nir_shader *
build_nir_vertex_shader(void)
{
const struct glsl_type *vec4 = glsl_vec4_type();
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "meta_resolve_vs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, NULL, "meta_resolve_vs");
nir_variable *pos_out = nir_variable_create(b.shader, nir_var_shader_out,
vec4, "gl_Position");
@@ -51,16 +50,13 @@ build_nir_vertex_shader(void)
static nir_shader *
build_resolve_fragment_shader(struct radv_device *dev, bool is_integer, int samples)
{
char name[64];
const struct glsl_type *vec4 = glsl_vec4_type();
const struct glsl_type *sampler_type = glsl_sampler_type(GLSL_SAMPLER_DIM_MS,
false,
false,
GLSL_TYPE_FLOAT);
snprintf(name, 64, "meta_resolve_fs-%d-%s", samples, is_integer ? "int" : "float");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL);
b.shader->info.name = ralloc_strdup(b.shader, name);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL, "meta_resolve_fs-%d-%s", samples, is_integer ? "int" : "float");
nir_variable *input_img = nir_variable_create(b.shader, nir_var_uniform,
sampler_type, "s_tex");
@@ -356,20 +352,17 @@ build_depth_stencil_resolve_fragment_shader(struct radv_device *dev, int samples
int index,
VkResolveModeFlagBits resolve_mode)
{
char name[64];
const struct glsl_type *vec4 = glsl_vec4_type();
const struct glsl_type *sampler_type = glsl_sampler_type(GLSL_SAMPLER_DIM_2D,
false,
false,
GLSL_TYPE_FLOAT);
snprintf(name, 64, "meta_resolve_fs_%s-%s-%d",
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL,
"meta_resolve_fs_%s-%s-%d",
index == DEPTH_RESOLVE ? "depth" : "stencil",
get_resolve_mode_str(resolve_mode), samples);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL);
b.shader->info.name = ralloc_strdup(b.shader, name);
nir_variable *input_img = nir_variable_create(b.shader, nir_var_uniform,
sampler_type, "s_tex");
input_img->data.descriptor_set = 0;

View File

@@ -3073,8 +3073,7 @@ VkResult radv_create_shaders(struct radv_pipeline *pipeline,
}
if (!modules[MESA_SHADER_FRAGMENT] && !modules[MESA_SHADER_COMPUTE]) {
nir_builder fs_b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL);
fs_b.shader->info.name = ralloc_strdup(fs_b.shader, "noop_fs");
nir_builder fs_b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL, "noop_fs");
fs_m.nir = fs_b.shader;
modules[MESA_SHADER_FRAGMENT] = &fs_m;
}

View File

@@ -153,8 +153,7 @@ build_occlusion_query_shader(struct radv_device *device) {
* }
* }
*/
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "occlusion_query");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL, "occlusion_query");
b.shader->info.cs.local_size[0] = 64;
b.shader->info.cs.local_size[1] = 1;
b.shader->info.cs.local_size[2] = 1;
@@ -320,8 +319,7 @@ build_pipeline_statistics_query_shader(struct radv_device *device) {
* }
* }
*/
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "pipeline_statistics_query");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL, "pipeline_statistics_query");
b.shader->info.cs.local_size[0] = 64;
b.shader->info.cs.local_size[1] = 1;
b.shader->info.cs.local_size[2] = 1;
@@ -514,8 +512,7 @@ build_tfb_query_shader(struct radv_device *device)
* }
* }
*/
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "tfb_query");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL, "tfb_query");
b.shader->info.cs.local_size[0] = 64;
b.shader->info.cs.local_size[1] = 1;
b.shader->info.cs.local_size[2] = 1;
@@ -692,8 +689,7 @@ build_timestamp_query_shader(struct radv_device *device)
* }
* }
*/
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "timestamp_query");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL, "timestamp_query");
b.shader->info.cs.local_size[0] = 64;
b.shader->info.cs.local_size[1] = 1;
b.shader->info.cs.local_size[2] = 1;

View File

@@ -1403,8 +1403,7 @@ radv_create_trap_handler_shader(struct radv_device *device)
struct radv_shader_binary *binary = NULL;
struct radv_shader_info info = {0};
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "meta_trap_handler");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, NULL, "meta_trap_handler");
options.explicit_scratch_args = true;
info.wave_size = 64;

View File

@@ -130,8 +130,8 @@ static nir_shader *
get_clear_rect_vs()
{
const nir_shader_compiler_options *options = v3dv_pipeline_get_nir_options();
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, options);
b.shader->info.name = ralloc_strdup(b.shader, "meta clear vs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, options,
"meta clear vs");
const struct glsl_type *vec4 = glsl_vec4_type();
nir_variable *vs_out_pos =
@@ -148,8 +148,8 @@ static nir_shader *
get_color_clear_rect_fs(uint32_t rt_idx, VkFormat format)
{
const nir_shader_compiler_options *options = v3dv_pipeline_get_nir_options();
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, options);
b.shader->info.name = ralloc_strdup(b.shader, "meta clear fs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, options,
"meta clear fs");
enum pipe_format pformat = vk_format_to_pipe_format(format);
const struct glsl_type *fs_out_type =
@@ -177,8 +177,8 @@ static nir_shader *
get_depth_clear_rect_fs()
{
const nir_shader_compiler_options *options = v3dv_pipeline_get_nir_options();
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, options);
b.shader->info.name = ralloc_strdup(b.shader, "meta depth clear fs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, options,
"meta depth clear fs");
nir_variable *fs_out_depth =
nir_variable_create(b.shader, nir_var_shader_out, glsl_float_type(),

View File

@@ -3493,8 +3493,8 @@ static nir_shader *
get_blit_vs()
{
const nir_shader_compiler_options *options = v3dv_pipeline_get_nir_options();
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, options);
b.shader->info.name = ralloc_strdup(b.shader, "meta blit vs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, options,
"meta blit vs");
const struct glsl_type *vec4 = glsl_vec4_type();
@@ -3538,8 +3538,8 @@ get_color_blit_fs(struct v3dv_device *device,
enum glsl_sampler_dim sampler_dim)
{
const nir_shader_compiler_options *options = v3dv_pipeline_get_nir_options();
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, options);
b.shader->info.name = ralloc_strdup(b.shader, "meta blit fs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, options,
"meta blit fs");
const struct glsl_type *vec4 = glsl_vec4_type();

View File

@@ -1996,8 +1996,8 @@ pipeline_compile_graphics(struct v3dv_pipeline *pipeline,
/* Add a no-op fragment shader if needed */
if (!pipeline->fs) {
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT,
&v3dv_nir_options);
b.shader->info.name = ralloc_strdup(b.shader, "noop_fs");
&v3dv_nir_options,
"noop_fs");
struct v3dv_pipeline_stage *p_stage =
vk_zalloc2(&device->alloc, pAllocator, sizeof(*p_stage), 8,

View File

@@ -53,14 +53,23 @@ nir_builder_init(nir_builder *build, nir_function_impl *impl)
build->shader = impl->function->shader;
}
static inline nir_builder MUST_CHECK
static inline nir_builder MUST_CHECK PRINTFLIKE(3, 4)
nir_builder_init_simple_shader(gl_shader_stage stage,
const nir_shader_compiler_options *options)
const nir_shader_compiler_options *options,
const char *name, ...)
{
nir_builder b;
memset(&b, 0, sizeof(b));
b.shader = nir_shader_create(NULL, stage, options, NULL);
if (name) {
va_list args;
va_start(args, name);
b.shader->info.name = ralloc_vasprintf(b.shader, name, args);
va_end(args);
}
nir_function *func = nir_function_create(b.shader, "main");
func->is_entrypoint = true;
b.exact = false;

View File

@@ -75,7 +75,7 @@ nir_builder_test::nir_builder_test()
glsl_type_singleton_init_or_ref();
static const nir_shader_compiler_options options = { };
_b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, &options);
_b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, &options, "builder test");
b = &_b;
}

View File

@@ -31,7 +31,8 @@ protected:
glsl_type_singleton_init_or_ref();
static const nir_shader_compiler_options options = { };
bld = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, &options);
bld = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, &options,
"comparison test");
v1 = nir_imm_vec4(&bld, -2.0, -1.0, 1.0, 2.0);
v2 = nir_imm_vec4(&bld, 2.0, 1.0, -1.0, -2.0);

View File

@@ -37,7 +37,7 @@ nir_cf_test::nir_cf_test()
glsl_type_singleton_init_or_ref();
static const nir_shader_compiler_options options = { };
b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, &options);
b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, &options, "cf test");
}
nir_cf_test::~nir_cf_test()

View File

@@ -89,7 +89,7 @@ nir_load_store_vectorize_test::nir_load_store_vectorize_test()
glsl_type_singleton_init_or_ref();
static const nir_shader_compiler_options options = { };
_b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, &options);
_b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, &options, "load store tests");
b = &_b;
}

View File

@@ -39,7 +39,7 @@ nir_opt_lower_returns_test::nir_opt_lower_returns_test()
glsl_type_singleton_init_or_ref();
static const nir_shader_compiler_options options = { };
bld = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, &options);
bld = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, &options, "lower returns test");
nir_variable *var = nir_variable_create(bld.shader, nir_var_shader_in, glsl_int_type(), "in");
in_def = nir_load_var(&bld, var);

View File

@@ -57,7 +57,8 @@ protected:
glsl_type_singleton_init_or_ref();
static const nir_shader_compiler_options options = { };
bld = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, &options);
bld = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, &options,
"negative equal tests");
memset(c1, 0, sizeof(c1));
memset(c2, 0, sizeof(c2));
}

View File

@@ -40,7 +40,7 @@ nir_opt_if_test::nir_opt_if_test()
glsl_type_singleton_init_or_ref();
static const nir_shader_compiler_options options = { };
bld = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, &options);
bld = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, &options, "if test");
nir_variable *var = nir_variable_create(bld.shader, nir_var_shader_in, glsl_int_type(), "in");
in_def = nir_load_var(&bld, var);

View File

@@ -48,7 +48,7 @@ nir_serialize_test::nir_serialize_test()
{
glsl_type_singleton_init_or_ref();
_b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, &options);
_b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, &options, "serialize test");
b = &_b;
}

View File

@@ -102,7 +102,8 @@ nir_vars_test::nir_vars_test()
glsl_type_singleton_init_or_ref();
static const nir_shader_compiler_options options = { };
_b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, &options);
_b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, &options,
"vars test");
b = &_b;
lin_ctx = linear_alloc_parent(b->shader, 0);
}

View File

@@ -2059,8 +2059,8 @@ tu_pipeline_builder_compile_shaders(struct tu_pipeline_builder *builder,
const nir_shader_compiler_options *nir_options =
ir3_get_compiler_options(builder->device->compiler);
nir_builder fs_b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT,
nir_options);
fs_b.shader->info.name = ralloc_strdup(fs_b.shader, "noop_fs");
nir_options,
"noop_fs");
nir[MESA_SHADER_FRAGMENT] = fs_b.shader;
}

View File

@@ -2300,7 +2300,7 @@ ttn_compile_init(const void *tgsi_tokens,
}
c->build = nir_builder_init_simple_shader(tgsi_processor_to_shader_stage(scan.processor),
options);
options, "TTN");
s = c->build.shader;

View File

@@ -199,8 +199,8 @@ static void *vc4_get_yuv_vs(struct pipe_context *pctx)
PIPE_SHADER_IR_NIR,
PIPE_SHADER_VERTEX);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, options);
b.shader->info.name = ralloc_strdup(b.shader, "linear_blit_vs");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, options,
"linear_blit_vs");
const struct glsl_type *vec4 = glsl_vec4_type();
nir_variable *pos_in = nir_variable_create(b.shader, nir_var_shader_in,
@@ -246,8 +246,7 @@ static void *vc4_get_yuv_fs(struct pipe_context *pctx, int cpp)
PIPE_SHADER_FRAGMENT);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT,
options);
b.shader->info.name = ralloc_strdup(b.shader, name);
options, "%s", name);
const struct glsl_type *vec4 = glsl_vec4_type();
const struct glsl_type *glsl_int = glsl_int_type();

View File

@@ -789,8 +789,8 @@ lvp_graphics_pipeline_init(struct lvp_pipeline *pipeline,
if (has_fragment_shader == false) {
/* create a dummy fragment shader for this pipeline. */
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL);
b.shader->info.name = ralloc_strdup(b.shader, "dummy_frag");
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, NULL,
"dummy_frag");
pipeline->pipeline_nir[MESA_SHADER_FRAGMENT] = b.shader;
struct pipe_shader_state shstate = {};

View File

@@ -29,10 +29,8 @@ blorp_nir_init_shader(nir_builder *b,
gl_shader_stage stage,
const char *name)
{
*b = nir_builder_init_simple_shader(stage, NULL);
*b = nir_builder_init_simple_shader(stage, NULL, "%s", name ? name : "");
ralloc_adopt(mem_ctx, b->shader);
if (name != NULL)
b->shader->info.name = ralloc_strdup(b->shader, name);
if (stage == MESA_SHADER_FRAGMENT)
b->shader->info.fs.origin_upper_left = true;
}

View File

@@ -1476,7 +1476,7 @@ brw_nir_create_passthrough_tcs(void *mem_ctx, const struct brw_compiler *compile
const struct brw_tcs_prog_key *key)
{
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_TESS_CTRL,
options);
options, "passthrough TCS");
ralloc_adopt(mem_ctx, b.shader);
nir_shader *nir = b.shader;
nir_variable *var;
@@ -1489,7 +1489,6 @@ brw_nir_create_passthrough_tcs(void *mem_ctx, const struct brw_compiler *compile
~(VARYING_BIT_TESS_LEVEL_INNER | VARYING_BIT_TESS_LEVEL_OUTER);
nir->info.outputs_written = key->outputs_written;
nir->info.tess.tcs_vertices_out = key->input_vertices;
nir->info.name = ralloc_strdup(nir, "passthrough");
nir->num_uniforms = 8 * sizeof(uint32_t);
var = nir_variable_create(nir, nir_var_uniform, glsl_vec4_type(), "hdr_0");

View File

@@ -969,7 +969,8 @@ prog_to_nir(const struct gl_program *prog,
return NULL;
c->prog = prog;
c->build = nir_builder_init_simple_shader(stage, options);
c->build = nir_builder_init_simple_shader(stage, options,
"ARB%d", prog->Id);
/* Copy the shader_info from the gl_program */
c->build.shader->info = prog->info;
@@ -997,7 +998,6 @@ prog_to_nir(const struct gl_program *prog,
ptn_add_output_stores(c);
s->info.name = ralloc_asprintf(s, "ARB%d", prog->Id);
s->info.num_textures = util_last_bit(prog->SamplersUsed);
s->info.num_ubos = 0;
s->info.num_abos = 0;

View File

@@ -151,7 +151,10 @@ make_drawpix_z_stencil_program_nir(struct st_context *st,
const nir_shader_compiler_options *options =
st_get_nir_compiler_options(st, MESA_SHADER_FRAGMENT);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, options);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, options,
"drawpixels %s%s",
write_depth ? "Z" : "",
write_stencil ? "S" : "");
nir_variable *texcoord =
nir_variable_create(b.shader, nir_var_shader_in, glsl_vec_type(2),
@@ -190,11 +193,7 @@ make_drawpix_z_stencil_program_nir(struct st_context *st,
nir_store_var(&b, out, stencil, 0x1);
}
char name[14];
snprintf(name, 14, "drawpixels %s%s",
write_depth ? "Z" : "", write_stencil ? "S" : "");
return st_nir_finish_builtin_shader(st, b.shader, name);
return st_nir_finish_builtin_shader(st, b.shader);
}
static void *
@@ -204,7 +203,8 @@ make_drawpix_zs_to_color_program_nir(struct st_context *st,
const nir_shader_compiler_options *options =
st_get_nir_compiler_options(st, MESA_SHADER_FRAGMENT);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, options);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, options,
"copypixels ZStoC");
nir_variable *texcoord =
nir_variable_create(b.shader, nir_var_shader_in, glsl_vec_type(2),
@@ -249,10 +249,7 @@ make_drawpix_zs_to_color_program_nir(struct st_context *st,
nir_store_var(&b, color_out, swizzled_ds, 0xf);
}
char name[17];
snprintf(name, 17, "copypixels ZStoC");
return st_nir_finish_builtin_shader(st, b.shader, name);
return st_nir_finish_builtin_shader(st, b.shader);
}

View File

@@ -62,8 +62,7 @@ void st_nir_lower_uniforms(struct st_context *st, struct nir_shader *nir);
struct pipe_shader_state *
st_nir_finish_builtin_shader(struct st_context *st,
struct nir_shader *nir,
const char *name);
struct nir_shader *nir);
struct pipe_shader_state *
st_nir_make_passthrough_shader(struct st_context *st,

View File

@@ -29,15 +29,13 @@
struct pipe_shader_state *
st_nir_finish_builtin_shader(struct st_context *st,
nir_shader *nir,
const char *name)
nir_shader *nir)
{
struct pipe_context *pipe = st->pipe;
struct pipe_screen *screen = pipe->screen;
gl_shader_stage stage = nir->info.stage;
enum pipe_shader_type sh = pipe_shader_type_from_mesa(stage);
nir->info.name = ralloc_strdup(nir, name);
nir->info.separate_shader = true;
if (stage == MESA_SHADER_FRAGMENT)
nir->info.fs.untyped_color_outputs = true;
@@ -117,7 +115,8 @@ st_nir_make_passthrough_shader(struct st_context *st,
const nir_shader_compiler_options *options =
st_get_nir_compiler_options(st, stage);
nir_builder b = nir_builder_init_simple_shader(stage, options);
nir_builder b = nir_builder_init_simple_shader(stage, options,
"%s", shader_name);
char var_name[15];
@@ -144,5 +143,5 @@ st_nir_make_passthrough_shader(struct st_context *st,
nir_copy_var(&b, out, in);
}
return st_nir_finish_builtin_shader(st, b.shader, shader_name);
return st_nir_finish_builtin_shader(st, b.shader);
}

View File

@@ -296,7 +296,8 @@ st_pbo_create_vs(struct st_context *st)
const nir_shader_compiler_options *options =
st_get_nir_compiler_options(st, MESA_SHADER_VERTEX);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, options);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_VERTEX, options,
"st/pbo VS");
nir_variable *in_pos = nir_variable_create(b.shader, nir_var_shader_in,
vec4, "in_pos");
@@ -332,7 +333,7 @@ st_pbo_create_vs(struct st_context *st)
}
}
return st_nir_finish_builtin_shader(st, b.shader, "st/pbo VS");
return st_nir_finish_builtin_shader(st, b.shader);
}
void *
@@ -410,7 +411,10 @@ create_fs(struct st_context *st, bool download,
bool pos_is_sysval =
screen->get_param(screen, PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, options);
nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, options,
download ?
"st/pbo download FS" :
"st/pbo upload FS");
nir_ssa_def *zero = nir_imm_int(&b, 0);
@@ -539,9 +543,7 @@ create_fs(struct st_context *st, bool download,
nir_store_var(&b, color, result, TGSI_WRITEMASK_XYZW);
}
return st_nir_finish_builtin_shader(st, b.shader, download ?
"st/pbo download FS" :
"st/pbo upload FS");
return st_nir_finish_builtin_shader(st, b.shader);
}
static enum st_pbo_conversion

View File

@@ -52,7 +52,7 @@ panfrost_build_blit_shader(struct panfrost_device *dev,
{
bool is_colour = loc >= FRAG_RESULT_DATA0;
nir_builder _b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, &midgard_nir_options);
nir_builder _b = nir_builder_init_simple_shader(MESA_SHADER_FRAGMENT, &midgard_nir_options, "pan_blit");
nir_builder *b = &_b;
nir_shader *shader = b->shader;