agx: Add scaffolding to build the helper shader at device init

Add the scaffolding to compile our helper program, and load it at device
init time.

Signed-off-by: Asahi Lina <lina@asahilina.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27616>
This commit is contained in:
Asahi Lina
2023-11-08 15:43:52 +09:00
committed by Marge Bot
parent 05c8b59f5b
commit c406ce793b
6 changed files with 96 additions and 0 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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)
{
}

View File

@@ -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

View File

@@ -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(

View File

@@ -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)
{
}