1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-19 23:52:10 +01:00

[dxvk] Add back-end function to compute linear image subresource layouts

This commit is contained in:
Philip Rebohle 2024-10-31 17:42:28 +01:00 committed by Philip Rebohle
parent 62970d24c3
commit 0896df7b9a
2 changed files with 68 additions and 0 deletions

View File

@ -42,6 +42,61 @@ namespace dxvk {
}
VkSubresourceLayout DxvkDevice::queryImageSubresourceLayout(
const DxvkImageCreateInfo& createInfo,
const VkImageSubresource& subresource) {
VkImageFormatListCreateInfo formatList = { VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO };
VkImageCreateInfo info = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO };
info.flags = createInfo.flags;
info.imageType = createInfo.type;
info.format = createInfo.format;
info.extent = createInfo.extent;
info.mipLevels = createInfo.mipLevels;
info.arrayLayers = createInfo.numLayers;
info.samples = createInfo.sampleCount;
info.tiling = VK_IMAGE_TILING_LINEAR;
info.usage = createInfo.usage;
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
if (createInfo.viewFormatCount && (createInfo.viewFormatCount > 1u || createInfo.viewFormats[0] != createInfo.format)) {
formatList.viewFormatCount = createInfo.viewFormatCount;
formatList.pViewFormats = createInfo.viewFormats;
info.pNext = &formatList;
}
if (m_features.khrMaintenance5.maintenance5) {
VkImageSubresource2KHR subresourceInfo = { VK_STRUCTURE_TYPE_IMAGE_SUBRESOURCE_2_KHR };
subresourceInfo.imageSubresource = subresource;
VkDeviceImageSubresourceInfoKHR query = { VK_STRUCTURE_TYPE_DEVICE_IMAGE_SUBRESOURCE_INFO_KHR };
query.pCreateInfo = &info;
query.pSubresource = &subresourceInfo;
VkSubresourceLayout2KHR layout = { VK_STRUCTURE_TYPE_SUBRESOURCE_LAYOUT_2_KHR };
m_vkd->vkGetDeviceImageSubresourceLayoutKHR(m_vkd->device(), &query, &layout);
return layout.subresourceLayout;
} else {
// Technically, there is no guarantee that all images with the same
// properties are going to have consistent subresource layouts if
// maintenance5 is not supported, but the only such use case we care
// about is RenderDoc.
VkImage image = VK_NULL_HANDLE;
VkResult vr = m_vkd->vkCreateImage(m_vkd->device(), &info, nullptr, &image);
if (vr != VK_SUCCESS)
throw DxvkError(str::format("Failed to create temporary image: ", vr));
VkSubresourceLayout layout = { };
m_vkd->vkGetImageSubresourceLayout(m_vkd->device(), image, &subresource, &layout);
m_vkd->vkDestroyImage(m_vkd->device(), image, nullptr);
return layout;
}
}
bool DxvkDevice::isUnifiedMemoryArchitecture() const {
return m_adapter->isUnifiedMemoryArchitecture();
}

View File

@ -208,6 +208,19 @@ namespace dxvk {
return m_submissionQueue.getLastError();
}
/**
* \brief Queries mapped image subresource layout
*
* Assumes that the image tiling is linear even
* if not explcitly set in the create info.
* \param [in] createInfo Image create info
* \param [in] subresource Subresource to query
* \returns Subresource layout
*/
VkSubresourceLayout queryImageSubresourceLayout(
const DxvkImageCreateInfo& createInfo,
const VkImageSubresource& subresource);
/**
* \brief Checks whether this is a UMA system
*