mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-03-13 19:29:14 +01:00
[dxvk] Reimplement imported buffers
This commit is contained in:
parent
5263307c4a
commit
1ba6b81901
@ -25,13 +25,20 @@ namespace dxvk {
|
||||
DxvkDevice* device,
|
||||
const DxvkBufferCreateInfo& createInfo,
|
||||
const DxvkBufferImportInfo& importInfo,
|
||||
DxvkMemoryAllocator& allocator,
|
||||
VkMemoryPropertyFlags memFlags)
|
||||
: m_vkd (device->vkd()),
|
||||
m_allocator (&allocator),
|
||||
m_properties (memFlags),
|
||||
m_shaderStages (util::shaderStages(createInfo.stages)),
|
||||
m_info (createInfo),
|
||||
m_import (importInfo) {
|
||||
m_info (createInfo) {
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \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
|
||||
@ -213,6 +197,7 @@ namespace dxvk {
|
||||
DxvkDevice* device,
|
||||
const DxvkBufferCreateInfo& createInfo,
|
||||
const DxvkBufferImportInfo& importInfo,
|
||||
DxvkMemoryAllocator& memAlloc,
|
||||
VkMemoryPropertyFlags memFlags);
|
||||
|
||||
~DxvkBuffer();
|
||||
@ -387,7 +372,7 @@ namespace dxvk {
|
||||
* \returns \c true if the buffer is imported
|
||||
*/
|
||||
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;
|
||||
|
||||
DxvkBufferCreateInfo m_info = { };
|
||||
DxvkBufferImportInfo m_import = { };
|
||||
|
||||
uint32_t m_xfbStride = 0u;
|
||||
uint32_t m_version = 0u;
|
||||
|
@ -218,7 +218,8 @@ namespace dxvk {
|
||||
const DxvkBufferCreateInfo& createInfo,
|
||||
const DxvkBufferImportInfo& importInfo,
|
||||
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(
|
||||
DxvkMemoryType& type,
|
||||
VkDeviceSize size,
|
||||
|
@ -424,6 +424,7 @@ namespace dxvk {
|
||||
OwnsBuffer = 1,
|
||||
OwnsImage = 2,
|
||||
Cacheable = 3,
|
||||
Imported = 4,
|
||||
};
|
||||
|
||||
using DxvkAllocationFlags = Flags<DxvkAllocationFlag>;
|
||||
@ -504,6 +505,14 @@ namespace dxvk {
|
||||
return cur >= getIncrement(access);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Queries allocation flags
|
||||
* \returns Allocation flags
|
||||
*/
|
||||
DxvkAllocationFlags flags() const {
|
||||
return m_flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Queries 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
|
||||
*
|
||||
@ -1106,6 +1131,17 @@ namespace dxvk {
|
||||
VkBufferUsageFlags bufferUsage,
|
||||
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
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user