Build Guide¶
This guide contains the detailed build setup for KangEngine. The root README keeps only the short path; use this document when setting up a new machine or enabling optional components.
Requirements¶
CMake
Ninja or a compatible build tool
A C++17 compiler
vcpkg
PhysX under
$HOME/Physics/PhysX(see platform-specific versions and build options below)Python 3.12 for Python bindings
vcpkg¶
KangEngine uses vcpkg manifest mode for most third-party C++ dependencies.
ImGui, ImGuizmo, and ImPlot are installed through this manifest and linked as
CMake package targets. ImPlot powers the Performance panel’s frame timing graph;
its context is created and destroyed alongside ImGui in PanelManager.
Clone and bootstrap vcpkg.
git clone https://github.com/microsoft/vcpkg.git cd vcpkg && ./bootstrap-vcpkg.sh
Export
VCPKG_ROOTand add vcpkg toPATH.export VCPKG_ROOT=/path/to/vcpkg export PATH=$VCPKG_ROOT:$PATH
Linux¶
Tested with Ubuntu 24.04.
Install system packages.
sudo apt install clang ninja-build unzip libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config autoconf autoconf-archive automake libtool
Choose and build one PhysX configuration.
CPU build — PhysX 5.1.2
Download NVIDIA Omniverse PhysX under $HOME/Physics/PhysX.
mkdir -p ~/Physics
cd ~/Physics
wget https://github.com/NVIDIA-Omniverse/PhysX/archive/refs/tags/104.1-physx-5.1.2.zip
unzip 104.1-physx-5.1.2.zip
mv PhysX-104.1-physx-5.1.2 PhysX
Build it with clang.
cd ~/Physics/PhysX/physx
./buildtools/packman/packman update -y
./generate_projects.sh
cd compiler/linux-release
cmake . \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_CXX_FLAGS="-Wno-error=unsafe-buffer-usage -Wno-unsafe-buffer-usage -Wno-error=switch-default -Wno-switch-default -Wno-error=invalid-offsetof -Wno-invalid-offsetof -Wno-error=unused-but-set-variable -Wno-unused-but-set-variable"
cmake --build . --config release
KangEngine uses the libraries in
~/Physics/PhysX/physx/bin/linux.clang/release. PhysX snippet executables may
fail to link against their bundled OpenGL package; KangEngine does not require
those executables.
GPU build — PhysX 5.8
Clone the NVIDIA Omniverse PhysX
110.0-omni-and-physx-5.8.0
tag under $HOME/Physics/PhysX.
mkdir -p ~/Physics
cd ~/Physics
git clone \
--branch 110.0-omni-and-physx-5.8.0 \
--depth 1 \
https://github.com/NVIDIA-Omniverse/PhysX.git \
PhysX
Follow PhysX’s official
README_LINUX.md
to install its Linux prerequisites and generate the build. Enable the PhysX GPU
projects and produce a release build under linux.x86_64.
KangEngine’s CUDA targets select that output through:
PHYSX_CUDA_BIN_PLATFORM=linux.x86_64
The expected GPU shared library is:
$HOME/Physics/PhysX/physx/bin/linux.x86_64/release/libPhysXGpu_64.so
PhysX 5.8 supports CUDA 12.8 directly. Building it with CUDA 13 requires the
compatibility patch below; the sm_89 verification applies to RTX 4090 and
other Ada targets.
CUDA 13 / RTX 4090 compatibility¶
PhysX 5.8 architecture and CUDA Driver API patches
TL;DR¶
For PhysX 5.8, CUDA 13, and RTX 4090:
export PHYSX_ROOT=$HOME/Physics/PhysX/physx
export PHYSX_BUILD=$PHYSX_ROOT/compiler/linux-clang-release-5.8
export PHYSX_CUDA_SOURCE=$PHYSX_ROOT/source/cudamanager/src/CudaContextManager.cpp
python3 - "$PHYSX_CUDA_SOURCE" <<'PY'
from pathlib import Path
import sys
path = Path(sys.argv[1])
source = path.read_text()
old = "status = cuCtxCreate(&mCtx, (unsigned int)flags, mDevHandle);"
new = """#if CUDA_VERSION >= 13000
CUctxCreateParams ctxCreateParams = {};
status = cuCtxCreate(&mCtx, &ctxCreateParams, (unsigned int)flags, mDevHandle);
#else
status = cuCtxCreate(&mCtx, (unsigned int)flags, mDevHandle);
#endif"""
if new not in source:
if old not in source:
raise SystemExit("cuCtxCreate call not found; inspect the PhysX source")
path.write_text(source.replace(old, new, 1))
PY
cmake -S $PHYSX_ROOT/compiler/public \
-B $PHYSX_BUILD \
-DPHYSX_ROOT_DIR=$PHYSX_ROOT \
-DTARGET_BUILD_PLATFORM=linux \
-DCMAKE_BUILD_TYPE=release \
-DPX_OUTPUT_LIB_DIR=$PHYSX_ROOT \
-DPX_OUTPUT_BIN_DIR=$PHYSX_ROOT \
-DPX_GENERATE_STATIC_LIBRARIES=ON \
-DPX_GENERATE_GPU_PROJECTS=ON \
-DPX_GENERATE_GPU_REDUCED_ARCHITECTURES=ON
rg 'ARCH_CODE_LIST' $PHYSX_BUILD/CMakeCache.txt
cmake --build $PHYSX_BUILD --parallel
/usr/local/cuda/bin/cuobjdump --list-elf \
$PHYSX_ROOT/bin/linux.x86_64/release/libPhysXGpu_64.so \
| rg 'sm_89'
Why these flags and patches are needed
These notes document the Linux build that produced a PhysX 5.8.0 GPU library
with native sm_89 cubins for RTX 4090. Use this path when the older PhysX
5.1 GPU binary reports PhysX internal CUDA kernel launch failures on Ada GPUs.
The examples below assume the PhysX checkout lives at:
$HOME/Physics/PhysX
The build directory name is not special. Use any clean directory outside older PhysX build trees; this document uses:
$HOME/Physics/PhysX/physx/compiler/linux-clang-release-5.8
CUDA 13 architecture fix¶
CUDA 13.0 nvcc no longer accepts compute_70. PhysX 5.8.0’s default GPU
architecture list includes it unless reduced GPU architectures are enabled.
Configure with PX_GENERATE_GPU_REDUCED_ARCHITECTURES=ON so the generated
ARCH_CODE_LIST starts at compute_80 and includes compute_89.
This is the minimal direct CMake invocation used for KangEngine:
export PHYSX_ROOT=$HOME/Physics/PhysX/physx
export PHYSX_BUILD=$PHYSX_ROOT/compiler/linux-clang-release-5.8
cmake -S $PHYSX_ROOT/compiler/public \
-B $PHYSX_BUILD \
-DPHYSX_ROOT_DIR=$PHYSX_ROOT \
-DTARGET_BUILD_PLATFORM=linux \
-DCMAKE_BUILD_TYPE=release \
-DPX_OUTPUT_LIB_DIR=$PHYSX_ROOT \
-DPX_OUTPUT_BIN_DIR=$PHYSX_ROOT \
-DPX_GENERATE_STATIC_LIBRARIES=ON \
-DPX_GENERATE_GPU_PROJECTS=ON \
-DPX_GENERATE_GPU_REDUCED_ARCHITECTURES=ON
PHYSX_BUILD can point to any clean build directory. Keep the remaining options
explicit: PhysX’s public CMake entry point requires the root/output paths, while
KangEngine needs static PhysX libraries, GPU projects, and the reduced CUDA
architecture list for CUDA 13.
After configure, confirm compute_70 is gone:
rg 'ARCH_CODE_LIST' \
$PHYSX_BUILD/CMakeCache.txt
Expected ARCH_CODE_LIST includes:
compute_80, compute_86, compute_89, compute_90, compute_100, compute_120
CUDA 13 cuCtxCreate patch¶
PhysX 5.8.0 calls the older 3-argument CUDA Driver API form:
cuCtxCreate(&mCtx, (unsigned int)flags, mDevHandle);
With CUDA 13 headers, cuCtxCreate maps to cuCtxCreate_v4, which expects a
CUctxCreateParams* argument. Patch
$PHYSX_ROOT/source/cudamanager/src/CudaContextManager.cpp
near the CUDA context creation call:
#if CUDA_VERSION >= 13000
CUctxCreateParams ctxCreateParams = {};
status = cuCtxCreate(&mCtx, &ctxCreateParams, (unsigned int)flags, mDevHandle);
#else
status = cuCtxCreate(&mCtx, (unsigned int)flags, mDevHandle);
#endif
Then build:
cmake --build \
$PHYSX_BUILD \
--parallel
The build should finish with:
[100%] Built target PhysXVehicle2
Verify native Ada GPU kernels¶
Check that the rebuilt GPU library contains sm_89 cubins:
/usr/local/cuda/bin/cuobjdump --list-elf \
$PHYSX_ROOT/bin/linux.x86_64/release/libPhysXGpu_64.so \
| rg 'sm_89'
You should see entries such as:
broadphase.sm_89.cubin
MemCopyBalanced.sm_89.cubin
solver.sm_89.cubin
solverTGS.sm_89.cubin
integrationTGS.sm_89.cubin
Use this PhysX binary directory when linking KangEngine against the 5.8.0 checkout:
$PHYSX_ROOT/bin/linux.x86_64/release
Do not run PhysX configure/build commands with sudo. If an earlier build
created root-owned files, repair their ownership:
sudo chown -R "$USER:$USER" ~/Physics/PhysX/physx
Build KangEngine for the selected PhysX configuration.
CPU KangEngine build
CC=clang CXX=clang++ cmake --preset=vcpkg
cmake --build build/release
GPU KangEngine build
KangEngine links PhysXGpu_64; its shared library must be discoverable at
runtime.
make build_all
make build_cuda
make build_python_cuda
Run make validate_physx_gpu for the process-isolated Python GPU regression
suite or make validate_physx_gpu_cpp for the native smoke test. See
PHYSX_GPU.md for the runtime contract.
Run KangEngine.
make run2
macOS¶
Tested with Apple Silicon using the macOS ARM64 CPU port of PhysX 5.8.
Clone the PhysX 5.8 macOS fork under
$HOME/Physics/PhysX. If this directory already contains PhysX 5.1, move that checkout aside first.mkdir -p ~/Physics cd ~/Physics git clone -b macos-arm64-5.8 https://github.com/Gudegi/PhysX.git
Install build tools. Xcode command-line tools must also be installed.
brew install cmake coreutils ninja autoconf automake autoconf-archive
Build PhysX with CMake and Ninja directly. Python and Packman are not required for this SDK build.
cd ~/Physics/PhysX physx_config=release physx_build="$PWD/build/macos-arm64-$physx_config" cmake -S physx/compiler/public -B "$physx_build" -G Ninja \ -DPHYSX_ROOT_DIR="$PWD/physx" \ -DTARGET_BUILD_PLATFORM=mac \ -DPX_OUTPUT_ARCH=arm \ -DCMAKE_OSX_ARCHITECTURES=arm64 \ -DCMAKE_BUILD_TYPE="$physx_config" \ -DPX_GENERATE_STATIC_LIBRARIES=ON \ -DPX_GENERATE_GPU_PROJECTS=OFF \ -DPX_GENERATE_GPU_PROJECTS_ONLY=OFF \ -DPX_BUILDSNIPPETS=OFF \ -DPX_BUILDPVDRUNTIME=OFF \ -DPX_BUILD_PLATFORM_TESTS=ON \ -DPX_OUTPUT_LIB_DIR="$PWD/physx" \ -DPX_OUTPUT_BIN_DIR="$PWD/physx" \ -DCMAKE_INSTALL_PREFIX="$PWD/install/macos-arm64-$physx_config" cmake --build "$physx_build" -j 6 ctest --test-dir "$physx_build" --output-on-failure
Headers remain in
physx/include; libraries are generated inphysx/bin/mac.arm64/release. KeepPX_OUTPUT_ARCH=arm: it enables the_64library suffix expected by KangEngine, such aslibPhysXExtensions_static_64.a.See the fork’s macOS build instructions for supported features and platform test coverage.
Configure from the KangEngine repository root.
cmake --preset=vcpkg
Build KangEngine.
cmake --build build/release
Build Targets¶
Common make targets:
Target |
Runtime |
USD |
Output or action |
|---|---|---|---|
|
C++ CPU |
disabled |
|
|
C++ CUDA |
disabled |
|
|
C++ CPU |
local |
|
|
Python CPU |
disabled |
development extension |
|
Python CUDA |
disabled |
development extension |
|
Python CPU |
local |
development extension |
|
Python CPU on macOS, CUDA on Linux |
local |
executable and development extension |
|
Python CPU on macOS, CUDA on Linux |
vcpkg |
wheel extension under |
|
platform default |
bundled vcpkg |
release wheels from the existing build |
|
platform default |
bundled vcpkg |
fresh-environment validation of packaged wheels |
|
platform default |
bundled vcpkg |
build, package, and validate in order |
|
Python CUDA |
disabled |
GPU regression tests |
|
C++ CUDA |
disabled |
native GPU smoke test |
|
current release configuration |
current cache |
run all automatic smoke checks without rebuilding |
|
current release configuration |
current cache |
build and run executable |
Development extensions are written to python/kangengine/_kangengine.so.
Debug variants are available as build_debug, build_usd_debug,
build_python_debug, and build_usd_python_debug.
The executable target is selected in CMakeLists.txt by changing the active MAIN_FILE entry near the example list.
Verify the Build¶
Smoke suites check the current development build. The runner does not build or
reconfigure the engine. Python cases use the runner’s interpreter and the
repository’s Python package, so build the Python extension first. Native targets
must already exist in build/release, or the directory passed to --build-dir.
Enable KANGENGINE_BUILD_SMOKES=ON in your CMake configuration to build native
smoke targets.
Run from the repository root:
python python/scripts/run_smokes.py --list
python python/scripts/run_smokes.py --suite core
python python/scripts/run_smokes.py --suite render --suite asset
python python/scripts/run_smokes.py --case py:scene_render_instancing_smoke
make smoke SUITE=render
make smoke SUITE=core
make smoke
Suites are execution presets and can overlap. Selecting multiple suites runs
each case once. The default suite is all; use make smoke SUITE=core or
python python/scripts/run_smokes.py --suite core for the smaller core suite.
Both make smoke and python python/scripts/run_smokes.py run every registered
automatic case, including CUDA, ovrtx, MCP, and stress checks. Explicit
SUITE=all and --suite all are equivalent. This requires all their dependencies
and excludes manual entries.
Use python python/scripts/run_smokes.py --suite all --list to preview the selection.
Suite |
Checks |
Additional requirements |
|---|---|---|
|
API, scene data, CPU animation, render contracts |
No display required |
|
Native rendering, materials, debug geometry, visuals |
OpenGL and a usable display/context; some cases also require PhysX |
|
Asset loading, textures, rigid visuals |
OpenGL; some cases also require USD or PhysX |
|
CPU physics and simulation |
PhysX |
|
CUDA physics and CUDA/OpenGL interop |
CUDA-enabled build and supported NVIDIA GPU; visual cases also require OpenGL |
|
Frame execution |
OpenGL |
|
Application automation |
OpenGL and MCP dependencies |
|
Optional renderer adapter |
ovrtx environment and supported GPU; some cases also require OpenGL or PhysX |
|
Fixed-update catch-up under stalls |
CUDA physics and OpenGL |
The gpu suite covers CUDA-specific checks. OpenGL rendering and ovrtx have
their own suites even though they also use the GPU.
Use --list --suite render to inspect sources and requirements without loading
the engine. Requirements describe what each case needs; the case itself checks
runtime availability. Each case runs sequentially in a separate process,
including argument variants such as
py:shared_material_updates_smoke:scene-renderer.
A failed, timed-out, skipped, or unstartable case makes the suite exit nonzero,
while remaining cases still run. Per-case output, durations, and summary.json
are saved under build/smoke-logs/.
Source validation targets such as make validate_render_component,
make validate_python_api, and make validate_physx_gpu configure and build
before running their checks. make validate_render_component selects a Python
CPU build without USD. To preserve your current build configuration, run the matching suite
directly, such as --suite render-component, --suite python-api, or
--suite physx-gpu.
The USD scene smoke requires a user-supplied file, and the native scene-input exporter is a utility. Both are listed as manual entries rather than included in automatic suites.
OpenUSD Optional¶
Development builds use OpenUSD from USD_DIR (default: ~/usd_build). Wheel
builds use vcpkg OpenUSD in the separate build/wheel directory.
Clone OpenUSD.
cd ~ git clone https://github.com/PixarAnimationStudios/OpenUSD.git
Build OpenUSD into
~/usd_build.mkdir -p ~/usd_build python3 ~/OpenUSD/build_scripts/build_usd.py ~/usd_build
If you build OpenUSD somewhere else, pass
-DUSD_DIR=/path/to/usd_buildto your CMake configure command.USD_DIRis the OpenUSD installation prefix containinginclude/andlib/.
Python Bindings Optional¶
KangEngine exposes a Python module, kangengine, via pybind11. The extension is
built by CMake and must match the consumer’s CPython ABI, Python minor version,
platform, and architecture.
Create a virtual environment with Python 3.12 using
uv.uv venv python/.venv --python 3.12 source python/.venv/bin/activate
Build the extension from the repo root.
make build_pythonOr with USD support:
make build_usd_pythonInstall the Python package in editable mode.
uv pip install -e ./python
Run an example.
python ./python/examples/view_bvh_character.py
Python Wheels¶
Build on each target OS using the development environment above. macOS uses PhysX CPU; Linux uses CUDA. Both include OpenUSD. Install the release tools into the Python environment used by Make:
uv sync --project python --group release
make wheel
This runs three stages in order, including when using make -j. You can also
run each stage separately; individual stages do not run earlier stages:
make build_wheel # Build the native extension under build/wheel
make pack_wheel # Package release wheels under python/dist/release
make validate_wheel # Install and test those exact wheels in a fresh environment
pack_wheel performs Linux manylinux repair and checks release metadata. Its
wheel-manifest.json records the current artifacts so validation does not pick
up older wheels in the directory. Linux packaging requires patchelf on PATH.
If you change source code, start again from the build stage. A failed validation
leaves the artifacts available for diagnosis; only publish after validation passes.
Use the same commands on both platforms. Validation runs PhysX CPU checks on macOS and CPU plus GPU checks on Linux. Linux validation requires an NVIDIA GPU and CUDA-enabled PyTorch; GPU failures are not silently skipped. Each physics check runs in a separate process without opening a viewer. Default validation checks base APIs without gpu and render features; To validate those features:
# Linux: include rendering and CUDA/OpenGL interop checks.
make validate_wheel WHEEL_VALIDATION_FLAGS="--gpu-smoke --render-smoke"
# macOS: include rendering checks.
make validate_wheel WHEEL_VALIDATION_FLAGS="--render-smoke"
Validation creates a temporary virtual environment, installs the wheel and its declared dependencies, and checks dependency compatibility before running tests. It does not reuse installed development packages. Dependency downloads may be needed on the first run. Validation uses the final packaged files, including the repaired Linux wheels. None of these commands uploads a release.
Linux produces two wheels: kangengine and kangengine-physx-gpu.
Install the engine wheel in a fresh Python 3.12 environment; pip finds the
PhysX GPU wheel in the same directory:
python -m pip install --find-links python/dist/release python/dist/release/<kangengine-wheel>.whl
Optional Pyroki development dependencies: uv sync --project python --group pyroki.
Optional Hardware / Resource Usage Monitor¶
Open Performance > Resources to show resource measurements, and expand
Hardware details for render-device information. Linux CPU/RAM monitoring
requires access to /proc.
Measurements run on a worker at most once per second while the panel requests
them; the frame profiler does not need to be enabled.
NVIDIA GPU utilization and VRAM monitoring is optional. CMake looks for nvml.h
in the CUDA toolkit include directories and common installation paths. For a
custom installation, configure the existing build with:
cmake -S . -B build/release -DKANGENGINE_NVML_INCLUDE_DIR=/path/to/nvml/include
cmake --build build/release --target KangEngine _kangengine -j 4
This feature does not require enabling CUDA interop. At runtime the monitor
loads libnvidia-ml.so.1 from the NVIDIA driver. Missing headers, driver library,
permissions, or unsupported counters produce N/A; they do not prevent CPU/RAM
monitoring or rendering. Device-wide GPU measurements include other processes
and are listed by device name/index separately from the active render device.
The CPU table compares System and This process. RAM and VRAM show both
scopes as used / total capacity bars with the peak observed while sampling.
GPU utilization is shown once per device as total activity.
Percentages and RAM/VRAM used / total capacity use two decimal places. Process
CPU is normalized to total host CPU capacity for comparison; the per-core value
is available in the CPU tooltip. Measurement notes and failure reasons are also
shown in the relevant tooltips. UUIDs are retained internally for device identity
and are not displayed.
VRAM prefers NVML v2 allocated memory, excluding driver reservations, to match
nvidia-smi. Legacy-only drivers use the v1 counter and its tooltip notes that
reservations are included. Values are displayed in GiB (MiB divided by 1024).
Process GPU utilization is not queried. Process VRAM is queried from graphics and compute process lists without double-counting the same PID. Child processes are excluded.
Raw process CPU uses 100% per logical CPU; RAM usage is host MemTotal - MemAvailable,
not a container memory limit. See the NVML device query reference
and Linux memory counter definitions
for the underlying counters.
With KANGENGINE_BUILD_SMOKES=ON, validate without a display using:
cmake --build build/release --target resource_monitor_smoke -j 4
./build/release/resource_monitor_smoke
./build/release/resource_monitor_smoke --require-gpu # Requires accessible NVIDIA hardware
Build the Documentation¶
Build the Python extension first so the API reference can import the pybind11 module:
make build_python
make docs
To include APIs that exist only in a USD-enabled build:
make build_usd_python
make docs