37
Approaching Minimum Overhead with Direct3D12 Jerry Cao – DevTech Engineer [email protected]

Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Approaching Minimum Overhead with Direct3D12

Jerry Cao – DevTech Engineer [email protected]

Page 2: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

D3D12 brief introduction

Explicit memory management

Reducing CPU overhead

CPU efficiency

CPU parallelism

Improving GPU efficiency

Performance Comparison with D3D11 and OpenGL 4.x

New Graphics Features

Overview

Page 3: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Latest high-performance graphics API

Low-level model, even more direct

Works across all Microsoft Platforms

Direct3D12 Introduction

Page 4: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

D3D11 Graphics Pipeline

Input Assembler

Verte Shader

Hull Shader

Tessellator

Domain Shader

Geometry Shader

Rasterizer

Pixel Shader

Output Merger

VB

IB

resources

Page 5: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Pipeline State Object

Input Assembler

Verte Shader

Hull Shader

Tessellator

Domain Shader

Geometry Shader

Rasterizer

Pixel Shader

Output Merger

Pipeline State Object

Input Assembler

Verte Shader

Hull Shader

Tessellator

Domain Shader

Geometry Shader

Rasterizer

Pixel Shader

Output Merger

Page 6: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Pipeline State Object (cont)

No implicit shader recompiling and linking during rendering.

Resolve state to many hardware instructions earlier.

PSO takes binary shader as output, shader cache friendly.

Still need our attention:

Create a PSO in a separate thread

Use same values for don’t-care fields

Use similar PSOs among successive draw calls

Page 7: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Flexible Memory Allocation

Heap based memory allocation

Texture

Buffer (VB/IB/CB)

Descriptors

Sampler Vertex Buffer Index Buffer

Vertex Buffer Index Buffer

D3D11

D3D12 Heap

Page 8: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Resource Binding Model

There are only four types of View in D3D11, there will be more in D3D12

Constant Buffer View

Vertex Buffer View

Index Buffer View

And they are no longer D3D objects, you are in control of managing the memory directly

Page 9: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

New Resource Binding model

The following resources are set in a similar manner:

Render Target

Vertex/Index Buffer ( through views, not resource handle )

Viewport/Scissor Rect

There are dramatic changes for setting the following resources:

Texture

Constant Data

Sampler

There are more to set in D3D12:

PSO

Root Signature

Heap

Page 10: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

New Resource Binding Model (cont)

D3D12 introduces a new type of object called “RootSignature”.

It is the only window for setting resources for shader stages.

Three type of data:

Descriptor table

Descriptor

Constant Data

Page 11: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Balance Overhead in Your Case

GPU Performance in term of memory fetching

CPU Performance in term of overhead

Descriptor Table Descriptor Constant Data

More indirection Indirection One memory fetch

Multiple resources Single resource Only constant data

Page 12: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Be Careful with your RootSignature

Keep the size of your RootSignature smaller

Limit shader visibility to a minimum set

Only change data when necessary

Page 13: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

VB IB

The New D3D12 Pipeline

Resources

Root

Signature

Costant Data

Pipeline State Object

Input Assembler

Verte Shader

Hull Shader

Tessellator

Domain Shader

Geometry Shader

Rasterizer

Pixel Shader

Output Merger

Page 14: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Issues of Resource Management

Everything is deferred in D3D pipeline, make sure you don’t

change anything that is already queued.

Handle the following issues by yourself

Resource lifetime management

Resource residency management

Resource hazard

Page 15: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Avoid Resource Hazard

State switching of D3D11 resources is implicit

In D3D12, developer should take control of it

ResourceBarrier

Page 16: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Avoid Resource Hazard

State switching of D3D11 resources is implicit

In D3D12, developer should take control of it

ResourceBarrier

Page 17: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Another Example of Conflict

Make sure you do not stamp on memory in use.

Draw Call

Submit

Update

First Half

Data

Draw Call

Submit

Update

Second

Half Data

Draw Call

Submit

Update

First Half

Data

Frame 5

CPU

GPU Draw Call Execution

Frame 6 Frame 7

Frame 6 Frame 5

conflict Draw Call Execution

Constant Buffer

Odd frame Even frame

Page 18: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Another Example of Conflict

Draw Call

Submit

Update

First Half

Data

Draw Call

Submit

Update

Second

Half Data

Draw Call

Submit

Update

First Half

Data

Frame 5

CPU

GPU Draw Call Execution

Frame 6 Frame 7

Frame 6 Frame 5

