- Root:
CMakeLists.txtdrives all builds and tests via CTest. - Source:
src/(C++17), public headers ininclude/. - Bench configs:
benchmarking/*.bench - Scripts:
scripts/for demo, tracing, and benchmarking helpers. - Tooling:
cmake/(modules, toolchains),external/(headers),doc/(standards),asset/,patches/. - Vulkan headers:
external/Vulkan-Headers/include/vulkan/(do not use the system headers)
- Configure (choose window system):
mkdir build && cd buildcmake .. -DWINDOWSYSTEM=x11(options:sdl,fbdev,pbuffers)
- Build:
make -j| Run tests:ctest --output-on-failure - Example run:
./vulkan_general --help(frombuild/).
- Language: C++20 with
-Wall -g. Match existing style insrc/andinclude/. - Names: test binaries follow
vulkan_<name>,gles_<name>,opencl_<name>; sources insrc/<api>_<name>.cpp. - CMake helpers: prefer
vulkan_test(name),gles_test(name),cl_test(name, version)to add tests and install bench files. - Bench files: add
benchmarking/<api>_<name>.benchaligned with the target name. - Add assert() calls to verify assumptions. Do not work around problems with defensive coding.
- Run test binaries directly, do not run via CTest unless asked to.
- For Vulkan tests, you can add the command line parameter
--cputo workaround AI sandbox problems. - For Vulkan tests, you can add the command line parameter
-vto enable the Vulkan validation layer. - Tests return error code 77 to indicate feature not supported.
- For GLES, window system is selectable via
-DWINDOWSYSTEM=<x11|sdl|fbuffers|fbdev>; default is X11. - Optional components can be toggled at configure time, e.g.,
-DNO_VULKAN=1,-DNO_GLES=1,-DNO_CL=1. - For Vulkan headers, install LunarG SDK or use provided
external/headers as configured.
- Create source
src/vulkan_<name>.cppand a bench filebenchmarking/vulkan_<name>.bench. - Register the test in
CMakeLists.txtwithvulkan_test(<name>)(orvulkan_window_testif it uses a surface). - Build with 'make -j'
- Run from build directory without GPU:
./vulkan_<name> -v --cpu. - Run from build directory with GPU:
./vulkan_<name> -v --gpu. - Fix any Vulkan validation errors shown in the output from the above runs.
- Use the check() function to test Vulkan call return values. Put it on a separate line after the Vulkan call. Do not wrap the Vulkan call.
- If asked to test an extension you are not familiar with, download the extension text from
https://docs.vulkan.org/refpages/latest/refpages/source/<extension name>.htmland read it.
Minimal src/vulkan_<name>.cpp:
#include "vulkan_common.h"
int main(int argc, char** argv)
{
vulkan_req_t reqs{}; // Optional: set reqs.usage/cmdopt
auto vk = test_init(argc, argv, "vulkan_<name>", reqs);
bench_start_iteration(vk.bench); // Start one deterministic iteration
// ... do work here ...
bench_stop_iteration(vk.bench);
test_done(vk);
return 0;
}Minimal benchmarking/vulkan_<name>.bench:
{ "name": "vulkan_<name>", "description": "Short description of test" }- Shaders shall be in separate files with extension giving their type, eg .comp for compute shaders, like
vulkan_<name>.<ext>. - Generate SPIRV from the GLSL source code with
glslangValidator -V vulkan_<name>.<ext> -o vulkan_<name>_<ext>.spirv - Then generate an include file with
xxd -i vulkan_<name>_<ext>.spirv > vulkan_<name>_<ext>.inc - Include this file in the C++ source code with
#include "vulkan_<name>_<ext>.inc"
- Create source
src/gles_<name>.cppand a bench filebenchmarking/gles_<name>.bench. - Register the test in
CMakeLists.txtwithgles_test(<name>). - Build with 'make -j'
- Run test as:
ctest -R gles_<name> --output-on-failure.
Minimal src/gles_<name>.cpp:
#include "gles_common.h"
static int setup_graphics(TOOLSTEST *handle)
{
// ... set up context here ...
}
static void callback_draw(TOOLSTEST *handle)
{
// ... do work here ...
}
static void test_cleanup(TOOLSTEST *handle)
{
// ... cleanup here ...
}
int main(int argc, char** argv)
{
return init(argc, argv, "gles_<name>.cpp", callback_draw, setup_graphics, test_cleanup);
}Minimal benchmarking/gles_<name>.bench:
{ "name": "gles_<name>", "description": "Short description of test" }- Create source
src/opencl_<name>.cppand a bench filebenchmarking/opencl_<name>.bench. - Register the test in
CMakeLists.txtwithcl_test(<name> 300). - Use the cl_check() function to test OpenCL call return values. Put it on a separate line after the OpenCL call. Do not wrap the OpenCL call.
- Build with 'make -j'
- Run from build directory without GPU:
./opencl_<name> -v --gpu-simulated. - Run from build directory with GPU:
./opencl_<name> -v --gpu-native. - Fix any errors shown in the output from the above runs.
Minimal src/opencl_<name>.cpp:
#include "opencl_common.h"
int main(int argc, char** argv)
{
reqs.usage = show_usage;
reqs.cmdopt = test_cmdopt;
opencl_setup_t cl = cl_test_init(argc, argv, "opencl_general", reqs);
bench_start_iteration(cl.bench);
// ... do work here ...
bench_stop_iteration(cl.bench);
cl_test_done(cl);
return 0;
}Minimal benchmarking/opencl_<name>.bench:
{ "name": "opencl_<name>", "description": "Short description of test" }