explicit directx12 multi gpu rendering...lightweight api multithreading needed in vr for...

73
1 FEBRUARY 2017 | EXPLICIT MGPU | Explicit DirectX12 Multi GPU rendering

Upload: others

Post on 09-Nov-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

1 FEBRUARY 2017 | EXPLICIT MGPU |

Explicit DirectX12 Multi GPU rendering

Page 2: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

2 FEBRUARY 2017 | EXPLICIT MGPU |

AGENDA

▶ Intro/Motivation

▶ API introduction

▶ Adding MGPU support (AFR)

▶ Tools of the trade

▶ Case study, Ashes Of The Singularity

By Dan Baker

EXPLICIT MGPU IN DIRECTX12

Page 3: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

3 FEBRUARY 2017 | EXPLICIT MGPU | OCTOBER 2016 | POLARIS MGPU UPDATE | 3

WHAT IS EXPLICIT MGPU?

▶ 2+ GPUs

▶ Sharing a bus (16GB/s)

▶ Synchronization up to the user

EXPLICIT MGPU IN DIRECTX12

Page 4: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

4 FEBRUARY 2017 | EXPLICIT MGPU | OCTOBER 2016 | POLARIS MGPU UPDATE | 4

WHAT IS EXPLICIT MGPU?

▶ 800 GPUs

▶ Sharing a bus (16GB/s bidirectional)

▶ Synchronization up to the user

EXPLICIT MGPU IN DIRECTX12

Page 5: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

5 FEBRUARY 2017 | EXPLICIT MGPU | OCTOBER 2016 | POLARIS MGPU UPDATE | 5

WHAT IS EXPLICIT MGPU?

▶ 800 GPUs

▶ Sharing a bus (1Mb/s)

▶ Synchronization up to the user

EXPLICIT MGPU IN DIRECTX12

Page 6: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

6 FEBRUARY 2017 | EXPLICIT MGPU |

YOU ARE ALREADY DOING IT

EXPLICIT MGPU IN DIRECTX12

Page 7: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

7 FEBRUARY 2017 | EXPLICIT MGPU |

MGPU IN DX11

▶ Black box

▶ Heavy weight API (and driver)

▶ DX11 is single threaded

EXPLICIT MGPU IN DIRECTX12

Page 8: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

8 FEBRUARY 2017 | EXPLICIT MGPU |

MGPU IN DX12 – WHY NOW?

▶ Explicit = full control

▶ Lightweight API

▶ Multithreading

▶ Needed in VR for one-GPU-per-eye configurations

EXPLICIT MGPU IN DIRECTX12

Page 9: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

9 FEBRUARY 2017 | EXPLICIT MGPU |

1.7X

2X

Radeon RX 480(8GB)

GTX 1080 FE

Radeon RX 480

CrossFire™

1.7X

1.8X

Radeon RX 480(8GB)

GTX 1080 FE

Radeon RX 480

CrossFire™

Incredible Performance gains in DirectX® 12

9

* Tested at 1440p. See Endnotes for details. Use of third party marks/products is for informational purposes and no endorsement of or by AMD is

implied

OCTOBER 2016 | POLARIS MGPU UPDATE |

1.8X

2X

Radeon RX 480(8GB)

GTX 1080 FE

Radeon RX 480

CrossFire™

*High Pr eset *Ultr a Preset*Offic ial Pr eset

Page 10: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

10 FEBRUARY 2017 | EXPLICIT MGPU |

MGPU MODES

▶ Linked Identical GPUs,

Enable in control panel

Optimal sharing of resources

▶ Unlinked Different type and vendor GPUs

Resources shared through the system memory

EXPLICIT MGPU IN DIRECTX12

Page 11: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

11 FEBRUARY 2017 | EXPLICIT MGPU |

ENABLING LINKED MODE

EXPLICIT MGPU IN DIRECTX12

Page 12: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

12 FEBRUARY 2017 | EXPLICIT MGPU |

MGPU THE EASY WAY

▶ Typical rendering loop:

EXPLICIT MGPU IN DIRECTX12

