Zum Hauptinhalt springen
Nicht aus der Schweiz? Besuchen Sie lehmanns.de

Learning Vulkan (eBook)

eBook Download: EPUB
2016
466 Seiten
Packt Publishing (Verlag)
978-1-78646-084-4 (ISBN)

Lese- und Medienproben

Learning Vulkan -  Singh Parminder Singh
Systemvoraussetzungen
28,79 inkl. MwSt
(CHF 28,10)
Der eBook-Verkauf erfolgt durch die Lehmanns Media GmbH (Berlin) zum Preis in Euro inkl. MwSt.
  • Download sofort lieferbar
  • Zahlungsarten anzeigen

Vulkan, the next generation graphics and compute API, is the latest offering by Khronos. This API is the successor of OpenGL and unlike OpenGL, it offers great flexibility and high performance capabilities to control modern GPU devices. With this book, you'll get great insights into the workings of Vulkan and how you can make stunning graphics run with minimum hardware requirements.

We begin with a brief introduction to the Vulkan system and show you its distinct features with the successor to the OpenGL API. First, you will see how to establish a connection with hardware devices to query the available queues, memory types, and capabilities offered. Vulkan is verbose, so before diving deep into programing, you'll get to grips with debugging techniques so even first-timers can overcome error traps using Vulkan's layer and extension features.

You'll get a grip on command buffers and acquire the knowledge to record various operation commands into command buffer and submit it to a proper queue for GPU processing. We'll take a detailed look at memory management and demonstrate the use of buffer and image resources to create drawing textures and image views for the presentation engine and vertex buffers to store geometry information.

You'll get a brief overview of SPIR-V, the new way to manage shaders, and you'll define the drawing operations as a single unit of work in the Render pass with the help of attachments and subpasses. You'll also create frame buffers and build a solid graphics pipeline, as well as making use of the synchronizing mechanism to manage GPU and CPU hand-shaking.

By the end, you'll know everything you need to know to get your hands dirty with the coolest Graphics API on the block.


Discover how to build impressive 3D graphics with the next-generation graphics API-VulkanAbout This BookGet started with the Vulkan API and its programming techniques using the easy-to-follow examples to create stunning 3D graphicsUnderstand memory management in Vulkan and implement image and buffer resourcesGet hands-on with the drawing process and synchronization, and render a 3D graphics scene with the Vulkan graphics pipelineWho This Book Is ForThis book is ideal for graphic programmers who want to get up and running with Vulkan. It's also great for programmers who have experience with OpenGL and other graphic APIs who want to take advantage of next generation APIs. A good knowledge of C/C++ is expected.What You Will LearnLearn fundamentals of Vulkan programing model to harness the power of modern GPU devices.Implement device, command buffer and queues to get connected with the physical hardware.Explore various validation layers and learn how to use it for debugging Vulkan application.Get a grip on memory management to control host and device memory operations.Understand and implement buffer and image resource types in Vulkan.Define drawing operations in the Render pass and implement graphics pipeline.Manage GLSL shader using SPIR-V and update the shader resources with descriptor sets and push constants.Learn the drawing process, manage resources with synchronization objects and render 3D scene output on screen with Swapchain.Bring realism to your rendered 3D scene with textures, and implement linear and optimal texturesIn DetailVulkan, the next generation graphics and compute API, is the latest offering by Khronos. This API is the successor of OpenGL and unlike OpenGL, it offers great flexibility and high performance capabilities to control modern GPU devices. With this book, you'll get great insights into the workings of Vulkan and how you can make stunning graphics run with minimum hardware requirements.We begin with a brief introduction to the Vulkan system and show you its distinct features with the successor to the OpenGL API. First, you will see how to establish a connection with hardware devices to query the available queues, memory types, and capabilities offered. Vulkan is verbose, so before diving deep into programing, you'll get to grips with debugging techniques so even first-timers can overcome error traps using Vulkan's layer and extension features.You'll get a grip on command buffers and acquire the knowledge to record various operation commands into command buffer and submit it to a proper queue for GPU processing. We'll take a detailed look at memory management and demonstrate the use of buffer and image resources to create drawing textures and image views for the presentation engine and vertex buffers to store geometry information.You'll get a brief overview of SPIR-V, the new way to manage shaders, and you'll define the drawing operations as a single unit of work in the Render pass with the help of attachments and subpasses. You'll also create frame buffers and build a solid graphics pipeline, as well as making use of the synchronizing mechanism to manage GPU and CPU hand-shaking.By the end, you'll know everything you need to know to get your hands dirty with the coolest Graphics API on the block.Style and approachThis book takes a practical approach to guide you through the Vulkan API, and you will get to build an application throughout the course of the book. Since you are expected to be familiar with C/C++, there is not much hand-holding throughout the course of the book.

