SlideShare una empresa de Scribd logo
1 de 26
Descargar para leer sin conexión
Introduction to DirectX
     Programming
     Direct3D Pipeline
Contents
• GPU programming model
• Introduction to DirectX
  – Direct3D
  – DXGI
  – HLSL
  – COM essentials
• Direct3D pipeline
GPU Architecture
• Well-suited for data-parallel computations
• Lower requirement for sophisticated flow control
CPU-GPU Relationship
• GPU: coprocessor with its own memory

            CPU                               GPU


 Core   Core      Core   Core
                                PCIe x16
                                   2.0
                                (8 GB/s)
                                                    (~150 GB/s)
 IMC (~30 GB/s)
                                           GPU Memory
        Main Memory
Programming with GPU
• Various APIs and technologies
  – Graphics programming
  – General-purpose GPU programming

                     Applications



        DirectX   OpenGL      CUDA    OpenCL



                        GPU
Introduction to DirectX
• Set of low-level APIs for creating high-
  performance multimedia applications, on
  Microsoft platforms (Windows, Xbox, …)
• Components
         2-D and 3-D graphics          Direct3D
                Sound           XAudio2, X3DAudio, XACT
                Input                   XInput


• DirectX SDK (Software Development Kit)
  – Libraries, header files, utilities, sample codes and docs
Direct3D
• API for rendering 2-D and 3-D graphics
• Hardware acceleration if available
• Advanced graphics capabilities
  – Graphics pipeline, z-buffering, anti-aliasing, alpha
    blending, mipmapping, …

• Abstractions
  – Pipeline stages, device, resource, swap chain, …

• API as set of COM-compliant objects
DXGI
• DirectX Graphics Infrastructure
  – Manages low-level tasks independent of DirectX
    graphics runtime
  – Common framework for future graphics components
• Supported tasks
  –   Enumerating adapters
  –   Managing swap chain
  –   Handling window resizing
  –   Choosing DXGI output and size
  –   Debugging in full-screen mode
Adapter
• Abstraction of hardware/software capability used
  by graphics applications
  – Hardware: video card, …
  – Software: Direct3D reference device, …
Swap Chain
• Encapsulates two or more buffers used for
  rendering and display
• Front buffer
  – Presented to display device
• Back buffer
  – Render target
• Presents back buffer by swapping two buffers
• Properties
  – Size of render area, display refresh rate, display mode,
    surface format, …
HLSL
• High Level Shading Language for DirectX
• For writing codes for programmable shaders in
  Direct3D pipeline
• Implements series of shader models

Shader Model     Shader Profiles                                                  Direct3D support
Shader model 1   vs_1_1                                                           Direct3D 9
Shader model 2   ps_2_0, ps_2_x, vs_2_0, vs_2_x
Shader model 3   ps_3_0, vs_3_0
Shader model 4   gs_4_0, ps_4_0, vs_4_0, gs_4_1, ps_4_1, vs_4_1                   Direct3D 10
Shader model 5   cs_4_0, cs_4_1, cs_5_0, ds_5_0, gs_5_0, hs_5_0, ps_5_0, vs_5_0   Direct3D 11
Compiling HLSL
• Shader profile
  – Target for compiling shader

a. Compile at runtime
  – D3DX11CompileFromFile function to compile from
    HLSL file
  – D3DCompile function to compile HLSL code in
    memory

b. Compile offline
  – FXC: shader-compiler tool (effect-compiler tool)
COM Essentials
• Component Object Model
  –   Binary standard
  –   Platform-independent
  –   Distributed
  –   Object-oriented

• COM-based technologies
  – OLE
  – ActiveX
  – Many components in Windows
COM Interfaces
• Object exposes set of interfaces
• Interface consists of group of related methods
• Application (client) use object through interfaces

                         Applications


                      IMyInterfaceA     IMyInterfaceB

                          IUnknown


                         COM Object
IUnknown Interface
• Every object implements IUnknown interface
Method                  Description
QueryInterface          Retrieves pointers to the supported interfaces on object
AddRef                  Increments reference count for interface on object
Release                 Decrements reference count for interface on object


COM in C++                                          // unknwn.h

