mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-08-15 21:19:47 +00:00
Compare commits
122 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3cfe9f04e1 | |||
| a074268eb0 | |||
| 50763528a2 | |||
| 4b3608b58d | |||
| b76d04e47d | |||
| 71afaff6b3 | |||
| dcbfa3c2d3 | |||
| 70ff43f2f8 | |||
| 76faac9252 | |||
| 6346371725 | |||
| 4162f86a11 | |||
| 86224e49ef | |||
| 6665a89dd2 | |||
| 515afa2959 | |||
| 8c8c7c6162 | |||
| fb65aa3c33 | |||
| a24ad03ff3 | |||
| 4884a0c002 | |||
| ab1d99d218 | |||
| e6ee576f80 | |||
| 1682b532da | |||
| 40fe050954 | |||
| 24ff23f2ea | |||
| 87ebbfb9b1 | |||
| 471778c850 | |||
| 095f27fd34 | |||
| a6c423cafb | |||
| 514507b674 | |||
| 10935f8d46 | |||
| a0dae2d490 | |||
| 5e40e3c9c0 | |||
| f61d05f8da | |||
| b04207fdfc | |||
| 91791bd5fe | |||
| 9928885a5d | |||
| 81fa91b400 | |||
| eb8706e366 | |||
| b9d55c9448 | |||
| 1188f285b7 | |||
| 200b81b087 | |||
| 742cadde1d | |||
| c3effdf558 | |||
| b9428acf12 | |||
| b027dc42ce | |||
| dc9c99b22d | |||
| 5346e77c0a | |||
| 914b78495c | |||
| a17b4cbb04 | |||
| a7b5910eaa | |||
| f98f8b65de | |||
| 88fcb7d338 | |||
| 4a4fd056ff | |||
| 236696b0ff | |||
| d1eb08c036 | |||
| 84a4149db2 | |||
| de9b1071a5 | |||
| 85049c2c78 | |||
| 7fcf88cb10 | |||
| e4f29899d2 | |||
| 41d2bf4a3e | |||
| 328a2c1081 | |||
| 6e48eeb09c | |||
| 2cdd7173a9 | |||
| 69342044ef | |||
| 1f41d809b0 | |||
| 250b545d75 | |||
| 5a9322af80 | |||
| bbee229d07 | |||
| cfe1c8b16c | |||
| dd5d09e3ae | |||
| 25af655e48 | |||
| 0cd5dd1e70 | |||
| 8c828e78f2 | |||
| b1adbd8e6b | |||
| 0fb0592a5f | |||
| b59dda3af6 | |||
| aec20586be | |||
| 6918f034e2 | |||
| 4b1e2d1d6a | |||
| 9318a508f7 | |||
| f95a9f3901 | |||
| 1169533a74 | |||
| 991ff44bd6 | |||
| 624f955821 | |||
| 5c0fe5da06 | |||
| 18630fa739 | |||
| 9752908030 | |||
| a711fd99a6 | |||
| f6c1404e09 | |||
| 77ffefbbbf | |||
| bf13e7ce1d | |||
| 3cd17ec392 | |||
| 7f4529b15d | |||
| f649730cb1 | |||
| 40c91abdad | |||
| d21bb9a1b7 | |||
| 94e814ecf1 | |||
| b8135a3e47 | |||
| 8d7f992792 | |||
| f199597158 | |||
| 9c313fb787 | |||
| eec29b83f3 | |||
| a57041d62f | |||
| 4956bc86c3 | |||
| e8b1dc7c0b | |||
| e81d170458 | |||
| 7ed7e5e31d | |||
| eb32b8766a | |||
| a484e6c34b | |||
| 84490a7d6f | |||
| 933f79af95 | |||
| f532357793 | |||
| ab92e5fa52 | |||
| 791880f9bf | |||
| e058a15074 | |||
| 6313800aee | |||
| 5428dbbd14 | |||
| 9694216ad7 | |||
| 4fbdc133dd | |||
| f210f16e8c | |||
| 20bf6bc282 | |||
| 99e95eebb1 |
@@ -65,7 +65,7 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "dev.eden.eden_emulator"
|
||||
minSdk = 24
|
||||
minSdk = 33
|
||||
targetSdk = 36
|
||||
versionName = getGitVersion()
|
||||
versionCode = autoVersion
|
||||
|
||||
+3
@@ -27,6 +27,7 @@ enum class BooleanSetting(override val key: String) : AbstractBooleanSetting {
|
||||
RENDERER_ASYNCHRONOUS_GPU_EMULATION("use_asynchronous_gpu_emulation"),
|
||||
RENDERER_ASYNC_PRESENTATION("async_presentation"),
|
||||
RENDERER_ASYNCHRONOUS_SHADERS("use_asynchronous_shaders"),
|
||||
RENDERER_UNIFIED_MEMORY("use_unified_memory"),
|
||||
RENDERER_REACTIVE_FLUSHING("use_reactive_flushing"),
|
||||
ENABLE_BUFFER_HISTORY("enable_buffer_history"),
|
||||
USE_OPTIMIZED_VERTEX_BUFFERS("use_optimized_vertex_buffers"),
|
||||
@@ -36,6 +37,8 @@ enum class BooleanSetting(override val key: String) : AbstractBooleanSetting {
|
||||
RENDERER_DEBUG("debug"),
|
||||
RENDERER_PATCH_OLD_QCOM_DRIVERS("patch_old_qcom_drivers"),
|
||||
RENDERER_VERTEX_INPUT_DYNAMIC_STATE("vertex_input_dynamic_state"),
|
||||
RENDERER_DYNAMIC_RENDERING("dynamic_rendering"),
|
||||
RENDERER_WORKGROUP_MEMORY_EXPLICIT_LAYOUT("workgroup_memory_explicit_layout"),
|
||||
RENDERER_SAMPLE_SHADING("sample_shading"),
|
||||
GPU_UNSWIZZLE_ENABLED("gpu_unswizzle_enabled"),
|
||||
PICTURE_IN_PICTURE("picture_in_picture"),
|
||||
|
||||
+22
-1
@@ -155,6 +155,20 @@ abstract class SettingsItem(
|
||||
descriptionId = R.string.vertex_input_dynamic_state_description
|
||||
)
|
||||
)
|
||||
put(
|
||||
SwitchSetting(
|
||||
BooleanSetting.RENDERER_DYNAMIC_RENDERING,
|
||||
titleId = R.string.dynamic_rendering,
|
||||
descriptionId = R.string.dynamic_rendering_description
|
||||
)
|
||||
)
|
||||
put(
|
||||
SwitchSetting(
|
||||
BooleanSetting.RENDERER_WORKGROUP_MEMORY_EXPLICIT_LAYOUT,
|
||||
titleId = R.string.workgroup_memory_explicit_layout,
|
||||
descriptionId = R.string.workgroup_memory_explicit_layout_description
|
||||
)
|
||||
)
|
||||
put(
|
||||
SliderSetting(
|
||||
IntSetting.RENDERER_SAMPLE_SHADING,
|
||||
@@ -594,7 +608,7 @@ abstract class SettingsItem(
|
||||
IntSetting.ANDROID_PIPELINE_WORKERS,
|
||||
titleId = R.string.pipeline_worker_cores,
|
||||
descriptionId = R.string.pipeline_worker_cores_description,
|
||||
min = 4,
|
||||
min = 2,
|
||||
max = 8,
|
||||
units = "cores"
|
||||
)
|
||||
@@ -685,6 +699,13 @@ abstract class SettingsItem(
|
||||
descriptionId = R.string.renderer_asynchronous_shaders_description
|
||||
)
|
||||
)
|
||||
put(
|
||||
SwitchSetting(
|
||||
BooleanSetting.RENDERER_UNIFIED_MEMORY,
|
||||
titleId = R.string.renderer_unified_memory,
|
||||
descriptionId = R.string.renderer_unified_memory_description
|
||||
)
|
||||
)
|
||||
put(
|
||||
SingleChoiceSetting(
|
||||
IntSetting.FAST_GPU_TIME,
|
||||
|
||||
+3
@@ -304,6 +304,7 @@ class SettingsFragmentPresenter(
|
||||
add(BooleanSetting.EMULATE_BGR565.key)
|
||||
add(BooleanSetting.RESCALE_HACK.key)
|
||||
add(BooleanSetting.RENDERER_ASYNCHRONOUS_SHADERS.key)
|
||||
add(BooleanSetting.RENDERER_UNIFIED_MEMORY.key)
|
||||
add(IntSetting.ANDROID_PIPELINE_WORKERS.key)
|
||||
add(BooleanSetting.RENDERER_ASYNCHRONOUS_GPU_EMULATION.key)
|
||||
add(BooleanSetting.RENDERER_ASYNC_PRESENTATION.key)
|
||||
@@ -313,6 +314,8 @@ class SettingsFragmentPresenter(
|
||||
|
||||
add(IntSetting.RENDERER_DYNA_STATE.key)
|
||||
add(BooleanSetting.RENDERER_VERTEX_INPUT_DYNAMIC_STATE.key)
|
||||
add(BooleanSetting.RENDERER_DYNAMIC_RENDERING.key)
|
||||
add(BooleanSetting.RENDERER_WORKGROUP_MEMORY_EXPLICIT_LAYOUT.key)
|
||||
add(IntSetting.RENDERER_SAMPLE_SHADING.key)
|
||||
|
||||
add(HeaderSetting(R.string.display))
|
||||
|
||||
@@ -147,13 +147,6 @@ namespace AndroidSettings {
|
||||
&show_performance_overlay};
|
||||
|
||||
|
||||
Settings::Setting<s32> pipeline_worker_count{linkage, 4, "pipeline_worker_count",
|
||||
Settings::Category::Android,
|
||||
Settings::Specialization::Default,
|
||||
true,
|
||||
true};
|
||||
|
||||
|
||||
Settings::Setting<bool> show_input_overlay{linkage, true, "show_input_overlay",
|
||||
Settings::Category::Overlay};
|
||||
Settings::Setting<bool> overlay_snap_to_grid{linkage, false, "overlay_snap_to_grid",
|
||||
|
||||
@@ -524,6 +524,8 @@
|
||||
<string name="rescale_hack_description">Enables a legacy handling for the rescale configuration pass for games by using a quick rescale path</string>
|
||||
<string name="renderer_asynchronous_shaders">Use asynchronous shaders</string>
|
||||
<string name="renderer_asynchronous_shaders_description">Compiles shaders asynchronously. This may reduce stutters but may also introduce glitches.</string>
|
||||
<string name="renderer_unified_memory">Unified memory access (UMA)</string>
|
||||
<string name="renderer_unified_memory_description">Allows GPU write buffer readbacks directly into guest memory, skipping the CPU staging copy.</string>
|
||||
<string name="gpu_unswizzle_settings">GPU Unswizzle Settings</string>
|
||||
<string name="gpu_unswizzle_settings_description">Configure GPU-based texture unswizzling parameters or disable it entirely. Adjust these settings to balance performance and texture loading quality.</string>
|
||||
<string name="gpu_unswizzle_enable">Enable GPU Unswizzle</string>
|
||||
@@ -544,6 +546,10 @@
|
||||
<string name="disabled">Disabled</string>
|
||||
<string name="vertex_input_dynamic_state">Vertex Input Dynamic State</string>
|
||||
<string name="vertex_input_dynamic_state_description">Enabling this feature allows for more flexible vertex input handling, potentially reducing pipeline compilation time in vertex/buffer.</string>
|
||||
<string name="dynamic_rendering">Dynamic Rendering</string>
|
||||
<string name="dynamic_rendering_description">Render without render pass and framebuffer objects. Results vary by driver: some gain performance, others lose it.</string>
|
||||
<string name="workgroup_memory_explicit_layout">Workgroup Memory Explicit Layout</string>
|
||||
<string name="workgroup_memory_explicit_layout_description">Let shaders declare explicit layouts for workgroup memory. Disabled by default: some Qualcomm drivers are unstable with it.</string>
|
||||
<string name="sample_shading_fraction">Sample Shading</string>
|
||||
<string name="sample_shading_fraction_description">Allows the fragment shader to execute per sample in a multi-sampled fragment instead once per fragment. Improves graphics quality at the cost of some performance.</string>
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace AudioCore {
|
||||
|
||||
AudioCore::AudioCore(Core::System& system) {
|
||||
audio_manager.emplace(system);
|
||||
audio_manager.emplace();
|
||||
CreateSinks();
|
||||
// Must be created after the sinks
|
||||
adsp.emplace(system, *output_sink);
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
|
||||
namespace AudioCore::AudioIn {
|
||||
|
||||
Manager::Manager(Core::System& system) {
|
||||
Manager::Manager(Core::System& system_) : system{system_} {
|
||||
std::iota(session_ids.begin(), session_ids.end(), 0);
|
||||
num_free_sessions = MaxInSessions;
|
||||
}
|
||||
|
||||
Result Manager::AcquireSessionId(Core::System& system, size_t& session_id) {
|
||||
Result Manager::AcquireSessionId(size_t& session_id) {
|
||||
if (num_free_sessions == 0) {
|
||||
LOG_ERROR(Service_Audio, "All 4 AudioIn sessions are in use, cannot create any more");
|
||||
return Service::Audio::ResultOutOfSessions;
|
||||
@@ -31,7 +31,7 @@ Result Manager::AcquireSessionId(Core::System& system, size_t& session_id) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void Manager::ReleaseSessionId(Core::System& system, const size_t session_id) {
|
||||
void Manager::ReleaseSessionId(const size_t session_id) {
|
||||
std::scoped_lock l{mutex};
|
||||
LOG_DEBUG(Service_Audio, "Freeing AudioIn session {}", session_id);
|
||||
session_ids[free_session_id] = session_id;
|
||||
@@ -41,20 +41,21 @@ void Manager::ReleaseSessionId(Core::System& system, const size_t session_id) {
|
||||
applet_resource_user_ids[session_id] = 0;
|
||||
}
|
||||
|
||||
Result Manager::LinkToManager(Core::System& system) {
|
||||
Result Manager::LinkToManager() {
|
||||
std::scoped_lock l{mutex};
|
||||
if (!linked_to_manager) {
|
||||
system.AudioCore().GetAudioManager().SetInManager(&Manager::BufferReleaseAndRegister);
|
||||
system.AudioCore().GetAudioManager().SetInManager(std::bind(&Manager::BufferReleaseAndRegister, this));
|
||||
linked_to_manager = true;
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void Manager::Start(Core::System& system) {
|
||||
void Manager::Start() {
|
||||
if (sessions_started) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::scoped_lock l{mutex};
|
||||
for (auto& session : sessions) {
|
||||
if (session) {
|
||||
@@ -65,19 +66,21 @@ void Manager::Start(Core::System& system) {
|
||||
sessions_started = true;
|
||||
}
|
||||
|
||||
void Manager::BufferReleaseAndRegister(void *data, Core::System& system) noexcept {
|
||||
Manager* this_ = (Manager*)data;
|
||||
std::scoped_lock l{this_->mutex};
|
||||
for (auto& session : this_->sessions) {
|
||||
void Manager::BufferReleaseAndRegister() {
|
||||
std::scoped_lock l{mutex};
|
||||
for (auto& session : sessions) {
|
||||
if (session != nullptr) {
|
||||
session->ReleaseAndRegisterBuffers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u32 Manager::GetDeviceNames(Core::System& system, std::span<Renderer::AudioDevice::AudioDeviceName> names, [[maybe_unused]] const bool filter) {
|
||||
u32 Manager::GetDeviceNames(std::span<Renderer::AudioDevice::AudioDeviceName> names,
|
||||
[[maybe_unused]] const bool filter) {
|
||||
std::scoped_lock l{mutex};
|
||||
LinkToManager(system);
|
||||
|
||||
LinkToManager();
|
||||
|
||||
auto input_devices{Sink::GetDeviceListForSink(Settings::values.sink_id.GetValue(), true)};
|
||||
if (!input_devices.empty() && !names.empty()) {
|
||||
names[0] = Renderer::AudioDevice::AudioDeviceName("Uac");
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
@@ -33,29 +30,31 @@ public:
|
||||
* @param session_id - Output session_id.
|
||||
* @return Result code.
|
||||
*/
|
||||
Result AcquireSessionId(Core::System& system, size_t& session_id);
|
||||
Result AcquireSessionId(size_t& session_id);
|
||||
|
||||
/**
|
||||
* Release a session id on close.
|
||||
*
|
||||
* @param session_id - Session id to free.
|
||||
*/
|
||||
void ReleaseSessionId(Core::System& system, const size_t session_id);
|
||||
void ReleaseSessionId(size_t session_id);
|
||||
|
||||
/**
|
||||
* Link the audio in manager to the main audio manager.
|
||||
*
|
||||
* @return Result code.
|
||||
*/
|
||||
Result LinkToManager(Core::System& system);
|
||||
Result LinkToManager();
|
||||
|
||||
/**
|
||||
* Start the audio in manager.
|
||||
*/
|
||||
void Start(Core::System& system);
|
||||
void Start();
|
||||
|
||||
/// @brief Callback function, called by the audio manager when the audio in event is signalled.
|
||||
static void BufferReleaseAndRegister(void *data, Core::System& system) noexcept;
|
||||
/**
|
||||
* Callback function, called by the audio manager when the audio in event is signalled.
|
||||
*/
|
||||
void BufferReleaseAndRegister();
|
||||
|
||||
/**
|
||||
* Get a list of audio in device names.
|
||||
@@ -65,8 +64,10 @@ public:
|
||||
*
|
||||
* @return Number of names written.
|
||||
*/
|
||||
u32 GetDeviceNames(Core::System& system, std::span<Renderer::AudioDevice::AudioDeviceName> names, bool filter);
|
||||
u32 GetDeviceNames(std::span<Renderer::AudioDevice::AudioDeviceName> names, bool filter);
|
||||
|
||||
/// Core system
|
||||
Core::System& system;
|
||||
/// Array of session ids
|
||||
std::array<size_t, MaxInSessions> session_ids{};
|
||||
/// Array of resource user ids
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
namespace AudioCore {
|
||||
|
||||
AudioManager::AudioManager(Core::System& system) {
|
||||
thread = std::jthread([&](std::stop_token stop_token) {
|
||||
AudioManager::AudioManager() {
|
||||
thread = std::jthread([this](std::stop_token stop_token) {
|
||||
Common::SetCurrentThreadName("AudioManager");
|
||||
std::unique_lock l{events.GetAudioEventLock()};
|
||||
events.ClearEvents();
|
||||
@@ -25,7 +25,7 @@ AudioManager::AudioManager(Core::System& system) {
|
||||
const auto event_type = Event::Type(i);
|
||||
if (events.CheckAudioEventSet(event_type) || timed_out) {
|
||||
if (buffer_events[i]) {
|
||||
buffer_events[i](this, system);
|
||||
buffer_events[i]();
|
||||
}
|
||||
}
|
||||
events.SetAudioEvent(event_type, false);
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
#include "audio_core/audio_event.h"
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
}
|
||||
|
||||
union Result;
|
||||
|
||||
namespace AudioCore {
|
||||
@@ -38,9 +34,10 @@ namespace AudioCore {
|
||||
* This is only used by audio in and audio out.
|
||||
*/
|
||||
class AudioManager {
|
||||
using BufferEventFunc = void (*)(void *data, Core::System& system) noexcept;
|
||||
using BufferEventFunc = std::function<void()>;
|
||||
|
||||
public:
|
||||
explicit AudioManager(Core::System& system);
|
||||
explicit AudioManager();
|
||||
|
||||
/**
|
||||
* Shutdown the audio manager.
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
|
||||
namespace AudioCore::AudioOut {
|
||||
|
||||
Manager::Manager(Core::System& system) {
|
||||
Manager::Manager(Core::System& system_) : system{system_} {
|
||||
std::iota(session_ids.begin(), session_ids.end(), 0);
|
||||
num_free_sessions = MaxOutSessions;
|
||||
}
|
||||
|
||||
Result Manager::AcquireSessionId(Core::System& system, size_t& session_id) {
|
||||
Result Manager::AcquireSessionId(size_t& session_id) {
|
||||
if (num_free_sessions == 0) {
|
||||
LOG_ERROR(Service_Audio, "All 12 Audio Out sessions are in use, cannot create any more");
|
||||
return Service::Audio::ResultOutOfSessions;
|
||||
@@ -30,7 +30,7 @@ Result Manager::AcquireSessionId(Core::System& system, size_t& session_id) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void Manager::ReleaseSessionId(Core::System& system, const size_t session_id) {
|
||||
void Manager::ReleaseSessionId(const size_t session_id) {
|
||||
std::scoped_lock l{mutex};
|
||||
LOG_DEBUG(Service_Audio, "Freeing AudioOut session {}", session_id);
|
||||
session_ids[free_session_id] = session_id;
|
||||
@@ -40,17 +40,17 @@ void Manager::ReleaseSessionId(Core::System& system, const size_t session_id) {
|
||||
applet_resource_user_ids[session_id] = 0;
|
||||
}
|
||||
|
||||
Result Manager::LinkToManager(Core::System& system) {
|
||||
Result Manager::LinkToManager() {
|
||||
std::scoped_lock l{mutex};
|
||||
if (!linked_to_manager) {
|
||||
system.AudioCore().GetAudioManager().SetOutManager(&Manager::BufferReleaseAndRegister);
|
||||
system.AudioCore().GetAudioManager().SetOutManager(std::bind(&Manager::BufferReleaseAndRegister, this));
|
||||
linked_to_manager = true;
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void Manager::Start(Core::System& system) {
|
||||
void Manager::Start() {
|
||||
if (sessions_started) {
|
||||
return;
|
||||
}
|
||||
@@ -65,14 +65,19 @@ void Manager::Start(Core::System& system) {
|
||||
sessions_started = true;
|
||||
}
|
||||
|
||||
void Manager::BufferReleaseAndRegister(void *data, Core::System& system) noexcept {
|
||||
Manager* this_ = (Manager*)data;
|
||||
std::scoped_lock l{this_->mutex};
|
||||
for (auto& session : this_->sessions) {
|
||||
void Manager::BufferReleaseAndRegister() {
|
||||
std::scoped_lock l{mutex};
|
||||
for (auto& session : sessions) {
|
||||
if (session != nullptr) {
|
||||
session->ReleaseAndRegisterBuffers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u32 Manager::GetAudioOutDeviceNames(
|
||||
std::vector<Renderer::AudioDevice::AudioDeviceName>& names) const {
|
||||
names.emplace_back("DeviceOut");
|
||||
return 1;
|
||||
}
|
||||
|
||||
} // namespace AudioCore::AudioOut
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
@@ -32,32 +29,42 @@ public:
|
||||
* @param session_id - Output session_id.
|
||||
* @return Result code.
|
||||
*/
|
||||
Result AcquireSessionId(Core::System& system, size_t& session_id);
|
||||
Result AcquireSessionId(size_t& session_id);
|
||||
|
||||
/**
|
||||
* Release a session id on close.
|
||||
*
|
||||
* @param session_id - Session id to free.
|
||||
*/
|
||||
void ReleaseSessionId(Core::System& system, const size_t session_id);
|
||||
void ReleaseSessionId(size_t session_id);
|
||||
|
||||
/**
|
||||
* Link this manager to the main audio manager.
|
||||
*
|
||||
* @return Result code.
|
||||
*/
|
||||
Result LinkToManager(Core::System& system);
|
||||
Result LinkToManager();
|
||||
|
||||
/**
|
||||
* Start the audio out manager.
|
||||
*/
|
||||
void Start(Core::System& system);
|
||||
void Start();
|
||||
|
||||
/**
|
||||
* Callback function, called by the audio manager when the audio out event is signalled.
|
||||
*/
|
||||
static void BufferReleaseAndRegister(void* data, Core::System& system) noexcept;
|
||||
void BufferReleaseAndRegister();
|
||||
|
||||
/**
|
||||
* Get a list of audio out device names.
|
||||
*
|
||||
* @param names - Output container to write names to.
|
||||
* @return Number of names written.
|
||||
*/
|
||||
u32 GetAudioOutDeviceNames(std::vector<Renderer::AudioDevice::AudioDeviceName>& names) const;
|
||||
|
||||
/// Core system
|
||||
Core::System& system;
|
||||
/// Array of session ids
|
||||
std::array<size_t, MaxOutSessions> session_ids{};
|
||||
/// Array of resource user ids
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "audio_core/audio_render_manager.h"
|
||||
#include "audio_core/common/audio_renderer_parameter.h"
|
||||
#include "audio_core/renderer/system_manager.h"
|
||||
#include "audio_core/common/feature_support.h"
|
||||
#include "core/core.h"
|
||||
|
||||
namespace AudioCore::Renderer {
|
||||
|
||||
Manager::Manager(Core::System& system_)
|
||||
: system_manager{std::make_unique<SystemManager>(system_)}
|
||||
{
|
||||
: system{system_}, system_manager{std::make_unique<SystemManager>(system)} {
|
||||
std::iota(session_ids.begin(), session_ids.end(), 0);
|
||||
}
|
||||
|
||||
@@ -64,11 +59,11 @@ u32 Manager::GetSessionCount() const {
|
||||
return session_count;
|
||||
}
|
||||
|
||||
bool Manager::AddSystem(Renderer::System& system_) {
|
||||
bool Manager::AddSystem(System& system_) {
|
||||
return system_manager->Add(system_);
|
||||
}
|
||||
|
||||
bool Manager::RemoveSystem(Renderer::System& system_) {
|
||||
bool Manager::RemoveSystem(System& system_) {
|
||||
return system_manager->Remove(system_);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
@@ -74,7 +71,7 @@ public:
|
||||
* @param system - The system to add.
|
||||
* @return True if the system was successfully added, otherwise false.
|
||||
*/
|
||||
bool AddSystem(Renderer::System& system);
|
||||
bool AddSystem(System& system);
|
||||
|
||||
/**
|
||||
* Remove a renderer system from the manager.
|
||||
@@ -82,7 +79,7 @@ public:
|
||||
* @param system - The system to remove.
|
||||
* @return True if the system was successfully removed, otherwise false.
|
||||
*/
|
||||
bool RemoveSystem(Renderer::System& system);
|
||||
bool RemoveSystem(System& system);
|
||||
|
||||
/**
|
||||
* Free a session id when the system wants to shut down.
|
||||
@@ -92,6 +89,8 @@ public:
|
||||
void ReleaseSessionId(s32 session_id);
|
||||
|
||||
private:
|
||||
/// Core system
|
||||
Core::System& system;
|
||||
/// Session ids, -1 when in use
|
||||
std::array<s32, MaxRendererSessions> session_ids{};
|
||||
/// Number of active renderers
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
@@ -19,9 +16,8 @@ namespace AudioCore {
|
||||
*/
|
||||
class WorkbufferAllocator {
|
||||
public:
|
||||
explicit WorkbufferAllocator(std::span<u8> buffer_)
|
||||
: buffer{buffer_}
|
||||
{}
|
||||
explicit WorkbufferAllocator(std::span<u8> buffer_, u64 size_)
|
||||
: buffer{reinterpret_cast<u64>(buffer_.data())}, size{size_} {}
|
||||
|
||||
/**
|
||||
* Allocate the given count of T elements, aligned to alignment.
|
||||
@@ -33,31 +29,36 @@ public:
|
||||
template <typename T>
|
||||
std::span<T> Allocate(u64 count, u64 alignment) {
|
||||
u64 out{0};
|
||||
u64 byte_size = count * sizeof(T);
|
||||
u64 byte_size{count * sizeof(T)};
|
||||
|
||||
if (byte_size > 0) {
|
||||
auto current{uintptr_t(buffer.data()) + offset};
|
||||
auto current{buffer + offset};
|
||||
auto aligned_buffer{Common::AlignUp(current, alignment)};
|
||||
if (aligned_buffer + byte_size <= uintptr_t(buffer.data()) + buffer.size()) {
|
||||
if (aligned_buffer + byte_size <= buffer + size) {
|
||||
out = aligned_buffer;
|
||||
offset = byte_size - uintptr_t(buffer.data()) + aligned_buffer;
|
||||
offset = byte_size - buffer + aligned_buffer;
|
||||
} else {
|
||||
LOG_ERROR(
|
||||
Service_Audio,
|
||||
"Allocated buffer was too small to hold new alloc.\nAllocator size={:08X}, "
|
||||
"offset={:08X}.\nAttempting to allocate {:08X} with alignment={:02X}",
|
||||
buffer.size(), offset, byte_size, alignment);
|
||||
size, offset, byte_size, alignment);
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return std::span<T>(reinterpret_cast<T*>(out), count);
|
||||
}
|
||||
|
||||
/// @brief Align the current offset to the given alignment.
|
||||
/// @param alignment - The required starting alignment.
|
||||
/**
|
||||
* Align the current offset to the given alignment.
|
||||
*
|
||||
* @param alignment - The required starting alignment.
|
||||
*/
|
||||
void Align(u64 alignment) {
|
||||
auto current{uintptr_t(buffer.data()) + offset};
|
||||
auto current{buffer + offset};
|
||||
auto aligned_buffer{Common::AlignUp(current, alignment)};
|
||||
offset = 0 - uintptr_t(buffer.data()) + aligned_buffer;
|
||||
offset = 0 - buffer + aligned_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +76,7 @@ public:
|
||||
* @return The size of the current buffer.
|
||||
*/
|
||||
u64 GetSize() const {
|
||||
return buffer.size();
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,11 +85,14 @@ public:
|
||||
* @return The remaining size left in the buffer.
|
||||
*/
|
||||
u64 GetRemainingSize() const {
|
||||
return buffer.size() - offset;
|
||||
return size - offset;
|
||||
}
|
||||
|
||||
private:
|
||||
const std::span<u8> buffer;
|
||||
/// The buffer into which we are allocating.
|
||||
u64 buffer;
|
||||
/// Size of the buffer we're allocating to.
|
||||
u64 size;
|
||||
/// Current offset into the buffer, an error will be thrown if it exceeds size.
|
||||
u64 offset{};
|
||||
};
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
@@ -11,43 +8,42 @@
|
||||
namespace AudioCore::AudioIn {
|
||||
|
||||
In::In(Core::System& system_, Manager& manager_, Kernel::KEvent* event_, size_t session_id_)
|
||||
: manager{manager_}, parent_mutex{manager.mutex}, event{event_}
|
||||
, audio_system{system_, event, session_id_}
|
||||
{}
|
||||
: manager{manager_}, parent_mutex{manager.mutex}, event{event_}, system{system_, event,
|
||||
session_id_} {}
|
||||
|
||||
void In::Free(Core::System& system) {
|
||||
void In::Free() {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
manager.ReleaseSessionId(system, audio_system.GetSessionId());
|
||||
manager.ReleaseSessionId(system.GetSessionId());
|
||||
}
|
||||
|
||||
System& In::GetSystem() {
|
||||
return audio_system;
|
||||
return system;
|
||||
}
|
||||
|
||||
AudioIn::State In::GetState() {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.GetState();
|
||||
return system.GetState();
|
||||
}
|
||||
|
||||
Result In::StartSystem() {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.Start();
|
||||
return system.Start();
|
||||
}
|
||||
|
||||
void In::StartSession() {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
audio_system.StartSession();
|
||||
system.StartSession();
|
||||
}
|
||||
|
||||
Result In::StopSystem() {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.Stop();
|
||||
return system.Stop();
|
||||
}
|
||||
|
||||
Result In::AppendBuffer(const AudioInBuffer& buffer, u64 tag) {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
|
||||
if (audio_system.AppendBuffer(buffer, tag)) {
|
||||
if (system.AppendBuffer(buffer, tag)) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
return Service::Audio::ResultBufferCountReached;
|
||||
@@ -55,20 +51,20 @@ Result In::AppendBuffer(const AudioInBuffer& buffer, u64 tag) {
|
||||
|
||||
void In::ReleaseAndRegisterBuffers() {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
if (audio_system.GetState() == State::Started) {
|
||||
audio_system.ReleaseBuffers();
|
||||
audio_system.RegisterBuffers();
|
||||
if (system.GetState() == State::Started) {
|
||||
system.ReleaseBuffers();
|
||||
system.RegisterBuffers();
|
||||
}
|
||||
}
|
||||
|
||||
bool In::FlushAudioInBuffers() {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.FlushAudioInBuffers();
|
||||
return system.FlushAudioInBuffers();
|
||||
}
|
||||
|
||||
u32 In::GetReleasedBuffers(std::span<u64> tags) {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.GetReleasedBuffers(tags);
|
||||
return system.GetReleasedBuffers(tags);
|
||||
}
|
||||
|
||||
Kernel::KReadableEvent& In::GetBufferEvent() {
|
||||
@@ -78,27 +74,27 @@ Kernel::KReadableEvent& In::GetBufferEvent() {
|
||||
|
||||
f32 In::GetVolume() const {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.GetVolume();
|
||||
return system.GetVolume();
|
||||
}
|
||||
|
||||
void In::SetVolume(f32 volume) {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
audio_system.SetVolume(volume);
|
||||
system.SetVolume(volume);
|
||||
}
|
||||
|
||||
bool In::ContainsAudioBuffer(u64 tag) const {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.ContainsAudioBuffer(tag);
|
||||
return system.ContainsAudioBuffer(tag);
|
||||
}
|
||||
|
||||
u32 In::GetBufferCount() const {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.GetBufferCount();
|
||||
return system.GetBufferCount();
|
||||
}
|
||||
|
||||
u64 In::GetPlayedSampleCount() const {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.GetPlayedSampleCount();
|
||||
return system.GetPlayedSampleCount();
|
||||
}
|
||||
|
||||
} // namespace AudioCore::AudioIn
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
@@ -33,7 +30,7 @@ public:
|
||||
/**
|
||||
* Free this audio in from the audio in manager.
|
||||
*/
|
||||
void Free(Core::System& system);
|
||||
void Free();
|
||||
|
||||
/**
|
||||
* Get this audio in's system.
|
||||
@@ -144,7 +141,7 @@ private:
|
||||
/// Buffer event, signalled when buffers are ready to be released
|
||||
Kernel::KEvent* event;
|
||||
/// Main audio in system
|
||||
System audio_system;
|
||||
System system;
|
||||
};
|
||||
|
||||
} // namespace AudioCore::AudioIn
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
@@ -11,43 +8,42 @@
|
||||
namespace AudioCore::AudioOut {
|
||||
|
||||
Out::Out(Core::System& system_, Manager& manager_, Kernel::KEvent* event_, size_t session_id_)
|
||||
: manager{manager_}, parent_mutex{manager.mutex}, event{event_}
|
||||
, audio_system{system_, event, session_id_}
|
||||
{}
|
||||
: manager{manager_}, parent_mutex{manager.mutex}, event{event_}, system{system_, event,
|
||||
session_id_} {}
|
||||
|
||||
void Out::Free(Core::System& system) {
|
||||
void Out::Free() {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
manager.ReleaseSessionId(system, audio_system.GetSessionId());
|
||||
manager.ReleaseSessionId(system.GetSessionId());
|
||||
}
|
||||
|
||||
System& Out::GetSystem() {
|
||||
return audio_system;
|
||||
return system;
|
||||
}
|
||||
|
||||
AudioOut::State Out::GetState() {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.GetState();
|
||||
return system.GetState();
|
||||
}
|
||||
|
||||
Result Out::StartSystem() {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.Start();
|
||||
return system.Start();
|
||||
}
|
||||
|
||||
void Out::StartSession() {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
audio_system.StartSession();
|
||||
system.StartSession();
|
||||
}
|
||||
|
||||
Result Out::StopSystem() {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.Stop();
|
||||
return system.Stop();
|
||||
}
|
||||
|
||||
Result Out::AppendBuffer(const AudioOutBuffer& buffer, const u64 tag) {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
|
||||
if (audio_system.AppendBuffer(buffer, tag)) {
|
||||
if (system.AppendBuffer(buffer, tag)) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
return Service::Audio::ResultBufferCountReached;
|
||||
@@ -55,20 +51,20 @@ Result Out::AppendBuffer(const AudioOutBuffer& buffer, const u64 tag) {
|
||||
|
||||
void Out::ReleaseAndRegisterBuffers() {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
if (audio_system.GetState() == State::Started) {
|
||||
audio_system.ReleaseBuffers();
|
||||
audio_system.RegisterBuffers();
|
||||
if (system.GetState() == State::Started) {
|
||||
system.ReleaseBuffers();
|
||||
system.RegisterBuffers();
|
||||
}
|
||||
}
|
||||
|
||||
bool Out::FlushAudioOutBuffers() {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.FlushAudioOutBuffers();
|
||||
return system.FlushAudioOutBuffers();
|
||||
}
|
||||
|
||||
u32 Out::GetReleasedBuffers(std::span<u64> tags) {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.GetReleasedBuffers(tags);
|
||||
return system.GetReleasedBuffers(tags);
|
||||
}
|
||||
|
||||
Kernel::KReadableEvent& Out::GetBufferEvent() {
|
||||
@@ -78,27 +74,27 @@ Kernel::KReadableEvent& Out::GetBufferEvent() {
|
||||
|
||||
f32 Out::GetVolume() const {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.GetVolume();
|
||||
return system.GetVolume();
|
||||
}
|
||||
|
||||
void Out::SetVolume(const f32 volume) {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
audio_system.SetVolume(volume);
|
||||
system.SetVolume(volume);
|
||||
}
|
||||
|
||||
bool Out::ContainsAudioBuffer(const u64 tag) const {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.ContainsAudioBuffer(tag);
|
||||
return system.ContainsAudioBuffer(tag);
|
||||
}
|
||||
|
||||
u32 Out::GetBufferCount() const {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.GetBufferCount();
|
||||
return system.GetBufferCount();
|
||||
}
|
||||
|
||||
u64 Out::GetPlayedSampleCount() const {
|
||||
std::scoped_lock l{parent_mutex};
|
||||
return audio_system.GetPlayedSampleCount();
|
||||
return system.GetPlayedSampleCount();
|
||||
}
|
||||
|
||||
} // namespace AudioCore::AudioOut
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
@@ -33,7 +30,7 @@ public:
|
||||
/**
|
||||
* Free this audio out from the audio out manager.
|
||||
*/
|
||||
void Free(Core::System& system);
|
||||
void Free();
|
||||
|
||||
/**
|
||||
* Get this audio out's system.
|
||||
@@ -144,7 +141,7 @@ private:
|
||||
/// Buffer event, signalled when buffers are ready to be released
|
||||
Kernel::KEvent* event;
|
||||
/// Main audio out system
|
||||
System audio_system;
|
||||
System system;
|
||||
};
|
||||
|
||||
} // namespace AudioCore::AudioOut
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
@@ -16,48 +13,56 @@
|
||||
namespace AudioCore::Renderer {
|
||||
|
||||
Renderer::Renderer(Core::System& system_, Manager& manager_, Kernel::KEvent* rendered_event)
|
||||
: system{system_}, manager{manager_}
|
||||
, audio_system{system_, rendered_event}
|
||||
{}
|
||||
: core{system_}, manager{manager_}, system{system_, rendered_event} {}
|
||||
|
||||
Result Renderer::Initialize(const AudioRendererParameterInternal& params, Kernel::KTransferMemory* transfer_memory, const u64 transfer_memory_size, Kernel::KProcess* process_handle, const u64 applet_resource_user_id, const s32 session_id) {
|
||||
Result Renderer::Initialize(const AudioRendererParameterInternal& params,
|
||||
Kernel::KTransferMemory* transfer_memory,
|
||||
const u64 transfer_memory_size, Kernel::KProcess* process_handle,
|
||||
const u64 applet_resource_user_id, const s32 session_id) {
|
||||
if (params.execution_mode == ExecutionMode::Auto) {
|
||||
if (!manager.AddSystem(audio_system)) {
|
||||
LOG_ERROR(Service_Audio, "Both Audio Render sessions are in use, cannot create any more");
|
||||
if (!manager.AddSystem(system)) {
|
||||
LOG_ERROR(Service_Audio,
|
||||
"Both Audio Render sessions are in use, cannot create any more");
|
||||
return Service::Audio::ResultOutOfSessions;
|
||||
}
|
||||
system_registered = true;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
audio_system.Initialize(params, transfer_memory, transfer_memory_size, process_handle, applet_resource_user_id, session_id);
|
||||
system.Initialize(params, transfer_memory, transfer_memory_size, process_handle,
|
||||
applet_resource_user_id, session_id);
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void Renderer::Finalize() {
|
||||
auto const session_id{audio_system.GetSessionId()};
|
||||
audio_system.Finalize();
|
||||
auto session_id{system.GetSessionId()};
|
||||
|
||||
system.Finalize();
|
||||
|
||||
if (system_registered) {
|
||||
manager.RemoveSystem(audio_system);
|
||||
manager.RemoveSystem(system);
|
||||
system_registered = false;
|
||||
}
|
||||
|
||||
manager.ReleaseSessionId(session_id);
|
||||
}
|
||||
|
||||
System& Renderer::GetSystem() {
|
||||
return audio_system;
|
||||
return system;
|
||||
}
|
||||
|
||||
void Renderer::Start() {
|
||||
audio_system.Start();
|
||||
system.Start();
|
||||
}
|
||||
|
||||
void Renderer::Stop() {
|
||||
audio_system.Stop();
|
||||
system.Stop();
|
||||
}
|
||||
|
||||
Result Renderer::RequestUpdate(std::span<const u8> input, std::span<u8> performance, std::span<u8> output) {
|
||||
return audio_system.Update(input, performance, output);
|
||||
Result Renderer::RequestUpdate(std::span<const u8> input, std::span<u8> performance,
|
||||
std::span<u8> output) {
|
||||
return system.Update(input, performance, output);
|
||||
}
|
||||
|
||||
} // namespace AudioCore::Renderer
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
@@ -87,7 +84,7 @@ public:
|
||||
|
||||
private:
|
||||
/// System core
|
||||
Core::System& system;
|
||||
Core::System& core;
|
||||
/// Manager this renderer is registered with
|
||||
Manager& manager;
|
||||
/// Is the audio renderer initialized?
|
||||
@@ -95,7 +92,7 @@ private:
|
||||
/// Is the system registered with the manager?
|
||||
bool system_registered{};
|
||||
/// Audio render system, main driver of audio rendering
|
||||
System audio_system;
|
||||
System system;
|
||||
};
|
||||
|
||||
} // namespace Renderer
|
||||
|
||||
@@ -145,7 +145,7 @@ Result System::Initialize(const AudioRendererParameterInternal& params,
|
||||
PoolMapper pool_mapper(process_handle, false);
|
||||
pool_mapper.InitializeSystemPool(memory_pool_info, workbuffer.get(), workbuffer_size);
|
||||
|
||||
WorkbufferAllocator allocator({workbuffer.get(), workbuffer_size});
|
||||
WorkbufferAllocator allocator({workbuffer.get(), workbuffer_size}, workbuffer_size);
|
||||
|
||||
samples_workbuffer =
|
||||
allocator.Allocate<s32>((voice_channels + mix_buffer_count) * sample_count, 0x10);
|
||||
|
||||
+290
-1
@@ -51,14 +51,60 @@
|
||||
|
||||
#endif // ^^^ POSIX ^^^
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
|
||||
#include "common/alignment.h"
|
||||
#include "common/assert.h"
|
||||
#include "common/free_region_manager.h"
|
||||
#include "common/host_memory.h"
|
||||
#include "common/logging.h"
|
||||
#include "common/memory_detect.h"
|
||||
#include "common/settings.h"
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <dlfcn.h>
|
||||
#include <android/hardware_buffer.h>
|
||||
|
||||
namespace {
|
||||
|
||||
struct NativeHandle {
|
||||
int version;
|
||||
int numFds;
|
||||
int numInts;
|
||||
int data[1];
|
||||
};
|
||||
|
||||
using PFN_AHardwareBuffer_getNativeHandle = const NativeHandle* (*)(const AHardwareBuffer*);
|
||||
using PFN_AHardwareBuffer_isSupported = int (*)(const AHardwareBuffer_Desc*);
|
||||
|
||||
void* NativeWindowLibrary() {
|
||||
static void* const lib = dlopen("libnativewindow.so", RTLD_NOW);
|
||||
return lib;
|
||||
}
|
||||
|
||||
PFN_AHardwareBuffer_getNativeHandle ResolveGetNativeHandle() {
|
||||
void* const lib = NativeWindowLibrary();
|
||||
if (lib == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return reinterpret_cast<PFN_AHardwareBuffer_getNativeHandle>(
|
||||
dlsym(lib, "AHardwareBuffer_getNativeHandle"));
|
||||
}
|
||||
|
||||
PFN_AHardwareBuffer_isSupported ResolveIsSupported() {
|
||||
void* const lib = NativeWindowLibrary();
|
||||
if (lib == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return reinterpret_cast<PFN_AHardwareBuffer_isSupported>(
|
||||
dlsym(lib, "AHardwareBuffer_isSupported"));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__) && __ANDROID_API__ < 30
|
||||
#include <sys/syscall.h>
|
||||
@@ -75,6 +121,12 @@ namespace Common {
|
||||
[[maybe_unused]] constexpr size_t PageAlignment = 0x1000;
|
||||
[[maybe_unused]] constexpr size_t HugePageSize = 0x200000;
|
||||
|
||||
static std::atomic<u64> committed_backing_size{};
|
||||
|
||||
u64 GetCommittedBackingSize() noexcept {
|
||||
return committed_backing_size.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
// Manually imported for MinGW compatibility
|
||||
@@ -509,6 +561,11 @@ public:
|
||||
bool Init() {
|
||||
long page_size = sysconf(_SC_PAGESIZE);
|
||||
ASSERT_MSG(page_size == 0x1000, "page size {:#x} is incompatible with 4K paging", page_size);
|
||||
#ifdef __ANDROID__
|
||||
if (InitAhbBacking()) {
|
||||
return InitVirtual();
|
||||
}
|
||||
#endif
|
||||
// Backing memory initialization
|
||||
#if defined(__sun__) || defined(__HAIKU__) || defined(__NetBSD__) || defined(__DragonFly__)
|
||||
fd = shm_open_anon(O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600);
|
||||
@@ -554,7 +611,10 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
// Virtual memory initialization
|
||||
return InitVirtual();
|
||||
}
|
||||
|
||||
bool InitVirtual() {
|
||||
virtual_base = virtual_map_base = static_cast<u8*>(ChooseVirtualBase(virtual_size));
|
||||
if (virtual_base == MAP_FAILED) {
|
||||
LOG_CRITICAL(HW_Memory, "mmap failed: {}", strerror(errno));
|
||||
@@ -567,6 +627,180 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
static AHardwareBuffer_Desc MakeBlobDesc(size_t len) {
|
||||
return AHardwareBuffer_Desc{
|
||||
.width = static_cast<u32>(len),
|
||||
.height = 1,
|
||||
.layers = 1,
|
||||
.format = AHARDWAREBUFFER_FORMAT_BLOB,
|
||||
.usage = AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN |
|
||||
AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
|
||||
AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER,
|
||||
.stride = 0,
|
||||
.rfu0 = 0,
|
||||
.rfu1 = 0,
|
||||
};
|
||||
}
|
||||
|
||||
static bool ProbeAhbBacking(PFN_AHardwareBuffer_getNativeHandle get_native_handle) {
|
||||
const AHardwareBuffer_Desc desc = MakeBlobDesc(PageAlignment * 2);
|
||||
AHardwareBuffer* buffer{};
|
||||
if (AHardwareBuffer_allocate(&desc, &buffer) != 0 || buffer == nullptr) {
|
||||
LOG_WARNING(HW_Memory, "Hardware buffer probe allocation failed");
|
||||
return false;
|
||||
}
|
||||
const NativeHandle* const handle = get_native_handle(buffer);
|
||||
if (handle == nullptr || handle->numFds < 1) {
|
||||
LOG_WARNING(HW_Memory, "Hardware buffer has no mappable file descriptor");
|
||||
AHardwareBuffer_release(buffer);
|
||||
return false;
|
||||
}
|
||||
const int probe_fd = handle->data[0];
|
||||
bool ok = true;
|
||||
const auto try_map = [&](int prot, off_t offset, const char* what) {
|
||||
if (!ok) {
|
||||
return;
|
||||
}
|
||||
void* const ptr = mmap(nullptr, PageAlignment, prot, MAP_SHARED, probe_fd, offset);
|
||||
if (ptr == MAP_FAILED) {
|
||||
LOG_WARNING(HW_Memory, "Hardware buffer backing rejects {}: {}", what,
|
||||
strerror(errno));
|
||||
ok = false;
|
||||
return;
|
||||
}
|
||||
munmap(ptr, PageAlignment);
|
||||
};
|
||||
try_map(PROT_READ | PROT_WRITE, 0, "shared mappings");
|
||||
try_map(PROT_READ | PROT_WRITE, static_cast<off_t>(PageAlignment), "mappings at an offset");
|
||||
#ifdef ARCHITECTURE_arm64
|
||||
try_map(PROT_READ | PROT_EXEC, 0, "executable mappings");
|
||||
#endif
|
||||
AHardwareBuffer_release(buffer);
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool InitAhbBacking() {
|
||||
if (!Settings::values.use_unified_memory.GetValue()) {
|
||||
return false;
|
||||
}
|
||||
static const PFN_AHardwareBuffer_getNativeHandle get_native_handle =
|
||||
ResolveGetNativeHandle();
|
||||
if (get_native_handle == nullptr) {
|
||||
LOG_WARNING(HW_Memory, "AHardwareBuffer_getNativeHandle is not available");
|
||||
return false;
|
||||
}
|
||||
static const PFN_AHardwareBuffer_isSupported is_supported = ResolveIsSupported();
|
||||
if (is_supported == nullptr) {
|
||||
LOG_WARNING(HW_Memory, "AHardwareBuffer_isSupported is not available");
|
||||
return false;
|
||||
}
|
||||
const u64 total_physical = Common::GetMemInfo().TotalPhysicalMemory;
|
||||
if (total_physical != 0 && backing_size > total_physical / 2) {
|
||||
LOG_WARNING(HW_Memory,
|
||||
"Hardware buffer backing would commit {} MiB on a {} MiB system, keeping "
|
||||
"lazily committed memory",
|
||||
backing_size >> 20, total_physical >> 20);
|
||||
return false;
|
||||
}
|
||||
if (!ProbeAhbBacking(get_native_handle)) {
|
||||
return false;
|
||||
}
|
||||
const auto try_window_size = [&](size_t window_size) -> bool {
|
||||
const size_t num_windows = (backing_size + window_size - 1) / window_size;
|
||||
std::vector<AHardwareBuffer*> buffers;
|
||||
std::vector<int> buffer_fds;
|
||||
const auto cleanup = [&] {
|
||||
for (AHardwareBuffer* buffer : buffers) {
|
||||
AHardwareBuffer_release(buffer);
|
||||
}
|
||||
buffers.clear();
|
||||
buffer_fds.clear();
|
||||
};
|
||||
for (size_t i = 0; i < num_windows; ++i) {
|
||||
const size_t len = (std::min)(window_size, backing_size - i * window_size);
|
||||
const AHardwareBuffer_Desc desc = MakeBlobDesc(len);
|
||||
AHardwareBuffer* buffer{};
|
||||
if (AHardwareBuffer_allocate(&desc, &buffer) != 0 || buffer == nullptr) {
|
||||
LOG_WARNING(HW_Memory, "Hardware buffer allocation failed for window {}", i);
|
||||
cleanup();
|
||||
return false;
|
||||
}
|
||||
buffers.push_back(buffer);
|
||||
const NativeHandle* const handle = get_native_handle(buffer);
|
||||
if (handle == nullptr || handle->numFds < 1) {
|
||||
LOG_WARNING(HW_Memory, "Hardware buffer has no mappable file descriptor");
|
||||
cleanup();
|
||||
return false;
|
||||
}
|
||||
const int buffer_fd = handle->data[0];
|
||||
const off_t buffer_len = lseek(buffer_fd, 0, SEEK_END);
|
||||
if (buffer_len < static_cast<off_t>(len)) {
|
||||
LOG_WARNING(HW_Memory, "Hardware buffer descriptor smaller than requested");
|
||||
cleanup();
|
||||
return false;
|
||||
}
|
||||
buffer_fds.push_back(buffer_fd);
|
||||
}
|
||||
u8* const base =
|
||||
static_cast<u8*>(mmap(nullptr, backing_size, PROT_NONE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0));
|
||||
if (base == MAP_FAILED) {
|
||||
cleanup();
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < num_windows; ++i) {
|
||||
const size_t len = (std::min)(window_size, backing_size - i * window_size);
|
||||
if (mmap(base + i * window_size, len, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED | MAP_FIXED, buffer_fds[i], 0) == MAP_FAILED) {
|
||||
LOG_WARNING(HW_Memory, "Hardware buffer mmap failed: {}", strerror(errno));
|
||||
munmap(base, backing_size);
|
||||
cleanup();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
backing_base = base;
|
||||
ahb_windows = std::move(buffers);
|
||||
ahb_fds = std::move(buffer_fds);
|
||||
ahb_window_size = window_size;
|
||||
ahb_backing = true;
|
||||
committed_backing_size.store(backing_size, std::memory_order_relaxed);
|
||||
LOG_INFO(HW_Memory,
|
||||
"Guest memory backed by {} hardware buffer windows of {} MiB, {} MiB committed",
|
||||
ahb_windows.size(), window_size >> 20, backing_size >> 20);
|
||||
return true;
|
||||
};
|
||||
static constexpr size_t candidate_window_sizes[] = {
|
||||
1024ULL << 20,
|
||||
512ULL << 20,
|
||||
256ULL << 20,
|
||||
128ULL << 20,
|
||||
};
|
||||
for (const size_t candidate : candidate_window_sizes) {
|
||||
const AHardwareBuffer_Desc window_desc = MakeBlobDesc(candidate);
|
||||
if (is_supported(&window_desc) == 0) {
|
||||
LOG_DEBUG(HW_Memory, "Allocator rejects {} MiB hardware buffer windows",
|
||||
candidate >> 20);
|
||||
continue;
|
||||
}
|
||||
if (try_window_size(candidate)) {
|
||||
return true;
|
||||
}
|
||||
LOG_WARNING(HW_Memory, "Could not back guest memory with {} MiB windows",
|
||||
candidate >> 20);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::span<AHardwareBuffer* const> AhbWindows() const noexcept {
|
||||
return ahb_windows;
|
||||
}
|
||||
|
||||
size_t AhbWindowSize() const noexcept {
|
||||
return ahb_backing ? ahb_window_size : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
~Impl() {
|
||||
Release();
|
||||
}
|
||||
@@ -587,6 +821,26 @@ public:
|
||||
#ifdef ARCHITECTURE_arm64
|
||||
if (True(perms & MemoryPermission::Execute))
|
||||
prot_flags |= PROT_EXEC;
|
||||
#endif
|
||||
#ifdef __ANDROID__
|
||||
if (ahb_backing) {
|
||||
size_t voff = virtual_offset;
|
||||
size_t hoff = host_offset;
|
||||
size_t remaining = length;
|
||||
while (remaining > 0) {
|
||||
const size_t window = hoff / ahb_window_size;
|
||||
const size_t local = hoff % ahb_window_size;
|
||||
const size_t chunk = (std::min)(remaining, ahb_window_size - local);
|
||||
void* const ret =
|
||||
mmap(virtual_base + voff, chunk, prot_flags, MAP_SHARED | MAP_FIXED,
|
||||
ahb_fds[window], static_cast<off_t>(local));
|
||||
ASSERT_MSG(ret != MAP_FAILED, "mmap: {}", strerror(errno));
|
||||
voff += chunk;
|
||||
hoff += chunk;
|
||||
remaining -= chunk;
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
int flags = (fd >= 0 ? MAP_SHARED : MAP_PRIVATE) | MAP_FIXED;
|
||||
void* ret = mmap(virtual_base + virtual_offset, length, prot_flags, flags, fd, host_offset);
|
||||
@@ -656,6 +910,18 @@ private:
|
||||
int ret = close(fd);
|
||||
ASSERT_MSG(ret == 0, "close failed: {}", strerror(errno));
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
for (AHardwareBuffer* buffer : ahb_windows) {
|
||||
AHardwareBuffer_release(buffer);
|
||||
}
|
||||
ahb_windows.clear();
|
||||
ahb_fds.clear();
|
||||
if (ahb_backing) {
|
||||
committed_backing_size.store(0, std::memory_order_relaxed);
|
||||
ahb_backing = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void AdjustMap(size_t* virtual_offset, size_t* length) {
|
||||
@@ -681,6 +947,13 @@ private:
|
||||
|
||||
int fd{-1}; // memfd file descriptor, -1 is the error value of memfd_create
|
||||
FreeRegionManager free_manager{};
|
||||
|
||||
#ifdef __ANDROID__
|
||||
bool ahb_backing{};
|
||||
std::vector<AHardwareBuffer*> ahb_windows;
|
||||
std::vector<int> ahb_fds;
|
||||
size_t ahb_window_size{};
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // ^^^ POSIX ^^^
|
||||
@@ -767,6 +1040,22 @@ void HostMemory::ClearBackingRegion(size_t physical_offset, size_t length, u32 f
|
||||
std::memset(backing_base + physical_offset, fill_value, length);
|
||||
}
|
||||
|
||||
std::span<AHardwareBuffer* const> HostMemory::BackingHardwareBuffers() const noexcept {
|
||||
#ifdef __ANDROID__
|
||||
return impl ? impl->AhbWindows() : std::span<AHardwareBuffer* const>{};
|
||||
#else
|
||||
return {};
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t HostMemory::BackingHardwareBufferWindowSize() const noexcept {
|
||||
#ifdef __ANDROID__
|
||||
return impl ? impl->AhbWindowSize() : 0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void HostMemory::EnableDirectMappedAddress() {
|
||||
#if !(defined(__OPENORBIS__) || defined(__managarm__))
|
||||
if (impl) {
|
||||
|
||||
@@ -8,12 +8,17 @@
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/virtual_buffer.h"
|
||||
|
||||
struct AHardwareBuffer;
|
||||
|
||||
namespace Common {
|
||||
|
||||
[[nodiscard]] u64 GetCommittedBackingSize() noexcept;
|
||||
|
||||
enum class MemoryPermission : u32 {
|
||||
Read = 1 << 0,
|
||||
Write = 1 << 1,
|
||||
@@ -62,6 +67,14 @@ public:
|
||||
return backing_base;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t BackingSize() const noexcept {
|
||||
return backing_size;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::span<AHardwareBuffer* const> BackingHardwareBuffers() const noexcept;
|
||||
|
||||
[[nodiscard]] size_t BackingHardwareBufferWindowSize() const noexcept;
|
||||
|
||||
[[nodiscard]] u8* VirtualBasePointer() noexcept {
|
||||
return virtual_base;
|
||||
}
|
||||
|
||||
@@ -587,6 +587,9 @@ struct Values {
|
||||
SwitchableSetting<bool> use_asynchronous_shaders{linkage, false, "use_asynchronous_shaders",
|
||||
Category::RendererHacks};
|
||||
|
||||
SwitchableSetting<bool> use_unified_memory{linkage, false, "use_unified_memory",
|
||||
Category::RendererHacks};
|
||||
|
||||
SwitchableSetting<GpuUnswizzleSize> gpu_unswizzle_texture_size{linkage,
|
||||
GpuUnswizzleSize::Large,
|
||||
"gpu_unswizzle_texture_size",
|
||||
@@ -635,6 +638,16 @@ struct Values {
|
||||
#endif
|
||||
"vertex_input_dynamic_state", Category::RendererExtensions};
|
||||
|
||||
SwitchableSetting<bool> dynamic_rendering{linkage, true, "dynamic_rendering",
|
||||
Category::RendererExtensions};
|
||||
|
||||
SwitchableSetting<bool> workgroup_memory_explicit_layout{
|
||||
linkage, false, "workgroup_memory_explicit_layout", Category::RendererExtensions};
|
||||
|
||||
SwitchableSetting<s32, true> pipeline_worker_count{
|
||||
linkage, 2, 2, 8, "pipeline_worker_count", Category::RendererAdvanced,
|
||||
Specialization::Scalar};
|
||||
|
||||
Setting<bool> renderer_debug{linkage, false, "debug", Category::RendererDebug};
|
||||
Setting<bool> renderer_shader_feedback{linkage, false, "shader_feedback",
|
||||
Category::RendererDebug};
|
||||
|
||||
+140
-21
@@ -1,5 +1,6 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: 2013 Dolphin Emulator Project
|
||||
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
@@ -39,6 +40,110 @@
|
||||
#include <unistd.h>
|
||||
#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"
|
||||
#ifdef ARCHITECTURE_x86_64
|
||||
#ifdef _MSC_VER
|
||||
@@ -78,6 +183,21 @@ void SetCurrentThreadPriority(ThreadPriority new_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
|
||||
pthread_t this_thread = pthread_self();
|
||||
const auto scheduling_type = SCHED_OTHER;
|
||||
@@ -132,29 +252,28 @@ void SetCurrentThreadName(const char* name) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void PinCurrentThreadToPerformanceCore(size_t core_id) {
|
||||
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) {
|
||||
void SetCurrentThreadToPerformanceCores() {
|
||||
#if defined(__ANDROID__)
|
||||
cpu_set_t set;
|
||||
CPU_ZERO(&set);
|
||||
CPU_SET(core_id, &set);
|
||||
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
|
||||
const cpu_set_t& mask = PerformanceCoreMask();
|
||||
if (CPU_COUNT(&mask) == 0) {
|
||||
return;
|
||||
}
|
||||
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
|
||||
|
||||
+7
-1
@@ -99,8 +99,14 @@ enum class ThreadPriority : u32 {
|
||||
Critical = 4,
|
||||
};
|
||||
|
||||
enum class ThreadPlacement : u32 {
|
||||
Default = 0,
|
||||
Background = 1,
|
||||
};
|
||||
|
||||
void SetCurrentThreadPriority(ThreadPriority new_priority);
|
||||
void SetCurrentThreadName(const char* name);
|
||||
void PinCurrentThreadToPerformanceCore(size_t core_id);
|
||||
void SetCurrentThreadToPerformanceCores();
|
||||
void SetCurrentThreadToEfficiencyCores();
|
||||
|
||||
} // 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-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||
@@ -37,10 +37,15 @@ class StatefulThreadWorker {
|
||||
using StateMaker = std::conditional_t<with_state, std::function<StateType()>, DummyCallable>;
|
||||
|
||||
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)} {
|
||||
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());
|
||||
if (placement == ThreadPlacement::Background) {
|
||||
Common::SetCurrentThreadPriority(ThreadPriority::Low);
|
||||
Common::SetCurrentThreadToEfficiencyCores();
|
||||
}
|
||||
{
|
||||
[[maybe_unused]] std::conditional_t<with_state, StateType, int> state{func()};
|
||||
while (!stop_token.stop_requested()) {
|
||||
|
||||
@@ -157,6 +157,8 @@ bool ArmNce::HandleGuestAlignmentFault(GuestContext* guest_ctx, void* raw_info,
|
||||
return HandleFailedGuestFault(guest_ctx, raw_info, raw_context);
|
||||
}
|
||||
|
||||
constexpr size_t NCE_WRITE_FAULT_CLUSTER_PAGES = 4;
|
||||
|
||||
bool ArmNce::HandleGuestAccessFault(GuestContext* guest_ctx, void* raw_info, void* raw_context) {
|
||||
auto* info = static_cast<siginfo_t*>(raw_info);
|
||||
|
||||
@@ -165,7 +167,7 @@ bool ArmNce::HandleGuestAccessFault(GuestContext* guest_ctx, void* raw_info, voi
|
||||
const Common::ProcessAddress addr =
|
||||
(reinterpret_cast<u64>(info->si_addr) & ~Memory::YUZU_PAGEMASK);
|
||||
auto& memory = guest_ctx->parent->m_running_thread->GetOwnerProcess()->GetMemory();
|
||||
if (memory.InvalidateNCE(addr, Memory::YUZU_PAGESIZE)) {
|
||||
if (memory.InvalidateNCE(addr, Memory::YUZU_PAGESIZE * NCE_WRITE_FAULT_CLUSTER_PAGES)) {
|
||||
// We handled the access successfully and are returning to guest code.
|
||||
return true;
|
||||
}
|
||||
|
||||
+5
-1
@@ -118,6 +118,7 @@ struct System::Impl {
|
||||
|
||||
is_multicore = Settings::values.use_multi_core.GetValue();
|
||||
extended_memory_layout = Settings::values.memory_layout_mode.GetValue() != Settings::MemoryLayout::Memory_4Gb;
|
||||
unified_memory = Settings::values.use_unified_memory.GetValue();
|
||||
|
||||
core_timing.SetMulticore(is_multicore);
|
||||
core_timing.Initialize([&system]() { system.RegisterHostThread(); });
|
||||
@@ -145,7 +146,8 @@ struct System::Impl {
|
||||
!device_memory.has_value() ||
|
||||
is_multicore != Settings::values.use_multi_core.GetValue() ||
|
||||
extended_memory_layout != (Settings::values.memory_layout_mode.GetValue() !=
|
||||
Settings::MemoryLayout::Memory_4Gb);
|
||||
Settings::MemoryLayout::Memory_4Gb) ||
|
||||
unified_memory != Settings::values.use_unified_memory.GetValue();
|
||||
|
||||
if (!must_reinitialize) {
|
||||
return;
|
||||
@@ -156,6 +158,7 @@ struct System::Impl {
|
||||
is_multicore = Settings::values.use_multi_core.GetValue();
|
||||
extended_memory_layout =
|
||||
Settings::values.memory_layout_mode.GetValue() != Settings::MemoryLayout::Memory_4Gb;
|
||||
unified_memory = Settings::values.use_unified_memory.GetValue();
|
||||
|
||||
Initialize(system);
|
||||
}
|
||||
@@ -503,6 +506,7 @@ struct System::Impl {
|
||||
std::atomic_bool is_powered_on{};
|
||||
bool is_multicore : 1 = false;
|
||||
bool extended_memory_layout : 1 = false;
|
||||
bool unified_memory : 1 = false;
|
||||
bool exit_locked : 1 = false;
|
||||
bool exit_requested : 1 = false;
|
||||
bool nvdec_active : 1 = false;
|
||||
|
||||
@@ -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"};
|
||||
Common::SetCurrentThreadName(name.c_str());
|
||||
Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);
|
||||
#ifdef __ANDROID__
|
||||
// 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
|
||||
Common::SetCurrentThreadToPerformanceCores();
|
||||
auto& data = core_data[core];
|
||||
data.host_context = Common::Fiber::ThreadToFiber();
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include "common/scratch_buffer.h"
|
||||
#include "common/virtual_buffer.h"
|
||||
|
||||
struct AHardwareBuffer;
|
||||
|
||||
namespace Core {
|
||||
|
||||
constexpr size_t DEVICE_PAGEBITS = 12ULL;
|
||||
@@ -95,6 +97,26 @@ public:
|
||||
ApplyOpOnPAddr(address, buffer, operation);
|
||||
}
|
||||
|
||||
u8* GetPhysicalBase() noexcept {
|
||||
return reinterpret_cast<u8*>(physical_base);
|
||||
}
|
||||
|
||||
const u8* GetPhysicalBase() const noexcept {
|
||||
return reinterpret_cast<const u8*>(physical_base);
|
||||
}
|
||||
|
||||
size_t GetPhysicalSize() const noexcept {
|
||||
return physical_size;
|
||||
}
|
||||
|
||||
std::span<AHardwareBuffer* const> GetBackingHardwareBuffers() const noexcept {
|
||||
return ahb_windows;
|
||||
}
|
||||
|
||||
size_t GetBackingHardwareBufferWindowSize() const noexcept {
|
||||
return ahb_window_size;
|
||||
}
|
||||
|
||||
PAddr GetPhysicalRawAddressFromDAddr(DAddr address) const {
|
||||
PAddr subbits = PAddr(address & page_mask);
|
||||
auto paddr = tracked_entries[(address >> page_bits)].compressed_physical_ptr;
|
||||
@@ -126,6 +148,10 @@ public:
|
||||
// New batch API to update multiple ranges with a single lock acquisition.
|
||||
void UpdatePagesCachedBatch(std::span<const std::pair<DAddr, size_t>> ranges, s32 delta);
|
||||
|
||||
void UpdateTexturePagesCount(DAddr addr, size_t size, s32 delta);
|
||||
|
||||
[[nodiscard]] bool IsRegionTextureCached(DAddr addr, size_t size) const noexcept;
|
||||
|
||||
private:
|
||||
struct TranslationEntry {
|
||||
DAddr guest_page{};
|
||||
@@ -171,6 +197,9 @@ private:
|
||||
std::unique_ptr<DeviceMemoryManagerAllocator<Traits>> impl;
|
||||
|
||||
const uintptr_t physical_base;
|
||||
const size_t physical_size;
|
||||
const std::span<AHardwareBuffer* const> ahb_windows;
|
||||
const size_t ahb_window_size;
|
||||
DeviceInterface* device_inter;
|
||||
|
||||
struct TrackedEntry {
|
||||
@@ -234,6 +263,7 @@ private:
|
||||
(1ULL << (device_virtual_bits - page_bits)) / subentries;
|
||||
using CachedPages = std::array<CounterEntry, num_counter_entries>;
|
||||
std::unique_ptr<CachedPages> cached_pages;
|
||||
std::unique_ptr<CachedPages> texture_cached_pages;
|
||||
Common::RangeMutex counter_guard;
|
||||
std::mutex mapping_guard;
|
||||
|
||||
|
||||
@@ -171,12 +171,16 @@ struct DeviceMemoryManagerAllocator {
|
||||
template <typename Traits>
|
||||
DeviceMemoryManager<Traits>::DeviceMemoryManager(const DeviceMemory& device_memory_)
|
||||
: physical_base{uintptr_t(device_memory_.buffer.BackingBasePointer())}
|
||||
, physical_size{device_memory_.buffer.BackingSize()}
|
||||
, ahb_windows{device_memory_.buffer.BackingHardwareBuffers()}
|
||||
, ahb_window_size{device_memory_.buffer.BackingHardwareBufferWindowSize()}
|
||||
, device_inter{nullptr}
|
||||
, compressed_device_addr(1ULL << ((Settings::values.memory_layout_mode.GetValue() == Settings::MemoryLayout::Memory_4Gb ? physical_min_bits : physical_max_bits) - Memory::YUZU_PAGEBITS))
|
||||
, tracked_entries(device_as_size >> Memory::YUZU_PAGEBITS)
|
||||
{
|
||||
impl = std::make_unique<DeviceMemoryManagerAllocator<Traits>>();
|
||||
cached_pages = std::make_unique<CachedPages>();
|
||||
texture_cached_pages = std::make_unique<CachedPages>();
|
||||
|
||||
const size_t total_virtual = device_as_size >> Memory::YUZU_PAGEBITS;
|
||||
for (size_t i = 0; i < total_virtual; i++) {
|
||||
@@ -625,6 +629,28 @@ void DeviceMemoryManager<Traits>::UpdatePagesCachedCount(DAddr addr, size_t size
|
||||
UpdatePagesCachedCountNoLock(addr, size, delta);
|
||||
}
|
||||
|
||||
template <typename Traits>
|
||||
void DeviceMemoryManager<Traits>::UpdateTexturePagesCount(DAddr addr, size_t size, s32 delta) {
|
||||
Common::ScopedRangeLock lk(counter_guard, addr, size);
|
||||
const size_t page_end = Common::DivCeil(addr + size, Memory::YUZU_PAGESIZE);
|
||||
for (size_t page = addr >> Memory::YUZU_PAGEBITS; page != page_end; ++page) {
|
||||
CounterAtomicType& count = texture_cached_pages->at(page >> subentries_shift).Count(page);
|
||||
count.fetch_add(static_cast<CounterType>(delta), std::memory_order_release);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Traits>
|
||||
bool DeviceMemoryManager<Traits>::IsRegionTextureCached(DAddr addr, size_t size) const noexcept {
|
||||
const size_t page_end = Common::DivCeil(addr + size, Memory::YUZU_PAGESIZE);
|
||||
for (size_t page = addr >> Memory::YUZU_PAGEBITS; page != page_end; ++page) {
|
||||
if (texture_cached_pages->at(page >> subentries_shift).Count(page).load(
|
||||
std::memory_order_acquire) != 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename Traits>
|
||||
void DeviceMemoryManager<Traits>::UpdatePagesCachedBatch(std::span<const std::pair<DAddr, size_t>> ranges, s32 delta) {
|
||||
if (ranges.empty()) {
|
||||
|
||||
@@ -50,7 +50,7 @@ IAudioIn::IAudioIn(Core::System& system_, Manager& manager, size_t session_id,
|
||||
}
|
||||
|
||||
IAudioIn::~IAudioIn() {
|
||||
impl->Free(system);
|
||||
impl->Free();
|
||||
service_context.CloseEvent(event);
|
||||
process->Close(system.Kernel());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
@@ -68,7 +65,7 @@ Result IAudioInManager::OpenAudioInAuto(
|
||||
Result IAudioInManager::ListAudioInsAutoFiltered(
|
||||
OutArray<AudioDeviceName, BufferAttr_HipcAutoSelect> out_audio_ins, Out<u32> out_count) {
|
||||
LOG_DEBUG(Service_Audio, "called");
|
||||
*out_count = impl->GetDeviceNames(system, out_audio_ins, true);
|
||||
*out_count = impl->GetDeviceNames(out_audio_ins, true);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
@@ -93,8 +90,8 @@ Result IAudioInManager::OpenAudioInProtocolSpecified(
|
||||
|
||||
size_t new_session_id{};
|
||||
|
||||
R_TRY(impl->LinkToManager(system));
|
||||
R_TRY(impl->AcquireSessionId(system, new_session_id));
|
||||
R_TRY(impl->LinkToManager());
|
||||
R_TRY(impl->AcquireSessionId(new_session_id));
|
||||
|
||||
LOG_DEBUG(Service_Audio, "Opening new AudioIn, session_id={}, free sessions={}", new_session_id,
|
||||
impl->num_free_sessions);
|
||||
|
||||
@@ -46,7 +46,7 @@ IAudioOut::IAudioOut(Core::System& system_, Manager& manager, size_t session_id,
|
||||
}
|
||||
|
||||
IAudioOut::~IAudioOut() {
|
||||
impl->Free(system);
|
||||
impl->Free();
|
||||
service_context.CloseEvent(event);
|
||||
process->Close(system.Kernel());
|
||||
}
|
||||
|
||||
@@ -77,8 +77,8 @@ Result IAudioOutManager::OpenAudioOutAuto(
|
||||
}
|
||||
|
||||
size_t new_session_id{};
|
||||
R_TRY(impl->LinkToManager(system));
|
||||
R_TRY(impl->AcquireSessionId(system, new_session_id));
|
||||
R_TRY(impl->LinkToManager());
|
||||
R_TRY(impl->AcquireSessionId(new_session_id));
|
||||
|
||||
const auto device_name = Common::StringFromBuffer(name[0].name);
|
||||
LOG_DEBUG(Service_Audio, "Opening new AudioOut, sessionid={}, free sessions={}", new_session_id,
|
||||
|
||||
@@ -230,6 +230,11 @@ std::unique_ptr<TranslationMap> InitializeTranslations(QObject* parent) {
|
||||
tr("Preserves GPU-modified data by reading it back before uploading.\nSome games require this to render certain effects properly."));
|
||||
INSERT(Settings, use_asynchronous_shaders, tr("Enable asynchronous shader compilation"),
|
||||
tr("May reduce shader stutter."));
|
||||
INSERT(Settings, use_unified_memory, tr("Enable unified memory access (UMA)"),
|
||||
tr("Lets the GPU write buffer readbacks directly into guest memory."));
|
||||
INSERT(Settings, pipeline_worker_count, tr("Pipeline Worker Threads"),
|
||||
tr("Number of threads used to build Vulkan pipelines.\n"
|
||||
"Higher values speed up compilation at the cost of heat and power."));
|
||||
INSERT(Settings, fast_gpu_time, tr("Fast GPU Time"),
|
||||
tr("Overclocks the emulated GPU to increase dynamic resolution and render "
|
||||
"distance.\nUse 256 for maximal performance and 512 for maximal graphics fidelity."));
|
||||
@@ -287,6 +292,12 @@ std::unique_ptr<TranslationMap> InitializeTranslations(QObject* parent) {
|
||||
INSERT(Settings, vertex_input_dynamic_state, tr("Vertex Input Dynamic State"),
|
||||
tr("Enables vertex input dynamic state feature for better quality and performance."));
|
||||
|
||||
INSERT(Settings, dynamic_rendering, tr("Dynamic Rendering"),
|
||||
tr("Renders without render pass and framebuffer objects.\n"
|
||||
"Results vary by driver: some gain performance, others lose it."));
|
||||
|
||||
INSERT(Settings, workgroup_memory_explicit_layout, QString(), QString());
|
||||
|
||||
INSERT(
|
||||
Settings, sample_shading, tr("Sample Shading"),
|
||||
tr("Allows the fragment shader to execute per sample in a multi-sampled fragment "
|
||||
|
||||
@@ -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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
@@ -665,6 +665,8 @@ void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, ScalarU32 value, ScalarU3
|
||||
const IR::Value& clamp, const IR::Value& segmentation_mask);
|
||||
void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, ScalarU32 value, ScalarU32 index,
|
||||
const IR::Value& clamp, const IR::Value& segmentation_mask);
|
||||
void EmitQuadBroadcast(EmitContext& ctx, IR::Inst& inst, ScalarU32 value, ScalarU32 lane);
|
||||
void EmitQuadSwap(EmitContext& ctx, IR::Inst& inst, ScalarU32 value, ScalarU32 direction);
|
||||
void EmitFSwizzleAdd(EmitContext& ctx, IR::Inst& inst, ScalarF32 op_a, ScalarF32 op_b,
|
||||
ScalarU32 swizzle);
|
||||
void EmitDPdxFine(EmitContext& ctx, IR::Inst& inst, ScalarF32 op_a);
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
@@ -97,6 +100,24 @@ void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, ScalarU32 value, Sca
|
||||
Shuffle(ctx, inst, value, index, clamp, segmentation_mask, "XOR");
|
||||
}
|
||||
|
||||
void EmitQuadBroadcast(EmitContext& ctx, IR::Inst& inst, ScalarU32 value, ScalarU32 lane) {
|
||||
const Register ret{ctx.reg_alloc.Define(inst)};
|
||||
ctx.Add("AND.U RC.x,{}.threadid,~3;"
|
||||
"AND.U RC.y,{},3;"
|
||||
"OR.U RC.x,RC.x,RC.y;"
|
||||
"SHFIDX.U {},{},RC.x,0x1C03;"
|
||||
"MOV.U {}.x,{}.y;",
|
||||
ctx.stage_name, lane, ret, value, ret, ret);
|
||||
}
|
||||
|
||||
void EmitQuadSwap(EmitContext& ctx, IR::Inst& inst, ScalarU32 value, ScalarU32 direction) {
|
||||
const Register ret{ctx.reg_alloc.Define(inst)};
|
||||
ctx.Add("ADD.U RC.x,{},1;"
|
||||
"SHFXOR.U {},{},RC.x,0x1C03;"
|
||||
"MOV.U {}.x,{}.y;",
|
||||
direction, ret, value, ret, ret);
|
||||
}
|
||||
|
||||
void EmitFSwizzleAdd(EmitContext& ctx, IR::Inst& inst, ScalarF32 op_a, ScalarF32 op_b,
|
||||
ScalarU32 swizzle) {
|
||||
const auto ret{ctx.reg_alloc.Define(inst)};
|
||||
|
||||
@@ -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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
@@ -743,6 +743,10 @@ void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view index, std::string_view clamp,
|
||||
std::string_view segmentation_mask);
|
||||
void EmitQuadBroadcast(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view lane);
|
||||
void EmitQuadSwap(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view direction);
|
||||
void EmitFSwizzleAdd(EmitContext& ctx, IR::Inst& inst, std::string_view op_a, std::string_view op_b,
|
||||
std::string_view swizzle);
|
||||
void EmitDPdxFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a);
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
@@ -200,6 +203,18 @@ void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view val
|
||||
ctx.AddU32("{}=shfl_in_bounds?shfl_result:{};", inst, value);
|
||||
}
|
||||
|
||||
void EmitQuadBroadcast(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view lane) {
|
||||
const auto src_thread_id{fmt::format("(({}&~3)|({}& 3))", THREAD_ID, lane)};
|
||||
ctx.AddU32("{}=readInvocationARB({},{});", inst, value, src_thread_id);
|
||||
}
|
||||
|
||||
void EmitQuadSwap(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view direction) {
|
||||
const auto src_thread_id{fmt::format("({}^({}+1))", THREAD_ID, direction)};
|
||||
ctx.AddU32("{}=readInvocationARB({},{});", inst, value, src_thread_id);
|
||||
}
|
||||
|
||||
void EmitFSwizzleAdd(EmitContext& ctx, IR::Inst& inst, std::string_view op_a, std::string_view op_b,
|
||||
std::string_view swizzle) {
|
||||
const auto mask{fmt::format("({}>>((gl_SubGroupInvocationARB&3)<<1))&3", swizzle)};
|
||||
|
||||
@@ -322,6 +322,11 @@ void DefineEntryPoint(const IR::Program& program, EmitContext& ctx, Id main) {
|
||||
if (ctx.runtime_info.force_early_z) {
|
||||
ctx.AddExecutionMode(main, spv::ExecutionMode::EarlyFragmentTests);
|
||||
}
|
||||
if (ctx.profile.support_shader_quad_control && program.info.uses_quad_shuffles) {
|
||||
ctx.AddExtension("SPV_KHR_quad_control");
|
||||
ctx.AddCapability(spv::Capability::QuadControlKHR);
|
||||
ctx.AddExecutionMode(main, spv::ExecutionMode::RequireFullQuadsKHR);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw NotImplementedException("Stage {}", program.stage);
|
||||
@@ -443,6 +448,12 @@ void SetupCapabilities(const Profile& profile, const Info& info, EmitContext& ct
|
||||
ctx.AddCapability(spv::Capability::GroupNonUniformVote);
|
||||
}
|
||||
}
|
||||
if (info.uses_quad_shuffles) {
|
||||
if (profile.support_quad_shuffles) {
|
||||
ctx.AddCapability(spv::Capability::GroupNonUniformQuad);
|
||||
}
|
||||
ctx.AddCapability(spv::Capability::GroupNonUniformShuffle);
|
||||
}
|
||||
if (info.uses_int64_bit_atomics && profile.support_int64_atomics) {
|
||||
ctx.AddCapability(spv::Capability::Int64Atomics);
|
||||
}
|
||||
|
||||
@@ -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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
@@ -622,6 +622,8 @@ Id EmitShuffleDown(EmitContext& ctx, IR::Inst* inst, Id value, Id index, Id clam
|
||||
Id segmentation_mask);
|
||||
Id EmitShuffleButterfly(EmitContext& ctx, IR::Inst* inst, Id value, Id index, Id clamp,
|
||||
Id segmentation_mask);
|
||||
Id EmitQuadBroadcast(EmitContext& ctx, Id value, Id lane);
|
||||
Id EmitQuadSwap(EmitContext& ctx, Id value, Id direction);
|
||||
Id EmitFSwizzleAdd(EmitContext& ctx, Id op_a, Id op_b, Id swizzle);
|
||||
Id EmitDPdxFine(EmitContext& ctx, Id op_a);
|
||||
Id EmitDPdyFine(EmitContext& ctx, Id op_a);
|
||||
|
||||
@@ -260,6 +260,21 @@ Id EmitShuffleButterfly(EmitContext& ctx, IR::Inst* inst, Id value, Id index, Id
|
||||
return SelectValue(ctx, in_range, value, src_thread_id);
|
||||
}
|
||||
|
||||
Id EmitQuadBroadcast(EmitContext& ctx, Id value, Id lane) {
|
||||
if (ctx.profile.support_quad_shuffles) {
|
||||
return ctx.OpGroupNonUniformQuadBroadcast(ctx.U32[1], SubgroupScope(ctx), value, lane);
|
||||
}
|
||||
const Id base{ctx.OpBitwiseAnd(ctx.U32[1], GetThreadId(ctx), ctx.Const(~3u))};
|
||||
const Id local_lane{ctx.OpBitwiseAnd(ctx.U32[1], lane, ctx.Const(3u))};
|
||||
const Id src_thread_id{ctx.OpBitwiseOr(ctx.U32[1], base, local_lane)};
|
||||
return ctx.OpGroupNonUniformShuffle(ctx.U32[1], SubgroupScope(ctx), value, src_thread_id);
|
||||
}
|
||||
|
||||
Id EmitQuadSwap(EmitContext& ctx, Id value, Id direction) {
|
||||
const Id xor_mask{ctx.OpIAdd(ctx.U32[1], direction, ctx.Const(1u))};
|
||||
return ctx.OpGroupNonUniformShuffleXor(ctx.U32[1], SubgroupScope(ctx), value, xor_mask);
|
||||
}
|
||||
|
||||
Id EmitFSwizzleAdd(EmitContext& ctx, Id op_a, Id op_b, Id swizzle) {
|
||||
const Id three{ctx.Const(3U)};
|
||||
Id mask{GetThreadId(ctx)};
|
||||
|
||||
@@ -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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
@@ -2100,6 +2100,14 @@ U32 IREmitter::ShuffleButterfly(const IR::U32& value, const IR::U32& index, cons
|
||||
return Inst<U32>(Opcode::ShuffleButterfly, value, index, clamp, seg_mask);
|
||||
}
|
||||
|
||||
U32 IREmitter::QuadBroadcast(const IR::U32& value, const IR::U32& lane) {
|
||||
return Inst<U32>(Opcode::QuadBroadcast, value, lane);
|
||||
}
|
||||
|
||||
U32 IREmitter::QuadSwap(const IR::U32& value, const IR::U32& direction) {
|
||||
return Inst<U32>(Opcode::QuadSwap, value, direction);
|
||||
}
|
||||
|
||||
F32 IREmitter::FSwizzleAdd(const F32& a, const F32& b, const U32& swizzle, FpControl control) {
|
||||
return Inst<F32>(Opcode::FSwizzleAdd, Flags{control}, a, b, swizzle);
|
||||
}
|
||||
|
||||
@@ -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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
@@ -394,6 +394,8 @@ public:
|
||||
const IR::U32& seg_mask);
|
||||
[[nodiscard]] U32 ShuffleButterfly(const IR::U32& value, const IR::U32& index,
|
||||
const IR::U32& clamp, const IR::U32& seg_mask);
|
||||
[[nodiscard]] U32 QuadBroadcast(const IR::U32& value, const IR::U32& lane);
|
||||
[[nodiscard]] U32 QuadSwap(const IR::U32& value, const IR::U32& direction);
|
||||
[[nodiscard]] F32 FSwizzleAdd(const F32& a, const F32& b, const U32& swizzle,
|
||||
FpControl control = {});
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Shader::IR {
|
||||
|
||||
namespace Detail {
|
||||
|
||||
OpcodeMeta META_TABLE[532] = {
|
||||
OpcodeMeta META_TABLE[] = {
|
||||
#define OPCODE(name_token, type_token, ...) \
|
||||
{ \
|
||||
.name{#name_token}, \
|
||||
@@ -21,7 +21,7 @@ OpcodeMeta META_TABLE[532] = {
|
||||
#undef OPCODE
|
||||
};
|
||||
|
||||
u8 NUM_ARGS[532] = {
|
||||
u8 NUM_ARGS[] = {
|
||||
#define OPCODE(name_token, type_token, ...) u8(CalculateNumArgsOf(Opcode::name_token)),
|
||||
#include "opcodes.inc"
|
||||
#undef OPCODE
|
||||
|
||||
@@ -57,12 +57,12 @@ static constexpr Type F64x2{Type::F64x2};
|
||||
static constexpr Type F64x3{Type::F64x3};
|
||||
static constexpr Type F64x4{Type::F64x4};
|
||||
|
||||
extern OpcodeMeta META_TABLE[532];
|
||||
extern OpcodeMeta META_TABLE[];
|
||||
constexpr size_t CalculateNumArgsOf(Opcode op) noexcept {
|
||||
const auto& arg_types = META_TABLE[size_t(op)].arg_types;
|
||||
return size_t(std::distance(arg_types.begin(), std::ranges::find(arg_types, Type::Void)));
|
||||
}
|
||||
extern u8 NUM_ARGS[532];
|
||||
extern u8 NUM_ARGS[];
|
||||
} // namespace Detail
|
||||
|
||||
/// Get return type of an opcode
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
@@ -579,6 +582,8 @@ OPCODE(ShuffleIndex, U32, U32,
|
||||
OPCODE(ShuffleUp, U32, U32, U32, U32, U32, )
|
||||
OPCODE(ShuffleDown, U32, U32, U32, U32, U32, )
|
||||
OPCODE(ShuffleButterfly, U32, U32, U32, U32, U32, )
|
||||
OPCODE(QuadBroadcast, U32, U32, U32, )
|
||||
OPCODE(QuadSwap, U32, U32, U32, )
|
||||
OPCODE(FSwizzleAdd, F32, F32, F32, U32, )
|
||||
OPCODE(DPdxFine, F32, F32, )
|
||||
OPCODE(DPdyFine, F32, F32, )
|
||||
|
||||
+30
-61
@@ -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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
@@ -39,17 +39,6 @@ IR::U32 scaleIndex(IR::IREmitter& ir, IR::U32 index, Shift shift) {
|
||||
}
|
||||
}
|
||||
|
||||
IR::U32 skewBytes(IR::IREmitter& ir, SZ sizeRead) {
|
||||
const IR::U32 lane = ir.LaneId();
|
||||
switch (sizeRead) {
|
||||
case SZ::U8: return lane;
|
||||
case SZ::U16: return ir.ShiftLeftLogical(lane, ir.Imm32(1));
|
||||
case SZ::U32:
|
||||
case SZ::F32: return ir.ShiftLeftLogical(lane, ir.Imm32(2));
|
||||
default: UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
} // Anonymous namespace
|
||||
|
||||
void TranslatorVisitor::ISBERD(u64 insn) {
|
||||
@@ -68,61 +57,41 @@ void TranslatorVisitor::ISBERD(u64 insn) {
|
||||
BitField<47, 2, Shift> shift;
|
||||
} const isberd{insn};
|
||||
|
||||
IR::U32 index{};
|
||||
if (isberd.src_reg_num.Value() == 0xFF) {
|
||||
index = ir.Imm32(isberd.imm.Value());
|
||||
} else {
|
||||
const IR::U32 scaledIndex = scaleIndex(ir, X(isberd.src_reg.Value()), isberd.shift.Value());
|
||||
index = ir.IAdd(scaledIndex, ir.Imm32(isberd.imm.Value()));
|
||||
if (isberd.skew != 0) {
|
||||
throw NotImplementedException("ISBERD SKEW");
|
||||
}
|
||||
if (isberd.o != 0) {
|
||||
throw NotImplementedException("ISBERD O");
|
||||
}
|
||||
if (isberd.sz.Value() > SZ::F32) {
|
||||
throw NotImplementedException("ISBERD SZ {}",
|
||||
static_cast<u64>(isberd.sz.Value()));
|
||||
}
|
||||
if (isberd.shift.Value() > Shift::B32) {
|
||||
throw NotImplementedException("ISBERD Shift {}",
|
||||
static_cast<u64>(isberd.shift.Value()));
|
||||
}
|
||||
|
||||
if (isberd.o.Value()) {
|
||||
if (isberd.skew.Value()) {
|
||||
index = ir.IAdd(index, skewBytes(ir, isberd.sz.Value()));
|
||||
switch (isberd.mode.Value()) {
|
||||
case Mode::Default:
|
||||
X(isberd.dest_reg.Value(), X(isberd.src_reg.Value()));
|
||||
return;
|
||||
case Mode::Attr: {
|
||||
IR::U32 offset{};
|
||||
if (isberd.src_reg_num.Value() == 0xFF) {
|
||||
offset = ir.Imm32(isberd.imm.Value());
|
||||
} else {
|
||||
const IR::U32 index{
|
||||
scaleIndex(ir, X(isberd.src_reg.Value()), isberd.shift.Value())};
|
||||
offset = ir.IAdd(index, ir.Imm32(isberd.imm.Value()));
|
||||
}
|
||||
|
||||
const IR::U64 index64 = ir.UConvert(64, index);
|
||||
IR::U32 globalLoaded{};
|
||||
switch (isberd.sz.Value()) {
|
||||
case SZ::U8: globalLoaded = ir.LoadGlobalU8 (index64); break;
|
||||
case SZ::U16: globalLoaded = ir.LoadGlobalU16(index64); break;
|
||||
case SZ::U32:
|
||||
case SZ::F32: globalLoaded = ir.LoadGlobal32(index64); break;
|
||||
default: UNREACHABLE();
|
||||
}
|
||||
X(isberd.dest_reg.Value(), globalLoaded);
|
||||
|
||||
X(isberd.dest_reg.Value(), ir.BitCast<IR::U32>(ir.GetAttributeIndexed(offset)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (isberd.mode.Value() != Mode::Default) {
|
||||
if (isberd.skew.Value()) {
|
||||
index = ir.IAdd(index, skewBytes(ir, SZ::U32));
|
||||
}
|
||||
|
||||
IR::F32 float_index{};
|
||||
switch (isberd.mode.Value()) {
|
||||
case Mode::Patch: float_index = ir.GetPatch(index.Patch());
|
||||
break;
|
||||
case Mode::Prim: float_index = ir.GetAttribute(index.Attribute());
|
||||
break;
|
||||
case Mode::Attr: float_index = ir.GetAttributeIndexed(index);
|
||||
break;
|
||||
default: UNREACHABLE();
|
||||
}
|
||||
X(isberd.dest_reg.Value(), ir.BitCast<IR::U32>(float_index));
|
||||
|
||||
return;
|
||||
default:
|
||||
throw NotImplementedException("ISBERD Mode {}",
|
||||
static_cast<u64>(isberd.mode.Value()));
|
||||
}
|
||||
|
||||
if (isberd.skew.Value()) {
|
||||
X(isberd.dest_reg.Value(), ir.IAdd(X(isberd.src_reg.Value()), ir.LaneId()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback copy
|
||||
X(isberd.dest_reg.Value(), X(isberd.src_reg.Value()));
|
||||
}
|
||||
|
||||
} // namespace Shader::Maxwell
|
||||
|
||||
@@ -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-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
@@ -36,7 +36,10 @@ enum class ShuffleMode : u64 {
|
||||
}
|
||||
}
|
||||
|
||||
void Shuffle(TranslatorVisitor& v, u64 insn, const IR::U32& index, const IR::U32& mask) {
|
||||
constexpr u32 QUAD_MASK = (28u << 8) | 3u;
|
||||
|
||||
void Shuffle(TranslatorVisitor& v, u64 insn, const IR::U32& index, const IR::U32& mask,
|
||||
bool index_is_imm, u32 index_imm, bool mask_is_imm, u32 mask_imm) {
|
||||
union {
|
||||
u64 insn;
|
||||
BitField<0, 8, IR::Reg> dest_reg;
|
||||
@@ -45,6 +48,21 @@ void Shuffle(TranslatorVisitor& v, u64 insn, const IR::U32& index, const IR::U32
|
||||
BitField<48, 3, IR::Pred> pred;
|
||||
} const shfl{insn};
|
||||
|
||||
const bool is_quad_candidate{mask_is_imm && mask_imm == QUAD_MASK && index_is_imm &&
|
||||
v.env.ShaderStage() == Stage::Fragment};
|
||||
if (is_quad_candidate) {
|
||||
if (shfl.mode == ShuffleMode::IDX && index_imm <= 3) {
|
||||
v.X(shfl.dest_reg, v.ir.QuadBroadcast(v.X(shfl.src_reg), v.ir.Imm32(index_imm)));
|
||||
v.ir.SetPred(shfl.pred, v.ir.Imm1(true));
|
||||
return;
|
||||
}
|
||||
if (shfl.mode == ShuffleMode::BFLY && index_imm >= 1 && index_imm <= 3) {
|
||||
v.X(shfl.dest_reg, v.ir.QuadSwap(v.X(shfl.src_reg), v.ir.Imm32(index_imm - 1)));
|
||||
v.ir.SetPred(shfl.pred, v.ir.Imm1(true));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const IR::U32 result{ShuffleOperation(v.ir, v.X(shfl.src_reg), index, mask, shfl.mode)};
|
||||
v.ir.SetPred(shfl.pred, v.ir.GetInBoundsFromOp(result));
|
||||
v.X(shfl.dest_reg, result);
|
||||
@@ -59,11 +77,14 @@ void TranslatorVisitor::SHFL(u64 insn) {
|
||||
BitField<29, 1, u64> src_b_flag;
|
||||
BitField<34, 13, u64> src_b_imm;
|
||||
} const flags{insn};
|
||||
const IR::U32 src_a{flags.src_a_flag != 0 ? ir.Imm32(static_cast<u32>(flags.src_a_imm))
|
||||
: GetReg20(insn)};
|
||||
const IR::U32 src_b{flags.src_b_flag != 0 ? ir.Imm32(static_cast<u32>(flags.src_b_imm))
|
||||
: GetReg39(insn)};
|
||||
Shuffle(*this, insn, src_a, src_b);
|
||||
const bool index_is_imm{flags.src_a_flag != 0};
|
||||
const bool mask_is_imm{flags.src_b_flag != 0};
|
||||
const IR::U32 src_a{index_is_imm ? ir.Imm32(static_cast<u32>(flags.src_a_imm))
|
||||
: GetReg20(insn)};
|
||||
const IR::U32 src_b{mask_is_imm ? ir.Imm32(static_cast<u32>(flags.src_b_imm))
|
||||
: GetReg39(insn)};
|
||||
Shuffle(*this, insn, src_a, src_b, index_is_imm, static_cast<u32>(flags.src_a_imm),
|
||||
mask_is_imm, static_cast<u32>(flags.src_b_imm));
|
||||
}
|
||||
|
||||
} // namespace Shader::Maxwell
|
||||
|
||||
@@ -498,6 +498,10 @@ void VisitUsages(Info& info, IR::Inst& inst) {
|
||||
case IR::Opcode::ShuffleButterfly:
|
||||
info.uses_subgroup_shuffles = true;
|
||||
break;
|
||||
case IR::Opcode::QuadBroadcast:
|
||||
case IR::Opcode::QuadSwap:
|
||||
info.uses_quad_shuffles = true;
|
||||
break;
|
||||
case IR::Opcode::GetCbufU8:
|
||||
case IR::Opcode::GetCbufS8:
|
||||
case IR::Opcode::GetCbufU16:
|
||||
|
||||
@@ -37,6 +37,8 @@ struct Profile {
|
||||
bool support_explicit_workgroup_layout{};
|
||||
bool support_workgroup_layout_8bit_access{};
|
||||
bool support_workgroup_layout_16bit_access{};
|
||||
bool support_shader_quad_control{};
|
||||
bool support_quad_shuffles{};
|
||||
bool support_vote{};
|
||||
u32 supported_subgroup_stages{0x7F};
|
||||
bool support_viewport_index_layer_non_geometry{};
|
||||
|
||||
@@ -252,6 +252,7 @@ struct Info {
|
||||
bool uses_is_helper_invocation{};
|
||||
bool uses_subgroup_invocation_id{};
|
||||
bool uses_subgroup_shuffles{};
|
||||
bool uses_quad_shuffles{};
|
||||
std::array<bool, 30> uses_patches{};
|
||||
|
||||
std::array<Interpolation, 32> interpolation{};
|
||||
|
||||
@@ -33,7 +33,7 @@ add_library(video_core STATIC
|
||||
control/channel_state_cache.h
|
||||
control/scheduler.cpp
|
||||
control/scheduler.h
|
||||
delayed_destruction_ring.h
|
||||
deferred_destruction_queue.h
|
||||
dirty_flags.cpp
|
||||
dirty_flags.h
|
||||
dma_pusher.cpp
|
||||
@@ -158,6 +158,8 @@ add_library(video_core STATIC
|
||||
renderer_vulkan/vk_compute_pass.h
|
||||
renderer_vulkan/vk_compute_pipeline.cpp
|
||||
renderer_vulkan/vk_compute_pipeline.h
|
||||
renderer_vulkan/vk_descriptor_buffer.cpp
|
||||
renderer_vulkan/vk_descriptor_buffer.h
|
||||
renderer_vulkan/vk_descriptor_pool.cpp
|
||||
renderer_vulkan/vk_descriptor_pool.h
|
||||
renderer_vulkan/vk_fence_manager.cpp
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <bit>
|
||||
#include <memory>
|
||||
#include <numeric>
|
||||
|
||||
@@ -31,44 +32,84 @@ BufferCache<P>::BufferCache(Tegra::MaxwellDeviceMemoryManager& device_memory_, R
|
||||
immediately_free = (Settings::values.vram_usage_mode.GetValue() == Settings::VramUsageMode::Aggressive);
|
||||
#endif
|
||||
if (!runtime.CanReportMemoryUsage()) {
|
||||
minimum_memory = DEFAULT_EXPECTED_MEMORY;
|
||||
critical_memory = DEFAULT_CRITICAL_MEMORY;
|
||||
memory_budget = FALLBACK_MEMORY_BUDGET;
|
||||
return;
|
||||
}
|
||||
|
||||
const s64 device_local_memory = static_cast<s64>(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));
|
||||
memory_budget = runtime.GetDeviceLocalMemory();
|
||||
}
|
||||
|
||||
template <class P>
|
||||
BufferCache<P>::~BufferCache() = default;
|
||||
|
||||
template <class P>
|
||||
void BufferCache<P>::RunGarbageCollector() {
|
||||
const bool aggressive_gc = total_used_memory >= critical_memory;
|
||||
const u64 ticks_to_destroy = aggressive_gc ? 60 : 120;
|
||||
int num_iterations = aggressive_gc ? 64 : 32;
|
||||
const auto clean_up = [this, &num_iterations](BufferId buffer_id) {
|
||||
if (num_iterations == 0) {
|
||||
u64 BufferCache<P>::DeviceUsage(bool force_refresh) {
|
||||
if (!runtime.CanReportMemoryUsage()) {
|
||||
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 BufferCache<P>::ReclaimMemory(u64 target_bytes, bool allow_download) {
|
||||
if (target_bytes == 0 || in_reclaim) {
|
||||
return 0;
|
||||
}
|
||||
in_reclaim = true;
|
||||
u64 freed = 0;
|
||||
const auto clean_up = [&](BufferId buffer_id) {
|
||||
if (freed >= target_bytes) {
|
||||
return true;
|
||||
}
|
||||
--num_iterations;
|
||||
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);
|
||||
DeleteBuffer(buffer_id);
|
||||
freed += buffer_bytes;
|
||||
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 == 0) {
|
||||
lru_cache.ForEachItemBelow(frame_tick > 0 ? frame_tick - 1 : 0, clean_up);
|
||||
}
|
||||
in_reclaim = false;
|
||||
usage_refresh_countdown = 0;
|
||||
reclaim_stalled = freed == 0;
|
||||
if (freed > 0) {
|
||||
reclaim_wait_sync_point = runtime.CurrentSyncPoint();
|
||||
}
|
||||
return freed;
|
||||
}
|
||||
|
||||
template <class P>
|
||||
void BufferCache<P>::EnsureHeadroom(bool allow_download) {
|
||||
if (reclaim_stalled) {
|
||||
return;
|
||||
}
|
||||
if (runtime.CompletedSyncPoint() < reclaim_wait_sync_point) {
|
||||
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;
|
||||
const u64 excess = usage - target;
|
||||
const u64 usage_mib = (std::max)(usage >> 20, u64{1});
|
||||
const u64 share = (((excess >> 20) * (total_used_memory >> 20)) / usage_mib) << 20;
|
||||
ReclaimMemory((std::min)(share, total_used_memory), allow_download);
|
||||
}
|
||||
|
||||
template <class P>
|
||||
@@ -96,15 +137,11 @@ void BufferCache<P>::TickFrame() {
|
||||
const bool skip_preferred = hits * 256 < shots * 251;
|
||||
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.
|
||||
if (runtime.CanReportMemoryUsage()) {
|
||||
total_used_memory = runtime.GetDeviceMemoryUsage();
|
||||
}
|
||||
if (total_used_memory >= minimum_memory) {
|
||||
RunGarbageCollector();
|
||||
}
|
||||
usage_refresh_countdown = 0;
|
||||
reclaim_stalled = false;
|
||||
EnsureHeadroom(true);
|
||||
++frame_tick;
|
||||
delayed_destruction_ring.Tick();
|
||||
sentenced_buffers.Reclaim(runtime.CompletedSyncPoint());
|
||||
|
||||
for (auto& buffer : async_buffers_death_ring) {
|
||||
runtime.FreeDeferredStagingBuffer(buffer);
|
||||
@@ -175,9 +212,71 @@ std::optional<VideoCore::RasterizerDownloadArea> BufferCache<P>::GetFlushArea(DA
|
||||
|
||||
template <class P>
|
||||
void BufferCache<P>::DownloadMemory(DAddr device_addr, u64 size) {
|
||||
ForEachBufferInRange(device_addr, size, [&](BufferId, Buffer& buffer) {
|
||||
DownloadBufferMemory(buffer, device_addr, size);
|
||||
if constexpr (!USE_MEMORY_MAPS) {
|
||||
std::scoped_lock lock{mutex};
|
||||
ForEachBufferInRange(device_addr, size, [&](BufferId, Buffer& buffer) {
|
||||
DownloadBufferMemory(buffer, device_addr, size);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
boost::container::small_vector<std::pair<BufferCopy, BufferId>, 8> downloads;
|
||||
u64 total_size_bytes = 0;
|
||||
u64 largest_copy = 0;
|
||||
|
||||
std::unique_lock lock{mutex};
|
||||
ForEachBufferInRange(device_addr, size, [&](BufferId buffer_id, Buffer& buffer) {
|
||||
memory_tracker.ForEachDownloadRangeAndClear(
|
||||
device_addr, size, [&](u64 device_addr_out, u64 range_size) {
|
||||
const DAddr buffer_addr = buffer.CpuAddr();
|
||||
const auto add_download = [&](DAddr start, DAddr end) {
|
||||
const u64 new_offset = start - buffer_addr;
|
||||
const u64 new_size = end - start;
|
||||
downloads.push_back({
|
||||
BufferCopy{
|
||||
.src_offset = new_offset,
|
||||
.dst_offset = total_size_bytes,
|
||||
.size = new_size,
|
||||
},
|
||||
buffer_id,
|
||||
});
|
||||
constexpr u64 align = 64ULL;
|
||||
constexpr u64 mask = ~(align - 1ULL);
|
||||
total_size_bytes += (new_size + align - 1) & mask;
|
||||
largest_copy = (std::max)(largest_copy, new_size);
|
||||
};
|
||||
gpu_modified_ranges.ForEachInRange(device_addr_out, range_size, add_download);
|
||||
ClearDownload(device_addr_out, range_size);
|
||||
gpu_modified_ranges.Subtract(device_addr_out, range_size);
|
||||
});
|
||||
});
|
||||
if (total_size_bytes == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto download_staging = runtime.DownloadStagingBuffer(total_size_bytes);
|
||||
boost::container::small_vector<BufferCopy, 8> writebacks;
|
||||
runtime.PreCopyBarrier();
|
||||
for (auto& [copy, buffer_id] : downloads) {
|
||||
copy.dst_offset += download_staging.offset;
|
||||
Buffer& buffer = slot_buffers[buffer_id];
|
||||
buffer.MarkUsage(copy.src_offset, copy.size);
|
||||
const std::array copies{copy};
|
||||
runtime.CopyBuffer(download_staging.buffer, buffer, copies, false);
|
||||
BufferCopy writeback{copy};
|
||||
writeback.src_offset = static_cast<u64>(buffer.CpuAddr()) + copy.src_offset;
|
||||
writebacks.push_back(writeback);
|
||||
}
|
||||
runtime.PostCopyBarrier();
|
||||
lock.unlock();
|
||||
|
||||
runtime.Finish();
|
||||
const u8* const base = download_staging.mapped_span.data();
|
||||
for (const BufferCopy& writeback : writebacks) {
|
||||
const u64 staging_offset = writeback.dst_offset - download_staging.offset;
|
||||
device_memory.WriteBlockUnsafe(static_cast<DAddr>(writeback.src_offset),
|
||||
base + staging_offset, writeback.size);
|
||||
}
|
||||
}
|
||||
|
||||
template <class P>
|
||||
@@ -214,7 +313,7 @@ bool BufferCache<P>::DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 am
|
||||
auto& src_buffer = slot_buffers[buffer_a];
|
||||
auto& dest_buffer = slot_buffers[buffer_b];
|
||||
SynchronizeBuffer(src_buffer, *cpu_src_address, static_cast<u32>(amount));
|
||||
SynchronizeBuffer(dest_buffer, *cpu_dest_address, static_cast<u32>(amount));
|
||||
memory_tracker.UnmarkRegionAsCpuModified(*cpu_dest_address, static_cast<u32>(amount));
|
||||
std::array copies{BufferCopy{
|
||||
.src_offset = src_buffer.Offset(*cpu_src_address),
|
||||
.dst_offset = dest_buffer.Offset(*cpu_dest_address),
|
||||
@@ -673,32 +772,44 @@ void BufferCache<P>::PopAsyncFlushes() {
|
||||
|
||||
template <class P>
|
||||
void BufferCache<P>::PopAsyncBuffers() {
|
||||
if (async_buffers.empty()) {
|
||||
return;
|
||||
}
|
||||
if (!async_buffers.front().has_value()) {
|
||||
struct Writeback {
|
||||
DAddr addr;
|
||||
const u8* src;
|
||||
u64 size;
|
||||
};
|
||||
boost::container::small_vector<Writeback, 8> writebacks;
|
||||
{
|
||||
std::scoped_lock lock{mutex};
|
||||
if (async_buffers.empty()) {
|
||||
return;
|
||||
}
|
||||
if (!async_buffers.front().has_value()) {
|
||||
async_buffers.pop_front();
|
||||
return;
|
||||
}
|
||||
auto& downloads = pending_downloads.front();
|
||||
auto& async_buffer = async_buffers.front();
|
||||
const u8* base = async_buffer->mapped_span.data();
|
||||
const size_t base_offset = async_buffer->offset;
|
||||
for (const auto& copy : downloads) {
|
||||
const DAddr device_addr = static_cast<DAddr>(copy.src_offset);
|
||||
const u64 dst_offset = copy.dst_offset - base_offset;
|
||||
const u8* read_mapped_memory = base + dst_offset;
|
||||
async_downloads.ForEachInRange(device_addr, copy.size, [&](DAddr start, DAddr end, s32) {
|
||||
writebacks.push_back(
|
||||
{start, &read_mapped_memory[start - device_addr], end - start});
|
||||
});
|
||||
async_downloads.Subtract(device_addr, copy.size, [&](DAddr start, DAddr end) {
|
||||
gpu_modified_ranges.Subtract(start, end - start);
|
||||
});
|
||||
}
|
||||
async_buffers_death_ring.emplace_back(*async_buffer);
|
||||
async_buffers.pop_front();
|
||||
return;
|
||||
pending_downloads.pop_front();
|
||||
}
|
||||
auto& downloads = pending_downloads.front();
|
||||
auto& async_buffer = async_buffers.front();
|
||||
u8* base = async_buffer->mapped_span.data();
|
||||
const size_t base_offset = async_buffer->offset;
|
||||
for (const auto& copy : downloads) {
|
||||
const DAddr device_addr = static_cast<DAddr>(copy.src_offset);
|
||||
const u64 dst_offset = copy.dst_offset - base_offset;
|
||||
const u8* read_mapped_memory = base + dst_offset;
|
||||
async_downloads.ForEachInRange(device_addr, copy.size, [&](DAddr start, DAddr end, s32) {
|
||||
device_memory.WriteBlockUnsafe(start, &read_mapped_memory[start - device_addr],
|
||||
end - start);
|
||||
});
|
||||
async_downloads.Subtract(device_addr, copy.size, [&](DAddr start, DAddr end) {
|
||||
gpu_modified_ranges.Subtract(start, end - start);
|
||||
});
|
||||
for (const auto& wb : writebacks) {
|
||||
device_memory.WriteBlockUnsafe(wb.addr, wb.src, wb.size);
|
||||
}
|
||||
async_buffers_death_ring.emplace_back(*async_buffer);
|
||||
async_buffers.pop_front();
|
||||
pending_downloads.pop_front();
|
||||
}
|
||||
|
||||
template <class P>
|
||||
@@ -809,46 +920,46 @@ void BufferCache<P>::BindHostVertexBuffers() {
|
||||
|
||||
if (use_optimized_vertex_buffers) {
|
||||
auto& flags = maxwell3d->dirty.flags;
|
||||
u32 enabled_mask = enabled_vertex_buffers_mask;
|
||||
HostBindings<Buffer> bindings{};
|
||||
u32 last_index = (std::numeric_limits<u32>::max)();
|
||||
const auto flush_bindings = [&]() {
|
||||
if (bindings.buffers.empty()) {
|
||||
return;
|
||||
}
|
||||
bindings.max_index = bindings.min_index + static_cast<u32>(bindings.buffers.size());
|
||||
runtime.BindVertexBuffers(bindings);
|
||||
bindings = HostBindings<Buffer>{};
|
||||
last_index = (std::numeric_limits<u32>::max)();
|
||||
};
|
||||
while (enabled_mask != 0) {
|
||||
const u32 index = std::countr_zero(enabled_mask);
|
||||
enabled_mask &= (enabled_mask - 1);
|
||||
const u32 enabled_mask = enabled_vertex_buffers_mask;
|
||||
bool any_dirty = false;
|
||||
u32 pending_mask = enabled_mask;
|
||||
while (pending_mask != 0) {
|
||||
const u32 index = std::countr_zero(pending_mask);
|
||||
pending_mask &= (pending_mask - 1);
|
||||
const Binding& binding = VertexBufferSlot(index);
|
||||
Buffer& buffer = slot_buffers[binding.buffer_id];
|
||||
TouchBuffer(buffer, binding.buffer_id);
|
||||
SynchronizeBuffer(buffer, binding.device_addr, binding.size);
|
||||
if (!flags[Dirty::VertexBuffer0 + index]) {
|
||||
flush_bindings();
|
||||
continue;
|
||||
}
|
||||
any_dirty |= flags[Dirty::VertexBuffer0 + index];
|
||||
}
|
||||
if (enabled_mask == 0 || !any_dirty) {
|
||||
return;
|
||||
}
|
||||
const u32 min_index = static_cast<u32>(std::countr_zero(enabled_mask));
|
||||
const u32 max_index = 32u - static_cast<u32>(std::countl_zero(enabled_mask));
|
||||
HostBindings<Buffer> bindings{};
|
||||
bindings.min_index = min_index;
|
||||
bindings.max_index = max_index;
|
||||
for (u32 index = min_index; index < max_index; ++index) {
|
||||
flags[Dirty::VertexBuffer0 + index] = false;
|
||||
const u32 stride = maxwell3d->regs.vertex_streams[index].stride;
|
||||
if ((enabled_mask & (1u << index)) == 0) {
|
||||
bindings.buffers.push_back(&slot_buffers[NULL_BUFFER_ID]);
|
||||
bindings.offsets.push_back(0);
|
||||
bindings.sizes.push_back(0);
|
||||
bindings.strides.push_back(stride);
|
||||
continue;
|
||||
}
|
||||
const Binding& binding = VertexBufferSlot(index);
|
||||
Buffer& buffer = slot_buffers[binding.buffer_id];
|
||||
const u32 offset = buffer.Offset(binding.device_addr);
|
||||
buffer.MarkUsage(offset, binding.size);
|
||||
if (!bindings.buffers.empty() && index != last_index + 1) {
|
||||
flush_bindings();
|
||||
}
|
||||
if (bindings.buffers.empty()) {
|
||||
bindings.min_index = index;
|
||||
}
|
||||
bindings.buffers.push_back(&buffer);
|
||||
bindings.offsets.push_back(offset);
|
||||
bindings.sizes.push_back(binding.size);
|
||||
bindings.strides.push_back(stride);
|
||||
last_index = index;
|
||||
}
|
||||
flush_bindings();
|
||||
runtime.BindVertexBuffers(bindings);
|
||||
} else {
|
||||
HostBindings<typename P::Buffer> host_bindings;
|
||||
bool any_valid{false};
|
||||
@@ -921,7 +1032,6 @@ void BufferCache<P>::BindHostGraphicsUniformBuffers(size_t stage) {
|
||||
|
||||
template <class P>
|
||||
void BufferCache<P>::BindHostGraphicsUniformBuffer(size_t stage, u32 index, u32 binding_index, bool needs_bind) {
|
||||
++channel_state->uniform_cache_shots[0];
|
||||
const Binding& binding = channel_state->uniform_buffers[stage][index];
|
||||
const DAddr device_addr = binding.device_addr;
|
||||
const u32 size = (std::min)(binding.size, (*channel_state->uniform_buffer_sizes)[stage][index]);
|
||||
@@ -940,8 +1050,12 @@ void BufferCache<P>::BindHostGraphicsUniformBuffer(size_t stage, u32 index, u32
|
||||
return alignment > 1 && (offset % alignment) != 0;
|
||||
}
|
||||
}();
|
||||
|
||||
const bool cached_buffer_is_current =
|
||||
has_host_buffer && !memory_tracker.IsRegionCpuModified(device_addr, size);
|
||||
const bool use_fast_buffer = needs_alignment_stream
|
||||
|| (has_host_buffer && size <= channel_state->uniform_buffer_skip_cache_size
|
||||
|| (has_host_buffer && !cached_buffer_is_current
|
||||
&& size <= channel_state->uniform_buffer_skip_cache_size
|
||||
&& !memory_tracker.IsRegionGpuModified(device_addr, size));
|
||||
if (use_fast_buffer) {
|
||||
if constexpr (IS_OPENGL) {
|
||||
@@ -968,7 +1082,7 @@ void BufferCache<P>::BindHostGraphicsUniformBuffer(size_t stage, u32 index, u32
|
||||
device_memory.ReadBlockUnsafe(device_addr, span.data(), size);
|
||||
return;
|
||||
}
|
||||
// Classic cached path
|
||||
++channel_state->uniform_cache_shots[0];
|
||||
if (SynchronizeBuffer(buffer, device_addr, size)) {
|
||||
++channel_state->uniform_cache_hits[0];
|
||||
}
|
||||
@@ -1576,6 +1690,7 @@ void BufferCache<P>::JoinOverlap(BufferId new_buffer_id, BufferId overlap_id,
|
||||
|
||||
template <class P>
|
||||
BufferId BufferCache<P>::CreateBuffer(DAddr device_addr, u32 wanted_size) {
|
||||
EnsureHeadroom(false);
|
||||
DAddr device_addr_end = Common::AlignUp(device_addr + wanted_size, CACHING_PAGESIZE);
|
||||
device_addr = Common::AlignDown(device_addr, CACHING_PAGESIZE);
|
||||
wanted_size = static_cast<u32>(device_addr_end - device_addr);
|
||||
@@ -1613,7 +1728,7 @@ void BufferCache<P>::ChangeRegister(BufferId buffer_id) {
|
||||
total_used_memory += Common::AlignUp(size, 1024);
|
||||
buffer.setLRUID(lru_cache.Insert(buffer_id, frame_tick));
|
||||
} 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());
|
||||
}
|
||||
const DAddr device_addr_begin = buffer.CpuAddr();
|
||||
@@ -1699,6 +1814,80 @@ void BufferCache<P>::ImmediateUploadMemory([[maybe_unused]] Buffer& buffer,
|
||||
}
|
||||
}
|
||||
|
||||
template <class P>
|
||||
bool BufferCache<P>::TryUnifiedDownloadMemory([[maybe_unused]] Buffer& buffer,
|
||||
[[maybe_unused]] std::span<BufferCopy> copies) {
|
||||
if constexpr (USE_UNIFIED_MEMORY) {
|
||||
const u8* const physical_base = device_memory.GetPhysicalBase();
|
||||
const u64 unified_size = runtime.UnifiedMemorySize();
|
||||
const u64 window_size = runtime.UnifiedMemoryWindowSize();
|
||||
if (window_size == 0) {
|
||||
return false;
|
||||
}
|
||||
boost::container::small_vector<u64, 4> window_ids;
|
||||
boost::container::small_vector<boost::container::small_vector<BufferCopy, 16>, 4> groups;
|
||||
const auto group_for = [&](u64 window) -> boost::container::small_vector<BufferCopy, 16>& {
|
||||
for (size_t i = 0; i < window_ids.size(); ++i) {
|
||||
if (window_ids[i] == window) {
|
||||
return groups[i];
|
||||
}
|
||||
}
|
||||
window_ids.push_back(window);
|
||||
groups.emplace_back();
|
||||
return groups.back();
|
||||
};
|
||||
for (const BufferCopy& copy : copies) {
|
||||
const DAddr device_addr = buffer.CpuAddr() + copy.src_offset;
|
||||
u64 downloaded = 0;
|
||||
while (downloaded < copy.size) {
|
||||
const DAddr page_addr = device_addr + downloaded;
|
||||
const u8* const ptr = device_memory.GetPointer<u8>(page_addr);
|
||||
if (ptr == nullptr) {
|
||||
return false;
|
||||
}
|
||||
const u64 page_offset = page_addr & Core::DEVICE_PAGEMASK;
|
||||
u64 chunk = (std::min)(copy.size - downloaded,
|
||||
static_cast<u64>(Core::DEVICE_PAGESIZE) - page_offset);
|
||||
const u64 phys_offset = static_cast<u64>(ptr - physical_base);
|
||||
if (phys_offset + chunk > unified_size) {
|
||||
return false;
|
||||
}
|
||||
const u64 window = phys_offset / window_size;
|
||||
const u64 local_offset = phys_offset % window_size;
|
||||
chunk = (std::min)(chunk, window_size - local_offset);
|
||||
auto& group = group_for(window);
|
||||
if (!group.empty()) {
|
||||
BufferCopy& last = group.back();
|
||||
if (last.src_offset + last.size == copy.src_offset + downloaded &&
|
||||
last.dst_offset + last.size == local_offset) {
|
||||
last.size += chunk;
|
||||
downloaded += chunk;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
group.push_back(BufferCopy{
|
||||
.src_offset = copy.src_offset + downloaded,
|
||||
.dst_offset = local_offset,
|
||||
.size = chunk,
|
||||
});
|
||||
downloaded += chunk;
|
||||
}
|
||||
}
|
||||
for (const BufferCopy& copy : copies) {
|
||||
buffer.MarkUsage(copy.src_offset, copy.size);
|
||||
}
|
||||
for (size_t i = 0; i < window_ids.size(); ++i) {
|
||||
const std::span<BufferCopy> group_span(groups[i].data(), groups[i].size());
|
||||
runtime.CopyBuffer(runtime.UnifiedMemoryWindowBuffer(window_ids[i]), buffer,
|
||||
group_span, true);
|
||||
}
|
||||
runtime.Finish();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template <class P>
|
||||
void BufferCache<P>::MappedUploadMemory([[maybe_unused]] Buffer& buffer,
|
||||
[[maybe_unused]] u64 total_size_bytes,
|
||||
@@ -1802,6 +1991,12 @@ void BufferCache<P>::DownloadBufferMemory(Buffer& buffer, DAddr device_addr, u64
|
||||
}
|
||||
|
||||
if constexpr (USE_MEMORY_MAPS) {
|
||||
if constexpr (USE_UNIFIED_MEMORY) {
|
||||
if (runtime.HasUnifiedMemory() &&
|
||||
TryUnifiedDownloadMemory(buffer, std::span(copies.data(), copies.size()))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto download_staging = runtime.DownloadStagingBuffer(total_size_bytes);
|
||||
const u8* const mapped_memory = download_staging.mapped_span.data();
|
||||
const std::span<BufferCopy> copies_span(copies.data(), copies.data() + copies.size());
|
||||
@@ -1872,7 +2067,7 @@ void BufferCache<P>::DeleteBuffer(BufferId buffer_id, bool do_not_mark) {
|
||||
#ifdef YUZU_LEGACY
|
||||
if (!do_not_mark || !immediately_free)
|
||||
#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);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <bit>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@@ -30,7 +31,7 @@
|
||||
#include "common/slot_vector.h"
|
||||
#include "video_core/buffer_cache/buffer_base.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/engines/maxwell_3d.h"
|
||||
#include "video_core/engines/kepler_compute.h"
|
||||
@@ -180,15 +181,18 @@ class BufferCache : public VideoCommon::ChannelSetupCaches<BufferCacheChannelInf
|
||||
static constexpr bool USE_MEMORY_MAPS = P::USE_MEMORY_MAPS;
|
||||
static constexpr bool SEPARATE_IMAGE_BUFFERS_BINDINGS = P::SEPARATE_IMAGE_BUFFER_BINDINGS;
|
||||
static constexpr bool USE_MEMORY_MAPS_FOR_UPLOADS = P::USE_MEMORY_MAPS_FOR_UPLOADS;
|
||||
static constexpr bool USE_UNIFIED_MEMORY = P::USE_UNIFIED_MEMORY;
|
||||
|
||||
#ifdef YUZU_LEGACY
|
||||
static constexpr s64 TARGET_THRESHOLD = 3_GiB;
|
||||
static constexpr u64 RECLAIM_HEADROOM = 384_MiB;
|
||||
#else
|
||||
static constexpr s64 TARGET_THRESHOLD = 4_GiB;
|
||||
static constexpr u64 RECLAIM_HEADROOM = 512_MiB;
|
||||
#endif
|
||||
|
||||
static constexpr s64 DEFAULT_EXPECTED_MEMORY = 512_MiB;
|
||||
static constexpr s64 DEFAULT_CRITICAL_MEMORY = 1_GiB;
|
||||
static constexpr u64 FALLBACK_MEMORY_BUDGET = 2_GiB;
|
||||
static constexpr u32 USAGE_REFRESH_INTERVAL = 16;
|
||||
static constexpr u64 RECLAIM_GUARD_FRAMES = 8;
|
||||
static constexpr u64 RECLAIM_TARGET_PERCENT = 95;
|
||||
|
||||
// Debug Flags.
|
||||
|
||||
@@ -215,6 +219,8 @@ public:
|
||||
|
||||
void TickFrame();
|
||||
|
||||
u64 ReclaimMemory(u64 target_bytes, bool allow_download);
|
||||
|
||||
void WriteMemory(DAddr device_addr, u64 size);
|
||||
|
||||
void CachedWriteMemory(DAddr device_addr, u64 size);
|
||||
@@ -358,7 +364,9 @@ private:
|
||||
((device_addr + size) & ~Core::DEVICE_PAGEMASK);
|
||||
}
|
||||
|
||||
void RunGarbageCollector();
|
||||
u64 DeviceUsage(bool force_refresh);
|
||||
|
||||
void EnsureHeadroom(bool allow_download);
|
||||
|
||||
void BindHostIndexBuffer();
|
||||
|
||||
@@ -443,6 +451,8 @@ private:
|
||||
|
||||
void MappedUploadMemory(Buffer& buffer, u64 total_size_bytes, std::span<BufferCopy> copies);
|
||||
|
||||
bool TryUnifiedDownloadMemory(Buffer& buffer, std::span<BufferCopy> copies);
|
||||
|
||||
void DownloadBufferMemory(Buffer& buffer_id);
|
||||
|
||||
void DownloadBufferMemory(Buffer& buffer_id, DAddr device_addr, u64 size);
|
||||
@@ -475,12 +485,7 @@ private:
|
||||
Tegra::MaxwellDeviceMemoryManager& device_memory;
|
||||
|
||||
Common::SlotVector<Buffer> slot_buffers;
|
||||
#ifdef YUZU_LEGACY
|
||||
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;
|
||||
DeferredDestructionQueue<Buffer> sentenced_buffers;
|
||||
|
||||
const Tegra::Engines::Maxwell3D::DrawManager::IndirectParams* current_draw_indirect{};
|
||||
|
||||
@@ -515,8 +520,14 @@ private:
|
||||
Common::LeastRecentlyUsedCache<LRUItemParams> lru_cache;
|
||||
u64 frame_tick = 0;
|
||||
u64 total_used_memory = 0;
|
||||
u64 minimum_memory = 0;
|
||||
u64 critical_memory = 0;
|
||||
u64 memory_budget = 0;
|
||||
u64 cached_device_usage = 0;
|
||||
/// Sync point the last reclaim's evictions were queued at. Their memory is not back with the
|
||||
/// device until this completes, so reclaiming again before then measures stale usage.
|
||||
u64 reclaim_wait_sync_point = 0;
|
||||
u32 usage_refresh_countdown = 0;
|
||||
bool in_reclaim = false;
|
||||
bool reclaim_stalled = false;
|
||||
BufferId inline_buffer_id;
|
||||
#ifdef YUZU_LEGACY
|
||||
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
|
||||
@@ -71,7 +71,8 @@ void Fermi2D::Blit() {
|
||||
constexpr s64 null_derivative = 1ULL << 32;
|
||||
Surface src = regs.src;
|
||||
const auto bytes_per_pixel = BytesPerBlock(PixelFormatFromRenderTargetFormat(src.format));
|
||||
const bool delegate_to_gpu = src.width > 512 && src.height > 512 && bytes_per_pixel <= 8 &&
|
||||
const u64 src_area = static_cast<u64>(src.width) * static_cast<u64>(src.height);
|
||||
const bool delegate_to_gpu = src_area > 512ULL * 512ULL && bytes_per_pixel <= 8 &&
|
||||
src.format != regs.dst.format;
|
||||
|
||||
auto srcX = args.src_x0;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "common/common_types.h"
|
||||
#include "common/settings.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/host1x/host1x.h"
|
||||
#include "video_core/host1x/syncpoint_manager.h"
|
||||
@@ -50,7 +50,8 @@ public:
|
||||
/// Notify the fence manager about a new frame
|
||||
void TickFrame() {
|
||||
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
|
||||
@@ -91,9 +92,6 @@ public:
|
||||
func();
|
||||
}
|
||||
fences.push(std::move(new_fence));
|
||||
if (should_flush) {
|
||||
rasterizer.FlushCommands();
|
||||
}
|
||||
if constexpr (can_async_check) {
|
||||
guard.unlock();
|
||||
cv.notify_all();
|
||||
@@ -186,7 +184,7 @@ private:
|
||||
}
|
||||
{
|
||||
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();
|
||||
}
|
||||
@@ -219,7 +217,7 @@ private:
|
||||
}
|
||||
{
|
||||
std::unique_lock lock(ring_guard);
|
||||
delayed_destruction_ring.Push(std::move(current_fence));
|
||||
sentenced_fences.Push(std::move(current_fence), retire_tick);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -238,10 +236,10 @@ private:
|
||||
|
||||
void PopAsyncFlushes() {
|
||||
{
|
||||
std::scoped_lock lock{buffer_cache.mutex, texture_cache.mutex};
|
||||
std::scoped_lock lock{texture_cache.mutex};
|
||||
texture_cache.PopAsyncFlushes();
|
||||
buffer_cache.PopAsyncFlushes();
|
||||
}
|
||||
buffer_cache.PopAsyncFlushes();
|
||||
query_cache.PopAsyncFlushes();
|
||||
}
|
||||
|
||||
@@ -264,7 +262,9 @@ private:
|
||||
|
||||
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
|
||||
|
||||
@@ -30,6 +30,7 @@ void ThreadManager::StartThread(VideoCore::RendererBase& renderer, Core::Fronten
|
||||
thread = std::jthread([&](std::stop_token stop_token) {
|
||||
Common::SetCurrentThreadName("GPU");
|
||||
Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);
|
||||
Common::SetCurrentThreadToPerformanceCores();
|
||||
system.RegisterHostThread();
|
||||
|
||||
auto current_context = context.Acquire();
|
||||
|
||||
@@ -17,11 +17,13 @@ set(SHADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/astc_decoder.comp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/blit_color_float.frag
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/block_linear_unswizzle_2d.comp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/block_linear_unswizzle_2d_buffer.comp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/blit_color_msaa.frag
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/blit_depth_msaa.frag
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/blit_depth_stencil_msaa.frag
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/block_linear_unswizzle_3d.comp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/block_linear_unswizzle_3d_bcn.comp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/block_linear_unswizzle_3d_buffer.comp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/convert_abgr8_to_d24s8.frag
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/convert_abgr8_to_d32f.frag
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/convert_d32f_to_abgr8.frag
|
||||
@@ -32,6 +34,7 @@ set(SHADER_FILES
|
||||
${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.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}/full_screen_triangle.vert
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/fxaa.frag
|
||||
|
||||
@@ -77,14 +77,8 @@ uvec4 local_buff;
|
||||
uvec4 color_endpoint_data;
|
||||
int color_bitsread = 0;
|
||||
|
||||
// Global "vector" to be pushed into when decoding
|
||||
// At most will require BLOCK_WIDTH x BLOCK_HEIGHT in single plane mode
|
||||
// At most will require BLOCK_WIDTH x BLOCK_HEIGHT x 2 in dual plane mode
|
||||
// So the maximum would be 144 (12 x 12) elements, x 2 for two planes
|
||||
#define DIVCEIL(number, divisor) (number + divisor - 1) / divisor
|
||||
#define ARRAY_NUM_ELEMENTS 144
|
||||
#define VECTOR_ARRAY_SIZE DIVCEIL(ARRAY_NUM_ELEMENTS * 2, 4)
|
||||
uint result_vector[ARRAY_NUM_ELEMENTS * 2];
|
||||
#define MAX_WEIGHT_VALUES 64
|
||||
uint result_vector[MAX_WEIGHT_VALUES];
|
||||
|
||||
int result_index = 0;
|
||||
uint result_vector_max_index;
|
||||
@@ -492,7 +486,7 @@ void DecodeColorValues(uvec4 modes, uint num_partitions, uint color_data_bits, o
|
||||
A = ReplicateBitTo9((bitval & 1));
|
||||
switch (encoding) {
|
||||
case JUST_BITS:
|
||||
color_values[++out_index] = FastReplicateTo8(bitval, bitlen);
|
||||
color_values[out_index++] = FastReplicateTo8(bitval, bitlen);
|
||||
break;
|
||||
case TRIT: {
|
||||
D = QuintTritValue(val);
|
||||
@@ -571,7 +565,7 @@ void DecodeColorValues(uvec4 modes, uint num_partitions, uint color_data_bits, o
|
||||
uint T = (D * C) + B;
|
||||
T ^= A;
|
||||
T = (A & 0x80) | (T >> 2);
|
||||
color_values[++out_index] = T;
|
||||
color_values[out_index++] = T;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -753,12 +747,12 @@ void ComputeEndpoints(out uvec4 ep1, out uvec4 ep2, uint color_endpoint_mode, ui
|
||||
#define READ_UINT_VALUES(N) \
|
||||
uvec4 V[2]; \
|
||||
for (uint i = 0; i < N; i++) { \
|
||||
V[i / 4][i % 4] = color_values[++colvals_index]; \
|
||||
V[i / 4][i % 4] = color_values[colvals_index++]; \
|
||||
}
|
||||
#define READ_INT_VALUES(N) \
|
||||
ivec4 V[2]; \
|
||||
for (uint i = 0; i < N; i++) { \
|
||||
V[i / 4][i % 4] = int(color_values[++colvals_index]); \
|
||||
V[i / 4][i % 4] = int(color_values[colvals_index++]); \
|
||||
}
|
||||
|
||||
switch (color_endpoint_mode) {
|
||||
@@ -1225,6 +1219,10 @@ void DecompressBlock(ivec3 coord) {
|
||||
FillError(coord);
|
||||
return;
|
||||
}
|
||||
if (GetNumWeightValues(size_params, dual_plane) > MAX_WEIGHT_VALUES) {
|
||||
FillError(coord);
|
||||
return;
|
||||
}
|
||||
uint partition_index = 1;
|
||||
uvec4 color_endpoint_mode = uvec4(0);
|
||||
uint ced_pointer = 0;
|
||||
@@ -1384,11 +1382,7 @@ void DecompressBlock(ivec3 coord) {
|
||||
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);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#version 430
|
||||
|
||||
#extension GL_EXT_shader_16bit_storage : require
|
||||
#extension GL_EXT_shader_8bit_storage : require
|
||||
|
||||
#define BINDING_INPUT_BUFFER 0
|
||||
#define BINDING_OUTPUT_BUFFER 1
|
||||
|
||||
layout(push_constant) uniform PushConstants {
|
||||
uvec3 dim;
|
||||
uint bytes_per_block_log2;
|
||||
|
||||
uvec3 origin;
|
||||
uint layer_stride;
|
||||
|
||||
uint block_size;
|
||||
uint x_shift;
|
||||
uint block_height;
|
||||
uint block_height_mask;
|
||||
} pc;
|
||||
|
||||
layout(binding = BINDING_INPUT_BUFFER, std430) buffer InputBufferU32 { uint u32data[]; };
|
||||
layout(binding = BINDING_INPUT_BUFFER, std430) buffer InputBufferU64 { uvec2 u64data[]; };
|
||||
layout(binding = BINDING_INPUT_BUFFER, std430) buffer InputBufferU128 { uvec4 u128data[]; };
|
||||
|
||||
layout(binding = BINDING_OUTPUT_BUFFER, std430) writeonly buffer OutputBuffer {
|
||||
uint out_u32[];
|
||||
};
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
const uint GOB_SIZE_X = 64;
|
||||
const uint GOB_SIZE_Y = 8;
|
||||
|
||||
const uint GOB_SIZE_X_SHIFT = 6;
|
||||
const uint GOB_SIZE_Y_SHIFT = 3;
|
||||
const uint GOB_SIZE_SHIFT = GOB_SIZE_X_SHIFT + GOB_SIZE_Y_SHIFT;
|
||||
|
||||
const uvec2 SWIZZLE_MASK = uvec2(GOB_SIZE_X - 1u, GOB_SIZE_Y - 1u);
|
||||
|
||||
uint SwizzleTable(uint pos) {
|
||||
const uint t[8] = uint[](
|
||||
0x12100200, 0x13110301, 0x16140604, 0x17150705,
|
||||
0x1a180a08, 0x1b190b09, 0x1e1c0e0c, 0x1f1d0f0d
|
||||
);
|
||||
const uint i = pos >> 4;
|
||||
const uint h = (t[i / 4] >> ((i % 4) * 8)) & 0xff;
|
||||
return (h << 4) | (pos & 0xf);
|
||||
}
|
||||
|
||||
uint SwizzleOffset(uvec2 pos) {
|
||||
pos = pos & SWIZZLE_MASK;
|
||||
return SwizzleTable(pos.y * 64u + pos.x);
|
||||
}
|
||||
|
||||
uvec4 ReadTexel(uint offset) {
|
||||
switch (pc.bytes_per_block_log2) {
|
||||
case 2u:
|
||||
return uvec4(u32data[offset / 4u], 0u, 0u, 0u);
|
||||
case 3u:
|
||||
return uvec4(u64data[offset / 8u], 0u, 0u);
|
||||
case 4u:
|
||||
return u128data[offset / 16u];
|
||||
}
|
||||
return uvec4(0u);
|
||||
}
|
||||
|
||||
void main() {
|
||||
uvec3 coord = gl_GlobalInvocationID;
|
||||
if (coord.x >= pc.dim.x || coord.y >= pc.dim.y || coord.z >= pc.dim.z) {
|
||||
return;
|
||||
}
|
||||
|
||||
uvec3 pos = coord + pc.origin;
|
||||
pos.x <<= pc.bytes_per_block_log2;
|
||||
|
||||
uint swizzle = SwizzleOffset(pos.xy);
|
||||
uint block_y = pos.y >> GOB_SIZE_Y_SHIFT;
|
||||
|
||||
uint offset = 0u;
|
||||
offset += pos.z * pc.layer_stride;
|
||||
offset += (block_y >> pc.block_height) * pc.block_size;
|
||||
offset += (block_y & pc.block_height_mask) << GOB_SIZE_SHIFT;
|
||||
offset += (pos.x >> GOB_SIZE_X_SHIFT) << pc.x_shift;
|
||||
offset += swizzle;
|
||||
|
||||
uvec4 texel = ReadTexel(offset);
|
||||
|
||||
uint words = 1u << (pc.bytes_per_block_log2 - 2u);
|
||||
uint linear_index = coord.x + coord.y * pc.dim.x + coord.z * pc.dim.x * pc.dim.y;
|
||||
uint out_idx = linear_index * words;
|
||||
|
||||
out_u32[out_idx] = texel.x;
|
||||
if (words > 1u) {
|
||||
out_u32[out_idx + 1u] = texel.y;
|
||||
}
|
||||
if (words > 2u) {
|
||||
out_u32[out_idx + 2u] = texel.z;
|
||||
out_u32[out_idx + 3u] = texel.w;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#version 430
|
||||
|
||||
#define BINDING_INPUT_BUFFER 0
|
||||
#define BINDING_OUTPUT_BUFFER 1
|
||||
|
||||
layout(push_constant) uniform PushConstants {
|
||||
uvec3 dim;
|
||||
uint bytes_per_block_log2;
|
||||
|
||||
uvec3 origin;
|
||||
uint slice_size;
|
||||
|
||||
uint block_size;
|
||||
uint x_shift;
|
||||
uint block_height;
|
||||
uint block_height_mask;
|
||||
|
||||
uint block_depth;
|
||||
uint block_depth_mask;
|
||||
} pc;
|
||||
|
||||
layout(binding = BINDING_INPUT_BUFFER, std430) buffer InputBufferU32 { uint u32data[]; };
|
||||
layout(binding = BINDING_INPUT_BUFFER, std430) buffer InputBufferU64 { uvec2 u64data[]; };
|
||||
layout(binding = BINDING_INPUT_BUFFER, std430) buffer InputBufferU128 { uvec4 u128data[]; };
|
||||
|
||||
layout(binding = BINDING_OUTPUT_BUFFER, std430) writeonly buffer OutputBuffer {
|
||||
uint out_u32[];
|
||||
};
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 4) in;
|
||||
|
||||
const uint GOB_SIZE_X = 64;
|
||||
const uint GOB_SIZE_Y = 8;
|
||||
|
||||
const uint GOB_SIZE_X_SHIFT = 6;
|
||||
const uint GOB_SIZE_Y_SHIFT = 3;
|
||||
const uint GOB_SIZE_SHIFT = GOB_SIZE_X_SHIFT + GOB_SIZE_Y_SHIFT;
|
||||
|
||||
const uvec2 SWIZZLE_MASK = uvec2(GOB_SIZE_X - 1u, GOB_SIZE_Y - 1u);
|
||||
|
||||
uint SwizzleTable(uint pos) {
|
||||
const uint t[8] = uint[](
|
||||
0x12100200, 0x13110301, 0x16140604, 0x17150705,
|
||||
0x1a180a08, 0x1b190b09, 0x1e1c0e0c, 0x1f1d0f0d
|
||||
);
|
||||
const uint i = pos >> 4;
|
||||
const uint h = (t[i / 4] >> ((i % 4) * 8)) & 0xff;
|
||||
return (h << 4) | (pos & 0xf);
|
||||
}
|
||||
|
||||
uint SwizzleOffset(uvec2 pos) {
|
||||
pos = pos & SWIZZLE_MASK;
|
||||
return SwizzleTable(pos.y * 64u + pos.x);
|
||||
}
|
||||
|
||||
uvec4 ReadTexel(uint offset) {
|
||||
switch (pc.bytes_per_block_log2) {
|
||||
case 2u:
|
||||
return uvec4(u32data[offset / 4u], 0u, 0u, 0u);
|
||||
case 3u:
|
||||
return uvec4(u64data[offset / 8u], 0u, 0u);
|
||||
case 4u:
|
||||
return u128data[offset / 16u];
|
||||
}
|
||||
return uvec4(0u);
|
||||
}
|
||||
|
||||
void main() {
|
||||
uvec3 coord = gl_GlobalInvocationID;
|
||||
if (coord.x >= pc.dim.x || coord.y >= pc.dim.y || coord.z >= pc.dim.z) {
|
||||
return;
|
||||
}
|
||||
|
||||
uvec3 pos = coord + pc.origin;
|
||||
pos.x <<= pc.bytes_per_block_log2;
|
||||
|
||||
uint swizzle = SwizzleOffset(pos.xy);
|
||||
uint block_y = pos.y >> GOB_SIZE_Y_SHIFT;
|
||||
|
||||
uint offset = 0u;
|
||||
offset += (pos.z >> pc.block_depth) * pc.slice_size;
|
||||
offset += (pos.z & pc.block_depth_mask) << (GOB_SIZE_SHIFT + pc.block_height);
|
||||
offset += (block_y >> pc.block_height) * pc.block_size;
|
||||
offset += (block_y & pc.block_height_mask) << GOB_SIZE_SHIFT;
|
||||
offset += (pos.x >> GOB_SIZE_X_SHIFT) << pc.x_shift;
|
||||
offset += swizzle;
|
||||
|
||||
uvec4 texel = ReadTexel(offset);
|
||||
|
||||
uint words = 1u << (pc.bytes_per_block_log2 - 2u);
|
||||
uint linear_index = coord.x + coord.y * pc.dim.x + coord.z * pc.dim.x * pc.dim.y;
|
||||
uint out_idx = linear_index * words;
|
||||
|
||||
out_u32[out_idx] = texel.x;
|
||||
if (words > 1u) {
|
||||
out_u32[out_idx + 1u] = texel.y;
|
||||
}
|
||||
if (words > 2u) {
|
||||
out_u32[out_idx + 2u] = texel.z;
|
||||
out_u32[out_idx + 3u] = texel.w;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -58,8 +58,9 @@ MemoryManager::MemoryManager(Core::System& system_, u64 address_space_bits_, GPU
|
||||
|
||||
MemoryManager::~MemoryManager() = default;
|
||||
|
||||
MemoryManager::EntryType MemoryManager::GetEntry(size_t position, bool is_big_page) const {
|
||||
if (is_big_page) {
|
||||
template <bool is_big_page>
|
||||
MemoryManager::EntryType MemoryManager::GetEntry(size_t position) const {
|
||||
if constexpr (is_big_page) {
|
||||
position = position >> big_page_bits;
|
||||
const u64 entry_mask = big_entries[position / 32];
|
||||
const size_t sub_index = position % 32;
|
||||
@@ -72,8 +73,9 @@ MemoryManager::EntryType MemoryManager::GetEntry(size_t position, bool is_big_pa
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryManager::SetEntry(size_t position, MemoryManager::EntryType entry, bool is_big_page) {
|
||||
if (is_big_page) {
|
||||
template <bool is_big_page>
|
||||
void MemoryManager::SetEntry(size_t position, MemoryManager::EntryType entry) {
|
||||
if constexpr (is_big_page) {
|
||||
position = position >> big_page_bits;
|
||||
const u64 entry_mask = big_entries[position / 32];
|
||||
const size_t sub_index = position % 32;
|
||||
@@ -106,21 +108,23 @@ inline void MemoryManager::SetBigPageContinuous(size_t big_page_index, bool valu
|
||||
(~(1ULL << sub_index) & continuous_mask) | (value ? 1ULL << sub_index : 0);
|
||||
}
|
||||
|
||||
GPUVAddr MemoryManager::PageTableOp(GPUVAddr gpu_addr, [[maybe_unused]] DAddr dev_addr, size_t size, PTEKind kind, MemoryManager::EntryType entry_type) {
|
||||
template <MemoryManager::EntryType entry_type>
|
||||
GPUVAddr MemoryManager::PageTableOp(GPUVAddr gpu_addr, [[maybe_unused]] DAddr dev_addr, size_t size,
|
||||
PTEKind kind) {
|
||||
[[maybe_unused]] u64 remaining_size{size};
|
||||
if (entry_type == EntryType::Mapped) {
|
||||
if constexpr (entry_type == EntryType::Mapped) {
|
||||
page_table.ReserveRange(gpu_addr, size);
|
||||
}
|
||||
for (u64 offset{}; offset < size; offset += page_size) {
|
||||
const GPUVAddr current_gpu_addr = gpu_addr + offset;
|
||||
[[maybe_unused]] const auto current_entry_type = GetEntry(current_gpu_addr, false);
|
||||
SetEntry(current_gpu_addr, entry_type, false);
|
||||
[[maybe_unused]] const auto current_entry_type = GetEntry<false>(current_gpu_addr);
|
||||
SetEntry<false>(current_gpu_addr, entry_type);
|
||||
if (current_entry_type != entry_type) {
|
||||
rasterizer->ModifyGPUMemory(unique_identifier, current_gpu_addr, page_size);
|
||||
}
|
||||
if (entry_type == EntryType::Mapped) {
|
||||
if constexpr (entry_type == EntryType::Mapped) {
|
||||
const DAddr current_dev_addr = dev_addr + offset;
|
||||
const auto index = PageEntryIndex(current_gpu_addr, false);
|
||||
const auto index = PageEntryIndex<false>(current_gpu_addr);
|
||||
const u32 sub_value = static_cast<u32>(current_dev_addr >> cpu_page_bits);
|
||||
page_table[index] = sub_value;
|
||||
}
|
||||
@@ -130,18 +134,20 @@ GPUVAddr MemoryManager::PageTableOp(GPUVAddr gpu_addr, [[maybe_unused]] DAddr de
|
||||
return gpu_addr;
|
||||
}
|
||||
|
||||
GPUVAddr MemoryManager::BigPageTableOp(GPUVAddr gpu_addr, [[maybe_unused]] DAddr dev_addr, size_t size, PTEKind kind, MemoryManager::EntryType entry_type) {
|
||||
template <MemoryManager::EntryType entry_type>
|
||||
GPUVAddr MemoryManager::BigPageTableOp(GPUVAddr gpu_addr, [[maybe_unused]] DAddr dev_addr,
|
||||
size_t size, PTEKind kind) {
|
||||
[[maybe_unused]] u64 remaining_size{size};
|
||||
for (u64 offset{}; offset < size; offset += big_page_size) {
|
||||
const GPUVAddr current_gpu_addr = gpu_addr + offset;
|
||||
[[maybe_unused]] const auto current_entry_type = GetEntry(current_gpu_addr, true);
|
||||
SetEntry(current_gpu_addr, entry_type, true);
|
||||
[[maybe_unused]] const auto current_entry_type = GetEntry<true>(current_gpu_addr);
|
||||
SetEntry<true>(current_gpu_addr, entry_type);
|
||||
if (current_entry_type != entry_type) {
|
||||
rasterizer->ModifyGPUMemory(unique_identifier, current_gpu_addr, big_page_size);
|
||||
}
|
||||
if (entry_type == EntryType::Mapped) {
|
||||
if constexpr (entry_type == EntryType::Mapped) {
|
||||
const DAddr current_dev_addr = dev_addr + offset;
|
||||
const auto index = PageEntryIndex(current_gpu_addr, true);
|
||||
const auto index = PageEntryIndex<true>(current_gpu_addr);
|
||||
const u32 sub_value = static_cast<u32>(current_dev_addr >> cpu_page_bits);
|
||||
big_page_table_dev[index] = sub_value;
|
||||
const bool is_continuous = ([&] {
|
||||
@@ -175,16 +181,19 @@ void MemoryManager::BindRasterizer(VideoCore::RasterizerInterface* rasterizer_)
|
||||
rasterizer = rasterizer_;
|
||||
}
|
||||
|
||||
GPUVAddr MemoryManager::Map(GPUVAddr gpu_addr, DAddr dev_addr, std::size_t size, PTEKind kind, bool is_big_pages) {
|
||||
if (is_big_pages)
|
||||
return BigPageTableOp(gpu_addr, dev_addr, size, kind, EntryType::Mapped);
|
||||
return PageTableOp(gpu_addr, dev_addr, size, kind, EntryType::Mapped);
|
||||
GPUVAddr MemoryManager::Map(GPUVAddr gpu_addr, DAddr dev_addr, std::size_t size, PTEKind kind,
|
||||
bool is_big_pages) {
|
||||
if (is_big_pages) [[likely]] {
|
||||
return BigPageTableOp<EntryType::Mapped>(gpu_addr, dev_addr, size, kind);
|
||||
}
|
||||
return PageTableOp<EntryType::Mapped>(gpu_addr, dev_addr, size, kind);
|
||||
}
|
||||
|
||||
GPUVAddr MemoryManager::MapSparse(GPUVAddr gpu_addr, std::size_t size, bool is_big_pages) {
|
||||
if (is_big_pages)
|
||||
return BigPageTableOp(gpu_addr, 0, size, PTEKind::INVALID, EntryType::Reserved);
|
||||
return PageTableOp(gpu_addr, 0, size, PTEKind::INVALID, EntryType::Reserved);
|
||||
if (is_big_pages) [[likely]] {
|
||||
return BigPageTableOp<EntryType::Reserved>(gpu_addr, 0, size, PTEKind::INVALID);
|
||||
}
|
||||
return PageTableOp<EntryType::Reserved>(gpu_addr, 0, size, PTEKind::INVALID);
|
||||
}
|
||||
|
||||
void MemoryManager::Unmap(GPUVAddr gpu_addr, std::size_t size) {
|
||||
@@ -198,21 +207,26 @@ void MemoryManager::Unmap(GPUVAddr gpu_addr, std::size_t size) {
|
||||
}
|
||||
page_stash.clear();
|
||||
|
||||
BigPageTableOp(gpu_addr, 0, size, PTEKind::INVALID, EntryType::Free);
|
||||
PageTableOp(gpu_addr, 0, size, PTEKind::INVALID, EntryType::Free);
|
||||
BigPageTableOp<EntryType::Free>(gpu_addr, 0, size, PTEKind::INVALID);
|
||||
PageTableOp<EntryType::Free>(gpu_addr, 0, size, PTEKind::INVALID);
|
||||
}
|
||||
|
||||
std::optional<DAddr> MemoryManager::GpuToCpuAddress(GPUVAddr gpu_addr) const {
|
||||
if (!IsWithinGPUAddressRange(gpu_addr)) [[unlikely]] {
|
||||
return std::nullopt;
|
||||
}
|
||||
if (GetEntry(gpu_addr, true) != EntryType::Mapped) [[unlikely]] {
|
||||
if (GetEntry(gpu_addr, false) != EntryType::Mapped)
|
||||
if (GetEntry<true>(gpu_addr) != EntryType::Mapped) [[unlikely]] {
|
||||
if (GetEntry<false>(gpu_addr) != EntryType::Mapped) {
|
||||
return std::nullopt;
|
||||
const DAddr dev_addr_base = DAddr(page_table[PageEntryIndex(gpu_addr, false)]) << cpu_page_bits;
|
||||
}
|
||||
|
||||
const DAddr dev_addr_base = static_cast<DAddr>(page_table[PageEntryIndex<false>(gpu_addr)])
|
||||
<< cpu_page_bits;
|
||||
return dev_addr_base + (gpu_addr & page_mask);
|
||||
}
|
||||
const DAddr dev_addr_base = DAddr(big_page_table_dev[PageEntryIndex(gpu_addr, true)]) << cpu_page_bits;
|
||||
|
||||
const DAddr dev_addr_base =
|
||||
static_cast<DAddr>(big_page_table_dev[PageEntryIndex<true>(gpu_addr)]) << cpu_page_bits;
|
||||
return dev_addr_base + (gpu_addr & big_page_mask);
|
||||
}
|
||||
|
||||
@@ -285,8 +299,10 @@ const u8* MemoryManager::GetPointer(GPUVAddr gpu_addr) const {
|
||||
#pragma inline_recursion(on)
|
||||
#endif
|
||||
|
||||
template <typename FuncMapped, typename FuncReserved, typename FuncUnmapped>
|
||||
inline void MemoryManager::MemoryOperation(GPUVAddr gpu_src_addr, std::size_t size, bool is_big_page, FuncMapped&& func_mapped, FuncReserved&& func_reserved, FuncUnmapped&& func_unmapped) const {
|
||||
template <bool is_big_pages, typename FuncMapped, typename FuncReserved, typename FuncUnmapped>
|
||||
inline void MemoryManager::MemoryOperation(GPUVAddr gpu_src_addr, std::size_t size,
|
||||
FuncMapped&& func_mapped, FuncReserved&& func_reserved,
|
||||
FuncUnmapped&& func_unmapped) const {
|
||||
using FuncMappedReturn =
|
||||
typename std::invoke_result<FuncMapped, std::size_t, std::size_t, std::size_t>::type;
|
||||
using FuncReservedReturn =
|
||||
@@ -299,7 +315,7 @@ inline void MemoryManager::MemoryOperation(GPUVAddr gpu_src_addr, std::size_t si
|
||||
u64 used_page_size;
|
||||
u64 used_page_mask;
|
||||
u64 used_page_bits;
|
||||
if (is_big_page) {
|
||||
if constexpr (is_big_pages) {
|
||||
used_page_size = big_page_size;
|
||||
used_page_mask = big_page_mask;
|
||||
used_page_bits = big_page_bits;
|
||||
@@ -316,7 +332,7 @@ inline void MemoryManager::MemoryOperation(GPUVAddr gpu_src_addr, std::size_t si
|
||||
while (remaining_size > 0) {
|
||||
const std::size_t copy_amount{
|
||||
(std::min)(static_cast<std::size_t>(used_page_size) - page_offset, remaining_size)};
|
||||
auto entry = GetEntry(current_address, is_big_page);
|
||||
auto entry = GetEntry<is_big_pages>(current_address);
|
||||
if (entry == EntryType::Mapped) [[likely]] {
|
||||
if constexpr (BOOL_BREAK_MAPPED) {
|
||||
if (func_mapped(page_index, page_offset, copy_amount)) {
|
||||
@@ -351,91 +367,164 @@ inline void MemoryManager::MemoryOperation(GPUVAddr gpu_src_addr, std::size_t si
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryManager::ReadBlockImpl(GPUVAddr gpu_src_addr, void* dest_buffer, std::size_t size, [[maybe_unused]] VideoCommon::CacheType which, bool unsafe) const {
|
||||
auto set_to_zero = [&]([[maybe_unused]] std::size_t page_index, [[maybe_unused]] std::size_t offset, std::size_t copy_amount) {
|
||||
template <bool is_safe>
|
||||
void MemoryManager::ReadBlockImpl(GPUVAddr gpu_src_addr, void* dest_buffer, std::size_t size,
|
||||
[[maybe_unused]] VideoCommon::CacheType which) const {
|
||||
const u8* run_src{nullptr};
|
||||
u8* run_dst{nullptr};
|
||||
std::size_t run_size{0};
|
||||
auto flush_run = [&] {
|
||||
if (run_size == 0) {
|
||||
return;
|
||||
}
|
||||
std::memcpy(run_dst, run_src, run_size);
|
||||
run_src = nullptr;
|
||||
run_dst = nullptr;
|
||||
run_size = 0;
|
||||
};
|
||||
auto append_run = [&](const u8* physical, std::size_t copy_amount) {
|
||||
if (physical == nullptr) [[unlikely]] {
|
||||
flush_run();
|
||||
std::memset(dest_buffer, 0, copy_amount);
|
||||
return;
|
||||
}
|
||||
if (run_size != 0 && run_src + run_size == physical &&
|
||||
run_dst + run_size == static_cast<u8*>(dest_buffer)) {
|
||||
run_size += copy_amount;
|
||||
return;
|
||||
}
|
||||
flush_run();
|
||||
run_src = physical;
|
||||
run_dst = static_cast<u8*>(dest_buffer);
|
||||
run_size = copy_amount;
|
||||
};
|
||||
auto set_to_zero = [&]([[maybe_unused]] std::size_t page_index,
|
||||
[[maybe_unused]] std::size_t offset, std::size_t copy_amount) {
|
||||
flush_run();
|
||||
std::memset(dest_buffer, 0, copy_amount);
|
||||
dest_buffer = static_cast<u8*>(dest_buffer) + copy_amount;
|
||||
};
|
||||
auto mapped_normal = [&](std::size_t page_index, std::size_t offset, std::size_t copy_amount) {
|
||||
const DAddr dev_addr_base = (DAddr(page_table[page_index]) << cpu_page_bits) + offset;
|
||||
if (!unsafe) {
|
||||
const DAddr dev_addr_base =
|
||||
(static_cast<DAddr>(page_table[page_index]) << cpu_page_bits) + offset;
|
||||
if constexpr (is_safe) {
|
||||
rasterizer->FlushRegion(dev_addr_base, copy_amount, which);
|
||||
}
|
||||
u8* physical = memory.GetPointer<u8>(dev_addr_base);
|
||||
std::memcpy(dest_buffer, physical, copy_amount);
|
||||
append_run(memory.GetPointer<u8>(dev_addr_base), copy_amount);
|
||||
dest_buffer = static_cast<u8*>(dest_buffer) + copy_amount;
|
||||
};
|
||||
auto mapped_big = [&](std::size_t page_index, std::size_t offset, std::size_t copy_amount) {
|
||||
const DAddr dev_addr_base = (DAddr(big_page_table_dev[page_index]) << cpu_page_bits) + offset;
|
||||
if (!unsafe) {
|
||||
const DAddr dev_addr_base =
|
||||
(static_cast<DAddr>(big_page_table_dev[page_index]) << cpu_page_bits) + offset;
|
||||
if constexpr (is_safe) {
|
||||
rasterizer->FlushRegion(dev_addr_base, copy_amount, which);
|
||||
}
|
||||
if (!IsBigPageContinuous(page_index)) [[unlikely]] {
|
||||
flush_run();
|
||||
memory.ReadBlockUnsafe(dev_addr_base, dest_buffer, copy_amount);
|
||||
} else {
|
||||
u8* physical = memory.GetPointer<u8>(dev_addr_base);
|
||||
std::memcpy(dest_buffer, physical, copy_amount);
|
||||
append_run(memory.GetPointer<u8>(dev_addr_base), copy_amount);
|
||||
}
|
||||
dest_buffer = static_cast<u8*>(dest_buffer) + copy_amount;
|
||||
};
|
||||
auto read_short_pages = [&](std::size_t page_index, std::size_t offset, std::size_t copy_amount) {
|
||||
auto read_short_pages = [&](std::size_t page_index, std::size_t offset,
|
||||
std::size_t copy_amount) {
|
||||
GPUVAddr base = (page_index << big_page_bits) + offset;
|
||||
MemoryOperation(base, copy_amount, false, mapped_normal, set_to_zero, set_to_zero);
|
||||
MemoryOperation<false>(base, copy_amount, mapped_normal, set_to_zero, set_to_zero);
|
||||
};
|
||||
MemoryOperation(gpu_src_addr, size, true, mapped_big, set_to_zero, read_short_pages);
|
||||
MemoryOperation<true>(gpu_src_addr, size, mapped_big, set_to_zero, read_short_pages);
|
||||
flush_run();
|
||||
}
|
||||
|
||||
void MemoryManager::ReadBlock(GPUVAddr gpu_src_addr, void* dest_buffer, std::size_t size, VideoCommon::CacheType which) const {
|
||||
ReadBlockImpl(gpu_src_addr, dest_buffer, size, which, false);
|
||||
void MemoryManager::ReadBlock(GPUVAddr gpu_src_addr, void* dest_buffer, std::size_t size,
|
||||
VideoCommon::CacheType which) const {
|
||||
ReadBlockImpl<true>(gpu_src_addr, dest_buffer, size, which);
|
||||
}
|
||||
|
||||
void MemoryManager::ReadBlockUnsafe(GPUVAddr gpu_src_addr, void* dest_buffer, const std::size_t size) const {
|
||||
ReadBlockImpl(gpu_src_addr, dest_buffer, size, VideoCommon::CacheType::None, true);
|
||||
void MemoryManager::ReadBlockUnsafe(GPUVAddr gpu_src_addr, void* dest_buffer,
|
||||
const std::size_t size) const {
|
||||
ReadBlockImpl<false>(gpu_src_addr, dest_buffer, size, VideoCommon::CacheType::None);
|
||||
}
|
||||
|
||||
void MemoryManager::WriteBlockImpl(GPUVAddr gpu_dest_addr, const void* src_buffer, std::size_t size, [[maybe_unused]] VideoCommon::CacheType which, bool unsafe) {
|
||||
auto just_advance = [&]([[maybe_unused]] std::size_t page_index, [[maybe_unused]] std::size_t offset, std::size_t copy_amount) {
|
||||
template <bool is_safe>
|
||||
void MemoryManager::WriteBlockImpl(GPUVAddr gpu_dest_addr, const void* src_buffer, std::size_t size,
|
||||
[[maybe_unused]] VideoCommon::CacheType which) {
|
||||
const u8* run_src{nullptr};
|
||||
u8* run_dst{nullptr};
|
||||
std::size_t run_size{0};
|
||||
auto flush_run = [&] {
|
||||
if (run_size == 0) {
|
||||
return;
|
||||
}
|
||||
std::memcpy(run_dst, run_src, run_size);
|
||||
run_src = nullptr;
|
||||
run_dst = nullptr;
|
||||
run_size = 0;
|
||||
};
|
||||
auto append_run = [&](u8* physical, std::size_t copy_amount) {
|
||||
if (physical == nullptr) [[unlikely]] {
|
||||
flush_run();
|
||||
return;
|
||||
}
|
||||
if (run_size != 0 && run_dst + run_size == physical &&
|
||||
run_src + run_size == static_cast<const u8*>(src_buffer)) {
|
||||
run_size += copy_amount;
|
||||
return;
|
||||
}
|
||||
flush_run();
|
||||
run_src = static_cast<const u8*>(src_buffer);
|
||||
run_dst = physical;
|
||||
run_size = copy_amount;
|
||||
};
|
||||
auto just_advance = [&]([[maybe_unused]] std::size_t page_index,
|
||||
[[maybe_unused]] std::size_t offset, std::size_t copy_amount) {
|
||||
flush_run();
|
||||
src_buffer = static_cast<const u8*>(src_buffer) + copy_amount;
|
||||
};
|
||||
auto mapped_normal = [&](std::size_t page_index, std::size_t offset, std::size_t copy_amount) {
|
||||
const DAddr dev_addr_base = (DAddr(page_table[page_index]) << cpu_page_bits) + offset;
|
||||
if (!unsafe) {
|
||||
const DAddr dev_addr_base =
|
||||
(static_cast<DAddr>(page_table[page_index]) << cpu_page_bits) + offset;
|
||||
if constexpr (is_safe) {
|
||||
rasterizer->InvalidateRegion(dev_addr_base, copy_amount, which);
|
||||
}
|
||||
u8* physical = memory.GetPointer<u8>(dev_addr_base);
|
||||
std::memcpy(physical, src_buffer, copy_amount);
|
||||
append_run(memory.GetPointer<u8>(dev_addr_base), copy_amount);
|
||||
src_buffer = static_cast<const u8*>(src_buffer) + copy_amount;
|
||||
};
|
||||
auto mapped_big = [&](std::size_t page_index, std::size_t offset, std::size_t copy_amount) {
|
||||
const DAddr dev_addr_base = (DAddr(big_page_table_dev[page_index]) << cpu_page_bits) + offset;
|
||||
if (!unsafe) {
|
||||
const DAddr dev_addr_base =
|
||||
(static_cast<DAddr>(big_page_table_dev[page_index]) << cpu_page_bits) + offset;
|
||||
if constexpr (is_safe) {
|
||||
rasterizer->InvalidateRegion(dev_addr_base, copy_amount, which);
|
||||
}
|
||||
if (!IsBigPageContinuous(page_index)) [[unlikely]] {
|
||||
flush_run();
|
||||
memory.WriteBlockUnsafe(dev_addr_base, src_buffer, copy_amount);
|
||||
} else {
|
||||
u8* physical = memory.GetPointer<u8>(dev_addr_base);
|
||||
std::memcpy(physical, src_buffer, copy_amount);
|
||||
append_run(memory.GetPointer<u8>(dev_addr_base), copy_amount);
|
||||
}
|
||||
src_buffer = static_cast<const u8*>(src_buffer) + copy_amount;
|
||||
};
|
||||
auto write_short_pages = [&](std::size_t page_index, std::size_t offset, std::size_t copy_amount) {
|
||||
auto write_short_pages = [&](std::size_t page_index, std::size_t offset,
|
||||
std::size_t copy_amount) {
|
||||
GPUVAddr base = (page_index << big_page_bits) + offset;
|
||||
MemoryOperation(base, copy_amount, false, mapped_normal, just_advance, just_advance);
|
||||
MemoryOperation<false>(base, copy_amount, mapped_normal, just_advance, just_advance);
|
||||
};
|
||||
MemoryOperation(gpu_dest_addr, size, true, mapped_big, just_advance, write_short_pages);
|
||||
MemoryOperation<true>(gpu_dest_addr, size, mapped_big, just_advance, write_short_pages);
|
||||
flush_run();
|
||||
}
|
||||
|
||||
void MemoryManager::WriteBlock(GPUVAddr gpu_dest_addr, const void* src_buffer, std::size_t size, VideoCommon::CacheType which) {
|
||||
WriteBlockImpl(gpu_dest_addr, src_buffer, size, which, false);
|
||||
void MemoryManager::WriteBlock(GPUVAddr gpu_dest_addr, const void* src_buffer, std::size_t size,
|
||||
VideoCommon::CacheType which) {
|
||||
WriteBlockImpl<true>(gpu_dest_addr, src_buffer, size, which);
|
||||
}
|
||||
|
||||
void MemoryManager::WriteBlockUnsafe(GPUVAddr gpu_dest_addr, const void* src_buffer, std::size_t size) {
|
||||
WriteBlockImpl(gpu_dest_addr, src_buffer, size, VideoCommon::CacheType::None, true);
|
||||
void MemoryManager::WriteBlockUnsafe(GPUVAddr gpu_dest_addr, const void* src_buffer,
|
||||
std::size_t size) {
|
||||
WriteBlockImpl<false>(gpu_dest_addr, src_buffer, size, VideoCommon::CacheType::None);
|
||||
}
|
||||
|
||||
void MemoryManager::WriteBlockCached(GPUVAddr gpu_dest_addr, const void* src_buffer, std::size_t size) {
|
||||
WriteBlockImpl(gpu_dest_addr, src_buffer, size, VideoCommon::CacheType::None, true);
|
||||
WriteBlockImpl<false>(gpu_dest_addr, src_buffer, size, VideoCommon::CacheType::None);
|
||||
accumulator.Add(gpu_dest_addr, size);
|
||||
}
|
||||
|
||||
@@ -446,18 +535,21 @@ void MemoryManager::FlushRegion(GPUVAddr gpu_addr, size_t size,
|
||||
[[maybe_unused]] std::size_t copy_amount) {};
|
||||
|
||||
auto mapped_normal = [&](std::size_t page_index, std::size_t offset, std::size_t copy_amount) {
|
||||
const DAddr dev_addr_base = (DAddr(page_table[page_index]) << cpu_page_bits) + offset;
|
||||
const DAddr dev_addr_base =
|
||||
(static_cast<DAddr>(page_table[page_index]) << cpu_page_bits) + offset;
|
||||
rasterizer->FlushRegion(dev_addr_base, copy_amount, which);
|
||||
};
|
||||
auto mapped_big = [&](std::size_t page_index, std::size_t offset, std::size_t copy_amount) {
|
||||
const DAddr dev_addr_base = (DAddr(big_page_table_dev[page_index]) << cpu_page_bits) + offset;
|
||||
const DAddr dev_addr_base =
|
||||
(static_cast<DAddr>(big_page_table_dev[page_index]) << cpu_page_bits) + offset;
|
||||
rasterizer->FlushRegion(dev_addr_base, copy_amount, which);
|
||||
};
|
||||
auto flush_short_pages = [&](std::size_t page_index, std::size_t offset, std::size_t copy_amount) {
|
||||
auto flush_short_pages = [&](std::size_t page_index, std::size_t offset,
|
||||
std::size_t copy_amount) {
|
||||
GPUVAddr base = (page_index << big_page_bits) + offset;
|
||||
MemoryOperation(base, copy_amount, false, mapped_normal, do_nothing, do_nothing);
|
||||
MemoryOperation<false>(base, copy_amount, mapped_normal, do_nothing, do_nothing);
|
||||
};
|
||||
MemoryOperation(gpu_addr, size, true, mapped_big, do_nothing, flush_short_pages);
|
||||
MemoryOperation<true>(gpu_addr, size, mapped_big, do_nothing, flush_short_pages);
|
||||
}
|
||||
|
||||
bool MemoryManager::IsMemoryDirty(GPUVAddr gpu_addr, size_t size,
|
||||
@@ -482,10 +574,10 @@ bool MemoryManager::IsMemoryDirty(GPUVAddr gpu_addr, size_t size,
|
||||
auto check_short_pages = [&](std::size_t page_index, std::size_t offset,
|
||||
std::size_t copy_amount) {
|
||||
GPUVAddr base = (page_index << big_page_bits) + offset;
|
||||
MemoryOperation(base, copy_amount, false, mapped_normal, do_nothing, do_nothing);
|
||||
MemoryOperation<false>(base, copy_amount, mapped_normal, do_nothing, do_nothing);
|
||||
return result;
|
||||
};
|
||||
MemoryOperation(gpu_addr, size, true, mapped_big, do_nothing, check_short_pages);
|
||||
MemoryOperation<true>(gpu_addr, size, mapped_big, do_nothing, check_short_pages);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -522,10 +614,10 @@ size_t MemoryManager::MaxContinuousRange(GPUVAddr gpu_addr, size_t size) const {
|
||||
auto check_short_pages = [&](std::size_t page_index, std::size_t offset,
|
||||
std::size_t copy_amount) {
|
||||
GPUVAddr base = (page_index << big_page_bits) + offset;
|
||||
MemoryOperation(base, copy_amount, false, short_check, fail, fail);
|
||||
MemoryOperation<false>(base, copy_amount, short_check, fail, fail);
|
||||
return result;
|
||||
};
|
||||
MemoryOperation(gpu_addr, size, true, big_check, fail, check_short_pages);
|
||||
MemoryOperation<true>(gpu_addr, size, big_check, fail, check_short_pages);
|
||||
return range_so_far;
|
||||
}
|
||||
|
||||
@@ -541,18 +633,21 @@ void MemoryManager::InvalidateRegion(GPUVAddr gpu_addr, size_t size,
|
||||
[[maybe_unused]] std::size_t copy_amount) {};
|
||||
|
||||
auto mapped_normal = [&](std::size_t page_index, std::size_t offset, std::size_t copy_amount) {
|
||||
const DAddr dev_addr_base = (DAddr(page_table[page_index]) << cpu_page_bits) + offset;
|
||||
const DAddr dev_addr_base =
|
||||
(static_cast<DAddr>(page_table[page_index]) << cpu_page_bits) + offset;
|
||||
rasterizer->InvalidateRegion(dev_addr_base, copy_amount, which);
|
||||
};
|
||||
auto mapped_big = [&](std::size_t page_index, std::size_t offset, std::size_t copy_amount) {
|
||||
const DAddr dev_addr_base = (DAddr(big_page_table_dev[page_index]) << cpu_page_bits) + offset;
|
||||
const DAddr dev_addr_base =
|
||||
(static_cast<DAddr>(big_page_table_dev[page_index]) << cpu_page_bits) + offset;
|
||||
rasterizer->InvalidateRegion(dev_addr_base, copy_amount, which);
|
||||
};
|
||||
auto invalidate_short_pages = [&](std::size_t page_index, std::size_t offset, std::size_t copy_amount) {
|
||||
auto invalidate_short_pages = [&](std::size_t page_index, std::size_t offset,
|
||||
std::size_t copy_amount) {
|
||||
GPUVAddr base = (page_index << big_page_bits) + offset;
|
||||
MemoryOperation(base, copy_amount, false, mapped_normal, do_nothing, do_nothing);
|
||||
MemoryOperation<false>(base, copy_amount, mapped_normal, do_nothing, do_nothing);
|
||||
};
|
||||
MemoryOperation(gpu_addr, size, true, mapped_big, do_nothing, invalidate_short_pages);
|
||||
MemoryOperation<true>(gpu_addr, size, mapped_big, do_nothing, invalidate_short_pages);
|
||||
}
|
||||
|
||||
void MemoryManager::CopyBlock(GPUVAddr gpu_dest_addr, GPUVAddr gpu_src_addr, std::size_t size,
|
||||
@@ -564,16 +659,16 @@ void MemoryManager::CopyBlock(GPUVAddr gpu_dest_addr, GPUVAddr gpu_src_addr, std
|
||||
}
|
||||
|
||||
bool MemoryManager::IsGranularRange(GPUVAddr gpu_addr, std::size_t size) const {
|
||||
if (GetEntry(gpu_addr, true) == EntryType::Mapped) [[likely]] {
|
||||
if (GetEntry<true>(gpu_addr) == EntryType::Mapped) [[likely]] {
|
||||
size_t page_index = gpu_addr >> big_page_bits;
|
||||
if (IsBigPageContinuous(page_index)) [[likely]] {
|
||||
const std::size_t page{(page_index & big_page_mask) + size};
|
||||
const std::size_t page{(gpu_addr & big_page_mask) + size};
|
||||
return page <= big_page_size;
|
||||
}
|
||||
const std::size_t page{(gpu_addr & Core::DEVICE_PAGEMASK) + size};
|
||||
return page <= Core::DEVICE_PAGESIZE;
|
||||
}
|
||||
if (GetEntry(gpu_addr, false) != EntryType::Mapped) {
|
||||
if (GetEntry<false>(gpu_addr) != EntryType::Mapped) {
|
||||
return false;
|
||||
}
|
||||
const std::size_t page{(gpu_addr & Core::DEVICE_PAGEMASK) + size};
|
||||
@@ -611,10 +706,10 @@ bool MemoryManager::IsContinuousRange(GPUVAddr gpu_addr, std::size_t size) const
|
||||
auto check_short_pages = [&](std::size_t page_index, std::size_t offset,
|
||||
std::size_t copy_amount) {
|
||||
GPUVAddr base = (page_index << big_page_bits) + offset;
|
||||
MemoryOperation(base, copy_amount, false, short_check, fail, fail);
|
||||
MemoryOperation<false>(base, copy_amount, short_check, fail, fail);
|
||||
return !result;
|
||||
};
|
||||
MemoryOperation(gpu_addr, size, true, big_check, fail, check_short_pages);
|
||||
MemoryOperation<true>(gpu_addr, size, big_check, fail, check_short_pages);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -627,12 +722,13 @@ bool MemoryManager::IsFullyMappedRange(GPUVAddr gpu_addr, std::size_t size) cons
|
||||
};
|
||||
auto pass = [&]([[maybe_unused]] std::size_t page_index, [[maybe_unused]] std::size_t offset,
|
||||
[[maybe_unused]] std::size_t copy_amount) { return false; };
|
||||
auto check_short_pages = [&](std::size_t page_index, std::size_t offset, std::size_t copy_amount) {
|
||||
auto check_short_pages = [&](std::size_t page_index, std::size_t offset,
|
||||
std::size_t copy_amount) {
|
||||
GPUVAddr base = (page_index << big_page_bits) + offset;
|
||||
MemoryOperation(base, copy_amount, false, pass, pass, fail);
|
||||
MemoryOperation<false>(base, copy_amount, pass, pass, fail);
|
||||
return !result;
|
||||
};
|
||||
MemoryOperation(gpu_addr, size, true, pass, fail, check_short_pages);
|
||||
MemoryOperation<true>(gpu_addr, size, pass, fail, check_short_pages);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -644,9 +740,13 @@ MemoryManager::GetSubmappedRange(GPUVAddr gpu_addr, std::size_t size) const {
|
||||
}
|
||||
|
||||
template <bool is_gpu_address>
|
||||
void MemoryManager::GetSubmappedRangeImpl(GPUVAddr gpu_addr, std::size_t size, boost::container::small_vector<std::pair<std::conditional_t<is_gpu_address, GPUVAddr, DAddr>, std::size_t>, 32>& result)
|
||||
void MemoryManager::GetSubmappedRangeImpl(
|
||||
GPUVAddr gpu_addr, std::size_t size,
|
||||
boost::container::small_vector<
|
||||
std::pair<std::conditional_t<is_gpu_address, GPUVAddr, DAddr>, std::size_t>, 32>& result)
|
||||
const {
|
||||
std::optional<std::pair<std::conditional_t<is_gpu_address, GPUVAddr, DAddr>, std::size_t>> last_segment{};
|
||||
std::optional<std::pair<std::conditional_t<is_gpu_address, GPUVAddr, DAddr>, std::size_t>>
|
||||
last_segment{};
|
||||
std::optional<DAddr> old_page_addr{};
|
||||
const auto split = [&last_segment, &result]([[maybe_unused]] std::size_t page_index,
|
||||
[[maybe_unused]] std::size_t offset,
|
||||
@@ -702,9 +802,9 @@ void MemoryManager::GetSubmappedRangeImpl(GPUVAddr gpu_addr, std::size_t size, b
|
||||
};
|
||||
auto do_short_pages = [&](std::size_t page_index, std::size_t offset, std::size_t copy_amount) {
|
||||
GPUVAddr base = (page_index << big_page_bits) + offset;
|
||||
MemoryOperation(base, copy_amount, false, extend_size_short, split, split);
|
||||
MemoryOperation<false>(base, copy_amount, extend_size_short, split, split);
|
||||
};
|
||||
MemoryOperation(gpu_addr, size, true, extend_size_big, split, do_short_pages);
|
||||
MemoryOperation<true>(gpu_addr, size, extend_size_big, split, do_short_pages);
|
||||
split(0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
|
||||
static constexpr bool HAS_FLUSH_INVALIDATION = true;
|
||||
|
||||
inline size_t GetID() const noexcept {
|
||||
size_t GetID() const {
|
||||
return unique_identifier;
|
||||
}
|
||||
|
||||
@@ -66,15 +66,16 @@ public:
|
||||
[[nodiscard]] const u8* GetPointer(GPUVAddr addr) const;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] inline T* GetPointer(GPUVAddr addr) noexcept {
|
||||
const auto address = GpuToCpuAddress(addr);
|
||||
if (!address)
|
||||
[[nodiscard]] T* GetPointer(GPUVAddr addr) {
|
||||
const auto address{GpuToCpuAddress(addr)};
|
||||
if (!address) {
|
||||
return {};
|
||||
}
|
||||
return memory.GetPointer<T>(*address);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] inline const T* GetPointer(GPUVAddr addr) const noexcept {
|
||||
[[nodiscard]] const T* GetPointer(GPUVAddr addr) const {
|
||||
return GetPointer<T*>(addr);
|
||||
}
|
||||
|
||||
@@ -84,9 +85,12 @@ public:
|
||||
* in the Host Memory counterpart. Note: This functions cause Host GPU Memory
|
||||
* Flushes and Invalidations, respectively to each operation.
|
||||
*/
|
||||
void ReadBlock(GPUVAddr gpu_src_addr, void* dest_buffer, std::size_t size, VideoCommon::CacheType which = VideoCommon::CacheType::All) const;
|
||||
void WriteBlock(GPUVAddr gpu_dest_addr, const void* src_buffer, std::size_t size, VideoCommon::CacheType which = VideoCommon::CacheType::All);
|
||||
void CopyBlock(GPUVAddr gpu_dest_addr, GPUVAddr gpu_src_addr, std::size_t size, VideoCommon::CacheType which = VideoCommon::CacheType::All);
|
||||
void ReadBlock(GPUVAddr gpu_src_addr, void* dest_buffer, std::size_t size,
|
||||
VideoCommon::CacheType which = VideoCommon::CacheType::All) const;
|
||||
void WriteBlock(GPUVAddr gpu_dest_addr, const void* src_buffer, std::size_t size,
|
||||
VideoCommon::CacheType which = VideoCommon::CacheType::All);
|
||||
void CopyBlock(GPUVAddr gpu_dest_addr, GPUVAddr gpu_src_addr, std::size_t size,
|
||||
VideoCommon::CacheType which = VideoCommon::CacheType::All);
|
||||
|
||||
/**
|
||||
* ReadBlockUnsafe and WriteBlockUnsafe are special versions of ReadBlock and
|
||||
@@ -156,14 +160,21 @@ public:
|
||||
u8* GetSpan(const GPUVAddr src_addr, const std::size_t size);
|
||||
|
||||
private:
|
||||
template <typename FuncMapped, typename FuncReserved, typename FuncUnmapped>
|
||||
inline void MemoryOperation(GPUVAddr gpu_src_addr, std::size_t size, bool is_big_page, FuncMapped&& func_mapped, FuncReserved&& func_reserved, FuncUnmapped&& func_unmapped) const;
|
||||
template <bool is_big_pages, typename FuncMapped, typename FuncReserved, typename FuncUnmapped>
|
||||
inline void MemoryOperation(GPUVAddr gpu_src_addr, std::size_t size, FuncMapped&& func_mapped,
|
||||
FuncReserved&& func_reserved, FuncUnmapped&& func_unmapped) const;
|
||||
|
||||
void ReadBlockImpl(GPUVAddr gpu_src_addr, void* dest_buffer, std::size_t size, VideoCommon::CacheType which, bool unsafe) const;
|
||||
void WriteBlockImpl(GPUVAddr gpu_dest_addr, const void* src_buffer, std::size_t size, VideoCommon::CacheType which, bool unsafe);
|
||||
template <bool is_safe>
|
||||
void ReadBlockImpl(GPUVAddr gpu_src_addr, void* dest_buffer, std::size_t size,
|
||||
VideoCommon::CacheType which) const;
|
||||
|
||||
[[nodiscard]] std::size_t PageEntryIndex(GPUVAddr gpu_addr, bool is_big_page) const {
|
||||
if (is_big_page) {
|
||||
template <bool is_safe>
|
||||
void WriteBlockImpl(GPUVAddr gpu_dest_addr, const void* src_buffer, std::size_t size,
|
||||
VideoCommon::CacheType which);
|
||||
|
||||
template <bool is_big_page>
|
||||
[[nodiscard]] std::size_t PageEntryIndex(GPUVAddr gpu_addr) const {
|
||||
if constexpr (is_big_page) {
|
||||
return (gpu_addr >> big_page_bits) & big_page_table_mask;
|
||||
} else {
|
||||
return (gpu_addr >> page_bits) & page_table_mask;
|
||||
@@ -176,7 +187,9 @@ private:
|
||||
template <bool is_gpu_address>
|
||||
void GetSubmappedRangeImpl(
|
||||
GPUVAddr gpu_addr, std::size_t size,
|
||||
boost::container::small_vector<std::pair<std::conditional_t<is_gpu_address, GPUVAddr, DAddr>, std::size_t>, 32>& result) const;
|
||||
boost::container::small_vector<
|
||||
std::pair<std::conditional_t<is_gpu_address, GPUVAddr, DAddr>, std::size_t>, 32>&
|
||||
result) const;
|
||||
|
||||
Core::System& system;
|
||||
MaxwellDeviceMemoryManager& memory;
|
||||
@@ -206,11 +219,19 @@ private:
|
||||
std::vector<u64> entries;
|
||||
std::vector<u64> big_entries;
|
||||
|
||||
GPUVAddr PageTableOp(GPUVAddr gpu_addr, [[maybe_unused]] DAddr dev_addr, size_t size, PTEKind kind, EntryType entry_type);
|
||||
GPUVAddr BigPageTableOp(GPUVAddr gpu_addr, [[maybe_unused]] DAddr dev_addr, size_t size, PTEKind kind, EntryType entry_type);
|
||||
template <EntryType entry_type>
|
||||
GPUVAddr PageTableOp(GPUVAddr gpu_addr, [[maybe_unused]] DAddr dev_addr, size_t size,
|
||||
PTEKind kind);
|
||||
|
||||
inline EntryType GetEntry(size_t position, bool is_big_page) const;
|
||||
inline void SetEntry(size_t position, EntryType entry, bool is_big_page);
|
||||
template <EntryType entry_type>
|
||||
GPUVAddr BigPageTableOp(GPUVAddr gpu_addr, [[maybe_unused]] DAddr dev_addr, size_t size,
|
||||
PTEKind kind);
|
||||
|
||||
template <bool is_big_page>
|
||||
inline EntryType GetEntry(size_t position) const;
|
||||
|
||||
template <bool is_big_page>
|
||||
inline void SetEntry(size_t position, EntryType entry);
|
||||
|
||||
Common::MultiLevelPageTable<u32> page_table;
|
||||
Common::RangeMap<GPUVAddr, PTEKind> kind_map;
|
||||
|
||||
@@ -93,7 +93,17 @@ public:
|
||||
void PostCopyBarrier();
|
||||
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);
|
||||
|
||||
@@ -128,6 +138,10 @@ public:
|
||||
|
||||
u64 GetDeviceMemoryUsage() const;
|
||||
|
||||
u64 GetDeviceAllocationUsage() const {
|
||||
return GetDeviceMemoryUsage();
|
||||
}
|
||||
|
||||
void BindFastUniformBuffer(size_t stage, u32 binding_index, u32 size) {
|
||||
const GLuint handle = fast_uniforms[stage][binding_index].handle;
|
||||
const GLsizeiptr gl_size = static_cast<GLsizeiptr>(size);
|
||||
@@ -213,9 +227,13 @@ private:
|
||||
GL_FRAGMENT_PROGRAM_PARAMETER_BUFFER_NV,
|
||||
};
|
||||
|
||||
static constexpr u64 SYNC_POINT_DELAY = 8;
|
||||
|
||||
const Device& device;
|
||||
StagingBufferPool& staging_buffer_pool;
|
||||
|
||||
u64 sync_point = 1;
|
||||
|
||||
bool has_fast_buffer_sub_data = false;
|
||||
bool use_assembly_shaders = false;
|
||||
bool has_unified_vertex_buffers = false;
|
||||
@@ -261,6 +279,7 @@ struct BufferCacheParams {
|
||||
|
||||
// TODO: Investigate why OpenGL seems to perform worse with persistently mapped buffer uploads
|
||||
static constexpr bool USE_MEMORY_MAPS_FOR_UPLOADS = false;
|
||||
static constexpr bool USE_UNIFIED_MEMORY = false;
|
||||
};
|
||||
|
||||
using BufferCache = VideoCommon::BufferCache<BufferCacheParams>;
|
||||
|
||||
@@ -485,7 +485,6 @@ void RasterizerOpenGL::FlushRegion(DAddr addr, u64 size, VideoCommon::CacheType
|
||||
texture_cache.DownloadMemory(addr, size);
|
||||
}
|
||||
if ((True(which & VideoCommon::CacheType::BufferCache))) {
|
||||
std::scoped_lock lock{buffer_cache.mutex};
|
||||
buffer_cache.DownloadMemory(addr, size);
|
||||
}
|
||||
if ((True(which & VideoCommon::CacheType::QueryCache))) {
|
||||
|
||||
@@ -87,6 +87,10 @@ public:
|
||||
|
||||
u64 GetDeviceMemoryUsage() const;
|
||||
|
||||
u64 GetDeviceAllocationUsage() const {
|
||||
return GetDeviceMemoryUsage();
|
||||
}
|
||||
|
||||
bool CanReportMemoryUsage() const {
|
||||
return device.CanReportMemoryUsage();
|
||||
}
|
||||
@@ -139,7 +143,19 @@ public:
|
||||
|
||||
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() {
|
||||
return state_tracker;
|
||||
@@ -174,6 +190,9 @@ private:
|
||||
std::array<OGLFramebuffer, 4> rescale_read_fbos;
|
||||
const Settings::ResolutionScalingInfo& resolution;
|
||||
u64 device_access_memory;
|
||||
|
||||
static constexpr u64 SYNC_POINT_DELAY = 8;
|
||||
u64 sync_point = 1;
|
||||
};
|
||||
|
||||
class Image : public VideoCommon::ImageBase {
|
||||
@@ -370,6 +389,7 @@ struct TextureCacheParams {
|
||||
static constexpr bool HAS_EMULATED_COPIES = true;
|
||||
static constexpr bool HAS_DEVICE_MEMORY_INFO = true;
|
||||
static constexpr bool IMPLEMENTS_ASYNC_DOWNLOADS = true;
|
||||
static constexpr bool HAS_TIMELINE_SYNC_POINTS = false;
|
||||
|
||||
using Runtime = OpenGL::TextureCacheRuntime;
|
||||
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_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_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_s8d24_to_abgr8_frag_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,
|
||||
VkFormat format, u32 base_level) {
|
||||
VkFormat format, u32 base_level,
|
||||
VkImageAspectFlags aspect_mask) {
|
||||
return device.CreateImageView(VkImageViewCreateInfo{
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
@@ -534,7 +536,7 @@ void RecordShaderReadBarrier(Scheduler& scheduler, const ImageView& image_view)
|
||||
.a = VK_COMPONENT_SWIZZLE_IDENTITY,
|
||||
},
|
||||
.subresourceRange{
|
||||
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
.aspectMask = aspect_mask,
|
||||
.baseMipLevel = base_level,
|
||||
.levelCount = 1,
|
||||
.baseArrayLayer = 0,
|
||||
@@ -545,6 +547,10 @@ void RecordShaderReadBarrier(Scheduler& scheduler, const ImageView& image_view)
|
||||
|
||||
void BeginRenderPass(vk::CommandBuffer& cmdbuf, const Framebuffer* framebuffer) {
|
||||
const VkRenderPass render_pass = framebuffer->RenderPass();
|
||||
if (!render_pass) {
|
||||
framebuffer->BeginRendering(cmdbuf);
|
||||
return;
|
||||
}
|
||||
const VkFramebuffer framebuffer_handle = framebuffer->Handle();
|
||||
const VkExtent2D render_area = framebuffer->RenderArea();
|
||||
const VkRenderPassBeginInfo renderpass_bi{
|
||||
@@ -561,6 +567,31 @@ void BeginRenderPass(vk::CommandBuffer& cmdbuf, const Framebuffer* framebuffer)
|
||||
};
|
||||
cmdbuf.BeginRenderPass(renderpass_bi, VK_SUBPASS_CONTENTS_INLINE);
|
||||
}
|
||||
|
||||
void EndRenderPass(vk::CommandBuffer& cmdbuf, const Framebuffer* framebuffer) {
|
||||
if (framebuffer->RenderPass()) {
|
||||
cmdbuf.EndRenderPass();
|
||||
} else {
|
||||
cmdbuf.EndRendering();
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] VkPipelineRenderingCreateInfo MakePipelineRenderingCreateInfo(
|
||||
const Framebuffer* framebuffer) {
|
||||
return VkPipelineRenderingCreateInfo{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.viewMask = 0,
|
||||
.colorAttachmentCount = framebuffer->NumColorAttachments(),
|
||||
.pColorAttachmentFormats = framebuffer->ColorAttachmentFormats().data(),
|
||||
.depthAttachmentFormat = framebuffer->HasAspectDepthBit()
|
||||
? framebuffer->DepthAttachmentFormat()
|
||||
: VK_FORMAT_UNDEFINED,
|
||||
.stencilAttachmentFormat = framebuffer->HasAspectStencilBit()
|
||||
? framebuffer->DepthAttachmentFormat()
|
||||
: VK_FORMAT_UNDEFINED,
|
||||
};
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
BlitImageHelper::BlitImageHelper(const Device& device_, Scheduler& scheduler_,
|
||||
@@ -610,6 +641,8 @@ BlitImageHelper::BlitImageHelper(const Device& device_, Scheduler& scheduler_,
|
||||
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_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>)),
|
||||
nearest_sampler(device.GetLogical().CreateSampler(SAMPLER_CREATE_INFO<VK_FILTER_NEAREST>)) {}
|
||||
|
||||
@@ -623,10 +656,12 @@ void BlitImageHelper::BlitColor(const Framebuffer* dst_framebuffer, const ImageV
|
||||
const BlitImagePipelineKey key{
|
||||
.renderpass = dst_framebuffer->RenderPass(),
|
||||
.operation = operation,
|
||||
.color_formats = dst_framebuffer->ColorAttachmentFormats(),
|
||||
.depth_format = dst_framebuffer->DepthAttachmentFormat(),
|
||||
};
|
||||
const VkPipelineLayout layout = *one_texture_pipeline_layout;
|
||||
const VkSampler sampler = is_linear ? *linear_sampler : *nearest_sampler;
|
||||
const VkPipeline pipeline = FindOrEmplaceColorPipeline(key);
|
||||
const VkPipeline pipeline = FindOrEmplaceColorPipeline(key, dst_framebuffer);
|
||||
const VkImageView src_view = src_image_view.Handle(Shader::TextureType::Color2D);
|
||||
|
||||
RecordShaderReadBarrier(scheduler, src_image_view);
|
||||
@@ -651,9 +686,11 @@ void BlitImageHelper::BlitColor(const Framebuffer* dst_framebuffer, VkImageView
|
||||
const BlitImagePipelineKey key{
|
||||
.renderpass = dst_framebuffer->RenderPass(),
|
||||
.operation = Tegra::Engines::Fermi2D::Operation::SrcCopy,
|
||||
.color_formats = dst_framebuffer->ColorAttachmentFormats(),
|
||||
.depth_format = dst_framebuffer->DepthAttachmentFormat(),
|
||||
};
|
||||
const VkPipelineLayout layout = *one_texture_pipeline_layout;
|
||||
const VkPipeline pipeline = FindOrEmplaceColorPipeline(key);
|
||||
const VkPipeline pipeline = FindOrEmplaceColorPipeline(key, dst_framebuffer);
|
||||
scheduler.RequestOutsideRenderPassOperationContext();
|
||||
scheduler.Record([this, dst_framebuffer, src_image_view, src_image, src_sampler, dst_region,
|
||||
src_region, src_size, pipeline, layout](vk::CommandBuffer cmdbuf) {
|
||||
@@ -666,7 +703,7 @@ void BlitImageHelper::BlitColor(const Framebuffer* dst_framebuffer, VkImageView
|
||||
nullptr);
|
||||
BindBlitState(cmdbuf, layout, dst_region, src_region, src_size);
|
||||
cmdbuf.Draw(3, 1, 0, 0);
|
||||
cmdbuf.EndRenderPass();
|
||||
EndRenderPass(cmdbuf, dst_framebuffer);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -676,10 +713,12 @@ void BlitImageHelper::BlitColorMSAA(const Framebuffer* dst_framebuffer,
|
||||
const BlitMSAAPipelineKey key{
|
||||
.renderpass = dst_framebuffer->RenderPass(),
|
||||
.samples = dst_framebuffer->Samples(),
|
||||
.color_formats = dst_framebuffer->ColorAttachmentFormats(),
|
||||
.depth_format = dst_framebuffer->DepthAttachmentFormat(),
|
||||
};
|
||||
const VkPipelineLayout layout = *one_texture_pipeline_layout;
|
||||
const VkSampler sampler = *nearest_sampler;
|
||||
const VkPipeline pipeline = FindOrEmplaceBlitColorMSAAPipeline(key);
|
||||
const VkPipeline pipeline = FindOrEmplaceBlitColorMSAAPipeline(key, dst_framebuffer);
|
||||
const VkImageView src_view = src_image_view.Handle(Shader::TextureType::Color2D);
|
||||
|
||||
RecordShaderReadBarrier(scheduler, src_image_view);
|
||||
@@ -703,7 +742,7 @@ void BlitImageHelper::ResolveDepthStencil(const Framebuffer* dst_framebuffer,
|
||||
const bool resolve_stencil =
|
||||
dst_framebuffer->HasAspectStencilBit() && device.IsExtShaderStencilExportSupported();
|
||||
const VkPipeline pipeline =
|
||||
FindOrEmplaceResolveDepthStencilPipeline(dst_framebuffer->RenderPass(), resolve_stencil);
|
||||
FindOrEmplaceResolveDepthStencilPipeline(dst_framebuffer, resolve_stencil);
|
||||
const VkPipelineLayout layout =
|
||||
resolve_stencil ? *two_textures_pipeline_layout : *one_texture_pipeline_layout;
|
||||
const VkSampler sampler = *nearest_sampler;
|
||||
@@ -747,10 +786,12 @@ void BlitImageHelper::BlitDepthStencil(const Framebuffer* dst_framebuffer,
|
||||
const BlitImagePipelineKey key{
|
||||
.renderpass = dst_framebuffer->RenderPass(),
|
||||
.operation = operation,
|
||||
.color_formats = dst_framebuffer->ColorAttachmentFormats(),
|
||||
.depth_format = dst_framebuffer->DepthAttachmentFormat(),
|
||||
};
|
||||
const VkPipelineLayout layout = *two_textures_pipeline_layout;
|
||||
const VkSampler sampler = *nearest_sampler;
|
||||
const VkPipeline pipeline = FindOrEmplaceDepthStencilPipeline(key);
|
||||
const VkPipeline pipeline = FindOrEmplaceDepthStencilPipeline(key, dst_framebuffer);
|
||||
const VkImageView src_depth_view = src_image_view.DepthView();
|
||||
const VkImageView src_stencil_view = src_image_view.StencilView();
|
||||
|
||||
@@ -772,25 +813,25 @@ void BlitImageHelper::BlitDepthStencil(const Framebuffer* dst_framebuffer,
|
||||
|
||||
void BlitImageHelper::ConvertD32ToR32(const Framebuffer* dst_framebuffer,
|
||||
const ImageView& src_image_view) {
|
||||
ConvertDepthToColorPipeline(convert_d32_to_r32_pipeline, dst_framebuffer->RenderPass());
|
||||
ConvertDepthToColorPipeline(convert_d32_to_r32_pipeline, dst_framebuffer);
|
||||
Convert(*convert_d32_to_r32_pipeline, dst_framebuffer, src_image_view);
|
||||
}
|
||||
|
||||
void BlitImageHelper::ConvertR32ToD32(const Framebuffer* dst_framebuffer,
|
||||
const ImageView& src_image_view) {
|
||||
ConvertColorToDepthPipeline(convert_r32_to_d32_pipeline, dst_framebuffer->RenderPass());
|
||||
ConvertColorToDepthPipeline(convert_r32_to_d32_pipeline, dst_framebuffer);
|
||||
Convert(*convert_r32_to_d32_pipeline, dst_framebuffer, src_image_view);
|
||||
}
|
||||
|
||||
void BlitImageHelper::ConvertD16ToR16(const Framebuffer* dst_framebuffer,
|
||||
const ImageView& src_image_view) {
|
||||
ConvertDepthToColorPipeline(convert_d16_to_r16_pipeline, dst_framebuffer->RenderPass());
|
||||
ConvertDepthToColorPipeline(convert_d16_to_r16_pipeline, dst_framebuffer);
|
||||
Convert(*convert_d16_to_r16_pipeline, dst_framebuffer, src_image_view);
|
||||
}
|
||||
|
||||
void BlitImageHelper::ConvertR16ToD16(const Framebuffer* dst_framebuffer,
|
||||
const ImageView& src_image_view) {
|
||||
ConvertColorToDepthPipeline(convert_r16_to_d16_pipeline, dst_framebuffer->RenderPass());
|
||||
ConvertColorToDepthPipeline(convert_r16_to_d16_pipeline, dst_framebuffer);
|
||||
Convert(*convert_r16_to_d16_pipeline, dst_framebuffer, src_image_view);
|
||||
}
|
||||
|
||||
@@ -801,35 +842,35 @@ void BlitImageHelper::ConvertABGR8ToD24S8(const Framebuffer* dst_framebuffer,
|
||||
LOG_WARNING(Render_Vulkan, "ConvertABGR8ToD24S8 requires shader_stencil_export, skipping");
|
||||
return;
|
||||
}
|
||||
ConvertPipelineDepthTargetEx(convert_abgr8_to_d24s8_pipeline, dst_framebuffer->RenderPass(),
|
||||
ConvertPipelineDepthTargetEx(convert_abgr8_to_d24s8_pipeline, dst_framebuffer,
|
||||
convert_abgr8_to_d24s8_frag);
|
||||
Convert(*convert_abgr8_to_d24s8_pipeline, dst_framebuffer, src_image_view);
|
||||
}
|
||||
|
||||
void BlitImageHelper::ConvertABGR8ToD32F(const Framebuffer* dst_framebuffer,
|
||||
const ImageView& src_image_view) {
|
||||
ConvertPipelineDepthTargetEx(convert_abgr8_to_d32f_pipeline, dst_framebuffer->RenderPass(),
|
||||
ConvertPipelineDepthTargetEx(convert_abgr8_to_d32f_pipeline, dst_framebuffer,
|
||||
convert_abgr8_to_d32f_frag);
|
||||
Convert(*convert_abgr8_to_d32f_pipeline, dst_framebuffer, src_image_view);
|
||||
}
|
||||
|
||||
void BlitImageHelper::ConvertD32FToABGR8(const Framebuffer* dst_framebuffer,
|
||||
ImageView& src_image_view) {
|
||||
ConvertPipelineColorTargetEx(convert_d32f_to_abgr8_pipeline, dst_framebuffer->RenderPass(),
|
||||
ConvertPipelineColorTargetEx(convert_d32f_to_abgr8_pipeline, dst_framebuffer,
|
||||
convert_d32f_to_abgr8_frag);
|
||||
ConvertDepthStencil(*convert_d32f_to_abgr8_pipeline, dst_framebuffer, src_image_view);
|
||||
}
|
||||
|
||||
void BlitImageHelper::ConvertD24S8ToABGR8(const Framebuffer* dst_framebuffer,
|
||||
ImageView& src_image_view) {
|
||||
ConvertPipelineColorTargetEx(convert_d24s8_to_abgr8_pipeline, dst_framebuffer->RenderPass(),
|
||||
ConvertPipelineColorTargetEx(convert_d24s8_to_abgr8_pipeline, dst_framebuffer,
|
||||
convert_d24s8_to_abgr8_frag);
|
||||
ConvertDepthStencil(*convert_d24s8_to_abgr8_pipeline, dst_framebuffer, src_image_view);
|
||||
}
|
||||
|
||||
void BlitImageHelper::ConvertS8D24ToABGR8(const Framebuffer* dst_framebuffer,
|
||||
ImageView& src_image_view) {
|
||||
ConvertPipelineColorTargetEx(convert_s8d24_to_abgr8_pipeline, dst_framebuffer->RenderPass(),
|
||||
ConvertPipelineColorTargetEx(convert_s8d24_to_abgr8_pipeline, dst_framebuffer,
|
||||
convert_s8d24_to_abgr8_frag);
|
||||
ConvertDepthStencil(*convert_s8d24_to_abgr8_pipeline, dst_framebuffer, src_image_view);
|
||||
}
|
||||
@@ -840,8 +881,10 @@ void BlitImageHelper::ClearColor(const Framebuffer* dst_framebuffer, u8 color_ma
|
||||
const BlitImagePipelineKey key{
|
||||
.renderpass = dst_framebuffer->RenderPass(),
|
||||
.operation = Tegra::Engines::Fermi2D::Operation::BlendPremult,
|
||||
.color_formats = dst_framebuffer->ColorAttachmentFormats(),
|
||||
.depth_format = dst_framebuffer->DepthAttachmentFormat(),
|
||||
};
|
||||
const VkPipeline pipeline = FindOrEmplaceClearColorPipeline(key);
|
||||
const VkPipeline pipeline = FindOrEmplaceClearColorPipeline(key, dst_framebuffer);
|
||||
const VkPipelineLayout layout = *clear_color_pipeline_layout;
|
||||
scheduler.RequestRenderpass(dst_framebuffer);
|
||||
scheduler.Record(
|
||||
@@ -867,8 +910,10 @@ void BlitImageHelper::ClearDepthStencil(const Framebuffer* dst_framebuffer, bool
|
||||
.stencil_mask = stencil_mask,
|
||||
.stencil_compare_mask = stencil_compare_mask,
|
||||
.stencil_ref = stencil_ref,
|
||||
.color_formats = dst_framebuffer->ColorAttachmentFormats(),
|
||||
.depth_format = dst_framebuffer->DepthAttachmentFormat(),
|
||||
};
|
||||
const VkPipeline pipeline = FindOrEmplaceClearStencilPipeline(key);
|
||||
const VkPipeline pipeline = FindOrEmplaceClearStencilPipeline(key, dst_framebuffer);
|
||||
const VkPipelineLayout layout = *clear_color_pipeline_layout;
|
||||
scheduler.RequestRenderpass(dst_framebuffer);
|
||||
scheduler.Record([pipeline, layout, clear_depth, dst_region](vk::CommandBuffer cmdbuf) {
|
||||
@@ -895,16 +940,34 @@ void BlitImageHelper::CopyMSAA(RenderPassCache& render_pass_cache, VkImage dst_i
|
||||
const s32 scale_y = 1 << samples_y;
|
||||
const VkSampleCountFlagBits 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{};
|
||||
renderpass_key.color_formats.fill(VideoCore::Surface::PixelFormat::Invalid);
|
||||
renderpass_key.color_formats[0] = dst_format;
|
||||
renderpass_key.depth_format = VideoCore::Surface::PixelFormat::Invalid;
|
||||
if (is_depth) {
|
||||
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;
|
||||
const VkRenderPass renderpass = render_pass_cache.Get(renderpass_key);
|
||||
const MSAACopyPipelineKey key{
|
||||
.renderpass = renderpass,
|
||||
.samples = samples,
|
||||
.msaa_to_non_msaa = msaa_to_non_msaa,
|
||||
.is_depth = is_depth,
|
||||
};
|
||||
const VkPipeline pipeline = FindOrEmplaceMSAACopyPipeline(key);
|
||||
const VkPipelineLayout layout = *msaa_copy_pipeline_layout;
|
||||
@@ -920,10 +983,10 @@ void BlitImageHelper::CopyMSAA(RenderPassCache& render_pass_cache, VkImage dst_i
|
||||
ASSERT(copy.dst_subresource.num_layers == 1);
|
||||
vk::ImageView src_view =
|
||||
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 =
|
||||
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 VkExtent2D dst_extent{copy.extent.width, copy.extent.height};
|
||||
const VkRect2D render_area{
|
||||
@@ -949,50 +1012,64 @@ void BlitImageHelper::CopyMSAA(RenderPassCache& render_pass_cache, VkImage dst_i
|
||||
scheduler.RequestOutsideRenderPassOperationContext();
|
||||
scheduler.Record([this, pipeline, layout, sampler, renderpass,
|
||||
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) {
|
||||
constexpr VkImageSubresourceRange color_range{
|
||||
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
const VkImageSubresourceRange src_range{
|
||||
.aspectMask = barrier_aspect,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = VK_REMAINING_MIP_LEVELS,
|
||||
.baseArrayLayer = 0,
|
||||
.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{
|
||||
VkImageMemoryBarrier{
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
||||
.pNext = nullptr,
|
||||
.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
|
||||
VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
.srcAccessMask = attachment_write | VK_ACCESS_SHADER_WRITE_BIT |
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
.dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
|
||||
.oldLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = src,
|
||||
.subresourceRange = color_range,
|
||||
.subresourceRange = src_range,
|
||||
},
|
||||
VkImageMemoryBarrier{
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
||||
.pNext = nullptr,
|
||||
.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
|
||||
VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
|
||||
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
.srcAccessMask = attachment_write | VK_ACCESS_SHADER_WRITE_BIT |
|
||||
VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
.dstAccessMask = attachment_read | attachment_write,
|
||||
.oldLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = dst,
|
||||
.subresourceRange = color_range,
|
||||
.subresourceRange = dst_range,
|
||||
},
|
||||
};
|
||||
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_FRAGMENT_SHADER_BIT |
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT |
|
||||
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | attachment_stage,
|
||||
0, nullptr, nullptr, pre_barriers);
|
||||
const VkRenderPassBeginInfo renderpass_bi{
|
||||
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
|
||||
@@ -1025,16 +1102,16 @@ void BlitImageHelper::CopyMSAA(RenderPassCache& render_pass_cache, VkImage dst_i
|
||||
const VkImageMemoryBarrier post_barrier{
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
||||
.pNext = nullptr,
|
||||
.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
.srcAccessMask = attachment_write,
|
||||
.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT,
|
||||
.oldLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.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_COMPUTE_SHADER_BIT |
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
@@ -1140,12 +1217,14 @@ void BlitImageHelper::ConvertDepthStencil(VkPipeline pipeline, const Framebuffer
|
||||
scheduler.InvalidateState();
|
||||
}
|
||||
|
||||
VkPipeline BlitImageHelper::FindOrEmplaceColorPipeline(const BlitImagePipelineKey& key) {
|
||||
VkPipeline BlitImageHelper::FindOrEmplaceColorPipeline(const BlitImagePipelineKey& key,
|
||||
const Framebuffer* framebuffer) {
|
||||
const auto it = std::ranges::find(blit_color_keys, key);
|
||||
if (it != blit_color_keys.end()) {
|
||||
return *blit_color_pipelines[std::distance(blit_color_keys.begin(), it)];
|
||||
}
|
||||
blit_color_keys.push_back(key);
|
||||
const VkPipelineRenderingCreateInfo rendering_ci = MakePipelineRenderingCreateInfo(framebuffer);
|
||||
|
||||
const std::array stages = MakeStages(*full_screen_vert, *blit_color_to_color_frag);
|
||||
const VkPipelineColorBlendAttachmentState blend_attachment{
|
||||
@@ -1173,7 +1252,7 @@ VkPipeline BlitImageHelper::FindOrEmplaceColorPipeline(const BlitImagePipelineKe
|
||||
const VkPipelineInputAssemblyStateCreateInfo input_assembly_ci = GetPipelineInputAssemblyStateCreateInfo(device);
|
||||
blit_color_pipelines.push_back(device.GetLogical().CreateGraphicsPipeline({
|
||||
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.pNext = key.renderpass ? nullptr : &rendering_ci,
|
||||
.flags = 0,
|
||||
.stageCount = static_cast<u32>(stages.size()),
|
||||
.pStages = stages.data(),
|
||||
@@ -1191,21 +1270,23 @@ VkPipeline BlitImageHelper::FindOrEmplaceColorPipeline(const BlitImagePipelineKe
|
||||
.subpass = 0,
|
||||
.basePipelineHandle = VK_NULL_HANDLE,
|
||||
.basePipelineIndex = 0,
|
||||
}));
|
||||
}, device.StaticPipelineCache()));
|
||||
return *blit_color_pipelines.back();
|
||||
}
|
||||
|
||||
VkPipeline BlitImageHelper::FindOrEmplaceDepthStencilPipeline(const BlitImagePipelineKey& key) {
|
||||
VkPipeline BlitImageHelper::FindOrEmplaceDepthStencilPipeline(const BlitImagePipelineKey& key,
|
||||
const Framebuffer* framebuffer) {
|
||||
const auto it = std::ranges::find(blit_depth_stencil_keys, key);
|
||||
if (it != blit_depth_stencil_keys.end()) {
|
||||
return *blit_depth_stencil_pipelines[std::distance(blit_depth_stencil_keys.begin(), it)];
|
||||
}
|
||||
blit_depth_stencil_keys.push_back(key);
|
||||
const VkPipelineRenderingCreateInfo rendering_ci = MakePipelineRenderingCreateInfo(framebuffer);
|
||||
const std::array stages = MakeStages(*full_screen_vert, *blit_depth_stencil_frag);
|
||||
const VkPipelineInputAssemblyStateCreateInfo input_assembly_ci = GetPipelineInputAssemblyStateCreateInfo(device);
|
||||
blit_depth_stencil_pipelines.push_back(device.GetLogical().CreateGraphicsPipeline({
|
||||
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.pNext = key.renderpass ? nullptr : &rendering_ci,
|
||||
.flags = 0,
|
||||
.stageCount = static_cast<u32>(stages.size()),
|
||||
.pStages = stages.data(),
|
||||
@@ -1223,42 +1304,50 @@ VkPipeline BlitImageHelper::FindOrEmplaceDepthStencilPipeline(const BlitImagePip
|
||||
.subpass = 0,
|
||||
.basePipelineHandle = VK_NULL_HANDLE,
|
||||
.basePipelineIndex = 0,
|
||||
}));
|
||||
}, device.StaticPipelineCache()));
|
||||
return *blit_depth_stencil_pipelines.back();
|
||||
}
|
||||
|
||||
VkPipeline BlitImageHelper::FindOrEmplaceClearColorPipeline(const BlitImagePipelineKey& key) {
|
||||
VkPipeline BlitImageHelper::FindOrEmplaceClearColorPipeline(const BlitImagePipelineKey& key,
|
||||
const Framebuffer* framebuffer) {
|
||||
const auto it = std::ranges::find(clear_color_keys, key);
|
||||
if (it != clear_color_keys.end()) {
|
||||
return *clear_color_pipelines[std::distance(clear_color_keys.begin(), it)];
|
||||
}
|
||||
clear_color_keys.push_back(key);
|
||||
const VkPipelineRenderingCreateInfo rendering_ci = MakePipelineRenderingCreateInfo(framebuffer);
|
||||
const std::array stages = MakeStages(*clear_color_vert, *clear_color_frag);
|
||||
const VkPipelineColorBlendAttachmentState color_blend_attachment_state{
|
||||
.blendEnable = VK_TRUE,
|
||||
.srcColorBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR,
|
||||
.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR,
|
||||
.colorBlendOp = VK_BLEND_OP_ADD,
|
||||
.srcAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_ALPHA,
|
||||
.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA,
|
||||
.alphaBlendOp = VK_BLEND_OP_ADD,
|
||||
.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |
|
||||
VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT,
|
||||
};
|
||||
const u32 num_color = framebuffer->NumColorAttachments();
|
||||
constexpr VkColorComponentFlags full_write_mask =
|
||||
VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT |
|
||||
VK_COLOR_COMPONENT_A_BIT;
|
||||
std::array<VkPipelineColorBlendAttachmentState, VideoCommon::NUM_RT> blend_attachments{};
|
||||
for (u32 index = 0; index < num_color; ++index) {
|
||||
blend_attachments[index] = VkPipelineColorBlendAttachmentState{
|
||||
.blendEnable = index == 0 ? VK_TRUE : VK_FALSE,
|
||||
.srcColorBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR,
|
||||
.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR,
|
||||
.colorBlendOp = VK_BLEND_OP_ADD,
|
||||
.srcAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_ALPHA,
|
||||
.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA,
|
||||
.alphaBlendOp = VK_BLEND_OP_ADD,
|
||||
.colorWriteMask = index == 0 ? full_write_mask : VkColorComponentFlags{0},
|
||||
};
|
||||
}
|
||||
const VkPipelineColorBlendStateCreateInfo color_blend_state_generic_create_info{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.flags = 0,
|
||||
.logicOpEnable = VK_FALSE,
|
||||
.logicOp = VK_LOGIC_OP_CLEAR,
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &color_blend_attachment_state,
|
||||
.attachmentCount = num_color,
|
||||
.pAttachments = blend_attachments.data(),
|
||||
.blendConstants = {0.0f, 0.0f, 0.0f, 0.0f},
|
||||
};
|
||||
const VkPipelineInputAssemblyStateCreateInfo input_assembly_ci = GetPipelineInputAssemblyStateCreateInfo(device);
|
||||
clear_color_pipelines.push_back(device.GetLogical().CreateGraphicsPipeline({
|
||||
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.pNext = key.renderpass ? nullptr : &rendering_ci,
|
||||
.flags = 0,
|
||||
.stageCount = static_cast<u32>(stages.size()),
|
||||
.pStages = stages.data(),
|
||||
@@ -1276,18 +1365,31 @@ VkPipeline BlitImageHelper::FindOrEmplaceClearColorPipeline(const BlitImagePipel
|
||||
.subpass = 0,
|
||||
.basePipelineHandle = VK_NULL_HANDLE,
|
||||
.basePipelineIndex = 0,
|
||||
}));
|
||||
}, device.StaticPipelineCache()));
|
||||
return *clear_color_pipelines.back();
|
||||
}
|
||||
|
||||
VkPipeline BlitImageHelper::FindOrEmplaceClearStencilPipeline(
|
||||
const BlitDepthStencilPipelineKey& key) {
|
||||
const BlitDepthStencilPipelineKey& key, const Framebuffer* framebuffer) {
|
||||
const auto it = std::ranges::find(clear_stencil_keys, key);
|
||||
if (it != clear_stencil_keys.end()) {
|
||||
return *clear_stencil_pipelines[std::distance(clear_stencil_keys.begin(), it)];
|
||||
}
|
||||
clear_stencil_keys.push_back(key);
|
||||
const VkPipelineRenderingCreateInfo rendering_ci = MakePipelineRenderingCreateInfo(framebuffer);
|
||||
const std::array stages = MakeStages(*clear_color_vert, *clear_stencil_frag);
|
||||
const u32 num_color = framebuffer->NumColorAttachments();
|
||||
std::array<VkPipelineColorBlendAttachmentState, VideoCommon::NUM_RT> blend_attachments{};
|
||||
const VkPipelineColorBlendStateCreateInfo 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 = num_color,
|
||||
.pAttachments = blend_attachments.data(),
|
||||
.blendConstants = {0.0f, 0.0f, 0.0f, 0.0f},
|
||||
};
|
||||
const auto stencil = VkStencilOpState{
|
||||
.failOp = VK_STENCIL_OP_KEEP,
|
||||
.passOp = VK_STENCIL_OP_REPLACE,
|
||||
@@ -1314,7 +1416,7 @@ VkPipeline BlitImageHelper::FindOrEmplaceClearStencilPipeline(
|
||||
const VkPipelineInputAssemblyStateCreateInfo input_assembly_ci = GetPipelineInputAssemblyStateCreateInfo(device);
|
||||
clear_stencil_pipelines.push_back(device.GetLogical().CreateGraphicsPipeline({
|
||||
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.pNext = key.renderpass ? nullptr : &rendering_ci,
|
||||
.flags = 0,
|
||||
.stageCount = static_cast<u32>(stages.size()),
|
||||
.pStages = stages.data(),
|
||||
@@ -1325,23 +1427,25 @@ VkPipeline BlitImageHelper::FindOrEmplaceClearStencilPipeline(
|
||||
.pRasterizationState = &PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
|
||||
.pMultisampleState = &PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
||||
.pDepthStencilState = &depth_stencil_ci,
|
||||
.pColorBlendState = &PIPELINE_COLOR_BLEND_STATE_GENERIC_CREATE_INFO,
|
||||
.pColorBlendState = &color_blend_ci,
|
||||
.pDynamicState = &PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
||||
.layout = *clear_color_pipeline_layout,
|
||||
.renderPass = key.renderpass,
|
||||
.subpass = 0,
|
||||
.basePipelineHandle = VK_NULL_HANDLE,
|
||||
.basePipelineIndex = 0,
|
||||
}));
|
||||
}, device.StaticPipelineCache()));
|
||||
return *clear_stencil_pipelines.back();
|
||||
}
|
||||
|
||||
VkPipeline BlitImageHelper::FindOrEmplaceBlitColorMSAAPipeline(const BlitMSAAPipelineKey& key) {
|
||||
VkPipeline BlitImageHelper::FindOrEmplaceBlitColorMSAAPipeline(const BlitMSAAPipelineKey& key,
|
||||
const Framebuffer* framebuffer) {
|
||||
const auto it = std::ranges::find(blit_msaa_color_keys, key);
|
||||
if (it != blit_msaa_color_keys.end()) {
|
||||
return *blit_msaa_color_pipelines[std::distance(blit_msaa_color_keys.begin(), it)];
|
||||
}
|
||||
blit_msaa_color_keys.push_back(key);
|
||||
const VkPipelineRenderingCreateInfo rendering_ci = MakePipelineRenderingCreateInfo(framebuffer);
|
||||
const std::array stages = MakeStages(*full_screen_vert, *blit_color_msaa_frag);
|
||||
const VkPipelineMultisampleStateCreateInfo multisample_ci{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
||||
@@ -1357,7 +1461,7 @@ VkPipeline BlitImageHelper::FindOrEmplaceBlitColorMSAAPipeline(const BlitMSAAPip
|
||||
const VkPipelineInputAssemblyStateCreateInfo input_assembly_ci = GetPipelineInputAssemblyStateCreateInfo(device);
|
||||
blit_msaa_color_pipelines.push_back(device.GetLogical().CreateGraphicsPipeline({
|
||||
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.pNext = key.renderpass ? nullptr : &rendering_ci,
|
||||
.flags = 0,
|
||||
.stageCount = static_cast<u32>(stages.size()),
|
||||
.pStages = stages.data(),
|
||||
@@ -1375,26 +1479,32 @@ VkPipeline BlitImageHelper::FindOrEmplaceBlitColorMSAAPipeline(const BlitMSAAPip
|
||||
.subpass = 0,
|
||||
.basePipelineHandle = VK_NULL_HANDLE,
|
||||
.basePipelineIndex = 0,
|
||||
}));
|
||||
}, device.StaticPipelineCache()));
|
||||
return *blit_msaa_color_pipelines.back();
|
||||
}
|
||||
|
||||
VkPipeline BlitImageHelper::FindOrEmplaceResolveDepthStencilPipeline(VkRenderPass renderpass,
|
||||
bool resolve_stencil) {
|
||||
VkPipeline BlitImageHelper::FindOrEmplaceResolveDepthStencilPipeline(
|
||||
const Framebuffer* framebuffer, bool resolve_stencil) {
|
||||
const VkRenderPass renderpass = framebuffer->RenderPass();
|
||||
const ResolveDepthStencilPipelineKey key{
|
||||
.renderpass = renderpass,
|
||||
.depth_format = framebuffer->DepthAttachmentFormat(),
|
||||
};
|
||||
auto& keys = resolve_stencil ? resolve_depth_stencil_keys : resolve_depth_keys;
|
||||
auto& pipelines = resolve_stencil ? resolve_depth_stencil_pipelines : resolve_depth_pipelines;
|
||||
const auto it = std::ranges::find(keys, renderpass);
|
||||
const auto it = std::ranges::find(keys, key);
|
||||
if (it != keys.end()) {
|
||||
return *pipelines[std::distance(keys.begin(), it)];
|
||||
}
|
||||
keys.push_back(renderpass);
|
||||
keys.push_back(key);
|
||||
const VkPipelineRenderingCreateInfo rendering_ci = MakePipelineRenderingCreateInfo(framebuffer);
|
||||
const std::array stages =
|
||||
MakeStages(*full_screen_vert,
|
||||
resolve_stencil ? *blit_depth_stencil_msaa_frag : *blit_depth_msaa_frag);
|
||||
const VkPipelineInputAssemblyStateCreateInfo input_assembly_ci = GetPipelineInputAssemblyStateCreateInfo(device);
|
||||
pipelines.push_back(device.GetLogical().CreateGraphicsPipeline({
|
||||
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.pNext = renderpass ? nullptr : &rendering_ci,
|
||||
.flags = 0,
|
||||
.stageCount = static_cast<u32>(stages.size()),
|
||||
.pStages = stages.data(),
|
||||
@@ -1413,7 +1523,7 @@ VkPipeline BlitImageHelper::FindOrEmplaceResolveDepthStencilPipeline(VkRenderPas
|
||||
.subpass = 0,
|
||||
.basePipelineHandle = VK_NULL_HANDLE,
|
||||
.basePipelineIndex = 0,
|
||||
}));
|
||||
}, device.StaticPipelineCache()));
|
||||
return *pipelines.back();
|
||||
}
|
||||
|
||||
@@ -1423,9 +1533,36 @@ VkPipeline BlitImageHelper::FindOrEmplaceMSAACopyPipeline(const MSAACopyPipeline
|
||||
return *msaa_copy_pipelines[std::distance(msaa_copy_keys.begin(), it)];
|
||||
}
|
||||
msaa_copy_keys.push_back(key);
|
||||
const std::array stages = MakeStages(*clear_color_vert, key.msaa_to_non_msaa
|
||||
? *convert_msaa_to_non_msaa_frag
|
||||
: *convert_non_msaa_to_msaa_frag);
|
||||
const VkShaderModule frag_module =
|
||||
key.msaa_to_non_msaa
|
||||
? *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{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
@@ -1450,37 +1587,42 @@ VkPipeline BlitImageHelper::FindOrEmplaceMSAACopyPipeline(const MSAACopyPipeline
|
||||
.pViewportState = &PIPELINE_VIEWPORT_STATE_CREATE_INFO,
|
||||
.pRasterizationState = &PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
|
||||
.pMultisampleState = &multisample_ci,
|
||||
.pDepthStencilState = nullptr,
|
||||
.pColorBlendState = &PIPELINE_COLOR_BLEND_STATE_GENERIC_CREATE_INFO,
|
||||
.pDepthStencilState = key.is_depth ? &depth_stencil_ci : nullptr,
|
||||
.pColorBlendState = key.is_depth ? &no_color_blend_ci
|
||||
: &PIPELINE_COLOR_BLEND_STATE_GENERIC_CREATE_INFO,
|
||||
.pDynamicState = &PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
||||
.layout = *msaa_copy_pipeline_layout,
|
||||
.renderPass = key.renderpass,
|
||||
.subpass = 0,
|
||||
.basePipelineHandle = VK_NULL_HANDLE,
|
||||
.basePipelineIndex = 0,
|
||||
}));
|
||||
}, device.StaticPipelineCache()));
|
||||
return *msaa_copy_pipelines.back();
|
||||
}
|
||||
|
||||
void BlitImageHelper::ConvertDepthToColorPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass) {
|
||||
ConvertPipeline(pipeline, renderpass, false);
|
||||
void BlitImageHelper::ConvertDepthToColorPipeline(vk::Pipeline& pipeline,
|
||||
const Framebuffer* framebuffer) {
|
||||
ConvertPipeline(pipeline, framebuffer, false);
|
||||
}
|
||||
|
||||
void BlitImageHelper::ConvertColorToDepthPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass) {
|
||||
ConvertPipeline(pipeline, renderpass, true);
|
||||
void BlitImageHelper::ConvertColorToDepthPipeline(vk::Pipeline& pipeline,
|
||||
const Framebuffer* framebuffer) {
|
||||
ConvertPipeline(pipeline, framebuffer, true);
|
||||
}
|
||||
|
||||
void BlitImageHelper::ConvertPipelineEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
|
||||
void BlitImageHelper::ConvertPipelineEx(vk::Pipeline& pipeline, const Framebuffer* framebuffer,
|
||||
vk::ShaderModule& module, bool single_texture,
|
||||
bool is_target_depth) {
|
||||
if (pipeline) {
|
||||
return;
|
||||
}
|
||||
const VkRenderPass renderpass = framebuffer->RenderPass();
|
||||
const VkPipelineRenderingCreateInfo rendering_ci = MakePipelineRenderingCreateInfo(framebuffer);
|
||||
const std::array stages = MakeStages(*full_screen_vert, *module);
|
||||
const VkPipelineInputAssemblyStateCreateInfo input_assembly_ci = GetPipelineInputAssemblyStateCreateInfo(device);
|
||||
pipeline = device.GetLogical().CreateGraphicsPipeline(VkGraphicsPipelineCreateInfo{
|
||||
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.pNext = renderpass ? nullptr : &rendering_ci,
|
||||
.flags = 0,
|
||||
.stageCount = static_cast<u32>(stages.size()),
|
||||
.pStages = stages.data(),
|
||||
@@ -1499,31 +1641,35 @@ void BlitImageHelper::ConvertPipelineEx(vk::Pipeline& pipeline, VkRenderPass ren
|
||||
.subpass = 0,
|
||||
.basePipelineHandle = VK_NULL_HANDLE,
|
||||
.basePipelineIndex = 0,
|
||||
});
|
||||
}, device.StaticPipelineCache());
|
||||
}
|
||||
|
||||
void BlitImageHelper::ConvertPipelineColorTargetEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
|
||||
void BlitImageHelper::ConvertPipelineColorTargetEx(vk::Pipeline& pipeline,
|
||||
const Framebuffer* framebuffer,
|
||||
vk::ShaderModule& module) {
|
||||
ConvertPipelineEx(pipeline, renderpass, module, false, false);
|
||||
ConvertPipelineEx(pipeline, framebuffer, module, false, false);
|
||||
}
|
||||
|
||||
void BlitImageHelper::ConvertPipelineDepthTargetEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
|
||||
void BlitImageHelper::ConvertPipelineDepthTargetEx(vk::Pipeline& pipeline,
|
||||
const Framebuffer* framebuffer,
|
||||
vk::ShaderModule& module) {
|
||||
ConvertPipelineEx(pipeline, renderpass, module, true, true);
|
||||
ConvertPipelineEx(pipeline, framebuffer, module, true, true);
|
||||
}
|
||||
|
||||
void BlitImageHelper::ConvertPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass,
|
||||
void BlitImageHelper::ConvertPipeline(vk::Pipeline& pipeline, const Framebuffer* framebuffer,
|
||||
bool is_target_depth) {
|
||||
if (pipeline) {
|
||||
return;
|
||||
}
|
||||
const VkRenderPass renderpass = framebuffer->RenderPass();
|
||||
const VkPipelineRenderingCreateInfo rendering_ci = MakePipelineRenderingCreateInfo(framebuffer);
|
||||
VkShaderModule frag_shader =
|
||||
is_target_depth ? *convert_float_to_depth_frag : *convert_depth_to_float_frag;
|
||||
const std::array stages = MakeStages(*full_screen_vert, frag_shader);
|
||||
const VkPipelineInputAssemblyStateCreateInfo input_assembly_ci = GetPipelineInputAssemblyStateCreateInfo(device);
|
||||
pipeline = device.GetLogical().CreateGraphicsPipeline(VkGraphicsPipelineCreateInfo{
|
||||
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.pNext = renderpass ? nullptr : &rendering_ci,
|
||||
.flags = 0,
|
||||
.stageCount = static_cast<u32>(stages.size()),
|
||||
.pStages = stages.data(),
|
||||
@@ -1542,7 +1688,7 @@ void BlitImageHelper::ConvertPipeline(vk::Pipeline& pipeline, VkRenderPass rende
|
||||
.subpass = 0,
|
||||
.basePipelineHandle = VK_NULL_HANDLE,
|
||||
.basePipelineIndex = 0,
|
||||
});
|
||||
}, device.StaticPipelineCache());
|
||||
}
|
||||
|
||||
} // namespace Vulkan
|
||||
|
||||
@@ -33,6 +33,8 @@ struct BlitImagePipelineKey {
|
||||
|
||||
VkRenderPass renderpass;
|
||||
Tegra::Engines::Fermi2D::Operation operation;
|
||||
std::array<VkFormat, VideoCommon::NUM_RT> color_formats;
|
||||
VkFormat depth_format;
|
||||
};
|
||||
|
||||
struct BlitDepthStencilPipelineKey {
|
||||
@@ -43,6 +45,8 @@ struct BlitDepthStencilPipelineKey {
|
||||
u8 stencil_mask;
|
||||
u32 stencil_compare_mask;
|
||||
u32 stencil_ref;
|
||||
std::array<VkFormat, VideoCommon::NUM_RT> color_formats;
|
||||
VkFormat depth_format;
|
||||
};
|
||||
|
||||
struct MSAACopyPipelineKey {
|
||||
@@ -51,6 +55,7 @@ struct MSAACopyPipelineKey {
|
||||
VkRenderPass renderpass;
|
||||
VkSampleCountFlagBits samples;
|
||||
bool msaa_to_non_msaa;
|
||||
bool is_depth;
|
||||
};
|
||||
|
||||
struct BlitMSAAPipelineKey {
|
||||
@@ -58,6 +63,15 @@ struct BlitMSAAPipelineKey {
|
||||
|
||||
VkRenderPass renderpass;
|
||||
VkSampleCountFlagBits samples;
|
||||
std::array<VkFormat, VideoCommon::NUM_RT> color_formats;
|
||||
VkFormat depth_format;
|
||||
};
|
||||
|
||||
struct ResolveDepthStencilPipelineKey {
|
||||
constexpr auto operator<=>(const ResolveDepthStencilPipelineKey&) const noexcept = default;
|
||||
|
||||
VkRenderPass renderpass;
|
||||
VkFormat depth_format;
|
||||
};
|
||||
|
||||
class BlitImageHelper {
|
||||
@@ -123,31 +137,36 @@ private:
|
||||
void ConvertDepthStencil(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
|
||||
ImageView& src_image_view);
|
||||
|
||||
[[nodiscard]] VkPipeline FindOrEmplaceColorPipeline(const BlitImagePipelineKey& key);
|
||||
[[nodiscard]] VkPipeline FindOrEmplaceColorPipeline(const BlitImagePipelineKey& key,
|
||||
const Framebuffer* framebuffer);
|
||||
|
||||
[[nodiscard]] VkPipeline FindOrEmplaceDepthStencilPipeline(const BlitImagePipelineKey& key);
|
||||
[[nodiscard]] VkPipeline FindOrEmplaceDepthStencilPipeline(const BlitImagePipelineKey& key,
|
||||
const Framebuffer* framebuffer);
|
||||
|
||||
[[nodiscard]] VkPipeline FindOrEmplaceClearColorPipeline(const BlitImagePipelineKey& key);
|
||||
[[nodiscard]] VkPipeline FindOrEmplaceClearColorPipeline(const BlitImagePipelineKey& key,
|
||||
const Framebuffer* framebuffer);
|
||||
[[nodiscard]] VkPipeline FindOrEmplaceClearStencilPipeline(
|
||||
const BlitDepthStencilPipelineKey& key);
|
||||
const BlitDepthStencilPipelineKey& key, const Framebuffer* framebuffer);
|
||||
[[nodiscard]] VkPipeline FindOrEmplaceMSAACopyPipeline(const MSAACopyPipelineKey& key);
|
||||
[[nodiscard]] VkPipeline FindOrEmplaceBlitColorMSAAPipeline(const BlitMSAAPipelineKey& key);
|
||||
[[nodiscard]] VkPipeline FindOrEmplaceResolveDepthStencilPipeline(VkRenderPass renderpass,
|
||||
[[nodiscard]] VkPipeline FindOrEmplaceBlitColorMSAAPipeline(const BlitMSAAPipelineKey& key,
|
||||
const Framebuffer* framebuffer);
|
||||
[[nodiscard]] VkPipeline FindOrEmplaceResolveDepthStencilPipeline(const Framebuffer* framebuffer,
|
||||
bool resolve_stencil);
|
||||
|
||||
void ConvertPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass, bool is_target_depth);
|
||||
void ConvertPipeline(vk::Pipeline& pipeline, const Framebuffer* framebuffer,
|
||||
bool is_target_depth);
|
||||
|
||||
void ConvertDepthToColorPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass);
|
||||
void ConvertDepthToColorPipeline(vk::Pipeline& pipeline, const Framebuffer* framebuffer);
|
||||
|
||||
void ConvertColorToDepthPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass);
|
||||
void ConvertColorToDepthPipeline(vk::Pipeline& pipeline, const Framebuffer* framebuffer);
|
||||
|
||||
void ConvertPipelineEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
|
||||
void ConvertPipelineEx(vk::Pipeline& pipeline, const Framebuffer* framebuffer,
|
||||
vk::ShaderModule& module, bool single_texture, bool is_target_depth);
|
||||
|
||||
void ConvertPipelineColorTargetEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
|
||||
void ConvertPipelineColorTargetEx(vk::Pipeline& pipeline, const Framebuffer* framebuffer,
|
||||
vk::ShaderModule& module);
|
||||
|
||||
void ConvertPipelineDepthTargetEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
|
||||
void ConvertPipelineDepthTargetEx(vk::Pipeline& pipeline, const Framebuffer* framebuffer,
|
||||
vk::ShaderModule& module);
|
||||
|
||||
const Device& device;
|
||||
@@ -180,6 +199,7 @@ private:
|
||||
vk::ShaderModule convert_s8d24_to_abgr8_frag;
|
||||
vk::ShaderModule convert_msaa_to_non_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 nearest_sampler;
|
||||
|
||||
@@ -195,9 +215,9 @@ private:
|
||||
std::vector<vk::Pipeline> msaa_copy_pipelines;
|
||||
std::vector<BlitMSAAPipelineKey> blit_msaa_color_keys;
|
||||
std::vector<vk::Pipeline> blit_msaa_color_pipelines;
|
||||
std::vector<VkRenderPass> resolve_depth_keys;
|
||||
std::vector<ResolveDepthStencilPipelineKey> resolve_depth_keys;
|
||||
std::vector<vk::Pipeline> resolve_depth_pipelines;
|
||||
std::vector<VkRenderPass> resolve_depth_stencil_keys;
|
||||
std::vector<ResolveDepthStencilPipelineKey> resolve_depth_stencil_keys;
|
||||
std::vector<vk::Pipeline> resolve_depth_stencil_pipelines;
|
||||
struct MSAACopyResources {
|
||||
u64 tick;
|
||||
|
||||
@@ -164,7 +164,9 @@ void FixedPipelineState::Refresh(Tegra::Engines::Maxwell3D& maxwell3d, DynamicFe
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
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,
|
||||
const DynamicFeatures& features) {
|
||||
if (!features.has_dynamic_state3_logic_op_enable) {
|
||||
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) {
|
||||
depth_clamp_disabled.Assign(regs.viewport_clip_control.geometry_clip ==
|
||||
Maxwell::ViewportClipControl::GeometryClip::Passthrough ||
|
||||
regs.viewport_clip_control.geometry_clip ==
|
||||
Maxwell::ViewportClipControl::GeometryClip::FrustumXYZ ||
|
||||
regs.viewport_clip_control.geometry_clip ==
|
||||
Maxwell::ViewportClipControl::GeometryClip::FrustumZ);
|
||||
depth_clamp_disabled.Assign(
|
||||
IsDepthClampEnabled(regs, features.has_depth_clip_enable) ? 0 : 1);
|
||||
}
|
||||
if (!features.has_dynamic_state3_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_enables;
|
||||
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_line_stipple_enable;
|
||||
bool has_dynamic_vertex_input;
|
||||
@@ -165,6 +167,7 @@ struct FixedPipelineState {
|
||||
BitField<10, 1, u32> logic_op_enable;
|
||||
BitField<11, 1, u32> depth_clamp_disabled;
|
||||
BitField<12, 1, u32> line_stipple_enable;
|
||||
BitField<13, 1, u32> depth_clip_disabled;
|
||||
};
|
||||
union {
|
||||
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_constructible_v<FixedPipelineState>);
|
||||
|
||||
bool IsDepthClipEnabled(const Maxwell& regs);
|
||||
bool IsDepthClampEnabled(const Maxwell& regs, bool has_depth_clip_enable);
|
||||
|
||||
} // namespace Vulkan
|
||||
|
||||
namespace std {
|
||||
|
||||
@@ -47,6 +47,93 @@ using Shader::Backend::SPIRV::NUM_TEXTURE_AND_IMAGE_SCALING_WORDS;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline VkDeviceSize DescriptorSizeForType(const Device& device,
|
||||
VkDescriptorType type) {
|
||||
const auto& props = device.DescriptorBufferProperties();
|
||||
const bool robust = device.IsRobustBufferAccessEnabled();
|
||||
switch (type) {
|
||||
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
||||
return robust ? props.robustUniformBufferDescriptorSize : props.uniformBufferDescriptorSize;
|
||||
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
||||
return robust ? props.robustStorageBufferDescriptorSize : props.storageBufferDescriptorSize;
|
||||
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
|
||||
return robust ? props.robustUniformTexelBufferDescriptorSize
|
||||
: props.uniformTexelBufferDescriptorSize;
|
||||
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
|
||||
return robust ? props.robustStorageTexelBufferDescriptorSize
|
||||
: props.storageTexelBufferDescriptorSize;
|
||||
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
||||
return props.combinedImageSamplerDescriptorSize;
|
||||
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
||||
return props.storageImageDescriptorSize;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
struct DescriptorBufferBinding {
|
||||
VkDescriptorType type;
|
||||
u32 count;
|
||||
VkDeviceSize offset;
|
||||
VkDeviceSize stride;
|
||||
};
|
||||
|
||||
struct DescriptorBufferLayout {
|
||||
VkDeviceSize size{};
|
||||
boost::container::small_vector<DescriptorBufferBinding, 32> bindings;
|
||||
|
||||
[[nodiscard]] bool Empty() const noexcept {
|
||||
return bindings.empty();
|
||||
}
|
||||
};
|
||||
|
||||
inline void WriteDescriptorBuffer(const Device& device, const DescriptorBufferLayout& layout,
|
||||
const DescriptorUpdateEntry* payload, u8* host) {
|
||||
const vk::Device& dev = device.GetLogical();
|
||||
for (const DescriptorBufferBinding& binding : layout.bindings) {
|
||||
for (u32 index = 0; index < binding.count; ++index) {
|
||||
const DescriptorUpdateEntry& entry = *(payload++);
|
||||
const VkDescriptorAddressInfoEXT address_info{
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_ADDRESS_INFO_EXT,
|
||||
.pNext = nullptr,
|
||||
.address = entry.address.address,
|
||||
.range = entry.address.range,
|
||||
.format = entry.address.format,
|
||||
};
|
||||
VkDescriptorGetInfoEXT get_info{
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_GET_INFO_EXT,
|
||||
.pNext = nullptr,
|
||||
.type = binding.type,
|
||||
.data{},
|
||||
};
|
||||
switch (binding.type) {
|
||||
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
||||
get_info.data.pUniformBuffer = &address_info;
|
||||
break;
|
||||
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
||||
get_info.data.pStorageBuffer = &address_info;
|
||||
break;
|
||||
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
|
||||
get_info.data.pUniformTexelBuffer = &address_info;
|
||||
break;
|
||||
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
|
||||
get_info.data.pStorageTexelBuffer = &address_info;
|
||||
break;
|
||||
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
||||
get_info.data.pCombinedImageSampler = &entry.image;
|
||||
break;
|
||||
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
||||
get_info.data.pStorageImage = &entry.image;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
dev.GetDescriptorEXT(get_info, binding.stride,
|
||||
host + binding.offset + index * binding.stride);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] inline u32 NumDescriptorEntries(const Shader::Info& info) {
|
||||
return Shader::NumDescriptors(info.constant_buffer_descriptors) +
|
||||
Shader::NumDescriptors(info.storage_buffers_descriptors) +
|
||||
@@ -65,16 +152,59 @@ public:
|
||||
num_descriptors <= device->MaxPushDescriptors();
|
||||
}
|
||||
|
||||
// TODO(crueter): utilize layout binding flags
|
||||
vk::DescriptorSetLayout CreateDescriptorSetLayout(bool use_push_descriptor) const {
|
||||
bool CanUseDescriptorBuffer() const noexcept {
|
||||
return device->IsExtDescriptorBufferSupported() && !bindings.empty() &&
|
||||
!CanUsePushDescriptor() &&
|
||||
device->DescriptorBufferProperties().combinedImageSamplerDescriptorSingleArray;
|
||||
}
|
||||
|
||||
DescriptorBufferLayout MakeDescriptorBufferLayout(VkDescriptorSetLayout layout) const {
|
||||
DescriptorBufferLayout result;
|
||||
if (!layout) {
|
||||
return result;
|
||||
}
|
||||
const vk::Device& dev = device->GetLogical();
|
||||
result.size = dev.GetDescriptorSetLayoutSizeEXT(layout);
|
||||
result.bindings.reserve(bindings.size());
|
||||
for (const VkDescriptorSetLayoutBinding& binding : bindings) {
|
||||
result.bindings.push_back(DescriptorBufferBinding{
|
||||
.type = binding.descriptorType,
|
||||
.count = binding.descriptorCount,
|
||||
.offset = dev.GetDescriptorSetLayoutBindingOffsetEXT(layout, binding.binding),
|
||||
.stride = DescriptorSizeForType(*device, binding.descriptorType),
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
vk::DescriptorSetLayout CreateDescriptorSetLayout(bool use_push_descriptor,
|
||||
bool use_descriptor_buffer = false) const {
|
||||
if (bindings.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
const VkDescriptorSetLayoutCreateFlags flags =
|
||||
use_push_descriptor ? VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR : 0;
|
||||
VkDescriptorSetLayoutCreateFlags flags = 0;
|
||||
if (use_push_descriptor) {
|
||||
flags |= VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR;
|
||||
}
|
||||
if (use_descriptor_buffer) {
|
||||
flags |= VK_DESCRIPTOR_SET_LAYOUT_CREATE_DESCRIPTOR_BUFFER_BIT_EXT;
|
||||
}
|
||||
boost::container::small_vector<VkDescriptorBindingFlags, 32> binding_flags;
|
||||
VkDescriptorSetLayoutBindingFlagsCreateInfo binding_flags_ci{};
|
||||
const void* pnext = nullptr;
|
||||
if (!use_push_descriptor && device->IsDescriptorBindingPartiallyBoundSupported()) {
|
||||
binding_flags.assign(bindings.size(), VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT);
|
||||
binding_flags_ci = {
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.bindingCount = static_cast<u32>(binding_flags.size()),
|
||||
.pBindingFlags = binding_flags.data(),
|
||||
};
|
||||
pnext = &binding_flags_ci;
|
||||
}
|
||||
return device->GetLogical().CreateDescriptorSetLayout({
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.pNext = pnext,
|
||||
.flags = flags,
|
||||
.bindingCount = static_cast<u32>(bindings.size()),
|
||||
.pBindings = bindings.data(),
|
||||
|
||||
@@ -491,7 +491,7 @@ static vk::Pipeline CreateWrappedPipelineImpl(
|
||||
.subpass = 0,
|
||||
.basePipelineHandle = 0,
|
||||
.basePipelineIndex = 0,
|
||||
});
|
||||
}, device.StaticPipelineCache());
|
||||
}
|
||||
|
||||
vk::Pipeline CreateWrappedPipeline(const Device& device, vk::RenderPass& renderpass,
|
||||
|
||||
@@ -69,6 +69,9 @@ vk::Buffer CreateBuffer(const Device& device, const MemoryAllocator& memory_allo
|
||||
if (device.IsExtConditionalRendering()) {
|
||||
flags |= VK_BUFFER_USAGE_CONDITIONAL_RENDERING_BIT_EXT;
|
||||
}
|
||||
if (device.IsBufferDeviceAddressSupported()) {
|
||||
flags |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
|
||||
}
|
||||
const VkBufferCreateInfo buffer_ci = {
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
@@ -91,6 +94,9 @@ Buffer::Buffer(BufferCacheRuntime& runtime, VideoCommon::NullBufferParams null_p
|
||||
device = &runtime.device;
|
||||
buffer = runtime.CreateNullBuffer();
|
||||
is_null = true;
|
||||
if (device->IsBufferDeviceAddressSupported()) {
|
||||
device_address = device->GetLogical().GetBufferDeviceAddress(*buffer);
|
||||
}
|
||||
}
|
||||
|
||||
Buffer::Buffer(BufferCacheRuntime& runtime, DAddr cpu_addr_, u64 size_bytes_)
|
||||
@@ -100,6 +106,9 @@ Buffer::Buffer(BufferCacheRuntime& runtime, DAddr cpu_addr_, u64 size_bytes_)
|
||||
if (runtime.device.HasDebuggingToolAttached()) {
|
||||
buffer.SetObjectNameEXT(fmt::format("Buffer 0x{:x}", CpuAddr()).c_str());
|
||||
}
|
||||
if (device->IsBufferDeviceAddressSupported()) {
|
||||
device_address = device->GetLogical().GetBufferDeviceAddress(*buffer);
|
||||
}
|
||||
}
|
||||
|
||||
void Buffer::MarkUsage(u64 offset, u64 size) noexcept {
|
||||
@@ -246,7 +255,6 @@ protected:
|
||||
StagingBufferPool& staging_pool;
|
||||
|
||||
vk::Buffer buffer{};
|
||||
MemoryCommit memory_commit{};
|
||||
VkIndexType index_type{};
|
||||
u32 num_indices = 0;
|
||||
};
|
||||
@@ -356,6 +364,16 @@ BufferCacheRuntime::BufferCacheRuntime(const Device& device_, MemoryAllocator& m
|
||||
scheduler_, staging_pool_);
|
||||
}
|
||||
|
||||
void BufferCacheRuntime::TryEnableUnifiedMemory(void* base, size_t size,
|
||||
std::span<AHardwareBuffer* const> hardware_buffers,
|
||||
size_t hardware_buffer_window) {
|
||||
unified_memory = std::make_unique<HostMemoryImport>(device, base, size, hardware_buffers,
|
||||
hardware_buffer_window);
|
||||
if (!unified_memory->IsValid()) {
|
||||
unified_memory.reset();
|
||||
}
|
||||
}
|
||||
|
||||
StagingBufferRef BufferCacheRuntime::UploadStagingBuffer(size_t size) {
|
||||
return staging_pool.Request(size, MemoryUsage::Upload);
|
||||
}
|
||||
@@ -364,6 +382,10 @@ StagingBufferRef BufferCacheRuntime::DownloadStagingBuffer(size_t size, bool def
|
||||
return staging_pool.Request(size, MemoryUsage::Download, deferred);
|
||||
}
|
||||
|
||||
VkFormat BufferCacheRuntime::TexelBufferFormat(VideoCore::Surface::PixelFormat format) const {
|
||||
return MaxwellToVK::SurfaceFormat(device, FormatType::Buffer, false, format).format;
|
||||
}
|
||||
|
||||
void BufferCacheRuntime::FreeDeferredStagingBuffer(StagingBufferRef& ref) {
|
||||
staging_pool.FreeDeferred(ref);
|
||||
}
|
||||
@@ -376,6 +398,10 @@ u64 BufferCacheRuntime::GetDeviceMemoryUsage() const {
|
||||
return device.GetDeviceMemoryUsage();
|
||||
}
|
||||
|
||||
u64 BufferCacheRuntime::GetDeviceAllocationUsage() const {
|
||||
return device.GetMemoryBudgetInfo().allocation_bytes;
|
||||
}
|
||||
|
||||
bool BufferCacheRuntime::CanReportMemoryUsage() const {
|
||||
return device.CanReportMemoryUsage();
|
||||
}
|
||||
@@ -404,6 +430,16 @@ u64 BufferCacheRuntime::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) {
|
||||
scheduler.Wait(buffer_tick);
|
||||
}
|
||||
@@ -641,6 +677,7 @@ void BufferCacheRuntime::BindTransformFeedbackBuffer(u32 index, VkBuffer buffer,
|
||||
offset = 0;
|
||||
size = 0;
|
||||
}
|
||||
scheduler.MarkTransformFeedbackUsed();
|
||||
scheduler.Record([index, buffer, offset, size](vk::CommandBuffer cmdbuf) {
|
||||
const VkDeviceSize vk_offset = offset;
|
||||
const VkDeviceSize vk_size = size;
|
||||
@@ -653,19 +690,26 @@ void BufferCacheRuntime::BindTransformFeedbackBuffers(VideoCommon::HostBindings<
|
||||
// Already logged in the rasterizer
|
||||
return;
|
||||
}
|
||||
boost::container::static_vector<VkBuffer, VideoCommon::NUM_VERTEX_BUFFERS> buffer_handles(bindings.buffers.size());
|
||||
for (u32 i = 0; i < bindings.buffers.size(); ++i) {
|
||||
const u32 count = std::min<u32>(static_cast<u32>(bindings.buffers.size()),
|
||||
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();
|
||||
if (handle == VK_NULL_HANDLE) {
|
||||
ReserveNullBuffer();
|
||||
handle = *null_buffer;
|
||||
bindings.offsets[i] = 0;
|
||||
bindings.sizes[i] = 0;
|
||||
} else {
|
||||
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) {
|
||||
cmdbuf.BindTransformFeedbackBuffersEXT(0, u32(buffer_handles_.size()), buffer_handles_.data(), bindings_.offsets.data(), bindings_.sizes.data());
|
||||
scheduler.MarkTransformFeedbackUsed();
|
||||
scheduler.Record([count, handles, offsets, sizes](vk::CommandBuffer cmdbuf) {
|
||||
cmdbuf.BindTransformFeedbackBuffersEXT(0, count, handles.data(), offsets.data(),
|
||||
sizes.data());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -690,6 +734,9 @@ vk::Buffer BufferCacheRuntime::CreateNullBuffer() {
|
||||
if (device.IsExtTransformFeedbackSupported()) {
|
||||
create_info.usage |= VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_BUFFER_BIT_EXT;
|
||||
}
|
||||
if (device.IsBufferDeviceAddressSupported()) {
|
||||
create_info.usage |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
|
||||
}
|
||||
vk::Buffer ret = memory_allocator.CreateBuffer(create_info, MemoryUsage::DeviceLocal);
|
||||
if (device.HasDebuggingToolAttached()) {
|
||||
ret.SetObjectNameEXT("Null buffer");
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
|
||||
#include "video_core/buffer_cache/buffer_cache_base.h"
|
||||
#include "video_core/buffer_cache/memory_tracker_base.h"
|
||||
@@ -39,6 +41,10 @@ public:
|
||||
return *buffer;
|
||||
}
|
||||
|
||||
[[nodiscard]] VkDeviceAddress DeviceAddress() const noexcept {
|
||||
return device_address;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsRegionUsed(u64 offset, u64 size) const noexcept {
|
||||
return tracker.IsUsed(offset, size);
|
||||
}
|
||||
@@ -70,6 +76,7 @@ private:
|
||||
vk::Buffer buffer;
|
||||
std::vector<BufferView> views;
|
||||
VideoCommon::UsageTracker tracker;
|
||||
VkDeviceAddress device_address{};
|
||||
u64 last_usage_tick{};
|
||||
bool is_null{};
|
||||
};
|
||||
@@ -92,6 +99,26 @@ public:
|
||||
|
||||
void TickFrame(Common::SlotVector<Buffer>& slot_buffers) noexcept;
|
||||
|
||||
void TryEnableUnifiedMemory(void* base, size_t size,
|
||||
std::span<AHardwareBuffer* const> hardware_buffers,
|
||||
size_t hardware_buffer_window);
|
||||
|
||||
[[nodiscard]] bool HasUnifiedMemory() const noexcept {
|
||||
return unified_memory != nullptr && unified_memory->IsValid();
|
||||
}
|
||||
|
||||
[[nodiscard]] u64 UnifiedMemorySize() const noexcept {
|
||||
return unified_memory ? unified_memory->GetSize() : 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] u64 UnifiedMemoryWindowSize() const noexcept {
|
||||
return unified_memory ? unified_memory->GetWindowSize() : 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] VkBuffer UnifiedMemoryWindowBuffer(size_t index) const noexcept {
|
||||
return unified_memory ? unified_memory->GetWindowBuffer(index) : VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
u64 CurrentTick();
|
||||
|
||||
u64 KnownGpuTick();
|
||||
@@ -100,10 +127,16 @@ public:
|
||||
|
||||
void Finish();
|
||||
|
||||
u64 CurrentSyncPoint() const noexcept;
|
||||
|
||||
u64 CompletedSyncPoint() const;
|
||||
|
||||
u64 GetDeviceLocalMemory() const;
|
||||
|
||||
u64 GetDeviceMemoryUsage() const;
|
||||
|
||||
u64 GetDeviceAllocationUsage() const;
|
||||
|
||||
bool CanReportMemoryUsage() const;
|
||||
|
||||
u32 GetUniformBufferAlignment() const;
|
||||
@@ -145,22 +178,25 @@ public:
|
||||
[[maybe_unused]] u32 binding_index,
|
||||
u32 size) {
|
||||
const StagingBufferRef ref = staging_pool.Request(size, MemoryUsage::Upload);
|
||||
BindBuffer(ref.buffer, static_cast<u32>(ref.offset), size);
|
||||
guest_descriptor_queue.AddBuffer(ref.buffer, ref.device_address,
|
||||
static_cast<u32>(ref.offset), size);
|
||||
return ref.mapped_span;
|
||||
}
|
||||
|
||||
void BindUniformBuffer(VkBuffer buffer, u32 offset, u32 size) {
|
||||
void BindUniformBuffer(const Buffer& buffer, u32 offset, u32 size) {
|
||||
BindBuffer(buffer, offset, size);
|
||||
}
|
||||
|
||||
void BindStorageBuffer(VkBuffer buffer, u32 offset, u32 size,
|
||||
void BindStorageBuffer(const Buffer& buffer, u32 offset, u32 size,
|
||||
[[maybe_unused]] bool is_written) {
|
||||
BindBuffer(buffer, offset, size);
|
||||
}
|
||||
|
||||
void BindTextureBuffer(Buffer& buffer, u32 offset, u32 size,
|
||||
VideoCore::Surface::PixelFormat format) {
|
||||
guest_descriptor_queue.AddTexelBuffer(buffer.View(offset, size, format));
|
||||
guest_descriptor_queue.AddTexelBuffer(buffer.View(offset, size, format),
|
||||
buffer.DeviceAddress(), offset, size,
|
||||
TexelBufferFormat(format));
|
||||
}
|
||||
|
||||
bool ShouldLimitDynamicStorageBuffers() const {
|
||||
@@ -172,14 +208,17 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void BindBuffer(VkBuffer buffer, u32 offset, u32 size) {
|
||||
if (buffer == VK_NULL_HANDLE) {
|
||||
guest_descriptor_queue.AddBuffer(buffer, 0, VK_WHOLE_SIZE);
|
||||
void BindBuffer(const Buffer& buffer, u32 offset, u32 size) {
|
||||
const VkBuffer handle = buffer.Handle();
|
||||
if (handle == VK_NULL_HANDLE) {
|
||||
guest_descriptor_queue.AddBuffer(handle, 0, 0, VK_WHOLE_SIZE);
|
||||
} else {
|
||||
guest_descriptor_queue.AddBuffer(buffer, offset, size);
|
||||
guest_descriptor_queue.AddBuffer(handle, buffer.DeviceAddress(), offset, size);
|
||||
}
|
||||
}
|
||||
|
||||
VkFormat TexelBufferFormat(VideoCore::Surface::PixelFormat format) const;
|
||||
|
||||
void ReserveNullBuffer();
|
||||
vk::Buffer CreateNullBuffer();
|
||||
|
||||
@@ -193,6 +232,7 @@ private:
|
||||
std::shared_ptr<QuadStripIndexBuffer> quad_strip_index_buffer;
|
||||
|
||||
vk::Buffer null_buffer;
|
||||
std::unique_ptr<HostMemoryImport> unified_memory;
|
||||
|
||||
std::unique_ptr<Uint8Pass> uint8_pass;
|
||||
QuadIndexedPass quad_index_pass;
|
||||
@@ -215,6 +255,7 @@ struct BufferCacheParams {
|
||||
static constexpr bool USE_MEMORY_MAPS = true;
|
||||
static constexpr bool SEPARATE_IMAGE_BUFFER_BINDINGS = false;
|
||||
static constexpr bool USE_MEMORY_MAPS_FOR_UPLOADS = true;
|
||||
static constexpr bool USE_UNIFIED_MEMORY = true;
|
||||
};
|
||||
|
||||
using BufferCache = VideoCommon::BufferCache<BufferCacheParams>;
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 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
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "video_core/renderer_vulkan/vk_command_pool.h"
|
||||
#include "video_core/renderer_vulkan/vk_master_semaphore.h"
|
||||
#include "video_core/vulkan_common/vulkan_device.h"
|
||||
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
||||
|
||||
@@ -14,32 +18,52 @@ constexpr size_t COMMAND_BUFFER_POOL_SIZE = 4;
|
||||
struct CommandPool::Pool {
|
||||
vk::CommandPool handle;
|
||||
vk::CommandBuffers cmdbufs;
|
||||
u64 tick;
|
||||
};
|
||||
|
||||
CommandPool::CommandPool(MasterSemaphore& master_semaphore_, const Device& device_)
|
||||
: ResourcePool(master_semaphore_, COMMAND_BUFFER_POOL_SIZE), device{device_} {}
|
||||
: master_semaphore{master_semaphore_}, device{device_} {}
|
||||
|
||||
CommandPool::~CommandPool() = default;
|
||||
|
||||
void CommandPool::Allocate(size_t begin, size_t end) {
|
||||
// Command buffers are going to be committed, recorded, executed every single usage cycle.
|
||||
// They are also going to be reset when committed.
|
||||
void CommandPool::AllocatePool() {
|
||||
Pool& pool = pools.emplace_back();
|
||||
pool.handle = device.GetLogical().CreateCommandPool({
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.flags =
|
||||
VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
|
||||
.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT,
|
||||
.queueFamilyIndex = device.GetGraphicsFamily(),
|
||||
});
|
||||
pool.cmdbufs = pool.handle.Allocate(COMMAND_BUFFER_POOL_SIZE);
|
||||
pool.tick = 0;
|
||||
}
|
||||
|
||||
void CommandPool::AcquirePool() {
|
||||
if (!pools.empty()) {
|
||||
master_semaphore.Refresh();
|
||||
const u64 gpu_tick = master_semaphore.KnownGpuTick();
|
||||
for (size_t i = 0; i < pools.size(); ++i) {
|
||||
const size_t candidate = (current_pool + 1 + i) % pools.size();
|
||||
if (gpu_tick >= pools[candidate].tick) {
|
||||
current_pool = candidate;
|
||||
current_index = 0;
|
||||
pools[current_pool].handle.Reset();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
AllocatePool();
|
||||
current_pool = pools.size() - 1;
|
||||
current_index = 0;
|
||||
}
|
||||
|
||||
VkCommandBuffer CommandPool::Commit() {
|
||||
const size_t index = CommitResource();
|
||||
const auto pool_index = index / COMMAND_BUFFER_POOL_SIZE;
|
||||
const auto sub_index = index % COMMAND_BUFFER_POOL_SIZE;
|
||||
return pools[pool_index].cmdbufs[sub_index];
|
||||
if (pools.empty() || current_index >= COMMAND_BUFFER_POOL_SIZE) {
|
||||
AcquirePool();
|
||||
}
|
||||
Pool& pool = pools[current_pool];
|
||||
pool.tick = master_semaphore.CurrentTick();
|
||||
return pool.cmdbufs[current_index++];
|
||||
}
|
||||
|
||||
} // namespace Vulkan
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 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
|
||||
|
||||
@@ -6,7 +9,7 @@
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
#include "video_core/renderer_vulkan/vk_resource_pool.h"
|
||||
#include "common/common_types.h"
|
||||
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
||||
|
||||
namespace Vulkan {
|
||||
@@ -14,20 +17,24 @@ namespace Vulkan {
|
||||
class Device;
|
||||
class MasterSemaphore;
|
||||
|
||||
class CommandPool final : public ResourcePool {
|
||||
class CommandPool final {
|
||||
public:
|
||||
explicit CommandPool(MasterSemaphore& master_semaphore_, const Device& device_);
|
||||
~CommandPool() override;
|
||||
|
||||
void Allocate(size_t begin, size_t end) override;
|
||||
~CommandPool();
|
||||
|
||||
VkCommandBuffer Commit();
|
||||
|
||||
private:
|
||||
struct Pool;
|
||||
|
||||
void AllocatePool();
|
||||
void AcquirePool();
|
||||
|
||||
MasterSemaphore& master_semaphore;
|
||||
const Device& device;
|
||||
std::vector<Pool> pools;
|
||||
size_t current_pool = 0;
|
||||
size_t current_index = 0;
|
||||
};
|
||||
|
||||
} // namespace Vulkan
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <numeric>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "video_core/renderer_vulkan/vk_texture_cache.h"
|
||||
|
||||
@@ -22,7 +24,9 @@
|
||||
#include "video_core/host_shaders/resolve_conditional_render_comp_spv.h"
|
||||
#include "video_core/host_shaders/vulkan_quad_indexed_comp_spv.h"
|
||||
#include "video_core/host_shaders/vulkan_uint8_comp_spv.h"
|
||||
#include "video_core/host_shaders/block_linear_unswizzle_2d_buffer_comp_spv.h"
|
||||
#include "video_core/host_shaders/block_linear_unswizzle_3d_bcn_comp_spv.h"
|
||||
#include "video_core/host_shaders/block_linear_unswizzle_3d_buffer_comp_spv.h"
|
||||
#include "video_core/renderer_vulkan/vk_compute_pass.h"
|
||||
#include "video_core/surface.h"
|
||||
#include "video_core/renderer_vulkan/vk_descriptor_pool.h"
|
||||
@@ -31,6 +35,7 @@
|
||||
#include "video_core/renderer_vulkan/vk_update_descriptor.h"
|
||||
#include "video_core/texture_cache/accelerated_swizzle.h"
|
||||
#include "video_core/texture_cache/types.h"
|
||||
#include "video_core/texture_cache/util.h"
|
||||
#include "video_core/textures/decoders.h"
|
||||
#include "video_core/vulkan_common/vulkan_device.h"
|
||||
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
||||
@@ -268,7 +273,7 @@ ComputePass::ComputePass(const Device& device_, Scheduler& scheduler, Descriptor
|
||||
.layout = *layout,
|
||||
.basePipelineHandle = {},
|
||||
.basePipelineIndex = 0,
|
||||
});
|
||||
}, device.StaticPipelineCache());
|
||||
}
|
||||
|
||||
ComputePass::~ComputePass() = default;
|
||||
@@ -570,7 +575,7 @@ void ASTCDecoderPass::Assemble(Image& image, const StagingBufferRef& map,
|
||||
const void* const descriptor_data{compute_pass_descriptor_queue.UpdateData()};
|
||||
|
||||
// To unswizzle the ASTC data
|
||||
const auto params = MakeBlockLinearSwizzle2DParams(swizzle, image.info);
|
||||
const auto params = VideoCommon::Accelerated::MakeBlockLinearSwizzle2DParams(swizzle, image.info);
|
||||
ASSERT(params.origin == (std::array<u32, 3>{0, 0, 0}));
|
||||
ASSERT(params.destination == (std::array<s32, 3>{0, 0, 0}));
|
||||
ASSERT(params.bytes_per_block_log2 == 4);
|
||||
@@ -713,7 +718,7 @@ void BlockLinearUnswizzle3DPass::Unswizzle(
|
||||
|
||||
ASSERT(swizzles.size() == 1);
|
||||
const auto& sw = swizzles[0];
|
||||
const auto params = MakeBlockLinearSwizzle3DParams(sw, image.info);
|
||||
const auto params = VideoCommon::Accelerated::MakeBlockLinearSwizzle3DParams(sw, image.info);
|
||||
|
||||
const u32 blocks_x = (image.info.size.width + 3) / 4;
|
||||
const u32 blocks_y = (image.info.size.height + 3) / 4;
|
||||
@@ -872,4 +877,626 @@ void BlockLinearUnswizzle3DPass::UnswizzleChunk(
|
||||
});
|
||||
}
|
||||
|
||||
namespace {
|
||||
constexpr u32 BL2D_BINDING_INPUT_BUFFER = 0;
|
||||
constexpr u32 BL2D_BINDING_OUTPUT_BUFFER = 1;
|
||||
|
||||
struct alignas(16) BlockLinearUnswizzle2DPushConstants {
|
||||
std::array<u32, 3> dim;
|
||||
u32 bytes_per_block_log2;
|
||||
std::array<u32, 3> origin;
|
||||
u32 layer_stride;
|
||||
u32 block_size;
|
||||
u32 x_shift;
|
||||
u32 block_height;
|
||||
u32 block_height_mask;
|
||||
};
|
||||
static_assert(sizeof(BlockLinearUnswizzle2DPushConstants) <= 128);
|
||||
|
||||
constexpr std::array<VkDescriptorSetLayoutBinding, 2> BL2D_BINDINGS{{
|
||||
{
|
||||
.binding = BL2D_BINDING_INPUT_BUFFER,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
.pImmutableSamplers = nullptr,
|
||||
},
|
||||
{
|
||||
.binding = BL2D_BINDING_OUTPUT_BUFFER,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
.pImmutableSamplers = nullptr,
|
||||
},
|
||||
}};
|
||||
|
||||
constexpr std::array<VkDescriptorUpdateTemplateEntry, 2> BL2D_TEMPLATE{{
|
||||
{
|
||||
.dstBinding = BL2D_BINDING_INPUT_BUFFER,
|
||||
.dstArrayElement = 0,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.offset = BL2D_BINDING_INPUT_BUFFER * sizeof(DescriptorUpdateEntry),
|
||||
.stride = sizeof(DescriptorUpdateEntry),
|
||||
},
|
||||
{
|
||||
.dstBinding = BL2D_BINDING_OUTPUT_BUFFER,
|
||||
.dstArrayElement = 0,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.offset = BL2D_BINDING_OUTPUT_BUFFER * sizeof(DescriptorUpdateEntry),
|
||||
.stride = sizeof(DescriptorUpdateEntry),
|
||||
},
|
||||
}};
|
||||
|
||||
constexpr DescriptorBankInfo BL2D_BANK_INFO{
|
||||
.uniform_buffers = 0,
|
||||
.storage_buffers = 2,
|
||||
.texture_buffers = 0,
|
||||
.image_buffers = 0,
|
||||
.textures = 0,
|
||||
.images = 0,
|
||||
.score = 2,
|
||||
};
|
||||
|
||||
constexpr bool BL2D_VERIFY_AGAINST_CPU = false;
|
||||
} // Anonymous namespace
|
||||
|
||||
BlockLinearUnswizzle2DPass::BlockLinearUnswizzle2DPass(
|
||||
const Device& device_, Scheduler& scheduler_, DescriptorPool& descriptor_pool_,
|
||||
StagingBufferPool& staging_buffer_pool_,
|
||||
ComputePassDescriptorQueue& compute_pass_descriptor_queue_)
|
||||
: ComputePass(device_, scheduler_, descriptor_pool_, BL2D_BINDINGS, BL2D_TEMPLATE,
|
||||
BL2D_BANK_INFO,
|
||||
COMPUTE_PUSH_CONSTANT_RANGE<sizeof(BlockLinearUnswizzle2DPushConstants)>,
|
||||
BLOCK_LINEAR_UNSWIZZLE_2D_BUFFER_COMP_SPV),
|
||||
scheduler{scheduler_}, staging_buffer_pool{staging_buffer_pool_},
|
||||
compute_pass_descriptor_queue{compute_pass_descriptor_queue_} {}
|
||||
|
||||
BlockLinearUnswizzle2DPass::~BlockLinearUnswizzle2DPass() = default;
|
||||
|
||||
bool BlockLinearUnswizzle2DPass::IsSupported(const VideoCommon::ImageInfo& info) {
|
||||
if (info.type != VideoCommon::ImageType::e2D) {
|
||||
return false;
|
||||
}
|
||||
if (info.resources.levels != 1) {
|
||||
return false;
|
||||
}
|
||||
if (info.num_samples > 1) {
|
||||
return false;
|
||||
}
|
||||
if (VideoCore::Surface::IsPixelFormatASTC(info.format) ||
|
||||
VideoCore::Surface::IsPixelFormatBCn(info.format)) {
|
||||
return false;
|
||||
}
|
||||
const u32 bytes_per_block = VideoCore::Surface::BytesPerBlock(info.format);
|
||||
if (bytes_per_block != 4 && bytes_per_block != 8 && bytes_per_block != 16) {
|
||||
return false;
|
||||
}
|
||||
return VideoCore::Surface::DefaultBlockWidth(info.format) == 1 &&
|
||||
VideoCore::Surface::DefaultBlockHeight(info.format) == 1;
|
||||
}
|
||||
|
||||
void BlockLinearUnswizzle2DPass::Unswizzle(
|
||||
Image& image, const StagingBufferRef& swizzled,
|
||||
std::span<const VideoCommon::SwizzleParameters> swizzles) {
|
||||
using namespace VideoCommon::Accelerated;
|
||||
|
||||
if (swizzles.empty()) {
|
||||
return;
|
||||
}
|
||||
const VideoCommon::SwizzleParameters& sw = swizzles.front();
|
||||
const auto params = VideoCommon::Accelerated::MakeBlockLinearSwizzle2DParams(sw, image.info);
|
||||
|
||||
const u32 width = sw.num_tiles.width;
|
||||
const u32 height = sw.num_tiles.height;
|
||||
const u32 depth = image.info.resources.layers;
|
||||
const u32 bytes_per_block = 1u << params.bytes_per_block_log2;
|
||||
const VkDeviceSize output_size =
|
||||
static_cast<VkDeviceSize>(width) * height * depth * bytes_per_block;
|
||||
|
||||
const StagingBufferRef output = staging_buffer_pool.Request(
|
||||
static_cast<size_t>(output_size), MemoryUsage::DeviceLocal);
|
||||
|
||||
BlockLinearUnswizzle2DPushConstants pc{};
|
||||
pc.dim = {width, height, depth};
|
||||
pc.bytes_per_block_log2 = params.bytes_per_block_log2;
|
||||
pc.origin = params.origin;
|
||||
pc.layer_stride = params.layer_stride;
|
||||
pc.block_size = params.block_size;
|
||||
pc.x_shift = params.x_shift;
|
||||
pc.block_height = params.block_height;
|
||||
pc.block_height_mask = params.block_height_mask;
|
||||
|
||||
scheduler.RequestOutsideRenderPassOperationContext();
|
||||
|
||||
compute_pass_descriptor_queue.Acquire(scheduler, 2);
|
||||
compute_pass_descriptor_queue.AddBuffer(swizzled.buffer,
|
||||
sw.buffer_offset + swizzled.offset,
|
||||
image.guest_size_bytes - sw.buffer_offset);
|
||||
compute_pass_descriptor_queue.AddBuffer(output.buffer, output.offset, output_size);
|
||||
|
||||
const void* descriptor_data = compute_pass_descriptor_queue.UpdateData();
|
||||
const VkDescriptorSet set = descriptor_allocator.Commit();
|
||||
|
||||
const u32 gx = Common::DivCeil(width, 16u);
|
||||
const u32 gy = Common::DivCeil(height, 8u);
|
||||
const bool is_initialized = image.ExchangeInitialization();
|
||||
|
||||
const VkBuffer out_buffer = output.buffer;
|
||||
const VkDeviceSize out_offset = output.offset;
|
||||
const VkImage dst_image = image.Handle();
|
||||
const VkImageAspectFlags aspect = image.AspectMask();
|
||||
|
||||
scheduler.Record([this, set, descriptor_data, pc, gx, gy, depth, output_size, out_buffer,
|
||||
out_offset, dst_image, aspect, width, height,
|
||||
is_initialized](vk::CommandBuffer cmdbuf) {
|
||||
if (dst_image == VK_NULL_HANDLE || out_buffer == VK_NULL_HANDLE) {
|
||||
return;
|
||||
}
|
||||
device.GetLogical().UpdateDescriptorSet(set, *descriptor_template, descriptor_data);
|
||||
cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline);
|
||||
cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_COMPUTE, *layout, 0, set, {});
|
||||
cmdbuf.PushConstants(*layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(pc), &pc);
|
||||
cmdbuf.Dispatch(gx, gy, depth);
|
||||
|
||||
const VkBufferMemoryBarrier buffer_barrier{
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
|
||||
.pNext = nullptr,
|
||||
.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.buffer = out_buffer,
|
||||
.offset = out_offset,
|
||||
.size = output_size,
|
||||
};
|
||||
const VkImageMemoryBarrier pre_copy{
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
||||
.pNext = nullptr,
|
||||
.srcAccessMask = static_cast<VkAccessFlags>(
|
||||
is_initialized ? VK_ACCESS_SHADER_READ_BIT : VK_ACCESS_NONE),
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
.oldLayout = is_initialized ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = dst_image,
|
||||
.subresourceRange{
|
||||
.aspectMask = aspect,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = VK_REMAINING_MIP_LEVELS,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = VK_REMAINING_ARRAY_LAYERS,
|
||||
},
|
||||
};
|
||||
cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
|
||||
(is_initialized ? vk::PIPELINE_STAGE_GRAPHICS_COMPUTE
|
||||
: VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT),
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, 0, {}, buffer_barrier, pre_copy);
|
||||
|
||||
const VkBufferImageCopy copy{
|
||||
.bufferOffset = out_offset,
|
||||
.bufferRowLength = 0,
|
||||
.bufferImageHeight = 0,
|
||||
.imageSubresource{
|
||||
.aspectMask = aspect,
|
||||
.mipLevel = 0,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = depth,
|
||||
},
|
||||
.imageOffset = {0, 0, 0},
|
||||
.imageExtent = {width, height, 1},
|
||||
};
|
||||
cmdbuf.CopyBufferToImage(out_buffer, dst_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, copy);
|
||||
|
||||
const VkImageMemoryBarrier post_copy{
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
||||
.pNext = nullptr,
|
||||
.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
.dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
|
||||
.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = dst_image,
|
||||
.subresourceRange{
|
||||
.aspectMask = aspect,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = VK_REMAINING_MIP_LEVELS,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = VK_REMAINING_ARRAY_LAYERS,
|
||||
},
|
||||
};
|
||||
cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
vk::PIPELINE_STAGE_GRAPHICS_COMPUTE, 0, {}, {}, post_copy);
|
||||
});
|
||||
|
||||
if constexpr (BL2D_VERIFY_AGAINST_CPU) {
|
||||
VerifyAgainstCpu(swizzled, sw, output, output_size, width, height, depth,
|
||||
bytes_per_block);
|
||||
}
|
||||
}
|
||||
|
||||
void BlockLinearUnswizzle2DPass::VerifyAgainstCpu(const StagingBufferRef& swizzled,
|
||||
const VideoCommon::SwizzleParameters& sw,
|
||||
const StagingBufferRef& gpu_output,
|
||||
VkDeviceSize output_size, u32 width, u32 height,
|
||||
u32 depth, u32 bytes_per_block) {
|
||||
const StagingBufferRef readback =
|
||||
staging_buffer_pool.Request(static_cast<size_t>(output_size), MemoryUsage::Download);
|
||||
|
||||
const VkBuffer src = gpu_output.buffer;
|
||||
const VkDeviceSize src_offset = gpu_output.offset;
|
||||
const VkBuffer dst = readback.buffer;
|
||||
const VkDeviceSize dst_offset = readback.offset;
|
||||
scheduler.Record([src, src_offset, dst, dst_offset, output_size](vk::CommandBuffer cmdbuf) {
|
||||
const VkBufferMemoryBarrier barrier{
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
|
||||
.pNext = nullptr,
|
||||
.srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.buffer = src,
|
||||
.offset = src_offset,
|
||||
.size = output_size,
|
||||
};
|
||||
cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0, {}, barrier, {});
|
||||
const VkBufferCopy copy{
|
||||
.srcOffset = src_offset,
|
||||
.dstOffset = dst_offset,
|
||||
.size = output_size,
|
||||
};
|
||||
cmdbuf.CopyBuffer(src, dst, copy);
|
||||
});
|
||||
scheduler.Finish();
|
||||
|
||||
const size_t size = static_cast<size_t>(output_size);
|
||||
std::vector<u8> reference(size);
|
||||
const std::span<const u8> input{swizzled.mapped_span.data() + sw.buffer_offset,
|
||||
swizzled.mapped_span.size() - sw.buffer_offset};
|
||||
Tegra::Texture::UnswizzleTexture(reference, input, bytes_per_block, width, height, depth,
|
||||
sw.block.height, sw.block.depth);
|
||||
|
||||
const u8* gpu_data = readback.mapped_span.data();
|
||||
if (std::memcmp(reference.data(), gpu_data, size) == 0) {
|
||||
LOG_INFO(Render_Vulkan, "BL2D verify OK: {}x{}x{} bpb={} ({} bytes)", width, height, depth,
|
||||
bytes_per_block, size);
|
||||
return;
|
||||
}
|
||||
size_t first_diff = size;
|
||||
size_t num_diff = 0;
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
if (reference[i] != gpu_data[i]) {
|
||||
if (first_diff == size) {
|
||||
first_diff = i;
|
||||
}
|
||||
++num_diff;
|
||||
}
|
||||
}
|
||||
LOG_CRITICAL(Render_Vulkan,
|
||||
"BL2D verify FAILED: {}x{}x{} bpb={} block_height={} first_diff={} "
|
||||
"num_diff={}/{} cpu=0x{:02x} gpu=0x{:02x}",
|
||||
width, height, depth, bytes_per_block, sw.block.height, first_diff,
|
||||
num_diff, size, reference[first_diff], gpu_data[first_diff]);
|
||||
}
|
||||
|
||||
namespace {
|
||||
constexpr u32 BL3DB_BINDING_INPUT_BUFFER = 0;
|
||||
constexpr u32 BL3DB_BINDING_OUTPUT_BUFFER = 1;
|
||||
|
||||
struct alignas(16) BlockLinearUnswizzle3DBufferPushConstants {
|
||||
std::array<u32, 3> dim;
|
||||
u32 bytes_per_block_log2;
|
||||
std::array<u32, 3> origin;
|
||||
u32 slice_size;
|
||||
u32 block_size;
|
||||
u32 x_shift;
|
||||
u32 block_height;
|
||||
u32 block_height_mask;
|
||||
u32 block_depth;
|
||||
u32 block_depth_mask;
|
||||
};
|
||||
static_assert(sizeof(BlockLinearUnswizzle3DBufferPushConstants) <= 128);
|
||||
|
||||
constexpr std::array<VkDescriptorSetLayoutBinding, 2> BL3DB_BINDINGS{{
|
||||
{
|
||||
.binding = BL3DB_BINDING_INPUT_BUFFER,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
.pImmutableSamplers = nullptr,
|
||||
},
|
||||
{
|
||||
.binding = BL3DB_BINDING_OUTPUT_BUFFER,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
|
||||
.pImmutableSamplers = nullptr,
|
||||
},
|
||||
}};
|
||||
|
||||
constexpr std::array<VkDescriptorUpdateTemplateEntry, 2> BL3DB_TEMPLATE{{
|
||||
{
|
||||
.dstBinding = BL3DB_BINDING_INPUT_BUFFER,
|
||||
.dstArrayElement = 0,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.offset = BL3DB_BINDING_INPUT_BUFFER * sizeof(DescriptorUpdateEntry),
|
||||
.stride = sizeof(DescriptorUpdateEntry),
|
||||
},
|
||||
{
|
||||
.dstBinding = BL3DB_BINDING_OUTPUT_BUFFER,
|
||||
.dstArrayElement = 0,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.offset = BL3DB_BINDING_OUTPUT_BUFFER * sizeof(DescriptorUpdateEntry),
|
||||
.stride = sizeof(DescriptorUpdateEntry),
|
||||
},
|
||||
}};
|
||||
|
||||
constexpr DescriptorBankInfo BL3DB_BANK_INFO{
|
||||
.uniform_buffers = 0,
|
||||
.storage_buffers = 2,
|
||||
.texture_buffers = 0,
|
||||
.image_buffers = 0,
|
||||
.textures = 0,
|
||||
.images = 0,
|
||||
.score = 2,
|
||||
};
|
||||
|
||||
constexpr bool BL3DB_VERIFY_AGAINST_CPU = false;
|
||||
} // Anonymous namespace
|
||||
|
||||
BlockLinearUnswizzle3DBufferPass::BlockLinearUnswizzle3DBufferPass(
|
||||
const Device& device_, Scheduler& scheduler_, DescriptorPool& descriptor_pool_,
|
||||
StagingBufferPool& staging_buffer_pool_,
|
||||
ComputePassDescriptorQueue& compute_pass_descriptor_queue_)
|
||||
: ComputePass(device_, scheduler_, descriptor_pool_, BL3DB_BINDINGS, BL3DB_TEMPLATE,
|
||||
BL3DB_BANK_INFO,
|
||||
COMPUTE_PUSH_CONSTANT_RANGE<sizeof(BlockLinearUnswizzle3DBufferPushConstants)>,
|
||||
BLOCK_LINEAR_UNSWIZZLE_3D_BUFFER_COMP_SPV),
|
||||
scheduler{scheduler_}, staging_buffer_pool{staging_buffer_pool_},
|
||||
compute_pass_descriptor_queue{compute_pass_descriptor_queue_} {}
|
||||
|
||||
BlockLinearUnswizzle3DBufferPass::~BlockLinearUnswizzle3DBufferPass() = default;
|
||||
|
||||
bool BlockLinearUnswizzle3DBufferPass::IsSupported(const Device& device,
|
||||
const VideoCommon::ImageInfo& info) {
|
||||
if (info.type != VideoCommon::ImageType::e3D) {
|
||||
return false;
|
||||
}
|
||||
if (info.resources.levels != 1 || info.resources.layers != 1) {
|
||||
return false;
|
||||
}
|
||||
if (info.num_samples > 1) {
|
||||
return false;
|
||||
}
|
||||
if (info.size.depth <= 1) {
|
||||
return false;
|
||||
}
|
||||
if (VideoCore::Surface::IsPixelFormatASTC(info.format)) {
|
||||
return false;
|
||||
}
|
||||
if (VideoCore::Surface::IsPixelFormatBCn(info.format) && !device.IsOptimalBcnSupported()) {
|
||||
return false;
|
||||
}
|
||||
const u32 bytes_per_block = VideoCore::Surface::BytesPerBlock(info.format);
|
||||
return bytes_per_block == 4 || bytes_per_block == 8 || bytes_per_block == 16;
|
||||
}
|
||||
|
||||
void BlockLinearUnswizzle3DBufferPass::Unswizzle(
|
||||
Image& image, const StagingBufferRef& swizzled,
|
||||
std::span<const VideoCommon::SwizzleParameters> swizzles) {
|
||||
if (swizzles.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const VideoCommon::SwizzleParameters& sw = swizzles.front();
|
||||
const auto params = VideoCommon::Accelerated::MakeBlockLinearSwizzle3DParams(sw, image.info);
|
||||
|
||||
const u32 blocks_x = sw.num_tiles.width;
|
||||
const u32 blocks_y = sw.num_tiles.height;
|
||||
const u32 blocks_z = sw.num_tiles.depth;
|
||||
const u32 bytes_per_block = 1u << params.bytes_per_block_log2;
|
||||
const VkDeviceSize output_size =
|
||||
static_cast<VkDeviceSize>(blocks_x) * blocks_y * blocks_z * bytes_per_block;
|
||||
|
||||
const StagingBufferRef output =
|
||||
staging_buffer_pool.Request(static_cast<size_t>(output_size), MemoryUsage::DeviceLocal);
|
||||
|
||||
BlockLinearUnswizzle3DBufferPushConstants pc{};
|
||||
pc.dim = {blocks_x, blocks_y, blocks_z};
|
||||
pc.bytes_per_block_log2 = params.bytes_per_block_log2;
|
||||
pc.origin = params.origin;
|
||||
pc.slice_size = params.slice_size;
|
||||
pc.block_size = params.block_size;
|
||||
pc.x_shift = params.x_shift;
|
||||
pc.block_height = params.block_height;
|
||||
pc.block_height_mask = params.block_height_mask;
|
||||
pc.block_depth = params.block_depth;
|
||||
pc.block_depth_mask = params.block_depth_mask;
|
||||
|
||||
scheduler.RequestOutsideRenderPassOperationContext();
|
||||
|
||||
compute_pass_descriptor_queue.Acquire(scheduler, 2);
|
||||
compute_pass_descriptor_queue.AddBuffer(swizzled.buffer, sw.buffer_offset + swizzled.offset,
|
||||
image.guest_size_bytes - sw.buffer_offset);
|
||||
compute_pass_descriptor_queue.AddBuffer(output.buffer, output.offset, output_size);
|
||||
|
||||
const void* descriptor_data = compute_pass_descriptor_queue.UpdateData();
|
||||
const VkDescriptorSet set = descriptor_allocator.Commit();
|
||||
|
||||
const u32 gx = Common::DivCeil(blocks_x, 8u);
|
||||
const u32 gy = Common::DivCeil(blocks_y, 8u);
|
||||
const u32 gz = Common::DivCeil(blocks_z, 4u);
|
||||
const bool is_initialized = image.ExchangeInitialization();
|
||||
|
||||
const VkBuffer out_buffer = output.buffer;
|
||||
const VkDeviceSize out_offset = output.offset;
|
||||
const VkImage dst_image = image.Handle();
|
||||
const VkImageAspectFlags aspect = image.AspectMask();
|
||||
const VkExtent3D extent{
|
||||
.width = image.info.size.width,
|
||||
.height = image.info.size.height,
|
||||
.depth = image.info.size.depth,
|
||||
};
|
||||
|
||||
scheduler.Record([this, set, descriptor_data, pc, gx, gy, gz, output_size, out_buffer,
|
||||
out_offset, dst_image, aspect, extent,
|
||||
is_initialized](vk::CommandBuffer cmdbuf) {
|
||||
if (dst_image == VK_NULL_HANDLE || out_buffer == VK_NULL_HANDLE) {
|
||||
return;
|
||||
}
|
||||
device.GetLogical().UpdateDescriptorSet(set, *descriptor_template, descriptor_data);
|
||||
cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline);
|
||||
cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_COMPUTE, *layout, 0, set, {});
|
||||
cmdbuf.PushConstants(*layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(pc), &pc);
|
||||
cmdbuf.Dispatch(gx, gy, gz);
|
||||
|
||||
const VkBufferMemoryBarrier buffer_barrier{
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
|
||||
.pNext = nullptr,
|
||||
.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.buffer = out_buffer,
|
||||
.offset = out_offset,
|
||||
.size = output_size,
|
||||
};
|
||||
const VkImageMemoryBarrier pre_copy{
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
||||
.pNext = nullptr,
|
||||
.srcAccessMask = static_cast<VkAccessFlags>(
|
||||
is_initialized ? VK_ACCESS_SHADER_READ_BIT : VK_ACCESS_NONE),
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
.oldLayout = is_initialized ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = dst_image,
|
||||
.subresourceRange{
|
||||
.aspectMask = aspect,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = VK_REMAINING_MIP_LEVELS,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = VK_REMAINING_ARRAY_LAYERS,
|
||||
},
|
||||
};
|
||||
cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
|
||||
(is_initialized ? vk::PIPELINE_STAGE_GRAPHICS_COMPUTE
|
||||
: VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT),
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, 0, {}, buffer_barrier, pre_copy);
|
||||
|
||||
const VkBufferImageCopy copy{
|
||||
.bufferOffset = out_offset,
|
||||
.bufferRowLength = 0,
|
||||
.bufferImageHeight = 0,
|
||||
.imageSubresource{
|
||||
.aspectMask = aspect,
|
||||
.mipLevel = 0,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
.imageOffset = {0, 0, 0},
|
||||
.imageExtent = extent,
|
||||
};
|
||||
cmdbuf.CopyBufferToImage(out_buffer, dst_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, copy);
|
||||
|
||||
const VkImageMemoryBarrier post_copy{
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
||||
.pNext = nullptr,
|
||||
.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
.dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
|
||||
.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = dst_image,
|
||||
.subresourceRange{
|
||||
.aspectMask = aspect,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = VK_REMAINING_MIP_LEVELS,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = VK_REMAINING_ARRAY_LAYERS,
|
||||
},
|
||||
};
|
||||
cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
vk::PIPELINE_STAGE_GRAPHICS_COMPUTE, 0, {}, {}, post_copy);
|
||||
});
|
||||
|
||||
if constexpr (BL3DB_VERIFY_AGAINST_CPU) {
|
||||
VerifyAgainstCpu(swizzled, sw, image.info, output, output_size, blocks_x, blocks_y,
|
||||
blocks_z, bytes_per_block);
|
||||
}
|
||||
}
|
||||
|
||||
void BlockLinearUnswizzle3DBufferPass::VerifyAgainstCpu(
|
||||
const StagingBufferRef& swizzled, const VideoCommon::SwizzleParameters& sw,
|
||||
const VideoCommon::ImageInfo& info, const StagingBufferRef& gpu_output,
|
||||
VkDeviceSize output_size, u32 blocks_x, u32 blocks_y, u32 blocks_z, u32 bytes_per_block) {
|
||||
const StagingBufferRef readback =
|
||||
staging_buffer_pool.Request(static_cast<size_t>(output_size), MemoryUsage::Download);
|
||||
|
||||
const VkBuffer src = gpu_output.buffer;
|
||||
const VkDeviceSize src_offset = gpu_output.offset;
|
||||
const VkBuffer dst = readback.buffer;
|
||||
const VkDeviceSize dst_offset = readback.offset;
|
||||
scheduler.Record([src, src_offset, dst, dst_offset, output_size](vk::CommandBuffer cmdbuf) {
|
||||
const VkBufferMemoryBarrier barrier{
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
|
||||
.pNext = nullptr,
|
||||
.srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.buffer = src,
|
||||
.offset = src_offset,
|
||||
.size = output_size,
|
||||
};
|
||||
cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0, {}, barrier, {});
|
||||
const VkBufferCopy copy{
|
||||
.srcOffset = src_offset,
|
||||
.dstOffset = dst_offset,
|
||||
.size = output_size,
|
||||
};
|
||||
cmdbuf.CopyBuffer(src, dst, copy);
|
||||
});
|
||||
scheduler.Finish();
|
||||
|
||||
const size_t size = static_cast<size_t>(output_size);
|
||||
std::vector<u8> reference(size);
|
||||
const std::span<const u8> input{swizzled.mapped_span.data() + sw.buffer_offset,
|
||||
swizzled.mapped_span.size() - sw.buffer_offset};
|
||||
const u32 stride_alignment = VideoCommon::CalculateLevelStrideAlignment(info, sw.level);
|
||||
Tegra::Texture::UnswizzleTexture(reference, input, bytes_per_block, blocks_x, blocks_y, blocks_z,
|
||||
sw.block.height, sw.block.depth, stride_alignment);
|
||||
|
||||
const u8* gpu_data = readback.mapped_span.data();
|
||||
if (std::memcmp(reference.data(), gpu_data, size) == 0) {
|
||||
LOG_INFO(Render_Vulkan, "BL3D verify OK: {}x{}x{} bpb={} ({} bytes)", blocks_x, blocks_y,
|
||||
blocks_z, bytes_per_block, size);
|
||||
return;
|
||||
}
|
||||
size_t first_diff = size;
|
||||
size_t num_diff = 0;
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
if (reference[i] != gpu_data[i]) {
|
||||
if (first_diff == size) {
|
||||
first_diff = i;
|
||||
}
|
||||
++num_diff;
|
||||
}
|
||||
}
|
||||
LOG_CRITICAL(Render_Vulkan,
|
||||
"BL3D verify FAILED: {}x{}x{} bpb={} block_height={} block_depth={} "
|
||||
"first_diff={} num_diff={}/{} cpu=0x{:02x} gpu=0x{:02x}",
|
||||
blocks_x, blocks_y, blocks_z, bytes_per_block, sw.block.height, sw.block.depth,
|
||||
first_diff, num_diff, size, reference[first_diff], gpu_data[first_diff]);
|
||||
}
|
||||
|
||||
} // namespace Vulkan
|
||||
|
||||
@@ -164,4 +164,54 @@ private:
|
||||
ComputePassDescriptorQueue& compute_pass_descriptor_queue;
|
||||
};
|
||||
|
||||
class BlockLinearUnswizzle2DPass final : public ComputePass {
|
||||
public:
|
||||
explicit BlockLinearUnswizzle2DPass(const Device& device_, Scheduler& scheduler_,
|
||||
DescriptorPool& descriptor_pool_,
|
||||
StagingBufferPool& staging_buffer_pool_,
|
||||
ComputePassDescriptorQueue& compute_pass_descriptor_queue_);
|
||||
~BlockLinearUnswizzle2DPass();
|
||||
|
||||
[[nodiscard]] static bool IsSupported(const VideoCommon::ImageInfo& info);
|
||||
|
||||
void Unswizzle(Image& image, const StagingBufferRef& swizzled,
|
||||
std::span<const VideoCommon::SwizzleParameters> swizzles);
|
||||
|
||||
private:
|
||||
void VerifyAgainstCpu(const StagingBufferRef& swizzled,
|
||||
const VideoCommon::SwizzleParameters& sw,
|
||||
const StagingBufferRef& gpu_output, VkDeviceSize output_size, u32 width,
|
||||
u32 height, u32 depth, u32 bytes_per_block);
|
||||
|
||||
Scheduler& scheduler;
|
||||
StagingBufferPool& staging_buffer_pool;
|
||||
ComputePassDescriptorQueue& compute_pass_descriptor_queue;
|
||||
};
|
||||
|
||||
class BlockLinearUnswizzle3DBufferPass final : public ComputePass {
|
||||
public:
|
||||
explicit BlockLinearUnswizzle3DBufferPass(
|
||||
const Device& device_, Scheduler& scheduler_, DescriptorPool& descriptor_pool_,
|
||||
StagingBufferPool& staging_buffer_pool_,
|
||||
ComputePassDescriptorQueue& compute_pass_descriptor_queue_);
|
||||
~BlockLinearUnswizzle3DBufferPass();
|
||||
|
||||
[[nodiscard]] static bool IsSupported(const Device& device,
|
||||
const VideoCommon::ImageInfo& info);
|
||||
|
||||
void Unswizzle(Image& image, const StagingBufferRef& swizzled,
|
||||
std::span<const VideoCommon::SwizzleParameters> swizzles);
|
||||
|
||||
private:
|
||||
void VerifyAgainstCpu(const StagingBufferRef& swizzled,
|
||||
const VideoCommon::SwizzleParameters& sw,
|
||||
const VideoCommon::ImageInfo& info,
|
||||
const StagingBufferRef& gpu_output, VkDeviceSize output_size,
|
||||
u32 blocks_x, u32 blocks_y, u32 blocks_z, u32 bytes_per_block);
|
||||
|
||||
Scheduler& scheduler;
|
||||
StagingBufferPool& staging_buffer_pool;
|
||||
ComputePassDescriptorQueue& compute_pass_descriptor_queue;
|
||||
};
|
||||
|
||||
} // namespace Vulkan
|
||||
|
||||
@@ -34,12 +34,14 @@ using Tegra::Texture::TexturePair;
|
||||
ComputePipeline::ComputePipeline(const Device& device_, Scheduler& scheduler, vk::PipelineCache& pipeline_cache_,
|
||||
DescriptorPool& descriptor_pool,
|
||||
GuestDescriptorQueue& guest_descriptor_queue_,
|
||||
DescriptorBufferRing& descriptor_buffer_ring_,
|
||||
Common::ThreadWorker* thread_worker,
|
||||
PipelineStatistics* pipeline_statistics,
|
||||
VideoCore::ShaderNotify* shader_notify, const Shader::Info& info_,
|
||||
vk::ShaderModule spv_module_, u64 shader_hash_)
|
||||
: device{device_},
|
||||
pipeline_cache(pipeline_cache_), guest_descriptor_queue{guest_descriptor_queue_}, info{info_},
|
||||
pipeline_cache(pipeline_cache_), guest_descriptor_queue{guest_descriptor_queue_},
|
||||
descriptor_buffer_ring{descriptor_buffer_ring_}, info{info_},
|
||||
shader_hash{shader_hash_}, spv_module(std::move(spv_module_)) {
|
||||
if (shader_notify) {
|
||||
shader_notify->MarkShaderBuilding();
|
||||
@@ -48,18 +50,35 @@ ComputePipeline::ComputePipeline(const Device& device_, Scheduler& scheduler, vk
|
||||
uniform_buffer_sizes.begin());
|
||||
num_descriptor_entries = NumDescriptorEntries(info);
|
||||
|
||||
auto func{[this, &scheduler, &descriptor_pool, shader_notify, pipeline_statistics] {
|
||||
DescriptorLayoutBuilder builder{device};
|
||||
builder.Add(info, VK_SHADER_STAGE_COMPUTE_BIT);
|
||||
DescriptorLayoutBuilder builder{device};
|
||||
builder.Add(info, VK_SHADER_STAGE_COMPUTE_BIT);
|
||||
|
||||
uses_push_descriptor = builder.CanUsePushDescriptor();
|
||||
descriptor_set_layout = builder.CreateDescriptorSetLayout(uses_push_descriptor);
|
||||
pipeline_layout = builder.CreatePipelineLayout(*descriptor_set_layout);
|
||||
uses_push_descriptor = builder.CanUsePushDescriptor();
|
||||
uses_descriptor_buffer = builder.CanUseDescriptorBuffer() && descriptor_buffer_ring.IsValid();
|
||||
descriptor_set_layout =
|
||||
builder.CreateDescriptorSetLayout(uses_push_descriptor, uses_descriptor_buffer);
|
||||
if (uses_descriptor_buffer) {
|
||||
descriptor_buffer_layout = builder.MakeDescriptorBufferLayout(*descriptor_set_layout);
|
||||
if (descriptor_buffer_layout.size > DescriptorBufferRing::MaxAllocationSize()) {
|
||||
LOG_WARNING(Render_Vulkan,
|
||||
"Compute shader {:016X} needs {} descriptor bytes, falling back to sets",
|
||||
shader_hash, descriptor_buffer_layout.size);
|
||||
uses_descriptor_buffer = false;
|
||||
descriptor_buffer_layout = {};
|
||||
descriptor_set_layout = builder.CreateDescriptorSetLayout(false);
|
||||
}
|
||||
}
|
||||
pipeline_layout = builder.CreatePipelineLayout(*descriptor_set_layout);
|
||||
if (!uses_descriptor_buffer) {
|
||||
descriptor_update_template =
|
||||
builder.CreateTemplate(*descriptor_set_layout, *pipeline_layout, uses_push_descriptor);
|
||||
if (!uses_push_descriptor) {
|
||||
descriptor_allocator = descriptor_pool.Allocator(device, scheduler, *descriptor_set_layout, info);
|
||||
descriptor_allocator =
|
||||
descriptor_pool.Allocator(device, scheduler, *descriptor_set_layout, info);
|
||||
}
|
||||
}
|
||||
|
||||
auto func{[this, shader_notify, pipeline_statistics] {
|
||||
const VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT subgroup_size_ci{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_REQUIRED_SUBGROUP_SIZE_CREATE_INFO_EXT,
|
||||
.pNext = nullptr,
|
||||
@@ -69,9 +88,20 @@ ComputePipeline::ComputePipeline(const Device& device_, Scheduler& scheduler, vk
|
||||
if (device.IsKhrPipelineExecutablePropertiesEnabled() && Settings::values.renderer_debug.GetValue()) {
|
||||
flags |= VK_PIPELINE_CREATE_CAPTURE_STATISTICS_BIT_KHR;
|
||||
}
|
||||
if (uses_descriptor_buffer) {
|
||||
flags |= VK_PIPELINE_CREATE_DESCRIPTOR_BUFFER_BIT_EXT;
|
||||
}
|
||||
VkPipelineCreationFeedback creation_feedback{};
|
||||
const VkPipelineCreationFeedbackCreateInfo feedback_ci{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_CREATION_FEEDBACK_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.pPipelineCreationFeedback = &creation_feedback,
|
||||
.pipelineStageCreationFeedbackCount = 0,
|
||||
.pPipelineStageCreationFeedbacks = nullptr,
|
||||
};
|
||||
const VkComputePipelineCreateInfo compute_ci{
|
||||
.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.pNext = device.IsExtPipelineCreationFeedbackSupported() ? &feedback_ci : nullptr,
|
||||
.flags = flags,
|
||||
.stage{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||
@@ -101,6 +131,14 @@ ComputePipeline::ComputePipeline(const Device& device_, Scheduler& scheduler, vk
|
||||
return;
|
||||
}
|
||||
|
||||
if ((creation_feedback.flags & VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT) != 0) {
|
||||
const bool cache_hit =
|
||||
(creation_feedback.flags &
|
||||
VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT) != 0;
|
||||
LOG_DEBUG(Render_Vulkan, "Compute pipeline {:016X} cache_hit={} duration={}us",
|
||||
shader_hash, cache_hit, creation_feedback.duration / 1000);
|
||||
}
|
||||
|
||||
// Log compute pipeline creation
|
||||
if (GPU::Logging::IsActive()) {
|
||||
GPU::Logging::GPULogger::GetInstance().LogPipelineStateChange(
|
||||
@@ -128,7 +166,7 @@ ComputePipeline::ComputePipeline(const Device& device_, Scheduler& scheduler, vk
|
||||
void ComputePipeline::Configure(Tegra::Engines::KeplerCompute& kepler_compute,
|
||||
Tegra::MemoryManager& gpu_memory, Scheduler& scheduler,
|
||||
BufferCache& buffer_cache, TextureCache& texture_cache) {
|
||||
guest_descriptor_queue.Acquire(scheduler, num_descriptor_entries);
|
||||
guest_descriptor_queue.Acquire(scheduler, num_descriptor_entries, uses_descriptor_buffer);
|
||||
|
||||
buffer_cache.SetComputeUniformBufferState(info.constant_buffer_mask, &uniform_buffer_sizes);
|
||||
buffer_cache.UnbindComputeStorageBuffers();
|
||||
@@ -249,9 +287,22 @@ void ComputePipeline::Configure(Tegra::Engines::KeplerCompute& kepler_compute,
|
||||
GPU::Logging::GPULogger::GetInstance().LogPipelineBind(true, "compute pipeline");
|
||||
}
|
||||
|
||||
const void* const descriptor_data{guest_descriptor_queue.UpdateData()};
|
||||
const DescriptorUpdateEntry* const descriptor_data{guest_descriptor_queue.UpdateData()};
|
||||
VkDeviceSize descriptor_buffer_offset{};
|
||||
bool descriptor_buffer_ready{false};
|
||||
if (uses_descriptor_buffer) {
|
||||
const DescriptorBufferRing::Allocation alloc{
|
||||
descriptor_buffer_ring.Allocate(scheduler, descriptor_buffer_layout.size)};
|
||||
if (alloc.host) {
|
||||
WriteDescriptorBuffer(device, descriptor_buffer_layout, descriptor_data, alloc.host);
|
||||
descriptor_buffer_offset = alloc.offset;
|
||||
descriptor_buffer_ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
const bool is_rescaling = !info.texture_descriptors.empty() || !info.image_descriptors.empty();
|
||||
scheduler.Record([this, descriptor_data, is_rescaling,
|
||||
scheduler.Record([this, descriptor_data, is_rescaling, descriptor_buffer_offset,
|
||||
descriptor_buffer_ready,
|
||||
rescaling_data = rescaling.Data()](vk::CommandBuffer cmdbuf) {
|
||||
if (!pipeline) {
|
||||
return;
|
||||
@@ -265,7 +316,17 @@ void ComputePipeline::Configure(Tegra::Engines::KeplerCompute& kepler_compute,
|
||||
RESCALING_LAYOUT_WORDS_OFFSET, sizeof(rescaling_data),
|
||||
rescaling_data.data());
|
||||
}
|
||||
if (uses_push_descriptor) {
|
||||
if (uses_descriptor_buffer) {
|
||||
if (!descriptor_buffer_ready) {
|
||||
return;
|
||||
}
|
||||
const VkDescriptorBufferBindingInfoEXT binding_info{
|
||||
descriptor_buffer_ring.BindingInfo()};
|
||||
cmdbuf.BindDescriptorBuffersEXT(binding_info);
|
||||
const u32 buffer_index{};
|
||||
cmdbuf.SetDescriptorBufferOffsetsEXT(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline_layout,
|
||||
0, buffer_index, descriptor_buffer_offset);
|
||||
} else if (uses_push_descriptor) {
|
||||
cmdbuf.PushDescriptorSetWithTemplateKHR(*descriptor_update_template, *pipeline_layout,
|
||||
0, descriptor_data);
|
||||
} else {
|
||||
|
||||
@@ -13,7 +13,9 @@
|
||||
#include "common/common_types.h"
|
||||
#include "common/thread_worker.h"
|
||||
#include "shader_recompiler/shader_info.h"
|
||||
#include "video_core/renderer_vulkan/pipeline_helper.h"
|
||||
#include "video_core/renderer_vulkan/vk_buffer_cache.h"
|
||||
#include "video_core/renderer_vulkan/vk_descriptor_buffer.h"
|
||||
#include "video_core/renderer_vulkan/vk_descriptor_pool.h"
|
||||
#include "video_core/renderer_vulkan/vk_texture_cache.h"
|
||||
#include "video_core/renderer_vulkan/vk_update_descriptor.h"
|
||||
@@ -34,6 +36,7 @@ public:
|
||||
explicit ComputePipeline(const Device& device, Scheduler& scheduler, vk::PipelineCache& pipeline_cache,
|
||||
DescriptorPool& descriptor_pool,
|
||||
GuestDescriptorQueue& guest_descriptor_queue,
|
||||
DescriptorBufferRing& descriptor_buffer_ring,
|
||||
Common::ThreadWorker* thread_worker,
|
||||
PipelineStatistics* pipeline_statistics,
|
||||
VideoCore::ShaderNotify* shader_notify, const Shader::Info& info,
|
||||
@@ -56,6 +59,7 @@ private:
|
||||
const Device& device;
|
||||
vk::PipelineCache& pipeline_cache;
|
||||
GuestDescriptorQueue& guest_descriptor_queue;
|
||||
DescriptorBufferRing& descriptor_buffer_ring;
|
||||
Shader::Info info;
|
||||
u64 shader_hash{};
|
||||
u32 num_descriptor_entries{};
|
||||
@@ -65,6 +69,8 @@ private:
|
||||
vk::ShaderModule spv_module;
|
||||
vk::DescriptorSetLayout descriptor_set_layout;
|
||||
bool uses_push_descriptor{false};
|
||||
bool uses_descriptor_buffer{false};
|
||||
DescriptorBufferLayout descriptor_buffer_layout;
|
||||
DescriptorAllocator descriptor_allocator;
|
||||
vk::PipelineLayout pipeline_layout;
|
||||
vk::DescriptorUpdateTemplate descriptor_update_template;
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "common/alignment.h"
|
||||
#include "common/assert.h"
|
||||
#include "common/logging.h"
|
||||
#include "video_core/renderer_vulkan/vk_descriptor_buffer.h"
|
||||
#include "video_core/renderer_vulkan/vk_scheduler.h"
|
||||
#include "video_core/vulkan_common/vulkan_device.h"
|
||||
|
||||
namespace Vulkan {
|
||||
|
||||
DescriptorBufferRing::DescriptorBufferRing(const Device& device_,
|
||||
MemoryAllocator& memory_allocator)
|
||||
: device{device_} {
|
||||
if (!device.IsExtDescriptorBufferSupported() || !device.IsBufferDeviceAddressSupported()) {
|
||||
return;
|
||||
}
|
||||
alignment = std::max<VkDeviceSize>(
|
||||
device.DescriptorBufferProperties().descriptorBufferOffsetAlignment, 1);
|
||||
const VkDeviceSize total = FRAME_SIZE * FRAMES_IN_FLIGHT + alignment;
|
||||
const VkBufferCreateInfo buffer_ci{
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.flags = 0,
|
||||
.size = total,
|
||||
.usage = VK_BUFFER_USAGE_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT |
|
||||
VK_BUFFER_USAGE_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT |
|
||||
VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
|
||||
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||
.queueFamilyIndexCount = 0,
|
||||
.pQueueFamilyIndices = nullptr,
|
||||
};
|
||||
buffer = memory_allocator.CreateBuffer(buffer_ci, MemoryUsage::Upload);
|
||||
if (!buffer.IsHostVisible()) {
|
||||
LOG_WARNING(Render_Vulkan, "Descriptor buffer is not host visible, disabling");
|
||||
buffer.reset();
|
||||
return;
|
||||
}
|
||||
if (device.HasDebuggingToolAttached()) {
|
||||
buffer.SetObjectNameEXT("Descriptor buffer");
|
||||
}
|
||||
const VkDeviceAddress raw_address = device.GetLogical().GetBufferDeviceAddress(*buffer);
|
||||
base_address = Common::AlignUp(raw_address, alignment);
|
||||
base_host = buffer.Mapped().data() + (base_address - raw_address);
|
||||
}
|
||||
|
||||
DescriptorBufferRing::~DescriptorBufferRing() = default;
|
||||
|
||||
void DescriptorBufferRing::TickFrame() {
|
||||
if (++frame_index >= FRAMES_IN_FLIGHT) {
|
||||
frame_index = 0;
|
||||
}
|
||||
frame_start = static_cast<VkDeviceSize>(frame_index) * FRAME_SIZE;
|
||||
cursor = 0;
|
||||
frame_reused = true;
|
||||
}
|
||||
|
||||
DescriptorBufferRing::Allocation DescriptorBufferRing::Allocate(Scheduler& scheduler,
|
||||
VkDeviceSize size) {
|
||||
ASSERT(buffer);
|
||||
const VkDeviceSize needed = Common::AlignUp(size, alignment);
|
||||
if (needed > FRAME_SIZE) {
|
||||
LOG_ERROR(Render_Vulkan, "Descriptor set of {} bytes exceeds frame capacity {}", needed,
|
||||
FRAME_SIZE);
|
||||
return Allocation{};
|
||||
}
|
||||
if (frame_reused) {
|
||||
frame_reused = false;
|
||||
scheduler.Wait(frame_ticks[frame_index]);
|
||||
}
|
||||
if (cursor + needed > FRAME_SIZE) {
|
||||
LOG_WARNING(Render_Vulkan, "Descriptor buffer frame exhausted, stalling on the GPU");
|
||||
scheduler.Finish();
|
||||
cursor = 0;
|
||||
}
|
||||
const VkDeviceSize offset = frame_start + cursor;
|
||||
cursor += needed;
|
||||
frame_ticks[frame_index] = scheduler.CurrentTick();
|
||||
return Allocation{
|
||||
.host = base_host + offset,
|
||||
.offset = offset,
|
||||
};
|
||||
}
|
||||
|
||||
VkDescriptorBufferBindingInfoEXT DescriptorBufferRing::BindingInfo() const noexcept {
|
||||
return VkDescriptorBufferBindingInfoEXT{
|
||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_BUFFER_BINDING_INFO_EXT,
|
||||
.pNext = nullptr,
|
||||
.address = base_address,
|
||||
.usage = VK_BUFFER_USAGE_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT |
|
||||
VK_BUFFER_USAGE_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT,
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace Vulkan
|
||||
@@ -0,0 +1,57 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "video_core/vulkan_common/vulkan_memory_allocator.h"
|
||||
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
||||
|
||||
namespace Vulkan {
|
||||
|
||||
class Device;
|
||||
class Scheduler;
|
||||
|
||||
class DescriptorBufferRing final {
|
||||
static constexpr size_t FRAMES_IN_FLIGHT = 8;
|
||||
static constexpr VkDeviceSize FRAME_SIZE = 512 * 1024;
|
||||
|
||||
public:
|
||||
explicit DescriptorBufferRing(const Device& device_, MemoryAllocator& memory_allocator);
|
||||
~DescriptorBufferRing();
|
||||
|
||||
struct Allocation {
|
||||
u8* host{};
|
||||
VkDeviceSize offset{};
|
||||
};
|
||||
|
||||
[[nodiscard]] static constexpr VkDeviceSize MaxAllocationSize() noexcept {
|
||||
return FRAME_SIZE;
|
||||
}
|
||||
|
||||
void TickFrame();
|
||||
|
||||
[[nodiscard]] Allocation Allocate(Scheduler& scheduler, VkDeviceSize size);
|
||||
|
||||
[[nodiscard]] VkDescriptorBufferBindingInfoEXT BindingInfo() const noexcept;
|
||||
|
||||
[[nodiscard]] bool IsValid() const noexcept {
|
||||
return static_cast<bool>(buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
const Device& device;
|
||||
vk::Buffer buffer;
|
||||
VkDeviceAddress base_address{};
|
||||
u8* base_host{};
|
||||
VkDeviceSize alignment{1};
|
||||
size_t frame_index{};
|
||||
VkDeviceSize frame_start{};
|
||||
VkDeviceSize cursor{};
|
||||
std::array<u64, FRAMES_IN_FLIGHT> frame_ticks{};
|
||||
bool frame_reused{};
|
||||
};
|
||||
|
||||
} // namespace Vulkan
|
||||
@@ -37,7 +37,7 @@ void InnerFence::Wait() {
|
||||
if (is_stubbed) {
|
||||
return;
|
||||
}
|
||||
scheduler.Wait(wait_tick);
|
||||
scheduler.WaitSubmitted(wait_tick);
|
||||
}
|
||||
|
||||
FenceManager::FenceManager(VideoCore::RasterizerInterface& rasterizer_, Tegra::GPU& gpu_,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <span>
|
||||
|
||||
@@ -250,13 +251,15 @@ GraphicsPipeline::GraphicsPipeline(
|
||||
Scheduler& scheduler_, BufferCache& buffer_cache_, TextureCache& texture_cache_,
|
||||
vk::PipelineCache& pipeline_cache_, VideoCore::ShaderNotify* shader_notify,
|
||||
const Device& device_, DescriptorPool& descriptor_pool,
|
||||
GuestDescriptorQueue& guest_descriptor_queue_, Common::ThreadWorker* worker_thread,
|
||||
GuestDescriptorQueue& guest_descriptor_queue_, DescriptorBufferRing& descriptor_buffer_ring_,
|
||||
Common::ThreadWorker* worker_thread,
|
||||
PipelineStatistics* pipeline_statistics, RenderPassCache& render_pass_cache,
|
||||
const GraphicsPipelineCacheKey& key_, std::array<vk::ShaderModule, NUM_STAGES> stages,
|
||||
const std::array<const Shader::Info*, NUM_STAGES>& infos)
|
||||
: key{key_}, device{device_}, texture_cache{texture_cache_}, buffer_cache{buffer_cache_},
|
||||
pipeline_cache(pipeline_cache_), scheduler{scheduler_},
|
||||
guest_descriptor_queue{guest_descriptor_queue_}, spv_modules{std::move(stages)} {
|
||||
guest_descriptor_queue{guest_descriptor_queue_},
|
||||
descriptor_buffer_ring{descriptor_buffer_ring_}, spv_modules{std::move(stages)} {
|
||||
if (shader_notify) {
|
||||
shader_notify->MarkShaderBuilding();
|
||||
}
|
||||
@@ -276,21 +279,40 @@ GraphicsPipeline::GraphicsPipeline(
|
||||
num_descriptor_entries += NumDescriptorEntries(*info);
|
||||
}
|
||||
fragment_has_color0_output = stage_infos[NUM_STAGES - 1].stores_frag_color[0];
|
||||
auto func{[this, shader_notify, &render_pass_cache, &descriptor_pool, pipeline_statistics] {
|
||||
DescriptorLayoutBuilder builder{MakeBuilder(device, stage_infos)};
|
||||
uses_push_descriptor = builder.CanUsePushDescriptor();
|
||||
descriptor_set_layout = builder.CreateDescriptorSetLayout(uses_push_descriptor);
|
||||
|
||||
if (!uses_push_descriptor) {
|
||||
descriptor_allocator = descriptor_pool.Allocator(device, scheduler, *descriptor_set_layout, stage_infos);
|
||||
DescriptorLayoutBuilder builder{MakeBuilder(device, stage_infos)};
|
||||
uses_push_descriptor = builder.CanUsePushDescriptor();
|
||||
uses_descriptor_buffer = builder.CanUseDescriptorBuffer() && descriptor_buffer_ring.IsValid();
|
||||
descriptor_set_layout =
|
||||
builder.CreateDescriptorSetLayout(uses_push_descriptor, uses_descriptor_buffer);
|
||||
if (uses_descriptor_buffer) {
|
||||
descriptor_buffer_layout = builder.MakeDescriptorBufferLayout(*descriptor_set_layout);
|
||||
if (descriptor_buffer_layout.size > DescriptorBufferRing::MaxAllocationSize()) {
|
||||
LOG_WARNING(Render_Vulkan,
|
||||
"Graphics pipeline {:016X} needs {} descriptor bytes, falling back to sets",
|
||||
key.Hash(), descriptor_buffer_layout.size);
|
||||
uses_descriptor_buffer = false;
|
||||
descriptor_buffer_layout = {};
|
||||
descriptor_set_layout = builder.CreateDescriptorSetLayout(uses_push_descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
const VkDescriptorSetLayout set_layout{*descriptor_set_layout};
|
||||
pipeline_layout = builder.CreatePipelineLayout(set_layout);
|
||||
const VkDescriptorSetLayout set_layout{*descriptor_set_layout};
|
||||
pipeline_layout = builder.CreatePipelineLayout(set_layout);
|
||||
if (!uses_descriptor_buffer) {
|
||||
descriptor_update_template =
|
||||
builder.CreateTemplate(set_layout, *pipeline_layout, uses_push_descriptor);
|
||||
if (!uses_push_descriptor) {
|
||||
descriptor_allocator =
|
||||
descriptor_pool.Allocator(device, scheduler, set_layout, stage_infos);
|
||||
}
|
||||
}
|
||||
|
||||
const VkRenderPass render_pass{render_pass_cache.Get(MakeRenderPassKey(key.state, device))};
|
||||
auto func{[this, shader_notify, &render_pass_cache, pipeline_statistics] {
|
||||
VkRenderPass render_pass{};
|
||||
if (!device.IsKhrDynamicRenderingSupported()) {
|
||||
render_pass = render_pass_cache.Get(MakeRenderPassKey(key.state, device));
|
||||
}
|
||||
Validate();
|
||||
try {
|
||||
MakePipeline(render_pass);
|
||||
@@ -496,7 +518,7 @@ bool GraphicsPipeline::ConfigureImpl(bool is_indexed) {
|
||||
buffer_cache.UpdateGraphicsBuffers(is_indexed);
|
||||
buffer_cache.BindHostGeometryBuffers(is_indexed);
|
||||
|
||||
guest_descriptor_queue.Acquire(scheduler, num_descriptor_entries);
|
||||
guest_descriptor_queue.Acquire(scheduler, num_descriptor_entries, uses_descriptor_buffer);
|
||||
|
||||
RescalingPushConstant rescaling;
|
||||
RenderAreaPushConstant render_area;
|
||||
@@ -565,8 +587,33 @@ void GraphicsPipeline::ConfigureDraw(const RescalingPushConstant& rescaling,
|
||||
}
|
||||
|
||||
const void* const descriptor_data{guest_descriptor_queue.UpdateData()};
|
||||
scheduler.Record([this, descriptor_data, bind_pipeline, rescaling_data = rescaling.Data(),
|
||||
is_rescaling, update_rescaling,
|
||||
bool update_descriptors = true;
|
||||
if (descriptor_set_layout && !uses_push_descriptor && !uses_descriptor_buffer) {
|
||||
const auto* const entries = static_cast<const DescriptorUpdateEntry*>(descriptor_data);
|
||||
update_descriptors =
|
||||
bind_pipeline || last_descriptor_payload.size() != num_descriptor_entries ||
|
||||
std::memcmp(last_descriptor_payload.data(), entries,
|
||||
num_descriptor_entries * sizeof(DescriptorUpdateEntry)) != 0;
|
||||
if (update_descriptors) {
|
||||
last_descriptor_payload.assign(entries, entries + num_descriptor_entries);
|
||||
}
|
||||
}
|
||||
VkDeviceSize descriptor_buffer_offset{};
|
||||
bool descriptor_buffer_ready{false};
|
||||
if (descriptor_set_layout && uses_descriptor_buffer) {
|
||||
const DescriptorBufferRing::Allocation alloc{
|
||||
descriptor_buffer_ring.Allocate(scheduler, descriptor_buffer_layout.size)};
|
||||
if (alloc.host) {
|
||||
WriteDescriptorBuffer(device, descriptor_buffer_layout,
|
||||
static_cast<const DescriptorUpdateEntry*>(descriptor_data),
|
||||
alloc.host);
|
||||
descriptor_buffer_offset = alloc.offset;
|
||||
descriptor_buffer_ready = true;
|
||||
}
|
||||
}
|
||||
scheduler.Record([this, descriptor_data, bind_pipeline, update_descriptors,
|
||||
descriptor_buffer_offset, descriptor_buffer_ready,
|
||||
rescaling_data = rescaling.Data(), is_rescaling, update_rescaling,
|
||||
uses_render_area = render_area.uses_render_area,
|
||||
render_area_data = render_area.words](vk::CommandBuffer cmdbuf) {
|
||||
if (bind_pipeline) {
|
||||
@@ -593,10 +640,20 @@ void GraphicsPipeline::ConfigureDraw(const RescalingPushConstant& rescaling,
|
||||
if (!descriptor_set_layout) {
|
||||
return;
|
||||
}
|
||||
if (uses_push_descriptor) {
|
||||
if (uses_descriptor_buffer) {
|
||||
if (!descriptor_buffer_ready) {
|
||||
return;
|
||||
}
|
||||
const VkDescriptorBufferBindingInfoEXT binding_info{
|
||||
descriptor_buffer_ring.BindingInfo()};
|
||||
cmdbuf.BindDescriptorBuffersEXT(binding_info);
|
||||
const u32 buffer_index{};
|
||||
cmdbuf.SetDescriptorBufferOffsetsEXT(VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline_layout,
|
||||
0, buffer_index, descriptor_buffer_offset);
|
||||
} else if (uses_push_descriptor) {
|
||||
cmdbuf.PushDescriptorSetWithTemplateKHR(*descriptor_update_template, *pipeline_layout,
|
||||
0, descriptor_data);
|
||||
} else {
|
||||
} else if (update_descriptors) {
|
||||
const VkDescriptorSet descriptor_set{descriptor_allocator.Commit()};
|
||||
const vk::Device& dev{device.GetLogical()};
|
||||
dev.UpdateDescriptorSet(descriptor_set, *descriptor_update_template, descriptor_data);
|
||||
@@ -757,16 +814,13 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
|
||||
.lineWidth = 1.0f,
|
||||
// TODO(alekpop): Transfer from regs
|
||||
};
|
||||
const bool smooth_lines_supported =
|
||||
device.IsExtLineRasterizationSupported() && device.SupportsSmoothLines();
|
||||
const bool stippled_lines_supported =
|
||||
device.IsExtLineRasterizationSupported() && device.SupportsStippledRectangularLines();
|
||||
const VkLineRasterizationModeEXT line_raster_mode =
|
||||
device.GetLineRasterizationMode(key.state.smooth_lines != 0);
|
||||
const bool stippled_lines_supported = device.SupportsStippleForMode(line_raster_mode);
|
||||
VkPipelineRasterizationLineStateCreateInfoEXT line_state{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT,
|
||||
.pNext = nullptr,
|
||||
.lineRasterizationMode = key.state.smooth_lines != 0 && smooth_lines_supported
|
||||
? VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT
|
||||
: VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT,
|
||||
.lineRasterizationMode = line_raster_mode,
|
||||
.stippledLineEnable =
|
||||
(dynamic.line_stipple_enable && stippled_lines_supported) ? VK_TRUE : VK_FALSE,
|
||||
.lineStippleFactor = key.state.line_stipple_factor,
|
||||
@@ -805,6 +859,16 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
|
||||
if (device.IsExtProvokingVertexSupported()) {
|
||||
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 alpha_to_one_supported = device.SupportsAlphaToOne();
|
||||
@@ -995,10 +1059,65 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
|
||||
if (device.IsKhrPipelineExecutablePropertiesEnabled() && Settings::values.renderer_debug.GetValue()) {
|
||||
flags |= VK_PIPELINE_CREATE_CAPTURE_STATISTICS_BIT_KHR;
|
||||
}
|
||||
if (uses_descriptor_buffer) {
|
||||
flags |= VK_PIPELINE_CREATE_DESCRIPTOR_BUFFER_BIT_EXT;
|
||||
}
|
||||
|
||||
const RenderPassKey renderpass_key{MakeRenderPassKey(key.state, device)};
|
||||
std::array<VkFormat, Maxwell::NumRenderTargets> color_attachment_formats{};
|
||||
for (size_t index = 0; index < renderpass_key.color_formats.size(); ++index) {
|
||||
const PixelFormat pixel_format{renderpass_key.color_formats[index]};
|
||||
if (pixel_format == PixelFormat::Invalid) {
|
||||
color_attachment_formats[index] = VK_FORMAT_UNDEFINED;
|
||||
continue;
|
||||
}
|
||||
color_attachment_formats[index] =
|
||||
MaxwellToVK::SurfaceFormat(device, FormatType::Optimal, true, pixel_format).format;
|
||||
}
|
||||
VkFormat depth_attachment_format{VK_FORMAT_UNDEFINED};
|
||||
VkFormat stencil_attachment_format{VK_FORMAT_UNDEFINED};
|
||||
if (renderpass_key.depth_format != PixelFormat::Invalid) {
|
||||
const VkFormat format{
|
||||
MaxwellToVK::SurfaceFormat(device, FormatType::Optimal, true,
|
||||
renderpass_key.depth_format)
|
||||
.format};
|
||||
const auto surface_type{VideoCore::Surface::GetFormatType(renderpass_key.depth_format)};
|
||||
if (surface_type == VideoCore::Surface::SurfaceType::Depth ||
|
||||
surface_type == VideoCore::Surface::SurfaceType::DepthStencil) {
|
||||
depth_attachment_format = format;
|
||||
}
|
||||
if (surface_type == VideoCore::Surface::SurfaceType::Stencil ||
|
||||
surface_type == VideoCore::Surface::SurfaceType::DepthStencil) {
|
||||
stencil_attachment_format = format;
|
||||
}
|
||||
}
|
||||
const VkPipelineRenderingCreateInfo rendering_ci{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.viewMask = 0,
|
||||
.colorAttachmentCount = static_cast<u32>(NumAttachments(key.state)),
|
||||
.pColorAttachmentFormats = color_attachment_formats.data(),
|
||||
.depthAttachmentFormat = depth_attachment_format,
|
||||
.stencilAttachmentFormat = stencil_attachment_format,
|
||||
};
|
||||
|
||||
VkPipelineCreationFeedback creation_feedback{};
|
||||
const VkPipelineCreationFeedbackCreateInfo feedback_ci{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_CREATION_FEEDBACK_CREATE_INFO,
|
||||
.pNext = device.IsKhrDynamicRenderingSupported() ? &rendering_ci : nullptr,
|
||||
.pPipelineCreationFeedback = &creation_feedback,
|
||||
.pipelineStageCreationFeedbackCount = 0,
|
||||
.pPipelineStageCreationFeedbacks = nullptr,
|
||||
};
|
||||
const void* const create_next =
|
||||
device.IsExtPipelineCreationFeedbackSupported()
|
||||
? static_cast<const void*>(&feedback_ci)
|
||||
: (device.IsKhrDynamicRenderingSupported() ? static_cast<const void*>(&rendering_ci)
|
||||
: nullptr);
|
||||
|
||||
pipeline = device.GetLogical().CreateGraphicsPipeline({
|
||||
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.pNext = create_next,
|
||||
.flags = flags,
|
||||
.stageCount = static_cast<u32>(shader_stages.size()),
|
||||
.pStages = shader_stages.data(),
|
||||
@@ -1018,6 +1137,14 @@ void GraphicsPipeline::MakePipeline(VkRenderPass render_pass) {
|
||||
.basePipelineIndex = 0,
|
||||
}, *pipeline_cache);
|
||||
|
||||
if ((creation_feedback.flags & VK_PIPELINE_CREATION_FEEDBACK_VALID_BIT) != 0) {
|
||||
const bool cache_hit =
|
||||
(creation_feedback.flags &
|
||||
VK_PIPELINE_CREATION_FEEDBACK_APPLICATION_PIPELINE_CACHE_HIT_BIT) != 0;
|
||||
LOG_DEBUG(Render_Vulkan, "Graphics pipeline {:016X} cache_hit={} duration={}us",
|
||||
key.Hash(), cache_hit, creation_feedback.duration / 1000);
|
||||
}
|
||||
|
||||
// Log graphics pipeline creation
|
||||
if (GPU::Logging::IsActive()) {
|
||||
const std::string pipeline_info = fmt::format(
|
||||
|
||||
@@ -12,14 +12,18 @@
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "common/thread_worker.h"
|
||||
#include "shader_recompiler/shader_info.h"
|
||||
#include "video_core/engines/maxwell_3d.h"
|
||||
#include "video_core/renderer_vulkan/fixed_pipeline_state.h"
|
||||
#include "video_core/renderer_vulkan/pipeline_helper.h"
|
||||
#include "video_core/renderer_vulkan/vk_buffer_cache.h"
|
||||
#include "video_core/renderer_vulkan/vk_descriptor_buffer.h"
|
||||
#include "video_core/renderer_vulkan/vk_descriptor_pool.h"
|
||||
#include "video_core/renderer_vulkan/vk_texture_cache.h"
|
||||
#include "video_core/renderer_vulkan/vk_update_descriptor.h"
|
||||
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
||||
|
||||
namespace VideoCore {
|
||||
@@ -76,7 +80,8 @@ public:
|
||||
Scheduler& scheduler, BufferCache& buffer_cache, TextureCache& texture_cache,
|
||||
vk::PipelineCache& pipeline_cache, VideoCore::ShaderNotify* shader_notify,
|
||||
const Device& device, DescriptorPool& descriptor_pool,
|
||||
GuestDescriptorQueue& guest_descriptor_queue, Common::ThreadWorker* worker_thread,
|
||||
GuestDescriptorQueue& guest_descriptor_queue,
|
||||
DescriptorBufferRing& descriptor_buffer_ring, Common::ThreadWorker* worker_thread,
|
||||
PipelineStatistics* pipeline_statistics, RenderPassCache& render_pass_cache,
|
||||
const GraphicsPipelineCacheKey& key, std::array<vk::ShaderModule, NUM_STAGES> stages,
|
||||
const std::array<const Shader::Info*, NUM_STAGES>& infos);
|
||||
@@ -148,6 +153,7 @@ private:
|
||||
vk::PipelineCache& pipeline_cache;
|
||||
Scheduler& scheduler;
|
||||
GuestDescriptorQueue& guest_descriptor_queue;
|
||||
DescriptorBufferRing& descriptor_buffer_ring;
|
||||
|
||||
bool (*configure_func)(GraphicsPipeline*, bool){};
|
||||
|
||||
@@ -170,10 +176,14 @@ private:
|
||||
vk::DescriptorUpdateTemplate descriptor_update_template;
|
||||
vk::Pipeline pipeline;
|
||||
|
||||
DescriptorBufferLayout descriptor_buffer_layout;
|
||||
std::vector<DescriptorUpdateEntry> last_descriptor_payload;
|
||||
|
||||
std::condition_variable build_condvar;
|
||||
std::mutex build_mutex;
|
||||
std::atomic_bool is_built{false};
|
||||
bool uses_push_descriptor{false};
|
||||
bool uses_descriptor_buffer{false};
|
||||
};
|
||||
|
||||
} // namespace Vulkan
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "common/cityhash.h"
|
||||
#include "common/fs/fs.h"
|
||||
#include "common/fs/path_util.h"
|
||||
#include "common/settings.h"
|
||||
#include "common/thread_worker.h"
|
||||
#include "core/core.h"
|
||||
#include "shader_recompiler/backend/spirv/emit_spirv.h"
|
||||
@@ -45,10 +46,6 @@
|
||||
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
||||
#include "video_core/gpu_logging/gpu_logging.h"
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include "../../android/app/src/main/jni/android_settings.h"
|
||||
#endif
|
||||
|
||||
namespace Vulkan {
|
||||
|
||||
namespace {
|
||||
@@ -63,6 +60,8 @@ using VideoCommon::GenericEnvironment;
|
||||
using VideoCommon::GraphicsEnvironment;
|
||||
|
||||
constexpr u32 CACHE_VERSION = 18;
|
||||
constexpr size_t VULKAN_CACHE_FLUSH_PIPELINES = 128;
|
||||
constexpr size_t VULKAN_CACHE_FLUSH_MIN_SECONDS = 30;
|
||||
constexpr std::array<char, 8> VULKAN_CACHE_MAGIC_NUMBER{'y', 'u', 'z', 'u', 'v', 'k', 'c', 'h'};
|
||||
|
||||
template <typename Container>
|
||||
@@ -304,12 +303,8 @@ size_t GetTotalPipelineWorkers() {
|
||||
const size_t max_core_threads =
|
||||
std::max<size_t>(static_cast<size_t>(std::thread::hardware_concurrency()), 2ULL) - 1ULL;
|
||||
#ifdef __ANDROID__
|
||||
const int configured = AndroidSettings::values.pipeline_worker_count.GetValue();
|
||||
const int clamped = std::clamp(configured, 4, 8);
|
||||
const size_t desired = static_cast<size_t>(clamped);
|
||||
if (desired == 0) {
|
||||
return 1ULL;
|
||||
}
|
||||
const s32 configured = Settings::values.pipeline_worker_count.GetValue();
|
||||
const size_t desired = static_cast<size_t>(std::clamp(configured, 2, 8));
|
||||
return std::min(max_core_threads, desired);
|
||||
#else
|
||||
return max_core_threads;
|
||||
@@ -340,17 +335,20 @@ PipelineCache::PipelineCache(Tegra::MaxwellDeviceMemoryManager& device_memory_,
|
||||
const Device& device_, Scheduler& scheduler_,
|
||||
DescriptorPool& descriptor_pool_,
|
||||
GuestDescriptorQueue& guest_descriptor_queue_,
|
||||
DescriptorBufferRing& descriptor_buffer_ring_,
|
||||
RenderPassCache& render_pass_cache_, BufferCache& buffer_cache_,
|
||||
TextureCache& texture_cache_, VideoCore::ShaderNotify& shader_notify_)
|
||||
: VideoCommon::ShaderCache{device_memory_}, device{device_}, scheduler{scheduler_},
|
||||
descriptor_pool{descriptor_pool_}, guest_descriptor_queue{guest_descriptor_queue_},
|
||||
descriptor_buffer_ring{descriptor_buffer_ring_},
|
||||
render_pass_cache{render_pass_cache_}, buffer_cache{buffer_cache_},
|
||||
texture_cache{texture_cache_}, shader_notify{shader_notify_},
|
||||
use_asynchronous_shaders{Settings::values.use_asynchronous_shaders.GetValue()},
|
||||
use_vulkan_pipeline_cache{Settings::values.use_vulkan_driver_pipeline_cache.GetValue()},
|
||||
workers(device.HasBrokenParallelShaderCompiling() ? 1ULL : GetTotalPipelineWorkers(),
|
||||
"VkPipelineBuilder"),
|
||||
serialization_thread(1, "VkPipelineSerialization") {
|
||||
serialization_thread(1, "VkPipelineSerialization", {},
|
||||
Common::ThreadPlacement::Background) {
|
||||
const auto& float_control{device.FloatControlProperties()};
|
||||
const VkDriverId driver_id{device.GetDriverID()};
|
||||
const VkShaderStageFlags subgroup_stages{device.GetSubgroupSupportedStages()};
|
||||
@@ -401,6 +399,8 @@ PipelineCache::PipelineCache(Tegra::MaxwellDeviceMemoryManager& device_memory_,
|
||||
device.IsWorkgroupMemoryExplicitLayout8BitAccessSupported(),
|
||||
.support_workgroup_layout_16bit_access =
|
||||
device.IsWorkgroupMemoryExplicitLayout16BitAccessSupported(),
|
||||
.support_shader_quad_control = device.IsKhrShaderQuadControlSupported(),
|
||||
.support_quad_shuffles = device.IsSubgroupFeatureSupported(VK_SUBGROUP_FEATURE_QUAD_BIT),
|
||||
.support_vote = device.IsSubgroupFeatureSupported(VK_SUBGROUP_FEATURE_VOTE_BIT),
|
||||
.supported_subgroup_stages = supported_subgroup_stages,
|
||||
.support_viewport_index_layer_non_geometry =
|
||||
@@ -514,6 +514,11 @@ PipelineCache::PipelineCache(Tegra::MaxwellDeviceMemoryManager& device_memory_,
|
||||
dynamic_features.has_dynamic_state3_depth_clamp_enable =
|
||||
dynamic_features.has_extended_dynamic_state_3_enables &&
|
||||
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_extended_dynamic_state_3_enables &&
|
||||
device.SupportsDynamicState3LogicOpEnable();
|
||||
@@ -526,7 +531,8 @@ PipelineCache::PipelineCache(Tegra::MaxwellDeviceMemoryManager& device_memory_,
|
||||
device.IsExtVertexInputDynamicStateSupported() &&
|
||||
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 =
|
||||
device.SupportsProvokingVertexFirstMode();
|
||||
dynamic_features.has_provoking_vertex_last_mode =
|
||||
@@ -696,6 +702,10 @@ void PipelineCache::LoadDiskResources(u64 title_id, std::stop_token stop_loading
|
||||
if (use_vulkan_pipeline_cache) {
|
||||
SerializeVulkanPipelineCache(vulkan_pipeline_cache_filename, vulkan_pipeline_cache,
|
||||
CACHE_VERSION);
|
||||
size_t size = 0;
|
||||
vulkan_pipeline_cache.Read(&size, nullptr);
|
||||
last_cache_size.store(size, std::memory_order_relaxed);
|
||||
last_flush = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
if (state.statistics) {
|
||||
@@ -703,6 +713,35 @@ void PipelineCache::LoadDiskResources(u64 title_id, std::stop_token stop_loading
|
||||
}
|
||||
}
|
||||
|
||||
void PipelineCache::QueueVulkanPipelineCacheFlush() {
|
||||
if (!use_vulkan_pipeline_cache || vulkan_pipeline_cache_filename.empty()) {
|
||||
return;
|
||||
}
|
||||
if (++pipelines_since_flush < VULKAN_CACHE_FLUSH_PIPELINES) {
|
||||
return;
|
||||
}
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
const auto megabytes = last_cache_size.load(std::memory_order_relaxed) / (1024 * 1024);
|
||||
const std::chrono::seconds interval{
|
||||
std::max<size_t>(VULKAN_CACHE_FLUSH_MIN_SECONDS, megabytes)};
|
||||
if (last_flush.time_since_epoch().count() != 0 && now - last_flush < interval) {
|
||||
return;
|
||||
}
|
||||
if (flush_in_flight.exchange(true, std::memory_order_acq_rel)) {
|
||||
return;
|
||||
}
|
||||
pipelines_since_flush = 0;
|
||||
last_flush = now;
|
||||
serialization_thread.QueueWork([this] {
|
||||
SerializeVulkanPipelineCache(vulkan_pipeline_cache_filename, vulkan_pipeline_cache,
|
||||
CACHE_VERSION);
|
||||
size_t size = 0;
|
||||
vulkan_pipeline_cache.Read(&size, nullptr);
|
||||
last_cache_size.store(size, std::memory_order_relaxed);
|
||||
flush_in_flight.store(false, std::memory_order_release);
|
||||
});
|
||||
}
|
||||
|
||||
GraphicsPipeline* PipelineCache::CurrentGraphicsPipelineSlowPath() {
|
||||
const auto [pair, is_new]{graphics_cache.try_emplace(graphics_key)};
|
||||
auto& pipeline{pair->second};
|
||||
@@ -741,7 +780,7 @@ std::unique_ptr<GraphicsPipeline> PipelineCache::CreateGraphicsPipeline(
|
||||
std::span<Shader::Environment* const> envs, PipelineStatistics* statistics,
|
||||
bool build_in_parallel) try {
|
||||
auto hash = key.Hash();
|
||||
LOG_INFO(Render_Vulkan, "0x{:016x}", hash);
|
||||
LOG_DEBUG(Render_Vulkan, "{:#016x}", hash);
|
||||
size_t env_index{0};
|
||||
std::array<Shader::IR::Program, Maxwell::MaxShaderProgram> programs;
|
||||
const bool uses_vertex_a{key.unique_hashes[0] != 0};
|
||||
@@ -836,8 +875,8 @@ std::unique_ptr<GraphicsPipeline> PipelineCache::CreateGraphicsPipeline(
|
||||
Common::ThreadWorker* const thread_worker{build_in_parallel ? &workers : nullptr};
|
||||
return std::make_unique<GraphicsPipeline>(
|
||||
scheduler, buffer_cache, texture_cache, vulkan_pipeline_cache, &shader_notify, device,
|
||||
descriptor_pool, guest_descriptor_queue, thread_worker, statistics, render_pass_cache, key,
|
||||
std::move(modules), infos);
|
||||
descriptor_pool, guest_descriptor_queue, descriptor_buffer_ring, thread_worker, statistics,
|
||||
render_pass_cache, key, std::move(modules), infos);
|
||||
|
||||
} catch (const Shader::Exception& exception) {
|
||||
auto hash = key.Hash();
|
||||
@@ -877,6 +916,7 @@ std::unique_ptr<GraphicsPipeline> PipelineCache::CreateGraphicsPipeline() {
|
||||
}
|
||||
SerializePipeline(key, env_ptrs, pipeline_cache_filename, CACHE_VERSION);
|
||||
});
|
||||
QueueVulkanPipelineCacheFlush();
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
@@ -896,6 +936,7 @@ std::unique_ptr<ComputePipeline> PipelineCache::CreateComputePipeline(
|
||||
SerializePipeline(key, std::array<const GenericEnvironment*, 1>{&env_},
|
||||
pipeline_cache_filename, CACHE_VERSION);
|
||||
});
|
||||
QueueVulkanPipelineCacheFlush();
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
@@ -904,11 +945,11 @@ std::unique_ptr<ComputePipeline> PipelineCache::CreateComputePipeline(
|
||||
PipelineStatistics* statistics, bool build_in_parallel) try {
|
||||
auto hash = key.Hash();
|
||||
if (device.HasBrokenCompute()) {
|
||||
LOG_ERROR(Render_Vulkan, "Skipping 0x{:016x}", hash);
|
||||
LOG_ERROR(Render_Vulkan, "Skipping {:#016x}", hash);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LOG_INFO(Render_Vulkan, "0x{:016x}", hash);
|
||||
LOG_DEBUG(Render_Vulkan, "{:#016x}", hash);
|
||||
|
||||
Shader::Maxwell::Flow::CFG cfg{env, pools.flow_block, env.StartAddress()};
|
||||
|
||||
@@ -925,7 +966,7 @@ std::unique_ptr<ComputePipeline> PipelineCache::CreateComputePipeline(
|
||||
const u32 max_shared_memory = device.GetMaxComputeSharedMemorySize();
|
||||
if (needs_shared_mem_clamp && program.shared_memory_size > max_shared_memory) {
|
||||
LOG_WARNING(Render_Vulkan,
|
||||
"Compute shader 0x{:016x} requests {}KB shared memory but device max is {}KB - clamping",
|
||||
"Compute shader {:#016x} requests {}KB shared memory but device max is {}KB - clamping",
|
||||
key.unique_hash,
|
||||
program.shared_memory_size / 1024,
|
||||
max_shared_memory / 1024);
|
||||
@@ -957,7 +998,8 @@ std::unique_ptr<ComputePipeline> PipelineCache::CreateComputePipeline(
|
||||
}
|
||||
Common::ThreadWorker* const thread_worker{build_in_parallel ? &workers : nullptr};
|
||||
return std::make_unique<ComputePipeline>(device, scheduler, vulkan_pipeline_cache, descriptor_pool,
|
||||
guest_descriptor_queue, thread_worker, statistics,
|
||||
guest_descriptor_queue, descriptor_buffer_ring,
|
||||
thread_worker, statistics,
|
||||
&shader_notify, program.info, std::move(spv_module),
|
||||
key.unique_hash);
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
@@ -105,6 +107,7 @@ public:
|
||||
explicit PipelineCache(Tegra::MaxwellDeviceMemoryManager& device_memory_, const Device& device,
|
||||
Scheduler& scheduler, DescriptorPool& descriptor_pool,
|
||||
GuestDescriptorQueue& guest_descriptor_queue,
|
||||
DescriptorBufferRing& descriptor_buffer_ring,
|
||||
RenderPassCache& render_pass_cache, BufferCache& buffer_cache,
|
||||
TextureCache& texture_cache, VideoCore::ShaderNotify& shader_notify_);
|
||||
~PipelineCache();
|
||||
@@ -143,10 +146,13 @@ private:
|
||||
vk::PipelineCache LoadVulkanPipelineCache(const std::filesystem::path& filename,
|
||||
u32 expected_cache_version);
|
||||
|
||||
void QueueVulkanPipelineCacheFlush();
|
||||
|
||||
const Device& device;
|
||||
Scheduler& scheduler;
|
||||
DescriptorPool& descriptor_pool;
|
||||
GuestDescriptorQueue& guest_descriptor_queue;
|
||||
DescriptorBufferRing& descriptor_buffer_ring;
|
||||
RenderPassCache& render_pass_cache;
|
||||
BufferCache& buffer_cache;
|
||||
TextureCache& texture_cache;
|
||||
@@ -169,6 +175,10 @@ private:
|
||||
|
||||
std::filesystem::path vulkan_pipeline_cache_filename;
|
||||
vk::PipelineCache vulkan_pipeline_cache;
|
||||
size_t pipelines_since_flush{};
|
||||
std::chrono::steady_clock::time_point last_flush{};
|
||||
std::atomic<size_t> last_cache_size{};
|
||||
std::atomic_bool flush_in_flight{};
|
||||
|
||||
Common::ThreadWorker workers;
|
||||
Common::ThreadWorker serialization_thread;
|
||||
|
||||
@@ -296,9 +296,6 @@ void PresentManager::RecreateSwapchain(Frame* frame) {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -235,11 +235,23 @@ public:
|
||||
return;
|
||||
}
|
||||
PauseCounter();
|
||||
const auto driver_id = device.GetDriverID();
|
||||
if (driver_id == VK_DRIVER_ID_QUALCOMM_PROPRIETARY ||
|
||||
driver_id == VK_DRIVER_ID_ARM_PROPRIETARY || driver_id == VK_DRIVER_ID_MESA_TURNIP) {
|
||||
pending_sync.clear();
|
||||
if (!CanResolveHostQueries()) {
|
||||
sync_values_stash.clear();
|
||||
scheduler.RequestOutsideRenderPassOperationContext();
|
||||
scheduler.Record([buffer = *accumulation_buffer](vk::CommandBuffer cmdbuf) {
|
||||
cmdbuf.FillBuffer(buffer, 0, 8, 0);
|
||||
});
|
||||
std::function<void()> func([this] {
|
||||
amend_value = 0;
|
||||
accumulation_value = 0;
|
||||
});
|
||||
rasterizer->SyncOperation(std::move(func));
|
||||
AbandonCurrentQuery();
|
||||
num_slots_used = 0;
|
||||
first_accumulation_checkpoint = (std::numeric_limits<size_t>::max)();
|
||||
last_accumulation_checkpoint = 0;
|
||||
accumulation_since_last_sync = false;
|
||||
pending_sync.clear();
|
||||
return;
|
||||
}
|
||||
sync_values_stash.clear();
|
||||
@@ -406,6 +418,13 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
bool CanResolveHostQueries() const {
|
||||
const auto driver_id = device.GetDriverID();
|
||||
return driver_id != VK_DRIVER_ID_QUALCOMM_PROPRIETARY &&
|
||||
driver_id != VK_DRIVER_ID_ARM_PROPRIETARY &&
|
||||
driver_id != VK_DRIVER_ID_MESA_TURNIP;
|
||||
}
|
||||
|
||||
template <typename Func>
|
||||
void ApplyBankOp(VideoCommon::HostQueryBase* query, Func&& func) {
|
||||
size_t size_slots = query->size_slots;
|
||||
@@ -919,7 +938,7 @@ private:
|
||||
return;
|
||||
}
|
||||
has_flushed_end_pending = true;
|
||||
// Refresh buffers state before beginning transform feedback so counters are up-to-date
|
||||
scheduler.MarkTransformFeedbackUsed();
|
||||
UpdateBuffers();
|
||||
if (!has_started || buffers_count == 0) {
|
||||
// No counter buffers available: begin without counters
|
||||
@@ -1423,18 +1442,12 @@ void QueryCacheRuntime::HostConditionalRenderingCompareValueImpl(VideoCommon::Lo
|
||||
return;
|
||||
}
|
||||
}
|
||||
bool was_running = impl->is_hcr_running;
|
||||
if (was_running) {
|
||||
PauseHostConditionalRendering();
|
||||
}
|
||||
PauseHostConditionalRendering();
|
||||
impl->hcr_setup.buffer = impl->hcr_buffer;
|
||||
impl->hcr_setup.offset = impl->hcr_offset;
|
||||
impl->hcr_setup.flags = is_equal ? VK_CONDITIONAL_RENDERING_INVERTED_BIT_EXT : 0;
|
||||
impl->hcr_is_set = true;
|
||||
impl->is_hcr_running = false;
|
||||
if (was_running) {
|
||||
ResumeHostConditionalRendering();
|
||||
}
|
||||
}
|
||||
|
||||
void QueryCacheRuntime::HostConditionalRenderingCompareBCImpl(DAddr address, bool is_equal,
|
||||
@@ -1451,10 +1464,7 @@ void QueryCacheRuntime::HostConditionalRenderingCompareBCImpl(DAddr address, boo
|
||||
to_resolve = buffer->Handle();
|
||||
to_resolve_offset = static_cast<u32>(offset);
|
||||
}
|
||||
bool was_running = impl->is_hcr_running;
|
||||
if (was_running) {
|
||||
PauseHostConditionalRendering();
|
||||
}
|
||||
PauseHostConditionalRendering();
|
||||
impl->conditional_resolve_pass->Resolve(*impl->hcr_resolve_buffer, to_resolve,
|
||||
to_resolve_offset, compare_to_zero);
|
||||
impl->hcr_setup.buffer = *impl->hcr_resolve_buffer;
|
||||
@@ -1462,9 +1472,6 @@ void QueryCacheRuntime::HostConditionalRenderingCompareBCImpl(DAddr address, boo
|
||||
impl->hcr_setup.flags = is_equal ? 0 : VK_CONDITIONAL_RENDERING_INVERTED_BIT_EXT;
|
||||
impl->hcr_is_set = true;
|
||||
impl->is_hcr_running = false;
|
||||
if (was_running) {
|
||||
ResumeHostConditionalRendering();
|
||||
}
|
||||
}
|
||||
|
||||
bool QueryCacheRuntime::HostConditionalRenderingCompareValue(VideoCommon::LookupData object_1,
|
||||
@@ -1472,6 +1479,12 @@ bool QueryCacheRuntime::HostConditionalRenderingCompareValue(VideoCommon::Lookup
|
||||
if (!impl->device.IsExtConditionalRendering()) {
|
||||
return false;
|
||||
}
|
||||
const auto driver_id = impl->device.GetDriverID();
|
||||
if (driver_id == VK_DRIVER_ID_QUALCOMM_PROPRIETARY ||
|
||||
driver_id == VK_DRIVER_ID_ARM_PROPRIETARY || driver_id == VK_DRIVER_ID_MESA_TURNIP) {
|
||||
EndHostConditionalRendering();
|
||||
return true;
|
||||
}
|
||||
HostConditionalRenderingCompareBCImpl(object_1.address, true, true);
|
||||
return true;
|
||||
}
|
||||
@@ -1518,10 +1531,12 @@ bool QueryCacheRuntime::HostConditionalRenderingCompareValues(VideoCommon::Looku
|
||||
return false;
|
||||
}
|
||||
|
||||
auto driver_id = impl->device.GetDriverID();
|
||||
const auto driver_id = impl->device.GetDriverID();
|
||||
const bool is_gpu_high = Settings::IsGPULevelHigh();
|
||||
|
||||
if ((!is_gpu_high && driver_id == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS) || driver_id == VK_DRIVER_ID_QUALCOMM_PROPRIETARY || driver_id == VK_DRIVER_ID_ARM_PROPRIETARY || driver_id == VK_DRIVER_ID_MESA_TURNIP) {
|
||||
if ((!is_gpu_high && driver_id == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS) ||
|
||||
driver_id == VK_DRIVER_ID_QUALCOMM_PROPRIETARY ||
|
||||
driver_id == VK_DRIVER_ID_ARM_PROPRIETARY || driver_id == VK_DRIVER_ID_MESA_TURNIP) {
|
||||
EndHostConditionalRendering();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
@@ -102,8 +104,20 @@ VkViewport GetViewportState(const Device& device, const Maxwell& regs, size_t in
|
||||
.maxDepth = src.translate_z + src.scale_z,
|
||||
};
|
||||
if (!device.IsExtDepthRangeUnrestrictedSupported()) {
|
||||
const float unclamped_min = viewport.minDepth;
|
||||
const float unclamped_max = viewport.maxDepth;
|
||||
viewport.minDepth = std::clamp(viewport.minDepth, 0.0f, 1.0f);
|
||||
viewport.maxDepth = std::clamp(viewport.maxDepth, 0.0f, 1.0f);
|
||||
if (viewport.minDepth != unclamped_min || viewport.maxDepth != unclamped_max) {
|
||||
static std::atomic<u32> reported{0};
|
||||
if (reported.fetch_add(1, std::memory_order_relaxed) < 32) {
|
||||
LOG_WARNING(Render_Vulkan,
|
||||
"Depth range clamped: viewport={} mode={} translate_z={} scale_z={} "
|
||||
"range=[{}, {}] -> [{}, {}]",
|
||||
index, static_cast<u32>(regs.depth_mode), src.translate_z, src.scale_z,
|
||||
unclamped_min, unclamped_max, viewport.minDepth, viewport.maxDepth);
|
||||
}
|
||||
}
|
||||
}
|
||||
return viewport;
|
||||
}
|
||||
@@ -203,7 +217,10 @@ RasterizerVulkan::RasterizerVulkan(Core::Frontend::EmuWindow& emu_window_, Tegra
|
||||
: gpu{gpu_}, device_memory{device_memory_}, device{device_},
|
||||
memory_allocator{memory_allocator_}, state_tracker{state_tracker_}, scheduler{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,
|
||||
device.IsExtDescriptorBufferSupported()),
|
||||
compute_pass_descriptor_queue(device, UpdateDescriptorQueue::COMPUTE_FRAME_PAYLOAD_SIZE),
|
||||
descriptor_buffer_ring(device, memory_allocator),
|
||||
blit_image(device, scheduler, state_tracker, descriptor_pool), render_pass_cache(device),
|
||||
texture_cache_runtime{
|
||||
device, scheduler, memory_allocator, staging_pool,
|
||||
@@ -216,14 +233,35 @@ RasterizerVulkan::RasterizerVulkan(Core::Frontend::EmuWindow& emu_window_, Tegra
|
||||
staging_pool, compute_pass_descriptor_queue, descriptor_pool, texture_cache),
|
||||
query_cache(gpu, *this, device_memory, query_cache_runtime),
|
||||
pipeline_cache(device_memory, device, scheduler, descriptor_pool, guest_descriptor_queue,
|
||||
render_pass_cache, buffer_cache, texture_cache, gpu.ShaderNotify()),
|
||||
descriptor_buffer_ring, render_pass_cache, buffer_cache, texture_cache,
|
||||
gpu.ShaderNotify()),
|
||||
accelerate_dma(buffer_cache, texture_cache, scheduler),
|
||||
fence_manager(*this, gpu, texture_cache, buffer_cache, query_cache, device, scheduler),
|
||||
wfi_event(device.GetLogical().CreateEvent()) {
|
||||
scheduler.SetQueryCache(query_cache);
|
||||
if (Settings::values.use_unified_memory.GetValue()) {
|
||||
buffer_cache_runtime.TryEnableUnifiedMemory(
|
||||
device_memory.GetPhysicalBase(), device_memory.GetPhysicalSize(),
|
||||
device_memory.GetBackingHardwareBuffers(),
|
||||
device_memory.GetBackingHardwareBufferWindowSize());
|
||||
}
|
||||
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() {
|
||||
memory_allocator.SetReclaimCallback(nullptr);
|
||||
scheduler.WaitWorker();
|
||||
scheduler.Finish();
|
||||
}
|
||||
@@ -241,11 +279,13 @@ void RasterizerVulkan::PrepareDraw(bool is_indexed, Func&& draw_func) {
|
||||
if (!pipeline) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock{buffer_cache.mutex, texture_cache.mutex};
|
||||
// update engine as channel may be different.
|
||||
pipeline->SetEngine(maxwell3d, gpu_memory);
|
||||
if (!pipeline->Configure(is_indexed))
|
||||
return;
|
||||
{
|
||||
std::scoped_lock lock{buffer_cache.mutex, texture_cache.mutex};
|
||||
pipeline->SetEngine(maxwell3d, gpu_memory);
|
||||
if (!pipeline->Configure(is_indexed)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
UpdateDynamicStates();
|
||||
|
||||
@@ -359,7 +399,6 @@ void RasterizerVulkan::DrawTexture() {
|
||||
|
||||
UpdateDynamicStates();
|
||||
|
||||
query_cache.NotifySegment(true);
|
||||
query_cache.CounterEnable(VideoCommon::QueryType::ZPassPixelCount64, maxwell3d->regs.zpass_pixel_count_enable);
|
||||
const auto& draw_texture_state = maxwell3d->draw_manager.draw_texture_state;
|
||||
const auto& sampler = texture_cache.GetSampler(draw_texture_state.src_sampler, false);
|
||||
@@ -420,15 +459,21 @@ void RasterizerVulkan::Clear(u32 layer_count) {
|
||||
const bool ds_deferrable =
|
||||
!ds_used || ((!framebuffer->HasAspectDepthBit() || use_depth) &&
|
||||
(!framebuffer->HasAspectStencilBit() || use_stencil) && !stencil_partial);
|
||||
const bool can_defer_clear = ENABLE_DEFERRED_CLEAR && !regs.clear_control.use_scissor &&
|
||||
regs.clear_surface.layer == 0 &&
|
||||
!scheduler.IsRenderPassActive() &&
|
||||
(!use_color || color_full_channels) && ds_deferrable;
|
||||
const bool clear_shape_deferrable = ENABLE_DEFERRED_CLEAR &&
|
||||
!regs.clear_control.use_scissor &&
|
||||
regs.clear_surface.layer == 0 &&
|
||||
(!use_color || color_full_channels) && ds_deferrable;
|
||||
// An open pass normally blocks deferral, which drops the clear to ClearAttachments inside the
|
||||
// pass and also loses the MSAA store discard, since that only applies when a clear is folded
|
||||
// into the begin. A pass whose BeginRendering has not been recorded yet can be retracted for
|
||||
// free, so the clear becomes a load op after all. Only retract when it will actually be used.
|
||||
const bool can_defer_clear =
|
||||
clear_shape_deferrable &&
|
||||
(!scheduler.IsRenderPassActive() || scheduler.RetractUnrecordedRenderPass());
|
||||
if (!can_defer_clear) {
|
||||
scheduler.RequestRenderpass(framebuffer);
|
||||
}
|
||||
|
||||
query_cache.NotifySegment(true);
|
||||
query_cache.CounterEnable(VideoCommon::QueryType::ZPassPixelCount64, maxwell3d->regs.zpass_pixel_count_enable);
|
||||
u32 up_scale = 1;
|
||||
u32 down_shift = 0;
|
||||
@@ -673,7 +718,6 @@ void RasterizerVulkan::FlushRegion(DAddr addr, u64 size, VideoCommon::CacheType
|
||||
texture_cache.DownloadMemory(addr, size);
|
||||
}
|
||||
if ((True(which & VideoCommon::CacheType::BufferCache))) {
|
||||
std::scoped_lock lock{buffer_cache.mutex};
|
||||
buffer_cache.DownloadMemory(addr, size);
|
||||
}
|
||||
if ((True(which & VideoCommon::CacheType::QueryCache))) {
|
||||
@@ -771,12 +815,15 @@ bool RasterizerVulkan::OnCPUWrite(DAddr addr, u64 size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static constexpr bool ENABLE_TEXTURE_CACHE_INVALIDATION_SKIP = true;
|
||||
|
||||
void RasterizerVulkan::OnCacheInvalidation(DAddr addr, u64 size) {
|
||||
if (addr == 0 || size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
if (!ENABLE_TEXTURE_CACHE_INVALIDATION_SKIP ||
|
||||
device_memory.IsRegionTextureCached(addr, size)) {
|
||||
std::scoped_lock lock{texture_cache.mutex};
|
||||
texture_cache.WriteMemory(addr, size);
|
||||
}
|
||||
@@ -880,8 +927,12 @@ void RasterizerVulkan::FlushCommands() {
|
||||
|
||||
void RasterizerVulkan::TickFrame() {
|
||||
draw_counter = 0;
|
||||
auto& master_semaphore = scheduler.GetMasterSemaphore();
|
||||
master_semaphore.Refresh();
|
||||
vk::TickDeletionQueue(master_semaphore.KnownGpuTick());
|
||||
guest_descriptor_queue.TickFrame();
|
||||
compute_pass_descriptor_queue.TickFrame();
|
||||
descriptor_buffer_ring.TickFrame();
|
||||
fence_manager.TickFrame();
|
||||
staging_pool.TickFrame();
|
||||
{
|
||||
@@ -969,11 +1020,11 @@ void RasterizerVulkan::LoadDiskResources(u64 title_id, std::stop_token stop_load
|
||||
|
||||
void RasterizerVulkan::FlushWork() {
|
||||
#ifdef __ANDROID__
|
||||
static constexpr u32 DRAWS_TO_DISPATCH = 512;
|
||||
static constexpr u32 CHECK_MASK = 3;
|
||||
static constexpr u32 DRAWS_TO_DISPATCH = 1024;
|
||||
static constexpr u32 CHECK_MASK = 63;
|
||||
#else
|
||||
static constexpr u32 DRAWS_TO_DISPATCH = 4096;
|
||||
static constexpr u32 CHECK_MASK = 7;
|
||||
static constexpr u32 CHECK_MASK = 31;
|
||||
#endif // __ANDROID__
|
||||
|
||||
static_assert(DRAWS_TO_DISPATCH % (CHECK_MASK + 1) == 0);
|
||||
@@ -1279,6 +1330,13 @@ void RasterizerVulkan::UpdateDepthBias(Tegra::Engines::Maxwell3D::Regs& regs) {
|
||||
regs.zeta.format == Tegra::DepthFormat::S8Z24_UNORM ||
|
||||
regs.zeta.format == Tegra::DepthFormat::V8Z24_UNORM;
|
||||
|
||||
const bool is_float_depth = regs.zeta.format == Tegra::DepthFormat::Z32_FLOAT ||
|
||||
regs.zeta.format == Tegra::DepthFormat::Z32_FLOAT_X24S8_UINT;
|
||||
|
||||
if (is_float_depth && !device.IsExtDepthBiasControlSupported()) {
|
||||
units /= static_cast<float>(1ULL << (32 - 24));
|
||||
}
|
||||
|
||||
if (is_d24 && !device.SupportsD24DepthBuffer()) {
|
||||
static constexpr const size_t length = sizeof(NEEDS_D24) / sizeof(NEEDS_D24[0]);
|
||||
|
||||
@@ -1451,7 +1509,10 @@ void RasterizerVulkan::UpdateLineWidth(Tegra::Engines::Maxwell3D::Regs& regs) {
|
||||
}
|
||||
const float width =
|
||||
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) {
|
||||
@@ -1548,7 +1609,10 @@ void RasterizerVulkan::UpdateLineStippleEnable(Tegra::Engines::Maxwell3D::Regs&
|
||||
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);
|
||||
});
|
||||
}
|
||||
@@ -1562,28 +1626,24 @@ void RasterizerVulkan::UpdateLineRasterizationMode(Tegra::Engines::Maxwell3D::Re
|
||||
}
|
||||
|
||||
if (!device.SupportsDynamicState3LineRasterizationMode()) {
|
||||
static std::once_flag warn_missing_rect;
|
||||
std::call_once(warn_missing_rect, [] {
|
||||
static std::once_flag warn_missing_dynamic_state;
|
||||
std::call_once(warn_missing_dynamic_state, [] {
|
||||
LOG_WARNING(Render_Vulkan,
|
||||
"Driver lacks rectangular line rasterization support; skipping dynamic "
|
||||
"line state updates");
|
||||
"Driver lacks dynamic line rasterization mode; the pipeline static value "
|
||||
"is used instead");
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const bool wants_smooth = regs.line_anti_alias_enable != 0;
|
||||
VkLineRasterizationModeEXT mode = VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT;
|
||||
if (wants_smooth) {
|
||||
if (device.SupportsSmoothLines()) {
|
||||
mode = VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT;
|
||||
} else {
|
||||
static std::once_flag warn_missing_smooth;
|
||||
std::call_once(warn_missing_smooth, [] {
|
||||
LOG_WARNING(Render_Vulkan,
|
||||
"Line anti-aliasing requested but smoothLines feature unavailable; "
|
||||
"using rectangular rasterization");
|
||||
});
|
||||
}
|
||||
const VkLineRasterizationModeEXT mode = device.GetLineRasterizationMode(wants_smooth);
|
||||
if (wants_smooth && mode != VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT) {
|
||||
static std::once_flag warn_missing_smooth;
|
||||
std::call_once(warn_missing_smooth, [] {
|
||||
LOG_WARNING(Render_Vulkan,
|
||||
"Line anti-aliasing requested but smoothLines feature unavailable; "
|
||||
"falling back to the closest supported mode");
|
||||
});
|
||||
}
|
||||
scheduler.Record([mode](vk::CommandBuffer cmdbuf) {
|
||||
cmdbuf.SetLineRasterizationModeEXT(mode);
|
||||
@@ -1643,12 +1703,7 @@ void RasterizerVulkan::UpdateDepthClampEnable(Tegra::Engines::Maxwell3D::Regs& r
|
||||
if (!device.SupportsDynamicState3DepthClampEnable()) {
|
||||
return;
|
||||
}
|
||||
bool is_enabled = !(regs.viewport_clip_control.geometry_clip ==
|
||||
Maxwell::ViewportClipControl::GeometryClip::Passthrough ||
|
||||
regs.viewport_clip_control.geometry_clip ==
|
||||
Maxwell::ViewportClipControl::GeometryClip::FrustumXYZ ||
|
||||
regs.viewport_clip_control.geometry_clip ==
|
||||
Maxwell::ViewportClipControl::GeometryClip::FrustumZ);
|
||||
const bool is_enabled = IsDepthClampEnabled(regs, device.IsExtDepthClipEnableSupported());
|
||||
scheduler.Record(
|
||||
[is_enabled](vk::CommandBuffer cmdbuf) { cmdbuf.SetDepthClampEnableEXT(is_enabled); });
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "video_core/rasterizer_interface.h"
|
||||
#include "video_core/renderer_vulkan/blit_image.h"
|
||||
#include "video_core/renderer_vulkan/vk_buffer_cache.h"
|
||||
#include "video_core/renderer_vulkan/vk_descriptor_buffer.h"
|
||||
#include "video_core/renderer_vulkan/vk_descriptor_pool.h"
|
||||
#include "video_core/renderer_vulkan/vk_fence_manager.h"
|
||||
#include "video_core/renderer_vulkan/vk_pipeline_cache.h"
|
||||
@@ -179,7 +180,6 @@ private:
|
||||
void UpdateRasterizerDiscardEnable(Tegra::Engines::Maxwell3D::Regs& regs);
|
||||
void UpdateConservativeRasterizationMode(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 UpdateDepthBiasEnable(Tegra::Engines::Maxwell3D::Regs& regs);
|
||||
void UpdateLogicOpEnable(Tegra::Engines::Maxwell3D::Regs& regs);
|
||||
@@ -207,6 +207,7 @@ private:
|
||||
DescriptorPool descriptor_pool;
|
||||
GuestDescriptorQueue guest_descriptor_queue;
|
||||
ComputePassDescriptorQueue compute_pass_descriptor_queue;
|
||||
DescriptorBufferRing descriptor_buffer_ring;
|
||||
BlitImageHelper blit_image;
|
||||
RenderPassCache render_pass_cache;
|
||||
|
||||
|
||||
@@ -12,10 +12,7 @@ ResourcePool::ResourcePool(MasterSemaphore& master_semaphore_, size_t grow_step_
|
||||
: master_semaphore{&master_semaphore_}, grow_step{grow_step_} {}
|
||||
|
||||
size_t ResourcePool::CommitResource() {
|
||||
// Refresh semaphore to query updated results
|
||||
master_semaphore->Refresh();
|
||||
const u64 gpu_tick = master_semaphore->KnownGpuTick();
|
||||
const auto search = [this, gpu_tick](size_t begin, size_t end) -> std::optional<size_t> {
|
||||
const auto search = [this](size_t begin, size_t end, u64 gpu_tick) -> std::optional<size_t> {
|
||||
for (size_t iterator = begin; iterator < end; ++iterator) {
|
||||
if (gpu_tick >= ticks[iterator]) {
|
||||
ticks[iterator] = master_semaphore->CurrentTick();
|
||||
@@ -24,11 +21,17 @@ size_t ResourcePool::CommitResource() {
|
||||
}
|
||||
return std::nullopt;
|
||||
};
|
||||
// Try to find a free resource from the hinted position to the end.
|
||||
std::optional<size_t> found = search(hint_iterator, ticks.size());
|
||||
const auto find_free = [&](u64 gpu_tick) -> std::optional<size_t> {
|
||||
std::optional<size_t> result = search(hint_iterator, ticks.size(), gpu_tick);
|
||||
if (!result) {
|
||||
result = search(0, hint_iterator, gpu_tick);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
std::optional<size_t> found = find_free(master_semaphore->KnownGpuTick());
|
||||
if (!found) {
|
||||
// Search from beginning to the hinted position.
|
||||
found = search(0, hint_iterator);
|
||||
master_semaphore->Refresh();
|
||||
found = find_free(master_semaphore->KnownGpuTick());
|
||||
if (!found) {
|
||||
// Both searches failed, the pool is full; handle it.
|
||||
const size_t free_resource = ManageOverflow();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user