Compare commits
9 Commits
android-15
...
android-16
Author | SHA1 | Date | |
---|---|---|---|
d813f6291d | |||
2ace6da47d | |||
a497205c8d | |||
c22f983b7c | |||
de53d5a716 | |||
f105e51b40 | |||
8244f327ca | |||
462ba1b360 | |||
4a86a55174 |
3
.github/workflows/verify.yml
vendored
3
.github/workflows/verify.yml
vendored
@ -79,7 +79,8 @@ jobs:
|
|||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
brew install autoconf automake boost@1.83 ccache ffmpeg fmt glslang hidapi libtool libusb lz4 ninja nlohmann-json openssl pkg-config qt@5 sdl2 speexdsp zlib zlib zstd
|
# workaround for https://github.com/actions/setup-python/issues/577
|
||||||
|
brew install autoconf automake boost@1.83 ccache ffmpeg fmt glslang hidapi libtool libusb lz4 ninja nlohmann-json openssl pkg-config qt@5 sdl2 speexdsp zlib zlib zstd || brew link --overwrite python@3.12
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
mkdir build
|
mkdir build
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
|----|----|----|----|----|
|
|----|----|----|----|----|
|
||||||
| [12237](https://github.com/yuzu-emu/yuzu//pull/12237) | [`a05c24242`](https://github.com/yuzu-emu/yuzu//pull/12237/files) | nce: implement instruction emulation for misaligned memory accesses | [liamwhite](https://github.com/liamwhite/) | Yes |
|
| [12237](https://github.com/yuzu-emu/yuzu//pull/12237) | [`a05c24242`](https://github.com/yuzu-emu/yuzu//pull/12237/files) | nce: implement instruction emulation for misaligned memory accesses | [liamwhite](https://github.com/liamwhite/) | Yes |
|
||||||
| [12335](https://github.com/yuzu-emu/yuzu//pull/12335) | [`86d26914a`](https://github.com/yuzu-emu/yuzu//pull/12335/files) | android: Game Properties | [t895](https://github.com/t895/) | Yes |
|
| [12335](https://github.com/yuzu-emu/yuzu//pull/12335) | [`86d26914a`](https://github.com/yuzu-emu/yuzu//pull/12335/files) | android: Game Properties | [t895](https://github.com/t895/) | Yes |
|
||||||
|
| [12344](https://github.com/yuzu-emu/yuzu//pull/12344) | [`2a3f84aaf`](https://github.com/yuzu-emu/yuzu//pull/12344/files) | video_core: use interval map for page count tracking | [liamwhite](https://github.com/liamwhite/) | Yes |
|
||||||
|
| [12345](https://github.com/yuzu-emu/yuzu//pull/12345) | [`b560ade66`](https://github.com/yuzu-emu/yuzu//pull/12345/files) | renderer_vulkan: cap async presentation frame count | [liamwhite](https://github.com/liamwhite/) | Yes |
|
||||||
|
| [12349](https://github.com/yuzu-emu/yuzu//pull/12349) | [`8abdfcf8d`](https://github.com/yuzu-emu/yuzu//pull/12349/files) | Have GetActiveChannelCount return the system channels instead of host device channels | [Kelebek1](https://github.com/Kelebek1/) | Yes |
|
||||||
|
| [12358](https://github.com/yuzu-emu/yuzu//pull/12358) | [`8ad5f2c50`](https://github.com/yuzu-emu/yuzu//pull/12358/files) | common: use memory holepunching when clearing memory | [liamwhite](https://github.com/liamwhite/) | Yes |
|
||||||
|
|
||||||
|
|
||||||
End of merge log. You can find the original README.md below the break.
|
End of merge log. You can find the original README.md below the break.
|
||||||
|
@ -253,8 +253,9 @@ CubebSink::~CubebSink() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
SinkStream* CubebSink::AcquireSinkStream(Core::System& system, u32 system_channels,
|
SinkStream* CubebSink::AcquireSinkStream(Core::System& system, u32 system_channels_,
|
||||||
const std::string& name, StreamType type) {
|
const std::string& name, StreamType type) {
|
||||||
|
system_channels = system_channels_;
|
||||||
SinkStreamPtr& stream = sink_streams.emplace_back(std::make_unique<CubebSinkStream>(
|
SinkStreamPtr& stream = sink_streams.emplace_back(std::make_unique<CubebSinkStream>(
|
||||||
ctx, device_channels, system_channels, output_device, input_device, name, type, system));
|
ctx, device_channels, system_channels, output_device, input_device, name, type, system));
|
||||||
|
|
||||||
|
@ -168,8 +168,9 @@ SDLSink::SDLSink(std::string_view target_device_name) {
|
|||||||
|
|
||||||
SDLSink::~SDLSink() = default;
|
SDLSink::~SDLSink() = default;
|
||||||
|
|
||||||
SinkStream* SDLSink::AcquireSinkStream(Core::System& system, u32 system_channels,
|
SinkStream* SDLSink::AcquireSinkStream(Core::System& system, u32 system_channels_,
|
||||||
const std::string&, StreamType type) {
|
const std::string&, StreamType type) {
|
||||||
|
system_channels = system_channels_;
|
||||||
SinkStreamPtr& stream = sink_streams.emplace_back(std::make_unique<SDLSinkStream>(
|
SinkStreamPtr& stream = sink_streams.emplace_back(std::make_unique<SDLSinkStream>(
|
||||||
device_channels, system_channels, output_device, input_device, type, system));
|
device_channels, system_channels, output_device, input_device, type, system));
|
||||||
return stream.get();
|
return stream.get();
|
||||||
|
@ -85,9 +85,21 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void SetSystemVolume(f32 volume) = 0;
|
virtual void SetSystemVolume(f32 volume) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of channels the game has set, can be different to the host hardware's support.
|
||||||
|
* Either 2 or 6.
|
||||||
|
*
|
||||||
|
* @return Number of device channels.
|
||||||
|
*/
|
||||||
|
u32 GetSystemChannels() const {
|
||||||
|
return system_channels;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Number of device channels supported by the hardware
|
/// Number of device channels supported by the hardware
|
||||||
u32 device_channels{2};
|
u32 device_channels{2};
|
||||||
|
/// Number of channels the game is sending
|
||||||
|
u32 system_channels{2};
|
||||||
};
|
};
|
||||||
|
|
||||||
using SinkPtr = std::unique_ptr<Sink>;
|
using SinkPtr = std::unique_ptr<Sink>;
|
||||||
|
@ -40,29 +40,38 @@ void SinkStream::AppendBuffer(SinkBuffer& buffer, std::span<s16> samples) {
|
|||||||
|
|
||||||
if (system_channels == 6 && device_channels == 2) {
|
if (system_channels == 6 && device_channels == 2) {
|
||||||
// We're given 6 channels, but our device only outputs 2, so downmix.
|
// We're given 6 channels, but our device only outputs 2, so downmix.
|
||||||
static constexpr std::array<f32, 4> down_mix_coeff{1.0f, 0.707f, 0.251f, 0.707f};
|
// Front = 1.0
|
||||||
|
// Center = 0.596
|
||||||
|
// Back = 0.707
|
||||||
|
// LFE = 0.354
|
||||||
|
// 1.0 + 0.596 + 0.707 + 0.354 = 2.657, 1/2.657 = 0.37636f downscale coefficient
|
||||||
|
static constexpr std::array<f32, 4> down_mix_coeff{0.37636f, 0.22431056f, 0.13323144f,
|
||||||
|
0.26608652f};
|
||||||
|
|
||||||
for (u32 read_index = 0, write_index = 0; read_index < samples.size();
|
for (u32 read_index = 0, write_index = 0; read_index < samples.size();
|
||||||
read_index += system_channels, write_index += device_channels) {
|
read_index += system_channels, write_index += device_channels) {
|
||||||
|
const auto fl =
|
||||||
|
static_cast<f32>(samples[read_index + static_cast<u32>(Channels::FrontLeft)]);
|
||||||
|
const auto fr =
|
||||||
|
static_cast<f32>(samples[read_index + static_cast<u32>(Channels::FrontRight)]);
|
||||||
|
const auto c =
|
||||||
|
static_cast<f32>(samples[read_index + static_cast<u32>(Channels::Center)]);
|
||||||
|
const auto lfe =
|
||||||
|
static_cast<f32>(samples[read_index + static_cast<u32>(Channels::LFE)]);
|
||||||
|
const auto bl =
|
||||||
|
static_cast<f32>(samples[read_index + static_cast<u32>(Channels::BackLeft)]);
|
||||||
|
const auto br =
|
||||||
|
static_cast<f32>(samples[read_index + static_cast<u32>(Channels::BackRight)]);
|
||||||
|
|
||||||
const auto left_sample{
|
const auto left_sample{
|
||||||
((Common::FixedPoint<49, 15>(
|
static_cast<s32>((fl * down_mix_coeff[0] + c * down_mix_coeff[1] +
|
||||||
samples[read_index + static_cast<u32>(Channels::FrontLeft)]) *
|
lfe * down_mix_coeff[2] + bl * down_mix_coeff[3]) *
|
||||||
down_mix_coeff[0] +
|
volume)};
|
||||||
samples[read_index + static_cast<u32>(Channels::Center)] * down_mix_coeff[1] +
|
|
||||||
samples[read_index + static_cast<u32>(Channels::LFE)] * down_mix_coeff[2] +
|
|
||||||
samples[read_index + static_cast<u32>(Channels::BackLeft)] * down_mix_coeff[3]) *
|
|
||||||
volume)
|
|
||||||
.to_int()};
|
|
||||||
|
|
||||||
const auto right_sample{
|
const auto right_sample{
|
||||||
((Common::FixedPoint<49, 15>(
|
static_cast<s32>((fr * down_mix_coeff[0] + c * down_mix_coeff[1] +
|
||||||
samples[read_index + static_cast<u32>(Channels::FrontRight)]) *
|
lfe * down_mix_coeff[2] + br * down_mix_coeff[3]) *
|
||||||
down_mix_coeff[0] +
|
volume)};
|
||||||
samples[read_index + static_cast<u32>(Channels::Center)] * down_mix_coeff[1] +
|
|
||||||
samples[read_index + static_cast<u32>(Channels::LFE)] * down_mix_coeff[2] +
|
|
||||||
samples[read_index + static_cast<u32>(Channels::BackRight)] * down_mix_coeff[3]) *
|
|
||||||
volume)
|
|
||||||
.to_int()};
|
|
||||||
|
|
||||||
samples[write_index + static_cast<u32>(Channels::FrontLeft)] =
|
samples[write_index + static_cast<u32>(Channels::FrontLeft)] =
|
||||||
static_cast<s16>(std::clamp(left_sample, min, max));
|
static_cast<s16>(std::clamp(left_sample, min, max));
|
||||||
|
@ -11,10 +11,6 @@
|
|||||||
|
|
||||||
#elif defined(__linux__) || defined(__FreeBSD__) // ^^^ Windows ^^^ vvv Linux vvv
|
#elif defined(__linux__) || defined(__FreeBSD__) // ^^^ Windows ^^^ vvv Linux vvv
|
||||||
|
|
||||||
#ifdef ANDROID
|
|
||||||
#include <android/sharedmem.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _GNU_SOURCE
|
#ifndef _GNU_SOURCE
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#endif
|
#endif
|
||||||
@ -193,6 +189,11 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ClearBackingRegion(size_t physical_offset, size_t length) {
|
||||||
|
// TODO: This does not seem to be possible on Windows.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void EnableDirectMappedAddress() {
|
void EnableDirectMappedAddress() {
|
||||||
// TODO
|
// TODO
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
@ -442,9 +443,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Backing memory initialization
|
// Backing memory initialization
|
||||||
#ifdef ANDROID
|
#if defined(__FreeBSD__) && __FreeBSD__ < 13
|
||||||
fd = ASharedMemory_create("HostMemory", backing_size);
|
|
||||||
#elif defined(__FreeBSD__) && __FreeBSD__ < 13
|
|
||||||
// XXX Drop after FreeBSD 12.* reaches EOL on 2024-06-30
|
// XXX Drop after FreeBSD 12.* reaches EOL on 2024-06-30
|
||||||
fd = shm_open(SHM_ANON, O_RDWR, 0600);
|
fd = shm_open(SHM_ANON, O_RDWR, 0600);
|
||||||
#else
|
#else
|
||||||
@ -455,7 +454,6 @@ public:
|
|||||||
throw std::bad_alloc{};
|
throw std::bad_alloc{};
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef ANDROID
|
|
||||||
// Defined to extend the file with zeros
|
// Defined to extend the file with zeros
|
||||||
int ret = ftruncate(fd, backing_size);
|
int ret = ftruncate(fd, backing_size);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
@ -463,7 +461,6 @@ public:
|
|||||||
strerror(errno));
|
strerror(errno));
|
||||||
throw std::bad_alloc{};
|
throw std::bad_alloc{};
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
backing_base = static_cast<u8*>(
|
backing_base = static_cast<u8*>(
|
||||||
mmap(nullptr, backing_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
|
mmap(nullptr, backing_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
|
||||||
@ -552,6 +549,19 @@ public:
|
|||||||
ASSERT_MSG(ret == 0, "mprotect failed: {}", strerror(errno));
|
ASSERT_MSG(ret == 0, "mprotect failed: {}", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ClearBackingRegion(size_t physical_offset, size_t length) {
|
||||||
|
#ifdef __linux__
|
||||||
|
// Set MADV_REMOVE on backing map to destroy it instantly.
|
||||||
|
// This also deletes the area from the backing file.
|
||||||
|
int ret = madvise(backing_base + physical_offset, length, MADV_REMOVE);
|
||||||
|
ASSERT_MSG(ret == 0, "madvise failed: {}", strerror(errno));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void EnableDirectMappedAddress() {
|
void EnableDirectMappedAddress() {
|
||||||
virtual_base = nullptr;
|
virtual_base = nullptr;
|
||||||
}
|
}
|
||||||
@ -623,6 +633,10 @@ public:
|
|||||||
|
|
||||||
void Protect(size_t virtual_offset, size_t length, bool read, bool write, bool execute) {}
|
void Protect(size_t virtual_offset, size_t length, bool read, bool write, bool execute) {}
|
||||||
|
|
||||||
|
bool ClearBackingRegion(size_t physical_offset, size_t length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void EnableDirectMappedAddress() {}
|
void EnableDirectMappedAddress() {}
|
||||||
|
|
||||||
u8* backing_base{nullptr};
|
u8* backing_base{nullptr};
|
||||||
@ -698,6 +712,12 @@ void HostMemory::Protect(size_t virtual_offset, size_t length, bool read, bool w
|
|||||||
impl->Protect(virtual_offset + virtual_base_offset, length, read, write, execute);
|
impl->Protect(virtual_offset + virtual_base_offset, length, read, write, execute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HostMemory::ClearBackingRegion(size_t physical_offset, size_t length, u32 fill_value) {
|
||||||
|
if (!impl || fill_value != 0 || !impl->ClearBackingRegion(physical_offset, length)) {
|
||||||
|
std::memset(backing_base + physical_offset, fill_value, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HostMemory::EnableDirectMappedAddress() {
|
void HostMemory::EnableDirectMappedAddress() {
|
||||||
if (impl) {
|
if (impl) {
|
||||||
impl->EnableDirectMappedAddress();
|
impl->EnableDirectMappedAddress();
|
||||||
|
@ -48,6 +48,8 @@ public:
|
|||||||
|
|
||||||
void EnableDirectMappedAddress();
|
void EnableDirectMappedAddress();
|
||||||
|
|
||||||
|
void ClearBackingRegion(size_t physical_offset, size_t length, u32 fill_value);
|
||||||
|
|
||||||
[[nodiscard]] u8* BackingBasePointer() noexcept {
|
[[nodiscard]] u8* BackingBasePointer() noexcept {
|
||||||
return backing_base;
|
return backing_base;
|
||||||
}
|
}
|
||||||
|
@ -421,8 +421,9 @@ Result KMemoryManager::AllocateForProcess(KPageGroup* out, size_t num_pages, u32
|
|||||||
} else {
|
} else {
|
||||||
// Set all the allocated memory.
|
// Set all the allocated memory.
|
||||||
for (const auto& block : *out) {
|
for (const auto& block : *out) {
|
||||||
std::memset(m_system.DeviceMemory().GetPointer<void>(block.GetAddress()), fill_pattern,
|
m_system.DeviceMemory().buffer.ClearBackingRegion(GetInteger(block.GetAddress()) -
|
||||||
block.GetSize());
|
Core::DramMemoryMap::Base,
|
||||||
|
block.GetSize(), fill_pattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +81,11 @@ void InvalidateInstructionCache(KernelCore& kernel, AddressType addr, u64 size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClearBackingRegion(Core::System& system, KPhysicalAddress addr, u64 size, u32 fill_value) {
|
||||||
|
system.DeviceMemory().buffer.ClearBackingRegion(GetInteger(addr) - Core::DramMemoryMap::Base,
|
||||||
|
size, fill_value);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename AddressType>
|
template <typename AddressType>
|
||||||
Result InvalidateDataCache(AddressType addr, u64 size) {
|
Result InvalidateDataCache(AddressType addr, u64 size) {
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
@ -1363,8 +1368,7 @@ Result KPageTableBase::MapInsecureMemory(KProcessAddress address, size_t size) {
|
|||||||
|
|
||||||
// Clear all the newly allocated pages.
|
// Clear all the newly allocated pages.
|
||||||
for (const auto& it : pg) {
|
for (const auto& it : pg) {
|
||||||
std::memset(GetHeapVirtualPointer(m_kernel, it.GetAddress()),
|
ClearBackingRegion(m_system, it.GetAddress(), it.GetSize(), m_heap_fill_value);
|
||||||
static_cast<u32>(m_heap_fill_value), it.GetSize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock the table.
|
// Lock the table.
|
||||||
@ -1570,8 +1574,7 @@ Result KPageTableBase::AllocateAndMapPagesImpl(PageLinkedList* page_list, KProce
|
|||||||
|
|
||||||
// Clear all pages.
|
// Clear all pages.
|
||||||
for (const auto& it : pg) {
|
for (const auto& it : pg) {
|
||||||
std::memset(GetHeapVirtualPointer(m_kernel, it.GetAddress()),
|
ClearBackingRegion(m_system, it.GetAddress(), it.GetSize(), m_heap_fill_value);
|
||||||
static_cast<u32>(m_heap_fill_value), it.GetSize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map the pages.
|
// Map the pages.
|
||||||
@ -2159,8 +2162,7 @@ Result KPageTableBase::SetHeapSize(KProcessAddress* out, size_t size) {
|
|||||||
|
|
||||||
// Clear all the newly allocated pages.
|
// Clear all the newly allocated pages.
|
||||||
for (const auto& it : pg) {
|
for (const auto& it : pg) {
|
||||||
std::memset(GetHeapVirtualPointer(m_kernel, it.GetAddress()), m_heap_fill_value,
|
ClearBackingRegion(m_system, it.GetAddress(), it.GetSize(), m_heap_fill_value);
|
||||||
it.GetSize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map the pages.
|
// Map the pages.
|
||||||
|
@ -359,7 +359,7 @@ private:
|
|||||||
|
|
||||||
void GetActiveChannelCount(HLERequestContext& ctx) {
|
void GetActiveChannelCount(HLERequestContext& ctx) {
|
||||||
const auto& sink{system.AudioCore().GetOutputSink()};
|
const auto& sink{system.AudioCore().GetOutputSink()};
|
||||||
u32 channel_count{sink.GetDeviceChannels()};
|
u32 channel_count{sink.GetSystemChannels()};
|
||||||
|
|
||||||
LOG_DEBUG(Service_Audio, "(STUBBED) called. Channels={}", channel_count);
|
LOG_DEBUG(Service_Audio, "(STUBBED) called. Channels={}", channel_count);
|
||||||
|
|
||||||
|
@ -23,13 +23,13 @@ constexpr VAddr c = 16 * HIGH_PAGE_SIZE;
|
|||||||
|
|
||||||
class RasterizerInterface {
|
class RasterizerInterface {
|
||||||
public:
|
public:
|
||||||
void UpdatePagesCachedCount(VAddr addr, u64 size, int delta) {
|
void UpdatePagesCachedCount(VAddr addr, u64 size, bool cache) {
|
||||||
const u64 page_start{addr >> Core::Memory::YUZU_PAGEBITS};
|
const u64 page_start{addr >> Core::Memory::YUZU_PAGEBITS};
|
||||||
const u64 page_end{(addr + size + Core::Memory::YUZU_PAGESIZE - 1) >>
|
const u64 page_end{(addr + size + Core::Memory::YUZU_PAGESIZE - 1) >>
|
||||||
Core::Memory::YUZU_PAGEBITS};
|
Core::Memory::YUZU_PAGEBITS};
|
||||||
for (u64 page = page_start; page < page_end; ++page) {
|
for (u64 page = page_start; page < page_end; ++page) {
|
||||||
int& value = page_table[page];
|
int& value = page_table[page];
|
||||||
value += delta;
|
value += (cache ? 1 : -1);
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
throw std::logic_error{"negative page"};
|
throw std::logic_error{"negative page"};
|
||||||
}
|
}
|
||||||
@ -546,4 +546,4 @@ TEST_CASE("MemoryTracker: Cached write downloads") {
|
|||||||
REQUIRE(!memory_track->IsRegionGpuModified(c + PAGE, PAGE));
|
REQUIRE(!memory_track->IsRegionGpuModified(c + PAGE, PAGE));
|
||||||
memory_track->MarkRegionAsCpuModified(c, WORD);
|
memory_track->MarkRegionAsCpuModified(c, WORD);
|
||||||
REQUIRE(rasterizer.Count() == 0);
|
REQUIRE(rasterizer.Count() == 0);
|
||||||
}
|
}
|
||||||
|
@ -473,7 +473,7 @@ private:
|
|||||||
VAddr addr = cpu_addr + word_index * BYTES_PER_WORD;
|
VAddr addr = cpu_addr + word_index * BYTES_PER_WORD;
|
||||||
IteratePages(changed_bits, [&](size_t offset, size_t size) {
|
IteratePages(changed_bits, [&](size_t offset, size_t size) {
|
||||||
rasterizer->UpdatePagesCachedCount(addr + offset * BYTES_PER_PAGE,
|
rasterizer->UpdatePagesCachedCount(addr + offset * BYTES_PER_PAGE,
|
||||||
size * BYTES_PER_PAGE, add_to_rasterizer ? 1 : -1);
|
size * BYTES_PER_PAGE, add_to_rasterizer);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
|
#include "common/alignment.h"
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/div_ceil.h"
|
#include "common/div_ceil.h"
|
||||||
@ -11,61 +12,65 @@
|
|||||||
|
|
||||||
namespace VideoCore {
|
namespace VideoCore {
|
||||||
|
|
||||||
|
static constexpr u16 IdentityValue = 1;
|
||||||
|
|
||||||
using namespace Core::Memory;
|
using namespace Core::Memory;
|
||||||
|
|
||||||
RasterizerAccelerated::RasterizerAccelerated(Memory& cpu_memory_)
|
RasterizerAccelerated::RasterizerAccelerated(Memory& cpu_memory_) : map{}, cpu_memory{cpu_memory_} {
|
||||||
: cached_pages(std::make_unique<CachedPages>()), cpu_memory{cpu_memory_} {}
|
// We are tracking CPU memory, which cannot map more than 39 bits.
|
||||||
|
const VAddr start_address = 0;
|
||||||
|
const VAddr end_address = (1ULL << 39);
|
||||||
|
const IntervalType address_space_interval(start_address, end_address);
|
||||||
|
const auto value = std::make_pair(address_space_interval, IdentityValue);
|
||||||
|
|
||||||
|
map.add(value);
|
||||||
|
}
|
||||||
|
|
||||||
RasterizerAccelerated::~RasterizerAccelerated() = default;
|
RasterizerAccelerated::~RasterizerAccelerated() = default;
|
||||||
|
|
||||||
void RasterizerAccelerated::UpdatePagesCachedCount(VAddr addr, u64 size, int delta) {
|
void RasterizerAccelerated::UpdatePagesCachedCount(VAddr addr, u64 size, bool cache) {
|
||||||
u64 uncache_begin = 0;
|
std::scoped_lock lk{map_lock};
|
||||||
u64 cache_begin = 0;
|
|
||||||
u64 uncache_bytes = 0;
|
|
||||||
u64 cache_bytes = 0;
|
|
||||||
|
|
||||||
std::atomic_thread_fence(std::memory_order_acquire);
|
// Align sizes.
|
||||||
const u64 page_end = Common::DivCeil(addr + size, YUZU_PAGESIZE);
|
addr = Common::AlignDown(addr, YUZU_PAGESIZE);
|
||||||
for (u64 page = addr >> YUZU_PAGEBITS; page != page_end; ++page) {
|
size = Common::AlignUp(size, YUZU_PAGESIZE);
|
||||||
std::atomic_uint16_t& count = cached_pages->at(page >> 2).Count(page);
|
|
||||||
|
|
||||||
if (delta > 0) {
|
// Declare the overall interval we are going to operate on.
|
||||||
ASSERT_MSG(count.load(std::memory_order::relaxed) < UINT16_MAX, "Count may overflow!");
|
const VAddr start_address = addr;
|
||||||
} else if (delta < 0) {
|
const VAddr end_address = addr + size;
|
||||||
ASSERT_MSG(count.load(std::memory_order::relaxed) > 0, "Count may underflow!");
|
const IntervalType modification_range(start_address, end_address);
|
||||||
} else {
|
|
||||||
ASSERT_MSG(false, "Delta must be non-zero!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds or subtracts 1, as count is a unsigned 8-bit value
|
// Find the boundaries of where to iterate.
|
||||||
count.fetch_add(static_cast<u16>(delta), std::memory_order_release);
|
const auto lower = map.lower_bound(modification_range);
|
||||||
|
const auto upper = map.upper_bound(modification_range);
|
||||||
|
|
||||||
// Assume delta is either -1 or 1
|
// Iterate over the contained intervals.
|
||||||
if (count.load(std::memory_order::relaxed) == 0) {
|
for (auto it = lower; it != upper; it++) {
|
||||||
if (uncache_bytes == 0) {
|
// Intersect interval range with modification range.
|
||||||
uncache_begin = page;
|
const auto current_range = modification_range & it->first;
|
||||||
}
|
|
||||||
uncache_bytes += YUZU_PAGESIZE;
|
// Calculate the address and size to operate over.
|
||||||
} else if (uncache_bytes > 0) {
|
const auto current_addr = current_range.lower();
|
||||||
cpu_memory.RasterizerMarkRegionCached(uncache_begin << YUZU_PAGEBITS, uncache_bytes,
|
const auto current_size = current_range.upper() - current_addr;
|
||||||
false);
|
|
||||||
uncache_bytes = 0;
|
// Get the current value of the range.
|
||||||
}
|
const auto value = it->second;
|
||||||
if (count.load(std::memory_order::relaxed) == 1 && delta > 0) {
|
|
||||||
if (cache_bytes == 0) {
|
if (cache && value == IdentityValue) {
|
||||||
cache_begin = page;
|
// If we are going to cache, and the value is not yet referenced, then cache this range.
|
||||||
}
|
cpu_memory.RasterizerMarkRegionCached(current_addr, current_size, true);
|
||||||
cache_bytes += YUZU_PAGESIZE;
|
} else if (!cache && value == IdentityValue + 1) {
|
||||||
} else if (cache_bytes > 0) {
|
// If we are going to uncache, and this is the last reference, then uncache this range.
|
||||||
cpu_memory.RasterizerMarkRegionCached(cache_begin << YUZU_PAGEBITS, cache_bytes, true);
|
cpu_memory.RasterizerMarkRegionCached(current_addr, current_size, false);
|
||||||
cache_bytes = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (uncache_bytes > 0) {
|
|
||||||
cpu_memory.RasterizerMarkRegionCached(uncache_begin << YUZU_PAGEBITS, uncache_bytes, false);
|
// Update the set.
|
||||||
}
|
const auto value = std::make_pair(modification_range, IdentityValue);
|
||||||
if (cache_bytes > 0) {
|
if (cache) {
|
||||||
cpu_memory.RasterizerMarkRegionCached(cache_begin << YUZU_PAGEBITS, cache_bytes, true);
|
map.add(value);
|
||||||
|
} else {
|
||||||
|
map.subtract(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
#include <mutex>
|
||||||
#include <atomic>
|
#include <boost/icl/interval_map.hpp>
|
||||||
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "video_core/rasterizer_interface.h"
|
#include "video_core/rasterizer_interface.h"
|
||||||
@ -21,28 +21,17 @@ public:
|
|||||||
explicit RasterizerAccelerated(Core::Memory::Memory& cpu_memory_);
|
explicit RasterizerAccelerated(Core::Memory::Memory& cpu_memory_);
|
||||||
~RasterizerAccelerated() override;
|
~RasterizerAccelerated() override;
|
||||||
|
|
||||||
void UpdatePagesCachedCount(VAddr addr, u64 size, int delta) override;
|
void UpdatePagesCachedCount(VAddr addr, u64 size, bool cache) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class CacheEntry final {
|
using PageIndex = VAddr;
|
||||||
public:
|
using PageReferenceCount = u16;
|
||||||
CacheEntry() = default;
|
|
||||||
|
|
||||||
std::atomic_uint16_t& Count(std::size_t page) {
|
using IntervalMap = boost::icl::interval_map<PageIndex, PageReferenceCount>;
|
||||||
return values[page & 3];
|
using IntervalType = IntervalMap::interval_type;
|
||||||
}
|
|
||||||
|
|
||||||
const std::atomic_uint16_t& Count(std::size_t page) const {
|
IntervalMap map;
|
||||||
return values[page & 3];
|
std::mutex map_lock;
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::array<std::atomic_uint16_t, 4> values{};
|
|
||||||
};
|
|
||||||
static_assert(sizeof(CacheEntry) == 8, "CacheEntry should be 8 bytes!");
|
|
||||||
|
|
||||||
using CachedPages = std::array<CacheEntry, 0x2000000>;
|
|
||||||
std::unique_ptr<CachedPages> cached_pages;
|
|
||||||
Core::Memory::Memory& cpu_memory;
|
Core::Memory::Memory& cpu_memory;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Increase/decrease the number of object in pages touching the specified region
|
/// Increase/decrease the number of object in pages touching the specified region
|
||||||
virtual void UpdatePagesCachedCount(VAddr addr, u64 size, int delta) {}
|
virtual void UpdatePagesCachedCount(VAddr addr, u64 size, bool cache) {}
|
||||||
|
|
||||||
/// Initialize disk cached resources for the game being emulated
|
/// Initialize disk cached resources for the game being emulated
|
||||||
virtual void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
virtual void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
||||||
|
@ -102,8 +102,8 @@ PresentManager::PresentManager(const vk::Instance& instance_,
|
|||||||
memory_allocator{memory_allocator_}, scheduler{scheduler_}, swapchain{swapchain_},
|
memory_allocator{memory_allocator_}, scheduler{scheduler_}, swapchain{swapchain_},
|
||||||
surface{surface_}, blit_supported{CanBlitToSwapchain(device.GetPhysical(),
|
surface{surface_}, blit_supported{CanBlitToSwapchain(device.GetPhysical(),
|
||||||
swapchain.GetImageViewFormat())},
|
swapchain.GetImageViewFormat())},
|
||||||
use_present_thread{Settings::values.async_presentation.GetValue()},
|
use_present_thread{Settings::values.async_presentation.GetValue()} {
|
||||||
image_count{swapchain.GetImageCount()} {
|
SetImageCount();
|
||||||
|
|
||||||
auto& dld = device.GetLogical();
|
auto& dld = device.GetLogical();
|
||||||
cmdpool = dld.CreateCommandPool({
|
cmdpool = dld.CreateCommandPool({
|
||||||
@ -289,7 +289,14 @@ void PresentManager::PresentThread(std::stop_token token) {
|
|||||||
|
|
||||||
void PresentManager::RecreateSwapchain(Frame* frame) {
|
void PresentManager::RecreateSwapchain(Frame* frame) {
|
||||||
swapchain.Create(*surface, frame->width, frame->height);
|
swapchain.Create(*surface, frame->width, frame->height);
|
||||||
image_count = swapchain.GetImageCount();
|
SetImageCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PresentManager::SetImageCount() {
|
||||||
|
// We cannot have more than 5 images in flight at any given time.
|
||||||
|
// FRAMES_IN_FLIGHT is 7, and the cache TICKS_TO_DESTROY is 6.
|
||||||
|
// Mali drivers will give us 6.
|
||||||
|
image_count = std::min<size_t>(swapchain.GetImageCount(), 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PresentManager::CopyToSwapchain(Frame* frame) {
|
void PresentManager::CopyToSwapchain(Frame* frame) {
|
||||||
|
@ -62,6 +62,8 @@ private:
|
|||||||
|
|
||||||
void RecreateSwapchain(Frame* frame);
|
void RecreateSwapchain(Frame* frame);
|
||||||
|
|
||||||
|
void SetImageCount();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const vk::Instance& instance;
|
const vk::Instance& instance;
|
||||||
Core::Frontend::EmuWindow& render_window;
|
Core::Frontend::EmuWindow& render_window;
|
||||||
|
@ -132,7 +132,7 @@ void ShaderCache::Register(std::unique_ptr<ShaderInfo> data, VAddr addr, size_t
|
|||||||
|
|
||||||
storage.push_back(std::move(data));
|
storage.push_back(std::move(data));
|
||||||
|
|
||||||
rasterizer.UpdatePagesCachedCount(addr, size, 1);
|
rasterizer.UpdatePagesCachedCount(addr, size, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderCache::InvalidatePagesInRegion(VAddr addr, size_t size) {
|
void ShaderCache::InvalidatePagesInRegion(VAddr addr, size_t size) {
|
||||||
@ -209,7 +209,7 @@ void ShaderCache::UnmarkMemory(Entry* entry) {
|
|||||||
|
|
||||||
const VAddr addr = entry->addr_start;
|
const VAddr addr = entry->addr_start;
|
||||||
const size_t size = entry->addr_end - addr;
|
const size_t size = entry->addr_end - addr;
|
||||||
rasterizer.UpdatePagesCachedCount(addr, size, -1);
|
rasterizer.UpdatePagesCachedCount(addr, size, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderCache::RemoveShadersFromStorage(std::span<ShaderInfo*> removed_shaders) {
|
void ShaderCache::RemoveShadersFromStorage(std::span<ShaderInfo*> removed_shaders) {
|
||||||
|
@ -2080,7 +2080,7 @@ void TextureCache<P>::TrackImage(ImageBase& image, ImageId image_id) {
|
|||||||
ASSERT(False(image.flags & ImageFlagBits::Tracked));
|
ASSERT(False(image.flags & ImageFlagBits::Tracked));
|
||||||
image.flags |= ImageFlagBits::Tracked;
|
image.flags |= ImageFlagBits::Tracked;
|
||||||
if (False(image.flags & ImageFlagBits::Sparse)) {
|
if (False(image.flags & ImageFlagBits::Sparse)) {
|
||||||
rasterizer.UpdatePagesCachedCount(image.cpu_addr, image.guest_size_bytes, 1);
|
rasterizer.UpdatePagesCachedCount(image.cpu_addr, image.guest_size_bytes, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (True(image.flags & ImageFlagBits::Registered)) {
|
if (True(image.flags & ImageFlagBits::Registered)) {
|
||||||
@ -2091,13 +2091,13 @@ void TextureCache<P>::TrackImage(ImageBase& image, ImageId image_id) {
|
|||||||
const auto& map = slot_map_views[map_view_id];
|
const auto& map = slot_map_views[map_view_id];
|
||||||
const VAddr cpu_addr = map.cpu_addr;
|
const VAddr cpu_addr = map.cpu_addr;
|
||||||
const std::size_t size = map.size;
|
const std::size_t size = map.size;
|
||||||
rasterizer.UpdatePagesCachedCount(cpu_addr, size, 1);
|
rasterizer.UpdatePagesCachedCount(cpu_addr, size, true);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ForEachSparseSegment(image,
|
ForEachSparseSegment(image,
|
||||||
[this]([[maybe_unused]] GPUVAddr gpu_addr, VAddr cpu_addr, size_t size) {
|
[this]([[maybe_unused]] GPUVAddr gpu_addr, VAddr cpu_addr, size_t size) {
|
||||||
rasterizer.UpdatePagesCachedCount(cpu_addr, size, 1);
|
rasterizer.UpdatePagesCachedCount(cpu_addr, size, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2106,7 +2106,7 @@ void TextureCache<P>::UntrackImage(ImageBase& image, ImageId image_id) {
|
|||||||
ASSERT(True(image.flags & ImageFlagBits::Tracked));
|
ASSERT(True(image.flags & ImageFlagBits::Tracked));
|
||||||
image.flags &= ~ImageFlagBits::Tracked;
|
image.flags &= ~ImageFlagBits::Tracked;
|
||||||
if (False(image.flags & ImageFlagBits::Sparse)) {
|
if (False(image.flags & ImageFlagBits::Sparse)) {
|
||||||
rasterizer.UpdatePagesCachedCount(image.cpu_addr, image.guest_size_bytes, -1);
|
rasterizer.UpdatePagesCachedCount(image.cpu_addr, image.guest_size_bytes, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ASSERT(True(image.flags & ImageFlagBits::Registered));
|
ASSERT(True(image.flags & ImageFlagBits::Registered));
|
||||||
@ -2117,7 +2117,7 @@ void TextureCache<P>::UntrackImage(ImageBase& image, ImageId image_id) {
|
|||||||
const auto& map = slot_map_views[map_view_id];
|
const auto& map = slot_map_views[map_view_id];
|
||||||
const VAddr cpu_addr = map.cpu_addr;
|
const VAddr cpu_addr = map.cpu_addr;
|
||||||
const std::size_t size = map.size;
|
const std::size_t size = map.size;
|
||||||
rasterizer.UpdatePagesCachedCount(cpu_addr, size, -1);
|
rasterizer.UpdatePagesCachedCount(cpu_addr, size, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user