Harden Vulkan setup for discrete GPUs

This commit is contained in:
Johanness
2026-05-24 00:15:55 +03:00
parent 8ef858e3c8
commit d7d0785c66
3 changed files with 49 additions and 8 deletions
+16
View File
@@ -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,
+4 -2
View File
@@ -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;
}
+29 -6
View File
@@ -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(