diff --git a/base/VulkanTools.cpp b/base/VulkanTools.cpp index 841758283..37f2f9cd7 100644 --- a/base/VulkanTools.cpp +++ b/base/VulkanTools.cpp @@ -441,5 +441,11 @@ namespace vks return (value + alignment - 1) & ~(alignment - 1); } + + VkDeviceSize alignedVkSize(VkDeviceSize value, VkDeviceSize alignment) + { + return (value + alignment - 1) & ~(alignment - 1); + } + } } diff --git a/base/VulkanTools.h b/base/VulkanTools.h index dc2323ce7..c358128b6 100644 --- a/base/VulkanTools.h +++ b/base/VulkanTools.h @@ -133,5 +133,6 @@ namespace vks bool fileExists(const std::string &filename); uint32_t alignedSize(uint32_t value, uint32_t alignment); + VkDeviceSize alignedVkSize(VkDeviceSize value, VkDeviceSize alignment); } } diff --git a/examples/descriptorbuffer/descriptorbuffer.cpp b/examples/descriptorbuffer/descriptorbuffer.cpp index 32beb2d73..b435eff19 100644 --- a/examples/descriptorbuffer/descriptorbuffer.cpp +++ b/examples/descriptorbuffer/descriptorbuffer.cpp @@ -204,8 +204,8 @@ class VulkanExample : public VulkanExampleBase vkGetDescriptorSetLayoutBindingOffsetEXT(device, combinedImageDescriptor.setLayout, 0, &combinedImageDescriptor.layoutOffset); // In order to copy resource descriptors to the correct place, we need to calculate aligned sizes - uniformDescriptor.layoutSize = vks::tools::alignedSize(uniformDescriptor.layoutSize, descriptorBufferProperties.descriptorBufferOffsetAlignment); - combinedImageDescriptor.layoutSize = vks::tools::alignedSize(combinedImageDescriptor.layoutSize, descriptorBufferProperties.descriptorBufferOffsetAlignment); + uniformDescriptor.layoutSize = vks::tools::alignedVkSize(uniformDescriptor.layoutSize, descriptorBufferProperties.descriptorBufferOffsetAlignment); + combinedImageDescriptor.layoutSize = vks::tools::alignedVkSize(combinedImageDescriptor.layoutSize, descriptorBufferProperties.descriptorBufferOffsetAlignment); // This buffer will contain resource descriptors for all the uniform buffers (one per cube and one with global matrices) VK_CHECK_RESULT(vulkanDevice->createBuffer( diff --git a/examples/descriptorindexing/descriptorindexing.cpp b/examples/descriptorindexing/descriptorindexing.cpp index b174ac30e..78943b062 100644 --- a/examples/descriptorindexing/descriptorindexing.cpp +++ b/examples/descriptorindexing/descriptorindexing.cpp @@ -100,7 +100,7 @@ class VulkanExample : public VulkanExampleBase for (size_t i = 0; i < textures.size(); i++) { std::random_device rndDevice; std::default_random_engine rndEngine(rndDevice()); - std::uniform_int_distribution rndDist(50, 255); + std::uniform_int_distribution<> rndDist(50, UCHAR_MAX); const int32_t dim = 3; const size_t bufferSize = dim * dim * 4; std::vector texture(bufferSize); diff --git a/examples/multisampling/multisampling.cpp b/examples/multisampling/multisampling.cpp index 33a9a40e4..4272ae2f5 100644 --- a/examples/multisampling/multisampling.cpp +++ b/examples/multisampling/multisampling.cpp @@ -98,7 +98,7 @@ class VulkanExample : public VulkanExampleBase void setupMultisampleTarget() { // Check if device supports requested sample count for color and depth frame buffer - assert((deviceProperties.limits.framebufferColorSampleCounts >= sampleCount) && (deviceProperties.limits.framebufferDepthSampleCounts >= sampleCount)); + assert((deviceProperties.limits.framebufferColorSampleCounts & sampleCount) && (deviceProperties.limits.framebufferDepthSampleCounts & sampleCount)); // Color target VkImageCreateInfo info = vks::initializers::imageCreateInfo(); @@ -503,20 +503,31 @@ class VulkanExample : public VulkanExampleBase void draw() { VulkanExampleBase::prepareFrame(); - - // Command buffer to be sumitted to the queue submitInfo.commandBufferCount = 1; submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer]; - - // Submit to queue VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE)); - VulkanExampleBase::submitFrame(); } + // Select the highest sample count usable by the platform + // In a realworld application, this would be a user setting instead + VkSampleCountFlagBits getMaxAvailableSampleCount() + { + VkSampleCountFlags supportedSampleCount = std::min(deviceProperties.limits.framebufferColorSampleCounts, deviceProperties.limits.framebufferDepthSampleCounts); + std::vector< VkSampleCountFlagBits> possibleSampleCounts { + VK_SAMPLE_COUNT_64_BIT, VK_SAMPLE_COUNT_32_BIT, VK_SAMPLE_COUNT_16_BIT, VK_SAMPLE_COUNT_8_BIT, VK_SAMPLE_COUNT_4_BIT, VK_SAMPLE_COUNT_2_BIT + }; + for (auto& possibleSampleCount : possibleSampleCounts) { + if (supportedSampleCount & possibleSampleCount) { + return possibleSampleCount; + } + } + return VK_SAMPLE_COUNT_1_BIT; + } + void prepare() { - sampleCount = getMaxUsableSampleCount(); + sampleCount = getMaxAvailableSampleCount(); UIOverlay.rasterizationSamples = sampleCount; VulkanExampleBase::prepare(); loadAssets(); @@ -544,19 +555,6 @@ class VulkanExample : public VulkanExampleBase updateUniformBuffers(); } - // Returns the maximum sample count usable by the platform - VkSampleCountFlagBits getMaxUsableSampleCount() - { - VkSampleCountFlags counts = std::min(deviceProperties.limits.framebufferColorSampleCounts, deviceProperties.limits.framebufferDepthSampleCounts); - if (counts & VK_SAMPLE_COUNT_64_BIT) { return VK_SAMPLE_COUNT_64_BIT; } - if (counts & VK_SAMPLE_COUNT_32_BIT) { return VK_SAMPLE_COUNT_32_BIT; } - if (counts & VK_SAMPLE_COUNT_16_BIT) { return VK_SAMPLE_COUNT_16_BIT; } - if (counts & VK_SAMPLE_COUNT_8_BIT) { return VK_SAMPLE_COUNT_8_BIT; } - if (counts & VK_SAMPLE_COUNT_4_BIT) { return VK_SAMPLE_COUNT_4_BIT; } - if (counts & VK_SAMPLE_COUNT_2_BIT) { return VK_SAMPLE_COUNT_2_BIT; } - return VK_SAMPLE_COUNT_1_BIT; - } - virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { if (vulkanDevice->features.sampleRateShading) { diff --git a/examples/shadowmappingomni/shadowmappingomni.cpp b/examples/shadowmappingomni/shadowmappingomni.cpp index deb40d99f..5ee8a3318 100644 --- a/examples/shadowmappingomni/shadowmappingomni.cpp +++ b/examples/shadowmappingomni/shadowmappingomni.cpp @@ -1,7 +1,7 @@ /* * Vulkan Example - Omni directional shadows using a dynamic cube map * -* Copyright (C) 2016-2023by Sascha Willems - www.saschawillems.de +* Copyright (C) 2016-2023 by Sascha Willems - www.saschawillems.de * * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) */ @@ -609,7 +609,7 @@ class VulkanExample : public VulkanExampleBase VkPipelineViewportStateCreateInfo viewportState = vks::initializers::pipelineViewportStateCreateInfo(1, 1, 0); VkPipelineMultisampleStateCreateInfo multisampleState = vks::initializers::pipelineMultisampleStateCreateInfo(VK_SAMPLE_COUNT_1_BIT, 0); std::vector dynamicStateEnables = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; - VkPipelineDynamicStateCreateInfo dynamicState = vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables.data(), dynamicStateEnables.size(), 0); + VkPipelineDynamicStateCreateInfo dynamicState = vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables); // 3D scene pipeline // Load shaders