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:
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
52
src/asahi/lib/agx_scratch.c
Normal file
52
src/asahi/lib/agx_scratch.c
Normal 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)
|
||||
{
|
||||
}
|
20
src/asahi/lib/agx_scratch.h
Normal file
20
src/asahi/lib/agx_scratch.h
Normal 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
|
@@ -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(
|
||||
|
14
src/asahi/lib/shaders/helper.cl
Normal file
14
src/asahi/lib/shaders/helper.cl
Normal 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)
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user