1 | Engine myengine1;2 |3 | myengine1.LoadResources(device);4 |5 |6 | for(;;)7 | {8 | myengine1.Render();9 | Present();

10 |11 |12 | }

Page 13: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

13 FEBRUARY 2017 | EXPLICIT MGPU |

MGPU THE EASY WAY

▶ Typical rendering loop:

EXPLICIT MGPU IN DIRECTX12

1 | Engine myengine1, myengine2; 2 |3 | myengine1.LoadResources(device1);4 | myengine2.LoadResources(device2);5 |6 | for(;;)7 | {8 | myengine1.Render();9 | present();

10 | myengine2.Render();11 | present();12 | }

Page 14: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

14 FEBRUARY 2017 | EXPLICIT MGPU |

ADDRESSING GPUS

▶ Typical rendering loop:

EXPLICIT MGPU IN DIRECTX12

1 | Engine myengine1, myengine2; 2 |3 | myengine1.LoadResources(node1);4 | myengine2.LoadResources(node2);5 |6 | for(;;)7 | {8 | myengine1.Render();9 | present();

10 | myengine2.Render();11 | present();12 | }

Page 15: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

15 FEBRUARY 2017 | EXPLICIT MGPU |

NODE MASK

EXPLICIT MGPU IN DIRECTX12

11001001

LSBMSB

▶ Each element of the bit field selects a GPU

Page 16: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

16 FEBRUARY 2017 | EXPLICIT MGPU |

NODE MASK

EXPLICIT MGPU IN DIRECTX12

LSBMSB

07152331

Page 17: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

17 FEBRUARY 2017 | EXPLICIT MGPU |

NOTICING THE NODE

EXPLICIT MGPU IN DIRECTX12

CreateCommandList( UINT nodeMask, D3D12_COMMAND_LIST_TYPE type, ID3D12CommandAllocator *pCommandAllocator,ID3D12PipelineState *pInitialState, REFIID riid, void **ppCommandList);

Page 18: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

18 FEBRUARY 2017 | EXPLICIT MGPU |

NOTICING THE NODE

EXPLICIT MGPU IN DIRECTX12

HRESULT CreateCommandQueue(…);

struct D3D12_COMMAND_QUEUE_DESC {

D3D12_COMMAND_LIST_TYPE Type; INT Priority; D3D12_COMMAND_QUEUE_FLAGS Flags; UINT NodeMask;

};

Page 19: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

19 FEBRUARY 2017 | EXPLICIT MGPU |

NOTICING THE NODE

EXPLICIT MGPU IN DIRECTX12

CreateRootSignature( UINT nodeMask, const void *pBlobWithRootSignature, SIZE_T blobLengthInBytes, REFIID riid, void **ppvRootSignature);

Page 20: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

20 FEBRUARY 2017 | EXPLICIT MGPU |

NOTICING THE NODE

EXPLICIT MGPU IN DIRECTX12

HRESULT CreateDescriptorHeap (…);

struct D3D12_DESCRIPTOR_HEAP_DESC {

D3D12_DESCRIPTOR_HEAP_TYPE Type; UINT NumDescriptors; D3D12_DESCRIPTOR_HEAP_FLAGS Flags; UINT NodeMask;

};

Page 21: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

21 FEBRUARY 2017 | EXPLICIT MGPU |

NOTICING THE NODE

EXPLICIT MGPU IN DIRECTX12

HRESULT CreateGraphicsPipelineState (…);

struct D3D12_GRAPHICS_PIPELINE_STATE_DESC {

D3D12_SHADER_BYTECODE VS; D3D12_SHADER_BYTECODE PS; […]DXGI_SAMPLE_DESC SampleDesc; UINT NodeMask; D3D12_CACHED_PIPELINE_STATE CachedPSO; D3D12_PIPELINE_STATE_FLAGS Flags;

};

Page 22: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

22 FEBRUARY 2017 | EXPLICIT MGPU |

NOTICING THE NODE

▶ Shared resource

EXPLICIT MGPU IN DIRECTX12

pDevice->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT, CreationNode, VisibleNode),D3D12_HEAP_FLAG_NONE,&RDesc,D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,nullptr,IID_PPV_ARGS(&m_pTexture2D));

