Skip to content

Commit 14fb52b

Browse files
authored
Merge branch 'SaschaWillems:master' into master
2 parents 95539f7 + e0bee1b commit 14fb52b

File tree

133 files changed

+12478
-14312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+12478
-14312
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ Note that some examples require specific device features, and if you are on a mu
8585

8686
Vulkan consumes shaders in an intermediate representation called SPIR-V. This makes it possible to use different shader languages by compiling them to that bytecode format. The primary shader language used here is [GLSL](shaders/glsl), most samples also come with [slang](shaders/slang/) and [HLSL](shaders/hlsl) shader sources, making it easy to compare the differences between those shading languages. The [Rust GPU](https://rust-gpu.github.io/) project maintains [Rust](https://www.rust-lang.org/) shader sources in a [separate repo](https://github.com/Rust-GPU/VulkanShaderExamples/tree/master/shaders/rust).
8787

88-
## A note on synchronization
89-
90-
Synchronization in the master branch currently isn't optimal und uses ```vkDeviceQueueWaitIdle``` at the end of each frame. This is a heavy operation and is suboptimal in regards to having CPU and GPU operations run in parallel. I'm currently reworking this in the [this branch](https://github.com/SaschaWillems/Vulkan/tree/sync_rework_second_attempt). While still work-in-progress, if you're interested in a more proper way of synchronization in Vulkan, please take a look at the [PR for that branch](https://github.com/SaschaWillems/Vulkan/pull/1224) to see progress.
91-
9288
## Examples
9389

9490
### Basics

base/VulkanBuffer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Encapsulates a Vulkan buffer
55
*
6-
* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de
6+
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
77
*
88
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
99
*/
@@ -126,10 +126,12 @@ namespace vks
126126
if (buffer)
127127
{
128128
vkDestroyBuffer(device, buffer, nullptr);
129+
buffer = VK_NULL_HANDLE;
129130
}
130131
if (memory)
131132
{
132133
vkFreeMemory(device, memory, nullptr);
134+
memory = VK_NULL_HANDLE;
133135
}
134136
}
135137
};

base/VulkanBuffer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Encapsulates a Vulkan buffer
55
*
6-
* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de
6+
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
77
*
88
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
99
*/
@@ -34,6 +34,7 @@ namespace vks
3434
VkBufferUsageFlags usageFlags;
3535
/** @brief Memory property flags to be filled by external source at buffer creation (to query at some later point) */
3636
VkMemoryPropertyFlags memoryPropertyFlags;
37+
uint64_t deviceAddress;
3738
VkResult map(VkDeviceSize size = VK_WHOLE_SIZE, VkDeviceSize offset = 0);
3839
void unmap();
3940
VkResult bind(VkDeviceSize offset = 0);

base/VulkanFrameBuffer.hpp

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Vulkan framebuffer class
33
*
4-
* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de
4+
* Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
55
*
66
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
77
*/
@@ -304,23 +304,36 @@ namespace vks
304304
}
305305

306306
// Use subpass dependencies for attachment layout transitions
307-
std::array<VkSubpassDependency, 2> dependencies;
307+
std::array<VkSubpassDependency, 4> dependencies{};
308308

309309
dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL;
310310
dependencies[0].dstSubpass = 0;
311-
dependencies[0].srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
312-
dependencies[0].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
313-
dependencies[0].srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
314-
dependencies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
315-
dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
316-
317-
dependencies[1].srcSubpass = 0;
318-
dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL;
319-
dependencies[1].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
320-
dependencies[1].dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
321-
dependencies[1].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
322-
dependencies[1].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
323-
dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
311+
dependencies[0].srcStageMask = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
312+
dependencies[0].dstStageMask = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
313+
dependencies[0].srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
314+
dependencies[0].dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
315+
316+
317+
dependencies[1].srcSubpass = VK_SUBPASS_EXTERNAL;
318+
dependencies[1].dstSubpass = 0;
319+
dependencies[1].srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
320+
dependencies[1].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
321+
dependencies[1].srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
322+
dependencies[1].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
323+
324+
dependencies[2].srcSubpass = 0;
325+
dependencies[2].dstSubpass = VK_SUBPASS_EXTERNAL;
326+
dependencies[2].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
327+
dependencies[2].dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
328+
dependencies[2].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
329+
dependencies[2].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
330+
331+
dependencies[3].srcSubpass = 0;
332+
dependencies[3].dstSubpass = VK_SUBPASS_EXTERNAL;
333+
dependencies[3].srcStageMask = VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
334+
dependencies[3].dstStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
335+
dependencies[3].srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
336+
dependencies[3].dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
324337

325338
// Create render pass
326339
VkRenderPassCreateInfo renderPassInfo = {};
@@ -329,19 +342,19 @@ namespace vks
329342
renderPassInfo.attachmentCount = static_cast<uint32_t>(attachmentDescriptions.size());
330343
renderPassInfo.subpassCount = 1;
331344
renderPassInfo.pSubpasses = &subpass;
332-
renderPassInfo.dependencyCount = 2;
345+
renderPassInfo.dependencyCount = 4;
333346
renderPassInfo.pDependencies = dependencies.data();
334347
VK_CHECK_RESULT(vkCreateRenderPass(vulkanDevice->logicalDevice, &renderPassInfo, nullptr, &renderPass));
335348

336349
std::vector<VkImageView> attachmentViews;
337-
for (auto attachment : attachments)
350+
for (auto& attachment : attachments)
338351
{
339352
attachmentViews.push_back(attachment.view);
340353
}
341354

342355
// Find. max number of layers across attachments
343356
uint32_t maxLayers = 0;
344-
for (auto attachment : attachments)
357+
for (auto& attachment : attachments)
345358
{
346359
if (attachment.subresourceRange.layerCount > maxLayers)
347360
{

base/VulkanInitializers.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ namespace vks
160160

161161
inline VkSubmitInfo submitInfo()
162162
{
163-
VkSubmitInfo submitInfo {};
164-
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
165-
return submitInfo;
163+
return { .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO };
166164
}
167165

168166
inline VkViewport viewport(

base/VulkanRaytracingSample.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Extended sample base class for ray tracing based samples
33
*
4-
* Copyright (C) 2020-2024 by Sascha Willems - www.saschawillems.de
4+
* Copyright (C) 2020-2025 by Sascha Willems - www.saschawillems.de
55
*
66
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
77
*/
@@ -139,6 +139,9 @@ void VulkanRaytracingSample::enableExtensions()
139139

140140
// Required by VK_KHR_spirv_1_4
141141
enabledDeviceExtensions.push_back(VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME);
142+
143+
// Format for the storage image is decided at runtime, so we can't explicilily state it in the shader
144+
enabledFeatures.shaderStorageImageWriteWithoutFormat = VK_TRUE;
142145
}
143146

144147
VulkanRaytracingSample::ScratchBuffer VulkanRaytracingSample::createScratchBuffer(VkDeviceSize size)

0 commit comments

Comments
 (0)