From d7d0785c6661b6c0ce5189df0cba9497ad57569f Mon Sep 17 00:00:00 2001 From: Johanness Date: Sun, 24 May 2026 00:15:55 +0300 Subject: [PATCH] Harden Vulkan setup for discrete GPUs --- V210ComputeDecoder.cpp | 16 ++++++++++++++++ VulkanContext.cpp | 6 ++++-- VulkanUtils.cpp | 35 +++++++++++++++++++++++++++++------ 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/V210ComputeDecoder.cpp b/V210ComputeDecoder.cpp index 864ec27..bb96fd9 100644 --- a/V210ComputeDecoder.cpp +++ b/V210ComputeDecoder.cpp @@ -266,6 +266,22 @@ void V210ComputeDecoder::createFeedResources( << " flags=0x" << std::hex << feed.v210MemoryProperties << std::dec << std::endl; + VkFormatProperties outputFormatProperties{}; + vkGetPhysicalDeviceFormatProperties( + physicalDevice, + VK_FORMAT_R8G8B8A8_UNORM, + &outputFormatProperties); + const VkFormatFeatureFlags requiredOutputFeatures = + VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT | + VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT; + if ((outputFormatProperties.optimalTilingFeatures & + requiredOutputFeatures) != requiredOutputFeatures) + { + throw std::runtime_error( + "VK_FORMAT_R8G8B8A8_UNORM does not support sampled " + "storage images on this GPU"); + } + createImage( m_device, physicalDevice, diff --git a/VulkanContext.cpp b/VulkanContext.cpp index b6af7b3..99d1ffa 100644 --- a/VulkanContext.cpp +++ b/VulkanContext.cpp @@ -30,8 +30,10 @@ QueueFamilyIndices findQueueFamilies( for (uint32_t i = 0; i < queueFamilyCount; ++i) { - if (queueFamilies[i].queueFlags & - VK_QUEUE_GRAPHICS_BIT) + if ((queueFamilies[i].queueFlags & + VK_QUEUE_GRAPHICS_BIT) && + (queueFamilies[i].queueFlags & + VK_QUEUE_COMPUTE_BIT)) { indices.graphicsFamily = i; } diff --git a/VulkanUtils.cpp b/VulkanUtils.cpp index f7bbca1..37c3976 100644 --- a/VulkanUtils.cpp +++ b/VulkanUtils.cpp @@ -117,7 +117,10 @@ void createBuffer( throw std::runtime_error("Failed to allocate buffer memory"); } - vkBindBufferMemory(device, buffer, bufferMemory, 0); + if (vkBindBufferMemory(device, buffer, bufferMemory, 0) != VK_SUCCESS) + { + throw std::runtime_error("Failed to bind buffer memory"); + } } void createBufferWithPreferredMemory( @@ -161,7 +164,10 @@ void createBufferWithPreferredMemory( throw std::runtime_error("Failed to allocate buffer memory"); } - vkBindBufferMemory(device, buffer, bufferMemory, 0); + if (vkBindBufferMemory(device, buffer, bufferMemory, 0) != VK_SUCCESS) + { + throw std::runtime_error("Failed to bind buffer memory"); + } } VkCommandBuffer beginSingleTimeCommands( @@ -192,15 +198,29 @@ void endSingleTimeCommands( VkQueue graphicsQueue, VkCommandBuffer commandBuffer) { - vkEndCommandBuffer(commandBuffer); + if (vkEndCommandBuffer(commandBuffer) != VK_SUCCESS) + { + throw std::runtime_error("Failed to end one-time command buffer"); + } VkSubmitInfo submitInfo{}; submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; submitInfo.commandBufferCount = 1; submitInfo.pCommandBuffers = &commandBuffer; - vkQueueSubmit(graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE); - vkQueueWaitIdle(graphicsQueue); + if (vkQueueSubmit( + graphicsQueue, + 1, + &submitInfo, + VK_NULL_HANDLE) != VK_SUCCESS) + { + throw std::runtime_error("Failed to submit one-time command buffer"); + } + + if (vkQueueWaitIdle(graphicsQueue) != VK_SUCCESS) + { + throw std::runtime_error("Failed to wait for one-time command buffer"); + } vkFreeCommandBuffers(device, commandPool, 1, &commandBuffer); } @@ -254,7 +274,10 @@ void createImage( throw std::runtime_error("Failed to allocate image memory"); } - vkBindImageMemory(device, image, imageMemory, 0); + if (vkBindImageMemory(device, image, imageMemory, 0) != VK_SUCCESS) + { + throw std::runtime_error("Failed to bind image memory"); + } } void recordImageLayoutTransition(