summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/common/uuid.h11
-rw-r--r--src/core/memory.cpp552
-rw-r--r--src/core/memory.h102
-rw-r--r--src/input_common/main.cpp8
-rw-r--r--src/input_common/mouse/mouse_poller.cpp1
-rw-r--r--src/input_common/sdl/sdl_impl.cpp87
-rw-r--r--src/video_core/command_classes/codecs/vp9.cpp4
-rw-r--r--src/video_core/command_classes/codecs/vp9_types.h2
-rw-r--r--src/video_core/vulkan_common/vulkan_memory_allocator.cpp8
-rw-r--r--src/video_core/vulkan_common/vulkan_memory_allocator.h2
-rw-r--r--src/yuzu/configuration/configure_general.ui60
-rw-r--r--src/yuzu/configuration/configure_graphics_advanced.ui7
-rw-r--r--src/yuzu/configuration/configure_input_player.cpp13
-rw-r--r--src/yuzu_cmd/CMakeLists.txt1
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.cpp1
15 files changed, 298 insertions, 561 deletions
diff --git a/src/common/uuid.h b/src/common/uuid.h
index aeb36939a..2353179d8 100644
--- a/src/common/uuid.h
+++ b/src/common/uuid.h
@@ -69,3 +69,14 @@ struct UUID {
static_assert(sizeof(UUID) == 16, "UUID is an invalid size!");
} // namespace Common
+
+namespace std {
+
+template <>
+struct hash<Common::UUID> {
+ size_t operator()(const Common::UUID& uuid) const noexcept {
+ return uuid.uuid[1] ^ uuid.uuid[0];
+ }
+};
+
+} // namespace std
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index f285c6f63..51c4dea26 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -4,8 +4,6 @@
#include <algorithm>
#include <cstring>
-#include <optional>
-#include <utility>
#include "common/assert.h"
#include "common/atomic_ops.h"
@@ -14,12 +12,10 @@
#include "common/page_table.h"
#include "common/settings.h"
#include "common/swap.h"
-#include "core/arm/arm_interface.h"
#include "core/core.h"
#include "core/device_memory.h"
#include "core/hle/kernel/k_page_table.h"
#include "core/hle/kernel/k_process.h"
-#include "core/hle/kernel/physical_memory.h"
#include "core/memory.h"
#include "video_core/gpu.h"
@@ -62,17 +58,7 @@ struct Memory::Impl {
}
}
- bool IsValidVirtualAddress(const Kernel::KProcess& process, const VAddr vaddr) const {
- const auto& page_table = process.PageTable().PageTableImpl();
- const auto [pointer, type] = page_table.pointers[vaddr >> PAGE_BITS].PointerType();
- return pointer != nullptr || type == Common::PageType::RasterizerCachedMemory;
- }
-
- bool IsValidVirtualAddress(VAddr vaddr) const {
- return IsValidVirtualAddress(*system.CurrentProcess(), vaddr);
- }
-
- u8* GetPointerFromRasterizerCachedMemory(VAddr vaddr) const {
+ [[nodiscard]] u8* GetPointerFromRasterizerCachedMemory(VAddr vaddr) const {
const PAddr paddr{current_page_table->backing_addr[vaddr >> PAGE_BITS]};
if (!paddr) {
@@ -82,18 +68,6 @@ struct Memory::Impl {
return system.DeviceMemory().GetPointer(paddr) + vaddr;
}
- u8* GetPointer(const VAddr vaddr) const {
- const uintptr_t raw_pointer = current_page_table->pointers[vaddr >> PAGE_BITS].Raw();
- if (u8* const pointer = Common::PageTable::PageInfo::ExtractPointer(raw_pointer)) {
- return pointer + vaddr;
- }
- const auto type = Common::PageTable::PageInfo::ExtractType(raw_pointer);
- if (type == Common::PageType::RasterizerCachedMemory) {
- return GetPointerFromRasterizerCachedMemory(vaddr);
- }
- return nullptr;
- }
-
u8 Read8(const VAddr addr) {
return Read<u8>(addr);
}
@@ -179,7 +153,7 @@ struct Memory::Impl {
std::string string;
string.reserve(max_length);
for (std::size_t i = 0; i < max_length; ++i) {
- const char c = Read8(vaddr);
+ const char c = Read<s8>(vaddr);
if (c == '\0') {
break;
}
@@ -190,15 +164,14 @@ struct Memory::Impl {
return string;
}
- void ReadBlock(const Kernel::KProcess& process, const VAddr src_addr, void* dest_buffer,
- const std::size_t size) {
+ void WalkBlock(const Kernel::KProcess& process, const VAddr addr, const std::size_t size,
+ auto on_unmapped, auto on_memory, auto on_rasterizer, auto increment) {
const auto& page_table = process.PageTable().PageTableImpl();
-
std::size_t remaining_size = size;
- std::size_t page_index = src_addr >> PAGE_BITS;
- std::size_t page_offset = src_addr & PAGE_MASK;
+ std::size_t page_index = addr >> PAGE_BITS;
+ std::size_t page_offset = addr & PAGE_MASK;
- while (remaining_size > 0) {
+ while (remaining_size) {
const std::size_t copy_amount =
std::min(static_cast<std::size_t>(PAGE_SIZE) - page_offset, remaining_size);
const auto current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
@@ -206,22 +179,18 @@ struct Memory::Impl {
const auto [pointer, type] = page_table.pointers[page_index].PointerType();
switch (type) {
case Common::PageType::Unmapped: {
- LOG_ERROR(HW_Memory,
- "Unmapped ReadBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
- current_vaddr, src_addr, size);
- std::memset(dest_buffer, 0, copy_amount);
+ on_unmapped(copy_amount, current_vaddr);
break;
}
case Common::PageType::Memory: {
DEBUG_ASSERT(pointer);
- const u8* const src_ptr = pointer + page_offset + (page_index << PAGE_BITS);
- std::memcpy(dest_buffer, src_ptr, copy_amount);
+ u8* mem_ptr = pointer + page_offset + (page_index << PAGE_BITS);
+ on_memory(copy_amount, mem_ptr);
break;
}
case Common::PageType::RasterizerCachedMemory: {
- const u8* const host_ptr{GetPointerFromRasterizerCachedMemory(current_vaddr)};
- system.GPU().FlushRegion(current_vaddr, copy_amount);
- std::memcpy(dest_buffer, host_ptr, copy_amount);
+ u8* const host_ptr{GetPointerFromRasterizerCachedMemory(current_vaddr)};
+ on_rasterizer(current_vaddr, copy_amount, host_ptr);
break;
}
default:
@@ -230,248 +199,122 @@ struct Memory::Impl {
page_index++;
page_offset = 0;
- dest_buffer = static_cast<u8*>(dest_buffer) + copy_amount;
+ increment(copy_amount);
remaining_size -= copy_amount;
}
}
- void ReadBlockUnsafe(const Kernel::KProcess& process, const VAddr src_addr, void* dest_buffer,
- const std::size_t size) {
- const auto& page_table = process.PageTable().PageTableImpl();
-
- std::size_t remaining_size = size;
- std::size_t page_index = src_addr >> PAGE_BITS;
- std::size_t page_offset = src_addr & PAGE_MASK;
-
- while (remaining_size > 0) {
- const std::size_t copy_amount =
- std::min(static_cast<std::size_t>(PAGE_SIZE) - page_offset, remaining_size);
- const auto current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
-
- const auto [pointer, type] = page_table.pointers[page_index].PointerType();
- switch (type) {
- case Common::PageType::Unmapped: {
+ template <bool UNSAFE>
+ void ReadBlockImpl(const Kernel::KProcess& process, const VAddr src_addr, void* dest_buffer,
+ const std::size_t size) {
+ WalkBlock(
+ process, src_addr, size,
+ [src_addr, size, &dest_buffer](const std::size_t copy_amount,
+ const VAddr current_vaddr) {
LOG_ERROR(HW_Memory,
"Unmapped ReadBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
current_vaddr, src_addr, size);
std::memset(dest_buffer, 0, copy_amount);
- break;
- }
- case Common::PageType::Memory: {
- DEBUG_ASSERT(pointer);
- const u8* const src_ptr = pointer + page_offset + (page_index << PAGE_BITS);
+ },
+ [&dest_buffer](const std::size_t copy_amount, const u8* const src_ptr) {
std::memcpy(dest_buffer, src_ptr, copy_amount);
- break;
- }
- case Common::PageType::RasterizerCachedMemory: {
- const u8* const host_ptr{GetPointerFromRasterizerCachedMemory(current_vaddr)};
+ },
+ [&system = system, &dest_buffer](const VAddr current_vaddr,
+ const std::size_t copy_amount,
+ const u8* const host_ptr) {
+ if constexpr (!UNSAFE) {
+ system.GPU().FlushRegion(current_vaddr, copy_amount);
+ }
std::memcpy(dest_buffer, host_ptr, copy_amount);
- break;
- }
- default:
- UNREACHABLE();
- }
-
- page_index++;
- page_offset = 0;
- dest_buffer = static_cast<u8*>(dest_buffer) + copy_amount;
- remaining_size -= copy_amount;
- }
+ },
+ [&dest_buffer](const std::size_t copy_amount) {
+ dest_buffer = static_cast<u8*>(dest_buffer) + copy_amount;
+ });
}
void ReadBlock(const VAddr src_addr, void* dest_buffer, const std::size_t size) {
- ReadBlock(*system.CurrentProcess(), src_addr, dest_buffer, size);
+ ReadBlockImpl<false>(*system.CurrentProcess(), src_addr, dest_buffer, size);
}
void ReadBlockUnsafe(const VAddr src_addr, void* dest_buffer, const std::size_t size) {
- ReadBlockUnsafe(*system.CurrentProcess(), src_addr, dest_buffer, size);
+ ReadBlockImpl<true>(*system.CurrentProcess(), src_addr, dest_buffer, size);
}
- void WriteBlock(const Kernel::KProcess& process, const VAddr dest_addr, const void* src_buffer,
- const std::size_t size) {
- const auto& page_table = process.PageTable().PageTableImpl();
- std::size_t remaining_size = size;
- std::size_t page_index = dest_addr >> PAGE_BITS;
- std::size_t page_offset = dest_addr & PAGE_MASK;
-
- while (remaining_size > 0) {
- const std::size_t copy_amount =
- std::min(static_cast<std::size_t>(PAGE_SIZE) - page_offset, remaining_size);
- const auto current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
-
- const auto [pointer, type] = page_table.pointers[page_index].PointerType();
- switch (type) {
- case Common::PageType::Unmapped: {
+ template <bool UNSAFE>
+ void WriteBlockImpl(const Kernel::KProcess& process, const VAddr dest_addr,
+ const void* src_buffer, const std::size_t size) {
+ WalkBlock(
+ process, dest_addr, size,
+ [dest_addr, size](const std::size_t copy_amount, const VAddr current_vaddr) {
LOG_ERROR(HW_Memory,
"Unmapped WriteBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
current_vaddr, dest_addr, size);
- break;
- }
- case Common::PageType::Memory: {
- DEBUG_ASSERT(pointer);
- u8* const dest_ptr = pointer + page_offset + (page_index << PAGE_BITS);
+ },
+ [&src_buffer](const std::size_t copy_amount, u8* const dest_ptr) {
std::memcpy(dest_ptr, src_buffer, copy_amount);
- break;
- }
- case Common::PageType::RasterizerCachedMemory: {
- u8* const host_ptr{GetPointerFromRasterizerCachedMemory(current_vaddr)};
- system.GPU().InvalidateRegion(current_vaddr, copy_amount);
- std::memcpy(host_ptr, src_buffer, copy_amount);
- break;
- }
- default:
- UNREACHABLE();
- }
-
- page_index++;
- page_offset = 0;
- src_buffer = static_cast<const u8*>(src_buffer) + copy_amount;
- remaining_size -= copy_amount;
- }
- }
-
- void WriteBlockUnsafe(const Kernel::KProcess& process, const VAddr dest_addr,
- const void* src_buffer, const std::size_t size) {
- const auto& page_table = process.PageTable().PageTableImpl();
- std::size_t remaining_size = size;
- std::size_t page_index = dest_addr >> PAGE_BITS;
- std::size_t page_offset = dest_addr & PAGE_MASK;
-
- while (remaining_size > 0) {
- const std::size_t copy_amount =
- std::min(static_cast<std::size_t>(PAGE_SIZE) - page_offset, remaining_size);
- const auto current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
-
- const auto [pointer, type] = page_table.pointers[page_index].PointerType();
- switch (type) {
- case Common::PageType::Unmapped: {
- LOG_ERROR(HW_Memory,
- "Unmapped WriteBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
- current_vaddr, dest_addr, size);
- break;
- }
- case Common::PageType::Memory: {
- DEBUG_ASSERT(pointer);
- u8* const dest_ptr = pointer + page_offset + (page_index << PAGE_BITS);
- std::memcpy(dest_ptr, src_buffer, copy_amount);
- break;
- }
- case Common::PageType::RasterizerCachedMemory: {
- u8* const host_ptr{GetPointerFromRasterizerCachedMemory(current_vaddr)};
+ },
+ [&system = system, &src_buffer](const VAddr current_vaddr,
+ const std::size_t copy_amount, u8* const host_ptr) {
+ if constexpr (!UNSAFE) {
+ system.GPU().InvalidateRegion(current_vaddr, copy_amount);
+ }
std::memcpy(host_ptr, src_buffer, copy_amount);
- break;
- }
- default:
- UNREACHABLE();
- }
-
- page_index++;
- page_offset = 0;
- src_buffer = static_cast<const u8*>(src_buffer) + copy_amount;
- remaining_size -= copy_amount;
- }
+ },
+ [&src_buffer](const std::size_t copy_amount) {
+ src_buffer = static_cast<const u8*>(src_buffer) + copy_amount;
+ });
}
void WriteBlock(const VAddr dest_addr, const void* src_buffer, const std::size_t size) {
- WriteBlock(*system.CurrentProcess(), dest_addr, src_buffer, size);
+ WriteBlockImpl<false>(*system.CurrentProcess(), dest_addr, src_buffer, size);
}
void WriteBlockUnsafe(const VAddr dest_addr, const void* src_buffer, const std::size_t size) {
- WriteBlockUnsafe(*system.CurrentProcess(), dest_addr, src_buffer, size);
+ WriteBlockImpl<true>(*system.CurrentProcess(), dest_addr, src_buffer, size);
}
void ZeroBlock(const Kernel::KProcess& process, const VAddr dest_addr, const std::size_t size) {
- const auto& page_table = process.PageTable().PageTableImpl();
- std::size_t remaining_size = size;
- std::size_t page_index = dest_addr >> PAGE_BITS;
- std::size_t page_offset = dest_addr & PAGE_MASK;
-
- while (remaining_size > 0) {
- const std::size_t copy_amount =
- std::min(static_cast<std::size_t>(PAGE_SIZE) - page_offset, remaining_size);
- const auto current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
-
- const auto [pointer, type] = page_table.pointers[page_index].PointerType();
- switch (type) {
- case Common::PageType::Unmapped: {
+ WalkBlock(
+ process, dest_addr, size,
+ [dest_addr, size](const std::size_t copy_amount, const VAddr current_vaddr) {
LOG_ERROR(HW_Memory,
"Unmapped ZeroBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
current_vaddr, dest_addr, size);
- break;
- }
- case Common::PageType::Memory: {
- DEBUG_ASSERT(pointer);
- u8* const dest_ptr = pointer + page_offset + (page_index << PAGE_BITS);
+ },
+ [](const std::size_t copy_amount, u8* const dest_ptr) {
std::memset(dest_ptr, 0, copy_amount);
- break;
- }
- case Common::PageType::RasterizerCachedMemory: {
- u8* const host_ptr{GetPointerFromRasterizerCachedMemory(current_vaddr)};
+ },
+ [&system = system](const VAddr current_vaddr, const std::size_t copy_amount,
+ u8* const host_ptr) {
system.GPU().InvalidateRegion(current_vaddr, copy_amount);
std::memset(host_ptr, 0, copy_amount);
- break;
- }
- default:
- UNREACHABLE();
- }
-
- page_index++;
- page_offset = 0;
- remaining_size -= copy_amount;
- }
- }
-
- void ZeroBlock(const VAddr dest_addr, const std::size_t size) {
- ZeroBlock(*system.CurrentProcess(), dest_addr, size);
+ },
+ [](const std::size_t copy_amount) {});
}
void CopyBlock(const Kernel::KProcess& process, VAddr dest_addr, VAddr src_addr,
const std::size_t size) {
- const auto& page_table = process.PageTable().PageTableImpl();
- std::size_t remaining_size = size;
- std::size_t page_index = src_addr >> PAGE_BITS;
- std::size_t page_offset = src_addr & PAGE_MASK;
-
- while (remaining_size > 0) {
- const std::size_t copy_amount =
- std::min(static_cast<std::size_t>(PAGE_SIZE) - page_offset, remaining_size);
- const auto current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
-
- const auto [pointer, type] = page_table.pointers[page_index].PointerType();
- switch (type) {
- case Common::PageType::Unmapped: {
+ WalkBlock(
+ process, dest_addr, size,
+ [this, &process, &dest_addr, &src_addr, size](const std::size_t copy_amount,
+ const VAddr current_vaddr) {
LOG_ERROR(HW_Memory,
"Unmapped CopyBlock @ 0x{:016X} (start address = 0x{:016X}, size = {})",
current_vaddr, src_addr, size);
ZeroBlock(process, dest_addr, copy_amount);
- break;
- }
- case Common::PageType::Memory: {
- DEBUG_ASSERT(pointer);
- const u8* src_ptr = pointer + page_offset + (page_index << PAGE_BITS);
- WriteBlock(process, dest_addr, src_ptr, copy_amount);
- break;
- }
- case Common::PageType::RasterizerCachedMemory: {
- const u8* const host_ptr{GetPointerFromRasterizerCachedMemory(current_vaddr)};
+ },
+ [this, &process, &dest_addr](const std::size_t copy_amount, const u8* const src_ptr) {
+ WriteBlockImpl<false>(process, dest_addr, src_ptr, copy_amount);
+ },
+ [this, &system = system, &process, &dest_addr](
+ const VAddr current_vaddr, const std::size_t copy_amount, u8* const host_ptr) {
system.GPU().FlushRegion(current_vaddr, copy_amount);
- WriteBlock(process, dest_addr, host_ptr, copy_amount);
- break;
- }
- default:
- UNREACHABLE();
- }
-
- page_index++;
- page_offset = 0;
- dest_addr += static_cast<VAddr>(copy_amount);
- src_addr += static_cast<VAddr>(copy_amount);
- remaining_size -= copy_amount;
- }
- }
-
- void CopyBlock(VAddr dest_addr, VAddr src_addr, std::size_t size) {
- return CopyBlock(*system.CurrentProcess(), dest_addr, src_addr, size);
+ WriteBlockImpl<false>(process, dest_addr, host_ptr, copy_amount);
+ },
+ [&dest_addr, &src_addr](const std::size_t copy_amount) {
+ dest_addr += static_cast<VAddr>(copy_amount);
+ src_addr += static_cast<VAddr>(copy_amount);
+ });
}
void RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached) {
@@ -514,7 +357,7 @@ struct Memory::Impl {
} else {
// Switch page type to uncached if now uncached
switch (page_type) {
- case Common::PageType::Unmapped:
+ case Common::PageType::Unmapped: // NOLINT(bugprone-branch-clone)
// It is not necessary for a process to have this region mapped into its address
// space, for example, a system module need not have a VRAM mapping.
break;
@@ -597,52 +440,68 @@ struct Memory::Impl {
}
}
- /**
- * Reads a particular data type out of memory at the given virtual address.
- *
- * @param vaddr The virtual address to read the data type from.
- *
- * @tparam T The data type to read out of memory. This type *must* be
- * trivially copyable, otherwise the behavior of this function
- * is undefined.
- *
- * @returns The instance of T read from the specified virtual address.
- */
- template <typename T>
- T Read(VAddr vaddr) {
+ [[nodiscard]] u8* GetPointerImpl(VAddr vaddr, auto on_unmapped, auto on_rasterizer) const {
// AARCH64 masks the upper 16 bit of all memory accesses
vaddr &= 0xffffffffffffLL;
if (vaddr >= 1uLL << current_page_table->GetAddressSpaceBits()) {
- LOG_ERROR(HW_Memory, "Unmapped Read{} @ 0x{:08X}", sizeof(T) * 8, vaddr);
- return 0;
+ on_unmapped();
+ return nullptr;
}
// Avoid adding any extra logic to this fast-path block
const uintptr_t raw_pointer = current_page_table->pointers[vaddr >> PAGE_BITS].Raw();
- if (const u8* const pointer = Common::PageTable::PageInfo::ExtractPointer(raw_pointer)) {
- T value;
- std::memcpy(&value, &pointer[vaddr], sizeof(T));
- return value;
+ if (u8* const pointer = Common::PageTable::PageInfo::ExtractPointer(raw_pointer)) {
+ return &pointer[vaddr];
}
switch (Common::PageTable::PageInfo::ExtractType(raw_pointer)) {
case Common::PageType::Unmapped:
- LOG_ERROR(HW_Memory, "Unmapped Read{} @ 0x{:08X}", sizeof(T) * 8, vaddr);
- return 0;
+ on_unmapped();
+ return nullptr;
case Common::PageType::Memory:
- ASSERT_MSG(false, "Mapped memory page without a pointer @ {:016X}", vaddr);
- break;
+ ASSERT_MSG(false, "Mapped memory page without a pointer @ 0x{:016X}", vaddr);
+ return nullptr;
case Common::PageType::RasterizerCachedMemory: {
- const u8* const host_ptr{GetPointerFromRasterizerCachedMemory(vaddr)};
- system.GPU().FlushRegion(vaddr, sizeof(T));
- T value;
- std::memcpy(&value, host_ptr, sizeof(T));
- return value;
+ u8* const host_ptr{GetPointerFromRasterizerCachedMemory(vaddr)};
+ on_rasterizer();
+ return host_ptr;
}
default:
UNREACHABLE();
}
- return {};
+ return nullptr;
+ }
+
+ [[nodiscard]] u8* GetPointer(const VAddr vaddr) const {
+ return GetPointerImpl(
+ vaddr, [vaddr]() { LOG_ERROR(HW_Memory, "Unmapped GetPointer @ 0x{:016X}", vaddr); },
+ []() {});
+ }
+
+ /**
+ * Reads a particular data type out of memory at the given virtual address.
+ *
+ * @param vaddr The virtual address to read the data type from.
+ *
+ * @tparam T The data type to read out of memory. This type *must* be
+ * trivially copyable, otherwise the behavior of this function
+ * is undefined.
+ *
+ * @returns The instance of T read from the specified virtual address.
+ */
+ template <typename T>
+ T Read(VAddr vaddr) {
+ T result = 0;
+ const u8* const ptr = GetPointerImpl(
+ vaddr,
+ [vaddr]() {
+ LOG_ERROR(HW_Memory, "Unmapped Read{} @ 0x{:016X}", sizeof(T) * 8, vaddr);
+ },
+ [&system = system, vaddr]() { system.GPU().FlushRegion(vaddr, sizeof(T)); });
+ if (ptr) {
+ std::memcpy(&result, ptr, sizeof(T));
+ }
+ return result;
}
/**
@@ -656,110 +515,46 @@ struct Memory::Impl {
*/
template <typename T>
void Write(VAddr vaddr, const T data) {
- // AARCH64 masks the upper 16 bit of all memory accesses
- vaddr &= 0xffffffffffffLL;
-
- if (vaddr >= 1uLL << current_page_table->GetAddressSpaceBits()) {
- LOG_ERROR(HW_Memory, "Unmapped Write{} 0x{:08X} @ 0x{:016X}", sizeof(data) * 8,
- static_cast<u32>(data), vaddr);
- return;
- }
-
- // Avoid adding any extra logic to this fast-path block
- const uintptr_t raw_pointer = current_page_table->pointers[vaddr >> PAGE_BITS].Raw();
- if (u8* const pointer = Common::PageTable::PageInfo::ExtractPointer(raw_pointer)) {
- std::memcpy(&pointer[vaddr], &data, sizeof(T));
- return;
- }
- switch (Common::PageTable::PageInfo::ExtractType(raw_pointer)) {
- case Common::PageType::Unmapped:
- LOG_ERROR(HW_Memory, "Unmapped Write{} 0x{:08X} @ 0x{:016X}", sizeof(data) * 8,
- static_cast<u32>(data), vaddr);
- return;
- case Common::PageType::Memory:
- ASSERT_MSG(false, "Mapped memory page without a pointer @ {:016X}", vaddr);
- break;
- case Common::PageType::RasterizerCachedMemory: {
- u8* const host_ptr{GetPointerFromRasterizerCachedMemory(vaddr)};
- system.GPU().InvalidateRegion(vaddr, sizeof(T));
- std::memcpy(host_ptr, &data, sizeof(T));
- break;
- }
- default:
- UNREACHABLE();
+ u8* const ptr = GetPointerImpl(
+ vaddr,
+ [vaddr, data]() {
+ LOG_ERROR(HW_Memory, "Unmapped Write{} @ 0x{:016X} = 0x{:016X}", sizeof(T) * 8,
+ vaddr, static_cast<u64>(data));
+ },
+ [&system = system, vaddr]() { system.GPU().InvalidateRegion(vaddr, sizeof(T)); });
+ if (ptr) {
+ std::memcpy(ptr, &data, sizeof(T));
}
}
template <typename T>
bool WriteExclusive(VAddr vaddr, const T data, const T expected) {
- // AARCH64 masks the upper 16 bit of all memory accesses
- vaddr &= 0xffffffffffffLL;
-
- if (vaddr >= 1uLL << current_page_table->GetAddressSpaceBits()) {
- LOG_ERROR(HW_Memory, "Unmapped Write{} 0x{:08X} @ 0x{:016X}", sizeof(data) * 8,
- static_cast<u32>(data), vaddr);
- return true;
- }
-
- const uintptr_t raw_pointer = current_page_table->pointers[vaddr >> PAGE_BITS].Raw();
- if (u8* const pointer = Common::PageTable::PageInfo::ExtractPointer(raw_pointer)) {
- // NOTE: Avoid adding any extra logic to this fast-path block
- const auto volatile_pointer = reinterpret_cast<volatile T*>(&pointer[vaddr]);
+ u8* const ptr = GetPointerImpl(
+ vaddr,
+ [vaddr, data]() {
+ LOG_ERROR(HW_Memory, "Unmapped WriteExclusive{} @ 0x{:016X} = 0x{:016X}",
+ sizeof(T) * 8, vaddr, static_cast<u64>(data));
+ },
+ [&system = system, vaddr]() { system.GPU().InvalidateRegion(vaddr, sizeof(T)); });
+ if (ptr) {
+ const auto volatile_pointer = reinterpret_cast<volatile T*>(ptr);
return Common::AtomicCompareAndSwap(volatile_pointer, data, expected);
}
- switch (Common::PageTable::PageInfo::ExtractType(raw_pointer)) {
- case Common::PageType::Unmapped:
- LOG_ERROR(HW_Memory, "Unmapped Write{} 0x{:08X} @ 0x{:016X}", sizeof(data) * 8,
- static_cast<u32>(data), vaddr);
- return true;
- case Common::PageType::Memory:
- ASSERT_MSG(false, "Mapped memory page without a pointer @ {:016X}", vaddr);
- break;
- case Common::PageType::RasterizerCachedMemory: {
- u8* host_ptr{GetPointerFromRasterizerCachedMemory(vaddr)};
- system.GPU().InvalidateRegion(vaddr, sizeof(T));
- auto* pointer = reinterpret_cast<volatile T*>(&host_ptr);
- return Common::AtomicCompareAndSwap(pointer, data, expected);
- }
- default:
- UNREACHABLE();
- }
return true;
}
bool WriteExclusive128(VAddr vaddr, const u128 data, const u128 expected) {
- // AARCH64 masks the upper 16 bit of all memory accesses
- vaddr &= 0xffffffffffffLL;
-
- if (vaddr >= 1uLL << current_page_table->GetAddressSpaceBits()) {
- LOG_ERROR(HW_Memory, "Unmapped Write{} 0x{:08X} @ 0x{:016X}", sizeof(data) * 8,
- static_cast<u32>(data[0]), vaddr);
- return true;
- }
-
- const uintptr_t raw_pointer = current_page_table->pointers[vaddr >> PAGE_BITS].Raw();
- if (u8* const pointer = Common::PageTable::PageInfo::ExtractPointer(raw_pointer)) {
- // NOTE: Avoid adding any extra logic to this fast-path block
- const auto volatile_pointer = reinterpret_cast<volatile u64*>(&pointer[vaddr]);
+ u8* const ptr = GetPointerImpl(
+ vaddr,
+ [vaddr, data]() {
+ LOG_ERROR(HW_Memory, "Unmapped WriteExclusive128 @ 0x{:016X} = 0x{:016X}{:016X}",
+ vaddr, static_cast<u64>(data[1]), static_cast<u64>(data[0]));
+ },
+ [&system = system, vaddr]() { system.GPU().InvalidateRegion(vaddr, sizeof(u128)); });
+ if (ptr) {
+ const auto volatile_pointer = reinterpret_cast<volatile u64*>(ptr);
return Common::AtomicCompareAndSwap(volatile_pointer, data, expected);
}
- switch (Common::PageTable::PageInfo::ExtractType(raw_pointer)) {
- case Common::PageType::Unmapped:
- LOG_ERROR(HW_Memory, "Unmapped Write{} 0x{:08X} @ 0x{:016X}{:016X}", sizeof(data) * 8,
- static_cast<u64>(data[1]), static_cast<u64>(data[0]), vaddr);
- return true;
- case Common::PageType::Memory:
- ASSERT_MSG(false, "Mapped memory page without a pointer @ {:016X}", vaddr);
- break;
- case Common::PageType::RasterizerCachedMemory: {
- u8* host_ptr{GetPointerFromRasterizerCachedMemory(vaddr)};
- system.GPU().InvalidateRegion(vaddr, sizeof(u128));
- auto* pointer = reinterpret_cast<volatile u64*>(&host_ptr);
- return Common::AtomicCompareAndSwap(pointer, data, expected);
- }
- default:
- UNREACHABLE();
- }
return true;
}
@@ -789,12 +584,11 @@ void Memory::UnmapRegion(Common::PageTable& page_table, VAddr base, u64 size) {
impl->UnmapRegion(page_table, base, size);
}
-bool Memory::IsValidVirtualAddress(const Kernel::KProcess& process, const VAddr vaddr) const {
- return impl->IsValidVirtualAddress(process, vaddr);
-}
-
bool Memory::IsValidVirtualAddress(const VAddr vaddr) const {
- return impl->IsValidVirtualAddress(vaddr);
+ const Kernel::KProcess& process = *system.CurrentProcess();
+ const auto& page_table = process.PageTable().PageTableImpl();
+ const auto [pointer, type] = page_table.pointers[vaddr >> PAGE_BITS].PointerType();
+ return pointer != nullptr || type == Common::PageType::RasterizerCachedMemory;
}
u8* Memory::GetPointer(VAddr vaddr) {
@@ -863,64 +657,38 @@ std::string Memory::ReadCString(VAddr vaddr, std::size_t max_length) {
void Memory::ReadBlock(const Kernel::KProcess& process, const VAddr src_addr, void* dest_buffer,
const std::size_t size) {
- impl->ReadBlock(process, src_addr, dest_buffer, size);
+ impl->ReadBlockImpl<false>(process, src_addr, dest_buffer, size);
}
void Memory::ReadBlock(const VAddr src_addr, void* dest_buffer, const std::size_t size) {
impl->ReadBlock(src_addr, dest_buffer, size);
}
-void Memory::ReadBlockUnsafe(const Kernel::KProcess& process, const VAddr src_addr,
- void* dest_buffer, const std::size_t size) {
- impl->ReadBlockUnsafe(process, src_addr, dest_buffer, size);
-}
-
void Memory::ReadBlockUnsafe(const VAddr src_addr, void* dest_buffer, const std::size_t size) {
impl->ReadBlockUnsafe(src_addr, dest_buffer, size);
}
void Memory::WriteBlock(const Kernel::KProcess& process, VAddr dest_addr, const void* src_buffer,
std::size_t size) {
- impl->WriteBlock(process, dest_addr, src_buffer, size);
+ impl->WriteBlockImpl<false>(process, dest_addr, src_buffer, size);
}
void Memory::WriteBlock(const VAddr dest_addr, const void* src_buffer, const std::size_t size) {
impl->WriteBlock(dest_addr, src_buffer, size);
}
-void Memory::WriteBlockUnsafe(const Kernel::KProcess& process, VAddr dest_addr,
- const void* src_buffer, std::size_t size) {
- impl->WriteBlockUnsafe(process, dest_addr, src_buffer, size);
-}
-
void Memory::WriteBlockUnsafe(const VAddr dest_addr, const void* src_buffer,
const std::size_t size) {
impl->WriteBlockUnsafe(dest_addr, src_buffer, size);
}
-void Memory::ZeroBlock(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size) {
- impl->ZeroBlock(process, dest_addr, size);
-}
-
-void Memory::ZeroBlock(VAddr dest_addr, std::size_t size) {
- impl->ZeroBlock(dest_addr, size);
-}
-
void Memory::CopyBlock(const Kernel::KProcess& process, VAddr dest_addr, VAddr src_addr,
const std::size_t size) {
impl->CopyBlock(process, dest_addr, src_addr, size);
}
-void Memory::CopyBlock(VAddr dest_addr, VAddr src_addr, std::size_t size) {
- impl->CopyBlock(dest_addr, src_addr, size);
-}
-
void Memory::RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached) {
impl->RasterizerMarkRegionCached(vaddr, size, cached);
}
-bool IsKernelVirtualAddress(const VAddr vaddr) {
- return KERNEL_REGION_VADDR <= vaddr && vaddr < KERNEL_REGION_END;
-}
-
} // namespace Core::Memory
diff --git a/src/core/memory.h b/src/core/memory.h
index c91eeced9..b5721b740 100644
--- a/src/core/memory.h
+++ b/src/core/memory.h
@@ -39,11 +39,6 @@ enum : VAddr {
/// Application stack
DEFAULT_STACK_SIZE = 0x100000,
-
- /// Kernel Virtual Address Range
- KERNEL_REGION_VADDR = 0xFFFFFF8000000000,
- KERNEL_REGION_SIZE = 0x7FFFE00000,
- KERNEL_REGION_END = KERNEL_REGION_VADDR + KERNEL_REGION_SIZE,
};
/// Central class that handles all memory operations and state.
@@ -56,7 +51,7 @@ public:
Memory& operator=(const Memory&) = delete;
Memory(Memory&&) = default;
- Memory& operator=(Memory&&) = default;
+ Memory& operator=(Memory&&) = delete;
/**
* Resets the state of the Memory system.
@@ -92,24 +87,13 @@ public:
/**
* Checks whether or not the supplied address is a valid virtual
- * address for the given process.
- *
- * @param process The emulated process to check the address against.
- * @param vaddr The virtual address to check the validity of.
- *
- * @returns True if the given virtual address is valid, false otherwise.
- */
- bool IsValidVirtualAddress(const Kernel::KProcess& process, VAddr vaddr) const;
-
- /**
- * Checks whether or not the supplied address is a valid virtual
* address for the current process.
*
* @param vaddr The virtual address to check the validity of.
*
* @returns True if the given virtual address is valid, false otherwise.
*/
- bool IsValidVirtualAddress(VAddr vaddr) const;
+ [[nodiscard]] bool IsValidVirtualAddress(VAddr vaddr) const;
/**
* Gets a pointer to the given address.
@@ -134,7 +118,7 @@ public:
* @returns The pointer to the given address, if the address is valid.
* If the address is not valid, nullptr will be returned.
*/
- const u8* GetPointer(VAddr vaddr) const;
+ [[nodiscard]] const u8* GetPointer(VAddr vaddr) const;
template <typename T>
const T* GetPointer(VAddr vaddr) const {
@@ -328,27 +312,6 @@ public:
std::size_t size);
/**
- * Reads a contiguous block of bytes from a specified process' address space.
- * This unsafe version does not trigger GPU flushing.
- *
- * @param process The process to read the data from.
- * @param src_addr The virtual address to begin reading from.
- * @param dest_buffer The buffer to place the read bytes into.
- * @param size The amount of data to read, in bytes.
- *
- * @note If a size of 0 is specified, then this function reads nothing and
- * no attempts to access memory are made at all.
- *
- * @pre dest_buffer must be at least size bytes in length, otherwise a
- * buffer overrun will occur.
- *
- * @post The range [dest_buffer, size) contains the read bytes from the
- * process' address space.
- */
- void ReadBlockUnsafe(const Kernel::KProcess& process, VAddr src_addr, void* dest_buffer,
- std::size_t size);
-
- /**
* Reads a contiguous block of bytes from the current process' address space.
*
* @param src_addr The virtual address to begin reading from.
@@ -409,26 +372,6 @@ public:
std::size_t size);
/**
- * Writes a range of bytes into a given process' address space at the specified
- * virtual address.
- * This unsafe version does not invalidate GPU Memory.
- *
- * @param process The process to write data into the address space of.
- * @param dest_addr The destination virtual address to begin writing the data at.
- * @param src_buffer The data to write into the process' address space.
- * @param size The size of the data to write, in bytes.
- *
- * @post The address range [dest_addr, size) in the process' address space
- * contains the data that was within src_buffer.
- *
- * @post If an attempt is made to write into an unmapped region of memory, the writes
- * will be ignored and an error will be logged.
- *
- */
- void WriteBlockUnsafe(const Kernel::KProcess& process, VAddr dest_addr, const void* src_buffer,
- std::size_t size);
-
- /**
* Writes a range of bytes into the current process' address space at the specified
* virtual address.
*
@@ -468,29 +411,6 @@ public:
void WriteBlockUnsafe(VAddr dest_addr, const void* src_buffer, std::size_t size);
/**
- * Fills the specified address range within a process' address space with zeroes.
- *
- * @param process The process that will have a portion of its memory zeroed out.
- * @param dest_addr The starting virtual address of the range to zero out.
- * @param size The size of the address range to zero out, in bytes.
- *
- * @post The range [dest_addr, size) within the process' address space is
- * filled with zeroes.
- */
- void ZeroBlock(const Kernel::KProcess& process, VAddr dest_addr, std::size_t size);
-
- /**
- * Fills the specified address range within the current process' address space with zeroes.
- *
- * @param dest_addr The starting virtual address of the range to zero out.
- * @param size The size of the address range to zero out, in bytes.
- *
- * @post The range [dest_addr, size) within the current process' address space is
- * filled with zeroes.
- */
- void ZeroBlock(VAddr dest_addr, std::size_t size);
-
- /**
* Copies data within a process' address space to another location within the
* same address space.
*
@@ -506,19 +426,6 @@ public:
std::size_t size);
/**
- * Copies data within the current process' address space to another location within the
- * same address space.
- *
- * @param dest_addr The destination virtual address to begin copying the data into.
- * @param src_addr The source virtual address to begin copying the data from.
- * @param size The size of the data to copy, in bytes.
- *
- * @post The range [dest_addr, size) within the current process' address space
- * contains the same data within the range [src_addr, size).
- */
- void CopyBlock(VAddr dest_addr, VAddr src_addr, std::size_t size);
-
- /**
* Marks each page within the specified address range as cached or uncached.
*
* @param vaddr The virtual address indicating the start of the address range.
@@ -535,7 +442,4 @@ private:
std::unique_ptr<Impl> impl;
};
-/// Determines if the given VAddr is a kernel address
-bool IsKernelVirtualAddress(VAddr vaddr);
-
} // namespace Core::Memory
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index 8de3d4520..ff23230f0 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -304,10 +304,10 @@ std::vector<std::unique_ptr<Polling::DevicePoller>> InputSubsystem::GetPollers([
}
std::string GenerateKeyboardParam(int key_code) {
- Common::ParamPackage param{
- {"engine", "keyboard"},
- {"code", std::to_string(key_code)},
- };
+ Common::ParamPackage param;
+ param.Set("engine", "keyboard");
+ param.Set("code", key_code);
+ param.Set("toggle", false);
return param.Serialize();
}
diff --git a/src/input_common/mouse/mouse_poller.cpp b/src/input_common/mouse/mouse_poller.cpp
index efcdd85d2..090b26972 100644
--- a/src/input_common/mouse/mouse_poller.cpp
+++ b/src/input_common/mouse/mouse_poller.cpp
@@ -57,6 +57,7 @@ Common::ParamPackage MouseButtonFactory::GetNextInput() const {
if (pad.button != MouseInput::MouseButton::Undefined) {
params.Set("engine", "mouse");
params.Set("button", static_cast<u16>(pad.button));
+ params.Set("toggle", false);
return params;
}
}
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp
index 70a0ba09c..f1f950d8a 100644
--- a/src/input_common/sdl/sdl_impl.cpp
+++ b/src/input_common/sdl/sdl_impl.cpp
@@ -82,6 +82,12 @@ public:
state.buttons.insert_or_assign(button, value);
}
+ void PreSetButton(int button) {
+ if (!state.buttons.contains(button)) {
+ SetButton(button, false);
+ }
+ }
+
void SetMotion(SDL_ControllerSensorEvent event) {
constexpr float gravity_constant = 9.80665f;
std::lock_guard lock{mutex};
@@ -155,9 +161,16 @@ public:
state.axes.insert_or_assign(axis, value);
}
- float GetAxis(int axis, float range) const {
+ void PreSetAxis(int axis) {
+ if (!state.axes.contains(axis)) {
+ SetAxis(axis, 0);
+ }
+ }
+
+ float GetAxis(int axis, float range, float offset) const {
std::lock_guard lock{mutex};
- return static_cast<float>(state.axes.at(axis)) / (32767.0f * range);
+ const float value = static_cast<float>(state.axes.at(axis)) / 32767.0f;
+ return (value + offset) / range;
}
bool RumblePlay(u16 amp_low, u16 amp_high) {
@@ -174,9 +187,10 @@ public:
return false;
}
- std::tuple<float, float> GetAnalog(int axis_x, int axis_y, float range) const {
- float x = GetAxis(axis_x, range);
- float y = GetAxis(axis_y, range);
+ std::tuple<float, float> GetAnalog(int axis_x, int axis_y, float range, float offset_x,
+ float offset_y) const {
+ float x = GetAxis(axis_x, range, offset_x);
+ float y = GetAxis(axis_y, range, offset_y);
y = -y; // 3DS uses an y-axis inverse from SDL
// Make sure the coordinates are in the unit circle,
@@ -483,7 +497,7 @@ public:
trigger_if_greater(trigger_if_greater_) {}
bool GetStatus() const override {
- const float axis_value = joystick->GetAxis(axis, 1.0f);
+ const float axis_value = joystick->GetAxis(axis, 1.0f, 0.0f);
if (trigger_if_greater) {
return axis_value > threshold;
}
@@ -500,12 +514,14 @@ private:
class SDLAnalog final : public Input::AnalogDevice {
public:
explicit SDLAnalog(std::shared_ptr<SDLJoystick> joystick_, int axis_x_, int axis_y_,
- bool invert_x_, bool invert_y_, float deadzone_, float range_)
+ bool invert_x_, bool invert_y_, float deadzone_, float range_,
+ float offset_x_, float offset_y_)
: joystick(std::move(joystick_)), axis_x(axis_x_), axis_y(axis_y_), invert_x(invert_x_),
- invert_y(invert_y_), deadzone(deadzone_), range(range_) {}
+ invert_y(invert_y_), deadzone(deadzone_), range(range_), offset_x(offset_x_),
+ offset_y(offset_y_) {}
std::tuple<float, float> GetStatus() const override {
- auto [x, y] = joystick->GetAnalog(axis_x, axis_y, range);
+ auto [x, y] = joystick->GetAnalog(axis_x, axis_y, range, offset_x, offset_y);
const float r = std::sqrt((x * x) + (y * y));
if (invert_x) {
x = -x;
@@ -522,8 +538,8 @@ public:
}
std::tuple<float, float> GetRawStatus() const override {
- const float x = joystick->GetAxis(axis_x, range);
- const float y = joystick->GetAxis(axis_y, range);
+ const float x = joystick->GetAxis(axis_x, range, offset_x);
+ const float y = joystick->GetAxis(axis_y, range, offset_y);
return {x, -y};
}
@@ -555,6 +571,8 @@ private:
const bool invert_y;
const float deadzone;
const float range;
+ const float offset_x;
+ const float offset_y;
};
class SDLVibration final : public Input::VibrationDevice {
@@ -621,7 +639,7 @@ public:
trigger_if_greater(trigger_if_greater_) {}
Input::MotionStatus GetStatus() const override {
- const float axis_value = joystick->GetAxis(axis, 1.0f);
+ const float axis_value = joystick->GetAxis(axis, 1.0f, 0.0f);
bool trigger = axis_value < threshold;
if (trigger_if_greater) {
trigger = axis_value > threshold;
@@ -720,13 +738,13 @@ public:
LOG_ERROR(Input, "Unknown direction {}", direction_name);
}
// This is necessary so accessing GetAxis with axis won't crash
- joystick->SetAxis(axis, 0);
+ joystick->PreSetAxis(axis);
return std::make_unique<SDLAxisButton>(joystick, axis, threshold, trigger_if_greater);
}
const int button = params.Get("button", 0);
// This is necessary so accessing GetButton with button won't crash
- joystick->SetButton(button, false);
+ joystick->PreSetButton(button);
return std::make_unique<SDLButton>(joystick, button, toggle);
}
@@ -757,13 +775,15 @@ public:
const std::string invert_y_value = params.Get("invert_y", "+");
const bool invert_x = invert_x_value == "-";
const bool invert_y = invert_y_value == "-";
+ const float offset_x = params.Get("offset_x", 0.0f);
+ const float offset_y = params.Get("offset_y", 0.0f);
auto joystick = state.GetSDLJoystickByGUID(guid, port);
// This is necessary so accessing GetAxis with axis_x and axis_y won't crash
- joystick->SetAxis(axis_x, 0);
- joystick->SetAxis(axis_y, 0);
+ joystick->PreSetAxis(axis_x);
+ joystick->PreSetAxis(axis_y);
return std::make_unique<SDLAnalog>(joystick, axis_x, axis_y, invert_x, invert_y, deadzone,
- range);
+ range, offset_x, offset_y);
}
private:
@@ -844,13 +864,13 @@ public:
LOG_ERROR(Input, "Unknown direction {}", direction_name);
}
// This is necessary so accessing GetAxis with axis won't crash
- joystick->SetAxis(axis, 0);
+ joystick->PreSetAxis(axis);
return std::make_unique<SDLAxisMotion>(joystick, axis, threshold, trigger_if_greater);
}
const int button = params.Get("button", 0);
// This is necessary so accessing GetButton with button won't crash
- joystick->SetButton(button, false);
+ joystick->PreSetButton(button);
return std::make_unique<SDLButtonMotion>(joystick, button);
}
@@ -995,6 +1015,7 @@ Common::ParamPackage BuildButtonParamPackageForButton(int port, std::string guid
params.Set("port", port);
params.Set("guid", std::move(guid));
params.Set("button", button);
+ params.Set("toggle", false);
return params;
}
@@ -1134,13 +1155,15 @@ Common::ParamPackage BuildParamPackageForBinding(int port, const std::string& gu
}
Common::ParamPackage BuildParamPackageForAnalog(int port, const std::string& guid, int axis_x,
- int axis_y) {
+ int axis_y, float offset_x, float offset_y) {
Common::ParamPackage params;
params.Set("engine", "sdl");
params.Set("port", port);
params.Set("guid", guid);
params.Set("axis_x", axis_x);
params.Set("axis_y", axis_y);
+ params.Set("offset_x", offset_x);
+ params.Set("offset_y", offset_y);
params.Set("invert_x", "+");
params.Set("invert_y", "+");
return params;
@@ -1342,24 +1365,39 @@ AnalogMapping SDLState::GetAnalogMappingForDevice(const Common::ParamPackage& pa
const auto& binding_left_y =
SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTY);
if (params.Has("guid2")) {
+ joystick2->PreSetAxis(binding_left_x.value.axis);
+ joystick2->PreSetAxis(binding_left_y.value.axis);
+ const auto left_offset_x = -joystick2->GetAxis(binding_left_x.value.axis, 1.0f, 0);
+ const auto left_offset_y = -joystick2->GetAxis(binding_left_y.value.axis, 1.0f, 0);
mapping.insert_or_assign(
Settings::NativeAnalog::LStick,
BuildParamPackageForAnalog(joystick2->GetPort(), joystick2->GetGUID(),
- binding_left_x.value.axis, binding_left_y.value.axis));
+ binding_left_x.value.axis, binding_left_y.value.axis,
+ left_offset_x, left_offset_y));
} else {
+ joystick->PreSetAxis(binding_left_x.value.axis);
+ joystick->PreSetAxis(binding_left_y.value.axis);
+ const auto left_offset_x = -joystick->GetAxis(binding_left_x.value.axis, 1.0f, 0);
+ const auto left_offset_y = -joystick->GetAxis(binding_left_y.value.axis, 1.0f, 0);
mapping.insert_or_assign(
Settings::NativeAnalog::LStick,
BuildParamPackageForAnalog(joystick->GetPort(), joystick->GetGUID(),
- binding_left_x.value.axis, binding_left_y.value.axis));
+ binding_left_x.value.axis, binding_left_y.value.axis,
+ left_offset_x, left_offset_y));
}
const auto& binding_right_x =
SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTX);
const auto& binding_right_y =
SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTY);
+ joystick->PreSetAxis(binding_right_x.value.axis);
+ joystick->PreSetAxis(binding_right_y.value.axis);
+ const auto right_offset_x = -joystick->GetAxis(binding_right_x.value.axis, 1.0f, 0);
+ const auto right_offset_y = -joystick->GetAxis(binding_right_y.value.axis, 1.0f, 0);
mapping.insert_or_assign(Settings::NativeAnalog::RStick,
BuildParamPackageForAnalog(joystick->GetPort(), joystick->GetGUID(),
binding_right_x.value.axis,
- binding_right_y.value.axis));
+ binding_right_y.value.axis, right_offset_x,
+ right_offset_y));
return mapping;
}
@@ -1563,8 +1601,9 @@ public:
}
if (const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which)) {
+ // Set offset to zero since the joystick is not on center
auto params = BuildParamPackageForAnalog(joystick->GetPort(), joystick->GetGUID(),
- first_axis, axis);
+ first_axis, axis, 0, 0);
first_axis = -1;
return params;
}
diff --git a/src/video_core/command_classes/codecs/vp9.cpp b/src/video_core/command_classes/codecs/vp9.cpp
index 7eecb3991..70030066a 100644
--- a/src/video_core/command_classes/codecs/vp9.cpp
+++ b/src/video_core/command_classes/codecs/vp9.cpp
@@ -397,14 +397,14 @@ Vp9FrameContainer VP9::GetCurrentFrame(const NvdecCommon::NvdecRegisters& state)
next_frame = std::move(temp);
} else {
next_frame.info = current_frame.info;
- next_frame.bit_stream = std::move(current_frame.bit_stream);
+ next_frame.bit_stream = current_frame.bit_stream;
}
return current_frame;
}
std::vector<u8> VP9::ComposeCompressedHeader() {
VpxRangeEncoder writer{};
- const bool update_probs = current_frame_info.show_frame && !current_frame_info.is_key_frame;
+ const bool update_probs = !current_frame_info.is_key_frame && current_frame_info.show_frame;
if (!current_frame_info.lossless) {
if (static_cast<u32>(current_frame_info.transform_mode) >= 3) {
writer.Write(3, 2);
diff --git a/src/video_core/command_classes/codecs/vp9_types.h b/src/video_core/command_classes/codecs/vp9_types.h
index 6820afa26..87eafdb03 100644
--- a/src/video_core/command_classes/codecs/vp9_types.h
+++ b/src/video_core/command_classes/codecs/vp9_types.h
@@ -176,7 +176,7 @@ struct PictureInfo {
.frame_size_changed = (vp9_flags & FrameFlags::FrameSizeChanged) != 0,
.error_resilient_mode = (vp9_flags & FrameFlags::ErrorResilientMode) != 0,
.last_frame_shown = (vp9_flags & FrameFlags::LastShowFrame) != 0,
- .show_frame = false,
+ .show_frame = true,
.ref_frame_sign_bias = ref_frame_sign_bias,
.base_q_index = base_q_index,
.y_dc_delta_q = y_dc_delta_q,
diff --git a/src/video_core/vulkan_common/vulkan_memory_allocator.cpp b/src/video_core/vulkan_common/vulkan_memory_allocator.cpp
index aa173d19e..300a61205 100644
--- a/src/video_core/vulkan_common/vulkan_memory_allocator.cpp
+++ b/src/video_core/vulkan_common/vulkan_memory_allocator.cpp
@@ -228,7 +228,9 @@ void MemoryCommit::Release() {
MemoryAllocator::MemoryAllocator(const Device& device_, bool export_allocations_)
: device{device_}, properties{device_.GetPhysical().GetMemoryProperties()},
- export_allocations{export_allocations_} {}
+ export_allocations{export_allocations_},
+ buffer_image_granularity{
+ device_.GetPhysical().GetProperties().limits.bufferImageGranularity} {}
MemoryAllocator::~MemoryAllocator() = default;
@@ -258,7 +260,9 @@ MemoryCommit MemoryAllocator::Commit(const vk::Buffer& buffer, MemoryUsage usage
}
MemoryCommit MemoryAllocator::Commit(const vk::Image& image, MemoryUsage usage) {
- auto commit = Commit(device.GetLogical().GetImageMemoryRequirements(*image), usage);
+ VkMemoryRequirements requirements = device.GetLogical().GetImageMemoryRequirements(*image);
+ requirements.size = Common::AlignUp(requirements.size, buffer_image_granularity);
+ auto commit = Commit(requirements, usage);
image.BindMemory(commit.Memory(), commit.Offset());
return commit;
}
diff --git a/src/video_core/vulkan_common/vulkan_memory_allocator.h b/src/video_core/vulkan_common/vulkan_memory_allocator.h
index b61e931e0..86e8ed119 100644
--- a/src/video_core/vulkan_common/vulkan_memory_allocator.h
+++ b/src/video_core/vulkan_common/vulkan_memory_allocator.h
@@ -123,6 +123,8 @@ private:
const VkPhysicalDeviceMemoryProperties properties; ///< Physical device properties.
const bool export_allocations; ///< True when memory allocations have to be exported.
std::vector<std::unique_ptr<MemoryAllocation>> allocations; ///< Current allocations.
+ VkDeviceSize buffer_image_granularity; // The granularity for adjacent offsets between buffers
+ // and optimal images
};
/// Returns true when a memory usage is guaranteed to be host visible.
diff --git a/src/yuzu/configuration/configure_general.ui b/src/yuzu/configuration/configure_general.ui
index 8ce97edec..69b6c2d66 100644
--- a/src/yuzu/configuration/configure_general.ui
+++ b/src/yuzu/configuration/configure_general.ui
@@ -25,6 +25,36 @@
<item>
<layout class="QVBoxLayout" name="GeneralVerticalLayout">
<item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QLabel" name="fps_cap_label">
+ <property name="text">
+ <string>Framerate Cap</string>
+ </property>
+ <property name="toolTip">
+ <string>Requires the use of the FPS Limiter Toggle hotkey to take effect.</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="fps_cap">
+ <property name="suffix">
+ <string>x</string>
+ </property>
+ <property name="minimum">
+ <number>1</number>
+ </property>
+ <property name="maximum">
+ <number>1000</number>
+ </property>
+ <property name="value">
+ <number>500</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="toggle_speed_limit">
@@ -52,36 +82,6 @@
</layout>
</item>
<item>
- <layout class="QHBoxLayout" name="horizontalLayout_2">
- <item>
- <widget class="QLabel" name="fps_cap_label">
- <property name="text">
- <string>Framerate Cap</string>
- </property>
- <property name="toolTip">
- <string>Requires the use of the FPS Limiter Toggle hotkey to take effect.</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QSpinBox" name="fps_cap">
- <property name="suffix">
- <string>x</string>
- </property>
- <property name="minimum">
- <number>1</number>
- </property>
- <property name="maximum">
- <number>1000</number>
- </property>
- <property name="value">
- <number>500</number>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
<widget class="QCheckBox" name="use_multi_core">
<property name="text">
<string>Multicore CPU Emulation</string>
diff --git a/src/yuzu/configuration/configure_graphics_advanced.ui b/src/yuzu/configuration/configure_graphics_advanced.ui
index 379dc5d2e..4fe6b86ae 100644
--- a/src/yuzu/configuration/configure_graphics_advanced.ui
+++ b/src/yuzu/configuration/configure_graphics_advanced.ui
@@ -82,14 +82,17 @@
<string>Enables asynchronous shader compilation, which may reduce shader stutter. This feature is experimental.</string>
</property>
<property name="text">
- <string>Use asynchronous shader building</string>
+ <string>Use asynchronous shader building (hack)</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="use_fast_gpu_time">
+ <property name="toolTip">
+ <string>Enables Fast GPU Time. This option will force most games to run at their highest native resolution.</string>
+ </property>
<property name="text">
- <string>Use Fast GPU Time</string>
+ <string>Use Fast GPU Time (hack)</string>
</property>
</widget>
</item>
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp
index 6b9bd05f1..7527c068b 100644
--- a/src/yuzu/configuration/configure_input_player.cpp
+++ b/src/yuzu/configuration/configure_input_player.cpp
@@ -309,11 +309,14 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
buttons_param[button_id].Clear();
button_map[button_id]->setText(tr("[not set]"));
});
- context_menu.addAction(tr("Toggle button"), [&] {
- const bool toggle_value = !buttons_param[button_id].Get("toggle", false);
- buttons_param[button_id].Set("toggle", toggle_value);
- button_map[button_id]->setText(ButtonToText(buttons_param[button_id]));
- });
+ if (buttons_param[button_id].Has("toggle")) {
+ context_menu.addAction(tr("Toggle button"), [&] {
+ const bool toggle_value =
+ !buttons_param[button_id].Get("toggle", false);
+ buttons_param[button_id].Set("toggle", toggle_value);
+ button_map[button_id]->setText(ButtonToText(buttons_param[button_id]));
+ });
+ }
if (buttons_param[button_id].Has("threshold")) {
context_menu.addAction(tr("Set threshold"), [&] {
const int button_threshold = static_cast<int>(
diff --git a/src/yuzu_cmd/CMakeLists.txt b/src/yuzu_cmd/CMakeLists.txt
index e55a19649..74fc24972 100644
--- a/src/yuzu_cmd/CMakeLists.txt
+++ b/src/yuzu_cmd/CMakeLists.txt
@@ -1,5 +1,6 @@
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules)
+# Credits to Samantas5855 and others for this function.
function(create_resource file output filename)
# Read hex data from file
file(READ ${file} filedata HEX)
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
index c80f7791c..87fce0c23 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
@@ -232,6 +232,7 @@ void EmuWindow_SDL2::WaitEvent() {
}
}
+// Credits to Samantas5855 and others for this function.
void EmuWindow_SDL2::SetWindowIcon() {
SDL_RWops* const yuzu_icon_stream = SDL_RWFromConstMem((void*)yuzu_icon, yuzu_icon_size);
if (yuzu_icon_stream == nullptr) {