DirectCompute

Last updated

Microsoft DirectCompute is an application programming interface (API) that supports running compute kernels on general-purpose computing on graphics processing units on Microsoft's Windows Vista, Windows 7 and later versions. DirectCompute is part of the Microsoft DirectX collection of APIs, and was initially released with the DirectX 11 API but runs on graphics processing units that use either DirectX 10 or DirectX 11. [1] The DirectCompute architecture shares a range of computational interfaces with its competitors: OpenCL from Khronos Group, compute shaders in OpenGL, and CUDA from NVIDIA.

Contents

The DirectCompute API brings enhanced multi-threading capabilities to leverage the emerging advanced compute resources. [2] The API is designed for non-graphical applications to access and use GPU resources. [3]

Compute Pipeline

The Compute pipeline is a type of graphics pipeline used for dispatching and executing compute shaders. Compute pipelines are run through compute command lists, which are restricted to recording only copy and compute commands. Compute shaders are used for general-purpose algorithms and computations, and are run through parallel processors on the GPU. This parallel execution model done by the compute pipeline is organized into a dispatch, thread groups, and threads. The dispatch is a 3-dimensional container of thread groups, and a thread group is a 3-dimensional container of threads. [4] [5] Thread groups are ran on the GPU in waves. [6]

This pipeline allows for workloads to be easily sent to the GPU without the need for restructuring all of a program's code. [7]

Example code

The initialization of the compute pipeline involves creating the root signature, reading the compute shader, and creating the pipeline state object.

// Set the root signatureCD3DX12_VERSIONED_ROOT_SIGNATURE_DESCroot_signature_desc{1,root_parameters,0,nullptr};// Serialize the root signatureMicrosoft::WRL::ComPtr<ID3DBlob>root_signature_blob{nullptr};Microsoft::WRL::ComPtr<ID3DBlob>error_blob{nullptr};D3DX12SerializeVersionedRootSignature(&root_signature_desc,D3D_ROOT_SIGNATURE_VERSION_1_1,root_signature_blob.GetAddressOf(),error_blob.GetAddressOf());// Create the root signatureMicrosoft::WRL::ComPtr<ID3D12RootSignature>root_signature{nullptr};device->CreateRootSignature(0,root_signature_blob->GetBufferPointer(),root_signature_blob->GetBufferSize(),IID_PPV_ARGS(root_signature.GetAddressOf()));// Read the compute shaderWindows::WRL::ComPtr<ID3DBlob>compute_shader{nullptr};D3DReadFileToBlob(L"C:/path/to/compute/shader",compute_shader.GetAddressOf());// Create the compute pipeline state object (PSO)structPipelineStateStream{CD3DX12_PIPELINE_STATE_STREAM_ROOT_SIGNATUREroot_signature;CD3DX12_PIPELINE_STATE_STREAM_CScompute_shader;}pipeline_state_stream;// Setting the root signature and the compute shader to the PSOpipeline_state_stream.root_signature=root_signature.Get();pipeline_state_stream.compute_shader=CD3DX12_SHADER_BYTECODE{compute_shader.Get()};D3D12_PIPELINE_STATE_STREAM_DESCpipeline_state_stream_desc{sizeof(PipelineStateStream),&pipeline_state_stream};// Create pipeline statedevice->CreatePipelineState(&pipeline_state_stream_desc,IID_PPV_ARGS(pipeline_state_stream.GetAddressOf()));

After the initialization of the compute pipeline, every frame, the pipeline state must be set, the compute root signature must be set, and the dispatch is run.

command_list->SetPipelineState(pipeline_state);command_list->SetComputeRootSignature(root_signature);command_list->Dispatch(groups_x,groups_y,groups_z);

See also

Further reading

Related Research Articles

<span class="mw-page-title-main">DirectX</span> Collection of multimedia related APIs on Microsoft platforms

Microsoft DirectX is a collection of application programming interfaces (APIs) for handling tasks related to multimedia, especially game programming and video, on Microsoft platforms. Originally, the names of these APIs all began with "Direct", such as Direct3D, DirectDraw, DirectMusic, DirectPlay, DirectSound, and so forth. The name DirectX was coined as a shorthand term for all of these APIs and soon became the name of the collection. When Microsoft later set out to develop a gaming console, the X was used as the basis of the name Xbox to indicate that the console was based on DirectX technology. The X initial has been carried forward in the naming of APIs designed for the Xbox such as XInput and the Cross-platform Audio Creation Tool (XACT), while the DirectX pattern has been continued for Windows APIs such as Direct2D and DirectWrite.

