mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-08-16 05:21:22 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 16b55f5802 | |||
| 44f6229b26 | |||
| bb66fbea51 | |||
| 97cc97b933 | |||
| 5d6897edac | |||
| 8217304b60 | |||
| 689f4d3214 | |||
| bdbdfe8e1d | |||
| d25d460116 | |||
| 06c8f9806b | |||
| aa012961b8 | |||
| d628737b48 | |||
| d5cc29a2f7 |
@@ -1,142 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <deque>
|
|
||||||
#include <memory>
|
|
||||||
#include <type_traits>
|
|
||||||
|
|
||||||
#include "common/common_types.h"
|
|
||||||
|
|
||||||
namespace Common {
|
|
||||||
|
|
||||||
template <class Traits>
|
|
||||||
class LeastRecentlyUsedCache {
|
|
||||||
using ObjectType = typename Traits::ObjectType;
|
|
||||||
using TickType = typename Traits::TickType;
|
|
||||||
|
|
||||||
struct Item {
|
|
||||||
ObjectType obj;
|
|
||||||
TickType tick;
|
|
||||||
Item* next{};
|
|
||||||
Item* prev{};
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
LeastRecentlyUsedCache() : first_item{}, last_item{} {}
|
|
||||||
~LeastRecentlyUsedCache() = default;
|
|
||||||
|
|
||||||
size_t Insert(ObjectType obj, TickType tick) {
|
|
||||||
const auto new_id = Build();
|
|
||||||
auto& item = item_pool[new_id];
|
|
||||||
item.obj = obj;
|
|
||||||
item.tick = tick;
|
|
||||||
Attach(item);
|
|
||||||
return new_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Touch(size_t id, TickType tick) {
|
|
||||||
auto& item = item_pool[id];
|
|
||||||
if (item.tick >= tick) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
item.tick = tick;
|
|
||||||
if (&item == last_item) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Detach(item);
|
|
||||||
Attach(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Free(size_t id) {
|
|
||||||
auto& item = item_pool[id];
|
|
||||||
Detach(item);
|
|
||||||
item.prev = nullptr;
|
|
||||||
item.next = nullptr;
|
|
||||||
free_items.push_back(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Func>
|
|
||||||
void ForEachItemBelow(TickType tick, Func&& func) {
|
|
||||||
static constexpr bool RETURNS_BOOL =
|
|
||||||
std::is_same_v<std::invoke_result_t<Func, ObjectType>, bool>;
|
|
||||||
Item* iterator = first_item;
|
|
||||||
while (iterator) {
|
|
||||||
if (static_cast<s64>(tick) - static_cast<s64>(iterator->tick) < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Item* next = iterator->next;
|
|
||||||
if constexpr (RETURNS_BOOL) {
|
|
||||||
if (func(iterator->obj)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
func(iterator->obj);
|
|
||||||
}
|
|
||||||
iterator = next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
size_t Build() {
|
|
||||||
if (free_items.empty()) {
|
|
||||||
const size_t item_id = item_pool.size();
|
|
||||||
auto& item = item_pool.emplace_back();
|
|
||||||
item.next = nullptr;
|
|
||||||
item.prev = nullptr;
|
|
||||||
return item_id;
|
|
||||||
}
|
|
||||||
const size_t item_id = free_items.front();
|
|
||||||
free_items.pop_front();
|
|
||||||
auto& item = item_pool[item_id];
|
|
||||||
item.next = nullptr;
|
|
||||||
item.prev = nullptr;
|
|
||||||
return item_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Attach(Item& item) {
|
|
||||||
if (!first_item) {
|
|
||||||
first_item = &item;
|
|
||||||
}
|
|
||||||
if (!last_item) {
|
|
||||||
last_item = &item;
|
|
||||||
} else {
|
|
||||||
item.prev = last_item;
|
|
||||||
last_item->next = &item;
|
|
||||||
item.next = nullptr;
|
|
||||||
last_item = &item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Detach(Item& item) {
|
|
||||||
if (item.prev) {
|
|
||||||
item.prev->next = item.next;
|
|
||||||
}
|
|
||||||
if (item.next) {
|
|
||||||
item.next->prev = item.prev;
|
|
||||||
}
|
|
||||||
if (&item == first_item) {
|
|
||||||
first_item = item.next;
|
|
||||||
if (first_item) {
|
|
||||||
first_item->prev = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (&item == last_item) {
|
|
||||||
last_item = item.prev;
|
|
||||||
if (last_item) {
|
|
||||||
last_item->next = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::deque<Item> item_pool;
|
|
||||||
std::deque<size_t> free_items;
|
|
||||||
Item* first_item{};
|
|
||||||
Item* last_item{};
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Common
|
|
||||||
@@ -109,12 +109,12 @@ public:
|
|||||||
return static_cast<u32>(other_cpu_addr - cpu_addr);
|
return static_cast<u32>(other_cpu_addr - cpu_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getLRUID() const noexcept {
|
u64 GetFrameTick() const noexcept {
|
||||||
return lru_id;
|
return frame_tick;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLRUID(size_t lru_id_) {
|
void SetFrameTick(u64 tick) noexcept {
|
||||||
lru_id = lru_id_;
|
frame_tick = tick;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t SizeBytes() const {
|
size_t SizeBytes() const {
|
||||||
@@ -125,7 +125,7 @@ private:
|
|||||||
VAddr cpu_addr = 0;
|
VAddr cpu_addr = 0;
|
||||||
BufferFlagBits flags{};
|
BufferFlagBits flags{};
|
||||||
int stream_score = 0;
|
int stream_score = 0;
|
||||||
size_t lru_id = SIZE_MAX;
|
u64 frame_tick = 0;
|
||||||
size_t size_bytes = 0;
|
size_t size_bytes = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -58,17 +58,22 @@ void BufferCache<P>::RunGarbageCollector() {
|
|||||||
const bool aggressive_gc = total_used_memory >= critical_memory;
|
const bool aggressive_gc = total_used_memory >= critical_memory;
|
||||||
const u64 ticks_to_destroy = aggressive_gc ? 60 : 120;
|
const u64 ticks_to_destroy = aggressive_gc ? 60 : 120;
|
||||||
int num_iterations = aggressive_gc ? 64 : 32;
|
int num_iterations = aggressive_gc ? 64 : 32;
|
||||||
const auto clean_up = [this, &num_iterations](BufferId buffer_id) {
|
const u64 threshold = frame_tick - ticks_to_destroy;
|
||||||
|
boost::container::small_vector<BufferId, 64> expired;
|
||||||
|
for (auto [id, buffer] : slot_buffers) {
|
||||||
|
if (buffer->GetFrameTick() < threshold) {
|
||||||
|
expired.push_back(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const auto buffer_id : expired) {
|
||||||
if (num_iterations == 0) {
|
if (num_iterations == 0) {
|
||||||
return true;
|
break;
|
||||||
}
|
}
|
||||||
--num_iterations;
|
--num_iterations;
|
||||||
auto& buffer = slot_buffers[buffer_id];
|
auto& buffer = slot_buffers[buffer_id];
|
||||||
DownloadBufferMemory(buffer);
|
DownloadBufferMemory(buffer);
|
||||||
DeleteBuffer(buffer_id);
|
DeleteBuffer(buffer_id);
|
||||||
return false;
|
}
|
||||||
};
|
|
||||||
lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, clean_up);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
@@ -1591,10 +1596,9 @@ void BufferCache<P>::ChangeRegister(BufferId buffer_id) {
|
|||||||
const auto size = buffer.SizeBytes();
|
const auto size = buffer.SizeBytes();
|
||||||
if (insert) {
|
if (insert) {
|
||||||
total_used_memory += Common::AlignUp(size, 1024);
|
total_used_memory += Common::AlignUp(size, 1024);
|
||||||
buffer.setLRUID(lru_cache.Insert(buffer_id, frame_tick));
|
buffer.SetFrameTick(frame_tick);
|
||||||
} else {
|
} else {
|
||||||
total_used_memory -= Common::AlignUp(size, 1024);
|
total_used_memory -= Common::AlignUp(size, 1024);
|
||||||
lru_cache.Free(buffer.getLRUID());
|
|
||||||
}
|
}
|
||||||
const DAddr device_addr_begin = buffer.CpuAddr();
|
const DAddr device_addr_begin = buffer.CpuAddr();
|
||||||
const DAddr device_addr_end = device_addr_begin + size;
|
const DAddr device_addr_end = device_addr_begin + size;
|
||||||
@@ -1612,7 +1616,7 @@ void BufferCache<P>::ChangeRegister(BufferId buffer_id) {
|
|||||||
template <class P>
|
template <class P>
|
||||||
void BufferCache<P>::TouchBuffer(Buffer& buffer, BufferId buffer_id) noexcept {
|
void BufferCache<P>::TouchBuffer(Buffer& buffer, BufferId buffer_id) noexcept {
|
||||||
if (buffer_id != NULL_BUFFER_ID) {
|
if (buffer_id != NULL_BUFFER_ID) {
|
||||||
lru_cache.Touch(buffer.getLRUID(), frame_tick);
|
buffer.SetFrameTick(frame_tick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/div_ceil.h"
|
#include "common/div_ceil.h"
|
||||||
#include "common/literals.h"
|
#include "common/literals.h"
|
||||||
#include "common/lru_cache.h"
|
|
||||||
#include "common/range_sets.h"
|
#include "common/range_sets.h"
|
||||||
#include "common/scope_exit.h"
|
#include "common/scope_exit.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
@@ -506,11 +505,6 @@ private:
|
|||||||
size_t immediate_buffer_capacity = 0;
|
size_t immediate_buffer_capacity = 0;
|
||||||
Common::ScratchBuffer<u8> immediate_buffer_alloc;
|
Common::ScratchBuffer<u8> immediate_buffer_alloc;
|
||||||
|
|
||||||
struct LRUItemParams {
|
|
||||||
using ObjectType = BufferId;
|
|
||||||
using TickType = u64;
|
|
||||||
};
|
|
||||||
Common::LeastRecentlyUsedCache<LRUItemParams> lru_cache;
|
|
||||||
u64 frame_tick = 0;
|
u64 frame_tick = 0;
|
||||||
u64 total_used_memory = 0;
|
u64 total_used_memory = 0;
|
||||||
u64 minimum_memory = 0;
|
u64 minimum_memory = 0;
|
||||||
|
|||||||
@@ -117,7 +117,35 @@ void DmaPusher::ProcessCommands(std::span<const CommandHeader> commands) {
|
|||||||
dma_state.is_last_call = true;
|
dma_state.is_last_call = true;
|
||||||
index += max_write;
|
index += max_write;
|
||||||
} else if (dma_state.method_count) {
|
} else if (dma_state.method_count) {
|
||||||
auto const command_header = commands[index]; //can copy
|
if (!dma_state.non_incrementing && !dma_increment_once &&
|
||||||
|
dma_state.method >= non_puller_methods) {
|
||||||
|
auto subchannel = subchannels[dma_state.subchannel];
|
||||||
|
const u32 available = u32(std::min<size_t>(
|
||||||
|
index + dma_state.method_count, commands.size()) - index);
|
||||||
|
u32 batch = 0;
|
||||||
|
u32 method = dma_state.method;
|
||||||
|
while (batch < available) {
|
||||||
|
const bool needs_exec =
|
||||||
|
(method < Engines::EngineInterface::EXECUTION_MASK_TABLE_SIZE)
|
||||||
|
? subchannel->execution_mask[method]
|
||||||
|
: subchannel->execution_mask_default;
|
||||||
|
if (needs_exec) break;
|
||||||
|
batch++;
|
||||||
|
method++;
|
||||||
|
}
|
||||||
|
if (batch > 0) {
|
||||||
|
auto& sink = subchannel->method_sink;
|
||||||
|
sink.reserve(sink.size() + batch);
|
||||||
|
for (u32 j = 0; j < batch; j++) {
|
||||||
|
sink.emplace_back(dma_state.method + j, commands[index + j].argument);
|
||||||
|
}
|
||||||
|
dma_state.method += batch;
|
||||||
|
dma_state.method_count -= batch;
|
||||||
|
index += batch;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto const command_header = commands[index];
|
||||||
dma_state.dma_word_offset = u32(index * sizeof(u32));
|
dma_state.dma_word_offset = u32(index * sizeof(u32));
|
||||||
dma_state.is_last_call = dma_state.method_count <= 1;
|
dma_state.is_last_call = dma_state.method_count <= 1;
|
||||||
CallMethod(command_header.argument);
|
CallMethod(command_header.argument);
|
||||||
@@ -176,7 +204,11 @@ void DmaPusher::CallMethod(u32 argument) {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
auto subchannel = subchannels[dma_state.subchannel];
|
auto subchannel = subchannels[dma_state.subchannel];
|
||||||
if (!subchannel->execution_mask[dma_state.method]) {
|
const bool needs_execution =
|
||||||
|
(dma_state.method < Engines::EngineInterface::EXECUTION_MASK_TABLE_SIZE)
|
||||||
|
? subchannel->execution_mask[dma_state.method]
|
||||||
|
: subchannel->execution_mask_default;
|
||||||
|
if (!needs_execution) {
|
||||||
subchannel->method_sink.emplace_back(dma_state.method, argument);
|
subchannel->method_sink.emplace_back(dma_state.method, argument);
|
||||||
} else {
|
} else {
|
||||||
subchannel->ConsumeSink(system);
|
subchannel->ConsumeSink(system);
|
||||||
|
|||||||
@@ -6,9 +6,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <bitset>
|
#include <array>
|
||||||
#include <limits>
|
#include <boost/container/small_vector.hpp>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|
||||||
@@ -43,10 +42,15 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::bitset<(std::numeric_limits<u16>::max)()> execution_mask{};
|
static constexpr size_t EXECUTION_MASK_TABLE_SIZE = 0xE00;
|
||||||
std::vector<std::pair<u32, u32>> method_sink{};
|
|
||||||
|
std::array<u8, EXECUTION_MASK_TABLE_SIZE> execution_mask{};
|
||||||
|
bool execution_mask_default{};
|
||||||
|
boost::container::small_vector<std::pair<u32, u32>, 64> method_sink{};
|
||||||
GPUVAddr current_dma_segment;
|
GPUVAddr current_dma_segment;
|
||||||
|
/// @brief Indicates whether the current DMA segment is dirty.
|
||||||
bool current_dirty{};
|
bool current_dirty{};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void ConsumeSinkImpl(Core::System& system) {
|
virtual void ConsumeSinkImpl(Core::System& system) {
|
||||||
for (auto [method, value] : method_sink) {
|
for (auto [method, value] : method_sink) {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ Fermi2D::Fermi2D(MemoryManager& memory_manager_) : memory_manager{memory_manager
|
|||||||
regs.src.depth = 1;
|
regs.src.depth = 1;
|
||||||
regs.dst.depth = 1;
|
regs.dst.depth = 1;
|
||||||
|
|
||||||
execution_mask.reset();
|
execution_mask.fill(0);
|
||||||
execution_mask[FERMI2D_REG_INDEX(pixels_from_memory.src_y0) + 1] = true;
|
execution_mask[FERMI2D_REG_INDEX(pixels_from_memory.src_y0) + 1] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ KeplerCompute::KeplerCompute(MemoryManager& memory_manager_)
|
|||||||
: memory_manager{memory_manager_}
|
: memory_manager{memory_manager_}
|
||||||
, upload_state{memory_manager, regs.upload}
|
, upload_state{memory_manager, regs.upload}
|
||||||
{
|
{
|
||||||
execution_mask.reset();
|
execution_mask.fill(0);
|
||||||
execution_mask[KEPLER_COMPUTE_REG_INDEX(exec_upload)] = true;
|
execution_mask[KEPLER_COMPUTE_REG_INDEX(exec_upload)] = true;
|
||||||
execution_mask[KEPLER_COMPUTE_REG_INDEX(data_upload)] = true;
|
execution_mask[KEPLER_COMPUTE_REG_INDEX(data_upload)] = true;
|
||||||
execution_mask[KEPLER_COMPUTE_REG_INDEX(launch)] = true;
|
execution_mask[KEPLER_COMPUTE_REG_INDEX(launch)] = true;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ KeplerMemory::~KeplerMemory() = default;
|
|||||||
void KeplerMemory::BindRasterizer(VideoCore::RasterizerInterface* rasterizer_) {
|
void KeplerMemory::BindRasterizer(VideoCore::RasterizerInterface* rasterizer_) {
|
||||||
upload_state.BindRasterizer(rasterizer_);
|
upload_state.BindRasterizer(rasterizer_);
|
||||||
|
|
||||||
execution_mask.reset();
|
execution_mask.fill(0);
|
||||||
execution_mask[KEPLERMEMORY_REG_INDEX(exec)] = true;
|
execution_mask[KEPLERMEMORY_REG_INDEX(exec)] = true;
|
||||||
execution_mask[KEPLERMEMORY_REG_INDEX(data)] = true;
|
execution_mask[KEPLERMEMORY_REG_INDEX(data)] = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,14 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && !defined(__clang__)
|
||||||
|
#include <intrin.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/bit_util.h"
|
#include "common/bit_util.h"
|
||||||
#include "common/scope_exit.h"
|
#include "common/scope_exit.h"
|
||||||
@@ -22,6 +28,16 @@
|
|||||||
|
|
||||||
namespace Tegra::Engines {
|
namespace Tegra::Engines {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
inline void PrefetchLine(const void* addr) {
|
||||||
|
#if defined(_MSC_VER) && !defined(__clang__)
|
||||||
|
_mm_prefetch(static_cast<const char*>(addr), _MM_HINT_T0);
|
||||||
|
#else
|
||||||
|
__builtin_prefetch(addr, 0, 1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
/// First register id that is actually a Macro call.
|
/// First register id that is actually a Macro call.
|
||||||
constexpr u32 MacroRegistersStart = 0xE00;
|
constexpr u32 MacroRegistersStart = 0xE00;
|
||||||
|
|
||||||
@@ -37,9 +53,10 @@ Maxwell3D::Maxwell3D(MemoryManager& memory_manager_)
|
|||||||
{
|
{
|
||||||
dirty.flags.flip();
|
dirty.flags.flip();
|
||||||
InitializeRegisterDefaults();
|
InitializeRegisterDefaults();
|
||||||
execution_mask.reset();
|
execution_mask.fill(0);
|
||||||
for (size_t i = 0; i < execution_mask.size(); i++)
|
for (size_t i = 0; i < EXECUTION_MASK_TABLE_SIZE; i++)
|
||||||
execution_mask[i] = IsMethodExecutable(u32(i));
|
execution_mask[i] = IsMethodExecutable(u32(i));
|
||||||
|
execution_mask_default = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Maxwell3D::~Maxwell3D() = default;
|
Maxwell3D::~Maxwell3D() = default;
|
||||||
@@ -282,18 +299,44 @@ u32 Maxwell3D::ProcessShadowRam(u32 method, u32 argument) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Maxwell3D::ConsumeSinkImpl(Core::System& system) {
|
void Maxwell3D::ConsumeSinkImpl(Core::System& system) {
|
||||||
|
std::stable_sort(method_sink.begin(), method_sink.end(),
|
||||||
|
[](const auto& a, const auto& b) { return a.first < b.first; });
|
||||||
|
|
||||||
|
const auto sink_size = method_sink.size();
|
||||||
const auto control = shadow_state.shadow_ram_control;
|
const auto control = shadow_state.shadow_ram_control;
|
||||||
if (control == Regs::ShadowRamControl::Track || control == Regs::ShadowRamControl::TrackWithFilter) {
|
if (control == Regs::ShadowRamControl::Track || control == Regs::ShadowRamControl::TrackWithFilter) {
|
||||||
for (auto [method, value] : method_sink) {
|
for (size_t i = 0; i < sink_size; ++i) {
|
||||||
|
const auto [method, value] = method_sink[i];
|
||||||
|
if (i + 1 < sink_size) {
|
||||||
|
const u32 next = method_sink[i + 1].first;
|
||||||
|
PrefetchLine(®s.reg_array[next]);
|
||||||
|
PrefetchLine(&shadow_state.reg_array[next]);
|
||||||
|
PrefetchLine(&dirty.tables[0][next]);
|
||||||
|
}
|
||||||
shadow_state.reg_array[method] = value;
|
shadow_state.reg_array[method] = value;
|
||||||
ProcessDirtyRegisters(method, value);
|
ProcessDirtyRegisters(method, value);
|
||||||
}
|
}
|
||||||
} else if (control == Regs::ShadowRamControl::Replay) {
|
} else if (control == Regs::ShadowRamControl::Replay) {
|
||||||
for (auto [method, value] : method_sink)
|
for (size_t i = 0; i < sink_size; ++i) {
|
||||||
|
const auto [method, value] = method_sink[i];
|
||||||
|
if (i + 1 < sink_size) {
|
||||||
|
const u32 next = method_sink[i + 1].first;
|
||||||
|
PrefetchLine(®s.reg_array[next]);
|
||||||
|
PrefetchLine(&shadow_state.reg_array[next]);
|
||||||
|
PrefetchLine(&dirty.tables[0][next]);
|
||||||
|
}
|
||||||
ProcessDirtyRegisters(method, shadow_state.reg_array[method]);
|
ProcessDirtyRegisters(method, shadow_state.reg_array[method]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for (auto [method, value] : method_sink)
|
for (size_t i = 0; i < sink_size; ++i) {
|
||||||
|
const auto [method, value] = method_sink[i];
|
||||||
|
if (i + 1 < sink_size) {
|
||||||
|
const u32 next = method_sink[i + 1].first;
|
||||||
|
PrefetchLine(®s.reg_array[next]);
|
||||||
|
PrefetchLine(&dirty.tables[0][next]);
|
||||||
|
}
|
||||||
ProcessDirtyRegisters(method, value);
|
ProcessDirtyRegisters(method, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
method_sink.clear();
|
method_sink.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ using namespace Texture;
|
|||||||
MaxwellDMA::MaxwellDMA(MemoryManager& memory_manager_)
|
MaxwellDMA::MaxwellDMA(MemoryManager& memory_manager_)
|
||||||
: memory_manager{memory_manager_}
|
: memory_manager{memory_manager_}
|
||||||
{
|
{
|
||||||
execution_mask.reset();
|
execution_mask.fill(0);
|
||||||
execution_mask[offsetof(Regs, launch_dma) / sizeof(u32)] = true;
|
execution_mask[offsetof(Regs, launch_dma) / sizeof(u32)] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -287,6 +287,7 @@ void QueryCacheBase<Traits>::CounterReport(GPUVAddr addr, QueryType counter_type
|
|||||||
u32 value = static_cast<u32>(query_base->value);
|
u32 value = static_cast<u32>(query_base->value);
|
||||||
std::memcpy(pointer, &value, sizeof(value));
|
std::memcpy(pointer, &value, sizeof(value));
|
||||||
}
|
}
|
||||||
|
query_base->flags |= QueryFlagBits::IsGuestSynced;
|
||||||
if (!is_synced) [[likely]] {
|
if (!is_synced) [[likely]] {
|
||||||
impl->pending_unregister.push_back(query_location);
|
impl->pending_unregister.push_back(query_location);
|
||||||
}
|
}
|
||||||
@@ -569,10 +570,12 @@ bool QueryCacheBase<Traits>::SemiFlushQueryDirty(QueryCacheBase<Traits>::QueryLo
|
|||||||
auto* ptr = impl->device_memory.template GetPointer<u8>(query_base->guest_address);
|
auto* ptr = impl->device_memory.template GetPointer<u8>(query_base->guest_address);
|
||||||
if (True(query_base->flags & QueryFlagBits::HasTimestamp)) {
|
if (True(query_base->flags & QueryFlagBits::HasTimestamp)) {
|
||||||
std::memcpy(ptr, &query_base->value, sizeof(query_base->value));
|
std::memcpy(ptr, &query_base->value, sizeof(query_base->value));
|
||||||
|
query_base->flags |= QueryFlagBits::IsGuestSynced;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
u32 value_l = static_cast<u32>(query_base->value);
|
u32 value_l = static_cast<u32>(query_base->value);
|
||||||
std::memcpy(ptr, &value_l, sizeof(value_l));
|
std::memcpy(ptr, &value_l, sizeof(value_l));
|
||||||
|
query_base->flags |= QueryFlagBits::IsGuestSynced;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return True(query_base->flags & QueryFlagBits::IsHostManaged) &&
|
return True(query_base->flags & QueryFlagBits::IsHostManaged) &&
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ void FixedPipelineState::Refresh(Tegra::Engines::Maxwell3D& maxwell3d, DynamicFe
|
|||||||
extended_dynamic_state_2_logic_op.Assign(features.has_extended_dynamic_state_2_logic_op ? 1 : 0);
|
extended_dynamic_state_2_logic_op.Assign(features.has_extended_dynamic_state_2_logic_op ? 1 : 0);
|
||||||
extended_dynamic_state_3_blend.Assign(features.has_extended_dynamic_state_3_blend ? 1 : 0);
|
extended_dynamic_state_3_blend.Assign(features.has_extended_dynamic_state_3_blend ? 1 : 0);
|
||||||
extended_dynamic_state_3_enables.Assign(features.has_extended_dynamic_state_3_enables ? 1 : 0);
|
extended_dynamic_state_3_enables.Assign(features.has_extended_dynamic_state_3_enables ? 1 : 0);
|
||||||
|
dynamic_state3_depth_clamp_enable.Assign(features.has_dynamic_state3_depth_clamp_enable ? 1 : 0);
|
||||||
dynamic_vertex_input.Assign(features.has_dynamic_vertex_input ? 1 : 0);
|
dynamic_vertex_input.Assign(features.has_dynamic_vertex_input ? 1 : 0);
|
||||||
xfb_enabled.Assign(regs.transform_feedback_enabled != 0);
|
xfb_enabled.Assign(regs.transform_feedback_enabled != 0);
|
||||||
ndc_minus_one_to_one.Assign(regs.depth_mode == Maxwell::DepthMode::MinusOneToOne ? 1 : 0);
|
ndc_minus_one_to_one.Assign(regs.depth_mode == Maxwell::DepthMode::MinusOneToOne ? 1 : 0);
|
||||||
|
|||||||
@@ -208,6 +208,7 @@ struct FixedPipelineState {
|
|||||||
BitField<12, 2, u32> tessellation_spacing;
|
BitField<12, 2, u32> tessellation_spacing;
|
||||||
BitField<14, 1, u32> tessellation_clockwise;
|
BitField<14, 1, u32> tessellation_clockwise;
|
||||||
BitField<15, 5, u32> patch_control_points_minus_one;
|
BitField<15, 5, u32> patch_control_points_minus_one;
|
||||||
|
BitField<20, 1, u32> dynamic_state3_depth_clamp_enable;
|
||||||
|
|
||||||
BitField<24, 4, Maxwell::PrimitiveTopology> topology;
|
BitField<24, 4, Maxwell::PrimitiveTopology> topology;
|
||||||
BitField<28, 4, Tegra::Texture::MsaaMode> msaa_mode;
|
BitField<28, 4, Tegra::Texture::MsaaMode> msaa_mode;
|
||||||
|
|||||||
@@ -907,7 +907,7 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
|
|||||||
|
|
||||||
// EDS3 - Enables (composite: per-feature)
|
// EDS3 - Enables (composite: per-feature)
|
||||||
if (key.state.extended_dynamic_state_3_enables) {
|
if (key.state.extended_dynamic_state_3_enables) {
|
||||||
if (device.SupportsDynamicState3DepthClampEnable()) {
|
if (key.state.dynamic_state3_depth_clamp_enable != 0) {
|
||||||
dynamic_states.push_back(VK_DYNAMIC_STATE_DEPTH_CLAMP_ENABLE_EXT);
|
dynamic_states.push_back(VK_DYNAMIC_STATE_DEPTH_CLAMP_ENABLE_EXT);
|
||||||
}
|
}
|
||||||
if (device.SupportsDynamicState3LogicOpEnable()) {
|
if (device.SupportsDynamicState3LogicOpEnable()) {
|
||||||
|
|||||||
@@ -492,7 +492,9 @@ PipelineCache::PipelineCache(Tegra::MaxwellDeviceMemoryManager& device_memory_,
|
|||||||
device.IsExtExtendedDynamicState3BlendingSupported();
|
device.IsExtExtendedDynamicState3BlendingSupported();
|
||||||
dynamic_features.has_extended_dynamic_state_3_enables =
|
dynamic_features.has_extended_dynamic_state_3_enables =
|
||||||
device.IsExtExtendedDynamicState3EnablesSupported();
|
device.IsExtExtendedDynamicState3EnablesSupported();
|
||||||
dynamic_features.has_dynamic_state3_depth_clamp_enable = false;
|
dynamic_features.has_dynamic_state3_depth_clamp_enable =
|
||||||
|
dynamic_features.has_extended_dynamic_state_3_enables &&
|
||||||
|
device.SupportsDynamicState3DepthClampEnable();
|
||||||
dynamic_features.has_dynamic_state3_logic_op_enable =
|
dynamic_features.has_dynamic_state3_logic_op_enable =
|
||||||
device.SupportsDynamicState3LogicOpEnable();
|
device.SupportsDynamicState3LogicOpEnable();
|
||||||
dynamic_features.has_dynamic_state3_line_stipple_enable =
|
dynamic_features.has_dynamic_state3_line_stipple_enable =
|
||||||
|
|||||||
@@ -113,6 +113,10 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] ComputePipeline* CurrentComputePipeline();
|
[[nodiscard]] ComputePipeline* CurrentComputePipeline();
|
||||||
|
|
||||||
|
[[nodiscard]] bool SupportsDynamicState3DepthClampEnable() const {
|
||||||
|
return dynamic_features.has_dynamic_state3_depth_clamp_enable;
|
||||||
|
}
|
||||||
|
|
||||||
void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
||||||
const VideoCore::DiskResourceLoadCallback& callback);
|
const VideoCore::DiskResourceLoadCallback& callback);
|
||||||
|
|
||||||
|
|||||||
@@ -1578,7 +1578,7 @@ void RasterizerVulkan::UpdateDepthClampEnable(Tegra::Engines::Maxwell3D::Regs& r
|
|||||||
if (!state_tracker.TouchDepthClampEnable()) {
|
if (!state_tracker.TouchDepthClampEnable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!device.SupportsDynamicState3DepthClampEnable()) {
|
if (!pipeline_cache.SupportsDynamicState3DepthClampEnable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool is_enabled = !(regs.viewport_clip_control.geometry_clip ==
|
bool is_enabled = !(regs.viewport_clip_control.geometry_clip ==
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -92,10 +93,12 @@ public:
|
|||||||
requires std::is_invocable_v<T, vk::CommandBuffer, vk::CommandBuffer>
|
requires std::is_invocable_v<T, vk::CommandBuffer, vk::CommandBuffer>
|
||||||
void RecordWithUploadBuffer(T&& command) {
|
void RecordWithUploadBuffer(T&& command) {
|
||||||
if (chunk->Record(command)) {
|
if (chunk->Record(command)) {
|
||||||
|
record_serial.fetch_add(1, std::memory_order_relaxed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DispatchWork();
|
DispatchWork();
|
||||||
(void)chunk->Record(command);
|
(void)chunk->Record(command);
|
||||||
|
record_serial.fetch_add(1, std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@@ -117,6 +120,11 @@ public:
|
|||||||
return master_semaphore->IsFree(tick);
|
return master_semaphore->IsFree(tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a monotonic serial incremented for every recorded command callback.
|
||||||
|
[[nodiscard]] u64 CurrentRecordSerial() const noexcept {
|
||||||
|
return record_serial.load(std::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
/// Waits for the given GPU tick, optionally pacing frames.
|
/// Waits for the given GPU tick, optionally pacing frames.
|
||||||
void Wait(u64 tick, double target_fps = 0.0) {
|
void Wait(u64 tick, double target_fps = 0.0) {
|
||||||
if (tick > 0) {
|
if (tick > 0) {
|
||||||
@@ -298,6 +306,7 @@ private:
|
|||||||
u64 frame_counter{};
|
u64 frame_counter{};
|
||||||
|
|
||||||
u64 last_submitted_tick = 0;
|
u64 last_submitted_tick = 0;
|
||||||
|
std::atomic<u64> record_serial{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Vulkan
|
} // namespace Vulkan
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -102,7 +105,7 @@ struct ImageBase {
|
|||||||
VAddr cpu_addr_end = 0;
|
VAddr cpu_addr_end = 0;
|
||||||
|
|
||||||
u64 modification_tick = 0;
|
u64 modification_tick = 0;
|
||||||
size_t lru_index = SIZE_MAX;
|
u64 last_use_tick = 0;
|
||||||
|
|
||||||
std::array<u32, MAX_MIP_LEVELS> mip_level_offsets{};
|
std::array<u32, MAX_MIP_LEVELS> mip_level_offsets{};
|
||||||
|
|
||||||
|
|||||||
@@ -159,11 +159,54 @@ void TextureCache<P>::RunGarbageCollector() {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const auto CollectBelow = [this](u64 threshold) {
|
||||||
|
boost::container::small_vector<ImageId, 64> expired;
|
||||||
|
for (auto [id, image] : slot_images) {
|
||||||
|
if (image->last_use_tick < threshold) {
|
||||||
|
expired.push_back(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return expired;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Aggressively clear massive sparse textures
|
||||||
|
if (total_used_memory >= expected_memory) {
|
||||||
|
auto candidates = CollectBelow(frame_tick);
|
||||||
|
for (const auto image_id : candidates) {
|
||||||
|
auto& image = slot_images[image_id];
|
||||||
|
if (image.info.is_sparse &&
|
||||||
|
image.guest_size_bytes >= 256_MiB &&
|
||||||
|
image.allocation_tick < frame_tick - 3) {
|
||||||
|
LOG_DEBUG(HW_GPU, "GC targeting old sparse texture at 0x{:X} ({} MiB, age: {} frames)",
|
||||||
|
image.gpu_addr, image.guest_size_bytes / (1024 * 1024),
|
||||||
|
frame_tick - image.allocation_tick);
|
||||||
|
if (Cleanup(image_id)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Configure(false);
|
Configure(false);
|
||||||
lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, Cleanup);
|
{
|
||||||
|
auto expired = CollectBelow(frame_tick - ticks_to_destroy);
|
||||||
|
for (const auto image_id : expired) {
|
||||||
|
if (Cleanup(image_id)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If pressure is still too high, prune aggressively.
|
||||||
if (total_used_memory >= critical_memory) {
|
if (total_used_memory >= critical_memory) {
|
||||||
Configure(true);
|
Configure(true);
|
||||||
lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, Cleanup);
|
auto expired = CollectBelow(frame_tick - ticks_to_destroy);
|
||||||
|
for (const auto image_id : expired) {
|
||||||
|
if (Cleanup(image_id)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1865,7 +1908,7 @@ std::pair<u32, u32> TextureCache<P>::PrepareDmaImage(ImageId dst_id, GPUVAddr ba
|
|||||||
const auto base = image.TryFindBase(base_addr);
|
const auto base = image.TryFindBase(base_addr);
|
||||||
PrepareImage(dst_id, mark_as_modified, false);
|
PrepareImage(dst_id, mark_as_modified, false);
|
||||||
const auto& new_image = slot_images[dst_id];
|
const auto& new_image = slot_images[dst_id];
|
||||||
lru_cache.Touch(new_image.lru_index, frame_tick);
|
new_image.last_use_tick = frame_tick;
|
||||||
return std::make_pair(base->level, base->layer);
|
return std::make_pair(base->level, base->layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2192,7 +2235,7 @@ void TextureCache<P>::RegisterImage(ImageId image_id) {
|
|||||||
tentative_size = TranscodedAstcSize(tentative_size, image.info.format);
|
tentative_size = TranscodedAstcSize(tentative_size, image.info.format);
|
||||||
}
|
}
|
||||||
total_used_memory += Common::AlignUp(tentative_size, 1024);
|
total_used_memory += Common::AlignUp(tentative_size, 1024);
|
||||||
image.lru_index = lru_cache.Insert(image_id, frame_tick);
|
image.last_use_tick = frame_tick;
|
||||||
|
|
||||||
ForEachGPUPage(image.gpu_addr, image.guest_size_bytes, [this, image_id](u64 page) {
|
ForEachGPUPage(image.gpu_addr, image.guest_size_bytes, [this, image_id](u64 page) {
|
||||||
(*channel_state->gpu_page_table)[page].push_back(image_id);
|
(*channel_state->gpu_page_table)[page].push_back(image_id);
|
||||||
@@ -2226,7 +2269,7 @@ void TextureCache<P>::UnregisterImage(ImageId image_id) {
|
|||||||
"Trying to unregister an already registered image");
|
"Trying to unregister an already registered image");
|
||||||
image.flags &= ~ImageFlagBits::Registered;
|
image.flags &= ~ImageFlagBits::Registered;
|
||||||
image.flags &= ~ImageFlagBits::BadOverlap;
|
image.flags &= ~ImageFlagBits::BadOverlap;
|
||||||
lru_cache.Free(image.lru_index);
|
|
||||||
const auto& clear_page_table =
|
const auto& clear_page_table =
|
||||||
[image_id](u64 page, ankerl::unordered_dense::map<u64, std::vector<ImageId>, Common::IdentityHash<u64>>& selected_page_table) {
|
[image_id](u64 page, ankerl::unordered_dense::map<u64, std::vector<ImageId>, Common::IdentityHash<u64>>& selected_page_table) {
|
||||||
const auto page_it = selected_page_table.find(page);
|
const auto page_it = selected_page_table.find(page);
|
||||||
@@ -2554,7 +2597,7 @@ void TextureCache<P>::PrepareImage(ImageId image_id, bool is_modification, bool
|
|||||||
if (is_modification) {
|
if (is_modification) {
|
||||||
MarkModification(image);
|
MarkModification(image);
|
||||||
}
|
}
|
||||||
lru_cache.Touch(image.lru_index, frame_tick);
|
image.last_use_tick = frame_tick;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/hash.h"
|
#include "common/hash.h"
|
||||||
#include "common/literals.h"
|
#include "common/literals.h"
|
||||||
#include "common/lru_cache.h"
|
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include "common/scratch_buffer.h"
|
#include "common/scratch_buffer.h"
|
||||||
#include "common/slot_vector.h"
|
#include "common/slot_vector.h"
|
||||||
@@ -485,11 +485,7 @@ private:
|
|||||||
std::deque<std::vector<AsyncBuffer>> async_buffers;
|
std::deque<std::vector<AsyncBuffer>> async_buffers;
|
||||||
std::deque<AsyncBuffer> async_buffers_death_ring;
|
std::deque<AsyncBuffer> async_buffers_death_ring;
|
||||||
|
|
||||||
struct LRUItemParams {
|
|
||||||
using ObjectType = ImageId;
|
|
||||||
using TickType = u64;
|
|
||||||
};
|
|
||||||
Common::LeastRecentlyUsedCache<LRUItemParams> lru_cache;
|
|
||||||
|
|
||||||
#ifdef YUZU_LEGACY
|
#ifdef YUZU_LEGACY
|
||||||
static constexpr size_t TICKS_TO_DESTROY = 6;
|
static constexpr size_t TICKS_TO_DESTROY = 6;
|
||||||
|
|||||||
Reference in New Issue
Block a user