DirectX 12. Why DirectX? Limited platforms Windows 10 XBox One. Large, connected API Direct3D DirectXMath XInput XAudio2

Similar documents
Why DirectX? Limited platforms. Large, connected API. Good for games on Microsoft platforms. Windows 10 XBox One. Direct3D DirectXMath XInput XAudio2

DirectX 11 First Elements

Chapter Answers. Appendix A. Chapter 1. This appendix provides answers to all of the book s chapter review questions.

ADVANCED RENDERING WITH DIRECTX 12

NVIDIA AFTERMATH: A NEW WAY OF DEBUGGING CRASHES ON THE GPU. Alex Dunn, 2 nd March 2017

EECS 487: Interactive Computer Graphics

Introduction to Multithreaded rendering and the usage of Deferred Contexts in DirectX 11

Explicit Multi GPU Programming with DirectX 12. Juha Sjöholm Developer Technology Engineer NVIDIA

Shrinath Shanbhag Senior Software Engineer Microsoft Corporation

NVIDIA Parallel Nsight. Jeff Kiel

Shader Series Primer: Fundamentals of the Programmable Pipeline in XNA Game Studio Express

Day: Thursday, 03/19 Time: 16:00-16:50 Location: Room 212A Level: Intermediate Type: Talk Tags: Developer - Tools & Libraries; Game Development

DirectX Programming #4. Kang, Seongtae Computer Graphics, 2009 Spring

Porting Roblox to Vulkan. Arseny

The Amazing DX Workshop

The Application Stage. The Game Loop, Resource Management and Renderer Design

Introduction to DirectX Raytracing

GPU Memory Model. Adapted from:

Vulkan API 杨瑜, 资深工程师

zspace Developer Native Programming Guide Version 1.0 Rev 1.1

Vulkan and Animation 3/13/ &height=285&playerId=

Low-Overhead Rendering with Direct3D. Evan Hart Principal Engineer - NVIDIA

Raise your VR game with NVIDIA GeForce Tools

Rendering Objects. Need to transform all geometry then

COMP371 COMPUTER GRAPHICS

Tiled shading: light culling reaching the speed of light. Dmitry Zhdan Developer Technology Engineer, NVIDIA

Bringing AAA graphics to mobile platforms. Niklas Smedberg Senior Engine Programmer, Epic Games

NVIDIA Developer Tools for Graphics and PhysX

Working with Metal Overview

Could you make the XNA functions yourself?

Why modern versions of OpenGL should be used Some useful API commands and extensions

Investigating real-time rendering techniques approaching realism using the Vulkan API

Understanding XNA Framework Performance. Shawn Hargreaves Software Development Engineer XNA Community Game Platform Microsoft

Motivation MGB Agenda. Compression. Scalability. Scalability. Motivation. Tessellation Basics. DX11 Tessellation Pipeline

Beginning Direct3D Game Programming: 1. The History of Direct3D Graphics

SLICING THE WORKLOAD MULTI-GPU OPENGL RENDERING APPROACHES

Copyright Khronos Group, Page Graphic Remedy. All Rights Reserved

Rendering Grass with Instancing in DirectX* 10

Rendering Subdivision Surfaces Efficiently on the GPU

Game Graphics & Real-time Rendering

Skinned Instancing. Bryan Dudash

Per-Face Texture Mapping for Realtime Rendering. Realtime Ptex

Squeezing Performance out of your Game with ATI Developer Performance Tools and Optimization Techniques

Vulkan C++ Markus Tavenrath, Senior DevTech Software Engineer Professional Visualization

GPU Memory Model Overview

Real - Time Rendering. Pipeline optimization. Michal Červeňanský Juraj Starinský

Bringing it all together: The challenge in delivering a complete graphics system architecture. Chris Porthouse

Shaders Part II. Traditional Rendering Pipeline

Hands-On Workshop: 3D Automotive Graphics on Connected Radios Using Rayleigh and OpenGL ES 2.0

CS451Real-time Rendering Pipeline

D3D12 & Vulkan Done Right. Gareth Thomas Developer Technology Engineer, AMD

Shaders (some slides taken from David M. course)

Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

Vulkan Timeline Semaphores

Achieving High-performance Graphics on Mobile With the Vulkan API

Geometry Shader - Silhouette edge rendering

Driving Change. Vulkanising Mad Max

Jomar Silva Technical Evangelist

NVSG NVIDIA Scene Graph

DirectX10 Effects and Performance. Bryan Dudash

Accelerating Realism with the (NVIDIA Scene Graph)

Shaders in Eve Online Páll Ragnar Pálsson

