Misc: clean up some for loops

This commit is contained in:
oltolm
2025-10-31 01:31:08 +01:00
committed by lightningterror
parent e8ba3653ee
commit 18fecfbd07
3 changed files with 21 additions and 25 deletions
+5 -7
View File
@@ -3,6 +3,7 @@
#pragma once
#include "HeterogeneousContainers.h"
#include <algorithm>
#include <cstdint>
#include <map>
@@ -75,12 +76,9 @@ public:
{
while (!m_items.empty() && count > 0)
{
typename MapType::iterator lowest = m_items.end();
for (auto iter = m_items.begin(); iter != m_items.end(); ++iter)
{
if (lowest == m_items.end() || iter->second.last_access < lowest->second.last_access)
lowest = iter;
}
auto lowest = std::min_element(m_items.begin(), m_items.end(), [](const auto& a, const auto& b) {
return a.second.last_access < b.second.last_access;
});
m_items.erase(lowest);
count--;
}
@@ -121,4 +119,4 @@ private:
CounterType m_last_counter = 0;
std::size_t m_max_capacity = 0;
bool m_manual_evict = false;
};
};
@@ -197,20 +197,18 @@ bool D3D12StreamBuffer::WaitForClearSpace(u32 num_bytes)
u32 new_space = 0;
u32 new_gpu_position = 0;
auto iter = m_tracked_fences.begin();
for (; iter != m_tracked_fences.end(); ++iter)
{
auto iter = std::find_if(m_tracked_fences.begin(), m_tracked_fences.end(), [&, this](const auto& iter) {
// Would this fence bring us in line with the GPU?
// This is the "last resort" case, where a command buffer execution has been forced
// after no additional data has been written to it, so we can assume that after the
// fence has been signaled the entire buffer is now consumed.
u32 gpu_position = iter->second;
u32 gpu_position = iter.second;
if (m_current_offset == gpu_position)
{
new_offset = 0;
new_space = m_size;
new_gpu_position = 0;
break;
return true;
}
// Assuming that we wait for this fence, are we allocating in front of the GPU?
@@ -225,7 +223,7 @@ bool D3D12StreamBuffer::WaitForClearSpace(u32 num_bytes)
new_offset = m_current_offset;
new_space = m_size - m_current_offset;
new_gpu_position = gpu_position;
break;
return true;
}
// We can wrap around to the start, behind the GPU, if there is enough space.
@@ -236,7 +234,7 @@ bool D3D12StreamBuffer::WaitForClearSpace(u32 num_bytes)
new_offset = 0;
new_space = gpu_position;
new_gpu_position = gpu_position;
break;
return true;
}
}
else
@@ -251,10 +249,11 @@ bool D3D12StreamBuffer::WaitForClearSpace(u32 num_bytes)
new_offset = m_current_offset;
new_space = gpu_position - m_current_offset;
new_gpu_position = gpu_position;
break;
return true;
}
}
}
return false;
});
// Did any fences satisfy this condition?
// Has the command buffer been executed yet? If not, the caller should execute it.
+8 -9
View File
@@ -234,20 +234,18 @@ bool VKStreamBuffer::WaitForClearSpace(u32 num_bytes)
u32 new_space = 0;
u32 new_gpu_position = 0;
auto iter = m_tracked_fences.begin();
for (; iter != m_tracked_fences.end(); ++iter)
{
auto iter = std::find_if(m_tracked_fences.begin(), m_tracked_fences.end(), [&, this](const auto& iter) {
// Would this fence bring us in line with the GPU?
// This is the "last resort" case, where a command buffer execution has been forced
// after no additional data has been written to it, so we can assume that after the
// fence has been signaled the entire buffer is now consumed.
u32 gpu_position = iter->second;
u32 gpu_position = iter.second;
if (m_current_offset == gpu_position)
{
new_offset = 0;
new_space = m_size;
new_gpu_position = 0;
break;
return true;
}
// Assuming that we wait for this fence, are we allocating in front of the GPU?
@@ -262,7 +260,7 @@ bool VKStreamBuffer::WaitForClearSpace(u32 num_bytes)
new_offset = m_current_offset;
new_space = m_size - m_current_offset;
new_gpu_position = gpu_position;
break;
return true;
}
// We can wrap around to the start, behind the GPU, if there is enough space.
@@ -273,7 +271,7 @@ bool VKStreamBuffer::WaitForClearSpace(u32 num_bytes)
new_offset = 0;
new_space = gpu_position - 1;
new_gpu_position = gpu_position;
break;
return true;
}
}
else
@@ -288,10 +286,11 @@ bool VKStreamBuffer::WaitForClearSpace(u32 num_bytes)
new_offset = m_current_offset;
new_space = available_space_inbetween - 1;
new_gpu_position = gpu_position;
break;
return true;
}
}
}
return false;
});
// Did any fences satisfy this condition?
// Has the command buffer been executed yet? If not, the caller should execute it.