pan/compiler: Move all NIR passe definitions to pan_nir.h

While we're at it, rename pan_lower_* to pan_nir_lower_* for consistency
with everything else.  The intention is that eventually this will be a
private header and drivers will stop calling these passes themselves.
However, that is a long way off so for now we'll just move them to the
sensibly named place.  Notably, pan_preprocess/optimize/postprocess_nir
stay in pan_compiler.h because those are intended to be external APIs
indefinitely.

Acked-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Acked-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38753>
This commit is contained in:
Faith Ekstrand 2025-12-01 11:35:13 -05:00 committed by Marge Bot
parent b7f45c66fe
commit 2d286ec80a
27 changed files with 123 additions and 107 deletions

View file

@ -10,7 +10,7 @@
#include "compiler/nir/nir_builder.h"
#include "pan_shader.h"
#include "panfrost/compiler/pan_compiler.h"
#include "panfrost/compiler/pan_nir_lower_framebuffer.h"
#include "panfrost/compiler/pan_nir.h"
#include "pan_context.h"
#ifndef PAN_ARCH
@ -119,7 +119,7 @@ GENX(pan_blend_get_shader_locked)(struct pan_blend_shader_cache *cache,
#if PAN_ARCH >= 6
NIR_PASS(_, nir, GENX(pan_inline_rt_conversion), rt_formats);
#else
NIR_PASS(_, nir, pan_lower_framebuffer, rt_formats,
NIR_PASS(_, nir, pan_nir_lower_framebuffer, rt_formats,
pan_raw_format_mask_midgard(rt_formats), MAX2(key.nr_samples, 1),
(cache->gpu_id >> 16) < 0x700);
#endif

View file

@ -39,6 +39,7 @@
#include "pan_shader.h"
#include "pan_texture.h"
#include "compiler/pan_compiler.h"
#include "compiler/pan_nir.h"
#if PAN_ARCH >= 6
/* On Midgard, the native preload infrastructure (via MFBD preloads) is broken

View file

@ -39,6 +39,7 @@
#include "pan_bo.h"
#include "pan_context.h"
#include "pan_compiler.h"
#include "pan_nir.h"
#include "shader_enums.h"
static struct panfrost_uncompiled_shader *
@ -162,7 +163,7 @@ panfrost_shader_compile(struct panfrost_screen *screen, const nir_shader *ir,
if (s->info.has_transform_feedback_varyings) {
NIR_PASS(_, s, nir_opt_constant_folding);
NIR_PASS(_, s, nir_io_add_intrinsic_xfb_info);
NIR_PASS(_, s, pan_lower_xfb);
NIR_PASS(_, s, pan_nir_lower_xfb);
}
}
@ -200,7 +201,7 @@ panfrost_shader_compile(struct panfrost_screen *screen, const nir_shader *ir,
}
if (dev->arch <= 5 && s->info.stage == MESA_SHADER_FRAGMENT) {
NIR_PASS(_, s, pan_lower_framebuffer, key->fs.rt_formats,
NIR_PASS(_, s, pan_nir_lower_framebuffer, key->fs.rt_formats,
pan_raw_format_mask_midgard(key->fs.rt_formats), 0,
panfrost_device_gpu_prod_id(dev) < 0x700);
}
@ -567,7 +568,7 @@ panfrost_create_shader_state(struct pipe_context *pctx,
* to the right attribute.
*/
if (nir->info.stage == MESA_SHADER_VERTEX && dev->arch <= 7) {
NIR_PASS(_, nir, pan_lower_image_index,
NIR_PASS(_, nir, pan_nir_lower_image_index,
util_bitcount64(nir->info.inputs_read));
}

View file

@ -10,6 +10,7 @@
#include "compiler/spirv/nir_spirv.h"
#include "panfrost/compiler/bifrost/bifrost_compile.h"
#include "panfrost/compiler/pan_compiler.h"
#include "panfrost/compiler/pan_nir.h"
#include "nir.h"
#include "nir_builder.h"
#include "nir_builder_opcodes.h"

View file

@ -30,7 +30,9 @@
#include "compiler/glsl_types.h"
#include "compiler/nir/nir_builder.h"
#include "compiler/nir/nir_deref.h"
#include "panfrost/compiler/pan_compiler.h"
#include "panfrost/compiler/pan_ir.h"
#include "panfrost/compiler/pan_nir.h"
#include "util/perf/cpu_trace.h"
#include "util/u_debug.h"
#include "util/u_qsort.h"
@ -6372,8 +6374,8 @@ void bifrost_lower_texture_nir(nir_shader *nir, unsigned gpu_id)
if (nir->info.stage == MESA_SHADER_FRAGMENT) {
NIR_PASS(_, nir, nir_lower_is_helper_invocation);
NIR_PASS(_, nir, pan_lower_helper_invocation);
NIR_PASS(_, nir, pan_lower_sample_pos);
NIR_PASS(_, nir, pan_nir_lower_helper_invocation);
NIR_PASS(_, nir, pan_nir_lower_sample_pos);
}
}

View file

@ -49,6 +49,8 @@
#include "midgard_ops.h"
#include "midgard_quirks.h"
#include "panfrost/compiler/pan_nir.h"
#include "disassemble.h"
#include "shader_enums.h"
@ -459,8 +461,8 @@ void midgard_lower_texture_nir(nir_shader *nir, unsigned gpu_id)
if (nir->info.stage == MESA_SHADER_FRAGMENT) {
NIR_PASS(_, nir, nir_lower_helper_writes, true);
NIR_PASS(_, nir, nir_lower_is_helper_invocation);
NIR_PASS(_, nir, pan_lower_helper_invocation);
NIR_PASS(_, nir, pan_lower_sample_pos);
NIR_PASS(_, nir, pan_nir_lower_helper_invocation);
NIR_PASS(_, nir, pan_nir_lower_sample_pos);
}
}

View file

@ -23,6 +23,7 @@
*/
#include "pan_compiler.h"
#include "pan_nir.h"
#include "bifrost/bifrost_compile.h"
#include "bifrost/bifrost/disassemble.h"

View file

@ -30,6 +30,7 @@
typedef struct nir_shader nir_shader;
struct nir_shader_compiler_options;
struct pan_shader_info;
const struct nir_shader_compiler_options *
pan_get_nir_shader_compiler_options(unsigned arch);
@ -38,9 +39,6 @@ void pan_preprocess_nir(nir_shader *nir, unsigned gpu_id);
void pan_optimize_nir(nir_shader *nir, unsigned gpu_id);
void pan_postprocess_nir(nir_shader *nir, unsigned gpu_id);
void pan_nir_lower_texture_early(nir_shader *nir, unsigned gpu_id);
void pan_nir_lower_texture_late(nir_shader *nir, unsigned gpu_id);
void pan_disassemble(FILE *fp, const void *code, size_t size,
unsigned gpu_id, bool verbose);

View file

@ -356,36 +356,6 @@ uint16_t pan_to_bytemask(unsigned bytes, unsigned mask);
#define PAN_WRITEOUT_S 4
#define PAN_WRITEOUT_2 8
/* Specify the mediump lowering behavior for pan_nir_collect_varyings */
enum pan_mediump_vary {
/* Always assign a 32-bit format to mediump varyings */
PAN_MEDIUMP_VARY_32BIT,
/* Assign a 16-bit format to varyings with smooth interpolation, and a
* 32-bit format to varyings with flat interpolation */
PAN_MEDIUMP_VARY_SMOOTH_16BIT,
};
bool pan_nir_lower_zs_store(nir_shader *nir);
bool pan_nir_lower_store_component(nir_shader *shader);
bool pan_nir_lower_vertex_id(nir_shader *shader);
bool pan_nir_lower_image_ms(nir_shader *shader);
bool pan_nir_lower_frag_coord_zw(nir_shader *shader);
bool pan_nir_lower_noperspective_vs(nir_shader *shader);
bool pan_nir_lower_noperspective_fs(nir_shader *shader);
bool pan_lower_helper_invocation(nir_shader *shader);
bool pan_lower_sample_pos(nir_shader *shader);
bool pan_lower_xfb(nir_shader *nir);
bool pan_lower_image_index(nir_shader *shader, unsigned vs_img_attrib_offset);
uint32_t pan_nir_collect_noperspective_varyings_fs(nir_shader *s);
void pan_nir_collect_varyings(nir_shader *s, struct pan_shader_info *info,
enum pan_mediump_vary mediump);
/*
* Helper returning the subgroup size. Generally, this is equal to the number of
* threads in a warp. For Midgard (including warping models), this returns 1, as

View file

@ -0,0 +1,78 @@
/*
* Copyright (C) 2025 Collabora, Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#ifndef __PAN_NIR_H__
#define __PAN_NIR_H__
#include "nir.h"
#include "pan_compiler.h"
#include "pan_ir.h"
struct util_format_description;
bool pan_nir_lower_zs_store(nir_shader *nir);
bool pan_nir_lower_store_component(nir_shader *shader);
bool pan_nir_lower_vertex_id(nir_shader *shader);
bool pan_nir_lower_image_ms(nir_shader *shader);
bool pan_nir_lower_frag_coord_zw(nir_shader *shader);
bool pan_nir_lower_noperspective_vs(nir_shader *shader);
bool pan_nir_lower_noperspective_fs(nir_shader *shader);
bool pan_nir_lower_helper_invocation(nir_shader *shader);
bool pan_nir_lower_sample_pos(nir_shader *shader);
bool pan_nir_lower_xfb(nir_shader *nir);
bool pan_nir_lower_image_index(nir_shader *shader,
unsigned vs_img_attrib_offset);
void pan_nir_lower_texture_early(nir_shader *nir, unsigned gpu_id);
void pan_nir_lower_texture_late(nir_shader *nir, unsigned gpu_id);
nir_alu_type
pan_unpacked_type_for_format(const struct util_format_description *desc);
bool pan_nir_lower_framebuffer(nir_shader *shader,
const enum pipe_format *rt_fmts,
uint8_t raw_fmt_mask,
unsigned blend_shader_nr_samples,
bool broken_ld_special);
uint32_t pan_nir_collect_noperspective_varyings_fs(nir_shader *s);
/* Specify the mediump lowering behavior for pan_nir_collect_varyings */
enum pan_mediump_vary {
/* Always assign a 32-bit format to mediump varyings */
PAN_MEDIUMP_VARY_32BIT,
/* Assign a 16-bit format to varyings with smooth interpolation, and a
* 32-bit format to varyings with flat interpolation */
PAN_MEDIUMP_VARY_SMOOTH_16BIT,
};
void pan_nir_collect_varyings(nir_shader *s, struct pan_shader_info *info,
enum pan_mediump_vary mediump);
#endif /* __PAN_NIR_H__ */

View file

@ -24,7 +24,7 @@
#include "compiler/nir/nir.h"
#include "compiler/nir/nir_builder.h"
#include "pan_ir.h"
#include "pan_nir.h"
static enum pipe_format
varying_format(nir_alu_type t, unsigned ncomps)

View file

@ -4,7 +4,7 @@
*/
#include "compiler/nir/nir_builder.h"
#include "pan_ir.h"
#include "pan_nir.h"
/* Lowers nir_load_frag_coord_zw to nir_load_frag_coord_zw_pan. */

View file

@ -47,7 +47,7 @@
* smallest precision necessary to store the pixel losslessly.
*/
#include "pan_nir_lower_framebuffer.h"
#include "pan_nir.h"
#include "compiler/nir/nir.h"
#include "compiler/nir/nir_builder.h"
#include "compiler/nir/nir_format_convert.h"
@ -618,9 +618,11 @@ lower(nir_builder *b, nir_instr *instr, void *data)
}
bool
pan_lower_framebuffer(nir_shader *shader, const enum pipe_format *rt_fmts,
uint8_t raw_fmt_mask, unsigned blend_shader_nr_samples,
bool broken_ld_special)
pan_nir_lower_framebuffer(nir_shader *shader,
const enum pipe_format *rt_fmts,
uint8_t raw_fmt_mask,
unsigned blend_shader_nr_samples,
bool broken_ld_special)
{
assert(shader->info.stage == MESA_SHADER_FRAGMENT);

View file

@ -1,41 +0,0 @@
/*
* Copyright (C) 2020 Collabora, Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Authors (Collabora):
* Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
*/
#ifndef __PAN_LOWER_FRAMEBUFFER_H
#define __PAN_LOWER_FRAMEBUFFER_H
#include "compiler/nir/nir.h"
#include "util/format/u_format.h"
nir_alu_type
pan_unpacked_type_for_format(const struct util_format_description *desc);
bool pan_lower_framebuffer(nir_shader *shader, const enum pipe_format *rt_fmts,
uint8_t raw_fmt_mask,
unsigned blend_shader_nr_samples,
bool broken_ld_special);
#endif

View file

@ -22,7 +22,7 @@
*/
#include "compiler/nir/nir_builder.h"
#include "pan_ir.h"
#include "pan_nir.h"
/* Lower gl_HelperInvocation to (gl_SampleMaskIn == 0), this depends on
* architectural details but is more efficient than NIR's lowering.
@ -42,7 +42,7 @@ pan_lower_helper_invocation_instr(nir_builder *b, nir_intrinsic_instr *intr,
}
bool
pan_lower_helper_invocation(nir_shader *shader)
pan_nir_lower_helper_invocation(nir_shader *shader)
{
return nir_shader_intrinsics_pass(shader, pan_lower_helper_invocation_instr,
nir_metadata_control_flow, NULL);

View file

@ -4,7 +4,7 @@
*/
#include "compiler/nir/nir_builder.h"
#include "pan_ir.h"
#include "pan_nir.h"
/* Vertex shader gets passed image attribute descriptors through the
* vertex attribute descriptor array. This forces us to apply an offset
@ -44,7 +44,7 @@ lower_image_intr(struct nir_builder *b, nir_intrinsic_instr *intr, void *data)
}
bool
pan_lower_image_index(nir_shader *shader, unsigned vs_img_attrib_offset)
pan_nir_lower_image_index(nir_shader *shader, unsigned vs_img_attrib_offset)
{
if (shader->info.stage != MESA_SHADER_VERTEX)
return false;

View file

@ -26,7 +26,7 @@
#include "compiler/nir/nir.h"
#include "compiler/nir/nir_builder.h"
#include "pan_ir.h"
#include "pan_nir.h"
static bool
nir_lower_image_ms(nir_builder *b, nir_intrinsic_instr *intr,

View file

@ -4,7 +4,7 @@
*/
#include "compiler/nir/nir_builder.h"
#include "pan_ir.h"
#include "pan_nir.h"
/* Mali only provides instructions to fetch varyings with either flat or
* perspective-correct interpolation. This pass lowers noperspective varyings

View file

@ -22,7 +22,7 @@
*/
#include "compiler/nir/nir_builder.h"
#include "pan_ir.h"
#include "pan_nir.h"
/* Sample positions are supplied in a packed 8:8 fixed-point vec2 format in GPU
* memory indexed by the sample. We lower in NIR to take advantage of possible
@ -85,7 +85,7 @@ pan_lower_sample_pos_impl(struct nir_builder *b, nir_intrinsic_instr *intr,
}
bool
pan_lower_sample_pos(nir_shader *shader)
pan_nir_lower_sample_pos(nir_shader *shader)
{
if (shader->info.stage != MESA_SHADER_FRAGMENT)
return false;

View file

@ -25,7 +25,7 @@
*/
#include "compiler/nir/nir_builder.h"
#include "pan_ir.h"
#include "pan_nir.h"
/*
* If the shader packs multiple varyings into the same location with different

View file

@ -4,7 +4,7 @@
*/
#include "compiler/nir/nir_builder.h"
#include "pan_ir.h"
#include "pan_nir.h"
/*
* load_vertex_id_zero_base() is supposed to return the zero-based

View file

@ -23,7 +23,7 @@
*/
#include "compiler/nir/nir_builder.h"
#include "pan_ir.h"
#include "pan_nir.h"
/* Midgard can write all of color, depth and stencil in a single writeout
* operation, so we merge depth/stencil stores with color stores.

View file

@ -22,7 +22,7 @@
*/
#include "compiler/nir/nir_builder.h"
#include "pan_ir.h"
#include "pan_nir.h"
static void
lower_xfb_output(nir_builder *b, nir_intrinsic_instr *intr,
@ -98,7 +98,7 @@ lower_xfb(nir_builder *b, nir_intrinsic_instr *intr, UNUSED void *data)
}
bool
pan_lower_xfb(nir_shader *nir)
pan_nir_lower_xfb(nir_shader *nir)
{
return nir_shader_intrinsics_pass(
nir, lower_xfb, nir_metadata_control_flow, NULL);

View file

@ -34,7 +34,7 @@
#include "compiler/nir/nir_conversion_builder.h"
#include "compiler/nir/nir_lower_blend.h"
#include "compiler/pan_compiler.h"
#include "compiler/pan_nir_lower_framebuffer.h"
#include "compiler/pan_nir.h"
#include "util/format/u_format.h"
#ifndef PAN_ARCH

View file

@ -29,7 +29,6 @@
#include "genxml/gen_macros.h"
#include "panfrost/lib/pan_props.h"
#include "panfrost/compiler/pan_ir.h"
#include "panfrost/compiler/pan_nir_lower_framebuffer.h"
static unsigned
pan_get_fixed_varying_mask(unsigned varyings_used)

View file

@ -12,6 +12,7 @@
#include "nir_builder.h"
#include "pan_shader.h"
#include "pan_nir.h"
struct panvk_fb_preload_shader_key {
enum panvk_meta_object_key_type type;

View file

@ -56,6 +56,7 @@
#include "compiler/bifrost/bifrost_nir.h"
#include "compiler/pan_compiler.h"
#include "compiler/pan_nir.h"
#include "pan_shader.h"
#include "vk_log.h"
@ -789,7 +790,7 @@ panvk_lower_nir(struct panvk_device *dev, nir_shader *nir,
assert(nir_can_lower_multiview(nir, options));
NIR_PASS(_, nir, nir_lower_multiview, options);
/* Pull output writes out of the loop and give them constant offsets for
* pan_lower_store_components */
* pan_nir_lower_store_components */
NIR_PASS(_, nir, nir_lower_io_vars_to_temporaries,
nir_shader_get_entrypoint(nir), nir_var_shader_out);
}
@ -929,10 +930,10 @@ panvk_lower_nir(struct panvk_device *dev, nir_shader *nir,
nir_metadata_control_flow, NULL);
/* since valhall, panvk_per_arch(nir_lower_descriptors) separates the
* driver set and the user sets, and does not need pan_lower_image_index
* driver set and the user sets, and does not need pan_nir_lower_image_index
*/
if (PAN_ARCH < 9 && stage == MESA_SHADER_VERTEX)
NIR_PASS(_, nir, pan_lower_image_index, MAX_VS_ATTRIBS);
NIR_PASS(_, nir, pan_nir_lower_image_index, MAX_VS_ATTRIBS);
if (noperspective_varyings && stage == MESA_SHADER_VERTEX) {
NIR_PASS(_, nir, nir_inline_sysval,