1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-20 19:54:19 +01:00

[dxvk] Introduce DxvkResourceMemoryInfo

And replace the old sparse thing.
This commit is contained in:
Philip Rebohle 2024-09-25 21:16:11 +02:00 committed by Philip Rebohle
parent bbd2461c8f
commit af4a2f7973
5 changed files with 53 additions and 38 deletions

View File

@ -1005,21 +1005,21 @@ namespace dxvk {
void bindBufferMemory(
const DxvkSparseBufferBindKey& key,
const DxvkSparsePageHandle& memory) {
const DxvkResourceMemoryInfo& memory) {
getSparseBindSubmission().bindBufferMemory(key, memory);
}
void bindImageMemory(
const DxvkSparseImageBindKey& key,
const DxvkSparsePageHandle& memory) {
const DxvkResourceMemoryInfo& memory) {
getSparseBindSubmission().bindImageMemory(key, memory);
}
void bindImageOpaqueMemory(
const DxvkSparseImageOpaqueBindKey& key,
const DxvkSparsePageHandle& memory) {
const DxvkResourceMemoryInfo& memory) {
getSparseBindSubmission().bindImageOpaqueMemory(key, memory);
}

View File

@ -1559,10 +1559,10 @@ namespace dxvk {
key.size = r.imageMipTailSize;
key.flags = VK_SPARSE_MEMORY_BIND_METADATA_BIT;
DxvkSparsePageHandle page;
DxvkResourceMemoryInfo page;
page.memory = imageMemory;
page.offset = imageOffset;
page.length = r.imageMipTailSize;
page.size = r.imageMipTailSize;
m_cmd->bindImageOpaqueMemory(key, page);

View File

@ -388,6 +388,19 @@ namespace dxvk {
};
/**
* \brief Memory properties
*/
struct DxvkResourceMemoryInfo {
/// Vulkan memory handle
VkDeviceMemory memory = VK_NULL_HANDLE;
/// Offset into memory object
VkDeviceSize offset = 0u;
/// Size of memory range
VkDeviceSize size = 0u;
};
/**
* \brief Buffer properties
*/
@ -521,6 +534,18 @@ namespace dxvk {
return m_mapPtr;
}
/**
* \brief Queries memory info
* \returns Memory info
*/
DxvkResourceMemoryInfo getMemoryInfo() const {
DxvkResourceMemoryInfo result = { };
result.memory = m_memory;
result.offset = m_address & DxvkPageAllocator::ChunkAddressMask;
result.size = m_size;
return result;
}
/**
* \brief Queries buffer info
* \returns Buffer info

View File

@ -446,21 +446,21 @@ namespace dxvk {
void DxvkSparseBindSubmission::bindBufferMemory(
const DxvkSparseBufferBindKey& key,
const DxvkSparsePageHandle& memory) {
const DxvkResourceMemoryInfo& memory) {
m_bufferBinds.insert_or_assign(key, memory);
}
void DxvkSparseBindSubmission::bindImageMemory(
const DxvkSparseImageBindKey& key,
const DxvkSparsePageHandle& memory) {
const DxvkResourceMemoryInfo& memory) {
m_imageBinds.insert_or_assign(key, memory);
}
void DxvkSparseBindSubmission::bindImageOpaqueMemory(
const DxvkSparseImageOpaqueBindKey& key,
const DxvkSparsePageHandle& memory) {
const DxvkResourceMemoryInfo& memory) {
m_imageOpaqueBinds.insert_or_assign(key, memory);
}
@ -560,8 +560,8 @@ namespace dxvk {
bool DxvkSparseBindSubmission::tryMergeImageBind(
std::pair<DxvkSparseImageBindKey, DxvkSparsePageHandle>& oldBind,
const std::pair<DxvkSparseImageBindKey, DxvkSparsePageHandle>& newBind) {
std::pair<DxvkSparseImageBindKey, DxvkResourceMemoryInfo>& oldBind,
const std::pair<DxvkSparseImageBindKey, DxvkResourceMemoryInfo>& newBind) {
if (oldBind.first.image != newBind.first.image
|| oldBind.first.subresource.aspectMask != newBind.first.subresource.aspectMask
|| oldBind.first.subresource.mipLevel != newBind.first.subresource.mipLevel
@ -572,7 +572,7 @@ namespace dxvk {
return false;
if (oldBind.second.memory) {
if (oldBind.second.offset + oldBind.second.length != newBind.second.offset)
if (oldBind.second.offset + oldBind.second.size != newBind.second.offset)
return false;
}
@ -604,7 +604,7 @@ namespace dxvk {
oldBind.first.extent.depth += delta.depth;
if (oldBind.second.memory)
oldBind.second.length += newBind.second.length;
oldBind.second.size += newBind.second.size;
}
return canMerge;
@ -641,14 +641,14 @@ namespace dxvk {
void DxvkSparseBindSubmission::processImageBinds(
DxvkSparseImageBindArrays& image) {
std::vector<std::pair<DxvkSparseImageBindKey, DxvkSparsePageHandle>> binds;
std::vector<std::pair<DxvkSparseImageBindKey, DxvkResourceMemoryInfo>> binds;
binds.reserve(m_imageBinds.size());
for (const auto& e : m_imageBinds) {
std::pair<DxvkSparseImageBindKey, DxvkSparsePageHandle> newBind = e;
std::pair<DxvkSparseImageBindKey, DxvkResourceMemoryInfo> newBind = e;
while (!binds.empty()) {
std::pair<DxvkSparseImageBindKey, DxvkSparsePageHandle> oldBind = binds.back();
std::pair<DxvkSparseImageBindKey, DxvkResourceMemoryInfo> oldBind = binds.back();
if (!tryMergeImageBind(oldBind, newBind))
break;

View File

@ -18,16 +18,6 @@ namespace dxvk {
constexpr static VkDeviceSize SparseMemoryPageSize = 1ull << 16;
/**
* \brief Sparse page handle
*/
struct DxvkSparsePageHandle {
VkDeviceMemory memory;
VkDeviceSize offset;
VkDeviceSize length;
};
/**
* \brief Buffer info for sparse page
*
@ -182,11 +172,11 @@ namespace dxvk {
* \brief Queries memory handle
* \returns Memory information
*/
DxvkSparsePageHandle getHandle() const {
DxvkSparsePageHandle result;
DxvkResourceMemoryInfo getHandle() const {
DxvkResourceMemoryInfo result;
result.memory = m_memory.memory();
result.offset = m_memory.offset();
result.length = m_memory.length();
result.size = m_memory.length();
return result;
}
@ -223,9 +213,9 @@ namespace dxvk {
* \brief Queries memory handle
* \returns Memory information
*/
DxvkSparsePageHandle getHandle() const {
DxvkResourceMemoryInfo getHandle() const {
if (m_page == nullptr)
return DxvkSparsePageHandle();
return DxvkResourceMemoryInfo();
return m_page->getHandle();
}
@ -670,7 +660,7 @@ namespace dxvk {
*/
void bindBufferMemory(
const DxvkSparseBufferBindKey& key,
const DxvkSparsePageHandle& memory);
const DxvkResourceMemoryInfo& memory);
/**
* \brief Adds an image memory bind
@ -680,7 +670,7 @@ namespace dxvk {
*/
void bindImageMemory(
const DxvkSparseImageBindKey& key,
const DxvkSparsePageHandle& memory);
const DxvkResourceMemoryInfo& memory);
/**
* \brief Adds an opaque image memory bind
@ -690,7 +680,7 @@ namespace dxvk {
*/
void bindImageOpaqueMemory(
const DxvkSparseImageOpaqueBindKey& key,
const DxvkSparsePageHandle& memory);
const DxvkResourceMemoryInfo& memory);
/**
* \brief Submits sparse binding operation
@ -720,17 +710,17 @@ namespace dxvk {
std::vector<uint64_t> m_signalSemaphoreValues;
std::vector<VkSemaphore> m_signalSemaphores;
std::map<DxvkSparseBufferBindKey, DxvkSparsePageHandle> m_bufferBinds;
std::map<DxvkSparseImageBindKey, DxvkSparsePageHandle> m_imageBinds;
std::map<DxvkSparseImageOpaqueBindKey, DxvkSparsePageHandle> m_imageOpaqueBinds;
std::map<DxvkSparseBufferBindKey, DxvkResourceMemoryInfo> m_bufferBinds;
std::map<DxvkSparseImageBindKey, DxvkResourceMemoryInfo> m_imageBinds;
std::map<DxvkSparseImageOpaqueBindKey, DxvkResourceMemoryInfo> m_imageOpaqueBinds;
static bool tryMergeMemoryBind(
VkSparseMemoryBind& oldBind,
const VkSparseMemoryBind& newBind);
static bool tryMergeImageBind(
std::pair<DxvkSparseImageBindKey, DxvkSparsePageHandle>& oldBind,
const std::pair<DxvkSparseImageBindKey, DxvkSparsePageHandle>& newBind);
std::pair<DxvkSparseImageBindKey, DxvkResourceMemoryInfo>& oldBind,
const std::pair<DxvkSparseImageBindKey, DxvkResourceMemoryInfo>& newBind);
void processBufferBinds(
DxvkSparseBufferBindArrays& buffer);