panvk: Restructure VS variant handling

There's no real point in the array of NIRs and the array of infos.  It
just makes everything more of a headache inside the loop.

Reviewed-by: Christoph Pillmayer <christoph.pillmayer@arm.com>
Acked-by: Eric R. Smith <eric.smith@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38821>
This commit is contained in:
Faith Ekstrand 2025-11-06 11:38:55 -05:00 committed by Marge Bot
parent 0191e1f28a
commit 4f0386fbfb

View file

@ -1292,9 +1292,6 @@ panvk_compile_shader(struct panvk_device *dev,
struct panvk_shader *shader;
VkResult result;
/* We consume the NIR, regardless of success or failure */
nir_shader *nir = info->nir;
size_t size =
sizeof(struct panvk_shader) + sizeof(struct panvk_shader_variant) *
panvk_shader_num_variants(info->stage);
@ -1319,24 +1316,20 @@ panvk_compile_shader(struct panvk_device *dev,
switch (info->stage) {
case MESA_SHADER_VERTEX: {
struct pan_compile_inputs input_variants[PANVK_VS_VARIANTS] = {0};
nir_shader *nir_variants[PANVK_VS_VARIANTS] = {0};
/* First we apply lowering for variants */
for (enum panvk_vs_variant v = 0; v < PANVK_VS_VARIANTS; ++v) {
const enum panvk_vs_variant last_variant = PANVK_VS_VARIANT_HW;
for (enum panvk_vs_variant v = 0; v <= last_variant; v++) {
struct panvk_shader_variant *variant = &shader->variants[v];
bool last = (v + 1) == PANVK_VS_VARIANTS;
input_variants[v] = inputs;
/* Each variant gets its own NIR. To save an extra clone, we use the
* original NIR for the last stage.
*/
nir_variants[v] = last ? nir : nir_shader_clone(NULL, nir);
const bool clone_nir = (v != last_variant);
nir_shader *nir =
clone_nir ? nir_shader_clone(NULL, info->nir) : info->nir;
panvk_lower_nir(dev, nir_variants[v], info->set_layout_count,
panvk_lower_nir(dev, nir, info->set_layout_count,
info->set_layouts, info->robustness,
state, &input_variants[v], &variant->desc_info);
state, &inputs, &variant->desc_info);
/* We need the driver_location to match the vertex attribute
* location, so we can use the attribute layout described by
@ -1354,10 +1347,13 @@ panvk_compile_shader(struct panvk_device *dev,
variant->own_bin = true;
result = panvk_compile_nir(dev, nir_variants[v], info->flags,
&input_variants[v], state,
noperspective_varyings,
variant);
result = panvk_compile_nir(dev, nir, info->flags, &inputs, state,
noperspective_varyings, variant);
/* If we cloned, it's our job to clean up */
if (clone_nir)
ralloc_free(nir);
if (result != VK_SUCCESS) {
panvk_shader_destroy(&dev->vk, &shader->vk, pAllocator);
return result;
@ -1370,6 +1366,8 @@ panvk_compile_shader(struct panvk_device *dev,
struct panvk_shader_variant *variant =
(struct panvk_shader_variant *)panvk_shader_only_variant(shader);
nir_shader *nir = info->nir;
if (state && state->ms && state->ms->sample_shading_enable)
nir->info.fs.uses_sample_shading = true;
@ -1413,6 +1411,8 @@ panvk_compile_shader(struct panvk_device *dev,
struct panvk_shader_variant *variant =
(struct panvk_shader_variant *)panvk_shader_only_variant(shader);
nir_shader *nir = info->nir;
panvk_lower_nir(dev, nir, info->set_layout_count, info->set_layouts,
info->robustness, state, &inputs, &variant->desc_info);