<span class="mw-page-title-main">OpenGL</span> Cross-platform graphics API

OpenGL is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardware-accelerated rendering.

Direct3D is a graphics application programming interface (API) for Microsoft Windows. Part of DirectX, Direct3D is used to render three-dimensional graphics in applications where performance is important, such as games. Direct3D uses hardware acceleration if it is available on the graphics card, allowing for hardware acceleration of the entire 3D rendering pipeline or even only partial acceleration. Direct3D exposes the advanced graphics capabilities of 3D graphics hardware, including Z-buffering, W-buffering, stencil buffering, spatial anti-aliasing, alpha blending, color blending, mipmapping, texture blending, clipping, culling, atmospheric effects, perspective-correct texture mapping, programmable HLSL shaders and effects. Integration with other DirectX technologies enables Direct3D to deliver such features as video mapping, hardware 3D rendering in 2D overlay planes, and even sprites, providing the use of 2D and 3D graphics in interactive media ties.

<span class="mw-page-title-main">High-Level Shader Language</span> Shading language

The High-Level Shader Language or High-Level Shading Language (HLSL) is a proprietary shading language developed by Microsoft for the Direct3D 9 API to augment the shader assembly language, and went on to become the required shading language for the unified shader model of Direct3D 10 and higher.

<span class="mw-page-title-main">Graphics processing unit</span> Specialized electronic circuit; graphics accelerator

A graphics processing unit (GPU) is a specialized electronic circuit initially designed for digital image processing and to accelerate computer graphics, being present either as a discrete video card or embedded on motherboards, mobile phones, personal computers, workstations, and game consoles. After their initial design, GPUs were found to be useful for non-graphic calculations involving embarrassingly parallel problems due to their parallel structure. Other non-graphical uses include the training of neural networks and cryptocurrency mining.

<span class="mw-page-title-main">Shader</span> Type of program in a graphical processing unit (GPU)

In computer graphics, a shader is a computer program that calculates the appropriate levels of light, darkness, and color during the rendering of a 3D scene—a process known as shading. Shaders have evolved to perform a variety of specialized functions in computer graphics special effects and video post-processing, as well as general-purpose computing on graphics processing units.

General-purpose computing on graphics processing units is the use of a graphics processing unit (GPU), which typically handles computation only for computer graphics, to perform computation in applications traditionally handled by the central processing unit (CPU). The use of multiple video cards in one computer, or large numbers of graphics chips, further parallelizes the already parallel nature of graphics processing.

A shading language is a graphics programming language adapted to programming shader effects. Shading languages usually consist of special data types like "vector", "matrix", "color" and "normal".

Windows Display Driver Model is the graphic driver architecture for video card drivers running Microsoft Windows versions beginning with Windows Vista.

<span class="mw-page-title-main">CUDA</span> Parallel computing platform and programming model

In computing, CUDA is a proprietary parallel computing platform and application programming interface (API) that allows software to use certain types of graphics processing units (GPUs) for accelerated general-purpose processing, an approach called general-purpose computing on GPUs (GPGPU). CUDA API and its runtime: The CUDA API is an extension of the C programming language that adds the ability to specify thread-level parallelism in C and also to specify GPU device specific operations. CUDA is a software layer that gives direct access to the GPU's virtual instruction set and parallel computational elements for the execution of compute kernels. In addition to drivers and runtime kernels, the CUDA platform includes compilers, libraries and developer tools to help programmers accelerate their applications.

<span class="mw-page-title-main">Unified shader model</span> GPU whose shading hardware has equal capabilities for all stages of rendering

In the field of 3D computer graphics, the unified shader model refers to a form of shader hardware in a graphical processing unit (GPU) where all of the shader stages in the rendering pipeline have the same capabilities. They can all read textures and buffers, and they use instruction sets that are almost identical.

Graphics Core Next (GCN) is the codename for a series of microarchitectures and an instruction set architecture that were developed by AMD for its GPUs as the successor to its TeraScale microarchitecture. The first product featuring GCN was launched on January 9, 2012.

<span class="mw-page-title-main">Fermi (microarchitecture)</span> GPU microarchitecture by Nvidia

Fermi is the codename for a graphics processing unit (GPU) microarchitecture developed by Nvidia, first released to retail in April 2010, as the successor to the Tesla microarchitecture. It was the primary microarchitecture used in the GeForce 400 series and 500 series. All desktop Fermi GPUs were manufactured in 40nm, mobile Fermi GPUs in 40nm and 28nm. Fermi is the oldest microarchitecture from Nvidia that receives support for Microsoft's rendering API Direct3D 12 feature_level 11.