Interface                Abstract class             class IUnknown
                                                    {
Interface method         Pure virtual function      public:
                                                        virtual HRESULT QueryInterface (
Interface inheritance    Class derivation                   /* [in] */ REFIID riid,
                          – Interface inheritance           /* [out] */ void** ppvObject ) = 0;
                          – No code reuse               virtual ULONG AddRef() = 0;
                                                        virtual ULONG Release() = 0;
Interface pointer        Pointer to class           };
Using COM Objects
Users                        Developers
• Initialize COM library     • Publish interfaces
• Create object and obtain       – Documents describing behavior of
                                   interface methods
  pointer of interface
• Use interface methods      • Provide interface
• Release object               implementation (in binary form)


Example in C++
 IMyInterface* my;           bool CreateMyObject(IMyInterface** pp);
 CreateMyObject(&my);
                             class IMyInterface
 HRESULT hr;                 {
 hr = my->MyMethod(i);       public:
                                 virtual HRESULT MyMethod(int i) = 0;
 my->Release();              };
GUID
• Globally unique identifier
   – Unique reference number used as identifier
   – Implements universally unique identifier (UUID)
     standard
   – Represented by 32-character hexademical string
     (e.g., {21EC2020-3AEA-1069-A2DD-08002B30309D})
   – Usually stored as 128-bit integer

• Interface identifier (IID)
• Class identifier (CLSID)
Error Handling in COM
• HRESULT
  – 32-bit value used to            Internal structure
    describe the status
    after operation
                                  Return value/code              Description
                                  0x00000000 S_OK                Operation successful
                                  0x80004001 E_NOIMPL            Not implemented
                                  0x80004002 E_NOINTERFACE       Interface not supported
                                  0x80004004 E_ABORT             Operation aborted
                                  0x80004005 E_FAIL              Unspecified failure
                                  0x80070057 E_INVALIDARG        One or more arguments are invalid


                     Macro               Description
                     SUCCEEDED(hr)       TRUE if hr represents success status value; otherwise, FALSE
                     FAILED(hr)          TRUE if hr represents falied status value; otherwise, FALSE
Direct3D Return Codes
HRESULT                        Description
S_OK                           No error occurred.

S_FALSE                        Alternate success value, indicating a successful but nonstandard
                               completion (the precise meaning depends on context).
E_FAIL                         Attempted to create a device with the debug layer enabled and the layer
                               is not installed.
E_OUTOFMEMORY                  Direct3D could not allocate sufficient memory to complete the call.

E_INVALIDARG                   An invalid parameter was passed to the returning function.

D3DERR_INVALIDCALL             The method call is invalid. For example, a method's parameter may not
                               be a valid pointer.
D3D11_ERROR_FILE_NOT_FOUND     The file was not found.

D3D11_ERROR_TOO_MANY_UNIQUE_   There are too many unique instances of a particular type of state object.
STATE_OBJECTS
D3D11_ERROR_TOO_MANY_UNIQUE_   There are too many unique instances of a particular type of view object.
VIEW_OBJECTS

                                                                                        (not exhaustive)
Direct3D Pipeline
• Stages
    – Configured using API
• Shader stages
    – Programmable using HLSL

Stage             Abbr.   Description
Input-assembler   IA      Supplies data to pipeline
Vertex-shader     VS      Processes vertices
Rasterizer        RS      Converts vector data into pixels
Pixel-shader      PS      Generates per-pixel data
Output-merger     OM      Generates final pipeline result


                                                             (Note: Some stages are omitted for simplicity)
Input-Assembler Stage
• Primitive
  – Composed of one or more vertices
  – Point, line and triangle
  – Primitive types (or topologies)
     • Point list, line list, line strip, triangle list, triangle strip, …

• Reads input data from user-filled buffers and
  assembles data into primitives
• Attaches system-generated values
  – VertexID, PrimitiveID, InstanceID, …
Shader Stages
• Vertex/hull/domain/geometry/pixel-shader and
  compute-shader
