diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 5a1cd90687c..fe15e16c885 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -3068,10 +3068,12 @@ panfrost_val_emit_varying_descriptors(struct panfrost_batch *batch) struct panfrost_compiled_shader *fs = batch->ctx->prog[MESA_SHADER_FRAGMENT]; - const uint32_t vs_out_mask = vs->info.varyings.fixed_varyings; - const uint32_t fs_in_mask = fs->info.varyings.fixed_varyings; - const uint32_t fs_in_slots = fs->info.varyings.input_count + - util_bitcount(fs_in_mask); + const struct pan_varying_layout *vs_layout = &vs->info.varyings.formats; + const struct pan_varying_layout *fs_format = &fs->info.varyings.formats; + pan_varying_layout_require_layout(vs_layout); + pan_varying_layout_require_format(fs_format); + + const uint32_t fs_in_slots = fs_format->count; struct pan_ptr bufs = pan_pool_alloc_desc_array(&batch->pool.base, fs_in_slots, ATTRIBUTE); @@ -3079,31 +3081,37 @@ panfrost_val_emit_varying_descriptors(struct panfrost_batch *batch) batch->nr_varying_attribs[MESA_SHADER_FRAGMENT] = fs_in_slots; - const uint32_t varying_size = panfrost_vertex_attribute_stride(vs, fs); - for (uint32_t i = 0; i < fs_in_slots; i++) { - const struct pan_shader_varying *var = &fs->info.varyings.input[i]; + const struct pan_varying_slot *fs_slot = + pan_varying_layout_slot_at(fs_format, i); - uint32_t index = 0; - if (var->location >= VARYING_SLOT_VAR0) { - unsigned nr_special = util_bitcount(vs_out_mask); - unsigned general_index = (var->location - VARYING_SLOT_VAR0); - index = nr_special + general_index; - } else { - index = util_bitcount(vs_out_mask & BITFIELD_MASK(var->location)); + if (!fs_slot || fs_slot->section != PAN_VARYING_SECTION_GENERIC) + continue; + + unsigned offset = 0; + enum pipe_format format = PIPE_FORMAT_NONE; + + const struct pan_varying_slot *vs_slot = + pan_varying_layout_find_slot(vs_layout, fs_slot->location); + if (vs_slot) { + offset = vs_slot->offset; + /* Trust the bit-size from VS */ + nir_alu_type base_type = nir_alu_type_get_base_type(fs_slot->alu_type); + nir_alu_type bit_size = nir_alu_type_get_type_size(vs_slot->alu_type); + format = pan_varying_format(base_type | bit_size, vs_slot->ncomps); } pan_pack(&descs[i], ATTRIBUTE, cfg) { cfg.attribute_type = MALI_ATTRIBUTE_TYPE_VERTEX_PACKET; cfg.offset_enable = false; - cfg.format = GENX(pan_format_from_pipe_format)(var->format)->hw; + cfg.format = GENX(pan_format_from_pipe_format)(format)->hw; cfg.table = 61; cfg.frequency = MALI_ATTRIBUTE_FREQUENCY_VERTEX; - cfg.offset = 1024 + (index * 16); + cfg.offset = 1024 + offset; /* On v12+, the hardware-controlled buffer is at index 1 for varyings */ cfg.buffer_index = PAN_ARCH >= 12 ? 1 : 0; - cfg.attribute_stride = varying_size; - cfg.packet_stride = varying_size + 16; + cfg.attribute_stride = vs_layout->generic_size_B; + cfg.packet_stride = vs_layout->generic_size_B + 16; } } diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.h b/src/gallium/drivers/panfrost/pan_cmdstream.h index 1a96423d16d..b0bd0ffa455 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.h +++ b/src/gallium/drivers/panfrost/pan_cmdstream.h @@ -257,19 +257,6 @@ panfrost_get_varying_shader(struct panfrost_batch *batch) } #endif -static inline unsigned -panfrost_vertex_attribute_stride(struct panfrost_compiled_shader *vs, - struct panfrost_compiled_shader *fs) -{ - unsigned v = vs->info.varyings.output_count; - unsigned f = fs->info.varyings.input_count; - unsigned slots = MAX2(v, f); - slots += util_bitcount(vs->info.varyings.fixed_varyings); - - /* Assumes 16 byte slots. We could do better. */ - return slots * 16; -} - static inline uint64_t panfrost_emit_resources(struct panfrost_batch *batch, mesa_shader_stage stage) diff --git a/src/gallium/drivers/panfrost/pan_csf.c b/src/gallium/drivers/panfrost/pan_csf.c index 790a9376cff..4f94fff9189 100644 --- a/src/gallium/drivers/panfrost/pan_csf.c +++ b/src/gallium/drivers/panfrost/pan_csf.c @@ -1184,7 +1184,7 @@ csf_emit_draw_state(struct panfrost_batch *batch, } cs_move32_to(b, cs_sr_reg32(b, IDVS, VARY_SIZE), - panfrost_vertex_attribute_stride(vs, fs)); + vs->info.varyings.formats.generic_size_B); cs_move64_to(b, cs_sr_reg64(b, IDVS, BLEND_DESC), batch->blend | MAX2(batch->key.nr_cbufs, 1)); cs_move64_to(b, cs_sr_reg64(b, IDVS, ZSD), batch->depth_stencil);