diff --git a/src/asahi/lib/agx_device.c b/src/asahi/lib/agx_device.c index acdf80026a1..526bc0e63d1 100644 --- a/src/asahi/lib/agx_device.c +++ b/src/asahi/lib/agx_device.c @@ -9,6 +9,7 @@ #include "util/timespec.h" #include "agx_bo.h" #include "agx_compile.h" +#include "agx_scratch.h" #include "decode.h" #include "glsl_types.h" #include "libagx_shaders.h" @@ -348,12 +349,17 @@ agx_open_device(void *memctx, struct agx_device *dev) sizeof(libagx_shaders_nir)); dev->libagx = nir_deserialize(memctx, &agx_nir_options, &blob); + dev->helper = agx_build_helper(dev); + return true; } void agx_close_device(struct agx_device *dev) { + if (dev->helper) + agx_bo_unreference(dev->helper); + agx_bo_cache_evict_all(dev); util_sparse_array_finish(&dev->bo_map); diff --git a/src/asahi/lib/agx_device.h b/src/asahi/lib/agx_device.h index b28a6e4ae38..e229026e063 100644 --- a/src/asahi/lib/agx_device.h +++ b/src/asahi/lib/agx_device.h @@ -117,6 +117,8 @@ struct agx_device { /* Number of hits/misses for the BO cache */ uint64_t hits, misses; } bo_cache; + + struct agx_bo *helper; }; bool agx_open_device(void *memctx, struct agx_device *dev); diff --git a/src/asahi/lib/agx_scratch.c b/src/asahi/lib/agx_scratch.c new file mode 100644 index 00000000000..e08a29732a9 --- /dev/null +++ b/src/asahi/lib/agx_scratch.c @@ -0,0 +1,52 @@ +/* + * Copyright 2023 Asahi Lina + * SPDX-License-Identifier: MIT + */ + +#include "agx_scratch.h" +#include "asahi/compiler/agx_compile.h" +#include "agx_bo.h" +#include "libagx_shaders.h" +#include "nir.h" +#include "nir_builder_opcodes.h" + +struct agx_bo * +agx_build_helper(struct agx_device *dev) +{ + struct agx_bo *bo; + struct util_dynarray binary; + + util_dynarray_init(&binary, NULL); + + nir_builder b = nir_builder_init_simple_shader( + MESA_SHADER_COMPUTE, &agx_nir_options, "Helper shader"); + + libagx_helper(&b); + + UNUSED struct agx_uncompiled_shader_info info; + UNUSED struct agx_shader_info compiled_info; + struct agx_shader_key key = {.libagx = dev->libagx}; + + agx_preprocess_nir(b.shader, dev->libagx, false, &info); + agx_compile_shader_nir(b.shader, &key, NULL, &binary, &compiled_info); + + bo = agx_bo_create(dev, binary.size, + AGX_BO_READONLY | AGX_BO_EXEC | AGX_BO_LOW_VA, + "Helper shader"); + assert(bo); + memcpy(bo->ptr.cpu, binary.data, binary.size); + util_dynarray_fini(&binary); + ralloc_free(b.shader); + + return bo; +} + +void +agx_scratch_init(struct agx_device *dev, struct agx_scratch *scratch) +{ +} + +void +agx_scratch_fini(struct agx_scratch *scratch) +{ +} diff --git a/src/asahi/lib/agx_scratch.h b/src/asahi/lib/agx_scratch.h new file mode 100644 index 00000000000..01fd0b57a96 --- /dev/null +++ b/src/asahi/lib/agx_scratch.h @@ -0,0 +1,20 @@ +/* + * Copyright 2023 Asahi Lina + * SPDX-License-Identifier: MIT + */ +#ifndef AGX_SCRATCH_H +#define AGX_SCRATCH_H + +#include "agx_device.h" + +struct agx_scratch { + struct agx_device *dev; + struct agx_bo *buf; +}; + +struct agx_bo *agx_build_helper(struct agx_device *dev); + +void agx_scratch_init(struct agx_device *dev, struct agx_scratch *scratch); +void agx_scratch_fini(struct agx_scratch *scratch); + +#endif diff --git a/src/asahi/lib/meson.build b/src/asahi/lib/meson.build index 856bfe7a344..9c9180d68a5 100644 --- a/src/asahi/lib/meson.build +++ b/src/asahi/lib/meson.build @@ -22,6 +22,7 @@ libasahi_lib_files = files( 'agx_nir_lower_vbo.c', 'agx_nir_predicate_layer_id.c', 'agx_ppp.h', + 'agx_scratch.c', 'pool.c', ) @@ -36,6 +37,7 @@ libagx_shader_files = files( 'shaders/tessellation.cl', 'shaders/tessellator.cl', 'shaders/texture.cl', + 'shaders/helper.cl', ) agx_pack = custom_target( diff --git a/src/asahi/lib/shaders/helper.cl b/src/asahi/lib/shaders/helper.cl new file mode 100644 index 00000000000..4f6928dda98 --- /dev/null +++ b/src/asahi/lib/shaders/helper.cl @@ -0,0 +1,14 @@ +/* + * Copyright 2023 Asahi Lina + * SPDX-License-Identifier: MIT + */ +#include "libagx.h" + +#define DB_NEXT 32 +#define DB_ACK 48 +#define DB_NACK 49 + +void +libagx_helper(void) +{ +}