• Built on common shader core
• Programmable with HLSL
 Classification                 Methods
 Creating shader object         ID3D11Device::Create[Vertex]Shader
 Setting shader to use          ID3D11DeviceContext::[VS]SetShader
 Setting up each shader stage   ID3D11DeviceContext::[VS]SetConstantBuffers
                                ID3D11DeviceContext::[VS]SetShaderResources
                                ID3D11DeviceContext::[VS]SetSamplers
                                ID3D11DeviceContext::CSSetUnorderedAccessViews
                                Note: [VS] means one of VS, HS, DS, GS, PS and CS, and
                                      [Vertex] one of Vertex, Hull, Domain, Geometry, Pixel and Compute
Vertex-Shader Stage
• Processes each vertex of primitives from IA
  – Performs per-vertex operations (transformations,
    skinning, morphing, per-vertex lighting, …)
• Single input vertex, single output vertex
  – Each vertex data can contain up to 16 vectors
  – Always run on all vertices
• Some texture methods available
  – Load, Sample, SampleCmpLevelZero, SampleGrad, …
• Mandatory stage
Rasterizer Stage
• Converts each primitive into pixels
  – Interpolating per-vertex values across primitive
• Performed operations
  – Clipping vertices to view frustum
  – Culling out back faces
  – Performing divide by z to provide perspective
    (input vertex positions assumed to be in
    homogeneous clip-space)
  – Mapping primitives to 2-D viewport
  – Determining how to invoke pixel shader
Pixel-Shader Stage
• Enables rich shading techniques and more
  – Per-pixel lighting, post-processing, ray-casting, …
• Processes each pixel from rasterizer stage
  – Interpolated per-pixel values as input
• Generated output
  – One or more colors (to be written to render targets)
  – Optional depth value
    (replacing the one interpolated by rasterizer)
• All texture methods available
Output-Merger Stage
• Generates final rendered pixel color
• Combines relevant information
   – Pipeline state, pixel data from PS, contents of render
     targets, contents of depth/stencil buffers, …

• Final step in pipeline
   – Determines visibility of pixels (depth-stencil testing)
   – Blends final pixel colors

Más contenido relacionado

La actualidad más candente

Basic structures in vhdl
Basic structures in vhdlBasic structures in vhdl
Basic structures in vhdl
Raj Mohan
 

La actualidad más candente (20)

Basic structures in vhdl
Basic structures in vhdlBasic structures in vhdl
Basic structures in vhdl
 
Vhdl 1 ppg
Vhdl 1 ppgVhdl 1 ppg
Vhdl 1 ppg
 
VHDL- data types
VHDL- data typesVHDL- data types
VHDL- data types
 
Vhdl new
Vhdl newVhdl new
Vhdl new
 
iOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIsiOS 101 - Xcode, Objective-C, iOS APIs
iOS 101 - Xcode, Objective-C, iOS APIs
 
Object Oriented Programming using C++ - Part 2
Object Oriented Programming using C++ - Part 2Object Oriented Programming using C++ - Part 2
Object Oriented Programming using C++ - Part 2
 
Sstic 2015 detailed_version_triton_concolic_execution_frame_work_f_saudel_jsa...
Sstic 2015 detailed_version_triton_concolic_execution_frame_work_f_saudel_jsa...Sstic 2015 detailed_version_triton_concolic_execution_frame_work_f_saudel_jsa...
Sstic 2015 detailed_version_triton_concolic_execution_frame_work_f_saudel_jsa...
 
Vhdl introduction
Vhdl introductionVhdl introduction
Vhdl introduction
 
Basics of Vhdl
Basics of VhdlBasics of Vhdl
Basics of Vhdl
 
Assembler
AssemblerAssembler
Assembler
 
Assembler
AssemblerAssembler
Assembler
 
C# for beginners
C# for beginnersC# for beginners
C# for beginners
 
Introduction toc sharp
Introduction toc sharpIntroduction toc sharp
Introduction toc sharp
 
Introduction to VHDL
Introduction to VHDLIntroduction to VHDL
Introduction to VHDL
 
How to design Programs using VHDL
How to design Programs using VHDLHow to design Programs using VHDL
How to design Programs using VHDL
 
Introduction to-csharp
Introduction to-csharpIntroduction to-csharp
Introduction to-csharp
 
Vhdl basic unit-2
Vhdl basic unit-2Vhdl basic unit-2
Vhdl basic unit-2
 
Vhdl
VhdlVhdl
Vhdl
 
