From ed4c4684c556de2dbef35c82d56e8793e0a0b446 Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Fri, 22 Dec 2023 14:30:18 +0100 Subject: [PATCH] Code cleanup. fixes warnings --- .../computeraytracing/computeraytracing.cpp | 18 +++++----------- examples/computeshader/computeshader.cpp | 21 ++++++++----------- examples/dynamicstate/dynamicstate.cpp | 2 +- examples/instancing/instancing.cpp | 4 ++-- .../negativeviewportheight.cpp | 10 ++++----- examples/texture3d/texture3d.cpp | 8 +++---- examples/texturecubemap/texturecubemap.cpp | 4 +--- .../texturemipmapgen/texturemipmapgen.cpp | 2 +- 8 files changed, 28 insertions(+), 41 deletions(-) diff --git a/examples/computeraytracing/computeraytracing.cpp b/examples/computeraytracing/computeraytracing.cpp index ac27db98..8096bb32 100644 --- a/examples/computeraytracing/computeraytracing.cpp +++ b/examples/computeraytracing/computeraytracing.cpp @@ -485,10 +485,7 @@ public: }; VkDescriptorPoolCreateInfo descriptorPoolInfo = - vks::initializers::descriptorPoolCreateInfo( - poolSizes.size(), - poolSizes.data(), - 3); + vks::initializers::descriptorPoolCreateInfo(poolSizes, 3); VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolInfo, nullptr, &descriptorPool)); } @@ -539,7 +536,7 @@ public: &textureComputeTarget.descriptor) }; - vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); + vkUpdateDescriptorSets(device, static_cast(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, nullptr); } void preparePipelines() @@ -586,10 +583,7 @@ public: VK_DYNAMIC_STATE_SCISSOR }; VkPipelineDynamicStateCreateInfo dynamicState = - vks::initializers::pipelineDynamicStateCreateInfo( - dynamicStateEnables.data(), - dynamicStateEnables.size(), - 0); + vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables); // Display pipeline std::array shaderStages; @@ -663,9 +657,7 @@ public: }; VkDescriptorSetLayoutCreateInfo descriptorLayout = - vks::initializers::descriptorSetLayoutCreateInfo( - setLayoutBindings.data(), - setLayoutBindings.size()); + vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings); VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorLayout, nullptr, &compute.descriptorSetLayout)); @@ -712,7 +704,7 @@ public: &compute.storageBuffers.planes.descriptor) }; - vkUpdateDescriptorSets(device, computeWriteDescriptorSets.size(), computeWriteDescriptorSets.data(), 0, NULL); + vkUpdateDescriptorSets(device, static_cast(computeWriteDescriptorSets.size()), computeWriteDescriptorSets.data(), 0, nullptr); // Create compute shader pipelines VkComputePipelineCreateInfo computePipelineCreateInfo = diff --git a/examples/computeshader/computeshader.cpp b/examples/computeshader/computeshader.cpp index fbf66a21..496d519f 100644 --- a/examples/computeshader/computeshader.cpp +++ b/examples/computeshader/computeshader.cpp @@ -1,7 +1,7 @@ /* * Vulkan Example - Compute shader image processing * -* Copyright (C) 2016 by 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) */ @@ -174,7 +174,7 @@ public: sampler.maxAnisotropy = 1.0f; sampler.compareOp = VK_COMPARE_OP_NEVER; sampler.minLod = 0.0f; - sampler.maxLod = tex->mipLevels; + sampler.maxLod = static_cast(tex->mipLevels); sampler.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; VK_CHECK_RESULT(vkCreateSampler(device, &sampler, nullptr, &tex->sampler)); @@ -347,9 +347,9 @@ public: // Assign to vertex buffer vertices.inputState = vks::initializers::pipelineVertexInputStateCreateInfo(); - vertices.inputState.vertexBindingDescriptionCount = vertices.bindingDescriptions.size(); + vertices.inputState.vertexBindingDescriptionCount = static_cast(vertices.bindingDescriptions.size()); vertices.inputState.pVertexBindingDescriptions = vertices.bindingDescriptions.data(); - vertices.inputState.vertexAttributeDescriptionCount = vertices.attributeDescriptions.size(); + vertices.inputState.vertexAttributeDescriptionCount = static_cast(vertices.attributeDescriptions.size()); vertices.inputState.pVertexAttributeDescriptions = vertices.attributeDescriptions.data(); } @@ -394,7 +394,7 @@ public: vks::initializers::writeDescriptorSet(graphics.descriptorSetPreCompute, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBufferVS.descriptor), vks::initializers::writeDescriptorSet(graphics.descriptorSetPreCompute, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &textureColorMap.descriptor) }; - vkUpdateDescriptorSets(device, baseImageWriteDescriptorSets.size(), baseImageWriteDescriptorSets.data(), 0, nullptr); + vkUpdateDescriptorSets(device, static_cast(baseImageWriteDescriptorSets.size()), baseImageWriteDescriptorSets.data(), 0, nullptr); // Final image (after compute shader processing) VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &graphics.descriptorSetPostCompute)); @@ -402,7 +402,7 @@ public: vks::initializers::writeDescriptorSet(graphics.descriptorSetPostCompute, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBufferVS.descriptor), vks::initializers::writeDescriptorSet(graphics.descriptorSetPostCompute, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &textureComputeTarget.descriptor) }; - vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, nullptr); + vkUpdateDescriptorSets(device, static_cast(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, nullptr); } @@ -450,10 +450,7 @@ public: VK_DYNAMIC_STATE_SCISSOR }; VkPipelineDynamicStateCreateInfo dynamicState = - vks::initializers::pipelineDynamicStateCreateInfo( - dynamicStateEnables.data(), - dynamicStateEnables.size(), - 0); + vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables); // Rendering pipeline // Load shaders @@ -476,7 +473,7 @@ public: pipelineCreateInfo.pViewportState = &viewportState; pipelineCreateInfo.pDepthStencilState = &depthStencilState; pipelineCreateInfo.pDynamicState = &dynamicState; - pipelineCreateInfo.stageCount = shaderStages.size(); + pipelineCreateInfo.stageCount = static_cast(shaderStages.size()); pipelineCreateInfo.pStages = shaderStages.data(); pipelineCreateInfo.renderPass = renderPass; @@ -528,7 +525,7 @@ public: vks::initializers::writeDescriptorSet(compute.descriptorSet, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 0, &textureColorMap.descriptor), vks::initializers::writeDescriptorSet(compute.descriptorSet, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1, &textureComputeTarget.descriptor) }; - vkUpdateDescriptorSets(device, computeWriteDescriptorSets.size(), computeWriteDescriptorSets.data(), 0, NULL); + vkUpdateDescriptorSets(device, static_cast(computeWriteDescriptorSets.size()), computeWriteDescriptorSets.data(), 0, nullptr); // Create compute shader pipelines VkComputePipelineCreateInfo computePipelineCreateInfo = diff --git a/examples/dynamicstate/dynamicstate.cpp b/examples/dynamicstate/dynamicstate.cpp index dd67bded..688c8913 100644 --- a/examples/dynamicstate/dynamicstate.cpp +++ b/examples/dynamicstate/dynamicstate.cpp @@ -226,7 +226,7 @@ public: &uniformBuffer.descriptor) }; - vkUpdateDescriptorSets(device, writeDescriptorSets.size(), writeDescriptorSets.data(), 0, NULL); + vkUpdateDescriptorSets(device, static_cast(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, nullptr); } void preparePipelines() diff --git a/examples/instancing/instancing.cpp b/examples/instancing/instancing.cpp index b3bc3f03..e3b57e85 100644 --- a/examples/instancing/instancing.cpp +++ b/examples/instancing/instancing.cpp @@ -339,7 +339,7 @@ public: // Inner ring rho = sqrt((pow(ring0[1], 2.0f) - pow(ring0[0], 2.0f)) * uniformDist(rndGenerator) + pow(ring0[0], 2.0f)); - theta = 2.0f * M_PI * uniformDist(rndGenerator); + theta = static_cast(2.0f * M_PI * uniformDist(rndGenerator)); instanceData[i].pos = glm::vec3(rho*cos(theta), uniformDist(rndGenerator) * 0.5f - 0.25f, rho*sin(theta)); instanceData[i].rot = glm::vec3(M_PI * uniformDist(rndGenerator), M_PI * uniformDist(rndGenerator), M_PI * uniformDist(rndGenerator)); instanceData[i].scale = 1.5f + uniformDist(rndGenerator) - uniformDist(rndGenerator); @@ -348,7 +348,7 @@ public: // Outer ring rho = sqrt((pow(ring1[1], 2.0f) - pow(ring1[0], 2.0f)) * uniformDist(rndGenerator) + pow(ring1[0], 2.0f)); - theta = 2.0f * M_PI * uniformDist(rndGenerator); + theta = static_cast(2.0f * M_PI * uniformDist(rndGenerator)); instanceData[i + INSTANCE_COUNT / 2].pos = glm::vec3(rho*cos(theta), uniformDist(rndGenerator) * 0.5f - 0.25f, rho*sin(theta)); instanceData[i + INSTANCE_COUNT / 2].rot = glm::vec3(M_PI * uniformDist(rndGenerator), M_PI * uniformDist(rndGenerator), M_PI * uniformDist(rndGenerator)); instanceData[i + INSTANCE_COUNT / 2].scale = 1.5f + uniformDist(rndGenerator) - uniformDist(rndGenerator); diff --git a/examples/negativeviewportheight/negativeviewportheight.cpp b/examples/negativeviewportheight/negativeviewportheight.cpp index bf86730b..594b412c 100644 --- a/examples/negativeviewportheight/negativeviewportheight.cpp +++ b/examples/negativeviewportheight/negativeviewportheight.cpp @@ -3,7 +3,7 @@ * * Note: Requires a device that supports VK_KHR_MAINTENANCE1 * -* Copyright (C) by 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) */ @@ -16,8 +16,8 @@ class VulkanExample : public VulkanExampleBase { public: bool negativeViewport = true; - int32_t offsety = 0; - int32_t offsetx = 0; + float offsety = 0.0f; + float offsetx = 0.0f; int32_t windingOrder = 1; int32_t cullMode = (int32_t)VK_CULL_MODE_BACK_BIT; int32_t quadType = 0; @@ -303,10 +303,10 @@ public: if (overlay->checkBox("Negative viewport height", &negativeViewport)) { buildCommandBuffers(); } - if (overlay->sliderInt("offset x", &offsetx, -(int32_t)width, (int32_t)width)) { + if (overlay->sliderFloat("offset x", &offsetx, -(float)width, (float)width)) { buildCommandBuffers(); } - if (overlay->sliderInt("offset y", &offsety, -(int32_t)height, (int32_t)height)) { + if (overlay->sliderFloat("offset y", &offsety, -(float)height, (float)height)) { buildCommandBuffers(); } } diff --git a/examples/texture3d/texture3d.cpp b/examples/texture3d/texture3d.cpp index 47ca5df6..ab330b0e 100644 --- a/examples/texture3d/texture3d.cpp +++ b/examples/texture3d/texture3d.cpp @@ -1,7 +1,7 @@ /* * Vulkan Example - 3D texture loading (and generation using perlin noise) example * -* Copyright (C) 2016 by 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) */ @@ -306,11 +306,11 @@ public: const float noiseScale = static_cast(rand() % 10) + 4.0f; #pragma omp parallel for - for (int32_t z = 0; z < texture.depth; z++) + for (int32_t z = 0; z < static_cast(texture.depth); z++) { - for (int32_t y = 0; y < texture.height; y++) + for (int32_t y = 0; y < static_cast(texture.height); y++) { - for (int32_t x = 0; x < texture.width; x++) + for (int32_t x = 0; x < static_cast(texture.width); x++) { float nx = (float)x / (float)texture.width; float ny = (float)y / (float)texture.height; diff --git a/examples/texturecubemap/texturecubemap.cpp b/examples/texturecubemap/texturecubemap.cpp index 7b1839ce..ab88aba3 100644 --- a/examples/texturecubemap/texturecubemap.cpp +++ b/examples/texturecubemap/texturecubemap.cpp @@ -386,9 +386,7 @@ public: }; VkDescriptorSetLayoutCreateInfo descriptorLayout = - vks::initializers::descriptorSetLayoutCreateInfo( - setLayoutBindings.data(), - setLayoutBindings.size()); + vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings); VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorLayout, nullptr, &descriptorSetLayout)); diff --git a/examples/texturemipmapgen/texturemipmapgen.cpp b/examples/texturemipmapgen/texturemipmapgen.cpp index 61f81486..561bd6db 100644 --- a/examples/texturemipmapgen/texturemipmapgen.cpp +++ b/examples/texturemipmapgen/texturemipmapgen.cpp @@ -114,7 +114,7 @@ public: // calculate num of mip maps // numLevels = 1 + floor(log2(max(w, h, d))) // Calculated as log2(max(width, height, depth))c + 1 (see specs) - texture.mipLevels = floor(log2(std::max(texture.width, texture.height))) + 1; + texture.mipLevels = static_cast(floor(log2(std::max(texture.width, texture.height))) + 1); // Get device properties for the requested texture format VkFormatProperties formatProperties;