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 <david.rosca@amd.com>
Reviewed-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41133>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2026-04-16 15:00:25 +02:00
parent 61ae8f60d1
commit 61acf0e781
9 changed files with 154 additions and 91 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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.");
}
}

View file

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

View file

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

View file

@ -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 <stdint.h>
/* 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