directx12 graphics and performance

38
DirectX graphics and performance Dmitry Andreev, Microsoft

Upload: devgamm-conference

Post on 15-Apr-2017

373 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: DirectX12 Graphics and Performance

DirectX graphics and performance

Dmitry Andreev, Microsoft

Page 2: DirectX12 Graphics and Performance

• Разработано API и рабочие драйвера • Около 67% игроков имеют совместимое с DirectX 12

оборудование• 29% уже установили Windows 10

• 1 год для бесплатного апгрейда до Windows 10 для Windows 7 и 8.x

Готовность DirectX 12

* базируется на Steam survey

Page 3: DirectX12 Graphics and Performance

Direct3D 12 API• Повышение эффективности• Снижение нагрузки на CPU• Увеличение масштабируемости для нескольких ядер

CPU• Улучшение качества контроля состояния• Включение возможностей D3D11

Page 4: DirectX12 Graphics and Performance

ID3D11DeviceContext

Рендер-контекст D3D11

Input Assembler

Vertex Shader

Hull Shader

Tessellator

Rasterizer

Domain Shader

Geometry Shader

Pixel Shader

Output Merger

GPU Memory

Другие состяния

Page 5: DirectX12 Graphics and Performance

Direct3D 12 – оптимизация состояния конвейера

Группировка конвейера в единый объект

Копирование PSO в состояние оборудования

HW State 1

HW State 2

PipelineState

ObjectHW State 3

Page 6: DirectX12 Graphics and Performance

ID3D11DeviceContext

Рендер-контекст D3D11

Input Assembler

Vertex Shader

Hull Shader

Tessellator

Rasterizer

Domain Shader

Geometry Shader

Pixel Shader

Output Merger

GPU Memory

Non-PSO State

Page 7: DirectX12 Graphics and Performance

Рендер-контекст D3D12 : Pipeline State Object (PSO)

Pipeline State ObjectInput Assembler

Vertex Shader

Hull Shader

Tessellator

Rasterizer

Domain Shader

Geometry Shader

Pixel Shader

Output Merger

GPU Memory

Non-PSO State

Page 8: DirectX12 Graphics and Performance

Direct3D 12: Дескрипторные кучи и дескрипторные таблицы• Масштабирование возможностей оборудования• Универсальный подход по связыванию ресурсов

• Повторное использование статической привязки

• Динамическая индексация шейдерных ресурсов

Page 9: DirectX12 Graphics and Performance

Дескриптор• Небольшой пакет данных описывающий параметры ресурса• Просто данные – не управляются драйверами/ОС

Descriptor { Type Format Mip Count pData }

Texture

Page 10: DirectX12 Graphics and Performance

Дескрипторная куча• Место хранения дескрипторов• Структура определяется

приложением• Низкий уровень затрат на

манипуляции• Допустимо создание

множества куч

GPU Memory

Desc

ripto

r Hea

p

Page 11: DirectX12 Graphics and Performance

Дескрипторные таблицы• Контекст указывает на активную кучу• Не является объектом API• Один тип представления на таблицу

Pipeline State Object…

Vertex Shader

Pixel Shader

Start IndexSize

Page 12: DirectX12 Graphics and Performance

Render Context: Дескрипторные кучи и дескрипторные таблицы

Pipeline State ObjectInput Assembler

Vertex Shader

Hull Shader

Tessellator

Rasterizer

Domain Shader

Geometry Shader

Pixel Shader

Output Merger

GPU Memory

Non-PSO State

Page 13: DirectX12 Graphics and Performance

Дескрипторные таблицы - HLSLTexture2D texA[8] : register(t3, 2);Texture2D texB[8] : register(t2, 4);

SamplerState sam[2] : register(s0, 1);

struct MyCBufferType{ float foo; float bar;};

cbuffer MyCBufferType buf[4] : register(c0, 2);

Page 14: DirectX12 Graphics and Performance

