DirectX 12-从达芬奇到当代艺术

计算机图形学是一门广泛而迅速发展的学科。每年,应用程序编程接口变得更加灵活,这使它们可以实现更复杂的图像形成和处理算法。但是,交互式图形的可能性尚未达到3D建模和可视化程序包的水平。所有这些都鼓励该领域的积极研究。


图片


DirectX 12是高性能图形编程界面的组件。新界面的主要目标是减少驱动程序的CPU开销,降低硬件抽象级别,在API级别组合图形卡的能力(在此之前,仅供应商专用的CrossFireX,NVIDIA SLI解决方案)。由Microsoft在2015年7月正式发布。


本文适用于已经使用图形库(OpenGL,DirectX 11)的用户。但是,对于计划从版本12开始学习图形的人来说,它可能也很有用。


在其中,我们将考虑以下主题:


  • 环境
  • 图形管道的简要说明
  • DirectX 12的新功能
    1. 状态
    2. 队伍
    3. 同步化
    4. 资源附件

环境


DirectX 12 Windows SDK Windows 10. IDE Visual Studio, C++. DirectX, d3d12.h dxgi1_6.h d3d12.lib, dxguid.lib, dxgi.lib, d3dcompiler.lib. Windows SDK. "D3D12 Helper Library" d3dx12.h, boilerplate . d3dx12.h .



, — - . , — . , . . , , . , — , .


, .



, , , , , , . — . , . , , , , . . — (clip space).



— , . . , . , . . ( ). API. , , .



, , , , . .



, (scissor test), (stencil test) (depth test). , . - , . , , . , .


DirectX 11 ( DiretcX 12 )


DirectX 12


DirectX 12.



11 : RSSetState(), OMSetDepthStencilState(), OMSetBlendState(). , . , . , — PSO (Pipeline State Object). : " ", . , , Root Signature ( ).



immideate context. . , DirectX 11 deferred context. DirectX 12 immideate context deferred . deferred command list, .


, : command list, , CPU .


, . , GPU, . , Release() — , .



GPU, DirectX 12 fence, ID3D12Fence . Fence — , GPU . «» , ID3D12CommandQueue::Signal() . ID3D12Fence::SetEventOnCompletion(UINT64 Value, HANDLE hEvent) winapi event. WaitForSingleObject() event- , . GPU , fence , WaitForSingleObject() .



— DirectX.



DirectX 11 : API. , ( ) 5 6 :


ID3D11ShaderResourceView* srvs[] = { 
    texture1->GetShaderResourceView();
    texture2->GetShaderResourceView();
};
context->PSSetShaderResources(5, 2, srvs);

GetShaderResourceView() ID3D11ShaderResourceView.
:


Texture2D texture1 : register(t5);
Texture2D texture2 : register(t6);

, . , . ? GCN ISA, :


All vector memory operations use an image resource constant (T#) that is a 128- or 256-bit value in SGPRs. This constant is sent to the texture cache when the instruction is executed. This constant defines the address, data format, and characteristics of the surface in memory.

, , (128 256-), . , , . , , «» . : (T#), (S#) (V#). Direct3D 12 , , — GPU.



, . — , (GPU , , , , ). . :


  • Constant buffer views (CBVs)
  • Unordered access views (UAVs)
  • Shader resource views (SRVs)
  • Samplers

CBVs, UAVs, SRVs , — . , .


shader visible . , non shader visible :


  • Render Target Views (RTVs)
  • Depth Stencil Views (DSVs)
  • Stream Output Views (SOVs)

views ( ), non shader visible ( D3D12_DESCRIPTOR_HEAP_FLAGS::D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE ).


view's, (, , ) :


  • Index Buffer View (IBV)
  • Vertex Buffer View (VBV)

D3D12_INDEX_BUFFER_VIEW D3D12_VERTEX_BUFFER_VIEW . Pipeline State Object. PSO .


, ID3D11...View, .


Root signature


Root signature — DirectX 12 API . , , . Root signature , () , .


Root signature , root parameter. root parameter root arguments. root argument, . Root parameter :


  • Root constants (1 DWORD == 32bit value)
  • Inline descriptors ( 64-bit GPU virtual addresses, 2 DWORDs )
  • (1 DWORD)

root signature — 64 DWORDs. , .


Root constant root signature 32- , constant buffer. (, MVP ), ( 4 ). , . : " ".


root signature inline descriptors. — per object. , . . ( ), GPU. , , ID3D12GraphicsCommandList::SetGraphicsRootConstantBufferView, root parameter inline descriptor .


, . descriptor range. Descriptor range — . :


typedef enum D3D12_DESCRIPTOR_RANGE_TYPE
    {
        D3D12_DESCRIPTOR_RANGE_TYPE_SRV = 0,
        D3D12_DESCRIPTOR_RANGE_TYPE_UAV = ( D3D12_DESCRIPTOR_RANGE_TYPE_SRV + 1 ) ,
        D3D12_DESCRIPTOR_RANGE_TYPE_CBV = ( D3D12_DESCRIPTOR_RANGE_TYPE_UAV + 1 ) ,
        D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER = ( D3D12_DESCRIPTOR_RANGE_TYPE_CBV + 1 ) 
    }   D3D12_DESCRIPTOR_RANGE_TYPE;

typedef struct D3D12_DESCRIPTOR_RANGE
    {
    D3D12_DESCRIPTOR_RANGE_TYPE RangeType;
    UINT NumDescriptors;
    UINT BaseShaderRegister;
//...
    }   D3D12_DESCRIPTOR_RANGE;

, RangeType — , NumDescriptors — , BaseShaderRegister — . . ID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable, root parameter . , , . , descriptor heap.



我们检查了DirectX 12的某些功能。如果您对本主题或计算机图形学的任何其他领域感兴趣,请在评论中退订。


链接:https:
//docs.microsoft.com/zh-cn/windows/win32/direct3d12/directx-12-programming-guide
https://developer.nvidia.com/dx12-dos-and-donts
https:// // gpuopen.com/performance-root-signature-descriptor-sets/


All Articles