Page 23: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

23 FEBRUARY 2017 | EXPLICIT MGPU |

NOTICING THE NODE

EXPLICIT MGPU IN DIRECTX12

CreateCommandQueue( D3D12_COMMAND_QUEUE_DESC *,…);CreateCommandList ( UINT nodeMask,…);CreateDescriptorHeap( D3D12_DESCRIPTOR_HEAP_DESC ,…);CreateQueryHeap( D3D12_QUERY_HEAP_DESC *,…);

CreateGraphicsPipelineState ( D3D12_GRAPHICS_PIPELINE_STATE_DESC *,…);CreateComputePipelineState( D3D12_COMPUTE_PIPELINE_STATE_DESC * ,…);CreateRootSignature( UINT nodeMask,… );CreateCommandSignature( D3D12_COMMAND_SIGNATURE_DESC *,…);CreateCommitedResource ( D3D12_HEAP_PROPERTIES *,…);

▶ Single node:

▶ Multi-node:

Page 24: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

24 FEBRUARY 2017 | EXPLICIT MGPU |

MGPU THE EASY WAY – BOTTOM LINE

▶ Use AFR

▶ Avoid frame dependencies

Time

Frame 1

Frame 6

Frame 3 Frame 5

Frame 2 Frame 4

Page 25: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

25 FEBRUARY 2017 | EXPLICIT MGPU |

FRAME DEPENDENCIES

▶ Temporal effectsMotion blur

Antialiasing

Reprojection

Particle state

EXPLICIT MGPU IN DIRECTX12

Time

Frame 1

Frame 6

Frame 3 Frame 5

Frame 2 Frame 4

Page 26: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

26 FEBRUARY 2017 | EXPLICIT MGPU |

FRAME DEPENDENCIES

▶ Temporal effectsMotion blur

Antialiasing

Reprojection

Particle state

EXPLICIT MGPU IN DIRECTX12

Time

Frame 1

Frame 6

Frame 3 Frame 5

Frame 2 Frame 4

Page 27: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

27 FEBRUARY 2017 | EXPLICIT MGPU |

ADDING MGPU SUPPORT

EXPLICIT MGPU IN DIRECTX12

Shadows

GBufferTone mappingLighting

Page 28: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

28 FEBRUARY 2017 | EXPLICIT MGPU |

ADDING MGPU SUPPORT

EXPLICIT MGPU IN DIRECTX12

Shadows

GBufferTone mappingLighting Motion Blur

Page 29: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

29 FEBRUARY 2017 | EXPLICIT MGPU |

ADDING MGPU SUPPORT

▶ Retrieving the previous frame:

EXPLICIT MGPU IN DIRECTX12

Shadows

GBufferTone mappingLighting Motion Blur

Shadows

GBufferTone mappingLighting Motion Blur

Page 30: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

30 FEBRUARY 2017 | EXPLICIT MGPU |

ADDING MGPU SUPPORT

EXPLICIT MGPU IN DIRECTX12

Shadows

GBufferTone mappingLighting Motion Blur

Shadows

GBufferTone mappingLighting Motion Blur

Shadows

GBufferTone mappingLighting Motion Blur

Shadows

GBufferLighting Motion Blur

Page 31: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

31 FEBRUARY 2017 | EXPLICIT MGPU |

ADDING MGPU SUPPORT

▶ Copies need to go over the PCIE! Who are you gonna call?

EXPLICIT MGPU IN DIRECTX12

Shadows

GBufferTone mappingLighting Motion Blur

Shadows

GBufferTone mappingLighting Motion Blur

Shadows

GBufferTone mappingLighting Motion Blur

Shadows

GBufferLighting Motion Blur

Page 32: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

32 FEBRUARY 2017 | EXPLICIT MGPU |

ADDING MGPU SUPPORT

▶ That is a job for the copy queue

EXPLICIT MGPU IN DIRECTX12

Shadows

GBufferTone mappingLighting Motion Blur

Shadows

GBufferTone mappingLighting Motion Blur