Getting started with the Vulkan programming model


Let's discuss the Vulkan programming model in detail. Here, the end user, considering he or she is a total beginner, will be able to understand the following concepts:

  • The Vulkan programming model
  • The rendering execution model, which will be described using a pseudo step-by-step approach
  • How Vulkan works

The following diagram shows a top-down approach of the Vulkan application programming model; we will understand this process in detail and also delve into the sublevel components and their functionalities:

Hardware initialization


When a Vulkan application starts, its very first job is the initialization of the hardware. Here, the application activates the Vulkan drivers by communicating with the loader. The following diagram represents a block diagram of a Loader with its subcomponents:

Loader: A loader is a piece of code used in the application start-up to locate the Vulkan drivers in a system in a unified way across platforms. The following are the responsibilities of a loader:

  • Locating drivers: As its primary job, a loader knows where to search for drivers in the given system. It finds the correct driver and loads it.
  • Platform-independent: Initializing Vulkan is consistent across all platforms. Unlike OpenGL, where creating a context requires working with a different window system API for each environment, EGL, GLX, and WGL. Platform differences in Vulkan are expressed as extensions.
  • Injectable layers: A loader supports a layered architecture and provides the capability to inject various layers at runtime. The big improvement is that the driver need not do any of the work (or retain any of the states it would need to do the work) in determining whether the application's use of the API is valid. Therefore, it's advisable to turn on the selected injectable layers, as per application requirements, during the development stage and turn them off at the deployment stage. For example, injectable layers can offer the following:
    • Tracing the Vulkan API commands
    • Capturing rendered scenes and executing them later
    • Error and validation for debugging purposes

The Vulkan application first performs a handshake with the loader library and initializes the Vulkan implementation driver. The loader library loads Vulkan APIs dynamically. The loader also offers a mechanism that allows the automatic loading of specific layers into all Vulkan applications; this is called an Implicit-Enabled layer.

Once the loader locates the drivers and successfully links with the APIs, the application is responsible for the following:

  • Creating a Vulkan instance
  • Querying the physical device for the available queues
  • Querying extensions and storing them as function pointers, such as WSI or special feature APIs
  • Enabling an injectable layer for error checking, debugging, or the validation process

Window presentation surfaces


Once the Vulkan implementation driver is located by the loader, we are good to draw something using the Vulkan APIs. For this, we need an image to perform the drawing task and put it on the presentation window to display it:

Building a presentation image and creating windows are very platform-specific jobs. In OpenGL, windowing is intimately linked; the window system framebuffer is created along with context/device. The big difference from GL here is that context/device creation in Vulkan needn't involve the window system at all; it is managed through Window System Integration (WSI).

WSI contains a set of cross-platform windowing management extensions:

  • A unique cross-platform implementation for the majority of platforms, such as Windows, Linux, Android, and other OSes
  • A consistent API standard to easily create surfaces and display them without getting into the details

WSI supports multiple windowing systems, such as Wayland, X, and Windows, and it also manages the ownership of images via a swapchain.

WSI provides a swapchain mechanism; this allows the use of multiple images in such a way that, while the window system is displaying one image, the application can prepare the next.

The following screenshot shows the double-buffering swap image process. It contains two images named First Image and Second Image. These images are swapped between Application and Display with the help of WSI:

WSI works as an interface between Display and Application. It makes sure that both images are acquired by Display and Application in a mutually exclusive way. Therefore, when an Application works on First Image, WSI hands over Second Image to Display in order to render its contents. Once the Application finishes the painting First image, it submits it to the WSI and in return acquires Second Image to work with and vice-versa.

At this point, perform the following tasks:

  • Create a native window (like the CreateWindow method in the Windows OS)
  • Create a WSI surface attached to the window
  • Create the swapchain to present to the surface
  • Request the drawing images from the created swapchain

Resource setup


Setting up resources means storing data into memory regions. It could be any type of data, for example, vertex attributes, such as position, color, or image type/name. Certainly, the data has resided somewhere in the memory for Vulkan to access it.

Unlike OpenGL, which manages the memory behind the scenes using hints, Vulkan provides full low-level access and control of the memory. Vulkan advertises the various types of available memory on the physical device, providing the application with a fine opportunity to manage these different types of memory explicitly.

Memory heaps can be categorized into two types, based upon their performance:

  • Host local: This is a slower type of memory
  • Device local: This is a type of memory with high bandwidth; it is faster

Memory heaps can be further divided based upon their memory type configurations:

  • Device local: This type of memory is physically attached to the physical device:
    • Visible to the device
    • Not visible to the host
  • Device local, host visible: This type of memory is also physically attached to the device:
    • Visible to the device
    • Visible to the host
  • Host local, host visible: This refers to the local memory of the host, but it is slower than the local device:
    • Visible to the device
    • Visible to the host

In Vulkan, resources are explicitly taken care of by the application with exclusive control of memory management. The following is the process of resource management:

  • Resource objects: For resource setup, an application is responsible for allocating memory for resources; these resources could be either images or buffer objects.
  • Allocation and suballocations: When resource objects are created, only logical addresses are associated with them; there is no physical backing available. The application allocates physical memory and binds these logical addresses to it. As allocation is an expensive process, suballocation is an efficient way to manage the memory; it allocates a big chunk of physical memory at once and puts different resource objects into it. Suballocation is the responsibility of an application. The following diagram shows the suballocated object from the big allocated piece of physical memory:
  • Sparse memory: For very large image objects, Vulkan fully supports sparse memory with all its features. Sparse memory is a special feature that allows you to store large image resources; which are much larger than the actual memory capacity, in the memory. This technique breaks the image into tiles and loads only those tiles that fit the application logic.
  • Staging buffers: The population of the object and image buffers is done using staging, where two different memory regions are used for the physical allocation. The ideal memory placement for a resource may not be visible to the host. In this case, the application must first populate the resource in a staging buffer that is host-visible...

EPUBEPUB (Ohne DRM)

Digital Rights Management: ohne DRM
Dieses eBook enthält kein DRM oder Kopier­schutz. Eine Weiter­gabe an Dritte ist jedoch rechtlich nicht zulässig, weil Sie beim Kauf nur die Rechte an der persön­lichen Nutzung erwerben.

Dateiformat: EPUB (Electronic Publication)
EPUB ist ein offener Standard für eBooks und eignet sich besonders zur Darstellung von Belle­tristik und Sach­büchern. Der Fließ­text wird dynamisch an die Display- und Schrift­größe ange­passt. Auch für mobile Lese­geräte ist EPUB daher gut geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür die kostenlose Software Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür eine kostenlose App.
Geräteliste und zusätzliche Hinweise

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

Mehr entdecken
aus dem Bereich
Bring out the best in your images using Adobe Photoshop Elements 2024

von Robin Nichols

eBook Download (2024)
Packt Publishing Limited (Verlag)
CHF 37,10
Discover the smart way to polish your digital imagery skills by …

von Gary Bradley

eBook Download (2024)
Packt Publishing (Verlag)
CHF 49,20
Generate creative images from text prompts and seamlessly integrate …

von Margarida Barreto

eBook Download (2024)
Packt Publishing (Verlag)
CHF 26,35