Crash course in verilog
Crash course in verilogCrash course in verilog
Crash course in verilog
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - C
 

Similar a 02 direct3 d_pipeline

Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
DefCamp
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
Sang Don Kim
 
The Next Mainstream Programming Language: A Game Developer's Perspective
The Next Mainstream Programming Language: A Game Developer's PerspectiveThe Next Mainstream Programming Language: A Game Developer's Perspective
The Next Mainstream Programming Language: A Game Developer's Perspective
kfrdbs
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/Invoke
Dmitri Nesteruk
 
Gdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glGdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_gl
changehee lee
 
Shape12 6
Shape12 6Shape12 6
Shape12 6
pslulli
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eve
chiportal
 
Game development
Game developmentGame development
Game development
Asido_
 

Similar a 02 direct3 d_pipeline (20)

3 boyd direct3_d12 (1)
3 boyd direct3_d12 (1)3 boyd direct3_d12 (1)
3 boyd direct3_d12 (1)
 
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
 
NvFX GTC 2013
NvFX GTC 2013NvFX GTC 2013
NvFX GTC 2013
 
The Next Mainstream Programming Language: A Game Developer's Perspective
The Next Mainstream Programming Language: A Game Developer's PerspectiveThe Next Mainstream Programming Language: A Game Developer's Perspective
The Next Mainstream Programming Language: A Game Developer's Perspective
 
Graphics Libraries
Graphics LibrariesGraphics Libraries
Graphics Libraries
 
arduinoedit.pptx
arduinoedit.pptxarduinoedit.pptx
arduinoedit.pptx
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/Invoke
 
Android RenderScript
Android RenderScriptAndroid RenderScript
Android RenderScript
 
Gdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glGdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_gl
 
Rider - Taking ReSharper out of Process
Rider - Taking ReSharper out of ProcessRider - Taking ReSharper out of Process
Rider - Taking ReSharper out of Process
 
Introduction to parallel computing using CUDA
Introduction to parallel computing using CUDAIntroduction to parallel computing using CUDA
Introduction to parallel computing using CUDA
 
Shape12 6
Shape12 6Shape12 6
Shape12 6
 
JIT Spraying Never Dies - Bypass CFG By Leveraging WARP Shader JIT Spraying.pdf
JIT Spraying Never Dies - Bypass CFG By Leveraging WARP Shader JIT Spraying.pdfJIT Spraying Never Dies - Bypass CFG By Leveraging WARP Shader JIT Spraying.pdf
JIT Spraying Never Dies - Bypass CFG By Leveraging WARP Shader JIT Spraying.pdf
 
RenderScript
RenderScriptRenderScript
RenderScript
 
The next generation of GPU APIs for Game Engines
The next generation of GPU APIs for Game EnginesThe next generation of GPU APIs for Game Engines
The next generation of GPU APIs for Game Engines
 
Track c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eveTrack c-High speed transaction-based hw-sw coverification -eve
Track c-High speed transaction-based hw-sw coverification -eve
 
Madeo - a CAD Tool for reconfigurable Hardware
Madeo - a CAD Tool for reconfigurable HardwareMadeo - a CAD Tool for reconfigurable Hardware
Madeo - a CAD Tool for reconfigurable Hardware
 
VHDL_VIKAS.pptx
VHDL_VIKAS.pptxVHDL_VIKAS.pptx
VHDL_VIKAS.pptx
 
Game development
Game developmentGame development
Game development
 

Último

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 

