Skip to content

Use of vk::StructureChain on device creation.#89

Merged
gpx1000 merged 1 commit intoKhronosGroup:mainfrom
asuessenbach:04_logical_device
Jul 8, 2025
Merged

Use of vk::StructureChain on device creation.#89
gpx1000 merged 1 commit intoKhronosGroup:mainfrom
asuessenbach:04_logical_device

Conversation

@asuessenbach
Copy link
Contributor

Demonstrates the usage of vk::StructureChain on device creation, with two slightly different approaches.

If one of them is considered to be good, I can adjust this code in the other sources as well.

{.dynamicRendering = true }, // vk::PhysicalDeviceVulkan13Features
{.extendedDynamicState = true } // vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really cool, I didn't even know this was available. We should also find a place in the tutorial text to call this out, describe pros/cons and recommend it. If you'd like go ahead and add this to the rest of the chapters and I'm happy to draft the language in the tutorial itself unless you wanna do that?

Copy link
Contributor Author

@asuessenbach asuessenbach Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you'd like go ahead and add this to the rest of the chapters

With "this", you mean the approach right above?
I also like that one a little more, even though it needs that vk::PhysicalDeviceFeatures2 as an anchor for the structs, which isn't used besides that.
The other approach doesn't need that struct, the feature structs are simply chained to vk::DeviceCreateInfo.

I'm happy to draft the language in the tutorial itself

Sounds good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, i meant the first approach. For some reason to my eye it still looks cleaner even if it requires an extra struct rather than directly to the device create info. Maybe because it feels closer to what I'm used to with the C version to use the extra struct or at least kinda follow what I'm expecting.

@asuessenbach
Copy link
Contributor Author

Adjusted the device creation in all the chapters.
Additionally, checked for support of samplerAnisotropy and timelineSemaphore, as needed, in pickPhysicalDevice.

Note: chapters 18_vertex_input, 22_descriptor_layout, and 26_texture_mapping have some validation errors; chapter 31_compute_shaders does not build successfully. Is that known?

@asuessenbach asuessenbach requested a review from gpx1000 July 8, 2025 10:44
@gpx1000
Copy link
Contributor

gpx1000 commented Jul 8, 2025

Thanks for the work @asuessenbach, I wasn't aware of the validation errors or compute shader not building. I'll take a look at that. This PR LGTM.

@gpx1000 gpx1000 merged commit 4c566c7 into KhronosGroup:main Jul 8, 2025
3 checks passed
@gpx1000
Copy link
Contributor

gpx1000 commented Jul 8, 2025

@asuessenbach , 31_compute_shader.cpp compiles and runs for me. CI shows it builds correctly, could you tell me more about what causes it to not build? I want to see if I can fix CI so it'll help me out. I'm working on the text to document this change in the tutorial right now (why I merged early). I'll also look into the validation issues.

@asuessenbach asuessenbach deleted the 04_logical_device branch July 9, 2025 15:25
@asuessenbach
Copy link
Contributor Author

asuessenbach commented Jul 9, 2025

@gpx1000: I can successfully compile 31_compute_shader.cpp. But before and up to this PR, I got the following messages on building 31_compute_shader:

