diff options
Diffstat (limited to 'src')
90 files changed, 2603 insertions, 492 deletions
diff --git a/src/audio_core/renderer/command/command_buffer.cpp b/src/audio_core/renderer/command/command_buffer.cpp index 2ef879ee1..8c6fe97e7 100644 --- a/src/audio_core/renderer/command/command_buffer.cpp +++ b/src/audio_core/renderer/command/command_buffer.cpp @@ -460,21 +460,23 @@ void CommandBuffer::GenerateDeviceSinkCommand(const s32 node_id, const s16 buffe cmd.session_id = session_id; + cmd.input_count = parameter.input_count; + s16 max_input{0}; + for (u32 i = 0; i < parameter.input_count; i++) { + cmd.inputs[i] = buffer_offset + parameter.inputs[i]; + max_input = std::max(max_input, cmd.inputs[i]); + } + if (state.upsampler_info != nullptr) { const auto size_{state.upsampler_info->sample_count * parameter.input_count}; const auto size_bytes{size_ * sizeof(s32)}; const auto addr{memory_pool->Translate(state.upsampler_info->samples_pos, size_bytes)}; cmd.sample_buffer = {reinterpret_cast<s32*>(addr), - parameter.input_count * state.upsampler_info->sample_count}; + (max_input + 1) * state.upsampler_info->sample_count}; } else { cmd.sample_buffer = samples_buffer; } - cmd.input_count = parameter.input_count; - for (u32 i = 0; i < parameter.input_count; i++) { - cmd.inputs[i] = buffer_offset + parameter.inputs[i]; - } - GenerateEnd<DeviceSinkCommand>(cmd); } diff --git a/src/common/cache_management.cpp b/src/common/cache_management.cpp index 57810b76a..ed353828a 100644 --- a/src/common/cache_management.cpp +++ b/src/common/cache_management.cpp @@ -1,11 +1,10 @@ // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include <cstdint> #include <cstring> -#include "alignment.h" -#include "cache_management.h" -#include "common_types.h" +#include "common/cache_management.h" namespace Common { diff --git a/src/common/cache_management.h b/src/common/cache_management.h index e467b87e4..038323e95 100644 --- a/src/common/cache_management.h +++ b/src/common/cache_management.h @@ -3,7 +3,7 @@ #pragma once -#include "stdlib.h" +#include <cstddef> namespace Common { diff --git a/src/common/input.h b/src/common/input.h index cb30b7254..449e0193f 100644 --- a/src/common/input.h +++ b/src/common/input.h @@ -383,6 +383,16 @@ void RegisterFactory(const std::string& name, std::shared_ptr<Factory<InputDevic } } +inline void RegisterInputFactory(const std::string& name, + std::shared_ptr<Factory<InputDevice>> factory) { + RegisterFactory<InputDevice>(name, std::move(factory)); +} + +inline void RegisterOutputFactory(const std::string& name, + std::shared_ptr<Factory<OutputDevice>> factory) { + RegisterFactory<OutputDevice>(name, std::move(factory)); +} + /** * Unregisters an input device factory. * @tparam InputDeviceType the type of input devices the factory can create @@ -395,6 +405,14 @@ void UnregisterFactory(const std::string& name) { } } +inline void UnregisterInputFactory(const std::string& name) { + UnregisterFactory<InputDevice>(name); +} + +inline void UnregisterOutputFactory(const std::string& name) { + UnregisterFactory<OutputDevice>(name); +} + /** * Create an input device from given paramters. * @tparam InputDeviceType the type of input devices to create @@ -416,13 +434,21 @@ std::unique_ptr<InputDeviceType> CreateDeviceFromString(const std::string& param return pair->second->Create(package); } +inline std::unique_ptr<InputDevice> CreateInputDeviceFromString(const std::string& params) { + return CreateDeviceFromString<InputDevice>(params); +} + +inline std::unique_ptr<OutputDevice> CreateOutputDeviceFromString(const std::string& params) { + return CreateDeviceFromString<OutputDevice>(params); +} + /** - * Create an input device from given paramters. + * Create an input device from given parameters. * @tparam InputDeviceType the type of input devices to create - * @param A ParamPackage that contains all parameters for creating the device + * @param package A ParamPackage that contains all parameters for creating the device */ template <typename InputDeviceType> -std::unique_ptr<InputDeviceType> CreateDevice(const Common::ParamPackage package) { +std::unique_ptr<InputDeviceType> CreateDevice(const ParamPackage& package) { const std::string engine = package.Get("engine", "null"); const auto& factory_list = Impl::FactoryList<InputDeviceType>::list; const auto pair = factory_list.find(engine); @@ -435,4 +461,12 @@ std::unique_ptr<InputDeviceType> CreateDevice(const Common::ParamPackage package return pair->second->Create(package); } +inline std::unique_ptr<InputDevice> CreateInputDevice(const ParamPackage& package) { + return CreateDevice<InputDevice>(package); +} + +inline std::unique_ptr<OutputDevice> CreateOutputDevice(const ParamPackage& package) { + return CreateDevice<OutputDevice>(package); +} + } // namespace Common::Input diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 8173462cb..d8ffe34c3 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -48,6 +48,7 @@ void LogSettings() { log_setting("CPU_Accuracy", values.cpu_accuracy.GetValue()); log_setting("Renderer_UseResolutionScaling", values.resolution_setup.GetValue()); log_setting("Renderer_ScalingFilter", values.scaling_filter.GetValue()); + log_setting("Renderer_FSRSlider", values.fsr_sharpening_slider.GetValue()); log_setting("Renderer_AntiAliasing", values.anti_aliasing.GetValue()); log_setting("Renderer_UseSpeedLimit", values.use_speed_limit.GetValue()); log_setting("Renderer_SpeedLimit", values.speed_limit.GetValue()); @@ -181,6 +182,7 @@ void RestoreGlobalState(bool is_powered_on) { values.cpuopt_unsafe_ignore_global_monitor.SetGlobal(true); // Renderer + values.fsr_sharpening_slider.SetGlobal(true); values.renderer_backend.SetGlobal(true); values.vulkan_device.SetGlobal(true); values.aspect_ratio.SetGlobal(true); diff --git a/src/common/settings.h b/src/common/settings.h index 0eb98939c..00e4421f7 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -421,6 +421,7 @@ struct Values { ResolutionScalingInfo resolution_info{}; SwitchableSetting<ResolutionSetup> resolution_setup{ResolutionSetup::Res1X, "resolution_setup"}; SwitchableSetting<ScalingFilter> scaling_filter{ScalingFilter::Bilinear, "scaling_filter"}; + SwitchableSetting<int, true> fsr_sharpening_slider{25, 0, 200, "fsr_sharpening_slider"}; SwitchableSetting<AntiAliasing> anti_aliasing{AntiAliasing::None, "anti_aliasing"}; // *nix platforms may have issues with the borderless windowed fullscreen mode. // Default to exclusive fullscreen on these platforms for now. @@ -442,7 +443,7 @@ struct Values { SwitchableSetting<NvdecEmulation> nvdec_emulation{NvdecEmulation::GPU, "nvdec_emulation"}; SwitchableSetting<bool> accelerate_astc{true, "accelerate_astc"}; SwitchableSetting<bool> use_vsync{true, "use_vsync"}; - SwitchableSetting<ShaderBackend, true> shader_backend{ShaderBackend::GLASM, ShaderBackend::GLSL, + SwitchableSetting<ShaderBackend, true> shader_backend{ShaderBackend::GLSL, ShaderBackend::GLSL, ShaderBackend::SPIRV, "shader_backend"}; SwitchableSetting<bool> use_asynchronous_shaders{false, "use_asynchronous_shaders"}; SwitchableSetting<bool> use_fast_gpu_time{true, "use_fast_gpu_time"}; diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index 443323390..65a9fe802 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp @@ -578,18 +578,18 @@ KeyManager::KeyManager() { if (Settings::values.use_dev_keys) { dev_mode = true; - LoadFromFile(yuzu_keys_dir / "dev.keys", false); LoadFromFile(yuzu_keys_dir / "dev.keys_autogenerated", false); + LoadFromFile(yuzu_keys_dir / "dev.keys", false); } else { dev_mode = false; - LoadFromFile(yuzu_keys_dir / "prod.keys", false); LoadFromFile(yuzu_keys_dir / "prod.keys_autogenerated", false); + LoadFromFile(yuzu_keys_dir / "prod.keys", false); } - LoadFromFile(yuzu_keys_dir / "title.keys", true); LoadFromFile(yuzu_keys_dir / "title.keys_autogenerated", true); - LoadFromFile(yuzu_keys_dir / "console.keys", false); + LoadFromFile(yuzu_keys_dir / "title.keys", true); LoadFromFile(yuzu_keys_dir / "console.keys_autogenerated", false); + LoadFromFile(yuzu_keys_dir / "console.keys", false); } static bool ValidCryptoRevisionString(std::string_view base, size_t begin, size_t length) { diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp index fb7e5802a..b6c8cc58d 100644 --- a/src/core/hid/emulated_console.cpp +++ b/src/core/hid/emulated_console.cpp @@ -68,7 +68,7 @@ void EmulatedConsole::ReloadInput() { // If you load any device here add the equivalent to the UnloadInput() function SetTouchParams(); - motion_devices = Common::Input::CreateDevice<Common::Input::InputDevice>(motion_params); + motion_devices = Common::Input::CreateInputDevice(motion_params); if (motion_devices) { motion_devices->SetCallback({ .on_change = @@ -79,7 +79,7 @@ void EmulatedConsole::ReloadInput() { // Unique index for identifying touch device source std::size_t index = 0; for (auto& touch_device : touch_devices) { - touch_device = Common::Input::CreateDevice<Common::Input::InputDevice>(touch_params[index]); + touch_device = Common::Input::CreateInputDevice(touch_params[index]); if (!touch_device) { continue; } diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index ec1364452..c96d9eef3 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include <algorithm> + #include "common/thread.h" #include "core/hid/emulated_controller.h" #include "core/hid/input_converter.h" @@ -144,29 +146,23 @@ void EmulatedController::LoadDevices() { LoadTASParams(); - std::transform(button_params.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, - button_params.begin() + Settings::NativeButton::BUTTON_NS_END, - button_devices.begin(), Common::Input::CreateDevice<Common::Input::InputDevice>); - std::transform(stick_params.begin() + Settings::NativeAnalog::STICK_HID_BEGIN, - stick_params.begin() + Settings::NativeAnalog::STICK_HID_END, - stick_devices.begin(), Common::Input::CreateDevice<Common::Input::InputDevice>); - std::transform(motion_params.begin() + Settings::NativeMotion::MOTION_HID_BEGIN, - motion_params.begin() + Settings::NativeMotion::MOTION_HID_END, - motion_devices.begin(), Common::Input::CreateDevice<Common::Input::InputDevice>); - std::transform(trigger_params.begin(), trigger_params.end(), trigger_devices.begin(), - Common::Input::CreateDevice<Common::Input::InputDevice>); - std::transform(battery_params.begin(), battery_params.end(), battery_devices.begin(), - Common::Input::CreateDevice<Common::Input::InputDevice>); - camera_devices = Common::Input::CreateDevice<Common::Input::InputDevice>(camera_params); - nfc_devices = Common::Input::CreateDevice<Common::Input::InputDevice>(nfc_params); - std::transform(output_params.begin(), output_params.end(), output_devices.begin(), - Common::Input::CreateDevice<Common::Input::OutputDevice>); + std::ranges::transform(button_params, button_devices.begin(), Common::Input::CreateInputDevice); + std::ranges::transform(stick_params, stick_devices.begin(), Common::Input::CreateInputDevice); + std::ranges::transform(motion_params, motion_devices.begin(), Common::Input::CreateInputDevice); + std::ranges::transform(trigger_params, trigger_devices.begin(), + Common::Input::CreateInputDevice); + std::ranges::transform(battery_params, battery_devices.begin(), + Common::Input::CreateInputDevice); + camera_devices = Common::Input::CreateInputDevice(camera_params); + nfc_devices = Common::Input::CreateInputDevice(nfc_params); + std::ranges::transform(output_params, output_devices.begin(), + Common::Input::CreateOutputDevice); // Initialize TAS devices - std::transform(tas_button_params.begin(), tas_button_params.end(), tas_button_devices.begin(), - Common::Input::CreateDevice<Common::Input::InputDevice>); - std::transform(tas_stick_params.begin(), tas_stick_params.end(), tas_stick_devices.begin(), - Common::Input::CreateDevice<Common::Input::InputDevice>); + std::ranges::transform(tas_button_params, tas_button_devices.begin(), + Common::Input::CreateInputDevice); + std::ranges::transform(tas_stick_params, tas_stick_devices.begin(), + Common::Input::CreateInputDevice); } void EmulatedController::LoadTASParams() { diff --git a/src/core/hid/emulated_devices.cpp b/src/core/hid/emulated_devices.cpp index 8d367b546..e421828d2 100644 --- a/src/core/hid/emulated_devices.cpp +++ b/src/core/hid/emulated_devices.cpp @@ -25,12 +25,12 @@ void EmulatedDevices::ReloadInput() { Common::ParamPackage mouse_params; mouse_params.Set("engine", "mouse"); mouse_params.Set("button", static_cast<int>(key_index)); - mouse_device = Common::Input::CreateDevice<Common::Input::InputDevice>(mouse_params); + mouse_device = Common::Input::CreateInputDevice(mouse_params); key_index++; } - mouse_stick_device = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>( - "engine:mouse,axis_x:0,axis_y:1"); + mouse_stick_device = + Common::Input::CreateInputDeviceFromString("engine:mouse,axis_x:0,axis_y:1"); // First two axis are reserved for mouse position key_index = 2; @@ -38,7 +38,7 @@ void EmulatedDevices::ReloadInput() { Common::ParamPackage mouse_params; mouse_params.Set("engine", "mouse"); mouse_params.Set("axis", static_cast<int>(key_index)); - mouse_device = Common::Input::CreateDevice<Common::Input::InputDevice>(mouse_params); + mouse_device = Common::Input::CreateInputDevice(mouse_params); key_index++; } @@ -50,7 +50,7 @@ void EmulatedDevices::ReloadInput() { keyboard_params.Set("button", static_cast<int>(key_index)); keyboard_params.Set("port", 1); keyboard_params.Set("pad", 0); - keyboard_device = Common::Input::CreateDevice<Common::Input::InputDevice>(keyboard_params); + keyboard_device = Common::Input::CreateInputDevice(keyboard_params); key_index++; } @@ -62,11 +62,11 @@ void EmulatedDevices::ReloadInput() { keyboard_params.Set("button", static_cast<int>(key_index)); keyboard_params.Set("port", 1); keyboard_params.Set("pad", 1); - keyboard_device = Common::Input::CreateDevice<Common::Input::InputDevice>(keyboard_params); + keyboard_device = Common::Input::CreateInputDevice(keyboard_params); key_index++; } - ring_analog_device = Common::Input::CreateDevice<Common::Input::InputDevice>(ring_params); + ring_analog_device = Common::Input::CreateInputDevice(ring_params); for (std::size_t index = 0; index < mouse_button_devices.size(); ++index) { if (!mouse_button_devices[index]) { @@ -145,6 +145,7 @@ void EmulatedDevices::UnloadInput() { for (auto& button : keyboard_modifier_devices) { button.reset(); } + ring_analog_device.reset(); } void EmulatedDevices::EnableConfiguration() { diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index d87be72d6..e252b5f4b 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h @@ -199,7 +199,7 @@ public: ~HLERequestContext(); /// Returns a pointer to the IPC command buffer for this request. - u32* CommandBuffer() { + [[nodiscard]] u32* CommandBuffer() { return cmd_buf.data(); } @@ -207,7 +207,7 @@ public: * Returns the session through which this request was made. This can be used as a map key to * access per-client data on services. */ - Kernel::KServerSession* Session() { + [[nodiscard]] Kernel::KServerSession* Session() { return server_session; } @@ -217,61 +217,61 @@ public: /// Writes data from this context back to the requesting process/thread. Result WriteToOutgoingCommandBuffer(KThread& requesting_thread); - u32_le GetHipcCommand() const { + [[nodiscard]] u32_le GetHipcCommand() const { return command; } - u32_le GetTipcCommand() const { + [[nodiscard]] u32_le GetTipcCommand() const { return static_cast<u32_le>(command_header->type.Value()) - static_cast<u32_le>(IPC::CommandType::TIPC_CommandRegion); } - u32_le GetCommand() const { + [[nodiscard]] u32_le GetCommand() const { return command_header->IsTipc() ? GetTipcCommand() : GetHipcCommand(); } - bool IsTipc() const { + [[nodiscard]] bool IsTipc() const { return command_header->IsTipc(); } - IPC::CommandType GetCommandType() const { + [[nodiscard]] IPC::CommandType GetCommandType() const { return command_header->type; } - u64 GetPID() const { + [[nodiscard]] u64 GetPID() const { return pid; } - u32 GetDataPayloadOffset() const { + [[nodiscard]] u32 GetDataPayloadOffset() const { return data_payload_offset; } - const std::vector<IPC::BufferDescriptorX>& BufferDescriptorX() const { + [[nodiscard]] const std::vector<IPC::BufferDescriptorX>& BufferDescriptorX() const { return buffer_x_desciptors; } - const std::vector<IPC::BufferDescriptorABW>& BufferDescriptorA() const { + [[nodiscard]] const std::vector<IPC::BufferDescriptorABW>& BufferDescriptorA() const { return buffer_a_desciptors; } - const std::vector<IPC::BufferDescriptorABW>& BufferDescriptorB() const { + [[nodiscard]] const std::vector<IPC::BufferDescriptorABW>& BufferDescriptorB() const { return buffer_b_desciptors; } - const std::vector<IPC::BufferDescriptorC>& BufferDescriptorC() const { + [[nodiscard]] const std::vector<IPC::BufferDescriptorC>& BufferDescriptorC() const { return buffer_c_desciptors; } - const IPC::DomainMessageHeader& GetDomainMessageHeader() const { + [[nodiscard]] const IPC::DomainMessageHeader& GetDomainMessageHeader() const { return domain_message_header.value(); } - bool HasDomainMessageHeader() const { + [[nodiscard]] bool HasDomainMessageHeader() const { return domain_message_header.has_value(); } /// Helper function to read a buffer using the appropriate buffer descriptor - std::vector<u8> ReadBuffer(std::size_t buffer_index = 0) const; + [[nodiscard]] std::vector<u8> ReadBuffer(std::size_t buffer_index = 0) const; /// Helper function to write a buffer using the appropriate buffer descriptor std::size_t WriteBuffer(const void* buffer, std::size_t size, @@ -308,22 +308,34 @@ public: } /// Helper function to get the size of the input buffer - std::size_t GetReadBufferSize(std::size_t buffer_index = 0) const; + [[nodiscard]] std::size_t GetReadBufferSize(std::size_t buffer_index = 0) const; /// Helper function to get the size of the output buffer - std::size_t GetWriteBufferSize(std::size_t buffer_index = 0) const; + [[nodiscard]] std::size_t GetWriteBufferSize(std::size_t buffer_index = 0) const; + + /// Helper function to derive the number of elements able to be contained in the read buffer + template <typename T> + [[nodiscard]] std::size_t GetReadBufferNumElements(std::size_t buffer_index = 0) const { + return GetReadBufferSize(buffer_index) / sizeof(T); + } + + /// Helper function to derive the number of elements able to be contained in the write buffer + template <typename T> + [[nodiscard]] std::size_t GetWriteBufferNumElements(std::size_t buffer_index = 0) const { + return GetWriteBufferSize(buffer_index) / sizeof(T); + } /// Helper function to test whether the input buffer at buffer_index can be read - bool CanReadBuffer(std::size_t buffer_index = 0) const; + [[nodiscard]] bool CanReadBuffer(std::size_t buffer_index = 0) const; /// Helper function to test whether the output buffer at buffer_index can be written - bool CanWriteBuffer(std::size_t buffer_index = 0) const; + [[nodiscard]] bool CanWriteBuffer(std::size_t buffer_index = 0) const; - Handle GetCopyHandle(std::size_t index) const { + [[nodiscard]] Handle GetCopyHandle(std::size_t index) const { return incoming_copy_handles.at(index); } - Handle GetMoveHandle(std::size_t index) const { + [[nodiscard]] Handle GetMoveHandle(std::size_t index) const { return incoming_move_handles.at(index); } @@ -348,13 +360,13 @@ public: manager = manager_; } - std::string Description() const; + [[nodiscard]] std::string Description() const; - KThread& GetThread() { + [[nodiscard]] KThread& GetThread() { return *thread; } - std::shared_ptr<SessionRequestManager> GetManager() const { + [[nodiscard]] std::shared_ptr<SessionRequestManager> GetManager() const { return manager.lock(); } diff --git a/src/core/hle/service/audio/audin_u.cpp b/src/core/hle/service/audio/audin_u.cpp index 608925dfc..053e8f9dd 100644 --- a/src/core/hle/service/audio/audin_u.cpp +++ b/src/core/hle/service/audio/audin_u.cpp @@ -122,10 +122,10 @@ private: } void GetReleasedAudioInBuffer(Kernel::HLERequestContext& ctx) { - auto write_buffer_size = ctx.GetWriteBufferSize() / sizeof(u64); - std::vector<u64> released_buffers(write_buffer_size, 0); + const auto write_buffer_size = ctx.GetWriteBufferNumElements<u64>(); + std::vector<u64> released_buffers(write_buffer_size); - auto count = impl->GetReleasedBuffers(released_buffers); + const auto count = impl->GetReleasedBuffers(released_buffers); [[maybe_unused]] std::string tags{}; for (u32 i = 0; i < count; i++) { @@ -228,7 +228,7 @@ void AudInU::ListAudioIns(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); const auto write_count = - static_cast<u32>(ctx.GetWriteBufferSize() / sizeof(AudioDevice::AudioDeviceName)); + static_cast<u32>(ctx.GetWriteBufferNumElements<AudioDevice::AudioDeviceName>()); std::vector<AudioDevice::AudioDeviceName> device_names{}; u32 out_count{0}; @@ -248,7 +248,7 @@ void AudInU::ListAudioInsAutoFiltered(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_Audio, "called"); const auto write_count = - static_cast<u32>(ctx.GetWriteBufferSize() / sizeof(AudioDevice::AudioDeviceName)); + static_cast<u32>(ctx.GetWriteBufferNumElements<AudioDevice::AudioDeviceName>()); std::vector<AudioDevice::AudioDeviceName> device_names{}; u32 out_count{0}; diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp index 122290c6a..29751f075 100644 --- a/src/core/hle/service/audio/audout_u.cpp +++ b/src/core/hle/service/audio/audout_u.cpp @@ -129,16 +129,16 @@ private: } void GetReleasedAudioOutBuffers(Kernel::HLERequestContext& ctx) { - auto write_buffer_size = ctx.GetWriteBufferSize() / sizeof(u64); - std::vector<u64> released_buffers(write_buffer_size, 0); + const auto write_buffer_size = ctx.GetWriteBufferNumElements<u64>(); + std::vector<u64> released_buffers(write_buffer_size); - auto count = impl->GetReleasedBuffers(released_buffers); + const auto count = impl->GetReleasedBuffers(released_buffers); [[maybe_unused]] std::string tags{}; for (u32 i = 0; i < count; i++) { tags += fmt::format("{:08X}, ", released_buffers[i]); } - [[maybe_unused]] auto sessionid{impl->GetSystem().GetSessionId()}; + [[maybe_unused]] const auto sessionid{impl->GetSystem().GetSessionId()}; LOG_TRACE(Service_Audio, "called. Session {} released {} buffers: {}", sessionid, count, tags); @@ -244,7 +244,7 @@ void AudOutU::ListAudioOuts(Kernel::HLERequestContext& ctx) { std::scoped_lock l{impl->mutex}; const auto write_count = - static_cast<u32>(ctx.GetWriteBufferSize() / sizeof(AudioDevice::AudioDeviceName)); + static_cast<u32>(ctx.GetWriteBufferNumElements<AudioDevice::AudioDeviceName>()); std::vector<AudioDevice::AudioDeviceName> device_names{}; if (write_count > 0) { device_names.emplace_back("DeviceOut"); diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp index 13423dca6..034ee273f 100644 --- a/src/core/hle/service/audio/audren_u.cpp +++ b/src/core/hle/service/audio/audren_u.cpp @@ -274,7 +274,7 @@ public: private: void ListAudioDeviceName(Kernel::HLERequestContext& ctx) { - const size_t in_count = ctx.GetWriteBufferSize() / sizeof(AudioDevice::AudioDeviceName); + const size_t in_count = ctx.GetWriteBufferNumElements<AudioDevice::AudioDeviceName>(); std::vector<AudioDevice::AudioDeviceName> out_names{}; @@ -335,7 +335,7 @@ private: } void GetActiveAudioDeviceName(Kernel::HLERequestContext& ctx) { - const auto write_size = ctx.GetWriteBufferSize() / sizeof(char); + const auto write_size = ctx.GetWriteBufferSize(); std::string out_name{"AudioTvOutput"}; LOG_DEBUG(Service_Audio, "(STUBBED) called. Name={}", out_name); @@ -387,7 +387,7 @@ private: } void ListAudioOutputDeviceName(Kernel::HLERequestContext& ctx) { - const size_t in_count = ctx.GetWriteBufferSize() / sizeof(AudioDevice::AudioDeviceName); + const size_t in_count = ctx.GetWriteBufferNumElements<AudioDevice::AudioDeviceName>(); std::vector<AudioDevice::AudioDeviceName> out_names{}; diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp index 8bafc3a98..825fb8bcc 100644 --- a/src/core/hle/service/audio/hwopus.cpp +++ b/src/core/hle/service/audio/hwopus.cpp @@ -68,7 +68,7 @@ private: ExtraBehavior extra_behavior) { u32 consumed = 0; u32 sample_count = 0; - std::vector<opus_int16> samples(ctx.GetWriteBufferSize() / sizeof(opus_int16)); + std::vector<opus_int16> samples(ctx.GetWriteBufferNumElements<opus_int16>()); if (extra_behavior == ExtraBehavior::ResetContext) { ResetDecoderContext(); diff --git a/src/core/hle/service/bcat/bcat_module.cpp b/src/core/hle/service/bcat/bcat_module.cpp index bc08ac487..cbe690a5d 100644 --- a/src/core/hle/service/bcat/bcat_module.cpp +++ b/src/core/hle/service/bcat/bcat_module.cpp @@ -443,7 +443,7 @@ private: } void Read(Kernel::HLERequestContext& ctx) { - auto write_size = ctx.GetWriteBufferSize() / sizeof(DeliveryCacheDirectoryEntry); + auto write_size = ctx.GetWriteBufferNumElements<DeliveryCacheDirectoryEntry>(); LOG_DEBUG(Service_BCAT, "called, write_size={:016X}", write_size); @@ -533,7 +533,7 @@ private: } void EnumerateDeliveryCacheDirectory(Kernel::HLERequestContext& ctx) { - auto size = ctx.GetWriteBufferSize() / sizeof(DirectoryName); + auto size = ctx.GetWriteBufferNumElements<DirectoryName>(); LOG_DEBUG(Service_BCAT, "called, size={:016X}", size); diff --git a/src/core/hle/service/es/es.cpp b/src/core/hle/service/es/es.cpp index ff9b0427c..d183e5829 100644 --- a/src/core/hle/service/es/es.cpp +++ b/src/core/hle/service/es/es.cpp @@ -192,12 +192,10 @@ private: } void ListCommonTicketRightsIds(Kernel::HLERequestContext& ctx) { - u32 out_entries; - if (keys.GetCommonTickets().empty()) - out_entries = 0; - else - out_entries = static_cast<u32>(ctx.GetWriteBufferSize() / sizeof(u128)); - + size_t out_entries = 0; + if (!keys.GetCommonTickets().empty()) { + out_entries = ctx.GetWriteBufferNumElements<u128>(); + } LOG_DEBUG(Service_ETicket, "called, entries={:016X}", out_entries); keys.PopulateTickets(); @@ -206,20 +204,19 @@ private: std::transform(tickets.begin(), tickets.end(), std::back_inserter(ids), [](const auto& pair) { return pair.first; }); - out_entries = static_cast<u32>(std::min<std::size_t>(ids.size(), out_entries)); + out_entries = std::min(ids.size(), out_entries); ctx.WriteBuffer(ids.data(), out_entries * sizeof(u128)); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); - rb.Push<u32>(out_entries); + rb.Push<u32>(static_cast<u32>(out_entries)); } void ListPersonalizedTicketRightsIds(Kernel::HLERequestContext& ctx) { - u32 out_entries; - if (keys.GetPersonalizedTickets().empty()) - out_entries = 0; - else - out_entries = static_cast<u32>(ctx.GetWriteBufferSize() / sizeof(u128)); + size_t out_entries = 0; + if (!keys.GetPersonalizedTickets().empty()) { + out_entries = ctx.GetWriteBufferNumElements<u128>(); + } LOG_DEBUG(Service_ETicket, "called, entries={:016X}", out_entries); @@ -229,12 +226,12 @@ private: std::transform(tickets.begin(), tickets.end(), std::back_inserter(ids), [](const auto& pair) { return pair.first; }); - out_entries = static_cast<u32>(std::min<std::size_t>(ids.size(), out_entries)); + out_entries = std::min(ids.size(), out_entries); ctx.WriteBuffer(ids.data(), out_entries * sizeof(u128)); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); - rb.Push<u32>(out_entries); + rb.Push<u32>(static_cast<u32>(out_entries)); } void GetCommonTicketSize(Kernel::HLERequestContext& ctx) { diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index c08274ef9..fbb16a7da 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -277,7 +277,7 @@ private: LOG_DEBUG(Service_FS, "called."); // Calculate how many entries we can fit in the output buffer - const u64 count_entries = ctx.GetWriteBufferSize() / sizeof(FileSys::Entry); + const u64 count_entries = ctx.GetWriteBufferNumElements<FileSys::Entry>(); // Cap at total number of entries. const u64 actual_entries = std::min(count_entries, entries.size() - next_entry_index); @@ -543,7 +543,7 @@ public: LOG_DEBUG(Service_FS, "called"); // Calculate how many entries we can fit in the output buffer - const u64 count_entries = ctx.GetWriteBufferSize() / sizeof(SaveDataInfo); + const u64 count_entries = ctx.GetWriteBufferNumElements<SaveDataInfo>(); // Cap at total number of entries. const u64 actual_entries = std::min(count_entries, info.size() - next_entry_index); diff --git a/src/core/hle/service/ldn/ldn.cpp b/src/core/hle/service/ldn/ldn.cpp index 6df563136..c49c61cff 100644 --- a/src/core/hle/service/ldn/ldn.cpp +++ b/src/core/hle/service/ldn/ldn.cpp @@ -292,7 +292,7 @@ public: void GetNetworkInfoLatestUpdate(Kernel::HLERequestContext& ctx) { const std::size_t network_buffer_size = ctx.GetWriteBufferSize(0); - const std::size_t node_buffer_count = ctx.GetWriteBufferSize(1) / sizeof(NodeLatestUpdate); + const std::size_t node_buffer_count = ctx.GetWriteBufferNumElements<NodeLatestUpdate>(1); if (node_buffer_count == 0 || network_buffer_size != sizeof(NetworkInfo)) { LOG_ERROR(Service_LDN, "Invalid buffer, size = {}, count = {}", network_buffer_size, @@ -333,7 +333,7 @@ public: const auto channel{rp.PopEnum<WifiChannel>()}; const auto scan_filter{rp.PopRaw<ScanFilter>()}; - const std::size_t network_info_size = ctx.GetWriteBufferSize() / sizeof(NetworkInfo); + const std::size_t network_info_size = ctx.GetWriteBufferNumElements<NetworkInfo>(); if (network_info_size == 0) { LOG_ERROR(Service_LDN, "Invalid buffer size {}", network_info_size); diff --git a/src/core/hle/service/nfc/nfc_user.cpp b/src/core/hle/service/nfc/nfc_user.cpp index 0753333bf..ced2d560b 100644 --- a/src/core/hle/service/nfc/nfc_user.cpp +++ b/src/core/hle/service/nfc/nfc_user.cpp @@ -118,7 +118,7 @@ void IUser::ListDevices(Kernel::HLERequestContext& ctx) { } std::vector<u64> nfp_devices; - const std::size_t max_allowed_devices = ctx.GetWriteBufferSize() / sizeof(u64); + const std::size_t max_allowed_devices = ctx.GetWriteBufferNumElements<u64>(); for (auto& device : devices) { if (nfp_devices.size() >= max_allowed_devices) { diff --git a/src/core/hle/service/nfp/nfp_user.cpp b/src/core/hle/service/nfp/nfp_user.cpp index 2fe3c0ea0..49816b4c7 100644 --- a/src/core/hle/service/nfp/nfp_user.cpp +++ b/src/core/hle/service/nfp/nfp_user.cpp @@ -104,9 +104,9 @@ void IUser::ListDevices(Kernel::HLERequestContext& ctx) { } std::vector<u64> nfp_devices; - const std::size_t max_allowed_devices = ctx.GetWriteBufferSize() / sizeof(u64); + const std::size_t max_allowed_devices = ctx.GetWriteBufferNumElements<u64>(); - for (auto& device : devices) { + for (const auto& device : devices) { if (nfp_devices.size() >= max_allowed_devices) { continue; } @@ -115,7 +115,7 @@ void IUser::ListDevices(Kernel::HLERequestContext& ctx) { } } - if (nfp_devices.size() == 0) { + if (nfp_devices.empty()) { IPC::ResponseBuilder rb{ctx, 2}; rb.Push(DeviceNotFound); return; diff --git a/src/core/hle/service/ns/iplatform_service_manager.cpp b/src/core/hle/service/ns/iplatform_service_manager.cpp index fd047ff26..1fab2f0dd 100644 --- a/src/core/hle/service/ns/iplatform_service_manager.cpp +++ b/src/core/hle/service/ns/iplatform_service_manager.cpp @@ -279,13 +279,10 @@ void IPlatformServiceManager::GetSharedFontInOrderOfPriority(Kernel::HLERequestC font_sizes.push_back(region.size); } - // Resize buffers if game requests smaller size output. - font_codes.resize( - std::min<std::size_t>(font_codes.size(), ctx.GetWriteBufferSize(0) / sizeof(u32))); - font_offsets.resize( - std::min<std::size_t>(font_offsets.size(), ctx.GetWriteBufferSize(1) / sizeof(u32))); - font_sizes.resize( - std::min<std::size_t>(font_sizes.size(), ctx.GetWriteBufferSize(2) / sizeof(u32))); + // Resize buffers if game requests smaller size output + font_codes.resize(std::min(font_codes.size(), ctx.GetWriteBufferNumElements<u32>(0))); + font_offsets.resize(std::min(font_offsets.size(), ctx.GetWriteBufferNumElements<u32>(1))); + font_sizes.resize(std::min(font_sizes.size(), ctx.GetWriteBufferNumElements<u32>(2))); ctx.WriteBuffer(font_codes, 0); ctx.WriteBuffer(font_offsets, 1); diff --git a/src/core/hle/service/nvdrv/core/syncpoint_manager.cpp b/src/core/hle/service/nvdrv/core/syncpoint_manager.cpp index eda2041a0..aba51d280 100644 --- a/src/core/hle/service/nvdrv/core/syncpoint_manager.cpp +++ b/src/core/hle/service/nvdrv/core/syncpoint_manager.cpp @@ -28,13 +28,15 @@ SyncpointManager::SyncpointManager(Tegra::Host1x::Host1x& host1x_) : host1x{host SyncpointManager::~SyncpointManager() = default; u32 SyncpointManager::ReserveSyncpoint(u32 id, bool client_managed) { - if (syncpoints.at(id).reserved) { + auto& syncpoint = syncpoints.at(id); + + if (syncpoint.reserved) { ASSERT_MSG(false, "Requested syncpoint is in use"); return 0; } - syncpoints.at(id).reserved = true; - syncpoints.at(id).interface_managed = client_managed; + syncpoint.reserved = true; + syncpoint.interface_managed = client_managed; return id; } @@ -56,11 +58,12 @@ u32 SyncpointManager::AllocateSyncpoint(bool client_managed) { void SyncpointManager::FreeSyncpoint(u32 id) { std::lock_guard lock(reservation_lock); - ASSERT(syncpoints.at(id).reserved); - syncpoints.at(id).reserved = false; + auto& syncpoint = syncpoints.at(id); + ASSERT(syncpoint.reserved); + syncpoint.reserved = false; } -bool SyncpointManager::IsSyncpointAllocated(u32 id) { +bool SyncpointManager::IsSyncpointAllocated(u32 id) const { return (id <= SyncpointCount) && syncpoints[id].reserved; } @@ -69,7 +72,7 @@ bool SyncpointManager::HasSyncpointExpired(u32 id, u32 threshold) const { if (!syncpoint.reserved) { ASSERT(false); - return 0; + return false; } // If the interface manages counters then we don't keep track of the maximum value as it handles @@ -82,40 +85,51 @@ bool SyncpointManager::HasSyncpointExpired(u32 id, u32 threshold) const { } u32 SyncpointManager::IncrementSyncpointMaxExt(u32 id, u32 amount) { - if (!syncpoints.at(id).reserved) { + auto& syncpoint = syncpoints.at(id); + + if (!syncpoint.reserved) { ASSERT(false); return 0; } - return syncpoints.at(id).counter_max += amount; + return syncpoint.counter_max += amount; } u32 SyncpointManager::ReadSyncpointMinValue(u32 id) { - if (!syncpoints.at(id).reserved) { + auto& syncpoint = syncpoints.at(id); + + if (!syncpoint.reserved) { ASSERT(false); return 0; } - return syncpoints.at(id).counter_min; + return syncpoint.counter_min; } u32 SyncpointManager::UpdateMin(u32 id) { - if (!syncpoints.at(id).reserved) { + auto& syncpoint = syncpoints.at(id); + + if (!syncpoint.reserved) { ASSERT(false); return 0; } - syncpoints.at(id).counter_min = host1x.GetSyncpointManager().GetHostSyncpointValue(id); - return syncpoints.at(id).counter_min; + syncpoint.counter_min = host1x.GetSyncpointManager().GetHostSyncpointValue(id); + return syncpoint.counter_min; } NvFence SyncpointManager::GetSyncpointFence(u32 id) { - if (!syncpoints.at(id).reserved) { + auto& syncpoint = syncpoints.at(id); + + if (!syncpoint.reserved) { ASSERT(false); return NvFence{}; } - return {.id = static_cast<s32>(id), .value = syncpoints.at(id).counter_max}; + return { + .id = static_cast<s32>(id), + .value = syncpoint.counter_max, + }; } } // namespace Service::Nvidia::NvCore diff --git a/src/core/hle/service/nvdrv/core/syncpoint_manager.h b/src/core/hle/service/nvdrv/core/syncpoint_manager.h index b76ef9032..4f2cefae5 100644 --- a/src/core/hle/service/nvdrv/core/syncpoint_manager.h +++ b/src/core/hle/service/nvdrv/core/syncpoint_manager.h @@ -44,7 +44,7 @@ public: /** * @brief Checks if the given syncpoint is both allocated and below the number of HW syncpoints */ - bool IsSyncpointAllocated(u32 id); + bool IsSyncpointAllocated(u32 id) const; /** * @brief Finds a free syncpoint and reserves it diff --git a/src/core/hle/service/nvdrv/nvdrv.cpp b/src/core/hle/service/nvdrv/nvdrv.cpp index 9f4c7c99a..6fc8565c0 100644 --- a/src/core/hle/service/nvdrv/nvdrv.cpp +++ b/src/core/hle/service/nvdrv/nvdrv.cpp @@ -55,48 +55,40 @@ void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger Module::Module(Core::System& system) : container{system.Host1x()}, service_context{system, "nvdrv"}, events_interface{*this} { builders["/dev/nvhost-as-gpu"] = [this, &system](DeviceFD fd) { - std::shared_ptr<Devices::nvdevice> device = - std::make_shared<Devices::nvhost_as_gpu>(system, *this, container); - return open_files.emplace(fd, device).first; + auto device = std::make_shared<Devices::nvhost_as_gpu>(system, *this, container); + return open_files.emplace(fd, std::move(device)).first; }; builders["/dev/nvhost-gpu"] = [this, &system](DeviceFD fd) { - std::shared_ptr<Devices::nvdevice> device = - std::make_shared<Devices::nvhost_gpu>(system, events_interface, container); - return open_files.emplace(fd, device).first; + auto device = std::make_shared<Devices::nvhost_gpu>(system, events_interface, container); + return open_files.emplace(fd, std::move(device)).first; }; builders["/dev/nvhost-ctrl-gpu"] = [this, &system](DeviceFD fd) { - std::shared_ptr<Devices::nvdevice> device = - std::make_shared<Devices::nvhost_ctrl_gpu>(system, events_interface); - return open_files.emplace(fd, device).first; + auto device = std::make_shared<Devices::nvhost_ctrl_gpu>(system, events_interface); + return open_files.emplace(fd, std::move(device)).first; }; builders["/dev/nvmap"] = [this, &system](DeviceFD fd) { - std::shared_ptr<Devices::nvdevice> device = - std::make_shared<Devices::nvmap>(system, container); - return open_files.emplace(fd, device).first; + auto device = std::make_shared<Devices::nvmap>(system, container); + return open_files.emplace(fd, std::move(device)).first; }; builders["/dev/nvdisp_disp0"] = [this, &system](DeviceFD fd) { - std::shared_ptr<Devices::nvdevice> device = - std::make_shared<Devices::nvdisp_disp0>(system, container); - return open_files.emplace(fd, device).first; + auto device = std::make_shared<Devices::nvdisp_disp0>(system, container); + return open_files.emplace(fd, std::move(device)).first; }; builders["/dev/nvhost-ctrl"] = [this, &system](DeviceFD fd) { - std::shared_ptr<Devices::nvdevice> device = - std::make_shared<Devices::nvhost_ctrl>(system, events_interface, container); - return open_files.emplace(fd, device).first; + auto device = std::make_shared<Devices::nvhost_ctrl>(system, events_interface, container); + return open_files.emplace(fd, std::move(device)).first; }; builders["/dev/nvhost-nvdec"] = [this, &system](DeviceFD fd) { - std::shared_ptr<Devices::nvdevice> device = - std::make_shared<Devices::nvhost_nvdec>(system, container); - return open_files.emplace(fd, device).first; + auto device = std::make_shared<Devices::nvhost_nvdec>(system, container); + return open_files.emplace(fd, std::move(device)).first; }; builders["/dev/nvhost-nvjpg"] = [this, &system](DeviceFD fd) { - std::shared_ptr<Devices::nvdevice> device = std::make_shared<Devices::nvhost_nvjpg>(system); - return open_files.emplace(fd, device).first; + auto device = std::make_shared<Devices::nvhost_nvjpg>(system); + return open_files.emplace(fd, std::move(device)).first; }; builders["/dev/nvhost-vic"] = [this, &system](DeviceFD fd) { - std::shared_ptr<Devices::nvdevice> device = - std::make_shared<Devices::nvhost_vic>(system, container); - return open_files.emplace(fd, device).first; + auto device = std::make_shared<Devices::nvhost_vic>(system, container); + return open_files.emplace(fd, std::move(device)).first; }; } diff --git a/src/core/hle/service/nvflinger/buffer_item_consumer.cpp b/src/core/hle/service/nvflinger/buffer_item_consumer.cpp index 6d2c92a2c..152bb5bdf 100644 --- a/src/core/hle/service/nvflinger/buffer_item_consumer.cpp +++ b/src/core/hle/service/nvflinger/buffer_item_consumer.cpp @@ -39,7 +39,7 @@ Status BufferItemConsumer::AcquireBuffer(BufferItem* item, std::chrono::nanoseco return Status::NoError; } -Status BufferItemConsumer::ReleaseBuffer(const BufferItem& item, Fence& release_fence) { +Status BufferItemConsumer::ReleaseBuffer(const BufferItem& item, const Fence& release_fence) { std::scoped_lock lock{mutex}; if (const auto status = AddReleaseFenceLocked(item.buf, item.graphic_buffer, release_fence); diff --git a/src/core/hle/service/nvflinger/buffer_item_consumer.h b/src/core/hle/service/nvflinger/buffer_item_consumer.h index 69046233d..a5c655d9e 100644 --- a/src/core/hle/service/nvflinger/buffer_item_consumer.h +++ b/src/core/hle/service/nvflinger/buffer_item_consumer.h @@ -22,7 +22,7 @@ public: explicit BufferItemConsumer(std::unique_ptr<BufferQueueConsumer> consumer); Status AcquireBuffer(BufferItem* item, std::chrono::nanoseconds present_when, bool wait_for_fence = true); - Status ReleaseBuffer(const BufferItem& item, Fence& release_fence); + Status ReleaseBuffer(const BufferItem& item, const Fence& release_fence); }; } // namespace Service::android diff --git a/src/core/hle/service/nvflinger/buffer_queue_consumer.cpp b/src/core/hle/service/nvflinger/buffer_queue_consumer.cpp index 1ce67c771..0767e548d 100644 --- a/src/core/hle/service/nvflinger/buffer_queue_consumer.cpp +++ b/src/core/hle/service/nvflinger/buffer_queue_consumer.cpp @@ -169,7 +169,7 @@ Status BufferQueueConsumer::Connect(std::shared_ptr<IConsumerListener> consumer_ return Status::NoInit; } - core->consumer_listener = consumer_listener; + core->consumer_listener = std::move(consumer_listener); core->consumer_controlled_by_app = controlled_by_app; return Status::NoError; diff --git a/src/core/hle/service/nvflinger/consumer_base.cpp b/src/core/hle/service/nvflinger/consumer_base.cpp index 5b9995854..982531e2d 100644 --- a/src/core/hle/service/nvflinger/consumer_base.cpp +++ b/src/core/hle/service/nvflinger/consumer_base.cpp @@ -83,7 +83,7 @@ Status ConsumerBase::AcquireBufferLocked(BufferItem* item, std::chrono::nanoseco } Status ConsumerBase::AddReleaseFenceLocked(s32 slot, - const std::shared_ptr<GraphicBuffer> graphic_buffer, + const std::shared_ptr<GraphicBuffer>& graphic_buffer, const Fence& fence) { LOG_DEBUG(Service_NVFlinger, "slot={}", slot); @@ -100,7 +100,7 @@ Status ConsumerBase::AddReleaseFenceLocked(s32 slot, } Status ConsumerBase::ReleaseBufferLocked(s32 slot, - const std::shared_ptr<GraphicBuffer> graphic_buffer) { + const std::shared_ptr<GraphicBuffer>& graphic_buffer) { // If consumer no longer tracks this graphic_buffer (we received a new // buffer on the same slot), the buffer producer is definitely no longer // tracking it. @@ -121,7 +121,7 @@ Status ConsumerBase::ReleaseBufferLocked(s32 slot, } bool ConsumerBase::StillTracking(s32 slot, - const std::shared_ptr<GraphicBuffer> graphic_buffer) const { + const std::shared_ptr<GraphicBuffer>& graphic_buffer) const { if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS) { return false; } diff --git a/src/core/hle/service/nvflinger/consumer_base.h b/src/core/hle/service/nvflinger/consumer_base.h index 90ba07f45..9a8a5f6bb 100644 --- a/src/core/hle/service/nvflinger/consumer_base.h +++ b/src/core/hle/service/nvflinger/consumer_base.h @@ -27,18 +27,18 @@ public: protected: explicit ConsumerBase(std::unique_ptr<BufferQueueConsumer> consumer_); - virtual ~ConsumerBase(); + ~ConsumerBase() override; - virtual void OnFrameAvailable(const BufferItem& item) override; - virtual void OnFrameReplaced(const BufferItem& item) override; - virtual void OnBuffersReleased() override; - virtual void OnSidebandStreamChanged() override; + void OnFrameAvailable(const BufferItem& item) override; + void OnFrameReplaced(const BufferItem& item) override; + void OnBuffersReleased() override; + void OnSidebandStreamChanged() override; void FreeBufferLocked(s32 slot_index); Status AcquireBufferLocked(BufferItem* item, std::chrono::nanoseconds present_when); - Status ReleaseBufferLocked(s32 slot, const std::shared_ptr<GraphicBuffer> graphic_buffer); - bool StillTracking(s32 slot, const std::shared_ptr<GraphicBuffer> graphic_buffer) const; - Status AddReleaseFenceLocked(s32 slot, const std::shared_ptr<GraphicBuffer> graphic_buffer, + Status ReleaseBufferLocked(s32 slot, const std::shared_ptr<GraphicBuffer>& graphic_buffer); + bool StillTracking(s32 slot, const std::shared_ptr<GraphicBuffer>& graphic_buffer) const; + Status AddReleaseFenceLocked(s32 slot, const std::shared_ptr<GraphicBuffer>& graphic_buffer, const Fence& fence); struct Slot final { diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp index c3af12c90..d1cbadde4 100644 --- a/src/core/hle/service/nvflinger/nvflinger.cpp +++ b/src/core/hle/service/nvflinger/nvflinger.cpp @@ -307,8 +307,7 @@ void NVFlinger::Compose() { swap_interval = buffer.swap_interval; - auto fence = android::Fence::NoFence(); - layer.GetConsumer().ReleaseBuffer(buffer, fence); + layer.GetConsumer().ReleaseBuffer(buffer, android::Fence::NoFence()); } } diff --git a/src/core/hle/service/nvflinger/producer_listener.h b/src/core/hle/service/nvflinger/producer_listener.h index 1c4d5db0e..6bf8aaf1e 100644 --- a/src/core/hle/service/nvflinger/producer_listener.h +++ b/src/core/hle/service/nvflinger/producer_listener.h @@ -10,6 +10,7 @@ namespace Service::android { class IProducerListener { public: + virtual ~IProducerListener() = default; virtual void OnBufferReleased() = 0; }; diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp index f761c2da4..4f1a8d6b7 100644 --- a/src/core/hle/service/set/set.cpp +++ b/src/core/hle/service/set/set.cpp @@ -83,7 +83,7 @@ void PushResponseLanguageCode(Kernel::HLERequestContext& ctx, std::size_t num_la } void GetAvailableLanguageCodesImpl(Kernel::HLERequestContext& ctx, std::size_t max_entries) { - const std::size_t requested_amount = ctx.GetWriteBufferSize() / sizeof(LanguageCode); + const std::size_t requested_amount = ctx.GetWriteBufferNumElements<LanguageCode>(); const std::size_t max_amount = std::min(requested_amount, max_entries); const std::size_t copy_amount = std::min(available_language_codes.size(), max_amount); const std::size_t copy_size = copy_amount * sizeof(LanguageCode); diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index 45ce588f0..8de86b61e 100644 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp @@ -361,6 +361,12 @@ void SDLDriver::CloseJoystick(SDL_Joystick* sdl_joystick) { } } +void SDLDriver::PumpEvents() const { + if (initialized) { + SDL_PumpEvents(); + } +} + void SDLDriver::HandleGameControllerEvent(const SDL_Event& event) { switch (event.type) { case SDL_JOYBUTTONUP: { @@ -451,14 +457,6 @@ SDLDriver::SDLDriver(std::string input_engine_) : InputEngine(std::move(input_en initialized = true; if (start_thread) { - poll_thread = std::thread([this] { - Common::SetCurrentThreadName("SDL_MainLoop"); - using namespace std::chrono_literals; - while (initialized) { - SDL_PumpEvents(); - std::this_thread::sleep_for(1ms); - } - }); vibration_thread = std::thread([this] { Common::SetCurrentThreadName("SDL_Vibration"); using namespace std::chrono_literals; @@ -481,7 +479,6 @@ SDLDriver::~SDLDriver() { initialized = false; if (start_thread) { - poll_thread.join(); vibration_thread.join(); SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER); } diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h index d1b4471cf..366bcc496 100644 --- a/src/input_common/drivers/sdl_driver.h +++ b/src/input_common/drivers/sdl_driver.h @@ -36,6 +36,8 @@ public: /// Unregisters SDL device factories and shut them down. ~SDLDriver() override; + void PumpEvents() const; + /// Handle SDL_Events for joysticks from SDL_PollEvent void HandleGameControllerEvent(const SDL_Event& event); @@ -128,7 +130,6 @@ private: bool start_thread = false; std::atomic<bool> initialized = false; - std::thread poll_thread; std::thread vibration_thread; }; } // namespace InputCommon diff --git a/src/input_common/helpers/stick_from_buttons.cpp b/src/input_common/helpers/stick_from_buttons.cpp index 536d413a5..82aa6ac2f 100644 --- a/src/input_common/helpers/stick_from_buttons.cpp +++ b/src/input_common/helpers/stick_from_buttons.cpp @@ -294,6 +294,15 @@ public: } private: + static constexpr Common::Input::AnalogProperties properties{ + .deadzone = 0.0f, + .range = 1.0f, + .threshold = 0.5f, + .offset = 0.0f, + .inverted = false, + .toggle = false, + }; + Button up; Button down; Button left; @@ -311,23 +320,17 @@ private: float last_x_axis_value{}; float last_y_axis_value{}; Common::Input::ButtonStatus modifier_status{}; - const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; std::chrono::time_point<std::chrono::steady_clock> last_update; }; std::unique_ptr<Common::Input::InputDevice> StickFromButton::Create( const Common::ParamPackage& params) { const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize(); - auto up = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>( - params.Get("up", null_engine)); - auto down = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>( - params.Get("down", null_engine)); - auto left = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>( - params.Get("left", null_engine)); - auto right = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>( - params.Get("right", null_engine)); - auto modifier = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>( - params.Get("modifier", null_engine)); + auto up = Common::Input::CreateInputDeviceFromString(params.Get("up", null_engine)); + auto down = Common::Input::CreateInputDeviceFromString(params.Get("down", null_engine)); + auto left = Common::Input::CreateInputDeviceFromString(params.Get("left", null_engine)); + auto right = Common::Input::CreateInputDeviceFromString(params.Get("right", null_engine)); + auto modifier = Common::Input::CreateInputDeviceFromString(params.Get("modifier", null_engine)); auto modifier_scale = params.Get("modifier_scale", 0.5f); auto modifier_angle = params.Get("modifier_angle", 5.5f); return std::make_unique<Stick>(std::move(up), std::move(down), std::move(left), diff --git a/src/input_common/helpers/touch_from_buttons.cpp b/src/input_common/helpers/touch_from_buttons.cpp index 003a38da5..e064b13d9 100644 --- a/src/input_common/helpers/touch_from_buttons.cpp +++ b/src/input_common/helpers/touch_from_buttons.cpp @@ -59,18 +59,25 @@ public: } private: + static constexpr Common::Input::AnalogProperties properties{ + .deadzone = 0.0f, + .range = 1.0f, + .threshold = 0.5f, + .offset = 0.0f, + .inverted = false, + .toggle = false, + }; + Button button; bool last_button_value; const float x; const float y; - const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; }; std::unique_ptr<Common::Input::InputDevice> TouchFromButton::Create( const Common::ParamPackage& params) { const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize(); - auto button = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>( - params.Get("button", null_engine)); + auto button = Common::Input::CreateInputDeviceFromString(params.Get("button", null_engine)); const float x = params.Get("x", 0.0f) / 1280.0f; const float y = params.Get("y", 0.0f) / 720.0f; return std::make_unique<TouchFromButtonDevice>(std::move(button), x, y); diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index b2064ef95..942a13535 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -33,119 +33,113 @@ struct InputSubsystem::Impl { keyboard->SetMappingCallback(mapping_callback); keyboard_factory = std::make_shared<InputFactory>(keyboard); keyboard_output_factory = std::make_shared<OutputFactory>(keyboard); - Common::Input::RegisterFactory<Common::Input::InputDevice>(keyboard->GetEngineName(), - keyboard_factory); - Common::Input::RegisterFactory<Common::Input::OutputDevice>(keyboard->GetEngineName(), - keyboard_output_factory); + Common::Input::RegisterInputFactory(keyboard->GetEngineName(), keyboard_factory); + Common::Input::RegisterOutputFactory(keyboard->GetEngineName(), keyboard_output_factory); mouse = std::make_shared<Mouse>("mouse"); mouse->SetMappingCallback(mapping_callback); mouse_factory = std::make_shared<InputFactory>(mouse); mouse_output_factory = std::make_shared<OutputFactory>(mouse); - Common::Input::RegisterFactory<Common::Input::InputDevice>(mouse->GetEngineName(), - mouse_factory); - Common::Input::RegisterFactory<Common::Input::OutputDevice>(mouse->GetEngineName(), - mouse_output_factory); + Common::Input::RegisterInputFactory(mouse->GetEngineName(), mouse_factory); + Common::Input::RegisterOutputFactory(mouse->GetEngineName(), mouse_output_factory); touch_screen = std::make_shared<TouchScreen>("touch"); touch_screen_factory = std::make_shared<InputFactory>(touch_screen); - Common::Input::RegisterFactory<Common::Input::InputDevice>(touch_screen->GetEngineName(), - touch_screen_factory); + Common::Input::RegisterInputFactory(touch_screen->GetEngineName(), touch_screen_factory); gcadapter = std::make_shared<GCAdapter>("gcpad"); gcadapter->SetMappingCallback(mapping_callback); gcadapter_input_factory = std::make_shared<InputFactory>(gcadapter); gcadapter_output_factory = std::make_shared<OutputFactory>(gcadapter); - Common::Input::RegisterFactory<Common::Input::InputDevice>(gcadapter->GetEngineName(), - gcadapter_input_factory); - Common::Input::RegisterFactory<Common::Input::OutputDevice>(gcadapter->GetEngineName(), - gcadapter_output_factory); + Common::Input::RegisterInputFactory(gcadapter->GetEngineName(), gcadapter_input_factory); + Common::Input::RegisterOutputFactory(gcadapter->GetEngineName(), gcadapter_output_factory); udp_client = std::make_shared<CemuhookUDP::UDPClient>("cemuhookudp"); udp_client->SetMappingCallback(mapping_callback); udp_client_input_factory = std::make_shared<InputFactory>(udp_client); udp_client_output_factory = std::make_shared<OutputFactory>(udp_client); - Common::Input::RegisterFactory<Common::Input::InputDevice>(udp_client->GetEngineName(), - udp_client_input_factory); - Common::Input::RegisterFactory<Common::Input::OutputDevice>(udp_client->GetEngineName(), - udp_client_output_factory); + Common::Input::RegisterInputFactory(udp_client->GetEngineName(), udp_client_input_factory); + Common::Input::RegisterOutputFactory(udp_client->GetEngineName(), + udp_client_output_factory); tas_input = std::make_shared<TasInput::Tas>("tas"); tas_input->SetMappingCallback(mapping_callback); tas_input_factory = std::make_shared<InputFactory>(tas_input); tas_output_factory = std::make_shared<OutputFactory>(tas_input); - Common::Input::RegisterFactory<Common::Input::InputDevice>(tas_input->GetEngineName(), - tas_input_factory); - Common::Input::RegisterFactory<Common::Input::OutputDevice>(tas_input->GetEngineName(), - tas_output_factory); + Common::Input::RegisterInputFactory(tas_input->GetEngineName(), tas_input_factory); + Common::Input::RegisterOutputFactory(tas_input->GetEngineName(), tas_output_factory); camera = std::make_shared<Camera>("camera"); camera->SetMappingCallback(mapping_callback); camera_input_factory = std::make_shared<InputFactory>(camera); camera_output_factory = std::make_shared<OutputFactory>(camera); - Common::Input::RegisterFactory<Common::Input::InputDevice>(camera->GetEngineName(), - camera_input_factory); - Common::Input::RegisterFactory<Common::Input::OutputDevice>(camera->GetEngineName(), - camera_output_factory); + Common::Input::RegisterInputFactory(camera->GetEngineName(), camera_input_factory); + Common::Input::RegisterOutputFactory(camera->GetEngineName(), camera_output_factory); virtual_amiibo = std::make_shared<VirtualAmiibo>("virtual_amiibo"); virtual_amiibo->SetMappingCallback(mapping_callback); virtual_amiibo_input_factory = std::make_shared<InputFactory>(virtual_amiibo); virtual_amiibo_output_factory = std::make_shared<OutputFactory>(virtual_amiibo); - Common::Input::RegisterFactory<Common::Input::InputDevice>(virtual_amiibo->GetEngineName(), - virtual_amiibo_input_factory); - Common::Input::RegisterFactory<Common::Input::OutputDevice>(virtual_amiibo->GetEngineName(), - virtual_amiibo_output_factory); + Common::Input::RegisterInputFactory(virtual_amiibo->GetEngineName(), + virtual_amiibo_input_factory); + Common::Input::RegisterOutputFactory(virtual_amiibo->GetEngineName(), + virtual_amiibo_output_factory); #ifdef HAVE_SDL2 sdl = std::make_shared<SDLDriver>("sdl"); sdl->SetMappingCallback(mapping_callback); sdl_input_factory = std::make_shared<InputFactory>(sdl); sdl_output_factory = std::make_shared<OutputFactory>(sdl); - Common::Input::RegisterFactory<Common::Input::InputDevice>(sdl->GetEngineName(), - sdl_input_factory); - Common::Input::RegisterFactory<Common::Input::OutputDevice>(sdl->GetEngineName(), - sdl_output_factory); + Common::Input::RegisterInputFactory(sdl->GetEngineName(), sdl_input_factory); + Common::Input::RegisterOutputFactory(sdl->GetEngineName(), sdl_output_factory); #endif - Common::Input::RegisterFactory<Common::Input::InputDevice>( - "touch_from_button", std::make_shared<TouchFromButton>()); - Common::Input::RegisterFactory<Common::Input::InputDevice>( - "analog_from_button", std::make_shared<StickFromButton>()); + Common::Input::RegisterInputFactory("touch_from_button", + std::make_shared<TouchFromButton>()); + Common::Input::RegisterInputFactory("analog_from_button", + std::make_shared<StickFromButton>()); } void Shutdown() { - Common::Input::UnregisterFactory<Common::Input::InputDevice>(keyboard->GetEngineName()); - Common::Input::UnregisterFactory<Common::Input::OutputDevice>(keyboard->GetEngineName()); + Common::Input::UnregisterInputFactory(keyboard->GetEngineName()); + Common::Input::UnregisterOutputFactory(keyboard->GetEngineName()); keyboard.reset(); - Common::Input::UnregisterFactory<Common::Input::InputDevice>(mouse->GetEngineName()); - Common::Input::UnregisterFactory<Common::Input::OutputDevice>(mouse->GetEngineName()); + Common::Input::UnregisterInputFactory(mouse->GetEngineName()); + Common::Input::UnregisterOutputFactory(mouse->GetEngineName()); mouse.reset(); - Common::Input::UnregisterFactory<Common::Input::InputDevice>(touch_screen->GetEngineName()); + Common::Input::UnregisterInputFactory(touch_screen->GetEngineName()); touch_screen.reset(); - Common::Input::UnregisterFactory<Common::Input::InputDevice>(gcadapter->GetEngineName()); - Common::Input::UnregisterFactory<Common::Input::OutputDevice>(gcadapter->GetEngineName()); + Common::Input::UnregisterInputFactory(gcadapter->GetEngineName()); + Common::Input::UnregisterOutputFactory(gcadapter->GetEngineName()); gcadapter.reset(); - Common::Input::UnregisterFactory<Common::Input::InputDevice>(udp_client->GetEngineName()); - Common::Input::UnregisterFactory<Common::Input::OutputDevice>(udp_client->GetEngineName()); + Common::Input::UnregisterInputFactory(udp_client->GetEngineName()); + Common::Input::UnregisterOutputFactory(udp_client->GetEngineName()); udp_client.reset(); - Common::Input::UnregisterFactory<Common::Input::InputDevice>(tas_input->GetEngineName()); - Common::Input::UnregisterFactory<Common::Input::OutputDevice>(tas_input->GetEngineName()); + Common::Input::UnregisterInputFactory(tas_input->GetEngineName()); + Common::Input::UnregisterOutputFactory(tas_input->GetEngineName()); tas_input.reset(); + Common::Input::UnregisterInputFactory(camera->GetEngineName()); + Common::Input::UnregisterOutputFactory(camera->GetEngineName()); + camera.reset(); + + Common::Input::UnregisterInputFactory(virtual_amiibo->GetEngineName()); + Common::Input::UnregisterOutputFactory(virtual_amiibo->GetEngineName()); + virtual_amiibo.reset(); + #ifdef HAVE_SDL2 - Common::Input::UnregisterFactory<Common::Input::InputDevice>(sdl->GetEngineName()); - Common::Input::UnregisterFactory<Common::Input::OutputDevice>(sdl->GetEngineName()); + Common::Input::UnregisterInputFactory(sdl->GetEngineName()); + Common::Input::UnregisterOutputFactory(sdl->GetEngineName()); sdl.reset(); #endif - Common::Input::UnregisterFactory<Common::Input::InputDevice>("touch_from_button"); - Common::Input::UnregisterFactory<Common::Input::InputDevice>("analog_from_button"); + Common::Input::UnregisterInputFactory("touch_from_button"); + Common::Input::UnregisterInputFactory("analog_from_button"); } [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const { @@ -324,6 +318,12 @@ struct InputSubsystem::Impl { #endif } + void PumpEvents() const { +#ifdef HAVE_SDL2 + sdl->PumpEvents(); +#endif + } + void RegisterInput(const MappingData& data) { mapping_factory->RegisterInput(data); } @@ -472,6 +472,10 @@ void InputSubsystem::StopMapping() const { impl->mapping_factory->StopMapping(); } +void InputSubsystem::PumpEvents() const { + impl->PumpEvents(); +} + std::string GenerateKeyboardParam(int key_code) { Common::ParamPackage param; param.Set("engine", "keyboard"); diff --git a/src/input_common/main.h b/src/input_common/main.h index ced252383..6218c37f6 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h @@ -147,6 +147,9 @@ public: /// Stop polling from all backends. void StopMapping() const; + /// Signals SDL driver for new input events + void PumpEvents() const; + private: struct Impl; std::unique_ptr<Impl> impl; diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index d7f7d336c..b03a30992 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -28,6 +28,10 @@ add_library(video_core STATIC dirty_flags.h dma_pusher.cpp dma_pusher.h + engines/sw_blitter/blitter.cpp + engines/sw_blitter/blitter.h + engines/sw_blitter/converter.cpp + engines/sw_blitter/converter.h engines/const_buffer_info.h engines/engine_interface.h engines/engine_upload.cpp diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h index 599551013..5d3a8293b 100644 --- a/src/video_core/buffer_cache/buffer_cache.h +++ b/src/video_core/buffer_cache/buffer_cache.h @@ -1742,12 +1742,12 @@ bool BufferCache<P>::InlineMemory(VAddr dest_address, size_t copy_size, SynchronizeBuffer(buffer, dest_address, static_cast<u32>(copy_size)); if constexpr (USE_MEMORY_MAPS) { + auto upload_staging = runtime.UploadStagingBuffer(copy_size); std::array copies{BufferCopy{ - .src_offset = 0, + .src_offset = upload_staging.offset, .dst_offset = buffer.Offset(dest_address), .size = copy_size, }}; - auto upload_staging = runtime.UploadStagingBuffer(copy_size); u8* const src_pointer = upload_staging.mapped_span.data(); std::memcpy(src_pointer, inlined_buffer.data(), copy_size); runtime.CopyBuffer(buffer, upload_staging.buffer, copies); diff --git a/src/video_core/control/channel_state.cpp b/src/video_core/control/channel_state.cpp index cdecc3a91..832025d75 100644 --- a/src/video_core/control/channel_state.cpp +++ b/src/video_core/control/channel_state.cpp @@ -20,7 +20,7 @@ void ChannelState::Init(Core::System& system, GPU& gpu) { ASSERT(memory_manager); dma_pusher = std::make_unique<Tegra::DmaPusher>(system, gpu, *memory_manager, *this); maxwell_3d = std::make_unique<Engines::Maxwell3D>(system, *memory_manager); - fermi_2d = std::make_unique<Engines::Fermi2D>(); + fermi_2d = std::make_unique<Engines::Fermi2D>(*memory_manager); kepler_compute = std::make_unique<Engines::KeplerCompute>(system, *memory_manager); maxwell_dma = std::make_unique<Engines::MaxwellDMA>(system, *memory_manager); kepler_memory = std::make_unique<Engines::KeplerMemory>(system, *memory_manager); diff --git a/src/video_core/engines/engine_upload.cpp b/src/video_core/engines/engine_upload.cpp index a34819234..e4f8331ab 100644 --- a/src/video_core/engines/engine_upload.cpp +++ b/src/video_core/engines/engine_upload.cpp @@ -49,13 +49,12 @@ void State::ProcessData(std::span<const u8> read_buffer) { if (regs.line_count == 1) { rasterizer->AccelerateInlineToMemory(address, copy_size, read_buffer); } else { - for (u32 line = 0; line < regs.line_count; ++line) { - const GPUVAddr dest_line = address + static_cast<size_t>(line) * regs.dest.pitch; - memory_manager.WriteBlockUnsafe( - dest_line, read_buffer.data() + static_cast<size_t>(line) * regs.line_length_in, - regs.line_length_in); + for (size_t line = 0; line < regs.line_count; ++line) { + const GPUVAddr dest_line = address + line * regs.dest.pitch; + std::span<const u8> buffer(read_buffer.data() + line * regs.line_length_in, + regs.line_length_in); + rasterizer->AccelerateInlineToMemory(dest_line, regs.line_length_in, buffer); } - memory_manager.InvalidateRegion(address, regs.dest.pitch * regs.line_count); } } else { u32 width = regs.dest.width; diff --git a/src/video_core/engines/engine_upload.h b/src/video_core/engines/engine_upload.h index f08f6e36a..94fafd9dc 100644 --- a/src/video_core/engines/engine_upload.h +++ b/src/video_core/engines/engine_upload.h @@ -39,7 +39,7 @@ struct Registers { u32 y; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } u32 BlockWidth() const { diff --git a/src/video_core/engines/fermi_2d.cpp b/src/video_core/engines/fermi_2d.cpp index 453e0fb01..c6478ae85 100644 --- a/src/video_core/engines/fermi_2d.cpp +++ b/src/video_core/engines/fermi_2d.cpp @@ -3,17 +3,25 @@ #include "common/assert.h" #include "common/logging/log.h" +#include "common/microprofile.h" #include "video_core/engines/fermi_2d.h" -#include "video_core/memory_manager.h" +#include "video_core/engines/sw_blitter/blitter.h" #include "video_core/rasterizer_interface.h" #include "video_core/surface.h" +#include "video_core/textures/decoders.h" + +MICROPROFILE_DECLARE(GPU_BlitEngine); +MICROPROFILE_DEFINE(GPU_BlitEngine, "GPU", "Blit Engine", MP_RGB(224, 224, 128)); using VideoCore::Surface::BytesPerBlock; using VideoCore::Surface::PixelFormatFromRenderTargetFormat; namespace Tegra::Engines { -Fermi2D::Fermi2D() { +using namespace Texture; + +Fermi2D::Fermi2D(MemoryManager& memory_manager_) { + sw_blitter = std::make_unique<Blitter::SoftwareBlitEngine>(memory_manager_); // Nvidia's OpenGL driver seems to assume these values regs.src.depth = 1; regs.dst.depth = 1; @@ -42,6 +50,7 @@ void Fermi2D::CallMultiMethod(u32 method, const u32* base_start, u32 amount, u32 } void Fermi2D::Blit() { + MICROPROFILE_SCOPE(GPU_BlitEngine); LOG_DEBUG(HW_GPU, "called. source address=0x{:x}, destination address=0x{:x}", regs.src.Address(), regs.dst.Address()); @@ -52,9 +61,16 @@ void Fermi2D::Blit() { UNIMPLEMENTED_IF_MSG(regs.clip_enable != 0, "Clipped blit enabled"); const auto& args = regs.pixels_from_memory; + constexpr s64 null_derivate = 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 && + src.format != regs.dst.format; Config config{ .operation = regs.operation, .filter = args.sample_mode.filter, + .must_accelerate = + args.du_dx != null_derivate || args.dv_dy != null_derivate || delegate_to_gpu, .dst_x0 = args.dst_x0, .dst_y0 = args.dst_y0, .dst_x1 = args.dst_x0 + args.dst_width, @@ -64,8 +80,7 @@ void Fermi2D::Blit() { .src_x1 = static_cast<s32>((args.du_dx * args.dst_width + args.src_x0) >> 32), .src_y1 = static_cast<s32>((args.dv_dy * args.dst_height + args.src_y0) >> 32), }; - Surface src = regs.src; - const auto bytes_per_pixel = BytesPerBlock(PixelFormatFromRenderTargetFormat(src.format)); + const auto need_align_to_pitch = src.linear == Tegra::Engines::Fermi2D::MemoryLayout::Pitch && static_cast<s32>(src.width) == config.src_x1 && @@ -78,8 +93,9 @@ void Fermi2D::Blit() { config.src_x1 -= config.src_x0; config.src_x0 = 0; } + if (!rasterizer->AccelerateSurfaceCopy(src, regs.dst, config)) { - UNIMPLEMENTED(); + sw_blitter->Blit(src, regs.dst, config); } } diff --git a/src/video_core/engines/fermi_2d.h b/src/video_core/engines/fermi_2d.h index 1229aa35b..100b21bac 100644 --- a/src/video_core/engines/fermi_2d.h +++ b/src/video_core/engines/fermi_2d.h @@ -5,6 +5,7 @@ #include <array> #include <cstddef> +#include <memory> #include "common/bit_field.h" #include "common/common_funcs.h" #include "common/common_types.h" @@ -21,6 +22,10 @@ class RasterizerInterface; namespace Tegra::Engines { +namespace Blitter { +class SoftwareBlitEngine; +} + /** * This Engine is known as G80_2D. Documentation can be found in: * https://github.com/envytools/envytools/blob/master/rnndb/graph/g80_2d.xml @@ -32,7 +37,7 @@ namespace Tegra::Engines { class Fermi2D final : public EngineInterface { public: - explicit Fermi2D(); + explicit Fermi2D(MemoryManager& memory_manager_); ~Fermi2D() override; /// Binds a rasterizer to this engine. @@ -92,7 +97,7 @@ public: u32 addr_lower; [[nodiscard]] constexpr GPUVAddr Address() const noexcept { - return (static_cast<GPUVAddr>(addr_upper) << 32) | static_cast<GPUVAddr>(addr_lower); + return (GPUVAddr{addr_upper} << 32) | GPUVAddr{addr_lower}; } }; static_assert(sizeof(Surface) == 0x28, "Surface has incorrect size"); @@ -286,6 +291,7 @@ public: struct Config { Operation operation; Filter filter; + bool must_accelerate; s32 dst_x0; s32 dst_y0; s32 dst_x1; @@ -298,6 +304,7 @@ public: private: VideoCore::RasterizerInterface* rasterizer = nullptr; + std::unique_ptr<Blitter::SoftwareBlitEngine> sw_blitter; /// Performs the copy from the source surface to the destination surface as configured in the /// registers. diff --git a/src/video_core/engines/kepler_compute.cpp b/src/video_core/engines/kepler_compute.cpp index 7c50bdbe0..e5c622155 100644 --- a/src/video_core/engines/kepler_compute.cpp +++ b/src/video_core/engines/kepler_compute.cpp @@ -50,11 +50,11 @@ void KeplerCompute::CallMultiMethod(u32 method, const u32* base_start, u32 amoun u32 methods_pending) { switch (method) { case KEPLER_COMPUTE_REG_INDEX(data_upload): - upload_state.ProcessData(base_start, static_cast<size_t>(amount)); + upload_state.ProcessData(base_start, amount); return; default: - for (std::size_t i = 0; i < amount; i++) { - CallMethod(method, base_start[i], methods_pending - static_cast<u32>(i) <= 1); + for (u32 i = 0; i < amount; i++) { + CallMethod(method, base_start[i], methods_pending - i <= 1); } break; } diff --git a/src/video_core/engines/kepler_compute.h b/src/video_core/engines/kepler_compute.h index aab309ecc..e154e3f06 100644 --- a/src/video_core/engines/kepler_compute.h +++ b/src/video_core/engines/kepler_compute.h @@ -68,7 +68,7 @@ public: struct { u32 address; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address) << 8)); + return GPUVAddr{address} << 8; } } launch_desc_loc; @@ -83,8 +83,7 @@ public: u32 address_low; u32 limit; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } } tsc; @@ -95,8 +94,7 @@ public: u32 address_low; u32 limit; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } } tic; @@ -106,8 +104,7 @@ public: u32 address_high; u32 address_low; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } } code_loc; @@ -162,8 +159,7 @@ public: BitField<15, 17, u32> size; }; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high.Value()) << 32) | - address_low); + return (GPUVAddr{address_high.Value()} << 32) | GPUVAddr{address_low}; } }; std::array<ConstBufferConfig, NumConstBuffers> const_buffer_config; diff --git a/src/video_core/engines/kepler_memory.cpp b/src/video_core/engines/kepler_memory.cpp index a3fbab1e5..08045d1cf 100644 --- a/src/video_core/engines/kepler_memory.cpp +++ b/src/video_core/engines/kepler_memory.cpp @@ -42,11 +42,11 @@ void KeplerMemory::CallMultiMethod(u32 method, const u32* base_start, u32 amount u32 methods_pending) { switch (method) { case KEPLERMEMORY_REG_INDEX(data): - upload_state.ProcessData(base_start, static_cast<size_t>(amount)); + upload_state.ProcessData(base_start, amount); return; default: - for (std::size_t i = 0; i < amount; i++) { - CallMethod(method, base_start[i], methods_pending - static_cast<u32>(i) <= 1); + for (u32 i = 0; i < amount; i++) { + CallMethod(method, base_start[i], methods_pending - i <= 1); } break; } diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index 5bb1427c1..55462752c 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp @@ -126,6 +126,7 @@ void Maxwell3D::InitializeRegisterDefaults() { draw_command[MAXWELL3D_REG_INDEX(draw_inline_index)] = true; draw_command[MAXWELL3D_REG_INDEX(inline_index_2x16.even)] = true; draw_command[MAXWELL3D_REG_INDEX(inline_index_4x8.index0)] = true; + draw_command[MAXWELL3D_REG_INDEX(draw.instance_id)] = true; } void Maxwell3D::ProcessMacro(u32 method, const u32* base_start, u32 amount, bool is_last_call) { @@ -249,9 +250,6 @@ void Maxwell3D::ProcessMethodCall(u32 method, u32 argument, u32 nonshadow_argume return; case MAXWELL3D_REG_INDEX(fragment_barrier): return rasterizer->FragmentBarrier(); - case MAXWELL3D_REG_INDEX(invalidate_texture_data_cache): - rasterizer->InvalidateGPUCache(); - return rasterizer->WaitForIdle(); case MAXWELL3D_REG_INDEX(tiled_cache_barrier): return rasterizer->TiledCacheBarrier(); } @@ -288,31 +286,58 @@ void Maxwell3D::CallMethod(u32 method, u32 method_argument, bool is_last_call) { ASSERT_MSG(method < Regs::NUM_REGS, "Invalid Maxwell3D register, increase the size of the Regs structure"); + const u32 argument = ProcessShadowRam(method, method_argument); + ProcessDirtyRegisters(method, argument); + if (draw_command[method]) { regs.reg_array[method] = method_argument; deferred_draw_method.push_back(method); - auto u32_to_u8 = [&](const u32 argument) { - inline_index_draw_indexes.push_back(static_cast<u8>(argument & 0x000000ff)); - inline_index_draw_indexes.push_back(static_cast<u8>((argument & 0x0000ff00) >> 8)); - inline_index_draw_indexes.push_back(static_cast<u8>((argument & 0x00ff0000) >> 16)); - inline_index_draw_indexes.push_back(static_cast<u8>((argument & 0xff000000) >> 24)); + auto update_inline_index = [&](const u32 index) { + inline_index_draw_indexes.push_back(static_cast<u8>(index & 0x000000ff)); + inline_index_draw_indexes.push_back(static_cast<u8>((index & 0x0000ff00) >> 8)); + inline_index_draw_indexes.push_back(static_cast<u8>((index & 0x00ff0000) >> 16)); + inline_index_draw_indexes.push_back(static_cast<u8>((index & 0xff000000) >> 24)); + draw_mode = DrawMode::InlineIndex; }; - if (MAXWELL3D_REG_INDEX(draw_inline_index) == method) { - u32_to_u8(method_argument); - } else if (MAXWELL3D_REG_INDEX(inline_index_2x16.even) == method) { - u32_to_u8(regs.inline_index_2x16.even); - u32_to_u8(regs.inline_index_2x16.odd); - } else if (MAXWELL3D_REG_INDEX(inline_index_4x8.index0) == method) { - u32_to_u8(regs.inline_index_4x8.index0); - u32_to_u8(regs.inline_index_4x8.index1); - u32_to_u8(regs.inline_index_4x8.index2); - u32_to_u8(regs.inline_index_4x8.index3); + switch (method) { + case MAXWELL3D_REG_INDEX(draw.end): + switch (draw_mode) { + case DrawMode::General: + ProcessDraw(1); + break; + case DrawMode::InlineIndex: + regs.index_buffer.count = static_cast<u32>(inline_index_draw_indexes.size() / 4); + regs.index_buffer.format = Regs::IndexFormat::UnsignedInt; + ProcessDraw(1); + inline_index_draw_indexes.clear(); + break; + case DrawMode::Instance: + break; + } + break; + case MAXWELL3D_REG_INDEX(draw_inline_index): + update_inline_index(method_argument); + break; + case MAXWELL3D_REG_INDEX(inline_index_2x16.even): + update_inline_index(regs.inline_index_2x16.even); + update_inline_index(regs.inline_index_2x16.odd); + break; + case MAXWELL3D_REG_INDEX(inline_index_4x8.index0): + update_inline_index(regs.inline_index_4x8.index0); + update_inline_index(regs.inline_index_4x8.index1); + update_inline_index(regs.inline_index_4x8.index2); + update_inline_index(regs.inline_index_4x8.index3); + break; + case MAXWELL3D_REG_INDEX(draw.instance_id): + draw_mode = + (regs.draw.instance_id == Maxwell3D::Regs::Draw::InstanceId::Subsequent) || + (regs.draw.instance_id == Maxwell3D::Regs::Draw::InstanceId::Unchanged) + ? DrawMode::Instance + : DrawMode::General; + break; } } else { ProcessDeferredDraw(); - - const u32 argument = ProcessShadowRam(method, method_argument); - ProcessDirtyRegisters(method, argument); ProcessMethodCall(method, argument, method_argument, is_last_call); } } @@ -345,11 +370,11 @@ void Maxwell3D::CallMultiMethod(u32 method, const u32* base_start, u32 amount, ProcessCBMultiData(base_start, amount); break; case MAXWELL3D_REG_INDEX(inline_data): - upload_state.ProcessData(base_start, static_cast<size_t>(amount)); + upload_state.ProcessData(base_start, amount); return; default: - for (std::size_t i = 0; i < amount; i++) { - CallMethod(method, base_start[i], methods_pending - static_cast<u32>(i) <= 1); + for (u32 i = 0; i < amount; i++) { + CallMethod(method, base_start[i], methods_pending - i <= 1); } break; } @@ -511,10 +536,7 @@ void Maxwell3D::ProcessCounterReset() { void Maxwell3D::ProcessSyncPoint() { const u32 sync_point = regs.sync_info.sync_point.Value(); - const u32 cache_flush = regs.sync_info.clean_l2.Value(); - if (cache_flush != 0) { - rasterizer->InvalidateGPUCache(); - } + [[maybe_unused]] const u32 cache_flush = regs.sync_info.clean_l2.Value(); rasterizer->SignalSyncPoint(sync_point); } @@ -626,57 +648,27 @@ void Maxwell3D::ProcessDraw(u32 instance_count) { } void Maxwell3D::ProcessDeferredDraw() { - if (deferred_draw_method.empty()) { + if (draw_mode != DrawMode::Instance || deferred_draw_method.empty()) { return; } - enum class DrawMode { - Undefined, - General, - Instance, - }; - DrawMode draw_mode{DrawMode::Undefined}; - u32 method_count = static_cast<u32>(deferred_draw_method.size()); - u32 method = deferred_draw_method[method_count - 1]; - if (MAXWELL3D_REG_INDEX(draw.end) != method) { - return; - } - draw_mode = (regs.draw.instance_id == Maxwell3D::Regs::Draw::InstanceId::Subsequent) || - (regs.draw.instance_id == Maxwell3D::Regs::Draw::InstanceId::Unchanged) - ? DrawMode::Instance - : DrawMode::General; - u32 instance_count = 0; - if (draw_mode == DrawMode::Instance) { - u32 vertex_buffer_count = 0; - u32 index_buffer_count = 0; - for (u32 index = 0; index < method_count; ++index) { - method = deferred_draw_method[index]; - if (method == MAXWELL3D_REG_INDEX(vertex_buffer.count)) { - instance_count = ++vertex_buffer_count; - } else if (method == MAXWELL3D_REG_INDEX(index_buffer.count)) { - instance_count = ++index_buffer_count; - } - } - ASSERT_MSG(!(vertex_buffer_count && index_buffer_count), - "Instance both indexed and direct?"); - } else { - instance_count = 1; - for (u32 index = 0; index < method_count; ++index) { - method = deferred_draw_method[index]; - if (MAXWELL3D_REG_INDEX(draw_inline_index) == method || - MAXWELL3D_REG_INDEX(inline_index_2x16.even) == method || - MAXWELL3D_REG_INDEX(inline_index_4x8.index0) == method) { - regs.index_buffer.count = static_cast<u32>(inline_index_draw_indexes.size() / 4); - regs.index_buffer.format = Regs::IndexFormat::UnsignedInt; - break; - } + const auto method_count = deferred_draw_method.size(); + u32 instance_count = 1; + u32 vertex_buffer_count = 0; + u32 index_buffer_count = 0; + for (size_t index = 0; index < method_count; ++index) { + const u32 method = deferred_draw_method[index]; + if (method == MAXWELL3D_REG_INDEX(vertex_buffer.count)) { + instance_count = ++vertex_buffer_count; + } else if (method == MAXWELL3D_REG_INDEX(index_buffer.count)) { + instance_count = ++index_buffer_count; } } + ASSERT_MSG(!(vertex_buffer_count && index_buffer_count), "Instance both indexed and direct?"); ProcessDraw(instance_count); deferred_draw_method.clear(); - inline_index_draw_indexes.clear(); } } // namespace Tegra::Engines diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h index c3099f9a6..deba292a5 100644 --- a/src/video_core/engines/maxwell_3d.h +++ b/src/video_core/engines/maxwell_3d.h @@ -96,8 +96,7 @@ public: u32 type; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } }; @@ -106,8 +105,7 @@ public: u32 address_low; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } }; @@ -124,8 +122,7 @@ public: Mode mode; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(offset_high) << 32) | - offset_low); + return (GPUVAddr{offset_high} << 32) | GPUVAddr{offset_low}; } }; @@ -187,7 +184,7 @@ public: default: // Thresholds begin at 0x10 (1 << 4) // Threshold is in the range 0x1 to 0x13 - return 1 << (4 + threshold.Value() - 1); + return 1U << (4 + threshold.Value() - 1); } } }; @@ -468,8 +465,7 @@ public: INSERT_PADDING_BYTES_NOINIT(0xC); GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } }; static_assert(sizeof(Buffer) == 0x20); @@ -511,12 +507,11 @@ public: u32 default_size_per_warp; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } u64 Size() const { - return (static_cast<u64>(size_high) << 32) | size_low; + return (u64{size_high} << 32) | u64{size_low}; } }; @@ -538,13 +533,11 @@ public: u32 storage_limit_address_low; GPUVAddr StorageAddress() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(storage_address_high) << 32) | - storage_address_low); + return (GPUVAddr{storage_address_high} << 32) | GPUVAddr{storage_address_low}; } GPUVAddr StorageLimitAddress() const { - return static_cast<GPUVAddr>( - (static_cast<GPUVAddr>(storage_limit_address_high) << 32) | - storage_limit_address_low); + return (GPUVAddr{storage_limit_address_high} << 32) | + GPUVAddr{storage_limit_address_low}; } }; @@ -829,11 +822,11 @@ public: struct CompressionThresholdSamples { u32 samples; - u32 Samples() { + u32 Samples() const { if (samples == 0) { return 0; } - return 1 << (samples - 1); + return 1U << (samples - 1); } }; @@ -1138,8 +1131,7 @@ public: INSERT_PADDING_BYTES_NOINIT(0x18); GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } }; static_assert(sizeof(RenderTargetConfig) == 0x40); @@ -1482,8 +1474,7 @@ public: u32 address_low; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } }; @@ -1533,8 +1524,7 @@ public: u32 address_low; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } }; @@ -1561,8 +1551,7 @@ public: u32 array_pitch; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } }; @@ -1910,8 +1899,7 @@ public: Mode mode; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } }; @@ -1921,8 +1909,7 @@ public: u32 limit; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } }; @@ -1932,8 +1919,7 @@ public: u32 limit; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } }; @@ -1981,8 +1967,7 @@ public: u32 address_low; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } }; @@ -2027,8 +2012,7 @@ public: u32 address_low; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } }; @@ -2224,19 +2208,16 @@ public: } GPUVAddr StartAddress() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(start_addr_high) << 32) | - start_addr_low); + return (GPUVAddr{start_addr_high} << 32) | GPUVAddr{start_addr_low}; } GPUVAddr EndAddress() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(limit_addr_high) << 32) | - limit_addr_low); + return (GPUVAddr{limit_addr_high} << 32) | GPUVAddr{limit_addr_low}; } /// Adjust the index buffer offset so it points to the first desired index. GPUVAddr IndexStart() const { - return StartAddress() + - static_cast<size_t>(first) * static_cast<size_t>(FormatSizeInBytes()); + return StartAddress() + size_t{first} * size_t{FormatSizeInBytes()}; } }; @@ -2464,8 +2445,7 @@ public: } query; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } }; @@ -2479,8 +2459,7 @@ public: u32 frequency; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } bool IsEnabled() const { @@ -2494,8 +2473,7 @@ public: u32 address_low; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } }; static_assert(sizeof(VertexStreamLimit) == 0x8); @@ -2543,8 +2521,7 @@ public: std::array<u32, NumCBData> buffer; GPUVAddr Address() const { - return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) | - address_low); + return (GPUVAddr{address_high} << 32) | GPUVAddr{address_low}; } }; @@ -3148,10 +3125,12 @@ private: /// Handles use of topology overrides (e.g., to avoid using a topology assigned from a macro) void ProcessTopologyOverride(); - void ProcessDraw(u32 instance_count = 1); - + /// Handles deferred draw(e.g., instance draw). void ProcessDeferredDraw(); + /// Handles a draw. + void ProcessDraw(u32 instance_count = 1); + /// Returns a query's value or an empty object if the value will be deferred through a cache. std::optional<u64> GetQueryResult(); @@ -3178,6 +3157,8 @@ private: std::array<bool, Regs::NUM_REGS> draw_command{}; std::vector<u32> deferred_draw_method; + enum class DrawMode : u32 { General = 0, Instance, InlineIndex }; + DrawMode draw_mode{DrawMode::General}; }; #define ASSERT_REG_POSITION(field_name, position) \ diff --git a/src/video_core/engines/maxwell_dma.cpp b/src/video_core/engines/maxwell_dma.cpp index 1bf6ca2dd..a189e60ae 100644 --- a/src/video_core/engines/maxwell_dma.cpp +++ b/src/video_core/engines/maxwell_dma.cpp @@ -41,8 +41,8 @@ void MaxwellDMA::CallMethod(u32 method, u32 method_argument, bool is_last_call) void MaxwellDMA::CallMultiMethod(u32 method, const u32* base_start, u32 amount, u32 methods_pending) { - for (size_t i = 0; i < amount; ++i) { - CallMethod(method, base_start[i], methods_pending - static_cast<u32>(i) <= 1); + for (u32 i = 0; i < amount; ++i) { + CallMethod(method, base_start[i], methods_pending - i <= 1); } } @@ -62,7 +62,8 @@ void MaxwellDMA::Launch() { if (!is_src_pitch && !is_dst_pitch) { // If both the source and the destination are in block layout, assert. - UNIMPLEMENTED_MSG("Tiled->Tiled DMA transfers are not yet implemented"); + CopyBlockLinearToBlockLinear(); + ReleaseSemaphore(); return; } @@ -93,14 +94,14 @@ void MaxwellDMA::Launch() { reinterpret_cast<u8*>(tmp_buffer.data()), regs.line_length_in * sizeof(u32)); } else { - auto convert_linear_2_blocklinear_addr = [](u64 address) { + const auto convert_linear_2_blocklinear_addr = [](u64 address) { return (address & ~0x1f0ULL) | ((address & 0x40) >> 2) | ((address & 0x10) << 1) | ((address & 0x180) >> 1) | ((address & 0x20) << 3); }; - auto src_kind = memory_manager.GetPageKind(regs.offset_in); - auto dst_kind = memory_manager.GetPageKind(regs.offset_out); - const bool is_src_pitch = IsPitchKind(static_cast<PTEKind>(src_kind)); - const bool is_dst_pitch = IsPitchKind(static_cast<PTEKind>(dst_kind)); + const auto src_kind = memory_manager.GetPageKind(regs.offset_in); + const auto dst_kind = memory_manager.GetPageKind(regs.offset_out); + const bool is_src_pitch = IsPitchKind(src_kind); + const bool is_dst_pitch = IsPitchKind(dst_kind); if (!is_src_pitch && is_dst_pitch) { UNIMPLEMENTED_IF(regs.line_length_in % 16 != 0); UNIMPLEMENTED_IF(regs.offset_in % 16 != 0); @@ -291,6 +292,70 @@ void MaxwellDMA::FastCopyBlockLinearToPitch() { memory_manager.WriteBlock(regs.offset_out, write_buffer.data(), dst_size); } +void MaxwellDMA::CopyBlockLinearToBlockLinear() { + UNIMPLEMENTED_IF(regs.src_params.block_size.width != 0); + + const bool is_remapping = regs.launch_dma.remap_enable != 0; + + // Deswizzle the input and copy it over. + const Parameters& src = regs.src_params; + const Parameters& dst = regs.dst_params; + + const u32 num_remap_components = regs.remap_const.num_dst_components_minus_one + 1; + const u32 remap_components_size = regs.remap_const.component_size_minus_one + 1; + + const u32 base_bpp = !is_remapping ? 1U : num_remap_components * remap_components_size; + + u32 src_width = src.width; + u32 dst_width = dst.width; + u32 x_elements = regs.line_length_in; + u32 src_x_offset = src.origin.x; + u32 dst_x_offset = dst.origin.x; + u32 bpp_shift = 0U; + if (!is_remapping) { + bpp_shift = Common::FoldRight( + 4U, [](u32 x, u32 y) { return std::min(x, static_cast<u32>(std::countr_zero(y))); }, + src_width, dst_width, x_elements, src_x_offset, dst_x_offset, + static_cast<u32>(regs.offset_in), static_cast<u32>(regs.offset_out)); + src_width >>= bpp_shift; + dst_width >>= bpp_shift; + x_elements >>= bpp_shift; + src_x_offset >>= bpp_shift; + dst_x_offset >>= bpp_shift; + } + + const u32 bytes_per_pixel = base_bpp << bpp_shift; + const size_t src_size = CalculateSize(true, bytes_per_pixel, src_width, src.height, src.depth, + src.block_size.height, src.block_size.depth); + const size_t dst_size = CalculateSize(true, bytes_per_pixel, dst_width, dst.height, dst.depth, + dst.block_size.height, dst.block_size.depth); + + const u32 pitch = x_elements * bytes_per_pixel; + const size_t mid_buffer_size = pitch * regs.line_count; + + if (read_buffer.size() < src_size) { + read_buffer.resize(src_size); + } + if (write_buffer.size() < dst_size) { + write_buffer.resize(dst_size); + } + + intermediate_buffer.resize(mid_buffer_size); + + memory_manager.ReadBlock(regs.offset_in, read_buffer.data(), src_size); + memory_manager.ReadBlock(regs.offset_out, write_buffer.data(), dst_size); + + UnswizzleSubrect(intermediate_buffer, read_buffer, bytes_per_pixel, src_width, src.height, + src.depth, src_x_offset, src.origin.y, x_elements, regs.line_count, + src.block_size.height, src.block_size.depth, pitch); + + SwizzleSubrect(write_buffer, intermediate_buffer, bytes_per_pixel, dst_width, dst.height, + dst.depth, dst_x_offset, dst.origin.y, x_elements, regs.line_count, + dst.block_size.height, dst.block_size.depth, pitch); + + memory_manager.WriteBlock(regs.offset_out, write_buffer.data(), dst_size); +} + void MaxwellDMA::ReleaseSemaphore() { const auto type = regs.launch_dma.semaphore_type; const GPUVAddr address = regs.semaphore.address; diff --git a/src/video_core/engines/maxwell_dma.h b/src/video_core/engines/maxwell_dma.h index 953e34adc..d40d3d302 100644 --- a/src/video_core/engines/maxwell_dma.h +++ b/src/video_core/engines/maxwell_dma.h @@ -223,6 +223,8 @@ private: void CopyPitchToBlockLinear(); + void CopyBlockLinearToBlockLinear(); + void FastCopyBlockLinearToPitch(); void ReleaseSemaphore(); @@ -234,6 +236,7 @@ private: std::vector<u8> read_buffer; std::vector<u8> write_buffer; + std::vector<u8> intermediate_buffer; static constexpr std::size_t NUM_REGS = 0x800; struct Regs { diff --git a/src/video_core/engines/puller.cpp b/src/video_core/engines/puller.cpp index 4d2278811..7718a09b3 100644 --- a/src/video_core/engines/puller.cpp +++ b/src/video_core/engines/puller.cpp @@ -31,7 +31,7 @@ void Puller::ProcessBindMethod(const MethodCall& method_call) { LOG_DEBUG(HW_GPU, "Binding subchannel {} to engine {}", method_call.subchannel, method_call.argument); const auto engine_id = static_cast<EngineID>(method_call.argument); - bound_engines[method_call.subchannel] = static_cast<EngineID>(engine_id); + bound_engines[method_call.subchannel] = engine_id; switch (engine_id) { case EngineID::FERMI_TWOD_A: dma_pusher.BindSubchannel(channel_state.fermi_2d.get(), method_call.subchannel); @@ -118,7 +118,7 @@ void Puller::ProcessSemaphoreRelease() { std::function<void()> operation([this, sequence_address, payload] { memory_manager.Write<u32>(sequence_address, payload); }); - rasterizer->SyncOperation(std::move(operation)); + rasterizer->SignalFence(std::move(operation)); } void Puller::ProcessSemaphoreAcquire() { @@ -151,8 +151,8 @@ void Puller::CallPullerMethod(const MethodCall& method_call) { case BufferMethods::SemaphoreAddressLow: case BufferMethods::SemaphoreSequencePayload: case BufferMethods::SyncpointPayload: - break; case BufferMethods::WrcacheFlush: + break; case BufferMethods::RefCnt: rasterizer->SignalReference(); break; @@ -285,12 +285,12 @@ void Puller::CallMultiMethod(u32 method, u32 subchannel, const u32* base_start, if (ExecuteMethodOnEngine(method)) { CallEngineMultiMethod(method, subchannel, base_start, amount, methods_pending); } else { - for (std::size_t i = 0; i < amount; i++) { + for (u32 i = 0; i < amount; i++) { CallPullerMethod(MethodCall{ method, base_start[i], subchannel, - methods_pending - static_cast<u32>(i), + methods_pending - i, }); } } diff --git a/src/video_core/engines/sw_blitter/blitter.cpp b/src/video_core/engines/sw_blitter/blitter.cpp new file mode 100644 index 000000000..2f1ea4626 --- /dev/null +++ b/src/video_core/engines/sw_blitter/blitter.cpp @@ -0,0 +1,238 @@ +// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#include <algorithm> +#include <cmath> +#include <vector> + +#include "video_core/engines/sw_blitter/blitter.h" +#include "video_core/engines/sw_blitter/converter.h" +#include "video_core/memory_manager.h" +#include "video_core/surface.h" +#include "video_core/textures/decoders.h" + +namespace Tegra { +class MemoryManager; +} + +using VideoCore::Surface::BytesPerBlock; +using VideoCore::Surface::PixelFormatFromRenderTargetFormat; + +namespace Tegra::Engines::Blitter { + +using namespace Texture; + +namespace { + +constexpr size_t ir_components = 4; + +void NearestNeighbor(std::span<const u8> input, std::span<u8> output, u32 src_width, u32 src_height, + u32 dst_width, u32 dst_height, size_t bpp) { + const size_t dx_du = std::llround((static_cast<f64>(src_width) / dst_width) * (1ULL << 32)); + const size_t dy_dv = std::llround((static_cast<f64>(src_height) / dst_height) * (1ULL << 32)); + size_t src_y = 0; + for (u32 y = 0; y < dst_height; y++) { + size_t src_x = 0; + for (u32 x = 0; x < dst_width; x++) { + const size_t read_from = ((src_y * src_width + src_x) >> 32) * bpp; + const size_t write_to = (y * dst_width + x) * bpp; + + std::memcpy(&output[write_to], &input[read_from], bpp); + src_x += dx_du; + } + src_y += dy_dv; + } +} + +void NearestNeighborFast(std::span<const f32> input, std::span<f32> output, u32 src_width, + u32 src_height, u32 dst_width, u32 dst_height) { + const size_t dx_du = std::llround((static_cast<f64>(src_width) / dst_width) * (1ULL << 32)); + const size_t dy_dv = std::llround((static_cast<f64>(src_height) / dst_height) * (1ULL << 32)); + size_t src_y = 0; + for (u32 y = 0; y < dst_height; y++) { + size_t src_x = 0; + for (u32 x = 0; x < dst_width; x++) { + const size_t read_from = ((src_y * src_width + src_x) >> 32) * ir_components; + const size_t write_to = (y * dst_width + x) * ir_components; + + std::memcpy(&output[write_to], &input[read_from], sizeof(f32) * ir_components); + src_x += dx_du; + } + src_y += dy_dv; + } +} + +void Bilinear(std::span<const f32> input, std::span<f32> output, size_t src_width, + size_t src_height, size_t dst_width, size_t dst_height) { + const auto bilinear_sample = [](std::span<const f32> x0_y0, std::span<const f32> x1_y0, + std::span<const f32> x0_y1, std::span<const f32> x1_y1, + f32 weight_x, f32 weight_y) { + std::array<f32, ir_components> result{}; + for (size_t i = 0; i < ir_components; i++) { + const f32 a = std::lerp(x0_y0[i], x1_y0[i], weight_x); + const f32 b = std::lerp(x0_y1[i], x1_y1[i], weight_x); + result[i] = std::lerp(a, b, weight_y); + } + return result; + }; + const f32 dx_du = + dst_width > 1 ? static_cast<f32>(src_width - 1) / static_cast<f32>(dst_width - 1) : 0.f; + const f32 dy_dv = + dst_height > 1 ? static_cast<f32>(src_height - 1) / static_cast<f32>(dst_height - 1) : 0.f; + for (u32 y = 0; y < dst_height; y++) { + for (u32 x = 0; x < dst_width; x++) { + const f32 x_low = std::floor(static_cast<f32>(x) * dx_du); + const f32 y_low = std::floor(static_cast<f32>(y) * dy_dv); + const f32 x_high = std::ceil(static_cast<f32>(x) * dx_du); + const f32 y_high = std::ceil(static_cast<f32>(y) * dy_dv); + const f32 weight_x = (static_cast<f32>(x) * dx_du) - x_low; + const f32 weight_y = (static_cast<f32>(y) * dy_dv) - y_low; + + const auto read_src = [&](f32 in_x, f32 in_y) { + const size_t read_from = + ((static_cast<size_t>(in_x) * src_width + static_cast<size_t>(in_y)) >> 32) * + ir_components; + return std::span<const f32>(&input[read_from], ir_components); + }; + + auto x0_y0 = read_src(x_low, y_low); + auto x1_y0 = read_src(x_high, y_low); + auto x0_y1 = read_src(x_low, y_high); + auto x1_y1 = read_src(x_high, y_high); + + const auto result = bilinear_sample(x0_y0, x1_y0, x0_y1, x1_y1, weight_x, weight_y); + + const size_t write_to = (y * dst_width + x) * ir_components; + + std::memcpy(&output[write_to], &result, sizeof(f32) * ir_components); + } + } +} + +} // namespace + +struct SoftwareBlitEngine::BlitEngineImpl { + std::vector<u8> tmp_buffer; + std::vector<u8> src_buffer; + std::vector<u8> dst_buffer; + std::vector<f32> intermediate_src; + std::vector<f32> intermediate_dst; + ConverterFactory converter_factory; +}; + +SoftwareBlitEngine::SoftwareBlitEngine(MemoryManager& memory_manager_) + : memory_manager{memory_manager_} { + impl = std::make_unique<BlitEngineImpl>(); +} + +SoftwareBlitEngine::~SoftwareBlitEngine() = default; + +bool SoftwareBlitEngine::Blit(Fermi2D::Surface& src, Fermi2D::Surface& dst, + Fermi2D::Config& config) { + const auto get_surface_size = [](Fermi2D::Surface& surface, u32 bytes_per_pixel) { + if (surface.linear == Fermi2D::MemoryLayout::BlockLinear) { + return CalculateSize(true, bytes_per_pixel, surface.width, surface.height, + surface.depth, surface.block_height, surface.block_depth); + } + return static_cast<size_t>(surface.pitch * surface.height); + }; + const auto process_pitch_linear = [](bool unpack, std::span<const u8> input, + std::span<u8> output, u32 extent_x, u32 extent_y, + u32 pitch, u32 x0, u32 y0, size_t bpp) { + const size_t base_offset = x0 * bpp; + const size_t copy_size = extent_x * bpp; + for (u32 y = y0; y < extent_y; y++) { + const size_t first_offset = y * pitch + base_offset; + const size_t second_offset = y * extent_x * bpp; + u8* write_to = unpack ? &output[first_offset] : &output[second_offset]; + const u8* read_from = unpack ? &input[second_offset] : &input[first_offset]; + std::memcpy(write_to, read_from, copy_size); + } + }; + + const u32 src_extent_x = config.src_x1 - config.src_x0; + const u32 src_extent_y = config.src_y1 - config.src_y0; + + const u32 dst_extent_x = config.dst_x1 - config.dst_x0; + const u32 dst_extent_y = config.dst_y1 - config.dst_y0; + const auto src_bytes_per_pixel = BytesPerBlock(PixelFormatFromRenderTargetFormat(src.format)); + const auto dst_bytes_per_pixel = BytesPerBlock(PixelFormatFromRenderTargetFormat(dst.format)); + const size_t src_size = get_surface_size(src, src_bytes_per_pixel); + impl->tmp_buffer.resize(src_size); + memory_manager.ReadBlock(src.Address(), impl->tmp_buffer.data(), src_size); + + const size_t src_copy_size = src_extent_x * src_extent_y * src_bytes_per_pixel; + + const size_t dst_copy_size = dst_extent_x * dst_extent_y * dst_bytes_per_pixel; + + impl->src_buffer.resize(src_copy_size); + + const bool no_passthrough = + src.format != dst.format || src_extent_x != dst_extent_x || src_extent_y != dst_extent_y; + + const auto convertion_phase_same_format = [&]() { + NearestNeighbor(impl->src_buffer, impl->dst_buffer, src_extent_x, src_extent_y, + dst_extent_x, dst_extent_y, dst_bytes_per_pixel); + }; + + const auto convertion_phase_ir = [&]() { + auto* input_converter = impl->converter_factory.GetFormatConverter(src.format); + impl->intermediate_src.resize((src_copy_size / src_bytes_per_pixel) * ir_components); + impl->intermediate_dst.resize((dst_copy_size / dst_bytes_per_pixel) * ir_components); + input_converter->ConvertTo(impl->src_buffer, impl->intermediate_src); + + if (config.filter != Fermi2D::Filter::Bilinear) { + NearestNeighborFast(impl->intermediate_src, impl->intermediate_dst, src_extent_x, + src_extent_y, dst_extent_x, dst_extent_y); + } else { + Bilinear(impl->intermediate_src, impl->intermediate_dst, src_extent_x, src_extent_y, + dst_extent_x, dst_extent_y); + } + + auto* output_converter = impl->converter_factory.GetFormatConverter(dst.format); + output_converter->ConvertFrom(impl->intermediate_dst, impl->dst_buffer); + }; + + // Do actuall Blit + + impl->dst_buffer.resize(dst_copy_size); + if (src.linear == Fermi2D::MemoryLayout::BlockLinear) { + UnswizzleSubrect(impl->src_buffer, impl->tmp_buffer, src_bytes_per_pixel, src.width, + src.height, src.depth, config.src_x0, config.src_y0, src_extent_x, + src_extent_y, src.block_height, src.block_depth, + src_extent_x * src_bytes_per_pixel); + } else { + process_pitch_linear(false, impl->tmp_buffer, impl->src_buffer, src_extent_x, src_extent_y, + src.pitch, config.src_x0, config.src_y0, src_bytes_per_pixel); + } + + // Conversion Phase + if (no_passthrough) { + if (src.format != dst.format || config.filter == Fermi2D::Filter::Bilinear) { + convertion_phase_ir(); + } else { + convertion_phase_same_format(); + } + } else { + impl->dst_buffer.swap(impl->src_buffer); + } + + const size_t dst_size = get_surface_size(dst, dst_bytes_per_pixel); + impl->tmp_buffer.resize(dst_size); + memory_manager.ReadBlock(dst.Address(), impl->tmp_buffer.data(), dst_size); + + if (dst.linear == Fermi2D::MemoryLayout::BlockLinear) { + SwizzleSubrect(impl->tmp_buffer, impl->dst_buffer, dst_bytes_per_pixel, dst.width, + dst.height, dst.depth, config.dst_x0, config.dst_y0, dst_extent_x, + dst_extent_y, dst.block_height, dst.block_depth, + dst_extent_x * dst_bytes_per_pixel); + } else { + process_pitch_linear(true, impl->dst_buffer, impl->tmp_buffer, dst_extent_x, dst_extent_y, + dst.pitch, config.dst_x0, config.dst_y0, + static_cast<size_t>(dst_bytes_per_pixel)); + } + memory_manager.WriteBlock(dst.Address(), impl->tmp_buffer.data(), dst_size); + return true; +} + +} // namespace Tegra::Engines::Blitter diff --git a/src/video_core/engines/sw_blitter/blitter.h b/src/video_core/engines/sw_blitter/blitter.h new file mode 100644 index 000000000..85b55c836 --- /dev/null +++ b/src/video_core/engines/sw_blitter/blitter.h @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include "video_core/engines/fermi_2d.h" + +namespace Tegra { +class MemoryManager; +} + +namespace Tegra::Engines::Blitter { + +class SoftwareBlitEngine { +public: + explicit SoftwareBlitEngine(MemoryManager& memory_manager_); + ~SoftwareBlitEngine(); + + bool Blit(Fermi2D::Surface& src, Fermi2D::Surface& dst, Fermi2D::Config& copy_config); + +private: + MemoryManager& memory_manager; + struct BlitEngineImpl; + std::unique_ptr<BlitEngineImpl> impl; +}; + +} // namespace Tegra::Engines::Blitter diff --git a/src/video_core/engines/sw_blitter/converter.cpp b/src/video_core/engines/sw_blitter/converter.cpp new file mode 100644 index 000000000..cd46dfd4f --- /dev/null +++ b/src/video_core/engines/sw_blitter/converter.cpp @@ -0,0 +1,1234 @@ +// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#include <array> +#include <bit> +#include <cmath> +#include <span> +#include <unordered_map> + +#include "common/assert.h" +#include "video_core/engines/sw_blitter/converter.h" +#include "video_core/surface.h" +#include "video_core/textures/decoders.h" + +#ifdef _MSC_VER +#define FORCE_INLINE __forceinline +#else +#define FORCE_INLINE inline __attribute__((always_inline)) +#endif + +namespace Tegra::Engines::Blitter { + +enum class Swizzle : size_t { + R = 0, + G = 1, + B = 2, + A = 3, + None, +}; + +enum class ComponentType : u32 { + SNORM = 1, + UNORM = 2, + SINT = 3, + UINT = 4, + SNORM_FORCE_FP16 = 5, + UNORM_FORCE_FP16 = 6, + FLOAT = 7, + SRGB = 8, +}; + +namespace { + +/* + * Note: Use generate_converters.py to generate the structs and searches for new render target + * formats and copy paste them to this file in order to update. just call "python + * generate_converters.py" and get the code from the output. modify the file to add new formats. + */ + +constexpr std::array<f32, 256> SRGB_TO_RGB_LUT = { + 0.000000e+00f, 3.035270e-04f, 6.070540e-04f, 9.105810e-04f, 1.214108e-03f, 1.517635e-03f, + 1.821162e-03f, 2.124689e-03f, 2.428216e-03f, 2.731743e-03f, 3.035270e-03f, 3.346536e-03f, + 3.676507e-03f, 4.024717e-03f, 4.391442e-03f, 4.776953e-03f, 5.181517e-03f, 5.605392e-03f, + 6.048833e-03f, 6.512091e-03f, 6.995410e-03f, 7.499032e-03f, 8.023193e-03f, 8.568126e-03f, + 9.134059e-03f, 9.721218e-03f, 1.032982e-02f, 1.096009e-02f, 1.161224e-02f, 1.228649e-02f, + 1.298303e-02f, 1.370208e-02f, 1.444384e-02f, 1.520851e-02f, 1.599629e-02f, 1.680738e-02f, + 1.764195e-02f, 1.850022e-02f, 1.938236e-02f, 2.028856e-02f, 2.121901e-02f, 2.217389e-02f, + 2.315337e-02f, 2.415763e-02f, 2.518686e-02f, 2.624122e-02f, 2.732089e-02f, 2.842604e-02f, + 2.955684e-02f, 3.071344e-02f, 3.189603e-02f, 3.310477e-02f, 3.433981e-02f, 3.560131e-02f, + 3.688945e-02f, 3.820437e-02f, 3.954624e-02f, 4.091520e-02f, 4.231141e-02f, 4.373503e-02f, + 4.518620e-02f, 4.666509e-02f, 4.817183e-02f, 4.970657e-02f, 5.126946e-02f, 5.286065e-02f, + 5.448028e-02f, 5.612849e-02f, 5.780543e-02f, 5.951124e-02f, 6.124605e-02f, 6.301001e-02f, + 6.480327e-02f, 6.662594e-02f, 6.847817e-02f, 7.036009e-02f, 7.227185e-02f, 7.421357e-02f, + 7.618538e-02f, 7.818742e-02f, 8.021982e-02f, 8.228271e-02f, 8.437621e-02f, 8.650046e-02f, + 8.865558e-02f, 9.084171e-02f, 9.305897e-02f, 9.530747e-02f, 9.758735e-02f, 9.989873e-02f, + 1.022417e-01f, 1.046165e-01f, 1.070231e-01f, 1.094617e-01f, 1.119324e-01f, 1.144354e-01f, + 1.169707e-01f, 1.195384e-01f, 1.221388e-01f, 1.247718e-01f, 1.274377e-01f, 1.301365e-01f, + 1.328683e-01f, 1.356333e-01f, 1.384316e-01f, 1.412633e-01f, 1.441285e-01f, 1.470273e-01f, + 1.499598e-01f, 1.529261e-01f, 1.559265e-01f, 1.589608e-01f, 1.620294e-01f, 1.651322e-01f, + 1.682694e-01f, 1.714411e-01f, 1.746474e-01f, 1.778884e-01f, 1.811642e-01f, 1.844750e-01f, + 1.878208e-01f, 1.912017e-01f, 1.946178e-01f, 1.980693e-01f, 2.015563e-01f, 2.050787e-01f, + 2.086369e-01f, 2.122308e-01f, 2.158605e-01f, 2.195262e-01f, 2.232280e-01f, 2.269659e-01f, + 2.307401e-01f, 2.345506e-01f, 2.383976e-01f, 2.422811e-01f, 2.462013e-01f, 2.501583e-01f, + 2.541521e-01f, 2.581829e-01f, 2.622507e-01f, 2.663556e-01f, 2.704978e-01f, 2.746773e-01f, + 2.788943e-01f, 2.831487e-01f, 2.874408e-01f, 2.917706e-01f, 2.961383e-01f, 3.005438e-01f, + 3.049873e-01f, 3.094689e-01f, 3.139887e-01f, 3.185468e-01f, 3.231432e-01f, 3.277781e-01f, + 3.324515e-01f, 3.371636e-01f, 3.419144e-01f, 3.467041e-01f, 3.515326e-01f, 3.564001e-01f, + 3.613068e-01f, 3.662526e-01f, 3.712377e-01f, 3.762621e-01f, 3.813260e-01f, 3.864294e-01f, + 3.915725e-01f, 3.967552e-01f, 4.019778e-01f, 4.072402e-01f, 4.125426e-01f, 4.178851e-01f, + 4.232677e-01f, 4.286905e-01f, 4.341536e-01f, 4.396572e-01f, 4.452012e-01f, 4.507858e-01f, + 4.564110e-01f, 4.620770e-01f, 4.677838e-01f, 4.735315e-01f, 4.793202e-01f, 4.851499e-01f, + 4.910209e-01f, 4.969330e-01f, 5.028865e-01f, 5.088813e-01f, 5.149177e-01f, 5.209956e-01f, + 5.271151e-01f, 5.332764e-01f, 5.394795e-01f, 5.457245e-01f, 5.520114e-01f, 5.583404e-01f, + 5.647115e-01f, 5.711249e-01f, 5.775805e-01f, 5.840784e-01f, 5.906188e-01f, 5.972018e-01f, + 6.038274e-01f, 6.104956e-01f, 6.172066e-01f, 6.239604e-01f, 6.307572e-01f, 6.375968e-01f, + 6.444797e-01f, 6.514056e-01f, 6.583748e-01f, 6.653873e-01f, 6.724432e-01f, 6.795425e-01f, + 6.866853e-01f, 6.938717e-01f, 7.011019e-01f, 7.083758e-01f, 7.156935e-01f, 7.230551e-01f, + 7.304608e-01f, 7.379104e-01f, 7.454042e-01f, 7.529422e-01f, 7.605245e-01f, 7.681512e-01f, + 7.758222e-01f, 7.835378e-01f, 7.912979e-01f, 7.991027e-01f, 8.069522e-01f, 8.148466e-01f, + 8.227857e-01f, 8.307699e-01f, 8.387990e-01f, 8.468732e-01f, 8.549926e-01f, 8.631572e-01f, + 8.713671e-01f, 8.796224e-01f, 8.879231e-01f, 8.962694e-01f, 9.046612e-01f, 9.130986e-01f, + 9.215819e-01f, 9.301109e-01f, 9.386857e-01f, 9.473065e-01f, 9.559733e-01f, 9.646863e-01f, + 9.734453e-01f, 9.822506e-01f, 9.911021e-01f, 1.000000e+00f}; + +constexpr std::array<f32, 256> RGB_TO_SRGB_LUT = { + 0.000000e+00f, 4.984009e-02f, 8.494473e-02f, 1.107021e-01f, 1.318038e-01f, 1.500052e-01f, + 1.661857e-01f, 1.808585e-01f, 1.943532e-01f, 2.068957e-01f, 2.186491e-01f, 2.297351e-01f, + 2.402475e-01f, 2.502604e-01f, 2.598334e-01f, 2.690152e-01f, 2.778465e-01f, 2.863614e-01f, + 2.945889e-01f, 3.025538e-01f, 3.102778e-01f, 3.177796e-01f, 3.250757e-01f, 3.321809e-01f, + 3.391081e-01f, 3.458689e-01f, 3.524737e-01f, 3.589320e-01f, 3.652521e-01f, 3.714419e-01f, + 3.775084e-01f, 3.834581e-01f, 3.892968e-01f, 3.950301e-01f, 4.006628e-01f, 4.061998e-01f, + 4.116451e-01f, 4.170030e-01f, 4.222770e-01f, 4.274707e-01f, 4.325873e-01f, 4.376298e-01f, + 4.426010e-01f, 4.475037e-01f, 4.523403e-01f, 4.571131e-01f, 4.618246e-01f, 4.664766e-01f, + 4.710712e-01f, 4.756104e-01f, 4.800958e-01f, 4.845292e-01f, 4.889122e-01f, 4.932462e-01f, + 4.975329e-01f, 5.017734e-01f, 5.059693e-01f, 5.101216e-01f, 5.142317e-01f, 5.183006e-01f, + 5.223295e-01f, 5.263194e-01f, 5.302714e-01f, 5.341862e-01f, 5.380651e-01f, 5.419087e-01f, + 5.457181e-01f, 5.494938e-01f, 5.532369e-01f, 5.569480e-01f, 5.606278e-01f, 5.642771e-01f, + 5.678965e-01f, 5.714868e-01f, 5.750484e-01f, 5.785821e-01f, 5.820884e-01f, 5.855680e-01f, + 5.890211e-01f, 5.924487e-01f, 5.958509e-01f, 5.992285e-01f, 6.025819e-01f, 6.059114e-01f, + 6.092176e-01f, 6.125010e-01f, 6.157619e-01f, 6.190008e-01f, 6.222180e-01f, 6.254140e-01f, + 6.285890e-01f, 6.317436e-01f, 6.348780e-01f, 6.379926e-01f, 6.410878e-01f, 6.441637e-01f, + 6.472208e-01f, 6.502595e-01f, 6.532799e-01f, 6.562824e-01f, 6.592672e-01f, 6.622347e-01f, + 6.651851e-01f, 6.681187e-01f, 6.710356e-01f, 6.739363e-01f, 6.768209e-01f, 6.796897e-01f, + 6.825429e-01f, 6.853807e-01f, 6.882034e-01f, 6.910111e-01f, 6.938041e-01f, 6.965826e-01f, + 6.993468e-01f, 7.020969e-01f, 7.048331e-01f, 7.075556e-01f, 7.102645e-01f, 7.129600e-01f, + 7.156424e-01f, 7.183118e-01f, 7.209683e-01f, 7.236121e-01f, 7.262435e-01f, 7.288625e-01f, + 7.314693e-01f, 7.340640e-01f, 7.366470e-01f, 7.392181e-01f, 7.417776e-01f, 7.443256e-01f, + 7.468624e-01f, 7.493880e-01f, 7.519025e-01f, 7.544061e-01f, 7.568989e-01f, 7.593810e-01f, + 7.618526e-01f, 7.643137e-01f, 7.667645e-01f, 7.692052e-01f, 7.716358e-01f, 7.740564e-01f, + 7.764671e-01f, 7.788681e-01f, 7.812595e-01f, 7.836413e-01f, 7.860138e-01f, 7.883768e-01f, + 7.907307e-01f, 7.930754e-01f, 7.954110e-01f, 7.977377e-01f, 8.000556e-01f, 8.023647e-01f, + 8.046651e-01f, 8.069569e-01f, 8.092403e-01f, 8.115152e-01f, 8.137818e-01f, 8.160402e-01f, + 8.182903e-01f, 8.205324e-01f, 8.227665e-01f, 8.249926e-01f, 8.272109e-01f, 8.294214e-01f, + 8.316242e-01f, 8.338194e-01f, 8.360070e-01f, 8.381871e-01f, 8.403597e-01f, 8.425251e-01f, + 8.446831e-01f, 8.468339e-01f, 8.489776e-01f, 8.511142e-01f, 8.532437e-01f, 8.553662e-01f, + 8.574819e-01f, 8.595907e-01f, 8.616927e-01f, 8.637881e-01f, 8.658767e-01f, 8.679587e-01f, + 8.700342e-01f, 8.721032e-01f, 8.741657e-01f, 8.762218e-01f, 8.782716e-01f, 8.803151e-01f, + 8.823524e-01f, 8.843835e-01f, 8.864085e-01f, 8.884274e-01f, 8.904402e-01f, 8.924471e-01f, + 8.944480e-01f, 8.964431e-01f, 8.984324e-01f, 9.004158e-01f, 9.023935e-01f, 9.043654e-01f, + 9.063318e-01f, 9.082925e-01f, 9.102476e-01f, 9.121972e-01f, 9.141413e-01f, 9.160800e-01f, + 9.180133e-01f, 9.199412e-01f, 9.218637e-01f, 9.237810e-01f, 9.256931e-01f, 9.276000e-01f, + 9.295017e-01f, 9.313982e-01f, 9.332896e-01f, 9.351761e-01f, 9.370575e-01f, 9.389339e-01f, + 9.408054e-01f, 9.426719e-01f, 9.445336e-01f, 9.463905e-01f, 9.482424e-01f, 9.500897e-01f, + 9.519322e-01f, 9.537700e-01f, 9.556032e-01f, 9.574316e-01f, 9.592555e-01f, 9.610748e-01f, + 9.628896e-01f, 9.646998e-01f, 9.665055e-01f, 9.683068e-01f, 9.701037e-01f, 9.718961e-01f, + 9.736842e-01f, 9.754679e-01f, 9.772474e-01f, 9.790225e-01f, 9.807934e-01f, 9.825601e-01f, + 9.843225e-01f, 9.860808e-01f, 9.878350e-01f, 9.895850e-01f, 9.913309e-01f, 9.930727e-01f, + 9.948106e-01f, 9.965444e-01f, 9.982741e-01f, 1.000000e+00f}; + +} // namespace + +struct R32G32B32A32_FLOATTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::FLOAT, ComponentType::FLOAT, ComponentType::FLOAT, ComponentType::FLOAT}; + static constexpr std::array<size_t, num_components> component_sizes = {32, 32, 32, 32}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::R, Swizzle::G, Swizzle::B, Swizzle::A}; +}; + +struct R32G32B32A32_SINTTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SINT, ComponentType::SINT, ComponentType::SINT, ComponentType::SINT}; + static constexpr std::array<size_t, num_components> component_sizes = {32, 32, 32, 32}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::R, Swizzle::G, Swizzle::B, Swizzle::A}; +}; + +struct R32G32B32A32_UINTTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UINT, ComponentType::UINT, ComponentType::UINT, ComponentType::UINT}; + static constexpr std::array<size_t, num_components> component_sizes = {32, 32, 32, 32}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::R, Swizzle::G, Swizzle::B, Swizzle::A}; +}; + +struct R32G32B32X32_FLOATTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::FLOAT, ComponentType::FLOAT, ComponentType::FLOAT, ComponentType::FLOAT}; + static constexpr std::array<size_t, num_components> component_sizes = {32, 32, 32, 32}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::R, Swizzle::G, Swizzle::B, Swizzle::None}; +}; + +struct R32G32B32X32_SINTTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SINT, ComponentType::SINT, ComponentType::SINT, ComponentType::SINT}; + static constexpr std::array<size_t, num_components> component_sizes = {32, 32, 32, 32}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::R, Swizzle::G, Swizzle::B, Swizzle::None}; +}; + +struct R32G32B32X32_UINTTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UINT, ComponentType::UINT, ComponentType::UINT, ComponentType::UINT}; + static constexpr std::array<size_t, num_components> component_sizes = {32, 32, 32, 32}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::R, Swizzle::G, Swizzle::B, Swizzle::None}; +}; + +struct R16G16B16A16_UNORMTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {16, 16, 16, 16}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::R, Swizzle::G, Swizzle::B, Swizzle::A}; +}; + +struct R16G16B16A16_SNORMTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SNORM, ComponentType::SNORM, ComponentType::SNORM, ComponentType::SNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {16, 16, 16, 16}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::R, Swizzle::G, Swizzle::B, Swizzle::A}; +}; + +struct R16G16B16A16_SINTTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SINT, ComponentType::SINT, ComponentType::SINT, ComponentType::SINT}; + static constexpr std::array<size_t, num_components> component_sizes = {16, 16, 16, 16}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::R, Swizzle::G, Swizzle::B, Swizzle::A}; +}; + +struct R16G16B16A16_UINTTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UINT, ComponentType::UINT, ComponentType::UINT, ComponentType::UINT}; + static constexpr std::array<size_t, num_components> component_sizes = {16, 16, 16, 16}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::R, Swizzle::G, Swizzle::B, Swizzle::A}; +}; + +struct R16G16B16A16_FLOATTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::FLOAT, ComponentType::FLOAT, ComponentType::FLOAT, ComponentType::FLOAT}; + static constexpr std::array<size_t, num_components> component_sizes = {16, 16, 16, 16}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::R, Swizzle::G, Swizzle::B, Swizzle::A}; +}; + +struct R32G32_FLOATTraits { + static constexpr size_t num_components = 2; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::FLOAT, ComponentType::FLOAT}; + static constexpr std::array<size_t, num_components> component_sizes = {32, 32}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R, + Swizzle::G}; +}; + +struct R32G32_SINTTraits { + static constexpr size_t num_components = 2; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SINT, ComponentType::SINT}; + static constexpr std::array<size_t, num_components> component_sizes = {32, 32}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R, + Swizzle::G}; +}; + +struct R32G32_UINTTraits { + static constexpr size_t num_components = 2; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UINT, ComponentType::UINT}; + static constexpr std::array<size_t, num_components> component_sizes = {32, 32}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R, + Swizzle::G}; +}; + +struct R16G16B16X16_FLOATTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::FLOAT, ComponentType::FLOAT, ComponentType::FLOAT, ComponentType::FLOAT}; + static constexpr std::array<size_t, num_components> component_sizes = {16, 16, 16, 16}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::R, Swizzle::G, Swizzle::B, Swizzle::None}; +}; + +struct A8R8G8B8_UNORMTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {8, 8, 8, 8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::A, Swizzle::R, Swizzle::G, Swizzle::B}; +}; + +struct A8R8G8B8_SRGBTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SRGB, ComponentType::SRGB, ComponentType::SRGB, ComponentType::SRGB}; + static constexpr std::array<size_t, num_components> component_sizes = {8, 8, 8, 8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::A, Swizzle::R, Swizzle::G, Swizzle::B}; +}; + +struct A2B10G10R10_UNORMTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {2, 10, 10, 10}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::A, Swizzle::B, Swizzle::G, Swizzle::R}; +}; + +struct A2B10G10R10_UINTTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UINT, ComponentType::UINT, ComponentType::UINT, ComponentType::UINT}; + static constexpr std::array<size_t, num_components> component_sizes = {2, 10, 10, 10}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::A, Swizzle::B, Swizzle::G, Swizzle::R}; +}; + +struct A2R10G10B10_UNORMTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {2, 10, 10, 10}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::A, Swizzle::R, Swizzle::G, Swizzle::B}; +}; + +struct A8B8G8R8_UNORMTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {8, 8, 8, 8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::A, Swizzle::B, Swizzle::G, Swizzle::R}; +}; + +struct A8B8G8R8_SRGBTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SRGB, ComponentType::SRGB, ComponentType::SRGB, ComponentType::SRGB}; + static constexpr std::array<size_t, num_components> component_sizes = {8, 8, 8, 8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::A, Swizzle::B, Swizzle::G, Swizzle::R}; +}; + +struct A8B8G8R8_SNORMTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SNORM, ComponentType::SNORM, ComponentType::SNORM, ComponentType::SNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {8, 8, 8, 8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::A, Swizzle::B, Swizzle::G, Swizzle::R}; +}; + +struct A8B8G8R8_SINTTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SINT, ComponentType::SINT, ComponentType::SINT, ComponentType::SINT}; + static constexpr std::array<size_t, num_components> component_sizes = {8, 8, 8, 8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::A, Swizzle::B, Swizzle::G, Swizzle::R}; +}; + +struct A8B8G8R8_UINTTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UINT, ComponentType::UINT, ComponentType::UINT, ComponentType::UINT}; + static constexpr std::array<size_t, num_components> component_sizes = {8, 8, 8, 8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::A, Swizzle::B, Swizzle::G, Swizzle::R}; +}; + +struct R16G16_UNORMTraits { + static constexpr size_t num_components = 2; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UNORM, ComponentType::UNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {16, 16}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R, + Swizzle::G}; +}; + +struct R16G16_SNORMTraits { + static constexpr size_t num_components = 2; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SNORM, ComponentType::SNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {16, 16}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R, + Swizzle::G}; +}; + +struct R16G16_SINTTraits { + static constexpr size_t num_components = 2; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SINT, ComponentType::SINT}; + static constexpr std::array<size_t, num_components> component_sizes = {16, 16}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R, + Swizzle::G}; +}; + +struct R16G16_UINTTraits { + static constexpr size_t num_components = 2; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UINT, ComponentType::UINT}; + static constexpr std::array<size_t, num_components> component_sizes = {16, 16}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R, + Swizzle::G}; +}; + +struct R16G16_FLOATTraits { + static constexpr size_t num_components = 2; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::FLOAT, ComponentType::FLOAT}; + static constexpr std::array<size_t, num_components> component_sizes = {16, 16}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R, + Swizzle::G}; +}; + +struct B10G11R11_FLOATTraits { + static constexpr size_t num_components = 3; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::FLOAT, ComponentType::FLOAT, ComponentType::FLOAT}; + static constexpr std::array<size_t, num_components> component_sizes = {10, 11, 11}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::B, Swizzle::G, Swizzle::R}; +}; + +struct R32_SINTTraits { + static constexpr size_t num_components = 1; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SINT}; + static constexpr std::array<size_t, num_components> component_sizes = {32}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R}; +}; + +struct R32_UINTTraits { + static constexpr size_t num_components = 1; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UINT}; + static constexpr std::array<size_t, num_components> component_sizes = {32}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R}; +}; + +struct R32_FLOATTraits { + static constexpr size_t num_components = 1; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::FLOAT}; + static constexpr std::array<size_t, num_components> component_sizes = {32}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R}; +}; + +struct X8R8G8B8_UNORMTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {8, 8, 8, 8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::None, Swizzle::R, Swizzle::G, Swizzle::B}; +}; + +struct X8R8G8B8_SRGBTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SRGB, ComponentType::SRGB, ComponentType::SRGB, ComponentType::SRGB}; + static constexpr std::array<size_t, num_components> component_sizes = {8, 8, 8, 8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::None, Swizzle::R, Swizzle::G, Swizzle::B}; +}; + +struct R5G6B5_UNORMTraits { + static constexpr size_t num_components = 3; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {5, 6, 5}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::R, Swizzle::G, Swizzle::B}; +}; + +struct A1R5G5B5_UNORMTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {1, 5, 5, 5}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::A, Swizzle::R, Swizzle::G, Swizzle::B}; +}; + +struct R8G8_UNORMTraits { + static constexpr size_t num_components = 2; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UNORM, ComponentType::UNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {8, 8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R, + Swizzle::G}; +}; + +struct R8G8_SNORMTraits { + static constexpr size_t num_components = 2; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SNORM, ComponentType::SNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {8, 8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R, + Swizzle::G}; +}; + +struct R8G8_SINTTraits { + static constexpr size_t num_components = 2; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SINT, ComponentType::SINT}; + static constexpr std::array<size_t, num_components> component_sizes = {8, 8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R, + Swizzle::G}; +}; + +struct R8G8_UINTTraits { + static constexpr size_t num_components = 2; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UINT, ComponentType::UINT}; + static constexpr std::array<size_t, num_components> component_sizes = {8, 8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R, + Swizzle::G}; +}; + +struct R16_UNORMTraits { + static constexpr size_t num_components = 1; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {16}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R}; +}; + +struct R16_SNORMTraits { + static constexpr size_t num_components = 1; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {16}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R}; +}; + +struct R16_SINTTraits { + static constexpr size_t num_components = 1; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SINT}; + static constexpr std::array<size_t, num_components> component_sizes = {16}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R}; +}; + +struct R16_UINTTraits { + static constexpr size_t num_components = 1; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UINT}; + static constexpr std::array<size_t, num_components> component_sizes = {16}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R}; +}; + +struct R16_FLOATTraits { + static constexpr size_t num_components = 1; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::FLOAT}; + static constexpr std::array<size_t, num_components> component_sizes = {16}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R}; +}; + +struct R8_UNORMTraits { + static constexpr size_t num_components = 1; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R}; +}; + +struct R8_SNORMTraits { + static constexpr size_t num_components = 1; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R}; +}; + +struct R8_SINTTraits { + static constexpr size_t num_components = 1; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SINT}; + static constexpr std::array<size_t, num_components> component_sizes = {8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R}; +}; + +struct R8_UINTTraits { + static constexpr size_t num_components = 1; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UINT}; + static constexpr std::array<size_t, num_components> component_sizes = {8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = {Swizzle::R}; +}; + +struct X1R5G5B5_UNORMTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {1, 5, 5, 5}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::None, Swizzle::R, Swizzle::G, Swizzle::B}; +}; + +struct X8B8G8R8_UNORMTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM, ComponentType::UNORM}; + static constexpr std::array<size_t, num_components> component_sizes = {8, 8, 8, 8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::None, Swizzle::B, Swizzle::G, Swizzle::R}; +}; + +struct X8B8G8R8_SRGBTraits { + static constexpr size_t num_components = 4; + static constexpr std::array<ComponentType, num_components> component_types = { + ComponentType::SRGB, ComponentType::SRGB, ComponentType::SRGB, ComponentType::SRGB}; + static constexpr std::array<size_t, num_components> component_sizes = {8, 8, 8, 8}; + static constexpr std::array<Swizzle, num_components> component_swizzle = { + Swizzle::None, Swizzle::B, Swizzle::G, Swizzle::R}; +}; + +template <class ConverterTraits> +class ConverterImpl : public Converter { +private: + static constexpr size_t num_components = ConverterTraits::num_components; + static constexpr std::array<ComponentType, num_components> component_types = + ConverterTraits::component_types; + static constexpr std::array<size_t, num_components> component_sizes = + ConverterTraits::component_sizes; + static constexpr std::array<Swizzle, num_components> component_swizzle = + ConverterTraits::component_swizzle; + + static constexpr size_t CalculateByteSize() { + size_t size = 0; + for (const size_t component_size : component_sizes) { + size += component_size; + } + const size_t power = (sizeof(size_t) * 8) - std::countl_zero(size) - 1ULL; + const size_t base_size = 1ULL << power; + const size_t mask = base_size - 1ULL; + return ((size & mask) != 0 ? base_size << 1ULL : base_size) / 8; + } + + static constexpr size_t total_bytes_per_pixel = CalculateByteSize(); + static constexpr size_t total_words_per_pixel = + (total_bytes_per_pixel + sizeof(u32) - 1U) / sizeof(u32); + static constexpr size_t components_per_ir_rep = 4; + + template <bool get_offsets> + static constexpr std::array<size_t, num_components> GetBoundWordsOffsets() { + std::array<size_t, num_components> result; + result.fill(0); + constexpr size_t total_bits_per_word = sizeof(u32) * 8; + size_t accumulated_size = 0; + size_t count = 0; + for (size_t i = 0; i < num_components; i++) { + if constexpr (get_offsets) { + result[i] = accumulated_size; + } else { + result[i] = count; + } + accumulated_size += component_sizes[i]; + if (accumulated_size > total_bits_per_word) { + if constexpr (get_offsets) { + result[i] = 0; + } else { + result[i]++; + } + count++; + accumulated_size = component_sizes[i]; + } + } + return result; + } + + static constexpr std::array<size_t, num_components> bound_words = GetBoundWordsOffsets<false>(); + static constexpr std::array<size_t, num_components> bound_offsets = + GetBoundWordsOffsets<true>(); + + static constexpr std::array<u32, num_components> GetComponentsMask() { + std::array<u32, num_components> result; + for (size_t i = 0; i < num_components; i++) { + result[i] = (((u32)~0) >> (8 * sizeof(u32) - component_sizes[i])) << bound_offsets[i]; + } + return result; + } + + static constexpr std::array<u32, num_components> component_mask = GetComponentsMask(); + + // We are forcing inline so the compiler can SIMD the conversations, since it may do 4 function + // calls, it may fail to detect the benefit of inlining. + template <size_t which_component> + FORCE_INLINE void ConvertToComponent(u32 which_word, f32& out_component) { + const u32 value = (which_word >> bound_offsets[which_component]) & + static_cast<u32>((1ULL << component_sizes[which_component]) - 1ULL); + const auto sign_extend = [](u32 base_value, size_t bits) { + const size_t shift_amount = sizeof(u32) * 8 - bits; + s32 shifted_value = static_cast<s32>(base_value << shift_amount); + return shifted_value >> shift_amount; + }; + const auto force_to_fp16 = [](f32 base_value) { + u32 tmp = std::bit_cast<u32>(base_value); + constexpr size_t fp32_mantissa_bits = 23; + constexpr size_t fp16_mantissa_bits = 10; + constexpr size_t mantissa_mask = + ~((1ULL << (fp32_mantissa_bits - fp16_mantissa_bits)) - 1ULL); + tmp = tmp & static_cast<u32>(mantissa_mask); + // TODO: force the exponent within the range of half float. Not needed in UNORM / SNORM + return std::bit_cast<f32>(tmp); + }; + const auto from_fp_n = [&sign_extend](u32 base_value, size_t bits, size_t mantissa) { + constexpr size_t fp32_mantissa_bits = 23; + size_t shift_towards = fp32_mantissa_bits - mantissa; + const u32 new_value = + static_cast<u32>(sign_extend(base_value, bits) << shift_towards) & (~(1U << 31)); + return std::bit_cast<f32>(new_value); + }; + const auto calculate_snorm = [&]() { + return static_cast<f32>( + static_cast<f32>(sign_extend(value, component_sizes[which_component])) / + static_cast<f32>((1ULL << (component_sizes[which_component] - 1ULL)) - 1ULL)); + }; + const auto calculate_unorm = [&]() { + return static_cast<f32>( + static_cast<f32>(value) / + static_cast<f32>((1ULL << (component_sizes[which_component])) - 1ULL)); + }; + if constexpr (component_types[which_component] == ComponentType::SNORM) { + out_component = calculate_snorm(); + } else if constexpr (component_types[which_component] == ComponentType::UNORM) { + out_component = calculate_unorm(); + } else if constexpr (component_types[which_component] == ComponentType::SINT) { + out_component = static_cast<f32>( + static_cast<s32>(sign_extend(value, component_sizes[which_component]))); + } else if constexpr (component_types[which_component] == ComponentType::UINT) { + out_component = static_cast<f32>( + static_cast<s32>(sign_extend(value, component_sizes[which_component]))); + } else if constexpr (component_types[which_component] == ComponentType::SNORM_FORCE_FP16) { + out_component = calculate_snorm(); + out_component = force_to_fp16(out_component); + } else if constexpr (component_types[which_component] == ComponentType::UNORM_FORCE_FP16) { + out_component = calculate_unorm(); + out_component = force_to_fp16(out_component); + } else if constexpr (component_types[which_component] == ComponentType::FLOAT) { + if constexpr (component_sizes[which_component] == 32) { + out_component = std::bit_cast<f32>(value); + } else if constexpr (component_sizes[which_component] == 16) { + static constexpr u32 sign_mask = 0x8000; + static constexpr u32 mantissa_mask = 0x8000; + out_component = std::bit_cast<f32>(((value & sign_mask) << 16) | + (((value & 0x7c00) + 0x1C000) << 13) | + ((value & mantissa_mask) << 13)); + } else { + out_component = from_fp_n(value, component_sizes[which_component], + component_sizes[which_component] - 5); + } + } else if constexpr (component_types[which_component] == ComponentType::SRGB) { + if constexpr (component_swizzle[which_component] == Swizzle::A) { + out_component = calculate_unorm(); + } else if constexpr (component_sizes[which_component] == 8) { + out_component = SRGB_TO_RGB_LUT[value]; + } else { + out_component = calculate_unorm(); + UNIMPLEMENTED_MSG("SRGB Conversion with component sizes of {} is unimplemented", + component_sizes[which_component]); + } + } + } + + // We are forcing inline so the compiler can SIMD the conversations, since it may do 4 function + // calls, it may fail to detect the benefit of inlining. + template <size_t which_component> + FORCE_INLINE void ConvertFromComponent(u32& which_word, f32 in_component) { + const auto insert_to_word = [&]<typename T>(T new_word) { + which_word |= (static_cast<u32>(new_word) << bound_offsets[which_component]) & + component_mask[which_component]; + }; + const auto to_fp_n = [](f32 base_value, size_t bits, size_t mantissa) { + constexpr size_t fp32_mantissa_bits = 23; + u32 tmp_value = std::bit_cast<u32>(std::max(base_value, 0.0f)); + size_t shift_towards = fp32_mantissa_bits - mantissa; + return tmp_value >> shift_towards; + }; + const auto calculate_unorm = [&]() { + return static_cast<u32>( + static_cast<f32>(in_component) * + static_cast<f32>((1ULL << (component_sizes[which_component])) - 1ULL)); + }; + if constexpr (component_types[which_component] == ComponentType::SNORM || + component_types[which_component] == ComponentType::SNORM_FORCE_FP16) { + s32 tmp_word = static_cast<s32>( + static_cast<f32>(in_component) * + static_cast<f32>((1ULL << (component_sizes[which_component] - 1ULL)) - 1ULL)); + insert_to_word(tmp_word); + + } else if constexpr (component_types[which_component] == ComponentType::UNORM || + component_types[which_component] == ComponentType::UNORM_FORCE_FP16) { + u32 tmp_word = calculate_unorm(); + insert_to_word(tmp_word); + } else if constexpr (component_types[which_component] == ComponentType::SINT) { + s32 tmp_word = static_cast<s32>(in_component); + insert_to_word(tmp_word); + } else if constexpr (component_types[which_component] == ComponentType::UINT) { + u32 tmp_word = static_cast<u32>(in_component); + insert_to_word(tmp_word); + } else if constexpr (component_types[which_component] == ComponentType::FLOAT) { + if constexpr (component_sizes[which_component] == 32) { + u32 tmp_word = std::bit_cast<u32>(in_component); + insert_to_word(tmp_word); + } else if constexpr (component_sizes[which_component] == 16) { + static constexpr u32 sign_mask = 0x8000; + static constexpr u32 mantissa_mask = 0x03ff; + static constexpr u32 exponent_mask = 0x7c00; + const u32 tmp_word = std::bit_cast<u32>(in_component); + const u32 half = ((tmp_word >> 16) & sign_mask) | + ((((tmp_word & 0x7f800000) - 0x38000000) >> 13) & exponent_mask) | + ((tmp_word >> 13) & mantissa_mask); + insert_to_word(half); + } else { + insert_to_word(to_fp_n(in_component, component_sizes[which_component], + component_sizes[which_component] - 5)); + } + } else if constexpr (component_types[which_component] == ComponentType::SRGB) { + if constexpr (component_swizzle[which_component] != Swizzle::A) { + if constexpr (component_sizes[which_component] == 8) { + const u32 index = calculate_unorm(); + in_component = RGB_TO_SRGB_LUT[index]; + } else { + UNIMPLEMENTED_MSG("SRGB Conversion with component sizes of {} is unimplemented", + component_sizes[which_component]); + } + } + const u32 tmp_word = calculate_unorm(); + insert_to_word(tmp_word); + } + } + +public: + void ConvertTo(std::span<const u8> input, std::span<f32> output) override { + const size_t num_pixels = output.size() / components_per_ir_rep; + for (size_t pixel = 0; pixel < num_pixels; pixel++) { + std::array<u32, total_words_per_pixel> words{}; + + std::memcpy(words.data(), &input[pixel * total_bytes_per_pixel], total_bytes_per_pixel); + std::span<f32> new_components(&output[pixel * components_per_ir_rep], + components_per_ir_rep); + if constexpr (component_swizzle[0] != Swizzle::None) { + ConvertToComponent<0>(words[bound_words[0]], + new_components[static_cast<size_t>(component_swizzle[0])]); + } else { + new_components[0] = 0.0f; + } + if constexpr (num_components >= 2) { + if constexpr (component_swizzle[1] != Swizzle::None) { + ConvertToComponent<1>( + words[bound_words[1]], + new_components[static_cast<size_t>(component_swizzle[1])]); + } else { + new_components[1] = 0.0f; + } + } else { + new_components[1] = 0.0f; + } + if constexpr (num_components >= 3) { + if constexpr (component_swizzle[2] != Swizzle::None) { + ConvertToComponent<2>( + words[bound_words[2]], + new_components[static_cast<size_t>(component_swizzle[2])]); + } else { + new_components[2] = 0.0f; + } + } else { + new_components[2] = 0.0f; + } + if constexpr (num_components >= 4) { + if constexpr (component_swizzle[3] != Swizzle::None) { + ConvertToComponent<3>( + words[bound_words[3]], + new_components[static_cast<size_t>(component_swizzle[3])]); + } else { + new_components[3] = 0.0f; + } + } else { + new_components[3] = 0.0f; + } + } + } + + void ConvertFrom(std::span<const f32> input, std::span<u8> output) override { + const size_t num_pixels = output.size() / total_bytes_per_pixel; + for (size_t pixel = 0; pixel < num_pixels; pixel++) { + std::span<const f32> old_components(&input[pixel * components_per_ir_rep], + components_per_ir_rep); + std::array<u32, total_words_per_pixel> words{}; + if constexpr (component_swizzle[0] != Swizzle::None) { + ConvertFromComponent<0>(words[bound_words[0]], + old_components[static_cast<size_t>(component_swizzle[0])]); + } + if constexpr (num_components >= 2) { + if constexpr (component_swizzle[1] != Swizzle::None) { + ConvertFromComponent<1>( + words[bound_words[1]], + old_components[static_cast<size_t>(component_swizzle[1])]); + } + } + if constexpr (num_components >= 3) { + if constexpr (component_swizzle[2] != Swizzle::None) { + ConvertFromComponent<2>( + words[bound_words[2]], + old_components[static_cast<size_t>(component_swizzle[2])]); + } + } + if constexpr (num_components >= 4) { + if constexpr (component_swizzle[3] != Swizzle::None) { + ConvertFromComponent<3>( + words[bound_words[3]], + old_components[static_cast<size_t>(component_swizzle[3])]); + } + } + std::memcpy(&output[pixel * total_bytes_per_pixel], words.data(), + total_bytes_per_pixel); + } + } + + ConverterImpl() = default; + ~ConverterImpl() override = default; +}; + +struct ConverterFactory::ConverterFactoryImpl { + std::unordered_map<RenderTargetFormat, std::unique_ptr<Converter>> converters_cache; +}; + +ConverterFactory::ConverterFactory() { + impl = std::make_unique<ConverterFactoryImpl>(); +} + +ConverterFactory::~ConverterFactory() = default; + +Converter* ConverterFactory::GetFormatConverter(RenderTargetFormat format) { + auto it = impl->converters_cache.find(format); + if (it == impl->converters_cache.end()) [[unlikely]] { + return BuildConverter(format); + } + return it->second.get(); +} + +class NullConverter : public Converter { +public: + void ConvertTo([[maybe_unused]] std::span<const u8> input, std::span<f32> output) override { + std::fill(output.begin(), output.end(), 0.0f); + } + void ConvertFrom([[maybe_unused]] std::span<const f32> input, std::span<u8> output) override { + const u8 fill_value = 0U; + std::fill(output.begin(), output.end(), fill_value); + } + NullConverter() = default; + ~NullConverter() = default; +}; + +Converter* ConverterFactory::BuildConverter(RenderTargetFormat format) { + switch (format) { + case RenderTargetFormat::R32G32B32A32_FLOAT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R32G32B32A32_FLOATTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R32G32B32A32_SINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R32G32B32A32_SINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R32G32B32A32_UINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R32G32B32A32_UINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R32G32B32X32_FLOAT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R32G32B32X32_FLOATTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R32G32B32X32_SINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R32G32B32X32_SINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R32G32B32X32_UINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R32G32B32X32_UINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R16G16B16A16_UNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R16G16B16A16_UNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R16G16B16A16_SNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R16G16B16A16_SNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R16G16B16A16_SINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R16G16B16A16_SINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R16G16B16A16_UINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R16G16B16A16_UINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R16G16B16A16_FLOAT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R16G16B16A16_FLOATTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R32G32_FLOAT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R32G32_FLOATTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R32G32_SINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R32G32_SINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R32G32_UINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R32G32_UINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R16G16B16X16_FLOAT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R16G16B16X16_FLOATTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::A8R8G8B8_UNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<A8R8G8B8_UNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::A8R8G8B8_SRGB: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<A8R8G8B8_SRGBTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::A2B10G10R10_UNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<A2B10G10R10_UNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::A2B10G10R10_UINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<A2B10G10R10_UINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::A2R10G10B10_UNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<A2R10G10B10_UNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::A8B8G8R8_UNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<A8B8G8R8_UNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::A8B8G8R8_SRGB: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<A8B8G8R8_SRGBTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::A8B8G8R8_SNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<A8B8G8R8_SNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::A8B8G8R8_SINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<A8B8G8R8_SINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::A8B8G8R8_UINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<A8B8G8R8_UINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R16G16_UNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R16G16_UNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R16G16_SNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R16G16_SNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R16G16_SINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R16G16_SINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R16G16_UINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R16G16_UINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R16G16_FLOAT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R16G16_FLOATTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::B10G11R11_FLOAT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<B10G11R11_FLOATTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R32_SINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R32_SINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R32_UINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R32_UINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R32_FLOAT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R32_FLOATTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::X8R8G8B8_UNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<X8R8G8B8_UNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::X8R8G8B8_SRGB: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<X8R8G8B8_SRGBTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R5G6B5_UNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R5G6B5_UNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::A1R5G5B5_UNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<A1R5G5B5_UNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R8G8_UNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R8G8_UNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R8G8_SNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R8G8_SNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R8G8_SINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R8G8_SINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R8G8_UINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R8G8_UINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R16_UNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R16_UNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R16_SNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R16_SNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R16_SINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R16_SINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R16_UINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R16_UINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R16_FLOAT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R16_FLOATTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R8_UNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R8_UNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R8_SNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R8_SNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R8_SINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R8_SINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::R8_UINT: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<R8_UINTTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::X1R5G5B5_UNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<X1R5G5B5_UNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::X8B8G8R8_UNORM: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<X8B8G8R8_UNORMTraits>>()) + .first->second.get(); + break; + case RenderTargetFormat::X8B8G8R8_SRGB: + return impl->converters_cache + .emplace(format, std::make_unique<ConverterImpl<X8B8G8R8_SRGBTraits>>()) + .first->second.get(); + break; + default: { + UNIMPLEMENTED_MSG("This format {} converter is not implemented", format); + return impl->converters_cache.emplace(format, std::make_unique<NullConverter>()) + .first->second.get(); + } + } +} + +} // namespace Tegra::Engines::Blitter diff --git a/src/video_core/engines/sw_blitter/converter.h b/src/video_core/engines/sw_blitter/converter.h new file mode 100644 index 000000000..f9bdc516e --- /dev/null +++ b/src/video_core/engines/sw_blitter/converter.h @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include <memory> +#include <span> + +#include "common/common_types.h" + +#include "video_core/gpu.h" + +namespace Tegra::Engines::Blitter { + +class Converter { +public: + virtual void ConvertTo(std::span<const u8> input, std::span<f32> output) = 0; + virtual void ConvertFrom(std::span<const f32> input, std::span<u8> output) = 0; + virtual ~Converter() = default; +}; + +class ConverterFactory { +public: + ConverterFactory(); + ~ConverterFactory(); + + Converter* GetFormatConverter(RenderTargetFormat format); + +private: + Converter* BuildConverter(RenderTargetFormat format); + + struct ConverterFactoryImpl; + std::unique_ptr<ConverterFactoryImpl> impl; +}; + +} // namespace Tegra::Engines::Blitter diff --git a/src/video_core/engines/sw_blitter/generate_converters.py b/src/video_core/engines/sw_blitter/generate_converters.py new file mode 100644 index 000000000..f641564f7 --- /dev/null +++ b/src/video_core/engines/sw_blitter/generate_converters.py @@ -0,0 +1,136 @@ +# SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project +# SPDX-License-Identifier: GPL-3.0-or-later + +import re + +class Format: + def __init__(self, string_value): + self.name = string_value + tmp = string_value.split('_') + self.component_type = tmp[1] + component_data = re.findall(r"\w\d+", tmp[0]) + self.num_components = len(component_data) + sizes = [] + swizzle = [] + for data in component_data: + swizzle.append(data[0]) + sizes.append(int(data[1:])) + self.sizes = sizes + self.swizzle = swizzle + + def build_component_type_array(self): + result = "{ " + b = False + for i in range(0, self.num_components): + if b: + result += ", " + b = True + result += "ComponentType::" + self.component_type + result += " }" + return result + + def build_component_sizes_array(self): + result = "{ " + b = False + for i in range(0, self.num_components): + if b: + result += ", " + b = True + result += str(self.sizes[i]) + result += " }" + return result + + def build_component_swizzle_array(self): + result = "{ " + b = False + for i in range(0, self.num_components): + if b: + result += ", " + b = True + swizzle = self.swizzle[i] + if swizzle == "X": + swizzle = "None" + result += "Swizzle::" + swizzle + result += " }" + return result + + def print_declaration(self): + print("struct " + self.name + "Traits {") + print(" static constexpr size_t num_components = " + str(self.num_components) + ";") + print(" static constexpr std::array<ComponentType, num_components> component_types = " + self.build_component_type_array() + ";") + print(" static constexpr std::array<size_t, num_components> component_sizes = " + self.build_component_sizes_array() + ";") + print(" static constexpr std::array<Swizzle, num_components> component_swizzle = " + self.build_component_swizzle_array() + ";") + print("};\n") + + def print_case(self): + print("case RenderTargetFormat::" + self.name + ":") + print(" return impl->converters_cache") + print(" .emplace(format, std::make_unique<ConverterImpl<" + self.name + "Traits>>())") + print(" .first->second.get();") + print(" break;") + +txt = """ +R32G32B32A32_FLOAT +R32G32B32A32_SINT +R32G32B32A32_UINT +R32G32B32X32_FLOAT +R32G32B32X32_SINT +R32G32B32X32_UINT +R16G16B16A16_UNORM +R16G16B16A16_SNORM +R16G16B16A16_SINT +R16G16B16A16_UINT +R16G16B16A16_FLOAT +R32G32_FLOAT +R32G32_SINT +R32G32_UINT +R16G16B16X16_FLOAT +A8R8G8B8_UNORM +A8R8G8B8_SRGB +A2B10G10R10_UNORM +A2B10G10R10_UINT +A2R10G10B10_UNORM +A8B8G8R8_UNORM +A8B8G8R8_SRGB +A8B8G8R8_SNORM +A8B8G8R8_SINT +A8B8G8R8_UINT +R16G16_UNORM +R16G16_SNORM +R16G16_SINT +R16G16_UINT +R16G16_FLOAT +B10G11R11_FLOAT +R32_SINT +R32_UINT +R32_FLOAT +X8R8G8B8_UNORM +X8R8G8B8_SRGB +R5G6B5_UNORM +A1R5G5B5_UNORM +R8G8_UNORM +R8G8_SNORM +R8G8_SINT +R8G8_UINT +R16_UNORM +R16_SNORM +R16_SINT +R16_UINT +R16_FLOAT +R8_UNORM +R8_SNORM +R8_SINT +R8_UINT +X1R5G5B5_UNORM +X8B8G8R8_UNORM +X8B8G8R8_SRGB +""" + +x = txt.split() +y = list(map(lambda a: Format(a), x)) +formats = list(y) +for format in formats: + format.print_declaration() + +for format in formats: + format.print_case() diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h index d0709dc69..8a871593a 100644 --- a/src/video_core/gpu.h +++ b/src/video_core/gpu.h @@ -27,12 +27,12 @@ struct CommandList; // TODO: Implement the commented ones enum class RenderTargetFormat : u32 { NONE = 0x0, - R32B32G32A32_FLOAT = 0xC0, + R32G32B32A32_FLOAT = 0xC0, R32G32B32A32_SINT = 0xC1, R32G32B32A32_UINT = 0xC2, - // R32G32B32X32_FLOAT = 0xC3, - // R32G32B32X32_SINT = 0xC4, - // R32G32B32X32_UINT = 0xC5, + R32G32B32X32_FLOAT = 0xC3, + R32G32B32X32_SINT = 0xC4, + R32G32B32X32_UINT = 0xC5, R16G16B16A16_UNORM = 0xC6, R16G16B16A16_SNORM = 0xC7, R16G16B16A16_SINT = 0xC8, @@ -56,13 +56,13 @@ enum class RenderTargetFormat : u32 { R16G16_SINT = 0xDC, R16G16_UINT = 0xDD, R16G16_FLOAT = 0xDE, - // A2R10G10B10_UNORM = 0xDF, + A2R10G10B10_UNORM = 0xDF, B10G11R11_FLOAT = 0xE0, R32_SINT = 0xE3, R32_UINT = 0xE4, R32_FLOAT = 0xE5, - // X8R8G8B8_UNORM = 0xE6, - // X8R8G8B8_SRGB = 0xE7, + X8R8G8B8_UNORM = 0xE6, + X8R8G8B8_SRGB = 0xE7, R5G6B5_UNORM = 0xE8, A1R5G5B5_UNORM = 0xE9, R8G8_UNORM = 0xEA, @@ -79,11 +79,11 @@ enum class RenderTargetFormat : u32 { R8_SINT = 0xF5, R8_UINT = 0xF6, - /* - A8_UNORM = 0xF7, + // A8_UNORM = 0xF7, X1R5G5B5_UNORM = 0xF8, X8B8G8R8_UNORM = 0xF9, X8B8G8R8_SRGB = 0xFA, + /* Z1R5G5B5_UNORM = 0xFB, O1R5G5B5_UNORM = 0xFC, Z8R8G8B8_UNORM = 0xFD, diff --git a/src/video_core/host1x/syncpoint_manager.cpp b/src/video_core/host1x/syncpoint_manager.cpp index a44fc83d3..8f23ce527 100644 --- a/src/video_core/host1x/syncpoint_manager.cpp +++ b/src/video_core/host1x/syncpoint_manager.cpp @@ -34,7 +34,7 @@ SyncpointManager::ActionHandle SyncpointManager::RegisterAction( } void SyncpointManager::DeregisterAction(std::list<RegisteredAction>& action_storage, - ActionHandle& handle) { + const ActionHandle& handle) { std::unique_lock lk(guard); // We want to ensure the iterator still exists prior to erasing it @@ -49,11 +49,11 @@ void SyncpointManager::DeregisterAction(std::list<RegisteredAction>& action_stor } } -void SyncpointManager::DeregisterGuestAction(u32 syncpoint_id, ActionHandle& handle) { +void SyncpointManager::DeregisterGuestAction(u32 syncpoint_id, const ActionHandle& handle) { DeregisterAction(guest_action_storage[syncpoint_id], handle); } -void SyncpointManager::DeregisterHostAction(u32 syncpoint_id, ActionHandle& handle) { +void SyncpointManager::DeregisterHostAction(u32 syncpoint_id, const ActionHandle& handle) { DeregisterAction(host_action_storage[syncpoint_id], handle); } diff --git a/src/video_core/host1x/syncpoint_manager.h b/src/video_core/host1x/syncpoint_manager.h index 50a264e23..847ed20c8 100644 --- a/src/video_core/host1x/syncpoint_manager.h +++ b/src/video_core/host1x/syncpoint_manager.h @@ -36,21 +36,19 @@ public: template <typename Func> ActionHandle RegisterGuestAction(u32 syncpoint_id, u32 expected_value, Func&& action) { - std::function<void()> func(action); return RegisterAction(syncpoints_guest[syncpoint_id], guest_action_storage[syncpoint_id], - expected_value, std::move(func)); + expected_value, std::move(action)); } template <typename Func> ActionHandle RegisterHostAction(u32 syncpoint_id, u32 expected_value, Func&& action) { - std::function<void()> func(action); return RegisterAction(syncpoints_host[syncpoint_id], host_action_storage[syncpoint_id], - expected_value, std::move(func)); + expected_value, std::move(action)); } - void DeregisterGuestAction(u32 syncpoint_id, ActionHandle& handle); + void DeregisterGuestAction(u32 syncpoint_id, const ActionHandle& handle); - void DeregisterHostAction(u32 syncpoint_id, ActionHandle& handle); + void DeregisterHostAction(u32 syncpoint_id, const ActionHandle& handle); void IncrementGuest(u32 syncpoint_id); @@ -76,7 +74,7 @@ private: std::list<RegisteredAction>& action_storage, u32 expected_value, std::function<void()>&& action); - void DeregisterAction(std::list<RegisteredAction>& action_storage, ActionHandle& handle); + void DeregisterAction(std::list<RegisteredAction>& action_storage, const ActionHandle& handle); void Wait(std::atomic<u32>& syncpoint, std::condition_variable& wait_cv, u32 expected_value); diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 354c6e429..f71a316b6 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -466,8 +466,7 @@ bool RasterizerOpenGL::AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Surf const Tegra::Engines::Fermi2D::Config& copy_config) { MICROPROFILE_SCOPE(OpenGL_Blits); std::scoped_lock lock{texture_cache.mutex}; - texture_cache.BlitImage(dst, src, copy_config); - return true; + return texture_cache.BlitImage(dst, src, copy_config); } Tegra::Engines::AccelerateDMAInterface& RasterizerOpenGL::AccessAccelerateDMA() { diff --git a/src/video_core/renderer_opengl/maxwell_to_gl.h b/src/video_core/renderer_opengl/maxwell_to_gl.h index e14f9b2db..ef1190e1f 100644 --- a/src/video_core/renderer_opengl/maxwell_to_gl.h +++ b/src/video_core/renderer_opengl/maxwell_to_gl.h @@ -28,6 +28,7 @@ constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> FORMAT_TAB {GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}, // A1R5G5B5_UNORM {GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV}, // A2B10G10R10_UNORM {GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV}, // A2B10G10R10_UINT + {GL_RGB10_A2, GL_BGRA, GL_UNSIGNED_INT_2_10_10_10_REV}, // A2R10G10B10_UNORM {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV}, // A1B5G5R5_UNORM {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1}, // A5B5G5R1_UNORM {GL_R8, GL_RED, GL_UNSIGNED_BYTE}, // R8_UNORM diff --git a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp index 5c156087b..430a84272 100644 --- a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp +++ b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp @@ -125,6 +125,7 @@ struct FormatTuple { {VK_FORMAT_A1R5G5B5_UNORM_PACK16, Attachable}, // A1R5G5B5_UNORM {VK_FORMAT_A2B10G10R10_UNORM_PACK32, Attachable | Storage}, // A2B10G10R10_UNORM {VK_FORMAT_A2B10G10R10_UINT_PACK32, Attachable | Storage}, // A2B10G10R10_UINT + {VK_FORMAT_A2R10G10B10_UNORM_PACK32, Attachable | Storage}, // A2R10G10B10_UNORM {VK_FORMAT_A1R5G5B5_UNORM_PACK16, Attachable}, // A1B5G5R5_UNORM (flipped with swizzle) {VK_FORMAT_R5G5B5A1_UNORM_PACK16}, // A5B5G5R1_UNORM (specially swizzled) {VK_FORMAT_R8_UNORM, Attachable | Storage}, // R8_UNORM @@ -149,7 +150,7 @@ struct FormatTuple { {VK_FORMAT_BC6H_UFLOAT_BLOCK}, // BC6H_UFLOAT {VK_FORMAT_BC6H_SFLOAT_BLOCK}, // BC6H_SFLOAT {VK_FORMAT_ASTC_4x4_UNORM_BLOCK}, // ASTC_2D_4X4_UNORM - {VK_FORMAT_B8G8R8A8_UNORM, Attachable}, // B8G8R8A8_UNORM + {VK_FORMAT_B8G8R8A8_UNORM, Attachable | Storage}, // B8G8R8A8_UNORM {VK_FORMAT_R32G32B32A32_SFLOAT, Attachable | Storage}, // R32G32B32A32_FLOAT {VK_FORMAT_R32G32B32A32_SINT, Attachable | Storage}, // R32G32B32A32_SINT {VK_FORMAT_R32G32_SFLOAT, Attachable | Storage}, // R32G32_FLOAT @@ -159,7 +160,7 @@ struct FormatTuple { {VK_FORMAT_R16_UNORM, Attachable | Storage}, // R16_UNORM {VK_FORMAT_R16_SNORM, Attachable | Storage}, // R16_SNORM {VK_FORMAT_R16_UINT, Attachable | Storage}, // R16_UINT - {VK_FORMAT_UNDEFINED}, // R16_SINT + {VK_FORMAT_R16_SINT, Attachable | Storage}, // R16_SINT {VK_FORMAT_R16G16_UNORM, Attachable | Storage}, // R16G16_UNORM {VK_FORMAT_R16G16_SFLOAT, Attachable | Storage}, // R16G16_FLOAT {VK_FORMAT_R16G16_UINT, Attachable | Storage}, // R16G16_UINT @@ -183,7 +184,7 @@ struct FormatTuple { {VK_FORMAT_BC2_SRGB_BLOCK}, // BC2_SRGB {VK_FORMAT_BC3_SRGB_BLOCK}, // BC3_SRGB {VK_FORMAT_BC7_SRGB_BLOCK}, // BC7_SRGB - {VK_FORMAT_R4G4B4A4_UNORM_PACK16, Attachable}, // A4B4G4R4_UNORM + {VK_FORMAT_R4G4B4A4_UNORM_PACK16}, // A4B4G4R4_UNORM {VK_FORMAT_R4G4_UNORM_PACK8}, // G4R4_UNORM {VK_FORMAT_ASTC_4x4_SRGB_BLOCK}, // ASTC_2D_4X4_SRGB {VK_FORMAT_ASTC_8x8_SRGB_BLOCK}, // ASTC_2D_8X8_SRGB diff --git a/src/video_core/renderer_vulkan/vk_fsr.cpp b/src/video_core/renderer_vulkan/vk_fsr.cpp index dd450169e..33daa8c1c 100644 --- a/src/video_core/renderer_vulkan/vk_fsr.cpp +++ b/src/video_core/renderer_vulkan/vk_fsr.cpp @@ -5,6 +5,7 @@ #include "common/bit_cast.h" #include "common/common_types.h" #include "common/div_ceil.h" +#include "common/settings.h" #include "video_core/host_shaders/vulkan_fidelityfx_fsr_easu_fp16_comp_spv.h" #include "video_core/host_shaders/vulkan_fidelityfx_fsr_easu_fp32_comp_spv.h" @@ -227,7 +228,10 @@ VkImageView FSR::Draw(Scheduler& scheduler, size_t image_index, VkImageView imag cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_COMPUTE, *rcas_pipeline); - FsrRcasCon(push_constants.data(), 0.25f); + const float sharpening = + static_cast<float>(Settings::values.fsr_sharpening_slider.GetValue()) / 100.0f; + + FsrRcasCon(push_constants.data(), sharpening); cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT, push_constants); { diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 12b13cc59..d8ad8815c 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -542,8 +542,7 @@ bool RasterizerVulkan::AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Surf const Tegra::Engines::Fermi2D::Surface& dst, const Tegra::Engines::Fermi2D::Config& copy_config) { std::scoped_lock lock{texture_cache.mutex}; - texture_cache.BlitImage(dst, src, copy_config); - return true; + return texture_cache.BlitImage(dst, src, copy_config); } Tegra::Engines::AccelerateDMAInterface& RasterizerVulkan::AccessAccelerateDMA() { diff --git a/src/video_core/surface.cpp b/src/video_core/surface.cpp index 6bd133d10..1a76d4178 100644 --- a/src/video_core/surface.cpp +++ b/src/video_core/surface.cpp @@ -93,11 +93,14 @@ PixelFormat PixelFormatFromDepthFormat(Tegra::DepthFormat format) { PixelFormat PixelFormatFromRenderTargetFormat(Tegra::RenderTargetFormat format) { switch (format) { - case Tegra::RenderTargetFormat::R32B32G32A32_FLOAT: + case Tegra::RenderTargetFormat::R32G32B32A32_FLOAT: + case Tegra::RenderTargetFormat::R32G32B32X32_FLOAT: return PixelFormat::R32G32B32A32_FLOAT; case Tegra::RenderTargetFormat::R32G32B32A32_SINT: + case Tegra::RenderTargetFormat::R32G32B32X32_SINT: return PixelFormat::R32G32B32A32_SINT; case Tegra::RenderTargetFormat::R32G32B32A32_UINT: + case Tegra::RenderTargetFormat::R32G32B32X32_UINT: return PixelFormat::R32G32B32A32_UINT; case Tegra::RenderTargetFormat::R16G16B16A16_UNORM: return PixelFormat::R16G16B16A16_UNORM; @@ -118,16 +121,22 @@ PixelFormat PixelFormatFromRenderTargetFormat(Tegra::RenderTargetFormat format) case Tegra::RenderTargetFormat::R16G16B16X16_FLOAT: return PixelFormat::R16G16B16X16_FLOAT; case Tegra::RenderTargetFormat::A8R8G8B8_UNORM: + case Tegra::RenderTargetFormat::X8R8G8B8_UNORM: return PixelFormat::B8G8R8A8_UNORM; case Tegra::RenderTargetFormat::A8R8G8B8_SRGB: + case Tegra::RenderTargetFormat::X8R8G8B8_SRGB: return PixelFormat::B8G8R8A8_SRGB; case Tegra::RenderTargetFormat::A2B10G10R10_UNORM: return PixelFormat::A2B10G10R10_UNORM; case Tegra::RenderTargetFormat::A2B10G10R10_UINT: return PixelFormat::A2B10G10R10_UINT; + case Tegra::RenderTargetFormat::A2R10G10B10_UNORM: + return PixelFormat::A2R10G10B10_UNORM; case Tegra::RenderTargetFormat::A8B8G8R8_UNORM: + case Tegra::RenderTargetFormat::X8B8G8R8_UNORM: return PixelFormat::A8B8G8R8_UNORM; case Tegra::RenderTargetFormat::A8B8G8R8_SRGB: + case Tegra::RenderTargetFormat::X8B8G8R8_SRGB: return PixelFormat::A8B8G8R8_SRGB; case Tegra::RenderTargetFormat::A8B8G8R8_SNORM: return PixelFormat::A8B8G8R8_SNORM; @@ -156,6 +165,7 @@ PixelFormat PixelFormatFromRenderTargetFormat(Tegra::RenderTargetFormat format) case Tegra::RenderTargetFormat::R5G6B5_UNORM: return PixelFormat::R5G6B5_UNORM; case Tegra::RenderTargetFormat::A1R5G5B5_UNORM: + case Tegra::RenderTargetFormat::X1R5G5B5_UNORM: return PixelFormat::A1R5G5B5_UNORM; case Tegra::RenderTargetFormat::R8G8_UNORM: return PixelFormat::R8G8_UNORM; @@ -204,23 +214,16 @@ PixelFormat PixelFormatFromGPUPixelFormat(Service::android::PixelFormat format) } SurfaceType GetFormatType(PixelFormat pixel_format) { - if (static_cast<std::size_t>(pixel_format) < - static_cast<std::size_t>(PixelFormat::MaxColorFormat)) { + if (pixel_format < PixelFormat::MaxColorFormat) { return SurfaceType::ColorTexture; } - - if (static_cast<std::size_t>(pixel_format) < - static_cast<std::size_t>(PixelFormat::MaxDepthFormat)) { + if (pixel_format < PixelFormat::MaxDepthFormat) { return SurfaceType::Depth; } - - if (static_cast<std::size_t>(pixel_format) < - static_cast<std::size_t>(PixelFormat::MaxStencilFormat)) { + if (pixel_format < PixelFormat::MaxStencilFormat) { return SurfaceType::Stencil; } - - if (static_cast<std::size_t>(pixel_format) < - static_cast<std::size_t>(PixelFormat::MaxDepthStencilFormat)) { + if (pixel_format < PixelFormat::MaxDepthStencilFormat) { return SurfaceType::DepthStencil; } diff --git a/src/video_core/surface.h b/src/video_core/surface.h index 57ca7f597..44b79af20 100644 --- a/src/video_core/surface.h +++ b/src/video_core/surface.h @@ -23,6 +23,7 @@ enum class PixelFormat { A1R5G5B5_UNORM, A2B10G10R10_UNORM, A2B10G10R10_UINT, + A2R10G10B10_UNORM, A1B5G5R5_UNORM, A5B5G5R1_UNORM, R8_UNORM, @@ -159,6 +160,7 @@ constexpr std::array<u8, MaxPixelFormat> BLOCK_WIDTH_TABLE = {{ 1, // A1R5G5B5_UNORM 1, // A2B10G10R10_UNORM 1, // A2B10G10R10_UINT + 1, // A2R10G10B10_UNORM 1, // A1B5G5R5_UNORM 1, // A5B5G5R1_UNORM 1, // R8_UNORM @@ -264,6 +266,7 @@ constexpr std::array<u8, MaxPixelFormat> BLOCK_HEIGHT_TABLE = {{ 1, // A1R5G5B5_UNORM 1, // A2B10G10R10_UNORM 1, // A2B10G10R10_UINT + 1, // A2R10G10B10_UNORM 1, // A1B5G5R5_UNORM 1, // A5B5G5R1_UNORM 1, // R8_UNORM @@ -369,6 +372,7 @@ constexpr std::array<u8, MaxPixelFormat> BITS_PER_BLOCK_TABLE = {{ 16, // A1R5G5B5_UNORM 32, // A2B10G10R10_UNORM 32, // A2B10G10R10_UINT + 32, // A2R10G10B10_UNORM 16, // A1B5G5R5_UNORM 16, // A5B5G5R1_UNORM 8, // R8_UNORM diff --git a/src/video_core/texture_cache/formatter.h b/src/video_core/texture_cache/formatter.h index acc854715..f1f0a057b 100644 --- a/src/video_core/texture_cache/formatter.h +++ b/src/video_core/texture_cache/formatter.h @@ -35,6 +35,8 @@ struct fmt::formatter<VideoCore::Surface::PixelFormat> : fmt::formatter<fmt::str return "A2B10G10R10_UNORM"; case PixelFormat::A2B10G10R10_UINT: return "A2B10G10R10_UINT"; + case PixelFormat::A2R10G10B10_UNORM: + return "A2R10G10B10_UNORM"; case PixelFormat::A1B5G5R5_UNORM: return "A1B5G5R5_UNORM"; case PixelFormat::A5B5G5R1_UNORM: diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 8ef75fe73..8e68a2e53 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h @@ -506,10 +506,14 @@ void TextureCache<P>::UnmapGPUMemory(size_t as_id, GPUVAddr gpu_addr, size_t siz } template <class P> -void TextureCache<P>::BlitImage(const Tegra::Engines::Fermi2D::Surface& dst, +bool TextureCache<P>::BlitImage(const Tegra::Engines::Fermi2D::Surface& dst, const Tegra::Engines::Fermi2D::Surface& src, const Tegra::Engines::Fermi2D::Config& copy) { - const BlitImages images = GetBlitImages(dst, src, copy); + const auto result = GetBlitImages(dst, src, copy); + if (!result) { + return false; + } + const BlitImages images = *result; const ImageId dst_id = images.dst_id; const ImageId src_id = images.src_id; @@ -596,6 +600,7 @@ void TextureCache<P>::BlitImage(const Tegra::Engines::Fermi2D::Surface& dst, runtime.BlitImage(dst_framebuffer, dst_view, src_view, dst_region, src_region, copy.filter, copy.operation); } + return true; } template <class P> @@ -1133,7 +1138,7 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA } template <class P> -typename TextureCache<P>::BlitImages TextureCache<P>::GetBlitImages( +std::optional<typename TextureCache<P>::BlitImages> TextureCache<P>::GetBlitImages( const Tegra::Engines::Fermi2D::Surface& dst, const Tegra::Engines::Fermi2D::Surface& src, const Tegra::Engines::Fermi2D::Config& copy) { @@ -1154,6 +1159,20 @@ typename TextureCache<P>::BlitImages TextureCache<P>::GetBlitImages( has_deleted_images = false; src_id = FindImage(src_info, src_addr, try_options); dst_id = FindImage(dst_info, dst_addr, try_options); + if (!copy.must_accelerate) { + do { + if (!src_id && !dst_id) { + return std::nullopt; + } + if (src_id && True(slot_images[src_id].flags & ImageFlagBits::GpuModified)) { + break; + } + if (dst_id && True(slot_images[dst_id].flags & ImageFlagBits::GpuModified)) { + break; + } + return std::nullopt; + } while (false); + } const ImageBase* const src_image = src_id ? &slot_images[src_id] : nullptr; if (src_image && src_image->info.num_samples > 1) { RelaxedOptions find_options{FIND_OPTIONS | RelaxedOptions::ForceBrokenViews}; @@ -1194,12 +1213,12 @@ typename TextureCache<P>::BlitImages TextureCache<P>::GetBlitImages( dst_id = FindOrInsertImage(dst_info, dst_addr, RelaxedOptions{}); } while (has_deleted_images); } - return BlitImages{ + return {BlitImages{ .dst_id = dst_id, .src_id = src_id, .dst_format = dst_info.format, .src_format = src_info.format, - }; + }}; } template <class P> diff --git a/src/video_core/texture_cache/texture_cache_base.h b/src/video_core/texture_cache/texture_cache_base.h index 2fa8445eb..9db7195bf 100644 --- a/src/video_core/texture_cache/texture_cache_base.h +++ b/src/video_core/texture_cache/texture_cache_base.h @@ -174,7 +174,7 @@ public: void UnmapGPUMemory(size_t as_id, GPUVAddr gpu_addr, size_t size); /// Blit an image with the given parameters - void BlitImage(const Tegra::Engines::Fermi2D::Surface& dst, + bool BlitImage(const Tegra::Engines::Fermi2D::Surface& dst, const Tegra::Engines::Fermi2D::Surface& src, const Tegra::Engines::Fermi2D::Config& copy); @@ -285,9 +285,9 @@ private: [[nodiscard]] ImageId JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VAddr cpu_addr); /// Return a blit image pair from the given guest blit parameters - [[nodiscard]] BlitImages GetBlitImages(const Tegra::Engines::Fermi2D::Surface& dst, - const Tegra::Engines::Fermi2D::Surface& src, - const Tegra::Engines::Fermi2D::Config& copy); + [[nodiscard]] std::optional<BlitImages> GetBlitImages( + const Tegra::Engines::Fermi2D::Surface& dst, const Tegra::Engines::Fermi2D::Surface& src, + const Tegra::Engines::Fermi2D::Config& copy); /// Find or create a sampler from a guest descriptor sampler [[nodiscard]] SamplerId FindSampler(const TSCEntry& config); diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index adad36221..0aa109dd3 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -295,7 +295,7 @@ if (APPLE) set_target_properties(yuzu PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist) elseif(WIN32) # compile as a win32 gui application instead of a console application - if (QT_VERSION VERSION_GREATER 6) + if (QT_VERSION VERSION_GREATER_EQUAL 6) target_link_libraries(yuzu PRIVATE Qt6::EntryPointPrivate) else() target_link_libraries(yuzu PRIVATE Qt5::WinMain) @@ -311,15 +311,15 @@ endif() create_target_directory_groups(yuzu) target_link_libraries(yuzu PRIVATE common core input_common network video_core) -target_link_libraries(yuzu PRIVATE Boost::boost glad Qt::Widgets Qt::Multimedia) +target_link_libraries(yuzu PRIVATE Boost::boost glad Qt${QT_MAJOR_VERSION}::Widgets) target_link_libraries(yuzu PRIVATE ${PLATFORM_LIBRARIES} Threads::Threads) target_include_directories(yuzu PRIVATE ../../externals/Vulkan-Headers/include) if (NOT WIN32) - target_include_directories(yuzu PRIVATE ${Qt5Gui_PRIVATE_INCLUDE_DIRS}) + target_include_directories(yuzu PRIVATE ${Qt${QT_MAJOR_VERSION}Gui_PRIVATE_INCLUDE_DIRS}) endif() if (UNIX AND NOT APPLE) - target_link_libraries(yuzu PRIVATE Qt::DBus) + target_link_libraries(yuzu PRIVATE Qt${QT_MAJOR_VERSION}::DBus) endif() target_compile_definitions(yuzu PRIVATE @@ -358,8 +358,13 @@ if (ENABLE_WEB_SERVICE) target_compile_definitions(yuzu PRIVATE -DENABLE_WEB_SERVICE) endif() +if (YUZU_USE_QT_MULTIMEDIA) + target_link_libraries(yuzu PRIVATE Qt${QT_MAJOR_VERSION}::Multimedia) + target_compile_definitions(yuzu PRIVATE -DYUZU_USE_QT_MULTIMEDIA) +endif () + if (YUZU_USE_QT_WEB_ENGINE) - target_link_libraries(yuzu PRIVATE Qt::WebEngineCore Qt::WebEngineWidgets) + target_link_libraries(yuzu PRIVATE Qt${QT_MAJOR_VERSION}::WebEngineCore Qt${QT_MAJOR_VERSION}::WebEngineWidgets) target_compile_definitions(yuzu PRIVATE -DYUZU_USE_QT_WEB_ENGINE) endif () @@ -367,7 +372,16 @@ if(UNIX AND NOT APPLE) install(TARGETS yuzu) endif() -if (YUZU_USE_BUNDLED_QT) +if (WIN32 AND QT_VERSION VERSION_GREATER_EQUAL 6) + if (MSVC AND NOT ${CMAKE_GENERATOR} STREQUAL "Ninja") + set(YUZU_EXE_DIR "${CMAKE_BINARY_DIR}/bin/$<CONFIG>") + else() + set(YUZU_EXE_DIR "${CMAKE_BINARY_DIR}/bin") + endif() + add_custom_command(TARGET yuzu POST_BUILD COMMAND ${WINDEPLOYQT_EXECUTABLE} "${YUZU_EXE_DIR}/yuzu.exe" --dir "${YUZU_EXE_DIR}" --libdir "${YUZU_EXE_DIR}" --plugindir "${YUZU_EXE_DIR}/plugins" --no-compiler-runtime --no-opengl-sw --no-system-d3d-compiler --no-translations --verbose 0) +endif() + +if (YUZU_USE_BUNDLED_QT AND QT_VERSION VERSION_LESS 6) include(CopyYuzuQt5Deps) copy_yuzu_Qt5_deps(yuzu) endif() diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index d88efacd7..c934069dd 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp @@ -4,8 +4,10 @@ #include <glad/glad.h> #include <QApplication> +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA #include <QCameraImageCapture> #include <QCameraInfo> +#endif #include <QHBoxLayout> #include <QMessageBox> #include <QPainter> @@ -707,6 +709,7 @@ void GRenderWindow::TouchEndEvent() { } void GRenderWindow::InitializeCamera() { +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA constexpr auto camera_update_ms = std::chrono::milliseconds{50}; // (50ms, 20Hz) if (!Settings::values.enable_ir_sensor) { return; @@ -760,18 +763,22 @@ void GRenderWindow::InitializeCamera() { connect(camera_timer.get(), &QTimer::timeout, [this] { RequestCameraCapture(); }); // This timer should be dependent of camera resolution 5ms for every 100 pixels camera_timer->start(camera_update_ms); +#endif } void GRenderWindow::FinalizeCamera() { +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA if (camera_timer) { camera_timer->stop(); } if (camera) { camera->unload(); } +#endif } void GRenderWindow::RequestCameraCapture() { +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA if (!Settings::values.enable_ir_sensor) { return; } @@ -788,6 +795,7 @@ void GRenderWindow::RequestCameraCapture() { pending_camera_snapshots++; camera_capture->capture(); +#endif } void GRenderWindow::OnCameraCapture(int requestId, const QImage& img) { diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h index c45ebf1a2..4a01481cd 100644 --- a/src/yuzu/bootmanager.h +++ b/src/yuzu/bootmanager.h @@ -241,8 +241,10 @@ private: bool is_virtual_camera; int pending_camera_snapshots; +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA std::unique_ptr<QCamera> camera; std::unique_ptr<QCameraImageCapture> camera_capture; +#endif std::unique_ptr<QTimer> camera_timer; Core::System& system; diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 343f3b8e5..0c93df428 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -672,6 +672,7 @@ void Config::ReadRendererValues() { ReadGlobalSetting(Settings::values.aspect_ratio); ReadGlobalSetting(Settings::values.resolution_setup); ReadGlobalSetting(Settings::values.scaling_filter); + ReadGlobalSetting(Settings::values.fsr_sharpening_slider); ReadGlobalSetting(Settings::values.anti_aliasing); ReadGlobalSetting(Settings::values.max_anisotropy); ReadGlobalSetting(Settings::values.use_speed_limit); @@ -1282,6 +1283,10 @@ void Config::SaveRendererValues() { static_cast<u32>(Settings::values.scaling_filter.GetValue(global)), static_cast<u32>(Settings::values.scaling_filter.GetDefault()), Settings::values.scaling_filter.UsingGlobal()); + WriteSetting(QString::fromStdString(Settings::values.fsr_sharpening_slider.GetLabel()), + static_cast<u32>(Settings::values.fsr_sharpening_slider.GetValue(global)), + static_cast<u32>(Settings::values.fsr_sharpening_slider.GetDefault()), + Settings::values.fsr_sharpening_slider.UsingGlobal()); WriteSetting(QString::fromStdString(Settings::values.anti_aliasing.GetLabel()), static_cast<u32>(Settings::values.anti_aliasing.GetValue(global)), static_cast<u32>(Settings::values.anti_aliasing.GetDefault()), diff --git a/src/yuzu/configuration/configure_camera.cpp b/src/yuzu/configuration/configure_camera.cpp index 2a61de2a1..d95e96696 100644 --- a/src/yuzu/configuration/configure_camera.cpp +++ b/src/yuzu/configuration/configure_camera.cpp @@ -2,8 +2,11 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include <memory> +#include <QtCore> +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA #include <QCameraImageCapture> #include <QCameraInfo> +#endif #include <QStandardItemModel> #include <QTimer> @@ -33,6 +36,7 @@ ConfigureCamera::ConfigureCamera(QWidget* parent, InputCommon::InputSubsystem* i ConfigureCamera::~ConfigureCamera() = default; void ConfigureCamera::PreviewCamera() { +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA const auto index = ui->ir_sensor_combo_box->currentIndex(); bool camera_found = false; const QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); @@ -101,6 +105,7 @@ void ConfigureCamera::PreviewCamera() { }); camera_timer->start(250); +#endif } void ConfigureCamera::DisplayCapturedFrame(int requestId, const QImage& img) { @@ -133,11 +138,13 @@ void ConfigureCamera::LoadConfiguration() { ui->ir_sensor_combo_box->clear(); input_devices.push_back("Auto"); ui->ir_sensor_combo_box->addItem(tr("Auto")); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA const auto cameras = QCameraInfo::availableCameras(); for (const QCameraInfo& cameraInfo : cameras) { input_devices.push_back(cameraInfo.deviceName().toStdString()); ui->ir_sensor_combo_box->addItem(cameraInfo.description()); } +#endif const auto current_device = Settings::values.ir_sensor_device.GetValue(); diff --git a/src/yuzu/configuration/configure_camera.h b/src/yuzu/configuration/configure_camera.h index db9833b5c..9a90512b3 100644 --- a/src/yuzu/configuration/configure_camera.h +++ b/src/yuzu/configuration/configure_camera.h @@ -46,8 +46,10 @@ private: bool is_virtual_camera; int pending_snapshots; +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA std::unique_ptr<QCamera> camera; std::unique_ptr<QCameraImageCapture> camera_capture; +#endif std::unique_ptr<QTimer> camera_timer; std::vector<std::string> input_devices; std::unique_ptr<Ui::ConfigureCamera> ui; diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index bd69d04a6..f1385e972 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp @@ -63,6 +63,11 @@ ConfigureGraphics::ConfigureGraphics(const Core::System& system_, QWidget* paren ui->api_widget->isEnabled()); ui->bg_label->setVisible(Settings::IsConfiguringGlobal()); ui->bg_combobox->setVisible(!Settings::IsConfiguringGlobal()); + + connect(ui->fsr_sharpening_slider, &QSlider::valueChanged, this, + &ConfigureGraphics::SetFSRIndicatorText); + ui->fsr_sharpening_combobox->setVisible(!Settings::IsConfiguringGlobal()); + ui->fsr_sharpening_label->setVisible(Settings::IsConfiguringGlobal()); } void ConfigureGraphics::UpdateDeviceSelection(int device) { @@ -110,6 +115,7 @@ void ConfigureGraphics::SetConfiguration() { static_cast<int>(Settings::values.resolution_setup.GetValue())); ui->scaling_filter_combobox->setCurrentIndex( static_cast<int>(Settings::values.scaling_filter.GetValue())); + ui->fsr_sharpening_slider->setValue(Settings::values.fsr_sharpening_slider.GetValue()); ui->anti_aliasing_combobox->setCurrentIndex( static_cast<int>(Settings::values.anti_aliasing.GetValue())); } else { @@ -147,6 +153,15 @@ void ConfigureGraphics::SetConfiguration() { ConfigurationShared::SetHighlight(ui->anti_aliasing_label, !Settings::values.anti_aliasing.UsingGlobal()); + ui->fsr_sharpening_combobox->setCurrentIndex( + Settings::values.fsr_sharpening_slider.UsingGlobal() ? 0 : 1); + ui->fsr_sharpening_slider->setEnabled( + !Settings::values.fsr_sharpening_slider.UsingGlobal()); + ui->fsr_sharpening_value->setEnabled(!Settings::values.fsr_sharpening_slider.UsingGlobal()); + ConfigurationShared::SetHighlight(ui->fsr_sharpening_layout, + !Settings::values.fsr_sharpening_slider.UsingGlobal()); + ui->fsr_sharpening_slider->setValue(Settings::values.fsr_sharpening_slider.GetValue()); + ui->bg_combobox->setCurrentIndex(Settings::values.bg_red.UsingGlobal() ? 0 : 1); ui->bg_button->setEnabled(!Settings::values.bg_red.UsingGlobal()); ConfigurationShared::SetHighlight(ui->bg_layout, !Settings::values.bg_red.UsingGlobal()); @@ -155,6 +170,12 @@ void ConfigureGraphics::SetConfiguration() { Settings::values.bg_green.GetValue(), Settings::values.bg_blue.GetValue())); UpdateAPILayout(); + SetFSRIndicatorText(ui->fsr_sharpening_slider->sliderPosition()); +} + +void ConfigureGraphics::SetFSRIndicatorText(int percentage) { + ui->fsr_sharpening_value->setText( + tr("%1%", "FSR sharpening percentage (e.g. 50%)").arg(100 - (percentage / 2))); } void ConfigureGraphics::ApplyConfiguration() { @@ -210,6 +231,7 @@ void ConfigureGraphics::ApplyConfiguration() { if (Settings::values.anti_aliasing.UsingGlobal()) { Settings::values.anti_aliasing.SetValue(anti_aliasing); } + Settings::values.fsr_sharpening_slider.SetValue(ui->fsr_sharpening_slider->value()); } else { if (ui->resolution_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { Settings::values.resolution_setup.SetGlobal(true); @@ -269,6 +291,13 @@ void ConfigureGraphics::ApplyConfiguration() { Settings::values.bg_green.SetValue(static_cast<u8>(bg_color.green())); Settings::values.bg_blue.SetValue(static_cast<u8>(bg_color.blue())); } + + if (ui->fsr_sharpening_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { + Settings::values.fsr_sharpening_slider.SetGlobal(true); + } else { + Settings::values.fsr_sharpening_slider.SetGlobal(false); + Settings::values.fsr_sharpening_slider.SetValue(ui->fsr_sharpening_slider->value()); + } } } @@ -380,6 +409,7 @@ void ConfigureGraphics::SetupPerGameUI() { ui->aspect_ratio_combobox->setEnabled(Settings::values.aspect_ratio.UsingGlobal()); ui->resolution_combobox->setEnabled(Settings::values.resolution_setup.UsingGlobal()); ui->scaling_filter_combobox->setEnabled(Settings::values.scaling_filter.UsingGlobal()); + ui->fsr_sharpening_slider->setEnabled(Settings::values.fsr_sharpening_slider.UsingGlobal()); ui->anti_aliasing_combobox->setEnabled(Settings::values.anti_aliasing.UsingGlobal()); ui->use_asynchronous_gpu_emulation->setEnabled( Settings::values.use_asynchronous_gpu_emulation.UsingGlobal()); @@ -387,6 +417,7 @@ void ConfigureGraphics::SetupPerGameUI() { ui->accelerate_astc->setEnabled(Settings::values.accelerate_astc.UsingGlobal()); ui->use_disk_shader_cache->setEnabled(Settings::values.use_disk_shader_cache.UsingGlobal()); ui->bg_button->setEnabled(Settings::values.bg_red.UsingGlobal()); + ui->fsr_slider_layout->setEnabled(Settings::values.fsr_sharpening_slider.UsingGlobal()); return; } @@ -396,6 +427,13 @@ void ConfigureGraphics::SetupPerGameUI() { ConfigurationShared::SetHighlight(ui->bg_layout, index == 1); }); + connect(ui->fsr_sharpening_combobox, qOverload<int>(&QComboBox::activated), this, + [this](int index) { + ui->fsr_sharpening_slider->setEnabled(index == 1); + ui->fsr_sharpening_value->setEnabled(index == 1); + ConfigurationShared::SetHighlight(ui->fsr_sharpening_layout, index == 1); + }); + ConfigurationShared::SetColoredTristate( ui->use_disk_shader_cache, Settings::values.use_disk_shader_cache, use_disk_shader_cache); ConfigurationShared::SetColoredTristate(ui->accelerate_astc, Settings::values.accelerate_astc, diff --git a/src/yuzu/configuration/configure_graphics.h b/src/yuzu/configuration/configure_graphics.h index 70034eb1b..d98d6624e 100644 --- a/src/yuzu/configuration/configure_graphics.h +++ b/src/yuzu/configuration/configure_graphics.h @@ -42,6 +42,8 @@ private: void RetrieveVulkanDevices(); + void SetFSRIndicatorText(int percentage); + void SetupPerGameUI(); Settings::RendererBackend GetCurrentGraphicsBackend() const; diff --git a/src/yuzu/configuration/configure_graphics.ui b/src/yuzu/configuration/configure_graphics.ui index fdbb33372..37271f956 100644 --- a/src/yuzu/configuration/configure_graphics.ui +++ b/src/yuzu/configuration/configure_graphics.ui @@ -152,6 +152,12 @@ </item> <item> <widget class="QGroupBox" name="groupBox"> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>16777215</height> + </size> + </property> <property name="title"> <string>Graphics Settings</string> </property> @@ -482,6 +488,146 @@ </widget> </item> <item> + <widget class="QWidget" name="fsr_sharpening_layout" native="true"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <property name="spacing"> + <number>6</number> + </property> + <property name="sizeConstraint"> + <enum>QLayout::SetDefaultConstraint</enum> + </property> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <layout class="QHBoxLayout" name="fsr_sharpening_label_group"> + <item> + <widget class="QComboBox" name="fsr_sharpening_combobox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <item> + <property name="text"> + <string>Use global FSR Sharpness</string> + </property> + </item> + <item> + <property name="text"> + <string>Set FSR Sharpness</string> + </property> + </item> + </widget> + </item> + <item> + <widget class="QLabel" name="fsr_sharpening_label"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>FSR Sharpness:</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="fsr_slider_layout"> + <property name="spacing"> + <number>6</number> + </property> + <item> + <widget class="QSlider" name="fsr_sharpening_slider"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="baseSize"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + <property name="maximum"> + <number>200</number> + </property> + <property name="sliderPosition"> + <number>25</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="invertedAppearance"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="fsr_sharpening_value"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>32</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>100%</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item> <widget class="QWidget" name="bg_layout" native="true"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> diff --git a/src/yuzu/configuration/configure_input_advanced.cpp b/src/yuzu/configuration/configure_input_advanced.cpp index 10f841b98..235b813d9 100644 --- a/src/yuzu/configuration/configure_input_advanced.cpp +++ b/src/yuzu/configuration/configure_input_advanced.cpp @@ -194,4 +194,8 @@ void ConfigureInputAdvanced::UpdateUIEnabled() { ui->mouse_panning->setEnabled(!ui->mouse_enabled->isChecked()); ui->mouse_panning_sensitivity->setEnabled(!ui->mouse_enabled->isChecked()); ui->ring_controller_configure->setEnabled(ui->enable_ring_controller->isChecked()); +#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0) || !defined(YUZU_USE_QT_MULTIMEDIA) + ui->enable_ir_sensor->setEnabled(false); + ui->camera_configure->setEnabled(false); +#endif } diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 4081af391..c21153560 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -167,6 +167,7 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; constexpr int default_mouse_hide_timeout = 2500; constexpr int default_mouse_center_timeout = 10; +constexpr int default_input_update_timeout = 1; /** * "Callouts" are one-time instructional messages shown to the user. In the config settings, there @@ -237,6 +238,7 @@ static void LogRuntimes() { LOG_INFO(Frontend, "Unable to inspect {}", runtime_dll_name); } #endif + LOG_INFO(Frontend, "Qt Compile: {} Runtime: {}", QT_VERSION_STR, qVersion()); } static QString PrettyProductName() { @@ -404,6 +406,10 @@ GMainWindow::GMainWindow(std::unique_ptr<Config> config_, bool has_broken_vulkan mouse_center_timer.setInterval(default_mouse_center_timeout); connect(&mouse_center_timer, &QTimer::timeout, this, &GMainWindow::CenterMouseCursor); + update_input_timer.setInterval(default_input_update_timeout); + connect(&update_input_timer, &QTimer::timeout, this, &GMainWindow::UpdateInputDrivers); + update_input_timer.start(); + MigrateConfigFiles(); if (has_broken_vulkan) { @@ -3636,6 +3642,13 @@ void GMainWindow::UpdateUISettings() { UISettings::values.first_start = false; } +void GMainWindow::UpdateInputDrivers() { + if (!input_subsystem) { + return; + } + input_subsystem->PumpEvents(); +} + void GMainWindow::HideMouseCursor() { if (emu_thread == nullptr && UISettings::values.hide_mouse) { mouse_hide_timer.stop(); @@ -4036,7 +4049,6 @@ void GMainWindow::UpdateUITheme() { const QString default_theme = QString::fromUtf8(UISettings::themes[static_cast<size_t>(Config::default_theme)].second); QString current_theme = UISettings::values.theme; - QStringList theme_paths(default_theme_paths); if (current_theme.isEmpty()) { current_theme = default_theme; @@ -4049,7 +4061,7 @@ void GMainWindow::UpdateUITheme() { if (current_theme == QStringLiteral("default") || current_theme == QStringLiteral("colorful")) { QIcon::setThemeName(current_theme == QStringLiteral("colorful") ? current_theme : startup_icon_theme); - QIcon::setThemeSearchPaths(theme_paths); + QIcon::setThemeSearchPaths(QStringList(default_theme_paths)); if (CheckDarkMode()) { current_theme = QStringLiteral("default_dark"); } @@ -4217,10 +4229,12 @@ int main(int argc, char* argv[]) { // so we can see if we get \u3008 instead // TL;DR all other number formats are consecutive in unicode code points // This bug is fixed in Qt6, specifically 6.0.0-alpha1 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) const QLocale locale = QLocale::system(); if (QStringLiteral("\u3008") == locale.toString(1)) { QLocale::setDefault(QLocale::system().name()); } +#endif // Qt changes the locale and causes issues in float conversion using std::to_string() when // generating shaders diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 6a9992d05..4f9c3b450 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -353,6 +353,7 @@ private: void UpdateGPUAccuracyButton(); void UpdateStatusButtons(); void UpdateUISettings(); + void UpdateInputDrivers(); void HideMouseCursor(); void ShowMouseCursor(); void CenterMouseCursor(); @@ -404,6 +405,7 @@ private: bool auto_muted = false; QTimer mouse_hide_timer; QTimer mouse_center_timer; + QTimer update_input_timer; QString startup_icon_theme; bool os_dark_mode = false; diff --git a/src/yuzu/main.ui b/src/yuzu/main.ui index e670acc30..013ba0ceb 100644 --- a/src/yuzu/main.ui +++ b/src/yuzu/main.ui @@ -231,6 +231,9 @@ <property name="text"> <string>Con&figure...</string> </property> + <property name="menuRole"> + <enum>QAction::PreferencesRole</enum> + </property> </action> <action name="action_Display_Dock_Widget_Headers"> <property name="checkable"> @@ -363,6 +366,9 @@ <property name="text"> <string>&Configure TAS...</string> </property> + <property name="menuRole"> + <enum>QAction::NoRole</enum> + </property> </action> <action name="action_Configure_Current_Game"> <property name="enabled"> @@ -371,6 +377,9 @@ <property name="text"> <string>Configure C&urrent Game...</string> </property> + <property name="menuRole"> + <enum>QAction::NoRole</enum> + </property> </action> <action name="action_TAS_Start"> <property name="enabled"> diff --git a/src/yuzu/multiplayer/direct_connect.cpp b/src/yuzu/multiplayer/direct_connect.cpp index 10bf0a4fb..cbd52da85 100644 --- a/src/yuzu/multiplayer/direct_connect.cpp +++ b/src/yuzu/multiplayer/direct_connect.cpp @@ -4,7 +4,7 @@ #include <QComboBox> #include <QFuture> #include <QIntValidator> -#include <QRegExpValidator> +#include <QRegularExpressionValidator> #include <QString> #include <QtConcurrent/QtConcurrentRun> #include "common/settings.h" diff --git a/src/yuzu/multiplayer/validation.h b/src/yuzu/multiplayer/validation.h index dabf860be..dd25af280 100644 --- a/src/yuzu/multiplayer/validation.h +++ b/src/yuzu/multiplayer/validation.h @@ -3,7 +3,7 @@ #pragma once -#include <QRegExp> +#include <QRegularExpression> #include <QString> #include <QValidator> @@ -29,19 +29,21 @@ public: private: /// room name can be alphanumeric and " " "_" "." and "-" and must have a size of 4-20 - QRegExp room_name_regex = QRegExp(QStringLiteral("^[a-zA-Z0-9._- ]{4,20}$")); - QRegExpValidator room_name; + QRegularExpression room_name_regex = + QRegularExpression(QStringLiteral("^[a-zA-Z0-9._ -]{4,20}")); + QRegularExpressionValidator room_name; /// nickname can be alphanumeric and " " "_" "." and "-" and must have a size of 4-20 - QRegExp nickname_regex = QRegExp(QStringLiteral("^[a-zA-Z0-9._- ]{4,20}$")); - QRegExpValidator nickname; + const QRegularExpression nickname_regex = + QRegularExpression(QStringLiteral("^[a-zA-Z0-9._ -]{4,20}")); + QRegularExpressionValidator nickname; /// ipv4 address only // TODO remove this when we support hostnames in direct connect - QRegExp ip_regex = QRegExp(QStringLiteral( + QRegularExpression ip_regex = QRegularExpression(QStringLiteral( "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|" "2[0-4][0-9]|25[0-5])")); - QRegExpValidator ip; + QRegularExpressionValidator ip; /// port must be between 0 and 65535 QIntValidator port; diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index 66dd0dc15..59f9c8e09 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp @@ -90,7 +90,11 @@ static const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> template <> void Config::ReadSetting(const std::string& group, Settings::Setting<std::string>& setting) { - setting = sdl2_config->Get(group, setting.GetLabel(), setting.GetDefault()); + std::string setting_value = sdl2_config->Get(group, setting.GetLabel(), setting.GetDefault()); + if (setting_value.empty()) { + setting_value = setting.GetDefault(); + } + setting = std::move(setting_value); } template <> @@ -299,6 +303,7 @@ void Config::ReadValues() { ReadSetting("Renderer", Settings::values.resolution_setup); ReadSetting("Renderer", Settings::values.scaling_filter); + ReadSetting("Renderer", Settings::values.fsr_sharpening_slider); ReadSetting("Renderer", Settings::values.anti_aliasing); ReadSetting("Renderer", Settings::values.fullscreen_mode); ReadSetting("Renderer", Settings::values.aspect_ratio); diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h index d214771b0..5bbc3f532 100644 --- a/src/yuzu_cmd/default_ini.h +++ b/src/yuzu_cmd/default_ini.h @@ -6,16 +6,22 @@ namespace DefaultINI { const char* sdl2_config_file = R"( -[ControlsGeneral] + +[ControlsP0] # The input devices and parameters for each Switch native input +# The config section determines the player number where the config will be applied on. For example "ControlsP0", "ControlsP1", ... # It should be in the format of "engine:[engine_name],[param1]:[value1],[param2]:[value2]..." # Escape characters $0 (for ':'), $1 (for ',') and $2 (for '$') can be used in values +# Indicates if this player should be connected at boot +connected= + # for button input, the following devices are available: # - "keyboard" (default) for keyboard input. Required parameters: # - "code": the code of the key to bind # - "sdl" for joystick input using SDL. Required parameters: -# - "joystick": the index of the joystick to bind +# - "guid": SDL identification GUID of the joystick +# - "port": the index of the joystick to bind # - "button"(optional): the index of the button to bind # - "hat"(optional): the index of the hat to bind as direction buttons # - "axis"(optional): the index of the axis to bind @@ -58,12 +64,29 @@ button_screenshot= # - "modifier_scale": a float number representing the applied modifier scale to the analog input. # Must be in range of 0.0-1.0. Defaults to 0.5 # - "sdl" for joystick input using SDL. Required parameters: -# - "joystick": the index of the joystick to bind +# - "guid": SDL identification GUID of the joystick +# - "port": the index of the joystick to bind # - "axis_x": the index of the axis to bind as x-axis (default to 0) # - "axis_y": the index of the axis to bind as y-axis (default to 1) lstick= rstick= +# for motion input, the following devices are available: +# - "keyboard" (default) for emulating random motion input from buttons. Required parameters: +# - "code": the code of the key to bind +# - "sdl" for motion input using SDL. Required parameters: +# - "guid": SDL identification GUID of the joystick +# - "port": the index of the joystick to bind +# - "motion": the index of the motion sensor to bind +# - "cemuhookudp" for motion input using Cemu Hook protocol. Required parameters: +# - "guid": the IP address of the cemu hook server encoded to a hex string. for example 192.168.0.1 = "c0a80001" +# - "port": the port of the cemu hook server +# - "pad": the index of the joystick +# - "motion": the index of the motion sensor of the joystick to bind +motionleft= +motionright= + +[ControlsGeneral] # To use the debug_pad, prepend `debug_pad_` before each button setting above. # i.e. debug_pad_button_a= diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp index 4ac72c2f6..37dd1747c 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp @@ -7,6 +7,7 @@ #include "common/scm_rev.h" #include "common/settings.h" #include "core/core.h" +#include "core/hid/hid_core.h" #include "core/perf_stats.h" #include "input_common/drivers/keyboard.h" #include "input_common/drivers/mouse.h" @@ -26,6 +27,7 @@ EmuWindow_SDL2::EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem_, Co } EmuWindow_SDL2::~EmuWindow_SDL2() { + system.HIDCore().UnloadInputDevices(); input_subsystem->Shutdown(); SDL_Quit(); } |