mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-08-23 16:06:30 +00:00
Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6cb9e3a9da | |||
| 7e1fc154c7 | |||
| 828220977b | |||
| 0684757788 | |||
| 30c44934e7 | |||
| 81efd5f1d1 | |||
| c51b9fed0f | |||
| 5157251457 | |||
| 71b9d8d3df | |||
| b6959029ca | |||
| 81aaf67c97 | |||
| 9289f5f55a | |||
| b38556d4f6 | |||
| 1616d19279 | |||
| 40756bbc52 | |||
| 424eb62cdb | |||
| e755504ed8 | |||
| b5d82311f6 | |||
| 6b65b2b6fc | |||
| 7fcdd9c9e4 | |||
| df681d1bd2 | |||
| bee168c5fa | |||
| d754fef20e | |||
| 0408db7adb | |||
| ead7505d00 | |||
| 65568e320d | |||
| 4154787b51 | |||
| 6f3e1b4471 | |||
| 240b65d61e | |||
| 461fa8ab6e | |||
| 0ef8acd602 | |||
| dbf5ee4e1f | |||
| e248832967 | |||
| 17167a27dc | |||
| a4bcb4a1e1 | |||
| b9ec214553 | |||
| 43b28d3731 |
@@ -65,7 +65,7 @@ android {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "dev.eden.eden_emulator"
|
applicationId = "dev.eden.eden_emulator"
|
||||||
minSdk = 24
|
minSdk = 33
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionName = getGitVersion()
|
versionName = getGitVersion()
|
||||||
versionCode = autoVersion
|
versionCode = autoVersion
|
||||||
|
|||||||
+1
-1
@@ -594,7 +594,7 @@ abstract class SettingsItem(
|
|||||||
IntSetting.ANDROID_PIPELINE_WORKERS,
|
IntSetting.ANDROID_PIPELINE_WORKERS,
|
||||||
titleId = R.string.pipeline_worker_cores,
|
titleId = R.string.pipeline_worker_cores,
|
||||||
descriptionId = R.string.pipeline_worker_cores_description,
|
descriptionId = R.string.pipeline_worker_cores_description,
|
||||||
min = 4,
|
min = 2,
|
||||||
max = 8,
|
max = 8,
|
||||||
units = "cores"
|
units = "cores"
|
||||||
)
|
)
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
|
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
|
||||||
@@ -169,7 +169,7 @@ class InputDialogFragment : DialogFragment() {
|
|||||||
NativeInput.onGamePadButtonEvent(
|
NativeInput.onGamePadButtonEvent(
|
||||||
controllerData.getGUID(),
|
controllerData.getGUID(),
|
||||||
controllerData.getPort(),
|
controllerData.getPort(),
|
||||||
InputHandler.getButtonIdFromEvent(event),
|
event.keyCode,
|
||||||
action
|
action
|
||||||
)
|
)
|
||||||
onInputReceived(event.device)
|
onInputReceived(event.device)
|
||||||
|
|||||||
@@ -49,12 +49,6 @@ object InputHandler {
|
|||||||
MotionEvent.AXIS_RTRIGGER
|
MotionEvent.AXIS_RTRIGGER
|
||||||
)
|
)
|
||||||
|
|
||||||
// Currently, Android doesn't support Joy-Con D-pad buttons. We fall back to the scan code
|
|
||||||
private const val LINUX_BUTTON_DPAD_UP = 0x220
|
|
||||||
private const val LINUX_BUTTON_DPAD_DOWN = 0x221
|
|
||||||
private const val LINUX_BUTTON_DPAD_LEFT = 0x222
|
|
||||||
private const val LINUX_BUTTON_DPAD_RIGHT = 0x223
|
|
||||||
|
|
||||||
fun isPhysicalGameController(device: InputDevice?): Boolean {
|
fun isPhysicalGameController(device: InputDevice?): Boolean {
|
||||||
device ?: return false
|
device ?: return false
|
||||||
|
|
||||||
@@ -93,25 +87,12 @@ object InputHandler {
|
|||||||
NativeInput.onGamePadButtonEvent(
|
NativeInput.onGamePadButtonEvent(
|
||||||
controllerData.getGUID(),
|
controllerData.getGUID(),
|
||||||
controllerData.getPort(),
|
controllerData.getPort(),
|
||||||
getButtonIdFromEvent(event),
|
event.keyCode,
|
||||||
action
|
action
|
||||||
)
|
)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getButtonIdFromEvent(event: KeyEvent): Int {
|
|
||||||
if (event.keyCode == 0) {
|
|
||||||
return when (event.scanCode) {
|
|
||||||
LINUX_BUTTON_DPAD_UP -> KeyEvent.KEYCODE_DPAD_UP
|
|
||||||
LINUX_BUTTON_DPAD_DOWN -> KeyEvent.KEYCODE_DPAD_DOWN
|
|
||||||
LINUX_BUTTON_DPAD_LEFT -> KeyEvent.KEYCODE_DPAD_LEFT
|
|
||||||
LINUX_BUTTON_DPAD_RIGHT -> KeyEvent.KEYCODE_DPAD_RIGHT
|
|
||||||
else -> return 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return event.keyCode
|
|
||||||
}
|
|
||||||
|
|
||||||
fun dispatchGenericMotionEvent(event: MotionEvent): Boolean {
|
fun dispatchGenericMotionEvent(event: MotionEvent): Boolean {
|
||||||
val controllerData =
|
val controllerData =
|
||||||
androidControllers[event.device.controllerNumber] ?: return false
|
androidControllers[event.device.controllerNumber] ?: return false
|
||||||
|
|||||||
+140
-21
@@ -1,5 +1,6 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: 2013 Dolphin Emulator Project
|
// SPDX-FileCopyrightText: 2013 Dolphin Emulator Project
|
||||||
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
|
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
@@ -39,6 +40,110 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __ANDROID__
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <fstream>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
[[maybe_unused]] constexpr int ANDROID_THREAD_PRIORITY_URGENT_AUDIO = -19;
|
||||||
|
[[maybe_unused]] constexpr int ANDROID_THREAD_PRIORITY_AUDIO = -16;
|
||||||
|
[[maybe_unused]] constexpr int ANDROID_THREAD_PRIORITY_URGENT_DISPLAY = -8;
|
||||||
|
[[maybe_unused]] constexpr int ANDROID_THREAD_PRIORITY_DISPLAY = -4;
|
||||||
|
[[maybe_unused]] constexpr int ANDROID_THREAD_PRIORITY_FOREGROUND = -2;
|
||||||
|
[[maybe_unused]] constexpr int ANDROID_THREAD_PRIORITY_MORE_FAVORABLE = -1;
|
||||||
|
[[maybe_unused]] constexpr int ANDROID_THREAD_PRIORITY_DEFAULT = 0;
|
||||||
|
[[maybe_unused]] constexpr int ANDROID_THREAD_PRIORITY_LESS_FAVORABLE = 1;
|
||||||
|
[[maybe_unused]] constexpr int ANDROID_THREAD_PRIORITY_BACKGROUND = 10;
|
||||||
|
[[maybe_unused]] constexpr int ANDROID_THREAD_PRIORITY_LOWEST = 19;
|
||||||
|
|
||||||
|
constexpr size_t ANDROID_MINIMUM_PERFORMANCE_CORES = 4;
|
||||||
|
|
||||||
|
cpu_set_t ComputePerformanceCoreMask() {
|
||||||
|
cpu_set_t mask;
|
||||||
|
CPU_ZERO(&mask);
|
||||||
|
|
||||||
|
cpu_set_t allowed;
|
||||||
|
CPU_ZERO(&allowed);
|
||||||
|
if (sched_getaffinity(gettid(), sizeof(allowed), &allowed) != 0) {
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::pair<long, int>> cores;
|
||||||
|
const int total = static_cast<int>(std::thread::hardware_concurrency());
|
||||||
|
for (int cpu = 0; cpu < total; ++cpu) {
|
||||||
|
if (!CPU_ISSET(cpu, &allowed)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
long max_frequency = 0;
|
||||||
|
std::ifstream file("/sys/devices/system/cpu/cpu" + std::to_string(cpu) +
|
||||||
|
"/cpufreq/cpuinfo_max_freq");
|
||||||
|
if (!file || !(file >> max_frequency) || max_frequency <= 0) {
|
||||||
|
CPU_ZERO(&mask);
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
cores.emplace_back(max_frequency, cpu);
|
||||||
|
}
|
||||||
|
if (cores.empty()) {
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(cores.begin(), cores.end(),
|
||||||
|
[](const auto& lhs, const auto& rhs) { return lhs.first > rhs.first; });
|
||||||
|
|
||||||
|
size_t taken = 0;
|
||||||
|
long cluster_frequency = cores.front().first;
|
||||||
|
for (const auto& [frequency, cpu] : cores) {
|
||||||
|
if (frequency != cluster_frequency) {
|
||||||
|
if (taken >= ANDROID_MINIMUM_PERFORMANCE_CORES) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cluster_frequency = frequency;
|
||||||
|
}
|
||||||
|
CPU_SET(cpu, &mask);
|
||||||
|
++taken;
|
||||||
|
}
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cpu_set_t& PerformanceCoreMask() {
|
||||||
|
static const cpu_set_t mask = ComputePerformanceCoreMask();
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu_set_t ComputeEfficiencyCoreMask() {
|
||||||
|
cpu_set_t mask;
|
||||||
|
CPU_ZERO(&mask);
|
||||||
|
|
||||||
|
const cpu_set_t& performance = PerformanceCoreMask();
|
||||||
|
if (CPU_COUNT(&performance) == 0) {
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu_set_t allowed;
|
||||||
|
CPU_ZERO(&allowed);
|
||||||
|
if (sched_getaffinity(gettid(), sizeof(allowed), &allowed) != 0) {
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int total = static_cast<int>(std::thread::hardware_concurrency());
|
||||||
|
for (int cpu = 0; cpu < total; ++cpu) {
|
||||||
|
if (CPU_ISSET(cpu, &allowed) && !CPU_ISSET(cpu, &performance)) {
|
||||||
|
CPU_SET(cpu, &mask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cpu_set_t& EfficiencyCoreMask() {
|
||||||
|
static const cpu_set_t mask = ComputeEfficiencyCoreMask();
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
} // Anonymous namespace
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "common/cpu_features.h"
|
#include "common/cpu_features.h"
|
||||||
#ifdef ARCHITECTURE_x86_64
|
#ifdef ARCHITECTURE_x86_64
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@@ -78,6 +183,21 @@ void SetCurrentThreadPriority(ThreadPriority new_priority) {
|
|||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
set_thread_priority(find_thread(NULL), priority);
|
set_thread_priority(find_thread(NULL), priority);
|
||||||
|
#elif defined(__ANDROID__)
|
||||||
|
const int nice_value = [&]() {
|
||||||
|
switch (new_priority) {
|
||||||
|
case ThreadPriority::Low: return ANDROID_THREAD_PRIORITY_BACKGROUND;
|
||||||
|
case ThreadPriority::Normal: return ANDROID_THREAD_PRIORITY_DEFAULT;
|
||||||
|
case ThreadPriority::High: return ANDROID_THREAD_PRIORITY_DISPLAY;
|
||||||
|
case ThreadPriority::VeryHigh: return ANDROID_THREAD_PRIORITY_URGENT_DISPLAY;
|
||||||
|
case ThreadPriority::Critical: return ANDROID_THREAD_PRIORITY_AUDIO;
|
||||||
|
default: return ANDROID_THREAD_PRIORITY_DEFAULT;
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
if (setpriority(PRIO_PROCESS, static_cast<id_t>(gettid()), nice_value) != 0) {
|
||||||
|
LOG_DEBUG(Common, "Could not set thread nice value to {}: {}", nice_value,
|
||||||
|
GetLastErrorMsg());
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
pthread_t this_thread = pthread_self();
|
pthread_t this_thread = pthread_self();
|
||||||
const auto scheduling_type = SCHED_OTHER;
|
const auto scheduling_type = SCHED_OTHER;
|
||||||
@@ -132,29 +252,28 @@ void SetCurrentThreadName(const char* name) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void PinCurrentThreadToPerformanceCore(size_t core_id) {
|
void SetCurrentThreadToPerformanceCores() {
|
||||||
ASSERT(core_id < 4);
|
|
||||||
// If we set a flag for a CPU that doesn't exist, the thread may not be allowed to
|
|
||||||
// run in ANY processor!
|
|
||||||
auto const total_cores = std::thread::hardware_concurrency();
|
|
||||||
if (core_id < total_cores) {
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
cpu_set_t set;
|
const cpu_set_t& mask = PerformanceCoreMask();
|
||||||
CPU_ZERO(&set);
|
if (CPU_COUNT(&mask) == 0) {
|
||||||
CPU_SET(core_id, &set);
|
return;
|
||||||
sched_setaffinity(pthread_self(), sizeof(set), &set);
|
|
||||||
#elif defined(__linux__) || defined(__FreeBSD__)
|
|
||||||
cpu_set_t set;
|
|
||||||
CPU_ZERO(&set);
|
|
||||||
CPU_SET(core_id, &set);
|
|
||||||
pthread_setaffinity_np(pthread_self(), sizeof(set), &set);
|
|
||||||
#elif defined(_WIN32)
|
|
||||||
DWORD set = 1UL << core_id;
|
|
||||||
SetThreadAffinityMask(GetCurrentThread(), set);
|
|
||||||
#else
|
|
||||||
// No pin functionality implemented
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
if (sched_setaffinity(gettid(), sizeof(mask), &mask) != 0) {
|
||||||
|
LOG_DEBUG(Common, "Could not restrict thread to performance cores: {}", GetLastErrorMsg());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetCurrentThreadToEfficiencyCores() {
|
||||||
|
#if defined(__ANDROID__)
|
||||||
|
const cpu_set_t& mask = EfficiencyCoreMask();
|
||||||
|
if (CPU_COUNT(&mask) == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (sched_setaffinity(gettid(), sizeof(mask), &mask) != 0) {
|
||||||
|
LOG_DEBUG(Common, "Could not restrict thread to efficiency cores: {}", GetLastErrorMsg());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ARCHITECTURE_x86_64
|
#ifdef ARCHITECTURE_x86_64
|
||||||
|
|||||||
+7
-1
@@ -99,8 +99,14 @@ enum class ThreadPriority : u32 {
|
|||||||
Critical = 4,
|
Critical = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class ThreadPlacement : u32 {
|
||||||
|
Default = 0,
|
||||||
|
Background = 1,
|
||||||
|
};
|
||||||
|
|
||||||
void SetCurrentThreadPriority(ThreadPriority new_priority);
|
void SetCurrentThreadPriority(ThreadPriority new_priority);
|
||||||
void SetCurrentThreadName(const char* name);
|
void SetCurrentThreadName(const char* name);
|
||||||
void PinCurrentThreadToPerformanceCore(size_t core_id);
|
void SetCurrentThreadToPerformanceCores();
|
||||||
|
void SetCurrentThreadToEfficiencyCores();
|
||||||
|
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
@@ -37,10 +37,15 @@ class StatefulThreadWorker {
|
|||||||
using StateMaker = std::conditional_t<with_state, std::function<StateType()>, DummyCallable>;
|
using StateMaker = std::conditional_t<with_state, std::function<StateType()>, DummyCallable>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit StatefulThreadWorker(size_t num_workers, std::string name, StateMaker func = {})
|
explicit StatefulThreadWorker(size_t num_workers, std::string name, StateMaker func = {},
|
||||||
|
ThreadPlacement placement = ThreadPlacement::Default)
|
||||||
: workers_queued{num_workers}, thread_name{std::move(name)} {
|
: workers_queued{num_workers}, thread_name{std::move(name)} {
|
||||||
const auto lambda = [this, func](std::stop_token stop_token) {
|
const auto lambda = [this, func, placement](std::stop_token stop_token) {
|
||||||
Common::SetCurrentThreadName(thread_name.c_str());
|
Common::SetCurrentThreadName(thread_name.c_str());
|
||||||
|
if (placement == ThreadPlacement::Background) {
|
||||||
|
Common::SetCurrentThreadPriority(ThreadPriority::Low);
|
||||||
|
Common::SetCurrentThreadToEfficiencyCores();
|
||||||
|
}
|
||||||
{
|
{
|
||||||
[[maybe_unused]] std::conditional_t<with_state, StateType, int> state{func()};
|
[[maybe_unused]] std::conditional_t<with_state, StateType, int> state{func()};
|
||||||
while (!stop_token.stop_requested()) {
|
while (!stop_token.stop_requested()) {
|
||||||
|
|||||||
@@ -174,12 +174,7 @@ void CpuManager::RunThread(std::stop_token token, std::size_t core) {
|
|||||||
std::string name = is_multicore ? ("CPUCore_" + std::to_string(core)) : std::string{"CPUThread"};
|
std::string name = is_multicore ? ("CPUCore_" + std::to_string(core)) : std::string{"CPUThread"};
|
||||||
Common::SetCurrentThreadName(name.c_str());
|
Common::SetCurrentThreadName(name.c_str());
|
||||||
Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);
|
Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);
|
||||||
#ifdef __ANDROID__
|
Common::SetCurrentThreadToPerformanceCores();
|
||||||
// Aimed specifically for Snapdragon 8 Elite devices
|
|
||||||
// This kills performance on desktop, but boosts perf for UMA devices
|
|
||||||
// like the S8E. Mediatek and Mali likely won't suffer.
|
|
||||||
Common::PinCurrentThreadToPerformanceCore(core);
|
|
||||||
#endif
|
|
||||||
auto& data = core_data[core];
|
auto& data = core_data[core];
|
||||||
data.host_context = Common::Fiber::ThreadToFiber();
|
data.host_context = Common::Fiber::ThreadToFiber();
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ add_library(video_core STATIC
|
|||||||
control/channel_state_cache.h
|
control/channel_state_cache.h
|
||||||
control/scheduler.cpp
|
control/scheduler.cpp
|
||||||
control/scheduler.h
|
control/scheduler.h
|
||||||
delayed_destruction_ring.h
|
deferred_destruction_queue.h
|
||||||
dirty_flags.cpp
|
dirty_flags.cpp
|
||||||
dirty_flags.h
|
dirty_flags.h
|
||||||
dma_pusher.cpp
|
dma_pusher.cpp
|
||||||
|
|||||||
@@ -31,44 +31,77 @@ BufferCache<P>::BufferCache(Tegra::MaxwellDeviceMemoryManager& device_memory_, R
|
|||||||
immediately_free = (Settings::values.vram_usage_mode.GetValue() == Settings::VramUsageMode::Aggressive);
|
immediately_free = (Settings::values.vram_usage_mode.GetValue() == Settings::VramUsageMode::Aggressive);
|
||||||
#endif
|
#endif
|
||||||
if (!runtime.CanReportMemoryUsage()) {
|
if (!runtime.CanReportMemoryUsage()) {
|
||||||
minimum_memory = DEFAULT_EXPECTED_MEMORY;
|
memory_budget = FALLBACK_MEMORY_BUDGET;
|
||||||
critical_memory = DEFAULT_CRITICAL_MEMORY;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const s64 device_local_memory = static_cast<s64>(runtime.GetDeviceLocalMemory());
|
memory_budget = runtime.GetDeviceLocalMemory();
|
||||||
const s64 min_spacing_expected = device_local_memory - 1_GiB;
|
|
||||||
const s64 min_spacing_critical = device_local_memory - 512_MiB;
|
|
||||||
const s64 mem_threshold = (std::min)(device_local_memory, TARGET_THRESHOLD);
|
|
||||||
const s64 min_vacancy_expected = (6 * mem_threshold) / 10;
|
|
||||||
const s64 min_vacancy_critical = (2 * mem_threshold) / 10;
|
|
||||||
minimum_memory = static_cast<u64>(
|
|
||||||
(std::max)((std::min)(device_local_memory - min_vacancy_expected, min_spacing_expected),
|
|
||||||
DEFAULT_EXPECTED_MEMORY));
|
|
||||||
critical_memory = static_cast<u64>(
|
|
||||||
(std::max)((std::min)(device_local_memory - min_vacancy_critical, min_spacing_critical),
|
|
||||||
DEFAULT_CRITICAL_MEMORY));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
BufferCache<P>::~BufferCache() = default;
|
BufferCache<P>::~BufferCache() = default;
|
||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
void BufferCache<P>::RunGarbageCollector() {
|
u64 BufferCache<P>::DeviceUsage(bool force_refresh) {
|
||||||
const bool aggressive_gc = total_used_memory >= critical_memory;
|
if (!runtime.CanReportAllocationUsage()) {
|
||||||
const u64 ticks_to_destroy = aggressive_gc ? 60 : 120;
|
return total_used_memory;
|
||||||
int num_iterations = aggressive_gc ? 64 : 32;
|
}
|
||||||
const auto clean_up = [this, &num_iterations](BufferId buffer_id) {
|
if (force_refresh || usage_refresh_countdown == 0) {
|
||||||
if (num_iterations == 0) {
|
cached_device_usage = runtime.GetDeviceAllocationUsage();
|
||||||
|
usage_refresh_countdown = USAGE_REFRESH_INTERVAL;
|
||||||
|
} else {
|
||||||
|
--usage_refresh_countdown;
|
||||||
|
}
|
||||||
|
return cached_device_usage;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class P>
|
||||||
|
u64 BufferCache<P>::ReclaimMemory(u64 target_bytes, bool allow_download) {
|
||||||
|
if (target_bytes == 0 || in_reclaim) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
in_reclaim = true;
|
||||||
|
sentenced_buffers.Reclaim(runtime.CompletedSyncPoint());
|
||||||
|
u64 freed = 0;
|
||||||
|
const auto clean_up = [&](BufferId buffer_id) {
|
||||||
|
if (freed >= target_bytes) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
--num_iterations;
|
|
||||||
auto& buffer = slot_buffers[buffer_id];
|
auto& buffer = slot_buffers[buffer_id];
|
||||||
|
if (!allow_download && IsRegionGpuModified(buffer.CpuAddr(), buffer.SizeBytes())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const u64 buffer_bytes = Common::AlignUp(buffer.SizeBytes(), 1024);
|
||||||
DownloadBufferMemory(buffer);
|
DownloadBufferMemory(buffer);
|
||||||
DeleteBuffer(buffer_id);
|
DeleteBuffer(buffer_id);
|
||||||
|
freed += buffer_bytes;
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, clean_up);
|
const u64 cold_tick =
|
||||||
|
frame_tick > RECLAIM_GUARD_FRAMES ? frame_tick - RECLAIM_GUARD_FRAMES : 0;
|
||||||
|
lru_cache.ForEachItemBelow(cold_tick, clean_up);
|
||||||
|
if (freed < target_bytes) {
|
||||||
|
lru_cache.ForEachItemBelow(frame_tick > 0 ? frame_tick - 1 : 0, clean_up);
|
||||||
|
}
|
||||||
|
sentenced_buffers.Reclaim(runtime.CompletedSyncPoint());
|
||||||
|
in_reclaim = false;
|
||||||
|
usage_refresh_countdown = 0;
|
||||||
|
reclaim_stalled = freed == 0;
|
||||||
|
return freed;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class P>
|
||||||
|
void BufferCache<P>::EnsureHeadroom(bool allow_download) {
|
||||||
|
if (reclaim_stalled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const u64 limit = memory_budget > RECLAIM_HEADROOM ? memory_budget - RECLAIM_HEADROOM : 0;
|
||||||
|
const u64 usage = DeviceUsage(false);
|
||||||
|
if (usage <= limit) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const u64 target = (limit / 100) * RECLAIM_TARGET_PERCENT;
|
||||||
|
ReclaimMemory((std::min)(usage - target, total_used_memory), allow_download);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
@@ -96,15 +129,11 @@ void BufferCache<P>::TickFrame() {
|
|||||||
const bool skip_preferred = hits * 256 < shots * 251;
|
const bool skip_preferred = hits * 256 < shots * 251;
|
||||||
channel_state->uniform_buffer_skip_cache_size = skip_preferred ? DEFAULT_SKIP_CACHE_SIZE : 0;
|
channel_state->uniform_buffer_skip_cache_size = skip_preferred ? DEFAULT_SKIP_CACHE_SIZE : 0;
|
||||||
|
|
||||||
// If we can obtain the memory info, use it instead of the estimate.
|
usage_refresh_countdown = 0;
|
||||||
if (runtime.CanReportMemoryUsage()) {
|
reclaim_stalled = false;
|
||||||
total_used_memory = runtime.GetDeviceMemoryUsage();
|
EnsureHeadroom(true);
|
||||||
}
|
|
||||||
if (total_used_memory >= minimum_memory) {
|
|
||||||
RunGarbageCollector();
|
|
||||||
}
|
|
||||||
++frame_tick;
|
++frame_tick;
|
||||||
delayed_destruction_ring.Tick();
|
sentenced_buffers.Reclaim(runtime.CompletedSyncPoint());
|
||||||
|
|
||||||
for (auto& buffer : async_buffers_death_ring) {
|
for (auto& buffer : async_buffers_death_ring) {
|
||||||
runtime.FreeDeferredStagingBuffer(buffer);
|
runtime.FreeDeferredStagingBuffer(buffer);
|
||||||
@@ -1576,6 +1605,7 @@ void BufferCache<P>::JoinOverlap(BufferId new_buffer_id, BufferId overlap_id,
|
|||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
BufferId BufferCache<P>::CreateBuffer(DAddr device_addr, u32 wanted_size) {
|
BufferId BufferCache<P>::CreateBuffer(DAddr device_addr, u32 wanted_size) {
|
||||||
|
EnsureHeadroom(false);
|
||||||
DAddr device_addr_end = Common::AlignUp(device_addr + wanted_size, CACHING_PAGESIZE);
|
DAddr device_addr_end = Common::AlignUp(device_addr + wanted_size, CACHING_PAGESIZE);
|
||||||
device_addr = Common::AlignDown(device_addr, CACHING_PAGESIZE);
|
device_addr = Common::AlignDown(device_addr, CACHING_PAGESIZE);
|
||||||
wanted_size = static_cast<u32>(device_addr_end - device_addr);
|
wanted_size = static_cast<u32>(device_addr_end - device_addr);
|
||||||
@@ -1613,7 +1643,7 @@ void BufferCache<P>::ChangeRegister(BufferId buffer_id) {
|
|||||||
total_used_memory += Common::AlignUp(size, 1024);
|
total_used_memory += Common::AlignUp(size, 1024);
|
||||||
buffer.setLRUID(lru_cache.Insert(buffer_id, frame_tick));
|
buffer.setLRUID(lru_cache.Insert(buffer_id, frame_tick));
|
||||||
} else {
|
} else {
|
||||||
total_used_memory -= Common::AlignUp(size, 1024);
|
total_used_memory -= std::min<u64>(total_used_memory, Common::AlignUp(size, 1024));
|
||||||
lru_cache.Free(buffer.getLRUID());
|
lru_cache.Free(buffer.getLRUID());
|
||||||
}
|
}
|
||||||
const DAddr device_addr_begin = buffer.CpuAddr();
|
const DAddr device_addr_begin = buffer.CpuAddr();
|
||||||
@@ -1872,7 +1902,7 @@ void BufferCache<P>::DeleteBuffer(BufferId buffer_id, bool do_not_mark) {
|
|||||||
#ifdef YUZU_LEGACY
|
#ifdef YUZU_LEGACY
|
||||||
if (!do_not_mark || !immediately_free)
|
if (!do_not_mark || !immediately_free)
|
||||||
#endif
|
#endif
|
||||||
delayed_destruction_ring.Push(std::move(slot_buffers[buffer_id]));
|
sentenced_buffers.Push(std::move(slot_buffers[buffer_id]), runtime.CurrentSyncPoint());
|
||||||
|
|
||||||
slot_buffers.erase(buffer_id);
|
slot_buffers.erase(buffer_id);
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <bit>
|
#include <bit>
|
||||||
|
#include <deque>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@@ -30,7 +31,7 @@
|
|||||||
#include "common/slot_vector.h"
|
#include "common/slot_vector.h"
|
||||||
#include "video_core/buffer_cache/buffer_base.h"
|
#include "video_core/buffer_cache/buffer_base.h"
|
||||||
#include "video_core/control/channel_state_cache.h"
|
#include "video_core/control/channel_state_cache.h"
|
||||||
#include "video_core/delayed_destruction_ring.h"
|
#include "video_core/deferred_destruction_queue.h"
|
||||||
#include "video_core/dirty_flags.h"
|
#include "video_core/dirty_flags.h"
|
||||||
#include "video_core/engines/maxwell_3d.h"
|
#include "video_core/engines/maxwell_3d.h"
|
||||||
#include "video_core/engines/kepler_compute.h"
|
#include "video_core/engines/kepler_compute.h"
|
||||||
@@ -182,13 +183,15 @@ class BufferCache : public VideoCommon::ChannelSetupCaches<BufferCacheChannelInf
|
|||||||
static constexpr bool USE_MEMORY_MAPS_FOR_UPLOADS = P::USE_MEMORY_MAPS_FOR_UPLOADS;
|
static constexpr bool USE_MEMORY_MAPS_FOR_UPLOADS = P::USE_MEMORY_MAPS_FOR_UPLOADS;
|
||||||
|
|
||||||
#ifdef YUZU_LEGACY
|
#ifdef YUZU_LEGACY
|
||||||
static constexpr s64 TARGET_THRESHOLD = 3_GiB;
|
static constexpr u64 RECLAIM_HEADROOM = 384_MiB;
|
||||||
#else
|
#else
|
||||||
static constexpr s64 TARGET_THRESHOLD = 4_GiB;
|
static constexpr u64 RECLAIM_HEADROOM = 512_MiB;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static constexpr s64 DEFAULT_EXPECTED_MEMORY = 512_MiB;
|
static constexpr u64 FALLBACK_MEMORY_BUDGET = 2_GiB;
|
||||||
static constexpr s64 DEFAULT_CRITICAL_MEMORY = 1_GiB;
|
static constexpr u32 USAGE_REFRESH_INTERVAL = 16;
|
||||||
|
static constexpr u64 RECLAIM_GUARD_FRAMES = 8;
|
||||||
|
static constexpr u64 RECLAIM_TARGET_PERCENT = 88;
|
||||||
|
|
||||||
// Debug Flags.
|
// Debug Flags.
|
||||||
|
|
||||||
@@ -215,6 +218,8 @@ public:
|
|||||||
|
|
||||||
void TickFrame();
|
void TickFrame();
|
||||||
|
|
||||||
|
u64 ReclaimMemory(u64 target_bytes, bool allow_download);
|
||||||
|
|
||||||
void WriteMemory(DAddr device_addr, u64 size);
|
void WriteMemory(DAddr device_addr, u64 size);
|
||||||
|
|
||||||
void CachedWriteMemory(DAddr device_addr, u64 size);
|
void CachedWriteMemory(DAddr device_addr, u64 size);
|
||||||
@@ -358,7 +363,9 @@ private:
|
|||||||
((device_addr + size) & ~Core::DEVICE_PAGEMASK);
|
((device_addr + size) & ~Core::DEVICE_PAGEMASK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunGarbageCollector();
|
u64 DeviceUsage(bool force_refresh);
|
||||||
|
|
||||||
|
void EnsureHeadroom(bool allow_download);
|
||||||
|
|
||||||
void BindHostIndexBuffer();
|
void BindHostIndexBuffer();
|
||||||
|
|
||||||
@@ -475,12 +482,7 @@ private:
|
|||||||
Tegra::MaxwellDeviceMemoryManager& device_memory;
|
Tegra::MaxwellDeviceMemoryManager& device_memory;
|
||||||
|
|
||||||
Common::SlotVector<Buffer> slot_buffers;
|
Common::SlotVector<Buffer> slot_buffers;
|
||||||
#ifdef YUZU_LEGACY
|
DeferredDestructionQueue<Buffer> sentenced_buffers;
|
||||||
static constexpr size_t TICKS_TO_DESTROY = 6;
|
|
||||||
#else
|
|
||||||
static constexpr size_t TICKS_TO_DESTROY = 8;
|
|
||||||
#endif
|
|
||||||
DelayedDestructionRing<Buffer, TICKS_TO_DESTROY> delayed_destruction_ring;
|
|
||||||
|
|
||||||
const Tegra::Engines::Maxwell3D::DrawManager::IndirectParams* current_draw_indirect{};
|
const Tegra::Engines::Maxwell3D::DrawManager::IndirectParams* current_draw_indirect{};
|
||||||
|
|
||||||
@@ -515,8 +517,11 @@ private:
|
|||||||
Common::LeastRecentlyUsedCache<LRUItemParams> lru_cache;
|
Common::LeastRecentlyUsedCache<LRUItemParams> lru_cache;
|
||||||
u64 frame_tick = 0;
|
u64 frame_tick = 0;
|
||||||
u64 total_used_memory = 0;
|
u64 total_used_memory = 0;
|
||||||
u64 minimum_memory = 0;
|
u64 memory_budget = 0;
|
||||||
u64 critical_memory = 0;
|
u64 cached_device_usage = 0;
|
||||||
|
u32 usage_refresh_countdown = 0;
|
||||||
|
bool in_reclaim = false;
|
||||||
|
bool reclaim_stalled = false;
|
||||||
BufferId inline_buffer_id;
|
BufferId inline_buffer_id;
|
||||||
#ifdef YUZU_LEGACY
|
#ifdef YUZU_LEGACY
|
||||||
bool immediately_free = false;
|
bool immediately_free = false;
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include <boost/container/deque.hpp>
|
||||||
|
#include <boost/container/options.hpp>
|
||||||
|
|
||||||
|
#include "common/common_types.h"
|
||||||
|
|
||||||
|
namespace VideoCommon {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class DeferredDestructionQueue {
|
||||||
|
public:
|
||||||
|
void Push(T&& object, u64 sync_point) {
|
||||||
|
entries.emplace_back(std::move(object), sync_point);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Reclaim(u64 completed_sync_point) {
|
||||||
|
while (!entries.empty() && entries.front().sync_point <= completed_sync_point) {
|
||||||
|
entries.pop_front();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clear() {
|
||||||
|
entries.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] size_t Size() const noexcept {
|
||||||
|
return entries.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool Empty() const noexcept {
|
||||||
|
return entries.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Entry {
|
||||||
|
Entry(T&& object_, u64 sync_point_) noexcept
|
||||||
|
: object{std::move(object_)}, sync_point{sync_point_} {}
|
||||||
|
|
||||||
|
T object;
|
||||||
|
u64 sync_point;
|
||||||
|
};
|
||||||
|
|
||||||
|
using EntryDequeOptions =
|
||||||
|
boost::container::deque_options<boost::container::block_size<8u>>::type;
|
||||||
|
|
||||||
|
boost::container::deque<Entry, void, EntryDequeOptions> entries;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace VideoCommon
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <cstddef>
|
|
||||||
#include <utility>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace VideoCommon {
|
|
||||||
|
|
||||||
/// Container to push objects to be destroyed a few ticks in the future
|
|
||||||
template <typename T, size_t TICKS_TO_DESTROY>
|
|
||||||
class DelayedDestructionRing {
|
|
||||||
public:
|
|
||||||
void Tick() {
|
|
||||||
index = (index + 1) % TICKS_TO_DESTROY;
|
|
||||||
elements[index].clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Push(T&& object) {
|
|
||||||
elements[index].push_back(std::move(object));
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
size_t index = 0;
|
|
||||||
std::array<std::vector<T>, TICKS_TO_DESTROY> elements;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace VideoCommon
|
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "common/thread.h"
|
#include "common/thread.h"
|
||||||
#include "video_core/delayed_destruction_ring.h"
|
#include "video_core/deferred_destruction_queue.h"
|
||||||
#include "video_core/gpu.h"
|
#include "video_core/gpu.h"
|
||||||
#include "video_core/host1x/host1x.h"
|
#include "video_core/host1x/host1x.h"
|
||||||
#include "video_core/host1x/syncpoint_manager.h"
|
#include "video_core/host1x/syncpoint_manager.h"
|
||||||
@@ -50,7 +50,8 @@ public:
|
|||||||
/// Notify the fence manager about a new frame
|
/// Notify the fence manager about a new frame
|
||||||
void TickFrame() {
|
void TickFrame() {
|
||||||
std::unique_lock lock(ring_guard);
|
std::unique_lock lock(ring_guard);
|
||||||
delayed_destruction_ring.Tick();
|
++retire_tick;
|
||||||
|
sentenced_fences.Reclaim(retire_tick > RETIRE_DELAY ? retire_tick - RETIRE_DELAY : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlike other fences, this one doesn't
|
// Unlike other fences, this one doesn't
|
||||||
@@ -186,7 +187,7 @@ private:
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::unique_lock lock(ring_guard);
|
std::unique_lock lock(ring_guard);
|
||||||
delayed_destruction_ring.Push(std::move(current_fence));
|
sentenced_fences.Push(std::move(current_fence), retire_tick);
|
||||||
}
|
}
|
||||||
fences.pop();
|
fences.pop();
|
||||||
}
|
}
|
||||||
@@ -219,7 +220,7 @@ private:
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::unique_lock lock(ring_guard);
|
std::unique_lock lock(ring_guard);
|
||||||
delayed_destruction_ring.Push(std::move(current_fence));
|
sentenced_fences.Push(std::move(current_fence), retire_tick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,7 +265,9 @@ private:
|
|||||||
|
|
||||||
std::jthread fence_thread;
|
std::jthread fence_thread;
|
||||||
|
|
||||||
DelayedDestructionRing<TFence, 8> delayed_destruction_ring;
|
static constexpr u64 RETIRE_DELAY = 8;
|
||||||
|
u64 retire_tick = 1;
|
||||||
|
DeferredDestructionQueue<TFence> sentenced_fences;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace VideoCommon
|
} // namespace VideoCommon
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ void ThreadManager::StartThread(VideoCore::RendererBase& renderer, Core::Fronten
|
|||||||
thread = std::jthread([&](std::stop_token stop_token) {
|
thread = std::jthread([&](std::stop_token stop_token) {
|
||||||
Common::SetCurrentThreadName("GPU");
|
Common::SetCurrentThreadName("GPU");
|
||||||
Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);
|
Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);
|
||||||
|
Common::SetCurrentThreadToPerformanceCores();
|
||||||
system.RegisterHostThread();
|
system.RegisterHostThread();
|
||||||
|
|
||||||
auto current_context = context.Acquire();
|
auto current_context = context.Acquire();
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ set(SHADER_FILES
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/convert_msaa_to_non_msaa.frag
|
${CMAKE_CURRENT_SOURCE_DIR}/convert_msaa_to_non_msaa.frag
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/convert_non_msaa_to_msaa.comp
|
${CMAKE_CURRENT_SOURCE_DIR}/convert_non_msaa_to_msaa.comp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/convert_non_msaa_to_msaa.frag
|
${CMAKE_CURRENT_SOURCE_DIR}/convert_non_msaa_to_msaa.frag
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/convert_non_msaa_to_msaa_depth.frag
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/convert_s8d24_to_abgr8.frag
|
${CMAKE_CURRENT_SOURCE_DIR}/convert_s8d24_to_abgr8.frag
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/full_screen_triangle.vert
|
${CMAKE_CURRENT_SOURCE_DIR}/full_screen_triangle.vert
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/fxaa.frag
|
${CMAKE_CURRENT_SOURCE_DIR}/fxaa.frag
|
||||||
|
|||||||
@@ -1384,11 +1384,7 @@ void DecompressBlock(ivec3 coord) {
|
|||||||
p = Cf / 65535.0f;
|
p = Cf / 65535.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VULKAN
|
|
||||||
imageStore(dest_image, coord + ivec3(i, j, 0), p.gbar);
|
|
||||||
#else
|
|
||||||
imageStore(dest_image, coord + ivec3(i, j, 0), clamp(p, 0.0f, 1.0f).gbar);
|
imageStore(dest_image, coord + ivec3(i, j, 0), clamp(p, 0.0f, 1.0f).gbar);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#version 450 core
|
||||||
|
|
||||||
|
layout(binding = 0) uniform sampler2D img_in;
|
||||||
|
|
||||||
|
layout(push_constant) uniform PushConstants {
|
||||||
|
ivec2 dst_offset;
|
||||||
|
ivec2 src_offset;
|
||||||
|
ivec2 scale;
|
||||||
|
};
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
const ivec2 msaa_coord = ivec2(gl_FragCoord.xy) - dst_offset;
|
||||||
|
const ivec2 sample_offset = ivec2(gl_SampleID % scale.x, gl_SampleID / scale.x);
|
||||||
|
const ivec2 coord = msaa_coord * scale + sample_offset + src_offset;
|
||||||
|
gl_FragDepth = texelFetch(img_in, coord, 0).r;
|
||||||
|
}
|
||||||
@@ -93,7 +93,17 @@ public:
|
|||||||
void PostCopyBarrier();
|
void PostCopyBarrier();
|
||||||
void Finish();
|
void Finish();
|
||||||
|
|
||||||
void TickFrame(Common::SlotVector<Buffer>&) noexcept {}
|
void TickFrame(Common::SlotVector<Buffer>&) noexcept {
|
||||||
|
++sync_point;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 CurrentSyncPoint() const noexcept {
|
||||||
|
return sync_point;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 CompletedSyncPoint() const noexcept {
|
||||||
|
return sync_point > SYNC_POINT_DELAY ? sync_point - SYNC_POINT_DELAY : 0;
|
||||||
|
}
|
||||||
|
|
||||||
void ClearBuffer(Buffer& dest_buffer, u32 offset, size_t size, u32 value);
|
void ClearBuffer(Buffer& dest_buffer, u32 offset, size_t size, u32 value);
|
||||||
|
|
||||||
@@ -128,6 +138,14 @@ public:
|
|||||||
|
|
||||||
u64 GetDeviceMemoryUsage() const;
|
u64 GetDeviceMemoryUsage() const;
|
||||||
|
|
||||||
|
u64 GetDeviceAllocationUsage() const {
|
||||||
|
return GetDeviceMemoryUsage();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CanReportAllocationUsage() const {
|
||||||
|
return device.CanReportMemoryUsage();
|
||||||
|
}
|
||||||
|
|
||||||
void BindFastUniformBuffer(size_t stage, u32 binding_index, u32 size) {
|
void BindFastUniformBuffer(size_t stage, u32 binding_index, u32 size) {
|
||||||
const GLuint handle = fast_uniforms[stage][binding_index].handle;
|
const GLuint handle = fast_uniforms[stage][binding_index].handle;
|
||||||
const GLsizeiptr gl_size = static_cast<GLsizeiptr>(size);
|
const GLsizeiptr gl_size = static_cast<GLsizeiptr>(size);
|
||||||
@@ -213,9 +231,13 @@ private:
|
|||||||
GL_FRAGMENT_PROGRAM_PARAMETER_BUFFER_NV,
|
GL_FRAGMENT_PROGRAM_PARAMETER_BUFFER_NV,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static constexpr u64 SYNC_POINT_DELAY = 8;
|
||||||
|
|
||||||
const Device& device;
|
const Device& device;
|
||||||
StagingBufferPool& staging_buffer_pool;
|
StagingBufferPool& staging_buffer_pool;
|
||||||
|
|
||||||
|
u64 sync_point = 1;
|
||||||
|
|
||||||
bool has_fast_buffer_sub_data = false;
|
bool has_fast_buffer_sub_data = false;
|
||||||
bool use_assembly_shaders = false;
|
bool use_assembly_shaders = false;
|
||||||
bool has_unified_vertex_buffers = false;
|
bool has_unified_vertex_buffers = false;
|
||||||
|
|||||||
@@ -87,6 +87,14 @@ public:
|
|||||||
|
|
||||||
u64 GetDeviceMemoryUsage() const;
|
u64 GetDeviceMemoryUsage() const;
|
||||||
|
|
||||||
|
u64 GetDeviceAllocationUsage() const {
|
||||||
|
return GetDeviceMemoryUsage();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CanReportAllocationUsage() const {
|
||||||
|
return device.CanReportMemoryUsage();
|
||||||
|
}
|
||||||
|
|
||||||
bool CanReportMemoryUsage() const {
|
bool CanReportMemoryUsage() const {
|
||||||
return device.CanReportMemoryUsage();
|
return device.CanReportMemoryUsage();
|
||||||
}
|
}
|
||||||
@@ -139,7 +147,19 @@ public:
|
|||||||
|
|
||||||
bool HasNativeASTC() const noexcept;
|
bool HasNativeASTC() const noexcept;
|
||||||
|
|
||||||
void TickFrame() {}
|
void TickFrame() {
|
||||||
|
++sync_point;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 CurrentSyncPoint() const noexcept {
|
||||||
|
return sync_point;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 CompletedSyncPoint() const noexcept {
|
||||||
|
return sync_point > SYNC_POINT_DELAY ? sync_point - SYNC_POINT_DELAY : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WaitSyncPoint(u64) {}
|
||||||
|
|
||||||
StateTracker& GetStateTracker() {
|
StateTracker& GetStateTracker() {
|
||||||
return state_tracker;
|
return state_tracker;
|
||||||
@@ -174,6 +194,9 @@ private:
|
|||||||
std::array<OGLFramebuffer, 4> rescale_read_fbos;
|
std::array<OGLFramebuffer, 4> rescale_read_fbos;
|
||||||
const Settings::ResolutionScalingInfo& resolution;
|
const Settings::ResolutionScalingInfo& resolution;
|
||||||
u64 device_access_memory;
|
u64 device_access_memory;
|
||||||
|
|
||||||
|
static constexpr u64 SYNC_POINT_DELAY = 8;
|
||||||
|
u64 sync_point = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Image : public VideoCommon::ImageBase {
|
class Image : public VideoCommon::ImageBase {
|
||||||
@@ -370,6 +393,7 @@ struct TextureCacheParams {
|
|||||||
static constexpr bool HAS_EMULATED_COPIES = true;
|
static constexpr bool HAS_EMULATED_COPIES = true;
|
||||||
static constexpr bool HAS_DEVICE_MEMORY_INFO = true;
|
static constexpr bool HAS_DEVICE_MEMORY_INFO = true;
|
||||||
static constexpr bool IMPLEMENTS_ASYNC_DOWNLOADS = true;
|
static constexpr bool IMPLEMENTS_ASYNC_DOWNLOADS = true;
|
||||||
|
static constexpr bool HAS_TIMELINE_SYNC_POINTS = false;
|
||||||
|
|
||||||
using Runtime = OpenGL::TextureCacheRuntime;
|
using Runtime = OpenGL::TextureCacheRuntime;
|
||||||
using Image = OpenGL::Image;
|
using Image = OpenGL::Image;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "video_core/host_shaders/convert_depth_to_float_frag_spv.h"
|
#include "video_core/host_shaders/convert_depth_to_float_frag_spv.h"
|
||||||
#include "video_core/host_shaders/convert_float_to_depth_frag_spv.h"
|
#include "video_core/host_shaders/convert_float_to_depth_frag_spv.h"
|
||||||
#include "video_core/host_shaders/convert_msaa_to_non_msaa_frag_spv.h"
|
#include "video_core/host_shaders/convert_msaa_to_non_msaa_frag_spv.h"
|
||||||
|
#include "video_core/host_shaders/convert_non_msaa_to_msaa_depth_frag_spv.h"
|
||||||
#include "video_core/host_shaders/convert_non_msaa_to_msaa_frag_spv.h"
|
#include "video_core/host_shaders/convert_non_msaa_to_msaa_frag_spv.h"
|
||||||
#include "video_core/host_shaders/convert_s8d24_to_abgr8_frag_spv.h"
|
#include "video_core/host_shaders/convert_s8d24_to_abgr8_frag_spv.h"
|
||||||
#include "video_core/host_shaders/full_screen_triangle_vert_spv.h"
|
#include "video_core/host_shaders/full_screen_triangle_vert_spv.h"
|
||||||
@@ -519,7 +520,8 @@ void RecordShaderReadBarrier(Scheduler& scheduler, const ImageView& image_view)
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] vk::ImageView MakeMSAACopyView(const vk::Device& device, VkImage image,
|
[[nodiscard]] vk::ImageView MakeMSAACopyView(const vk::Device& device, VkImage image,
|
||||||
VkFormat format, u32 base_level) {
|
VkFormat format, u32 base_level,
|
||||||
|
VkImageAspectFlags aspect_mask) {
|
||||||
return device.CreateImageView(VkImageViewCreateInfo{
|
return device.CreateImageView(VkImageViewCreateInfo{
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
@@ -534,7 +536,7 @@ void RecordShaderReadBarrier(Scheduler& scheduler, const ImageView& image_view)
|
|||||||
.a = VK_COMPONENT_SWIZZLE_IDENTITY,
|
.a = VK_COMPONENT_SWIZZLE_IDENTITY,
|
||||||
},
|
},
|
||||||
.subresourceRange{
|
.subresourceRange{
|
||||||
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
.aspectMask = aspect_mask,
|
||||||
.baseMipLevel = base_level,
|
.baseMipLevel = base_level,
|
||||||
.levelCount = 1,
|
.levelCount = 1,
|
||||||
.baseArrayLayer = 0,
|
.baseArrayLayer = 0,
|
||||||
@@ -610,6 +612,8 @@ BlitImageHelper::BlitImageHelper(const Device& device_, Scheduler& scheduler_,
|
|||||||
convert_s8d24_to_abgr8_frag(BuildShader(device, CONVERT_S8D24_TO_ABGR8_FRAG_SPV)),
|
convert_s8d24_to_abgr8_frag(BuildShader(device, CONVERT_S8D24_TO_ABGR8_FRAG_SPV)),
|
||||||
convert_msaa_to_non_msaa_frag(BuildShader(device, CONVERT_MSAA_TO_NON_MSAA_FRAG_SPV)),
|
convert_msaa_to_non_msaa_frag(BuildShader(device, CONVERT_MSAA_TO_NON_MSAA_FRAG_SPV)),
|
||||||
convert_non_msaa_to_msaa_frag(BuildShader(device, CONVERT_NON_MSAA_TO_MSAA_FRAG_SPV)),
|
convert_non_msaa_to_msaa_frag(BuildShader(device, CONVERT_NON_MSAA_TO_MSAA_FRAG_SPV)),
|
||||||
|
convert_non_msaa_to_msaa_depth_frag(
|
||||||
|
BuildShader(device, CONVERT_NON_MSAA_TO_MSAA_DEPTH_FRAG_SPV)),
|
||||||
linear_sampler(device.GetLogical().CreateSampler(SAMPLER_CREATE_INFO<VK_FILTER_LINEAR>)),
|
linear_sampler(device.GetLogical().CreateSampler(SAMPLER_CREATE_INFO<VK_FILTER_LINEAR>)),
|
||||||
nearest_sampler(device.GetLogical().CreateSampler(SAMPLER_CREATE_INFO<VK_FILTER_NEAREST>)) {}
|
nearest_sampler(device.GetLogical().CreateSampler(SAMPLER_CREATE_INFO<VK_FILTER_NEAREST>)) {}
|
||||||
|
|
||||||
@@ -895,16 +899,34 @@ void BlitImageHelper::CopyMSAA(RenderPassCache& render_pass_cache, VkImage dst_i
|
|||||||
const s32 scale_y = 1 << samples_y;
|
const s32 scale_y = 1 << samples_y;
|
||||||
const VkSampleCountFlagBits samples =
|
const VkSampleCountFlagBits samples =
|
||||||
msaa_to_non_msaa ? VK_SAMPLE_COUNT_1_BIT : SampleCountFlag(num_samples);
|
msaa_to_non_msaa ? VK_SAMPLE_COUNT_1_BIT : SampleCountFlag(num_samples);
|
||||||
|
const auto dst_surface_type = VideoCore::Surface::GetFormatType(dst_format);
|
||||||
|
const bool is_depth = dst_surface_type == VideoCore::Surface::SurfaceType::Depth ||
|
||||||
|
dst_surface_type == VideoCore::Surface::SurfaceType::DepthStencil;
|
||||||
|
const bool has_stencil = dst_surface_type == VideoCore::Surface::SurfaceType::DepthStencil;
|
||||||
|
const VkImageAspectFlags view_aspect =
|
||||||
|
is_depth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
|
VkImageAspectFlags barrier_aspect = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
|
if (is_depth) {
|
||||||
|
barrier_aspect = VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||||
|
if (has_stencil) {
|
||||||
|
barrier_aspect |= VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||||
|
}
|
||||||
|
}
|
||||||
RenderPassKey renderpass_key{};
|
RenderPassKey renderpass_key{};
|
||||||
renderpass_key.color_formats.fill(VideoCore::Surface::PixelFormat::Invalid);
|
renderpass_key.color_formats.fill(VideoCore::Surface::PixelFormat::Invalid);
|
||||||
renderpass_key.color_formats[0] = dst_format;
|
if (is_depth) {
|
||||||
renderpass_key.depth_format = VideoCore::Surface::PixelFormat::Invalid;
|
renderpass_key.depth_format = dst_format;
|
||||||
|
} else {
|
||||||
|
renderpass_key.color_formats[0] = dst_format;
|
||||||
|
renderpass_key.depth_format = VideoCore::Surface::PixelFormat::Invalid;
|
||||||
|
}
|
||||||
renderpass_key.samples = samples;
|
renderpass_key.samples = samples;
|
||||||
const VkRenderPass renderpass = render_pass_cache.Get(renderpass_key);
|
const VkRenderPass renderpass = render_pass_cache.Get(renderpass_key);
|
||||||
const MSAACopyPipelineKey key{
|
const MSAACopyPipelineKey key{
|
||||||
.renderpass = renderpass,
|
.renderpass = renderpass,
|
||||||
.samples = samples,
|
.samples = samples,
|
||||||
.msaa_to_non_msaa = msaa_to_non_msaa,
|
.msaa_to_non_msaa = msaa_to_non_msaa,
|
||||||
|
.is_depth = is_depth,
|
||||||
};
|
};
|
||||||
const VkPipeline pipeline = FindOrEmplaceMSAACopyPipeline(key);
|
const VkPipeline pipeline = FindOrEmplaceMSAACopyPipeline(key);
|
||||||
const VkPipelineLayout layout = *msaa_copy_pipeline_layout;
|
const VkPipelineLayout layout = *msaa_copy_pipeline_layout;
|
||||||
@@ -920,10 +942,10 @@ void BlitImageHelper::CopyMSAA(RenderPassCache& render_pass_cache, VkImage dst_i
|
|||||||
ASSERT(copy.dst_subresource.num_layers == 1);
|
ASSERT(copy.dst_subresource.num_layers == 1);
|
||||||
vk::ImageView src_view =
|
vk::ImageView src_view =
|
||||||
MakeMSAACopyView(device.GetLogical(), src_image, src_vk_format,
|
MakeMSAACopyView(device.GetLogical(), src_image, src_vk_format,
|
||||||
static_cast<u32>(copy.src_subresource.base_level));
|
static_cast<u32>(copy.src_subresource.base_level), view_aspect);
|
||||||
vk::ImageView dst_view =
|
vk::ImageView dst_view =
|
||||||
MakeMSAACopyView(device.GetLogical(), dst_image, dst_vk_format,
|
MakeMSAACopyView(device.GetLogical(), dst_image, dst_vk_format,
|
||||||
static_cast<u32>(copy.dst_subresource.base_level));
|
static_cast<u32>(copy.dst_subresource.base_level), view_aspect);
|
||||||
const VkOffset2D dst_offset{copy.dst_offset.x, copy.dst_offset.y};
|
const VkOffset2D dst_offset{copy.dst_offset.x, copy.dst_offset.y};
|
||||||
const VkExtent2D dst_extent{copy.extent.width, copy.extent.height};
|
const VkExtent2D dst_extent{copy.extent.width, copy.extent.height};
|
||||||
const VkRect2D render_area{
|
const VkRect2D render_area{
|
||||||
@@ -949,50 +971,64 @@ void BlitImageHelper::CopyMSAA(RenderPassCache& render_pass_cache, VkImage dst_i
|
|||||||
scheduler.RequestOutsideRenderPassOperationContext();
|
scheduler.RequestOutsideRenderPassOperationContext();
|
||||||
scheduler.Record([this, pipeline, layout, sampler, renderpass,
|
scheduler.Record([this, pipeline, layout, sampler, renderpass,
|
||||||
framebuffer_handle = *framebuffer, src_view_handle = *src_view,
|
framebuffer_handle = *framebuffer, src_view_handle = *src_view,
|
||||||
src = src_image, dst = dst_image, render_area,
|
src = src_image, dst = dst_image, render_area, is_depth, barrier_aspect,
|
||||||
push_constants](vk::CommandBuffer cmdbuf) {
|
push_constants](vk::CommandBuffer cmdbuf) {
|
||||||
constexpr VkImageSubresourceRange color_range{
|
const VkImageSubresourceRange src_range{
|
||||||
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
.aspectMask = barrier_aspect,
|
||||||
.baseMipLevel = 0,
|
.baseMipLevel = 0,
|
||||||
.levelCount = VK_REMAINING_MIP_LEVELS,
|
.levelCount = VK_REMAINING_MIP_LEVELS,
|
||||||
.baseArrayLayer = 0,
|
.baseArrayLayer = 0,
|
||||||
.layerCount = VK_REMAINING_ARRAY_LAYERS,
|
.layerCount = VK_REMAINING_ARRAY_LAYERS,
|
||||||
};
|
};
|
||||||
|
const VkImageSubresourceRange dst_range = src_range;
|
||||||
|
const VkAccessFlags attachment_read =
|
||||||
|
is_depth ? VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT
|
||||||
|
: VK_ACCESS_COLOR_ATTACHMENT_READ_BIT;
|
||||||
|
const VkAccessFlags attachment_write =
|
||||||
|
is_depth ? VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
|
||||||
|
: VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||||
|
const VkPipelineStageFlags depth_stage =
|
||||||
|
VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT |
|
||||||
|
VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
|
||||||
|
const VkPipelineStageFlags attachment_stage =
|
||||||
|
is_depth ? depth_stage
|
||||||
|
: static_cast<VkPipelineStageFlags>(
|
||||||
|
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
|
||||||
const std::array pre_barriers{
|
const std::array pre_barriers{
|
||||||
VkImageMemoryBarrier{
|
VkImageMemoryBarrier{
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
|
.srcAccessMask = attachment_write | VK_ACCESS_SHADER_WRITE_BIT |
|
||||||
VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT,
|
VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||||
.dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
|
.dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
|
||||||
.oldLayout = VK_IMAGE_LAYOUT_GENERAL,
|
.oldLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||||
.image = src,
|
.image = src,
|
||||||
.subresourceRange = color_range,
|
.subresourceRange = src_range,
|
||||||
},
|
},
|
||||||
VkImageMemoryBarrier{
|
VkImageMemoryBarrier{
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
|
.srcAccessMask = attachment_write | VK_ACCESS_SHADER_WRITE_BIT |
|
||||||
VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT,
|
VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||||
.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
|
.dstAccessMask = attachment_read | attachment_write,
|
||||||
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
|
||||||
.oldLayout = VK_IMAGE_LAYOUT_GENERAL,
|
.oldLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||||
.image = dst,
|
.image = dst,
|
||||||
.subresourceRange = color_range,
|
.subresourceRange = dst_range,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT |
|
cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT |
|
||||||
|
VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT |
|
||||||
|
VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT |
|
||||||
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
|
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
|
||||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT |
|
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT |
|
||||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT |
|
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | attachment_stage,
|
||||||
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
|
|
||||||
0, nullptr, nullptr, pre_barriers);
|
0, nullptr, nullptr, pre_barriers);
|
||||||
const VkRenderPassBeginInfo renderpass_bi{
|
const VkRenderPassBeginInfo renderpass_bi{
|
||||||
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
|
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
|
||||||
@@ -1025,16 +1061,16 @@ void BlitImageHelper::CopyMSAA(RenderPassCache& render_pass_cache, VkImage dst_i
|
|||||||
const VkImageMemoryBarrier post_barrier{
|
const VkImageMemoryBarrier post_barrier{
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
.srcAccessMask = attachment_write,
|
||||||
.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT,
|
.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT,
|
||||||
.oldLayout = VK_IMAGE_LAYOUT_GENERAL,
|
.oldLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||||
.image = dst,
|
.image = dst,
|
||||||
.subresourceRange = color_range,
|
.subresourceRange = dst_range,
|
||||||
};
|
};
|
||||||
cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
|
cmdbuf.PipelineBarrier(attachment_stage,
|
||||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT |
|
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT |
|
||||||
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
|
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
|
||||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||||
@@ -1423,9 +1459,36 @@ VkPipeline BlitImageHelper::FindOrEmplaceMSAACopyPipeline(const MSAACopyPipeline
|
|||||||
return *msaa_copy_pipelines[std::distance(msaa_copy_keys.begin(), it)];
|
return *msaa_copy_pipelines[std::distance(msaa_copy_keys.begin(), it)];
|
||||||
}
|
}
|
||||||
msaa_copy_keys.push_back(key);
|
msaa_copy_keys.push_back(key);
|
||||||
const std::array stages = MakeStages(*clear_color_vert, key.msaa_to_non_msaa
|
const VkShaderModule frag_module =
|
||||||
? *convert_msaa_to_non_msaa_frag
|
key.msaa_to_non_msaa
|
||||||
: *convert_non_msaa_to_msaa_frag);
|
? *convert_msaa_to_non_msaa_frag
|
||||||
|
: (key.is_depth ? *convert_non_msaa_to_msaa_depth_frag
|
||||||
|
: *convert_non_msaa_to_msaa_frag);
|
||||||
|
const std::array stages = MakeStages(*clear_color_vert, frag_module);
|
||||||
|
const VkPipelineDepthStencilStateCreateInfo depth_stencil_ci{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.depthTestEnable = VK_TRUE,
|
||||||
|
.depthWriteEnable = VK_TRUE,
|
||||||
|
.depthCompareOp = VK_COMPARE_OP_ALWAYS,
|
||||||
|
.depthBoundsTestEnable = VK_FALSE,
|
||||||
|
.stencilTestEnable = VK_FALSE,
|
||||||
|
.front = {},
|
||||||
|
.back = {},
|
||||||
|
.minDepthBounds = 0.0f,
|
||||||
|
.maxDepthBounds = 0.0f,
|
||||||
|
};
|
||||||
|
static constexpr VkPipelineColorBlendStateCreateInfo no_color_blend_ci{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.logicOpEnable = VK_FALSE,
|
||||||
|
.logicOp = VK_LOGIC_OP_CLEAR,
|
||||||
|
.attachmentCount = 0,
|
||||||
|
.pAttachments = nullptr,
|
||||||
|
.blendConstants = {0.0f, 0.0f, 0.0f, 0.0f},
|
||||||
|
};
|
||||||
const VkPipelineMultisampleStateCreateInfo multisample_ci{
|
const VkPipelineMultisampleStateCreateInfo multisample_ci{
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
@@ -1450,8 +1513,9 @@ VkPipeline BlitImageHelper::FindOrEmplaceMSAACopyPipeline(const MSAACopyPipeline
|
|||||||
.pViewportState = &PIPELINE_VIEWPORT_STATE_CREATE_INFO,
|
.pViewportState = &PIPELINE_VIEWPORT_STATE_CREATE_INFO,
|
||||||
.pRasterizationState = &PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
|
.pRasterizationState = &PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
|
||||||
.pMultisampleState = &multisample_ci,
|
.pMultisampleState = &multisample_ci,
|
||||||
.pDepthStencilState = nullptr,
|
.pDepthStencilState = key.is_depth ? &depth_stencil_ci : nullptr,
|
||||||
.pColorBlendState = &PIPELINE_COLOR_BLEND_STATE_GENERIC_CREATE_INFO,
|
.pColorBlendState = key.is_depth ? &no_color_blend_ci
|
||||||
|
: &PIPELINE_COLOR_BLEND_STATE_GENERIC_CREATE_INFO,
|
||||||
.pDynamicState = &PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
.pDynamicState = &PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
||||||
.layout = *msaa_copy_pipeline_layout,
|
.layout = *msaa_copy_pipeline_layout,
|
||||||
.renderPass = key.renderpass,
|
.renderPass = key.renderpass,
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ struct MSAACopyPipelineKey {
|
|||||||
VkRenderPass renderpass;
|
VkRenderPass renderpass;
|
||||||
VkSampleCountFlagBits samples;
|
VkSampleCountFlagBits samples;
|
||||||
bool msaa_to_non_msaa;
|
bool msaa_to_non_msaa;
|
||||||
|
bool is_depth;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BlitMSAAPipelineKey {
|
struct BlitMSAAPipelineKey {
|
||||||
@@ -180,6 +181,7 @@ private:
|
|||||||
vk::ShaderModule convert_s8d24_to_abgr8_frag;
|
vk::ShaderModule convert_s8d24_to_abgr8_frag;
|
||||||
vk::ShaderModule convert_msaa_to_non_msaa_frag;
|
vk::ShaderModule convert_msaa_to_non_msaa_frag;
|
||||||
vk::ShaderModule convert_non_msaa_to_msaa_frag;
|
vk::ShaderModule convert_non_msaa_to_msaa_frag;
|
||||||
|
vk::ShaderModule convert_non_msaa_to_msaa_depth_frag;
|
||||||
vk::Sampler linear_sampler;
|
vk::Sampler linear_sampler;
|
||||||
vk::Sampler nearest_sampler;
|
vk::Sampler nearest_sampler;
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,9 @@ void FixedPipelineState::Refresh(Tegra::Engines::Maxwell3D& maxwell3d, DynamicFe
|
|||||||
}
|
}
|
||||||
|
|
||||||
provoking_vertex_last.Assign(use_last_provoking_vertex ? 1 : 0);
|
provoking_vertex_last.Assign(use_last_provoking_vertex ? 1 : 0);
|
||||||
conservative_raster_enable.Assign(regs.conservative_raster_enable != 0 ? 1 : 0);
|
if (!features.has_dynamic_state3_conservative_raster_mode) {
|
||||||
|
conservative_raster_enable.Assign(regs.conservative_raster_enable != 0 ? 1 : 0);
|
||||||
|
}
|
||||||
smooth_lines.Assign(regs.line_anti_alias_enable != 0 ? 1 : 0);
|
smooth_lines.Assign(regs.line_anti_alias_enable != 0 ? 1 : 0);
|
||||||
alpha_to_coverage_enabled.Assign(regs.anti_alias_alpha_control.alpha_to_coverage != 0 ? 1 : 0);
|
alpha_to_coverage_enabled.Assign(regs.anti_alias_alpha_control.alpha_to_coverage != 0 ? 1 : 0);
|
||||||
alpha_to_one_enabled.Assign(regs.anti_alias_alpha_control.alpha_to_one != 0 ? 1 : 0);
|
alpha_to_one_enabled.Assign(regs.anti_alias_alpha_control.alpha_to_one != 0 ? 1 : 0);
|
||||||
@@ -360,18 +362,35 @@ void FixedPipelineState::DynamicState::Refresh2(const Maxwell& regs,
|
|||||||
depth_bias_enable.Assign(enabled_lut[POLYGON_OFFSET_ENABLE_LUT[topology_index]] != 0 ? 1 : 0);
|
depth_bias_enable.Assign(enabled_lut[POLYGON_OFFSET_ENABLE_LUT[topology_index]] != 0 ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsDepthClipEnabled(const Maxwell& regs) {
|
||||||
|
const auto clip = regs.viewport_clip_control.geometry_clip.Value();
|
||||||
|
return clip == Maxwell::ViewportClipControl::GeometryClip::Passthrough ||
|
||||||
|
clip == Maxwell::ViewportClipControl::GeometryClip::FrustumXYZ ||
|
||||||
|
clip == Maxwell::ViewportClipControl::GeometryClip::FrustumZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsDepthClampEnabled(const Maxwell& regs, bool has_depth_clip_enable) {
|
||||||
|
if (!IsDepthClipEnabled(regs)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!has_depth_clip_enable) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return regs.viewport_clip_control.pixel_min_z.Value() != 0 ||
|
||||||
|
regs.viewport_clip_control.pixel_max_z.Value() != 0;
|
||||||
|
}
|
||||||
|
|
||||||
void FixedPipelineState::DynamicState::Refresh3(const Maxwell& regs,
|
void FixedPipelineState::DynamicState::Refresh3(const Maxwell& regs,
|
||||||
const DynamicFeatures& features) {
|
const DynamicFeatures& features) {
|
||||||
if (!features.has_dynamic_state3_logic_op_enable) {
|
if (!features.has_dynamic_state3_logic_op_enable) {
|
||||||
logic_op_enable.Assign(regs.logic_op.enable != 0 ? 1 : 0);
|
logic_op_enable.Assign(regs.logic_op.enable != 0 ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
if (features.has_depth_clip_enable) {
|
||||||
|
depth_clip_disabled.Assign(IsDepthClipEnabled(regs) ? 0 : 1);
|
||||||
|
}
|
||||||
if (!features.has_dynamic_state3_depth_clamp_enable) {
|
if (!features.has_dynamic_state3_depth_clamp_enable) {
|
||||||
depth_clamp_disabled.Assign(regs.viewport_clip_control.geometry_clip ==
|
depth_clamp_disabled.Assign(
|
||||||
Maxwell::ViewportClipControl::GeometryClip::Passthrough ||
|
IsDepthClampEnabled(regs, features.has_depth_clip_enable) ? 0 : 1);
|
||||||
regs.viewport_clip_control.geometry_clip ==
|
|
||||||
Maxwell::ViewportClipControl::GeometryClip::FrustumXYZ ||
|
|
||||||
regs.viewport_clip_control.geometry_clip ==
|
|
||||||
Maxwell::ViewportClipControl::GeometryClip::FrustumZ);
|
|
||||||
}
|
}
|
||||||
if (!features.has_dynamic_state3_line_stipple_enable) {
|
if (!features.has_dynamic_state3_line_stipple_enable) {
|
||||||
line_stipple_enable.Assign(regs.line_stipple_enable);
|
line_stipple_enable.Assign(regs.line_stipple_enable);
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ struct DynamicFeatures {
|
|||||||
bool has_extended_dynamic_state_3_blend;
|
bool has_extended_dynamic_state_3_blend;
|
||||||
bool has_extended_dynamic_state_3_enables;
|
bool has_extended_dynamic_state_3_enables;
|
||||||
bool has_dynamic_state3_depth_clamp_enable;
|
bool has_dynamic_state3_depth_clamp_enable;
|
||||||
|
bool has_dynamic_state3_conservative_raster_mode;
|
||||||
|
bool has_depth_clip_enable;
|
||||||
bool has_dynamic_state3_logic_op_enable;
|
bool has_dynamic_state3_logic_op_enable;
|
||||||
bool has_dynamic_state3_line_stipple_enable;
|
bool has_dynamic_state3_line_stipple_enable;
|
||||||
bool has_dynamic_vertex_input;
|
bool has_dynamic_vertex_input;
|
||||||
@@ -165,6 +167,7 @@ struct FixedPipelineState {
|
|||||||
BitField<10, 1, u32> logic_op_enable;
|
BitField<10, 1, u32> logic_op_enable;
|
||||||
BitField<11, 1, u32> depth_clamp_disabled;
|
BitField<11, 1, u32> depth_clamp_disabled;
|
||||||
BitField<12, 1, u32> line_stipple_enable;
|
BitField<12, 1, u32> line_stipple_enable;
|
||||||
|
BitField<13, 1, u32> depth_clip_disabled;
|
||||||
};
|
};
|
||||||
union {
|
union {
|
||||||
u32 raw2;
|
u32 raw2;
|
||||||
@@ -298,6 +301,9 @@ static_assert(std::has_unique_object_representations_v<FixedPipelineState>);
|
|||||||
static_assert(std::is_trivially_copyable_v<FixedPipelineState>);
|
static_assert(std::is_trivially_copyable_v<FixedPipelineState>);
|
||||||
static_assert(std::is_trivially_constructible_v<FixedPipelineState>);
|
static_assert(std::is_trivially_constructible_v<FixedPipelineState>);
|
||||||
|
|
||||||
|
bool IsDepthClipEnabled(const Maxwell& regs);
|
||||||
|
bool IsDepthClampEnabled(const Maxwell& regs, bool has_depth_clip_enable);
|
||||||
|
|
||||||
} // namespace Vulkan
|
} // namespace Vulkan
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
|||||||
@@ -246,7 +246,6 @@ protected:
|
|||||||
StagingBufferPool& staging_pool;
|
StagingBufferPool& staging_pool;
|
||||||
|
|
||||||
vk::Buffer buffer{};
|
vk::Buffer buffer{};
|
||||||
MemoryCommit memory_commit{};
|
|
||||||
VkIndexType index_type{};
|
VkIndexType index_type{};
|
||||||
u32 num_indices = 0;
|
u32 num_indices = 0;
|
||||||
};
|
};
|
||||||
@@ -376,6 +375,10 @@ u64 BufferCacheRuntime::GetDeviceMemoryUsage() const {
|
|||||||
return device.GetDeviceMemoryUsage();
|
return device.GetDeviceMemoryUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u64 BufferCacheRuntime::GetDeviceAllocationUsage() const {
|
||||||
|
return device.GetMemoryBudgetInfo().allocation_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
bool BufferCacheRuntime::CanReportMemoryUsage() const {
|
bool BufferCacheRuntime::CanReportMemoryUsage() const {
|
||||||
return device.CanReportMemoryUsage();
|
return device.CanReportMemoryUsage();
|
||||||
}
|
}
|
||||||
@@ -404,6 +407,16 @@ u64 BufferCacheRuntime::KnownGpuTick() {
|
|||||||
return scheduler.GetMasterSemaphore().KnownGpuTick();
|
return scheduler.GetMasterSemaphore().KnownGpuTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u64 BufferCacheRuntime::CurrentSyncPoint() const noexcept {
|
||||||
|
return scheduler.GetMasterSemaphore().CurrentTick();
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 BufferCacheRuntime::CompletedSyncPoint() const {
|
||||||
|
auto& master_semaphore = scheduler.GetMasterSemaphore();
|
||||||
|
master_semaphore.Refresh();
|
||||||
|
return master_semaphore.KnownGpuTick();
|
||||||
|
}
|
||||||
|
|
||||||
void BufferCacheRuntime::Wait(u64 buffer_tick) {
|
void BufferCacheRuntime::Wait(u64 buffer_tick) {
|
||||||
scheduler.Wait(buffer_tick);
|
scheduler.Wait(buffer_tick);
|
||||||
}
|
}
|
||||||
@@ -641,6 +654,7 @@ void BufferCacheRuntime::BindTransformFeedbackBuffer(u32 index, VkBuffer buffer,
|
|||||||
offset = 0;
|
offset = 0;
|
||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
|
scheduler.MarkTransformFeedbackUsed();
|
||||||
scheduler.Record([index, buffer, offset, size](vk::CommandBuffer cmdbuf) {
|
scheduler.Record([index, buffer, offset, size](vk::CommandBuffer cmdbuf) {
|
||||||
const VkDeviceSize vk_offset = offset;
|
const VkDeviceSize vk_offset = offset;
|
||||||
const VkDeviceSize vk_size = size;
|
const VkDeviceSize vk_size = size;
|
||||||
@@ -653,19 +667,26 @@ void BufferCacheRuntime::BindTransformFeedbackBuffers(VideoCommon::HostBindings<
|
|||||||
// Already logged in the rasterizer
|
// Already logged in the rasterizer
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boost::container::static_vector<VkBuffer, VideoCommon::NUM_VERTEX_BUFFERS> buffer_handles(bindings.buffers.size());
|
const u32 count = std::min<u32>(static_cast<u32>(bindings.buffers.size()),
|
||||||
for (u32 i = 0; i < bindings.buffers.size(); ++i) {
|
VideoCommon::NUM_TRANSFORM_FEEDBACK_BUFFERS);
|
||||||
|
std::array<VkBuffer, VideoCommon::NUM_TRANSFORM_FEEDBACK_BUFFERS> handles{};
|
||||||
|
std::array<VkDeviceSize, VideoCommon::NUM_TRANSFORM_FEEDBACK_BUFFERS> offsets{};
|
||||||
|
std::array<VkDeviceSize, VideoCommon::NUM_TRANSFORM_FEEDBACK_BUFFERS> sizes{};
|
||||||
|
for (u32 i = 0; i < count; ++i) {
|
||||||
auto handle = bindings.buffers[i]->Handle();
|
auto handle = bindings.buffers[i]->Handle();
|
||||||
if (handle == VK_NULL_HANDLE) {
|
if (handle == VK_NULL_HANDLE) {
|
||||||
ReserveNullBuffer();
|
ReserveNullBuffer();
|
||||||
handle = *null_buffer;
|
handle = *null_buffer;
|
||||||
bindings.offsets[i] = 0;
|
} else {
|
||||||
bindings.sizes[i] = 0;
|
offsets[i] = bindings.offsets[i];
|
||||||
|
sizes[i] = bindings.sizes[i];
|
||||||
}
|
}
|
||||||
buffer_handles[i] = handle;
|
handles[i] = handle;
|
||||||
}
|
}
|
||||||
scheduler.Record([bindings_ = std::move(bindings), buffer_handles_ = std::move(buffer_handles)](vk::CommandBuffer cmdbuf) {
|
scheduler.MarkTransformFeedbackUsed();
|
||||||
cmdbuf.BindTransformFeedbackBuffersEXT(0, u32(buffer_handles_.size()), buffer_handles_.data(), bindings_.offsets.data(), bindings_.sizes.data());
|
scheduler.Record([count, handles, offsets, sizes](vk::CommandBuffer cmdbuf) {
|
||||||
|
cmdbuf.BindTransformFeedbackBuffersEXT(0, count, handles.data(), offsets.data(),
|
||||||
|
sizes.data());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,10 +100,20 @@ public:
|
|||||||
|
|
||||||
void Finish();
|
void Finish();
|
||||||
|
|
||||||
|
u64 CurrentSyncPoint() const noexcept;
|
||||||
|
|
||||||
|
u64 CompletedSyncPoint() const;
|
||||||
|
|
||||||
u64 GetDeviceLocalMemory() const;
|
u64 GetDeviceLocalMemory() const;
|
||||||
|
|
||||||
u64 GetDeviceMemoryUsage() const;
|
u64 GetDeviceMemoryUsage() const;
|
||||||
|
|
||||||
|
u64 GetDeviceAllocationUsage() const;
|
||||||
|
|
||||||
|
bool CanReportAllocationUsage() const noexcept {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool CanReportMemoryUsage() const;
|
bool CanReportMemoryUsage() const;
|
||||||
|
|
||||||
u32 GetUniformBufferAlignment() const;
|
u32 GetUniformBufferAlignment() const;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ void InnerFence::Wait() {
|
|||||||
if (is_stubbed) {
|
if (is_stubbed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
scheduler.Wait(wait_tick);
|
scheduler.WaitSubmitted(wait_tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
FenceManager::FenceManager(VideoCore::RasterizerInterface& rasterizer_, Tegra::GPU& gpu_,
|
FenceManager::FenceManager(VideoCore::RasterizerInterface& rasterizer_, Tegra::GPU& gpu_,
|
||||||
|
|||||||
@@ -757,16 +757,13 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
|
|||||||
.lineWidth = 1.0f,
|
.lineWidth = 1.0f,
|
||||||
// TODO(alekpop): Transfer from regs
|
// TODO(alekpop): Transfer from regs
|
||||||
};
|
};
|
||||||
const bool smooth_lines_supported =
|
const VkLineRasterizationModeEXT line_raster_mode =
|
||||||
device.IsExtLineRasterizationSupported() && device.SupportsSmoothLines();
|
device.GetLineRasterizationMode(key.state.smooth_lines != 0);
|
||||||
const bool stippled_lines_supported =
|
const bool stippled_lines_supported = device.SupportsStippleForMode(line_raster_mode);
|
||||||
device.IsExtLineRasterizationSupported() && device.SupportsStippledRectangularLines();
|
|
||||||
VkPipelineRasterizationLineStateCreateInfoEXT line_state{
|
VkPipelineRasterizationLineStateCreateInfoEXT line_state{
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
.lineRasterizationMode = key.state.smooth_lines != 0 && smooth_lines_supported
|
.lineRasterizationMode = line_raster_mode,
|
||||||
? VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT
|
|
||||||
: VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT,
|
|
||||||
.stippledLineEnable =
|
.stippledLineEnable =
|
||||||
(dynamic.line_stipple_enable && stippled_lines_supported) ? VK_TRUE : VK_FALSE,
|
(dynamic.line_stipple_enable && stippled_lines_supported) ? VK_TRUE : VK_FALSE,
|
||||||
.lineStippleFactor = key.state.line_stipple_factor,
|
.lineStippleFactor = key.state.line_stipple_factor,
|
||||||
@@ -805,6 +802,16 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
|
|||||||
if (device.IsExtProvokingVertexSupported()) {
|
if (device.IsExtProvokingVertexSupported()) {
|
||||||
provoking_vertex.pNext = std::exchange(rasterization_ci.pNext, &provoking_vertex);
|
provoking_vertex.pNext = std::exchange(rasterization_ci.pNext, &provoking_vertex);
|
||||||
}
|
}
|
||||||
|
VkPipelineRasterizationDepthClipStateCreateInfoEXT depth_clip_state{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_DEPTH_CLIP_STATE_CREATE_INFO_EXT,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.depthClipEnable = static_cast<VkBool32>(dynamic.depth_clip_disabled == 0 ? VK_TRUE
|
||||||
|
: VK_FALSE),
|
||||||
|
};
|
||||||
|
if (device.IsExtDepthClipEnableSupported()) {
|
||||||
|
depth_clip_state.pNext = std::exchange(rasterization_ci.pNext, &depth_clip_state);
|
||||||
|
}
|
||||||
|
|
||||||
const bool supports_alpha_output = fragment_has_color0_output;
|
const bool supports_alpha_output = fragment_has_color0_output;
|
||||||
const bool alpha_to_one_supported = device.SupportsAlphaToOne();
|
const bool alpha_to_one_supported = device.SupportsAlphaToOne();
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ size_t GetTotalPipelineWorkers() {
|
|||||||
std::max<size_t>(static_cast<size_t>(std::thread::hardware_concurrency()), 2ULL) - 1ULL;
|
std::max<size_t>(static_cast<size_t>(std::thread::hardware_concurrency()), 2ULL) - 1ULL;
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
const int configured = AndroidSettings::values.pipeline_worker_count.GetValue();
|
const int configured = AndroidSettings::values.pipeline_worker_count.GetValue();
|
||||||
const int clamped = std::clamp(configured, 4, 8);
|
const int clamped = std::clamp(configured, 2, 8);
|
||||||
const size_t desired = static_cast<size_t>(clamped);
|
const size_t desired = static_cast<size_t>(clamped);
|
||||||
if (desired == 0) {
|
if (desired == 0) {
|
||||||
return 1ULL;
|
return 1ULL;
|
||||||
@@ -349,8 +349,9 @@ PipelineCache::PipelineCache(Tegra::MaxwellDeviceMemoryManager& device_memory_,
|
|||||||
use_asynchronous_shaders{Settings::values.use_asynchronous_shaders.GetValue()},
|
use_asynchronous_shaders{Settings::values.use_asynchronous_shaders.GetValue()},
|
||||||
use_vulkan_pipeline_cache{Settings::values.use_vulkan_driver_pipeline_cache.GetValue()},
|
use_vulkan_pipeline_cache{Settings::values.use_vulkan_driver_pipeline_cache.GetValue()},
|
||||||
workers(device.HasBrokenParallelShaderCompiling() ? 1ULL : GetTotalPipelineWorkers(),
|
workers(device.HasBrokenParallelShaderCompiling() ? 1ULL : GetTotalPipelineWorkers(),
|
||||||
"VkPipelineBuilder"),
|
"VkPipelineBuilder", {}, Common::ThreadPlacement::Background),
|
||||||
serialization_thread(1, "VkPipelineSerialization") {
|
serialization_thread(1, "VkPipelineSerialization", {},
|
||||||
|
Common::ThreadPlacement::Background) {
|
||||||
const auto& float_control{device.FloatControlProperties()};
|
const auto& float_control{device.FloatControlProperties()};
|
||||||
const VkDriverId driver_id{device.GetDriverID()};
|
const VkDriverId driver_id{device.GetDriverID()};
|
||||||
const VkShaderStageFlags subgroup_stages{device.GetSubgroupSupportedStages()};
|
const VkShaderStageFlags subgroup_stages{device.GetSubgroupSupportedStages()};
|
||||||
@@ -514,6 +515,11 @@ PipelineCache::PipelineCache(Tegra::MaxwellDeviceMemoryManager& device_memory_,
|
|||||||
dynamic_features.has_dynamic_state3_depth_clamp_enable =
|
dynamic_features.has_dynamic_state3_depth_clamp_enable =
|
||||||
dynamic_features.has_extended_dynamic_state_3_enables &&
|
dynamic_features.has_extended_dynamic_state_3_enables &&
|
||||||
device.SupportsDynamicState3DepthClampEnable();
|
device.SupportsDynamicState3DepthClampEnable();
|
||||||
|
dynamic_features.has_dynamic_state3_conservative_raster_mode =
|
||||||
|
dynamic_features.has_extended_dynamic_state_3_enables &&
|
||||||
|
device.SupportsDynamicState3ConservativeRasterizationMode();
|
||||||
|
dynamic_features.has_depth_clip_enable =
|
||||||
|
device.IsExtDepthClipEnableSupported();
|
||||||
dynamic_features.has_dynamic_state3_logic_op_enable =
|
dynamic_features.has_dynamic_state3_logic_op_enable =
|
||||||
dynamic_features.has_extended_dynamic_state_3_enables &&
|
dynamic_features.has_extended_dynamic_state_3_enables &&
|
||||||
device.SupportsDynamicState3LogicOpEnable();
|
device.SupportsDynamicState3LogicOpEnable();
|
||||||
@@ -526,7 +532,8 @@ PipelineCache::PipelineCache(Tegra::MaxwellDeviceMemoryManager& device_memory_,
|
|||||||
device.IsExtVertexInputDynamicStateSupported() &&
|
device.IsExtVertexInputDynamicStateSupported() &&
|
||||||
Settings::values.vertex_input_dynamic_state.GetValue();
|
Settings::values.vertex_input_dynamic_state.GetValue();
|
||||||
|
|
||||||
dynamic_features.has_provoking_vertex = device.IsExtProvokingVertexSupported();
|
dynamic_features.has_provoking_vertex =
|
||||||
|
device.IsExtProvokingVertexSupported();
|
||||||
dynamic_features.has_provoking_vertex_first_mode =
|
dynamic_features.has_provoking_vertex_first_mode =
|
||||||
device.SupportsProvokingVertexFirstMode();
|
device.SupportsProvokingVertexFirstMode();
|
||||||
dynamic_features.has_provoking_vertex_last_mode =
|
dynamic_features.has_provoking_vertex_last_mode =
|
||||||
|
|||||||
@@ -296,9 +296,6 @@ void PresentManager::RecreateSwapchain(Frame* frame) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PresentManager::SetImageCount() {
|
void PresentManager::SetImageCount() {
|
||||||
// We cannot have more than 7 images in flight at any given time.
|
|
||||||
// FRAMES_IN_FLIGHT is 8, and the cache TICKS_TO_DESTROY is 8.
|
|
||||||
// Mali drivers will give us 6.
|
|
||||||
image_count = std::min<size_t>(swapchain.GetImageCount(), 7);
|
image_count = std::min<size_t>(swapchain.GetImageCount(), 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -919,7 +919,7 @@ private:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
has_flushed_end_pending = true;
|
has_flushed_end_pending = true;
|
||||||
// Refresh buffers state before beginning transform feedback so counters are up-to-date
|
scheduler.MarkTransformFeedbackUsed();
|
||||||
UpdateBuffers();
|
UpdateBuffers();
|
||||||
if (!has_started || buffers_count == 0) {
|
if (!has_started || buffers_count == 0) {
|
||||||
// No counter buffers available: begin without counters
|
// No counter buffers available: begin without counters
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <limits>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
@@ -203,7 +204,8 @@ RasterizerVulkan::RasterizerVulkan(Core::Frontend::EmuWindow& emu_window_, Tegra
|
|||||||
: gpu{gpu_}, device_memory{device_memory_}, device{device_},
|
: gpu{gpu_}, device_memory{device_memory_}, device{device_},
|
||||||
memory_allocator{memory_allocator_}, state_tracker{state_tracker_}, scheduler{scheduler_},
|
memory_allocator{memory_allocator_}, state_tracker{state_tracker_}, scheduler{scheduler_},
|
||||||
staging_pool(device, memory_allocator, scheduler), descriptor_pool(device, scheduler),
|
staging_pool(device, memory_allocator, scheduler), descriptor_pool(device, scheduler),
|
||||||
guest_descriptor_queue(device), compute_pass_descriptor_queue(device),
|
guest_descriptor_queue(device, UpdateDescriptorQueue::GUEST_FRAME_PAYLOAD_SIZE),
|
||||||
|
compute_pass_descriptor_queue(device, UpdateDescriptorQueue::COMPUTE_FRAME_PAYLOAD_SIZE),
|
||||||
blit_image(device, scheduler, state_tracker, descriptor_pool), render_pass_cache(device),
|
blit_image(device, scheduler, state_tracker, descriptor_pool), render_pass_cache(device),
|
||||||
texture_cache_runtime{
|
texture_cache_runtime{
|
||||||
device, scheduler, memory_allocator, staging_pool,
|
device, scheduler, memory_allocator, staging_pool,
|
||||||
@@ -221,9 +223,23 @@ RasterizerVulkan::RasterizerVulkan(Core::Frontend::EmuWindow& emu_window_, Tegra
|
|||||||
fence_manager(*this, gpu, texture_cache, buffer_cache, query_cache, device, scheduler),
|
fence_manager(*this, gpu, texture_cache, buffer_cache, query_cache, device, scheduler),
|
||||||
wfi_event(device.GetLogical().CreateEvent()) {
|
wfi_event(device.GetLogical().CreateEvent()) {
|
||||||
scheduler.SetQueryCache(query_cache);
|
scheduler.SetQueryCache(query_cache);
|
||||||
|
memory_allocator.SetReclaimCallback([this](u64 bytes) -> u64 {
|
||||||
|
u64 freed = staging_pool.ReclaimMemory(bytes);
|
||||||
|
if (freed < bytes) {
|
||||||
|
freed += texture_cache.ReclaimMemory(bytes - freed, false);
|
||||||
|
}
|
||||||
|
if (freed < bytes) {
|
||||||
|
freed += buffer_cache.ReclaimMemory(bytes - freed, false);
|
||||||
|
}
|
||||||
|
auto& master_semaphore = scheduler.GetMasterSemaphore();
|
||||||
|
master_semaphore.Refresh();
|
||||||
|
vk::TickDeletionQueue(master_semaphore.KnownGpuTick());
|
||||||
|
return freed;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
RasterizerVulkan::~RasterizerVulkan() {
|
RasterizerVulkan::~RasterizerVulkan() {
|
||||||
|
memory_allocator.SetReclaimCallback(nullptr);
|
||||||
scheduler.WaitWorker();
|
scheduler.WaitWorker();
|
||||||
scheduler.Finish();
|
scheduler.Finish();
|
||||||
}
|
}
|
||||||
@@ -880,6 +896,9 @@ void RasterizerVulkan::FlushCommands() {
|
|||||||
|
|
||||||
void RasterizerVulkan::TickFrame() {
|
void RasterizerVulkan::TickFrame() {
|
||||||
draw_counter = 0;
|
draw_counter = 0;
|
||||||
|
auto& master_semaphore = scheduler.GetMasterSemaphore();
|
||||||
|
master_semaphore.Refresh();
|
||||||
|
vk::TickDeletionQueue(master_semaphore.KnownGpuTick());
|
||||||
guest_descriptor_queue.TickFrame();
|
guest_descriptor_queue.TickFrame();
|
||||||
compute_pass_descriptor_queue.TickFrame();
|
compute_pass_descriptor_queue.TickFrame();
|
||||||
fence_manager.TickFrame();
|
fence_manager.TickFrame();
|
||||||
@@ -1451,7 +1470,10 @@ void RasterizerVulkan::UpdateLineWidth(Tegra::Engines::Maxwell3D::Regs& regs) {
|
|||||||
}
|
}
|
||||||
const float width =
|
const float width =
|
||||||
regs.line_anti_alias_enable ? regs.line_width_smooth : regs.line_width_aliased;
|
regs.line_anti_alias_enable ? regs.line_width_smooth : regs.line_width_aliased;
|
||||||
scheduler.Record([width](vk::CommandBuffer cmdbuf) { cmdbuf.SetLineWidth(width); });
|
const float clamped_width = device.ClampLineWidth(width);
|
||||||
|
scheduler.Record([clamped_width](vk::CommandBuffer cmdbuf) {
|
||||||
|
cmdbuf.SetLineWidth(clamped_width);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerVulkan::UpdateCullMode(Tegra::Engines::Maxwell3D::Regs& regs) {
|
void RasterizerVulkan::UpdateCullMode(Tegra::Engines::Maxwell3D::Regs& regs) {
|
||||||
@@ -1548,7 +1570,10 @@ void RasterizerVulkan::UpdateLineStippleEnable(Tegra::Engines::Maxwell3D::Regs&
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduler.Record([enable = regs.line_stipple_enable](vk::CommandBuffer cmdbuf) {
|
const VkLineRasterizationModeEXT mode =
|
||||||
|
device.GetLineRasterizationMode(regs.line_anti_alias_enable != 0);
|
||||||
|
const bool enable = regs.line_stipple_enable != 0 && device.SupportsStippleForMode(mode);
|
||||||
|
scheduler.Record([enable](vk::CommandBuffer cmdbuf) {
|
||||||
cmdbuf.SetLineStippleEnableEXT(enable);
|
cmdbuf.SetLineStippleEnableEXT(enable);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1562,28 +1587,24 @@ void RasterizerVulkan::UpdateLineRasterizationMode(Tegra::Engines::Maxwell3D::Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!device.SupportsDynamicState3LineRasterizationMode()) {
|
if (!device.SupportsDynamicState3LineRasterizationMode()) {
|
||||||
static std::once_flag warn_missing_rect;
|
static std::once_flag warn_missing_dynamic_state;
|
||||||
std::call_once(warn_missing_rect, [] {
|
std::call_once(warn_missing_dynamic_state, [] {
|
||||||
LOG_WARNING(Render_Vulkan,
|
LOG_WARNING(Render_Vulkan,
|
||||||
"Driver lacks rectangular line rasterization support; skipping dynamic "
|
"Driver lacks dynamic line rasterization mode; the pipeline static value "
|
||||||
"line state updates");
|
"is used instead");
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool wants_smooth = regs.line_anti_alias_enable != 0;
|
const bool wants_smooth = regs.line_anti_alias_enable != 0;
|
||||||
VkLineRasterizationModeEXT mode = VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT;
|
const VkLineRasterizationModeEXT mode = device.GetLineRasterizationMode(wants_smooth);
|
||||||
if (wants_smooth) {
|
if (wants_smooth && mode != VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT) {
|
||||||
if (device.SupportsSmoothLines()) {
|
static std::once_flag warn_missing_smooth;
|
||||||
mode = VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT;
|
std::call_once(warn_missing_smooth, [] {
|
||||||
} else {
|
LOG_WARNING(Render_Vulkan,
|
||||||
static std::once_flag warn_missing_smooth;
|
"Line anti-aliasing requested but smoothLines feature unavailable; "
|
||||||
std::call_once(warn_missing_smooth, [] {
|
"falling back to the closest supported mode");
|
||||||
LOG_WARNING(Render_Vulkan,
|
});
|
||||||
"Line anti-aliasing requested but smoothLines feature unavailable; "
|
|
||||||
"using rectangular rasterization");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
scheduler.Record([mode](vk::CommandBuffer cmdbuf) {
|
scheduler.Record([mode](vk::CommandBuffer cmdbuf) {
|
||||||
cmdbuf.SetLineRasterizationModeEXT(mode);
|
cmdbuf.SetLineRasterizationModeEXT(mode);
|
||||||
@@ -1643,12 +1664,7 @@ void RasterizerVulkan::UpdateDepthClampEnable(Tegra::Engines::Maxwell3D::Regs& r
|
|||||||
if (!device.SupportsDynamicState3DepthClampEnable()) {
|
if (!device.SupportsDynamicState3DepthClampEnable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool is_enabled = !(regs.viewport_clip_control.geometry_clip ==
|
const bool is_enabled = IsDepthClampEnabled(regs, device.IsExtDepthClipEnableSupported());
|
||||||
Maxwell::ViewportClipControl::GeometryClip::Passthrough ||
|
|
||||||
regs.viewport_clip_control.geometry_clip ==
|
|
||||||
Maxwell::ViewportClipControl::GeometryClip::FrustumXYZ ||
|
|
||||||
regs.viewport_clip_control.geometry_clip ==
|
|
||||||
Maxwell::ViewportClipControl::GeometryClip::FrustumZ);
|
|
||||||
scheduler.Record(
|
scheduler.Record(
|
||||||
[is_enabled](vk::CommandBuffer cmdbuf) { cmdbuf.SetDepthClampEnableEXT(is_enabled); });
|
[is_enabled](vk::CommandBuffer cmdbuf) { cmdbuf.SetDepthClampEnableEXT(is_enabled); });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,6 @@ private:
|
|||||||
void UpdateRasterizerDiscardEnable(Tegra::Engines::Maxwell3D::Regs& regs);
|
void UpdateRasterizerDiscardEnable(Tegra::Engines::Maxwell3D::Regs& regs);
|
||||||
void UpdateConservativeRasterizationMode(Tegra::Engines::Maxwell3D::Regs& regs);
|
void UpdateConservativeRasterizationMode(Tegra::Engines::Maxwell3D::Regs& regs);
|
||||||
void UpdateLineStippleEnable(Tegra::Engines::Maxwell3D::Regs& regs);
|
void UpdateLineStippleEnable(Tegra::Engines::Maxwell3D::Regs& regs);
|
||||||
void UpdateLineStipple(Tegra::Engines::Maxwell3D::Regs& regs);
|
|
||||||
void UpdateLineRasterizationMode(Tegra::Engines::Maxwell3D::Regs& regs);
|
void UpdateLineRasterizationMode(Tegra::Engines::Maxwell3D::Regs& regs);
|
||||||
void UpdateDepthBiasEnable(Tegra::Engines::Maxwell3D::Regs& regs);
|
void UpdateDepthBiasEnable(Tegra::Engines::Maxwell3D::Regs& regs);
|
||||||
void UpdateLogicOpEnable(Tegra::Engines::Maxwell3D::Regs& regs);
|
void UpdateLogicOpEnable(Tegra::Engines::Maxwell3D::Regs& regs);
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ Scheduler::Scheduler(const Device& device_, StateTracker& state_tracker_)
|
|||||||
master_semaphore{std::make_unique<MasterSemaphore>(device)},
|
master_semaphore{std::make_unique<MasterSemaphore>(device)},
|
||||||
command_pool{std::make_unique<CommandPool>(*master_semaphore, device)} {
|
command_pool{std::make_unique<CommandPool>(*master_semaphore, device)} {
|
||||||
|
|
||||||
|
vk::SetDeletionTimeline(master_semaphore->CurrentTick());
|
||||||
AcquireNewChunk();
|
AcquireNewChunk();
|
||||||
AllocateWorkerCommandBuffer();
|
AllocateWorkerCommandBuffer();
|
||||||
worker_thread = std::jthread([this](std::stop_token token) { WorkerThread(token); });
|
worker_thread = std::jthread([this](std::stop_token token) { WorkerThread(token); });
|
||||||
@@ -322,6 +323,7 @@ u64 Scheduler::SubmitExecution(VkSemaphore signal_semaphore, VkSemaphore wait_se
|
|||||||
InvalidateState();
|
InvalidateState();
|
||||||
|
|
||||||
const u64 signal_value = master_semaphore->NextTick();
|
const u64 signal_value = master_semaphore->NextTick();
|
||||||
|
vk::SetDeletionTimeline(master_semaphore->CurrentTick());
|
||||||
RecordWithUploadBuffer([signal_semaphore, wait_semaphore, signal_value,
|
RecordWithUploadBuffer([signal_semaphore, wait_semaphore, signal_value,
|
||||||
this](vk::CommandBuffer cmdbuf, vk::CommandBuffer upload_cmdbuf) {
|
this](vk::CommandBuffer cmdbuf, vk::CommandBuffer upload_cmdbuf) {
|
||||||
static constexpr VkMemoryBarrier WRITE_BARRIER{
|
static constexpr VkMemoryBarrier WRITE_BARRIER{
|
||||||
@@ -398,7 +400,7 @@ void Scheduler::EndRenderPass()
|
|||||||
Record([num_images = num_renderpass_images,
|
Record([num_images = num_renderpass_images,
|
||||||
images = renderpass_images,
|
images = renderpass_images,
|
||||||
ranges = renderpass_image_ranges,
|
ranges = renderpass_image_ranges,
|
||||||
has_transform_feedback = device.IsExtTransformFeedbackSupported()](
|
has_transform_feedback = state.uses_transform_feedback](
|
||||||
vk::CommandBuffer cmdbuf) {
|
vk::CommandBuffer cmdbuf) {
|
||||||
std::array<VkImageMemoryBarrier, 9> barriers;
|
std::array<VkImageMemoryBarrier, 9> barriers;
|
||||||
for (size_t i = 0; i < num_images; ++i) {
|
for (size_t i = 0; i < num_images; ++i) {
|
||||||
@@ -453,6 +455,7 @@ void Scheduler::EndRenderPass()
|
|||||||
});
|
});
|
||||||
|
|
||||||
state.renderpass = VkRenderPass{};
|
state.renderpass = VkRenderPass{};
|
||||||
|
state.uses_transform_feedback = false;
|
||||||
num_renderpass_images = 0;
|
num_renderpass_images = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,11 @@ public:
|
|||||||
return state.renderpass != VK_NULL_HANDLE;
|
return state.renderpass != VK_NULL_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Flags that transform feedback writes have been recorded since the last render pass end.
|
||||||
|
void MarkTransformFeedbackUsed() noexcept {
|
||||||
|
state.uses_transform_feedback = true;
|
||||||
|
}
|
||||||
|
|
||||||
/// Update the pipeline to the current execution context.
|
/// Update the pipeline to the current execution context.
|
||||||
bool UpdateGraphicsPipeline(GraphicsPipeline* pipeline);
|
bool UpdateGraphicsPipeline(GraphicsPipeline* pipeline);
|
||||||
|
|
||||||
@@ -131,33 +136,16 @@ public:
|
|||||||
}
|
}
|
||||||
master_semaphore->Wait(tick);
|
master_semaphore->Wait(tick);
|
||||||
}
|
}
|
||||||
if (Settings::values.use_speed_limit.GetValue() && target_fps > 0.0) {
|
ApplyFramePacing(target_fps);
|
||||||
auto now = std::chrono::steady_clock::now();
|
}
|
||||||
if (last_target_fps != target_fps) {
|
|
||||||
frame_interval = std::chrono::duration_cast<std::chrono::steady_clock::duration>(std::chrono::duration<double>(1.0 / target_fps));
|
void WaitSubmitted(u64 tick, double target_fps = 0.0) {
|
||||||
max_frame_count = static_cast<int>(0.1 * target_fps);
|
if (tick > 0 && tick < master_semaphore->CurrentTick()) {
|
||||||
last_target_fps = target_fps;
|
master_semaphore->Wait(tick);
|
||||||
frame_counter = 0;
|
}
|
||||||
start_time = now;
|
ApplyFramePacing(target_fps);
|
||||||
}
|
|
||||||
frame_counter++;
|
|
||||||
auto target_time = start_time + frame_interval * frame_counter;
|
|
||||||
if (target_time >= now) {
|
|
||||||
auto sleep_time = target_time - now;
|
|
||||||
if (sleep_time > std::chrono::milliseconds(15)) {
|
|
||||||
std::this_thread::sleep_for(sleep_time - std::chrono::milliseconds(1));
|
|
||||||
}
|
|
||||||
while (std::chrono::steady_clock::now() < target_time) {
|
|
||||||
std::this_thread::yield();
|
|
||||||
}
|
|
||||||
} else if (frame_counter > max_frame_count) {
|
|
||||||
frame_counter = 0;
|
|
||||||
start_time = now;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the master timeline semaphore.
|
|
||||||
[[nodiscard]] MasterSemaphore& GetMasterSemaphore() const noexcept {
|
[[nodiscard]] MasterSemaphore& GetMasterSemaphore() const noexcept {
|
||||||
return *master_semaphore;
|
return *master_semaphore;
|
||||||
}
|
}
|
||||||
@@ -165,6 +153,35 @@ public:
|
|||||||
std::mutex submit_mutex;
|
std::mutex submit_mutex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void ApplyFramePacing(double target_fps) {
|
||||||
|
if (!Settings::values.use_speed_limit.GetValue() || target_fps <= 0.0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto now = std::chrono::steady_clock::now();
|
||||||
|
if (last_target_fps != target_fps) {
|
||||||
|
frame_interval = std::chrono::duration_cast<std::chrono::steady_clock::duration>(
|
||||||
|
std::chrono::duration<double>(1.0 / target_fps));
|
||||||
|
max_frame_count = static_cast<int>(0.1 * target_fps);
|
||||||
|
last_target_fps = target_fps;
|
||||||
|
frame_counter = 0;
|
||||||
|
start_time = now;
|
||||||
|
}
|
||||||
|
frame_counter++;
|
||||||
|
auto target_time = start_time + frame_interval * frame_counter;
|
||||||
|
if (target_time >= now) {
|
||||||
|
auto sleep_time = target_time - now;
|
||||||
|
if (sleep_time > std::chrono::milliseconds(15)) {
|
||||||
|
std::this_thread::sleep_for(sleep_time - std::chrono::milliseconds(1));
|
||||||
|
}
|
||||||
|
while (std::chrono::steady_clock::now() < target_time) {
|
||||||
|
std::this_thread::yield();
|
||||||
|
}
|
||||||
|
} else if (frame_counter > max_frame_count) {
|
||||||
|
frame_counter = 0;
|
||||||
|
start_time = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Command {
|
class Command {
|
||||||
public:
|
public:
|
||||||
virtual ~Command() = default;
|
virtual ~Command() = default;
|
||||||
@@ -255,6 +272,7 @@ private:
|
|||||||
bool is_rescaling = false;
|
bool is_rescaling = false;
|
||||||
bool rescaling_defined = false;
|
bool rescaling_defined = false;
|
||||||
bool needs_state_enable_refresh = false;
|
bool needs_state_enable_refresh = false;
|
||||||
|
bool uses_transform_feedback = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DeferredClear {
|
struct DeferredClear {
|
||||||
|
|||||||
@@ -252,25 +252,62 @@ void StagingBufferPool::ReleaseLevel(StagingBuffersCache& cache, size_t log2) {
|
|||||||
constexpr size_t deletions_per_tick = 16;
|
constexpr size_t deletions_per_tick = 16;
|
||||||
auto& staging = cache[log2];
|
auto& staging = cache[log2];
|
||||||
auto& entries = staging.entries;
|
auto& entries = staging.entries;
|
||||||
const size_t old_size = entries.size();
|
if (entries.empty()) {
|
||||||
|
staging.delete_index = 0;
|
||||||
|
staging.iterate_index = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto is_deletable = [this](const StagingBuffer& entry) {
|
const auto is_deletable = [this](const StagingBuffer& entry) {
|
||||||
return scheduler.IsFree(entry.tick);
|
return scheduler.IsFree(entry.tick);
|
||||||
};
|
};
|
||||||
const size_t begin_offset = staging.delete_index;
|
const size_t begin_offset = (std::min)(staging.delete_index, entries.size());
|
||||||
const size_t end_offset = (std::min)(begin_offset + deletions_per_tick, old_size);
|
const size_t end_offset = (std::min)(begin_offset + deletions_per_tick, entries.size());
|
||||||
const auto begin = entries.begin() + begin_offset;
|
const auto begin = entries.begin() + begin_offset;
|
||||||
const auto end = entries.begin() + end_offset;
|
const auto end = entries.begin() + end_offset;
|
||||||
entries.erase(std::remove_if(begin, end, is_deletable), end);
|
const auto surviving_end = std::remove_if(begin, end, is_deletable);
|
||||||
|
const size_t removed = static_cast<size_t>(std::distance(surviving_end, end));
|
||||||
|
entries.erase(surviving_end, end);
|
||||||
|
|
||||||
const size_t new_size = entries.size();
|
staging.delete_index = end_offset - removed;
|
||||||
staging.delete_index += deletions_per_tick;
|
if (staging.delete_index >= entries.size()) {
|
||||||
if (staging.delete_index >= new_size) {
|
|
||||||
staging.delete_index = 0;
|
staging.delete_index = 0;
|
||||||
}
|
}
|
||||||
if (staging.iterate_index > new_size) {
|
if (staging.iterate_index > entries.size()) {
|
||||||
staging.iterate_index = 0;
|
staging.iterate_index = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u64 StagingBufferPool::ReclaimMemory(u64 target_bytes) {
|
||||||
|
u64 freed = 0;
|
||||||
|
const auto is_deletable = [this](const StagingBuffer& entry) {
|
||||||
|
return scheduler.IsFree(entry.tick);
|
||||||
|
};
|
||||||
|
const auto reclaim_cache = [&](StagingBuffersCache& cache) {
|
||||||
|
for (size_t level = NUM_LEVELS; level-- > 0 && freed < target_bytes;) {
|
||||||
|
auto& staging = cache[level];
|
||||||
|
auto& entries = staging.entries;
|
||||||
|
if (entries.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const u64 entry_bytes = 1ULL << level;
|
||||||
|
auto it = entries.begin();
|
||||||
|
while (it != entries.end() && freed < target_bytes) {
|
||||||
|
if (is_deletable(*it)) {
|
||||||
|
it = entries.erase(it);
|
||||||
|
freed += entry_bytes;
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
staging.delete_index = 0;
|
||||||
|
staging.iterate_index = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
reclaim_cache(device_local_cache);
|
||||||
|
reclaim_cache(upload_cache);
|
||||||
|
reclaim_cache(download_cache);
|
||||||
|
return freed;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Vulkan
|
} // namespace Vulkan
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
@@ -42,6 +45,8 @@ public:
|
|||||||
|
|
||||||
void TickFrame();
|
void TickFrame();
|
||||||
|
|
||||||
|
u64 ReclaimMemory(u64 target_bytes);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct StreamBufferCommit {
|
struct StreamBufferCommit {
|
||||||
size_t upper_bound;
|
size_t upper_bound;
|
||||||
|
|||||||
@@ -9,10 +9,6 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
|
||||||
#include <android/api-level.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "common/logging.h"
|
#include "common/logging.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "common/settings_enums.h"
|
#include "common/settings_enums.h"
|
||||||
@@ -176,34 +172,26 @@ bool Swapchain::AcquireNextImage() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto wait_with_frame_pacing = [this] {
|
#ifdef __ANDROID__
|
||||||
|
scheduler.WaitSubmitted(resource_ticks[image_index]);
|
||||||
|
#else
|
||||||
switch (Settings::values.frame_pacing_mode.GetValue()) {
|
switch (Settings::values.frame_pacing_mode.GetValue()) {
|
||||||
case Settings::FramePacingMode::Target_Auto:
|
case Settings::FramePacingMode::Target_Auto:
|
||||||
scheduler.Wait(resource_ticks[image_index]);
|
scheduler.WaitSubmitted(resource_ticks[image_index]);
|
||||||
break;
|
break;
|
||||||
case Settings::FramePacingMode::Target_30:
|
case Settings::FramePacingMode::Target_30:
|
||||||
scheduler.Wait(resource_ticks[image_index], 30.0);
|
scheduler.WaitSubmitted(resource_ticks[image_index], 30.0);
|
||||||
break;
|
break;
|
||||||
case Settings::FramePacingMode::Target_60:
|
case Settings::FramePacingMode::Target_60:
|
||||||
scheduler.Wait(resource_ticks[image_index], 60.0);
|
scheduler.WaitSubmitted(resource_ticks[image_index], 60.0);
|
||||||
break;
|
break;
|
||||||
case Settings::FramePacingMode::Target_90:
|
case Settings::FramePacingMode::Target_90:
|
||||||
scheduler.Wait(resource_ticks[image_index], 90.0);
|
scheduler.WaitSubmitted(resource_ticks[image_index], 90.0);
|
||||||
break;
|
break;
|
||||||
case Settings::FramePacingMode::Target_120:
|
case Settings::FramePacingMode::Target_120:
|
||||||
scheduler.Wait(resource_ticks[image_index], 120.0);
|
scheduler.WaitSubmitted(resource_ticks[image_index], 120.0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
|
||||||
if (android_get_device_api_level() >= 30) {
|
|
||||||
scheduler.Wait(resource_ticks[image_index]);
|
|
||||||
} else {
|
|
||||||
wait_with_frame_pacing();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
wait_with_frame_pacing();
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
resource_ticks[image_index] = scheduler.CurrentTick();
|
resource_ticks[image_index] = scheduler.CurrentTick();
|
||||||
|
|||||||
@@ -144,11 +144,6 @@ constexpr VkBorderColor ConvertBorderColor(const std::array<float, 4>& color) {
|
|||||||
info.size.depth == 1;
|
info.size.depth == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool WillUseWidenedAstcFormat(const Device& device, const ImageInfo& info) {
|
|
||||||
return WillUseAcceleratedAstcDecode(device, info) &&
|
|
||||||
!VideoCore::Surface::IsPixelFormatSRGB(info.format);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] VkImageCreateInfo MakeImageCreateInfo(const Device& device, const ImageInfo& info,
|
[[nodiscard]] VkImageCreateInfo MakeImageCreateInfo(const Device& device, const ImageInfo& info,
|
||||||
std::optional<VkFormat> format_override = {}) {
|
std::optional<VkFormat> format_override = {}) {
|
||||||
auto format_info =
|
auto format_info =
|
||||||
@@ -212,7 +207,11 @@ constexpr VkBorderColor ConvertBorderColor(const std::array<float, 4>& color) {
|
|||||||
return device.IsFormatSupported(view_format, VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT,
|
return device.IsFormatSupported(view_format, VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT,
|
||||||
FormatType::Optimal);
|
FormatType::Optimal);
|
||||||
});
|
});
|
||||||
if (has_storage_compatible_view) {
|
const bool storage_allowed_for_samples =
|
||||||
|
image_ci.samples == VK_SAMPLE_COUNT_1_BIT ||
|
||||||
|
(device.GetStorageImageSampleCounts() &
|
||||||
|
static_cast<VkSampleCountFlags>(image_ci.samples)) != 0;
|
||||||
|
if (has_storage_compatible_view && storage_allowed_for_samples) {
|
||||||
image_ci.usage |= VK_IMAGE_USAGE_STORAGE_BIT;
|
image_ci.usage |= VK_IMAGE_USAGE_STORAGE_BIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -896,6 +895,15 @@ void BlitScale(Scheduler& scheduler, VkImage src_image, VkImage dst_image, const
|
|||||||
0, nullptr, nullptr, write_barriers);
|
0, nullptr, nullptr, write_barriers);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool CanBlitNatively(const Device& device, PixelFormat format) {
|
||||||
|
static constexpr auto OPTIMAL_FORMAT = FormatType::Optimal;
|
||||||
|
static constexpr VkFormatFeatureFlags BLIT_USAGE =
|
||||||
|
VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT;
|
||||||
|
const VkFormat vk_format =
|
||||||
|
MaxwellToVK::SurfaceFormat(device, OPTIMAL_FORMAT, false, format).format;
|
||||||
|
return device.IsFormatSupported(vk_format, BLIT_USAGE, OPTIMAL_FORMAT);
|
||||||
|
}
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
||||||
TextureCacheRuntime::TextureCacheRuntime(const Device& device_, Scheduler& scheduler_,
|
TextureCacheRuntime::TextureCacheRuntime(const Device& device_, Scheduler& scheduler_,
|
||||||
@@ -1228,27 +1236,19 @@ void TextureCacheRuntime::BlitImage(Framebuffer* dst_framebuffer, ImageView& dst
|
|||||||
blit_image_helper.ResolveDepthStencil(dst_framebuffer, src, dst_region, src_region);
|
blit_image_helper.ResolveDepthStencil(dst_framebuffer, src, dst_region, src_region);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (aspect_mask == (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
|
static constexpr VkImageAspectFlags DEPTH_STENCIL_ASPECTS =
|
||||||
const auto format = src.format;
|
VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||||
const auto can_blit_depth_stencil = [this, format] {
|
if ((aspect_mask & DEPTH_STENCIL_ASPECTS) != 0 && !CanBlitNatively(device, src.format)) {
|
||||||
switch (format) {
|
if (aspect_mask != DEPTH_STENCIL_ASPECTS) {
|
||||||
case VideoCore::Surface::PixelFormat::D24_UNORM_S8_UINT:
|
UNIMPLEMENTED_MSG("Host cannot blit format {} and no helper path exists for aspect "
|
||||||
case VideoCore::Surface::PixelFormat::S8_UINT_D24_UNORM:
|
"mask 0x{:x}",
|
||||||
return device.IsBlitDepth24Stencil8Supported();
|
src.format, aspect_mask);
|
||||||
case VideoCore::Surface::PixelFormat::D32_FLOAT_S8_UINT:
|
|
||||||
return device.IsBlitDepth32Stencil8Supported();
|
|
||||||
default:
|
|
||||||
UNREACHABLE();
|
|
||||||
}
|
|
||||||
}();
|
|
||||||
// Use shader-based depth/stencil blits if hardware doesn't support the format
|
|
||||||
// Note: MSAA resolves (MSAA->single) use vkCmdResolveImage which works fine
|
|
||||||
if (!can_blit_depth_stencil) {
|
|
||||||
UNIMPLEMENTED_IF(is_src_msaa || is_dst_msaa);
|
|
||||||
blit_image_helper.BlitDepthStencil(dst_framebuffer, src, dst_region, src_region,
|
|
||||||
filter, operation);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
UNIMPLEMENTED_IF(is_src_msaa || is_dst_msaa);
|
||||||
|
blit_image_helper.BlitDepthStencil(dst_framebuffer, src, dst_region, src_region, filter,
|
||||||
|
operation);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
ASSERT(!(is_dst_msaa && !is_src_msaa));
|
ASSERT(!(is_dst_msaa && !is_src_msaa));
|
||||||
ASSERT(operation == Fermi2D::Operation::SrcCopy);
|
ASSERT(operation == Fermi2D::Operation::SrcCopy);
|
||||||
@@ -1643,7 +1643,14 @@ void TextureCacheRuntime::CopyImageMSAA(Image& dst, Image& src,
|
|||||||
const u32 num_samples = msaa_to_non_msaa ? src.info.num_samples : dst.info.num_samples;
|
const u32 num_samples = msaa_to_non_msaa ? src.info.num_samples : dst.info.num_samples;
|
||||||
if (dst.AspectMask() != VK_IMAGE_ASPECT_COLOR_BIT ||
|
if (dst.AspectMask() != VK_IMAGE_ASPECT_COLOR_BIT ||
|
||||||
VideoCore::Surface::IsPixelFormatInteger(dst.info.format)) {
|
VideoCore::Surface::IsPixelFormatInteger(dst.info.format)) {
|
||||||
UNIMPLEMENTED_MSG("Copying images with different samples is not supported.");
|
const u64 key{(static_cast<u64>(dst.AspectMask()) << 32) |
|
||||||
|
static_cast<u64>(dst.info.format)};
|
||||||
|
if (unsupported_msaa_resolves.insert(key).second) {
|
||||||
|
LOG_WARNING(Render_Vulkan,
|
||||||
|
"MSAA resolve unsupported: format={}, aspect={:#x}, samples {}->{}",
|
||||||
|
dst.info.format, dst.AspectMask(), src.info.num_samples,
|
||||||
|
dst.info.num_samples);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ENABLE_MSAA_RESOLVE_CONSUME && msaa_to_non_msaa && copies.size() == 1 &&
|
if (ENABLE_MSAA_RESOLVE_CONSUME && msaa_to_non_msaa && copies.size() == 1 &&
|
||||||
@@ -1753,6 +1760,20 @@ void TextureCacheRuntime::CopyImageMSAA(Image& dst, Image& src,
|
|||||||
src.info.format, num_samples, copies, msaa_to_non_msaa);
|
src.info.format, num_samples, copies, msaa_to_non_msaa);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u64 TextureCacheRuntime::CurrentSyncPoint() const noexcept {
|
||||||
|
return scheduler.CurrentTick();
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 TextureCacheRuntime::CompletedSyncPoint() const {
|
||||||
|
auto& master_semaphore = scheduler.GetMasterSemaphore();
|
||||||
|
master_semaphore.Refresh();
|
||||||
|
return master_semaphore.KnownGpuTick();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextureCacheRuntime::WaitSyncPoint(u64 sync_point) {
|
||||||
|
scheduler.Wait(sync_point);
|
||||||
|
}
|
||||||
|
|
||||||
u64 TextureCacheRuntime::GetDeviceLocalMemory() const {
|
u64 TextureCacheRuntime::GetDeviceLocalMemory() const {
|
||||||
return device.GetDeviceLocalMemory();
|
return device.GetDeviceLocalMemory();
|
||||||
}
|
}
|
||||||
@@ -1761,6 +1782,10 @@ u64 TextureCacheRuntime::GetDeviceMemoryUsage() const {
|
|||||||
return device.GetDeviceMemoryUsage();
|
return device.GetDeviceMemoryUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u64 TextureCacheRuntime::GetDeviceAllocationUsage() const {
|
||||||
|
return device.GetMemoryBudgetInfo().allocation_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
bool TextureCacheRuntime::CanReportMemoryUsage() const {
|
bool TextureCacheRuntime::CanReportMemoryUsage() const {
|
||||||
return device.CanReportMemoryUsage();
|
return device.CanReportMemoryUsage();
|
||||||
}
|
}
|
||||||
@@ -1770,6 +1795,7 @@ std::optional<size_t> TextureCacheRuntime::GetSamplerHeapBudget() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextureCacheRuntime::TickFrame() {
|
void TextureCacheRuntime::TickFrame() {
|
||||||
|
device.TickAllocatorFrame();
|
||||||
std::erase_if(pending_msaa_images, [this](const auto& pending) {
|
std::erase_if(pending_msaa_images, [this](const auto& pending) {
|
||||||
return scheduler.IsFree(pending.first);
|
return scheduler.IsFree(pending.first);
|
||||||
});
|
});
|
||||||
@@ -1780,12 +1806,7 @@ Image::Image(TextureCacheRuntime& runtime_, const ImageInfo& info_, GPUVAddr gpu
|
|||||||
: VideoCommon::ImageBase(info_, gpu_addr_, cpu_addr_), scheduler{&runtime_.scheduler},
|
: VideoCommon::ImageBase(info_, gpu_addr_, cpu_addr_), scheduler{&runtime_.scheduler},
|
||||||
runtime{&runtime_},
|
runtime{&runtime_},
|
||||||
original_image(MakeImage(runtime_.device, runtime_.memory_allocator, info,
|
original_image(MakeImage(runtime_.device, runtime_.memory_allocator, info,
|
||||||
WillUseWidenedAstcFormat(runtime_.device, info)
|
runtime->ViewFormats(info.format))),
|
||||||
? std::span<const VkFormat>{}
|
|
||||||
: runtime->ViewFormats(info.format),
|
|
||||||
WillUseWidenedAstcFormat(runtime_.device, info)
|
|
||||||
? std::make_optional(VK_FORMAT_R32G32B32A32_SFLOAT)
|
|
||||||
: std::nullopt)),
|
|
||||||
aspect_mask(ImageAspectMask(info.format)) {
|
aspect_mask(ImageAspectMask(info.format)) {
|
||||||
if (IsPixelFormatASTC(info.format) && !runtime->device.IsOptimalAstcSupported()) {
|
if (IsPixelFormatASTC(info.format) && !runtime->device.IsOptimalAstcSupported()) {
|
||||||
switch (Settings::values.accelerate_astc.GetValue()) {
|
switch (Settings::values.accelerate_astc.GetValue()) {
|
||||||
@@ -1816,9 +1837,7 @@ Image::Image(TextureCacheRuntime& runtime_, const ImageInfo& info_, GPUVAddr gpu
|
|||||||
Settings::values.astc_recompression.GetValue() ==
|
Settings::values.astc_recompression.GetValue() ==
|
||||||
Settings::AstcRecompression::Uncompressed) {
|
Settings::AstcRecompression::Uncompressed) {
|
||||||
const auto& device = runtime->device.GetLogical();
|
const auto& device = runtime->device.GetLogical();
|
||||||
const VkFormat storage_format = WillUseWidenedAstcFormat(runtime->device, info)
|
const VkFormat storage_format = VK_FORMAT_A8B8G8R8_UNORM_PACK32;
|
||||||
? VK_FORMAT_R32G32B32A32_SFLOAT
|
|
||||||
: VK_FORMAT_A8B8G8R8_UNORM_PACK32;
|
|
||||||
for (s32 level = 0; level < info.resources.levels; ++level) {
|
for (s32 level = 0; level < info.resources.levels; ++level) {
|
||||||
storage_image_views[level] =
|
storage_image_views[level] =
|
||||||
MakeStorageView(device, level, *original_image, storage_format);
|
MakeStorageView(device, level, *original_image, storage_format);
|
||||||
@@ -1892,9 +1911,11 @@ void Image::UploadMemory(VkBuffer buffer, VkDeviceSize offset,
|
|||||||
ScaleDown(true);
|
ScaleDown(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool wants_msaa_upload = info.num_samples > 1
|
const bool is_color_upload = (aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != 0
|
||||||
&& (aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != 0
|
|
||||||
&& !VideoCore::Surface::IsPixelFormatInteger(info.format);
|
&& !VideoCore::Surface::IsPixelFormatInteger(info.format);
|
||||||
|
const bool is_depth_upload = (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != 0;
|
||||||
|
const bool wants_msaa_upload =
|
||||||
|
info.num_samples > 1 && (is_color_upload || is_depth_upload);
|
||||||
|
|
||||||
if (wants_msaa_upload) {
|
if (wants_msaa_upload) {
|
||||||
ImageInfo temp_info = info;
|
ImageInfo temp_info = info;
|
||||||
@@ -1933,10 +1954,10 @@ void Image::UploadMemory(VkBuffer buffer, VkDeviceSize offset,
|
|||||||
image_copies.push_back(image_copy);
|
image_copies.push_back(image_copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runtime->TransitionImageLayout(*this);
|
||||||
runtime->blit_image_helper.CopyMSAA(runtime->render_pass_cache, Handle(), info.format,
|
runtime->blit_image_helper.CopyMSAA(runtime->render_pass_cache, Handle(), info.format,
|
||||||
temp_vk_image, info.format, info.num_samples,
|
temp_vk_image, info.format, info.num_samples,
|
||||||
image_copies, false);
|
image_copies, false);
|
||||||
initialized = true;
|
|
||||||
runtime->pending_msaa_images.emplace_back(scheduler->CurrentTick(), std::move(temp_image));
|
runtime->pending_msaa_images.emplace_back(scheduler->CurrentTick(), std::move(temp_image));
|
||||||
|
|
||||||
if (is_rescaled) {
|
if (is_rescaled) {
|
||||||
@@ -1947,6 +1968,9 @@ void Image::UploadMemory(VkBuffer buffer, VkDeviceSize offset,
|
|||||||
|
|
||||||
if (info.num_samples > 1) {
|
if (info.num_samples > 1) {
|
||||||
LOG_WARNING(Render_Vulkan, "MSAA upload not implemented for format {}", info.format);
|
LOG_WARNING(Render_Vulkan, "MSAA upload not implemented for format {}", info.format);
|
||||||
|
if (runtime != nullptr) {
|
||||||
|
runtime->TransitionImageLayout(*this);
|
||||||
|
}
|
||||||
if (is_rescaled) {
|
if (is_rescaled) {
|
||||||
ScaleUp();
|
ScaleUp();
|
||||||
}
|
}
|
||||||
@@ -2204,9 +2228,7 @@ VkImageView Image::StorageImageView(s32 level) noexcept {
|
|||||||
auto format_info =
|
auto format_info =
|
||||||
MaxwellToVK::SurfaceFormat(runtime->device, FormatType::Optimal, true, info.format);
|
MaxwellToVK::SurfaceFormat(runtime->device, FormatType::Optimal, true, info.format);
|
||||||
if (WillUseAcceleratedAstcDecode(runtime->device, info)) {
|
if (WillUseAcceleratedAstcDecode(runtime->device, info)) {
|
||||||
format_info.format = WillUseWidenedAstcFormat(runtime->device, info)
|
format_info.format = VK_FORMAT_A8B8G8R8_UNORM_PACK32;
|
||||||
? VK_FORMAT_R32G32B32A32_SFLOAT
|
|
||||||
: VK_FORMAT_A8B8G8R8_UNORM_PACK32;
|
|
||||||
}
|
}
|
||||||
view = MakeStorageView(runtime->device.GetLogical(), level, *(this->*current_image),
|
view = MakeStorageView(runtime->device.GetLogical(), level, *(this->*current_image),
|
||||||
format_info.format);
|
format_info.format);
|
||||||
@@ -2382,11 +2404,7 @@ ImageView::ImageView(TextureCacheRuntime& runtime, const VideoCommon::ImageViewI
|
|||||||
SanitizeDepthStencilSwizzle(swizzle, device->SupportsDepthStencilSwizzleOne());
|
SanitizeDepthStencilSwizzle(swizzle, device->SupportsDepthStencilSwizzleOne());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uses_widened_astc_format = WillUseWidenedAstcFormat(*device, image.info);
|
|
||||||
auto format_info = MaxwellToVK::SurfaceFormat(*device, FormatType::Optimal, true, format);
|
auto format_info = MaxwellToVK::SurfaceFormat(*device, FormatType::Optimal, true, format);
|
||||||
if (uses_widened_astc_format) {
|
|
||||||
format_info.format = VK_FORMAT_R32G32B32A32_SFLOAT;
|
|
||||||
}
|
|
||||||
if (device->ApiVersion() >= VK_API_VERSION_1_3) {
|
if (device->ApiVersion() >= VK_API_VERSION_1_3) {
|
||||||
const VkFormatProperties3 properties3 =
|
const VkFormatProperties3 properties3 =
|
||||||
device->GetPhysical().GetFormatProperties3(format_info.format);
|
device->GetPhysical().GetFormatProperties3(format_info.format);
|
||||||
@@ -2529,14 +2547,12 @@ VkImageView ImageView::StorageView(Shader::TextureType texture_type,
|
|||||||
Shader::ImageFormat image_format) {
|
Shader::ImageFormat image_format) {
|
||||||
if (image_handle) {
|
if (image_handle) {
|
||||||
if (image_format == Shader::ImageFormat::Typeless) {
|
if (image_format == Shader::ImageFormat::Typeless) {
|
||||||
if (!typeless_storage_view) {
|
auto& view{typeless_storage_views[static_cast<size_t>(texture_type)]};
|
||||||
|
if (!view) {
|
||||||
auto info = MaxwellToVK::SurfaceFormat(*device, FormatType::Optimal, true, format);
|
auto info = MaxwellToVK::SurfaceFormat(*device, FormatType::Optimal, true, format);
|
||||||
if (uses_widened_astc_format) {
|
view = MakeView(info.format, VK_IMAGE_ASPECT_COLOR_BIT, texture_type);
|
||||||
info.format = VK_FORMAT_R32G32B32A32_SFLOAT;
|
|
||||||
}
|
|
||||||
typeless_storage_view = MakeView(info.format, VK_IMAGE_ASPECT_COLOR_BIT, texture_type);
|
|
||||||
}
|
}
|
||||||
return *typeless_storage_view;
|
return *view;
|
||||||
}
|
}
|
||||||
const bool is_signed = image_format == Shader::ImageFormat::R8_SINT
|
const bool is_signed = image_format == Shader::ImageFormat::R8_SINT
|
||||||
|| image_format == Shader::ImageFormat::R16_SINT;
|
|| image_format == Shader::ImageFormat::R16_SINT;
|
||||||
|
|||||||
@@ -60,10 +60,22 @@ public:
|
|||||||
|
|
||||||
void TickFrame();
|
void TickFrame();
|
||||||
|
|
||||||
|
u64 CurrentSyncPoint() const noexcept;
|
||||||
|
|
||||||
|
u64 CompletedSyncPoint() const;
|
||||||
|
|
||||||
|
void WaitSyncPoint(u64 sync_point);
|
||||||
|
|
||||||
u64 GetDeviceLocalMemory() const;
|
u64 GetDeviceLocalMemory() const;
|
||||||
|
|
||||||
u64 GetDeviceMemoryUsage() const;
|
u64 GetDeviceMemoryUsage() const;
|
||||||
|
|
||||||
|
u64 GetDeviceAllocationUsage() const;
|
||||||
|
|
||||||
|
bool CanReportAllocationUsage() const noexcept {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool CanReportMemoryUsage() const;
|
bool CanReportMemoryUsage() const;
|
||||||
|
|
||||||
std::optional<size_t> GetSamplerHeapBudget() const;
|
std::optional<size_t> GetSamplerHeapBudget() const;
|
||||||
@@ -156,6 +168,7 @@ public:
|
|||||||
std::array<vk::Buffer, indexing_slots> buffers{};
|
std::array<vk::Buffer, indexing_slots> buffers{};
|
||||||
std::vector<std::pair<u64, vk::Image>> pending_msaa_images;
|
std::vector<std::pair<u64, vk::Image>> pending_msaa_images;
|
||||||
ankerl::unordered_dense::map<VkImage, ResolveShadow> resolve_shadows;
|
ankerl::unordered_dense::map<VkImage, ResolveShadow> resolve_shadows;
|
||||||
|
ankerl::unordered_dense::set<u64> unsupported_msaa_resolves;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Framebuffer {
|
class Framebuffer {
|
||||||
@@ -426,7 +439,7 @@ private:
|
|||||||
|
|
||||||
std::array<vk::ImageView, Shader::NUM_TEXTURE_TYPES> image_views;
|
std::array<vk::ImageView, Shader::NUM_TEXTURE_TYPES> image_views;
|
||||||
std::optional<StorageViews> storage_views;
|
std::optional<StorageViews> storage_views;
|
||||||
vk::ImageView typeless_storage_view;
|
std::array<vk::ImageView, Shader::NUM_TEXTURE_TYPES> typeless_storage_views;
|
||||||
vk::ImageView depth_view;
|
vk::ImageView depth_view;
|
||||||
vk::ImageView stencil_view;
|
vk::ImageView stencil_view;
|
||||||
vk::ImageView color_view;
|
vk::ImageView color_view;
|
||||||
@@ -436,7 +449,6 @@ private:
|
|||||||
VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
|
VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
u32 buffer_size = 0;
|
u32 buffer_size = 0;
|
||||||
|
|
||||||
bool uses_widened_astc_format = false;
|
|
||||||
bool supports_depth_comparison = false;
|
bool supports_depth_comparison = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -487,6 +499,7 @@ struct TextureCacheParams {
|
|||||||
static constexpr bool HAS_EMULATED_COPIES = false;
|
static constexpr bool HAS_EMULATED_COPIES = false;
|
||||||
static constexpr bool HAS_DEVICE_MEMORY_INFO = true;
|
static constexpr bool HAS_DEVICE_MEMORY_INFO = true;
|
||||||
static constexpr bool IMPLEMENTS_ASYNC_DOWNLOADS = true;
|
static constexpr bool IMPLEMENTS_ASYNC_DOWNLOADS = true;
|
||||||
|
static constexpr bool HAS_TIMELINE_SYNC_POINTS = true;
|
||||||
|
|
||||||
using Runtime = Vulkan::TextureCacheRuntime;
|
using Runtime = Vulkan::TextureCacheRuntime;
|
||||||
using Image = Vulkan::Image;
|
using Image = Vulkan::Image;
|
||||||
|
|||||||
@@ -16,8 +16,9 @@
|
|||||||
|
|
||||||
namespace Vulkan {
|
namespace Vulkan {
|
||||||
|
|
||||||
UpdateDescriptorQueue::UpdateDescriptorQueue(const Device& device_)
|
UpdateDescriptorQueue::UpdateDescriptorQueue(const Device& device_, size_t frame_payload_size_)
|
||||||
: device{device_}
|
: device{device_}, frame_payload_size{frame_payload_size_},
|
||||||
|
payload(frame_payload_size_ * FRAMES_IN_FLIGHT)
|
||||||
{
|
{
|
||||||
payload_start = payload.data();
|
payload_start = payload.data();
|
||||||
payload_cursor = payload.data();
|
payload_cursor = payload.data();
|
||||||
@@ -29,19 +30,19 @@ void UpdateDescriptorQueue::TickFrame() {
|
|||||||
if (++frame_index >= FRAMES_IN_FLIGHT) {
|
if (++frame_index >= FRAMES_IN_FLIGHT) {
|
||||||
frame_index = 0;
|
frame_index = 0;
|
||||||
}
|
}
|
||||||
payload_start = payload.data() + frame_index * FRAME_PAYLOAD_SIZE;
|
payload_start = payload.data() + frame_index * frame_payload_size;
|
||||||
payload_cursor = payload_start;
|
payload_cursor = payload_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateDescriptorQueue::Acquire(Scheduler& scheduler, size_t required_entries) {
|
void UpdateDescriptorQueue::Acquire(Scheduler& scheduler, size_t required_entries) {
|
||||||
static constexpr size_t DEFAULT_REQUIRED_ENTRIES = 0x400;
|
static constexpr size_t DEFAULT_REQUIRED_ENTRIES = 0x400;
|
||||||
const size_t reserve = required_entries > 0 ? required_entries : DEFAULT_REQUIRED_ENTRIES;
|
const size_t reserve = required_entries > 0 ? required_entries : DEFAULT_REQUIRED_ENTRIES;
|
||||||
ASSERT_MSG(reserve < FRAME_PAYLOAD_SIZE, "Descriptor reservation {} >= frame capacity {}",
|
ASSERT_MSG(reserve < frame_payload_size, "Descriptor reservation {} >= frame capacity {}",
|
||||||
reserve, FRAME_PAYLOAD_SIZE);
|
reserve, frame_payload_size);
|
||||||
const size_t used = static_cast<size_t>(std::distance(payload_start, payload_cursor));
|
const size_t used = static_cast<size_t>(std::distance(payload_start, payload_cursor));
|
||||||
if (used + reserve >= FRAME_PAYLOAD_SIZE) {
|
if (used + reserve >= frame_payload_size) {
|
||||||
LOG_WARNING(Render_Vulkan, "Payload overflow (used={}, reserve={}, capacity={})",
|
LOG_WARNING(Render_Vulkan, "Payload overflow (used={}, reserve={}, capacity={})",
|
||||||
used, reserve, FRAME_PAYLOAD_SIZE);
|
used, reserve, frame_payload_size);
|
||||||
scheduler.WaitWorker();
|
scheduler.WaitWorker();
|
||||||
payload_cursor = payload_start;
|
payload_cursor = payload_start;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
#include <vector>
|
||||||
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
||||||
|
|
||||||
namespace Vulkan {
|
namespace Vulkan {
|
||||||
@@ -30,11 +30,12 @@ class UpdateDescriptorQueue final {
|
|||||||
// This should be plenty for the vast majority of cases. Most desktop platforms only
|
// This should be plenty for the vast majority of cases. Most desktop platforms only
|
||||||
// provide up to 3 swapchain images.
|
// provide up to 3 swapchain images.
|
||||||
static constexpr size_t FRAMES_IN_FLIGHT = 8;
|
static constexpr size_t FRAMES_IN_FLIGHT = 8;
|
||||||
static constexpr size_t FRAME_PAYLOAD_SIZE = 0x20000;
|
|
||||||
static constexpr size_t PAYLOAD_SIZE = FRAME_PAYLOAD_SIZE * FRAMES_IN_FLIGHT;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit UpdateDescriptorQueue(const Device& device_);
|
static constexpr size_t GUEST_FRAME_PAYLOAD_SIZE = 0x80000;
|
||||||
|
static constexpr size_t COMPUTE_FRAME_PAYLOAD_SIZE = 0x20000;
|
||||||
|
|
||||||
|
explicit UpdateDescriptorQueue(const Device& device_, size_t frame_payload_size_);
|
||||||
~UpdateDescriptorQueue();
|
~UpdateDescriptorQueue();
|
||||||
|
|
||||||
void TickFrame();
|
void TickFrame();
|
||||||
@@ -74,11 +75,12 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const Device& device;
|
const Device& device;
|
||||||
|
const size_t frame_payload_size;
|
||||||
size_t frame_index{0};
|
size_t frame_index{0};
|
||||||
DescriptorUpdateEntry* payload_cursor = nullptr;
|
DescriptorUpdateEntry* payload_cursor = nullptr;
|
||||||
DescriptorUpdateEntry* payload_start = nullptr;
|
DescriptorUpdateEntry* payload_start = nullptr;
|
||||||
const DescriptorUpdateEntry* upload_start = nullptr;
|
const DescriptorUpdateEntry* upload_start = nullptr;
|
||||||
std::array<DescriptorUpdateEntry, PAYLOAD_SIZE> payload;
|
std::vector<DescriptorUpdateEntry> payload;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: should these be separate classes instead?
|
// TODO: should these be separate classes instead?
|
||||||
|
|||||||
@@ -284,7 +284,24 @@ std::optional<u64> GenericEnvironment::TryFindSize() {
|
|||||||
Tegra::Texture::TICEntry GenericEnvironment::ReadTextureInfo(GPUVAddr tic_addr, u32 tic_limit,
|
Tegra::Texture::TICEntry GenericEnvironment::ReadTextureInfo(GPUVAddr tic_addr, u32 tic_limit,
|
||||||
bool via_header_index, u32 raw) {
|
bool via_header_index, u32 raw) {
|
||||||
const auto handle{Tegra::Texture::TexturePair(raw, via_header_index)};
|
const auto handle{Tegra::Texture::TexturePair(raw, via_header_index)};
|
||||||
ASSERT(handle.first <= tic_limit);
|
if (handle.first > tic_limit) {
|
||||||
|
LOG_CRITICAL(Shader,
|
||||||
|
"TIC index out of range: raw=0x{:08x} tic_index={} tsc_index={} tic_limit={} "
|
||||||
|
"tic_addr=0x{:x} via_header_index={} stage={} program_base=0x{:x} "
|
||||||
|
"start_address=0x{:x}",
|
||||||
|
raw, handle.first, handle.second, tic_limit, tic_addr, via_header_index,
|
||||||
|
static_cast<u32>(stage), program_base, start_address);
|
||||||
|
ASSERT(handle.first <= tic_limit);
|
||||||
|
Tegra::Texture::TICEntry fallback{};
|
||||||
|
fallback.format.Assign(Tegra::Texture::TextureFormat::A8B8G8R8);
|
||||||
|
fallback.r_type.Assign(Tegra::Texture::ComponentType::UNORM);
|
||||||
|
fallback.g_type.Assign(Tegra::Texture::ComponentType::UNORM);
|
||||||
|
fallback.b_type.Assign(Tegra::Texture::ComponentType::UNORM);
|
||||||
|
fallback.a_type.Assign(Tegra::Texture::ComponentType::UNORM);
|
||||||
|
fallback.texture_type.Assign(Tegra::Texture::TextureType::Texture2D);
|
||||||
|
fallback.normalized_coords.Assign(1);
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
const GPUVAddr descriptor_addr{tic_addr + handle.first * sizeof(Tegra::Texture::TICEntry)};
|
const GPUVAddr descriptor_addr{tic_addr + handle.first * sizeof(Tegra::Texture::TICEntry)};
|
||||||
Tegra::Texture::TICEntry entry;
|
Tegra::Texture::TICEntry entry;
|
||||||
gpu_memory->ReadBlock(descriptor_addr, &entry, sizeof(entry));
|
gpu_memory->ReadBlock(descriptor_addr, &entry, sizeof(entry));
|
||||||
|
|||||||
@@ -58,23 +58,9 @@ TextureCache<P>::TextureCache(Runtime& runtime_, Tegra::MaxwellDeviceMemoryManag
|
|||||||
void(slot_samplers.insert(runtime, sampler_descriptor));
|
void(slot_samplers.insert(runtime, sampler_descriptor));
|
||||||
|
|
||||||
if constexpr (HAS_DEVICE_MEMORY_INFO) {
|
if constexpr (HAS_DEVICE_MEMORY_INFO) {
|
||||||
const s64 device_local_memory = static_cast<s64>(runtime.GetDeviceLocalMemory());
|
memory_budget = runtime.GetDeviceLocalMemory();
|
||||||
const s64 min_spacing_expected = device_local_memory - 1_GiB;
|
|
||||||
const s64 min_spacing_critical = device_local_memory - 512_MiB;
|
|
||||||
const s64 mem_threshold = (std::min)(device_local_memory, TARGET_THRESHOLD);
|
|
||||||
const s64 min_vacancy_expected = (6 * mem_threshold) / 10;
|
|
||||||
const s64 min_vacancy_critical = (2 * mem_threshold) / 10;
|
|
||||||
expected_memory = static_cast<u64>(
|
|
||||||
(std::max)((std::min)(device_local_memory - min_vacancy_expected, min_spacing_expected),
|
|
||||||
DEFAULT_EXPECTED_MEMORY));
|
|
||||||
critical_memory = static_cast<u64>(
|
|
||||||
(std::max)((std::min)(device_local_memory - min_vacancy_critical, min_spacing_critical),
|
|
||||||
DEFAULT_CRITICAL_MEMORY));
|
|
||||||
minimum_memory = static_cast<u64>((device_local_memory - mem_threshold) / 2);
|
|
||||||
} else {
|
} else {
|
||||||
expected_memory = DEFAULT_EXPECTED_MEMORY + 512_MiB;
|
memory_budget = FALLBACK_MEMORY_BUDGET;
|
||||||
critical_memory = DEFAULT_CRITICAL_MEMORY + 1_GiB;
|
|
||||||
minimum_memory = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool gpu_unswizzle_enabled = Settings::values.gpu_unswizzle_enabled.GetValue();
|
const bool gpu_unswizzle_enabled = Settings::values.gpu_unswizzle_enabled.GetValue();
|
||||||
@@ -114,71 +100,154 @@ TextureCache<P>::TextureCache(Runtime& runtime_, Tegra::MaxwellDeviceMemoryManag
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
void TextureCache<P>::RunGarbageCollector() {
|
void TextureCache<P>::QueueEvictionDownload(Image& image) {
|
||||||
bool high_priority_mode = false;
|
auto copies = FullDownloadCopies(image.info);
|
||||||
bool aggressive_mode = false;
|
auto staging = runtime.DownloadStagingBuffer(image.unswizzled_size_bytes, true);
|
||||||
u64 ticks_to_destroy = 0;
|
image.DownloadMemory(staging, FixSmallVectorADL(copies));
|
||||||
size_t num_iterations = 0;
|
pending_eviction_downloads.push_back(PendingEvictionDownload{
|
||||||
const auto Configure = [&](bool allow_aggressive) {
|
.staging = staging,
|
||||||
high_priority_mode = total_used_memory >= expected_memory;
|
.gpu_memory = gpu_memory,
|
||||||
aggressive_mode = allow_aggressive && total_used_memory >= critical_memory;
|
.copies = std::move(copies),
|
||||||
ticks_to_destroy = aggressive_mode ? 10ULL : high_priority_mode ? 25ULL : 50ULL;
|
.info = image.info,
|
||||||
num_iterations = aggressive_mode ? 40 : (high_priority_mode ? 20 : 10);
|
.gpu_addr = image.gpu_addr,
|
||||||
};
|
.sync_point = runtime.CurrentSyncPoint(),
|
||||||
const auto Cleanup = [this, &num_iterations, &high_priority_mode, &aggressive_mode](ImageId image_id) {
|
});
|
||||||
if (num_iterations == 0) {
|
}
|
||||||
return true;
|
|
||||||
}
|
template <class P>
|
||||||
--num_iterations;
|
void TextureCache<P>::TickEvictionDownloads(u64 completed_sync_point) {
|
||||||
auto& image = slot_images[image_id];
|
while (!pending_eviction_downloads.empty() &&
|
||||||
if (True(image.flags & ImageFlagBits::IsDecoding)) {
|
pending_eviction_downloads.front().sync_point <= completed_sync_point) {
|
||||||
return false;
|
auto& entry = pending_eviction_downloads.front();
|
||||||
}
|
SwizzleImage(*entry.gpu_memory, entry.gpu_addr, entry.info, FixSmallVectorADL(entry.copies),
|
||||||
const bool must_download = image.IsSafeDownload() && False(image.flags & ImageFlagBits::BadOverlap);
|
entry.staging.mapped_span.subspan(entry.staging.offset), swizzle_data_buffer);
|
||||||
if ((!aggressive_mode && True(image.flags & ImageFlagBits::CostlyLoad)) || (!high_priority_mode && must_download)) {
|
runtime.FreeDeferredStagingBuffer(entry.staging);
|
||||||
return false;
|
pending_eviction_downloads.pop_front();
|
||||||
}
|
|
||||||
if (must_download) {
|
|
||||||
auto map = runtime.DownloadStagingBuffer(image.unswizzled_size_bytes);
|
|
||||||
const auto copies = FixSmallVectorADL(FullDownloadCopies(image.info));
|
|
||||||
image.DownloadMemory(map, copies);
|
|
||||||
runtime.Finish();
|
|
||||||
SwizzleImage(*gpu_memory, image.gpu_addr, image.info, copies, map.mapped_span, swizzle_data_buffer);
|
|
||||||
}
|
|
||||||
if (True(image.flags & ImageFlagBits::Tracked)) {
|
|
||||||
UntrackImage(image, image_id);
|
|
||||||
}
|
|
||||||
UnregisterImage(image_id);
|
|
||||||
DeleteImage(image_id, image.scale_tick > frame_tick + 5);
|
|
||||||
if (aggressive_mode && total_used_memory < critical_memory) {
|
|
||||||
num_iterations >>= 2;
|
|
||||||
aggressive_mode = false;
|
|
||||||
} else if (high_priority_mode && total_used_memory < expected_memory) {
|
|
||||||
num_iterations >>= 1;
|
|
||||||
high_priority_mode = false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
Configure(false);
|
|
||||||
lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, Cleanup);
|
|
||||||
if (total_used_memory >= critical_memory) {
|
|
||||||
Configure(true);
|
|
||||||
lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, Cleanup);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class P>
|
||||||
|
void TextureCache<P>::FlushEvictionDownloads() {
|
||||||
|
if (pending_eviction_downloads.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const u64 last_sync_point = pending_eviction_downloads.back().sync_point;
|
||||||
|
runtime.WaitSyncPoint(last_sync_point);
|
||||||
|
TickEvictionDownloads(last_sync_point);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class P>
|
||||||
|
u64 TextureCache<P>::ImageSizeBytes(const ImageBase& image) {
|
||||||
|
u64 tentative_size = (std::max)(image.guest_size_bytes, image.unswizzled_size_bytes);
|
||||||
|
if ((IsPixelFormatASTC(image.info.format) &&
|
||||||
|
True(image.flags & ImageFlagBits::AcceleratedUpload)) ||
|
||||||
|
True(image.flags & ImageFlagBits::Converted)) {
|
||||||
|
tentative_size = TranscodedAstcSize(tentative_size, image.info.format);
|
||||||
|
}
|
||||||
|
u64 size = Common::AlignUp(tentative_size, 1024);
|
||||||
|
if (image.HasScaled()) {
|
||||||
|
size += GetScaledImageSizeBytes(image);
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class P>
|
||||||
|
u64 TextureCache<P>::DeviceUsage(bool force_refresh) {
|
||||||
|
if (!runtime.CanReportAllocationUsage()) {
|
||||||
|
return total_used_memory;
|
||||||
|
}
|
||||||
|
if (force_refresh || usage_refresh_countdown == 0) {
|
||||||
|
cached_device_usage = runtime.GetDeviceAllocationUsage();
|
||||||
|
usage_refresh_countdown = USAGE_REFRESH_INTERVAL;
|
||||||
|
} else {
|
||||||
|
--usage_refresh_countdown;
|
||||||
|
}
|
||||||
|
return cached_device_usage;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class P>
|
||||||
|
u64 TextureCache<P>::ReclaimMemory(u64 target_bytes, bool allow_download) {
|
||||||
|
if (target_bytes == 0 || in_reclaim) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
in_reclaim = true;
|
||||||
|
const u64 drain_point = runtime.CompletedSyncPoint();
|
||||||
|
TickEvictionDownloads(drain_point);
|
||||||
|
sentenced_images.Reclaim(drain_point);
|
||||||
|
sentenced_image_view.Reclaim(drain_point);
|
||||||
|
sentenced_framebuffers.Reclaim(drain_point);
|
||||||
|
u64 freed = 0;
|
||||||
|
const auto evict = [&](ImageId image_id) {
|
||||||
|
if (freed >= target_bytes) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
auto& image = slot_images[image_id];
|
||||||
|
if (True(image.flags & ImageFlagBits::IsDecoding)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const bool must_download =
|
||||||
|
image.IsSafeDownload() && False(image.flags & ImageFlagBits::BadOverlap);
|
||||||
|
bool queued_download = false;
|
||||||
|
if (must_download) {
|
||||||
|
if constexpr (HAS_TIMELINE_SYNC_POINTS) {
|
||||||
|
if (!allow_download) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QueueEvictionDownload(image);
|
||||||
|
queued_download = true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const u64 image_bytes = ImageSizeBytes(image);
|
||||||
|
if (True(image.flags & ImageFlagBits::Tracked)) {
|
||||||
|
UntrackImage(image, image_id);
|
||||||
|
}
|
||||||
|
UnregisterImage(image_id);
|
||||||
|
DeleteImage(image_id, !queued_download && image.scale_tick > frame_tick + 5);
|
||||||
|
freed += image_bytes;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
const u64 cold_tick =
|
||||||
|
frame_tick > RECLAIM_GUARD_FRAMES ? frame_tick - RECLAIM_GUARD_FRAMES : 0;
|
||||||
|
lru_cache.ForEachItemBelow(cold_tick, evict);
|
||||||
|
if (freed < target_bytes) {
|
||||||
|
lru_cache.ForEachItemBelow(frame_tick > 0 ? frame_tick - 1 : 0, evict);
|
||||||
|
}
|
||||||
|
const u64 exit_point = runtime.CompletedSyncPoint();
|
||||||
|
sentenced_images.Reclaim(exit_point);
|
||||||
|
sentenced_image_view.Reclaim(exit_point);
|
||||||
|
sentenced_framebuffers.Reclaim(exit_point);
|
||||||
|
in_reclaim = false;
|
||||||
|
usage_refresh_countdown = 0;
|
||||||
|
reclaim_stalled = freed == 0;
|
||||||
|
return freed;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class P>
|
||||||
|
void TextureCache<P>::EnsureHeadroom(bool allow_download) {
|
||||||
|
if (reclaim_stalled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const u64 limit = memory_budget > RECLAIM_HEADROOM ? memory_budget - RECLAIM_HEADROOM : 0;
|
||||||
|
const u64 usage = DeviceUsage(false);
|
||||||
|
if (usage <= limit) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const u64 target = (limit / 100) * RECLAIM_TARGET_PERCENT;
|
||||||
|
ReclaimMemory((std::min)(usage - target, total_used_memory), allow_download);
|
||||||
|
}
|
||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
void TextureCache<P>::TickFrame() {
|
void TextureCache<P>::TickFrame() {
|
||||||
// If we can obtain the memory info, use it instead of the estimate.
|
usage_refresh_countdown = 0;
|
||||||
if (runtime.CanReportMemoryUsage()) {
|
reclaim_stalled = false;
|
||||||
total_used_memory = runtime.GetDeviceMemoryUsage();
|
EnsureHeadroom(true);
|
||||||
}
|
const u64 completed_sync_point = runtime.CompletedSyncPoint();
|
||||||
if (total_used_memory > minimum_memory) {
|
TickEvictionDownloads(completed_sync_point);
|
||||||
RunGarbageCollector();
|
sentenced_images.Reclaim(completed_sync_point);
|
||||||
}
|
sentenced_framebuffers.Reclaim(completed_sync_point);
|
||||||
sentenced_images.Tick();
|
sentenced_image_view.Reclaim(completed_sync_point);
|
||||||
sentenced_framebuffers.Tick();
|
|
||||||
sentenced_image_view.Tick();
|
|
||||||
TickAsyncDecode();
|
TickAsyncDecode();
|
||||||
TickAsyncUnswizzle();
|
TickAsyncUnswizzle();
|
||||||
|
|
||||||
@@ -596,6 +665,7 @@ void TextureCache<P>::WriteMemory(DAddr cpu_addr, size_t size) {
|
|||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
void TextureCache<P>::DownloadMemory(DAddr cpu_addr, size_t size) {
|
void TextureCache<P>::DownloadMemory(DAddr cpu_addr, size_t size) {
|
||||||
|
FlushEvictionDownloads();
|
||||||
boost::container::small_vector<ImageId, 16> images;
|
boost::container::small_vector<ImageId, 16> images;
|
||||||
ForEachImageInRegion(cpu_addr, size, [&images](ImageId image_id, ImageBase& image) {
|
ForEachImageInRegion(cpu_addr, size, [&images](ImageId image_id, ImageBase& image) {
|
||||||
if (!image.IsSafeDownload()) {
|
if (!image.IsSafeDownload()) {
|
||||||
@@ -894,6 +964,7 @@ void TextureCache<P>::CommitAsyncFlushes() {
|
|||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
void TextureCache<P>::PopAsyncFlushes() {
|
void TextureCache<P>::PopAsyncFlushes() {
|
||||||
|
TickEvictionDownloads(runtime.CompletedSyncPoint());
|
||||||
if (committed_downloads.empty()) {
|
if (committed_downloads.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1294,8 +1365,9 @@ void TextureCache<P>::InvalidateScale(Image& image) {
|
|||||||
}
|
}
|
||||||
RemoveImageViewReferences(image_view_ids);
|
RemoveImageViewReferences(image_view_ids);
|
||||||
RemoveFramebuffers(image_view_ids);
|
RemoveFramebuffers(image_view_ids);
|
||||||
|
const u64 sync_point = runtime.CurrentSyncPoint();
|
||||||
for (const ImageViewId image_view_id : image_view_ids) {
|
for (const ImageViewId image_view_id : image_view_ids) {
|
||||||
sentenced_image_view.Push(std::move(slot_image_views[image_view_id]));
|
sentenced_image_view.Push(std::move(slot_image_views[image_view_id]), sync_point);
|
||||||
slot_image_views.erase(image_view_id);
|
slot_image_views.erase(image_view_id);
|
||||||
}
|
}
|
||||||
image.image_view_ids.clear();
|
image.image_view_ids.clear();
|
||||||
@@ -1331,6 +1403,7 @@ void TextureCache<P>::QueueAsyncDecode(Image& image, ImageId image_id) {
|
|||||||
LOG_INFO(HW_GPU, "Queuing async texture decode");
|
LOG_INFO(HW_GPU, "Queuing async texture decode");
|
||||||
|
|
||||||
image.flags |= ImageFlagBits::IsDecoding;
|
image.flags |= ImageFlagBits::IsDecoding;
|
||||||
|
runtime.TransitionImageLayout(image);
|
||||||
auto decode = std::make_unique<AsyncDecodeContext>();
|
auto decode = std::make_unique<AsyncDecodeContext>();
|
||||||
auto* decode_ptr = decode.get();
|
auto* decode_ptr = decode.get();
|
||||||
decode->image_id = image_id;
|
decode->image_id = image_id;
|
||||||
@@ -1363,6 +1436,7 @@ void TextureCache<P>::QueueAsyncUnswizzle(Image& image, ImageId image_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
image.flags |= ImageFlagBits::IsDecoding;
|
image.flags |= ImageFlagBits::IsDecoding;
|
||||||
|
runtime.TransitionImageLayout(image);
|
||||||
|
|
||||||
unswizzle_queue.push_back({
|
unswizzle_queue.push_back({
|
||||||
.image_id = image_id,
|
.image_id = image_id,
|
||||||
@@ -1523,6 +1597,7 @@ ImageId TextureCache<P>::InsertImage(const ImageInfo& info, GPUVAddr gpu_addr,
|
|||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, DAddr cpu_addr) {
|
ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, DAddr cpu_addr) {
|
||||||
|
EnsureHeadroom(false);
|
||||||
ImageInfo new_info = info;
|
ImageInfo new_info = info;
|
||||||
const size_t size_bytes = CalculateGuestSizeInBytes(new_info);
|
const size_t size_bytes = CalculateGuestSizeInBytes(new_info);
|
||||||
const bool broken_views = runtime.HasBrokenTextureViewFormats();
|
const bool broken_views = runtime.HasBrokenTextureViewFormats();
|
||||||
@@ -1631,7 +1706,28 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, DA
|
|||||||
for (const ImageId overlap_id : join_ignore_textures) {
|
for (const ImageId overlap_id : join_ignore_textures) {
|
||||||
Image& overlap = slot_images[overlap_id];
|
Image& overlap = slot_images[overlap_id];
|
||||||
if (True(overlap.flags & ImageFlagBits::GpuModified)) {
|
if (True(overlap.flags & ImageFlagBits::GpuModified)) {
|
||||||
UNIMPLEMENTED();
|
if (new_image.TryFindBase(overlap.gpu_addr) &&
|
||||||
|
(!can_rescale || ImageCanRescale(overlap))) {
|
||||||
|
if (can_rescale) {
|
||||||
|
ScaleUp(overlap);
|
||||||
|
} else {
|
||||||
|
ScaleDown(overlap);
|
||||||
|
}
|
||||||
|
join_copies_to_do.emplace_back(JoinCopy{false, overlap_id});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (overlap.IsSafeDownload() && False(overlap.flags & ImageFlagBits::BadOverlap) &&
|
||||||
|
gpu_memory->GpuToCpuAddress(overlap.gpu_addr).has_value()) {
|
||||||
|
QueueEvictionDownload(overlap);
|
||||||
|
} else {
|
||||||
|
LOG_WARNING(HW_GPU,
|
||||||
|
"Dropping GPU modified overlap, contents are not recoverable: "
|
||||||
|
"gpu_addr=0x{:x} format={} size={}x{}x{} levels={} layers={}",
|
||||||
|
overlap.gpu_addr, static_cast<int>(overlap.info.format),
|
||||||
|
overlap.info.size.width, overlap.info.size.height,
|
||||||
|
overlap.info.size.depth, overlap.info.resources.levels,
|
||||||
|
overlap.info.resources.layers);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (True(overlap.flags & ImageFlagBits::Tracked)) {
|
if (True(overlap.flags & ImageFlagBits::Tracked)) {
|
||||||
UntrackImage(overlap, overlap_id);
|
UntrackImage(overlap, overlap_id);
|
||||||
@@ -2185,13 +2281,7 @@ void TextureCache<P>::RegisterImage(ImageId image_id) {
|
|||||||
ASSERT_MSG(False(image.flags & ImageFlagBits::Registered),
|
ASSERT_MSG(False(image.flags & ImageFlagBits::Registered),
|
||||||
"Trying to register an already registered image");
|
"Trying to register an already registered image");
|
||||||
image.flags |= ImageFlagBits::Registered;
|
image.flags |= ImageFlagBits::Registered;
|
||||||
u64 tentative_size = (std::max)(image.guest_size_bytes, image.unswizzled_size_bytes);
|
total_used_memory += ImageSizeBytes(image);
|
||||||
if ((IsPixelFormatASTC(image.info.format) &&
|
|
||||||
True(image.flags & ImageFlagBits::AcceleratedUpload)) ||
|
|
||||||
True(image.flags & ImageFlagBits::Converted)) {
|
|
||||||
tentative_size = TranscodedAstcSize(tentative_size, image.info.format);
|
|
||||||
}
|
|
||||||
total_used_memory += Common::AlignUp(tentative_size, 1024);
|
|
||||||
image.lru_index = lru_cache.Insert(image_id, frame_tick);
|
image.lru_index = lru_cache.Insert(image_id, frame_tick);
|
||||||
|
|
||||||
ForEachGPUPage(image.gpu_addr, image.guest_size_bytes, [this, image_id](u64 page) {
|
ForEachGPUPage(image.gpu_addr, image.guest_size_bytes, [this, image_id](u64 page) {
|
||||||
@@ -2354,16 +2444,7 @@ void TextureCache<P>::UntrackImage(ImageBase& image, ImageId image_id) {
|
|||||||
template <class P>
|
template <class P>
|
||||||
void TextureCache<P>::DeleteImage(ImageId image_id, bool immediate_delete) {
|
void TextureCache<P>::DeleteImage(ImageId image_id, bool immediate_delete) {
|
||||||
ImageBase& image = slot_images[image_id];
|
ImageBase& image = slot_images[image_id];
|
||||||
if (image.HasScaled()) {
|
total_used_memory -= std::min<u64>(total_used_memory, ImageSizeBytes(image));
|
||||||
total_used_memory -= GetScaledImageSizeBytes(image);
|
|
||||||
}
|
|
||||||
u64 tentative_size = (std::max)(image.guest_size_bytes, image.unswizzled_size_bytes);
|
|
||||||
if ((IsPixelFormatASTC(image.info.format) &&
|
|
||||||
True(image.flags & ImageFlagBits::AcceleratedUpload)) ||
|
|
||||||
True(image.flags & ImageFlagBits::Converted)) {
|
|
||||||
tentative_size = TranscodedAstcSize(tentative_size, image.info.format);
|
|
||||||
}
|
|
||||||
total_used_memory -= Common::AlignUp(tentative_size, 1024);
|
|
||||||
const GPUVAddr gpu_addr = image.gpu_addr;
|
const GPUVAddr gpu_addr = image.gpu_addr;
|
||||||
const auto alloc_it = image_allocs_table.find(gpu_addr);
|
const auto alloc_it = image_allocs_table.find(gpu_addr);
|
||||||
if (alloc_it == image_allocs_table.end()) {
|
if (alloc_it == image_allocs_table.end()) {
|
||||||
@@ -2417,14 +2498,15 @@ void TextureCache<P>::DeleteImage(ImageId image_id, bool immediate_delete) {
|
|||||||
ASSERT_MSG(num_removed_overlaps == 1, "Invalid number of removed overlapps: {}",
|
ASSERT_MSG(num_removed_overlaps == 1, "Invalid number of removed overlapps: {}",
|
||||||
num_removed_overlaps);
|
num_removed_overlaps);
|
||||||
}
|
}
|
||||||
|
const u64 sync_point = runtime.CurrentSyncPoint();
|
||||||
for (const ImageViewId image_view_id : image_view_ids) {
|
for (const ImageViewId image_view_id : image_view_ids) {
|
||||||
if (!immediate_delete) {
|
if (!immediate_delete) {
|
||||||
sentenced_image_view.Push(std::move(slot_image_views[image_view_id]));
|
sentenced_image_view.Push(std::move(slot_image_views[image_view_id]), sync_point);
|
||||||
}
|
}
|
||||||
slot_image_views.erase(image_view_id);
|
slot_image_views.erase(image_view_id);
|
||||||
}
|
}
|
||||||
if (!immediate_delete) {
|
if (!immediate_delete) {
|
||||||
sentenced_images.Push(std::move(slot_images[image_id]));
|
sentenced_images.Push(std::move(slot_images[image_id]), sync_point);
|
||||||
}
|
}
|
||||||
slot_images.erase(image_id);
|
slot_images.erase(image_id);
|
||||||
|
|
||||||
@@ -2470,7 +2552,8 @@ void TextureCache<P>::RemoveFramebuffers(std::span<const ImageViewId> removed_vi
|
|||||||
last_framebuffer_id = {};
|
last_framebuffer_id = {};
|
||||||
last_framebuffer_serial = 0;
|
last_framebuffer_serial = 0;
|
||||||
}
|
}
|
||||||
sentenced_framebuffers.Push(std::move(slot_framebuffers[framebuffer_id]));
|
sentenced_framebuffers.Push(std::move(slot_framebuffers[framebuffer_id]),
|
||||||
|
runtime.CurrentSyncPoint());
|
||||||
it = framebuffers.erase(it);
|
it = framebuffers.erase(it);
|
||||||
} else {
|
} else {
|
||||||
++it;
|
++it;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
#include "common/thread_worker.h"
|
#include "common/thread_worker.h"
|
||||||
#include "video_core/compatible_formats.h"
|
#include "video_core/compatible_formats.h"
|
||||||
#include "video_core/control/channel_state_cache.h"
|
#include "video_core/control/channel_state_cache.h"
|
||||||
#include "video_core/delayed_destruction_ring.h"
|
#include "video_core/deferred_destruction_queue.h"
|
||||||
#include "video_core/engines/fermi_2d.h"
|
#include "video_core/engines/fermi_2d.h"
|
||||||
#include "video_core/surface.h"
|
#include "video_core/surface.h"
|
||||||
#include "video_core/texture_cache/descriptor_table.h"
|
#include "video_core/texture_cache/descriptor_table.h"
|
||||||
@@ -108,18 +108,20 @@ class TextureCache : public VideoCommon::ChannelSetupCaches<TextureCacheChannelI
|
|||||||
static constexpr bool HAS_DEVICE_MEMORY_INFO = P::HAS_DEVICE_MEMORY_INFO;
|
static constexpr bool HAS_DEVICE_MEMORY_INFO = P::HAS_DEVICE_MEMORY_INFO;
|
||||||
/// True when the API can do asynchronous texture downloads.
|
/// True when the API can do asynchronous texture downloads.
|
||||||
static constexpr bool IMPLEMENTS_ASYNC_DOWNLOADS = P::IMPLEMENTS_ASYNC_DOWNLOADS;
|
static constexpr bool IMPLEMENTS_ASYNC_DOWNLOADS = P::IMPLEMENTS_ASYNC_DOWNLOADS;
|
||||||
|
static constexpr bool HAS_TIMELINE_SYNC_POINTS = P::HAS_TIMELINE_SYNC_POINTS;
|
||||||
|
|
||||||
static constexpr size_t UNSET_CHANNEL{(std::numeric_limits<size_t>::max)()};
|
static constexpr size_t UNSET_CHANNEL{(std::numeric_limits<size_t>::max)()};
|
||||||
|
|
||||||
#ifdef YUZU_LEGACY
|
#ifdef YUZU_LEGACY
|
||||||
static constexpr s64 TARGET_THRESHOLD = 3_GiB;
|
static constexpr u64 RECLAIM_HEADROOM = 384_MiB;
|
||||||
#else
|
#else
|
||||||
static constexpr s64 TARGET_THRESHOLD = 4_GiB;
|
static constexpr u64 RECLAIM_HEADROOM = 512_MiB;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static constexpr s64 DEFAULT_EXPECTED_MEMORY = 1_GiB + 125_MiB;
|
static constexpr u64 FALLBACK_MEMORY_BUDGET = 2_GiB;
|
||||||
static constexpr s64 DEFAULT_CRITICAL_MEMORY = 1_GiB + 625_MiB;
|
static constexpr u32 USAGE_REFRESH_INTERVAL = 16;
|
||||||
static constexpr size_t GC_EMERGENCY_COUNTS = 2;
|
static constexpr u64 RECLAIM_GUARD_FRAMES = 8;
|
||||||
|
static constexpr u64 RECLAIM_TARGET_PERCENT = 88;
|
||||||
|
|
||||||
using Runtime = typename P::Runtime;
|
using Runtime = typename P::Runtime;
|
||||||
using Image = typename P::Image;
|
using Image = typename P::Image;
|
||||||
@@ -154,6 +156,8 @@ public:
|
|||||||
/// Notify the cache that a new frame has been queued
|
/// Notify the cache that a new frame has been queued
|
||||||
void TickFrame();
|
void TickFrame();
|
||||||
|
|
||||||
|
u64 ReclaimMemory(u64 target_bytes, bool allow_download);
|
||||||
|
|
||||||
/// Return a constant reference to the given image view id
|
/// Return a constant reference to the given image view id
|
||||||
[[nodiscard]] const ImageView& GetImageView(ImageViewId id) const noexcept;
|
[[nodiscard]] const ImageView& GetImageView(ImageViewId id) const noexcept;
|
||||||
|
|
||||||
@@ -293,8 +297,17 @@ private:
|
|||||||
|
|
||||||
void OnGPUASRegister(size_t map_id) final override;
|
void OnGPUASRegister(size_t map_id) final override;
|
||||||
|
|
||||||
/// Runs the Garbage Collector.
|
u64 ImageSizeBytes(const ImageBase& image);
|
||||||
void RunGarbageCollector();
|
|
||||||
|
u64 DeviceUsage(bool force_refresh);
|
||||||
|
|
||||||
|
void EnsureHeadroom(bool allow_download);
|
||||||
|
|
||||||
|
void QueueEvictionDownload(Image& image);
|
||||||
|
|
||||||
|
void TickEvictionDownloads(u64 completed_sync_point);
|
||||||
|
|
||||||
|
void FlushEvictionDownloads();
|
||||||
|
|
||||||
/// Find or create an image view in the guest descriptor table
|
/// Find or create an image view in the guest descriptor table
|
||||||
ImageViewId VisitImageView(u32 index, bool compute);
|
ImageViewId VisitImageView(u32 index, bool compute);
|
||||||
@@ -451,9 +464,11 @@ private:
|
|||||||
bool has_deleted_images = false;
|
bool has_deleted_images = false;
|
||||||
bool is_rescaling = false;
|
bool is_rescaling = false;
|
||||||
u64 total_used_memory = 0;
|
u64 total_used_memory = 0;
|
||||||
u64 minimum_memory;
|
u64 memory_budget = 0;
|
||||||
u64 expected_memory;
|
u64 cached_device_usage = 0;
|
||||||
u64 critical_memory;
|
u32 usage_refresh_countdown = 0;
|
||||||
|
bool in_reclaim = false;
|
||||||
|
bool reclaim_stalled = false;
|
||||||
size_t gpu_unswizzle_maxsize = 0;
|
size_t gpu_unswizzle_maxsize = 0;
|
||||||
size_t swizzle_chunk_size = 0;
|
size_t swizzle_chunk_size = 0;
|
||||||
u32 swizzle_slices_per_batch = 0;
|
u32 swizzle_slices_per_batch = 0;
|
||||||
@@ -491,14 +506,19 @@ private:
|
|||||||
};
|
};
|
||||||
Common::LeastRecentlyUsedCache<LRUItemParams> lru_cache;
|
Common::LeastRecentlyUsedCache<LRUItemParams> lru_cache;
|
||||||
|
|
||||||
#ifdef YUZU_LEGACY
|
DeferredDestructionQueue<Image> sentenced_images;
|
||||||
static constexpr size_t TICKS_TO_DESTROY = 6;
|
DeferredDestructionQueue<ImageView> sentenced_image_view;
|
||||||
#else
|
DeferredDestructionQueue<Framebuffer> sentenced_framebuffers;
|
||||||
static constexpr size_t TICKS_TO_DESTROY = 8;
|
|
||||||
#endif
|
struct PendingEvictionDownload {
|
||||||
DelayedDestructionRing<Image, TICKS_TO_DESTROY> sentenced_images;
|
AsyncBuffer staging;
|
||||||
DelayedDestructionRing<ImageView, TICKS_TO_DESTROY> sentenced_image_view;
|
Tegra::MemoryManager* gpu_memory;
|
||||||
DelayedDestructionRing<Framebuffer, TICKS_TO_DESTROY> sentenced_framebuffers;
|
boost::container::small_vector<VideoCommon::BufferImageCopy, 16> copies;
|
||||||
|
VideoCommon::ImageInfo info;
|
||||||
|
GPUVAddr gpu_addr;
|
||||||
|
u64 sync_point;
|
||||||
|
};
|
||||||
|
std::deque<PendingEvictionDownload> pending_eviction_downloads;
|
||||||
|
|
||||||
ankerl::unordered_dense::map<GPUVAddr, ImageAllocId> image_allocs_table;
|
ankerl::unordered_dense::map<GPUVAddr, ImageAllocId> image_allocs_table;
|
||||||
|
|
||||||
@@ -509,7 +529,8 @@ private:
|
|||||||
u64 frame_tick = 0;
|
u64 frame_tick = 0;
|
||||||
u64 last_sampler_gc_frame = (std::numeric_limits<u64>::max)();
|
u64 last_sampler_gc_frame = (std::numeric_limits<u64>::max)();
|
||||||
|
|
||||||
Common::ThreadWorker texture_decode_worker{1, "TextureDecoder"};
|
Common::ThreadWorker texture_decode_worker{1, "TextureDecoder", {},
|
||||||
|
Common::ThreadPlacement::Background};
|
||||||
std::vector<std::unique_ptr<AsyncDecodeContext>> async_decodes;
|
std::vector<std::unique_ptr<AsyncDecodeContext>> async_decodes;
|
||||||
|
|
||||||
std::deque<PendingUnswizzle> unswizzle_queue;
|
std::deque<PendingUnswizzle> unswizzle_queue;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
@@ -747,7 +747,7 @@ boost::container::small_vector<ImageCopy, 16> MakeShrinkImageCopies(const ImageI
|
|||||||
|
|
||||||
const bool is_dst_3d = dst.type == ImageType::e3D;
|
const bool is_dst_3d = dst.type == ImageType::e3D;
|
||||||
if (is_dst_3d) {
|
if (is_dst_3d) {
|
||||||
ASSERT(src.type == ImageType::e3D);
|
ASSERT(src.type == ImageType::e3D || src.resources.layers == 1);
|
||||||
ASSERT(src.resources.levels == 1);
|
ASSERT(src.resources.levels == 1);
|
||||||
}
|
}
|
||||||
const bool both_2d{src.type == ImageType::e2D && dst.type == ImageType::e2D};
|
const bool both_2d{src.type == ImageType::e2D && dst.type == ImageType::e2D};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
@@ -10,7 +10,8 @@ namespace Tegra::Texture {
|
|||||||
|
|
||||||
Common::ThreadWorker& GetThreadWorkers() {
|
Common::ThreadWorker& GetThreadWorkers() {
|
||||||
static Common::ThreadWorker workers{(std::max)(std::thread::hardware_concurrency(), 2U) / 2,
|
static Common::ThreadWorker workers{(std::max)(std::thread::hardware_concurrency(), 2U) / 2,
|
||||||
"ImageTranscode"};
|
"ImageTranscode", {},
|
||||||
|
Common::ThreadPlacement::Background};
|
||||||
|
|
||||||
return workers;
|
return workers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
@@ -732,7 +733,7 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR
|
|||||||
.device = *logical,
|
.device = *logical,
|
||||||
.preferredLargeHeapBlockSize = is_integrated
|
.preferredLargeHeapBlockSize = is_integrated
|
||||||
? (64u * 1024u * 1024u)
|
? (64u * 1024u * 1024u)
|
||||||
: (256u * 1024u * 1024u),
|
: (128u * 1024u * 1024u),
|
||||||
.pAllocationCallbacks = nullptr,
|
.pAllocationCallbacks = nullptr,
|
||||||
.pDeviceMemoryCallbacks = nullptr,
|
.pDeviceMemoryCallbacks = nullptr,
|
||||||
.pHeapSizeLimit = nullptr,
|
.pHeapSizeLimit = nullptr,
|
||||||
@@ -744,12 +745,32 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR
|
|||||||
|
|
||||||
vk::Check(vmaCreateAllocator(&allocator_info, &allocator));
|
vk::Check(vmaCreateAllocator(&allocator_info, &allocator));
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto& limits = properties.properties.limits;
|
||||||
|
LOG_INFO(Render_Vulkan, "MSAA sample count support:");
|
||||||
|
LOG_INFO(Render_Vulkan, " framebufferColorSampleCounts: {:#x}",
|
||||||
|
limits.framebufferColorSampleCounts);
|
||||||
|
LOG_INFO(Render_Vulkan, " framebufferDepthSampleCounts: {:#x}",
|
||||||
|
limits.framebufferDepthSampleCounts);
|
||||||
|
LOG_INFO(Render_Vulkan, " framebufferStencilSampleCounts: {:#x}",
|
||||||
|
limits.framebufferStencilSampleCounts);
|
||||||
|
LOG_INFO(Render_Vulkan, " sampledImageColorSampleCounts: {:#x}",
|
||||||
|
limits.sampledImageColorSampleCounts);
|
||||||
|
LOG_INFO(Render_Vulkan, " sampledImageDepthSampleCounts: {:#x}",
|
||||||
|
limits.sampledImageDepthSampleCounts);
|
||||||
|
LOG_INFO(Render_Vulkan, " sampledImageIntegerSampleCounts:{:#x}",
|
||||||
|
limits.sampledImageIntegerSampleCounts);
|
||||||
|
LOG_INFO(Render_Vulkan, " storageImageSampleCounts: {:#x}",
|
||||||
|
limits.storageImageSampleCounts);
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize GPU logging if enabled
|
// Initialize GPU logging if enabled
|
||||||
InitializeGPULogging();
|
InitializeGPULogging();
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::~Device() {
|
Device::~Device() {
|
||||||
ShutdownGPULogging();
|
ShutdownGPULogging();
|
||||||
|
vk::FlushDeletionQueue();
|
||||||
vmaDestroyAllocator(allocator);
|
vmaDestroyAllocator(allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -817,7 +838,8 @@ bool Device::ComputeIsOptimalAstcSupported() const {
|
|||||||
VK_FORMAT_ASTC_12x10_UNORM_BLOCK, VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
|
VK_FORMAT_ASTC_12x10_UNORM_BLOCK, VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
|
||||||
VK_FORMAT_ASTC_12x12_UNORM_BLOCK, VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
|
VK_FORMAT_ASTC_12x12_UNORM_BLOCK, VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
|
||||||
};
|
};
|
||||||
if (!features.features.textureCompressionASTC_LDR) {
|
if (!features.features.textureCompressionASTC_LDR ||
|
||||||
|
!features.texture_compression_astc_hdr.textureCompressionASTC_HDR) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto format_feature_usage{VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
|
const auto format_feature_usage{VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
|
||||||
@@ -1209,10 +1231,20 @@ void Device::RemoveUnsuitableExtensions() {
|
|||||||
RemoveExtensionFeatureIfUnsuitable(extensions.depth_bias_control, features.depth_bias_control,
|
RemoveExtensionFeatureIfUnsuitable(extensions.depth_bias_control, features.depth_bias_control,
|
||||||
VK_EXT_DEPTH_BIAS_CONTROL_EXTENSION_NAME);
|
VK_EXT_DEPTH_BIAS_CONTROL_EXTENSION_NAME);
|
||||||
|
|
||||||
|
// VK_EXT_depth_clamp_zero_one
|
||||||
|
extensions.depth_clamp_zero_one = features.depth_clamp_zero_one.depthClampZeroOne;
|
||||||
|
RemoveExtensionFeatureIfUnsuitable(extensions.depth_clamp_zero_one,
|
||||||
|
features.depth_clamp_zero_one,
|
||||||
|
VK_EXT_DEPTH_CLAMP_ZERO_ONE_EXTENSION_NAME);
|
||||||
|
|
||||||
// VK_EXT_depth_clip_control
|
// VK_EXT_depth_clip_control
|
||||||
extensions.depth_clip_control = features.depth_clip_control.depthClipControl;
|
extensions.depth_clip_control = features.depth_clip_control.depthClipControl;
|
||||||
RemoveExtensionFeatureIfUnsuitable(extensions.depth_clip_control, features.depth_clip_control,
|
RemoveExtensionFeatureIfUnsuitable(extensions.depth_clip_control, features.depth_clip_control,
|
||||||
VK_EXT_DEPTH_CLIP_CONTROL_EXTENSION_NAME);
|
VK_EXT_DEPTH_CLIP_CONTROL_EXTENSION_NAME);
|
||||||
|
// VK_EXT_depth_clip_enable
|
||||||
|
extensions.depth_clip_enable = features.depth_clip_enable.depthClipEnable;
|
||||||
|
RemoveExtensionFeatureIfUnsuitable(extensions.depth_clip_enable, features.depth_clip_enable,
|
||||||
|
VK_EXT_DEPTH_CLIP_ENABLE_EXTENSION_NAME);
|
||||||
|
|
||||||
// VK_EXT_extended_dynamic_state
|
// VK_EXT_extended_dynamic_state
|
||||||
extensions.extended_dynamic_state = features.extended_dynamic_state.extendedDynamicState;
|
extensions.extended_dynamic_state = features.extended_dynamic_state.extendedDynamicState;
|
||||||
@@ -1444,6 +1476,23 @@ std::optional<size_t> Device::GetSamplerHeapBudget() const {
|
|||||||
return sampler_heap_budget;
|
return sampler_heap_budget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Device::MemoryBudgetInfo Device::GetMemoryBudgetInfo() const {
|
||||||
|
std::array<VmaBudget, VK_MAX_MEMORY_HEAPS> budgets{};
|
||||||
|
vmaGetHeapBudgets(allocator, budgets.data());
|
||||||
|
MemoryBudgetInfo info{};
|
||||||
|
for (const size_t heap : valid_heap_memory) {
|
||||||
|
info.usage += budgets[heap].usage;
|
||||||
|
info.budget += budgets[heap].budget;
|
||||||
|
info.block_bytes += budgets[heap].statistics.blockBytes;
|
||||||
|
info.allocation_bytes += budgets[heap].statistics.allocationBytes;
|
||||||
|
}
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::TickAllocatorFrame() const {
|
||||||
|
vmaSetCurrentFrameIndex(allocator, ++allocator_frame_index);
|
||||||
|
}
|
||||||
|
|
||||||
u64 Device::GetDeviceMemoryUsage() const {
|
u64 Device::GetDeviceMemoryUsage() const {
|
||||||
VkPhysicalDeviceMemoryBudgetPropertiesEXT budget;
|
VkPhysicalDeviceMemoryBudgetPropertiesEXT budget;
|
||||||
budget.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT;
|
budget.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT;
|
||||||
@@ -1493,9 +1542,12 @@ void Device::CollectPhysicalMemoryInfo() {
|
|||||||
device_access_memory -= reserve_memory;
|
device_access_memory -= reserve_memory;
|
||||||
if (Settings::values.vram_usage_mode.GetValue() != Settings::VramUsageMode::Aggressive) {
|
if (Settings::values.vram_usage_mode.GetValue() != Settings::VramUsageMode::Aggressive) {
|
||||||
// Account for resolution scaling in memory limits
|
// Account for resolution scaling in memory limits
|
||||||
const size_t normal_memory = 6_GiB;
|
const u64 normal_memory = 6_GiB;
|
||||||
const size_t scaler_memory = 1_GiB * Settings::values.resolution_info.ScaleUp(1);
|
const u64 scaler_memory = 1_GiB * Settings::values.resolution_info.ScaleUp(1);
|
||||||
device_access_memory = std::min<u64>(device_access_memory, normal_memory + scaler_memory);
|
const u64 baseline = normal_memory + scaler_memory;
|
||||||
|
const u64 proportional = (device_access_memory / 4) * 3;
|
||||||
|
device_access_memory =
|
||||||
|
std::min<u64>(device_access_memory, std::max<u64>(baseline, proportional));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,9 @@ VK_DEFINE_HANDLE(VmaAllocator)
|
|||||||
FEATURE(EXT, ColorWriteEnable, COLOR_WRITE_ENABLE, color_write_enable) \
|
FEATURE(EXT, ColorWriteEnable, COLOR_WRITE_ENABLE, color_write_enable) \
|
||||||
FEATURE(EXT, CustomBorderColor, CUSTOM_BORDER_COLOR, custom_border_color) \
|
FEATURE(EXT, CustomBorderColor, CUSTOM_BORDER_COLOR, custom_border_color) \
|
||||||
FEATURE(EXT, DepthBiasControl, DEPTH_BIAS_CONTROL, depth_bias_control) \
|
FEATURE(EXT, DepthBiasControl, DEPTH_BIAS_CONTROL, depth_bias_control) \
|
||||||
|
FEATURE(EXT, DepthClampZeroOne, DEPTH_CLAMP_ZERO_ONE, depth_clamp_zero_one) \
|
||||||
FEATURE(EXT, DepthClipControl, DEPTH_CLIP_CONTROL, depth_clip_control) \
|
FEATURE(EXT, DepthClipControl, DEPTH_CLIP_CONTROL, depth_clip_control) \
|
||||||
|
FEATURE(EXT, DepthClipEnable, DEPTH_CLIP_ENABLE, depth_clip_enable) \
|
||||||
FEATURE(EXT, ExtendedDynamicState, EXTENDED_DYNAMIC_STATE, extended_dynamic_state) \
|
FEATURE(EXT, ExtendedDynamicState, EXTENDED_DYNAMIC_STATE, extended_dynamic_state) \
|
||||||
FEATURE(EXT, ExtendedDynamicState2, EXTENDED_DYNAMIC_STATE_2, extended_dynamic_state2) \
|
FEATURE(EXT, ExtendedDynamicState2, EXTENDED_DYNAMIC_STATE_2, extended_dynamic_state2) \
|
||||||
FEATURE(EXT, ExtendedDynamicState3, EXTENDED_DYNAMIC_STATE_3, extended_dynamic_state3) \
|
FEATURE(EXT, ExtendedDynamicState3, EXTENDED_DYNAMIC_STATE_3, extended_dynamic_state3) \
|
||||||
@@ -255,6 +257,17 @@ public:
|
|||||||
return allocator;
|
return allocator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct MemoryBudgetInfo {
|
||||||
|
u64 usage;
|
||||||
|
u64 budget;
|
||||||
|
u64 block_bytes;
|
||||||
|
u64 allocation_bytes;
|
||||||
|
};
|
||||||
|
|
||||||
|
MemoryBudgetInfo GetMemoryBudgetInfo() const;
|
||||||
|
|
||||||
|
void TickAllocatorFrame() const;
|
||||||
|
|
||||||
/// Returns the logical device.
|
/// Returns the logical device.
|
||||||
const vk::Device& GetLogical() const {
|
const vk::Device& GetLogical() const {
|
||||||
return logical;
|
return logical;
|
||||||
@@ -369,8 +382,7 @@ FN_MAX_LIMIT_LIST
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool IsOptimalAstcSupported() const {
|
bool IsOptimalAstcSupported() const {
|
||||||
return features.features.textureCompressionASTC_LDR &&
|
return is_optimal_astc_supported;
|
||||||
features.texture_compression_astc_hdr.textureCompressionASTC_HDR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if BCn is natively supported.
|
/// Returns true if BCn is natively supported.
|
||||||
@@ -602,6 +614,16 @@ FN_MAX_LIMIT_LIST
|
|||||||
return extensions.depth_clip_control;
|
return extensions.depth_clip_control;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true if the device supports VK_EXT_depth_clamp_zero_one.
|
||||||
|
bool IsExtDepthClampZeroOneSupported() const {
|
||||||
|
return extensions.depth_clamp_zero_one;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns true if the device supports VK_EXT_depth_clip_enable.
|
||||||
|
bool IsExtDepthClipEnableSupported() const {
|
||||||
|
return extensions.depth_clip_enable;
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if the device supports VK_EXT_depth_bias_control.
|
/// Returns true if the device supports VK_EXT_depth_bias_control.
|
||||||
bool IsExtDepthBiasControlSupported() const {
|
bool IsExtDepthBiasControlSupported() const {
|
||||||
return extensions.depth_bias_control;
|
return extensions.depth_bias_control;
|
||||||
@@ -734,6 +756,38 @@ FN_MAX_LIMIT_LIST
|
|||||||
return features.line_rasterization.stippledRectangularLines != VK_FALSE;
|
return features.line_rasterization.stippledRectangularLines != VK_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkLineRasterizationModeEXT GetLineRasterizationMode(bool wants_smooth) const {
|
||||||
|
if (wants_smooth && SupportsSmoothLines()) {
|
||||||
|
return VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT;
|
||||||
|
}
|
||||||
|
if (SupportsRectangularLines()) {
|
||||||
|
return VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT;
|
||||||
|
}
|
||||||
|
return VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SupportsStippleForMode(VkLineRasterizationModeEXT mode) const {
|
||||||
|
switch (mode) {
|
||||||
|
case VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT:
|
||||||
|
return features.line_rasterization.stippledSmoothLines != VK_FALSE;
|
||||||
|
case VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT:
|
||||||
|
return features.line_rasterization.stippledBresenhamLines != VK_FALSE;
|
||||||
|
default:
|
||||||
|
return features.line_rasterization.stippledRectangularLines != VK_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float ClampLineWidth(float width) const {
|
||||||
|
if (!features.features.wideLines) {
|
||||||
|
return 1.0f;
|
||||||
|
}
|
||||||
|
const auto& range = properties.properties.limits.lineWidthRange;
|
||||||
|
if (!(width >= range[0])) {
|
||||||
|
return range[0];
|
||||||
|
}
|
||||||
|
return width > range[1] ? range[1] : width;
|
||||||
|
}
|
||||||
|
|
||||||
bool SupportsAlphaToOne() const {
|
bool SupportsAlphaToOne() const {
|
||||||
return features.features.alphaToOne != VK_FALSE;
|
return features.features.alphaToOne != VK_FALSE;
|
||||||
}
|
}
|
||||||
@@ -876,6 +930,10 @@ FN_MAX_LIMIT_LIST
|
|||||||
|
|
||||||
u64 GetDeviceMemoryUsage() const;
|
u64 GetDeviceMemoryUsage() const;
|
||||||
|
|
||||||
|
VkSampleCountFlags GetStorageImageSampleCounts() const {
|
||||||
|
return properties.properties.limits.storageImageSampleCounts;
|
||||||
|
}
|
||||||
|
|
||||||
u32 GetSetsPerPool() const {
|
u32 GetSetsPerPool() const {
|
||||||
return sets_per_pool;
|
return sets_per_pool;
|
||||||
}
|
}
|
||||||
@@ -1060,6 +1118,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
VkInstance instance; ///< Vulkan instance.
|
VkInstance instance; ///< Vulkan instance.
|
||||||
VmaAllocator allocator; ///< VMA allocator.
|
VmaAllocator allocator; ///< VMA allocator.
|
||||||
|
mutable u32 allocator_frame_index{};
|
||||||
vk::DeviceDispatch dld; ///< Device function pointers.
|
vk::DeviceDispatch dld; ///< Device function pointers.
|
||||||
vk::PhysicalDevice physical; ///< Physical device.
|
vk::PhysicalDevice physical; ///< Physical device.
|
||||||
vk::Device logical; ///< Logical device.
|
vk::Device logical; ///< Logical device.
|
||||||
|
|||||||
@@ -30,26 +30,6 @@ namespace Vulkan {
|
|||||||
|
|
||||||
// Helpers translating MemoryUsage to flags/usage
|
// Helpers translating MemoryUsage to flags/usage
|
||||||
|
|
||||||
[[maybe_unused]] VkMemoryPropertyFlags MemoryUsagePropertyFlags(MemoryUsage usage) {
|
|
||||||
switch (usage) {
|
|
||||||
case MemoryUsage::DeviceLocal:
|
|
||||||
return VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
|
||||||
case MemoryUsage::Upload:
|
|
||||||
return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
|
||||||
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
|
||||||
case MemoryUsage::Download:
|
|
||||||
return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
|
||||||
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
|
|
||||||
VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
|
|
||||||
case MemoryUsage::Stream:
|
|
||||||
return VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
|
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
|
||||||
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
|
||||||
}
|
|
||||||
ASSERT_MSG(false, "Invalid memory usage={}", usage);
|
|
||||||
return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] VkMemoryPropertyFlags MemoryUsagePreferredVmaFlags(MemoryUsage usage) {
|
[[nodiscard]] VkMemoryPropertyFlags MemoryUsagePreferredVmaFlags(MemoryUsage usage) {
|
||||||
if (usage == MemoryUsage::Download) {
|
if (usage == MemoryUsage::Download) {
|
||||||
return VK_MEMORY_PROPERTY_HOST_CACHED_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
return VK_MEMORY_PROPERTY_HOST_CACHED_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
||||||
@@ -86,125 +66,11 @@ namespace Vulkan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// This avoids calling vkGetBufferMemoryRequirements* directly.
|
|
||||||
template<typename T>
|
|
||||||
static VkBuffer GetVkHandleFromBuffer(const T &buf) {
|
|
||||||
if constexpr (requires { static_cast<VkBuffer>(buf); }) {
|
|
||||||
return static_cast<VkBuffer>(buf);
|
|
||||||
} else if constexpr (requires {{ buf.GetHandle() } -> std::convertible_to<VkBuffer>; }) {
|
|
||||||
return buf.GetHandle();
|
|
||||||
} else if constexpr (requires {{ buf.Handle() } -> std::convertible_to<VkBuffer>; }) {
|
|
||||||
return buf.Handle();
|
|
||||||
} else if constexpr (requires {{ buf.vk_handle() } -> std::convertible_to<VkBuffer>; }) {
|
|
||||||
return buf.vk_handle();
|
|
||||||
} else {
|
|
||||||
static_assert(sizeof(T) == 0, "Cannot extract VkBuffer handle from vk::Buffer");
|
|
||||||
return VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
//MemoryCommit is now VMA-backed
|
|
||||||
MemoryCommit::MemoryCommit(VmaAllocator alloc, VmaAllocation a,
|
|
||||||
const VmaAllocationInfo &info) noexcept
|
|
||||||
: allocator{alloc}, allocation{a}, memory{info.deviceMemory},
|
|
||||||
offset{info.offset}, size{info.size}, mapped_ptr{info.pMappedData} {
|
|
||||||
// Log GPU memory allocation
|
|
||||||
if (GPU::Logging::IsActive() &&
|
|
||||||
Settings::values.gpu_log_memory_tracking.GetValue()) {
|
|
||||||
GPU::Logging::GPULogger::GetInstance().LogMemoryAllocation(
|
|
||||||
reinterpret_cast<uintptr_t>(memory),
|
|
||||||
static_cast<u64>(size),
|
|
||||||
0 // Memory property flags (not easily available from VMA)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MemoryCommit::~MemoryCommit() { Release(); }
|
|
||||||
|
|
||||||
MemoryCommit::MemoryCommit(MemoryCommit &&rhs) noexcept
|
|
||||||
: allocator{std::exchange(rhs.allocator, nullptr)},
|
|
||||||
allocation{std::exchange(rhs.allocation, nullptr)},
|
|
||||||
memory{std::exchange(rhs.memory, VK_NULL_HANDLE)},
|
|
||||||
offset{std::exchange(rhs.offset, 0)},
|
|
||||||
size{std::exchange(rhs.size, 0)},
|
|
||||||
mapped_ptr{std::exchange(rhs.mapped_ptr, nullptr)} {}
|
|
||||||
|
|
||||||
MemoryCommit &MemoryCommit::operator=(MemoryCommit &&rhs) noexcept {
|
|
||||||
if (this != &rhs) {
|
|
||||||
Release();
|
|
||||||
allocator = std::exchange(rhs.allocator, nullptr);
|
|
||||||
allocation = std::exchange(rhs.allocation, nullptr);
|
|
||||||
memory = std::exchange(rhs.memory, VK_NULL_HANDLE);
|
|
||||||
offset = std::exchange(rhs.offset, 0);
|
|
||||||
size = std::exchange(rhs.size, 0);
|
|
||||||
mapped_ptr = std::exchange(rhs.mapped_ptr, nullptr);
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::span<u8> MemoryCommit::Map()
|
|
||||||
{
|
|
||||||
if (!allocation) return {};
|
|
||||||
if (!mapped_ptr) {
|
|
||||||
if (vmaMapMemory(allocator, allocation, &mapped_ptr) != VK_SUCCESS) return {};
|
|
||||||
}
|
|
||||||
const size_t n = static_cast<size_t>(std::min<VkDeviceSize>(size,
|
|
||||||
(std::numeric_limits<size_t>::max)()));
|
|
||||||
return std::span<u8>{static_cast<u8 *>(mapped_ptr), n};
|
|
||||||
}
|
|
||||||
|
|
||||||
std::span<const u8> MemoryCommit::Map() const
|
|
||||||
{
|
|
||||||
if (!allocation) return {};
|
|
||||||
if (!mapped_ptr) {
|
|
||||||
void *p = nullptr;
|
|
||||||
if (vmaMapMemory(allocator, allocation, &p) != VK_SUCCESS) return {};
|
|
||||||
const_cast<MemoryCommit *>(this)->mapped_ptr = p;
|
|
||||||
}
|
|
||||||
const size_t n = static_cast<size_t>(std::min<VkDeviceSize>(size,
|
|
||||||
(std::numeric_limits<size_t>::max)()));
|
|
||||||
return std::span<const u8>{static_cast<const u8 *>(mapped_ptr), n};
|
|
||||||
}
|
|
||||||
|
|
||||||
void MemoryCommit::Unmap()
|
|
||||||
{
|
|
||||||
if (allocation && mapped_ptr) {
|
|
||||||
vmaUnmapMemory(allocator, allocation);
|
|
||||||
mapped_ptr = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MemoryCommit::Release() {
|
|
||||||
if (allocation && allocator) {
|
|
||||||
// Log GPU memory deallocation
|
|
||||||
if (GPU::Logging::IsActive() &&
|
|
||||||
Settings::values.gpu_log_memory_tracking.GetValue() &&
|
|
||||||
memory != VK_NULL_HANDLE) {
|
|
||||||
GPU::Logging::GPULogger::GetInstance().LogMemoryDeallocation(
|
|
||||||
reinterpret_cast<uintptr_t>(memory)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mapped_ptr) {
|
|
||||||
vmaUnmapMemory(allocator, allocation);
|
|
||||||
mapped_ptr = nullptr;
|
|
||||||
}
|
|
||||||
vmaFreeMemory(allocator, allocation);
|
|
||||||
}
|
|
||||||
allocation = nullptr;
|
|
||||||
allocator = nullptr;
|
|
||||||
memory = VK_NULL_HANDLE;
|
|
||||||
offset = 0;
|
|
||||||
size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
MemoryAllocator::MemoryAllocator(const Device &device_)
|
MemoryAllocator::MemoryAllocator(const Device &device_)
|
||||||
: device{device_}, allocator{device.GetAllocator()},
|
: device{device_}, allocator{device.GetAllocator()},
|
||||||
properties{device_.GetPhysical().GetMemoryProperties().memoryProperties},
|
properties{device_.GetPhysical().GetMemoryProperties().memoryProperties} {
|
||||||
buffer_image_granularity{
|
|
||||||
device_.GetPhysical().GetProperties().limits.bufferImageGranularity} {
|
|
||||||
|
|
||||||
// Preserve the previous "RenderDoc small heap" trimming behavior that we had in original vma minus the heap bug
|
// Preserve the previous "RenderDoc small heap" trimming behavior that we had in original vma minus the heap bug
|
||||||
if (device.HasDebuggingToolAttached())
|
if (device.HasDebuggingToolAttached())
|
||||||
@@ -224,6 +90,21 @@ namespace Vulkan {
|
|||||||
|
|
||||||
MemoryAllocator::~MemoryAllocator() = default;
|
MemoryAllocator::~MemoryAllocator() = default;
|
||||||
|
|
||||||
|
void MemoryAllocator::SetReclaimCallback(ReclaimCallback callback) {
|
||||||
|
reclaim_callback = std::move(callback);
|
||||||
|
vk::SetAllocatorOwnerThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MemoryAllocator::ReclaimAtLeast(u64 hint_bytes) const {
|
||||||
|
if (!reclaim_callback || in_reclaim) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
in_reclaim = true;
|
||||||
|
const u64 freed = reclaim_callback(hint_bytes);
|
||||||
|
in_reclaim = false;
|
||||||
|
return freed > 0;
|
||||||
|
}
|
||||||
|
|
||||||
vk::Image MemoryAllocator::CreateImage(const VkImageCreateInfo &ci) const
|
vk::Image MemoryAllocator::CreateImage(const VkImageCreateInfo &ci) const
|
||||||
{
|
{
|
||||||
const VmaAllocationCreateInfo alloc_ci = {
|
const VmaAllocationCreateInfo alloc_ci = {
|
||||||
@@ -240,7 +121,26 @@ namespace Vulkan {
|
|||||||
VkImage handle{};
|
VkImage handle{};
|
||||||
VmaAllocation allocation{};
|
VmaAllocation allocation{};
|
||||||
VmaAllocationInfo alloc_info{};
|
VmaAllocationInfo alloc_info{};
|
||||||
vk::Check(vmaCreateImage(allocator, &ci, &alloc_ci, &handle, &allocation, &alloc_info));
|
DEBUG_ASSERT(vk::OnAllocatorOwnerThread());
|
||||||
|
|
||||||
|
VkResult res = vmaCreateImage(allocator, &ci, &alloc_ci, &handle, &allocation, &alloc_info);
|
||||||
|
|
||||||
|
if (res != VK_SUCCESS && ReclaimAtLeast(IMAGE_RECLAIM_HINT)) {
|
||||||
|
res = vmaCreateImage(allocator, &ci, &alloc_ci, &handle, &allocation, &alloc_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res != VK_SUCCESS) {
|
||||||
|
auto relaxed_ci = alloc_ci;
|
||||||
|
relaxed_ci.flags &= ~VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT;
|
||||||
|
res = vmaCreateImage(allocator, &ci, &relaxed_ci, &handle, &allocation, &alloc_info);
|
||||||
|
|
||||||
|
if (res != VK_SUCCESS) {
|
||||||
|
relaxed_ci.preferredFlags &= ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
||||||
|
res = vmaCreateImage(allocator, &ci, &relaxed_ci, &handle, &allocation, &alloc_info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vk::Check(res);
|
||||||
|
|
||||||
// Log GPU memory allocation for images
|
// Log GPU memory allocation for images
|
||||||
if (GPU::Logging::IsActive() &&
|
if (GPU::Logging::IsActive() &&
|
||||||
@@ -277,7 +177,28 @@ namespace Vulkan {
|
|||||||
VmaAllocation allocation{};
|
VmaAllocation allocation{};
|
||||||
VkMemoryPropertyFlags property_flags{};
|
VkMemoryPropertyFlags property_flags{};
|
||||||
|
|
||||||
vk::Check(vmaCreateBuffer(allocator, &ci, &alloc_ci, &handle, &allocation, &alloc_info));
|
DEBUG_ASSERT(vk::OnAllocatorOwnerThread());
|
||||||
|
|
||||||
|
VkResult res = vmaCreateBuffer(allocator, &ci, &alloc_ci, &handle, &allocation, &alloc_info);
|
||||||
|
|
||||||
|
if (res != VK_SUCCESS && ReclaimAtLeast(ci.size)) {
|
||||||
|
res = vmaCreateBuffer(allocator, &ci, &alloc_ci, &handle, &allocation, &alloc_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res != VK_SUCCESS) {
|
||||||
|
auto relaxed_ci = alloc_ci;
|
||||||
|
relaxed_ci.flags &= ~VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT;
|
||||||
|
res = vmaCreateBuffer(allocator, &ci, &relaxed_ci, &handle, &allocation, &alloc_info);
|
||||||
|
|
||||||
|
if (res != VK_SUCCESS &&
|
||||||
|
(relaxed_ci.preferredFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) {
|
||||||
|
relaxed_ci.preferredFlags &= ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
||||||
|
res = vmaCreateBuffer(allocator, &ci, &relaxed_ci, &handle, &allocation,
|
||||||
|
&alloc_info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vk::Check(res);
|
||||||
vmaGetAllocationMemoryProperties(allocator, allocation, &property_flags);
|
vmaGetAllocationMemoryProperties(allocator, allocation, &property_flags);
|
||||||
|
|
||||||
// Log GPU memory allocation for buffers
|
// Log GPU memory allocation for buffers
|
||||||
@@ -299,77 +220,4 @@ namespace Vulkan {
|
|||||||
device.GetDispatchLoader());
|
device.GetDispatchLoader());
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryCommit MemoryAllocator::Commit(const VkMemoryRequirements &reqs, MemoryUsage usage)
|
|
||||||
{
|
|
||||||
const auto vma_usage = MemoryUsageVma(usage);
|
|
||||||
VmaAllocationCreateInfo ci{};
|
|
||||||
ci.flags = VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT | MemoryUsageVmaFlags(usage);
|
|
||||||
ci.usage = vma_usage;
|
|
||||||
ci.memoryTypeBits = reqs.memoryTypeBits & valid_memory_types;
|
|
||||||
ci.requiredFlags = 0;
|
|
||||||
ci.preferredFlags = MemoryUsagePreferredVmaFlags(usage);
|
|
||||||
|
|
||||||
VmaAllocation a{};
|
|
||||||
VmaAllocationInfo info{};
|
|
||||||
|
|
||||||
VkResult res = vmaAllocateMemory(allocator, &reqs, &ci, &a, &info);
|
|
||||||
|
|
||||||
if (res != VK_SUCCESS) {
|
|
||||||
// Relax 1: drop budget constraint
|
|
||||||
auto ci2 = ci;
|
|
||||||
ci2.flags &= ~VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT;
|
|
||||||
res = vmaAllocateMemory(allocator, &reqs, &ci2, &a, &info);
|
|
||||||
|
|
||||||
// Relax 2: if we preferred DEVICE_LOCAL, drop that preference
|
|
||||||
if (res != VK_SUCCESS && (ci.preferredFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) {
|
|
||||||
auto ci3 = ci2;
|
|
||||||
ci3.preferredFlags &= ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
|
||||||
res = vmaAllocateMemory(allocator, &reqs, &ci3, &a, &info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vk::Check(res);
|
|
||||||
return MemoryCommit(allocator, a, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
MemoryCommit MemoryAllocator::Commit(const vk::Buffer &buffer, MemoryUsage usage) {
|
|
||||||
// Allocate memory appropriate for this buffer automatically
|
|
||||||
const auto vma_usage = MemoryUsageVma(usage);
|
|
||||||
|
|
||||||
VmaAllocationCreateInfo ci{};
|
|
||||||
ci.flags = VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT | MemoryUsageVmaFlags(usage);
|
|
||||||
ci.usage = vma_usage;
|
|
||||||
ci.requiredFlags = 0;
|
|
||||||
ci.preferredFlags = MemoryUsagePreferredVmaFlags(usage);
|
|
||||||
ci.pool = VK_NULL_HANDLE;
|
|
||||||
ci.pUserData = nullptr;
|
|
||||||
ci.priority = 0.0f;
|
|
||||||
|
|
||||||
const VkBuffer raw = *buffer;
|
|
||||||
|
|
||||||
VmaAllocation a{};
|
|
||||||
VmaAllocationInfo info{};
|
|
||||||
|
|
||||||
// Let VMA infer memory requirements from the buffer
|
|
||||||
VkResult res = vmaAllocateMemoryForBuffer(allocator, raw, &ci, &a, &info);
|
|
||||||
|
|
||||||
if (res != VK_SUCCESS) {
|
|
||||||
auto ci2 = ci;
|
|
||||||
ci2.flags &= ~VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT;
|
|
||||||
res = vmaAllocateMemoryForBuffer(allocator, raw, &ci2, &a, &info);
|
|
||||||
|
|
||||||
if (res != VK_SUCCESS && (ci.preferredFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) {
|
|
||||||
auto ci3 = ci2;
|
|
||||||
ci3.preferredFlags &= ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
|
||||||
res = vmaAllocateMemoryForBuffer(allocator, raw, &ci3, &a, &info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vk::Check(res);
|
|
||||||
vk::Check(vmaBindBufferMemory2(allocator, a, 0, raw, nullptr));
|
|
||||||
return MemoryCommit(allocator, a, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Vulkan
|
} // namespace Vulkan
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <span>
|
#include <span>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -39,51 +40,6 @@ namespace Vulkan {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ownership handle of a memory commitment (real VMA allocation).
|
|
||||||
class MemoryCommit {
|
|
||||||
public:
|
|
||||||
MemoryCommit() noexcept = default;
|
|
||||||
|
|
||||||
MemoryCommit(VmaAllocator allocator, VmaAllocation allocation,
|
|
||||||
const VmaAllocationInfo &info) noexcept;
|
|
||||||
|
|
||||||
~MemoryCommit();
|
|
||||||
|
|
||||||
MemoryCommit(const MemoryCommit &) = delete;
|
|
||||||
|
|
||||||
MemoryCommit &operator=(const MemoryCommit &) = delete;
|
|
||||||
|
|
||||||
MemoryCommit(MemoryCommit &&) noexcept;
|
|
||||||
|
|
||||||
MemoryCommit &operator=(MemoryCommit &&) noexcept;
|
|
||||||
|
|
||||||
[[nodiscard]] std::span<u8> Map();
|
|
||||||
|
|
||||||
[[nodiscard]] std::span<const u8> Map() const;
|
|
||||||
|
|
||||||
void Unmap();
|
|
||||||
|
|
||||||
explicit operator bool() const noexcept { return allocation != nullptr; }
|
|
||||||
|
|
||||||
VkDeviceMemory Memory() const noexcept { return memory; }
|
|
||||||
|
|
||||||
VkDeviceSize Offset() const noexcept { return offset; }
|
|
||||||
|
|
||||||
VkDeviceSize Size() const noexcept { return size; }
|
|
||||||
|
|
||||||
VmaAllocation Allocation() const noexcept { return allocation; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
void Release();
|
|
||||||
|
|
||||||
VmaAllocator allocator{}; ///< VMA allocator
|
|
||||||
VmaAllocation allocation{}; ///< VMA allocation handle
|
|
||||||
VkDeviceMemory memory{}; ///< Underlying VkDeviceMemory chosen by VMA
|
|
||||||
VkDeviceSize offset{}; ///< Offset of this allocation inside VkDeviceMemory
|
|
||||||
VkDeviceSize size{}; ///< Size of the allocation
|
|
||||||
void *mapped_ptr{}; ///< Optional persistent mapped pointer
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Memory allocator container.
|
/// Memory allocator container.
|
||||||
/// Allocates and releases memory allocations on demand.
|
/// Allocates and releases memory allocations on demand.
|
||||||
class MemoryAllocator {
|
class MemoryAllocator {
|
||||||
@@ -107,36 +63,21 @@ namespace Vulkan {
|
|||||||
|
|
||||||
vk::Buffer CreateBuffer(const VkBufferCreateInfo &ci, MemoryUsage usage) const;
|
vk::Buffer CreateBuffer(const VkBufferCreateInfo &ci, MemoryUsage usage) const;
|
||||||
|
|
||||||
/**
|
using ReclaimCallback = std::function<u64(u64)>;
|
||||||
* Commits a memory with the specified requirements.
|
|
||||||
*
|
|
||||||
* @param requirements Requirements returned from a Vulkan call.
|
|
||||||
* @param usage Indicates how the memory will be used.
|
|
||||||
*
|
|
||||||
* @returns A memory commit.
|
|
||||||
*/
|
|
||||||
MemoryCommit Commit(const VkMemoryRequirements &requirements, MemoryUsage usage);
|
|
||||||
|
|
||||||
/// Commits memory required by the buffer and binds it (for buffers created outside VMA).
|
void SetReclaimCallback(ReclaimCallback callback);
|
||||||
MemoryCommit Commit(const vk::Buffer &buffer, MemoryUsage usage);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool IsAutoUsage(VmaMemoryUsage u) noexcept {
|
bool ReclaimAtLeast(u64 hint_bytes) const;
|
||||||
switch (u) {
|
|
||||||
case VMA_MEMORY_USAGE_AUTO:
|
static constexpr u64 IMAGE_RECLAIM_HINT = 64ULL * 1024 * 1024;
|
||||||
case VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE:
|
|
||||||
case VMA_MEMORY_USAGE_AUTO_PREFER_HOST:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const Device &device; ///< Device handle.
|
const Device &device; ///< Device handle.
|
||||||
VmaAllocator allocator; ///< VMA allocator.
|
VmaAllocator allocator; ///< VMA allocator.
|
||||||
const VkPhysicalDeviceMemoryProperties properties; ///< Physical device memory properties.
|
const VkPhysicalDeviceMemoryProperties properties; ///< Physical device memory properties.
|
||||||
VkDeviceSize buffer_image_granularity; ///< Adjacent buffer/image granularity
|
|
||||||
u32 valid_memory_types{~0u};
|
u32 valid_memory_types{~0u};
|
||||||
|
ReclaimCallback reclaim_callback;
|
||||||
|
mutable bool in_reclaim{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Vulkan
|
} // namespace Vulkan
|
||||||
|
|||||||
@@ -5,11 +5,16 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <atomic>
|
||||||
|
#include <limits>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <thread>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "common/assert.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/logging.h"
|
#include "common/logging.h"
|
||||||
#include "video_core/vulkan_common/vk_enum_string_helper.h"
|
#include "video_core/vulkan_common/vk_enum_string_helper.h"
|
||||||
@@ -20,6 +25,60 @@ namespace Vulkan::vk {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
std::thread::id allocator_owner_thread;
|
||||||
|
|
||||||
|
template <typename HandleType>
|
||||||
|
struct PendingRelease {
|
||||||
|
VmaAllocator allocator;
|
||||||
|
HandleType handle;
|
||||||
|
VmaAllocation allocation;
|
||||||
|
u64 timeline;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::mutex deletion_mutex;
|
||||||
|
std::atomic<u64> deletion_timeline{1};
|
||||||
|
std::vector<PendingRelease<VkImage>> pending_images;
|
||||||
|
std::vector<PendingRelease<VkBuffer>> pending_buffers;
|
||||||
|
|
||||||
|
template <typename HandleType>
|
||||||
|
void PushPendingRelease(std::vector<PendingRelease<HandleType>>& pending, VmaAllocator allocator,
|
||||||
|
HandleType handle, VmaAllocation allocation) noexcept {
|
||||||
|
std::scoped_lock lock{deletion_mutex};
|
||||||
|
pending.push_back(PendingRelease<HandleType>{
|
||||||
|
.allocator = allocator,
|
||||||
|
.handle = handle,
|
||||||
|
.allocation = allocation,
|
||||||
|
.timeline = deletion_timeline.load(std::memory_order_acquire),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename HandleType>
|
||||||
|
void ExtractReleased(std::vector<PendingRelease<HandleType>>& pending,
|
||||||
|
std::vector<PendingRelease<HandleType>>& released, u64 completed_value) {
|
||||||
|
const auto split = std::partition(pending.begin(), pending.end(),
|
||||||
|
[completed_value](const PendingRelease<HandleType>& entry) {
|
||||||
|
return entry.timeline > completed_value;
|
||||||
|
});
|
||||||
|
released.assign(split, pending.end());
|
||||||
|
pending.erase(split, pending.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrainDeletionQueue(u64 completed_value) noexcept {
|
||||||
|
std::vector<PendingRelease<VkImage>> images;
|
||||||
|
std::vector<PendingRelease<VkBuffer>> buffers;
|
||||||
|
{
|
||||||
|
std::scoped_lock lock{deletion_mutex};
|
||||||
|
ExtractReleased(pending_images, images, completed_value);
|
||||||
|
ExtractReleased(pending_buffers, buffers, completed_value);
|
||||||
|
}
|
||||||
|
for (const auto& entry : images) {
|
||||||
|
vmaDestroyImage(entry.allocator, entry.handle, entry.allocation);
|
||||||
|
}
|
||||||
|
for (const auto& entry : buffers) {
|
||||||
|
vmaDestroyBuffer(entry.allocator, entry.handle, entry.allocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Func>
|
template <typename Func>
|
||||||
void SortPhysicalDevices(std::vector<VkPhysicalDevice>& devices, const InstanceDispatch& dld,
|
void SortPhysicalDevices(std::vector<VkPhysicalDevice>& devices, const InstanceDispatch& dld,
|
||||||
Func&& func) {
|
Func&& func) {
|
||||||
@@ -502,13 +561,35 @@ DebugReportCallback Instance::CreateDebugReportCallback(
|
|||||||
return DebugReportCallback(object, handle, *dld);
|
return DebugReportCallback(object, handle, *dld);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetAllocatorOwnerThread() {
|
||||||
|
allocator_owner_thread = std::this_thread::get_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OnAllocatorOwnerThread() noexcept {
|
||||||
|
return allocator_owner_thread == std::thread::id{} ||
|
||||||
|
allocator_owner_thread == std::this_thread::get_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetDeletionTimeline(u64 value) noexcept {
|
||||||
|
deletion_timeline.store(value, std::memory_order_release);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TickDeletionQueue(u64 completed_value) noexcept {
|
||||||
|
DEBUG_ASSERT(OnAllocatorOwnerThread());
|
||||||
|
DrainDeletionQueue(completed_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FlushDeletionQueue() noexcept {
|
||||||
|
DrainDeletionQueue((std::numeric_limits<u64>::max)());
|
||||||
|
}
|
||||||
|
|
||||||
void Image::SetObjectNameEXT(const char* name) const {
|
void Image::SetObjectNameEXT(const char* name) const {
|
||||||
SetObjectName(dld, owner, handle, VK_OBJECT_TYPE_IMAGE, name);
|
SetObjectName(dld, owner, handle, VK_OBJECT_TYPE_IMAGE, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::Release() const noexcept {
|
void Image::Release() const noexcept {
|
||||||
if (handle) {
|
if (handle) {
|
||||||
vmaDestroyImage(allocator, handle, allocation);
|
PushPendingRelease(pending_images, allocator, handle, allocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -530,7 +611,7 @@ void Buffer::SetObjectNameEXT(const char* name) const {
|
|||||||
|
|
||||||
void Buffer::Release() const noexcept {
|
void Buffer::Release() const noexcept {
|
||||||
if (handle) {
|
if (handle) {
|
||||||
vmaDestroyBuffer(allocator, handle, allocation);
|
PushPendingRelease(pending_buffers, allocator, handle, allocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -131,6 +131,16 @@ private:
|
|||||||
VkResult result;
|
VkResult result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void SetAllocatorOwnerThread();
|
||||||
|
|
||||||
|
[[nodiscard]] bool OnAllocatorOwnerThread() noexcept;
|
||||||
|
|
||||||
|
void SetDeletionTimeline(u64 value) noexcept;
|
||||||
|
|
||||||
|
void TickDeletionQueue(u64 completed_value) noexcept;
|
||||||
|
|
||||||
|
void FlushDeletionQueue() noexcept;
|
||||||
|
|
||||||
/// Throws a Vulkan exception if result is not success.
|
/// Throws a Vulkan exception if result is not success.
|
||||||
inline void Check(VkResult result) {
|
inline void Check(VkResult result) {
|
||||||
if (result != VK_SUCCESS) {
|
if (result != VK_SUCCESS) {
|
||||||
|
|||||||
Reference in New Issue
Block a user