Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Fixed remaining warnings (MSVC VS2022)
  • Loading branch information
SaschaWillems committed Dec 27, 2023
1 parent f6e77be commit ac957ef
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 25 deletions.
6 changes: 6 additions & 0 deletions base/VulkanTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,5 +441,11 @@ namespace vks
return (value + alignment - 1) & ~(alignment - 1);
}


VkDeviceSize alignedVkSize(VkDeviceSize value, VkDeviceSize alignment)
{
return (value + alignment - 1) & ~(alignment - 1);
}

}
}
1 change: 1 addition & 0 deletions base/VulkanTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions examples/descriptorbuffer/descriptorbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion examples/descriptorindexing/descriptorindexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<short> 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<uint8_t> texture(bufferSize);
Expand Down
38 changes: 18 additions & 20 deletions examples/multisampling/multisampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions examples/shadowmappingomni/shadowmappingomni.cpp
Original file line number Diff line number Diff line change
@@ -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)
*/
Expand Down Expand Up @@ -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<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
// Load shaders
Expand Down

0 comments on commit ac957ef

Please sign in to comment.