diff options
26 files changed, 366 insertions, 46 deletions
diff --git a/.ci/yuzu-mainline-step2.yml b/.ci/yuzu-mainline-step2.yml index a90041d28..3159ce3ed 100644 --- a/.ci/yuzu-mainline-step2.yml +++ b/.ci/yuzu-mainline-step2.yml @@ -19,6 +19,7 @@ stages: displayName: 'build' jobs: - job: build + timeoutInMinutes: 120 displayName: 'standard' pool: vmImage: ubuntu-latest @@ -43,6 +44,7 @@ stages: displayName: 'build-windows' jobs: - job: build + timeoutInMinutes: 120 displayName: 'msvc' pool: vmImage: windows-2019 @@ -65,4 +67,4 @@ stages: - job: github displayName: 'github' steps: - - template: ./templates/release-github.yml
\ No newline at end of file + - template: ./templates/release-github.yml 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 { constexpr explicit UUID(const u64 lo, const u64 hi) : uuid{{lo, hi}} {} [[nodiscard]] constexpr explicit operator bool() const { - return uuid[0] != INVALID_UUID[0] && uuid[1] != INVALID_UUID[1]; + return uuid != INVALID_UUID; } [[nodiscard]] constexpr bool operator==(const UUID& rhs) const { - // TODO(DarkLordZach): Replace with uuid == rhs.uuid with C++20 - return uuid[0] == rhs.uuid[0] && uuid[1] == rhs.uuid[1]; + return uuid == rhs.uuid; } [[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() { case sizeof(ControllerUpdateFirmwareArg): controller_private_arg.mode = ControllerSupportMode::ShowControllerFirmwareUpdate; break; + case sizeof(ControllerKeyRemappingArg): + controller_private_arg.mode = + ControllerSupportMode::ShowControllerKeyRemappingForSystem; + break; default: UNIMPLEMENTED_MSG("Unknown ControllerPrivateArg mode={} with arg_size={}", controller_private_arg.mode, controller_private_arg.arg_size); @@ -99,7 +103,9 @@ void Controller::Initialize() { // This is always 0 (Application) except with ShowControllerFirmwareUpdateForSystem. if (controller_private_arg.caller >= ControllerSupportCaller::MaxControllerSupportCaller) { if (controller_private_arg.flag_1 && - controller_private_arg.mode == ControllerSupportMode::ShowControllerFirmwareUpdate) { + (controller_private_arg.mode == ControllerSupportMode::ShowControllerFirmwareUpdate || + controller_private_arg.mode == + ControllerSupportMode::ShowControllerKeyRemappingForSystem)) { controller_private_arg.caller = ControllerSupportCaller::System; } else { controller_private_arg.caller = ControllerSupportCaller::Application; @@ -121,6 +127,7 @@ void Controller::Initialize() { std::memcpy(&controller_user_arg_old, user_arg.data(), user_arg.size()); break; case ControllerAppletVersion::Version7: + case ControllerAppletVersion::Version8: ASSERT(user_arg.size() == sizeof(ControllerSupportArgNew)); std::memcpy(&controller_user_arg_new, user_arg.data(), user_arg.size()); break; @@ -143,6 +150,16 @@ void Controller::Initialize() { std::memcpy(&controller_update_arg, update_arg.data(), update_arg.size()); break; } + case ControllerSupportMode::ShowControllerKeyRemappingForSystem: { + const auto remapping_arg_storage = broker.PopNormalDataToApplet(); + ASSERT(remapping_arg_storage != nullptr); + + const auto& remapping_arg = remapping_arg_storage->GetData(); + ASSERT(remapping_arg.size() == sizeof(ControllerKeyRemappingArg)); + + std::memcpy(&controller_key_remapping_arg, remapping_arg.data(), remapping_arg.size()); + break; + } default: { UNIMPLEMENTED_MSG("Unimplemented ControllerSupportMode={}", controller_private_arg.mode); break; @@ -179,6 +196,7 @@ void Controller::Execute() { std::vector<ExplainText>(controller_user_arg_old.explain_text.begin(), controller_user_arg_old.explain_text.end())); case ControllerAppletVersion::Version7: + case ControllerAppletVersion::Version8: default: return ConvertToFrontendParameters( controller_private_arg, controller_user_arg_new.header, @@ -210,6 +228,7 @@ void Controller::Execute() { } case ControllerSupportMode::ShowControllerStrapGuide: case ControllerSupportMode::ShowControllerFirmwareUpdate: + case ControllerSupportMode::ShowControllerKeyRemappingForSystem: UNIMPLEMENTED_MSG("ControllerSupportMode={} is not implemented", controller_private_arg.mode); 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 { Version3 = 0x3, // 1.0.0 - 2.3.0 Version4 = 0x4, // 3.0.0 - 5.1.0 Version5 = 0x5, // 6.0.0 - 7.0.1 - Version7 = 0x7, // 8.0.0+ + Version7 = 0x7, // 8.0.0 - 10.2.0 + Version8 = 0x8, // 11.0.0+ }; enum class ControllerSupportMode : u8 { ShowControllerSupport, ShowControllerStrapGuide, ShowControllerFirmwareUpdate, + ShowControllerKeyRemappingForSystem, MaxControllerSupportMode, }; @@ -78,7 +80,7 @@ struct ControllerSupportArgOld { static_assert(sizeof(ControllerSupportArgOld) == 0x21C, "ControllerSupportArgOld has incorrect size."); -// LibraryAppletVersion 0x7 +// LibraryAppletVersion 0x7, 0x8 struct ControllerSupportArgNew { ControllerSupportArgHeader header{}; std::array<IdentificationColor, 8> identification_colors{}; @@ -95,6 +97,14 @@ struct ControllerUpdateFirmwareArg { static_assert(sizeof(ControllerUpdateFirmwareArg) == 0x4, "ControllerUpdateFirmwareArg has incorrect size."); +struct ControllerKeyRemappingArg { + u64 unknown{}; + u32 unknown_2{}; + INSERT_PADDING_WORDS(1); +}; +static_assert(sizeof(ControllerKeyRemappingArg) == 0x10, + "ControllerKeyRemappingArg has incorrect size."); + struct ControllerSupportResultInfo { s8 player_count{}; INSERT_PADDING_BYTES(3); @@ -128,6 +138,7 @@ private: ControllerSupportArgOld controller_user_arg_old; ControllerSupportArgNew controller_user_arg_new; ControllerUpdateFirmwareArg controller_update_arg; + ControllerKeyRemappingArg controller_key_remapping_arg; bool complete{false}; ResultCode status{ResultSuccess}; 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: return state.buttons.at(button); } + bool ToggleButton(int button) { + std::lock_guard lock{mutex}; + + if (!state.toggle_buttons.contains(button) || !state.lock_buttons.contains(button)) { + state.toggle_buttons.insert_or_assign(button, false); + state.lock_buttons.insert_or_assign(button, false); + } + + const bool button_state = state.toggle_buttons.at(button); + const bool button_lock = state.lock_buttons.at(button); + + if (button_lock) { + return button_state; + } + + state.lock_buttons.insert_or_assign(button, true); + + if (button_state) { + state.toggle_buttons.insert_or_assign(button, false); + } else { + state.toggle_buttons.insert_or_assign(button, true); + } + + return !button_state; + } + + bool UnlockButton(int button) { + std::lock_guard lock{mutex}; + if (!state.toggle_buttons.contains(button)) { + return false; + } + state.lock_buttons.insert_or_assign(button, false); + return state.toggle_buttons.at(button); + } + void SetAxis(int axis, Sint16 value) { std::lock_guard lock{mutex}; state.axes.insert_or_assign(axis, value); @@ -241,6 +276,8 @@ public: private: struct State { std::unordered_map<int, bool> buttons; + std::unordered_map<int, bool> toggle_buttons{}; + std::unordered_map<int, bool> lock_buttons{}; std::unordered_map<int, Sint16> axes; std::unordered_map<int, Uint8> hats; } state; @@ -402,16 +439,25 @@ void SDLState::CloseJoysticks() { class SDLButton final : public Input::ButtonDevice { public: - explicit SDLButton(std::shared_ptr<SDLJoystick> joystick_, int button_) - : joystick(std::move(joystick_)), button(button_) {} + explicit SDLButton(std::shared_ptr<SDLJoystick> joystick_, int button_, bool toggle_) + : joystick(std::move(joystick_)), button(button_), toggle(toggle_) {} bool GetStatus() const override { - return joystick->GetButton(button); + const bool button_state = joystick->GetButton(button); + if (!toggle) { + return button_state; + } + + if (button_state) { + return joystick->ToggleButton(button); + } + return joystick->UnlockButton(button); } private: std::shared_ptr<SDLJoystick> joystick; int button; + bool toggle; }; class SDLDirectionButton final : public Input::ButtonDevice { @@ -635,6 +681,7 @@ public: std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override { const std::string guid = params.Get("guid", "0"); const int port = params.Get("port", 0); + const auto toggle = params.Get("toggle", false); auto joystick = state.GetSDLJoystickByGUID(guid, port); @@ -660,7 +707,8 @@ public: if (params.Has("axis")) { const int axis = params.Get("axis", 0); - const float threshold = params.Get("threshold", 0.5f); + // Convert range from (0.0, 1.0) to (-1.0, 1.0) + const float threshold = (params.Get("threshold", 0.5f) - 0.5f) * 2.0f; const std::string direction_name = params.Get("direction", ""); bool trigger_if_greater; if (direction_name == "+") { @@ -679,7 +727,7 @@ public: const int button = params.Get("button", 0); // This is necessary so accessing GetButton with button won't crash joystick->SetButton(button, false); - return std::make_unique<SDLButton>(joystick, button); + return std::make_unique<SDLButton>(joystick, button, toggle); } private: @@ -933,12 +981,11 @@ Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid params.Set("port", port); params.Set("guid", std::move(guid)); params.Set("axis", axis); + params.Set("threshold", "0.5"); if (value > 0) { params.Set("direction", "+"); - params.Set("threshold", "0.5"); } else { params.Set("direction", "-"); - params.Set("threshold", "-0.5"); } return params; } 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: /// Pop asynchronous downloads void PopAsyncFlushes(); - [[nodiscard]] bool DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount); + bool DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount); + + bool DMAClear(GPUVAddr src_address, u64 amount, u32 value); /// Return true when a CPU region is modified from the GPU [[nodiscard]] bool IsRegionGpuModified(VAddr addr, size_t size); + /// Return true when a region is registered on the cache + [[nodiscard]] bool IsRegionRegistered(VAddr addr, size_t size); + /// Return true when a CPU region is modified from the CPU [[nodiscard]] bool IsRegionCpuModified(VAddr addr, size_t size); @@ -324,6 +329,8 @@ private: [[nodiscard]] bool HasFastUniformBufferBound(size_t stage, u32 binding_index) const noexcept; + void ClearDownload(IntervalType subtract_interval); + VideoCore::RasterizerInterface& rasterizer; Tegra::Engines::Maxwell3D& maxwell3d; Tegra::Engines::KeplerCompute& kepler_compute; @@ -463,23 +470,28 @@ void BufferCache<P>::DownloadMemory(VAddr cpu_addr, u64 size) { } template <class P> +void BufferCache<P>::ClearDownload(IntervalType subtract_interval) { + uncommitted_ranges.subtract(subtract_interval); + for (auto& interval_set : committed_ranges) { + interval_set.subtract(subtract_interval); + } +} + +template <class P> bool BufferCache<P>::DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) { const std::optional<VAddr> cpu_src_address = gpu_memory.GpuToCpuAddress(src_address); const std::optional<VAddr> cpu_dest_address = gpu_memory.GpuToCpuAddress(dest_address); if (!cpu_src_address || !cpu_dest_address) { return false; } - const bool source_dirty = IsRegionGpuModified(*cpu_src_address, amount); - const bool dest_dirty = IsRegionGpuModified(*cpu_dest_address, amount); + const bool source_dirty = IsRegionRegistered(*cpu_src_address, amount); + const bool dest_dirty = IsRegionRegistered(*cpu_dest_address, amount); if (!source_dirty && !dest_dirty) { return false; } const IntervalType subtract_interval{*cpu_dest_address, *cpu_dest_address + amount}; - uncommitted_ranges.subtract(subtract_interval); - for (auto& interval_set : committed_ranges) { - interval_set.subtract(subtract_interval); - } + ClearDownload(subtract_interval); BufferId buffer_a; BufferId buffer_b; @@ -510,12 +522,13 @@ bool BufferCache<P>::DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 am ForEachWrittenRange(*cpu_src_address, amount, mirror); // This subtraction in this order is important for overlapping copies. common_ranges.subtract(subtract_interval); + bool atleast_1_download = tmp_intervals.size() != 0; for (const IntervalType add_interval : tmp_intervals) { common_ranges.add(add_interval); } runtime.CopyBuffer(dest_buffer, src_buffer, copies); - if (source_dirty) { + if (atleast_1_download) { dest_buffer.MarkRegionAsGpuModified(*cpu_dest_address, amount); } std::vector<u8> tmp_buffer(amount); @@ -525,6 +538,33 @@ bool BufferCache<P>::DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 am } template <class P> +bool BufferCache<P>::DMAClear(GPUVAddr dst_address, u64 amount, u32 value) { + const std::optional<VAddr> cpu_dst_address = gpu_memory.GpuToCpuAddress(dst_address); + if (!cpu_dst_address) { + return false; + } + const bool dest_dirty = IsRegionRegistered(*cpu_dst_address, amount); + if (!dest_dirty) { + return false; + } + + const size_t size = amount * sizeof(u32); + const IntervalType subtract_interval{*cpu_dst_address, *cpu_dst_address + size}; + ClearDownload(subtract_interval); + common_ranges.subtract(subtract_interval); + + BufferId buffer; + do { + has_deleted_buffers = false; + buffer = FindBuffer(*cpu_dst_address, static_cast<u32>(size)); + } while (has_deleted_buffers); + auto& dest_buffer = slot_buffers[buffer]; + const u32 offset = static_cast<u32>(*cpu_dst_address - dest_buffer.CpuAddr()); + runtime.ClearBuffer(dest_buffer, offset, size, value); + return true; +} + +template <class P> void BufferCache<P>::BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr, u32 size) { const std::optional<VAddr> cpu_addr = gpu_memory.GpuToCpuAddress(gpu_addr); @@ -782,6 +822,27 @@ bool BufferCache<P>::IsRegionGpuModified(VAddr addr, size_t size) { } template <class P> +bool BufferCache<P>::IsRegionRegistered(VAddr addr, size_t size) { + const VAddr end_addr = addr + size; + const u64 page_end = Common::DivCeil(end_addr, PAGE_SIZE); + for (u64 page = addr >> PAGE_BITS; page < page_end;) { + const BufferId buffer_id = page_table[page]; + if (!buffer_id) { + ++page; + continue; + } + Buffer& buffer = slot_buffers[buffer_id]; + const VAddr buf_start_addr = buffer.CpuAddr(); + const VAddr buf_end_addr = buf_start_addr + buffer.SizeBytes(); + if (buf_start_addr < end_addr && addr < buf_end_addr) { + return true; + } + page = Common::DivCeil(end_addr, PAGE_SIZE); + } + return false; +} + +template <class P> bool BufferCache<P>::IsRegionCpuModified(VAddr addr, size_t size) { const u64 page_end = Common::DivCeil(addr + size, PAGE_SIZE); for (u64 page = addr >> PAGE_BITS; page < page_end;) { @@ -1425,6 +1486,7 @@ void BufferCache<P>::DownloadBufferMemory(Buffer& buffer, VAddr cpu_addr, u64 si const VAddr end_address = start_address + range_size; ForEachWrittenRange(start_address, range_size, add_download); const IntervalType subtract_interval{start_address, end_address}; + ClearDownload(subtract_interval); common_ranges.subtract(subtract_interval); }); 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 @@ #include "common/assert.h" #include "common/logging/log.h" +#include "common/microprofile.h" #include "common/settings.h" #include "core/core.h" #include "video_core/engines/maxwell_3d.h" @@ -12,6 +13,9 @@ #include "video_core/renderer_base.h" #include "video_core/textures/decoders.h" +MICROPROFILE_DECLARE(GPU_DMAEngine); +MICROPROFILE_DEFINE(GPU_DMAEngine, "GPU", "DMA Engine", MP_RGB(224, 224, 128)); + namespace Tegra::Engines { using namespace Texture; @@ -43,6 +47,7 @@ void MaxwellDMA::CallMultiMethod(u32 method, const u32* base_start, u32 amount, } void MaxwellDMA::Launch() { + MICROPROFILE_SCOPE(GPU_DMAEngine); LOG_TRACE(Render_OpenGL, "DMA copy 0x{:x} -> 0x{:x}", static_cast<GPUVAddr>(regs.offset_in), static_cast<GPUVAddr>(regs.offset_out)); @@ -87,9 +92,11 @@ void MaxwellDMA::CopyPitchToPitch() { // TODO: allow multisized components. if (is_buffer_clear) { ASSERT(regs.remap_const.component_size_minus_one == 3); + accelerate.BufferClear(regs.offset_out, regs.line_length_in, regs.remap_consta_value); std::vector<u32> tmp_buffer(regs.line_length_in, regs.remap_consta_value); - memory_manager.WriteBlock(regs.offset_out, reinterpret_cast<u8*>(tmp_buffer.data()), - regs.line_length_in * sizeof(u32)); + memory_manager.WriteBlockUnsafe(regs.offset_out, + reinterpret_cast<u8*>(tmp_buffer.data()), + regs.line_length_in * sizeof(u32)); return; } UNIMPLEMENTED_IF(regs.launch_dma.remap_enable != 0); @@ -179,8 +186,13 @@ void MaxwellDMA::CopyPitchToBlockLinear() { write_buffer.resize(dst_size); } - memory_manager.ReadBlock(regs.offset_in, read_buffer.data(), src_size); - memory_manager.ReadBlock(regs.offset_out, write_buffer.data(), dst_size); + if (Settings::IsGPULevelExtreme()) { + memory_manager.ReadBlock(regs.offset_in, read_buffer.data(), src_size); + memory_manager.ReadBlock(regs.offset_out, write_buffer.data(), dst_size); + } else { + memory_manager.ReadBlockUnsafe(regs.offset_in, read_buffer.data(), src_size); + memory_manager.ReadBlockUnsafe(regs.offset_out, write_buffer.data(), dst_size); + } // If the input is linear and the output is tiled, swizzle the input and copy it over. 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 { public: /// Write the value to the register identified by method. virtual bool BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) = 0; + + virtual bool BufferClear(GPUVAddr src_address, u64 amount, u32 value) = 0; }; /** 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, } } +void BufferCacheRuntime::ClearBuffer(Buffer& dest_buffer, u32 offset, size_t size, u32 value) { + glClearNamedBufferSubData(dest_buffer.Handle(), GL_R32UI, static_cast<GLintptr>(offset), + static_cast<GLsizeiptr>(size / sizeof(u32)), GL_RGBA, GL_UNSIGNED_INT, + &value); +} + void BufferCacheRuntime::BindIndexBuffer(Buffer& buffer, u32 offset, u32 size) { if (has_unified_vertex_buffers) { 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: void CopyBuffer(Buffer& dst_buffer, Buffer& src_buffer, std::span<const VideoCommon::BufferCopy> copies); + void ClearBuffer(Buffer& dest_buffer, u32 offset, size_t size, u32 value); + void BindIndexBuffer(Buffer& buffer, u32 offset, u32 size); 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 return buffer_cache.DMACopy(src_address, dest_address, amount); } +bool AccelerateDMA::BufferClear(GPUVAddr src_address, u64 amount, u32 value) { + std::scoped_lock lock{buffer_cache.mutex}; + return buffer_cache.DMAClear(src_address, amount, value); +} + } // 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: bool BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) override; + bool BufferClear(GPUVAddr src_address, u64 amount, u32 value) override; + private: BufferCache& buffer_cache; }; 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: bool has_broken_texture_view_formats = false; StagingBuffers upload_buffers{GL_MAP_WRITE_BIT, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT}; - StagingBuffers download_buffers{GL_MAP_READ_BIT, GL_MAP_READ_BIT}; + StagingBuffers download_buffers{GL_MAP_READ_BIT | GL_CLIENT_STORAGE_BIT, GL_MAP_READ_BIT}; OGLTexture null_image_1d_array; 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, }); } +void BufferCacheRuntime::ClearBuffer(VkBuffer dest_buffer, u32 offset, size_t size, u32 value) { + static constexpr VkMemoryBarrier READ_BARRIER{ + .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, + .pNext = nullptr, + .srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT, + .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT, + }; + static constexpr VkMemoryBarrier WRITE_BARRIER{ + .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, + .pNext = nullptr, + .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, + .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, + }; + + scheduler.RequestOutsideRenderPassOperationContext(); + scheduler.Record([dest_buffer, offset, size, value](vk::CommandBuffer cmdbuf) { + cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, READ_BARRIER); + cmdbuf.FillBuffer(dest_buffer, offset, size, value); + cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + 0, WRITE_BARRIER); + }); +} + void BufferCacheRuntime::BindIndexBuffer(PrimitiveTopology topology, IndexFormat index_format, u32 base_vertex, u32 num_indices, VkBuffer buffer, 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: void CopyBuffer(VkBuffer src_buffer, VkBuffer dst_buffer, std::span<const VideoCommon::BufferCopy> copies); + void ClearBuffer(VkBuffer dest_buffer, u32 offset, size_t size, u32 value); + void BindIndexBuffer(PrimitiveTopology topology, IndexFormat index_format, u32 num_indices, u32 base_vertex, VkBuffer buffer, u32 offset, u32 size); 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() { AccelerateDMA::AccelerateDMA(BufferCache& buffer_cache_) : buffer_cache{buffer_cache_} {} +bool AccelerateDMA::BufferClear(GPUVAddr src_address, u64 amount, u32 value) { + std::scoped_lock lock{buffer_cache.mutex}; + return buffer_cache.DMAClear(src_address, amount, value); +} + bool AccelerateDMA::BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) { std::scoped_lock lock{buffer_cache.mutex}; 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: bool BufferCopy(GPUVAddr start_address, GPUVAddr end_address, u64 amount) override; + bool BufferClear(GPUVAddr src_address, u64 amount, u32 value) override; + private: BufferCache& buffer_cache; }; 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 bool GRenderWindow::InitRenderTarget() { ReleaseRenderTarget(); + { + // Create a dummy render widget so that Qt + // places the render window at the correct position. + const RenderWidget dummy_widget{this}; + } + first_frame = false; 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) { if (param.Has("button")) { const QString button_str = QString::fromStdString(param.Get("button", "")); + const QString toggle = QString::fromStdString(param.Get("toggle", false) ? "~" : ""); - return QObject::tr("Button %1").arg(button_str); + return QObject::tr("%1Button %2").arg(toggle, button_str); } if (param.Has("motion")) { @@ -313,6 +314,24 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i buttons_param[button_id].Set("toggle", toggle_value); button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); }); + if (buttons_param[button_id].Has("threshold")) { + context_menu.addAction(tr("Set threshold"), [&] { + const int button_threshold = static_cast<int>( + buttons_param[button_id].Get("threshold", 0.5f) * 100.0f); + const int new_threshold = QInputDialog::getInt( + this, tr("Set threshold"), tr("Choose a value between 0% and 100%"), + button_threshold, 0, 100); + buttons_param[button_id].Set("threshold", new_threshold / 100.0f); + + if (button_id == Settings::NativeButton::ZL) { + ui->sliderZLThreshold->setValue(new_threshold); + } + if (button_id == Settings::NativeButton::ZR) { + ui->sliderZRThreshold->setValue(new_threshold); + } + }); + } + context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param); }); @@ -341,6 +360,20 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i }); } + connect(ui->sliderZLThreshold, &QSlider::valueChanged, [=, this] { + if (buttons_param[Settings::NativeButton::ZL].Has("threshold")) { + const auto slider_value = ui->sliderZLThreshold->value(); + buttons_param[Settings::NativeButton::ZL].Set("threshold", slider_value / 100.0f); + } + }); + + connect(ui->sliderZRThreshold, &QSlider::valueChanged, [=, this] { + if (buttons_param[Settings::NativeButton::ZR].Has("threshold")) { + const auto slider_value = ui->sliderZRThreshold->value(); + buttons_param[Settings::NativeButton::ZR].Set("threshold", slider_value / 100.0f); + } + }); + for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { auto* const analog_button = analog_map_buttons[analog_id][sub_button_id]; @@ -849,6 +882,18 @@ void ConfigureInputPlayer::UpdateUI() { button_map[button]->setText(ButtonToText(buttons_param[button])); } + if (buttons_param[Settings::NativeButton::ZL].Has("threshold")) { + const int button_threshold = static_cast<int>( + buttons_param[Settings::NativeButton::ZL].Get("threshold", 0.5f) * 100.0f); + ui->sliderZLThreshold->setValue(button_threshold); + } + + if (buttons_param[Settings::NativeButton::ZR].Has("threshold")) { + const int button_threshold = static_cast<int>( + buttons_param[Settings::NativeButton::ZR].Get("threshold", 0.5f) * 100.0f); + ui->sliderZRThreshold->setValue(button_threshold); + } + for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { motion_map[motion_id]->setText(ButtonToText(motions_param[motion_id])); } 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 @@ </item> <item> <widget class="QGroupBox" name="buttonShoulderButtonsButtonZLGroup"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="title"> <string>ZL</string> </property> @@ -1378,6 +1384,22 @@ </property> </widget> </item> + <item> + <widget class="QSlider" name="sliderZLThreshold"> + <property name="maximumSize"> + <size> + <width>70</width> + <height>15</height> + </size> + </property> + <property name="maximum"> + <number>100</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> </layout> </widget> </item> @@ -1759,6 +1781,12 @@ </item> <item> <widget class="QGroupBox" name="buttonShoulderButtonsZRGroup"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="title"> <string>ZR</string> </property> @@ -1803,6 +1831,22 @@ </property> </widget> </item> + <item> + <widget class="QSlider" name="sliderZRThreshold"> + <property name="maximumSize"> + <size> + <width>70</width> + <height>15</height> + </size> + </property> + <property name="maximum"> + <number>100</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> </layout> </widget> </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() { ReadSetting("Renderer", Settings::values.renderer_debug); ReadSetting("Renderer", Settings::values.vulkan_device); + ReadSetting("Renderer", Settings::values.fullscreen_mode); ReadSetting("Renderer", Settings::values.aspect_ratio); ReadSetting("Renderer", Settings::values.max_anisotropy); 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 = # Which Vulkan physical device to use (defaults to 0) vulkan_device = +# Whether to use fullscreen or borderless window mode +# 0 (Windows default): Borderless window, 1 (All other default): Exclusive fullscreen +fullscreen_mode = + # Aspect ratio # 0: Default (16:9), 1: Force 4:3, 2: Force 21:9, 3: Stretch to Window aspect_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 @@ #include "common/logging/log.h" #include "common/scm_rev.h" +#include "common/settings.h" #include "core/core.h" #include "core/perf_stats.h" #include "input_common/keyboard.h" @@ -122,24 +123,37 @@ void EmuWindow_SDL2::OnResize() { } void EmuWindow_SDL2::Fullscreen() { - if (SDL_SetWindowFullscreen(render_window, SDL_WINDOW_FULLSCREEN) == 0) { - return; - } - - LOG_ERROR(Frontend, "Fullscreening failed: {}", SDL_GetError()); + switch (Settings::values.fullscreen_mode.GetValue()) { + case 1: // Exclusive fullscreen + // Set window size to render size before entering fullscreen -- SDL does not resize to + // display dimensions in this mode. + // TODO: Multiply the window size by resolution_factor (for both docked modes) + if (Settings::values.use_docked_mode) { + SDL_SetWindowSize(render_window, Layout::ScreenDocked::Width, + Layout::ScreenDocked::Height); + } - // Try a different fullscreening method - LOG_INFO(Frontend, "Attempting to use borderless fullscreen..."); - if (SDL_SetWindowFullscreen(render_window, SDL_WINDOW_FULLSCREEN_DESKTOP) == 0) { - return; - } + if (SDL_SetWindowFullscreen(render_window, SDL_WINDOW_FULLSCREEN) == 0) { + return; + } - LOG_ERROR(Frontend, "Borderless fullscreening failed: {}", SDL_GetError()); + LOG_ERROR(Frontend, "Fullscreening failed: {}", SDL_GetError()); + LOG_INFO(Frontend, "Attempting to use borderless fullscreen..."); + [[fallthrough]]; + case 0: // Borderless window + if (SDL_SetWindowFullscreen(render_window, SDL_WINDOW_FULLSCREEN_DESKTOP) == 0) { + return; + } - // Fallback algorithm: Maximise window. - // Works on all systems (unless something is seriously wrong), so no fallback for this one. - LOG_INFO(Frontend, "Falling back on a maximised window..."); - SDL_MaximizeWindow(render_window); + LOG_ERROR(Frontend, "Borderless fullscreening failed: {}", SDL_GetError()); + [[fallthrough]]; + default: + // Fallback algorithm: Maximise window. + // Works on all systems (unless something is seriously wrong), so no fallback for this one. + LOG_INFO(Frontend, "Falling back on a maximised window..."); + SDL_MaximizeWindow(render_window); + break; + } } void 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 @@ #include <SDL.h> #include <SDL_syswm.h> -EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsystem) +EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsystem, bool fullscreen) : EmuWindow_SDL2{input_subsystem} { const std::string window_title = fmt::format("yuzu {} | {}-{} (Vulkan)", Common::g_build_name, Common::g_scm_branch, Common::g_scm_desc); @@ -42,6 +42,10 @@ EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsyste SetWindowIcon(); + if (fullscreen) { + Fullscreen(); + } + switch (wm.subsystem) { #ifdef SDL_VIDEO_DRIVER_WINDOWS 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; class EmuWindow_SDL2_VK final : public EmuWindow_SDL2 { public: - explicit EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsystem); + explicit EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsystem, bool fullscreen); ~EmuWindow_SDL2_VK() override; 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) { emu_window = std::make_unique<EmuWindow_SDL2_GL>(&input_subsystem, fullscreen); break; case Settings::RendererBackend::Vulkan: - emu_window = std::make_unique<EmuWindow_SDL2_VK>(&input_subsystem); + emu_window = std::make_unique<EmuWindow_SDL2_VK>(&input_subsystem, fullscreen); break; } |