Draw Call Execution

Wait

Constant Buffer

Odd frame Even frame

Make sure you do not stamp on memory in use.

Page 19: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Typical Resource Hazard Scene

Shadow map

Deferred Shading/Lighting

Real-time Reflection and Refraction

In any case that render target is used as texture in following draw

calls

Page 20: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

New Concepts in Execution Model

Command Queue

3D queue

Compute queue

Copy queue

Command List

Bundle

3D

Compute

Copy

Page 21: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Queue 3D/Compute/Copy CL CL

Execution Model

CL

Command List

Bundle

Draw Call

DC Bundle

DC DC

Page 22: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Steps to Issue Draw Calls

No more immediate context.

To issue a draw call

1. Create a 3D queue

2. Create a command list

3. Record the draw call in the command list

4. Execute command

Page 23: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Multi-thread Rendering

Old multi-thread rendering model

One dedicated thread for submitting draw/dispatch calls.

Several other thread for other things, like AI, visibility test.

The new model

Several threads for anything

Page 24: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Multi-thread Rendering (cont)

D3D9 D3D11 D3D12

D3D

9 D

evic

e

D3D

11 Im

media

te c

onte

xt

D3D

11 d

efe

rred c

onte

xt

D3D

12 c

om

mand q

ueue

Page 25: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Better GPU Efficiency

Dispatch Idle Dispatch Idle Dispatch Idle Dispatch

Dispatch

Dispatch

Dispatch Idle Dispatch

D3D11

D3D12

Page 26: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Porting from D3D11 to D3D12

A low hanging fruit: D3D11on12

Only minor changes in your D3D11 code:

Create D3D12 device

Create wrapped resource for back buffer

Manage render targets explicitly

Flush right before present

Fence your frame

Performing a full porting is necessary, don’t expect too much on

D3D11on12.

Page 27: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

API test (Extended version)

API test is a simple benchmark program for testing API

performance.

There are four problems:

Clear

Dynamic streaming, 250000 particles, each with different vertex buffer

data

Untextured Objects, 64x64x64 objects, each with different constant data

Textured Objects, 160000 quads, each with different textures

Get the source on github:

https://github.com/JerryCao1985/apitest

Page 28: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Performance

0 20 40 60 80 100 120 140 160

GLMapUnsynchronized

D3D11UpdatteSubresource

GLBufferSubData

D3D11MapNoOverwrite

GLMapPersistent

D3D12 naive

D3D12 Bundle

D3D12 MT

Dynamic Streaming

Page 29: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Performance

0 10 20 30 40 50 60 70 80 90

GLMapUnsynchronized

GLDynamicBuffer

GLUniform

GLTexCoord

GLBindless

GLMapPersistent

GLDrawLoop

Set32bitconstant

SetConstantBufferView

D3D11 naive

D3D12 Bundle

D3D12 MT

Untextured Object

Page 30: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Performance

0 20 40 60 80 100 120 140

GLNaive

GLNaiveUniform

GLBindless

GLNoTexUniform

GLSBTA

D3D11 Naive

GLTextureArray

GLNoTex

D3D12 Naive

D3D12 NoTex

D3D12 MT

Textured Quads

Page 31: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

New Graphics Features

Conservative Rasterization

Raster Order View

Tiled Resources (Volumes, 3D Texture)

Typed UAV Load

PS Specified Stencil Reference

Page 32: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Conservative Rasterization

Draws all pixels a triangle touches

Different Tiers – see DX spec

Possible before through GS trick but

relatively slow

See J. Hasselgren et. Al, “Conservative

Rasterization“, GPU Gems 2

Now we can use rasterization do

implement some nice techniques!

Page 33: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Hybrid Raytraced Shadows

Prim Buffer – Triangle vertices

Prim Indices Map – Prim buffer indices

of triangles

Prim Count Map – # of tris per texel

Raytrace triangles in a later pass

Prim Count Map NxN

Prim Indices Map NxNxd

Prim Buffer

Page 34: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Shadow Map Algorithm

Page 35: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Hybrid Ray Traced Shadow

Page 36: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Conclusion

D3D12 better performance

Pipeline changes

Memory model changes

New model of issuing draw/dispatch calls

Less dummy wait

D3D12 performance comparison with other APIs

D3D12 new graphics features

Hybrid Ray traced shadow

Page 37: Approaching Minimum Overhead with Direct3D12developer.download.nvidia.com/assets/gameworks/downloads...Resource Binding Model There are only four types of View in D3D11, there will

Q&A