Top Banner

Click here to load reader

GDC : Mar16.pdf

Jan 02, 2017

ReportDownload

Documents

duonganh

  • Copyright Khronos Group 2016 - Page 142

    Swapchains Unchained!(What you need to know about Vulkan WSI)

    Alon Or-bach, Chair, Vulkan Window System Integration Sub-Group March 2016

  • Copyright Khronos Group 2016 - Page 143

    Intro to Vulkan Window System Integration Explicit control for acquisition and

    presentation of images - Designed to fit the Vulkan API and todays

    compositing window systems

    Not all extensions are supported by every platform- You MUST check and enable the extensions

    your app/engine uses!!!

    Todays presentation should help you get presentation working- Learn how to present through a swapchain- Overview of Vulkan objects used by the WSI

    extensions

    WSI Jargon Buster Platform

    Our terminology for an OS

    / window system e.g.

    Android, Windows,

    Wayland, X11 via XCB

    Presentation EngineThe platforms compositor or display engine

    ApplicationYour app or game engine

  • Copyright Khronos Group 2016 - Page 144

    How many WSI extensions are there? Two cross-platform instance extensions- VK_KHR_surface- VK_KHR_display

    Six (platform) instance extensions- VK_KHR_android_surface- VK_KHR_mir_surface- VK_KHR_wayland_surface- VK_KHR_win32_surface- VK_KHR_xcb_surface- VK_KHR_xlib_surface

    Two cross-platform device extensions- VK_KHR_swapchain- VK_KHR_display_swapchain

  • Copyright Khronos Group 2016 - Page 145

    Vulkan Surfaces VkSurfaceKHR- Vulkans way to encapsulate a native

    window / surface

    Platform-independent surface queries- Find out crucial information about your

    surfaces properties- e.g., if presentation is supported by a

    particular queue on a particular device

    - Some platforms provide additional queries An implementation may support multiple

    platforms- e.g., both xlib and xcb

    Physical Device A

    Platform X

    Queue Family 2

    Queue Family 1 Queue

    Family 0

    Platform Y

    Physical Device B

    Queue Family 1Queue

    Family 0

    Surface from

    Platform X

    Physical Device C

    Queue Family 1Queue

    Family 0

  • Copyright Khronos Group 2016 - Page 146

    Vulkan Swapchains: VK_KHR_swapchain Array of presentable images associated with

    a surface- Application requests a minimum number

    of presentable images

    - Implementation creates at least that number

    - Implementation may have a limit Upfront allocation of presentable images- No allocation hitching at crucial moment- Pre-record fixed content command buffers

    Present mode determines behavior- FIFO support mandatory- Platforms can offer mailbox,

    immediate, FIFO relaxed

    const VkSwapchainCreateInfoKHR createInfo ={VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, // sTypeNULL, // pNext0, // flagsmySurface, // surfacedesiredNumberOfPresentableImages, // minImageCountsurfaceFormat, // imageFormatsurfaceColorSpace, // imageColorSpacemyExtent, // imageExtent1, // imageArrayLayersVK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, // imageUsageVK_SHARING_MODE_EXCLUSIVE, // imageSharingMode0, // queueFamilyIndexCountNULL, // pQueueFamilyIndicessurfaceProperties.currentTransform, // preTransformVK_COMPOSITE_ALPHA_INHERIT_BIT_KHR, // compositeAlphaswapchainPresentMode, // presentModeVK_TRUE, // clippedVK_NULL_HANDLE // oldSwapchain};

  • Copyright Khronos Group 2016 - Page 147

    Vulkan Swapchains: Theyre good! Application knows which image within a

    swapchain it is presenting- Content of image preserved between

    presents

    Application is responsible for explicitly recreating swapchains - no surprises- Platform informs app if current swapchain- Suboptimal: e.g. after window resize,

    swapchain still usable for present via image

    scaling

    - Surface Lost: swapchain no longer usable for present

    - Application is responsible to create a new swapchain

  • Copyright Khronos Group 2016 - Page 148

    Vulkan Swapchains: Theyre jolly good! Presenting and acquiring are separate

    operations- No need to submit a new image to acquire

    another one, unless presentation engine

    cannot release it

    Application must only modify presentable images it has acquired

    Presentation engine must only display presentable images that have been presented!

    Stalls in frame loop are very bad!

  • Copyright Khronos Group 2016 - Page 149

    VK_KHR__surface

    VK_KHR_surface

    VK_KHR_swapchain

    Platform-specific APIs

    Steps to setup your presentable images1 Create a native window/surface

    2 Create a Vulkan surface

    3 Query information about your surface

    4 Create a Vulkan swapchain

    5 Get your presentable images

  • Copyright Khronos Group 2016 - Page 150

    VK_KHR_swapchain

    Vulkan Frame Loop as easy as 1-2-3!

    2 Submit command buffer(s) for that image

    1 Acquire the next presentable image 3 Present the image

    0 Create your swapchain

    LegendSetup

    Steady-state

    Response to suboptimal

    / surface_lost

  • Copyright Khronos Group 2016 - Page 151

    Vulkan Displays: VK_KHR_display Vulkans way to discover display devices

    (screens, panels) outside a window system- Reminder: Not supported on all platforms

    Defines VkDisplayKHR and VkDisplayModeKHR objects- Represent the display devices and the

    modes they support connected to a

    VkPhysicalDevice

    - Determine if a display supports multiple planes that are blended together

    Enables creation of a VkSurfaceKHR to represent a display plane

    Physical Device

    Surface

    Display 0

    Plane 2Plane 1

    Plane 0

    Display Mode 1Display

    Mode 0

    Display 1

    Display Mode 1Display

    Mode 0

  • Copyright Khronos Group 2016 - Page 152

    VK_KHR_display_swapchain Extends the information provided at vkQueuePresentKHR- What region to present from the swapchain image- What region to present to on the display- Whether the display should persist the image

    Adds ability to create a shared swapchain- Swapchain that takes multiple VkSwapchainCreateInfoKHR structs- Allows multiple displays to be presented to simultaneously- No guarantee that presents are atomic ...presently!

  • Copyright Khronos Group 2016 - Page 153

    Any question?

    [email protected]@alonorbach (disclaimers apply!)

  • Copyright Khronos Group 2016 - Page 1

    LunarG SDK for VulkanKaren Ghavam, CEO

    Karl Schultz, Principal EngineerJon Ashburn, Principal Engineer

  • Copyright Khronos Group 2016 - Page 2

    Enter the Raffle for your prize!Congratulations!

    You are the recipient of the Vulkan Programming Guide, courtesy of LunarG!

    Is your OpenGL Programming Guide getting lonely? Well, it will soon have a companion. In August 2016, when the Vulkan Programming Guide becomes available, LunarG will ship it directly to you!

    In the meantime, visit LunarXchange (Vulkan.lunarg.com) for the LunarG SDK for Vulkan, and accept this book bag, anxiously awaiting its Vulkan Programming Guide.

  • Copyright Khronos Group 2016 - Page 3

    LunarG SDK Loader Binary Validation Layer Libraries Vulkan trace and replay tools- vktrace- vkreplay

    SPIR-V Tools- GLSL Validator - SPIR-V Disassembler and Assembler - SPIR-V Remapper

    RenderDoc* Sample Programs

    *For a detailed demonstration of RenderDoc dont miss:Practical Development for Vulkan (presented by Valve Software). Thursday. 12:45 1:45. Room 3009, West Hall

  • Copyright Khronos Group 2016 - Page 4

    Download the LunarG SDK for Vulkan at LunarXchange: vulkan.lunarg.com

    Version 1.0.5.0 now available!

  • Copyright Khronos Group 2016 - Page 5

    The Power of a Layered Ecosystem

    Development pathValidation

    layer

    Debug layer

    Other layers

    Production path

    Vulkan application

    Installable Client Driver

    Vulkan application

    Installable Client Driver

    Loader

    Loader

  • Copyright Khronos Group 2016 - Page 6

    Layers: Fully IntegratedProgrammatic Approach

    Vulkan application

    Debug Report

    Callback

    Installable Client Driver

    Layer

    Application supplies list

    of layers

    Application handles messages in

    callback

    Layers report results as

    messages

    Loader

  • Copyright Khronos Group 2016 - Page 7

    Layers: Externally ActivatedAd-hoc Approach

    Vulkan application

    Debug Report

    Callback

    Installable Client Driver

    Layer

    User sets environment variables:

    VK_INSTANCE_LAYER=layer name

    Default Debug Report writes to output stream

    Layers report results as

    messages

    Loader

    Layer Settings File

  • Copyright Khronos Group 2016 - Page 8

    Demo Well Be Using

    HologramBy

    Chia-I Wu (olv)

    Well-written Vulkan demo Simulation of 5000 moving objects Demonstrates multi-threaded command

    buffer recording Can be found in: https://github.com/LunarG/VulkanSamples

  • Copyright Khronos Group 2016 - Page 9

    Demo!

    Watch the demo for a minute or so

  • Copyright Khronos Group 2016 - Page 10

    A Few Hologram Internals Object Data

    5000 ShaderParamBlocks

    struct ShaderParamBlock {float light_pos[4];float light_color[4];float model[4 * 4];float view_projection[4 * 4];

    };

    One ShaderParamBlock per Object

    For Each Frame and For Each Object: Modify ShaderParamBlock BindDescriptorSet

    Two Frames of Object Data

  • Copyright Khronos Group 2016 - Page 11

    Modify DemoLets add code to modulate the transparency