The Ultimate Developers Toolkit. Jonathan Zarge Dan Ginsburg

Optimisation. CS7GV3 Real-time Rendering

Approximate Catmull-Clark Patches. Scott Schaefer Charles Loop

Shader Programming CgFX, OpenGL 2.0. Michael Haller 2003

SIGGRAPH Briefing August 2014

Shader Programming and Graphics Hardware

Unity Software (Shanghai) Co. Ltd.

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

Graphics Hardware. Graphics Processing Unit (GPU) is a Subsidiary hardware. With massively multi-threaded many-core. Dedicated to 2D and 3D graphics

Vulkan: Architecture positive How Vulkan maps to PowerVR GPUs Kevin sun Lead Developer Support Engineer, APAC PowerVR Graphics.

Coding OpenGL ES 3.0 for Better Graphics Quality

Deferred rendering using Compute shaders

DirectX10 Effects. Sarah Tariq

CPSC 436D Video Game Programming

Practical Development for Vulkan. Dan Ginsburg, Valve Baldur Karlsson, Unity Dean Sekulic, Croteam

Spring 2009 Prof. Hyesoon Kim

PROFESSIONAL. WebGL Programming DEVELOPING 3D GRAPHICS FOR THE WEB. Andreas Anyuru WILEY. John Wiley & Sons, Ltd.

Blis: Better Language for Image Stuff Project Proposal Programming Languages and Translators, Spring 2017

Spring 2011 Prof. Hyesoon Kim

printf Debugging Examples

Lecture 25: Board Notes: Threads and GPUs

Siggraph Agenda. Usability & Productivity. FX Composer 2.5. Usability & Productivity 9/12/2008 9:16 AM

NVIDIA Nsight Visual Studio Edition 4.0 A Fast-Forward of All the Greatness of the Latest Edition. Sébastien Dominé, NVIDIA

GPGPU LAB. Case study: Finite-Difference Time- Domain Method on CUDA

NVIDIA Authoring Tools for

What s New in DI-Guy 12.5

The Graphics Pipeline

OpenGL with Qt 5. Qt Developer Days, Berlin Presented by Sean Harmer. Produced by Klarälvdalens Datakonsult AB

General Purpose Computation (CAD/CAM/CAE) on the GPU (a.k.a. Topics in Manufacturing)

Metal for OpenGL Developers

Mali Developer Resources. Kevin Ho ARM Taiwan FAE

Introduction to OpenGL. CS 4620 Balazs Kovacs, 2014 Daniel Schroeder, 2013 Pramook Khungurn, 2012

This guide updated December 20, 2017

Copyright Khronos Group Page 1

Intel Core 4 DX11 Extensions Getting Kick Ass Visual Quality out of the Latest Intel GPUs

Technical Guide. Updated April 19, Page 1 of 134

The Witness on Android Post Mortem. Denis Barkar 3 March, 2017

Introductory Seminar

Transcription:

DirectX 12 Why DirectX? Limited platforms Windows 10 XBox One Large, connected API Direct3D DirectXMath XInput XAudio2 Good for games on Microsoft platforms 1

Setting Up for DX12 Development Be on Windows 10 Enable developer mode in Update and Security Settings Download Visual Studio 2017 Install selecting the Universal Windows Platform and Game Development with C++ workloads Start Visual Studio Create new project Under C++ select Windows Universal Select DirectX 12 App 2

Pipeline Overview 3

Initialization Debug Layer #if defined(_debug) // Enable the D3D12 debug layer. { ComPtr<ID3D12Debug> debugcontroller; if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController)))) { debugcontroller->enabledebuglayer(); } } #endif 4

Create Device ComPtr<IDXGIFactory4> factory; ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(&factory))); ComPtr<IDXGIAdapter1> hardwareadapter; GetHardwareAdapter(factory.Get(), &hardwareadapter); ThrowIfFailed(D3D12CreateDevice( hardwareadapter.get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&m_device) )); Command Queue D3D12_COMMAND_QUEUE_DESC queuedesc = {}; queuedesc.flags = D3D12_COMMAND_QUEUE_FLAG_NONE; queuedesc.type = D3D12_COMMAND_LIST_TYPE_DIRECT; ThrowIfFailed(m_device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&m_commandQueue))); 5

