Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

DirectCompute

From Wikipedia, the free encyclopedia
Application programming interface from Microsoft

Microsoft DirectCompute is anapplication programming interface (API) that supports runningcompute kernels ongeneral-purpose computing on graphics processing units on Microsoft'sWindows Vista,Windows 7 and later versions. DirectCompute is part of theMicrosoft DirectX collection of APIs, and was initially released with theDirectX 11 API but runs on graphics processing units that use eitherDirectX 10 or DirectX 11.[1] The DirectCompute architecture shares a range of computational interfaces with its competitors:OpenCL fromKhronos Group, compute shaders inOpenGL, andCUDA fromNVIDIA.

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 useGPU resources.[3]

Compute Pipeline

[edit]

The Compute pipeline is a type ofgraphics pipeline used for dispatching and executing computeshaders. Compute pipelines are run through computecommand 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 parallelprocessors on the GPU. This parallel execution model done by the compute pipeline is organized into a dispatch, thread groups, andthreads. The dispatch is a 3-dimensional container of thread groups, and a thread group is a 3-dimensional container of threads.[4] Thread groups are ran on the GPU inwaves.[5]

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

A typical compute pipeline contains a read-only shader resource view as an input, constant buffer views for additional resource constants, and an unordered access view for an output. It is important to set the resource states of these resources in order to improve performance.[7]

Example code

[edit]

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

[edit]

Further reading

[edit]

References

[edit]
  1. ^"DirectCompute".developer.nvidia.com.NVIDIA. 28 September 2010. Retrieved22 March 2015.
  2. ^James, Dave; Chiapetta, Marco."The Directx Evolution"(PDF).Maximum PC.19 (8):52–59.ISSN 1522-4279. Retrieved2024-08-07 – via MasterFILE Complete.
  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). Retrieved2024-02-14.
  5. ^Lively, David; Gruen, Holger (2017-03-03)."Wave Programming in D3D12 and Vulkan"(PDF).gpuopen. Retrieved2024-02-15.
  6. ^Graham-Smith, Darien (September 2021)."The Return of GPU Computing".PCPro (323):44–47.ISSN 1355-4603. Retrieved2024-06-10 – via MasterFILE Complete.
  7. ^Kramer, Lou (2022-07-22)."Compute Shaders"(PDF).gpuopen. Retrieved2024-03-11.

External links

[edit]
Management
tools
Apps
Shell
Services
File systems
Server
Architecture
Security
Compatibility
API
Games
Discontinued
Games
Apps
Others
Spun off to
Microsoft Store
Microsoft development tools
Development
environments
Visual Studio
Others
Languages
APIs and
frameworks
Native
.NET
Device drivers
Database
SQL Server
SQL services
Other
Source control
Testing and
debugging
Delivery
Graphics and UI
Audio
Multimedia
Web
Data access
Networking
Communication
Administration and
management
Component model
Libraries
Device drivers
Security
.NET
Software factories
IPC
Accessibility
Text and multilingual
support
Stub icon

This article related toMicrosoft is astub. You can help Wikipedia byadding missing information.

Retrieved from "https://en.wikipedia.org/w/index.php?title=DirectCompute&oldid=1277521706"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp