mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-06-01 08:13:16 +00:00
core: Rewrite thread local storage implementation (#118)
This commit is contained in:
parent
b94efcba5a
commit
1b9bf924ca
11 changed files with 176 additions and 189 deletions
|
@ -1,9 +1,11 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <limits>
|
||||
#include "common/assert.h"
|
||||
#include "common/config.h"
|
||||
#include "core/libraries/videoout/buffer.h"
|
||||
#include "core/virtual_memory.h"
|
||||
#include "video_core/renderer_vulkan/vk_scheduler.h"
|
||||
#include "video_core/texture_cache/texture_cache.h"
|
||||
#include "video_core/texture_cache/tile_manager.h"
|
||||
|
@ -15,7 +17,7 @@
|
|||
#define PAGE_NOACCESS PROT_NONE
|
||||
#define PAGE_READWRITE (PROT_READ | PROT_WRITE)
|
||||
#else
|
||||
#include <Windows.h>
|
||||
#include <windows.h>
|
||||
|
||||
void mprotect(void* addr, size_t len, int prot) {
|
||||
DWORD old_prot{};
|
||||
|
@ -57,6 +59,7 @@ LONG WINAPI GuestFaultSignalHandler(EXCEPTION_POINTERS* pExp) noexcept {
|
|||
#endif
|
||||
|
||||
static constexpr u64 StreamBufferSize = 128_MB;
|
||||
static constexpr u64 PageShift = 12;
|
||||
|
||||
TextureCache::TextureCache(const Vulkan::Instance& instance_, Vulkan::Scheduler& scheduler_)
|
||||
: instance{instance_}, scheduler{scheduler_},
|
||||
|
@ -76,7 +79,7 @@ TextureCache::TextureCache(const Vulkan::Instance& instance_, Vulkan::Scheduler&
|
|||
guest_access_fault.sa_mask = signal_mask;
|
||||
sigaction(SIGSEGV, &guest_access_fault, nullptr);
|
||||
#else
|
||||
veh_handle = AddVectoredExceptionHandler(1, GuestFaultSignalHandler);
|
||||
veh_handle = AddVectoredExceptionHandler(0, GuestFaultSignalHandler);
|
||||
ASSERT_MSG(veh_handle, "Failed to register an exception handler");
|
||||
#endif
|
||||
g_texture_cache = this;
|
||||
|
@ -243,8 +246,8 @@ void TextureCache::UntrackImage(Image& image, ImageId image_id) {
|
|||
}
|
||||
|
||||
void TextureCache::UpdatePagesCachedCount(VAddr addr, u64 size, s32 delta) {
|
||||
const u64 num_pages = ((addr + size - 1) >> PageBits) - (addr >> PageBits) + 1;
|
||||
const u64 page_start = addr >> PageBits;
|
||||
const u64 num_pages = ((addr + size - 1) >> PageShift) - (addr >> PageShift) + 1;
|
||||
const u64 page_start = addr >> PageShift;
|
||||
const u64 page_end = page_start + num_pages;
|
||||
|
||||
const auto pages_interval =
|
||||
|
@ -256,8 +259,8 @@ void TextureCache::UpdatePagesCachedCount(VAddr addr, u64 size, s32 delta) {
|
|||
const auto& range = cached_pages.equal_range(pages_interval);
|
||||
for (const auto& [range, count] : boost::make_iterator_range(range)) {
|
||||
const auto interval = range & pages_interval;
|
||||
const VAddr interval_start_addr = boost::icl::first(interval) << PageBits;
|
||||
const VAddr interval_end_addr = boost::icl::last_next(interval) << PageBits;
|
||||
const VAddr interval_start_addr = boost::icl::first(interval) << PageShift;
|
||||
const VAddr interval_end_addr = boost::icl::last_next(interval) << PageShift;
|
||||
const u32 interval_size = interval_end_addr - interval_start_addr;
|
||||
void* addr = reinterpret_cast<void*>(interval_start_addr);
|
||||
if (delta > 0 && count == delta) {
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <forward_list>
|
||||
#include <boost/container/small_vector.hpp>
|
||||
#include <boost/icl/interval_map.hpp>
|
||||
#include <tsl/robin_map.h>
|
||||
|
@ -19,7 +18,12 @@ struct BufferAttributeGroup;
|
|||
namespace VideoCore {
|
||||
|
||||
class TextureCache {
|
||||
static constexpr u64 PageBits = 14;
|
||||
// This is the page shift for adding images into the hash map. It isn't related to
|
||||
// the page size of the guest or the host and is chosen for convenience. A number too
|
||||
// small will increase the number of hash map lookups per image, while too large will
|
||||
// increase the number of images per page.
|
||||
static constexpr u64 PageBits = 20;
|
||||
static constexpr u64 PageMask = (1ULL << PageBits) - 1;
|
||||
|
||||
public:
|
||||
explicit TextureCache(const Vulkan::Instance& instance, Vulkan::Scheduler& scheduler);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue