mesa/arbprog: Move the GLSLFragCoordIsSysVal handling to prog_to_nir.
We don't need to go grubbing around in the ARB program when we can use the right variable type at prog_to_nir time. This does leave fp->system_values_read/inputs_read as they were, but I don't see anywhere that that matters (the NIR will have its info gathered appropriately, and other lowering may also cause mismatch between the gl_program and the NIR). Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17528>
This commit is contained in:
parent
c002bbeb2f
commit
153f7b8852
|
@ -27,6 +27,7 @@
|
|||
#include "compiler/nir/nir_builder.h"
|
||||
#include "compiler/glsl/list.h"
|
||||
|
||||
#include "main/mtypes.h"
|
||||
#include "main/shader_types.h"
|
||||
#include "util/ralloc.h"
|
||||
|
||||
|
@ -45,6 +46,7 @@
|
|||
*/
|
||||
|
||||
struct ptn_compile {
|
||||
const struct gl_context *ctx;
|
||||
const struct gl_program *prog;
|
||||
nir_builder build;
|
||||
bool error;
|
||||
|
@ -866,6 +868,16 @@ setup_registers_and_variables(struct ptn_compile *c)
|
|||
while (inputs_read) {
|
||||
const int i = u_bit_scan64(&inputs_read);
|
||||
|
||||
if (c->ctx->Const.GLSLFragCoordIsSysVal &&
|
||||
shader->info.stage == MESA_SHADER_FRAGMENT &&
|
||||
i == VARYING_SLOT_POS) {
|
||||
nir_variable *var = nir_variable_create(shader, nir_var_system_value, glsl_vec4_type(),
|
||||
"frag_coord");
|
||||
var->data.location = SYSTEM_VALUE_FRAG_COORD;
|
||||
c->input_vars[i] = var;
|
||||
continue;
|
||||
}
|
||||
|
||||
nir_variable *var =
|
||||
nir_variable_create(shader, nir_var_shader_in, glsl_vec4_type(),
|
||||
ralloc_asprintf(shader, "in_%d", i));
|
||||
|
@ -974,7 +986,7 @@ setup_registers_and_variables(struct ptn_compile *c)
|
|||
}
|
||||
|
||||
struct nir_shader *
|
||||
prog_to_nir(const struct gl_program *prog,
|
||||
prog_to_nir(const struct gl_context *ctx, const struct gl_program *prog,
|
||||
const nir_shader_compiler_options *options)
|
||||
{
|
||||
struct ptn_compile *c;
|
||||
|
@ -985,6 +997,7 @@ prog_to_nir(const struct gl_program *prog,
|
|||
if (!c)
|
||||
return NULL;
|
||||
c->prog = prog;
|
||||
c->ctx = ctx;
|
||||
|
||||
c->build = nir_builder_init_simple_shader(stage, options, NULL);
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct nir_shader *prog_to_nir(const struct gl_program *prog,
|
||||
struct nir_shader *prog_to_nir(const struct gl_context *ctx, const struct gl_program *prog,
|
||||
const nir_shader_compiler_options *options);
|
||||
|
||||
enum glsl_sampler_dim _mesa_texture_index_to_sampler_dim(gl_texture_index index,
|
||||
|
|
|
@ -506,30 +506,3 @@ _mesa_remove_output_reads(struct gl_program *prog, gl_register_file type)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_mesa_program_fragment_position_to_sysval(struct gl_program *prog)
|
||||
{
|
||||
GLuint i;
|
||||
|
||||
if (prog->Target != GL_FRAGMENT_PROGRAM_ARB ||
|
||||
!(prog->info.inputs_read & BITFIELD64_BIT(VARYING_SLOT_POS)))
|
||||
return;
|
||||
|
||||
prog->info.inputs_read &= ~BITFIELD64_BIT(VARYING_SLOT_POS);
|
||||
BITSET_SET(prog->info.system_values_read, SYSTEM_VALUE_FRAG_COORD);
|
||||
|
||||
for (i = 0; i < prog->arb.NumInstructions; i++) {
|
||||
struct prog_instruction *inst = prog->arb.Instructions + i;
|
||||
const GLuint numSrc = _mesa_num_inst_src_regs(inst->Opcode);
|
||||
GLuint j;
|
||||
|
||||
for (j = 0; j < numSrc; j++) {
|
||||
if (inst->SrcReg[j].File == PROGRAM_INPUT &&
|
||||
inst->SrcReg[j].Index == VARYING_SLOT_POS) {
|
||||
inst->SrcReg[j].File = PROGRAM_SYSTEM_VALUE;
|
||||
inst->SrcReg[j].Index = SYSTEM_VALUE_FRAG_COORD;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,9 +47,6 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_program *fprog,
|
|||
extern void
|
||||
_mesa_remove_output_reads(struct gl_program *prog, gl_register_file type);
|
||||
|
||||
extern void
|
||||
_mesa_program_fragment_position_to_sysval(struct gl_program *prog);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -407,7 +407,7 @@ st_translate_prog_to_nir(struct st_context *st, struct gl_program *prog,
|
|||
st_get_nir_compiler_options(st, prog->info.stage);
|
||||
|
||||
/* Translate to NIR */
|
||||
nir_shader *nir = prog_to_nir(prog, options);
|
||||
nir_shader *nir = prog_to_nir(st->ctx, prog, options);
|
||||
|
||||
st_prog_to_nir_postprocess(st, nir, prog);
|
||||
|
||||
|
@ -824,8 +824,6 @@ st_translate_fragment_program(struct st_context *st,
|
|||
{
|
||||
/* Non-GLSL programs: */
|
||||
_mesa_remove_output_reads(fp, PROGRAM_OUTPUT);
|
||||
if (st->ctx->Const.GLSLFragCoordIsSysVal)
|
||||
_mesa_program_fragment_position_to_sysval(fp);
|
||||
|
||||
/* This determines which states will be updated when the assembly
|
||||
* shader is bound.
|
||||
|
|
Loading…
Reference in New Issue