1
0
mirror of https://github.com/EduApps-CDG/OpenDX synced 2024-12-30 09:45:37 +01:00
OpenDX/src/dxvk/dxvk_memory.h
2017-10-10 23:32:13 +02:00

105 lines
2.1 KiB
C++

#pragma once
#include "dxvk_adapter.h"
namespace dxvk {
class DxvkMemoryAllocator;
/**
* \brief Memory slice
*/
class DxvkMemory {
public:
DxvkMemory();
DxvkMemory(
DxvkMemoryAllocator* alloc,
VkDeviceMemory memory,
void* mapPtr);
DxvkMemory (DxvkMemory&& other);
DxvkMemory& operator = (DxvkMemory&& other);
~DxvkMemory();
/**
* \brief Memory object
*
* This information is required when
* binding memory to Vulkan objects.
* \returns Memory object
*/
VkDeviceMemory memory() const {
return m_memory;
}
/**
* \brief Offset from memory object
*
* This information is required when
* binding memory to Vulkan objects.
* \returns Offset from memory object
*/
VkDeviceSize offset() const {
return 0;
}
/**
* \brief Pointer to mapped data
* \returns Pointer to mapped data
*/
void* mapPtr() const {
return m_mapPtr;
}
private:
DxvkMemoryAllocator* m_alloc = nullptr;
VkDeviceMemory m_memory = VK_NULL_HANDLE;
void* m_mapPtr = nullptr;
};
/**
* \brief Memory allocator
*
* Allocates device memory for Vulkan resources.
* Memory objects will be destroyed automatically.
*/
class DxvkMemoryAllocator {
friend class DxvkMemory;
public:
DxvkMemoryAllocator(
const Rc<DxvkAdapter>& adapter,
const Rc<vk::DeviceFn>& vkd);
~DxvkMemoryAllocator();
/**
* \brief Allocates device memory
*
* \param [in] req Memory requirements
* \param [in] flats Memory type flags
* \returns Allocated memory slice
*/
DxvkMemory alloc(
const VkMemoryRequirements& req,
const VkMemoryPropertyFlags flags);
private:
const Rc<vk::DeviceFn> m_vkd;
const VkPhysicalDeviceMemoryProperties m_memProps;
VkDeviceMemory allocMemory(
VkDeviceSize blockSize,
uint32_t memoryType);
void freeMemory(
VkDeviceMemory memory);
};
}