Code cleanup

Fixed remaining warnings (MSVC VS2022)
This commit is contained in:
Sascha Willems 2023-12-27 19:58:33 +01:00
parent f6e77be11f
commit ac957ef8af
6 changed files with 30 additions and 25 deletions

View file

@ -441,5 +441,11 @@ namespace vks
return (value + alignment - 1) & ~(alignment - 1); return (value + alignment - 1) & ~(alignment - 1);
} }
VkDeviceSize alignedVkSize(VkDeviceSize value, VkDeviceSize alignment)
{
return (value + alignment - 1) & ~(alignment - 1);
}
} }
} }

View file

@ -133,5 +133,6 @@ namespace vks
bool fileExists(const std::string &filename); bool fileExists(const std::string &filename);
uint32_t alignedSize(uint32_t value, uint32_t alignment); uint32_t alignedSize(uint32_t value, uint32_t alignment);
VkDeviceSize alignedVkSize(VkDeviceSize value, VkDeviceSize alignment);
} }
} }

View file

@ -204,8 +204,8 @@ public:
vkGetDescriptorSetLayoutBindingOffsetEXT(device, combinedImageDescriptor.setLayout, 0, &combinedImageDescriptor.layoutOffset); vkGetDescriptorSetLayoutBindingOffsetEXT(device, combinedImageDescriptor.setLayout, 0, &combinedImageDescriptor.layoutOffset);
// In order to copy resource descriptors to the correct place, we need to calculate aligned sizes // 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); uniformDescriptor.layoutSize = vks::tools::alignedVkSize(uniformDescriptor.layoutSize, descriptorBufferProperties.descriptorBufferOffsetAlignment);
combinedImageDescriptor.layoutSize = vks::tools::alignedSize(combinedImageDescriptor.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) // This buffer will contain resource descriptors for all the uniform buffers (one per cube and one with global matrices)
VK_CHECK_RESULT(vulkanDevice->createBuffer( VK_CHECK_RESULT(vulkanDevice->createBuffer(

View file

@ -100,7 +100,7 @@ public:
for (size_t i = 0; i < textures.size(); i++) { for (size_t i = 0; i < textures.size(); i++) {
std::random_device rndDevice; std::random_device rndDevice;
std::default_random_engine rndEngine(rndDevice()); std::default_random_engine rndEngine(rndDevice());
std::uniform_int_distribution<short> rndDist(50, 255); std::uniform_int_distribution<> rndDist(50, UCHAR_MAX);
const int32_t dim = 3; const int32_t dim = 3;
const size_t bufferSize = dim * dim * 4; const size_t bufferSize = dim * dim * 4;
std::vector<uint8_t> texture(bufferSize); std::vector<uint8_t> texture(bufferSize);

View file

@ -98,7 +98,7 @@ public:
void setupMultisampleTarget() void setupMultisampleTarget()
{ {
// Check if device supports requested sample count for color and depth frame buffer // 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 // Color target
VkImageCreateInfo info = vks::initializers::imageCreateInfo(); VkImageCreateInfo info = vks::initializers::imageCreateInfo();
@ -503,20 +503,31 @@ public:
void draw() void draw()
{ {
VulkanExampleBase::prepareFrame(); VulkanExampleBase::prepareFrame();
// Command buffer to be sumitted to the queue
submitInfo.commandBufferCount = 1; submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer]; submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
// Submit to queue
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE)); VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
VulkanExampleBase::submitFrame(); 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() void prepare()
{ {
sampleCount = getMaxUsableSampleCount(); sampleCount = getMaxAvailableSampleCount();
UIOverlay.rasterizationSamples = sampleCount; UIOverlay.rasterizationSamples = sampleCount;
VulkanExampleBase::prepare(); VulkanExampleBase::prepare();
loadAssets(); loadAssets();
@ -544,19 +555,6 @@ public:
updateUniformBuffers(); 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) virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
{ {
if (vulkanDevice->features.sampleRateShading) { if (vulkanDevice->features.sampleRateShading) {

View file

@ -1,7 +1,7 @@
/* /*
* Vulkan Example - Omni directional shadows using a dynamic cube map * 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) * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/ */
@ -609,7 +609,7 @@ public:
VkPipelineViewportStateCreateInfo viewportState = vks::initializers::pipelineViewportStateCreateInfo(1, 1, 0); VkPipelineViewportStateCreateInfo viewportState = vks::initializers::pipelineViewportStateCreateInfo(1, 1, 0);
VkPipelineMultisampleStateCreateInfo multisampleState = vks::initializers::pipelineMultisampleStateCreateInfo(VK_SAMPLE_COUNT_1_BIT, 0); VkPipelineMultisampleStateCreateInfo multisampleState = vks::initializers::pipelineMultisampleStateCreateInfo(VK_SAMPLE_COUNT_1_BIT, 0);
std::vector<VkDynamicState> dynamicStateEnables = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; std::vector<VkDynamicState> 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 // 3D scene pipeline
// Load shaders // Load shaders