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

[dxvk] Add method to allocate backing storage with constraints

This commit is contained in:
Philip Rebohle 2024-10-18 01:30:55 +02:00 committed by Philip Rebohle
parent a3c8c88222
commit bfcfcab60f
6 changed files with 72 additions and 4 deletions

View File

@ -77,5 +77,27 @@ namespace dxvk {
DxvkSparsePageTable* DxvkBuffer::getSparsePageTable() {
return m_storage->getSparsePageTable();
}
Rc<DxvkResourceAllocation> DxvkBuffer::relocateStorage(
DxvkAllocationModes mode) {
// The resource may become non-relocatable even after we allocate new
// backing storage, but if it already is then don't waste memory.
if (!canRelocate())
return nullptr;
DxvkAllocationInfo allocationInfo = { };
allocationInfo.resourceCookie = cookie();
allocationInfo.properties = m_properties;
allocationInfo.mode = mode;
VkBufferCreateInfo info = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
info.flags = m_info.flags;
info.usage = m_info.usage;
info.size = m_info.size;
m_sharingMode.fill(info);
return m_allocator->createBufferResource(info, allocationInfo, nullptr);
}
}

View File

@ -397,6 +397,15 @@ namespace dxvk {
*/
DxvkSparsePageTable* getSparsePageTable();
/**
* \brief Allocates new backing storage with constraints
*
* \param [in] mode Allocation mode flags
* \returns Operation status and allocation
*/
Rc<DxvkResourceAllocation> relocateStorage(
DxvkAllocationModes mode);
private:
Rc<vk::DeviceFn> m_vkd;

View File

@ -1586,7 +1586,7 @@ namespace dxvk {
DxvkImageUsageInfo usage = usageInfo;
usage.flags |= createFlags;
auto storage = image->allocateStorageWithUsage(usage);
auto storage = image->allocateStorageWithUsage(usage, 0u);
DxvkRelocateImageInfo relocateInfo;
relocateInfo.image = image;

View File

@ -108,6 +108,15 @@ namespace dxvk {
}
Rc<DxvkResourceAllocation> DxvkImage::relocateStorage(
DxvkAllocationModes mode) {
if (!canRelocate())
return nullptr;
return allocateStorageWithUsage(DxvkImageUsageInfo(), mode);
}
Rc<DxvkImageView> DxvkImage::createView(
const DxvkImageViewKey& info) {
std::unique_lock lock(m_viewMutex);
@ -120,11 +129,13 @@ namespace dxvk {
Rc<DxvkResourceAllocation> DxvkImage::allocateStorage() {
return allocateStorageWithUsage(DxvkImageUsageInfo());
return allocateStorageWithUsage(DxvkImageUsageInfo(), 0u);
}
Rc<DxvkResourceAllocation> DxvkImage::allocateStorageWithUsage(const DxvkImageUsageInfo& usageInfo) {
Rc<DxvkResourceAllocation> DxvkImage::allocateStorageWithUsage(
const DxvkImageUsageInfo& usageInfo,
DxvkAllocationModes mode) {
const DxvkFormatInfo* formatInfo = lookupFormatInfo(m_info.format);
small_vector<VkFormat, 4> localViewFormats;

View File

@ -515,6 +515,15 @@ namespace dxvk {
*/
DxvkSparsePageTable* getSparsePageTable();
/**
* \brief Allocates new backing storage with constraints
*
* \param [in] mode Allocation mode flags
* \returns Operation status and allocation
*/
Rc<DxvkResourceAllocation> relocateStorage(
DxvkAllocationModes mode);
/**
* \brief Creates image resource
*
@ -529,10 +538,12 @@ namespace dxvk {
* Creates new backing storage with additional usage flags
* enabled. Useful to expand on usage flags after creation.
* \param [in] usage Usage flags to add
* \param [in] mode Allocation constraints
* \returns New underlying image resource
*/
Rc<DxvkResourceAllocation> allocateStorageWithUsage(
const DxvkImageUsageInfo& usage);
const DxvkImageUsageInfo& usage,
DxvkAllocationModes mode);
/**
* \brief Assigns backing storage to the image

View File

@ -522,6 +522,21 @@ namespace dxvk {
*/
virtual DxvkSparsePageTable* getSparsePageTable() = 0;
/**
* \brief Allocates new backing storage with constraints
*
* \param [in] mode Allocation mode flags to control behaviour.
* When relocating the resource to a preferred memory type,
* \c NoFallback should be set, when defragmenting device
* memory then \c NoAllocation should also be set.
* \returns \c true in the first field if the operation is
* considered successful, i.e. if an new backing allocation
* was successfully created or is unnecessary. The second
* field will contain the new allocation itself.
*/
virtual Rc<DxvkResourceAllocation> relocateStorage(
DxvkAllocationModes mode) = 0;
private:
std::atomic<uint64_t> m_useCount = { 0u };