02 direct3 d_pipeline

  • 1. Introduction to DirectX Programming Direct3D Pipeline
  • 2. Contents • GPU programming model • Introduction to DirectX – Direct3D – DXGI – HLSL – COM essentials • Direct3D pipeline
  • 3. GPU Architecture • Well-suited for data-parallel computations • Lower requirement for sophisticated flow control
  • 4. CPU-GPU Relationship • GPU: coprocessor with its own memory CPU GPU Core Core Core Core PCIe x16 2.0 (8 GB/s) (~150 GB/s) IMC (~30 GB/s) GPU Memory Main Memory
  • 5. Programming with GPU • Various APIs and technologies – Graphics programming – General-purpose GPU programming Applications DirectX OpenGL CUDA OpenCL GPU
  • 6. Introduction to DirectX • Set of low-level APIs for creating high- performance multimedia applications, on Microsoft platforms (Windows, Xbox, …) • Components 2-D and 3-D graphics Direct3D Sound XAudio2, X3DAudio, XACT Input XInput • DirectX SDK (Software Development Kit) – Libraries, header files, utilities, sample codes and docs
  • 7. Direct3D • API for rendering 2-D and 3-D graphics • Hardware acceleration if available • Advanced graphics capabilities – Graphics pipeline, z-buffering, anti-aliasing, alpha blending, mipmapping, … • Abstractions – Pipeline stages, device, resource, swap chain, … • API as set of COM-compliant objects
  • 8. DXGI • DirectX Graphics Infrastructure – Manages low-level tasks independent of DirectX graphics runtime – Common framework for future graphics components • Supported tasks – Enumerating adapters – Managing swap chain – Handling window resizing – Choosing DXGI output and size – Debugging in full-screen mode
  • 9. Adapter • Abstraction of hardware/software capability used by graphics applications – Hardware: video card, … – Software: Direct3D reference device, …
  • 10. Swap Chain • Encapsulates two or more buffers used for rendering and display • Front buffer – Presented to display device • Back buffer – Render target • Presents back buffer by swapping two buffers • Properties – Size of render area, display refresh rate, display mode, surface format, …
  • 11. HLSL • High Level Shading Language for DirectX • For writing codes for programmable shaders in Direct3D pipeline • Implements series of shader models Shader Model Shader Profiles Direct3D support Shader model 1 vs_1_1 Direct3D 9 Shader model 2 ps_2_0, ps_2_x, vs_2_0, vs_2_x Shader model 3 ps_3_0, vs_3_0 Shader model 4 gs_4_0, ps_4_0, vs_4_0, gs_4_1, ps_4_1, vs_4_1 Direct3D 10 Shader model 5 cs_4_0, cs_4_1, cs_5_0, ds_5_0, gs_5_0, hs_5_0, ps_5_0, vs_5_0 Direct3D 11
  • 12. Compiling HLSL • Shader profile – Target for compiling shader a. Compile at runtime – D3DX11CompileFromFile function to compile from HLSL file – D3DCompile function to compile HLSL code in memory b. Compile offline – FXC: shader-compiler tool (effect-compiler tool)
  • 13. COM Essentials • Component Object Model – Binary standard – Platform-independent – Distributed – Object-oriented • COM-based technologies – OLE – ActiveX – Many components in Windows
  • 14. COM Interfaces • Object exposes set of interfaces • Interface consists of group of related methods • Application (client) use object through interfaces Applications IMyInterfaceA IMyInterfaceB IUnknown COM Object
  • 15. IUnknown Interface • Every object implements IUnknown interface Method Description QueryInterface Retrieves pointers to the supported interfaces on object AddRef Increments reference count for interface on object Release Decrements reference count for interface on object COM in C++ // unknwn.h Interface Abstract class class IUnknown { Interface method Pure virtual function public: virtual HRESULT QueryInterface ( Interface inheritance Class derivation /* [in] */ REFIID riid, – Interface inheritance /* [out] */ void** ppvObject ) = 0; – No code reuse virtual ULONG AddRef() = 0; virtual ULONG Release() = 0; Interface pointer Pointer to class };
  • 16. Using COM Objects Users Developers • Initialize COM library • Publish interfaces • Create object and obtain – Documents describing behavior of interface methods pointer of interface • Use interface methods • Provide interface • Release object implementation (in binary form) Example in C++ IMyInterface* my; bool CreateMyObject(IMyInterface** pp); CreateMyObject(&my); class IMyInterface HRESULT hr; { hr = my->MyMethod(i); public: virtual HRESULT MyMethod(int i) = 0; my->Release(); };
  • 17. GUID • Globally unique identifier – Unique reference number used as identifier – Implements universally unique identifier (UUID) standard – Represented by 32-character hexademical string (e.g., {21EC2020-3AEA-1069-A2DD-08002B30309D}) – Usually stored as 128-bit integer • Interface identifier (IID) • Class identifier (CLSID)
  • 18. Error Handling in COM • HRESULT – 32-bit value used to Internal structure describe the status after operation Return value/code Description 0x00000000 S_OK Operation successful 0x80004001 E_NOIMPL Not implemented 0x80004002 E_NOINTERFACE Interface not supported 0x80004004 E_ABORT Operation aborted 0x80004005 E_FAIL Unspecified failure 0x80070057 E_INVALIDARG One or more arguments are invalid Macro Description SUCCEEDED(hr) TRUE if hr represents success status value; otherwise, FALSE FAILED(hr) TRUE if hr represents falied status value; otherwise, FALSE
  • 19. Direct3D Return Codes HRESULT Description S_OK No error occurred. S_FALSE Alternate success value, indicating a successful but nonstandard completion (the precise meaning depends on context). E_FAIL Attempted to create a device with the debug layer enabled and the layer is not installed. E_OUTOFMEMORY Direct3D could not allocate sufficient memory to complete the call. E_INVALIDARG An invalid parameter was passed to the returning function. D3DERR_INVALIDCALL The method call is invalid. For example, a method's parameter may not be a valid pointer. D3D11_ERROR_FILE_NOT_FOUND The file was not found. D3D11_ERROR_TOO_MANY_UNIQUE_ There are too many unique instances of a particular type of state object. STATE_OBJECTS D3D11_ERROR_TOO_MANY_UNIQUE_ There are too many unique instances of a particular type of view object. VIEW_OBJECTS (not exhaustive)
  • 20. Direct3D Pipeline • Stages – Configured using API • Shader stages – Programmable using HLSL Stage Abbr. Description Input-assembler IA Supplies data to pipeline Vertex-shader VS Processes vertices Rasterizer RS Converts vector data into pixels Pixel-shader PS Generates per-pixel data Output-merger OM Generates final pipeline result (Note: Some stages are omitted for simplicity)
  • 21. Input-Assembler Stage • Primitive – Composed of one or more vertices – Point, line and triangle – Primitive types (or topologies) • Point list, line list, line strip, triangle list, triangle strip, … • Reads input data from user-filled buffers and assembles data into primitives • Attaches system-generated values – VertexID, PrimitiveID, InstanceID, …
  • 22. Shader Stages • Vertex/hull/domain/geometry/pixel-shader and compute-shader • Built on common shader core • Programmable with HLSL Classification Methods Creating shader object ID3D11Device::Create[Vertex]Shader Setting shader to use ID3D11DeviceContext::[VS]SetShader Setting up each shader stage ID3D11DeviceContext::[VS]SetConstantBuffers ID3D11DeviceContext::[VS]SetShaderResources ID3D11DeviceContext::[VS]SetSamplers ID3D11DeviceContext::CSSetUnorderedAccessViews Note: [VS] means one of VS, HS, DS, GS, PS and CS, and [Vertex] one of Vertex, Hull, Domain, Geometry, Pixel and Compute
  • 23. Vertex-Shader Stage • Processes each vertex of primitives from IA – Performs per-vertex operations (transformations, skinning, morphing, per-vertex lighting, …) • Single input vertex, single output vertex – Each vertex data can contain up to 16 vectors – Always run on all vertices • Some texture methods available – Load, Sample, SampleCmpLevelZero, SampleGrad, … • Mandatory stage
  • 24. Rasterizer Stage • Converts each primitive into pixels – Interpolating per-vertex values across primitive • Performed operations – Clipping vertices to view frustum – Culling out back faces – Performing divide by z to provide perspective (input vertex positions assumed to be in homogeneous clip-space) – Mapping primitives to 2-D viewport – Determining how to invoke pixel shader
  • 25. Pixel-Shader Stage • Enables rich shading techniques and more – Per-pixel lighting, post-processing, ray-casting, … • Processes each pixel from rasterizer stage – Interpolated per-pixel values as input • Generated output – One or more colors (to be written to render targets) – Optional depth value (replacing the one interpolated by rasterizer) • All texture methods available
  • 26. Output-Merger Stage • Generates final rendered pixel color • Combines relevant information – Pipeline state, pixel data from PS, contents of render targets, contents of depth/stencil buffers, … • Final step in pipeline – Determines visibility of pixels (depth-stencil testing) – Blends final pixel colors