panvk: Emit VS-accessible image attributes at a fixed offset

We need to do that if we want to be able to use vk_vertex_input_state
as our reference attribute layout without having to adjust things based
on the attribute actually accessed by the vertex shader.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com>
Acked-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28927>
This commit is contained in:
Boris Brezillon 2024-04-23 17:15:51 +02:00 committed by Marge Bot
parent 497c43f161
commit 3683aaeb02
3 changed files with 21 additions and 14 deletions

View file

@ -20,6 +20,8 @@
#include "panvk_macros.h"
#include "panvk_pipeline_layout.h"
#define MAX_VS_ATTRIBS 16
struct nir_shader;
struct pan_blend_state;
struct panvk_device;

View file

@ -924,18 +924,13 @@ panvk_draw_prepare_vs_attribs(struct panvk_cmd_buffer *cmdbuf,
pipeline->base.img_access_mask & BITFIELD_BIT(MESA_SHADER_VERTEX)
? pipeline->base.layout->num_imgs
: 0;
unsigned attrib_count = pipeline->state.vs.attribs.attrib_count + num_imgs;
unsigned num_vs_attribs = pipeline->state.vs.attribs.attrib_count;
unsigned attrib_count =
num_imgs ? MAX_VS_ATTRIBS + num_imgs : num_vs_attribs;
if (cmdbuf->state.gfx.vs.attribs || !attrib_count)
return;
if (!pipeline->state.vs.attribs.buf_count) {
panvk_prepare_img_attribs(cmdbuf, desc_state, &pipeline->base);
cmdbuf->state.gfx.vs.attrib_bufs = desc_state->img.attrib_bufs;
cmdbuf->state.gfx.vs.attribs = desc_state->img.attribs;
return;
}
unsigned attrib_buf_count = pipeline->state.vs.attribs.buf_count * 2;
struct panfrost_ptr bufs = pan_pool_alloc_desc_array(
&cmdbuf->desc_pool.base, attrib_buf_count + 1, ATTRIBUTE_BUFFER);
@ -950,7 +945,7 @@ panvk_draw_prepare_vs_attribs(struct panvk_cmd_buffer *cmdbuf,
&attrib_buf_descs[i * 2]);
}
for (unsigned i = 0; i < pipeline->state.vs.attribs.attrib_count; i++) {
for (unsigned i = 0; i < num_vs_attribs; i++) {
unsigned buf_idx = pipeline->state.vs.attribs.attrib[i].buf;
panvk_draw_emit_attrib(draw, &pipeline->state.vs.attribs.attrib[i],
@ -960,11 +955,17 @@ panvk_draw_prepare_vs_attribs(struct panvk_cmd_buffer *cmdbuf,
}
if (num_imgs) {
/* Image load/store are passed a fixed offset, so we can make vertex input
* dynamic. Images are always placed after all potential vertex
* attributes. Buffers are tightly packed since they don't interfere with
* the vertex shader.
*/
unsigned bufs_offset =
pipeline->state.vs.attribs.buf_count * pan_size(ATTRIBUTE_BUFFER) * 2;
unsigned attribs_offset =
pipeline->state.vs.attribs.buf_count * pan_size(ATTRIBUTE);
unsigned attribs_offset = MAX_VS_ATTRIBS * pan_size(ATTRIBUTE);
memset(attribs.cpu + num_vs_attribs * pan_size(ATTRIBUTE), 0,
(MAX_VS_ATTRIBS - num_vs_attribs) * pan_size(ATTRIBUTE));
panvk_fill_img_attribs(cmdbuf, desc_state, &pipeline->base,
bufs.cpu + bufs_offset,
attribs.cpu + attribs_offset,

View file

@ -361,8 +361,7 @@ panvk_per_arch(shader_create)(struct panvk_device *dev, gl_shader_stage stage,
}
if (stage == MESA_SHADER_VERTEX)
NIR_PASS_V(nir, pan_lower_image_index,
util_bitcount64(nir->info.inputs_read));
NIR_PASS_V(nir, pan_lower_image_index, MAX_VS_ATTRIBS);
struct sysval_options sysval_options = {
.static_blend_constants =
@ -389,8 +388,13 @@ panvk_per_arch(shader_create)(struct panvk_device *dev, gl_shader_stage stage,
panvk_per_arch(pipeline_layout_total_ubo_count)(layout);
shader->info.sampler_count = layout->num_samplers;
shader->info.texture_count = layout->num_textures;
/* Image attributes start at MAX_VS_ATTRIBS in the VS attribute table,
* and zero in other stages.
*/
if (shader->has_img_access)
shader->info.attribute_count += layout->num_imgs;
shader->info.attribute_count =
layout->num_imgs + (stage == MESA_SHADER_VERTEX ? MAX_VS_ATTRIBS : 0);
shader->local_size.x = nir->info.workgroup_size[0];
shader->local_size.y = nir->info.workgroup_size[1];