Build started at 17:32...
1>------ Build started: Project: ZERO_CHECK, Configuration: Debug x64 ------
1>1>Checking Build System
1>CMake is re-running because C:/git/Vulkan-Tutorial/attachments/build/VS2022_64/CMakeFiles/generate.stamp is out-of-date.
1>  the file 'C:/git/Vulkan-Tutorial/attachments/CMakeLists.txt'
1>  is newer than 'C:/git/Vulkan-Tutorial/attachments/build/VS2022_64/CMakeFiles/generate.stamp.depend'
1>  result='-1'
1>-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
1>-- vulkan_libraryC:/VulkanSDK/1.4.304.0/Lib/vulkan-1.libsearchpathsC:\VulkanSDK\1.4.304.0/libC:\VulkanSDK\1.4.304.0/bin
1>-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
1>-- Configuring done (0.8s)
1>-- Generating done (3.3s)
1>-- Build files have been written to: C:/git/Vulkan-Tutorial/attachments/build/VS2022_64
2>------ Build started: Project: VulkanCppModule, Configuration: Debug x64 ------
3>------ Build started: Project: 31_compute_shader_slang_shader, Configuration: Debug x64 ------
4>------ Build started: Project: 31_compute_shader_shader, Configuration: Debug x64 ------
2>Scanning sources for module dependencies...
3>1>Generating 31_compute_shader/shaders
4>1>Generating 31_compute_shader/shaders
2>VulkanCppModule.vcxproj -> C:\git\Vulkan-Tutorial\attachments\build\VS2022_64\Debug\VulkanCppModule.lib
4>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(237,5): warning MSB8065: Custom build for item "C:\git\Vulkan-Tutorial\attachments\build\VS2022_64\CMakeFiles\bcd53b743d157528b805195178d5912a\shaders.rule" succeeded, but specified output "c:\git\vulkan-tutorial\attachments\build\vs2022_64\31_compute_shader\shaders" has not been created. This may cause incremental build to work incorrectly.
3>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(237,5): warning MSB8065: Custom build for item "C:\git\Vulkan-Tutorial\attachments\build\VS2022_64\CMakeFiles\bcd53b743d157528b805195178d5912a\shaders.rule" succeeded, but specified output "c:\git\vulkan-tutorial\attachments\build\vs2022_64\31_compute_shader\shaders" has not been created. This may cause incremental build to work incorrectly.
3>Compiling Slang Shaders
4>Compiling Shaders
4>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(254,5): warning MSB8064: Custom build for item "C:\git\Vulkan-Tutorial\attachments\build\VS2022_64\CMakeFiles\94f577179af9fd3ff610b815a900b6db\frag.spv.rule" succeeded, but specified dependency "c:\git\vulkan-tutorial\attachments\build\vs2022_64\31_compute_shader\shaders" does not exist. This may cause incremental build to work incorrectly.
4>Done building project "31_compute_shader_shader.vcxproj".
3>CUSTOMBUILD : error 49999: unknown system-value semantic 'SV_PointCoord'
3>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(254,5): error MSB8066: Custom build for 'C:\git\Vulkan-Tutorial\attachments\build\VS2022_64\CMakeFiles\94f577179af9fd3ff610b815a900b6db\slang.spv.rule;C:\git\Vulkan-Tutorial\attachments\build\VS2022_64\CMakeFiles\3658f24c55f2d7f5e510e77c2c0242fc\31_compute_shader_slang_shader.rule' exited with code -1.
3>Done building project "31_compute_shader_slang_shader.vcxproj" -- FAILED.
5>------ Build started: Project: 31_compute_shader, Configuration: Debug x64 ------
5>Scanning sources for module dependencies...
5>31_compute_shader.cpp
5>Compiling...
5>31_compute_shader.cpp
5>31_compute_shader.vcxproj -> C:\git\Vulkan-Tutorial\attachments\build\VS2022_64\31_compute_shader\Debug\31_compute_shader.exe
========== Build: 4 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 17:32 and took 09,036 seconds ==========

I can't easily identify the issue here.
And I get similar results on all those *shader and *slang_shader projects.

With top of tree, I even can't create the solution using the CMake GUI. I get

Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
The C compiler identification is MSVC 19.43.34810.0
The CXX compiler identification is MSVC 19.43.34810.0
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe - skipped
Detecting C compile features
Detecting C compile features - done
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe - skipped
Detecting CXX compile features
Detecting CXX compile features - done
Performing Test CMAKE_HAVE_LIBC_PTHREAD
Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
Looking for pthread_create in pthreads
Looking for pthread_create in pthreads - not found
Looking for pthread_create in pthread
Looking for pthread_create in pthread - not found
Found Threads: TRUE
Found glm: C:/git/vcpkg/installed/x64-windows/include
vulkan_libraryC:/VulkanSDK/1.4.304.0/Lib/vulkan-1.libsearchpathsC:\VulkanSDK\1.4.304.0/libC:\VulkanSDK\1.4.304.0/bin
Found Vulkan: C:/VulkanSDK/1.4.304.0/Lib/vulkan-1.lib (found version "1.4.304") found components: glslc glslangValidator
Found tinyobjloader: C:/git/vcpkg/installed/x64-windows/include
nlohmann_json not found, fetching from GitHub...
CMake Deprecation Warning at build/VS2022_64/_deps/nlohmann_json-src/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


