early-access version 3441

This commit is contained in:
pineappleEA 2023-03-08 06:16:07 +01:00
parent fcd34e75d7
commit 089cce35df
9 changed files with 44 additions and 18 deletions

View File

@ -1,7 +1,7 @@
yuzu emulator early access yuzu emulator early access
============= =============
This is the source code for early-access 3440. This is the source code for early-access 3441.
## Legal Notice ## Legal Notice

View File

@ -91,6 +91,7 @@ add_library(common STATIC
multi_level_page_table.h multi_level_page_table.h
nvidia_flags.cpp nvidia_flags.cpp
nvidia_flags.h nvidia_flags.h
overflow.h
page_table.cpp page_table.cpp
page_table.h page_table.h
param_package.cpp param_package.cpp

View File

@ -3,19 +3,21 @@
#pragma once #pragma once
#include <cstring> #include <version>
#include <type_traits>
#ifdef __cpp_lib_bit_cast
#include <bit>
#endif
namespace Common { namespace Common {
template <typename To, typename From> template <typename To, typename From>
[[nodiscard]] std::enable_if_t<sizeof(To) == sizeof(From) && std::is_trivially_copyable_v<From> && constexpr inline To BitCast(const From& from) {
std::is_trivially_copyable_v<To>, #ifdef __cpp_lib_bit_cast
To> return std::bit_cast<To>(from);
BitCast(const From& src) noexcept { #else
To dst; return __builtin_bit_cast(To, from);
std::memcpy(&dst, &src, sizeof(To)); #endif
return dst;
} }
} // namespace Common } // namespace Common

22
src/common/overflow.h Executable file
View File

@ -0,0 +1,22 @@
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <type_traits>
#include "bit_cast.h"
namespace Common {
template <typename T>
requires(std::is_integral_v<T> && std::is_signed_v<T>)
inline T WrappingAdd(T lhs, T rhs) {
using U = std::make_unsigned_t<T>;
U lhs_u = BitCast<U>(lhs);
U rhs_u = BitCast<U>(rhs);
return BitCast<T>(lhs_u + rhs_u);
}
} // namespace Common

View File

@ -44,11 +44,11 @@ const KAddressSpaceInfo& GetAddressSpaceInfo(size_t width, KAddressSpaceInfo::Ty
} // namespace } // namespace
uintptr_t KAddressSpaceInfo::GetAddressSpaceStart(size_t width, KAddressSpaceInfo::Type type) { std::size_t KAddressSpaceInfo::GetAddressSpaceStart(size_t width, KAddressSpaceInfo::Type type) {
return GetAddressSpaceInfo(width, type).address; return GetAddressSpaceInfo(width, type).address;
} }
size_t KAddressSpaceInfo::GetAddressSpaceSize(size_t width, KAddressSpaceInfo::Type type) { std::size_t KAddressSpaceInfo::GetAddressSpaceSize(size_t width, KAddressSpaceInfo::Type type) {
return GetAddressSpaceInfo(width, type).size; return GetAddressSpaceInfo(width, type).size;
} }

View File

@ -18,7 +18,7 @@ struct KAddressSpaceInfo final {
Count, Count,
}; };
static u64 GetAddressSpaceStart(std::size_t width, Type type); static std::size_t GetAddressSpaceStart(std::size_t width, Type type);
static std::size_t GetAddressSpaceSize(std::size_t width, Type type); static std::size_t GetAddressSpaceSize(std::size_t width, Type type);
const std::size_t bit_width{}; const std::size_t bit_width{};

View File

@ -21,9 +21,9 @@ public:
~KDeviceAddressSpace(); ~KDeviceAddressSpace();
Result Initialize(u64 address, u64 size); Result Initialize(u64 address, u64 size);
void Finalize(); void Finalize() override;
bool IsInitialized() const { bool IsInitialized() const override {
return m_is_initialized; return m_is_initialized;
} }
static void PostDestroy(uintptr_t arg) {} static void PostDestroy(uintptr_t arg) {}

View File

@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include "common/assert.h" #include "common/assert.h"
#include "common/overflow.h"
#include "core/core.h" #include "core/core.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/hle/kernel/k_resource_limit.h" #include "core/hle/kernel/k_resource_limit.h"
@ -104,7 +105,7 @@ bool KResourceLimit::Reserve(LimitableResource which, s64 value, s64 timeout) {
ASSERT(current_hints[index] <= current_values[index]); ASSERT(current_hints[index] <= current_values[index]);
// If we would overflow, don't allow to succeed. // If we would overflow, don't allow to succeed.
if (current_values[index] + value <= current_values[index]) { if (Common::WrappingAdd(current_values[index], value) <= current_values[index]) {
break; break;
} }

View File

@ -238,7 +238,7 @@ private:
return indices; return indices;
} }
void MakeAndUpdateIndices(u8* staging_data, size_t quad_size, u32 quad, u32 first) { void MakeAndUpdateIndices(u8* staging_data, size_t quad_size, u32 quad, u32 first) override {
switch (index_type) { switch (index_type) {
case VK_INDEX_TYPE_UINT8_EXT: case VK_INDEX_TYPE_UINT8_EXT:
std::memcpy(staging_data, MakeIndices<u8>(quad, first).data(), quad_size); std::memcpy(staging_data, MakeIndices<u8>(quad, first).data(), quad_size);
@ -278,7 +278,7 @@ private:
return indices; return indices;
} }
void MakeAndUpdateIndices(u8* staging_data, size_t quad_size, u32 quad, u32 first) { void MakeAndUpdateIndices(u8* staging_data, size_t quad_size, u32 quad, u32 first) override {
switch (index_type) { switch (index_type) {
case VK_INDEX_TYPE_UINT8_EXT: case VK_INDEX_TYPE_UINT8_EXT:
std::memcpy(staging_data, MakeIndices<u8>(quad, first).data(), quad_size); std::memcpy(staging_data, MakeIndices<u8>(quad, first).data(), quad_size);