tips and experience of dx12 engine development

Click here to load reader

Upload: yeong-cheon-you

Post on 20-Feb-2017

560 views

Category:

Software


1 download

TRANSCRIPT

PowerPoint

DirectX 12 Microsoft MVPVisual Studio and Development Technologies

Twitter: @dgtmanBlog : http://megayuchi.wordpress.com

DirectX?MS Graphics API Windows API OpenGL . Windows 100% XBOX, Wndows Phone DirectX DX9 >>>> DX11 >> DX12

DirectX 12?DirectX 12 == Direct 3D12Direct 2D, Direct Write .D3D D3D11 on D3D12 .

!CPU . GPU .. . ?

CPU ->Draw Call -> GPU . State ->OMSetRSSetPSSetVSSet -> ID3D12PipenlineState .DirectX runtime Application . ..-_-;;;;;;;;

.

DirectX 9/11 DirectX 12 F1. .

DirectX 9/11 ?(implicit) DirectX runtime . . GPU .Single-Thread GPU 100% runtime Driver .

DirectX 12 .

DirectX 12 ? 120 DX12 .

Multi-Thread .GPU .45 60 .

DirectX 9/11 -> DirectX 12Resource BindingCommand List & Command QueueState -> ID3D12PipelineStateShader .D3DX? DirectXTex? -> . . .-_-

Resource BindingDX9/11 > DX12 ( 500 )

Resource BindingVertex BufferIndex BufferTextureConstant BufferUnorderd Acceess Buffer (for Compute Shader)Sampler

Resource Graphics Pipeline bind.

Buffer ID3D12Resource , D3D CPU/GPU .CBV Constant Buffer View Buffer ConstantBuffer Shader .SRV Shader Resource ViewBuffer Texture Shader .UAV Unordered Access ViewBuffer Compute Shader read/write

DescriptorResource CBV,SRV,UAV Descriptor .Texture(SRV), Constant Buffer(CBV)32-64bytes .(GPU .) . . GPU Memory, CPU Memory pair .D3D12_GPU_DESCRIPTOR_HANDLE, D3D12_CPU_DESCRIPTOR_HANDLE .

Descriptor HeapDescriptor MemoryID3D12DescriptorHeap .CPU , GPU pair .CBV,SRV Descriptor Heap CPU/GPU (write).Descriptor Heap CPU write, Shader GPU read.

Root Signature ID3D12RootSignature(Texture, Contant Buffer, Sampler) Resource Pipeline bind Resource binding .

Descriptor TableDescriptor Descriptor Heap Descriptor Table .

TR MatrixBones MatrixLight CubeShadow MapmaterialdiffusemasktoonpCommandList->SetGraphicsRootDescriptorTable(0, gpuHeap);pCommandList->SetGraphicsRootDescriptorTable(1, gpuHeap);FaceGroup 0

materialdiffusemasktoonpCommandList->SetGraphicsRootDescriptorTable(1, gpuHeap);FaceGroup 1

materialdiffusemasktoonpCommandList->SetGraphicsRootDescriptorTable(1, gpuHeap);FaceGroup 2

CD3DX12_DESCRIPTOR_RANGE rangesPerObj[3];rangesPerObj[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 2, 0);// b0 : default , b1 : bonesrangesPerObj[1].Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 5);// b5 : Light CuberangesPerObj[2].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 3);// t3 : shadow CD3DX12_DESCRIPTOR_RANGE rangesPerFacegroup[2];rangesPerFacegroup[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 2);// b2 : materialrangesPerFacegroup[1].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 3, 0);// t0 : diffuse , t1 : mask , t2 : toon table

CD3DX12_ROOT_PARAMETER rootParameters[2];rootParameters[0].InitAsDescriptorTable(_countof(rangesPerObj), rangesPerObj, D3D12_SHADER_VISIBILITY_ALL);rootParameters[1].InitAsDescriptorTable(_countof(rangesPerFacegroup), rangesPerFacegroup, D3D12_SHADER_VISIBILITY_ALL);TR MatrixBones MatrixLight CubeShadow Mapmaterialdiffusemaskb0b1b5et3b2t0t1toont201234567Shader RegisterDescriptor TableDescriptor HeapRoot Parameter 0Root Parameter 1

Yeong-Cheon You (YY) -

TR MatrixBones MatrixLight CubeShadow MapmaterialdiffusemasktoonDescriptor Heapmaterialdiffusemasktoonmaterialdiffusemasktoon0123456789101112131415 Descriptor : 16

