From 514d3e5393574e3bc9693ef0d97869b2771d3d71 Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Tue, 22 Oct 2024 21:06:05 +0200 Subject: [PATCH] Minor code cleanup, check for device limits --- examples/descriptorbuffer/descriptorbuffer.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/descriptorbuffer/descriptorbuffer.cpp b/examples/descriptorbuffer/descriptorbuffer.cpp index d74a34ec3..951e8027e 100644 --- a/examples/descriptorbuffer/descriptorbuffer.cpp +++ b/examples/descriptorbuffer/descriptorbuffer.cpp @@ -97,7 +97,7 @@ class VulkanExample : public VulkanExampleBase vkDestroyDescriptorSetLayout(device, combinedImageDescriptor.setLayout, nullptr); vkDestroyPipeline(device, pipeline, nullptr); vkDestroyPipelineLayout(device, pipelineLayout, nullptr); - for (auto cube : cubes) { + for (auto& cube : cubes) { cube.uniformBuffer.destroy(); cube.texture.destroy(); } @@ -163,7 +163,10 @@ class VulkanExample : public VulkanExampleBase VkPipelineViewportStateCreateInfo viewportStateCI = vks::initializers::pipelineViewportStateCreateInfo(1, 1, 0); VkPipelineMultisampleStateCreateInfo multisampleStateCI = vks::initializers::pipelineMultisampleStateCreateInfo(VK_SAMPLE_COUNT_1_BIT, 0); VkPipelineDynamicStateCreateInfo dynamicStateCI = vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables.data(), static_cast(dynamicStateEnables.size()), 0); - std::array shaderStages; + std::array shaderStages = { + loadShader(getShadersPath() + "descriptorbuffer/cube.vert.spv", VK_SHADER_STAGE_VERTEX_BIT), + loadShader(getShadersPath() + "descriptorbuffer/cube.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT) + }; VkGraphicsPipelineCreateInfo pipelineCI = vks::initializers::pipelineCreateInfo(pipelineLayout, renderPass, 0); pipelineCI.pInputAssemblyState = &inputAssemblyStateCI; @@ -177,9 +180,6 @@ class VulkanExample : public VulkanExampleBase pipelineCI.pStages = shaderStages.data(); pipelineCI.pVertexInputState = vkglTF::Vertex::getPipelineVertexInputState({ vkglTF::VertexComponent::Position, vkglTF::VertexComponent::Normal, vkglTF::VertexComponent::UV, vkglTF::VertexComponent::Color }); pipelineCI.flags = VK_PIPELINE_CREATE_DESCRIPTOR_BUFFER_BIT_EXT; - - shaderStages[0] = loadShader(getShadersPath() + "descriptorbuffer/cube.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); - shaderStages[1] = loadShader(getShadersPath() + "descriptorbuffer/cube.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipeline)); } @@ -196,6 +196,11 @@ class VulkanExample : public VulkanExampleBase deviceProps2.pNext = &descriptorBufferProperties; vkGetPhysicalDeviceProperties2KHR(physicalDevice, &deviceProps2); + // Some devices have very low limits for the no. of max descriptor buffer bindings, so we need to check + if (descriptorBufferProperties.maxResourceDescriptorBufferBindings < 2) { + vks::tools::exitFatal("This sample requires at least 2 descriptor bindings to run, the selected device only supports " + std::to_string(descriptorBufferProperties.maxResourceDescriptorBufferBindings), - 1); + } + vkGetDescriptorSetLayoutSizeEXT(device, uniformDescriptor.setLayout, &uniformDescriptor.layoutSize); vkGetDescriptorSetLayoutSizeEXT(device, combinedImageDescriptor.setLayout, &combinedImageDescriptor.layoutSize); @@ -268,7 +273,7 @@ class VulkanExample : public VulkanExampleBase { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); - VkClearValue clearValues[2]; + VkClearValue clearValues[2]{}; clearValues[0].color = defaultClearColor; clearValues[1].depthStencil = { 1.0f, 0 };