mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-03-14 22:29:15 +01:00
[dxvk] Reimplement imported buffers
This commit is contained in:
parent
5263307c4a
commit
1ba6b81901
@ -25,13 +25,20 @@ namespace dxvk {
|
|||||||
DxvkDevice* device,
|
DxvkDevice* device,
|
||||||
const DxvkBufferCreateInfo& createInfo,
|
const DxvkBufferCreateInfo& createInfo,
|
||||||
const DxvkBufferImportInfo& importInfo,
|
const DxvkBufferImportInfo& importInfo,
|
||||||
|
DxvkMemoryAllocator& allocator,
|
||||||
VkMemoryPropertyFlags memFlags)
|
VkMemoryPropertyFlags memFlags)
|
||||||
: m_vkd (device->vkd()),
|
: m_vkd (device->vkd()),
|
||||||
|
m_allocator (&allocator),
|
||||||
m_properties (memFlags),
|
m_properties (memFlags),
|
||||||
m_shaderStages (util::shaderStages(createInfo.stages)),
|
m_shaderStages (util::shaderStages(createInfo.stages)),
|
||||||
m_info (createInfo),
|
m_info (createInfo) {
|
||||||
m_import (importInfo) {
|
VkBufferCreateInfo info = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
|
||||||
|
info.flags = m_info.flags;
|
||||||
|
info.usage = m_info.usage;
|
||||||
|
info.size = m_info.size;
|
||||||
|
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||||
|
|
||||||
|
assignSlice(allocator.importBufferResource(info, importInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,22 +59,6 @@ namespace dxvk {
|
|||||||
VkBufferUsageFlags usage = 0u;
|
VkBufferUsageFlags usage = 0u;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Buffer import info
|
|
||||||
*
|
|
||||||
* Used to import an existing Vulkan buffer. Note
|
|
||||||
* that imported buffers must not be renamed.
|
|
||||||
*/
|
|
||||||
struct DxvkBufferImportInfo {
|
|
||||||
/// Buffer handle
|
|
||||||
VkBuffer buffer = VK_NULL_HANDLE;
|
|
||||||
/// Buffer offset
|
|
||||||
VkDeviceSize offset = 0;
|
|
||||||
/// Pointer to mapped memory region
|
|
||||||
void* mapPtr = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Buffer slice info
|
* \brief Buffer slice info
|
||||||
@ -213,6 +197,7 @@ namespace dxvk {
|
|||||||
DxvkDevice* device,
|
DxvkDevice* device,
|
||||||
const DxvkBufferCreateInfo& createInfo,
|
const DxvkBufferCreateInfo& createInfo,
|
||||||
const DxvkBufferImportInfo& importInfo,
|
const DxvkBufferImportInfo& importInfo,
|
||||||
|
DxvkMemoryAllocator& memAlloc,
|
||||||
VkMemoryPropertyFlags memFlags);
|
VkMemoryPropertyFlags memFlags);
|
||||||
|
|
||||||
~DxvkBuffer();
|
~DxvkBuffer();
|
||||||
@ -387,7 +372,7 @@ namespace dxvk {
|
|||||||
* \returns \c true if the buffer is imported
|
* \returns \c true if the buffer is imported
|
||||||
*/
|
*/
|
||||||
bool isForeign() const {
|
bool isForeign() const {
|
||||||
return m_import.buffer != VK_NULL_HANDLE;
|
return m_storage->flags().test(DxvkAllocationFlag::Imported);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -407,7 +392,6 @@ namespace dxvk {
|
|||||||
VkShaderStageFlags m_shaderStages = 0u;
|
VkShaderStageFlags m_shaderStages = 0u;
|
||||||
|
|
||||||
DxvkBufferCreateInfo m_info = { };
|
DxvkBufferCreateInfo m_info = { };
|
||||||
DxvkBufferImportInfo m_import = { };
|
|
||||||
|
|
||||||
uint32_t m_xfbStride = 0u;
|
uint32_t m_xfbStride = 0u;
|
||||||
uint32_t m_version = 0u;
|
uint32_t m_version = 0u;
|
||||||
|
@ -218,7 +218,8 @@ namespace dxvk {
|
|||||||
const DxvkBufferCreateInfo& createInfo,
|
const DxvkBufferCreateInfo& createInfo,
|
||||||
const DxvkBufferImportInfo& importInfo,
|
const DxvkBufferImportInfo& importInfo,
|
||||||
VkMemoryPropertyFlags memoryType) {
|
VkMemoryPropertyFlags memoryType) {
|
||||||
return new DxvkBuffer(this, createInfo, importInfo, memoryType);
|
return new DxvkBuffer(this, createInfo,
|
||||||
|
importInfo, m_objects.memoryManager(), memoryType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -907,6 +907,23 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Rc<DxvkResourceAllocation> DxvkMemoryAllocator::importBufferResource(
|
||||||
|
const VkBufferCreateInfo& createInfo,
|
||||||
|
const DxvkBufferImportInfo& importInfo) {
|
||||||
|
Rc<DxvkResourceAllocation> allocation = m_allocationPool.create(this, nullptr);
|
||||||
|
allocation->m_flags.set(DxvkAllocationFlag::Imported);
|
||||||
|
allocation->m_size = createInfo.size;
|
||||||
|
allocation->m_mapPtr = importInfo.mapPtr;
|
||||||
|
allocation->m_buffer = importInfo.buffer;
|
||||||
|
allocation->m_bufferOffset = importInfo.offset;
|
||||||
|
|
||||||
|
if (createInfo.usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT)
|
||||||
|
allocation->m_bufferAddress = getBufferDeviceAddress(importInfo.buffer) + importInfo.offset;
|
||||||
|
|
||||||
|
return allocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DxvkDeviceMemory DxvkMemoryAllocator::allocateDeviceMemory(
|
DxvkDeviceMemory DxvkMemoryAllocator::allocateDeviceMemory(
|
||||||
DxvkMemoryType& type,
|
DxvkMemoryType& type,
|
||||||
VkDeviceSize size,
|
VkDeviceSize size,
|
||||||
|
@ -424,6 +424,7 @@ namespace dxvk {
|
|||||||
OwnsBuffer = 1,
|
OwnsBuffer = 1,
|
||||||
OwnsImage = 2,
|
OwnsImage = 2,
|
||||||
Cacheable = 3,
|
Cacheable = 3,
|
||||||
|
Imported = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
using DxvkAllocationFlags = Flags<DxvkAllocationFlag>;
|
using DxvkAllocationFlags = Flags<DxvkAllocationFlag>;
|
||||||
@ -504,6 +505,14 @@ namespace dxvk {
|
|||||||
return cur >= getIncrement(access);
|
return cur >= getIncrement(access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Queries allocation flags
|
||||||
|
* \returns Allocation flags
|
||||||
|
*/
|
||||||
|
DxvkAllocationFlags flags() const {
|
||||||
|
return m_flags;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Queries mapped memory region
|
* \brief Queries mapped memory region
|
||||||
* \returns Mapped memory region
|
* \returns Mapped memory region
|
||||||
@ -988,6 +997,22 @@ namespace dxvk {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Buffer import info
|
||||||
|
*
|
||||||
|
* Used to import an existing Vulkan buffer. Note
|
||||||
|
* that imported buffers must not be renamed.
|
||||||
|
*/
|
||||||
|
struct DxvkBufferImportInfo {
|
||||||
|
/// Buffer handle
|
||||||
|
VkBuffer buffer = VK_NULL_HANDLE;
|
||||||
|
/// Buffer offset
|
||||||
|
VkDeviceSize offset = 0;
|
||||||
|
/// Pointer to mapped memory region
|
||||||
|
void* mapPtr = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Memory allocator
|
* \brief Memory allocator
|
||||||
*
|
*
|
||||||
@ -1106,6 +1131,17 @@ namespace dxvk {
|
|||||||
VkBufferUsageFlags bufferUsage,
|
VkBufferUsageFlags bufferUsage,
|
||||||
VkMemoryPropertyFlags properties);
|
VkMemoryPropertyFlags properties);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Imports existing buffer resource
|
||||||
|
*
|
||||||
|
* \param [in] createInfo Buffer create info
|
||||||
|
* \param [in] importInfo Buffer import info
|
||||||
|
* \returns Buffer resource
|
||||||
|
*/
|
||||||
|
Rc<DxvkResourceAllocation> importBufferResource(
|
||||||
|
const VkBufferCreateInfo& createInfo,
|
||||||
|
const DxvkBufferImportInfo& importInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Queries memory stats
|
* \brief Queries memory stats
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user