1
Preparing for Vulkan
@jcant0n
2
• 2013 AMD y DICE trabajan en Mantle
Un poco de historia
3
• 2013 AMD y DICE trabajan en Mantle
• February 2014 Nvidia new DX11 drivers
Un poco de historia
4
• 2013 AMD y DICE trabajan en Mantle
• February 2014 Nvidia new DX11 drivers
• March 2014 GDC DirectX 12
Un poco de historia
5
• 2013 AMD y DICE trabajan en Mantle
• February 2014 Nvidia new DX11 drivers
• March 2014 GDC DirectX 12
• June 2014 Apple anuncia Metal
Un poco de historia
6
• 2013 AMD y DICE trabajan en Mantle
• February 2014 Nvidia new DX11 drivers
• March 2014 GDC DirectX 12
• June 2014 Apple anuncia Metal
• July 2014 Khronos Group, call for Participants
Un poco de historia
7
• 2013 AMD y DICE trabajan en Mantle
• February 2014 Nvidia new DX11 drivers
• March 2014 GDC DirectX 12
• June 2014 Apple anuncia Metal
• July 2014 Khronos Group, call for Participants
• June 2015 Metal on MacOS
Un poco de historia
8
• 2013 AMD y DICE trabajan en Mantle
• February 2014 Nvidia new DX11 drivers
• March 2014 GDC DirectX 12
• June 2014 Apple anuncia Metal
• July 2014 Khronos Group, call for Participants
• June 2015 Metal on MacOS
• GDC 2015 Khronos Group presenta Vulkan
Un poco de historia
9
Vulkan Model
10
OpenGL Driver
Application
Vulkan Driver
Application
• Simpler drivers for low-overhead
• Cross vendor portability
• Unified API for mobile and Desktop
• Easy error management
• No driver compile shaders, SPIR-V
Developers
11
12
Developers
Developers
13
Developers
14
1. Low level memory management
2. Reducir comunicación CPU -> GPU
3. Multithreading and multiGPU API
Objetivos
15
Low level memory
16
CPU GPU
GPU
Buffers and Textures
CPU
Staging
Buffer
GPU
Device
buffer
vkCreateBuffer
vkGetBufferMemoryRequirements
vkAllocateMemory
vkBindBufferMemory
Resource Layouts
17
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
0 1 2 3 4 5 6 …
VK_IMAGE_LAYOUT_UNDEFINED
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
VK_IMAGE_LAYOUT_GENERAL
Multithreading API
18
Update work
State change
State change
Draw Calls
State change
Draw Calls
Driver call
Driver call
Driver call
Driver call
Driver call
Driver call
Driver call
CPU 1 CPU 2 CPU 3 CPU 4
GPU
Bored…
Reducir CPU -> GPU
19
GL.Enable(EnableCap.CullFace); GL.FrontFace(FrontFaceDirection)
GL.PolygonMode(MaterialFace.FrontAndBack, FillMode)
GL.Enable(EnableCap.ScissorTest) GL.PolygonOffset(DepthBias, SlopeScaleDepthBias)
GL.Enable(DepthClamp)
Rasterization State
Pipeline State Object
Rasterization
State
Reducir CPU -> GPU
20
Color Blend
State
Depth Stencil
State
Multisample
State
Dynamic State
Vertex Input
State
Input Assembly
State
Viewport State
Reducir CPU -> GPU
21
Bind
Pipeline A
Bind
Set #0
Bind
Set #1
Effective
State
Bind
Pipeline B
Bind
Set #1
Effective
State
Bind
Pipeline C
Effective
State
Set #0
Set #1 none
Reducir CPU -> GPU
22
Device
Queue
Command Buffer
RenderPass
Begin
Bind
Vertex/Index
Set Viewport Bind Pipeline
Bind Descriptor
Set
Draw
RenderPass
End
GPU Multiengine
23
Graphics
engine
Compute
Engine
Copy engine
Command
List
Command
List
Command
List
Command
List
Command
List
Command
List
Command
List
Command
List
Command
List
Graphics
Queue
Compute
Queue
Copy
Queue
Multithreading API
24
Update work
Write
Command
Buffers
CPU 1
Update work
Write
Command
Buffers
CPU 2
Update work
Write
Command
Buffers
CPU 3
CPU 4 Thread
coordination
Submit to
Queue
Swapping
Game
work
GPU
• Leer algún libro o tutorial https://vulkan-tutorial.com/
• Bichear código de otros primero
• Tener muchísima paciencia
• Para todo lo demás
Recomendaciones
25
• ¿Cómo estáis percibiendo este cambio de APIs?
• ¿Algún “truquillo” que compartir?
• ¿Se nota la diferencia de performance¿
• ¿Porqué Apple retira soporte a OpenGL 2018?
• ¿En qué lenguaje programas ahora tus shaders?
Debate
26
@jcant0n
27
Gracias

