mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 05:18:08 +02:00
asahi/clc: switch to nir_lower_calls_to_builtins
common code has a generic version, so we don't need to handroll this. Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32382>
This commit is contained in:
parent
d8ece9bf3a
commit
83581b3f1f
4 changed files with 29 additions and 118 deletions
|
|
@ -28,109 +28,6 @@ static const struct spirv_to_nir_options spirv_options = {
|
|||
.create_library = true,
|
||||
};
|
||||
|
||||
static bool
|
||||
lower_builtins(nir_builder *b, nir_instr *instr, void *data)
|
||||
{
|
||||
if (instr->type != nir_instr_type_call)
|
||||
return false;
|
||||
|
||||
nir_call_instr *call = nir_instr_as_call(instr);
|
||||
nir_function *func = call->callee;
|
||||
|
||||
if (strcmp(func->name, "nir_interleave_agx") == 0) {
|
||||
b->cursor = nir_instr_remove(&call->instr);
|
||||
nir_store_deref(
|
||||
b, nir_src_as_deref(call->params[0]),
|
||||
nir_interleave_agx(b, call->params[1].ssa, call->params[2].ssa), 1);
|
||||
|
||||
return true;
|
||||
} else if (strcmp(func->name, "nir_doorbell_agx") == 0) {
|
||||
b->cursor = nir_instr_remove(&call->instr);
|
||||
nir_doorbell_agx(b, call->params[0].ssa);
|
||||
return true;
|
||||
} else if (strcmp(func->name, "nir_stack_map_agx") == 0) {
|
||||
b->cursor = nir_instr_remove(&call->instr);
|
||||
nir_stack_map_agx(b, call->params[0].ssa, call->params[1].ssa);
|
||||
return true;
|
||||
} else if (strcmp(func->name, "nir_stack_unmap_agx") == 0) {
|
||||
b->cursor = nir_instr_remove(&call->instr);
|
||||
nir_store_deref(b, nir_src_as_deref(call->params[0]),
|
||||
nir_stack_unmap_agx(b, call->params[1].ssa), 1);
|
||||
return true;
|
||||
} else if (strcmp(func->name, "nir_load_core_id_agx") == 0) {
|
||||
b->cursor = nir_instr_remove(&call->instr);
|
||||
nir_store_deref(b, nir_src_as_deref(call->params[0]),
|
||||
nir_load_core_id_agx(b), 1);
|
||||
return true;
|
||||
} else if (strcmp(func->name, "nir_load_helper_op_id_agx") == 0) {
|
||||
b->cursor = nir_instr_remove(&call->instr);
|
||||
nir_store_deref(b, nir_src_as_deref(call->params[0]),
|
||||
nir_load_helper_op_id_agx(b, 1, 32), 1);
|
||||
return true;
|
||||
} else if (strcmp(func->name, "nir_load_helper_arg_lo_agx") == 0) {
|
||||
b->cursor = nir_instr_remove(&call->instr);
|
||||
nir_store_deref(b, nir_src_as_deref(call->params[0]),
|
||||
nir_load_helper_arg_lo_agx(b, 1, 32), 1);
|
||||
return true;
|
||||
} else if (strcmp(func->name, "nir_load_helper_arg_hi_agx") == 0) {
|
||||
b->cursor = nir_instr_remove(&call->instr);
|
||||
nir_store_deref(b, nir_src_as_deref(call->params[0]),
|
||||
nir_load_helper_arg_hi_agx(b, 1, 32), 1);
|
||||
return true;
|
||||
} else if (strcmp(func->name, "ballot") == 0) {
|
||||
b->cursor = nir_instr_remove(&call->instr);
|
||||
nir_store_deref(b, nir_src_as_deref(call->params[0]),
|
||||
nir_ballot(b, 1, 32, call->params[1].ssa), 1);
|
||||
return true;
|
||||
} else if (strcmp(func->name, "nir_fence_helper_exit_agx") == 0) {
|
||||
b->cursor = nir_instr_remove(&call->instr);
|
||||
nir_fence_helper_exit_agx(b);
|
||||
return true;
|
||||
} else if (strcmp(func->name, "nir_bindless_image_load_array") == 0) {
|
||||
b->cursor = nir_instr_remove(&call->instr);
|
||||
|
||||
nir_def *texel = nir_bindless_image_load(
|
||||
b, 4, 32, call->params[1].ssa, call->params[2].ssa, nir_imm_int(b, 0),
|
||||
nir_imm_int(b, 0), .image_array = true,
|
||||
.image_dim = GLSL_SAMPLER_DIM_2D, .dest_type = nir_type_uint32,
|
||||
.access = ACCESS_IN_BOUNDS_AGX);
|
||||
|
||||
nir_store_deref(b, nir_src_as_deref(call->params[0]), texel, 0xf);
|
||||
return true;
|
||||
} else if (strcmp(func->name, "nir_bindless_image_store_array") == 0) {
|
||||
b->cursor = nir_instr_remove(&call->instr);
|
||||
|
||||
nir_bindless_image_store(
|
||||
b, call->params[0].ssa, call->params[1].ssa, nir_imm_int(b, 0),
|
||||
call->params[2].ssa, nir_imm_int(b, 0), .image_array = true,
|
||||
.image_dim = GLSL_SAMPLER_DIM_2D, .src_type = nir_type_uint32,
|
||||
.access = ACCESS_NON_READABLE);
|
||||
return true;
|
||||
} else if (strcmp(func->name, "nir_bindless_image_load_ms_array") == 0) {
|
||||
b->cursor = nir_instr_remove(&call->instr);
|
||||
|
||||
nir_def *texel = nir_bindless_image_load(
|
||||
b, 4, 32, call->params[1].ssa, call->params[2].ssa,
|
||||
call->params[3].ssa, nir_imm_int(b, 0), .image_array = true,
|
||||
.image_dim = GLSL_SAMPLER_DIM_MS, .dest_type = nir_type_uint32,
|
||||
.access = ACCESS_IN_BOUNDS_AGX);
|
||||
|
||||
nir_store_deref(b, nir_src_as_deref(call->params[0]), texel, 0xf);
|
||||
return true;
|
||||
} else if (strcmp(func->name, "nir_bindless_image_store_ms_array") == 0) {
|
||||
b->cursor = nir_instr_remove(&call->instr);
|
||||
|
||||
nir_bindless_image_store(
|
||||
b, call->params[0].ssa, call->params[1].ssa, call->params[2].ssa,
|
||||
call->params[3].ssa, nir_imm_int(b, 0), .image_array = true,
|
||||
.image_dim = GLSL_SAMPLER_DIM_MS, .src_type = nir_type_uint32,
|
||||
.access = ACCESS_NON_READABLE);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Standard optimization loop */
|
||||
static void
|
||||
optimize(nir_shader *nir)
|
||||
|
|
@ -180,7 +77,7 @@ compile(void *memctx, const uint32_t *spirv, size_t spirv_size)
|
|||
ralloc_steal(memctx, nir);
|
||||
|
||||
NIR_PASS(_, nir, nir_lower_system_values);
|
||||
nir_shader_instructions_pass(nir, lower_builtins, nir_metadata_none, NULL);
|
||||
NIR_PASS(_, nir, nir_lower_calls_to_builtins);
|
||||
|
||||
/* We have to lower away local constant initializers right before we
|
||||
* inline functions. That way they get properly initialized at the top
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
* Copyright 2024 Valve Corporation
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include "compiler/nir/nir_defines.h"
|
||||
#include "compiler/shader_enums.h"
|
||||
#include "agx_pack.h"
|
||||
#include "compression.h"
|
||||
#include "libagx.h"
|
||||
|
|
@ -97,11 +99,15 @@ libagx_decompress(constant struct libagx_decompress_push *push, uint3 coord_tl,
|
|||
for (uint i = 0; i < 8; ++i) {
|
||||
int4 c_sa = img_coord_sa + (int4)(i, 0, 0, 0);
|
||||
if (samples == 1) {
|
||||
texels[i] = nir_bindless_image_load_array(HANDLE(compressed), c_sa);
|
||||
texels[i] = nir_bindless_image_load(
|
||||
HANDLE(compressed), c_sa, 0, 0, GLSL_SAMPLER_DIM_2D, true, 0,
|
||||
ACCESS_IN_BOUNDS_AGX, nir_type_uint32);
|
||||
} else {
|
||||
int4 dec_px = decompose_px(c_sa, samples);
|
||||
texels[i] = nir_bindless_image_load_ms_array(
|
||||
HANDLE(compressed), dec_px, sample_id(c_sa, samples));
|
||||
texels[i] = nir_bindless_image_load(
|
||||
HANDLE(compressed), dec_px, sample_id(c_sa, samples), 0,
|
||||
GLSL_SAMPLER_DIM_MS, true, 0, ACCESS_IN_BOUNDS_AGX,
|
||||
nir_type_uint32);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -111,11 +117,16 @@ libagx_decompress(constant struct libagx_decompress_push *push, uint3 coord_tl,
|
|||
for (uint i = 0; i < 8; ++i) {
|
||||
int4 c_sa = img_coord_sa + (int4)(i, 0, 0, 0);
|
||||
if (samples == 1) {
|
||||
nir_bindless_image_store_array(HANDLE(uncompressed), c_sa, texels[i]);
|
||||
nir_bindless_image_store(HANDLE(uncompressed), c_sa, 0, texels[i], 0,
|
||||
GLSL_SAMPLER_DIM_2D, true, 0,
|
||||
ACCESS_NON_READABLE, nir_type_uint32);
|
||||
} else {
|
||||
int4 dec_px = decompose_px(c_sa, samples);
|
||||
nir_bindless_image_store_ms_array(HANDLE(uncompressed), dec_px,
|
||||
sample_id(c_sa, samples), texels[i]);
|
||||
|
||||
nir_bindless_image_store(HANDLE(uncompressed), dec_px,
|
||||
sample_id(c_sa, samples), texels[i], 0,
|
||||
GLSL_SAMPLER_DIM_MS, true, 0,
|
||||
ACCESS_NON_READABLE, nir_type_uint32);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -276,10 +276,10 @@ static uint
|
|||
first_true_thread_in_workgroup(bool cond, local uint *scratch)
|
||||
{
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
scratch[get_sub_group_id()] = ballot(cond);
|
||||
scratch[get_sub_group_id()] = nir_ballot(cond);
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
uint first_group = ctz(ballot(scratch[get_sub_group_local_id()]));
|
||||
uint first_group = ctz(nir_ballot(scratch[get_sub_group_local_id()]));
|
||||
uint off = ctz(first_group < 32 ? scratch[first_group] : 0);
|
||||
return (first_group * 32) + off;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,18 +40,21 @@ uint32_t nir_load_helper_arg_lo_agx(void);
|
|||
uint32_t nir_load_helper_arg_hi_agx(void);
|
||||
void nir_fence_helper_exit_agx(void);
|
||||
|
||||
uint4 nir_bindless_image_load_array(uint2 handle, int4 coord);
|
||||
void nir_bindless_image_store_array(uint2 handle, int4 coord, uint4 datum);
|
||||
uint4 nir_bindless_image_load_ms_array(uint2 handle, int4 coord, uint sample);
|
||||
void nir_bindless_image_store_ms_array(uint2 handle, int4 coord, uint sample,
|
||||
uint4 datum);
|
||||
uint4 nir_bindless_image_load(uint2 handle, int4 coord, uint sample, uint lod,
|
||||
uint image_dim, uint image_array, uint format,
|
||||
uint access, uint dest_type);
|
||||
|
||||
void nir_bindless_image_store(uint2 handle, int4 coord, uint sample,
|
||||
uint4 datum, uint lod, uint image_dim,
|
||||
uint image_array, uint format, uint access,
|
||||
uint src_type);
|
||||
|
||||
uint libagx_load_index_buffer_internal(uintptr_t index_buffer,
|
||||
uint32_t index_buffer_range_el, uint id,
|
||||
uint index_size);
|
||||
|
||||
/* I have no idea why CL doesn't have this */
|
||||
uint ballot(bool cond);
|
||||
uint nir_ballot(bool cond);
|
||||
|
||||
#define _S(x) #x
|
||||
#define AGX_PASTE_(x, y) x##y
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue