From 41bd7aa9c861f3ec5bec3df2a7f45ba8358c32a8 Mon Sep 17 00:00:00 2001 From: Lucas Stach Date: Sun, 12 Jan 2025 21:28:26 +0100 Subject: [PATCH] etnaviv: emit varying interpolation state on halti5 Pull the interpolation qualifiers from NIR and translate them to HALTI5_SHADER_ATTRIBUTES states. Signed-off-by: Lucas Stach Reviewed-by: Christian Gmeiner Part-of: --- src/gallium/drivers/etnaviv/etnaviv_compiler.h | 4 +++- .../drivers/etnaviv/etnaviv_compiler_nir.c | 17 +++++++++++++++++ src/gallium/drivers/etnaviv/etnaviv_emit.c | 3 +++ src/gallium/drivers/etnaviv/etnaviv_internal.h | 2 ++ src/gallium/drivers/etnaviv/etnaviv_shader.c | 9 ++++++++- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler.h b/src/gallium/drivers/etnaviv/etnaviv_compiler.h index 5ea548e5322..13b5199baec 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_compiler.h +++ b/src/gallium/drivers/etnaviv/etnaviv_compiler.h @@ -61,7 +61,8 @@ struct etna_compiler { struct etna_shader_inout { int reg; /* native register */ int slot; /* nir: gl_varying_slot or gl_vert_attrib */ - int num_components; + uint8_t interpolation; + uint8_t num_components; }; struct etna_shader_io_file { @@ -137,6 +138,7 @@ struct etna_varying { uint32_t pa_attributes; uint8_t num_components; uint8_t use[4]; + uint8_t semantic; uint8_t reg; }; diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c index cff4f07ae91..41e839d8cd4 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c +++ b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c @@ -1212,6 +1212,7 @@ etna_compile_shader(struct etna_shader_variant *v) unsigned idx = var->data.driver_location; sf->reg[idx].reg = idx; sf->reg[idx].slot = var->data.location; + sf->reg[idx].interpolation = var->data.interpolation; sf->reg[idx].num_components = glsl_get_components(var->type); sf->num_reg = MAX2(sf->num_reg, idx+1); } @@ -1221,6 +1222,7 @@ etna_compile_shader(struct etna_shader_variant *v) unsigned idx = var->data.driver_location; sf->reg[idx].reg = idx + 1; sf->reg[idx].slot = var->data.location; + sf->reg[idx].interpolation = var->data.interpolation; sf->reg[idx].num_components = glsl_get_components(var->type); sf->num_reg = MAX2(sf->num_reg, idx+1); count++; @@ -1405,6 +1407,21 @@ etna_link_shader(struct etna_shader_link_info *info, varying->use[i] = VARYING_COMPONENT_USE_GENERIC; } + switch (fsio->interpolation) { + case INTERP_MODE_NONE: + case INTERP_MODE_SMOOTH: + varying->semantic = VARYING_INTERPOLATION_MODE_SMOOTH; + break; + case INTERP_MODE_NOPERSPECTIVE: + varying->semantic = VARYING_INTERPOLATION_MODE_NONPERSPECTIVE; + break; + case INTERP_MODE_FLAT: + varying->semantic = VARYING_INTERPOLATION_MODE_FLAT; + break; + default: + unreachable("unsupported varying interpolation mode"); + } + /* point/tex coord is an input to the PS without matching VS output, * so it gets a varying slot without being assigned a VS register. */ diff --git a/src/gallium/drivers/etnaviv/etnaviv_emit.c b/src/gallium/drivers/etnaviv/etnaviv_emit.c index 2104b876799..1f94f5e88f0 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_emit.c +++ b/src/gallium/drivers/etnaviv/etnaviv_emit.c @@ -150,6 +150,9 @@ emit_halti5_only_state(struct etna_context *ctx, int vs_output_count) /*01080*/ EMIT_STATE(PS_VARYING_NUM_COMPONENTS(0), ctx->shader_state.GL_VARYING_NUM_COMPONENTS[0]); /*01084*/ EMIT_STATE(PS_VARYING_NUM_COMPONENTS(1), ctx->shader_state.GL_VARYING_NUM_COMPONENTS[1]); /*03888*/ EMIT_STATE(GL_HALTI5_SH_SPECIALS, ctx->shader_state.GL_HALTI5_SH_SPECIALS); + for (int x = 0; x < ctx->shader_state.halti5_shader_attributes_states; ++x) { + /*038C0*/ EMIT_STATE(GL_HALTI5_SHADER_ATTRIBUTES(x), ctx->shader_state.GL_HALTI5_SHADER_ATTRIBUTES[x]); + } } if (unlikely(dirty & (ETNA_DIRTY_BLEND))) { for (int i = 1; i < ctx->framebuffer.num_rt; i++) { diff --git a/src/gallium/drivers/etnaviv/etnaviv_internal.h b/src/gallium/drivers/etnaviv/etnaviv_internal.h index 08182a4f632..de1e75ddca8 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_internal.h +++ b/src/gallium/drivers/etnaviv/etnaviv_internal.h @@ -253,6 +253,8 @@ struct compiled_shader_state { uint32_t GL_VARYING_TOTAL_COMPONENTS; uint32_t GL_VARYING_NUM_COMPONENTS[2]; uint32_t GL_VARYING_COMPONENT_USE[4]; + uint32_t GL_HALTI5_SHADER_ATTRIBUTES[VIVS_GL_HALTI5_SHADER_ATTRIBUTES__LEN]; + int halti5_shader_attributes_states; uint32_t GL_HALTI5_SH_SPECIALS; uint32_t FE_HALTI5_ID_CONFIG; unsigned vs_inst_mem_size; diff --git a/src/gallium/drivers/etnaviv/etnaviv_shader.c b/src/gallium/drivers/etnaviv/etnaviv_shader.c index 9b1617da92b..3ee019f31b8 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_shader.c +++ b/src/gallium/drivers/etnaviv/etnaviv_shader.c @@ -232,12 +232,16 @@ etna_link_shaders(struct etna_context *ctx, struct compiled_shader_state *cs, uint32_t total_components = 0; DEFINE_ETNA_BITARRAY(num_components, ETNA_NUM_VARYINGS, 4) = {0}; DEFINE_ETNA_BITARRAY(component_use, 4 * ETNA_NUM_VARYINGS, 2) = {0}; + DEFINE_ETNA_BITARRAY(halti5_varying_semantic, 4 * 32, 4) = {0}; for (int idx = 0; idx < link.num_varyings; ++idx) { const struct etna_varying *varying = &link.varyings[idx]; etna_bitarray_set(num_components, 4, idx, varying->num_components); for (int comp = 0; comp < varying->num_components; ++comp) { - etna_bitarray_set(component_use, 2, total_components, varying->use[comp]); + if (ctx->screen->info->halti >= 5) + etna_bitarray_set(halti5_varying_semantic, 4, total_components, varying->semantic); + else + etna_bitarray_set(component_use, 2, total_components, varying->use[comp]); total_components += 1; } } @@ -246,6 +250,9 @@ etna_link_shaders(struct etna_context *ctx, struct compiled_shader_state *cs, VIVS_GL_VARYING_TOTAL_COMPONENTS_NUM(align(total_components, 2)); memcpy(cs->GL_VARYING_NUM_COMPONENTS, num_components, sizeof(uint32_t) * 2); memcpy(cs->GL_VARYING_COMPONENT_USE, component_use, sizeof(uint32_t) * 4); + memcpy(cs->GL_HALTI5_SHADER_ATTRIBUTES, halti5_varying_semantic, + sizeof(uint32_t) * VIVS_GL_HALTI5_SHADER_ATTRIBUTES__LEN); + cs->halti5_shader_attributes_states = DIV_ROUND_UP(total_components, 8); cs->GL_HALTI5_SH_SPECIALS = 0x7f7f0000 | /* unknown bits, probably other PS inputs */