Freakend 2019: Preparing for Vulkan

  • 1.
  • 2.
  • 3.
    • 2013 AMDy DICE trabajan en Mantle Un poco de historia 3
  • 4.
    • 2013 AMDy DICE trabajan en Mantle • February 2014 Nvidia new DX11 drivers Un poco de historia 4
  • 5.
    • 2013 AMDy DICE trabajan en Mantle • February 2014 Nvidia new DX11 drivers • March 2014 GDC DirectX 12 Un poco de historia 5
  • 6.
    • 2013 AMDy DICE trabajan en Mantle • February 2014 Nvidia new DX11 drivers • March 2014 GDC DirectX 12 • June 2014 Apple anuncia Metal Un poco de historia 6
  • 7.
    • 2013 AMDy DICE trabajan en Mantle • February 2014 Nvidia new DX11 drivers • March 2014 GDC DirectX 12 • June 2014 Apple anuncia Metal • July 2014 Khronos Group, call for Participants Un poco de historia 7
  • 8.
    • 2013 AMDy DICE trabajan en Mantle • February 2014 Nvidia new DX11 drivers • March 2014 GDC DirectX 12 • June 2014 Apple anuncia Metal • July 2014 Khronos Group, call for Participants • June 2015 Metal on MacOS Un poco de historia 8
  • 9.
    • 2013 AMDy DICE trabajan en Mantle • February 2014 Nvidia new DX11 drivers • March 2014 GDC DirectX 12 • June 2014 Apple anuncia Metal • July 2014 Khronos Group, call for Participants • June 2015 Metal on MacOS • GDC 2015 Khronos Group presenta Vulkan Un poco de historia 9
  • 10.
    Vulkan Model 10 OpenGL Driver Application VulkanDriver Application • Simpler drivers for low-overhead • Cross vendor portability • Unified API for mobile and Desktop • Easy error management • No driver compile shaders, SPIR-V
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
    1. Low levelmemory management 2. Reducir comunicación CPU -> GPU 3. Multithreading and multiGPU API Objetivos 15
  • 16.
    Low level memory 16 CPUGPU GPU Buffers and Textures CPU Staging Buffer GPU Device buffer vkCreateBuffer vkGetBufferMemoryRequirements vkAllocateMemory vkBindBufferMemory
  • 17.
    Resource Layouts 17 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL 01 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 … VK_IMAGE_LAYOUT_UNDEFINED VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL VK_IMAGE_LAYOUT_PRESENT_SRC_KHR VK_IMAGE_LAYOUT_GENERAL
  • 18.
    Multithreading API 18 Update work Statechange State change Draw Calls State change Draw Calls Driver call Driver call Driver call Driver call Driver call Driver call Driver call CPU 1 CPU 2 CPU 3 CPU 4 GPU Bored…
  • 19.
    Reducir CPU ->GPU 19 GL.Enable(EnableCap.CullFace); GL.FrontFace(FrontFaceDirection) GL.PolygonMode(MaterialFace.FrontAndBack, FillMode) GL.Enable(EnableCap.ScissorTest) GL.PolygonOffset(DepthBias, SlopeScaleDepthBias) GL.Enable(DepthClamp) Rasterization State
  • 20.
    Pipeline State Object Rasterization State ReducirCPU -> GPU 20 Color Blend State Depth Stencil State Multisample State Dynamic State Vertex Input State Input Assembly State Viewport State
  • 21.
    Reducir CPU ->GPU 21 Bind Pipeline A Bind Set #0 Bind Set #1 Effective State Bind Pipeline B Bind Set #1 Effective State Bind Pipeline C Effective State Set #0 Set #1 none
  • 22.
    Reducir CPU ->GPU 22 Device Queue Command Buffer RenderPass Begin Bind Vertex/Index Set Viewport Bind Pipeline Bind Descriptor Set Draw RenderPass End
  • 23.
  • 24.
    Multithreading API 24 Update work Write Command Buffers CPU1 Update work Write Command Buffers CPU 2 Update work Write Command Buffers CPU 3 CPU 4 Thread coordination Submit to Queue Swapping Game work GPU
  • 25.
    • Leer algúnlibro o tutorial https://vulkan-tutorial.com/ • Bichear código de otros primero • Tener muchísima paciencia • Para todo lo demás Recomendaciones 25
  • 26.
    • ¿Cómo estáispercibiendo este cambio de APIs? • ¿Algún “truquillo” que compartir? • ¿Se nota la diferencia de performance¿ • ¿Porqué Apple retira soporte a OpenGL 2018? • ¿En qué lenguaje programas ahora tus shaders? Debate 26
  • 27.