mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-02 10:24:12 +01:00
[dxvk] Add helper to get memory type mask for buffer usage
This commit is contained in:
parent
e80dd6db5f
commit
00f7545d15
@ -311,7 +311,7 @@ namespace dxvk {
|
|||||||
// Ensure the allocation size is also aligned
|
// Ensure the allocation size is also aligned
|
||||||
VkDeviceSize size = align(requirements.size, requirements.alignment);
|
VkDeviceSize size = align(requirements.size, requirements.alignment);
|
||||||
|
|
||||||
for (auto typeIndex : getMemoryTypeMask(requirements, properties)) {
|
for (auto typeIndex : bit::BitMask(requirements.memoryTypeBits & getMemoryTypeMask(properties))) {
|
||||||
auto& type = m_memTypes[typeIndex];
|
auto& type = m_memTypes[typeIndex];
|
||||||
|
|
||||||
// Use correct memory pool depending on property flags. This way we avoid
|
// Use correct memory pool depending on property flags. This way we avoid
|
||||||
@ -402,7 +402,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
DxvkDeviceMemory memory = { };
|
DxvkDeviceMemory memory = { };
|
||||||
|
|
||||||
for (auto typeIndex : getMemoryTypeMask(requirements, properties)) {
|
for (auto typeIndex : bit::BitMask(requirements.memoryTypeBits & getMemoryTypeMask(properties))) {
|
||||||
auto& type = m_memTypes[typeIndex];
|
auto& type = m_memTypes[typeIndex];
|
||||||
memory = allocateDeviceMemory(type, requirements.size, next);
|
memory = allocateDeviceMemory(type, requirements.size, next);
|
||||||
|
|
||||||
@ -412,9 +412,6 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logMemoryError(requirements);
|
|
||||||
logMemoryStats();
|
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1138,13 +1135,24 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bit::BitMask DxvkMemoryAllocator::getMemoryTypeMask(
|
uint32_t DxvkMemoryAllocator::getMemoryTypeMask(
|
||||||
const VkMemoryRequirements& requirements,
|
|
||||||
VkMemoryPropertyFlags properties) const {
|
VkMemoryPropertyFlags properties) const {
|
||||||
uint32_t mask = requirements.memoryTypeBits;
|
return m_memTypesByPropertyFlags[uint32_t(properties) % uint32_t(m_memTypesByPropertyFlags.size())];
|
||||||
mask &= m_memTypesByPropertyFlags[uint32_t(properties) % uint32_t(m_memTypesByPropertyFlags.size())];
|
}
|
||||||
|
|
||||||
return bit::BitMask(mask);
|
|
||||||
|
uint32_t DxvkMemoryAllocator::findGlobalBufferMemoryTypeMask(
|
||||||
|
VkBufferUsageFlags usage) const {
|
||||||
|
// Iterate over all candidate memory types as a fallback in case
|
||||||
|
// the device has memory types with limited buffer support.
|
||||||
|
uint32_t mask = m_globalBufferMemoryTypes;
|
||||||
|
|
||||||
|
for (auto typeIndex : bit::BitMask(mask)) {
|
||||||
|
if (usage & ~m_memTypes[typeIndex].bufferUsage)
|
||||||
|
mask ^= 1u << typeIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -961,10 +961,12 @@ namespace dxvk {
|
|||||||
|
|
||||||
void logMemoryStats() const;
|
void logMemoryStats() const;
|
||||||
|
|
||||||
bit::BitMask getMemoryTypeMask(
|
uint32_t getMemoryTypeMask(
|
||||||
const VkMemoryRequirements& requirements,
|
|
||||||
VkMemoryPropertyFlags properties) const;
|
VkMemoryPropertyFlags properties) const;
|
||||||
|
|
||||||
|
uint32_t findGlobalBufferMemoryTypeMask(
|
||||||
|
VkBufferUsageFlags usage) const;
|
||||||
|
|
||||||
void runWorker();
|
void runWorker();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user