From 61acf0e7816b061d7b28277e6fca5eb4fbf52b9b Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Thu, 16 Apr 2026 15:00:25 +0200 Subject: [PATCH] radeonsi: add tests subfolder and move AMD_TEST code inside And move the exit(0) code to the si_tests function. Reviewed-by: David Rosca Reviewed-by: Qiang Yu Part-of: --- src/gallium/drivers/radeonsi/meson.build | 6 +- src/gallium/drivers/radeonsi/si_pipe.c | 64 +------------------ src/gallium/drivers/radeonsi/si_pipe.h | 23 ------- .../radeonsi/{ => tests}/si_test_dma_perf.c | 5 +- .../{ => tests}/si_test_image_copy_region.c | 5 +- .../drivers/radeonsi/tests/si_test_vm_fault.c | 35 ++++++++++ src/gallium/drivers/radeonsi/tests/si_tests.c | 53 +++++++++++++++ src/gallium/drivers/radeonsi/tests/si_tests.h | 29 +++++++++ .../drivers/radeonsi/tests/si_tests_private.h | 25 ++++++++ 9 files changed, 154 insertions(+), 91 deletions(-) rename src/gallium/drivers/radeonsi/{ => tests}/si_test_dma_perf.c (99%) rename src/gallium/drivers/radeonsi/{ => tests}/si_test_image_copy_region.c (99%) create mode 100644 src/gallium/drivers/radeonsi/tests/si_test_vm_fault.c create mode 100644 src/gallium/drivers/radeonsi/tests/si_tests.c create mode 100644 src/gallium/drivers/radeonsi/tests/si_tests.h create mode 100644 src/gallium/drivers/radeonsi/tests/si_tests_private.h diff --git a/src/gallium/drivers/radeonsi/meson.build b/src/gallium/drivers/radeonsi/meson.build index 05ac717883d..15132f020a1 100644 --- a/src/gallium/drivers/radeonsi/meson.build +++ b/src/gallium/drivers/radeonsi/meson.build @@ -144,8 +144,10 @@ if with_gfx_compute 'gfx/si_nir_lower_vs_inputs.c', 'gfx/si_nir_mark_divergent_texture_non_uniform.c', 'gfx/si_nir_optim.c', - 'si_test_dma_perf.c', - 'si_test_image_copy_region.c', + 'tests/si_tests.c', + 'tests/si_test_dma_perf.c', + 'tests/si_test_image_copy_region.c', + 'tests/si_test_vm_fault.c', ) foreach ver : ['6', '7', '8', '9', '10', '103', '11', '115', '117', '12'] diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c index edbebaa1a46..ced57a1465d 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.c +++ b/src/gallium/drivers/radeonsi/si_pipe.c @@ -8,13 +8,13 @@ #include "si_pipe.h" #include "gfx/si_gfx.h" #include "mm/si_mm.h" +#include "tests/si_tests.h" #include "driver_ddebug/dd_util.h" #include "si_public.h" #include "sid.h" #include "util/u_memory.h" #include "util/u_suballoc.h" -#include "util/u_tests.h" #include "util/u_upload_mgr.h" #include "util/xmlconfig.h" #include "si_utrace.h" @@ -84,20 +84,6 @@ static const struct debug_named_value radeonsi_debug_options[] = { DEBUG_NAMED_VALUE_END /* must be last */ }; -static const struct debug_named_value test_options[] = { - /* Tests: */ - {"clearbuffer", DBG(TEST_CLEAR_BUFFER), "Test correctness of the clear_buffer compute shader"}, - {"copybuffer", DBG(TEST_COPY_BUFFER), "Test correctness of the copy_buffer compute shader"}, - {"imagecopy", DBG(TEST_IMAGE_COPY), "Invoke resource_copy_region tests with images and exit."}, - {"computeblit", DBG(TEST_COMPUTE_BLIT), "Invoke blits tests and exit."}, - {"testvmfaultcp", DBG(TEST_VMFAULT_CP), "Invoke a CP VM fault test and exit."}, - {"testvmfaultshader", DBG(TEST_VMFAULT_SHADER), "Invoke a shader VM fault test and exit."}, - {"dmaperf", DBG(TEST_DMA_PERF), "Test DMA performance"}, - {"testmemperf", DBG(TEST_MEM_PERF), "Test map + memcpy perf using the winsys."}, - - DEBUG_NAMED_VALUE_END /* must be last */ -}; - bool si_virtgpu_probe_nctx(int fd, const struct virgl_renderer_capset_drm *caps) { #ifdef HAVE_AMDGPU_VIRTIO @@ -204,36 +190,10 @@ void si_destroy_screen(struct pipe_screen *pscreen) FREE(sscreen); } -static void si_test_vmfault(struct si_screen *sscreen, uint64_t test_flags) -{ - struct pipe_context *ctx = sscreen->aux_context.general.ctx; - struct si_context *sctx = (struct si_context *)ctx; - struct pipe_resource *buf = pipe_buffer_create_const0(&sscreen->b, 0, PIPE_USAGE_DEFAULT, 64); - - if (!buf) { - puts("Buffer allocation failed."); - exit(1); - } - - si_resource(buf)->gpu_address = 0; /* cause a VM fault */ - - if (test_flags & DBG(TEST_VMFAULT_CP)) { - si_cp_dma_copy_buffer(sctx, buf, buf, 0, 4, 4); - ctx->flush(ctx, NULL, 0); - puts("VM fault test: CP - done."); - } - if (test_flags & DBG(TEST_VMFAULT_SHADER)) { - util_test_constant_buffer(ctx, buf); - puts("VM fault test: Shader - done."); - } - exit(0); -} - static struct pipe_screen *radeonsi_screen_create_impl(struct radeon_winsys *ws, const struct pipe_screen_config *config) { struct si_screen *sscreen = CALLOC_STRUCT(si_screen); - uint64_t test_flags; if (!sscreen) { return NULL; @@ -252,7 +212,6 @@ static struct pipe_screen *radeonsi_screen_create_impl(struct radeon_winsys *ws, sscreen->debug_flags = debug_get_flags_option("R600_DEBUG", radeonsi_debug_options, 0); sscreen->debug_flags |= debug_get_flags_option("AMD_DEBUG", radeonsi_debug_options, 0); - test_flags = debug_get_flags_option("AMD_TEST", test_options, 0); if ((sscreen->debug_flags & DBG(TMZ)) && !sscreen->info.has_tmz_support) { @@ -294,26 +253,7 @@ static struct pipe_screen *radeonsi_screen_create_impl(struct radeon_winsys *ws, for (unsigned i = 0; i < ARRAY_SIZE(sscreen->aux_contexts); i++) (void)mtx_init(&sscreen->aux_contexts[i].lock, mtx_plain | mtx_recursive); - if (test_flags & DBG(TEST_CLEAR_BUFFER)) - si_test_clear_buffer(sscreen); - - if (test_flags & DBG(TEST_COPY_BUFFER)) - si_test_copy_buffer(sscreen); - - if (test_flags & DBG(TEST_IMAGE_COPY)) - si_test_image_copy_region(sscreen); - - if (test_flags & DBG(TEST_COMPUTE_BLIT)) - si_test_blit(sscreen, test_flags); - - if (test_flags & DBG(TEST_DMA_PERF)) - si_test_dma_perf(sscreen); - - if (test_flags & DBG(TEST_MEM_PERF)) - si_test_mem_perf(sscreen); - - if (test_flags & (DBG(TEST_VMFAULT_CP) | DBG(TEST_VMFAULT_SHADER))) - si_test_vmfault(sscreen, test_flags); + si_run_tests(sscreen); return &sscreen->b; } diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h index 2c17b229fc4..149acd38f72 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.h +++ b/src/gallium/drivers/radeonsi/si_pipe.h @@ -254,19 +254,6 @@ enum DBG_NO_ENCODE_TIER2, }; -enum -{ - /* Tests: */ - DBG_TEST_CLEAR_BUFFER, - DBG_TEST_COPY_BUFFER, - DBG_TEST_IMAGE_COPY, - DBG_TEST_COMPUTE_BLIT, - DBG_TEST_VMFAULT_CP, - DBG_TEST_VMFAULT_SHADER, - DBG_TEST_DMA_PERF, - DBG_TEST_MEM_PERF, -}; - #define DBG_ALL_SHADERS (((1 << (DBG_MS + 1)) - 1)) #define DBG(name) (1ull << DBG_##name) @@ -1630,16 +1617,6 @@ MESAPROC void *gfx11_create_sh_query_result_cs(struct si_context *sctx) TAILPTR; void si_gfx11_init_query(struct si_context *sctx); void si_gfx11_destroy_query(struct si_context *sctx); -/* si_test_image_copy_region.c */ -MESAPROC void si_test_image_copy_region(struct si_screen *sscreen) TAILV; -MESAPROC void si_test_blit(struct si_screen *sscreen, unsigned test_flags) TAILV; - -/* si_test_dma_perf.c */ -MESAPROC void si_test_dma_perf(struct si_screen *sscreen) TAILV; -MESAPROC void si_test_mem_perf(struct si_screen *sscreen) TAILV; -MESAPROC void si_test_clear_buffer(struct si_screen *sscreen) TAILV; -MESAPROC void si_test_copy_buffer(struct si_screen *sscreen) TAILV; - /* si_state_viewport.c */ void si_update_vs_viewport_state(struct si_context *ctx); void si_init_viewport_functions(struct si_context *ctx); diff --git a/src/gallium/drivers/radeonsi/si_test_dma_perf.c b/src/gallium/drivers/radeonsi/tests/si_test_dma_perf.c similarity index 99% rename from src/gallium/drivers/radeonsi/si_test_dma_perf.c rename to src/gallium/drivers/radeonsi/tests/si_test_dma_perf.c index e35c355eb1c..e35ec3a87c5 100644 --- a/src/gallium/drivers/radeonsi/si_test_dma_perf.c +++ b/src/gallium/drivers/radeonsi/tests/si_test_dma_perf.c @@ -4,6 +4,9 @@ * SPDX-License-Identifier: MIT */ +#include "si_tests.h" +#include "si_tests_private.h" + #include "si_pipe.h" #include "si_query.h" #include "util/streaming-load-memcpy.h" @@ -516,7 +519,6 @@ void si_test_clear_buffer(struct si_screen *sscreen) } ctx->destroy(ctx); - exit(0); } void si_test_copy_buffer(struct si_screen *sscreen) @@ -626,5 +628,4 @@ void si_test_copy_buffer(struct si_screen *sscreen) } ctx->destroy(ctx); - exit(0); } diff --git a/src/gallium/drivers/radeonsi/si_test_image_copy_region.c b/src/gallium/drivers/radeonsi/tests/si_test_image_copy_region.c similarity index 99% rename from src/gallium/drivers/radeonsi/si_test_image_copy_region.c rename to src/gallium/drivers/radeonsi/tests/si_test_image_copy_region.c index 3e3e519b482..595c8a903b1 100644 --- a/src/gallium/drivers/radeonsi/si_test_image_copy_region.c +++ b/src/gallium/drivers/radeonsi/tests/si_test_image_copy_region.c @@ -6,6 +6,9 @@ /* This file implements randomized texture blit tests. */ +#include "si_tests.h" +#include "si_tests_private.h" + #include "si_pipe.h" #include "gfx/si_gfx.h" #include "util/rand_xor.h" @@ -618,7 +621,6 @@ void si_test_image_copy_region(struct si_screen *sscreen) } ctx->destroy(ctx); - exit(0); } void si_test_blit(struct si_screen *sscreen, unsigned test_flags) @@ -944,5 +946,4 @@ void si_test_blit(struct si_screen *sscreen, unsigned test_flags) } ctx->destroy(ctx); - exit(0); } diff --git a/src/gallium/drivers/radeonsi/tests/si_test_vm_fault.c b/src/gallium/drivers/radeonsi/tests/si_test_vm_fault.c new file mode 100644 index 00000000000..7215a45b177 --- /dev/null +++ b/src/gallium/drivers/radeonsi/tests/si_test_vm_fault.c @@ -0,0 +1,35 @@ +/* + * Copyright 2026 Advanced Micro Devices, Inc. + * + * SPDX-License-Identifier: MIT + */ + +#include "si_tests.h" +#include "si_tests_private.h" + +#include "si_pipe.h" +#include "util/u_tests.h" + +void si_test_vmfault(struct si_screen *sscreen, uint64_t test_flags) +{ + struct pipe_context *ctx = sscreen->aux_context.general.ctx; + struct si_context *sctx = (struct si_context *)ctx; + struct pipe_resource *buf = pipe_buffer_create_const0(&sscreen->b, 0, PIPE_USAGE_DEFAULT, 64); + + if (!buf) { + puts("Buffer allocation failed."); + exit(1); + } + + si_resource(buf)->gpu_address = 0; /* cause a VM fault */ + + if (test_flags & DBG(TEST_VMFAULT_CP)) { + si_cp_dma_copy_buffer(sctx, buf, buf, 0, 4, 4); + ctx->flush(ctx, NULL, 0); + puts("VM fault test: CP - done."); + } + if (test_flags & DBG(TEST_VMFAULT_SHADER)) { + util_test_constant_buffer(ctx, buf); + puts("VM fault test: Shader - done."); + } +} diff --git a/src/gallium/drivers/radeonsi/tests/si_tests.c b/src/gallium/drivers/radeonsi/tests/si_tests.c new file mode 100644 index 00000000000..d828c7c7bd0 --- /dev/null +++ b/src/gallium/drivers/radeonsi/tests/si_tests.c @@ -0,0 +1,53 @@ +/* + * Copyright 2026 Advanced Micro Devices, Inc. + * + * SPDX-License-Identifier: MIT + */ + +#include "si_tests.h" +#include "si_tests_private.h" + +#include "si_pipe.h" + +static const struct debug_named_value test_options[] = { + /* Tests: */ + {"clearbuffer", DBG(TEST_CLEAR_BUFFER), "Test correctness of the clear_buffer compute shader"}, + {"copybuffer", DBG(TEST_COPY_BUFFER), "Test correctness of the copy_buffer compute shader"}, + {"imagecopy", DBG(TEST_IMAGE_COPY), "Invoke resource_copy_region tests with images and exit."}, + {"computeblit", DBG(TEST_COMPUTE_BLIT), "Invoke blits tests and exit."}, + {"testvmfaultcp", DBG(TEST_VMFAULT_CP), "Invoke a CP VM fault test and exit."}, + {"testvmfaultshader", DBG(TEST_VMFAULT_SHADER), "Invoke a shader VM fault test and exit."}, + {"dmaperf", DBG(TEST_DMA_PERF), "Test DMA performance"}, + {"testmemperf", DBG(TEST_MEM_PERF), "Test map + memcpy perf using the winsys."}, + + DEBUG_NAMED_VALUE_END /* must be last */ +}; + +void si_run_tests(struct si_screen *sscreen) +{ + uint64_t test_flags = debug_get_flags_option("AMD_TEST", test_options, 0); + + if (test_flags & DBG(TEST_CLEAR_BUFFER)) + si_test_clear_buffer(sscreen); + + if (test_flags & DBG(TEST_COPY_BUFFER)) + si_test_copy_buffer(sscreen); + + if (test_flags & DBG(TEST_IMAGE_COPY)) + si_test_image_copy_region(sscreen); + + if (test_flags & DBG(TEST_COMPUTE_BLIT)) + si_test_blit(sscreen, test_flags); + + if (test_flags & DBG(TEST_DMA_PERF)) + si_test_dma_perf(sscreen); + + if (test_flags & DBG(TEST_MEM_PERF)) + si_test_mem_perf(sscreen); + + if (test_flags & (DBG(TEST_VMFAULT_CP) | DBG(TEST_VMFAULT_SHADER))) + si_test_vmfault(sscreen, test_flags); + + if (test_flags) + exit(0); +} diff --git a/src/gallium/drivers/radeonsi/tests/si_tests.h b/src/gallium/drivers/radeonsi/tests/si_tests.h new file mode 100644 index 00000000000..1bd672f22f2 --- /dev/null +++ b/src/gallium/drivers/radeonsi/tests/si_tests.h @@ -0,0 +1,29 @@ +/* + * Copyright 2026 Advanced Micro Devices, Inc. + * + * SPDX-License-Identifier: MIT + */ + +#ifndef SI_TESTS_H +#define SI_TESTS_H + +#include "util/u_stub_gfx_compute.h" + +enum +{ + /* Tests: */ + DBG_TEST_CLEAR_BUFFER, + DBG_TEST_COPY_BUFFER, + DBG_TEST_IMAGE_COPY, + DBG_TEST_COMPUTE_BLIT, + DBG_TEST_VMFAULT_CP, + DBG_TEST_VMFAULT_SHADER, + DBG_TEST_DMA_PERF, + DBG_TEST_MEM_PERF, +}; + +struct si_screen; + +MESAPROC void si_run_tests(struct si_screen *sscreen) TAILV; + +#endif /* SI_TESTS_H */ diff --git a/src/gallium/drivers/radeonsi/tests/si_tests_private.h b/src/gallium/drivers/radeonsi/tests/si_tests_private.h new file mode 100644 index 00000000000..655bd9578a0 --- /dev/null +++ b/src/gallium/drivers/radeonsi/tests/si_tests_private.h @@ -0,0 +1,25 @@ +/* + * Copyright 2026 Advanced Micro Devices, Inc. + * + * SPDX-License-Identifier: MIT + */ + +#ifndef SI_TESTS_PRIVATE_H +#define SI_TESTS_PRIVATE_H + +#include + + /* si_test_image_copy_region.c */ +void si_test_image_copy_region(struct si_screen *sscreen); +void si_test_blit(struct si_screen *sscreen, unsigned test_flags); + +/* si_test_dma_perf.c */ +void si_test_dma_perf(struct si_screen *sscreen); +void si_test_mem_perf(struct si_screen *sscreen); +void si_test_clear_buffer(struct si_screen *sscreen); +void si_test_copy_buffer(struct si_screen *sscreen); + +/* si_test_vm_fault.c */ +void si_test_vmfault(struct si_screen *sscreen, uint64_t test_flags); + +#endif