Swap Chain Description DXGI_SWAP_CHAIN_DESC swapchaindesc = {}; swapchaindesc.buffercount = FrameCount; swapchaindesc.bufferdesc.width = m_width; swapchaindesc.bufferdesc.height = m_height; swapchaindesc.bufferdesc.format = DXGI_FORMAT_R8G8B8A8_UNORM; swapchaindesc.bufferusage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapchaindesc.swapeffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; swapchaindesc.outputwindow = Win32Application::GetHwnd(); swapchaindesc.sampledesc.count = 1; swapchaindesc.windowed = TRUE; Swap Chain Creation ComPtr<IDXGISwapChain> swapchain; ThrowIfFailed(factory->CreateSwapChain( m_commandqueue.get(), &swapchaindesc, &swapchain )); ThrowIfFailed(swapChain.As(&m_swapChain)); 6

Create Descriptor Heap (RTVs) D3D12_DESCRIPTOR_HEAP_DESC rtvheapdesc = {}; rtvheapdesc.numdescriptors = FrameCount; rtvheapdesc.type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV; rtvheapdesc.flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE; ThrowIfFailed(m_device->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(&m_rtvHeap))); m_rtvdescriptorsize = m_device- >GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV); Create RTVs for Each Frame CD3DX12_CPU_DESCRIPTOR_HANDLE rtvhandle(m_rtvheap- >GetCPUDescriptorHandleForHeapStart()); for (UINT n = 0; n < FrameCount; n++) { ThrowIfFailed(m_swapChain->GetBuffer(n, IID_PPV_ARGS(&m_renderTargets[n]))); m_device->createrendertargetview(m_rendertargets[n].get(), nullptr, rtvhandle); rtvhandle.offset(1, m_rtvdescriptorsize); } 7

Setup for Pipeline Create Root Signature Description Bind Root Signature to device M_device -> CreateRootSignature Compile and Load Shaders D3DCompileFromFile function Define Input Element Description array Tells the pipeline how vertices will be defined Pipeline Creation D3D12_GRAPHICS_PIPELINE_STATE_DESC psodesc = {}; psodesc.inputlayout = { inputelementdescs, _countof(inputelementdescs) }; psodesc.prootsignature = m_rootsignature.get(); psodesc.vs = { reinterpret_cast<uint8*>(vertexshader->getbufferpointer()), vertexshader->getbuffersize() }; psodesc.ps = { reinterpret_cast<uint8*>(pixelshader->getbufferpointer()), pixelshader->getbuffersize() }; psodesc.rasterizerstate = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT); psodesc.blendstate = CD3DX12_BLEND_DESC(D3D12_DEFAULT); psodesc.depthstencilstate.depthenable = FALSE; psodesc.depthstencilstate.stencilenable = FALSE; psodesc.samplemask = UINT_MAX; psodesc.primitivetopologytype = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; psodesc.numrendertargets = 1; psodesc.rtvformats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; psodesc.sampledesc.count = 1; ThrowIfFailed(m_device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_pipelineState))) 8

Command List Create command list for use when drawing ThrowIfFailed(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_commandallocator.get(), m_pipelinestate.get(), IID_PPV_ARGS(&m_commandList))); ThrowIfFailed(m_commandList->Close()); Command List must be closed before continuing initialization Create Vertex Buffer Create array of structs for geometry Create Resource on Device ThrowIfFailed(m_device->CreateCommittedResource( &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD), D3D12_HEAP_FLAG_NONE, &CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&m_vertexBuffer))); Do not use UPLOAD for static data 9

Vertex Buffer (cont.) Copy vertices to the buffer UINT8* pvertexdatabegin; CD3DX12_RANGE readrange(0, 0); // We do not intend to read from this resource on the CPU. ThrowIfFailed(m_vertexBuffer->Map(0, &readrange, reinterpret_cast<void**>(&pvertexdatabegin))); memcpy(pvertexdatabegin, objectvertices, sizeof(objectvertices)); m_vertexbuffer->unmap(0, nullptr); Initialize Vertex Buffer View m_vertexbufferview.bufferlocation = m_vertexbuffer->getgpuvirtualaddress(); m_vertexbufferview.strideinbytes = sizeof(vertex); m_vertexbufferview.sizeinbytes = vertexbuffersize; Fence Create a fence Wait for fence before ending initialization Ensures all setup is complete 10

Rendering Populate Command List Enter commands into the command list m_commandlist -> SomeCommand Some commands include: SetGraphicsRootSignature RSSetViewport RSSetScissorRects IASetPrimitiveTopologies IASetVertexBuffers DrawInstanced Close command list after completion 11

Execute Command List ID3D12CommandList* ppcommandlists[] = { m_commandlist.get() }; m_commandqueue->executecommandlists(_countof(ppcommandlists), ppcommandlists); Present Swap Chain m_swapchain->present(1, 0); Wait for fence 12

Closing the App Wait for fence Make sure the gpu is done will all commands Destroy the fence CloseHandle(m_fenceEvent); 13