DirectX 12 - From Leonardo da Vinci to Contemporary Art

Computer graphics is an extensive and rapidly developing discipline. Every year, application programming interfaces become more flexible, which allows them to implement more complex image formation and processing algorithms. However, the possibilities of interactive graphics have not reached the level of 3d modeling and visualization packages. All this encourages active research in this area.


image


DirectX 12 is a component of the high-performance graphics programming interface. The main goals of the new interface are to reduce the CPU overhead of the driver, lower the level of hardware abstraction, the ability to combine graphics cards at the API level (before that there were only vender-specific CrossFireX, NVIDIA SLI solutions). Officially released by Microsoft in July 2015.


The article is intended for those who have already worked with graphic libraries (OpenGL, DirectX 11). However, for people who plan to start studying graphics with version 12, it may also be useful.


In it, we will consider the following topics:


  • Environment
  • Brief description of the graphic pipeline
  • New DirectX 12 features
    1. States
    2. Teams
    3. Synchronization
    4. Resource Attachment

Environment


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.



We examined some of the features of DirectX 12. If you are interested in this topic or any other area of ​​computer graphics, unsubscribe in the comments.


Links:
https://docs.microsoft.com/en-us/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