1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-03-14 22:29:15 +01:00

[dxvk] Introduce DxvkPhysicalImage

This commit is contained in:
Philip Rebohle 2020-01-08 16:14:45 +01:00 committed by Philip Rebohle
parent 2c457e496a
commit 5193e8ef24
2 changed files with 23 additions and 15 deletions

View File

@ -41,7 +41,7 @@ namespace dxvk {
info.initialLayout = createInfo.initialLayout; info.initialLayout = createInfo.initialLayout;
if (m_vkd->vkCreateImage(m_vkd->device(), if (m_vkd->vkCreateImage(m_vkd->device(),
&info, nullptr, &m_image) != VK_SUCCESS) { &info, nullptr, &m_image.image) != VK_SUCCESS) {
throw DxvkError(str::format( throw DxvkError(str::format(
"DxvkImage: Failed to create image:", "DxvkImage: Failed to create image:",
"\n Type: ", info.imageType, "\n Type: ", info.imageType,
@ -72,14 +72,14 @@ namespace dxvk {
VkImageMemoryRequirementsInfo2KHR memReqInfo; VkImageMemoryRequirementsInfo2KHR memReqInfo;
memReqInfo.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2_KHR; memReqInfo.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2_KHR;
memReqInfo.image = m_image; memReqInfo.image = m_image.image;
memReqInfo.pNext = VK_NULL_HANDLE; memReqInfo.pNext = VK_NULL_HANDLE;
VkMemoryDedicatedAllocateInfoKHR dedMemoryAllocInfo; VkMemoryDedicatedAllocateInfoKHR dedMemoryAllocInfo;
dedMemoryAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR; dedMemoryAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR;
dedMemoryAllocInfo.pNext = VK_NULL_HANDLE; dedMemoryAllocInfo.pNext = VK_NULL_HANDLE;
dedMemoryAllocInfo.buffer = VK_NULL_HANDLE; dedMemoryAllocInfo.buffer = VK_NULL_HANDLE;
dedMemoryAllocInfo.image = m_image; dedMemoryAllocInfo.image = m_image.image;
m_vkd->vkGetImageMemoryRequirements2KHR( m_vkd->vkGetImageMemoryRequirements2KHR(
m_vkd->device(), &memReqInfo, &memReq); m_vkd->device(), &memReqInfo, &memReq);
@ -98,12 +98,12 @@ namespace dxvk {
float priority = isGpuWritable ? 1.0f : 0.5f; float priority = isGpuWritable ? 1.0f : 0.5f;
// Ask driver whether we should be using a dedicated allocation // Ask driver whether we should be using a dedicated allocation
m_memory = memAlloc.alloc(&memReq.memoryRequirements, m_image.memory = memAlloc.alloc(&memReq.memoryRequirements,
dedicatedRequirements, dedMemoryAllocInfo, memFlags, priority); dedicatedRequirements, dedMemoryAllocInfo, memFlags, priority);
// Try to bind the allocated memory slice to the image // Try to bind the allocated memory slice to the image
if (m_vkd->vkBindImageMemory(m_vkd->device(), if (m_vkd->vkBindImageMemory(m_vkd->device(), m_image.image,
m_image, m_memory.memory(), m_memory.offset()) != VK_SUCCESS) m_image.memory.memory(), m_image.memory.offset()) != VK_SUCCESS)
throw DxvkError("DxvkImage::DxvkImage: Failed to bind device memory"); throw DxvkError("DxvkImage::DxvkImage: Failed to bind device memory");
} }
@ -112,7 +112,7 @@ namespace dxvk {
const Rc<vk::DeviceFn>& vkd, const Rc<vk::DeviceFn>& vkd,
const DxvkImageCreateInfo& info, const DxvkImageCreateInfo& info,
VkImage image) VkImage image)
: m_vkd(vkd), m_info(info), m_image(image) { : m_vkd(vkd), m_info(info), m_image({ image }) {
} }
@ -120,8 +120,8 @@ namespace dxvk {
DxvkImage::~DxvkImage() { DxvkImage::~DxvkImage() {
// This is a bit of a hack to determine whether // This is a bit of a hack to determine whether
// the image is implementation-handled or not // the image is implementation-handled or not
if (m_memory.memory() != VK_NULL_HANDLE) if (m_image.memory.memory() != VK_NULL_HANDLE)
m_vkd->vkDestroyImage(m_vkd->device(), m_image, nullptr); m_vkd->vkDestroyImage(m_vkd->device(), m_image.image, nullptr);
} }

View File

@ -96,6 +96,15 @@ namespace dxvk {
VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
}; };
}; };
/**
* \brief Stores an image and its memory slice.
*/
struct DxvkPhysicalImage {
VkImage image = VK_NULL_HANDLE;
DxvkMemory memory;
};
/** /**
@ -143,7 +152,7 @@ namespace dxvk {
* \returns Image handle * \returns Image handle
*/ */
VkImage handle() const { VkImage handle() const {
return m_image; return m_image.image;
} }
/** /**
@ -177,7 +186,7 @@ namespace dxvk {
* \returns Pointer to mapped memory region * \returns Pointer to mapped memory region
*/ */
void* mapPtr(VkDeviceSize offset) const { void* mapPtr(VkDeviceSize offset) const {
return m_memory.mapPtr(offset); return m_image.memory.mapPtr(offset);
} }
/** /**
@ -210,7 +219,7 @@ namespace dxvk {
const VkImageSubresource& subresource) const { const VkImageSubresource& subresource) const {
VkSubresourceLayout result; VkSubresourceLayout result;
m_vkd->vkGetImageSubresourceLayout( m_vkd->vkGetImageSubresourceLayout(
m_vkd->device(), m_image, m_vkd->device(), m_image.image,
&subresource, &result); &subresource, &result);
return result; return result;
} }
@ -272,7 +281,7 @@ namespace dxvk {
* \returns The memory size of the image * \returns The memory size of the image
*/ */
VkDeviceSize memSize() const { VkDeviceSize memSize() const {
return m_memory.length(); return m_image.memory.length();
} }
private: private:
@ -280,8 +289,7 @@ namespace dxvk {
Rc<vk::DeviceFn> m_vkd; Rc<vk::DeviceFn> m_vkd;
DxvkImageCreateInfo m_info; DxvkImageCreateInfo m_info;
VkMemoryPropertyFlags m_memFlags; VkMemoryPropertyFlags m_memFlags;
DxvkMemory m_memory; DxvkPhysicalImage m_image;
VkImage m_image = VK_NULL_HANDLE;
small_vector<VkFormat, 4> m_viewFormats; small_vector<VkFormat, 4> m_viewFormats;