Using the multi-header code from C:/git/Vulkan-Tutorial/attachments/build/VS2022_64/_deps/nlohmann_json-src/include/
tinygltf not found, fetching from GitHub...
CMake Error at CMake/Findtinygltf.cmake:80 (file):
  file failed to create symbolic link
  'C:/git/Vulkan-Tutorial/attachments/build/VS2022_64/_deps/tinygltf-src/nlohmann/json.hpp':
  A required privilege is not held by the client.


Call Stack (most recent call first):
  C:/git/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
  CMakeLists.txt:14 (find_package)


CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.30/Modules/FindPackageHandleStandardArgs.cmake:441 (message):
  The package name passed to `find_package_handle_standard_args` (tinygltf)
  does not match the name of the calling package (TinyGLTF).  This can lead
  to problems in calling code that expects `find_package` result variables
  (e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  CMake/Findtinygltf.cmake:104 (find_package_handle_standard_args)
  C:/git/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
  CMakeLists.txt:14 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

Found tinygltf: $<BUILD_INTERFACE:C:/git/Vulkan-Tutorial/attachments/build/VS2022_64/_deps/tinygltf-src>;$<INSTALL_INTERFACE:include>
CMake Error at C:/Program Files/CMake/share/cmake-3.30/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
  Could NOT find KTX (missing: KTX_INCLUDE_DIR KTX_LIBRARY)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.30/Modules/FindPackageHandleStandardArgs.cmake:603 (_FPHSA_FAILURE_MESSAGE)
  CMake/FindKTX.cmake:55 (find_package_handle_standard_args)
  C:/git/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
  CMakeLists.txt:15 (find_package)


Configuring incomplete, errors occurred!

Is there anything obvious, I'm missing?

@SaschaWillems
Copy link
Collaborator

SaschaWillems commented Jul 9, 2025

I had similar CMake errors. CMake GUI was picking up wrong packages, I need to run on cmd line and specifiy the vcpkg toolchain like this:

cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=V:\github\vcpkg\scripts\buildsystems\vcpkg.cmake

That picks up the correct packages.

Using CMake's GUI on Windows doesn't work for me either, I guess that's because you explicitly need to specify the vcpkg toolchain

@gpx1000
Copy link
Contributor

gpx1000 commented Jul 9, 2025 via email

@asuessenbach
Copy link
Contributor Author

Unfortunately, using that command line doesn't resolve my issue.

When I run the install_dependencies_windows.bat, I get the following:

C:\git\Vulkan-Tutorial\scripts>install_dependencies_windows.bat
Installing dependencies for Vulkan Tutorial...
Enabling binary caching for vcpkg...
Installing all dependencies...
Detecting compiler hash for triplet x64-windows...
Compiler found: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe
The following packages will be built and installed:
    ktx:x64-windows@4.3.2
    nlohmann-json:x64-windows@3.11.3#1
    stb:x64-windows@2024-07-29#1
    tinygltf:x64-windows@2.9.3
    tinyobjloader:x64-windows@2.0.0rc13
Restored 0 package(s) from C:\Users\ASUESS~1\AppData\Local\Temp\vcpkg-cache in 231 us. Use --debug to see more details.
Installing 1/5 ktx:x64-windows@4.3.2...
Building ktx:x64-windows@4.3.2...
-- Using cached KhronosGroup-KTX-Software-v4.3.2.tar.gz.
-- Cleaning sources at C:/git/vcpkg/buildtrees/ktx/src/v4.3.2-8d9e3937e6.clean. Use --editable to skip cleaning for the packages you specify.
-- Extracting source C:/git/vcpkg/downloads/KhronosGroup-KTX-Software-v4.3.2.tar.gz
-- Applying patch 0001-Use-vcpkg-zstd.patch
-- Applying patch 0002-Fix-versioning.patch
-- Applying patch 0003-mkversion.patch
-- Applying patch 0004-quirks.patch
-- Applying patch 0005-no-vendored-libs.patch
-- Applying patch 0006-fix-ios-install.patch
-- Using source at C:/git/vcpkg/buildtrees/ktx/src/v4.3.2-8d9e3937e6.clean
-- Downloading https://mirror.msys2.org/msys/x86_64/util-linux-2.35.2-3-x86_64.pkg.tar.zst;https://repo.msys2.org/msys/x86_64/util-linux-2.35.2-3-x86_64.pkg.tar.zst;https://repo.msys2.org/msys/x86_64/util-linux-2.35.2-3-x86_64.pkg.tar.zst;https://repo.msys2.org/msys/x86_64/util-linux-2.35.2-3-x86_64.pkg.tar.zst;https://repo.msys2.org/msys/x86_64/util-linux-2.35.2-3-x86_64.pkg.tar.zst;https://repo.msys2.org/msys/x86_64/util-linux-2.35.2-3-x86_64.pkg.tar.zst -> util-linux-2.35.2-3-x86_64.pkg.tar.zst...
[DEBUG] To include the environment variables in debug output, pass --debug-env
[DEBUG] Trying to load bundleconfig from C:\git\vcpkg\vcpkg-bundle.json
[DEBUG] Failed to open: C:\git\vcpkg\vcpkg-bundle.json
[DEBUG] Bundle config: readonly=false, usegitregistry=false, embeddedsha=nullopt, deployment=Git, vsversion=nullopt
[DEBUG] Metrics enabled.
[DEBUG] Feature flag 'binarycaching' unset
[DEBUG] Feature flag 'compilertracking' unset
[DEBUG] Feature flag 'registries' unset
[DEBUG] Feature flag 'versions' unset
[DEBUG] Feature flag 'dependencygraph' unset
error: Missing util-linux-2.35.2-3-x86_64.pkg.tar.zst and downloads are blocked by x-block-origin.
error: https://mirror.msys2.org/msys/x86_64/util-linux-2.35.2-3-x86_64.pkg.tar.zst: failed: status code 404
error: https://repo.msys2.org/msys/x86_64/util-linux-2.35.2-3-x86_64.pkg.tar.zst: failed: status code 404
error: https://repo.msys2.org/msys/x86_64/util-linux-2.35.2-3-x86_64.pkg.tar.zst: failed: status code 404
error: https://repo.msys2.org/msys/x86_64/util-linux-2.35.2-3-x86_64.pkg.tar.zst: failed: status code 404
error: https://repo.msys2.org/msys/x86_64/util-linux-2.35.2-3-x86_64.pkg.tar.zst: failed: status code 404
error: https://repo.msys2.org/msys/x86_64/util-linux-2.35.2-3-x86_64.pkg.tar.zst: failed: status code 404
[DEBUG] D:\a\_work\1\s\src\vcpkg\base\downloads.cpp(1030):
[DEBUG] Time in subprocesses: 0us
[DEBUG] Time in parsing JSON: 8us
[DEBUG] Time in JSON reader: 0us
[DEBUG] Time in filesystem: 2660us
[DEBUG] Time in loading ports: 0us
[DEBUG] Exiting after 551 ms (529719us)

CMake Error at scripts/cmake/vcpkg_download_distfile.cmake:32 (message):

      Failed to download file with error: 1
      If you are using a proxy, please check your proxy setting. Possible causes are:

      1. You are actually using an HTTP proxy, but setting HTTPS_PROXY variable
         to `https://address:port`. This is not correct, because `https://` prefix
         claims the proxy is an HTTPS proxy, while your proxy (v2ray, shadowsocksr
         , etc..) is an HTTP proxy. Try setting `http://address:port` to both
         HTTP_PROXY and HTTPS_PROXY instead.

      2. If you are using Windows, vcpkg will automatically use your Windows IE Proxy Settings
         set by your proxy software. See https://github.com/microsoft/vcpkg-tool/pull/77
         The value set by your proxy might be wrong, or have same `https://` prefix issue.

      3. Your proxy's remote server is out of service.

      If you've tried directly download the link, and believe this is not a temporary
      download server failure, please submit an issue at https://github.com/Microsoft/vcpkg/issues
      to report this upstream download server failure.


Call Stack (most recent call first):
  scripts/cmake/vcpkg_download_distfile.cmake:270 (z_vcpkg_download_distfile_show_proxy_and_fail)
  scripts/cmake/vcpkg_acquire_msys.cmake:25 (vcpkg_download_distfile)
  scripts/cmake/vcpkg_acquire_msys.cmake:124 (z_vcpkg_acquire_msys_download_package)
  scripts/cmake/vcpkg_acquire_msys.cmake:212 (z_vcpkg_acquire_msys_download_packages)
  ports/ktx/portfile.cmake:19 (vcpkg_acquire_msys)
  scripts/ports.cmake:192 (include)


error: building ktx:x64-windows failed with: BUILD_FAILED
See https://learn.microsoft.com/vcpkg/troubleshoot/build-failures?WT.mc_id=vcpkg_inproduct_cli for more information.
Elapsed time to handle ktx:x64-windows: 5.6 s
Please ensure you're using the latest port files with `git pull` and `vcpkg update`.
Then check for known issues at:
  https://github.com/microsoft/vcpkg/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+ktx
You can submit a new issue at:
  https://github.com/microsoft/vcpkg/issues/new?title=[ktx]+Build+error+on+x64-windows&body=Copy+issue+body+from+C%3A%2Finstalled%2Fvcpkg%2Fissue_body.md
You can also submit an issue by running (GitHub CLI must be installed):
  gh issue create -R microsoft/vcpkg --title "[ktx] Build failure on x64-windows" --body-file C:/installed/vcpkg/issue_body.md

Don't forget to install the Vulkan SDK from https://vulkan.lunarg.com/

All dependencies have been installed successfully!
You can now use CMake to build your Vulkan project.

Example CMake command:
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=[path\to\vcpkg]\scripts\buildsystems\vcpkg.cmake
cmake --build build

C:\git\Vulkan-Tutorial\scripts>

It says, all dependencies have been installed successfully, but there's some error on the KTX stuff.

When I then run the build as given by @SaschaWillems, I get

Microsoft Windows [Version 10.0.19045.2486]
(c) Microsoft Corporation. All rights reserved.

C:\Windows\system32>cd C:\git\Vulkan-Tutorial\attachments

C:\git\Vulkan-Tutorial\attachments>cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=C:\git\vcpkg\scripts\buildsystems\vcpkg.cmake
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
-- vulkan_libraryC:/VulkanSDK/1.4.304.0/Lib/vulkan-1.libsearchpathsC:\VulkanSDK\1.4.304.0/libC:\VulkanSDK\1.4.304.0/bin
-- nlohmann_json not found, fetching from GitHub...
CMake Deprecation Warning at build/_deps/nlohmann_json-src/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Using the multi-header code from C:/git/Vulkan-Tutorial/attachments/build/_deps/nlohmann_json-src/include/
-- tinygltf not found, fetching from GitHub...
CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.30/Modules/FindPackageHandleStandardArgs.cmake:441 (message):
  The package name passed to `find_package_handle_standard_args` (tinygltf)
  does not match the name of the calling package (TinyGLTF).  This can lead
  to problems in calling code that expects `find_package` result variables
  (e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  CMake/Findtinygltf.cmake:104 (find_package_handle_standard_args)
  C:/git/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
  CMakeLists.txt:14 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at C:/Program Files/CMake/share/cmake-3.30/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
  Could NOT find KTX (missing: KTX_INCLUDE_DIR KTX_LIBRARY)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.30/Modules/FindPackageHandleStandardArgs.cmake:603 (_FPHSA_FAILURE_MESSAGE)
  CMake/FindKTX.cmake:55 (find_package_handle_standard_args)
  C:/git/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
  CMakeLists.txt:15 (find_package)


-- Configuring incomplete, errors occurred!

C:\git\Vulkan-Tutorial\attachments>

I have no ideas how to resolve that.

@gpx1000
Copy link
Contributor

gpx1000 commented Jul 10, 2025

hmm... looks like the CI is also having the problem. Lemme investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants