Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions en/01_Overview.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ with the existing APIs somehow. This resulted in less than ideal abstractions
Aside from these new features, the past decade also saw an influx of mobile
and embedded devices with powerful graphics hardware. These mobile GPUs have
different architectures based on their energy and space requirements.
One such example is https://en.wikipedia.org/wiki/Tiled_rendering[tiled rendering],
One such example is https://en.wikipedia.org/wiki/Tiled_rendering[tiled rendering],
which would benefit from improved performance by offering the
programmer more control over this functionality.
Another limitation originating from the age of these APIs is limited
Expand Down Expand Up @@ -261,10 +261,12 @@ developed by LunarG. We'll look into installing this SDK in the next chapter.
Functions have a lower case `vk` prefix, types like enumerations and structs
have a `Vk` prefix and enumeration values have a `VK_` prefix.
The API heavily uses structs to provide parameters to functions.
For example, object creation generally follows this pattern:
For example, object creation generally follows this pattern in both the C API and the C++ RAII wrapper:

[,c++]
[source,multilang,c++,c]
.Object creation pattern
----
// START c
VkXXXCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_XXX_CREATE_INFO;
createInfo.pNext = nullptr;
Expand All @@ -276,6 +278,12 @@ if (vkCreateXXX(&createInfo, nullptr, &object) != VK_SUCCESS) {
std::cerr << "failed to create object" << std::endl;
return false;
}
// END c

// START c++
auto createInfo = vk::xxx();
auto object = vk::raii::XXX(context, createInfo);
// END c++
----

Many structures in Vulkan require you to explicitly specify the type of
Expand All @@ -291,15 +299,6 @@ error code.
The specification describes which error codes each function can return and
what they mean.

To help illustrate the utility of using the RAII C++ Vulkan abstraction; this
is the same code written with our modern API:

[,c++]
----
auto createInfo = vk::xxx();
auto object = vk::raii::XXX(context, createInfo);
----

Failure of such calls is reported by C++ exceptions. The exception will
respond with more information about the error including the aforementioned
vkResult, this enables us to check multiple commands from one call and keep
Expand Down
57 changes: 50 additions & 7 deletions en/03_Drawing_a_triangle/01_Presentation/00_Window_surface.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ works in this tutorial.

Start by adding a `surface` class member right below the debug callback.

[,c++]
[source,multilang,c++,c]
.Surface member
----
// START c++
vk::raii::SurfaceKHR surface = nullptr;
// END c++

// START c
VkSurfaceKHR surface = VK_NULL_HANDLE;
// END c
----

Although the `VkSurfaceKHR` object and its usage is platform-agnostic, its
Expand Down Expand Up @@ -72,12 +79,22 @@ Because a window surface is a Vulkan object, it comes with a
important parameters: `hwnd` and `hinstance`. These are the handles to the
window and the process.

[,c++]
[source,multilang,c++,c]
.Win32 surface create info
----
// START c++
vk::Win32SurfaceCreateInfoKHR createInfo{
.hwnd = glfwGetWin32Window(window),
.hinstance = GetModuleHandle(nullptr)
};
// END c++

// START c
VkWin32SurfaceCreateInfoKHR createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
createInfo.hwnd = glfwGetWin32Window(window);
createInfo.hinstance = GetModuleHandle(nullptr);
// END c
----

The `glfwGetWin32Window` function is used to get the raw `HWND` from the GLFW
Expand All @@ -91,11 +108,18 @@ Technically, this is a WSI extension function, but it is so commonly used
that the standard Vulkan loader includes it, so unlike other extensions, you
don't need to explicitly load it.

[,c++]
[source,multilang,c++,c]
.Create the Win32 surface
----
// START c++
surface = vk::raii::SurfaceKHR(instance, createInfo);
// END c++

// START c
if (vkCreateWin32SurfaceKHR(instance, &createInfo, nullptr, &surface) != VK_SUCCESS) {
throw std::runtime_error("failed to create window surface!");
}
// END c
----

The process is similar for other platforms like Linux, where
Expand Down Expand Up @@ -125,15 +149,26 @@ void createSurface() {
The GLFW call takes simple parameters instead of a struct which makes the
implementation of the function very straightforward:

[,c++]
[source,multilang,c++,c]
.GLFW window surface creation
----
// START c++
void createSurface() {
VkSurfaceKHR _surface;
VkSurfaceKHR _surface;
if (glfwCreateWindowSurface(*instance, window, nullptr, &_surface) != 0) {
throw std::runtime_error("failed to create window surface!");
}
surface = vk::raii::SurfaceKHR(instance, _surface);
}
// END c++

// START c
void createSurface() {
if (glfwCreateWindowSurface(instance, window, nullptr, &surface) != VK_SUCCESS) {
throw std::runtime_error("failed to create window surface!");
}
}
// END c
----

However, as you see in the above, GLFW only deals with the Vulkan C API.
Expand Down Expand Up @@ -165,9 +200,17 @@ to our window surface. The function to check for that is
queue family index and surface as parameters. Add a call to it
in the same loop as the `VK_QUEUE_GRAPHICS_BIT`:

[,c++]
[source,multilang,c++,c]
.Presentation support query
----
VkBool32 presentSupport = physicalDevice.getSurfaceSupportKHR( graphicsIndex, *surface );
// START c++
VkBool32 presentSupport = physicalDevice.getSurfaceSupportKHR(graphicsIndex, *surface);
// END c++

// START c
VkBool32 presentSupport = VK_FALSE;
vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, graphicsIndex, surface, &presentSupport);
// END c
----

Then check the value of the boolean and store the presentation family
Expand Down
Loading
Loading