Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions .github/workflows/renderdoc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
name: Test NCNN RenderDoc Integration

on:
push:
branches: [ master ]
workflow_dispatch:

jobs:
test-renderdoc-linux:
runs-on: ubuntu-latest
strategy:
matrix:
compiler: [gcc, clang]
build_type: [Release, Debug]

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
cmake ninja-build \
libvulkan-dev vulkan-utils vulkan-validationlayers \
renderdoc \
libglfw3-dev libglm-dev \
libprotobuf-dev protobuf-compiler \
libopencv-dev

- name: Setup compiler
if: matrix.compiler == 'clang'
run: |
sudo apt-get install -y clang
echo "CC=clang" >> $GITHUB_ENV
echo "CXX=clang++" >> $GITHUB_ENV

- name: Configure CMake
run: |
cmake -B build -G Ninja \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DNCNN_VULKAN=ON \
-DNCNN_SIMPLEVK=OFF \
-DNCNN_ENABLE_RENDERDOC_PROFILING=ON \
-DNCNN_BUILD_BENCHMARK=ON

- name: Build
run: cmake --build build --parallel

- name: Build benchncnn
run: cmake --build build --target benchncnn --parallel

- name: Copy benchmark param files
run: |
echo "Copying benchmark param files..."
mkdir -p build/benchmark
cp benchmark/*.param build/benchmark/ || echo "No param files found in benchmark directory"
ls -la build/benchmark/*.param || echo "No param files copied"

- name: Test RenderDoc capture with benchncnn
run: |
export NCNN_RENDERDOC_CAPTURE_PATH="./benchncnn_capture"

echo "Running benchncnn with RenderDoc headless capture..."
renderdoccmd capture ./build/benchmark/benchncnn 10 4 0 0 1

if [ -f "benchncnn_capture.rdc" ]; then
echo "RenderDoc capture file created successfully"
ls -la benchncnn_capture.rdc
else
echo "RenderDoc capture file not found"
exit 1
fi

- name: Upload RenderDoc capture
uses: actions/upload-artifact@v4
if: always()
with:
name: renderdoc-capture-linux-${{ matrix.compiler }}-${{ matrix.build_type }}
path: |
benchncnn_capture.rdc

test-renderdoc-windows:
runs-on: windows-latest
strategy:
matrix:
arch: [x64, x86]
build_type: [Release, Debug]

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup MSVC
uses: microsoft/[email protected]

- name: Install Vulkan SDK
run: |
$url = "https://sdk.lunarg.com/sdk/download/1.3.268.0/windows/VulkanSDK-1.3.268.0-Installer.exe"
$installer = "$env:TEMP\VulkanSDK-Installer.exe"
Invoke-WebRequest -Uri $url -OutFile $installer
Start-Process -FilePath $installer -ArgumentList "/S" -Wait

- name: Install RenderDoc
run: |
$url = "https://renderdoc.org/stable/1.40/RenderDoc_1.40_64.msi"
$installer = "$env:TEMP\RenderDoc-Installer.msi"
Invoke-WebRequest -Uri $url -OutFile $installer
Start-Process -FilePath $installer -ArgumentList "/quiet" -Wait

- name: Configure CMake
run: |
cmake -B build -A ${{ matrix.arch }} `
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} `
-DNCNN_VULKAN=ON `
-DNCNN_SIMPLEVK=OFF `
-DNCNN_ENABLE_RENDERDOC_PROFILING=ON `
-DNCNN_BUILD_BENCHMARK=ON

- name: Build
run: cmake --build build --config ${{ matrix.build_type }} --parallel

- name: Build benchncnn
run: cmake --build build --config ${{ matrix.build_type }} --target benchncnn --parallel

- name: Copy benchmark param files (Windows)
run: |
Write-Host "Copying benchmark param files..."
New-Item -ItemType Directory -Force -Path "build\benchmark"
if (Test-Path "benchmark\*.param") {
Copy-Item "benchmark\*.param" "build\benchmark\" -Force
Get-ChildItem "build\benchmark\*.param"
} else {
Write-Host "No param files found in benchmark directory"
}

- name: Test RenderDoc capture with benchncnn
run: |
$env:PATH += ";C:\VulkanSDK\1.3.268.0\Bin"
$env:PATH += ";C:\Program Files\RenderDoc"
$env:NCNN_RENDERDOC_CAPTURE_PATH = "benchncnn_capture.rdc"

Write-Host "Running benchncnn with RenderDoc capture..."
& "C:\Program Files\RenderDoc\renderdoccmd.exe" capture .\build\benchmark\${{ matrix.build_type }}\benchncnn.exe 10 4 0 0 1

if (Test-Path "benchncnn_capture.rdc") {
Write-Host "RenderDoc capture file created successfully"
Get-ChildItem benchncnn_capture.rdc
} else {
Write-Host "RenderDoc capture file not found"
exit 1
}

- name: Upload Windows RenderDoc capture
uses: actions/upload-artifact@v4
if: always()
with:
name: renderdoc-capture-windows-${{ matrix.arch }}-${{ matrix.build_type }}
path: |
benchncnn_capture.rdc


integration-test:
runs-on: ubuntu-latest
needs: [test-renderdoc-linux, test-renderdoc-windows]

steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
pattern: renderdoc-capture-*
merge-multiple: true

- name: Summary with capture analysis
run: |
echo "## NCNN RenderDoc Cross-Platform Test Results" >> $GITHUB_STEP_SUMMARY
echo "Linux benchncnn RenderDoc capture completed" >> $GITHUB_STEP_SUMMARY
echo "Windows benchncnn RenderDoc capture completed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

echo "### Generated RenderDoc Captures:" >> $GITHUB_STEP_SUMMARY
for file in *.rdc; do
if [ -f "$file" ]; then
size=$(stat -c%s "$file" 2>/dev/null || echo "unknown")
echo "- $file (${size} bytes)" >> $GITHUB_STEP_SUMMARY
fi
done

echo "" >> $GITHUB_STEP_SUMMARY
echo "RenderDoc integration with benchncnn successfully tested!" >> $GITHUB_STEP_SUMMARY
echo "Capture files are available in the artifacts for analysis." >> $GITHUB_STEP_SUMMARY
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ option(NCNN_PYTHON "build python api" OFF)
option(NCNN_INT8 "int8 inference" ON)
option(NCNN_BF16 "bf16 inference" ON)
option(NCNN_FORCE_INLINE "force inline some function" ON)
option(NCNN_ENABLE_RENDERDOC_PROFILING "Enables profiling with the RenderDoc tool." OFF)

if(ANDROID OR IOS OR NCNN_SIMPLESTL)
option(NCNN_DISABLE_RTTI "disable rtti" ON)
Expand Down Expand Up @@ -798,6 +799,9 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
endif()

if(NCNN_VULKAN)
if(NCNN_ENABLE_RENDERDOC_PROFILING)
add_definitions(-DNCNN_ENABLE_RENDERDOC_PROFILING=1)
endif()
if(NCNN_SYSTEM_GLSLANG)
find_package(Threads)
find_package(SPIRV-Tools QUIET)
Expand Down
6 changes: 6 additions & 0 deletions benchmark/benchncnn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ int main(int argc, char** argv)

g_blob_vkallocator = new ncnn::VkBlobAllocator(g_vkdev);
g_staging_vkallocator = new ncnn::VkStagingAllocator(g_vkdev);
#if NCNN_ENABLE_RENDERDOC_PROFILING
ncnn::start_renderdoc_capture();
#endif // NCNN_ENABLE_RENDERDOC_PROFILING
}
#endif // NCNN_VULKAN

Expand Down Expand Up @@ -467,6 +470,9 @@ int main(int argc, char** argv)
#if NCNN_VULKAN
delete g_blob_vkallocator;
delete g_staging_vkallocator;
#if NCNN_ENABLE_RENDERDOC_PROFILING
ncnn::end_renderdoc_capture();
#endif // NCNN_ENABLE_RENDERDOC_PROFILING
#endif // NCNN_VULKAN

return 0;
Expand Down
41 changes: 41 additions & 0 deletions docs/developer-guide/glsl-extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,47 @@ void main()

At runtime, `NCNN_LOGE` will print out the value of `gx`

#### RenderDoc Integration

When validation layer is enabled, ncnn also supports RenderDoc integration for GPU debugging and profiling. To enable RenderDoc support:

* Build with RenderDoc support:
```bash
cmake -DNCNN_VULKAN=ON -DNCNN_SIMPLEVK=OFF -DNCNN_ENABLE_RENDERDOC_PROFILING=ON ..
```

* Add capture calls in your program:
```cpp
int main() {
// Start RenderDoc capture
ncnn::start_renderdoc_capture();

// ... inference operations ...

// End RenderDoc capture
ncnn::end_renderdoc_capture();
return 0;
}
```

* Specify capture file path (optional):
```bash
export NCNN_RENDERDOC_CAPTURE_PATH="/path/to/capture_file"
```

* Capture GPU operations:
```bash
renderdoccmd capture your_ncnn_application
```

When RenderDoc integration is enabled, ncnn will:
- Detect RenderDoc library at runtime
- Begin capture when GPU operations start
- End capture when GPU instance is destroyed
- Save capture files for analysis in RenderDoc

The generated `.rdc` files can be opened in RenderDoc GUI to analyze Vulkan API calls, shader execution, memory usage, and GPU performance metrics for ncnn inference operations.

### option macros

enable glsl extension only if user enable some options
Expand Down
40 changes: 40 additions & 0 deletions docs/developer-guide/glsl-extension.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,46 @@ void main()

在运行时,`NCNN_LOGE` 将打印出 `gx` 的值

#### RenderDoc 集成

当启用验证层时,ncnn 还支持 RenderDoc 集成,用于 GPU 调试和性能分析。启用 RenderDoc 支持需要:

* 构建时启用 RenderDoc 支持:
```bash
cmake -DNCNN_VULKAN=ON -DNCNN_SIMPLEVK=OFF -DNCNN_ENABLE_RENDERDOC_PROFILING=ON ..
```

* 在程序中添加捕获调用:
```cpp
int main() {
// 开始RenderDoc捕获
ncnn::start_renderdoc_capture();

// ... 推理操作 ...

// 结束RenderDoc捕获
ncnn::end_renderdoc_capture();
return 0;
}
```
* 指定捕获文件路径(可选):
```bash
export NCNN_RENDERDOC_CAPTURE_PATH="/path/to/capture_file"
```

* 捕获 GPU 操作:
```bash
renderdoccmd capture your_ncnn_application
```

当启用 RenderDoc 集成时,ncnn 将会:
- 在运行时自动检测 RenderDoc 库
- 在 GPU 操作开始时开始捕获
- 在 GPU 实例销毁时结束捕获
- 保存捕获文件供 RenderDoc 分析

生成的 `.rdc` 文件可以在 RenderDoc GUI 中打开,用于分析 ncnn 推理操作的 Vulkan API 调用、着色器执行、内存使用情况和 GPU 性能指标。

### 选项宏

仅当用户启用某些选项时才启用 GLSL 扩展
Expand Down
Loading
Loading