summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/uuid.h5
-rw-r--r--src/core/hle/service/am/applets/applet_controller.cpp21
-rw-r--r--src/core/hle/service/am/applets/applet_controller.h15
-rw-r--r--src/input_common/sdl/sdl_impl.cpp61
-rw-r--r--src/video_core/buffer_cache/buffer_cache.h78
-rw-r--r--src/video_core/engines/maxwell_dma.cpp20
-rw-r--r--src/video_core/engines/maxwell_dma.h2
-rw-r--r--src/video_core/renderer_opengl/gl_buffer_cache.cpp6
-rw-r--r--src/video_core/renderer_opengl/gl_buffer_cache.h2
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp5
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h2
-rw-r--r--src/video_core/renderer_opengl/gl_texture_cache.h2
-rw-r--r--src/video_core/renderer_vulkan/vk_buffer_cache.cpp24
-rw-r--r--src/video_core/renderer_vulkan/vk_buffer_cache.h2
-rw-r--r--src/video_core/renderer_vulkan/vk_rasterizer.cpp5
-rw-r--r--src/video_core/renderer_vulkan/vk_rasterizer.h2
-rw-r--r--src/yuzu/bootmanager.cpp6
-rw-r--r--src/yuzu/configuration/configure_input_player.cpp47
-rw-r--r--src/yuzu/configuration/configure_input_player.ui44
-rw-r--r--src/yuzu_cmd/config.cpp1
-rw-r--r--src/yuzu_cmd/default_ini.h4
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.cpp44
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp6
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h2
-rw-r--r--src/yuzu_cmd/yuzu.cpp2
25 files changed, 363 insertions, 45 deletions
diff --git a/src/common/uuid.h b/src/common/uuid.h
index 2e7a18405..0ffa37e7c 100644
--- a/src/common/uuid.h
+++ b/src/common/uuid.h
@@ -20,12 +20,11 @@ struct UUID {
20 constexpr explicit UUID(const u64 lo, const u64 hi) : uuid{{lo, hi}} {} 20 constexpr explicit UUID(const u64 lo, const u64 hi) : uuid{{lo, hi}} {}
21 21
22 [[nodiscard]] constexpr explicit operator bool() const { 22 [[nodiscard]] constexpr explicit operator bool() const {
23 return uuid[0] != INVALID_UUID[0] && uuid[1] != INVALID_UUID[1]; 23 return uuid != INVALID_UUID;
24 } 24 }
25 25
26 [[nodiscard]] constexpr bool operator==(const UUID& rhs) const { 26 [[nodiscard]] constexpr bool operator==(const UUID& rhs) const {
27 // TODO(DarkLordZach): Replace with uuid == rhs.uuid with C++20 27 return uuid == rhs.uuid;
28 return uuid[0] == rhs.uuid[0] && uuid[1] == rhs.uuid[1];
29 } 28 }
30 29
31 [[nodiscard]] constexpr bool operator!=(const UUID& rhs) const { 30 [[nodiscard]] constexpr bool operator!=(const UUID& rhs) const {
diff --git a/src/core/hle/service/am/applets/applet_controller.cpp b/src/core/hle/service/am/applets/applet_controller.cpp
index 12682effe..2721679c1 100644
--- a/src/core/hle/service/am/applets/applet_controller.cpp
+++ b/src/core/hle/service/am/applets/applet_controller.cpp
@@ -87,6 +87,10 @@ void Controller::Initialize() {
87 case sizeof(ControllerUpdateFirmwareArg): 87 case sizeof(ControllerUpdateFirmwareArg):
88 controller_private_arg.mode = ControllerSupportMode::ShowControllerFirmwareUpdate; 88 controller_private_arg.mode = ControllerSupportMode::ShowControllerFirmwareUpdate;
89 break; 89 break;
90 case sizeof(ControllerKeyRemappingArg):
91 controller_private_arg.mode =
92 ControllerSupportMode::ShowControllerKeyRemappingForSystem;
93 break;
90 default: 94 default:
91 UNIMPLEMENTED_MSG("Unknown ControllerPrivateArg mode={} with arg_size={}", 95 UNIMPLEMENTED_MSG("Unknown ControllerPrivateArg mode={} with arg_size={}",
92 controller_private_arg.mode, controller_private_arg.arg_size); 96 controller_private_arg.mode, controller_private_arg.arg_size);
@@ -99,7 +103,9 @@ void Controller::Initialize() {
99 // This is always 0 (Application) except with ShowControllerFirmwareUpdateForSystem. 103 // This is always 0 (Application) except with ShowControllerFirmwareUpdateForSystem.
100 if (controller_private_arg.caller >= ControllerSupportCaller::MaxControllerSupportCaller) { 104 if (controller_private_arg.caller >= ControllerSupportCaller::MaxControllerSupportCaller) {
101 if (controller_private_arg.flag_1 && 105 if (controller_private_arg.flag_1 &&
102 controller_private_arg.mode == ControllerSupportMode::ShowControllerFirmwareUpdate) { 106 (controller_private_arg.mode == ControllerSupportMode::ShowControllerFirmwareUpdate ||
107 controller_private_arg.mode ==
108 ControllerSupportMode::ShowControllerKeyRemappingForSystem)) {
103 controller_private_arg.caller = ControllerSupportCaller::System; 109 controller_private_arg.caller = ControllerSupportCaller::System;
104 } else { 110 } else {
105 controller_private_arg.caller = ControllerSupportCaller::Application; 111 controller_private_arg.caller = ControllerSupportCaller::Application;
@@ -121,6 +127,7 @@ void Controller::Initialize() {
121 std::memcpy(&controller_user_arg_old, user_arg.data(), user_arg.size()); 127 std::memcpy(&controller_user_arg_old, user_arg.data(), user_arg.size());
122 break; 128 break;
123 case ControllerAppletVersion::Version7: 129 case ControllerAppletVersion::Version7:
130 case ControllerAppletVersion::Version8:
124 ASSERT(user_arg.size() == sizeof(ControllerSupportArgNew)); 131 ASSERT(user_arg.size() == sizeof(ControllerSupportArgNew));
125 std::memcpy(&controller_user_arg_new, user_arg.data(), user_arg.size()); 132 std::memcpy(&controller_user_arg_new, user_arg.data(), user_arg.size());
126 break; 133 break;
@@ -143,6 +150,16 @@ void Controller::Initialize() {
143 std::memcpy(&controller_update_arg, update_arg.data(), update_arg.size()); 150 std::memcpy(&controller_update_arg, update_arg.data(), update_arg.size());
144 break; 151 break;
145 } 152 }
153 case ControllerSupportMode::ShowControllerKeyRemappingForSystem: {
154 const auto remapping_arg_storage = broker.PopNormalDataToApplet();
155 ASSERT(remapping_arg_storage != nullptr);
156
157 const auto& remapping_arg = remapping_arg_storage->GetData();
158 ASSERT(remapping_arg.size() == sizeof(ControllerKeyRemappingArg));
159
160 std::memcpy(&controller_key_remapping_arg, remapping_arg.data(), remapping_arg.size());
161 break;
162 }
146 default: { 163 default: {
147 UNIMPLEMENTED_MSG("Unimplemented ControllerSupportMode={}", controller_private_arg.mode); 164 UNIMPLEMENTED_MSG("Unimplemented ControllerSupportMode={}", controller_private_arg.mode);
148 break; 165 break;
@@ -179,6 +196,7 @@ void Controller::Execute() {
179 std::vector<ExplainText>(controller_user_arg_old.explain_text.begin(), 196 std::vector<ExplainText>(controller_user_arg_old.explain_text.begin(),
180 controller_user_arg_old.explain_text.end())); 197 controller_user_arg_old.explain_text.end()));
181 case ControllerAppletVersion::Version7: 198 case ControllerAppletVersion::Version7:
199 case ControllerAppletVersion::Version8:
182 default: 200 default:
183 return ConvertToFrontendParameters( 201 return ConvertToFrontendParameters(
184 controller_private_arg, controller_user_arg_new.header, 202 controller_private_arg, controller_user_arg_new.header,
@@ -210,6 +228,7 @@ void Controller::Execute() {
210 } 228 }
211 case ControllerSupportMode::ShowControllerStrapGuide: 229 case ControllerSupportMode::ShowControllerStrapGuide:
212 case ControllerSupportMode::ShowControllerFirmwareUpdate: 230 case ControllerSupportMode::ShowControllerFirmwareUpdate:
231 case ControllerSupportMode::ShowControllerKeyRemappingForSystem:
213 UNIMPLEMENTED_MSG("ControllerSupportMode={} is not implemented", 232 UNIMPLEMENTED_MSG("ControllerSupportMode={} is not implemented",
214 controller_private_arg.mode); 233 controller_private_arg.mode);
215 ConfigurationComplete(); 234 ConfigurationComplete();
diff --git a/src/core/hle/service/am/applets/applet_controller.h b/src/core/hle/service/am/applets/applet_controller.h
index 20617e91f..0a34c4fc0 100644
--- a/src/core/hle/service/am/applets/applet_controller.h
+++ b/src/core/hle/service/am/applets/applet_controller.h
@@ -25,13 +25,15 @@ enum class ControllerAppletVersion : u32_le {
25 Version3 = 0x3, // 1.0.0 - 2.3.0 25 Version3 = 0x3, // 1.0.0 - 2.3.0
26 Version4 = 0x4, // 3.0.0 - 5.1.0 26 Version4 = 0x4, // 3.0.0 - 5.1.0
27 Version5 = 0x5, // 6.0.0 - 7.0.1 27 Version5 = 0x5, // 6.0.0 - 7.0.1
28 Version7 = 0x7, // 8.0.0+ 28 Version7 = 0x7, // 8.0.0 - 10.2.0
29 Version8 = 0x8, // 11.0.0+
29}; 30};
30 31
31enum class ControllerSupportMode : u8 { 32enum class ControllerSupportMode : u8 {
32 ShowControllerSupport, 33 ShowControllerSupport,
33 ShowControllerStrapGuide, 34 ShowControllerStrapGuide,
34 ShowControllerFirmwareUpdate, 35 ShowControllerFirmwareUpdate,
36 ShowControllerKeyRemappingForSystem,
35 37
36 MaxControllerSupportMode, 38 MaxControllerSupportMode,
37}; 39};
@@ -78,7 +80,7 @@ struct ControllerSupportArgOld {
78static_assert(sizeof(ControllerSupportArgOld) == 0x21C, 80static_assert(sizeof(ControllerSupportArgOld) == 0x21C,
79 "ControllerSupportArgOld has incorrect size."); 81 "ControllerSupportArgOld has incorrect size.");
80 82
81// LibraryAppletVersion 0x7 83// LibraryAppletVersion 0x7, 0x8
82struct ControllerSupportArgNew { 84struct ControllerSupportArgNew {
83 ControllerSupportArgHeader header{}; 85 ControllerSupportArgHeader header{};
84 std::array<IdentificationColor, 8> identification_colors{}; 86 std::array<IdentificationColor, 8> identification_colors{};
@@ -95,6 +97,14 @@ struct ControllerUpdateFirmwareArg {
95static_assert(sizeof(ControllerUpdateFirmwareArg) == 0x4, 97static_assert(sizeof(ControllerUpdateFirmwareArg) == 0x4,
96 "ControllerUpdateFirmwareArg has incorrect size."); 98 "ControllerUpdateFirmwareArg has incorrect size.");
97 99
100struct ControllerKeyRemappingArg {
101 u64 unknown{};
102 u32 unknown_2{};
103 INSERT_PADDING_WORDS(1);
104};
105static_assert(sizeof(ControllerKeyRemappingArg) == 0x10,
106 "ControllerKeyRemappingArg has incorrect size.");
107
98struct ControllerSupportResultInfo { 108struct ControllerSupportResultInfo {
99 s8 player_count{}; 109 s8 player_count{};
100 INSERT_PADDING_BYTES(3); 110 INSERT_PADDING_BYTES(3);
@@ -128,6 +138,7 @@ private:
128 ControllerSupportArgOld controller_user_arg_old; 138 ControllerSupportArgOld controller_user_arg_old;
129 ControllerSupportArgNew controller_user_arg_new; 139 ControllerSupportArgNew controller_user_arg_new;
130 ControllerUpdateFirmwareArg controller_update_arg; 140 ControllerUpdateFirmwareArg controller_update_arg;
141 ControllerKeyRemappingArg controller_key_remapping_arg;
131 bool complete{false}; 142 bool complete{false};
132 ResultCode status{ResultSuccess}; 143 ResultCode status{ResultSuccess};
133 bool is_single_mode{false}; 144 bool is_single_mode{false};
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp
index 1656b85fb..70a0ba09c 100644
--- a/src/input_common/sdl/sdl_impl.cpp
+++ b/src/input_common/sdl/sdl_impl.cpp
@@ -115,6 +115,41 @@ public:
115 return state.buttons.at(button); 115 return state.buttons.at(button);
116 } 116 }
117 117
118 bool ToggleButton(int button) {
119 std::lock_guard lock{mutex};
120
121 if (!state.toggle_buttons.contains(button) || !state.lock_buttons.contains(button)) {
122 state.toggle_buttons.insert_or_assign(button, false);
123 state.lock_buttons.insert_or_assign(button, false);
124 }
125
126 const bool button_state = state.toggle_buttons.at(button);
127 const bool button_lock = state.lock_buttons.at(button);
128
129 if (button_lock) {
130 return button_state;
131 }
132
133 state.lock_buttons.insert_or_assign(button, true);
134
135 if (button_state) {
136 state.toggle_buttons.insert_or_assign(button, false);
137 } else {
138 state.toggle_buttons.insert_or_assign(button, true);
139 }
140
141 return !button_state;
142 }
143
144 bool UnlockButton(int button) {
145 std::lock_guard lock{mutex};
146 if (!state.toggle_buttons.contains(button)) {
147 return false;
148 }
149 state.lock_buttons.insert_or_assign(button, false);
150 return state.toggle_buttons.at(button);
151 }
152
118 void SetAxis(int axis, Sint16 value) { 153 void SetAxis(int axis, Sint16 value) {
119 std::lock_guard lock{mutex}; 154 std::lock_guard lock{mutex};
120 state.axes.insert_or_assign(axis, value); 155 state.axes.insert_or_assign(axis, value);
@@ -241,6 +276,8 @@ public:
241private: 276private:
242 struct State { 277 struct State {
243 std::unordered_map<int, bool> buttons; 278 std::unordered_map<int, bool> buttons;
279 std::unordered_map<int, bool> toggle_buttons{};
280 std::unordered_map<int, bool> lock_buttons{};
244 std::unordered_map<int, Sint16> axes; 281 std::unordered_map<int, Sint16> axes;
245 std::unordered_map<int, Uint8> hats; 282 std::unordered_map<int, Uint8> hats;
246 } state; 283 } state;
@@ -402,16 +439,25 @@ void SDLState::CloseJoysticks() {
402 439
403class SDLButton final : public Input::ButtonDevice { 440class SDLButton final : public Input::ButtonDevice {
404public: 441public:
405 explicit SDLButton(std::shared_ptr<SDLJoystick> joystick_, int button_) 442 explicit SDLButton(std::shared_ptr<SDLJoystick> joystick_, int button_, bool toggle_)
406 : joystick(std::move(joystick_)), button(button_) {} 443 : joystick(std::move(joystick_)), button(button_), toggle(toggle_) {}
407 444
408 bool GetStatus() const override { 445 bool GetStatus() const override {
409 return joystick->GetButton(button); 446 const bool button_state = joystick->GetButton(button);
447 if (!toggle) {
448 return button_state;
449 }
450
451 if (button_state) {
452 return joystick->ToggleButton(button);
453 }
454 return joystick->UnlockButton(button);
410 } 455 }
411 456
412private: 457private:
413 std::shared_ptr<SDLJoystick> joystick; 458 std::shared_ptr<SDLJoystick> joystick;
414 int button; 459 int button;
460 bool toggle;
415}; 461};
416 462
417class SDLDirectionButton final : public Input::ButtonDevice { 463class SDLDirectionButton final : public Input::ButtonDevice {
@@ -635,6 +681,7 @@ public:
635 std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override { 681 std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override {
636 const std::string guid = params.Get("guid", "0"); 682 const std::string guid = params.Get("guid", "0");
637 const int port = params.Get("port", 0); 683 const int port = params.Get("port", 0);
684 const auto toggle = params.Get("toggle", false);
638 685
639 auto joystick = state.GetSDLJoystickByGUID(guid, port); 686 auto joystick = state.GetSDLJoystickByGUID(guid, port);
640 687
@@ -660,7 +707,8 @@ public:
660 707
661 if (params.Has("axis")) { 708 if (params.Has("axis")) {
662 const int axis = params.Get("axis", 0); 709 const int axis = params.Get("axis", 0);
663 const float threshold = params.Get("threshold", 0.5f); 710 // Convert range from (0.0, 1.0) to (-1.0, 1.0)
711 const float threshold = (params.Get("threshold", 0.5f) - 0.5f) * 2.0f;
664 const std::string direction_name = params.Get("direction", ""); 712 const std::string direction_name = params.Get("direction", "");
665 bool trigger_if_greater; 713 bool trigger_if_greater;
666 if (direction_name == "+") { 714 if (direction_name == "+") {
@@ -679,7 +727,7 @@ public:
679 const int button = params.Get("button", 0); 727 const int button = params.Get("button", 0);
680 // This is necessary so accessing GetButton with button won't crash 728 // This is necessary so accessing GetButton with button won't crash
681 joystick->SetButton(button, false); 729 joystick->SetButton(button, false);
682 return std::make_unique<SDLButton>(joystick, button); 730 return std::make_unique<SDLButton>(joystick, button, toggle);
683 } 731 }
684 732
685private: 733private:
@@ -933,12 +981,11 @@ Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid
933 params.Set("port", port); 981 params.Set("port", port);
934 params.Set("guid", std::move(guid)); 982 params.Set("guid", std::move(guid));
935 params.Set("axis", axis); 983 params.Set("axis", axis);
984 params.Set("threshold", "0.5");
936 if (value > 0) { 985 if (value > 0) {
937 params.Set("direction", "+"); 986 params.Set("direction", "+");
938 params.Set("threshold", "0.5");
939 } else { 987 } else {
940 params.Set("direction", "-"); 988 params.Set("direction", "-");
941 params.Set("threshold", "-0.5");
942 } 989 }
943 return params; 990 return params;
944} 991}
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h
index 2871682f6..7373cb62d 100644
--- a/src/video_core/buffer_cache/buffer_cache.h
+++ b/src/video_core/buffer_cache/buffer_cache.h
@@ -164,11 +164,16 @@ public:
164 /// Pop asynchronous downloads 164 /// Pop asynchronous downloads
165 void PopAsyncFlushes(); 165 void PopAsyncFlushes();
166 166
167 [[nodiscard]] bool DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount); 167 bool DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount);
168
169 bool DMAClear(GPUVAddr src_address, u64 amount, u32 value);
168 170
169 /// Return true when a CPU region is modified from the GPU 171 /// Return true when a CPU region is modified from the GPU
170 [[nodiscard]] bool IsRegionGpuModified(VAddr addr, size_t size); 172 [[nodiscard]] bool IsRegionGpuModified(VAddr addr, size_t size);
171 173
174 /// Return true when a region is registered on the cache
175 [[nodiscard]] bool IsRegionRegistered(VAddr addr, size_t size);
176
172 /// Return true when a CPU region is modified from the CPU 177 /// Return true when a CPU region is modified from the CPU
173 [[nodiscard]] bool IsRegionCpuModified(VAddr addr, size_t size); 178 [[nodiscard]] bool IsRegionCpuModified(VAddr addr, size_t size);
174 179
@@ -324,6 +329,8 @@ private:
324 329
325 [[nodiscard]] bool HasFastUniformBufferBound(size_t stage, u32 binding_index) const noexcept; 330 [[nodiscard]] bool HasFastUniformBufferBound(size_t stage, u32 binding_index) const noexcept;
326 331
332 void ClearDownload(IntervalType subtract_interval);
333
327 VideoCore::RasterizerInterface& rasterizer; 334 VideoCore::RasterizerInterface& rasterizer;
328 Tegra::Engines::Maxwell3D& maxwell3d; 335 Tegra::Engines::Maxwell3D& maxwell3d;
329 Tegra::Engines::KeplerCompute& kepler_compute; 336 Tegra::Engines::KeplerCompute& kepler_compute;
@@ -463,23 +470,28 @@ void BufferCache<P>::DownloadMemory(VAddr cpu_addr, u64 size) {
463} 470}
464 471
465template <class P> 472template <class P>
473void BufferCache<P>::ClearDownload(IntervalType subtract_interval) {
474 uncommitted_ranges.subtract(subtract_interval);
475 for (auto& interval_set : committed_ranges) {
476 interval_set.subtract(subtract_interval);
477 }
478}
479
480template <class P>
466bool BufferCache<P>::DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) { 481bool BufferCache<P>::DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) {
467 const std::optional<VAddr> cpu_src_address = gpu_memory.GpuToCpuAddress(src_address); 482 const std::optional<VAddr> cpu_src_address = gpu_memory.GpuToCpuAddress(src_address);
468 const std::optional<VAddr> cpu_dest_address = gpu_memory.GpuToCpuAddress(dest_address); 483 const std::optional<VAddr> cpu_dest_address = gpu_memory.GpuToCpuAddress(dest_address);
469 if (!cpu_src_address || !cpu_dest_address) { 484 if (!cpu_src_address || !cpu_dest_address) {
470 return false; 485 return false;
471 } 486 }
472 const bool source_dirty = IsRegionGpuModified(*cpu_src_address, amount); 487 const bool source_dirty = IsRegionRegistered(*cpu_src_address, amount);
473 const bool dest_dirty = IsRegionGpuModified(*cpu_dest_address, amount); 488 const bool dest_dirty = IsRegionRegistered(*cpu_dest_address, amount);
474 if (!source_dirty && !dest_dirty) { 489 if (!source_dirty && !dest_dirty) {
475 return false; 490 return false;
476 } 491 }
477 492
478 const IntervalType subtract_interval{*cpu_dest_address, *cpu_dest_address + amount}; 493 const IntervalType subtract_interval{*cpu_dest_address, *cpu_dest_address + amount};
479 uncommitted_ranges.subtract(subtract_interval); 494 ClearDownload(subtract_interval);
480 for (auto& interval_set : committed_ranges) {
481 interval_set.subtract(subtract_interval);
482 }
483 495
484 BufferId buffer_a; 496 BufferId buffer_a;
485 BufferId buffer_b; 497 BufferId buffer_b;
@@ -510,12 +522,13 @@ bool BufferCache<P>::DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 am
510 ForEachWrittenRange(*cpu_src_address, amount, mirror); 522 ForEachWrittenRange(*cpu_src_address, amount, mirror);
511 // This subtraction in this order is important for overlapping copies. 523 // This subtraction in this order is important for overlapping copies.
512 common_ranges.subtract(subtract_interval); 524 common_ranges.subtract(subtract_interval);
525 bool atleast_1_download = tmp_intervals.size() != 0;
513 for (const IntervalType add_interval : tmp_intervals) { 526 for (const IntervalType add_interval : tmp_intervals) {
514 common_ranges.add(add_interval); 527 common_ranges.add(add_interval);
515 } 528 }
516 529
517 runtime.CopyBuffer(dest_buffer, src_buffer, copies); 530 runtime.CopyBuffer(dest_buffer, src_buffer, copies);
518 if (source_dirty) { 531 if (atleast_1_download) {
519 dest_buffer.MarkRegionAsGpuModified(*cpu_dest_address, amount); 532 dest_buffer.MarkRegionAsGpuModified(*cpu_dest_address, amount);
520 } 533 }
521 std::vector<u8> tmp_buffer(amount); 534 std::vector<u8> tmp_buffer(amount);
@@ -525,6 +538,33 @@ bool BufferCache<P>::DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 am
525} 538}
526 539
527template <class P> 540template <class P>
541bool BufferCache<P>::DMAClear(GPUVAddr dst_address, u64 amount, u32 value) {
542 const std::optional<VAddr> cpu_dst_address = gpu_memory.GpuToCpuAddress(dst_address);
543 if (!cpu_dst_address) {
544 return false;
545 }
546 const bool dest_dirty = IsRegionRegistered(*cpu_dst_address, amount);
547 if (!dest_dirty) {
548 return false;
549 }
550
551 const size_t size = amount * sizeof(u32);
552 const IntervalType subtract_interval{*cpu_dst_address, *cpu_dst_address + size};
553 ClearDownload(subtract_interval);
554 common_ranges.subtract(subtract_interval);
555
556 BufferId buffer;
557 do {
558 has_deleted_buffers = false;
559 buffer = FindBuffer(*cpu_dst_address, static_cast<u32>(size));
560 } while (has_deleted_buffers);
561 auto& dest_buffer = slot_buffers[buffer];
562 const u32 offset = static_cast<u32>(*cpu_dst_address - dest_buffer.CpuAddr());
563 runtime.ClearBuffer(dest_buffer, offset, size, value);
564 return true;
565}
566
567template <class P>
528void BufferCache<P>::BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr, 568void BufferCache<P>::BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr,
529 u32 size) { 569 u32 size) {
530 const std::optional<VAddr> cpu_addr = gpu_memory.GpuToCpuAddress(gpu_addr); 570 const std::optional<VAddr> cpu_addr = gpu_memory.GpuToCpuAddress(gpu_addr);
@@ -782,6 +822,27 @@ bool BufferCache<P>::IsRegionGpuModified(VAddr addr, size_t size) {
782} 822}
783 823
784template <class P> 824template <class P>
825bool BufferCache<P>::IsRegionRegistered(VAddr addr, size_t size) {
826 const VAddr end_addr = addr + size;
827 const u64 page_end = Common::DivCeil(end_addr, PAGE_SIZE);
828 for (u64 page = addr >> PAGE_BITS; page < page_end;) {
829 const BufferId buffer_id = page_table[page];
830 if (!buffer_id) {
831 ++page;
832 continue;
833 }
834 Buffer& buffer = slot_buffers[buffer_id];
835 const VAddr buf_start_addr = buffer.CpuAddr();
836 const VAddr buf_end_addr = buf_start_addr + buffer.SizeBytes();
837 if (buf_start_addr < end_addr && addr < buf_end_addr) {
838 return true;
839 }
840 page = Common::DivCeil(end_addr, PAGE_SIZE);
841 }
842 return false;
843}
844
845template <class P>
785bool BufferCache<P>::IsRegionCpuModified(VAddr addr, size_t size) { 846bool BufferCache<P>::IsRegionCpuModified(VAddr addr, size_t size) {
786 const u64 page_end = Common::DivCeil(addr + size, PAGE_SIZE); 847 const u64 page_end = Common::DivCeil(addr + size, PAGE_SIZE);
787 for (u64 page = addr >> PAGE_BITS; page < page_end;) { 848 for (u64 page = addr >> PAGE_BITS; page < page_end;) {
@@ -1425,6 +1486,7 @@ void BufferCache<P>::DownloadBufferMemory(Buffer& buffer, VAddr cpu_addr, u64 si
1425 const VAddr end_address = start_address + range_size; 1486 const VAddr end_address = start_address + range_size;
1426 ForEachWrittenRange(start_address, range_size, add_download); 1487 ForEachWrittenRange(start_address, range_size, add_download);
1427 const IntervalType subtract_interval{start_address, end_address}; 1488 const IntervalType subtract_interval{start_address, end_address};
1489 ClearDownload(subtract_interval);
1428 common_ranges.subtract(subtract_interval); 1490 common_ranges.subtract(subtract_interval);
1429 }); 1491 });
1430 if (total_size_bytes == 0) { 1492 if (total_size_bytes == 0) {
diff --git a/src/video_core/engines/maxwell_dma.cpp b/src/video_core/engines/maxwell_dma.cpp
index 24481952b..c51776466 100644
--- a/src/video_core/engines/maxwell_dma.cpp
+++ b/src/video_core/engines/maxwell_dma.cpp
@@ -4,6 +4,7 @@
4 4
5#include "common/assert.h" 5#include "common/assert.h"
6#include "common/logging/log.h" 6#include "common/logging/log.h"
7#include "common/microprofile.h"
7#include "common/settings.h" 8#include "common/settings.h"
8#include "core/core.h" 9#include "core/core.h"
9#include "video_core/engines/maxwell_3d.h" 10#include "video_core/engines/maxwell_3d.h"
@@ -12,6 +13,9 @@
12#include "video_core/renderer_base.h" 13#include "video_core/renderer_base.h"
13#include "video_core/textures/decoders.h" 14#include "video_core/textures/decoders.h"
14 15
16MICROPROFILE_DECLARE(GPU_DMAEngine);
17MICROPROFILE_DEFINE(GPU_DMAEngine, "GPU", "DMA Engine", MP_RGB(224, 224, 128));
18
15namespace Tegra::Engines { 19namespace Tegra::Engines {
16 20
17using namespace Texture; 21using namespace Texture;
@@ -43,6 +47,7 @@ void MaxwellDMA::CallMultiMethod(u32 method, const u32* base_start, u32 amount,
43} 47}
44 48
45void MaxwellDMA::Launch() { 49void MaxwellDMA::Launch() {
50 MICROPROFILE_SCOPE(GPU_DMAEngine);
46 LOG_TRACE(Render_OpenGL, "DMA copy 0x{:x} -> 0x{:x}", static_cast<GPUVAddr>(regs.offset_in), 51 LOG_TRACE(Render_OpenGL, "DMA copy 0x{:x} -> 0x{:x}", static_cast<GPUVAddr>(regs.offset_in),
47 static_cast<GPUVAddr>(regs.offset_out)); 52 static_cast<GPUVAddr>(regs.offset_out));
48 53
@@ -87,9 +92,11 @@ void MaxwellDMA::CopyPitchToPitch() {
87 // TODO: allow multisized components. 92 // TODO: allow multisized components.
88 if (is_buffer_clear) { 93 if (is_buffer_clear) {
89 ASSERT(regs.remap_const.component_size_minus_one == 3); 94 ASSERT(regs.remap_const.component_size_minus_one == 3);
95 accelerate.BufferClear(regs.offset_out, regs.line_length_in, regs.remap_consta_value);
90 std::vector<u32> tmp_buffer(regs.line_length_in, regs.remap_consta_value); 96 std::vector<u32> tmp_buffer(regs.line_length_in, regs.remap_consta_value);
91 memory_manager.WriteBlock(regs.offset_out, reinterpret_cast<u8*>(tmp_buffer.data()), 97 memory_manager.WriteBlockUnsafe(regs.offset_out,
92 regs.line_length_in * sizeof(u32)); 98 reinterpret_cast<u8*>(tmp_buffer.data()),
99 regs.line_length_in * sizeof(u32));
93 return; 100 return;
94 } 101 }
95 UNIMPLEMENTED_IF(regs.launch_dma.remap_enable != 0); 102 UNIMPLEMENTED_IF(regs.launch_dma.remap_enable != 0);
@@ -179,8 +186,13 @@ void MaxwellDMA::CopyPitchToBlockLinear() {
179 write_buffer.resize(dst_size); 186 write_buffer.resize(dst_size);
180 } 187 }
181 188
182 memory_manager.ReadBlock(regs.offset_in, read_buffer.data(), src_size); 189 if (Settings::IsGPULevelExtreme()) {
183 memory_manager.ReadBlock(regs.offset_out, write_buffer.data(), dst_size); 190 memory_manager.ReadBlock(regs.offset_in, read_buffer.data(), src_size);
191 memory_manager.ReadBlock(regs.offset_out, write_buffer.data(), dst_size);
192 } else {
193 memory_manager.ReadBlockUnsafe(regs.offset_in, read_buffer.data(), src_size);
194 memory_manager.ReadBlockUnsafe(regs.offset_out, write_buffer.data(), dst_size);
195 }
184 196
185 // If the input is linear and the output is tiled, swizzle the input and copy it over. 197 // If the input is linear and the output is tiled, swizzle the input and copy it over.
186 if (regs.dst_params.block_size.depth > 0) { 198 if (regs.dst_params.block_size.depth > 0) {
diff --git a/src/video_core/engines/maxwell_dma.h b/src/video_core/engines/maxwell_dma.h
index 4ed0d0996..d3329b0f8 100644
--- a/src/video_core/engines/maxwell_dma.h
+++ b/src/video_core/engines/maxwell_dma.h
@@ -31,6 +31,8 @@ class AccelerateDMAInterface {
31public: 31public:
32 /// Write the value to the register identified by method. 32 /// Write the value to the register identified by method.
33 virtual bool BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) = 0; 33 virtual bool BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) = 0;
34
35 virtual bool BufferClear(GPUVAddr src_address, u64 amount, u32 value) = 0;
34}; 36};
35 37
36/** 38/**
diff --git a/src/video_core/renderer_opengl/gl_buffer_cache.cpp b/src/video_core/renderer_opengl/gl_buffer_cache.cpp
index c225d1fc9..c4189fb60 100644
--- a/src/video_core/renderer_opengl/gl_buffer_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_buffer_cache.cpp
@@ -98,6 +98,12 @@ void BufferCacheRuntime::CopyBuffer(Buffer& dst_buffer, Buffer& src_buffer,
98 } 98 }
99} 99}
100 100
101void BufferCacheRuntime::ClearBuffer(Buffer& dest_buffer, u32 offset, size_t size, u32 value) {
102 glClearNamedBufferSubData(dest_buffer.Handle(), GL_R32UI, static_cast<GLintptr>(offset),
103 static_cast<GLsizeiptr>(size / sizeof(u32)), GL_RGBA, GL_UNSIGNED_INT,
104 &value);
105}
106
101void BufferCacheRuntime::BindIndexBuffer(Buffer& buffer, u32 offset, u32 size) { 107void BufferCacheRuntime::BindIndexBuffer(Buffer& buffer, u32 offset, u32 size) {
102 if (has_unified_vertex_buffers) { 108 if (has_unified_vertex_buffers) {
103 buffer.MakeResident(GL_READ_ONLY); 109 buffer.MakeResident(GL_READ_ONLY);
diff --git a/src/video_core/renderer_opengl/gl_buffer_cache.h b/src/video_core/renderer_opengl/gl_buffer_cache.h
index d8b20a9af..fe91aa452 100644
--- a/src/video_core/renderer_opengl/gl_buffer_cache.h
+++ b/src/video_core/renderer_opengl/gl_buffer_cache.h
@@ -57,6 +57,8 @@ public:
57 void CopyBuffer(Buffer& dst_buffer, Buffer& src_buffer, 57 void CopyBuffer(Buffer& dst_buffer, Buffer& src_buffer,
58 std::span<const VideoCommon::BufferCopy> copies); 58 std::span<const VideoCommon::BufferCopy> copies);
59 59
60 void ClearBuffer(Buffer& dest_buffer, u32 offset, size_t size, u32 value);
61
60 void BindIndexBuffer(Buffer& buffer, u32 offset, u32 size); 62 void BindIndexBuffer(Buffer& buffer, u32 offset, u32 size);
61 63
62 void BindVertexBuffer(u32 index, Buffer& buffer, u32 offset, u32 size, u32 stride); 64 void BindVertexBuffer(u32 index, Buffer& buffer, u32 offset, u32 size, u32 stride);
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 82c84127a..ceb3abcb2 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -1407,4 +1407,9 @@ bool AccelerateDMA::BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64
1407 return buffer_cache.DMACopy(src_address, dest_address, amount); 1407 return buffer_cache.DMACopy(src_address, dest_address, amount);
1408} 1408}
1409 1409
1410bool AccelerateDMA::BufferClear(GPUVAddr src_address, u64 amount, u32 value) {
1411 std::scoped_lock lock{buffer_cache.mutex};
1412 return buffer_cache.DMAClear(src_address, amount, value);
1413}
1414
1410} // namespace OpenGL 1415} // namespace OpenGL
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index ccee9ba33..d30ad698f 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -65,6 +65,8 @@ public:
65 65
66 bool BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) override; 66 bool BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) override;
67 67
68 bool BufferClear(GPUVAddr src_address, u64 amount, u32 value) override;
69
68private: 70private:
69 BufferCache& buffer_cache; 71 BufferCache& buffer_cache;
70}; 72};
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.h b/src/video_core/renderer_opengl/gl_texture_cache.h
index 25fe61566..cf3b789e3 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.h
+++ b/src/video_core/renderer_opengl/gl_texture_cache.h
@@ -122,7 +122,7 @@ private:
122 bool has_broken_texture_view_formats = false; 122 bool has_broken_texture_view_formats = false;
123 123
124 StagingBuffers upload_buffers{GL_MAP_WRITE_BIT, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT}; 124 StagingBuffers upload_buffers{GL_MAP_WRITE_BIT, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT};
125 StagingBuffers download_buffers{GL_MAP_READ_BIT, GL_MAP_READ_BIT}; 125 StagingBuffers download_buffers{GL_MAP_READ_BIT | GL_CLIENT_STORAGE_BIT, GL_MAP_READ_BIT};
126 126
127 OGLTexture null_image_1d_array; 127 OGLTexture null_image_1d_array;
128 OGLTexture null_image_cube_array; 128 OGLTexture null_image_cube_array;
diff --git a/src/video_core/renderer_vulkan/vk_buffer_cache.cpp b/src/video_core/renderer_vulkan/vk_buffer_cache.cpp
index 7d4e6ea7b..0def1e769 100644
--- a/src/video_core/renderer_vulkan/vk_buffer_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_buffer_cache.cpp
@@ -136,6 +136,30 @@ void BufferCacheRuntime::CopyBuffer(VkBuffer dst_buffer, VkBuffer src_buffer,
136 }); 136 });
137} 137}
138 138
139void BufferCacheRuntime::ClearBuffer(VkBuffer dest_buffer, u32 offset, size_t size, u32 value) {
140 static constexpr VkMemoryBarrier READ_BARRIER{
141 .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER,
142 .pNext = nullptr,
143 .srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
144 .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT,
145 };
146 static constexpr VkMemoryBarrier WRITE_BARRIER{
147 .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER,
148 .pNext = nullptr,
149 .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
150 .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
151 };
152
153 scheduler.RequestOutsideRenderPassOperationContext();
154 scheduler.Record([dest_buffer, offset, size, value](vk::CommandBuffer cmdbuf) {
155 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
156 0, READ_BARRIER);
157 cmdbuf.FillBuffer(dest_buffer, offset, size, value);
158 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
159 0, WRITE_BARRIER);
160 });
161}
162
139void BufferCacheRuntime::BindIndexBuffer(PrimitiveTopology topology, IndexFormat index_format, 163void BufferCacheRuntime::BindIndexBuffer(PrimitiveTopology topology, IndexFormat index_format,
140 u32 base_vertex, u32 num_indices, VkBuffer buffer, 164 u32 base_vertex, u32 num_indices, VkBuffer buffer,
141 u32 offset, [[maybe_unused]] u32 size) { 165 u32 offset, [[maybe_unused]] u32 size) {
diff --git a/src/video_core/renderer_vulkan/vk_buffer_cache.h b/src/video_core/renderer_vulkan/vk_buffer_cache.h
index 6ea8448d7..3bb81d5b3 100644
--- a/src/video_core/renderer_vulkan/vk_buffer_cache.h
+++ b/src/video_core/renderer_vulkan/vk_buffer_cache.h
@@ -60,6 +60,8 @@ public:
60 void CopyBuffer(VkBuffer src_buffer, VkBuffer dst_buffer, 60 void CopyBuffer(VkBuffer src_buffer, VkBuffer dst_buffer,
61 std::span<const VideoCommon::BufferCopy> copies); 61 std::span<const VideoCommon::BufferCopy> copies);
62 62
63 void ClearBuffer(VkBuffer dest_buffer, u32 offset, size_t size, u32 value);
64
63 void BindIndexBuffer(PrimitiveTopology topology, IndexFormat index_format, u32 num_indices, 65 void BindIndexBuffer(PrimitiveTopology topology, IndexFormat index_format, u32 num_indices,
64 u32 base_vertex, VkBuffer buffer, u32 offset, u32 size); 66 u32 base_vertex, VkBuffer buffer, u32 offset, u32 size);
65 67
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
index a8ffbe6ba..f57c15b37 100644
--- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp
+++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
@@ -706,6 +706,11 @@ void RasterizerVulkan::FlushWork() {
706 706
707AccelerateDMA::AccelerateDMA(BufferCache& buffer_cache_) : buffer_cache{buffer_cache_} {} 707AccelerateDMA::AccelerateDMA(BufferCache& buffer_cache_) : buffer_cache{buffer_cache_} {}
708 708
709bool AccelerateDMA::BufferClear(GPUVAddr src_address, u64 amount, u32 value) {
710 std::scoped_lock lock{buffer_cache.mutex};
711 return buffer_cache.DMAClear(src_address, amount, value);
712}
713
709bool AccelerateDMA::BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) { 714bool AccelerateDMA::BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) {
710 std::scoped_lock lock{buffer_cache.mutex}; 715 std::scoped_lock lock{buffer_cache.mutex};
711 return buffer_cache.DMACopy(src_address, dest_address, amount); 716 return buffer_cache.DMACopy(src_address, dest_address, amount);
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.h b/src/video_core/renderer_vulkan/vk_rasterizer.h
index 3a78de258..2065209be 100644
--- a/src/video_core/renderer_vulkan/vk_rasterizer.h
+++ b/src/video_core/renderer_vulkan/vk_rasterizer.h
@@ -56,6 +56,8 @@ public:
56 56
57 bool BufferCopy(GPUVAddr start_address, GPUVAddr end_address, u64 amount) override; 57 bool BufferCopy(GPUVAddr start_address, GPUVAddr end_address, u64 amount) override;
58 58
59 bool BufferClear(GPUVAddr src_address, u64 amount, u32 value) override;
60
59private: 61private:
60 BufferCache& buffer_cache; 62 BufferCache& buffer_cache;
61}; 63};
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index bfae73b60..d72ca5acc 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -567,6 +567,12 @@ std::unique_ptr<Core::Frontend::GraphicsContext> GRenderWindow::CreateSharedCont
567bool GRenderWindow::InitRenderTarget() { 567bool GRenderWindow::InitRenderTarget() {
568 ReleaseRenderTarget(); 568 ReleaseRenderTarget();
569 569
570 {
571 // Create a dummy render widget so that Qt
572 // places the render window at the correct position.
573 const RenderWidget dummy_widget{this};
574 }
575
570 first_frame = false; 576 first_frame = false;
571 577
572 switch (Settings::values.renderer_backend.GetValue()) { 578 switch (Settings::values.renderer_backend.GetValue()) {
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp
index d5d624b96..6b9bd05f1 100644
--- a/src/yuzu/configuration/configure_input_player.cpp
+++ b/src/yuzu/configuration/configure_input_player.cpp
@@ -149,8 +149,9 @@ QString ButtonToText(const Common::ParamPackage& param) {
149 149
150 if (param.Has("button")) { 150 if (param.Has("button")) {
151 const QString button_str = QString::fromStdString(param.Get("button", "")); 151 const QString button_str = QString::fromStdString(param.Get("button", ""));
152 const QString toggle = QString::fromStdString(param.Get("toggle", false) ? "~" : "");
152 153
153 return QObject::tr("Button %1").arg(button_str); 154 return QObject::tr("%1Button %2").arg(toggle, button_str);
154 } 155 }
155 156
156 if (param.Has("motion")) { 157 if (param.Has("motion")) {
@@ -313,6 +314,24 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
313 buttons_param[button_id].Set("toggle", toggle_value); 314 buttons_param[button_id].Set("toggle", toggle_value);
314 button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); 315 button_map[button_id]->setText(ButtonToText(buttons_param[button_id]));
315 }); 316 });
317 if (buttons_param[button_id].Has("threshold")) {
318 context_menu.addAction(tr("Set threshold"), [&] {
319 const int button_threshold = static_cast<int>(
320 buttons_param[button_id].Get("threshold", 0.5f) * 100.0f);
321 const int new_threshold = QInputDialog::getInt(
322 this, tr("Set threshold"), tr("Choose a value between 0% and 100%"),
323 button_threshold, 0, 100);
324 buttons_param[button_id].Set("threshold", new_threshold / 100.0f);
325
326 if (button_id == Settings::NativeButton::ZL) {
327 ui->sliderZLThreshold->setValue(new_threshold);
328 }
329 if (button_id == Settings::NativeButton::ZR) {
330 ui->sliderZRThreshold->setValue(new_threshold);
331 }
332 });
333 }
334
316 context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); 335 context_menu.exec(button_map[button_id]->mapToGlobal(menu_location));
317 ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param); 336 ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param);
318 }); 337 });
@@ -341,6 +360,20 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
341 }); 360 });
342 } 361 }
343 362
363 connect(ui->sliderZLThreshold, &QSlider::valueChanged, [=, this] {
364 if (buttons_param[Settings::NativeButton::ZL].Has("threshold")) {
365 const auto slider_value = ui->sliderZLThreshold->value();
366 buttons_param[Settings::NativeButton::ZL].Set("threshold", slider_value / 100.0f);
367 }
368 });
369
370 connect(ui->sliderZRThreshold, &QSlider::valueChanged, [=, this] {
371 if (buttons_param[Settings::NativeButton::ZR].Has("threshold")) {
372 const auto slider_value = ui->sliderZRThreshold->value();
373 buttons_param[Settings::NativeButton::ZR].Set("threshold", slider_value / 100.0f);
374 }
375 });
376
344 for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { 377 for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) {
345 for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { 378 for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
346 auto* const analog_button = analog_map_buttons[analog_id][sub_button_id]; 379 auto* const analog_button = analog_map_buttons[analog_id][sub_button_id];
@@ -849,6 +882,18 @@ void ConfigureInputPlayer::UpdateUI() {
849 button_map[button]->setText(ButtonToText(buttons_param[button])); 882 button_map[button]->setText(ButtonToText(buttons_param[button]));
850 } 883 }
851 884
885 if (buttons_param[Settings::NativeButton::ZL].Has("threshold")) {
886 const int button_threshold = static_cast<int>(
887 buttons_param[Settings::NativeButton::ZL].Get("threshold", 0.5f) * 100.0f);
888 ui->sliderZLThreshold->setValue(button_threshold);
889 }
890
891 if (buttons_param[Settings::NativeButton::ZR].Has("threshold")) {
892 const int button_threshold = static_cast<int>(
893 buttons_param[Settings::NativeButton::ZR].Get("threshold", 0.5f) * 100.0f);
894 ui->sliderZRThreshold->setValue(button_threshold);
895 }
896
852 for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { 897 for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
853 motion_map[motion_id]->setText(ButtonToText(motions_param[motion_id])); 898 motion_map[motion_id]->setText(ButtonToText(motions_param[motion_id]));
854 } 899 }
diff --git a/src/yuzu/configuration/configure_input_player.ui b/src/yuzu/configuration/configure_input_player.ui
index e76aa484f..e7433912b 100644
--- a/src/yuzu/configuration/configure_input_player.ui
+++ b/src/yuzu/configuration/configure_input_player.ui
@@ -1334,6 +1334,12 @@
1334 </item> 1334 </item>
1335 <item> 1335 <item>
1336 <widget class="QGroupBox" name="buttonShoulderButtonsButtonZLGroup"> 1336 <widget class="QGroupBox" name="buttonShoulderButtonsButtonZLGroup">
1337 <property name="sizePolicy">
1338 <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
1339 <horstretch>0</horstretch>
1340 <verstretch>0</verstretch>
1341 </sizepolicy>
1342 </property>
1337 <property name="title"> 1343 <property name="title">
1338 <string>ZL</string> 1344 <string>ZL</string>
1339 </property> 1345 </property>
@@ -1378,6 +1384,22 @@
1378 </property> 1384 </property>
1379 </widget> 1385 </widget>
1380 </item> 1386 </item>
1387 <item>
1388 <widget class="QSlider" name="sliderZLThreshold">
1389 <property name="maximumSize">
1390 <size>
1391 <width>70</width>
1392 <height>15</height>
1393 </size>
1394 </property>
1395 <property name="maximum">
1396 <number>100</number>
1397 </property>
1398 <property name="orientation">
1399 <enum>Qt::Horizontal</enum>
1400 </property>
1401 </widget>
1402 </item>
1381 </layout> 1403 </layout>
1382 </widget> 1404 </widget>
1383 </item> 1405 </item>
@@ -1759,6 +1781,12 @@
1759 </item> 1781 </item>
1760 <item> 1782 <item>
1761 <widget class="QGroupBox" name="buttonShoulderButtonsZRGroup"> 1783 <widget class="QGroupBox" name="buttonShoulderButtonsZRGroup">
1784 <property name="sizePolicy">
1785 <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
1786 <horstretch>0</horstretch>
1787 <verstretch>0</verstretch>
1788 </sizepolicy>
1789 </property>
1762 <property name="title"> 1790 <property name="title">
1763 <string>ZR</string> 1791 <string>ZR</string>
1764 </property> 1792 </property>
@@ -1803,6 +1831,22 @@
1803 </property> 1831 </property>
1804 </widget> 1832 </widget>
1805 </item> 1833 </item>
1834 <item>
1835 <widget class="QSlider" name="sliderZRThreshold">
1836 <property name="maximumSize">
1837 <size>
1838 <width>70</width>
1839 <height>15</height>
1840 </size>
1841 </property>
1842 <property name="maximum">
1843 <number>100</number>
1844 </property>
1845 <property name="orientation">
1846 <enum>Qt::Horizontal</enum>
1847 </property>
1848 </widget>
1849 </item>
1806 </layout> 1850 </layout>
1807 </widget> 1851 </widget>
1808 </item> 1852 </item>
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp
index b18056baf..3e22fee37 100644
--- a/src/yuzu_cmd/config.cpp
+++ b/src/yuzu_cmd/config.cpp
@@ -446,6 +446,7 @@ void Config::ReadValues() {
446 ReadSetting("Renderer", Settings::values.renderer_debug); 446 ReadSetting("Renderer", Settings::values.renderer_debug);
447 ReadSetting("Renderer", Settings::values.vulkan_device); 447 ReadSetting("Renderer", Settings::values.vulkan_device);
448 448
449 ReadSetting("Renderer", Settings::values.fullscreen_mode);
449 ReadSetting("Renderer", Settings::values.aspect_ratio); 450 ReadSetting("Renderer", Settings::values.aspect_ratio);
450 ReadSetting("Renderer", Settings::values.max_anisotropy); 451 ReadSetting("Renderer", Settings::values.max_anisotropy);
451 ReadSetting("Renderer", Settings::values.use_frame_limit); 452 ReadSetting("Renderer", Settings::values.use_frame_limit);
diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h
index b362f10b4..88d33ecab 100644
--- a/src/yuzu_cmd/default_ini.h
+++ b/src/yuzu_cmd/default_ini.h
@@ -224,6 +224,10 @@ debug =
224# Which Vulkan physical device to use (defaults to 0) 224# Which Vulkan physical device to use (defaults to 0)
225vulkan_device = 225vulkan_device =
226 226
227# Whether to use fullscreen or borderless window mode
228# 0 (Windows default): Borderless window, 1 (All other default): Exclusive fullscreen
229fullscreen_mode =
230
227# Aspect ratio 231# Aspect ratio
228# 0: Default (16:9), 1: Force 4:3, 2: Force 21:9, 3: Stretch to Window 232# 0: Default (16:9), 1: Force 4:3, 2: Force 21:9, 3: Stretch to Window
229aspect_ratio = 233aspect_ratio =
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
index 896181f0b..353e51ea7 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
@@ -6,6 +6,7 @@
6 6
7#include "common/logging/log.h" 7#include "common/logging/log.h"
8#include "common/scm_rev.h" 8#include "common/scm_rev.h"
9#include "common/settings.h"
9#include "core/core.h" 10#include "core/core.h"
10#include "core/perf_stats.h" 11#include "core/perf_stats.h"
11#include "input_common/keyboard.h" 12#include "input_common/keyboard.h"
@@ -122,24 +123,37 @@ void EmuWindow_SDL2::OnResize() {
122} 123}
123 124
124void EmuWindow_SDL2::Fullscreen() { 125void EmuWindow_SDL2::Fullscreen() {
125 if (SDL_SetWindowFullscreen(render_window, SDL_WINDOW_FULLSCREEN) == 0) { 126 switch (Settings::values.fullscreen_mode.GetValue()) {
126 return; 127 case 1: // Exclusive fullscreen
127 } 128 // Set window size to render size before entering fullscreen -- SDL does not resize to
128 129 // display dimensions in this mode.
129 LOG_ERROR(Frontend, "Fullscreening failed: {}", SDL_GetError()); 130 // TODO: Multiply the window size by resolution_factor (for both docked modes)
131 if (Settings::values.use_docked_mode) {
132 SDL_SetWindowSize(render_window, Layout::ScreenDocked::Width,
133 Layout::ScreenDocked::Height);
134 }
130 135
131 // Try a different fullscreening method 136 if (SDL_SetWindowFullscreen(render_window, SDL_WINDOW_FULLSCREEN) == 0) {
132 LOG_INFO(Frontend, "Attempting to use borderless fullscreen..."); 137 return;
133 if (SDL_SetWindowFullscreen(render_window, SDL_WINDOW_FULLSCREEN_DESKTOP) == 0) { 138 }
134 return;
135 }
136 139
137 LOG_ERROR(Frontend, "Borderless fullscreening failed: {}", SDL_GetError()); 140 LOG_ERROR(Frontend, "Fullscreening failed: {}", SDL_GetError());
141 LOG_INFO(Frontend, "Attempting to use borderless fullscreen...");
142 [[fallthrough]];
143 case 0: // Borderless window
144 if (SDL_SetWindowFullscreen(render_window, SDL_WINDOW_FULLSCREEN_DESKTOP) == 0) {
145 return;
146 }
138 147
139 // Fallback algorithm: Maximise window. 148 LOG_ERROR(Frontend, "Borderless fullscreening failed: {}", SDL_GetError());
140 // Works on all systems (unless something is seriously wrong), so no fallback for this one. 149 [[fallthrough]];
141 LOG_INFO(Frontend, "Falling back on a maximised window..."); 150 default:
142 SDL_MaximizeWindow(render_window); 151 // Fallback algorithm: Maximise window.
152 // Works on all systems (unless something is seriously wrong), so no fallback for this one.
153 LOG_INFO(Frontend, "Falling back on a maximised window...");
154 SDL_MaximizeWindow(render_window);
155 break;
156 }
143} 157}
144 158
145void EmuWindow_SDL2::WaitEvent() { 159void EmuWindow_SDL2::WaitEvent() {
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp
index 152e56db8..d1473dbab 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp
@@ -24,7 +24,7 @@
24#include <SDL.h> 24#include <SDL.h>
25#include <SDL_syswm.h> 25#include <SDL_syswm.h>
26 26
27EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsystem) 27EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsystem, bool fullscreen)
28 : EmuWindow_SDL2{input_subsystem} { 28 : EmuWindow_SDL2{input_subsystem} {
29 const std::string window_title = fmt::format("yuzu {} | {}-{} (Vulkan)", Common::g_build_name, 29 const std::string window_title = fmt::format("yuzu {} | {}-{} (Vulkan)", Common::g_build_name,
30 Common::g_scm_branch, Common::g_scm_desc); 30 Common::g_scm_branch, Common::g_scm_desc);
@@ -42,6 +42,10 @@ EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsyste
42 42
43 SetWindowIcon(); 43 SetWindowIcon();
44 44
45 if (fullscreen) {
46 Fullscreen();
47 }
48
45 switch (wm.subsystem) { 49 switch (wm.subsystem) {
46#ifdef SDL_VIDEO_DRIVER_WINDOWS 50#ifdef SDL_VIDEO_DRIVER_WINDOWS
47 case SDL_SYSWM_TYPE::SDL_SYSWM_WINDOWS: 51 case SDL_SYSWM_TYPE::SDL_SYSWM_WINDOWS:
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h
index bdfdc3c6f..de53844f0 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h
@@ -19,7 +19,7 @@ class InputSubsystem;
19 19
20class EmuWindow_SDL2_VK final : public EmuWindow_SDL2 { 20class EmuWindow_SDL2_VK final : public EmuWindow_SDL2 {
21public: 21public:
22 explicit EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsystem); 22 explicit EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsystem, bool fullscreen);
23 ~EmuWindow_SDL2_VK() override; 23 ~EmuWindow_SDL2_VK() override;
24 24
25 std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; 25 std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override;
diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp
index 9607cdcb1..ac4ea88d3 100644
--- a/src/yuzu_cmd/yuzu.cpp
+++ b/src/yuzu_cmd/yuzu.cpp
@@ -175,7 +175,7 @@ int main(int argc, char** argv) {
175 emu_window = std::make_unique<EmuWindow_SDL2_GL>(&input_subsystem, fullscreen); 175 emu_window = std::make_unique<EmuWindow_SDL2_GL>(&input_subsystem, fullscreen);
176 break; 176 break;
177 case Settings::RendererBackend::Vulkan: 177 case Settings::RendererBackend::Vulkan:
178 emu_window = std::make_unique<EmuWindow_SDL2_VK>(&input_subsystem); 178 emu_window = std::make_unique<EmuWindow_SDL2_VK>(&input_subsystem, fullscreen);
179 break; 179 break;
180 } 180 }
181 181