compiler->scalar_stage[stage]);
}
+ /* TODO: Verify if its feasible to split up the NIR linking work into a
+ * per-stage part (that fill out information we need for the passes) and a
+ * actual linking part, so that we could fold back brw_nir_lower_resources
+ * back into brw_create_nir.
+ */
+
/* SPIR-V programs use a NIR linker */
if (shProg->data->spirv) {
if (!gl_nir_link_uniforms(ctx, shProg))
struct gl_program *prog = shader->Program;
+ brw_nir_lower_resources(prog->nir, shProg, prog, &brw->screen->devinfo);
+
NIR_PASS_V(prog->nir, brw_nir_lower_gl_images, prog);
}
brw_preprocess_nir(brw->screen->compiler, nir, softfp64);
- NIR_PASS_V(nir, gl_nir_lower_samplers, shader_prog);
- prog->info.textures_used = nir->info.textures_used;
- prog->info.textures_used_by_txf = nir->info.textures_used_by_txf;
-
- NIR_PASS_V(nir, brw_nir_lower_image_load_store, devinfo);
-
- NIR_PASS_V(nir, gl_nir_lower_buffers, shader_prog);
- /* Do a round of constant folding to clean up address calculations */
- NIR_PASS_V(nir, nir_opt_constant_folding);
-
if (stage == MESA_SHADER_TESS_CTRL) {
/* Lower gl_PatchVerticesIn from a sys. value to a uniform on Gen8+. */
static const gl_state_index16 tokens[STATE_LENGTH] =
}
void
+brw_nir_lower_resources(nir_shader *nir, struct gl_shader_program *shader_prog,
+ struct gl_program *prog,
+ const struct gen_device_info *devinfo)
+{
+ NIR_PASS_V(prog->nir, gl_nir_lower_samplers, shader_prog);
+ prog->info.textures_used = prog->nir->info.textures_used;
+ prog->info.textures_used_by_txf = prog->nir->info.textures_used_by_txf;
+
+ NIR_PASS_V(prog->nir, brw_nir_lower_image_load_store, devinfo);
+
+ NIR_PASS_V(prog->nir, gl_nir_lower_buffers, shader_prog);
+ /* Do a round of constant folding to clean up address calculations */
+ NIR_PASS_V(prog->nir, nir_opt_constant_folding);
+}
+
+void
brw_shader_gather_info(nir_shader *nir, struct gl_program *prog)
{
nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
prog->nir = brw_create_nir(brw, NULL, prog, MESA_SHADER_FRAGMENT, true);
+ brw_nir_lower_resources(prog->nir, NULL, prog, &brw->screen->devinfo);
+
brw_shader_gather_info(prog->nir, prog);
brw_fs_precompile(ctx, prog);
prog->nir = brw_create_nir(brw, NULL, prog, MESA_SHADER_VERTEX,
compiler->scalar_stage[MESA_SHADER_VERTEX]);
+ brw_nir_lower_resources(prog->nir, NULL, prog, &brw->screen->devinfo);
+
brw_shader_gather_info(prog->nir, prog);
brw_vs_precompile(ctx, prog);