Shadows

GBufferTone mappingLighting Motion Blur

Shadows

GBufferLighting Motion Blur

Copy

Copy

Page 33: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

33 FEBRUARY 2017 | EXPLICIT MGPU |

ADDING MGPU SUPPORT

▶ Let’s focus on the copy

EXPLICIT MGPU IN DIRECTX12

Shadows

GBufferTone mappingLighting Motion Blur

Shadows

GBufferTone mappingLighting Motion Blur

Copy

Page 34: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

34 FEBRUARY 2017 | EXPLICIT MGPU |

ADDING MGPU SUPPORT

▶ Copy into a temporary resource

EXPLICIT MGPU IN DIRECTX12

Shadows

GBufferTone mappingLighting Motion Blur

Shadows

GBufferTone mappingLighting Motion Blur

Copy

TMP

Page 35: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

35 FEBRUARY 2017 | EXPLICIT MGPU |

ADDING MGPU SUPPORT

▶ Copy as soon as possible!

EXPLICIT MGPU IN DIRECTX12

Shadows

GBufferTone mappingLighting Motion Blur

Shadows

GBufferTone mappingLighting Motion Blur

TMP

Copy

Page 36: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

36 FEBRUARY 2017 | EXPLICIT MGPU |

SYNCHRONIZATION

▶ Queue operations

Execute()

Wait()

Signal()

EXPLICIT MGPU IN DIRECTX12

Page 37: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

37 FEBRUARY 2017 | EXPLICIT MGPU |

Co

py

QG

rap

hic

s Q

SYNCHRONIZATION

▶ Queues detail

EXPLICIT MGPU IN DIRECTX12

Shadows

GBuffer

Tone mapping

Lighting Motion Blur

Copy

TMP

Page 38: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

38 FEBRUARY 2017 | EXPLICIT MGPU |

Co

py

QG

rap

hic

s Q

SYNCHRONIZATION

▶ Pausing the Copy Queue

EXPLICIT MGPU IN DIRECTX12

Shadows

GBuffer

Tone mapping

Lighting Motion Blur

CopyWait

TMP

Page 39: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

39 FEBRUARY 2017 | EXPLICIT MGPU |

Co

py

QG

rap

hic

s Q

SYNCHRONIZATION

▶ Resuming the Copy Queue

EXPLICIT MGPU IN DIRECTX12

Shadows

GBuffer

Tone mapping

Lighting Motion BlurGo!

CopyWait

TMP

Page 40: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

40 FEBRUARY 2017 | EXPLICIT MGPU |

SYNCHRONIZATION

▶ Fence foo ( = 8 )

EXPLICIT MGPU IN DIRECTX12

Co

py

QG

rap

hic

s Q

Go!

Wait until foo=9

Set foo to 9

Wait

Page 41: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

41 FEBRUARY 2017 | EXPLICIT MGPU |

SYNCHRONIZATION

▶ Fence foo ( = 8 )

EXPLICIT MGPU IN DIRECTX12

Co

py

QG

rap

hic

s Q

Go!

Set foo to 9

m_CopyQueue->Wait(m_FenceFoo, 9);

m_GfxQueue->Signal(m_FenceFoo, 9);

Wait until foo=9

Wait

Page 42: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

42 FEBRUARY 2017 | EXPLICIT MGPU |

Co

py

QG

rap

hic

s Q

SYNCHRONIZATION

▶ Execute!

EXPLICIT MGPU IN DIRECTX12

Shadows

GBuffer

Tone mapping

Lighting Motion BlurGo!

Execute()

CopyWait

TMP

Page 43: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

43 FEBRUARY 2017 | EXPLICIT MGPU |

Co

py

QG

rap

hic

s Q

SYNCHRONIZATION

▶ Execute!

EXPLICIT MGPU IN DIRECTX12

Shadows

GBuffer

Tone mapping

Lighting Motion BlurGo!

Signal()

CopyWait

TMP

Page 44: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

44 FEBRUARY 2017 | EXPLICIT MGPU |

Co

py

QG

rap

hic

s Q

SYNCHRONIZATION

