From d695c848290a64cdfd2365a039f256dd70d54c43 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 4 Dec 2024 08:41:14 -0500 Subject: [PATCH] libagx: port to common libcl.h Signed-off-by: Alyssa Rosenzweig Reviewed-by: Mary Guillemard Part-of: --- src/asahi/genxml/agx_pack_header.h | 107 +++------------------------ src/asahi/genxml/gen_pack.py | 6 +- src/asahi/libagx/compression.cl | 5 +- src/asahi/libagx/compression.h | 3 +- src/asahi/libagx/draws.cl | 2 +- src/asahi/libagx/geometry.cl | 16 +--- src/asahi/libagx/geometry.h | 12 +-- src/asahi/libagx/helper.cl | 3 +- src/asahi/libagx/helper.h | 12 +-- src/asahi/libagx/libagx.h | 87 ---------------------- src/asahi/libagx/libagx_dgc.h | 62 +++++++--------- src/asahi/libagx/libagx_intrinsics.h | 27 +++++++ src/asahi/libagx/query.cl | 2 +- src/asahi/libagx/query.h | 2 +- src/asahi/libagx/tessellator.h | 6 +- src/asahi/libagx/texture.cl | 3 +- 16 files changed, 98 insertions(+), 257 deletions(-) delete mode 100644 src/asahi/libagx/libagx.h create mode 100644 src/asahi/libagx/libagx_intrinsics.h diff --git a/src/asahi/genxml/agx_pack_header.h b/src/asahi/genxml/agx_pack_header.h index d4e18c8b77b..58517678a9d 100644 --- a/src/asahi/genxml/agx_pack_header.h +++ b/src/asahi/genxml/agx_pack_header.h @@ -8,100 +8,13 @@ #pragma once +#include "compiler/libcl/libcl.h" +#include "util/bitpack_helpers.h" + #ifndef __OPENCL_VERSION__ #include #include -#include "util/bitpack_helpers.h" #include "util/half_float.h" -#define FILE_TYPE FILE -#define CONSTANT_ const -#define GLOBAL_ -#else - -#include "libagx.h" -#define assert(x) -#define FILE_TYPE void -#define CONSTANT_ constant -#define GLOBAL_ global -#define BITFIELD64_MASK(x) ((x == 64) ? ~0ul : ((1ul << x) - 1)) -#define IS_POT(v) (((v) & ((v) - 1)) == 0) -#define IS_POT_NONZERO(v) ((v) != 0 && IS_POT(v)) - -static uint64_t -util_bitpack_uint(uint64_t v, uint32_t start, uint32_t end) -{ - return v << start; -} - -static uint64_t -util_bitpack_sint(int64_t v, uint32_t start, uint32_t end) -{ - const int bits = end - start + 1; - const uint64_t mask = BITFIELD64_MASK(bits); - return (v & mask) << start; -} - -static uint32_t -util_bitpack_float(float v) -{ - union { - float f; - uint32_t dw; - } x; - x.f = v; - return x.dw; -} - -static inline float -uif(uint32_t ui) -{ - union { - float f; - uint32_t dw; - } fi; - fi.dw = ui; - return fi.f; -} - -#define DIV_ROUND_UP(A, B) (((A) + (B) - 1) / (B)) -#define CLAMP(X, MIN, MAX) ((X) > (MIN) ? ((X) > (MAX) ? (MAX) : (X)) : (MIN)) -#define ALIGN_POT(x, pot_align) (((x) + (pot_align) - 1) & ~((pot_align) - 1)) - -static inline unsigned -util_logbase2(unsigned n) -{ - return ((sizeof(unsigned) * 8 - 1) - __builtin_clz(n | 1)); -} - -static inline int64_t -util_sign_extend(uint64_t val, unsigned width) -{ - unsigned shift = 64 - width; - return (int64_t)(val << shift) >> shift; -} - -static inline uint16_t -_mesa_float_to_half(float f) -{ - union { - half h; - uint16_t w; - } hi; - hi.h = convert_half(f); - return hi.w; -} - -static inline float -_mesa_half_to_float(uint16_t w) -{ - union { - half h; - uint16_t w; - } hi; - hi.w = w; - return convert_float(hi.h); -} - #endif #define __gen_unpack_float(x, y, z) uif(__gen_unpack_uint(x, y, z)) @@ -109,7 +22,7 @@ _mesa_half_to_float(uint16_t w) _mesa_half_to_float(__gen_unpack_uint(x, y, z)) static inline uint64_t -__gen_unpack_uint(CONSTANT_ uint32_t *restrict cl, uint32_t start, uint32_t end) +__gen_unpack_uint(constant uint32_t *restrict cl, uint32_t start, uint32_t end) { uint64_t val = 0; const int width = end - start + 1; @@ -135,13 +48,13 @@ __gen_pack_lod(float f, uint32_t start, uint32_t end) } static inline float -__gen_unpack_lod(CONSTANT_ uint32_t *restrict cl, uint32_t start, uint32_t end) +__gen_unpack_lod(constant uint32_t *restrict cl, uint32_t start, uint32_t end) { return ((float)__gen_unpack_uint(cl, start, end)) / (1 << 6); } static inline uint64_t -__gen_unpack_sint(CONSTANT_ uint32_t *restrict cl, uint32_t start, uint32_t end) +__gen_unpack_sint(constant uint32_t *restrict cl, uint32_t start, uint32_t end) { int size = end - start + 1; int64_t val = __gen_unpack_uint(cl, start, end); @@ -177,16 +90,16 @@ __gen_from_groups(uint32_t value, uint32_t group_size, uint32_t length) #define agx_pack(dst, T, name) \ for (struct AGX_##T name = {AGX_##T##_header}, \ - *_loop_count = (GLOBAL_ void *)((uintptr_t)0); \ + *_loop_count = (global void *)((uintptr_t)0); \ (uintptr_t)_loop_count < 1; ( \ { \ - AGX_##T##_pack((GLOBAL_ uint32_t *)(dst), &name); \ - _loop_count = (GLOBAL_ void *)(((uintptr_t)_loop_count) + 1); \ + AGX_##T##_pack((global uint32_t *)(dst), &name); \ + _loop_count = (global void *)(((uintptr_t)_loop_count) + 1); \ })) #define agx_unpack(fp, src, T, name) \ struct AGX_##T name; \ - AGX_##T##_unpack(fp, (CONSTANT_ uint8_t *)(src), &name) + AGX_##T##_unpack(fp, (constant uint8_t *)(src), &name) #define agx_print(fp, T, var, indent) AGX_##T##_print(fp, &(var), indent) diff --git a/src/asahi/genxml/gen_pack.py b/src/asahi/genxml/gen_pack.py index 1d711a06e31..48f0a6d688b 100644 --- a/src/asahi/genxml/gen_pack.py +++ b/src/asahi/genxml/gen_pack.py @@ -395,7 +395,7 @@ class Group(object): convert = None args = [] - args.append('(CONSTANT_ uint32_t *) cl') + args.append('(constant uint32_t *) cl') args.append(str(fieldref.start)) args.append(str(fieldref.end)) @@ -573,7 +573,7 @@ class Parser(object): print("};\n") def emit_pack_function(self, name, group): - print("static inline void\n%s_pack(GLOBAL_ uint32_t * restrict cl,\n%sconst struct %s * restrict values)\n{" % + print("static inline void\n%s_pack(global uint32_t * restrict cl,\n%sconst struct %s * restrict values)\n{" % (name, ' ' * (len(name) + 6), name)) group.emit_pack_function() @@ -590,7 +590,7 @@ class Parser(object): def emit_unpack_function(self, name, group): print("static inline bool") - print("%s_unpack(FILE_TYPE *fp, CONSTANT_ uint8_t * restrict cl,\n%sstruct %s * restrict values)\n{" % + print("%s_unpack(FILE *fp, constant uint8_t * restrict cl,\n%sstruct %s * restrict values)\n{" % (name.upper(), ' ' * (len(name) + 8), name)) group.emit_unpack_function() diff --git a/src/asahi/libagx/compression.cl b/src/asahi/libagx/compression.cl index aebc5effa20..ca7f947ee74 100644 --- a/src/asahi/libagx/compression.cl +++ b/src/asahi/libagx/compression.cl @@ -2,11 +2,12 @@ * Copyright 2024 Valve Corporation * SPDX-License-Identifier: MIT */ +#include "compiler/libcl/libcl.h" #include "compiler/nir/nir_defines.h" #include "compiler/shader_enums.h" #include "agx_pack.h" #include "compression.h" -#include "libagx.h" +#include "libagx_intrinsics.h" /* * Decompress in place. The metadata is updated, so other processes can read the @@ -38,7 +39,7 @@ index_metadata(uint3 c, uint width, uint height, uint layer_stride) uint major_coord = width > height ? c.x : c.y; uint minor_dim = min(width, height); - uint intl_bits = libagx_logbase2_ceil(minor_dim); + uint intl_bits = util_logbase2_ceil(minor_dim); uint intl_mask = (1 << intl_bits) - 1; uint2 intl_coords = c.xy & intl_mask; diff --git a/src/asahi/libagx/compression.h b/src/asahi/libagx/compression.h index f22228b7df1..a7faf00e635 100644 --- a/src/asahi/libagx/compression.h +++ b/src/asahi/libagx/compression.h @@ -3,7 +3,6 @@ * SPDX-License-Identifier: MIT */ #include "agx_pack.h" -#include "libagx.h" #pragma once @@ -11,4 +10,4 @@ struct libagx_decompress_images { struct agx_texture_packed compressed; struct agx_pbe_packed uncompressed; }; -AGX_STATIC_ASSERT(sizeof(struct libagx_decompress_images) == 48); +static_assert(sizeof(struct libagx_decompress_images) == 48); diff --git a/src/asahi/libagx/draws.cl b/src/asahi/libagx/draws.cl index 64925c6ef63..9e5cf30e1bd 100644 --- a/src/asahi/libagx/draws.cl +++ b/src/asahi/libagx/draws.cl @@ -2,7 +2,7 @@ * Copyright 2024 Valve Corporation * SPDX-License-Identifier: MIT */ -#include "libagx.h" +#include "compiler/libcl/libcl.h" /* * To implement drawIndirectCount generically, we dispatch a kernel to diff --git a/src/asahi/libagx/geometry.cl b/src/asahi/libagx/geometry.cl index e3a58ab1746..8044b4ced5b 100644 --- a/src/asahi/libagx/geometry.cl +++ b/src/asahi/libagx/geometry.cl @@ -5,19 +5,10 @@ */ #include "geometry.h" +#include "libagx_intrinsics.h" #include "query.h" #include "tessellator.h" -/* Compatible with util/u_math.h */ -static inline uint -util_logbase2_ceil(uint n) -{ - if (n <= 1) - return 0; - else - return 32 - clz(n - 1); -} - /* Swap the two non-provoking vertices third vert in odd triangles. This * generates a vertex ID list with a consistent winding order. * @@ -332,10 +323,11 @@ static uint first_true_thread_in_workgroup(bool cond, local uint *scratch) { barrier(CLK_LOCAL_MEM_FENCE); - scratch[get_sub_group_id()] = nir_ballot(cond); + scratch[get_sub_group_id()] = sub_group_ballot(cond)[0]; barrier(CLK_LOCAL_MEM_FENCE); - uint first_group = ctz(nir_ballot(scratch[get_sub_group_local_id()])); + uint first_group = + ctz(sub_group_ballot(scratch[get_sub_group_local_id()])[0]); uint off = ctz(first_group < 32 ? scratch[first_group] : 0); return (first_group * 32) + off; } diff --git a/src/asahi/libagx/geometry.h b/src/asahi/libagx/geometry.h index fdb0538f8c8..405397d2154 100644 --- a/src/asahi/libagx/geometry.h +++ b/src/asahi/libagx/geometry.h @@ -4,8 +4,8 @@ * SPDX-License-Identifier: MIT */ +#include "compiler/libcl/libcl.h" #include "compiler/shader_enums.h" -#include "libagx.h" #ifndef __OPENCL_VERSION__ #include "util/bitscan.h" @@ -30,7 +30,7 @@ struct agx_geometry_state { GLOBAL(uchar) heap; uint32_t heap_bottom, heap_size; } PACKED; -AGX_STATIC_ASSERT(sizeof(struct agx_geometry_state) == 4 * 4); +static_assert(sizeof(struct agx_geometry_state) == 4 * 4); struct agx_ia_state { /* Index buffer if present. */ @@ -44,7 +44,7 @@ struct agx_ia_state { */ uint32_t verts_per_instance; } PACKED; -AGX_STATIC_ASSERT(sizeof(struct agx_ia_state) == 4 * 4); +static_assert(sizeof(struct agx_ia_state) == 4 * 4); static inline uint64_t libagx_index_buffer(uint64_t index_buffer, uint size_el, uint offset_el, @@ -139,7 +139,7 @@ struct agx_geometry_params { */ uint32_t input_topology; } PACKED; -AGX_STATIC_ASSERT(sizeof(struct agx_geometry_params) == 82 * 4); +static_assert(sizeof(struct agx_geometry_params) == 82 * 4); /* TCS shared memory layout: * @@ -237,8 +237,8 @@ libagx_tcs_out_stride(uint nr_patch_out, uint out_patch_size, static uint libagx_compact_prim(enum mesa_prim prim) { - AGX_STATIC_ASSERT(MESA_PRIM_QUAD_STRIP == MESA_PRIM_QUADS + 1); - AGX_STATIC_ASSERT(MESA_PRIM_POLYGON == MESA_PRIM_QUADS + 2); + static_assert(MESA_PRIM_QUAD_STRIP == MESA_PRIM_QUADS + 1); + static_assert(MESA_PRIM_POLYGON == MESA_PRIM_QUADS + 2); #ifndef __OPENCL_VERSION__ assert(prim != MESA_PRIM_QUADS); diff --git a/src/asahi/libagx/helper.cl b/src/asahi/libagx/helper.cl index ccb4fb4f5df..aa3eb84fa28 100644 --- a/src/asahi/libagx/helper.cl +++ b/src/asahi/libagx/helper.cl @@ -2,8 +2,9 @@ * Copyright 2023 Asahi Lina * SPDX-License-Identifier: MIT */ +#include "compiler/libcl/libcl.h" #include "helper.h" -#include "libagx.h" +#include "libagx_intrinsics.h" #define DB_NEXT 32 #define DB_ACK 48 diff --git a/src/asahi/libagx/helper.h b/src/asahi/libagx/helper.h index aae2632b0ec..5bd09e2b4a9 100644 --- a/src/asahi/libagx/helper.h +++ b/src/asahi/libagx/helper.h @@ -6,8 +6,8 @@ #ifndef LIBAGX_HELPER_H #define LIBAGX_HELPER_H +#include "compiler/libcl/libcl.h" #include "agx_pack.h" -#include "libagx.h" // Enable this to debug core mappings. // #define SCRATCH_DEBUG_CORES 512 @@ -26,7 +26,7 @@ struct agx_helper_block { uint32_t blocks[4]; } PACKED; -AGX_STATIC_ASSERT(sizeof(struct agx_helper_block) == 16); +static_assert(sizeof(struct agx_helper_block) == 16); struct agx_helper_core { GLOBAL(struct agx_helper_block) blocklist; @@ -36,15 +36,15 @@ struct agx_helper_core { uint32_t _pad; uint32_t alloc_count[AGX_SPILL_SIZE_BUCKETS]; } PACKED; -AGX_STATIC_ASSERT(sizeof(struct agx_helper_core) == - (8 + 3 * 4 + AGX_SPILL_SIZE_BUCKETS * 4 + 4)); +static_assert(sizeof(struct agx_helper_core) == + (8 + 3 * 4 + AGX_SPILL_SIZE_BUCKETS * 4 + 4)); struct agx_helper_header { uint32_t subgroups; uint32_t _pad; struct agx_helper_core cores[AGX_MAX_CORE_ID]; } PACKED; -AGX_STATIC_ASSERT(sizeof(struct agx_helper_header) == - (4 + 4 + AGX_MAX_CORE_ID * sizeof(struct agx_helper_core))); +static_assert(sizeof(struct agx_helper_header) == + (4 + 4 + AGX_MAX_CORE_ID * sizeof(struct agx_helper_core))); #endif diff --git a/src/asahi/libagx/libagx.h b/src/asahi/libagx/libagx.h deleted file mode 100644 index 2f39150fe2d..00000000000 --- a/src/asahi/libagx/libagx.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2023 Alyssa Rosenzweig - * SPDX-License-Identifier: MIT - */ - -#ifndef LIBAGX_H -#define LIBAGX_H - -/* Define stdint types compatible between the CPU and GPU for shared headers */ -#ifndef __OPENCL_VERSION__ -#include -#include "util/macros.h" -#define GLOBAL(type_) uint64_t -#define CONSTANT(type_) uint64_t -#define AGX_STATIC_ASSERT(_COND) static_assert(_COND, #_COND) -#define global_ -#define constant_ -#else -#pragma OPENCL EXTENSION cl_khr_fp16 : enable -#define PACKED __attribute__((packed, aligned(4))) -#define GLOBAL(type_) global type_ * -#define CONSTANT(type_) constant type_ * -#define global_ global -#define constant_ constant -#define ASSERTED -#define assert(x) -#define BITFIELD_BIT(b) (1u << b) -#define BITFIELD_MASK(m) (((m) == 32) ? 0xffffffff : ((1u << (m)) - 1)) - -typedef ulong uint64_t; -typedef uint uint32_t; -typedef ushort uint16_t; -typedef uchar uint8_t; - -typedef long int64_t; -typedef int int32_t; -typedef short int16_t; -typedef char int8_t; - -/* Define NIR intrinsics for CL */ -uint32_t nir_interleave_agx(uint16_t x, uint16_t y); -void nir_doorbell_agx(uint8_t value); -void nir_stack_map_agx(uint16_t index, uint32_t address); -uint32_t nir_stack_unmap_agx(uint16_t index); -uint32_t nir_load_core_id_agx(void); -uint32_t nir_load_helper_op_id_agx(void); -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(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); - -/* I have no idea why CL doesn't have this */ -uint nir_ballot(bool cond); - -#define _S(x) #x -#define AGX_PASTE_(x, y) x##y -#define AGX_PASTE(x, y) AGX_PASTE_(x, y) -#define AGX_STATIC_ASSERT(_COND) \ - typedef char AGX_PASTE(static_assertion, __LINE__)[(_COND) ? 1 : -1] - -#define KERNEL(x) __attribute__((reqd_work_group_size(x, 1, 1))) kernel void - -static inline uint -align(uint x, uint y) -{ - return (x + y - 1) & ~(y - 1); -} - -static inline uint32_t -libagx_logbase2_ceil(uint32_t n) -{ - return (n <= 1) ? 0 : 32 - clz(n - 1); -} - -#define offsetof(x, y) __builtin_offsetof(x, y) - -#endif - -#endif diff --git a/src/asahi/libagx/libagx_dgc.h b/src/asahi/libagx/libagx_dgc.h index a7a8f5d42e4..1636184acd3 100644 --- a/src/asahi/libagx/libagx_dgc.h +++ b/src/asahi/libagx/libagx_dgc.h @@ -5,24 +5,18 @@ #pragma once +#include "compiler/libcl/libcl.h" #include "agx_pack.h" -#include "libagx.h" - -#ifdef __OPENCL_VERSION__ -#define NDEBUG -#define memcpy __builtin_memcpy -#define STATIC_ASSERT AGX_STATIC_ASSERT -#endif #define agx_push(ptr, T, cfg) \ for (unsigned _loop = 0; _loop < 1; \ - ++_loop, ptr = (global_ void *)(((uintptr_t)ptr) + AGX_##T##_LENGTH)) \ + ++_loop, ptr = (global void *)(((uintptr_t)ptr) + AGX_##T##_LENGTH)) \ agx_pack(ptr, T, cfg) #define agx_push_packed(ptr, src, T) \ - STATIC_ASSERT(sizeof(src) == AGX_##T##_LENGTH); \ + static_assert(sizeof(src) == AGX_##T##_LENGTH); \ memcpy(ptr, &src, sizeof(src)); \ - ptr = (global_ void *)(((uintptr_t)ptr) + sizeof(src)); + ptr = (global void *)(((uintptr_t)ptr) + sizeof(src)); struct agx_workgroup { uint32_t x, y, z; @@ -85,8 +79,8 @@ enum agx_chip { AGX_CHIP_G14X, }; -static inline global_ uint32_t * -agx_cdm_launch(global_ uint32_t *out, enum agx_chip chip, struct agx_grid grid, +static inline global uint32_t * +agx_cdm_launch(global uint32_t *out, enum agx_chip chip, struct agx_grid grid, struct agx_workgroup wg, struct agx_cdm_launch_word_0_packed launch, uint32_t usc) { @@ -134,8 +128,8 @@ agx_cdm_launch(global_ uint32_t *out, enum agx_chip chip, struct agx_grid grid, return out; } -static inline global_ uint32_t * -agx_cdm_barrier(global_ uint32_t *out, enum agx_chip chip) +static inline global uint32_t * +agx_cdm_barrier(global uint32_t *out, enum agx_chip chip) { agx_push(out, CDM_BARRIER, cfg) { cfg.unk_5 = true; @@ -181,8 +175,8 @@ agx_cdm_barrier(global_ uint32_t *out, enum agx_chip chip) return out; } -static inline global_ uint32_t * -agx_cdm_return(global_ uint32_t *out) +static inline global uint32_t * +agx_cdm_return(global uint32_t *out) { agx_push(out, CDM_STREAM_RETURN, cfg) ; @@ -190,8 +184,8 @@ agx_cdm_return(global_ uint32_t *out) return out; } -static inline global_ uint32_t * -agx_cdm_terminate(global_ uint32_t *out) +static inline global uint32_t * +agx_cdm_terminate(global uint32_t *out) { agx_push(out, CDM_STREAM_TERMINATE, _) ; @@ -199,8 +193,8 @@ agx_cdm_terminate(global_ uint32_t *out) return out; } -static inline global_ uint32_t * -agx_vdm_terminate(global_ uint32_t *out) +static inline global uint32_t * +agx_vdm_terminate(global uint32_t *out) { agx_push(out, VDM_STREAM_TERMINATE, _) ; @@ -208,8 +202,8 @@ agx_vdm_terminate(global_ uint32_t *out) return out; } -static inline global_ uint32_t * -agx_cdm_jump(global_ uint32_t *out, uint64_t target) +static inline global uint32_t * +agx_cdm_jump(global uint32_t *out, uint64_t target) { agx_push(out, CDM_STREAM_LINK, cfg) { cfg.target_lo = target & BITFIELD_MASK(32); @@ -219,8 +213,8 @@ agx_cdm_jump(global_ uint32_t *out, uint64_t target) return out; } -static inline global_ uint32_t * -agx_vdm_jump(global_ uint32_t *out, uint64_t target) +static inline global uint32_t * +agx_vdm_jump(global uint32_t *out, uint64_t target) { agx_push(out, VDM_STREAM_LINK, cfg) { cfg.target_lo = target & BITFIELD_MASK(32); @@ -230,14 +224,14 @@ agx_vdm_jump(global_ uint32_t *out, uint64_t target) return out; } -static inline global_ uint32_t * -agx_cs_jump(global_ uint32_t *out, uint64_t target, bool vdm) +static inline global uint32_t * +agx_cs_jump(global uint32_t *out, uint64_t target, bool vdm) { return vdm ? agx_vdm_jump(out, target) : agx_cdm_jump(out, target); } -static inline global_ uint32_t * -agx_cdm_call(global_ uint32_t *out, uint64_t target) +static inline global uint32_t * +agx_cdm_call(global uint32_t *out, uint64_t target) { agx_push(out, CDM_STREAM_LINK, cfg) { cfg.target_lo = target & BITFIELD_MASK(32); @@ -248,8 +242,8 @@ agx_cdm_call(global_ uint32_t *out, uint64_t target) return out; } -static inline global_ uint32_t * -agx_vdm_call(global_ uint32_t *out, uint64_t target) +static inline global uint32_t * +agx_vdm_call(global uint32_t *out, uint64_t target) { agx_push(out, VDM_STREAM_LINK, cfg) { cfg.target_lo = target & BITFIELD_MASK(32); @@ -285,7 +279,7 @@ struct agx_shader { /* Opaque structure representing a USC program being constructed */ struct agx_usc_builder { - global_ uint8_t *head; + global uint8_t *head; #ifndef NDEBUG uint8_t *begin; @@ -294,11 +288,11 @@ struct agx_usc_builder { } PACKED; #ifdef __OPENCL_VERSION__ -AGX_STATIC_ASSERT(sizeof(struct agx_usc_builder) == 8); +static_assert(sizeof(struct agx_usc_builder) == 8); #endif static struct agx_usc_builder -agx_usc_builder(global_ void *out, ASSERTED size_t size) +agx_usc_builder(global void *out, ASSERTED size_t size) { return (struct agx_usc_builder){ .head = out, @@ -358,7 +352,7 @@ agx_usc_uniform(struct agx_usc_builder *b, unsigned start_halfs, } static inline void -agx_usc_words_precomp(global_ uint32_t *out, constant_ struct agx_shader *s, +agx_usc_words_precomp(global uint32_t *out, constant struct agx_shader *s, uint64_t data, unsigned data_size) { /* Map the data directly as uniforms starting at u0 */ diff --git a/src/asahi/libagx/libagx_intrinsics.h b/src/asahi/libagx/libagx_intrinsics.h new file mode 100644 index 00000000000..17e2e785ec6 --- /dev/null +++ b/src/asahi/libagx/libagx_intrinsics.h @@ -0,0 +1,27 @@ +/* + * Copyright 2023 Alyssa Rosenzweig + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include "compiler/libcl/libcl.h" + +uint32_t nir_interleave_agx(uint16_t x, uint16_t y); +void nir_doorbell_agx(uint8_t value); +void nir_stack_map_agx(uint16_t index, uint32_t address); +uint32_t nir_stack_unmap_agx(uint16_t index); +uint32_t nir_load_core_id_agx(void); +uint32_t nir_load_helper_op_id_agx(void); +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(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); diff --git a/src/asahi/libagx/query.cl b/src/asahi/libagx/query.cl index 1b635133d00..c1ec47d6b4c 100644 --- a/src/asahi/libagx/query.cl +++ b/src/asahi/libagx/query.cl @@ -4,7 +4,7 @@ * Copyright 2022 Collabora Ltd. and Red Hat Inc. * SPDX-License-Identifier: MIT */ -#include "libagx.h" +#include "compiler/libcl/libcl.h" #include "query.h" static inline void diff --git a/src/asahi/libagx/query.h b/src/asahi/libagx/query.h index 07163db62ba..be4d7e43f27 100644 --- a/src/asahi/libagx/query.h +++ b/src/asahi/libagx/query.h @@ -4,7 +4,7 @@ * Copyright 2022 Collabora Ltd. and Red Hat Inc. * SPDX-License-Identifier: MIT */ -#include "libagx.h" +#include "compiler/libcl/libcl.h" #pragma once diff --git a/src/asahi/libagx/tessellator.h b/src/asahi/libagx/tessellator.h index 0eb920811be..004287bda6b 100644 --- a/src/asahi/libagx/tessellator.h +++ b/src/asahi/libagx/tessellator.h @@ -5,7 +5,7 @@ #pragma once -#include "libagx.h" +#include "compiler/libcl/libcl.h" enum libagx_tess_partitioning { LIBAGX_TESS_PARTITIONING_FRACTIONAL_ODD, @@ -25,7 +25,7 @@ struct libagx_tess_point { uint32_t u; uint32_t v; }; -AGX_STATIC_ASSERT(sizeof(struct libagx_tess_point) == 8); +static_assert(sizeof(struct libagx_tess_point) == 8); struct libagx_tess_args { /* Heap to allocate tessellator outputs in */ @@ -104,4 +104,4 @@ struct libagx_tess_args { */ uint32_t ccw; } PACKED; -AGX_STATIC_ASSERT(sizeof(struct libagx_tess_args) == 35 * 4); +static_assert(sizeof(struct libagx_tess_args) == 35 * 4); diff --git a/src/asahi/libagx/texture.cl b/src/asahi/libagx/texture.cl index c4fee794743..4afa6fc0cd6 100644 --- a/src/asahi/libagx/texture.cl +++ b/src/asahi/libagx/texture.cl @@ -3,7 +3,8 @@ * Copyright 2023 Valve Corporation * SPDX-License-Identifier: MIT */ -#include "libagx.h" +#include "compiler/libcl/libcl.h" +#include "libagx_intrinsics.h" #include uint3