agx: move texture lowering into lib

This is a bit annoying, but it gets rid of the libagx dep which is preventing
precompiling helper programs.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27616>
This commit is contained in:
Alyssa Rosenzweig 2024-02-09 11:53:28 -04:00 committed by Marge Bot
parent 0fa6901f32
commit 4a3b905bb8
12 changed files with 64 additions and 74 deletions

View file

@ -3083,13 +3083,10 @@ agx_compile_shader_nir(nir_shader *nir, struct agx_shader_key *key,
(nir->info.outputs_written & VARYING_BIT_CLIP_DIST0))
NIR_PASS(_, nir, agx_nir_lower_clip_distance);
bool needs_libagx = nir->info.stage == MESA_SHADER_GEOMETRY;
/* Late tilebuffer lowering creates multisampled image stores */
NIR_PASS(needs_libagx, nir, agx_nir_lower_multisampled_image_store);
bool needs_libagx = true /* TODO: Optimize */;
if (nir->info.stage == MESA_SHADER_FRAGMENT)
NIR_PASS(needs_libagx, nir, agx_nir_lower_interpolation);
NIR_PASS(_, nir, agx_nir_lower_interpolation);
NIR_PASS(_, nir, nir_lower_vars_to_ssa);

View file

@ -238,12 +238,6 @@ struct agx_shader_key {
};
};
/* Texture backend flags */
#define AGX_TEXTURE_FLAG_NO_CLAMP (1 << 0)
bool agx_nir_lower_texture_early(nir_shader *s, bool support_lod_bias);
bool agx_nir_lower_texture(nir_shader *s);
void agx_preprocess_nir(nir_shader *nir, const nir_shader *libagx,
bool allow_mediump,
struct agx_uncompiled_shader_info *out);
@ -254,8 +248,6 @@ bool agx_nir_lower_sample_mask(nir_shader *s);
bool agx_nir_lower_cull_distance_fs(struct nir_shader *s,
unsigned nr_distances);
bool agx_nir_needs_texture_crawl(nir_instr *instr);
void agx_compile_shader_nir(nir_shader *nir, struct agx_shader_key *key,
struct util_debug_callback *debug,
struct util_dynarray *binary,

View file

@ -13,7 +13,6 @@ bool agx_nir_lower_interpolation(struct nir_shader *s);
bool agx_nir_lower_algebraic_late(struct nir_shader *shader);
bool agx_nir_fuse_algebraic_late(struct nir_shader *shader);
bool agx_nir_fence_images(struct nir_shader *shader);
bool agx_nir_lower_multisampled_image_store(struct nir_shader *s);
bool agx_nir_lower_layer(struct nir_shader *s);
bool agx_nir_lower_clip_distance(struct nir_shader *s);
bool agx_nir_lower_cull_distance_vs(struct nir_shader *s);

View file

@ -1,46 +0,0 @@
/*
* Copyright 2023 Valve Corporation
* SPDX-License-Identifier: MIT
*/
#include "compiler/nir/nir_builder.h"
#include "agx_nir.h"
#include "nir.h"
#include "nir_builder_opcodes.h"
#include "nir_intrinsics.h"
static bool
pass(struct nir_builder *b, nir_intrinsic_instr *intr, void *data)
{
b->cursor = nir_after_instr(&intr->instr);
/* If the image is write-only, there is no fencing needed */
if (nir_intrinsic_has_access(intr) &&
(nir_intrinsic_access(intr) & ACCESS_NON_READABLE)) {
return false;
}
switch (intr->intrinsic) {
case nir_intrinsic_image_store:
case nir_intrinsic_bindless_image_store:
nir_fence_pbe_to_tex_agx(b);
return true;
case nir_intrinsic_image_atomic:
case nir_intrinsic_bindless_image_atomic:
case nir_intrinsic_image_atomic_swap:
case nir_intrinsic_bindless_image_atomic_swap:
nir_fence_mem_to_tex_agx(b);
return true;
default:
return false;
}
}
bool
agx_nir_fence_images(nir_shader *s)
{
return nir_shader_intrinsics_pass(
s, pass, nir_metadata_block_index | nir_metadata_dominance, NULL);
}

View file

@ -7,14 +7,12 @@ libasahi_agx_files = files(
'agx_dce.c',
'agx_liveness.c',
'agx_insert_waits.c',
'agx_nir_fence_images.c',
'agx_nir_lower_address.c',
'agx_nir_lower_clip_distance.c',
'agx_nir_lower_cull_distance.c',
'agx_nir_lower_frag_sidefx.c',
'agx_nir_lower_sample_mask.c',
'agx_nir_lower_discard_zs_emit.c',
'agx_nir_lower_texture.c',
'agx_nir_lower_interpolation.c',
'agx_nir_lower_layer.c',
'agx_nir_lower_load_mask.c',

View file

@ -4,8 +4,8 @@
*/
#include "agx_meta.h"
#include "agx_compile.h"
#include "agx_device.h" /* for AGX_MEMORY_TYPE_SHADER */
#include "agx_nir_passes.h"
#include "agx_tilebuffer.h"
#include "nir.h"
#include "nir_builder.h"
@ -33,12 +33,14 @@ agx_compile_meta_shader(struct agx_meta_cache *cache, nir_shader *shader,
struct util_dynarray binary;
util_dynarray_init(&binary, NULL);
agx_nir_lower_texture(shader);
agx_preprocess_nir(shader, cache->dev->libagx, false, NULL);
if (tib) {
unsigned bindless_base = 0;
agx_nir_lower_tilebuffer(shader, tib, NULL, &bindless_base, NULL, true);
agx_nir_lower_monolithic_msaa(
shader, &(struct agx_msaa_state){.nr_samples = tib->nr_samples});
agx_nir_lower_multisampled_image_store(shader);
nir_shader_intrinsics_pass(
shader, lower_tex_handle_to_u0,

View file

@ -1,4 +1,5 @@
/*
* Copyright 2023 Valve Corporation
* Copyright 2021 Alyssa Rosenzweig
* Copyright 2020 Collabora Ltd.
* Copyright 2016 Broadcom
@ -7,16 +8,39 @@
#include "compiler/nir/nir.h"
#include "compiler/nir/nir_builder.h"
#include "compiler/nir/nir_builtin_builder.h"
#include "agx_compile.h"
#include "agx_compiler.h"
#include "agx_internal_formats.h"
#include "agx_nir.h"
#include "glsl_types.h"
#include "agx_nir_passes.h"
#include "libagx_shaders.h"
#include "nir_builder_opcodes.h"
#include "nir_intrinsics.h"
#include "nir_intrinsics_indices.h"
#include "nir_builtin_builder.h"
static bool
fence_image(struct nir_builder *b, nir_intrinsic_instr *intr, void *data)
{
b->cursor = nir_after_instr(&intr->instr);
/* If the image is write-only, there is no fencing needed */
if (nir_intrinsic_has_access(intr) &&
(nir_intrinsic_access(intr) & ACCESS_NON_READABLE)) {
return false;
}
switch (intr->intrinsic) {
case nir_intrinsic_image_store:
case nir_intrinsic_bindless_image_store:
nir_fence_pbe_to_tex_agx(b);
return true;
case nir_intrinsic_image_atomic:
case nir_intrinsic_bindless_image_atomic:
case nir_intrinsic_image_atomic_swap:
case nir_intrinsic_bindless_image_atomic_swap:
nir_fence_mem_to_tex_agx(b);
return true;
default:
return false;
}
}
static nir_def *
texture_descriptor_ptr(nir_builder *b, nir_tex_instr *tex)
@ -588,7 +612,8 @@ agx_nir_lower_texture(nir_shader *s)
/* Insert fences before lowering image atomics, since image atomics need
* different fencing than other image operations.
*/
NIR_PASS(progress, s, agx_nir_fence_images);
NIR_PASS(progress, s, nir_shader_intrinsics_pass, fence_image,
nir_metadata_block_index | nir_metadata_dominance, NULL);
NIR_PASS(progress, s, nir_lower_image_atomics_to_global);

View file

@ -0,0 +1,19 @@
/*
* Copyright 2024 Alyssa Rosenzweig
* SPDX-License-Identifier: MIT
*/
#pragma once
#include <stdbool.h>
struct nir_shader;
struct nir_instr;
/* Texture backend flags */
#define AGX_TEXTURE_FLAG_NO_CLAMP (1 << 0)
bool agx_nir_lower_texture_early(struct nir_shader *s, bool support_lod_bias);
bool agx_nir_lower_texture(struct nir_shader *s);
bool agx_nir_lower_multisampled_image_store(struct nir_shader *s);
bool agx_nir_needs_texture_crawl(struct nir_instr *instr);

View file

@ -18,6 +18,7 @@ libasahi_lib_files = files(
'agx_nir_lower_msaa.c',
'agx_nir_lower_sample_intrinsics.c',
'agx_nir_lower_tess.c',
'agx_nir_lower_texture.c',
'agx_nir_lower_tilebuffer.c',
'agx_nir_lower_vbo.c',
'agx_nir_predicate_layer_id.c',

View file

@ -8,8 +8,8 @@
*/
#include <stdint.h>
#include "asahi/compiler/agx_compile.h"
#include "asahi/layout/layout.h"
#include "asahi/lib/agx_nir_passes.h"
#include "compiler/nir/nir_builder.h"
#include "compiler/nir/nir_format_convert.h"
#include "gallium/auxiliary/util/u_blitter.h"

View file

@ -3,7 +3,7 @@
* SPDX-License-Identifier: MIT
*/
#include "asahi/compiler/agx_compile.h"
#include "asahi/lib/agx_nir_passes.h"
#include "compiler/glsl_types.h"
#include "compiler/nir/nir_builder.h"
#include "agx_state.h"

View file

@ -13,6 +13,7 @@
#include "asahi/layout/layout.h"
#include "asahi/lib/agx_formats.h"
#include "asahi/lib/agx_helpers.h"
#include "asahi/lib/agx_nir_passes.h"
#include "asahi/lib/agx_ppp.h"
#include "asahi/lib/agx_usc.h"
#include "compiler/nir/nir.h"
@ -2029,6 +2030,8 @@ agx_compile_variant(struct agx_device *dev, struct pipe_context *pctx,
NIR_PASS(_, nir, agx_nir_predicate_layer_id);
}
NIR_PASS(_, nir, agx_nir_lower_multisampled_image_store);
struct agx_shader_key base_key = {0};
if (nir->info.stage == MESA_SHADER_VERTEX) {