C++AMP accelerated collision detection (WINRT)

I was very upset when I had to remove this part of book during the page counts. Honestly, writing about all new features of DirectX 11.1 in just 146 pages was really hard, especially when the target audiences of our book were armatures and professionals.

In chapter 5 of DirectX 11.1 Game Programming book, I explained, what is C++AMP technology and how and when we can use it in our application, but for those  who have’t read the book yet and unfamiliar with C++AMP technology, I going to demonstrate it in short sentences.

C++ Amp or C++ Accelerated Massive Parallelism is a small extension library that enables heterogeneous computing, which brings “GPGPU” programming for developers by taking advantage of GPU.  C++ AMP fairly looked like an extension. It is C++, not C, and is used for implementing data parallelism directly in C++, it also integrated with direct3D for accelerating your code, if the code cannot be run on GPUs, it will fall back onto CPUs.

For getting more information about C++AMP, please check see this link out.

The Prerequisites

The following are some essential prerequisites that should be considered before developing an application using DirectX 11.2:

  • The first important requirement is a personal computer or tablet running on Windows 8.1.
  • You need to set up Microsoft Visual Studio Express 2013 for Windows 8.1 as a developer environment.
  • Make sure you set up the Windows Software Development Kit (SDK) for Windows 8.1. The Windows SDK for Windows 8.1 contains headers, libraries, and tools that can be used when creating Windows 8.1 applications.
  • Download the source code of this project which uploaded by me on MSDN Code Gallery.

In Chapter 05 of DirectX 11.1 Game Programming, my main concern was that C++AMP & Compute Shader results in good gains. Also I compare performances of both on Windows Store app. We learned how & when we must each technology.

Now let’s assume some collision detection on C++AMP:

  • The data is on the CPU, so it has to be transferred to the GPU, if GPU is not available it has to fall back on the CPU.
  • The commands will be queued in the GPU queue, and will be processed asynchronously, so it might take a full frame until the results are available.
  • The results have to be transferred back to the CPU

In this case, the GPU can process the collisions faster than CPU, but transferring data back to the CPU might obtain bottleneck of your application. The results on CPU might be more quickly if you have a spare thread to do the computations, so make sure run your code on GPU when you think it is really the efficient way.

In this section, we are going to extend our collision detection with C++Amp, which means we can check more collision detection in one frame. We want to check collision between player’s spaceship and other spaceships, if collision happened, then player must go back to initial position.

Open “manager.cpp” from “Graphics\cpp” folder of the solution. Make sure get the project and source codes from here. Let’s take a look at the UpdateModels method of this class.

When collision happened, we’ve reset the position of the player’s spaceship. the following image shows the result of project.

DirectX 11.1 Game Programming | C++AMP accelerated collision detection

More Information

For getting more samples about C++AMP,  make sure check this link.

This is the final article of DirectX 11.1 Game Programming in 2013. Happy New Year 😉

One thought on “C++AMP accelerated collision detection (WINRT)”

Leave a Reply

Your email address will not be published. Required fields are marked *