diff options
66 files changed, 1307 insertions, 671 deletions
diff --git a/.gitmodules b/.gitmodules index 4962f7bfd..93ba9b930 100644 --- a/.gitmodules +++ b/.gitmodules @@ -37,6 +37,6 @@ [submodule "opus"] path = externals/opus/opus url = https://github.com/xiph/opus.git -[submodule "externals/ffmpeg"] +[submodule "ffmpeg"] path = externals/ffmpeg url = https://git.ffmpeg.org/ffmpeg.git diff --git a/CMakeLists.txt b/CMakeLists.txt index c45123139..ac7c3ce90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -504,7 +504,7 @@ if (YUZU_USE_BUNDLED_FFMPEG) endif() else() # WIN32 # Use yuzu FFmpeg binaries - set(FFmpeg_EXT_NAME "ffmpeg-4.2.1") + set(FFmpeg_EXT_NAME "ffmpeg-4.3.1") set(FFmpeg_PATH "${CMAKE_BINARY_DIR}/externals/${FFmpeg_EXT_NAME}") download_bundled_external("ffmpeg/" ${FFmpeg_EXT_NAME} "") set(FFmpeg_FOUND YES) diff --git a/CMakeModules/CopyYuzuFFmpegDeps.cmake b/CMakeModules/CopyYuzuFFmpegDeps.cmake index b7162cf17..26384e8b8 100644 --- a/CMakeModules/CopyYuzuFFmpegDeps.cmake +++ b/CMakeModules/CopyYuzuFFmpegDeps.cmake @@ -1,10 +1,6 @@ function(copy_yuzu_FFmpeg_deps target_dir) include(WindowsCopyFiles) set(DLL_DEST "${CMAKE_BINARY_DIR}/bin/$<CONFIG>/") - windows_copy_files(${target_dir} ${FFmpeg_DLL_DIR} ${DLL_DEST} - avcodec-58.dll - avutil-56.dll - swresample-3.dll - swscale-5.dll - ) + file(READ "${FFmpeg_PATH}/requirements.txt" FFmpeg_REQUIRED_DLLS) + windows_copy_files(${target_dir} ${FFmpeg_DLL_DIR} ${DLL_DEST} ${FFmpeg_REQUIRED_DLLS}) endfunction(copy_yuzu_FFmpeg_deps) diff --git a/externals/dynarmic b/externals/dynarmic -Subproject 8c09da666aa3f0bb1000b0b6c5d5b0a1876f306 +Subproject cafa687684a3e5dbe86be7150c0f8183d2ad53c diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index d1d177b51..a0ae07752 100644 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt @@ -15,6 +15,8 @@ add_library(audio_core STATIC command_generator.cpp command_generator.h common.h + delay_line.cpp + delay_line.h effect_context.cpp effect_context.h info_updater.cpp diff --git a/src/audio_core/command_generator.cpp b/src/audio_core/command_generator.cpp index 5b1065520..437cc5ccd 100644 --- a/src/audio_core/command_generator.cpp +++ b/src/audio_core/command_generator.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <cmath> +#include <numbers> #include "audio_core/algorithm/interpolate.h" #include "audio_core/command_generator.h" #include "audio_core/effect_context.h" @@ -13,6 +15,20 @@ namespace AudioCore { namespace { constexpr std::size_t MIX_BUFFER_SIZE = 0x3f00; constexpr std::size_t SCALED_MIX_BUFFER_SIZE = MIX_BUFFER_SIZE << 15ULL; +using DelayLineTimes = std::array<f32, AudioCommon::I3DL2REVERB_DELAY_LINE_COUNT>; + +constexpr DelayLineTimes FDN_MIN_DELAY_LINE_TIMES{5.0f, 6.0f, 13.0f, 14.0f}; +constexpr DelayLineTimes FDN_MAX_DELAY_LINE_TIMES{45.704f, 82.782f, 149.94f, 271.58f}; +constexpr DelayLineTimes DECAY0_MAX_DELAY_LINE_TIMES{17.0f, 13.0f, 9.0f, 7.0f}; +constexpr DelayLineTimes DECAY1_MAX_DELAY_LINE_TIMES{19.0f, 11.0f, 10.0f, 6.0f}; +constexpr std::array<f32, AudioCommon::I3DL2REVERB_TAPS> EARLY_TAP_TIMES{ + 0.017136f, 0.059154f, 0.161733f, 0.390186f, 0.425262f, 0.455411f, 0.689737f, + 0.745910f, 0.833844f, 0.859502f, 0.000000f, 0.075024f, 0.168788f, 0.299901f, + 0.337443f, 0.371903f, 0.599011f, 0.716741f, 0.817859f, 0.851664f}; +constexpr std::array<f32, AudioCommon::I3DL2REVERB_TAPS> EARLY_GAIN{ + 0.67096f, 0.61027f, 1.0f, 0.35680f, 0.68361f, 0.65978f, 0.51939f, + 0.24712f, 0.45945f, 0.45021f, 0.64196f, 0.54879f, 0.92925f, 0.38270f, + 0.72867f, 0.69794f, 0.5464f, 0.24563f, 0.45214f, 0.44042f}; template <std::size_t N> void ApplyMix(s32* output, const s32* input, s32 gain, s32 sample_count) { @@ -65,6 +81,154 @@ s32 ApplyMixDepop(s32* output, s32 first_sample, s32 delta, s32 sample_count) { } } +float Pow10(float x) { + if (x >= 0.0f) { + return 1.0f; + } else if (x <= -5.3f) { + return 0.0f; + } + return std::pow(10.0f, x); +} + +float SinD(float degrees) { + return std::sin(degrees * std::numbers::pi_v<float> / 180.0f); +} + +float CosD(float degrees) { + return std::cos(degrees * std::numbers::pi_v<float> / 180.0f); +} + +float ToFloat(s32 sample) { + return static_cast<float>(sample) / 65536.f; +} + +s32 ToS32(float sample) { + constexpr auto min = -8388608.0f; + constexpr auto max = 8388607.f; + float rescaled_sample = sample * 65536.0f; + if (rescaled_sample < min) { + rescaled_sample = min; + } + if (rescaled_sample > max) { + rescaled_sample = max; + } + return static_cast<s32>(rescaled_sample); +} + +constexpr std::array<std::size_t, 20> REVERB_TAP_INDEX_1CH{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +constexpr std::array<std::size_t, 20> REVERB_TAP_INDEX_2CH{0, 0, 0, 1, 1, 1, 1, 0, 0, 0, + 1, 1, 1, 0, 0, 0, 0, 1, 1, 1}; + +constexpr std::array<std::size_t, 20> REVERB_TAP_INDEX_4CH{0, 0, 0, 1, 1, 1, 1, 2, 2, 2, + 1, 1, 1, 0, 0, 0, 0, 3, 3, 3}; + +constexpr std::array<std::size_t, 20> REVERB_TAP_INDEX_6CH{4, 0, 0, 1, 1, 1, 1, 2, 2, 2, + 1, 1, 1, 0, 0, 0, 0, 3, 3, 3}; + +template <std::size_t CHANNEL_COUNT> +void ApplyReverbGeneric(I3dl2ReverbState& state, + const std::array<const s32*, AudioCommon::MAX_CHANNEL_COUNT>& input, + const std::array<s32*, AudioCommon::MAX_CHANNEL_COUNT>& output, + s32 sample_count) { + + auto GetTapLookup = []() { + if constexpr (CHANNEL_COUNT == 1) { + return REVERB_TAP_INDEX_1CH; + } else if constexpr (CHANNEL_COUNT == 2) { + return REVERB_TAP_INDEX_2CH; + } else if constexpr (CHANNEL_COUNT == 4) { + return REVERB_TAP_INDEX_4CH; + } else if constexpr (CHANNEL_COUNT == 6) { + return REVERB_TAP_INDEX_6CH; + } + }; + + const auto& tap_index_lut = GetTapLookup(); + for (s32 sample = 0; sample < sample_count; sample++) { + std::array<f32, CHANNEL_COUNT> out_samples{}; + std::array<f32, AudioCommon::I3DL2REVERB_DELAY_LINE_COUNT> fsamp{}; + std::array<f32, AudioCommon::I3DL2REVERB_DELAY_LINE_COUNT> mixed{}; + std::array<f32, AudioCommon::I3DL2REVERB_DELAY_LINE_COUNT> osamp{}; + + // Mix everything into a single sample + s32 temp_mixed_sample = 0; + for (std::size_t i = 0; i < CHANNEL_COUNT; i++) { + temp_mixed_sample += input[i][sample]; + } + const auto current_sample = ToFloat(temp_mixed_sample); + const auto early_tap = state.early_delay_line.TapOut(state.early_to_late_taps); + + for (std::size_t i = 0; i < AudioCommon::I3DL2REVERB_TAPS; i++) { + const auto tapped_samp = + state.early_delay_line.TapOut(state.early_tap_steps[i]) * EARLY_GAIN[i]; + out_samples[tap_index_lut[i]] += tapped_samp; + + if constexpr (CHANNEL_COUNT == 6) { + // handle lfe + out_samples[5] += tapped_samp; + } + } + + state.lowpass_0 = current_sample * state.lowpass_2 + state.lowpass_0 * state.lowpass_1; + state.early_delay_line.Tick(state.lowpass_0); + + for (std::size_t i = 0; i < CHANNEL_COUNT; i++) { + out_samples[i] *= state.early_gain; + } + + // Two channel seems to apply a latet gain, we require to save this + f32 filter{}; + for (std::size_t i = 0; i < AudioCommon::I3DL2REVERB_DELAY_LINE_COUNT; i++) { + filter = state.fdn_delay_line[i].GetOutputSample(); + const auto computed = filter * state.lpf_coefficients[0][i] + state.shelf_filter[i]; + state.shelf_filter[i] = + filter * state.lpf_coefficients[1][i] + computed * state.lpf_coefficients[2][i]; + fsamp[i] = computed; + } + + // Mixing matrix + mixed[0] = fsamp[1] + fsamp[2]; + mixed[1] = -fsamp[0] - fsamp[3]; + mixed[2] = fsamp[0] - fsamp[3]; + mixed[3] = fsamp[1] - fsamp[2]; + + if constexpr (CHANNEL_COUNT == 2) { + for (auto& mix : mixed) { + mix *= (filter * state.late_gain); + } + } + + for (std::size_t i = 0; i < AudioCommon::I3DL2REVERB_DELAY_LINE_COUNT; i++) { + const auto late = early_tap * state.late_gain; + osamp[i] = state.decay_delay_line0[i].Tick(late + mixed[i]); + osamp[i] = state.decay_delay_line1[i].Tick(osamp[i]); + state.fdn_delay_line[i].Tick(osamp[i]); + } + + if constexpr (CHANNEL_COUNT == 1) { + output[0][sample] = ToS32(state.dry_gain * ToFloat(input[0][sample]) + + (out_samples[0] + osamp[0] + osamp[1])); + } else if constexpr (CHANNEL_COUNT == 2 || CHANNEL_COUNT == 4) { + for (std::size_t i = 0; i < CHANNEL_COUNT; i++) { + output[i][sample] = + ToS32(state.dry_gain * ToFloat(input[i][sample]) + (out_samples[i] + osamp[i])); + } + } else if constexpr (CHANNEL_COUNT == 6) { + const auto temp_center = state.center_delay_line.Tick(0.5f * (osamp[2] - osamp[3])); + for (std::size_t i = 0; i < 4; i++) { + output[i][sample] = + ToS32(state.dry_gain * ToFloat(input[i][sample]) + (out_samples[i] + osamp[i])); + } + output[4][sample] = + ToS32(state.dry_gain * ToFloat(input[4][sample]) + (out_samples[4] + temp_center)); + output[5][sample] = + ToS32(state.dry_gain * ToFloat(input[5][sample]) + (out_samples[5] + osamp[3])); + } + } +} + } // namespace CommandGenerator::CommandGenerator(AudioCommon::AudioRendererParameter& worker_params_, @@ -271,11 +435,10 @@ void CommandGenerator::GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voic } // Generate biquad filter - // GenerateBiquadFilterCommand(mix_buffer_count, biquad_filter, - // dsp_state.biquad_filter_state, - // mix_buffer_count + channel, mix_buffer_count + - // channel, worker_params.sample_count, - // voice_info.GetInParams().node_id); + // GenerateBiquadFilterCommand(mix_buffer_count, biquad_filter, + // dsp_state.biquad_filter_state, + // mix_buffer_count + channel, mix_buffer_count + channel, + // worker_params.sample_count, voice_info.GetInParams().node_id); } } @@ -376,21 +539,54 @@ void CommandGenerator::GenerateEffectCommand(ServerMixInfo& mix_info) { void CommandGenerator::GenerateI3dl2ReverbEffectCommand(s32 mix_buffer_offset, EffectBase* info, bool enabled) { - if (!enabled) { + auto* reverb = dynamic_cast<EffectI3dl2Reverb*>(info); + const auto& params = reverb->GetParams(); + auto& state = reverb->GetState(); + const auto channel_count = params.channel_count; + + if (channel_count != 1 && channel_count != 2 && channel_count != 4 && channel_count != 6) { return; } - const auto& params = dynamic_cast<EffectI3dl2Reverb*>(info)->GetParams(); - const auto channel_count = params.channel_count; + + std::array<const s32*, AudioCommon::MAX_CHANNEL_COUNT> input{}; + std::array<s32*, AudioCommon::MAX_CHANNEL_COUNT> output{}; + + const auto status = params.status; for (s32 i = 0; i < channel_count; i++) { - // TODO(ogniK): Actually implement reverb - /* - if (params.input[i] != params.output[i]) { - const auto* input = GetMixBuffer(mix_buffer_offset + params.input[i]); - auto* output = GetMixBuffer(mix_buffer_offset + params.output[i]); - ApplyMix<1>(output, input, 32768, worker_params.sample_count); - }*/ - auto* output = GetMixBuffer(mix_buffer_offset + params.output[i]); - std::memset(output, 0, worker_params.sample_count * sizeof(s32)); + input[i] = GetMixBuffer(mix_buffer_offset + params.input[i]); + output[i] = GetMixBuffer(mix_buffer_offset + params.output[i]); + } + + if (enabled) { + if (status == ParameterStatus::Initialized) { + InitializeI3dl2Reverb(reverb->GetParams(), state, info->GetWorkBuffer()); + } else if (status == ParameterStatus::Updating) { + UpdateI3dl2Reverb(reverb->GetParams(), state, false); + } + } + + if (enabled) { + switch (channel_count) { + case 1: + ApplyReverbGeneric<1>(state, input, output, worker_params.sample_count); + break; + case 2: + ApplyReverbGeneric<2>(state, input, output, worker_params.sample_count); + break; + case 4: + ApplyReverbGeneric<4>(state, input, output, worker_params.sample_count); + break; + case 6: + ApplyReverbGeneric<6>(state, input, output, worker_params.sample_count); + break; + } + } else { + for (s32 i = 0; i < channel_count; i++) { + // Only copy if the buffer input and output do not match! + if ((mix_buffer_offset + params.input[i]) != (mix_buffer_offset + params.output[i])) { + std::memcpy(output[i], input[i], worker_params.sample_count * sizeof(s32)); + } + } } } @@ -528,6 +724,133 @@ s32 CommandGenerator::ReadAuxBuffer(AuxInfoDSP& recv_info, VAddr recv_buffer, u3 return sample_count; } +void CommandGenerator::InitializeI3dl2Reverb(I3dl2ReverbParams& info, I3dl2ReverbState& state, + std::vector<u8>& work_buffer) { + // Reset state + state.lowpass_0 = 0.0f; + state.lowpass_1 = 0.0f; + state.lowpass_2 = 0.0f; + + state.early_delay_line.Reset(); + state.early_tap_steps.fill(0); + state.early_gain = 0.0f; + state.late_gain = 0.0f; + state.early_to_late_taps = 0; + for (std::size_t i = 0; i < AudioCommon::I3DL2REVERB_DELAY_LINE_COUNT; i++) { + state.fdn_delay_line[i].Reset(); + state.decay_delay_line0[i].Reset(); + state.decay_delay_line1[i].Reset(); + } + state.last_reverb_echo = 0.0f; + state.center_delay_line.Reset(); + for (auto& coef : state.lpf_coefficients) { + coef.fill(0.0f); + } + state.shelf_filter.fill(0.0f); + state.dry_gain = 0.0f; + + const auto sample_rate = info.sample_rate / 1000; + f32* work_buffer_ptr = reinterpret_cast<f32*>(work_buffer.data()); + + s32 delay_samples{}; + for (std::size_t i = 0; i < AudioCommon::I3DL2REVERB_DELAY_LINE_COUNT; i++) { + delay_samples = + AudioCommon::CalculateDelaySamples(sample_rate, FDN_MAX_DELAY_LINE_TIMES[i]); + state.fdn_delay_line[i].Initialize(delay_samples, work_buffer_ptr); + work_buffer_ptr += delay_samples + 1; + + delay_samples = + AudioCommon::CalculateDelaySamples(sample_rate, DECAY0_MAX_DELAY_LINE_TIMES[i]); + state.decay_delay_line0[i].Initialize(delay_samples, 0.0f, work_buffer_ptr); + work_buffer_ptr += delay_samples + 1; + + delay_samples = + AudioCommon::CalculateDelaySamples(sample_rate, DECAY1_MAX_DELAY_LINE_TIMES[i]); + state.decay_delay_line1[i].Initialize(delay_samples, 0.0f, work_buffer_ptr); + work_buffer_ptr += delay_samples + 1; + } + delay_samples = AudioCommon::CalculateDelaySamples(sample_rate, 5.0f); + state.center_delay_line.Initialize(delay_samples, work_buffer_ptr); + work_buffer_ptr += delay_samples + 1; + + delay_samples = AudioCommon::CalculateDelaySamples(sample_rate, 400.0f); + state.early_delay_line.Initialize(delay_samples, work_buffer_ptr); + + UpdateI3dl2Reverb(info, state, true); +} + +void CommandGenerator::UpdateI3dl2Reverb(I3dl2ReverbParams& info, I3dl2ReverbState& state, + bool should_clear) { + + state.dry_gain = info.dry_gain; + state.shelf_filter.fill(0.0f); + state.lowpass_0 = 0.0f; + state.early_gain = Pow10(std::min(info.room + info.reflection, 5000.0f) / 2000.0f); + state.late_gain = Pow10(std::min(info.room + info.reverb, 5000.0f) / 2000.0f); + + const auto sample_rate = info.sample_rate / 1000; + const f32 hf_gain = Pow10(info.room_hf / 2000.0f); + if (hf_gain >= 1.0f) { + state.lowpass_2 = 1.0f; + state.lowpass_1 = 0.0f; + } else { + const auto a = 1.0f - hf_gain; + const auto b = 2.0f * (1.0f - hf_gain * CosD(256.0f * info.hf_reference / + static_cast<f32>(info.sample_rate))); + const auto c = std::sqrt(b * b - 4.0f * a * a); + + state.lowpass_1 = (b - c) / (2.0f * a); + state.lowpass_2 = 1.0f - state.lowpass_1; + } + state.early_to_late_taps = AudioCommon::CalculateDelaySamples( + sample_rate, 1000.0f * (info.reflection_delay + info.reverb_delay)); + + state.last_reverb_echo = 0.6f * info.diffusion * 0.01f; + for (std::size_t i = 0; i < AudioCommon::I3DL2REVERB_DELAY_LINE_COUNT; i++) { + const auto length = + FDN_MIN_DELAY_LINE_TIMES[i] + + (info.density / 100.0f) * (FDN_MAX_DELAY_LINE_TIMES[i] - FDN_MIN_DELAY_LINE_TIMES[i]); + state.fdn_delay_line[i].SetDelay(AudioCommon::CalculateDelaySamples(sample_rate, length)); + + const auto delay_sample_counts = state.fdn_delay_line[i].GetDelay() + + state.decay_delay_line0[i].GetDelay() + + state.decay_delay_line1[i].GetDelay(); + + float a = (-60.0f * static_cast<f32>(delay_sample_counts)) / + (info.decay_time * static_cast<f32>(info.sample_rate)); + float b = a / info.hf_decay_ratio; + float c = CosD(128.0f * 0.5f * info.hf_reference / static_cast<f32>(info.sample_rate)) / + SinD(128.0f * 0.5f * info.hf_reference / static_cast<f32>(info.sample_rate)); + float d = Pow10((b - a) / 40.0f); + float e = Pow10((b + a) / 40.0f) * 0.7071f; + + state.lpf_coefficients[0][i] = e * ((d * c) + 1.0f) / (c + d); + state.lpf_coefficients[1][i] = e * (1.0f - (d * c)) / (c + d); + state.lpf_coefficients[2][i] = (c - d) / (c + d); + + state.decay_delay_line0[i].SetCoefficient(state.last_reverb_echo); + state.decay_delay_line1[i].SetCoefficient(-0.9f * state.last_reverb_echo); + } + + if (should_clear) { + for (std::size_t i = 0; i < AudioCommon::I3DL2REVERB_DELAY_LINE_COUNT; i++) { + state.fdn_delay_line[i].Clear(); + state.decay_delay_line0[i].Clear(); + state.decay_delay_line1[i].Clear(); + } + state.early_delay_line.Clear(); + state.center_delay_line.Clear(); + } + + const auto max_early_delay = state.early_delay_line.GetMaxDelay(); + const auto reflection_time = 1000.0f * (0.0098f * info.reverb_delay + 0.02f); + for (std::size_t tap = 0; tap < AudioCommon::I3DL2REVERB_TAPS; tap++) { + const auto length = AudioCommon::CalculateDelaySamples( + sample_rate, 1000.0f * info.reflection_delay + reflection_time * EARLY_TAP_TIMES[tap]); + state.early_tap_steps[tap] = std::min(length, max_early_delay); + } +} + void CommandGenerator::GenerateVolumeRampCommand(float last_volume, float current_volume, s32 channel, s32 node_id) { const auto last = static_cast<s32>(last_volume * 32768.0f); diff --git a/src/audio_core/command_generator.h b/src/audio_core/command_generator.h index b937350b1..2ebb755b0 100644 --- a/src/audio_core/command_generator.h +++ b/src/audio_core/command_generator.h @@ -21,6 +21,8 @@ class ServerMixInfo; class EffectContext; class EffectBase; struct AuxInfoDSP; +struct I3dl2ReverbParams; +struct I3dl2ReverbState; using MixVolumeBuffer = std::array<float, AudioCommon::MAX_MIX_BUFFERS>; class CommandGenerator { @@ -80,6 +82,9 @@ private: s32 ReadAuxBuffer(AuxInfoDSP& recv_info, VAddr recv_buffer, u32 max_samples, s32* out_data, u32 sample_count, u32 read_offset, u32 read_count); + void InitializeI3dl2Reverb(I3dl2ReverbParams& info, I3dl2ReverbState& state, + std::vector<u8>& work_buffer); + void UpdateI3dl2Reverb(I3dl2ReverbParams& info, I3dl2ReverbState& state, bool should_clear); // DSP Code s32 DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 sample_count, s32 channel, std::size_t mix_offset); diff --git a/src/audio_core/common.h b/src/audio_core/common.h index ec59a3ba9..fe546c55d 100644 --- a/src/audio_core/common.h +++ b/src/audio_core/common.h @@ -33,6 +33,29 @@ constexpr std::size_t TEMP_MIX_BASE_SIZE = 0x3f00; // TODO(ogniK): Work out this // and our const ends up being 0x3f04, the 4 bytes are most // likely the sample history constexpr std::size_t TOTAL_TEMP_MIX_SIZE = TEMP_MIX_BASE_SIZE + AudioCommon::MAX_SAMPLE_HISTORY; +constexpr f32 I3DL2REVERB_MAX_LEVEL = 5000.0f; +constexpr f32 I3DL2REVERB_MIN_REFLECTION_DURATION = 0.02f; +constexpr std::size_t I3DL2REVERB_TAPS = 20; +constexpr std::size_t I3DL2REVERB_DELAY_LINE_COUNT = 4; +using Fractional = s32; + +template <typename T> +constexpr Fractional ToFractional(T x) { + return static_cast<Fractional>(x * static_cast<T>(0x4000)); +} + +constexpr Fractional MultiplyFractional(Fractional lhs, Fractional rhs) { + return static_cast<Fractional>(static_cast<s64>(lhs) * rhs >> 14); +} + +constexpr s32 FractionalToFixed(Fractional x) { + const auto s = x & (1 << 13); + return static_cast<s32>(x >> 14) + s; +} + +constexpr s32 CalculateDelaySamples(s32 sample_rate_khz, float time) { + return FractionalToFixed(MultiplyFractional(ToFractional(sample_rate_khz), ToFractional(time))); +} static constexpr u32 VersionFromRevision(u32_le rev) { // "REV7" -> 7 diff --git a/src/audio_core/delay_line.cpp b/src/audio_core/delay_line.cpp new file mode 100644 index 000000000..f4e4dd8d2 --- /dev/null +++ b/src/audio_core/delay_line.cpp @@ -0,0 +1,104 @@ +#include <cstring> +#include "audio_core/delay_line.h" + +namespace AudioCore { +DelayLineBase::DelayLineBase() = default; +DelayLineBase::~DelayLineBase() = default; + +void DelayLineBase::Initialize(s32 max_delay_, float* src_buffer) { + buffer = src_buffer; + buffer_end = buffer + max_delay_; + max_delay = max_delay_; + output = buffer; + SetDelay(max_delay_); + Clear(); +} + +void DelayLineBase::SetDelay(s32 new_delay) { + if (max_delay < new_delay) { + return; + } + delay = new_delay; + input = (buffer + ((output - buffer) + new_delay) % (max_delay + 1)); +} + +s32 DelayLineBase::GetDelay() const { + return delay; +} + +s32 DelayLineBase::GetMaxDelay() const { + return max_delay; +} + +f32 DelayLineBase::TapOut(s32 last_sample) { + const float* ptr = input - (last_sample + 1); + if (ptr < buffer) { + ptr += (max_delay + 1); + } + + return *ptr; +} + +f32 DelayLineBase::Tick(f32 sample) { + *(input++) = sample; + const auto out_sample = *(output++); + + if (buffer_end < input) { + input = buffer; + } + + if (buffer_end < output) { + output = buffer; + } + + return out_sample; +} + +float* DelayLineBase::GetInput() { + return input; +} + +const float* DelayLineBase::GetInput() const { + return input; +} + +f32 DelayLineBase::GetOutputSample() const { + return *output; +} + +void DelayLineBase::Clear() { + std::memset(buffer, 0, sizeof(float) * max_delay); +} + +void DelayLineBase::Reset() { + buffer = nullptr; + buffer_end = nullptr; + max_delay = 0; + input = nullptr; + output = nullptr; + delay = 0; +} + +DelayLineAllPass::DelayLineAllPass() = default; +DelayLineAllPass::~DelayLineAllPass() = default; + +void DelayLineAllPass::Initialize(u32 delay_, float coeffcient_, f32* src_buffer) { + DelayLineBase::Initialize(delay_, src_buffer); + SetCoefficient(coeffcient_); +} + +void DelayLineAllPass::SetCoefficient(float coeffcient_) { + coefficient = coeffcient_; +} + +f32 DelayLineAllPass::Tick(f32 sample) { + const auto temp = sample - coefficient * *output; + return coefficient * temp + DelayLineBase::Tick(temp); +} + +void DelayLineAllPass::Reset() { + coefficient = 0.0f; + DelayLineBase::Reset(); +} + +} // namespace AudioCore diff --git a/src/audio_core/delay_line.h b/src/audio_core/delay_line.h new file mode 100644 index 000000000..cafddd432 --- /dev/null +++ b/src/audio_core/delay_line.h @@ -0,0 +1,46 @@ +#pragma once + +#include "common/common_types.h" + +namespace AudioCore { + +class DelayLineBase { +public: + DelayLineBase(); + ~DelayLineBase(); + + void Initialize(s32 max_delay_, float* src_buffer); + void SetDelay(s32 new_delay); + s32 GetDelay() const; + s32 GetMaxDelay() const; + f32 TapOut(s32 last_sample); + f32 Tick(f32 sample); + float* GetInput(); + const float* GetInput() const; + f32 GetOutputSample() const; + void Clear(); + void Reset(); + +protected: + float* buffer{nullptr}; + float* buffer_end{nullptr}; + s32 max_delay{}; + float* input{nullptr}; + float* output{nullptr}; + s32 delay{}; +}; + +class DelayLineAllPass final : public DelayLineBase { +public: + DelayLineAllPass(); + ~DelayLineAllPass(); + + void Initialize(u32 delay, float coeffcient_, f32* src_buffer); + void SetCoefficient(float coeffcient_); + f32 Tick(f32 sample); + void Reset(); + +private: + float coefficient{}; +}; +} // namespace AudioCore diff --git a/src/audio_core/effect_context.cpp b/src/audio_core/effect_context.cpp index f770b9608..89e4573c7 100644 --- a/src/audio_core/effect_context.cpp +++ b/src/audio_core/effect_context.cpp @@ -90,6 +90,14 @@ s32 EffectBase::GetProcessingOrder() const { return processing_order; } +std::vector<u8>& EffectBase::GetWorkBuffer() { + return work_buffer; +} + +const std::vector<u8>& EffectBase::GetWorkBuffer() const { + return work_buffer; +} + EffectI3dl2Reverb::EffectI3dl2Reverb() : EffectGeneric(EffectType::I3dl2Reverb) {} EffectI3dl2Reverb::~EffectI3dl2Reverb() = default; @@ -117,6 +125,12 @@ void EffectI3dl2Reverb::Update(EffectInfo::InParams& in_params) { usage = UsageState::Initialized; params.status = ParameterStatus::Initialized; skipped = in_params.buffer_address == 0 || in_params.buffer_size == 0; + if (!skipped) { + auto& cur_work_buffer = GetWorkBuffer(); + // Has two buffers internally + cur_work_buffer.resize(in_params.buffer_size * 2); + std::fill(cur_work_buffer.begin(), cur_work_buffer.end(), 0); + } } } @@ -129,6 +143,14 @@ void EffectI3dl2Reverb::UpdateForCommandGeneration() { GetParams().status = ParameterStatus::Updated; } +I3dl2ReverbState& EffectI3dl2Reverb::GetState() { + return state; +} + +const I3dl2ReverbState& EffectI3dl2Reverb::GetState() const { + return state; +} + EffectBiquadFilter::EffectBiquadFilter() : EffectGeneric(EffectType::BiquadFilter) {} EffectBiquadFilter::~EffectBiquadFilter() = default; diff --git a/src/audio_core/effect_context.h b/src/audio_core/effect_context.h index c5e0b398c..5e0655dd7 100644 --- a/src/audio_core/effect_context.h +++ b/src/audio_core/effect_context.h @@ -8,6 +8,7 @@ #include <memory> #include <vector> #include "audio_core/common.h" +#include "audio_core/delay_line.h" #include "common/common_funcs.h" #include "common/common_types.h" #include "common/swap.h" @@ -194,6 +195,8 @@ public: [[nodiscard]] bool IsEnabled() const; [[nodiscard]] s32 GetMixID() const; [[nodiscard]] s32 GetProcessingOrder() const; + [[nodiscard]] std::vector<u8>& GetWorkBuffer(); + [[nodiscard]] const std::vector<u8>& GetWorkBuffer() const; protected: UsageState usage{UsageState::Invalid}; @@ -201,6 +204,7 @@ protected: s32 mix_id{}; s32 processing_order{}; bool enabled = false; + std::vector<u8> work_buffer{}; }; template <typename T> @@ -212,7 +216,7 @@ public: return internal_params; } - const I3dl2ReverbParams& GetParams() const { + const T& GetParams() const { return internal_params; } @@ -229,6 +233,27 @@ public: void UpdateForCommandGeneration() override; }; +struct I3dl2ReverbState { + f32 lowpass_0{}; + f32 lowpass_1{}; + f32 lowpass_2{}; + + DelayLineBase early_delay_line{}; + std::array<u32, AudioCommon::I3DL2REVERB_TAPS> early_tap_steps{}; + f32 early_gain{}; + f32 late_gain{}; + + u32 early_to_late_taps{}; + std::array<DelayLineBase, AudioCommon::I3DL2REVERB_DELAY_LINE_COUNT> fdn_delay_line{}; + std::array<DelayLineAllPass, AudioCommon::I3DL2REVERB_DELAY_LINE_COUNT> decay_delay_line0{}; + std::array<DelayLineAllPass, AudioCommon::I3DL2REVERB_DELAY_LINE_COUNT> decay_delay_line1{}; + f32 last_reverb_echo{}; + DelayLineBase center_delay_line{}; + std::array<std::array<f32, AudioCommon::I3DL2REVERB_DELAY_LINE_COUNT>, 3> lpf_coefficients{}; + std::array<f32, AudioCommon::I3DL2REVERB_DELAY_LINE_COUNT> shelf_filter{}; + f32 dry_gain{}; +}; + class EffectI3dl2Reverb : public EffectGeneric<I3dl2ReverbParams> { public: explicit EffectI3dl2Reverb(); @@ -237,8 +262,12 @@ public: void Update(EffectInfo::InParams& in_params) override; void UpdateForCommandGeneration() override; + I3dl2ReverbState& GetState(); + const I3dl2ReverbState& GetState() const; + private: bool skipped = false; + I3dl2ReverbState state{}; }; class EffectBiquadFilter : public EffectGeneric<BiquadFilterParams> { diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 263c457cd..b657506b1 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -168,7 +168,6 @@ add_library(common STATIC time_zone.cpp time_zone.h tree.h - uint128.cpp uint128.h uuid.cpp uuid.h diff --git a/src/common/cityhash.cpp b/src/common/cityhash.cpp index 4e1d874b5..66218fc21 100644 --- a/src/common/cityhash.cpp +++ b/src/common/cityhash.cpp @@ -28,8 +28,10 @@ // compromising on hash quality. #include <algorithm> -#include <string.h> // for memcpy and memset -#include "cityhash.h" +#include <cstring> +#include <utility> + +#include "common/cityhash.h" #include "common/swap.h" // #include "config.h" @@ -42,21 +44,17 @@ using namespace std; -typedef uint8_t uint8; -typedef uint32_t uint32; -typedef uint64_t uint64; - namespace Common { -static uint64 UNALIGNED_LOAD64(const char* p) { - uint64 result; - memcpy(&result, p, sizeof(result)); +static u64 unaligned_load64(const char* p) { + u64 result; + std::memcpy(&result, p, sizeof(result)); return result; } -static uint32 UNALIGNED_LOAD32(const char* p) { - uint32 result; - memcpy(&result, p, sizeof(result)); +static u32 unaligned_load32(const char* p) { + u32 result; + std::memcpy(&result, p, sizeof(result)); return result; } @@ -76,64 +74,64 @@ static uint32 UNALIGNED_LOAD32(const char* p) { #endif #endif -static uint64 Fetch64(const char* p) { - return uint64_in_expected_order(UNALIGNED_LOAD64(p)); +static u64 Fetch64(const char* p) { + return uint64_in_expected_order(unaligned_load64(p)); } -static uint32 Fetch32(const char* p) { - return uint32_in_expected_order(UNALIGNED_LOAD32(p)); +static u32 Fetch32(const char* p) { + return uint32_in_expected_order(unaligned_load32(p)); } // Some primes between 2^63 and 2^64 for various uses. -static const uint64 k0 = 0xc3a5c85c97cb3127ULL; -static const uint64 k1 = 0xb492b66fbe98f273ULL; -static const uint64 k2 = 0x9ae16a3b2f90404fULL; +static constexpr u64 k0 = 0xc3a5c85c97cb3127ULL; +static constexpr u64 k1 = 0xb492b66fbe98f273ULL; +static constexpr u64 k2 = 0x9ae16a3b2f90404fULL; // Bitwise right rotate. Normally this will compile to a single // instruction, especially if the shift is a manifest constant. -static uint64 Rotate(uint64 val, int shift) { +static u64 Rotate(u64 val, int shift) { // Avoid shifting by 64: doing so yields an undefined result. return shift == 0 ? val : ((val >> shift) | (val << (64 - shift))); } -static uint64 ShiftMix(uint64 val) { +static u64 ShiftMix(u64 val) { return val ^ (val >> 47); } -static uint64 HashLen16(uint64 u, uint64 v) { - return Hash128to64(uint128(u, v)); +static u64 HashLen16(u64 u, u64 v) { + return Hash128to64(u128{u, v}); } -static uint64 HashLen16(uint64 u, uint64 v, uint64 mul) { +static u64 HashLen16(u64 u, u64 v, u64 mul) { // Murmur-inspired hashing. - uint64 a = (u ^ v) * mul; + u64 a = (u ^ v) * mul; a ^= (a >> 47); - uint64 b = (v ^ a) * mul; + u64 b = (v ^ a) * mul; b ^= (b >> 47); b *= mul; return b; } -static uint64 HashLen0to16(const char* s, std::size_t len) { +static u64 HashLen0to16(const char* s, size_t len) { if (len >= 8) { - uint64 mul = k2 + len * 2; - uint64 a = Fetch64(s) + k2; - uint64 b = Fetch64(s + len - 8); - uint64 c = Rotate(b, 37) * mul + a; - uint64 d = (Rotate(a, 25) + b) * mul; + u64 mul = k2 + len * 2; + u64 a = Fetch64(s) + k2; + u64 b = Fetch64(s + len - 8); + u64 c = Rotate(b, 37) * mul + a; + u64 d = (Rotate(a, 25) + b) * mul; return HashLen16(c, d, mul); } if (len >= 4) { - uint64 mul = k2 + len * 2; - uint64 a = Fetch32(s); + u64 mul = k2 + len * 2; + u64 a = Fetch32(s); return HashLen16(len + (a << 3), Fetch32(s + len - 4), mul); } if (len > 0) { - uint8 a = s[0]; - uint8 b = s[len >> 1]; - uint8 c = s[len - 1]; - uint32 y = static_cast<uint32>(a) + (static_cast<uint32>(b) << 8); - uint32 z = static_cast<uint32>(len) + (static_cast<uint32>(c) << 2); + u8 a = s[0]; + u8 b = s[len >> 1]; + u8 c = s[len - 1]; + u32 y = static_cast<u32>(a) + (static_cast<u32>(b) << 8); + u32 z = static_cast<u32>(len) + (static_cast<u32>(c) << 2); return ShiftMix(y * k2 ^ z * k0) * k2; } return k2; @@ -141,22 +139,21 @@ static uint64 HashLen0to16(const char* s, std::size_t len) { // This probably works well for 16-byte strings as well, but it may be overkill // in that case. -static uint64 HashLen17to32(const char* s, std::size_t len) { - uint64 mul = k2 + len * 2; - uint64 a = Fetch64(s) * k1; - uint64 b = Fetch64(s + 8); - uint64 c = Fetch64(s + len - 8) * mul; - uint64 d = Fetch64(s + len - 16) * k2; +static u64 HashLen17to32(const char* s, size_t len) { + u64 mul = k2 + len * 2; + u64 a = Fetch64(s) * k1; + u64 b = Fetch64(s + 8); + u64 c = Fetch64(s + len - 8) * mul; + u64 d = Fetch64(s + len - 16) * k2; return HashLen16(Rotate(a + b, 43) + Rotate(c, 30) + d, a + Rotate(b + k2, 18) + c, mul); } // Return a 16-byte hash for 48 bytes. Quick and dirty. // Callers do best to use "random-looking" values for a and b. -static pair<uint64, uint64> WeakHashLen32WithSeeds(uint64 w, uint64 x, uint64 y, uint64 z, uint64 a, - uint64 b) { +static pair<u64, u64> WeakHashLen32WithSeeds(u64 w, u64 x, u64 y, u64 z, u64 a, u64 b) { a += w; b = Rotate(b + a + z, 21); - uint64 c = a; + u64 c = a; a += x; a += y; b += Rotate(a, 44); @@ -164,34 +161,34 @@ static pair<uint64, uint64> WeakHashLen32WithSeeds(uint64 w, uint64 x, uint64 y, } // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty. -static pair<uint64, uint64> WeakHashLen32WithSeeds(const char* s, uint64 a, uint64 b) { +static pair<u64, u64> WeakHashLen32WithSeeds(const char* s, u64 a, u64 b) { return WeakHashLen32WithSeeds(Fetch64(s), Fetch64(s + 8), Fetch64(s + 16), Fetch64(s + 24), a, b); } // Return an 8-byte hash for 33 to 64 bytes. -static uint64 HashLen33to64(const char* s, std::size_t len) { - uint64 mul = k2 + len * 2; - uint64 a = Fetch64(s) * k2; - uint64 b = Fetch64(s + 8); - uint64 c = Fetch64(s + len - 24); - uint64 d = Fetch64(s + len - 32); - uint64 e = Fetch64(s + 16) * k2; - uint64 f = Fetch64(s + 24) * 9; - uint64 g = Fetch64(s + len - 8); - uint64 h = Fetch64(s + len - 16) * mul; - uint64 u = Rotate(a + g, 43) + (Rotate(b, 30) + c) * 9; - uint64 v = ((a + g) ^ d) + f + 1; - uint64 w = swap64((u + v) * mul) + h; - uint64 x = Rotate(e + f, 42) + c; - uint64 y = (swap64((v + w) * mul) + g) * mul; - uint64 z = e + f + c; +static u64 HashLen33to64(const char* s, size_t len) { + u64 mul = k2 + len * 2; + u64 a = Fetch64(s) * k2; + u64 b = Fetch64(s + 8); + u64 c = Fetch64(s + len - 24); + u64 d = Fetch64(s + len - 32); + u64 e = Fetch64(s + 16) * k2; + u64 f = Fetch64(s + 24) * 9; + u64 g = Fetch64(s + len - 8); + u64 h = Fetch64(s + len - 16) * mul; + u64 u = Rotate(a + g, 43) + (Rotate(b, 30) + c) * 9; + u64 v = ((a + g) ^ d) + f + 1; + u64 w = swap64((u + v) * mul) + h; + u64 x = Rotate(e + f, 42) + c; + u64 y = (swap64((v + w) * mul) + g) * mul; + u64 z = e + f + c; a = swap64((x + z) * mul + y) + b; b = ShiftMix((z + a) * mul + d + h) * mul; return b + x; } -uint64 CityHash64(const char* s, std::size_t len) { +u64 CityHash64(const char* s, size_t len) { if (len <= 32) { if (len <= 16) { return HashLen0to16(s, len); @@ -204,15 +201,15 @@ uint64 CityHash64(const char* s, std::size_t len) { // For strings over 64 bytes we hash the end first, and then as we // loop we keep 56 bytes of state: v, w, x, y, and z. - uint64 x = Fetch64(s + len - 40); - uint64 y = Fetch64(s + len - 16) + Fetch64(s + len - 56); - uint64 z = HashLen16(Fetch64(s + len - 48) + len, Fetch64(s + len - 24)); - pair<uint64, uint64> v = WeakHashLen32WithSeeds(s + len - 64, len, z); - pair<uint64, uint64> w = WeakHashLen32WithSeeds(s + len - 32, y + k1, x); + u64 x = Fetch64(s + len - 40); + u64 y = Fetch64(s + len - 16) + Fetch64(s + len - 56); + u64 z = HashLen16(Fetch64(s + len - 48) + len, Fetch64(s + len - 24)); + pair<u64, u64> v = WeakHashLen32WithSeeds(s + len - 64, len, z); + pair<u64, u64> w = WeakHashLen32WithSeeds(s + len - 32, y + k1, x); x = x * k1 + Fetch64(s); // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks. - len = (len - 1) & ~static_cast<std::size_t>(63); + len = (len - 1) & ~static_cast<size_t>(63); do { x = Rotate(x + y + v.first + Fetch64(s + 8), 37) * k1; y = Rotate(y + v.second + Fetch64(s + 48), 42) * k1; @@ -229,21 +226,21 @@ uint64 CityHash64(const char* s, std::size_t len) { HashLen16(v.second, w.second) + x); } -uint64 CityHash64WithSeed(const char* s, std::size_t len, uint64 seed) { +u64 CityHash64WithSeed(const char* s, size_t len, u64 seed) { return CityHash64WithSeeds(s, len, k2, seed); } -uint64 CityHash64WithSeeds(const char* s, std::size_t len, uint64 seed0, uint64 seed1) { +u64 CityHash64WithSeeds(const char* s, size_t len, u64 seed0, u64 seed1) { return HashLen16(CityHash64(s, len) - seed0, seed1); } // A subroutine for CityHash128(). Returns a decent 128-bit hash for strings // of any length representable in signed long. Based on City and Murmur. -static uint128 CityMurmur(const char* s, std::size_t len, uint128 seed) { - uint64 a = Uint128Low64(seed); - uint64 b = Uint128High64(seed); - uint64 c = 0; - uint64 d = 0; +static u128 CityMurmur(const char* s, size_t len, u128 seed) { + u64 a = seed[0]; + u64 b = seed[1]; + u64 c = 0; + u64 d = 0; signed long l = static_cast<long>(len) - 16; if (l <= 0) { // len <= 16 a = ShiftMix(a * k1) * k1; @@ -266,20 +263,20 @@ static uint128 CityMurmur(const char* s, std::size_t len, uint128 seed) { } a = HashLen16(a, c); b = HashLen16(d, b); - return uint128(a ^ b, HashLen16(b, a)); + return u128{a ^ b, HashLen16(b, a)}; } -uint128 CityHash128WithSeed(const char* s, std::size_t len, uint128 seed) { +u128 CityHash128WithSeed(const char* s, size_t len, u128 seed) { if (len < 128) { return CityMurmur(s, len, seed); } // We expect len >= 128 to be the common case. Keep 56 bytes of state: // v, w, x, y, and z. - pair<uint64, uint64> v, w; - uint64 x = Uint128Low64(seed); - uint64 y = Uint128High64(seed); - uint64 z = len * k1; + pair<u64, u64> v, w; + u64 x = seed[0]; + u64 y = seed[1]; + u64 z = len * k1; v.first = Rotate(y ^ k1, 49) * k1 + Fetch64(s); v.second = Rotate(v.first, 42) * k1 + Fetch64(s + 8); w.first = Rotate(y + z, 35) * k1 + x; @@ -313,7 +310,7 @@ uint128 CityHash128WithSeed(const char* s, std::size_t len, uint128 seed) { w.first *= 9; v.first *= k0; // If 0 < len < 128, hash up to 4 chunks of 32 bytes each from the end of s. - for (std::size_t tail_done = 0; tail_done < len;) { + for (size_t tail_done = 0; tail_done < len;) { tail_done += 32; y = Rotate(x + y, 42) * k0 + v.second; w.first += Fetch64(s + len - tail_done + 16); @@ -328,13 +325,12 @@ uint128 CityHash128WithSeed(const char* s, std::size_t len, uint128 seed) { // different 56-byte-to-8-byte hashes to get a 16-byte final result. x = HashLen16(x, v.first); y = HashLen16(y + z, w.first); - return uint128(HashLen16(x + v.second, w.second) + y, HashLen16(x + w.second, y + v.second)); + return u128{HashLen16(x + v.second, w.second) + y, HashLen16(x + w.second, y + v.second)}; } -uint128 CityHash128(const char* s, std::size_t len) { - return len >= 16 - ? CityHash128WithSeed(s + 16, len - 16, uint128(Fetch64(s), Fetch64(s + 8) + k0)) - : CityHash128WithSeed(s, len, uint128(k0, k1)); +u128 CityHash128(const char* s, size_t len) { + return len >= 16 ? CityHash128WithSeed(s + 16, len - 16, u128{Fetch64(s), Fetch64(s + 8) + k0}) + : CityHash128WithSeed(s, len, u128{k0, k1}); } } // namespace Common diff --git a/src/common/cityhash.h b/src/common/cityhash.h index a00804e01..022d0f7cb 100644 --- a/src/common/cityhash.h +++ b/src/common/cityhash.h @@ -61,50 +61,38 @@ #pragma once -#include <cstddef> -#include <cstdint> -#include <utility> +#include "common/common_types.h" namespace Common { -using uint128 = std::pair<uint64_t, uint64_t>; - -[[nodiscard]] inline uint64_t Uint128Low64(const uint128& x) { - return x.first; -} -[[nodiscard]] inline uint64_t Uint128High64(const uint128& x) { - return x.second; -} - // Hash function for a byte array. -[[nodiscard]] uint64_t CityHash64(const char* buf, std::size_t len); +[[nodiscard]] u64 CityHash64(const char* buf, size_t len); // Hash function for a byte array. For convenience, a 64-bit seed is also // hashed into the result. -[[nodiscard]] uint64_t CityHash64WithSeed(const char* buf, std::size_t len, uint64_t seed); +[[nodiscard]] u64 CityHash64WithSeed(const char* buf, size_t len, u64 seed); // Hash function for a byte array. For convenience, two seeds are also // hashed into the result. -[[nodiscard]] uint64_t CityHash64WithSeeds(const char* buf, std::size_t len, uint64_t seed0, - uint64_t seed1); +[[nodiscard]] u64 CityHash64WithSeeds(const char* buf, size_t len, u64 seed0, u64 seed1); // Hash function for a byte array. -[[nodiscard]] uint128 CityHash128(const char* s, std::size_t len); +[[nodiscard]] u128 CityHash128(const char* s, size_t len); // Hash function for a byte array. For convenience, a 128-bit seed is also // hashed into the result. -[[nodiscard]] uint128 CityHash128WithSeed(const char* s, std::size_t len, uint128 seed); +[[nodiscard]] u128 CityHash128WithSeed(const char* s, size_t len, u128 seed); // Hash 128 input bits down to 64 bits of output. // This is intended to be a reasonably good hash function. -[[nodiscard]] inline uint64_t Hash128to64(const uint128& x) { +[[nodiscard]] inline u64 Hash128to64(const u128& x) { // Murmur-inspired hashing. - const uint64_t kMul = 0x9ddfea08eb382d69ULL; - uint64_t a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul; + const u64 mul = 0x9ddfea08eb382d69ULL; + u64 a = (x[0] ^ x[1]) * mul; a ^= (a >> 47); - uint64_t b = (Uint128High64(x) ^ a) * kMul; + u64 b = (x[1] ^ a) * mul; b ^= (b >> 47); - b *= kMul; + b *= mul; return b; } diff --git a/src/common/uint128.cpp b/src/common/uint128.cpp deleted file mode 100644 index 16bf7c828..000000000 --- a/src/common/uint128.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2019 yuzu Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#ifdef _MSC_VER -#include <intrin.h> - -#pragma intrinsic(_umul128) -#pragma intrinsic(_udiv128) -#endif -#include <cstring> -#include "common/uint128.h" - -namespace Common { - -#ifdef _MSC_VER - -u64 MultiplyAndDivide64(u64 a, u64 b, u64 d) { - u128 r{}; - r[0] = _umul128(a, b, &r[1]); - u64 remainder; -#if _MSC_VER < 1923 - return udiv128(r[1], r[0], d, &remainder); -#else - return _udiv128(r[1], r[0], d, &remainder); -#endif -} - -#else - -u64 MultiplyAndDivide64(u64 a, u64 b, u64 d) { - const u64 diva = a / d; - const u64 moda = a % d; - const u64 divb = b / d; - const u64 modb = b % d; - return diva * b + moda * divb + moda * modb / d; -} - -#endif - -u128 Multiply64Into128(u64 a, u64 b) { - u128 result; -#ifdef _MSC_VER - result[0] = _umul128(a, b, &result[1]); -#else - unsigned __int128 tmp = a; - tmp *= b; - std::memcpy(&result, &tmp, sizeof(u128)); -#endif - return result; -} - -std::pair<u64, u64> Divide128On32(u128 dividend, u32 divisor) { - u64 remainder = dividend[0] % divisor; - u64 accum = dividend[0] / divisor; - if (dividend[1] == 0) - return {accum, remainder}; - // We ignore dividend[1] / divisor as that overflows - const u64 first_segment = (dividend[1] % divisor) << 32; - accum += (first_segment / divisor) << 32; - const u64 second_segment = (first_segment % divisor) << 32; - accum += (second_segment / divisor); - remainder += second_segment % divisor; - if (remainder >= divisor) { - accum++; - remainder -= divisor; - } - return {accum, remainder}; -} - -} // namespace Common diff --git a/src/common/uint128.h b/src/common/uint128.h index 969259ab6..4780b2f9d 100644 --- a/src/common/uint128.h +++ b/src/common/uint128.h @@ -4,19 +4,118 @@ #pragma once +#include <cstring> #include <utility> + +#ifdef _MSC_VER +#include <intrin.h> +#pragma intrinsic(__umulh) +#pragma intrinsic(_umul128) +#pragma intrinsic(_udiv128) +#else +#include <x86intrin.h> +#endif + #include "common/common_types.h" namespace Common { // This function multiplies 2 u64 values and divides it by a u64 value. -[[nodiscard]] u64 MultiplyAndDivide64(u64 a, u64 b, u64 d); +[[nodiscard]] static inline u64 MultiplyAndDivide64(u64 a, u64 b, u64 d) { +#ifdef _MSC_VER + u128 r{}; + r[0] = _umul128(a, b, &r[1]); + u64 remainder; +#if _MSC_VER < 1923 + return udiv128(r[1], r[0], d, &remainder); +#else + return _udiv128(r[1], r[0], d, &remainder); +#endif +#else + const u64 diva = a / d; + const u64 moda = a % d; + const u64 divb = b / d; + const u64 modb = b % d; + return diva * b + moda * divb + moda * modb / d; +#endif +} // This function multiplies 2 u64 values and produces a u128 value; -[[nodiscard]] u128 Multiply64Into128(u64 a, u64 b); +[[nodiscard]] static inline u128 Multiply64Into128(u64 a, u64 b) { + u128 result; +#ifdef _MSC_VER + result[0] = _umul128(a, b, &result[1]); +#else + unsigned __int128 tmp = a; + tmp *= b; + std::memcpy(&result, &tmp, sizeof(u128)); +#endif + return result; +} + +[[nodiscard]] static inline u64 GetFixedPoint64Factor(u64 numerator, u64 divisor) { +#ifdef __SIZEOF_INT128__ + const auto base = static_cast<unsigned __int128>(numerator) << 64ULL; + return static_cast<u64>(base / divisor); +#elif defined(_M_X64) || defined(_M_ARM64) + std::array<u64, 2> r = {0, numerator}; + u64 remainder; +#if _MSC_VER < 1923 + return udiv128(r[1], r[0], divisor, &remainder); +#else + return _udiv128(r[1], r[0], divisor, &remainder); +#endif +#else + // This one is bit more inaccurate. + return MultiplyAndDivide64(std::numeric_limits<u64>::max(), numerator, divisor); +#endif +} + +[[nodiscard]] static inline u64 MultiplyHigh(u64 a, u64 b) { +#ifdef __SIZEOF_INT128__ + return (static_cast<unsigned __int128>(a) * static_cast<unsigned __int128>(b)) >> 64; +#elif defined(_M_X64) || defined(_M_ARM64) + return __umulh(a, b); // MSVC +#else + // Generic fallback + const u64 a_lo = u32(a); + const u64 a_hi = a >> 32; + const u64 b_lo = u32(b); + const u64 b_hi = b >> 32; + + const u64 a_x_b_hi = a_hi * b_hi; + const u64 a_x_b_mid = a_hi * b_lo; + const u64 b_x_a_mid = b_hi * a_lo; + const u64 a_x_b_lo = a_lo * b_lo; + + const u64 carry_bit = (static_cast<u64>(static_cast<u32>(a_x_b_mid)) + + static_cast<u64>(static_cast<u32>(b_x_a_mid)) + (a_x_b_lo >> 32)) >> + 32; + + const u64 multhi = a_x_b_hi + (a_x_b_mid >> 32) + (b_x_a_mid >> 32) + carry_bit; + + return multhi; +#endif +} // This function divides a u128 by a u32 value and produces two u64 values: // the result of division and the remainder -[[nodiscard]] std::pair<u64, u64> Divide128On32(u128 dividend, u32 divisor); +[[nodiscard]] static inline std::pair<u64, u64> Divide128On32(u128 dividend, u32 divisor) { + u64 remainder = dividend[0] % divisor; + u64 accum = dividend[0] / divisor; + if (dividend[1] == 0) + return {accum, remainder}; + // We ignore dividend[1] / divisor as that overflows + const u64 first_segment = (dividend[1] % divisor) << 32; + accum += (first_segment / divisor) << 32; + const u64 second_segment = (first_segment % divisor) << 32; + accum += (second_segment / divisor); + remainder += second_segment % divisor; + if (remainder >= divisor) { + accum++; + remainder -= divisor; + } + return {accum, remainder}; +} } // namespace Common diff --git a/src/common/wall_clock.cpp b/src/common/wall_clock.cpp index a8c143f85..49830b8ab 100644 --- a/src/common/wall_clock.cpp +++ b/src/common/wall_clock.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <cstdint> + #include "common/uint128.h" #include "common/wall_clock.h" diff --git a/src/common/x64/native_clock.cpp b/src/common/x64/native_clock.cpp index a65f6b832..87de40624 100644 --- a/src/common/x64/native_clock.cpp +++ b/src/common/x64/native_clock.cpp @@ -8,68 +8,10 @@ #include <mutex> #include <thread> -#ifdef _MSC_VER -#include <intrin.h> - -#pragma intrinsic(__umulh) -#pragma intrinsic(_udiv128) -#else -#include <x86intrin.h> -#endif - #include "common/atomic_ops.h" #include "common/uint128.h" #include "common/x64/native_clock.h" -namespace { - -[[nodiscard]] u64 GetFixedPoint64Factor(u64 numerator, u64 divisor) { -#ifdef __SIZEOF_INT128__ - const auto base = static_cast<unsigned __int128>(numerator) << 64ULL; - return static_cast<u64>(base / divisor); -#elif defined(_M_X64) || defined(_M_ARM64) - std::array<u64, 2> r = {0, numerator}; - u64 remainder; -#if _MSC_VER < 1923 - return udiv128(r[1], r[0], divisor, &remainder); -#else - return _udiv128(r[1], r[0], divisor, &remainder); -#endif -#else - // This one is bit more inaccurate. - return MultiplyAndDivide64(std::numeric_limits<u64>::max(), numerator, divisor); -#endif -} - -[[nodiscard]] u64 MultiplyHigh(u64 a, u64 b) { -#ifdef __SIZEOF_INT128__ - return (static_cast<unsigned __int128>(a) * static_cast<unsigned __int128>(b)) >> 64; -#elif defined(_M_X64) || defined(_M_ARM64) - return __umulh(a, b); // MSVC -#else - // Generic fallback - const u64 a_lo = u32(a); - const u64 a_hi = a >> 32; - const u64 b_lo = u32(b); - const u64 b_hi = b >> 32; - - const u64 a_x_b_hi = a_hi * b_hi; - const u64 a_x_b_mid = a_hi * b_lo; - const u64 b_x_a_mid = b_hi * a_lo; - const u64 a_x_b_lo = a_lo * b_lo; - - const u64 carry_bit = (static_cast<u64>(static_cast<u32>(a_x_b_mid)) + - static_cast<u64>(static_cast<u32>(b_x_a_mid)) + (a_x_b_lo >> 32)) >> - 32; - - const u64 multhi = a_x_b_hi + (a_x_b_mid >> 32) + (b_x_a_mid >> 32) + carry_bit; - - return multhi; -#endif -} - -} // namespace - namespace Common { u64 EstimateRDTSCFrequency() { diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e74e6a668..c6bdf72ec 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -19,7 +19,6 @@ add_library(core STATIC core.h core_timing.cpp core_timing.h - core_timing_util.cpp core_timing_util.h cpu_manager.cpp cpu_manager.h @@ -266,6 +265,7 @@ add_library(core STATIC hle/service/am/applets/software_keyboard.h hle/service/am/applets/web_browser.cpp hle/service/am/applets/web_browser.h + hle/service/am/applets/web_types.h hle/service/am/idle.cpp hle/service/am/idle.h hle/service/am/omm.cpp diff --git a/src/core/core.cpp b/src/core/core.cpp index 30f5e1128..de6305e2a 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -308,6 +308,9 @@ struct System::Impl { // Close all CPU/threading state cpu_manager.Shutdown(); + // Release the Time Manager's resources + time_manager.Shutdown(); + // Shutdown kernel and core timing core_timing.Shutdown(); kernel.Shutdown(); diff --git a/src/core/core_timing_util.cpp b/src/core/core_timing_util.cpp deleted file mode 100644 index 8ce8e602e..000000000 --- a/src/core/core_timing_util.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2008 Dolphin Emulator Project / 2017 Citra Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#include "core/core_timing_util.h" - -#include <cinttypes> -#include <limits> -#include "common/logging/log.h" -#include "common/uint128.h" -#include "core/hardware_properties.h" - -namespace Core::Timing { - -constexpr u64 MAX_VALUE_TO_MULTIPLY = std::numeric_limits<s64>::max() / Hardware::BASE_CLOCK_RATE; - -s64 msToCycles(std::chrono::milliseconds ms) { - if (static_cast<u64>(ms.count() / 1000) > MAX_VALUE_TO_MULTIPLY) { - LOG_ERROR(Core_Timing, "Integer overflow, use max value"); - return std::numeric_limits<s64>::max(); - } - if (static_cast<u64>(ms.count()) > MAX_VALUE_TO_MULTIPLY) { - LOG_DEBUG(Core_Timing, "Time very big, do rounding"); - return Hardware::BASE_CLOCK_RATE * (ms.count() / 1000); - } - return (Hardware::BASE_CLOCK_RATE * ms.count()) / 1000; -} - -s64 usToCycles(std::chrono::microseconds us) { - if (static_cast<u64>(us.count() / 1000000) > MAX_VALUE_TO_MULTIPLY) { - LOG_ERROR(Core_Timing, "Integer overflow, use max value"); - return std::numeric_limits<s64>::max(); - } - if (static_cast<u64>(us.count()) > MAX_VALUE_TO_MULTIPLY) { - LOG_DEBUG(Core_Timing, "Time very big, do rounding"); - return Hardware::BASE_CLOCK_RATE * (us.count() / 1000000); - } - return (Hardware::BASE_CLOCK_RATE * us.count()) / 1000000; -} - -s64 nsToCycles(std::chrono::nanoseconds ns) { - const u128 temporal = Common::Multiply64Into128(ns.count(), Hardware::BASE_CLOCK_RATE); - return Common::Divide128On32(temporal, static_cast<u32>(1000000000)).first; -} - -u64 msToClockCycles(std::chrono::milliseconds ns) { - const u128 temp = Common::Multiply64Into128(ns.count(), Hardware::CNTFREQ); - return Common::Divide128On32(temp, 1000).first; -} - -u64 usToClockCycles(std::chrono::microseconds ns) { - const u128 temp = Common::Multiply64Into128(ns.count(), Hardware::CNTFREQ); - return Common::Divide128On32(temp, 1000000).first; -} - -u64 nsToClockCycles(std::chrono::nanoseconds ns) { - const u128 temp = Common::Multiply64Into128(ns.count(), Hardware::CNTFREQ); - return Common::Divide128On32(temp, 1000000000).first; -} - -u64 CpuCyclesToClockCycles(u64 ticks) { - const u128 temporal = Common::Multiply64Into128(ticks, Hardware::CNTFREQ); - return Common::Divide128On32(temporal, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first; -} - -std::chrono::milliseconds CyclesToMs(s64 cycles) { - const u128 temporal = Common::Multiply64Into128(cycles, 1000); - u64 ms = Common::Divide128On32(temporal, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first; - return std::chrono::milliseconds(ms); -} - -std::chrono::nanoseconds CyclesToNs(s64 cycles) { - const u128 temporal = Common::Multiply64Into128(cycles, 1000000000); - u64 ns = Common::Divide128On32(temporal, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first; - return std::chrono::nanoseconds(ns); -} - -std::chrono::microseconds CyclesToUs(s64 cycles) { - const u128 temporal = Common::Multiply64Into128(cycles, 1000000); - u64 us = Common::Divide128On32(temporal, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first; - return std::chrono::microseconds(us); -} - -} // namespace Core::Timing diff --git a/src/core/core_timing_util.h b/src/core/core_timing_util.h index e4a046bf9..14c36a485 100644 --- a/src/core/core_timing_util.h +++ b/src/core/core_timing_util.h @@ -1,24 +1,59 @@ -// Copyright 2008 Dolphin Emulator Project / 2017 Citra Emulator Project -// Licensed under GPLv2+ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version // Refer to the license.txt file included. #pragma once #include <chrono> + #include "common/common_types.h" +#include "core/hardware_properties.h" namespace Core::Timing { -s64 msToCycles(std::chrono::milliseconds ms); -s64 usToCycles(std::chrono::microseconds us); -s64 nsToCycles(std::chrono::nanoseconds ns); -u64 msToClockCycles(std::chrono::milliseconds ns); -u64 usToClockCycles(std::chrono::microseconds ns); -u64 nsToClockCycles(std::chrono::nanoseconds ns); -std::chrono::milliseconds CyclesToMs(s64 cycles); -std::chrono::nanoseconds CyclesToNs(s64 cycles); -std::chrono::microseconds CyclesToUs(s64 cycles); - -u64 CpuCyclesToClockCycles(u64 ticks); +namespace detail { +constexpr u64 CNTFREQ_ADJUSTED = Hardware::CNTFREQ / 1000; +constexpr u64 BASE_CLOCK_RATE_ADJUSTED = Hardware::BASE_CLOCK_RATE / 1000; +} // namespace detail + +[[nodiscard]] constexpr s64 msToCycles(std::chrono::milliseconds ms) { + return ms.count() * detail::BASE_CLOCK_RATE_ADJUSTED; +} + +[[nodiscard]] constexpr s64 usToCycles(std::chrono::microseconds us) { + return us.count() * detail::BASE_CLOCK_RATE_ADJUSTED / 1000; +} + +[[nodiscard]] constexpr s64 nsToCycles(std::chrono::nanoseconds ns) { + return ns.count() * detail::BASE_CLOCK_RATE_ADJUSTED / 1000000; +} + +[[nodiscard]] constexpr u64 msToClockCycles(std::chrono::milliseconds ms) { + return static_cast<u64>(ms.count()) * detail::CNTFREQ_ADJUSTED; +} + +[[nodiscard]] constexpr u64 usToClockCycles(std::chrono::microseconds us) { + return us.count() * detail::CNTFREQ_ADJUSTED / 1000; +} + +[[nodiscard]] constexpr u64 nsToClockCycles(std::chrono::nanoseconds ns) { + return ns.count() * detail::CNTFREQ_ADJUSTED / 1000000; +} + +[[nodiscard]] constexpr u64 CpuCyclesToClockCycles(u64 ticks) { + return ticks * detail::CNTFREQ_ADJUSTED / detail::BASE_CLOCK_RATE_ADJUSTED; +} + +[[nodiscard]] constexpr std::chrono::milliseconds CyclesToMs(s64 cycles) { + return std::chrono::milliseconds(cycles / detail::BASE_CLOCK_RATE_ADJUSTED); +} + +[[nodiscard]] constexpr std::chrono::nanoseconds CyclesToNs(s64 cycles) { + return std::chrono::nanoseconds(cycles * 1000000 / detail::BASE_CLOCK_RATE_ADJUSTED); +} + +[[nodiscard]] constexpr std::chrono::microseconds CyclesToUs(s64 cycles) { + return std::chrono::microseconds(cycles * 1000 / detail::BASE_CLOCK_RATE_ADJUSTED); +} } // namespace Core::Timing diff --git a/src/core/frontend/applets/controller.h b/src/core/frontend/applets/controller.h index dff71d8d9..b0626a0f9 100644 --- a/src/core/frontend/applets/controller.h +++ b/src/core/frontend/applets/controller.h @@ -31,6 +31,7 @@ struct ControllerParameters { bool allow_dual_joycons{}; bool allow_left_joycon{}; bool allow_right_joycon{}; + bool allow_gamecube_controller{}; }; class ControllerApplet { diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index b6e6f115e..39c5182c5 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -101,8 +101,6 @@ struct KernelCore::Impl { current_process = nullptr; - system_resource_limit = nullptr; - global_handle_table.Clear(); preemption_event = nullptr; @@ -111,6 +109,13 @@ struct KernelCore::Impl { exclusive_monitor.reset(); + hid_shared_mem = nullptr; + font_shared_mem = nullptr; + irs_shared_mem = nullptr; + time_shared_mem = nullptr; + + system_resource_limit = nullptr; + // Next host thead ID to use, 0-3 IDs represent core threads, >3 represent others next_host_thread_id = Core::Hardware::NUM_CPU_CORES; } diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index dbf198345..70b9f3824 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -21,6 +21,7 @@ namespace Service::HID { constexpr s32 HID_JOYSTICK_MAX = 0x7fff; +constexpr s32 HID_TRIGGER_MAX = 0x7fff; [[maybe_unused]] constexpr s32 HID_JOYSTICK_MIN = -0x7fff; constexpr std::size_t NPAD_OFFSET = 0x9A00; constexpr u32 BATTERY_FULL = 2; @@ -48,6 +49,8 @@ Controller_NPad::NPadControllerType Controller_NPad::MapSettingsTypeToNPad( return NPadControllerType::JoyRight; case Settings::ControllerType::Handheld: return NPadControllerType::Handheld; + case Settings::ControllerType::GameCube: + return NPadControllerType::GameCube; default: UNREACHABLE(); return NPadControllerType::ProController; @@ -67,6 +70,8 @@ Settings::ControllerType Controller_NPad::MapNPadToSettingsType( return Settings::ControllerType::RightJoycon; case NPadControllerType::Handheld: return Settings::ControllerType::Handheld; + case NPadControllerType::GameCube: + return Settings::ControllerType::GameCube; default: UNREACHABLE(); return Settings::ControllerType::ProController; @@ -209,6 +214,13 @@ void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) { controller.assignment_mode = NpadAssignments::Single; controller.footer_type = AppletFooterUiType::JoyRightHorizontal; break; + case NPadControllerType::GameCube: + controller.style_set.gamecube.Assign(1); + // The GC Controller behaves like a wired Pro Controller + controller.device_type.fullkey.Assign(1); + controller.system_properties.is_vertical.Assign(1); + controller.system_properties.use_plus.Assign(1); + break; case NPadControllerType::Pokeball: controller.style_set.palma.Assign(1); controller.device_type.palma.Assign(1); @@ -259,6 +271,7 @@ void Controller_NPad::OnInit() { style.joycon_right.Assign(1); style.joycon_dual.Assign(1); style.fullkey.Assign(1); + style.gamecube.Assign(1); style.palma.Assign(1); } @@ -339,6 +352,7 @@ void Controller_NPad::RequestPadStateUpdate(u32 npad_id) { auto& pad_state = npad_pad_states[controller_idx].pad_states; auto& lstick_entry = npad_pad_states[controller_idx].l_stick; auto& rstick_entry = npad_pad_states[controller_idx].r_stick; + auto& trigger_entry = npad_trigger_states[controller_idx]; const auto& button_state = buttons[controller_idx]; const auto& analog_state = sticks[controller_idx]; const auto [stick_l_x_f, stick_l_y_f] = @@ -404,6 +418,17 @@ void Controller_NPad::RequestPadStateUpdate(u32 npad_id) { pad_state.left_sl.Assign(button_state[SL - BUTTON_HID_BEGIN]->GetStatus()); pad_state.left_sr.Assign(button_state[SR - BUTTON_HID_BEGIN]->GetStatus()); } + + if (controller_type == NPadControllerType::GameCube) { + trigger_entry.l_analog = static_cast<s32>( + button_state[ZL - BUTTON_HID_BEGIN]->GetStatus() ? HID_TRIGGER_MAX : 0); + trigger_entry.r_analog = static_cast<s32>( + button_state[ZR - BUTTON_HID_BEGIN]->GetStatus() ? HID_TRIGGER_MAX : 0); + pad_state.zl.Assign(false); + pad_state.zr.Assign(button_state[R - BUTTON_HID_BEGIN]->GetStatus()); + pad_state.l.Assign(button_state[ZL - BUTTON_HID_BEGIN]->GetStatus()); + pad_state.r.Assign(button_state[ZR - BUTTON_HID_BEGIN]->GetStatus()); + } } void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, @@ -418,6 +443,11 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* &npad.joy_left_states, &npad.joy_right_states, &npad.palma_states, &npad.system_ext_states}; + // There is the posibility to have more controllers with analog triggers + const std::array<TriggerGeneric*, 1> controller_triggers{ + &npad.gc_trigger_states, + }; + for (auto* main_controller : controller_npads) { main_controller->common.entry_count = 16; main_controller->common.total_entry_count = 17; @@ -435,6 +465,21 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* cur_entry.timestamp2 = cur_entry.timestamp; } + for (auto* analog_trigger : controller_triggers) { + analog_trigger->entry_count = 16; + analog_trigger->total_entry_count = 17; + + const auto& last_entry = analog_trigger->trigger[analog_trigger->last_entry_index]; + + analog_trigger->timestamp = core_timing.GetCPUTicks(); + analog_trigger->last_entry_index = (analog_trigger->last_entry_index + 1) % 17; + + auto& cur_entry = analog_trigger->trigger[analog_trigger->last_entry_index]; + + cur_entry.timestamp = last_entry.timestamp + 1; + cur_entry.timestamp2 = cur_entry.timestamp; + } + const auto& controller_type = connected_controllers[i].type; if (controller_type == NPadControllerType::None || !connected_controllers[i].is_connected) { @@ -444,6 +489,7 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* RequestPadStateUpdate(npad_index); auto& pad_state = npad_pad_states[npad_index]; + auto& trigger_state = npad_trigger_states[npad_index]; auto& main_controller = npad.fullkey_states.npad[npad.fullkey_states.common.last_entry_index]; @@ -456,6 +502,8 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* auto& pokeball_entry = npad.palma_states.npad[npad.palma_states.common.last_entry_index]; auto& libnx_entry = npad.system_ext_states.npad[npad.system_ext_states.common.last_entry_index]; + auto& trigger_entry = + npad.gc_trigger_states.trigger[npad.gc_trigger_states.last_entry_index]; libnx_entry.connection_status.raw = 0; libnx_entry.connection_status.is_connected.Assign(1); @@ -524,6 +572,18 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* libnx_entry.connection_status.is_right_connected.Assign(1); break; + case NPadControllerType::GameCube: + main_controller.connection_status.raw = 0; + main_controller.connection_status.is_connected.Assign(1); + main_controller.connection_status.is_wired.Assign(1); + main_controller.pad.pad_states.raw = pad_state.pad_states.raw; + main_controller.pad.l_stick = pad_state.l_stick; + main_controller.pad.r_stick = pad_state.r_stick; + trigger_entry.l_analog = trigger_state.l_analog; + trigger_entry.r_analog = trigger_state.r_analog; + + libnx_entry.connection_status.is_wired.Assign(1); + break; case NPadControllerType::Pokeball: pokeball_entry.connection_status.raw = 0; pokeball_entry.connection_status.is_connected.Assign(1); @@ -674,6 +734,7 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing right_sixaxis_entry.orientation = motion_devices[1].orientation; } break; + case NPadControllerType::GameCube: case NPadControllerType::Pokeball: break; } @@ -1135,6 +1196,8 @@ bool Controller_NPad::IsControllerSupported(NPadControllerType controller) const return style.joycon_left; case NPadControllerType::JoyRight: return style.joycon_right; + case NPadControllerType::GameCube: + return style.gamecube; case NPadControllerType::Pokeball: return style.palma; default: diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index 48bab988c..bc2e6779d 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h @@ -51,6 +51,7 @@ public: JoyDual, JoyLeft, JoyRight, + GameCube, Pokeball, }; @@ -60,6 +61,7 @@ public: JoyconDual = 5, JoyconLeft = 6, JoyconRight = 7, + GameCube = 8, Pokeball = 9, MaxNpadType = 10, }; @@ -389,6 +391,25 @@ private: }; static_assert(sizeof(SixAxisGeneric) == 0x708, "SixAxisGeneric is an invalid size"); + struct TriggerState { + s64_le timestamp{}; + s64_le timestamp2{}; + s32_le l_analog{}; + s32_le r_analog{}; + }; + static_assert(sizeof(TriggerState) == 0x18, "TriggerState is an invalid size"); + + struct TriggerGeneric { + INSERT_PADDING_BYTES(0x4); + s64_le timestamp; + INSERT_PADDING_BYTES(0x4); + s64_le total_entry_count; + s64_le last_entry_index; + s64_le entry_count; + std::array<TriggerState, 17> trigger{}; + }; + static_assert(sizeof(TriggerGeneric) == 0x1C8, "TriggerGeneric is an invalid size"); + struct NPadSystemProperties { union { s64_le raw{}; @@ -509,7 +530,9 @@ private: AppletFooterUiType footer_type; // nfc_states needs to be checked switchbrew does not match with HW NfcXcdHandle nfc_states; - INSERT_PADDING_BYTES(0xdef); + INSERT_PADDING_BYTES(0x8); // Mutex + TriggerGeneric gc_trigger_states; + INSERT_PADDING_BYTES(0xc1f); }; static_assert(sizeof(NPadEntry) == 0x5000, "NPadEntry is an invalid size"); @@ -560,6 +583,7 @@ private: f32 sixaxis_fusion_parameter2{}; bool sixaxis_at_rest{true}; std::array<ControllerPad, 10> npad_pad_states{}; + std::array<TriggerState, 10> npad_trigger_states{}; bool is_in_lr_assignment_mode{false}; Core::System& system; }; diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp b/src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp index 36970f828..ecba1dba1 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_nvdec.cpp @@ -34,8 +34,7 @@ NvResult nvhost_nvdec::Ioctl1(Ioctl command, const std::vector<u8>& input, case 0xa: { if (command.length == 0x1c) { LOG_INFO(Service_NVDRV, "NVDEC video stream ended"); - Tegra::ChCommandHeaderList cmdlist(1); - cmdlist[0] = Tegra::ChCommandHeader{0xDEADB33F}; + Tegra::ChCommandHeaderList cmdlist{{0xDEADB33F}}; system.GPU().PushCommandBuffer(cmdlist); } return UnmapBuffer(input, output); diff --git a/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp b/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp index 72499654c..70849a9bd 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_vic.cpp @@ -28,8 +28,13 @@ NvResult nvhost_vic::Ioctl1(Ioctl command, const std::vector<u8>& input, std::ve return GetWaitbase(input, output); case 0x9: return MapBuffer(input, output); - case 0xa: + case 0xa: { + if (command.length == 0x1c) { + Tegra::ChCommandHeaderList cmdlist{{0xDEADB33F}}; + system.GPU().PushCommandBuffer(cmdlist); + } return UnmapBuffer(input, output); + } default: break; } diff --git a/src/core/hle/service/time/time_manager.cpp b/src/core/hle/service/time/time_manager.cpp index 858623e2b..1f7309f6b 100644 --- a/src/core/hle/service/time/time_manager.cpp +++ b/src/core/hle/service/time/time_manager.cpp @@ -279,6 +279,10 @@ const SharedMemory& TimeManager::GetSharedMemory() const { return impl->shared_memory; } +void TimeManager::Shutdown() { + impl.reset(); +} + void TimeManager::UpdateLocalSystemClockTime(s64 posix_time) { impl->UpdateLocalSystemClockTime(system, posix_time); } diff --git a/src/core/hle/service/time/time_manager.h b/src/core/hle/service/time/time_manager.h index 993c7c288..4db8cc0e1 100644 --- a/src/core/hle/service/time/time_manager.h +++ b/src/core/hle/service/time/time_manager.h @@ -61,6 +61,8 @@ public: const SharedMemory& GetSharedMemory() const; + void Shutdown(); + void SetupTimeZoneManager(std::string location_name, Clock::SteadyClockTimePoint time_zone_updated_time_point, std::size_t total_location_name_count, u128 time_zone_rule_version, diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp index 67a584d53..b864d26f2 100644 --- a/src/input_common/mouse/mouse_input.cpp +++ b/src/input_common/mouse/mouse_input.cpp @@ -33,11 +33,16 @@ void Mouse::UpdateThread() { info.motion.UpdateOrientation(update_time * 1000); info.tilt_speed = 0; info.data.motion = info.motion.GetMotion(); + if (Settings::values.mouse_panning) { + info.last_mouse_change *= 0.96f; + info.data.axis = {static_cast<int>(16 * info.last_mouse_change.x), + static_cast<int>(16 * -info.last_mouse_change.y)}; + } } if (configuring) { UpdateYuzuSettings(); } - if (mouse_panning_timout++ > 8) { + if (mouse_panning_timout++ > 20) { StopPanning(); } std::this_thread::sleep_for(std::chrono::milliseconds(update_time)); @@ -82,16 +87,27 @@ void Mouse::StopPanning() { void Mouse::MouseMove(int x, int y, int center_x, int center_y) { for (MouseInfo& info : mouse_info) { if (Settings::values.mouse_panning) { - const auto mouse_change = Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y); + auto mouse_change = + (Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>(); mouse_panning_timout = 0; if (mouse_change.y == 0 && mouse_change.x == 0) { continue; } + const auto mouse_change_length = mouse_change.Length(); + if (mouse_change_length < 3.0f) { + mouse_change /= mouse_change_length / 3.0f; + } + + info.last_mouse_change = (info.last_mouse_change * 0.91f) + (mouse_change * 0.09f); + + const auto last_mouse_change_length = info.last_mouse_change.Length(); + if (last_mouse_change_length > 8.0f) { + info.last_mouse_change /= last_mouse_change_length / 8.0f; + } else if (last_mouse_change_length < 1.0f) { + info.last_mouse_change = mouse_change / mouse_change.Length(); + } - info.last_mouse_change = (info.last_mouse_change * 0.8f) + (mouse_change * 0.2f); - info.data.axis = {static_cast<int>(16 * info.last_mouse_change.x), - static_cast<int>(16 * -info.last_mouse_change.y)}; info.tilt_direction = info.last_mouse_change; info.tilt_speed = info.tilt_direction.Normalize() * info.sensitivity; continue; diff --git a/src/input_common/settings.h b/src/input_common/settings.h index 75486554b..a59f5d461 100644 --- a/src/input_common/settings.h +++ b/src/input_common/settings.h @@ -340,6 +340,7 @@ enum class ControllerType { LeftJoycon, RightJoycon, Handheld, + GameCube, }; struct PlayerInput { diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 6a5c18945..4ea0076e9 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -1,5 +1,6 @@ add_executable(tests common/bit_field.cpp + common/cityhash.cpp common/fibers.cpp common/param_package.cpp common/ring_buffer.cpp diff --git a/src/tests/common/cityhash.cpp b/src/tests/common/cityhash.cpp new file mode 100644 index 000000000..7a40b6c4a --- /dev/null +++ b/src/tests/common/cityhash.cpp @@ -0,0 +1,22 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include <catch2/catch.hpp> + +#include "common/cityhash.h" + +constexpr char msg[] = "The blue frogs are singing under the crimson sky.\n" + "It is time to run, Robert."; + +using namespace Common; + +TEST_CASE("CityHash", "[common]") { + // These test results were built against a known good version. + REQUIRE(CityHash64(msg, sizeof(msg)) == 0x92d5c2e9cbfbbc01); + REQUIRE(CityHash64WithSeed(msg, sizeof(msg), 0xdead) == 0xbfbe93f21a2820dd); + REQUIRE(CityHash64WithSeeds(msg, sizeof(msg), 0xbeef, 0xcafe) == 0xb343317955fc8a06); + REQUIRE(CityHash128(msg, sizeof(msg)) == u128{0x98e60d0423747eaa, 0xd8694c5b6fcaede9}); + REQUIRE(CityHash128WithSeed(msg, sizeof(msg), {0xdead, 0xbeef}) == + u128{0xf0307dba81199ebe, 0xd77764e0c4a9eb74}); +} diff --git a/src/video_core/cdma_pusher.cpp b/src/video_core/cdma_pusher.cpp index 33b3c060b..a3fda1094 100644 --- a/src/video_core/cdma_pusher.cpp +++ b/src/video_core/cdma_pusher.cpp @@ -37,59 +37,43 @@ CDmaPusher::CDmaPusher(GPU& gpu_) CDmaPusher::~CDmaPusher() = default; -void CDmaPusher::Push(ChCommandHeaderList&& entries) { - cdma_queue.push(std::move(entries)); -} - -void CDmaPusher::DispatchCalls() { - while (!cdma_queue.empty()) { - Step(); - } -} - -void CDmaPusher::Step() { - const auto entries{cdma_queue.front()}; - cdma_queue.pop(); - - std::vector<u32> values(entries.size()); - std::memcpy(values.data(), entries.data(), entries.size() * sizeof(u32)); - - for (const u32 value : values) { +void CDmaPusher::ProcessEntries(ChCommandHeaderList&& entries) { + for (const auto& value : entries) { if (mask != 0) { const auto lbs = static_cast<u32>(std::countr_zero(mask)); mask &= ~(1U << lbs); - ExecuteCommand(static_cast<u32>(offset + lbs), value); + ExecuteCommand(offset + lbs, value.raw); continue; } else if (count != 0) { --count; - ExecuteCommand(static_cast<u32>(offset), value); + ExecuteCommand(offset, value.raw); if (incrementing) { ++offset; } continue; } - const auto mode = static_cast<ChSubmissionMode>((value >> 28) & 0xf); + const auto mode = value.submission_mode.Value(); switch (mode) { case ChSubmissionMode::SetClass: { - mask = value & 0x3f; - offset = (value >> 16) & 0xfff; - current_class = static_cast<ChClassId>((value >> 6) & 0x3ff); + mask = value.value & 0x3f; + offset = value.method_offset; + current_class = static_cast<ChClassId>((value.value >> 6) & 0x3ff); break; } case ChSubmissionMode::Incrementing: case ChSubmissionMode::NonIncrementing: - count = value & 0xffff; - offset = (value >> 16) & 0xfff; + count = value.value; + offset = value.method_offset; incrementing = mode == ChSubmissionMode::Incrementing; break; case ChSubmissionMode::Mask: - mask = value & 0xffff; - offset = (value >> 16) & 0xfff; + mask = value.value; + offset = value.method_offset; break; case ChSubmissionMode::Immediate: { - const u32 data = value & 0xfff; - offset = (value >> 16) & 0xfff; - ExecuteCommand(static_cast<u32>(offset), data); + const u32 data = value.value & 0xfff; + offset = value.method_offset; + ExecuteCommand(offset, data); break; } default: @@ -102,8 +86,8 @@ void CDmaPusher::Step() { void CDmaPusher::ExecuteCommand(u32 state_offset, u32 data) { switch (current_class) { case ChClassId::NvDec: - ThiStateWrite(nvdec_thi_state, state_offset, {data}); - switch (static_cast<ThiMethod>(state_offset)) { + ThiStateWrite(nvdec_thi_state, offset, data); + switch (static_cast<ThiMethod>(offset)) { case ThiMethod::IncSyncpt: { LOG_DEBUG(Service_NVDRV, "NVDEC Class IncSyncpt Method"); const auto syncpoint_id = static_cast<u32>(data & 0xFF); @@ -120,7 +104,7 @@ void CDmaPusher::ExecuteCommand(u32 state_offset, u32 data) { LOG_DEBUG(Service_NVDRV, "NVDEC method 0x{:X}", static_cast<u32>(nvdec_thi_state.method_0)); nvdec_processor->ProcessMethod(static_cast<Nvdec::Method>(nvdec_thi_state.method_0), - {data}); + data); break; default: break; @@ -144,7 +128,7 @@ void CDmaPusher::ExecuteCommand(u32 state_offset, u32 data) { case ThiMethod::SetMethod1: LOG_DEBUG(Service_NVDRV, "VIC method 0x{:X}, Args=({})", static_cast<u32>(vic_thi_state.method_0), data); - vic_processor->ProcessMethod(static_cast<Vic::Method>(vic_thi_state.method_0), {data}); + vic_processor->ProcessMethod(static_cast<Vic::Method>(vic_thi_state.method_0), data); break; default: break; @@ -153,7 +137,7 @@ void CDmaPusher::ExecuteCommand(u32 state_offset, u32 data) { case ChClassId::Host1x: // This device is mainly for syncpoint synchronization LOG_DEBUG(Service_NVDRV, "Host1X Class Method"); - host1x_processor->ProcessMethod(static_cast<Host1x::Method>(state_offset), {data}); + host1x_processor->ProcessMethod(static_cast<Host1x::Method>(offset), data); break; default: UNIMPLEMENTED_MSG("Current class not implemented {:X}", static_cast<u32>(current_class)); @@ -161,10 +145,9 @@ void CDmaPusher::ExecuteCommand(u32 state_offset, u32 data) { } } -void CDmaPusher::ThiStateWrite(ThiRegisters& state, u32 state_offset, - const std::vector<u32>& arguments) { - u8* const state_offset_ptr = reinterpret_cast<u8*>(&state) + sizeof(u32) * state_offset; - std::memcpy(state_offset_ptr, arguments.data(), sizeof(u32) * arguments.size()); +void CDmaPusher::ThiStateWrite(ThiRegisters& state, u32 state_offset, u32 argument) { + u8* const offset_ptr = reinterpret_cast<u8*>(&state) + sizeof(u32) * state_offset; + std::memcpy(offset_ptr, &argument, sizeof(u32)); } } // namespace Tegra diff --git a/src/video_core/cdma_pusher.h b/src/video_core/cdma_pusher.h index e5f212c1a..1bada44dd 100644 --- a/src/video_core/cdma_pusher.h +++ b/src/video_core/cdma_pusher.h @@ -5,9 +5,7 @@ #pragma once #include <memory> -#include <unordered_map> #include <vector> -#include <queue> #include "common/bit_field.h" #include "common/common_types.h" @@ -16,9 +14,9 @@ namespace Tegra { class GPU; +class Host1x; class Nvdec; class Vic; -class Host1x; enum class ChSubmissionMode : u32 { SetClass = 0, @@ -48,16 +46,10 @@ enum class ChClassId : u32 { NvDec = 0xf0 }; -enum class ChMethod : u32 { - Empty = 0, - SetMethod = 0x10, - SetData = 0x11, -}; - union ChCommandHeader { u32 raw; BitField<0, 16, u32> value; - BitField<16, 12, ChMethod> method_offset; + BitField<16, 12, u32> method_offset; BitField<28, 4, ChSubmissionMode> submission_mode; }; static_assert(sizeof(ChCommandHeader) == sizeof(u32), "ChCommand header is an invalid size"); @@ -99,21 +91,15 @@ public: explicit CDmaPusher(GPU& gpu_); ~CDmaPusher(); - /// Push NVDEC command buffer entries into queue - void Push(ChCommandHeaderList&& entries); - - /// Process queued command buffer entries - void DispatchCalls(); - - /// Process one queue element - void Step(); + /// Process the command entry + void ProcessEntries(ChCommandHeaderList&& entries); +private: /// Invoke command class devices to execute the command based on the current state void ExecuteCommand(u32 state_offset, u32 data); -private: /// Write arguments value to the ThiRegisters member at the specified offset - void ThiStateWrite(ThiRegisters& state, u32 state_offset, const std::vector<u32>& arguments); + void ThiStateWrite(ThiRegisters& state, u32 offset, u32 argument); GPU& gpu; std::shared_ptr<Tegra::Nvdec> nvdec_processor; @@ -124,13 +110,10 @@ private: ThiRegisters vic_thi_state{}; ThiRegisters nvdec_thi_state{}; - s32 count{}; - s32 offset{}; + u32 count{}; + u32 offset{}; u32 mask{}; bool incrementing{}; - - // Queue of command lists to be processed - std::queue<ChCommandHeaderList> cdma_queue; }; } // namespace Tegra diff --git a/src/video_core/command_classes/codecs/codec.cpp b/src/video_core/command_classes/codecs/codec.cpp index 39bc923a5..d02dc6260 100644 --- a/src/video_core/command_classes/codecs/codec.cpp +++ b/src/video_core/command_classes/codecs/codec.cpp @@ -44,8 +44,10 @@ Codec::~Codec() { } void Codec::SetTargetCodec(NvdecCommon::VideoCodec codec) { - LOG_INFO(Service_NVDRV, "NVDEC video codec initialized to {}", codec); - current_codec = codec; + if (current_codec != codec) { + LOG_INFO(Service_NVDRV, "NVDEC video codec initialized to {}", static_cast<u32>(codec)); + current_codec = codec; + } } void Codec::StateWrite(u32 offset, u64 arguments) { @@ -55,7 +57,6 @@ void Codec::StateWrite(u32 offset, u64 arguments) { void Codec::Decode() { bool is_first_frame = false; - if (!initialized) { if (current_codec == NvdecCommon::VideoCodec::H264) { av_codec = avcodec_find_decoder(AV_CODEC_ID_H264); diff --git a/src/video_core/command_classes/nvdec.cpp b/src/video_core/command_classes/nvdec.cpp index 79e1f4e13..e4f919afd 100644 --- a/src/video_core/command_classes/nvdec.cpp +++ b/src/video_core/command_classes/nvdec.cpp @@ -12,16 +12,16 @@ Nvdec::Nvdec(GPU& gpu_) : gpu(gpu_), codec(std::make_unique<Codec>(gpu)) {} Nvdec::~Nvdec() = default; -void Nvdec::ProcessMethod(Method method, const std::vector<u32>& arguments) { +void Nvdec::ProcessMethod(Method method, u32 argument) { if (method == Method::SetVideoCodec) { - codec->StateWrite(static_cast<u32>(method), arguments[0]); + codec->StateWrite(static_cast<u32>(method), argument); } else { - codec->StateWrite(static_cast<u32>(method), static_cast<u64>(arguments[0]) << 8); + codec->StateWrite(static_cast<u32>(method), static_cast<u64>(argument) << 8); } switch (method) { case Method::SetVideoCodec: - codec->SetTargetCodec(static_cast<NvdecCommon::VideoCodec>(arguments[0])); + codec->SetTargetCodec(static_cast<NvdecCommon::VideoCodec>(argument)); break; case Method::Execute: Execute(); diff --git a/src/video_core/command_classes/nvdec.h b/src/video_core/command_classes/nvdec.h index e4877c533..e66be80b8 100644 --- a/src/video_core/command_classes/nvdec.h +++ b/src/video_core/command_classes/nvdec.h @@ -23,7 +23,7 @@ public: ~Nvdec(); /// Writes the method into the state, Invoke Execute() if encountered - void ProcessMethod(Method method, const std::vector<u32>& arguments); + void ProcessMethod(Method method, u32 argument); /// Return most recently decoded frame [[nodiscard]] AVFramePtr GetFrame(); diff --git a/src/video_core/command_classes/vic.cpp b/src/video_core/command_classes/vic.cpp index 2b7569335..0a8b82f2b 100644 --- a/src/video_core/command_classes/vic.cpp +++ b/src/video_core/command_classes/vic.cpp @@ -18,18 +18,14 @@ extern "C" { namespace Tegra { Vic::Vic(GPU& gpu_, std::shared_ptr<Nvdec> nvdec_processor_) - : gpu(gpu_), nvdec_processor(std::move(nvdec_processor_)) {} -Vic::~Vic() = default; + : gpu(gpu_), + nvdec_processor(std::move(nvdec_processor_)), converted_frame_buffer{nullptr, av_free} {} -void Vic::VicStateWrite(u32 offset, u32 arguments) { - u8* const state_offset = reinterpret_cast<u8*>(&vic_state) + offset * sizeof(u32); - std::memcpy(state_offset, &arguments, sizeof(u32)); -} +Vic::~Vic() = default; -void Vic::ProcessMethod(Method method, const std::vector<u32>& arguments) { - LOG_DEBUG(HW_GPU, "Vic method 0x{:X}", method); - VicStateWrite(static_cast<u32>(method), arguments[0]); - const u64 arg = static_cast<u64>(arguments[0]) << 8; +void Vic::ProcessMethod(Method method, u32 argument) { + LOG_DEBUG(HW_GPU, "Vic method 0x{:X}", static_cast<u32>(method)); + const u64 arg = static_cast<u64>(argument) << 8; switch (method) { case Method::Execute: Execute(); @@ -53,8 +49,7 @@ void Vic::ProcessMethod(Method method, const std::vector<u32>& arguments) { void Vic::Execute() { if (output_surface_luma_address == 0) { - LOG_ERROR(Service_NVDRV, "VIC Luma address not set. Received 0x{:X}", - vic_state.output_surface.luma_offset); + LOG_ERROR(Service_NVDRV, "VIC Luma address not set."); return; } const VicConfig config{gpu.MemoryManager().Read<u64>(config_struct_address + 0x20)}; @@ -89,8 +84,10 @@ void Vic::Execute() { // Get Converted frame const std::size_t linear_size = frame->width * frame->height * 4; - using AVMallocPtr = std::unique_ptr<u8, decltype(&av_free)>; - AVMallocPtr converted_frame_buffer{static_cast<u8*>(av_malloc(linear_size)), av_free}; + // Only allocate frame_buffer once per stream, as the size is not expected to change + if (!converted_frame_buffer) { + converted_frame_buffer = AVMallocPtr{static_cast<u8*>(av_malloc(linear_size)), av_free}; + } const int converted_stride{frame->width * 4}; u8* const converted_frame_buf_addr{converted_frame_buffer.get()}; @@ -104,12 +101,12 @@ void Vic::Execute() { const u32 block_height = static_cast<u32>(config.block_linear_height_log2); const auto size = Tegra::Texture::CalculateSize(true, 4, frame->width, frame->height, 1, block_height, 0); - std::vector<u8> swizzled_data(size); + luma_buffer.resize(size); Tegra::Texture::SwizzleSubrect(frame->width, frame->height, frame->width * 4, - frame->width, 4, swizzled_data.data(), + frame->width, 4, luma_buffer.data(), converted_frame_buffer.get(), block_height, 0, 0); - gpu.MemoryManager().WriteBlock(output_surface_luma_address, swizzled_data.data(), size); + gpu.MemoryManager().WriteBlock(output_surface_luma_address, luma_buffer.data(), size); } else { // send pitch linear frame gpu.MemoryManager().WriteBlock(output_surface_luma_address, converted_frame_buf_addr, @@ -132,15 +129,15 @@ void Vic::Execute() { const auto stride = frame->linesize[0]; const auto half_stride = frame->linesize[1]; - std::vector<u8> luma_buffer(aligned_width * surface_height); - std::vector<u8> chroma_buffer(aligned_width * half_height); + luma_buffer.resize(aligned_width * surface_height); + chroma_buffer.resize(aligned_width * half_height); // Populate luma buffer for (std::size_t y = 0; y < surface_height - 1; ++y) { - std::size_t src = y * stride; - std::size_t dst = y * aligned_width; + const std::size_t src = y * stride; + const std::size_t dst = y * aligned_width; - std::size_t size = surface_width; + const std::size_t size = surface_width; for (std::size_t offset = 0; offset < size; ++offset) { luma_buffer[dst + offset] = luma_ptr[src + offset]; @@ -151,8 +148,8 @@ void Vic::Execute() { // Populate chroma buffer from both channels with interleaving. for (std::size_t y = 0; y < half_height; ++y) { - std::size_t src = y * half_stride; - std::size_t dst = y * aligned_width; + const std::size_t src = y * half_stride; + const std::size_t dst = y * aligned_width; for (std::size_t x = 0; x < half_width; ++x) { chroma_buffer[dst + x * 2] = chroma_b_ptr[src + x]; diff --git a/src/video_core/command_classes/vic.h b/src/video_core/command_classes/vic.h index 8c4e284a1..f5a2ed100 100644 --- a/src/video_core/command_classes/vic.h +++ b/src/video_core/command_classes/vic.h @@ -15,43 +15,6 @@ namespace Tegra { class GPU; class Nvdec; -struct PlaneOffsets { - u32 luma_offset{}; - u32 chroma_u_offset{}; - u32 chroma_v_offset{}; -}; - -struct VicRegisters { - INSERT_PADDING_WORDS(64); - u32 nop{}; - INSERT_PADDING_WORDS(15); - u32 pm_trigger{}; - INSERT_PADDING_WORDS(47); - u32 set_application_id{}; - u32 set_watchdog_timer{}; - INSERT_PADDING_WORDS(17); - u32 context_save_area{}; - u32 context_switch{}; - INSERT_PADDING_WORDS(43); - u32 execute{}; - INSERT_PADDING_WORDS(63); - std::array<std::array<PlaneOffsets, 8>, 8> surfacex_slots{}; - u32 picture_index{}; - u32 control_params{}; - u32 config_struct_offset{}; - u32 filter_struct_offset{}; - u32 palette_offset{}; - u32 hist_offset{}; - u32 context_id{}; - u32 fce_ucode_size{}; - PlaneOffsets output_surface{}; - u32 fce_ucode_offset{}; - INSERT_PADDING_WORDS(4); - std::array<u32, 8> slot_context_id{}; - INSERT_PADDING_WORDS(16); -}; -static_assert(sizeof(VicRegisters) == 0x7A0, "VicRegisters is an invalid size"); - class Vic { public: enum class Method : u32 { @@ -67,14 +30,11 @@ public: ~Vic(); /// Write to the device state. - void ProcessMethod(Method method, const std::vector<u32>& arguments); + void ProcessMethod(Method method, u32 argument); private: void Execute(); - void VicStateWrite(u32 offset, u32 arguments); - VicRegisters vic_state{}; - enum class VideoPixelFormat : u64_le { RGBA8 = 0x1f, BGRA8 = 0x20, @@ -88,8 +48,6 @@ private: BitField<9, 2, u64_le> chroma_loc_vert; BitField<11, 4, u64_le> block_linear_kind; BitField<15, 4, u64_le> block_linear_height_log2; - BitField<19, 3, u64_le> reserved0; - BitField<22, 10, u64_le> reserved1; BitField<32, 14, u64_le> surface_width_minus1; BitField<46, 14, u64_le> surface_height_minus1; }; @@ -97,6 +55,13 @@ private: GPU& gpu; std::shared_ptr<Tegra::Nvdec> nvdec_processor; + /// Avoid reallocation of the following buffers every frame, as their + /// size does not change during a stream + using AVMallocPtr = std::unique_ptr<u8, decltype(&av_free)>; + AVMallocPtr converted_frame_buffer; + std::vector<u8> luma_buffer; + std::vector<u8> chroma_buffer; + GPUVAddr config_struct_address{}; GPUVAddr output_surface_luma_address{}; GPUVAddr output_surface_chroma_u_address{}; diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp index 2a9bd4121..51c63af4a 100644 --- a/src/video_core/gpu.cpp +++ b/src/video_core/gpu.cpp @@ -30,8 +30,7 @@ MICROPROFILE_DEFINE(GPU_wait, "GPU", "Wait for the GPU", MP_RGB(128, 128, 192)); GPU::GPU(Core::System& system_, bool is_async_, bool use_nvdec_) : system{system_}, memory_manager{std::make_unique<Tegra::MemoryManager>(system)}, - dma_pusher{std::make_unique<Tegra::DmaPusher>(system, *this)}, - cdma_pusher{std::make_unique<Tegra::CDmaPusher>(*this)}, use_nvdec{use_nvdec_}, + dma_pusher{std::make_unique<Tegra::DmaPusher>(system, *this)}, use_nvdec{use_nvdec_}, maxwell_3d{std::make_unique<Engines::Maxwell3D>(system, *memory_manager)}, fermi_2d{std::make_unique<Engines::Fermi2D>()}, kepler_compute{std::make_unique<Engines::KeplerCompute>(system, *memory_manager)}, @@ -494,8 +493,7 @@ void GPU::PushCommandBuffer(Tegra::ChCommandHeaderList& entries) { // TODO(ameerj): RE proper async nvdec operation // gpu_thread.SubmitCommandBuffer(std::move(entries)); - cdma_pusher->Push(std::move(entries)); - cdma_pusher->DispatchCalls(); + cdma_pusher->ProcessEntries(std::move(entries)); } void GPU::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) { diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cpp index 50319f1d5..eb0e43c0c 100644 --- a/src/video_core/gpu_thread.cpp +++ b/src/video_core/gpu_thread.cpp @@ -48,8 +48,7 @@ static void RunThread(Core::System& system, VideoCore::RendererBase& renderer, dma_pusher.DispatchCalls(); } else if (auto* command_list = std::get_if<SubmitChCommandEntries>(&next.data)) { // NVDEC - cdma_pusher.Push(std::move(command_list->entries)); - cdma_pusher.DispatchCalls(); + cdma_pusher.ProcessEntries(std::move(command_list->entries)); } else if (const auto* data = std::get_if<SwapBuffersCommand>(&next.data)) { renderer.SwapBuffers(data->framebuffer ? &*data->framebuffer : nullptr); } else if (std::holds_alternative<OnCommandListEndCommand>(next.data)) { diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index 529570ff0..5cf7cd151 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp @@ -335,6 +335,10 @@ void ShaderCacheOpenGL::LoadDiskCache(u64 title_id, const std::atomic_bool& stop const VideoCore::DiskResourceLoadCallback& callback) { disk_cache.BindTitleID(title_id); const std::optional transferable = disk_cache.LoadTransferable(); + + LOG_INFO(Render_OpenGL, "Total Shader Count: {}", + transferable.has_value() ? transferable->size() : 0); + if (!transferable) { return; } diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp index 5be6dabd9..362278f01 100644 --- a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp +++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp @@ -12,14 +12,15 @@ #include "common/cityhash.h" #include "common/common_types.h" #include "video_core/renderer_vulkan/fixed_pipeline_state.h" +#include "video_core/renderer_vulkan/vk_state_tracker.h" namespace Vulkan { namespace { -constexpr std::size_t POINT = 0; -constexpr std::size_t LINE = 1; -constexpr std::size_t POLYGON = 2; +constexpr size_t POINT = 0; +constexpr size_t LINE = 1; +constexpr size_t POLYGON = 2; constexpr std::array POLYGON_OFFSET_ENABLE_LUT = { POINT, // Points LINE, // Lines @@ -40,10 +41,14 @@ constexpr std::array POLYGON_OFFSET_ENABLE_LUT = { } // Anonymous namespace -void FixedPipelineState::Fill(const Maxwell& regs, bool has_extended_dynamic_state) { - const std::array enabled_lut = {regs.polygon_offset_point_enable, - regs.polygon_offset_line_enable, - regs.polygon_offset_fill_enable}; +void FixedPipelineState::Refresh(Tegra::Engines::Maxwell3D& maxwell3d, + bool has_extended_dynamic_state) { + const Maxwell& regs = maxwell3d.regs; + const std::array enabled_lut{ + regs.polygon_offset_point_enable, + regs.polygon_offset_line_enable, + regs.polygon_offset_fill_enable, + }; const u32 topology_index = static_cast<u32>(regs.draw.topology.Value()); raw1 = 0; @@ -64,45 +69,53 @@ void FixedPipelineState::Fill(const Maxwell& regs, bool has_extended_dynamic_sta raw2 = 0; const auto test_func = - regs.alpha_test_enabled == 1 ? regs.alpha_test_func : Maxwell::ComparisonOp::Always; + regs.alpha_test_enabled != 0 ? regs.alpha_test_func : Maxwell::ComparisonOp::Always; alpha_test_func.Assign(PackComparisonOp(test_func)); early_z.Assign(regs.force_early_fragment_tests != 0 ? 1 : 0); alpha_test_ref = Common::BitCast<u32>(regs.alpha_test_ref); point_size = Common::BitCast<u32>(regs.point_size); - for (std::size_t index = 0; index < Maxwell::NumVertexArrays; ++index) { - binding_divisors[index] = - regs.instanced_arrays.IsInstancingEnabled(index) ? regs.vertex_array[index].divisor : 0; + if (maxwell3d.dirty.flags[Dirty::InstanceDivisors]) { + maxwell3d.dirty.flags[Dirty::InstanceDivisors] = false; + for (size_t index = 0; index < Maxwell::NumVertexArrays; ++index) { + const bool is_enabled = regs.instanced_arrays.IsInstancingEnabled(index); + binding_divisors[index] = is_enabled ? regs.vertex_array[index].divisor : 0; + } } - - for (size_t index = 0; index < Maxwell::NumVertexAttributes; ++index) { - const auto& input = regs.vertex_attrib_format[index]; - auto& attribute = attributes[index]; - attribute.raw = 0; - attribute.enabled.Assign(input.IsConstant() ? 0 : 1); - attribute.buffer.Assign(input.buffer); - attribute.offset.Assign(input.offset); - attribute.type.Assign(static_cast<u32>(input.type.Value())); - attribute.size.Assign(static_cast<u32>(input.size.Value())); - attribute.binding_index_enabled.Assign(regs.vertex_array[index].IsEnabled() ? 1 : 0); + if (maxwell3d.dirty.flags[Dirty::VertexAttributes]) { + maxwell3d.dirty.flags[Dirty::VertexAttributes] = false; + for (size_t index = 0; index < Maxwell::NumVertexAttributes; ++index) { + const auto& input = regs.vertex_attrib_format[index]; + auto& attribute = attributes[index]; + attribute.raw = 0; + attribute.enabled.Assign(input.IsConstant() ? 0 : 1); + attribute.buffer.Assign(input.buffer); + attribute.offset.Assign(input.offset); + attribute.type.Assign(static_cast<u32>(input.type.Value())); + attribute.size.Assign(static_cast<u32>(input.size.Value())); + } } - - for (std::size_t index = 0; index < std::size(attachments); ++index) { - attachments[index].Fill(regs, index); + if (maxwell3d.dirty.flags[Dirty::Blending]) { + maxwell3d.dirty.flags[Dirty::Blending] = false; + for (size_t index = 0; index < attachments.size(); ++index) { + attachments[index].Refresh(regs, index); + } + } + if (maxwell3d.dirty.flags[Dirty::ViewportSwizzles]) { + maxwell3d.dirty.flags[Dirty::ViewportSwizzles] = false; + const auto& transform = regs.viewport_transform; + std::ranges::transform(transform, viewport_swizzles.begin(), [](const auto& viewport) { + return static_cast<u16>(viewport.swizzle.raw); + }); } - - const auto& transform = regs.viewport_transform; - std::transform(transform.begin(), transform.end(), viewport_swizzles.begin(), - [](const auto& viewport) { return static_cast<u16>(viewport.swizzle.raw); }); - if (!has_extended_dynamic_state) { no_extended_dynamic_state.Assign(1); - dynamic_state.Fill(regs); + dynamic_state.Refresh(regs); } } -void FixedPipelineState::BlendingAttachment::Fill(const Maxwell& regs, std::size_t index) { +void FixedPipelineState::BlendingAttachment::Refresh(const Maxwell& regs, size_t index) { const auto& mask = regs.color_mask[regs.color_mask_common ? 0 : index]; raw = 0; @@ -141,7 +154,7 @@ void FixedPipelineState::BlendingAttachment::Fill(const Maxwell& regs, std::size enable.Assign(1); } -void FixedPipelineState::DynamicState::Fill(const Maxwell& regs) { +void FixedPipelineState::DynamicState::Refresh(const Maxwell& regs) { u32 packed_front_face = PackFrontFace(regs.front_face); if (regs.screen_y_control.triangle_rast_flip != 0) { // Flip front face @@ -178,9 +191,9 @@ void FixedPipelineState::DynamicState::Fill(const Maxwell& regs) { }); } -std::size_t FixedPipelineState::Hash() const noexcept { +size_t FixedPipelineState::Hash() const noexcept { const u64 hash = Common::CityHash64(reinterpret_cast<const char*>(this), Size()); - return static_cast<std::size_t>(hash); + return static_cast<size_t>(hash); } bool FixedPipelineState::operator==(const FixedPipelineState& rhs) const noexcept { diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.h b/src/video_core/renderer_vulkan/fixed_pipeline_state.h index 465a55fdb..a0eb83a68 100644 --- a/src/video_core/renderer_vulkan/fixed_pipeline_state.h +++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.h @@ -58,7 +58,7 @@ struct FixedPipelineState { BitField<30, 1, u32> enable; }; - void Fill(const Maxwell& regs, std::size_t index); + void Refresh(const Maxwell& regs, size_t index); constexpr std::array<bool, 4> Mask() const noexcept { return {mask_r != 0, mask_g != 0, mask_b != 0, mask_a != 0}; @@ -96,8 +96,6 @@ struct FixedPipelineState { BitField<6, 14, u32> offset; BitField<20, 3, u32> type; BitField<23, 6, u32> size; - // Not really an element of a vertex attribute, but it can be packed here - BitField<29, 1, u32> binding_index_enabled; constexpr Maxwell::VertexAttribute::Type Type() const noexcept { return static_cast<Maxwell::VertexAttribute::Type>(type.Value()); @@ -108,7 +106,7 @@ struct FixedPipelineState { } }; - template <std::size_t Position> + template <size_t Position> union StencilFace { BitField<Position + 0, 3, u32> action_stencil_fail; BitField<Position + 3, 3, u32> action_depth_fail; @@ -152,7 +150,7 @@ struct FixedPipelineState { // Vertex stride is a 12 bits value, we have 4 bits to spare per element std::array<u16, Maxwell::NumVertexArrays> vertex_strides; - void Fill(const Maxwell& regs); + void Refresh(const Maxwell& regs); Maxwell::ComparisonOp DepthTestFunc() const noexcept { return UnpackComparisonOp(depth_test_func); @@ -199,9 +197,9 @@ struct FixedPipelineState { std::array<u16, Maxwell::NumViewports> viewport_swizzles; DynamicState dynamic_state; - void Fill(const Maxwell& regs, bool has_extended_dynamic_state); + void Refresh(Tegra::Engines::Maxwell3D& maxwell3d, bool has_extended_dynamic_state); - std::size_t Hash() const noexcept; + size_t Hash() const noexcept; bool operator==(const FixedPipelineState& rhs) const noexcept; @@ -209,8 +207,8 @@ struct FixedPipelineState { return !operator==(rhs); } - std::size_t Size() const noexcept { - const std::size_t total_size = sizeof *this; + size_t Size() const noexcept { + const size_t total_size = sizeof *this; return total_size - (no_extended_dynamic_state != 0 ? 0 : sizeof(DynamicState)); } }; @@ -224,7 +222,7 @@ namespace std { template <> struct hash<Vulkan::FixedPipelineState> { - std::size_t operator()(const Vulkan::FixedPipelineState& k) const noexcept { + size_t operator()(const Vulkan::FixedPipelineState& k) const noexcept { return k.Hash(); } }; diff --git a/src/video_core/renderer_vulkan/vk_buffer_cache.cpp b/src/video_core/renderer_vulkan/vk_buffer_cache.cpp index 848eedd66..668633e7b 100644 --- a/src/video_core/renderer_vulkan/vk_buffer_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_buffer_cache.cpp @@ -201,10 +201,6 @@ void BufferCacheRuntime::BindTransformFeedbackBuffer(u32 index, VkBuffer buffer, }); } -void BufferCacheRuntime::BindBuffer(VkBuffer buffer, u32 offset, u32 size) { - update_descriptor_queue.AddBuffer(buffer, offset, size); -} - void BufferCacheRuntime::ReserveQuadArrayLUT(u32 num_indices, bool wait_for_idle) { if (num_indices <= current_num_indices) { return; diff --git a/src/video_core/renderer_vulkan/vk_buffer_cache.h b/src/video_core/renderer_vulkan/vk_buffer_cache.h index 041e6515c..982e92191 100644 --- a/src/video_core/renderer_vulkan/vk_buffer_cache.h +++ b/src/video_core/renderer_vulkan/vk_buffer_cache.h @@ -8,6 +8,7 @@ #include "video_core/engines/maxwell_3d.h" #include "video_core/renderer_vulkan/vk_compute_pass.h" #include "video_core/renderer_vulkan/vk_staging_buffer_pool.h" +#include "video_core/renderer_vulkan/vk_update_descriptor.h" #include "video_core/vulkan_common/vulkan_memory_allocator.h" #include "video_core/vulkan_common/vulkan_wrapper.h" @@ -16,7 +17,6 @@ namespace Vulkan { class Device; class VKDescriptorPool; class VKScheduler; -class VKUpdateDescriptorQueue; class BufferCacheRuntime; @@ -86,7 +86,9 @@ public: } private: - void BindBuffer(VkBuffer buffer, u32 offset, u32 size); + void BindBuffer(VkBuffer buffer, u32 offset, u32 size) { + update_descriptor_queue.AddBuffer(buffer, offset, size); + } void ReserveQuadArrayLUT(u32 num_indices, bool wait_for_idle); diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp index d50dca604..fc6dd83eb 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp @@ -221,9 +221,6 @@ vk::Pipeline VKGraphicsPipeline::CreatePipeline(const SPIRVProgram& program, std::vector<VkVertexInputBindingDescription> vertex_bindings; std::vector<VkVertexInputBindingDivisorDescriptionEXT> vertex_binding_divisors; for (std::size_t index = 0; index < Maxwell::NumVertexArrays; ++index) { - if (state.attributes[index].binding_index_enabled == 0) { - continue; - } const bool instanced = state.binding_divisors[index] != 0; const auto rate = instanced ? VK_VERTEX_INPUT_RATE_INSTANCE : VK_VERTEX_INPUT_RATE_VERTEX; vertex_bindings.push_back({ diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 684d4e3a6..dfd38f575 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -267,8 +267,7 @@ void RasterizerVulkan::Draw(bool is_indexed, bool is_instanced) { query_cache.UpdateCounters(); - GraphicsPipelineCacheKey key; - key.fixed_state.Fill(maxwell3d.regs, device.IsExtExtendedDynamicStateSupported()); + graphics_key.fixed_state.Refresh(maxwell3d, device.IsExtExtendedDynamicStateSupported()); std::scoped_lock lock{buffer_cache.mutex, texture_cache.mutex}; @@ -276,14 +275,15 @@ void RasterizerVulkan::Draw(bool is_indexed, bool is_instanced) { texture_cache.UpdateRenderTargets(false); const auto shaders = pipeline_cache.GetShaders(); - key.shaders = GetShaderAddresses(shaders); + graphics_key.shaders = GetShaderAddresses(shaders); + SetupShaderDescriptors(shaders, is_indexed); const Framebuffer* const framebuffer = texture_cache.GetFramebuffer(); - key.renderpass = framebuffer->RenderPass(); + graphics_key.renderpass = framebuffer->RenderPass(); - auto* const pipeline = - pipeline_cache.GetGraphicsPipeline(key, framebuffer->NumColorBuffers(), async_shaders); + VKGraphicsPipeline* const pipeline = pipeline_cache.GetGraphicsPipeline( + graphics_key, framebuffer->NumColorBuffers(), async_shaders); if (pipeline == nullptr || pipeline->GetHandle() == VK_NULL_HANDLE) { // Async graphics pipeline was not ready. return; diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.h b/src/video_core/renderer_vulkan/vk_rasterizer.h index 7fc6741da..acea1ba2d 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.h +++ b/src/video_core/renderer_vulkan/vk_rasterizer.h @@ -20,6 +20,7 @@ #include "video_core/renderer_vulkan/vk_buffer_cache.h" #include "video_core/renderer_vulkan/vk_descriptor_pool.h" #include "video_core/renderer_vulkan/vk_fence_manager.h" +#include "video_core/renderer_vulkan/vk_graphics_pipeline.h" #include "video_core/renderer_vulkan/vk_pipeline_cache.h" #include "video_core/renderer_vulkan/vk_query_cache.h" #include "video_core/renderer_vulkan/vk_scheduler.h" @@ -173,6 +174,8 @@ private: VKUpdateDescriptorQueue update_descriptor_queue; BlitImageHelper blit_image; + GraphicsPipelineCacheKey graphics_key; + TextureCacheRuntime texture_cache_runtime; TextureCache texture_cache; BufferCacheRuntime buffer_cache_runtime; diff --git a/src/video_core/renderer_vulkan/vk_state_tracker.cpp b/src/video_core/renderer_vulkan/vk_state_tracker.cpp index e81fad007..956f86845 100644 --- a/src/video_core/renderer_vulkan/vk_state_tracker.cpp +++ b/src/video_core/renderer_vulkan/vk_state_tracker.cpp @@ -18,9 +18,7 @@ #define NUM(field_name) (sizeof(Maxwell3D::Regs::field_name) / (sizeof(u32))) namespace Vulkan { - namespace { - using namespace Dirty; using namespace VideoCommon::Dirty; using Tegra::Engines::Maxwell3D; @@ -128,6 +126,34 @@ void SetupDirtyStencilTestEnable(Tables& tables) { tables[0][OFF(stencil_enable)] = StencilTestEnable; } +void SetupDirtyBlending(Tables& tables) { + tables[0][OFF(color_mask_common)] = Blending; + tables[0][OFF(independent_blend_enable)] = Blending; + FillBlock(tables[0], OFF(color_mask), NUM(color_mask), Blending); + FillBlock(tables[0], OFF(blend), NUM(blend), Blending); + FillBlock(tables[0], OFF(independent_blend), NUM(independent_blend), Blending); +} + +void SetupDirtyInstanceDivisors(Tables& tables) { + static constexpr size_t divisor_offset = 3; + for (size_t index = 0; index < Regs::NumVertexArrays; ++index) { + tables[0][OFF(instanced_arrays) + index] = InstanceDivisors; + tables[0][OFF(vertex_array) + index * NUM(vertex_array[0]) + divisor_offset] = + InstanceDivisors; + } +} + +void SetupDirtyVertexAttributes(Tables& tables) { + FillBlock(tables[0], OFF(vertex_attrib_format), NUM(vertex_attrib_format), VertexAttributes); +} + +void SetupDirtyViewportSwizzles(Tables& tables) { + static constexpr size_t swizzle_offset = 6; + for (size_t index = 0; index < Regs::NumViewports; ++index) { + tables[0][OFF(viewport_transform) + index * NUM(viewport_transform[0]) + swizzle_offset] = + ViewportSwizzles; + } +} } // Anonymous namespace StateTracker::StateTracker(Tegra::GPU& gpu) @@ -148,6 +174,10 @@ StateTracker::StateTracker(Tegra::GPU& gpu) SetupDirtyFrontFace(tables); SetupDirtyStencilOp(tables); SetupDirtyStencilTestEnable(tables); + SetupDirtyBlending(tables); + SetupDirtyInstanceDivisors(tables); + SetupDirtyVertexAttributes(tables); + SetupDirtyViewportSwizzles(tables); } } // namespace Vulkan diff --git a/src/video_core/renderer_vulkan/vk_state_tracker.h b/src/video_core/renderer_vulkan/vk_state_tracker.h index c335d2bdf..84e918a71 100644 --- a/src/video_core/renderer_vulkan/vk_state_tracker.h +++ b/src/video_core/renderer_vulkan/vk_state_tracker.h @@ -35,6 +35,11 @@ enum : u8 { StencilOp, StencilTestEnable, + Blending, + InstanceDivisors, + VertexAttributes, + ViewportSwizzles, + Last }; static_assert(Last <= std::numeric_limits<u8>::max()); diff --git a/src/video_core/renderer_vulkan/vk_update_descriptor.cpp b/src/video_core/renderer_vulkan/vk_update_descriptor.cpp index f99273c6a..dc45fdcb1 100644 --- a/src/video_core/renderer_vulkan/vk_update_descriptor.cpp +++ b/src/video_core/renderer_vulkan/vk_update_descriptor.cpp @@ -20,20 +20,20 @@ VKUpdateDescriptorQueue::VKUpdateDescriptorQueue(const Device& device_, VKSchedu VKUpdateDescriptorQueue::~VKUpdateDescriptorQueue() = default; void VKUpdateDescriptorQueue::TickFrame() { - payload.clear(); + payload_cursor = payload.data(); } void VKUpdateDescriptorQueue::Acquire() { // Minimum number of entries required. // This is the maximum number of entries a single draw call migth use. - static constexpr std::size_t MIN_ENTRIES = 0x400; + static constexpr size_t MIN_ENTRIES = 0x400; - if (payload.size() + MIN_ENTRIES >= payload.max_size()) { + if (std::distance(payload.data(), payload_cursor) + MIN_ENTRIES >= payload.max_size()) { LOG_WARNING(Render_Vulkan, "Payload overflow, waiting for worker thread"); scheduler.WaitWorker(); - payload.clear(); + payload_cursor = payload.data(); } - upload_start = &*payload.end(); + upload_start = payload_cursor; } void VKUpdateDescriptorQueue::Send(VkDescriptorUpdateTemplateKHR update_template, diff --git a/src/video_core/renderer_vulkan/vk_update_descriptor.h b/src/video_core/renderer_vulkan/vk_update_descriptor.h index e214f7195..d35e77c44 100644 --- a/src/video_core/renderer_vulkan/vk_update_descriptor.h +++ b/src/video_core/renderer_vulkan/vk_update_descriptor.h @@ -4,8 +4,7 @@ #pragma once -#include <variant> -#include <boost/container/static_vector.hpp> +#include <array> #include "common/common_types.h" #include "video_core/vulkan_common/vulkan_wrapper.h" @@ -16,13 +15,15 @@ class Device; class VKScheduler; struct DescriptorUpdateEntry { - DescriptorUpdateEntry(VkDescriptorImageInfo image_) : image{image_} {} + struct Empty {}; + DescriptorUpdateEntry() = default; + DescriptorUpdateEntry(VkDescriptorImageInfo image_) : image{image_} {} DescriptorUpdateEntry(VkDescriptorBufferInfo buffer_) : buffer{buffer_} {} - DescriptorUpdateEntry(VkBufferView texel_buffer_) : texel_buffer{texel_buffer_} {} union { + Empty empty{}; VkDescriptorImageInfo image; VkDescriptorBufferInfo buffer; VkBufferView texel_buffer; @@ -41,39 +42,40 @@ public: void Send(VkDescriptorUpdateTemplateKHR update_template, VkDescriptorSet set); void AddSampledImage(VkImageView image_view, VkSampler sampler) { - payload.emplace_back(VkDescriptorImageInfo{ + *(payload_cursor++) = VkDescriptorImageInfo{ .sampler = sampler, .imageView = image_view, .imageLayout = VK_IMAGE_LAYOUT_GENERAL, - }); + }; } void AddImage(VkImageView image_view) { - payload.emplace_back(VkDescriptorImageInfo{ + *(payload_cursor++) = VkDescriptorImageInfo{ .sampler = VK_NULL_HANDLE, .imageView = image_view, .imageLayout = VK_IMAGE_LAYOUT_GENERAL, - }); + }; } - void AddBuffer(VkBuffer buffer, u64 offset, size_t size) { - payload.emplace_back(VkDescriptorBufferInfo{ + void AddBuffer(VkBuffer buffer, VkDeviceSize offset, VkDeviceSize size) { + *(payload_cursor++) = VkDescriptorBufferInfo{ .buffer = buffer, .offset = offset, .range = size, - }); + }; } void AddTexelBuffer(VkBufferView texel_buffer) { - payload.emplace_back(texel_buffer); + *(payload_cursor++) = texel_buffer; } private: const Device& device; VKScheduler& scheduler; + DescriptorUpdateEntry* payload_cursor = nullptr; const DescriptorUpdateEntry* upload_start = nullptr; - boost::container::static_vector<DescriptorUpdateEntry, 0x10000> payload; + std::array<DescriptorUpdateEntry, 0x10000> payload; }; } // namespace Vulkan diff --git a/src/yuzu/applets/controller.cpp b/src/yuzu/applets/controller.cpp index c680fd2c2..b92cd6886 100644 --- a/src/yuzu/applets/controller.cpp +++ b/src/yuzu/applets/controller.cpp @@ -67,6 +67,8 @@ bool IsControllerCompatible(Settings::ControllerType controller_type, return parameters.allow_right_joycon; case Settings::ControllerType::Handheld: return parameters.enable_single_mode && parameters.allow_handheld; + case Settings::ControllerType::GameCube: + return parameters.allow_gamecube_controller; default: return false; } @@ -370,7 +372,7 @@ void QtControllerSelectorDialog::SetSupportedControllers() { QStringLiteral("image: url(:/controller/applet_joycon_right%0_disabled); ").arg(theme)); } - if (parameters.allow_pro_controller) { + if (parameters.allow_pro_controller || parameters.allow_gamecube_controller) { ui->controllerSupported5->setStyleSheet( QStringLiteral("image: url(:/controller/applet_pro_controller%0); ").arg(theme)); } else { @@ -420,6 +422,10 @@ void QtControllerSelectorDialog::SetEmulatedControllers(std::size_t player_index Settings::ControllerType::Handheld); emulated_controllers[player_index]->addItem(tr("Handheld")); } + + pairs.emplace_back(emulated_controllers[player_index]->count(), + Settings::ControllerType::GameCube); + emulated_controllers[player_index]->addItem(tr("GameCube Controller")); } Settings::ControllerType QtControllerSelectorDialog::GetControllerTypeFromIndex( @@ -461,6 +467,7 @@ void QtControllerSelectorDialog::UpdateControllerIcon(std::size_t player_index) switch (GetControllerTypeFromIndex(emulated_controllers[player_index]->currentIndex(), player_index)) { case Settings::ControllerType::ProController: + case Settings::ControllerType::GameCube: return QStringLiteral("image: url(:/controller/applet_pro_controller%0); "); case Settings::ControllerType::DualJoyconDetached: return QStringLiteral("image: url(:/controller/applet_dual_joycon%0); "); diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 0635d13d0..3d6f64300 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -614,12 +614,6 @@ void Config::ReadDataStorageValues() { QString::fromStdString(FS::GetUserPath(FS::UserPath::DumpDir))) .toString() .toStdString()); - FS::GetUserPath(FS::UserPath::CacheDir, - qt_config - ->value(QStringLiteral("cache_directory"), - QString::fromStdString(FS::GetUserPath(FS::UserPath::CacheDir))) - .toString() - .toStdString()); Settings::values.gamecard_inserted = ReadSetting(QStringLiteral("gamecard_inserted"), false).toBool(); Settings::values.gamecard_current_game = @@ -1218,9 +1212,6 @@ void Config::SaveDataStorageValues() { WriteSetting(QStringLiteral("dump_directory"), QString::fromStdString(FS::GetUserPath(FS::UserPath::DumpDir)), QString::fromStdString(FS::GetUserPath(FS::UserPath::DumpDir))); - WriteSetting(QStringLiteral("cache_directory"), - QString::fromStdString(FS::GetUserPath(FS::UserPath::CacheDir)), - QString::fromStdString(FS::GetUserPath(FS::UserPath::CacheDir))); WriteSetting(QStringLiteral("gamecard_inserted"), Settings::values.gamecard_inserted, false); WriteSetting(QStringLiteral("gamecard_current_game"), Settings::values.gamecard_current_game, false); diff --git a/src/yuzu/configuration/configure_filesystem.cpp b/src/yuzu/configuration/configure_filesystem.cpp index 7ab4a80f7..bde2d4620 100644 --- a/src/yuzu/configuration/configure_filesystem.cpp +++ b/src/yuzu/configuration/configure_filesystem.cpp @@ -26,8 +26,6 @@ ConfigureFilesystem::ConfigureFilesystem(QWidget* parent) [this] { SetDirectory(DirectoryTarget::Dump, ui->dump_path_edit); }); connect(ui->load_path_button, &QToolButton::pressed, this, [this] { SetDirectory(DirectoryTarget::Load, ui->load_path_edit); }); - connect(ui->cache_directory_button, &QToolButton::pressed, this, - [this] { SetDirectory(DirectoryTarget::Cache, ui->cache_directory_edit); }); connect(ui->reset_game_list_cache, &QPushButton::pressed, this, &ConfigureFilesystem::ResetMetadata); @@ -50,8 +48,6 @@ void ConfigureFilesystem::setConfiguration() { QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::DumpDir))); ui->load_path_edit->setText( QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::LoadDir))); - ui->cache_directory_edit->setText( - QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir))); ui->gamecard_inserted->setChecked(Settings::values.gamecard_inserted); ui->gamecard_current_game->setChecked(Settings::values.gamecard_current_game); @@ -72,9 +68,6 @@ void ConfigureFilesystem::applyConfiguration() { ui->dump_path_edit->text().toStdString()); Common::FS::GetUserPath(Common::FS::UserPath::LoadDir, ui->load_path_edit->text().toStdString()); - Common::FS::GetUserPath(Common::FS::UserPath::CacheDir, - ui->cache_directory_edit->text().toStdString()); - Settings::values.gamecard_path = ui->gamecard_path_edit->text().toStdString(); Settings::values.gamecard_inserted = ui->gamecard_inserted->isChecked(); Settings::values.gamecard_current_game = ui->gamecard_current_game->isChecked(); @@ -103,9 +96,6 @@ void ConfigureFilesystem::SetDirectory(DirectoryTarget target, QLineEdit* edit) case DirectoryTarget::Load: caption = tr("Select Mod Load Directory..."); break; - case DirectoryTarget::Cache: - caption = tr("Select Cache Directory..."); - break; } QString str; diff --git a/src/yuzu/configuration/configure_filesystem.h b/src/yuzu/configuration/configure_filesystem.h index a79303760..2147cd405 100644 --- a/src/yuzu/configuration/configure_filesystem.h +++ b/src/yuzu/configuration/configure_filesystem.h @@ -32,7 +32,6 @@ private: Gamecard, Dump, Load, - Cache, }; void SetDirectory(DirectoryTarget target, QLineEdit* edit); diff --git a/src/yuzu/configuration/configure_filesystem.ui b/src/yuzu/configuration/configure_filesystem.ui index 84bea0600..62b9abc7a 100644 --- a/src/yuzu/configuration/configure_filesystem.ui +++ b/src/yuzu/configuration/configure_filesystem.ui @@ -198,40 +198,7 @@ <string>Caching</string> </property> <layout class="QGridLayout" name="gridLayout_5"> - <item row="0" column="0"> - <widget class="QLabel" name="label_10"> - <property name="text"> - <string>Cache Directory</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <spacer name="horizontalSpacer_3"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Fixed</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="2"> - <widget class="QLineEdit" name="cache_directory_edit"/> - </item> - <item row="0" column="3"> - <widget class="QToolButton" name="cache_directory_button"> - <property name="text"> - <string>...</string> - </property> - </widget> - </item> - <item row="1" column="0" colspan="4"> + <item row="0" column="0" colspan="2"> <layout class="QHBoxLayout" name="horizontalLayout_2"> <item> <widget class="QCheckBox" name="cache_game_list"> diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index c9d19c948..21d0d3449 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp @@ -467,10 +467,14 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i UpdateControllerIcon(); UpdateControllerAvailableButtons(); + UpdateControllerEnabledButtons(); + UpdateControllerButtonNames(); UpdateMotionButtons(); connect(ui->comboControllerType, qOverload<int>(&QComboBox::currentIndexChanged), [this](int) { UpdateControllerIcon(); UpdateControllerAvailableButtons(); + UpdateControllerEnabledButtons(); + UpdateControllerButtonNames(); UpdateMotionButtons(); }); @@ -558,9 +562,6 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i &ConfigureInputPlayer::SaveProfile); LoadConfiguration(); - - // TODO(wwylele): enable this when we actually emulate it - ui->buttonHome->setEnabled(false); ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param); ui->controllerFrame->SetConnectedStatus(ui->groupConnectedController->isChecked()); } @@ -924,6 +925,12 @@ void ConfigureInputPlayer::SetConnectableControllers() { Settings::ControllerType::Handheld); ui->comboControllerType->addItem(tr("Handheld")); } + + if (enable_all || npad_style_set.gamecube == 1) { + index_controller_type_pairs.emplace_back(ui->comboControllerType->count(), + Settings::ControllerType::GameCube); + ui->comboControllerType->addItem(tr("GameCube Controller")); + } }; Core::System& system{Core::System::GetInstance()}; @@ -1014,7 +1021,7 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() { // List of all the widgets that will be hidden by any of the following layouts that need // "unhidden" after the controller type changes - const std::array<QWidget*, 9> layout_show = { + const std::array<QWidget*, 11> layout_show = { ui->buttonShoulderButtonsSLSR, ui->horizontalSpacerShoulderButtonsWidget, ui->horizontalSpacerShoulderButtonsWidget2, @@ -1024,6 +1031,8 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() { ui->buttonShoulderButtonsRight, ui->buttonMiscButtonsPlusHome, ui->bottomRight, + ui->buttonMiscButtonsMinusGroup, + ui->buttonMiscButtonsScreenshotGroup, }; for (auto* widget : layout_show) { @@ -1056,6 +1065,14 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() { ui->bottomLeft, }; break; + case Settings::ControllerType::GameCube: + layout_hidden = { + ui->buttonShoulderButtonsSLSR, + ui->horizontalSpacerShoulderButtonsWidget2, + ui->buttonMiscButtonsMinusGroup, + ui->buttonMiscButtonsScreenshotGroup, + }; + break; } for (auto* widget : layout_hidden) { @@ -1063,6 +1080,52 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() { } } +void ConfigureInputPlayer::UpdateControllerEnabledButtons() { + auto layout = GetControllerTypeFromIndex(ui->comboControllerType->currentIndex()); + if (debug) { + layout = Settings::ControllerType::ProController; + } + + // List of all the widgets that will be disabled by any of the following layouts that need + // "enabled" after the controller type changes + const std::array<QWidget*, 4> layout_enable = { + ui->buttonHome, + ui->buttonLStickPressedGroup, + ui->groupRStickPressed, + ui->buttonShoulderButtonsButtonLGroup, + }; + + for (auto* widget : layout_enable) { + widget->setEnabled(true); + } + + std::vector<QWidget*> layout_disable; + switch (layout) { + case Settings::ControllerType::ProController: + case Settings::ControllerType::DualJoyconDetached: + case Settings::ControllerType::Handheld: + case Settings::ControllerType::LeftJoycon: + case Settings::ControllerType::RightJoycon: + // TODO(wwylele): enable this when we actually emulate it + layout_disable = { + ui->buttonHome, + }; + break; + case Settings::ControllerType::GameCube: + layout_disable = { + ui->buttonHome, + ui->buttonLStickPressedGroup, + ui->groupRStickPressed, + ui->buttonShoulderButtonsButtonLGroup, + }; + break; + } + + for (auto* widget : layout_disable) { + widget->setEnabled(false); + } +} + void ConfigureInputPlayer::UpdateMotionButtons() { if (debug) { // Motion isn't used with the debug controller, hide both groupboxes. @@ -1085,6 +1148,11 @@ void ConfigureInputPlayer::UpdateMotionButtons() { ui->buttonMotionLeftGroup->hide(); ui->buttonMotionRightGroup->show(); break; + case Settings::ControllerType::GameCube: + // Hide both "Motion 1/2". + ui->buttonMotionLeftGroup->hide(); + ui->buttonMotionRightGroup->hide(); + break; case Settings::ControllerType::DualJoyconDetached: default: // Show both "Motion 1/2". @@ -1094,6 +1162,36 @@ void ConfigureInputPlayer::UpdateMotionButtons() { } } +void ConfigureInputPlayer::UpdateControllerButtonNames() { + auto layout = GetControllerTypeFromIndex(ui->comboControllerType->currentIndex()); + if (debug) { + layout = Settings::ControllerType::ProController; + } + + switch (layout) { + case Settings::ControllerType::ProController: + case Settings::ControllerType::DualJoyconDetached: + case Settings::ControllerType::Handheld: + case Settings::ControllerType::LeftJoycon: + case Settings::ControllerType::RightJoycon: + ui->buttonMiscButtonsPlusGroup->setTitle(tr("Plus")); + ui->buttonShoulderButtonsButtonZLGroup->setTitle(tr("ZL")); + ui->buttonShoulderButtonsZRGroup->setTitle(tr("ZR")); + ui->buttonShoulderButtonsRGroup->setTitle(tr("R")); + ui->LStick->setTitle(tr("Left Stick")); + ui->RStick->setTitle(tr("Right Stick")); + break; + case Settings::ControllerType::GameCube: + ui->buttonMiscButtonsPlusGroup->setTitle(tr("Start / Pause")); + ui->buttonShoulderButtonsButtonZLGroup->setTitle(tr("L")); + ui->buttonShoulderButtonsZRGroup->setTitle(tr("R")); + ui->buttonShoulderButtonsRGroup->setTitle(tr("Z")); + ui->LStick->setTitle(tr("Control Stick")); + ui->RStick->setTitle(tr("C-Stick")); + break; + } +} + void ConfigureInputPlayer::UpdateMappingWithDefaults() { if (ui->comboDevices->currentIndex() == 0) { return; diff --git a/src/yuzu/configuration/configure_input_player.h b/src/yuzu/configuration/configure_input_player.h index da2b89136..efe953fbc 100644 --- a/src/yuzu/configuration/configure_input_player.h +++ b/src/yuzu/configuration/configure_input_player.h @@ -143,9 +143,15 @@ private: /// Hides and disables controller settings based on the current controller type. void UpdateControllerAvailableButtons(); + /// Disables controller settings based on the current controller type. + void UpdateControllerEnabledButtons(); + /// Shows or hides motion groupboxes based on the current controller type. void UpdateMotionButtons(); + /// Alters the button names based on the current controller type. + void UpdateControllerButtonNames(); + /// Gets the default controller mapping for this device and auto configures the input to match. void UpdateMappingWithDefaults(); diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp index 0e8a964d2..61ba91cef 100644 --- a/src/yuzu/configuration/configure_input_player_widget.cpp +++ b/src/yuzu/configuration/configure_input_player_widget.cpp @@ -227,6 +227,9 @@ void PlayerControlPreview::paintEvent(QPaintEvent* event) { case Settings::ControllerType::RightJoycon: DrawRightController(p, center); break; + case Settings::ControllerType::GameCube: + DrawGCController(p, center); + break; case Settings::ControllerType::ProController: default: DrawProController(p, center); diff --git a/src/yuzu/debugger/controller.cpp b/src/yuzu/debugger/controller.cpp index 85724a8f3..2731d948d 100644 --- a/src/yuzu/debugger/controller.cpp +++ b/src/yuzu/debugger/controller.cpp @@ -42,7 +42,7 @@ void ControllerDialog::refreshConfiguration() { QAction* ControllerDialog::toggleViewAction() { if (toggle_view_action == nullptr) { - toggle_view_action = new QAction(windowTitle(), this); + toggle_view_action = new QAction(tr("&Controller P1"), this); toggle_view_action->setCheckable(true); toggle_view_action->setChecked(isVisible()); connect(toggle_view_action, &QAction::toggled, this, &ControllerDialog::setVisible); diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index aa0a9f288..6d8bc5509 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp @@ -329,9 +329,6 @@ void Config::ReadValues() { FS::GetUserPath( FS::UserPath::DumpDir, sdl2_config->Get("Data Storage", "dump_directory", FS::GetUserPath(FS::UserPath::DumpDir))); - FS::GetUserPath(FS::UserPath::CacheDir, - sdl2_config->Get("Data Storage", "cache_directory", - FS::GetUserPath(FS::UserPath::CacheDir))); Settings::values.gamecard_inserted = sdl2_config->GetBoolean("Data Storage", "gamecard_inserted", false); Settings::values.gamecard_current_game = |