D3D12_GPU_DESCRIPTOR_HANDLE gpuHeap = pDescriptorHeap->GetGPUDescriptorHandleForHeapStart();pCommandList->IASetVertexBuffer();pCommandList->SetGraphicsRootDescriptorTable(0, gpuHeap);for (i=0; iSetGraphicsRootDescriptorTable(1, gpuHeap);pCommandList->IASetIndexBuffer(); pCommandList->DrawIndexedInstanced();gpuHeap.Offset(4, DescriptorSize);

}Object Face Group 0Face Group 1Face Group 2

Command List & Command Queue Graphics Command Command List RecordingCommand Queue . ( GPU Queue )1 Command List . -> Command List recording Execute .

Command List 0Command QueueClear RTVSetRTVSetPSODrawCommand QueueCommand List 1Clear RTVSetRTVSetPSODrawClear RTVSetRTVSetPSODrawClear RTVSetRTVSetPSODraw

Execute()Execute()Thread 1Thread 0GPU Hardware queue

21

Pipeline State ID3D12PipelineStateBlend StateDepth StateRender Target formatShaders

.

Shader , Blend ID3D12PipelineState .Shader Pipeline State !

Pipeline State

DX12

Debugging

Debugging API . DX12 runtime . GPU . (99%) . .

D3D12 Debug Layer , Resource Barrier . .

ID3D12Debug*pDebugController = NULL;

// Enable the D3D12 debug layer.if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&pDebugController)))){pDebugController->EnableDebugLayer();}

exe app Error Warning .

DirectX Control Panel

Visual Studio Graphics Debugger .Pipeline D3DResouce .Descriptor Table . .ALT+F5 .

Shadow map ( https://goo.gl/nC5f80 )

Shadow map ( https://goo.gl/nC5f80 )

Optimization

D3D11 ? . D3D11 . D3D12 D3D11 . .. -> .

GPUViewMircrosoft ADK Performance Toolkit ADKAdmin CMD C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\gpuview >Log.cmd logging Log.cmd loggingMerged.etl GPUView

GPUView D3D11 vs D3D12

DirectX 11 , !!!Single-Thread Rendering GPU Memory (avoid Map, Unmap) D3DResource . -> DX11 Resource Renaming DX11 GPU Queue .

?CPU -> Draw Call -> GPU . . Command List Execute . Command List Command Execute ? GPU . Command List Command Execute .Command List Execute Multi-Thread Rendering .

From Direct3D 12 API Preview in Build 2014D3D12 runtime CPU .

D3D12 runtime CPU . GPU D3D12 .GPU H/W Queue .

Execute Execute() GPU H/W Queue CommandD3D11 Execute() present() . Present GPU -_-;;;;;

Command List Pooling Command List .Command List N Command .N Execute(), Command List Command . Command List .

Command List Pooling . .

Multi-Thread RenderingMulti-Thread Command . n 4 thread n/4 .GPU Queue empty .

D3D12 Multi-Thread Rendering

From Approaching Minimum Overhead with Direct3D12 NVIDIA

Multi-Thread Rendering 1 Command List Queue Command List Command Execute()

Multi-Thread Rendering Thread 0Command ListObj 0Obj 1Obj 23Obj 24...Thread 1Command ListObj 25Obj 26Obj 48Obj 49...Thread 2Command ListObj 50Obj 51Obj 73Obj 74...Thread 3Command ListObj 75Obj 76Obj 98Obj 99...Command Queue

Execute()Execute()Execute()Execute()

1 Threads

Present

Present

8 Threads

Present

Present

Res. 3000x2000D3D11D3D1210 Characters25 fps28 fps11%100 Characters16 fps19 fps16%

( .. .)@Surface Book i5 nvidia dGPU

Demo

D3D12 11 .45 60 . 10% - 30%. API D3D12 .DirectX Runtime, Driver .D3D12 API .

FAQDirectX 12 OS ?Windows 10 PC, XBOX ONE, Windows 10 Mobile (Snapdragon 808 , Lumia950/950XL)Direct Write Direct2D .D3D11 on D2D . D3D12 API Thread-safe?. Thread-safe. lock .

Referenceyuchi dev D3D tagApproaching Minimum Overhead with Direct3D12Direct3D 12 APIPreviewEfficient Rendering with DirectX 12 on Intel GraphicsDIRECTX ADVANCEMENTS IN THE MANY CORE ERA Getting the most out of the PC Platform Using GPUView to Understand your DirectX 11 Game