File(s): | Download (Intel Software GitHub*) |
License: | Intel Sample Source Code License Agreement |
Optimized for... | |
---|---|
Operating System: | Windows® 10 (64 bit) |
Hardware: | GPU required |
Software: (Programming Language, tool, IDE, Framework) |
Microsoft Visual Studio* 2017, Unreal Engine* 4, C# |
Prerequisites: |
Familiarity with Microsoft Visual Studio, Unreal Engine API, 3D graphics, parallel processing. |
Introduction
Parallel processing has become one of the most important aspects of today's programming techniques. The shift in paradigm forced by the CPU's hitting the power wall enforced programming techniques that emphasize spreading computations over multiple cores/processors. As it turns out, many of the computation tasks that software developers face are parallelizable. One example is the case of modeling particle systems. Such systems are widely used in many fields from physical simulation to computer games.
The Vulkan* API is a collaborative effort by the industry to meet current demands of computer graphics. It is a new approach that emphasizes hiding the CPU bottleneck through parallelism, and allowing much more flexibility in application structure. Aside from components related only to graphics, the Vulkan API also defines the compute pipeline for numerical computation.
This code and accompanying article (see References below) discuss and compare aspects of the implementation of a particle system using CPU and GPU using a Vulkan-based renderer as an example. We recommend that you read the article while looking at the code. Make sure you have the examples downloaded and use your favorite code browsing tool.
The code demonstrates the following concepts:
- Vulkan renderer for CPU based simulator
- CPU-based particle simulator
- Multithreaded approach to computing particle system
- Vulkan compute in a modeling particle system
The code is organized to emphasize architectural concepts, as such, it makes two important assumptions: 1) the return status from Vulkan function calls is in most cases ignored to keep the code base as simple as possible. In production, every return status should be checked and reacted on; 2) conceptually close topics are kept within a single code flow. This reduces the need for jumping through the sources, but sometimes leads to rather long functions.
Get Started
Vulkan* renderer for CPU based simulator
At a high level, when programming using Vulkan, the goal is to construct a virtual device to which drawing commands will be submitted. The draw commands are submitted to constructs called “queues”. The number of queues available and their capabilities depend upon how they were selected during construction of the virtual device, and the actual capabilities of the hardware. The power of Vulkan lies in the fact that the workload submitted to queues could be assembled and sent in parallel to already executing tasks. Vulkan offers functionality to coherently maintain the resources and perform synchronization.
In our application, we took the approach of breaking up the Vulkan renderer setup into five components, with the intent of presenting an easy to understand codebase.
- Device
- AppInstance
- SurfaceWindows
- Scene
- ParticlesElement
CPU-based particle simulator
The next section describes the model of particle simulator that was implemented for this project. The implementation is based on a real-time infinite loop. The simulation loop contains three main operations:
- Obtain the time difference between the current and previous iteration (CPU_TP23)
- Compute the next Euler iteration for the particle model (CPU_TP24)
- Upload and render a new frame using the Vulkan renderer (CPU_TP25
These are described in detail in the article.
Multithreaded approach to computing particle system
This section covers various approaches to improving performance by parallelizing the workload. The code demonstrates application of the recommended choice.
Vulkan compute in a modeling particle system
Performance can further be improved by shifting the work to the GPU. This section, addresses the topic of porting a CPU-based particle simulator onto the GPU using Vulkan compute. Vulkan compute is an integral part of the Vulkan API. Although most of the simulation will be moved onto the GPU, the sorting and generation of particles will be still kept on the CPU. The goal of this section is to present how to set-up the compute pipeline, instantiate more advanced shader input constructs, and show how to send frequently changing, but small, portions of data onto the GPU without using memory mapping.
Tutorial
Tomasz Chadzynski, Integrated Computing Solutions, Inc., Parallel Techniques in Modeling Particle Systems Using Vulkan API, 2017
Updated Log
Created March 20, 2018