▶ Execute!

EXPLICIT MGPU IN DIRECTX12

Shadows

GBuffer

Tone mapping

Lighting Motion BlurGo!

Execute()

CopyWait

TMP

Page 45: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

45 FEBRUARY 2017 | EXPLICIT MGPU |

Co

py

QG

rap

hic

s Q

ADDING MGPU SUPPORT

▶ Now with barriers

EXPLICIT MGPU IN DIRECTX12

Shadows

GBuffer

Tone mapping

Lighting Motion BlurGo!

CopyWait

TMP

Page 46: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

46 FEBRUARY 2017 | EXPLICIT MGPU |

Co

py

QG

rap

hic

s Q

ADDING MGPU SUPPORT

▶ Now with barriers

EXPLICIT MGPU IN DIRECTX12

Shadows

GBuffer

Tone mapping

Lighting Motion Blur

Copy

Go!

TMP

Lit->copy SRCTMP->copy DST

Wait

Page 47: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

47 FEBRUARY 2017 | EXPLICIT MGPU |

Co

py

QG

rap

hic

s Q

BARRIERS

▶ Let it go!

EXPLICIT MGPU IN DIRECTX12

Shadows

GBuffer

Tone mapping

Lighting Motion Blur

Copy

Go!

TMP

Lit->copy SRCTMP->copy DST

?

Wait

Page 48: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

48 FEBRUARY 2017 | EXPLICIT MGPU |

Co

py

QG

rap

hic

s Q

BARRIERS

▶ Release ownership by transitioning to COMMON

EXPLICIT MGPU IN DIRECTX12

Shadows

GBuffer

Tone mapping

Lighting Motion Blur

CopyWait

Go!

TMP

Lit->copy SRCTMP->copy DST

Lit->COMMON

Page 49: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

49 FEBRUARY 2017 | EXPLICIT MGPU |

Co

py

QG

rap

hic

s Q

BARRIERS

▶ Release ownership by transitioning to COMMON

EXPLICIT MGPU IN DIRECTX12

Shadows

GBuffer

Tone mapping

Lighting Motion Blur

CopyWait

Go!

Lit->copy SRCTMP->copy DST

Lit->COMMON

TMP

Lit->COMMONTMP-> COMMON

Page 50: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

50 FEBRUARY 2017 | EXPLICIT MGPU |

ADDING MGPU SUPPORT

EXPLICIT MGPU IN DIRECTX12

▶ All together now!

Co

py

QG

rap

hic

s Q

Shadows

GBuffer

Tone mappingLighting Motion Blur

CopyWait

Go!

Lit->COMMON

TMP-> COMMON

Lit->copy SRCTMP->copy DST

Gra

ph

ics

Q Go!

Shadows

GBuffer

Tone mappingLighting Motion Blur

Co

py

Q CopyWaitLit->COMMON

TMP-> COMMON

Lit->copy SRCTMP->copy DST

TMP

Lit->COMMONTMP-> COMMON

Lit->COMMONTMP-> COMMON

Page 51: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

51 FEBRUARY 2017 | EXPLICIT MGPU |

ADDING MGPU SUPPORT

EXPLICIT MGPU IN DIRECTX12

▶ After and before

Co

py

QG

rap

hic

s Q

Shadows

GBuffer

Lighting

Gra

ph

ics

Q

Shadows

GBuffer

Lighting

Co

py

Q

Tone mappingMotion Blur

Tone mappingMotion Blur

Page 52: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

52 FEBRUARY 2017 | EXPLICIT MGPU |

COPY QUEUE CODE

▶ blah

EXPLICIT MGPU IN DIRECTX12

// Wait for signal from the GFX queuem_CopyQueue->Wait(m_FenceFoo, 9);

// Taking over resources from the Graphics queueD3D12_RESOURCE_BARRIER barriersPreCopy[] = {

CD3DX12_RESOURCE_BARRIER::Transition(pDest, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_COPY_DEST),CD3DX12_RESOURCE_BARRIER::Transition(pSrc, D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_COPY_SOURCE),

};m_pCopyCmdLst->ResourceBarrier(2, barriersPreCopy);