Дескрипторные таблицы - HLSLfloat4 main( uint i1 : INDEX1, uint i2 : INDEX2, float2 coord : TEXCOORD) : SV_TARGET{ MyCBufferType b = buf[i1]; // CBuffer table 2 element #(i1) SamplerState s = sam[i1]; // Sampler table 1 element #(i1) Texture2D tA = texA[i1]; // SRV table 2 element #(i1+3) Texture2D tB = texB[i2]; // SRV table 4 element #(i2+2) float4 colorA = tA.Sample(s, coord); float4 colorB = tB.Sample(s, coord); return colorA * b.foo + colorB * b.bar;}

Page 15: DirectX12 Graphics and Performance

Очереди команд и списки команд

Command Queue

Execute Command List 1Execute Command List 2Signal Fence

Command List 1ClearSetTableExecute Bundle ASetTableDrawSetPSODraw

Command List 2ClearDispatchSetTableExecute Bundle ASetTableExecute Bundle B

SetP

SODraw

SetP

SOSe

tTable

Dispatc

h

SetP

SOSe

tTable

DrawSe

tPSO

Draw

Page 16: DirectX12 Graphics and Performance

Перегрузка CPU : Повторяющиеся команды рендера• Типичное приложение посылает идентичные пакеты команд от

фрейма к фрейму• 90-95% для типичного современного приложения

Page 17: DirectX12 Graphics and Performance

Бандл• Небольшой список команд

• Единожды записанный• Может быть использован

множество раз Context

ClearDrawSetTableExecute BundleSetTableExecute BundleSetPSO…

SetP

SODraw

SetP

SOSe

tTable

Dispatc

h

SetP

SOSe

tTable

DrawSe

tPSO

Draw

Page 18: DirectX12 Graphics and Performance

Пример без бандлов// Setup

pContext->SetPipelineState(pPSO);

pContext->SetRenderTargetViewTable(0, 1, FALSE, 0);

pContext->SetVertexBufferTable(0, 1);

pContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

// Draw 1

pContext->SetConstantBufferViewTable(D3D12_SHADER_STAGE_PIXEL, 0, 1);

pContext->SetShaderResourceViewTable(D3D12_SHADER_STAGE_PIXEL, 0, 1);

pContext->DrawInstanced(6, 1, 0, 0);

pContext->SetShaderResourceViewTable(D3D12_SHADER_STAGE_PIXEL, 1, 1);

pContext->DrawInstanced(6, 1, 6, 0);

// Draw 2

pContext->SetConstantBufferViewTable(D3D12_SHADER_STAGE_PIXEL, 1, 1);

pContext->SetShaderResourceViewTable(D3D12_SHADER_STAGE_PIXEL, 0, 1);

pContext->DrawInstanced(6, 1, 0, 0);

pContext->SetShaderResourceViewTable(D3D12_SHADER_STAGE_PIXEL, 1, 1);

pContext->DrawInstanced(6, 1, 6, 0);

Set object #1 specific tables and draw

Setup pipeline state and common descriptor tables

Set object #2 specific tables and draw

Page 19: DirectX12 Graphics and Performance

Создание бандла// Create bundle

pDevice->CreateCommandList(D3D12_COMMAND_LIST_TYPE_BUNDLE, pBundleAllocator, pPSO, pDescriptorHeap, &pBundle);

// Record commands

pBundle->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

pBundle->SetShaderResourceViewTable(D3D12_SHADER_STAGE_PIXEL, 0, 1);

pBundle->DrawInstanced(6, 1, 0, 0);

pBundle->SetShaderResourceViewTable(D3D12_SHADER_STAGE_PIXEL, 1, 1);

pBundle->DrawInstanced(6, 1, 6, 0);

pBundle->Close();

Page 20: DirectX12 Graphics and Performance

С бандлами// Setup

pContext->SetPipelineState(pPSO);

pContext->SetRenderTargetViewTable(0, 1, FALSE, 0);

pContext->SetVertexBufferTable(0, 1);

pContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

// Draw 1

pContext->SetConstantBufferViewTable(D3D12_SHADER_STAGE_PIXEL, 0, 1);

pContext->SetShaderResourceViewTable(D3D12_SHADER_STAGE_PIXEL, 0, 1);

pContext->DrawInstanced(6, 1, 0, 0);

pContext->SetShaderResourceViewTable(D3D12_SHADER_STAGE_PIXEL, 1, 1);

pContext->DrawInstanced(6, 1, 6, 0);

// Draw 2

pContext->SetConstantBufferViewTable(D3D12_SHADER_STAGE_PIXEL, 1, 1);

pContext->SetShaderResourceViewTable(D3D12_SHADER_STAGE_PIXEL, 0, 1);

pContext->DrawInstanced(6, 1, 0, 0);

pContext->SetShaderResourceViewTable(D3D12_SHADER_STAGE_PIXEL, 1, 1);

pContext->DrawInstanced(6, 1, 6, 0);

// Setup

pContext->SetRenderTargetViewTable(0, 1, FALSE, 0);

pContext->SetVertexBufferTable(0, 1);

// Draw 1 and 2

pContext->SetConstantBufferViewTable(D3D12_SHADER_STAGE_PIXEL, 0, 1);

pContext->ExecuteBundle(pBundle);

pContext->SetConstantBufferViewTable(D3D12_SHADER_STAGE_PIXEL, 1, 1);

pContext->ExecuteBundle(pBundle);

Без

Page 21: DirectX12 Graphics and Performance

D3D11 ПрофайлингPresen

tApp Logic D3D11 UMD KMDDXGK

App LogicD3D11

App LogicD3D11

App LogicD3D11

Thread 0

Thread 1

Thread 2

Thread 3

0 ms 2.50 ms 5.00 ms 7.50 ms

App Logic D3D Runtime User-mode Driver DXGKernel Kernel-mode Driver Present

Page 22: DirectX12 Graphics and Performance

D3D12 Профайлинг

App Logic UMDD3 D1 2 Pre

sen

tDXG

K/K

MD

App Logic UMDD3 D1 2App Logic UMDD3 D1 2

App Logic UMDD3 D1 2

Thread 0

Thread 1

Thread 2

Thread 3

0 ms 2.50 ms 5.00 ms 7.50 ms

App Logic D3D Runtime User-mode Driver DXGKernel Kernel-mode Driver Present

Page 23: DirectX12 Graphics and Performance

D3D11 v D3D12 результаты

App Logic UMDD 3 D 1 2 P r e s e n tD X G K / K M D

App Logic UMDD 3 D 1 2

App Logic UMDD 3 D 1 2

App Logic UMDD 3 D 1 2

Thread 0

Thread 1

Thread 2

Thread 3

0 ms 2.50 ms 5.00 ms 7.50 ms

PresentApp Logic D3D11 UMD KMDDX

GK

App Logic D 3 D 1 1

App Logic D 3 D 1 1

App Logic D 3 D 1 1

Thread 0

Thread 1

Thread 2

Thread 3

0 ms 2.50 ms 5.00 ms 7.50 ms

App+GFX (ms) GFX-only (ms)

D3D11 D3D12 D3D11 D3D12

Thread 0 7.88 3.80 5.73 1.17

Thread 1 3.08 2.50 0.35 0.81

Thread 2 2.84 2.46 0.34 0.69

Thread 3 2.63 2.45 0.23 0.65

Total 16.42 11.21 6.65 3.32

Page 25: DirectX12 Graphics and Performance

Копирование ресурсов с помощью Multiengine

• Синхронизация между GPUs• Разделяемая общая память

…dGPU3D->Draw(frame1A)dGPU3D->Signal(renderComplete)

dGPUCopy->Wait(renderComplete)dGPUCopy->Copy(frame1A, sharedHeap)dGPUCopy->Signal(copyComplete)

iGPU3D->Wait(copyComplete)iGPU3D->Bind(sharedFrame)iGPU3D->Draw(frame1B)iGPU3D->Present(frame1B)…

Page 26: DirectX12 Graphics and Performance

Visual Studio Graphics Analyzer

Page 27: DirectX12 Graphics and Performance

Инструменты анализа графики: последнее поколение

PIX для Xbox 360

CPU, GPU, системный профайлинг и отладка для Xbox консоли

Page 28: DirectX12 Graphics and Performance

Инструменты анализа графики: последнее поколение

PIX для Xbox 360

Popular unified CPU, GPU, System profiling and debugging tool for Xbox console

PIX для Windows

DirectX SDK инструмент для отладки графики

Page 29: DirectX12 Graphics and Performance

Инструменты анализа графики: последнее поколение

PIX для Xbox 360

Popular unified CPU, GPU, System profiling and debugging tool for Xbox console

PIX для Windows

DirectX SDK graphics tool focused on graphics debugging

Visual Studio 2012

Visual Studio Graphics Diagnostics 2012:интегрированный в Visual Studio инструмент базирующийся на PIX

Page 30: DirectX12 Graphics and Performance

• Графики в реальном масштабе времени• Visual Studio Graphics

Analyzer (VSGA)• Специальный

инструмент для анализа фреймов

• Создан с использованием Visual Studio shell

Улучшенный инструмент анализа и диагностики

Page 31: DirectX12 Graphics and Performance

Графические инструменты Visual Studio

Шаблоны проектовШаблоны элементов3D Starter KitDirectX ToolkitПримеры

Отладчик графикиВсе Windows устройства

Графический профайлерАнализ фреймовАнализ GPU

Редактор изображенийПросмотр моделейДизайнер шейдеровContent pipelineКомпиляция HLSL в

Проектные инструменты

Контентные инструменты

Инструменты анализа

Page 32: DirectX12 Graphics and Performance

Анализ проблем с рендером используя Visual Studio Graphics

Diagnostics

Page 33: DirectX12 Graphics and Performance

•Просмотр исходного кода шейдера и результатов компиляции в ассемблер

•Редактирование кода и мгновенный просмотр результатов

Редактирование шейдеров

Page 34: DirectX12 Graphics and Performance

Разрешение проблем производительности с помощью GPU usage

Page 35: DirectX12 Graphics and Performance

Анализ нагрузки на GPU• Графики в реальном масштабе

времени: frame time, frame rate, GPU utilization

• Удобно для поиска «бутылочных горлышек» при работе GPU/CPU

Page 36: DirectX12 Graphics and Performance

• Легкий инструмент для записи и проигрывания фреймов приложения directx • Полный анализ в

VS

Инструмент командной строки для записи фреймов

Page 37: DirectX12 Graphics and Performance

• Graphics Tools• Visual Studio Community Edition:

http://www.visualstudio.com/downloads/visual-studio-2015-downloads-vs• http://blogs.msdn.com/b/vcblog/

• DirectX 12• Блог: http://blogs.msdn.com/b/directx/• Документация : https://msdn.microsoft.com/en-us/library/dn903821(v=vs.85).aspx

• GDC 2015:• http://channel9.msdn.com/Events/GDC/GDC-2015/Advanced-DirectX12-Graphics-and-Performance• http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/D3D12-A-new-meaning-for-efficienc

y-and-performance.ppsx• DirectX Tools:

http://channel9.msdn.com/Events/GDC/GDC-2015/Solve-the-Tough-Graphics-Problems-with-your-Game-Using-DirectX-Tools

• Direct3D 12 Power & Performance: http://channel9.msdn.com/Events/GDC/GDC-2015/Better-Power-Better-Performance-Your-Game-on-DirectX12

• Microsoft DirectX 12 and Graphics Education • https://github.com/Microsoft/DirectX-Graphics-Samples.git

Ресурсы

Page 38: DirectX12 Graphics and Performance

©2015 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.