<span class="mw-page-title-main">Kepler (microarchitecture)</span> GPU microarchitecture by Nvidia

Kepler is the codename for a GPU microarchitecture developed by Nvidia, first introduced at retail in April 2012, as the successor to the Fermi microarchitecture. Kepler was Nvidia's first microarchitecture to focus on energy efficiency. Most GeForce 600 series, most GeForce 700 series, and some GeForce 800M series GPUs were based on Kepler, all manufactured in 28 nm. Kepler found use in the GK20A, the GPU component of the Tegra K1 SoC, and in the Quadro Kxxx series, the Quadro NVS 510, and Tesla computing modules.

<span class="mw-page-title-main">Mantle (API)</span> Low-overhead rendering API

Mantle was a low-overhead rendering API targeted at 3D video games. AMD originally developed Mantle in cooperation with DICE, starting in 2013. Mantle was designed as an alternative to Direct3D and OpenGL, primarily for use on personal computers, although Mantle supports the GPUs present in the PlayStation 4 and in the Xbox One. In 2015, Mantle's public development was suspended and in 2019 completely discontinued, as DirectX 12 and the Mantle-derived Vulkan rose in popularity.

CodeXL was an open-source software development tool suite which included a GPU debugger, a GPU profiler, a CPU profiler, a graphics frame analyzer and a static shader/kernel analyzer.

<span class="mw-page-title-main">Metal (API)</span> iOS, macOS, and tvOS graphics rendering API

Metal is a low-level, low-overhead hardware-accelerated 3D graphic and compute shader API created by Apple, debuting in iOS 8. Metal combines functions similar to OpenGL and OpenCL in one API. It is intended to improve performance by offering low-level access to the GPU hardware for apps on iOS, iPadOS, macOS, and tvOS. It can be compared to low-level APIs on other platforms such as Vulkan and DirectX 12.

Vulkan is a low-level, low-overhead cross-platform API and open standard for 3D graphics and computing. It was intended to address the shortcomings of OpenGL, and allow developers more control over the GPU. It is designed to support a wide variety of GPUs, CPUs and operating systems, and it is also designed to work with modern multi-core CPUs.

<span class="mw-page-title-main">GPUOpen</span> Middleware software suite

GPUOpen is a middleware software suite originally developed by AMD's Radeon Technologies Group that offers advanced visual effects for computer games. It was released in 2016. GPUOpen serves as an alternative to, and a direct competitor of Nvidia GameWorks. GPUOpen is similar to GameWorks in that it encompasses several different graphics technologies as its main components that were previously independent and separate from one another. However, GPUOpen is partially open source software, unlike GameWorks which is proprietary and closed.

DirectX Raytracing (DXR) is a feature introduced in Microsoft's DirectX 12 that implements ray tracing, for video graphic rendering. DXR was released with the Windows 10 October update on October 10, 2018. It requires an AMD Radeon RX 6000 series, AMD Radeon RX 7000 series, Intel Arc A series, or Nvidia GeForce 20, 30, or 40 series video card, which is designed to handle the high computing load used for ray tracing.

References

  1. "DirectCompute". developer.nvidia.com. NVIDIA. 28 September 2010. Retrieved 22 March 2015.
  2. James, Dave; Chiapetta, Marco. "The Directx Evolution" (PDF). Maximum PC. 19 (8): 52–59. ISSN   1522-4279 . Retrieved 2024-08-07 via MasterFILE Complete.{{cite journal}}: CS1 maint: url-status (link)
  3. Mohr, Neil. "Beyond Graphics with Gpgpus: Maximum PC". Maximum PC: 46–51. ISSN   1522-4279 via MasterFILE Complete.
  4. Young, Eric (2010-09-20). "DirectCompute - Optimizations and Best Practices" (PDF). Retrieved 2024-02-14.
  5. Kramer, Lou (2022-07-22). "Compute Shaders" (PDF). gpuopen. Retrieved 2024-03-11.
  6. Lively, David; Gruen, Holger (2017-03-03). "Wave Programming in D3D12 and Vulkan" (PDF). gpuopen. Retrieved 2024-02-15.
  7. Graham-Smith, Darien (September 2021). "The Return of GPU Computing". PCPro (323): 44–47. ISSN   1355-4603 . Retrieved 2024-06-10 via MasterFILE Complete.