// Do Copym_pCopyCmdLst->CopyResource(pDest, pSrc);

// Release ownership so the direct queue can use these resourcesD3D12_RESOURCE_BARRIER barriersPostCopy[] = {

CD3DX12_RESOURCE_BARRIER::Transition(pSrc, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COMMON),CD3DX12_RESOURCE_BARRIER::Transition(pDest, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COMMON),

};pCopyCmdLst->ResourceBarrier(2, barriersPostCopy);

Page 53: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

53 FEBRUARY 2017 | EXPLICIT MGPU |

PSEUDO CODE

▶ Graphics Queue A

EXPLICIT MGPU IN DIRECTX12

Shadows(A.shadowRT);

GBuffer(A.gbufferRT);

Lighting(A.litRT, A.shadowRT, A.gbufferRT);

Signal(A.CopyQueue);

MotionBlur(A.hdr, A.litRT, A.lastFrame);

ToneMapping(swapchain, A.hdr);

Present();

Wait(A.DirectQueue)

Copy( B.lastFrame , A.litRT);

▶ Copy queue A

Page 54: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

54 FEBRUARY 2017 | EXPLICIT MGPU |

PSEUDO CODE

▶ Graphics Queue B

EXPLICIT MGPU IN DIRECTX12

Shadows(B.shadowRT);

GBuffer(B.gbufferRT);

Lighting(B.litRT, B.shadowRT, B.gbufferRT);

Signal(B.CopyQueue);

MotionBlur(B.hdr, B.litRT, B.lastFrame);

ToneMapping(swapchain, B.hdr);

Present();

Wait(B.DirectQueue)

Copy( A.lastFrame , B.litRT);

▶ Copy queue B

Page 55: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

55 FEBRUARY 2017 | EXPLICIT MGPU |

TOOLS OF THE TRADE - GPUVIEW

EXPLICIT MGPU IN DIRECTX12

Page 56: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

56 FEBRUARY 2017 | EXPLICIT MGPU |

TOOLS OF THE TRADE - GPUVIEW

EXPLICIT MGPU IN DIRECTX12

Direct Queue A

Copy Queue A

Page 57: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

57 FEBRUARY 2017 | EXPLICIT MGPU |

TOOLS OF THE TRADE - GPUVIEW

EXPLICIT MGPU IN DIRECTX12

Direct Queue A

Copy Queue A

Direct Queue B

Copy Queue B

Page 58: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

58 FEBRUARY 2017 | EXPLICIT MGPU |

TOOLS OF THE TRADE - GPUVIEW

EXPLICIT MGPU IN DIRECTX12

Page 59: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

59 FEBRUARY 2017 | EXPLICIT MGPU |

TOOLS OF THE TRADE - GPUVIEW

EXPLICIT MGPU IN DIRECTX12

Page 60: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

60 FEBRUARY 2017 | EXPLICIT MGPU |

FRAME PACING

EXPLICIT MGPU IN DIRECTX12

Page 61: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

61 FEBRUARY 2017 | EXPLICIT MGPU |

SHOW ME THE CODE

EXPLICIT MGPU IN DIRECTX12

Page 62: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

62 FEBRUARY 2017 | EXPLICIT MGPU |

SHOW ME THE CODE

EXPLICIT MGPU IN DIRECTX12

Page 63: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

63 FEBRUARY 2017 | EXPLICIT MGPU |

SHOW ME THE CODE

EXPLICIT MGPU IN DIRECTX12

Page 64: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

64 FEBRUARY 2017 | EXPLICIT MGPU |

WRAPPING UP

▶ Quick AFR

▶ MGPU API

▶ Synchronization

▶ Queue ownership

▶ Sample code

▶ Lucky winner!

EXPLICIT MGPU IN DIRECTX 12

Page 65: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

65 FEBRUARY 2017 | EXPLICIT MGPU |

CASE STUDY, EXPLICIT MGPU IN NITROUS

▶ Ashes of the Singularity supports Multi-GPURegardless of hardware supported linked mode

▶ Essentially AFR support, alternate frame rendering

