Git Product home page Git Product logo

vulkantutorial's Introduction

Vulkan tutorial

This repository hosts the contents of vulkan-tutorial.com. The website itself is based on daux.io, which supports GitHub flavored Markdown. The actual site runs daux.io with a custom theme and a few modifications (https://github.com/Overv/daux.io) and this is built into a Docker image.

Use issues and pull requests to provide feedback related to the website. If you have a problem with your code, then use the comments section in the related chapter to ask a question. Please provide your operating system, graphics card, driver version, source code, expected behaviour and actual behaviour.

E-book

This guide is now available in e-book formats as well:

The e-book can be built from the existing content by running:

 python3 build_ebook.py

This script depends on the following utilities being available on the path:

  • inkscape: SVG to PNG conversion (tested with version 1.0.2)
  • pandoc: Building a PDF and EPUB from the Markdown code (tested with version 2.13)

You also need to install a LaTeX distribution for PDF generation.

Changing code across chapters

It is sometimes necessary to change code that is reused across many chapters, for example a function like createBuffer. If you make such a change, then you should update the code files using the following steps:

  • Update any chapters that reference the modified code.
  • Make a copy of the first file that uses it and modify the code there, e.g. base_code_fixed.cpp.
  • Create a patch using diff -Naur base_code.cpp base_code_fixed.cpp > patch.txt.
  • Apply the patch to the specified code file and all files in later chapters using the incremental_patch.sh script. Run it like this: ./incremental_patch.sh base_code.cpp patch.txt.
  • Clean up the base_code_fixed.cpp and patch.txt files.
  • Commit.

Rendering the tutorial

To render the tutorial (i.e. convert the markdown to html), you have two options:

  1. Serve rendered files on the fly using a web server that has php installed
  2. Generate static html files that you can view locally or put on a server

For either of these options, you'll need php and a patch'ed daux.

PHP

  1. Make sure PHP is installed (Daux is written in PHP)
    1. Both the php_mbstring and php_openssl extensions need to be enabled
    2. The phar.readonly setting needs to be set to Off (to be able to rebuild Daux)
  2. Make sure Composer is installed, a php dependency manager that Daux uses

Clone, patch, and rebuild daux

  1. Clone daux
    • git clone https://github.com/dauxio/daux.io.git
  2. Make a new branch at the older revision that the VulkanTutorial patch is against:
    • git checkout d45ccff -b vtpatch
    • Making a new branch isn't strictly necessary, as you could reset master, but this keeps master intact.
  3. Copy over the daux.patch file into the daux.io directory, make sure line endings are UNIX style (in case you're using Windows), and apply the patch. It should apply cleanly.
    • git am daux.patch
  4. Run composer in the daux.io directory so that it downloads the dependencies Daux needs in order to be built
    • composer install
  5. Rebuild Daux
    • php bin/compile (this can take a while)
    • A newly made daux.phar will now be in your base directory

Using Daux to serve rendered files on the fly

Once you've completed the above, follow the instructions on the daux site for how to run daux using a web server.

As a simple option considering you have php installed, you can also use php's built in development web server if you just need to locally see what things look like:

  1. In the daux.io directory, edit global.json so that the docs_directory option points at your VulkanTutorial directory
    • "docs_directory": "../VulkanTutorial",
  2. In the daux.io directory, run
    • php -S localhost:8080 index.php
  3. Type localhost:8080 in your web browser URL bar and hit enter. You should now see the VulkanTutorial front page.

Using Daux to statically generate html files

Before we generate the static files, we need to tweak daux and the tutorial setup to prevent it from trying to load a few outside resources (which will stall your browser when trying to load the otherwise static page)

  1. In the VulkanTutorial directory, edit config.json and remove the google_analytics line so daux doesn't try to load that.
  2. In the daux.io directory, edit themes/daux/config.json and remove the font line so that daux doesn't try to load an external font.
  3. Rebuild daux according to the earlier instructions so it picks up the theme changes.

We're working on improvements so in the future the above steps won't be necessary.

Now with the above done, we can generate the static files. Asuming the daux.io and VulkanTutorial directories are next to each other, go into the daux.io directory and run a command similar to: php generate -s ../VulkanTutorial -d ../VulkanTutorial/out.

-s tells it where to find the documentation, while -d tells it where to put the generated files.

Note: if you want to generate the docs again, delete the out directory first or daux will make a new out directory within the existing out directory.

License

The contents of this repository are licensed as CC BY-SA 4.0, unless stated otherwise. By contributing to this repository, you agree to license your contributions to the public under that same license.

The code listings in the code directory are licensed as CC0 1.0 Universal. By contributing to that directory, you agree to license your contributions to the public under that same public domain-like license.

vulkantutorial's People

Contributors

adenflorian avatar akien-mga avatar charles-lunarg avatar diskhkme avatar eliedebrauwer avatar feyleth avatar frguthmann avatar fvcaputo avatar jonasdem avatar jsancheznet avatar kondrak avatar krenodeno avatar littlewhite-tb avatar maltekliemann avatar mrsaleh avatar mrtrizer avatar overv avatar petershinners avatar rhermes avatar rithulkamesh avatar saschawillems avatar szellmann avatar thesusian avatar tthelin avatar vittorioromeo avatar whydoubt avatar winterismute avatar z80fan avatar zaonirinku avatar zingam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vulkantutorial's Issues

error: โ€˜strcmpโ€™ was not declared in this scope

vulkan, glfw and glm installed from a package:

$ g++ -DNDEBUG -lvulkan -lglfw -std=c++11 hello_triangle.cpp 
hello_triangle.cpp: In member function โ€˜bool HelloTriangleApplication::checkValidationLayerSupport()โ€™:
hello_triangle.cpp:823:64: error: โ€˜strcmpโ€™ was not declared in this scope
                 if (strcmp(layerName, layerProperties.layerName) == 0) {
                                                                ^

adding #include <string.h> does compile it.

This is on ArchLinux, gcc-6.1.1, vulkan-headers-1.0.21, vulkan-intel 12.0.1 (mesa), glfw-x11 3.2-4, glm 0.9.7.5-1

VK_IMAGE_LAYOUT_PREINITIALIZED is not necessary

In the "Images" chapter of the Texture Mapping section, the createImage function creates an image with an initial layout of VK_IMAGE_LAYOUT_PREINITIALIZED. The reason given for this is so that the contents of the image are preserved by the first transition. However, data is not placed into the image before the first transition in any part of the tutorial. I think this was left over from when the tutorial used a staging image to transfer the texture, but since it uses a staging buffer now, VK_IMAGE_LAYOUT_PREINITIALIZED is not necessary.

For reference, section 11.4 of the spec says

VK_IMAGE_LAYOUT_PREINITIALIZED does not support device access.
...
Currently, VK_IMAGE_LAYOUT_PREINITIALIZED is only useful with VK_IMAGE_TILING_LINEAR images because there is not a standard layout defined for VK_IMAGE_TILING_OPTIMAL images.

VK_IMAGE_TILING_LINEAR is also never used.

terminate called after throwing an instance of 'std::bad_alloc'

I'm getting this error:

$ g++ -DNDEBUG -lvulkan -lglfw -std=c++11 descriptor_layout.cpp 
$ ./a.out 
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted (core dumped)

seems code uses push_back of on-stack variables

Staging image update

Hello @Overv,
Thanks for the great tutorial.

I noticed a point that could be improved.
In @SaschaWillems examples, the staging image is a staging buffer, I then asked the question on ##vulkan (irc) and @baldurk (creator of renderdoc) answered to me:

staging VkBuffers are the way to go. You can use your own packing/padding layout (so you can memcpy directly from a file for example) as you don't have to respect the implementation's image layout, and most image formats won't allow you to create a linear image anyway

His explanation is very good, it would be great to update the tutorial and to use a staging buffer.
What do you think about that ?

Fix broken links for *KHR functions/structs

The website automatically generate links for any references to vkSomething functions and VkSomething structs, but this doesn't work for certain functions that are not included in the Khronos reference, like VkSurfaceKHR. These should be blacklisted to not have broken links created from them, which confuses users.

Exception-safe programming

As I'm following the tutorial (part 3 creating the VDeleter 00_Setup/00_Base_code) and I noticed the assignment operator isn't checking for self assignment.
Is this the intention or not, or am I missing something?

Redesign drawing and presentation logic

There are two known issues in the current drawing and presentation logic of the tutorial:

  1. Rendering of frames spirals out of control because semaphores are not used properly and there is no host<->GPU synchronization. (#77 #76 #22)
  2. It is unclear if subpass dependencies are used properly, especially with regards to the depth buffer and memory reads as part of presentation.

I will research other samples and reference code to correct these and update the tutorial + code.

Synchronization in Tutorial 06 : Images

You are loading an image from the CPU.
If you want to use it in the GPU (through a command buffer), the spec says :

For host writes to be seen by subsequent command buffer operations, a pipeline barrier from a source of VK_ACCESS_HOST_WRITE_BIT and VK_PIPELINE_STAGE_HOST_BIT to a destination of the relevant device pipeline stages and access types must be performed. Note that such a barrier is performed implicitly upon each command buffer submission, so an explicit barrier is only rarely needed

As I understand, it performs a kind of a global memory barrier with :

srcStage = VK_PIPELINE_STAGE_HOST_BIT;
srcAccess = VK_ACCESS_HOST_WRITE_BIT;
dstStage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
dstAccess = VK_ACCESS_MEMORY_READ_BIT;

Since this memory barrier is performed implicity, you do not need the barrier to use the image inside a commandBuffer.
However, you still need to transition your image from the LAYOUT_PREINITIALIZED to the LAYOUT_TRANSFER_SRC.
Since the execution barrier was done as we saw above, we do not need an another, but we still need an image memory barrier to transition the image. I will do it like that /

oldLayout = PREINITIALIZED;
newLayout = TRANSFER_SRC;
srcStage = TOP_OF_PIPE; // Since it could be 
srcAccess = 0; 
dstStage = TRANSFER;
dstAccess = VK_ACCESS_TRANSFER_READ_BIT; // Since you can use this "cache" before, it is better to make memory visible IMHO

Put srcAccess to 0 will lead to validation layer warning. I post an issu here

For the image with memory that resides on GPU side (you called it textureImage I think), you can do:

oldLayout = UNDEFINED; // obvious
newLayout = TRANSFER_DST;
srcStage = TOP_OF_PIPE;
srcAccess = 0;
dstStage = TRANSFER;
dstAccess = 0; // TRANSFER_WRITE is not useful IMHO since you do not need memory visibility

After, you can make the copy !

After the copy is done, you must transition the textureImage's layout to SHADER_READ_ONLY_OPTIMAL;
When the transfer is done? After TRANSFER stage
Before which stage it must be done? Before the FRAGMENT_SHADER (if you use it only in the fragment shader), but I'd go for ALL_GRAPHICS or ALL_COMMANDS (to use it in the computeShader).

So the barrier should be something like that :

oldLayout = TRANSFER_DST;
newLayout = SHADER_READ_ONLY;
srcStage = TRANSFER;
srcAccess = TRANSFER_WRITE; // Make the memory available
dstStage = ALL_COMMANDS; FRAGMENT_SHADER; // It is up to you;
dstAccess = SHADER_READ; // Make the memory visible for shader reads !

It is where I think you must correct it.

IMHO you must as well use barrier when you use buffers ! But in my opinion you just need one and only one barrier for buffers (to make the memory visible after the transfer :))

IMHO, TOP_OF_PIPE for barrier is not a good idea.
I tryed to make that clear on my website.

I hope I did not forget anything.

VDeleter is confusing and unnecessary.

While it is good practice to abstract away memory management like this, the VDeleter template class is a completely distinct concept from Vulkan. This tutorial series would be much easier to follow if memory management was explicitly done, not abstracted away.

The Problem

The code exists to be read, and understood, not elegant and functional. This is a case where elegance hides the functionality.

The reader is here to learn about the Vulkan API, and nothing else.
By encapsulating the memory management, the reader has an unnecessary knowledge dependency. He or she must drop everything, and learn how this new template class works and will be used in the future before they can do what they came for: learn Vulkan.

To make matters worse, if the reader wants to use their own abstraction for memory management, they still have to figure out what VDeleter is doing in every subsequent tutorial.

A Better Way

Don't abstract away any memory management.

But isn't that bad programming?

Yes.
It is also good teaching.

Won't I be adding more confusion?

No.
More code does not equate to more confusing code.
Vulkan is inherently verbose. The reader is expecting to write a lot of code.

Won't the reader just make their own VDeleter (or something similar)?

Almost definitely.
Make a separate tutorial about it! That would be a helpful resource to anyone who hasn't already done something similar. Like I said before,

The reader is here to learn about the Vulkan API.

Common abstractions for handling memory are great to know, but they aren't Vulkan.

disqus embedding doesn't play nice with statically generated files (w/ fix)

In figuring out how to statically generate the tutorial, I came across several performance issues where the static files are still trying to reach out to the internet, but with a bad assumption that "//" as a URL prefix would always work (it doesn't when protocol is file:) It takes about ~10s for Chrome to give up on trying to resolve the bad URL for each one of these.

The discuss thread is one of them (loading google analytics and the special font are the others, but you can turn those off via config files).

The disqus thread is part of the patch into the daux theme so it's not so simple.

If we put in "local file detection" as part of the disqus loading code we fix the problem as it'll only load when served from a web server

If you want me to make a formal pull request I can, but basically this is the change to fix the issue (it needs to be incorporated into daux.patch though)

diff --git a/templates/content.php b/templates/content.php
index 82e79cd..03017b7 100644
--- a/templates/content.php
+++ b/templates/content.php
@@ -26,6 +26,7 @@

     <div id="disqus_thread"></div>
     <script>
+    if (document.location.host) {
         var disqus_config = function() {
             var path = location.pathname;
             if (path == '/') path = '/Introduction';
@@ -38,6 +39,7 @@
             s.setAttribute('data-timestamp', +new Date());
             (d.head || d.body).appendChild(s);
         })();
+    }
     </script>
     <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
 </article>

Website issues

There is a problem on your website https://vulkan-tutorial.com/ where some pages have problem with resource loading and fails to present properly. The following errors are caused by:

<!-- hightlight.js -->
<script src="//vulkan-tutorial.com/Uniform_buffers/themes/daux/js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

The script fails to load and the function call prevents the pages to load as expected.

ebook version out of date

I've been using the pdf version of this guide, Getting to the rotating rectangle example shows several fatal mistakes in the pdf that are not present in the html guide;

ubo.model = glm::rotate(glm::mat4(), time * glm::radians(90.0f) ...

you need to specify that matf(1.0f), ... otherwise you see nothing.

There's also no VDeleter, what's up with that?

Template Export in Tutorial 02

It appears there is an issue in Visual Studio 2017 when exporting C++ templates.

Template error

It seems that Visual Studio doesn't include the files added through Add -> New Item..., I'm not sure if this is intended behaviour or not. A quick workaround I've found is to drag and drop the main.cpp file into the project rather than adding files through that system. Exporting the template should then work as one would expect.

Perhaps this could be noted in the tutorial in the Template Export section.

Upgrade validation layers to use VK_EXT_debug_utils

According to Vulkan specs, VK_EXT_debug_utils is the "proper" extension to use for validation layers and VK_EXT_debug_report will no longer be developed further. I think it would be a good idea to mention that in the tutorial and replace current implementation to make use of the new structures.

Process memory grows with no end

I've done the tutorial until "hello_triangle.cpp" and I've found that the process memory slowly grows and seems like there's no drop-down period. Could you please check it out? I'm not sure if somebody out there face the issue like me.

OpenGL version support

Your website claims that only cards that support OpenGL 4.3 or later will be supported by Vulkan. But I recall that the presentations claimed that OpenGL 4.1 hardware would be the minimum.

Bound submission queue depth properly with fences

#76, #22 are symptoms of a deeper problem -- the tutorial code has no bound on the number of frames the app may run ahead of the driver.

There is no guarantee of backpressure from any of vkQueueSubmit/vkQueuePresentKHR/vkAcquireNextImageKHR - the examples are just getting lucky because most implementations /do/ provide some in one of the WSI calls.

Proposal: Expand tutorial to cover using Vulkan with Java

Your tutorial is fantastic and well written. I'm actually using it to learn Vulkan with Java, translating everything as I go. The Java game development / LWJGL community could use a tutorial like yours, but rather than making yet another tutorial, when so much of the content is the same, I was hoping you might be willing to accept contributions to your tutorial to expand it to cover Java.

As a proof of concept, I forked your tutorial and started incorporating Java elements into it to see how it would turn out. I've got the code ported so far to the swap chain chapter, and I've edited 00 and 01 of the text.
master...tthelin:master

Are you interested in the idea? If so I'd keep going, clean things up, and send over pull requests as I make progress. I'm open to how you'd like the content done.

Code left over from saving result in 03/00/01 (creating two instances)

In the tutorial noted, we create the instance and store the result in one line of code:

VkResult result = vkCreateInstance(&createInfo, nullptr, &instance);

And then immediately ignore the result (apparently this is the new preferred method?) and create the instance again:

if (vkCreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS) {

I assume that either the first part should no longer exist, or the second part should revert to if (result != VK_SUCCESS) {

Provide utility for building the code

There are dozens of cpp file under the code directory.
I might have missed something, but I can't find any support for building them into executables.
I've seen the Development Environment chapter, but I think this is missing actual ready to go build scripts.

Is Vulkan support linux

I have a freescale i.MX6 dev board, the OS of it is linux, and the dev board has a LCD(7 inch).

  1. How to integrate the Vulkan into linux?
  2. How to use Vulkan draw text/triangle or other shape show on the LCD?

Vertex shader input

In the chapter "Vertex input description" you declared the vertex attribute as
layout(location = 0) in vec2 inPosition;
so to use it, you had to cast it to vec4, like this
gl_Position = vec4(inPosition, 0.0, 1.0);
Later in the chapter "Depth buffering" you had to change this to

layout(location = 0) in vec3 inPosition;
...
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0);

All this does not make sense.
Vulkan specification says

If the format does not include G, B, or A components, then those are filled with (0,0,1) as needed (using either 1.0f or integer 1 based on the format) for attributes that are not 64-bit data types. The number of components in the vertex shader input variable need not exactly match the number of components in the format. If the vertex shader has fewer components, the extra components are discarded.

Therefore, if you declare a vertex attribute, like this
layout(location = 0) in vec4 inPosition;
you do not need to cast it to vec4, whatever the format.

So this cast here just adds an extra operation. And forces us to recompile the shader when changing the format of the vertices.

Chapter on multisampling

I feel that one thing that's still missing from the tutorial to make it complete is a chapter on how to implement multisampling in existing code. Given that the reader made it past mipmapping, adding multisampling won't be that difficult and as of today it's basically a minimum feature to have in a renderer/game engine.

What do you think? If it sounds interesting (and nobody else is working on it to your knowledge) I'd be happy to contribute.

Expired SSL certificate of vulkan-tutorial.com

vulkan-tutorial.com uses an invalid security certificate. 

The certificate expired on June 24, 2017 at 10:01 PM. The current time is June 24, 2017 at 10:36 PM. 

Error code: SEC_ERROR_EXPIRED_CERTIFICATE

validation layer: SPIR-V module not valid: Invalid SPIR-V magic number.

Your hello triangle builds fine, the window opens but doesn't get filled with black and I get this error.

    validation layer: SPIR-V module not valid: Invalid SPIR-V magic number.

I've tried google, but found nothing. I'll keep looking.

My setup

Antergos Linux 4.7.0-1-ARCH
glinfo :
GL_VERSION: 4.5.0 NVIDIA 367.35
GL_RENDERER: GeForce GTX 970/PCIe/SSE2
GL_VENDOR: NVIDIA Corporation

Screenshot

screenshot from 2016-08-13 12-46-36

Typo in Graphics Pipeline Conclusion

At the last paragraph:

Now run your program and you'll see that all of the hard work has finally paid off! We are already getting quite close to seeing the that triangle pop up on the screen. In the next couple of chapters we'll set up the actual framebuffers from the swap chain images and prepare the drawing commands.

Would have opened a PR but I was not sure which variant you meant/prefer.

Also, I find that this paragraph is a little misleading, I thought I should have seen something on my screen, and this comment thought too.

You should make more clear that we're not done yet ;)

Full system freeze

The swap_chain_creation.cpp as well as my own implementation following your tutorial up to this point reliably freezes my machine if I interact in any way with the window (moving, resizing, closing etc.). Additionally I get a "validation layer: vkDeviceWaitIdle: returned VK_ERROR_DEVICE_LOST, indicating that the logical device has been lost" error when terminating the application.

Note that SashaWillems basic triangle example works fine.

Mipmapping tutorial does not mention why extra uses are added to texture image

@vazgriz Could you add an explanation for why createImage in createTextureImage changes from:

createImage(texWidth, texHeight, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, textureImage, textureImageMemory);

to:

createImage(texWidth, texHeight, mipLevels, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, textureImage, textureImageMemory);

The chapter currently doesn't explicitly mention why the extra flags are added. It should mention that they are needed for the generateMipmaps operations.

Consider rewriting the tutorial using plain C

Hi, please consider rewriting the tutorial using plain C (optionally with the use of C++ RAII) to keep the focus of the learner on Vulkan and away from C++ issues.

For example this code fragment from the Base Code chapter is not exception safe...

void run() {
    initVulkan();
    mainLoop();
    cleanup();
}

The call to cleanup() will be skipped if initVulkan() or mainLoop() throws an exception.

Exceptions are a C++ specific thing. It is just a distraction while learning Vulkan.

CMake in Development Environment Section

I think it would be worth while putting CMake in place of Make for this section. If your version of CMake isn't too old (at least 3.7) CMake already comes with a module FindVulkan.cmake. Creating a CMake project can then look pretty simple.

cmake_minimum_required(VERSION 3.7)
project(vulkan_tut)

set(CMAKE_CXX_STANDARD 14)

set(SOURCE_FILES main.cpp)
add_executable(vulkan_tut ${SOURCE_FILES})

find_package(PkgConfig REQUIRED)

pkg_search_module(GLFW REQUIRED glfw3)

include_directories(${GLFW_INCLUDE_DIRS})

find_package(Vulkan REQUIRED)

find_package(glm REQUIRED)

target_link_libraries(vulkan_tut ${GLFW_LIBRARIES} ${Vulkan_LIBRARIES})

If you're for some reason stuck with an old version of CMake, glfw3 actually comes with its own FindVulkan.cmake.

Useless dependency in Tutorial 03.03

You are making a subpass dependency between "before the renderpass" and the subpass 0.

As you wrote your dependency, it can be understandable like "I am waiting for the presentation finish to read".
However, presentation engine is asynchronous and synchronisation for it should be done via Semaphore. Moreover semaphores make memory available and visible :

This semaphore signal operation defines the first half of a memory dependency, guaranteeing that all memory accesses defined by the submitted queue operations in the batch are made available, and that those queue operations have completed execution.

A semaphore wait operation defines the second half of a memory dependency for the semaphores being waited on. This half of the memory dependency guarantees that the first half has completed execution, and also guarantees that all available memory accesses are made visible to the queue operations in the batch.

The semaphore we are talking about is the semaphore that you use inside the vkAcquireNextImageKHR.

The presentation engine may not have finished reading from the image at the
time it is acquired, so the application must use semaphore and/or fence to ensure that the image layout and contents
are not modified until the presentation engine reads have completed.

So, to me you do not need to use a dependency since the layout transition is performed by the renderpass itself, and the memory dependencies / execution dependencies are performed by the semaphore.

transitionImageLayout function doesn't follow the spec

The table in Section 6.1.3, specifies what pipeline stage each access mask can be accessed in. For example, when dstAccessMask is VK_ACCESS_TRANSFER_WRITE_BIT, dstStageMask must be VK_PIPELINE_STAGE_TRANSFER_BIT. The current function always uses VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT for the source and dest stage.

The easiest way to correct this would be choosing the source and dest stages alongside the access masks

VkPipelineStageFlags source;
VkPipelineStageFlags dest;

if (oldLayout == VK_IMAGE_LAYOUT_UNDEFINED && newLayout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
    barrier.srcAccessMask = 0;
    barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;

    source = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
    dest = VK_PIPELINE_STAGE_TRANSFER_BIT;
}

...

vkCmdPipelineBarrier(
    commandBuffer,
    source, dest,
    0,
    0, nullptr,
    0, nullptr,
    1, &barrier
);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.