Use Direct3D 12 Compute Shader in C (Basic)
This is a simple sample that describes how to use Direct3D 12 compute shader in the C programming language. Why C? Because the C-style COM APIs for Direct3D 12 contain no magical wrappers, it will fully demonstrate the whole process in detail without concealment.
The function of this sample is very simple. It calculates the sum of each int
element in the source buffer with 10, and stores the result to the corresponding location in the destination buffer.
The genenral process is as follows:
- Initialize all the necessary assets.
- Initialize the command list and the command queue
- Create the source buffer object and the destination buffer object.
- Do the compute operation and fetch the result.
- Release all the resources.
The demo project is built with Visual Studio 2022 community. Before you start, you may have to do the following stuffs.
- Ensure that Visual Studio 2022 (Community) has been installed.
- Ensure that Windows Kits for Windows 10 with DirectX 12 SDK have been installed. This can be installed with Visual Studio Installer.
- Now, you can open the solution file (.sln) in this sample and check the directory in which DirectX 12 SDK was installed.