Skip to content

Commit bc53177

Browse files
committed
Add real triangle rendering pipeline for benchmark scenes
1 parent 791dcea commit bc53177

7 files changed

Lines changed: 454 additions & 49 deletions

File tree

CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,36 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
66
set(CMAKE_CXX_EXTENSIONS OFF)
77

88
find_package(Vulkan REQUIRED)
9+
find_program(GLSLANG_VALIDATOR glslangValidator REQUIRED)
10+
11+
set(SHADER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/shaders)
12+
set(SPIRV_DIR ${CMAKE_CURRENT_BINARY_DIR}/shaders)
13+
file(MAKE_DIRECTORY ${SPIRV_DIR})
14+
15+
set(SHADER_OUTPUTS
16+
${SPIRV_DIR}/triangle.vert.spv
17+
${SPIRV_DIR}/triangle.frag.spv
18+
)
19+
20+
add_custom_command(
21+
OUTPUT ${SPIRV_DIR}/triangle.vert.spv
22+
COMMAND ${GLSLANG_VALIDATOR} -V ${SHADER_DIR}/triangle.vert -o ${SPIRV_DIR}/triangle.vert.spv
23+
DEPENDS ${SHADER_DIR}/triangle.vert
24+
)
25+
26+
add_custom_command(
27+
OUTPUT ${SPIRV_DIR}/triangle.frag.spv
28+
COMMAND ${GLSLANG_VALIDATOR} -V ${SHADER_DIR}/triangle.frag -o ${SPIRV_DIR}/triangle.frag.spv
29+
DEPENDS ${SHADER_DIR}/triangle.frag
30+
)
31+
32+
add_custom_target(vk-bench-shaders DEPENDS ${SHADER_OUTPUTS})
933

1034
add_executable(vk-bench src/main.cpp)
35+
add_dependencies(vk-bench vk-bench-shaders)
1136
target_include_directories(vk-bench PRIVATE include)
1237
target_link_libraries(vk-bench PRIVATE Vulkan::Vulkan)
38+
target_compile_definitions(vk-bench PRIVATE VK_BENCH_SHADER_DIR="/usr/local/share/vk-bench/shaders")
1339

1440
install(TARGETS vk-bench RUNTIME DESTINATION bin)
41+
install(FILES ${SHADER_OUTPUTS} DESTINATION share/vk-bench/shaders)

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
55
cmake \
66
pkg-config \
77
vulkan-tools \
8+
glslang-tools \
89
&& rm -rf /var/lib/apt/lists/*
910

1011
WORKDIR /workspace
1112
COPY CMakeLists.txt /workspace/CMakeLists.txt
1213
COPY src /workspace/src
1314
COPY include /workspace/include
15+
COPY shaders /workspace/shaders
1416
RUN cmake -S /workspace -B /workspace/build -DCMAKE_BUILD_TYPE=Release \
1517
&& cmake --build /workspace/build --config Release -j"$(nproc)" \
1618
&& install -m 0755 /workspace/build/vk-bench /usr/local/bin/vk-bench

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ A containerized Vulkan micro-benchmark that renders one controlled workload at a
88

99
This Level 0 repo intentionally scopes to **one executable** (`vk-bench`) and **three micro-scenes**:
1010

11-
- `triangle` (sanity / low work)
12-
- `million-tris` (high draw-like transfer load)
11+
- `triangle` (real graphics pipeline rendering one triangle to an offscreen target)
12+
- `million-tris` (graphics raster stress via 1,000,000 triangle instances)
1313
- `compute-copy` (bandwidth-focused transfer load)
1414

1515
No assets, textures, or engine features are included.
@@ -83,5 +83,5 @@ vk-bench --headless --frames 300 --out results.json
8383

8484
## Known limitations
8585

86-
- Current Level 0 workload uses transfer-copy command streams to provide stable timing; it does not yet create a swapchain/windowed render path.
86+
- Triangle and million-tris scenes render offscreen (headless-friendly) and do not create a swapchain/windowed present path yet.
8787
- CI can validate build/formatting but not real GPU benchmark values unless run on a self-hosted GPU runner.

docker/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
55
cmake \
66
pkg-config \
77
vulkan-tools \
8+
glslang-tools \
89
&& rm -rf /var/lib/apt/lists/*
910

1011
WORKDIR /workspace
1112
COPY CMakeLists.txt /workspace/CMakeLists.txt
1213
COPY src /workspace/src
1314
COPY include /workspace/include
15+
COPY shaders /workspace/shaders
1416
RUN cmake -S /workspace -B /workspace/build -DCMAKE_BUILD_TYPE=Release \
1517
&& cmake --build /workspace/build --config Release -j"$(nproc)" \
1618
&& install -m 0755 /workspace/build/vk-bench /usr/local/bin/vk-bench

shaders/triangle.frag

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#version 450
2+
3+
layout(location = 0) in vec3 v_color;
4+
layout(location = 0) out vec4 out_color;
5+
6+
void main() {
7+
out_color = vec4(v_color, 1.0);
8+
}

shaders/triangle.vert

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#version 450
2+
3+
vec2 positions[3] = vec2[](
4+
vec2(0.0, -0.5),
5+
vec2(0.5, 0.5),
6+
vec2(-0.5, 0.5)
7+
);
8+
9+
vec3 colors[3] = vec3[](
10+
vec3(1.0, 0.1, 0.1),
11+
vec3(0.1, 1.0, 0.1),
12+
vec3(0.1, 0.2, 1.0)
13+
);
14+
15+
layout(location = 0) out vec3 v_color;
16+
17+
void main() {
18+
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
19+
v_color = colors[gl_VertexIndex];
20+
}

0 commit comments

Comments
 (0)