▶ Nitrous 2.0 will do something different

EXPLICIT MGPU IN DIRECTX12

Page 66: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

66 FEBRUARY 2017 | EXPLICIT MGPU |

BASICS

▶ Eliminated all cross frame dependenciesRendering technique does not require previous frames contents

▶ Reissue queue which will issue command to both GPUS (even if one GPU is not ‘active’ for a frame)

▶ Frame Queue which only generates commands for active frame

EXPLICIT MGPU IN DIRECTX12

Reissue Queue

Frame Queue

Page 67: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

67 FEBRUARY 2017 | EXPLICIT MGPU |

BACKBUFFER

▶ Nitrous 1.0 does not use backbuffer present on different GPUSBackbuffers exist on “main” GPU

Backbuffer is manually copied via queues

▶ Frame pacing is done manually

▶ Linked mode enables more slick operation, but requires hardware level support

EXPLICIT MGPU IN DIRECTX12

Page 68: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

68 FEBRUARY 2017 | EXPLICIT MGPU |

FRAME PACING DONE MANUALLY

▶ Chop main queue into < 1ms command buffers

▶ Allow windows 10 scheduler to insert present when second GPU is done

▶ Works ok, except precision of windows timers means +- 2-3ms accuracy

▶ Hopefully will be improved in future DX versions

EXPLICIT MGPU IN DIRECTX12

Cmd Cmd

Cmd Cmd Cmd Cmd CmdPresentMain Queue

Present Queue

Secondary GPU Cmd Cmd Cmd Cmd

Page 69: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

69 FEBRUARY 2017 | EXPLICIT MGPU |

SETTING QUEUED FRAMES HIGHER

EXPLICIT MGPU IN DIRECTX12

// Set number of frames to 4 if using MGPU AFR modeg_pDevice->QueryInterface(IID_IDXGISwapChain2, (void**)&g_pSwapChain2);g_pSwapChain2->SetMaximumFrameLatency(4);

// If using maximum frame latency, need to manually block on presentif(g_pSwapChain2){

HANDLE SwapChainHandle = g_pSwapChain2->GetFrameLatencyWaitableObject();if(WaitForSingleObject(SwapChainHandle,0)== WAIT_OBJECT_0)

g_bWaitOnPresent = true;CloseHandle(SwapChainHandle);

}

SwapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT;

Page 70: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

70 FEBRUARY 2017 | EXPLICIT MGPU |

MULTIGPU IN NITROUS 2.0

▶ AFR is limited approach, increases latency

▶ Alternatives include split screen rendering

▶ What about VR? One card per eye?Sounds simple, but not necessarily the best choice

Some rendering can be shared between the eyes

▶ Oxide looking at something else

EXPLICIT MGPU IN DIRECTX12

Page 71: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

71 FEBRUARY 2017 | EXPLICIT MGPU |

OBJECT SPACE RENDERING

▶ Opposite of deferred, shading happens before rasterization

▶ Shading can be shared between eyes!

EXPLICIT MGPU IN DIRECTX12

Page 72: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

72 FEBRUARY 2017 | EXPLICIT MGPU |

COMPLETELY DIFFERENT MGPU SETUP

EXPLICIT MGPU IN DIRECTX12

RasterizeMain GPU

Aux GPU

▶ Can shade on 1 GPU, and raster on other GPU

▶ Shading data can have (Quite a bit) latency without noticeable visual effect

▶ AXU GPU can be set to never block main GPU

▶ Mismatch of GPU performance possible

▶ Challenge: Load balancing, possible arbitrary # of GPUs could be supported

ShadeShade

Rasterize

Page 73: Explicit DirectX12 Multi GPU rendering...Lightweight API Multithreading Needed in VR for one-GPU-per-eye configurations EXPLICIT MGPU IN DIRECTX12

73 FEBRUARY 2017 | EXPLICIT MGPU | OCTOBER 2016 | POLARIS MGPU UPDATE | 73

THANK YOU!

▶ GPU raffle

▶ Questions and Answers

▶ Please fill the feedback form

EXPLICIT MGPU IN DIRECTX12