mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-28 04:54:30 +00:00
Iterators
This commit is contained in:
parent
a6c8dc2252
commit
ab1c3c8b89
@ -14,6 +14,9 @@ namespace Common {
|
|||||||
struct SlotId {
|
struct SlotId {
|
||||||
static constexpr u32 INVALID_INDEX = std::numeric_limits<u32>::max();
|
static constexpr u32 INVALID_INDEX = std::numeric_limits<u32>::max();
|
||||||
|
|
||||||
|
SlotId() noexcept = default;
|
||||||
|
constexpr SlotId(u32 index) noexcept : index(index) {}
|
||||||
|
|
||||||
constexpr auto operator<=>(const SlotId&) const noexcept = default;
|
constexpr auto operator<=>(const SlotId&) const noexcept = default;
|
||||||
|
|
||||||
constexpr explicit operator bool() const noexcept {
|
constexpr explicit operator bool() const noexcept {
|
||||||
@ -28,6 +31,63 @@ class SlotVector {
|
|||||||
constexpr static std::size_t InitialCapacity = 2048;
|
constexpr static std::size_t InitialCapacity = 2048;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
template <typename ValueType, typename Pointer, typename Reference>
|
||||||
|
class Iterator {
|
||||||
|
public:
|
||||||
|
using iterator_category = std::forward_iterator_tag;
|
||||||
|
using value_type = ValueType;
|
||||||
|
using difference_type = std::ptrdiff_t;
|
||||||
|
using pointer = Pointer;
|
||||||
|
using reference = Reference;
|
||||||
|
|
||||||
|
Iterator(SlotVector& vector_, SlotId index_) : vector(vector_), slot(index_) {
|
||||||
|
AdvanceToValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
reference operator*() const {
|
||||||
|
return vector[slot];
|
||||||
|
}
|
||||||
|
|
||||||
|
pointer operator->() const {
|
||||||
|
return &vector[slot];
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator& operator++() {
|
||||||
|
++slot.index;
|
||||||
|
AdvanceToValid();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator operator++(int) {
|
||||||
|
Iterator temp = *this;
|
||||||
|
++(*this);
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const Iterator& other) const {
|
||||||
|
return slot == other.slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const Iterator& other) const {
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void AdvanceToValid() {
|
||||||
|
while (slot < vector.values_capacity && !vector.ReadStorageBit(slot.index)) {
|
||||||
|
++slot.index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SlotVector& vector;
|
||||||
|
SlotId slot;
|
||||||
|
};
|
||||||
|
|
||||||
|
using iterator = Iterator<T, T*, T&>;
|
||||||
|
using const_iterator = Iterator<const T, const T*, const T&>;
|
||||||
|
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||||
|
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||||
|
|
||||||
SlotVector() {
|
SlotVector() {
|
||||||
Reserve(InitialCapacity);
|
Reserve(InitialCapacity);
|
||||||
}
|
}
|
||||||
@ -78,6 +138,54 @@ public:
|
|||||||
return values_capacity - free_list.size();
|
return values_capacity - free_list.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iterator begin() noexcept {
|
||||||
|
return iterator(*this, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const_iterator begin() const noexcept {
|
||||||
|
return const_iterator(*this, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const_iterator cbegin() const noexcept {
|
||||||
|
return begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
iterator end() noexcept {
|
||||||
|
return iterator(*this, values_capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
const_iterator end() const noexcept {
|
||||||
|
return const_iterator(*this, values_capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
const_iterator cend() const noexcept {
|
||||||
|
return end();
|
||||||
|
}
|
||||||
|
|
||||||
|
reverse_iterator rbegin() noexcept {
|
||||||
|
return reverse_iterator(end());
|
||||||
|
}
|
||||||
|
|
||||||
|
const_reverse_iterator rbegin() const noexcept {
|
||||||
|
return const_reverse_iterator(end());
|
||||||
|
}
|
||||||
|
|
||||||
|
const_reverse_iterator crbegin() const noexcept {
|
||||||
|
return rbegin();
|
||||||
|
}
|
||||||
|
|
||||||
|
reverse_iterator rend() noexcept {
|
||||||
|
return reverse_iterator(begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
const_reverse_iterator rend() const noexcept {
|
||||||
|
return const_reverse_iterator(begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
const_reverse_iterator crend() const noexcept {
|
||||||
|
return rend();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct NonTrivialDummy {
|
struct NonTrivialDummy {
|
||||||
NonTrivialDummy() noexcept {}
|
NonTrivialDummy() noexcept {}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "common/config.h"
|
#include "common/config.h"
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/recursive_lock.h"
|
|
||||||
#include "core/memory.h"
|
#include "core/memory.h"
|
||||||
#include "shader_recompiler/runtime_info.h"
|
#include "shader_recompiler/runtime_info.h"
|
||||||
#include "video_core/amdgpu/liverpool.h"
|
#include "video_core/amdgpu/liverpool.h"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
|
#include "common/recursive_lock.h"
|
||||||
#include "video_core/buffer_cache/buffer_cache.h"
|
#include "video_core/buffer_cache/buffer_cache.h"
|
||||||
#include "video_core/page_manager.h"
|
#include "video_core/page_manager.h"
|
||||||
#include "video_core/renderer_vulkan/vk_pipeline_cache.h"
|
#include "video_core/renderer_vulkan/vk_pipeline_cache.h"
|
||||||
@ -71,6 +71,14 @@ public:
|
|||||||
return pipeline_cache;
|
return pipeline_cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Func>
|
||||||
|
void ForEachMappedRangeInRange(VAddr addr, u64 size, Func&& func) {
|
||||||
|
const auto range = decltype(mapped_ranges)::interval_type::right_open(addr, addr + size);
|
||||||
|
Common::RecursiveSharedLock lock{mapped_ranges_mutex};
|
||||||
|
for (const auto& mapped_range : mapped_ranges & range) {
|
||||||
|
func(mapped_range);
|
||||||
|
}
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
RenderState PrepareRenderState(u32 mrt_mask);
|
RenderState PrepareRenderState(u32 mrt_mask);
|
||||||
void BeginRendering(const GraphicsPipeline& pipeline, RenderState& state);
|
void BeginRendering(const GraphicsPipeline& pipeline, RenderState& state);
|
||||||
|
Loading…
Reference in New Issue
Block a user