Skip to content

Commit e3321a5

Browse files
authored
add an N-body vulkan sharing sample (#67)
* first working version * simplified * vulkan nbody runs with no validation errors and first frame output * added one vertex buffer per swapchain image * copies are working through the host * external memory is working * remove unneeded GLU dependency * update GitHub actions checkout to v3 * added external memory and semaphore support * minor dma_buf fixes * add an option to require linear images * add an OpenGL CMake default if one is not provided explicitly * update READMEs
1 parent c7a55b0 commit e3321a5

17 files changed

Lines changed: 2284 additions & 20 deletions

File tree

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
check:
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v3
1919

2020
- name: Check Tabs
2121
run: |
@@ -36,7 +36,7 @@ jobs:
3636
runs-on: ${{matrix.os}}
3737

3838
steps:
39-
- uses: actions/checkout@v2
39+
- uses: actions/checkout@v3
4040

4141
- name: Get Ubuntu OpenGL Dependencies
4242
if: matrix.os == 'ubuntu-latest'
@@ -45,20 +45,20 @@ jobs:
4545
sudo apt-get install -y libglfw3-dev
4646
4747
- name: Get OpenCL Headers
48-
uses: actions/checkout@main
48+
uses: actions/checkout@v3
4949
with:
5050
repository: KhronosGroup/OpenCL-Headers
5151
path: external/OpenCL-Headers
5252

5353
- name: Get OpenCL ICD Loader
54-
uses: actions/checkout@main
54+
uses: actions/checkout@v3
5555
with:
5656
repository: KhronosGroup/OpenCL-ICD-Loader
5757
path: external/opencl-icd-loader
5858

5959
- name: Get OpenCL Extension Loader
6060
if: matrix.ext == 'YES'
61-
uses: actions/checkout@master
61+
uses: actions/checkout@v3
6262
with:
6363
repository: bashbaug/opencl-extension-loader
6464
path: external/opencl-extension-loader
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2022 Ben Ashbaugh
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in all
11+
# copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
add_opencl_sample(
22+
NUMBER 01
23+
TARGET nbodygl
24+
VERSION 120
25+
CATEGORY opengl
26+
SOURCES main.cpp
27+
INCLUDES ${OPENGL_INCLUDE_DIRS}
28+
LIBS ${OPENGL_LIBRARIES} glfw)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# N-Body Simulation with OpenGL
2+
3+
## Sample Purpose
4+
5+
This sample uses OpenCL to compute an [N-body simulation](https://en.wikipedia.org/wiki/N-body_simulation), which is then rendered with OpenGL.
6+
7+
This sample currently does not share the OpenCL buffer with OpenGL and will unconditionally copy from OpenCL to OpenGL on the host.
8+
It is most useful as a reference for the similar Vulkan sample.
9+
10+
## Key APIs and Concepts
11+
12+
This example shows how to copy from an OpenCL buffer to OpenGL.
13+
14+
## Command Line Options
15+
16+
| Option | Default Value | Description |
17+
|:--|:-:|:--|
18+
| `-d <index>` | 0 | Specify the index of the OpenCL device in the platform to execute on the sample on.
19+
| `-p <index>` | 0 | Specify the index of the OpenCL platform to execute the sample on.
20+
| `-n` | 1024 | Specify the number of bodies to simulate.
21+
| `-g` | 0| Specify the local work size. If the local works size is zero a `NULL` local work size is used.
22+
| `-w` | 1024 | Specify the render width in pixels.
23+
| `-h` | 1024 | Specify the render height in pixels.
24+
25+
## Controls While Running
26+
27+
| Control | Description |
28+
|:--|:--|
29+
| `Escape` | Exits from the sample.
30+
| `Space` | Toggle animation (default: `false`).
31+
| `S` | Single-step the simulation.
32+
| `R` | Re-initialize the simulation.
33+
| `V` | Toggle vsync (default: `true`). Disabling vsync may increase framerate but may cause [screen tearing](https://en.wikipedia.org/wiki/Screen_tearing).

0 commit comments

Comments
 (0)