diff options
Diffstat (limited to 'src')
48 files changed, 983 insertions, 254 deletions
diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index 82e4850f7..c381dbe1d 100644 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt | |||
| @@ -17,6 +17,8 @@ add_library(audio_core STATIC | |||
| 17 | sink_stream.h | 17 | sink_stream.h |
| 18 | stream.cpp | 18 | stream.cpp |
| 19 | stream.h | 19 | stream.h |
| 20 | time_stretch.cpp | ||
| 21 | time_stretch.h | ||
| 20 | 22 | ||
| 21 | $<$<BOOL:${ENABLE_CUBEB}>:cubeb_sink.cpp cubeb_sink.h> | 23 | $<$<BOOL:${ENABLE_CUBEB}>:cubeb_sink.cpp cubeb_sink.h> |
| 22 | ) | 24 | ) |
| @@ -24,6 +26,7 @@ add_library(audio_core STATIC | |||
| 24 | create_target_directory_groups(audio_core) | 26 | create_target_directory_groups(audio_core) |
| 25 | 27 | ||
| 26 | target_link_libraries(audio_core PUBLIC common core) | 28 | target_link_libraries(audio_core PUBLIC common core) |
| 29 | target_link_libraries(audio_core PRIVATE SoundTouch) | ||
| 27 | 30 | ||
| 28 | if(ENABLE_CUBEB) | 31 | if(ENABLE_CUBEB) |
| 29 | target_link_libraries(audio_core PRIVATE cubeb) | 32 | target_link_libraries(audio_core PRIVATE cubeb) |
diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp index 5a1177d0c..79155a7a0 100644 --- a/src/audio_core/cubeb_sink.cpp +++ b/src/audio_core/cubeb_sink.cpp | |||
| @@ -3,27 +3,23 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <atomic> | ||
| 6 | #include <cstring> | 7 | #include <cstring> |
| 7 | #include <mutex> | ||
| 8 | |||
| 9 | #include "audio_core/cubeb_sink.h" | 8 | #include "audio_core/cubeb_sink.h" |
| 10 | #include "audio_core/stream.h" | 9 | #include "audio_core/stream.h" |
| 10 | #include "audio_core/time_stretch.h" | ||
| 11 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 12 | #include "common/ring_buffer.h" | ||
| 13 | #include "core/settings.h" | ||
| 12 | 14 | ||
| 13 | namespace AudioCore { | 15 | namespace AudioCore { |
| 14 | 16 | ||
| 15 | class SinkStreamImpl final : public SinkStream { | 17 | class CubebSinkStream final : public SinkStream { |
| 16 | public: | 18 | public: |
| 17 | SinkStreamImpl(cubeb* ctx, u32 sample_rate, u32 num_channels_, cubeb_devid output_device, | 19 | CubebSinkStream(cubeb* ctx, u32 sample_rate, u32 num_channels_, cubeb_devid output_device, |
| 18 | const std::string& name) | 20 | const std::string& name) |
| 19 | : ctx{ctx}, num_channels{num_channels_} { | 21 | : ctx{ctx}, num_channels{std::min(num_channels_, 2u)}, time_stretch{sample_rate, |
| 20 | 22 | num_channels} { | |
| 21 | if (num_channels == 6) { | ||
| 22 | // 6-channel audio does not seem to work with cubeb + SDL, so we downsample this to 2 | ||
| 23 | // channel for now | ||
| 24 | is_6_channel = true; | ||
| 25 | num_channels = 2; | ||
| 26 | } | ||
| 27 | 23 | ||
| 28 | cubeb_stream_params params{}; | 24 | cubeb_stream_params params{}; |
| 29 | params.rate = sample_rate; | 25 | params.rate = sample_rate; |
| @@ -38,7 +34,7 @@ public: | |||
| 38 | 34 | ||
| 39 | if (cubeb_stream_init(ctx, &stream_backend, name.c_str(), nullptr, nullptr, output_device, | 35 | if (cubeb_stream_init(ctx, &stream_backend, name.c_str(), nullptr, nullptr, output_device, |
| 40 | ¶ms, std::max(512u, minimum_latency), | 36 | ¶ms, std::max(512u, minimum_latency), |
| 41 | &SinkStreamImpl::DataCallback, &SinkStreamImpl::StateCallback, | 37 | &CubebSinkStream::DataCallback, &CubebSinkStream::StateCallback, |
| 42 | this) != CUBEB_OK) { | 38 | this) != CUBEB_OK) { |
| 43 | LOG_CRITICAL(Audio_Sink, "Error initializing cubeb stream"); | 39 | LOG_CRITICAL(Audio_Sink, "Error initializing cubeb stream"); |
| 44 | return; | 40 | return; |
| @@ -50,7 +46,7 @@ public: | |||
| 50 | } | 46 | } |
| 51 | } | 47 | } |
| 52 | 48 | ||
| 53 | ~SinkStreamImpl() { | 49 | ~CubebSinkStream() { |
| 54 | if (!ctx) { | 50 | if (!ctx) { |
| 55 | return; | 51 | return; |
| 56 | } | 52 | } |
| @@ -62,27 +58,32 @@ public: | |||
| 62 | cubeb_stream_destroy(stream_backend); | 58 | cubeb_stream_destroy(stream_backend); |
| 63 | } | 59 | } |
| 64 | 60 | ||
| 65 | void EnqueueSamples(u32 num_channels, const std::vector<s16>& samples) override { | 61 | void EnqueueSamples(u32 source_num_channels, const std::vector<s16>& samples) override { |
| 66 | if (!ctx) { | 62 | if (source_num_channels > num_channels) { |
| 63 | // Downsample 6 channels to 2 | ||
| 64 | std::vector<s16> buf; | ||
| 65 | buf.reserve(samples.size() * num_channels / source_num_channels); | ||
| 66 | for (size_t i = 0; i < samples.size(); i += source_num_channels) { | ||
| 67 | for (size_t ch = 0; ch < num_channels; ch++) { | ||
| 68 | buf.push_back(samples[i + ch]); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | queue.Push(buf); | ||
| 67 | return; | 72 | return; |
| 68 | } | 73 | } |
| 69 | 74 | ||
| 70 | std::lock_guard lock{queue_mutex}; | 75 | queue.Push(samples); |
| 76 | } | ||
| 71 | 77 | ||
| 72 | queue.reserve(queue.size() + samples.size() * GetNumChannels()); | 78 | size_t SamplesInQueue(u32 num_channels) const override { |
| 79 | if (!ctx) | ||
| 80 | return 0; | ||
| 73 | 81 | ||
| 74 | if (is_6_channel) { | 82 | return queue.Size() / num_channels; |
| 75 | // Downsample 6 channels to 2 | 83 | } |
| 76 | const size_t sample_count_copy_size = samples.size() * 2; | 84 | |
| 77 | queue.reserve(sample_count_copy_size); | 85 | void Flush() override { |
| 78 | for (size_t i = 0; i < samples.size(); i += num_channels) { | 86 | should_flush = true; |
| 79 | queue.push_back(samples[i]); | ||
| 80 | queue.push_back(samples[i + 1]); | ||
| 81 | } | ||
| 82 | } else { | ||
| 83 | // Copy as-is | ||
| 84 | std::copy(samples.begin(), samples.end(), std::back_inserter(queue)); | ||
| 85 | } | ||
| 86 | } | 87 | } |
| 87 | 88 | ||
| 88 | u32 GetNumChannels() const { | 89 | u32 GetNumChannels() const { |
| @@ -95,10 +96,11 @@ private: | |||
| 95 | cubeb* ctx{}; | 96 | cubeb* ctx{}; |
| 96 | cubeb_stream* stream_backend{}; | 97 | cubeb_stream* stream_backend{}; |
| 97 | u32 num_channels{}; | 98 | u32 num_channels{}; |
| 98 | bool is_6_channel{}; | ||
| 99 | 99 | ||
| 100 | std::mutex queue_mutex; | 100 | Common::RingBuffer<s16, 0x10000> queue; |
| 101 | std::vector<s16> queue; | 101 | std::array<s16, 2> last_frame; |
| 102 | std::atomic<bool> should_flush{}; | ||
| 103 | TimeStretcher time_stretch; | ||
| 102 | 104 | ||
| 103 | static long DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer, | 105 | static long DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer, |
| 104 | void* output_buffer, long num_frames); | 106 | void* output_buffer, long num_frames); |
| @@ -144,38 +146,52 @@ CubebSink::~CubebSink() { | |||
| 144 | SinkStream& CubebSink::AcquireSinkStream(u32 sample_rate, u32 num_channels, | 146 | SinkStream& CubebSink::AcquireSinkStream(u32 sample_rate, u32 num_channels, |
| 145 | const std::string& name) { | 147 | const std::string& name) { |
| 146 | sink_streams.push_back( | 148 | sink_streams.push_back( |
| 147 | std::make_unique<SinkStreamImpl>(ctx, sample_rate, num_channels, output_device, name)); | 149 | std::make_unique<CubebSinkStream>(ctx, sample_rate, num_channels, output_device, name)); |
| 148 | return *sink_streams.back(); | 150 | return *sink_streams.back(); |
| 149 | } | 151 | } |
| 150 | 152 | ||
| 151 | long SinkStreamImpl::DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer, | 153 | long CubebSinkStream::DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer, |
| 152 | void* output_buffer, long num_frames) { | 154 | void* output_buffer, long num_frames) { |
| 153 | SinkStreamImpl* impl = static_cast<SinkStreamImpl*>(user_data); | 155 | CubebSinkStream* impl = static_cast<CubebSinkStream*>(user_data); |
| 154 | u8* buffer = reinterpret_cast<u8*>(output_buffer); | 156 | u8* buffer = reinterpret_cast<u8*>(output_buffer); |
| 155 | 157 | ||
| 156 | if (!impl) { | 158 | if (!impl) { |
| 157 | return {}; | 159 | return {}; |
| 158 | } | 160 | } |
| 159 | 161 | ||
| 160 | std::lock_guard lock{impl->queue_mutex}; | 162 | const size_t num_channels = impl->GetNumChannels(); |
| 163 | const size_t samples_to_write = num_channels * num_frames; | ||
| 164 | size_t samples_written; | ||
| 165 | |||
| 166 | if (Settings::values.enable_audio_stretching) { | ||
| 167 | const std::vector<s16> in{impl->queue.Pop()}; | ||
| 168 | const size_t num_in{in.size() / num_channels}; | ||
| 169 | s16* const out{reinterpret_cast<s16*>(buffer)}; | ||
| 170 | const size_t out_frames = impl->time_stretch.Process(in.data(), num_in, out, num_frames); | ||
| 171 | samples_written = out_frames * num_channels; | ||
| 161 | 172 | ||
| 162 | const size_t frames_to_write{ | 173 | if (impl->should_flush) { |
| 163 | std::min(impl->queue.size() / impl->GetNumChannels(), static_cast<size_t>(num_frames))}; | 174 | impl->time_stretch.Flush(); |
| 175 | impl->should_flush = false; | ||
| 176 | } | ||
| 177 | } else { | ||
| 178 | samples_written = impl->queue.Pop(buffer, samples_to_write); | ||
| 179 | } | ||
| 164 | 180 | ||
| 165 | memcpy(buffer, impl->queue.data(), frames_to_write * sizeof(s16) * impl->GetNumChannels()); | 181 | if (samples_written >= num_channels) { |
| 166 | impl->queue.erase(impl->queue.begin(), | 182 | std::memcpy(&impl->last_frame[0], buffer + (samples_written - num_channels) * sizeof(s16), |
| 167 | impl->queue.begin() + frames_to_write * impl->GetNumChannels()); | 183 | num_channels * sizeof(s16)); |
| 184 | } | ||
| 168 | 185 | ||
| 169 | if (frames_to_write < num_frames) { | 186 | // Fill the rest of the frames with last_frame |
| 170 | // Fill the rest of the frames with silence | 187 | for (size_t i = samples_written; i < samples_to_write; i += num_channels) { |
| 171 | memset(buffer + frames_to_write * sizeof(s16) * impl->GetNumChannels(), 0, | 188 | std::memcpy(buffer + i * sizeof(s16), &impl->last_frame[0], num_channels * sizeof(s16)); |
| 172 | (num_frames - frames_to_write) * sizeof(s16) * impl->GetNumChannels()); | ||
| 173 | } | 189 | } |
| 174 | 190 | ||
| 175 | return num_frames; | 191 | return num_frames; |
| 176 | } | 192 | } |
| 177 | 193 | ||
| 178 | void SinkStreamImpl::StateCallback(cubeb_stream* stream, void* user_data, cubeb_state state) {} | 194 | void CubebSinkStream::StateCallback(cubeb_stream* stream, void* user_data, cubeb_state state) {} |
| 179 | 195 | ||
| 180 | std::vector<std::string> ListCubebSinkDevices() { | 196 | std::vector<std::string> ListCubebSinkDevices() { |
| 181 | std::vector<std::string> device_list; | 197 | std::vector<std::string> device_list; |
diff --git a/src/audio_core/null_sink.h b/src/audio_core/null_sink.h index f235d93e5..2ed0c83b6 100644 --- a/src/audio_core/null_sink.h +++ b/src/audio_core/null_sink.h | |||
| @@ -21,6 +21,12 @@ public: | |||
| 21 | private: | 21 | private: |
| 22 | struct NullSinkStreamImpl final : SinkStream { | 22 | struct NullSinkStreamImpl final : SinkStream { |
| 23 | void EnqueueSamples(u32 /*num_channels*/, const std::vector<s16>& /*samples*/) override {} | 23 | void EnqueueSamples(u32 /*num_channels*/, const std::vector<s16>& /*samples*/) override {} |
| 24 | |||
| 25 | size_t SamplesInQueue(u32 /*num_channels*/) const override { | ||
| 26 | return 0; | ||
| 27 | } | ||
| 28 | |||
| 29 | void Flush() override {} | ||
| 24 | } null_sink_stream; | 30 | } null_sink_stream; |
| 25 | }; | 31 | }; |
| 26 | 32 | ||
diff --git a/src/audio_core/sink_stream.h b/src/audio_core/sink_stream.h index 41b6736d8..4309ad094 100644 --- a/src/audio_core/sink_stream.h +++ b/src/audio_core/sink_stream.h | |||
| @@ -25,6 +25,10 @@ public: | |||
| 25 | * @param samples Samples in interleaved stereo PCM16 format. | 25 | * @param samples Samples in interleaved stereo PCM16 format. |
| 26 | */ | 26 | */ |
| 27 | virtual void EnqueueSamples(u32 num_channels, const std::vector<s16>& samples) = 0; | 27 | virtual void EnqueueSamples(u32 num_channels, const std::vector<s16>& samples) = 0; |
| 28 | |||
| 29 | virtual std::size_t SamplesInQueue(u32 num_channels) const = 0; | ||
| 30 | |||
| 31 | virtual void Flush() = 0; | ||
| 28 | }; | 32 | }; |
| 29 | 33 | ||
| 30 | using SinkStreamPtr = std::unique_ptr<SinkStream>; | 34 | using SinkStreamPtr = std::unique_ptr<SinkStream>; |
diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index dbae75d8c..84dcdd98d 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp | |||
| @@ -73,6 +73,7 @@ static void VolumeAdjustSamples(std::vector<s16>& samples) { | |||
| 73 | void Stream::PlayNextBuffer() { | 73 | void Stream::PlayNextBuffer() { |
| 74 | if (!IsPlaying()) { | 74 | if (!IsPlaying()) { |
| 75 | // Ensure we are in playing state before playing the next buffer | 75 | // Ensure we are in playing state before playing the next buffer |
| 76 | sink_stream.Flush(); | ||
| 76 | return; | 77 | return; |
| 77 | } | 78 | } |
| 78 | 79 | ||
| @@ -83,6 +84,7 @@ void Stream::PlayNextBuffer() { | |||
| 83 | 84 | ||
| 84 | if (queued_buffers.empty()) { | 85 | if (queued_buffers.empty()) { |
| 85 | // No queued buffers - we are effectively paused | 86 | // No queued buffers - we are effectively paused |
| 87 | sink_stream.Flush(); | ||
| 86 | return; | 88 | return; |
| 87 | } | 89 | } |
| 88 | 90 | ||
| @@ -90,6 +92,7 @@ void Stream::PlayNextBuffer() { | |||
| 90 | queued_buffers.pop(); | 92 | queued_buffers.pop(); |
| 91 | 93 | ||
| 92 | VolumeAdjustSamples(active_buffer->Samples()); | 94 | VolumeAdjustSamples(active_buffer->Samples()); |
| 95 | |||
| 93 | sink_stream.EnqueueSamples(GetNumChannels(), active_buffer->GetSamples()); | 96 | sink_stream.EnqueueSamples(GetNumChannels(), active_buffer->GetSamples()); |
| 94 | 97 | ||
| 95 | CoreTiming::ScheduleEventThreadsafe(GetBufferReleaseCycles(*active_buffer), release_event, {}); | 98 | CoreTiming::ScheduleEventThreadsafe(GetBufferReleaseCycles(*active_buffer), release_event, {}); |
diff --git a/src/audio_core/time_stretch.cpp b/src/audio_core/time_stretch.cpp new file mode 100644 index 000000000..da094c46b --- /dev/null +++ b/src/audio_core/time_stretch.cpp | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cmath> | ||
| 7 | #include <cstddef> | ||
| 8 | #include "audio_core/time_stretch.h" | ||
| 9 | #include "common/logging/log.h" | ||
| 10 | |||
| 11 | namespace AudioCore { | ||
| 12 | |||
| 13 | TimeStretcher::TimeStretcher(u32 sample_rate, u32 channel_count) | ||
| 14 | : m_sample_rate(sample_rate), m_channel_count(channel_count) { | ||
| 15 | m_sound_touch.setChannels(channel_count); | ||
| 16 | m_sound_touch.setSampleRate(sample_rate); | ||
| 17 | m_sound_touch.setPitch(1.0); | ||
| 18 | m_sound_touch.setTempo(1.0); | ||
| 19 | } | ||
| 20 | |||
| 21 | void TimeStretcher::Clear() { | ||
| 22 | m_sound_touch.clear(); | ||
| 23 | } | ||
| 24 | |||
| 25 | void TimeStretcher::Flush() { | ||
| 26 | m_sound_touch.flush(); | ||
| 27 | } | ||
| 28 | |||
| 29 | size_t TimeStretcher::Process(const s16* in, size_t num_in, s16* out, size_t num_out) { | ||
| 30 | const double time_delta = static_cast<double>(num_out) / m_sample_rate; // seconds | ||
| 31 | |||
| 32 | // We were given actual_samples number of samples, and num_samples were requested from us. | ||
| 33 | double current_ratio = static_cast<double>(num_in) / static_cast<double>(num_out); | ||
| 34 | |||
| 35 | const double max_latency = 1.0; // seconds | ||
| 36 | const double max_backlog = m_sample_rate * max_latency; | ||
| 37 | const double backlog_fullness = m_sound_touch.numSamples() / max_backlog; | ||
| 38 | if (backlog_fullness > 5.0) { | ||
| 39 | // Too many samples in backlog: Don't push anymore on | ||
| 40 | num_in = 0; | ||
| 41 | } | ||
| 42 | |||
| 43 | // We ideally want the backlog to be about 50% full. | ||
| 44 | // This gives some headroom both ways to prevent underflow and overflow. | ||
| 45 | // We tweak current_ratio to encourage this. | ||
| 46 | constexpr double tweak_time_scale = 0.05; // seconds | ||
| 47 | const double tweak_correction = (backlog_fullness - 0.5) * (time_delta / tweak_time_scale); | ||
| 48 | current_ratio *= std::pow(1.0 + 2.0 * tweak_correction, tweak_correction < 0 ? 3.0 : 1.0); | ||
| 49 | |||
| 50 | // This low-pass filter smoothes out variance in the calculated stretch ratio. | ||
| 51 | // The time-scale determines how responsive this filter is. | ||
| 52 | constexpr double lpf_time_scale = 2.0; // seconds | ||
| 53 | const double lpf_gain = 1.0 - std::exp(-time_delta / lpf_time_scale); | ||
| 54 | m_stretch_ratio += lpf_gain * (current_ratio - m_stretch_ratio); | ||
| 55 | |||
| 56 | // Place a lower limit of 5% speed. When a game boots up, there will be | ||
| 57 | // many silence samples. These do not need to be timestretched. | ||
| 58 | m_stretch_ratio = std::max(m_stretch_ratio, 0.05); | ||
| 59 | m_sound_touch.setTempo(m_stretch_ratio); | ||
| 60 | |||
| 61 | LOG_DEBUG(Audio, "{:5}/{:5} ratio:{:0.6f} backlog:{:0.6f}", num_in, num_out, m_stretch_ratio, | ||
| 62 | backlog_fullness); | ||
| 63 | |||
| 64 | m_sound_touch.putSamples(in, num_in); | ||
| 65 | return m_sound_touch.receiveSamples(out, num_out); | ||
| 66 | } | ||
| 67 | |||
| 68 | } // namespace AudioCore | ||
diff --git a/src/audio_core/time_stretch.h b/src/audio_core/time_stretch.h new file mode 100644 index 000000000..7e39e695e --- /dev/null +++ b/src/audio_core/time_stretch.h | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include <cstddef> | ||
| 9 | #include <SoundTouch.h> | ||
| 10 | #include "common/common_types.h" | ||
| 11 | |||
| 12 | namespace AudioCore { | ||
| 13 | |||
| 14 | class TimeStretcher { | ||
| 15 | public: | ||
| 16 | TimeStretcher(u32 sample_rate, u32 channel_count); | ||
| 17 | |||
| 18 | /// @param in Input sample buffer | ||
| 19 | /// @param num_in Number of input frames in `in` | ||
| 20 | /// @param out Output sample buffer | ||
| 21 | /// @param num_out Desired number of output frames in `out` | ||
| 22 | /// @returns Actual number of frames written to `out` | ||
| 23 | size_t Process(const s16* in, size_t num_in, s16* out, size_t num_out); | ||
| 24 | |||
| 25 | void Clear(); | ||
| 26 | |||
| 27 | void Flush(); | ||
| 28 | |||
| 29 | private: | ||
| 30 | u32 m_sample_rate; | ||
| 31 | u32 m_channel_count; | ||
| 32 | soundtouch::SoundTouch m_sound_touch; | ||
| 33 | double m_stretch_ratio = 1.0; | ||
| 34 | }; | ||
| 35 | |||
| 36 | } // namespace AudioCore | ||
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index f41946cc6..6a3f1fe08 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -71,6 +71,7 @@ add_library(common STATIC | |||
| 71 | param_package.cpp | 71 | param_package.cpp |
| 72 | param_package.h | 72 | param_package.h |
| 73 | quaternion.h | 73 | quaternion.h |
| 74 | ring_buffer.h | ||
| 74 | scm_rev.cpp | 75 | scm_rev.cpp |
| 75 | scm_rev.h | 76 | scm_rev.h |
| 76 | scope_exit.h | 77 | scope_exit.h |
diff --git a/src/common/ring_buffer.h b/src/common/ring_buffer.h new file mode 100644 index 000000000..30d934a38 --- /dev/null +++ b/src/common/ring_buffer.h | |||
| @@ -0,0 +1,111 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <algorithm> | ||
| 8 | #include <array> | ||
| 9 | #include <atomic> | ||
| 10 | #include <cstddef> | ||
| 11 | #include <cstring> | ||
| 12 | #include <type_traits> | ||
| 13 | #include <vector> | ||
| 14 | #include "common/common_types.h" | ||
| 15 | |||
| 16 | namespace Common { | ||
| 17 | |||
| 18 | /// SPSC ring buffer | ||
| 19 | /// @tparam T Element type | ||
| 20 | /// @tparam capacity Number of slots in ring buffer | ||
| 21 | /// @tparam granularity Slot size in terms of number of elements | ||
| 22 | template <typename T, size_t capacity, size_t granularity = 1> | ||
| 23 | class RingBuffer { | ||
| 24 | /// A "slot" is made of `granularity` elements of `T`. | ||
| 25 | static constexpr size_t slot_size = granularity * sizeof(T); | ||
| 26 | // T must be safely memcpy-able and have a trivial default constructor. | ||
| 27 | static_assert(std::is_trivial_v<T>); | ||
| 28 | // Ensure capacity is sensible. | ||
| 29 | static_assert(capacity < std::numeric_limits<size_t>::max() / 2 / granularity); | ||
| 30 | static_assert((capacity & (capacity - 1)) == 0, "capacity must be a power of two"); | ||
| 31 | // Ensure lock-free. | ||
| 32 | static_assert(std::atomic<size_t>::is_always_lock_free); | ||
| 33 | |||
| 34 | public: | ||
| 35 | /// Pushes slots into the ring buffer | ||
| 36 | /// @param new_slots Pointer to the slots to push | ||
| 37 | /// @param slot_count Number of slots to push | ||
| 38 | /// @returns The number of slots actually pushed | ||
| 39 | size_t Push(const void* new_slots, size_t slot_count) { | ||
| 40 | const size_t write_index = m_write_index.load(); | ||
| 41 | const size_t slots_free = capacity + m_read_index.load() - write_index; | ||
| 42 | const size_t push_count = std::min(slot_count, slots_free); | ||
| 43 | |||
| 44 | const size_t pos = write_index % capacity; | ||
| 45 | const size_t first_copy = std::min(capacity - pos, push_count); | ||
| 46 | const size_t second_copy = push_count - first_copy; | ||
| 47 | |||
| 48 | const char* in = static_cast<const char*>(new_slots); | ||
| 49 | std::memcpy(m_data.data() + pos * granularity, in, first_copy * slot_size); | ||
| 50 | in += first_copy * slot_size; | ||
| 51 | std::memcpy(m_data.data(), in, second_copy * slot_size); | ||
| 52 | |||
| 53 | m_write_index.store(write_index + push_count); | ||
| 54 | |||
| 55 | return push_count; | ||
| 56 | } | ||
| 57 | |||
| 58 | size_t Push(const std::vector<T>& input) { | ||
| 59 | return Push(input.data(), input.size()); | ||
| 60 | } | ||
| 61 | |||
| 62 | /// Pops slots from the ring buffer | ||
| 63 | /// @param output Where to store the popped slots | ||
| 64 | /// @param max_slots Maximum number of slots to pop | ||
| 65 | /// @returns The number of slots actually popped | ||
| 66 | size_t Pop(void* output, size_t max_slots = ~size_t(0)) { | ||
| 67 | const size_t read_index = m_read_index.load(); | ||
| 68 | const size_t slots_filled = m_write_index.load() - read_index; | ||
| 69 | const size_t pop_count = std::min(slots_filled, max_slots); | ||
| 70 | |||
| 71 | const size_t pos = read_index % capacity; | ||
| 72 | const size_t first_copy = std::min(capacity - pos, pop_count); | ||
| 73 | const size_t second_copy = pop_count - first_copy; | ||
| 74 | |||
| 75 | char* out = static_cast<char*>(output); | ||
| 76 | std::memcpy(out, m_data.data() + pos * granularity, first_copy * slot_size); | ||
| 77 | out += first_copy * slot_size; | ||
| 78 | std::memcpy(out, m_data.data(), second_copy * slot_size); | ||
| 79 | |||
| 80 | m_read_index.store(read_index + pop_count); | ||
| 81 | |||
| 82 | return pop_count; | ||
| 83 | } | ||
| 84 | |||
| 85 | std::vector<T> Pop(size_t max_slots = ~size_t(0)) { | ||
| 86 | std::vector<T> out(std::min(max_slots, capacity) * granularity); | ||
| 87 | const size_t count = Pop(out.data(), out.size() / granularity); | ||
| 88 | out.resize(count * granularity); | ||
| 89 | return out; | ||
| 90 | } | ||
| 91 | |||
| 92 | /// @returns Number of slots used | ||
| 93 | size_t Size() const { | ||
| 94 | return m_write_index.load() - m_read_index.load(); | ||
| 95 | } | ||
| 96 | |||
| 97 | /// @returns Maximum size of ring buffer | ||
| 98 | constexpr size_t Capacity() const { | ||
| 99 | return capacity; | ||
| 100 | } | ||
| 101 | |||
| 102 | private: | ||
| 103 | // It is important to align the below variables for performance reasons: | ||
| 104 | // Having them on the same cache-line would result in false-sharing between them. | ||
| 105 | alignas(128) std::atomic<size_t> m_read_index{0}; | ||
| 106 | alignas(128) std::atomic<size_t> m_write_index{0}; | ||
| 107 | |||
| 108 | std::array<T, granularity * capacity> m_data; | ||
| 109 | }; | ||
| 110 | |||
| 111 | } // namespace Common | ||
diff --git a/src/core/hle/kernel/errors.h b/src/core/hle/kernel/errors.h index 4054d5db6..ad39c8271 100644 --- a/src/core/hle/kernel/errors.h +++ b/src/core/hle/kernel/errors.h | |||
| @@ -21,6 +21,7 @@ enum { | |||
| 21 | HandleTableFull = 105, | 21 | HandleTableFull = 105, |
| 22 | InvalidMemoryState = 106, | 22 | InvalidMemoryState = 106, |
| 23 | InvalidMemoryPermissions = 108, | 23 | InvalidMemoryPermissions = 108, |
| 24 | InvalidThreadPriority = 112, | ||
| 24 | InvalidProcessorId = 113, | 25 | InvalidProcessorId = 113, |
| 25 | InvalidHandle = 114, | 26 | InvalidHandle = 114, |
| 26 | InvalidCombination = 116, | 27 | InvalidCombination = 116, |
| @@ -36,7 +37,7 @@ enum { | |||
| 36 | // WARNING: The kernel is quite inconsistent in it's usage of errors code. Make sure to always | 37 | // WARNING: The kernel is quite inconsistent in it's usage of errors code. Make sure to always |
| 37 | // double check that the code matches before re-using the constant. | 38 | // double check that the code matches before re-using the constant. |
| 38 | 39 | ||
| 39 | // TODO(bunnei): Replace these with correct errors for Switch OS | 40 | // TODO(bunnei): Replace -1 with correct errors for Switch OS |
| 40 | constexpr ResultCode ERR_HANDLE_TABLE_FULL(ErrorModule::Kernel, ErrCodes::HandleTableFull); | 41 | constexpr ResultCode ERR_HANDLE_TABLE_FULL(ErrorModule::Kernel, ErrCodes::HandleTableFull); |
| 41 | constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE(-1); | 42 | constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE(-1); |
| 42 | constexpr ResultCode ERR_PORT_NAME_TOO_LONG(ErrorModule::Kernel, ErrCodes::TooLarge); | 43 | constexpr ResultCode ERR_PORT_NAME_TOO_LONG(ErrorModule::Kernel, ErrCodes::TooLarge); |
| @@ -53,15 +54,16 @@ constexpr ResultCode ERR_INVALID_ADDRESS_STATE(ErrorModule::Kernel, ErrCodes::In | |||
| 53 | constexpr ResultCode ERR_INVALID_MEMORY_PERMISSIONS(ErrorModule::Kernel, | 54 | constexpr ResultCode ERR_INVALID_MEMORY_PERMISSIONS(ErrorModule::Kernel, |
| 54 | ErrCodes::InvalidMemoryPermissions); | 55 | ErrCodes::InvalidMemoryPermissions); |
| 55 | constexpr ResultCode ERR_INVALID_HANDLE(ErrorModule::Kernel, ErrCodes::InvalidHandle); | 56 | constexpr ResultCode ERR_INVALID_HANDLE(ErrorModule::Kernel, ErrCodes::InvalidHandle); |
| 57 | constexpr ResultCode ERR_INVALID_PROCESSOR_ID(ErrorModule::Kernel, ErrCodes::InvalidProcessorId); | ||
| 56 | constexpr ResultCode ERR_INVALID_STATE(ErrorModule::Kernel, ErrCodes::InvalidState); | 58 | constexpr ResultCode ERR_INVALID_STATE(ErrorModule::Kernel, ErrCodes::InvalidState); |
| 59 | constexpr ResultCode ERR_INVALID_THREAD_PRIORITY(ErrorModule::Kernel, | ||
| 60 | ErrCodes::InvalidThreadPriority); | ||
| 57 | constexpr ResultCode ERR_INVALID_POINTER(-1); | 61 | constexpr ResultCode ERR_INVALID_POINTER(-1); |
| 58 | constexpr ResultCode ERR_INVALID_OBJECT_ADDR(-1); | 62 | constexpr ResultCode ERR_INVALID_OBJECT_ADDR(-1); |
| 59 | constexpr ResultCode ERR_NOT_AUTHORIZED(-1); | 63 | constexpr ResultCode ERR_NOT_AUTHORIZED(-1); |
| 60 | /// Alternate code returned instead of ERR_INVALID_HANDLE in some code paths. | 64 | /// Alternate code returned instead of ERR_INVALID_HANDLE in some code paths. |
| 61 | constexpr ResultCode ERR_INVALID_HANDLE_OS(-1); | 65 | constexpr ResultCode ERR_INVALID_HANDLE_OS(-1); |
| 62 | constexpr ResultCode ERR_NOT_FOUND(-1); | 66 | constexpr ResultCode ERR_NOT_FOUND(-1); |
| 63 | constexpr ResultCode ERR_OUT_OF_RANGE(-1); | ||
| 64 | constexpr ResultCode ERR_OUT_OF_RANGE_KERNEL(-1); | ||
| 65 | constexpr ResultCode RESULT_TIMEOUT(ErrorModule::Kernel, ErrCodes::Timeout); | 67 | constexpr ResultCode RESULT_TIMEOUT(ErrorModule::Kernel, ErrCodes::Timeout); |
| 66 | /// Returned when Accept() is called on a port with no sessions to be accepted. | 68 | /// Returned when Accept() is called on a port with no sessions to be accepted. |
| 67 | constexpr ResultCode ERR_NO_PENDING_SESSIONS(-1); | 69 | constexpr ResultCode ERR_NO_PENDING_SESSIONS(-1); |
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 1c9373ed8..f500fd2e7 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -273,7 +273,11 @@ static void Break(u64 reason, u64 info1, u64 info2) { | |||
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | /// Used to output a message on a debug hardware unit - does nothing on a retail unit | 275 | /// Used to output a message on a debug hardware unit - does nothing on a retail unit |
| 276 | static void OutputDebugString(VAddr address, s32 len) { | 276 | static void OutputDebugString(VAddr address, u64 len) { |
| 277 | if (len == 0) { | ||
| 278 | return; | ||
| 279 | } | ||
| 280 | |||
| 277 | std::string str(len, '\0'); | 281 | std::string str(len, '\0'); |
| 278 | Memory::ReadBlock(address, str.data(), str.size()); | 282 | Memory::ReadBlock(address, str.data(), str.size()); |
| 279 | LOG_DEBUG(Debug_Emulated, "{}", str); | 283 | LOG_DEBUG(Debug_Emulated, "{}", str); |
| @@ -378,7 +382,7 @@ static ResultCode GetThreadPriority(u32* priority, Handle handle) { | |||
| 378 | /// Sets the priority for the specified thread | 382 | /// Sets the priority for the specified thread |
| 379 | static ResultCode SetThreadPriority(Handle handle, u32 priority) { | 383 | static ResultCode SetThreadPriority(Handle handle, u32 priority) { |
| 380 | if (priority > THREADPRIO_LOWEST) { | 384 | if (priority > THREADPRIO_LOWEST) { |
| 381 | return ERR_OUT_OF_RANGE; | 385 | return ERR_INVALID_THREAD_PRIORITY; |
| 382 | } | 386 | } |
| 383 | 387 | ||
| 384 | auto& kernel = Core::System::GetInstance().Kernel(); | 388 | auto& kernel = Core::System::GetInstance().Kernel(); |
| @@ -523,7 +527,7 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V | |||
| 523 | std::string name = fmt::format("unknown-{:X}", entry_point); | 527 | std::string name = fmt::format("unknown-{:X}", entry_point); |
| 524 | 528 | ||
| 525 | if (priority > THREADPRIO_LOWEST) { | 529 | if (priority > THREADPRIO_LOWEST) { |
| 526 | return ERR_OUT_OF_RANGE; | 530 | return ERR_INVALID_THREAD_PRIORITY; |
| 527 | } | 531 | } |
| 528 | 532 | ||
| 529 | SharedPtr<ResourceLimit>& resource_limit = Core::CurrentProcess()->resource_limit; | 533 | SharedPtr<ResourceLimit>& resource_limit = Core::CurrentProcess()->resource_limit; |
| @@ -544,8 +548,8 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V | |||
| 544 | case THREADPROCESSORID_3: | 548 | case THREADPROCESSORID_3: |
| 545 | break; | 549 | break; |
| 546 | default: | 550 | default: |
| 547 | ASSERT_MSG(false, "Unsupported thread processor ID: {}", processor_id); | 551 | LOG_ERROR(Kernel_SVC, "Invalid thread processor ID: {}", processor_id); |
| 548 | break; | 552 | return ERR_INVALID_PROCESSOR_ID; |
| 549 | } | 553 | } |
| 550 | 554 | ||
| 551 | auto& kernel = Core::System::GetInstance().Kernel(); | 555 | auto& kernel = Core::System::GetInstance().Kernel(); |
diff --git a/src/core/hle/kernel/svc_wrap.h b/src/core/hle/kernel/svc_wrap.h index 79c3fe31b..1eda5f879 100644 --- a/src/core/hle/kernel/svc_wrap.h +++ b/src/core/hle/kernel/svc_wrap.h | |||
| @@ -222,9 +222,9 @@ void SvcWrap() { | |||
| 222 | func((s64)PARAM(0)); | 222 | func((s64)PARAM(0)); |
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | template <void func(u64, s32 len)> | 225 | template <void func(u64, u64 len)> |
| 226 | void SvcWrap() { | 226 | void SvcWrap() { |
| 227 | func(PARAM(0), (s32)(PARAM(1) & 0xFFFFFFFF)); | 227 | func(PARAM(0), PARAM(1)); |
| 228 | } | 228 | } |
| 229 | 229 | ||
| 230 | template <void func(u64, u64, u64)> | 230 | template <void func(u64, u64, u64)> |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 3d10d9af2..3f12a84dc 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -227,12 +227,12 @@ ResultVal<SharedPtr<Thread>> Thread::Create(KernelCore& kernel, std::string name | |||
| 227 | // Check if priority is in ranged. Lowest priority -> highest priority id. | 227 | // Check if priority is in ranged. Lowest priority -> highest priority id. |
| 228 | if (priority > THREADPRIO_LOWEST) { | 228 | if (priority > THREADPRIO_LOWEST) { |
| 229 | LOG_ERROR(Kernel_SVC, "Invalid thread priority: {}", priority); | 229 | LOG_ERROR(Kernel_SVC, "Invalid thread priority: {}", priority); |
| 230 | return ERR_OUT_OF_RANGE; | 230 | return ERR_INVALID_THREAD_PRIORITY; |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | if (processor_id > THREADPROCESSORID_MAX) { | 233 | if (processor_id > THREADPROCESSORID_MAX) { |
| 234 | LOG_ERROR(Kernel_SVC, "Invalid processor id: {}", processor_id); | 234 | LOG_ERROR(Kernel_SVC, "Invalid processor id: {}", processor_id); |
| 235 | return ERR_OUT_OF_RANGE_KERNEL; | 235 | return ERR_INVALID_PROCESSOR_ID; |
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | // TODO(yuriks): Other checks, returning 0xD9001BEA | 238 | // TODO(yuriks): Other checks, returning 0xD9001BEA |
diff --git a/src/core/hle/service/audio/audio.cpp b/src/core/hle/service/audio/audio.cpp index 6b5e15633..128df7db5 100644 --- a/src/core/hle/service/audio/audio.cpp +++ b/src/core/hle/service/audio/audio.cpp | |||
| @@ -15,6 +15,7 @@ | |||
| 15 | #include "core/hle/service/audio/audren_u.h" | 15 | #include "core/hle/service/audio/audren_u.h" |
| 16 | #include "core/hle/service/audio/codecctl.h" | 16 | #include "core/hle/service/audio/codecctl.h" |
| 17 | #include "core/hle/service/audio/hwopus.h" | 17 | #include "core/hle/service/audio/hwopus.h" |
| 18 | #include "core/hle/service/service.h" | ||
| 18 | 19 | ||
| 19 | namespace Service::Audio { | 20 | namespace Service::Audio { |
| 20 | 21 | ||
diff --git a/src/core/hle/service/audio/audio.h b/src/core/hle/service/audio/audio.h index 95e5691f7..f5bd3bf5f 100644 --- a/src/core/hle/service/audio/audio.h +++ b/src/core/hle/service/audio/audio.h | |||
| @@ -4,7 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "core/hle/service/service.h" | 7 | namespace Service::SM { |
| 8 | class ServiceManager; | ||
| 9 | } | ||
| 8 | 10 | ||
| 9 | namespace Service::Audio { | 11 | namespace Service::Audio { |
| 10 | 12 | ||
diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp index 05100ca8f..80a002322 100644 --- a/src/core/hle/service/audio/audout_u.cpp +++ b/src/core/hle/service/audio/audout_u.cpp | |||
| @@ -3,15 +3,20 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <array> | 5 | #include <array> |
| 6 | #include <cstring> | ||
| 6 | #include <vector> | 7 | #include <vector> |
| 7 | 8 | ||
| 9 | #include "audio_core/audio_out.h" | ||
| 8 | #include "audio_core/codec.h" | 10 | #include "audio_core/codec.h" |
| 11 | #include "common/common_funcs.h" | ||
| 9 | #include "common/logging/log.h" | 12 | #include "common/logging/log.h" |
| 13 | #include "common/swap.h" | ||
| 10 | #include "core/core.h" | 14 | #include "core/core.h" |
| 11 | #include "core/hle/ipc_helpers.h" | 15 | #include "core/hle/ipc_helpers.h" |
| 12 | #include "core/hle/kernel/event.h" | 16 | #include "core/hle/kernel/event.h" |
| 13 | #include "core/hle/kernel/hle_ipc.h" | 17 | #include "core/hle/kernel/hle_ipc.h" |
| 14 | #include "core/hle/service/audio/audout_u.h" | 18 | #include "core/hle/service/audio/audout_u.h" |
| 19 | #include "core/memory.h" | ||
| 15 | 20 | ||
| 16 | namespace Service::Audio { | 21 | namespace Service::Audio { |
| 17 | 22 | ||
| @@ -25,6 +30,18 @@ enum { | |||
| 25 | constexpr std::array<char, 10> DefaultDevice{{"DeviceOut"}}; | 30 | constexpr std::array<char, 10> DefaultDevice{{"DeviceOut"}}; |
| 26 | constexpr int DefaultSampleRate{48000}; | 31 | constexpr int DefaultSampleRate{48000}; |
| 27 | 32 | ||
| 33 | struct AudoutParams { | ||
| 34 | s32_le sample_rate; | ||
| 35 | u16_le channel_count; | ||
| 36 | INSERT_PADDING_BYTES(2); | ||
| 37 | }; | ||
| 38 | static_assert(sizeof(AudoutParams) == 0x8, "AudoutParams is an invalid size"); | ||
| 39 | |||
| 40 | enum class AudioState : u32 { | ||
| 41 | Started, | ||
| 42 | Stopped, | ||
| 43 | }; | ||
| 44 | |||
| 28 | class IAudioOut final : public ServiceFramework<IAudioOut> { | 45 | class IAudioOut final : public ServiceFramework<IAudioOut> { |
| 29 | public: | 46 | public: |
| 30 | IAudioOut(AudoutParams audio_params, AudioCore::AudioOut& audio_core) | 47 | IAudioOut(AudoutParams audio_params, AudioCore::AudioOut& audio_core) |
diff --git a/src/core/hle/service/audio/audout_u.h b/src/core/hle/service/audio/audout_u.h index aa52d3855..dcaf64708 100644 --- a/src/core/hle/service/audio/audout_u.h +++ b/src/core/hle/service/audio/audout_u.h | |||
| @@ -4,27 +4,18 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "audio_core/audio_out.h" | ||
| 8 | #include "core/hle/service/service.h" | 7 | #include "core/hle/service/service.h" |
| 9 | 8 | ||
| 9 | namespace AudioCore { | ||
| 10 | class AudioOut; | ||
| 11 | } | ||
| 12 | |||
| 10 | namespace Kernel { | 13 | namespace Kernel { |
| 11 | class HLERequestContext; | 14 | class HLERequestContext; |
| 12 | } | 15 | } |
| 13 | 16 | ||
| 14 | namespace Service::Audio { | 17 | namespace Service::Audio { |
| 15 | 18 | ||
| 16 | struct AudoutParams { | ||
| 17 | s32_le sample_rate; | ||
| 18 | u16_le channel_count; | ||
| 19 | INSERT_PADDING_BYTES(2); | ||
| 20 | }; | ||
| 21 | static_assert(sizeof(AudoutParams) == 0x8, "AudoutParams is an invalid size"); | ||
| 22 | |||
| 23 | enum class AudioState : u32 { | ||
| 24 | Started, | ||
| 25 | Stopped, | ||
| 26 | }; | ||
| 27 | |||
| 28 | class IAudioOut; | 19 | class IAudioOut; |
| 29 | 20 | ||
| 30 | class AudOutU final : public ServiceFramework<AudOutU> { | 21 | class AudOutU final : public ServiceFramework<AudOutU> { |
diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp index 3870bec65..e84c4fa2b 100644 --- a/src/core/hle/service/audio/audren_u.cpp +++ b/src/core/hle/service/audio/audren_u.cpp | |||
| @@ -2,12 +2,14 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 5 | #include <array> | 6 | #include <array> |
| 7 | #include <memory> | ||
| 6 | 8 | ||
| 9 | #include "audio_core/audio_renderer.h" | ||
| 7 | #include "common/alignment.h" | 10 | #include "common/alignment.h" |
| 11 | #include "common/common_funcs.h" | ||
| 8 | #include "common/logging/log.h" | 12 | #include "common/logging/log.h" |
| 9 | #include "core/core_timing.h" | ||
| 10 | #include "core/core_timing_util.h" | ||
| 11 | #include "core/hle/ipc_helpers.h" | 13 | #include "core/hle/ipc_helpers.h" |
| 12 | #include "core/hle/kernel/event.h" | 14 | #include "core/hle/kernel/event.h" |
| 13 | #include "core/hle/kernel/hle_ipc.h" | 15 | #include "core/hle/kernel/hle_ipc.h" |
diff --git a/src/core/hle/service/audio/audren_u.h b/src/core/hle/service/audio/audren_u.h index 85a995a2f..c6bc3a90a 100644 --- a/src/core/hle/service/audio/audren_u.h +++ b/src/core/hle/service/audio/audren_u.h | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "audio_core/audio_renderer.h" | ||
| 8 | #include "core/hle/service/service.h" | 7 | #include "core/hle/service/service.h" |
| 9 | 8 | ||
| 10 | namespace Kernel { | 9 | namespace Kernel { |
diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp index 341bfda42..668fef145 100644 --- a/src/core/hle/service/audio/hwopus.cpp +++ b/src/core/hle/service/audio/hwopus.cpp | |||
| @@ -3,7 +3,12 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <cstring> | 5 | #include <cstring> |
| 6 | #include <memory> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 6 | #include <opus.h> | 9 | #include <opus.h> |
| 10 | |||
| 11 | #include "common/common_funcs.h" | ||
| 7 | #include "common/logging/log.h" | 12 | #include "common/logging/log.h" |
| 8 | #include "core/hle/ipc_helpers.h" | 13 | #include "core/hle/ipc_helpers.h" |
| 9 | #include "core/hle/kernel/hle_ipc.h" | 14 | #include "core/hle/kernel/hle_ipc.h" |
diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp index da1c46d59..ac0eaaa8f 100644 --- a/src/core/hle/service/ns/pl_u.cpp +++ b/src/core/hle/service/ns/pl_u.cpp | |||
| @@ -2,6 +2,10 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 6 | #include <cstring> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 5 | #include <FontChineseSimplified.h> | 9 | #include <FontChineseSimplified.h> |
| 6 | #include <FontChineseTraditional.h> | 10 | #include <FontChineseTraditional.h> |
| 7 | #include <FontExtendedChineseSimplified.h> | 11 | #include <FontExtendedChineseSimplified.h> |
| @@ -9,14 +13,19 @@ | |||
| 9 | #include <FontNintendoExtended.h> | 13 | #include <FontNintendoExtended.h> |
| 10 | #include <FontStandard.h> | 14 | #include <FontStandard.h> |
| 11 | 15 | ||
| 16 | #include "common/assert.h" | ||
| 12 | #include "common/common_paths.h" | 17 | #include "common/common_paths.h" |
| 18 | #include "common/common_types.h" | ||
| 13 | #include "common/file_util.h" | 19 | #include "common/file_util.h" |
| 20 | #include "common/logging/log.h" | ||
| 21 | #include "common/swap.h" | ||
| 14 | #include "core/core.h" | 22 | #include "core/core.h" |
| 15 | #include "core/file_sys/content_archive.h" | 23 | #include "core/file_sys/content_archive.h" |
| 16 | #include "core/file_sys/nca_metadata.h" | 24 | #include "core/file_sys/nca_metadata.h" |
| 17 | #include "core/file_sys/registered_cache.h" | 25 | #include "core/file_sys/registered_cache.h" |
| 18 | #include "core/file_sys/romfs.h" | 26 | #include "core/file_sys/romfs.h" |
| 19 | #include "core/hle/ipc_helpers.h" | 27 | #include "core/hle/ipc_helpers.h" |
| 28 | #include "core/hle/kernel/shared_memory.h" | ||
| 20 | #include "core/hle/service/filesystem/filesystem.h" | 29 | #include "core/hle/service/filesystem/filesystem.h" |
| 21 | #include "core/hle/service/ns/pl_u.h" | 30 | #include "core/hle/service/ns/pl_u.h" |
| 22 | 31 | ||
| @@ -35,49 +44,41 @@ struct FontRegion { | |||
| 35 | u32 size; | 44 | u32 size; |
| 36 | }; | 45 | }; |
| 37 | 46 | ||
| 38 | static constexpr std::array<std::pair<FontArchives, const char*>, 7> SHARED_FONTS{ | 47 | constexpr std::array<std::pair<FontArchives, const char*>, 7> SHARED_FONTS{ |
| 39 | std::make_pair(FontArchives::Standard, "nintendo_udsg-r_std_003.bfttf"), | 48 | std::make_pair(FontArchives::Standard, "nintendo_udsg-r_std_003.bfttf"), |
| 40 | std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_org_zh-cn_003.bfttf"), | 49 | std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_org_zh-cn_003.bfttf"), |
| 41 | std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_ext_zh-cn_003.bfttf"), | 50 | std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_ext_zh-cn_003.bfttf"), |
| 42 | std::make_pair(FontArchives::ChineseTraditional, "nintendo_udjxh-db_zh-tw_003.bfttf"), | 51 | std::make_pair(FontArchives::ChineseTraditional, "nintendo_udjxh-db_zh-tw_003.bfttf"), |
| 43 | std::make_pair(FontArchives::Korean, "nintendo_udsg-r_ko_003.bfttf"), | 52 | std::make_pair(FontArchives::Korean, "nintendo_udsg-r_ko_003.bfttf"), |
| 44 | std::make_pair(FontArchives::Extension, "nintendo_ext_003.bfttf"), | 53 | std::make_pair(FontArchives::Extension, "nintendo_ext_003.bfttf"), |
| 45 | std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf")}; | 54 | std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf"), |
| 55 | }; | ||
| 46 | 56 | ||
| 47 | static constexpr std::array<const char*, 7> SHARED_FONTS_TTF{"FontStandard.ttf", | 57 | constexpr std::array<const char*, 7> SHARED_FONTS_TTF{ |
| 48 | "FontChineseSimplified.ttf", | 58 | "FontStandard.ttf", |
| 49 | "FontExtendedChineseSimplified.ttf", | 59 | "FontChineseSimplified.ttf", |
| 50 | "FontChineseTraditional.ttf", | 60 | "FontExtendedChineseSimplified.ttf", |
| 51 | "FontKorean.ttf", | 61 | "FontChineseTraditional.ttf", |
| 52 | "FontNintendoExtended.ttf", | 62 | "FontKorean.ttf", |
| 53 | "FontNintendoExtended2.ttf"}; | 63 | "FontNintendoExtended.ttf", |
| 64 | "FontNintendoExtended2.ttf", | ||
| 65 | }; | ||
| 54 | 66 | ||
| 55 | // The below data is specific to shared font data dumped from Switch on f/w 2.2 | 67 | // The below data is specific to shared font data dumped from Switch on f/w 2.2 |
| 56 | // Virtual address and offsets/sizes likely will vary by dump | 68 | // Virtual address and offsets/sizes likely will vary by dump |
| 57 | static constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL}; | 69 | constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL}; |
| 58 | static constexpr u32 EXPECTED_RESULT{ | 70 | constexpr u32 EXPECTED_RESULT{0x7f9a0218}; // What we expect the decrypted bfttf first 4 bytes to be |
| 59 | 0x7f9a0218}; // What we expect the decrypted bfttf first 4 bytes to be | 71 | constexpr u32 EXPECTED_MAGIC{0x36f81a1e}; // What we expect the encrypted bfttf first 4 bytes to be |
| 60 | static constexpr u32 EXPECTED_MAGIC{ | 72 | constexpr u64 SHARED_FONT_MEM_SIZE{0x1100000}; |
| 61 | 0x36f81a1e}; // What we expect the encrypted bfttf first 4 bytes to be | 73 | constexpr FontRegion EMPTY_REGION{0, 0}; |
| 62 | static constexpr u64 SHARED_FONT_MEM_SIZE{0x1100000}; | ||
| 63 | static constexpr FontRegion EMPTY_REGION{0, 0}; | ||
| 64 | std::vector<FontRegion> | ||
| 65 | SHARED_FONT_REGIONS{}; // Automatically populated based on shared_fonts dump or system archives | ||
| 66 | |||
| 67 | const FontRegion& GetSharedFontRegion(size_t index) { | ||
| 68 | if (index >= SHARED_FONT_REGIONS.size() || SHARED_FONT_REGIONS.empty()) { | ||
| 69 | // No font fallback | ||
| 70 | return EMPTY_REGION; | ||
| 71 | } | ||
| 72 | return SHARED_FONT_REGIONS.at(index); | ||
| 73 | } | ||
| 74 | 74 | ||
| 75 | enum class LoadState : u32 { | 75 | enum class LoadState : u32 { |
| 76 | Loading = 0, | 76 | Loading = 0, |
| 77 | Done = 1, | 77 | Done = 1, |
| 78 | }; | 78 | }; |
| 79 | 79 | ||
| 80 | void DecryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output, size_t& offset) { | 80 | static void DecryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output, |
| 81 | size_t& offset) { | ||
| 81 | ASSERT_MSG(offset + (input.size() * sizeof(u32)) < SHARED_FONT_MEM_SIZE, | 82 | ASSERT_MSG(offset + (input.size() * sizeof(u32)) < SHARED_FONT_MEM_SIZE, |
| 82 | "Shared fonts exceeds 17mb!"); | 83 | "Shared fonts exceeds 17mb!"); |
| 83 | ASSERT_MSG(input[0] == EXPECTED_MAGIC, "Failed to derive key, unexpected magic number"); | 84 | ASSERT_MSG(input[0] == EXPECTED_MAGIC, "Failed to derive key, unexpected magic number"); |
| @@ -104,28 +105,52 @@ static void EncryptSharedFont(const std::vector<u8>& input, std::vector<u8>& out | |||
| 104 | offset += input.size() + (sizeof(u32) * 2); | 105 | offset += input.size() + (sizeof(u32) * 2); |
| 105 | } | 106 | } |
| 106 | 107 | ||
| 108 | // Helper function to make BuildSharedFontsRawRegions a bit nicer | ||
| 107 | static u32 GetU32Swapped(const u8* data) { | 109 | static u32 GetU32Swapped(const u8* data) { |
| 108 | u32 value; | 110 | u32 value; |
| 109 | std::memcpy(&value, data, sizeof(value)); | 111 | std::memcpy(&value, data, sizeof(value)); |
| 110 | return Common::swap32(value); // Helper function to make BuildSharedFontsRawRegions a bit nicer | 112 | return Common::swap32(value); |
| 111 | } | 113 | } |
| 112 | 114 | ||
| 113 | void BuildSharedFontsRawRegions(const std::vector<u8>& input) { | 115 | struct PL_U::Impl { |
| 114 | unsigned cur_offset = 0; // As we can derive the xor key we can just populate the offsets based | 116 | const FontRegion& GetSharedFontRegion(size_t index) const { |
| 115 | // on the shared memory dump | 117 | if (index >= shared_font_regions.size() || shared_font_regions.empty()) { |
| 116 | for (size_t i = 0; i < SHARED_FONTS.size(); i++) { | 118 | // No font fallback |
| 117 | // Out of shared fonts/Invalid font | 119 | return EMPTY_REGION; |
| 118 | if (GetU32Swapped(input.data() + cur_offset) != EXPECTED_RESULT) | 120 | } |
| 119 | break; | 121 | return shared_font_regions.at(index); |
| 120 | const u32 KEY = GetU32Swapped(input.data() + cur_offset) ^ | ||
| 121 | EXPECTED_MAGIC; // Derive key withing inverse xor | ||
| 122 | const u32 SIZE = GetU32Swapped(input.data() + cur_offset + 4) ^ KEY; | ||
| 123 | SHARED_FONT_REGIONS.push_back(FontRegion{cur_offset + 8, SIZE}); | ||
| 124 | cur_offset += SIZE + 8; | ||
| 125 | } | 122 | } |
| 126 | } | ||
| 127 | 123 | ||
| 128 | PL_U::PL_U() : ServiceFramework("pl:u") { | 124 | void BuildSharedFontsRawRegions(const std::vector<u8>& input) { |
| 125 | // As we can derive the xor key we can just populate the offsets | ||
| 126 | // based on the shared memory dump | ||
| 127 | unsigned cur_offset = 0; | ||
| 128 | |||
| 129 | for (size_t i = 0; i < SHARED_FONTS.size(); i++) { | ||
| 130 | // Out of shared fonts/invalid font | ||
| 131 | if (GetU32Swapped(input.data() + cur_offset) != EXPECTED_RESULT) { | ||
| 132 | break; | ||
| 133 | } | ||
| 134 | |||
| 135 | // Derive key withing inverse xor | ||
| 136 | const u32 KEY = GetU32Swapped(input.data() + cur_offset) ^ EXPECTED_MAGIC; | ||
| 137 | const u32 SIZE = GetU32Swapped(input.data() + cur_offset + 4) ^ KEY; | ||
| 138 | shared_font_regions.push_back(FontRegion{cur_offset + 8, SIZE}); | ||
| 139 | cur_offset += SIZE + 8; | ||
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | /// Handle to shared memory region designated for a shared font | ||
| 144 | Kernel::SharedPtr<Kernel::SharedMemory> shared_font_mem; | ||
| 145 | |||
| 146 | /// Backing memory for the shared font data | ||
| 147 | std::shared_ptr<std::vector<u8>> shared_font; | ||
| 148 | |||
| 149 | // Automatically populated based on shared_fonts dump or system archives. | ||
| 150 | std::vector<FontRegion> shared_font_regions; | ||
| 151 | }; | ||
| 152 | |||
| 153 | PL_U::PL_U() : ServiceFramework("pl:u"), impl{std::make_unique<Impl>()} { | ||
| 129 | static const FunctionInfo functions[] = { | 154 | static const FunctionInfo functions[] = { |
| 130 | {0, &PL_U::RequestLoad, "RequestLoad"}, | 155 | {0, &PL_U::RequestLoad, "RequestLoad"}, |
| 131 | {1, &PL_U::GetLoadState, "GetLoadState"}, | 156 | {1, &PL_U::GetLoadState, "GetLoadState"}, |
| @@ -141,7 +166,7 @@ PL_U::PL_U() : ServiceFramework("pl:u") { | |||
| 141 | // Rebuild shared fonts from data ncas | 166 | // Rebuild shared fonts from data ncas |
| 142 | if (nand->HasEntry(static_cast<u64>(FontArchives::Standard), | 167 | if (nand->HasEntry(static_cast<u64>(FontArchives::Standard), |
| 143 | FileSys::ContentRecordType::Data)) { | 168 | FileSys::ContentRecordType::Data)) { |
| 144 | shared_font = std::make_shared<std::vector<u8>>(SHARED_FONT_MEM_SIZE); | 169 | impl->shared_font = std::make_shared<std::vector<u8>>(SHARED_FONT_MEM_SIZE); |
| 145 | for (auto font : SHARED_FONTS) { | 170 | for (auto font : SHARED_FONTS) { |
| 146 | const auto nca = | 171 | const auto nca = |
| 147 | nand->GetEntry(static_cast<u64>(font.first), FileSys::ContentRecordType::Data); | 172 | nand->GetEntry(static_cast<u64>(font.first), FileSys::ContentRecordType::Data); |
| @@ -177,12 +202,12 @@ PL_U::PL_U() : ServiceFramework("pl:u") { | |||
| 177 | static_cast<u32>(offset + 8), | 202 | static_cast<u32>(offset + 8), |
| 178 | static_cast<u32>((font_data_u32.size() * sizeof(u32)) - | 203 | static_cast<u32>((font_data_u32.size() * sizeof(u32)) - |
| 179 | 8)}; // Font offset and size do not account for the header | 204 | 8)}; // Font offset and size do not account for the header |
| 180 | DecryptSharedFont(font_data_u32, *shared_font, offset); | 205 | DecryptSharedFont(font_data_u32, *impl->shared_font, offset); |
| 181 | SHARED_FONT_REGIONS.push_back(region); | 206 | impl->shared_font_regions.push_back(region); |
| 182 | } | 207 | } |
| 183 | 208 | ||
| 184 | } else { | 209 | } else { |
| 185 | shared_font = std::make_shared<std::vector<u8>>( | 210 | impl->shared_font = std::make_shared<std::vector<u8>>( |
| 186 | SHARED_FONT_MEM_SIZE); // Shared memory needs to always be allocated and a fixed size | 211 | SHARED_FONT_MEM_SIZE); // Shared memory needs to always be allocated and a fixed size |
| 187 | 212 | ||
| 188 | const std::string user_path = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir); | 213 | const std::string user_path = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir); |
| @@ -206,8 +231,8 @@ PL_U::PL_U() : ServiceFramework("pl:u") { | |||
| 206 | static_cast<u32>(offset + 8), | 231 | static_cast<u32>(offset + 8), |
| 207 | static_cast<u32>(ttf_bytes.size())}; // Font offset and size do not account | 232 | static_cast<u32>(ttf_bytes.size())}; // Font offset and size do not account |
| 208 | // for the header | 233 | // for the header |
| 209 | EncryptSharedFont(ttf_bytes, *shared_font, offset); | 234 | EncryptSharedFont(ttf_bytes, *impl->shared_font, offset); |
| 210 | SHARED_FONT_REGIONS.push_back(region); | 235 | impl->shared_font_regions.push_back(region); |
| 211 | } else { | 236 | } else { |
| 212 | LOG_WARNING(Service_NS, "Unable to load font: {}", font_ttf); | 237 | LOG_WARNING(Service_NS, "Unable to load font: {}", font_ttf); |
| 213 | } | 238 | } |
| @@ -222,8 +247,8 @@ PL_U::PL_U() : ServiceFramework("pl:u") { | |||
| 222 | if (file.IsOpen()) { | 247 | if (file.IsOpen()) { |
| 223 | // Read shared font data | 248 | // Read shared font data |
| 224 | ASSERT(file.GetSize() == SHARED_FONT_MEM_SIZE); | 249 | ASSERT(file.GetSize() == SHARED_FONT_MEM_SIZE); |
| 225 | file.ReadBytes(shared_font->data(), shared_font->size()); | 250 | file.ReadBytes(impl->shared_font->data(), impl->shared_font->size()); |
| 226 | BuildSharedFontsRawRegions(*shared_font); | 251 | impl->BuildSharedFontsRawRegions(*impl->shared_font); |
| 227 | } else { | 252 | } else { |
| 228 | LOG_WARNING(Service_NS, | 253 | LOG_WARNING(Service_NS, |
| 229 | "Shared Font file missing. Loading open source replacement from memory"); | 254 | "Shared Font file missing. Loading open source replacement from memory"); |
| @@ -240,8 +265,8 @@ PL_U::PL_U() : ServiceFramework("pl:u") { | |||
| 240 | for (const std::vector<u8>& font_ttf : open_source_shared_fonts_ttf) { | 265 | for (const std::vector<u8>& font_ttf : open_source_shared_fonts_ttf) { |
| 241 | const FontRegion region{static_cast<u32>(offset + 8), | 266 | const FontRegion region{static_cast<u32>(offset + 8), |
| 242 | static_cast<u32>(font_ttf.size())}; | 267 | static_cast<u32>(font_ttf.size())}; |
| 243 | EncryptSharedFont(font_ttf, *shared_font, offset); | 268 | EncryptSharedFont(font_ttf, *impl->shared_font, offset); |
| 244 | SHARED_FONT_REGIONS.push_back(region); | 269 | impl->shared_font_regions.push_back(region); |
| 245 | } | 270 | } |
| 246 | } | 271 | } |
| 247 | } | 272 | } |
| @@ -275,7 +300,7 @@ void PL_U::GetSize(Kernel::HLERequestContext& ctx) { | |||
| 275 | LOG_DEBUG(Service_NS, "called, font_id={}", font_id); | 300 | LOG_DEBUG(Service_NS, "called, font_id={}", font_id); |
| 276 | IPC::ResponseBuilder rb{ctx, 3}; | 301 | IPC::ResponseBuilder rb{ctx, 3}; |
| 277 | rb.Push(RESULT_SUCCESS); | 302 | rb.Push(RESULT_SUCCESS); |
| 278 | rb.Push<u32>(GetSharedFontRegion(font_id).size); | 303 | rb.Push<u32>(impl->GetSharedFontRegion(font_id).size); |
| 279 | } | 304 | } |
| 280 | 305 | ||
| 281 | void PL_U::GetSharedMemoryAddressOffset(Kernel::HLERequestContext& ctx) { | 306 | void PL_U::GetSharedMemoryAddressOffset(Kernel::HLERequestContext& ctx) { |
| @@ -285,17 +310,18 @@ void PL_U::GetSharedMemoryAddressOffset(Kernel::HLERequestContext& ctx) { | |||
| 285 | LOG_DEBUG(Service_NS, "called, font_id={}", font_id); | 310 | LOG_DEBUG(Service_NS, "called, font_id={}", font_id); |
| 286 | IPC::ResponseBuilder rb{ctx, 3}; | 311 | IPC::ResponseBuilder rb{ctx, 3}; |
| 287 | rb.Push(RESULT_SUCCESS); | 312 | rb.Push(RESULT_SUCCESS); |
| 288 | rb.Push<u32>(GetSharedFontRegion(font_id).offset); | 313 | rb.Push<u32>(impl->GetSharedFontRegion(font_id).offset); |
| 289 | } | 314 | } |
| 290 | 315 | ||
| 291 | void PL_U::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) { | 316 | void PL_U::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) { |
| 292 | // Map backing memory for the font data | 317 | // Map backing memory for the font data |
| 293 | Core::CurrentProcess()->vm_manager.MapMemoryBlock( | 318 | Core::CurrentProcess()->vm_manager.MapMemoryBlock(SHARED_FONT_MEM_VADDR, impl->shared_font, 0, |
| 294 | SHARED_FONT_MEM_VADDR, shared_font, 0, SHARED_FONT_MEM_SIZE, Kernel::MemoryState::Shared); | 319 | SHARED_FONT_MEM_SIZE, |
| 320 | Kernel::MemoryState::Shared); | ||
| 295 | 321 | ||
| 296 | // Create shared font memory object | 322 | // Create shared font memory object |
| 297 | auto& kernel = Core::System::GetInstance().Kernel(); | 323 | auto& kernel = Core::System::GetInstance().Kernel(); |
| 298 | shared_font_mem = Kernel::SharedMemory::Create( | 324 | impl->shared_font_mem = Kernel::SharedMemory::Create( |
| 299 | kernel, Core::CurrentProcess(), SHARED_FONT_MEM_SIZE, Kernel::MemoryPermission::ReadWrite, | 325 | kernel, Core::CurrentProcess(), SHARED_FONT_MEM_SIZE, Kernel::MemoryPermission::ReadWrite, |
| 300 | Kernel::MemoryPermission::Read, SHARED_FONT_MEM_VADDR, Kernel::MemoryRegion::BASE, | 326 | Kernel::MemoryPermission::Read, SHARED_FONT_MEM_VADDR, Kernel::MemoryRegion::BASE, |
| 301 | "PL_U:shared_font_mem"); | 327 | "PL_U:shared_font_mem"); |
| @@ -303,7 +329,7 @@ void PL_U::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) { | |||
| 303 | LOG_DEBUG(Service_NS, "called"); | 329 | LOG_DEBUG(Service_NS, "called"); |
| 304 | IPC::ResponseBuilder rb{ctx, 2, 1}; | 330 | IPC::ResponseBuilder rb{ctx, 2, 1}; |
| 305 | rb.Push(RESULT_SUCCESS); | 331 | rb.Push(RESULT_SUCCESS); |
| 306 | rb.PushCopyObjects(shared_font_mem); | 332 | rb.PushCopyObjects(impl->shared_font_mem); |
| 307 | } | 333 | } |
| 308 | 334 | ||
| 309 | void PL_U::GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx) { | 335 | void PL_U::GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx) { |
| @@ -316,9 +342,9 @@ void PL_U::GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx) { | |||
| 316 | std::vector<u32> font_sizes; | 342 | std::vector<u32> font_sizes; |
| 317 | 343 | ||
| 318 | // TODO(ogniK): Have actual priority order | 344 | // TODO(ogniK): Have actual priority order |
| 319 | for (size_t i = 0; i < SHARED_FONT_REGIONS.size(); i++) { | 345 | for (size_t i = 0; i < impl->shared_font_regions.size(); i++) { |
| 320 | font_codes.push_back(static_cast<u32>(i)); | 346 | font_codes.push_back(static_cast<u32>(i)); |
| 321 | auto region = GetSharedFontRegion(i); | 347 | auto region = impl->GetSharedFontRegion(i); |
| 322 | font_offsets.push_back(region.offset); | 348 | font_offsets.push_back(region.offset); |
| 323 | font_sizes.push_back(region.size); | 349 | font_sizes.push_back(region.size); |
| 324 | } | 350 | } |
diff --git a/src/core/hle/service/ns/pl_u.h b/src/core/hle/service/ns/pl_u.h index 296c3db05..253f26a2a 100644 --- a/src/core/hle/service/ns/pl_u.h +++ b/src/core/hle/service/ns/pl_u.h | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include "core/hle/kernel/shared_memory.h" | ||
| 9 | #include "core/hle/service/service.h" | 8 | #include "core/hle/service/service.h" |
| 10 | 9 | ||
| 11 | namespace Service::NS { | 10 | namespace Service::NS { |
| @@ -23,11 +22,8 @@ private: | |||
| 23 | void GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx); | 22 | void GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx); |
| 24 | void GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx); | 23 | void GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx); |
| 25 | 24 | ||
| 26 | /// Handle to shared memory region designated for a shared font | 25 | struct Impl; |
| 27 | Kernel::SharedPtr<Kernel::SharedMemory> shared_font_mem; | 26 | std::unique_ptr<Impl> impl; |
| 28 | |||
| 29 | /// Backing memory for the shared font data | ||
| 30 | std::shared_ptr<std::vector<u8>> shared_font; | ||
| 31 | }; | 27 | }; |
| 32 | 28 | ||
| 33 | } // namespace Service::NS | 29 | } // namespace Service::NS |
diff --git a/src/core/hle/service/prepo/prepo.cpp b/src/core/hle/service/prepo/prepo.cpp index 3c43b8d8c..6a9eccfb5 100644 --- a/src/core/hle/service/prepo/prepo.cpp +++ b/src/core/hle/service/prepo/prepo.cpp | |||
| @@ -1,36 +1,47 @@ | |||
| 1 | #include <cinttypes> | 1 | // Copyright 2018 yuzu emulator team |
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 2 | #include "common/logging/log.h" | 5 | #include "common/logging/log.h" |
| 3 | #include "core/hle/ipc_helpers.h" | 6 | #include "core/hle/ipc_helpers.h" |
| 4 | #include "core/hle/kernel/event.h" | ||
| 5 | #include "core/hle/service/prepo/prepo.h" | 7 | #include "core/hle/service/prepo/prepo.h" |
| 8 | #include "core/hle/service/service.h" | ||
| 6 | 9 | ||
| 7 | namespace Service::PlayReport { | 10 | namespace Service::PlayReport { |
| 8 | PlayReport::PlayReport(const char* name) : ServiceFramework(name) { | ||
| 9 | static const FunctionInfo functions[] = { | ||
| 10 | {10100, nullptr, "SaveReport"}, | ||
| 11 | {10101, &PlayReport::SaveReportWithUser, "SaveReportWithUser"}, | ||
| 12 | {10200, nullptr, "RequestImmediateTransmission"}, | ||
| 13 | {10300, nullptr, "GetTransmissionStatus"}, | ||
| 14 | {20100, nullptr, "SaveSystemReport"}, | ||
| 15 | {20200, nullptr, "SetOperationMode"}, | ||
| 16 | {20101, nullptr, "SaveSystemReportWithUser"}, | ||
| 17 | {30100, nullptr, "ClearStorage"}, | ||
| 18 | {40100, nullptr, "IsUserAgreementCheckEnabled"}, | ||
| 19 | {40101, nullptr, "SetUserAgreementCheckEnabled"}, | ||
| 20 | {90100, nullptr, "GetStorageUsage"}, | ||
| 21 | {90200, nullptr, "GetStatistics"}, | ||
| 22 | {90201, nullptr, "GetThroughputHistory"}, | ||
| 23 | {90300, nullptr, "GetLastUploadError"}, | ||
| 24 | }; | ||
| 25 | RegisterHandlers(functions); | ||
| 26 | }; | ||
| 27 | 11 | ||
| 28 | void PlayReport::SaveReportWithUser(Kernel::HLERequestContext& ctx) { | 12 | class PlayReport final : public ServiceFramework<PlayReport> { |
| 29 | // TODO(ogniK): Do we want to add play report? | 13 | public: |
| 30 | LOG_WARNING(Service_PREPO, "(STUBBED) called"); | 14 | explicit PlayReport(const char* name) : ServiceFramework{name} { |
| 15 | // clang-format off | ||
| 16 | static const FunctionInfo functions[] = { | ||
| 17 | {10100, nullptr, "SaveReport"}, | ||
| 18 | {10101, &PlayReport::SaveReportWithUser, "SaveReportWithUser"}, | ||
| 19 | {10200, nullptr, "RequestImmediateTransmission"}, | ||
| 20 | {10300, nullptr, "GetTransmissionStatus"}, | ||
| 21 | {20100, nullptr, "SaveSystemReport"}, | ||
| 22 | {20200, nullptr, "SetOperationMode"}, | ||
| 23 | {20101, nullptr, "SaveSystemReportWithUser"}, | ||
| 24 | {30100, nullptr, "ClearStorage"}, | ||
| 25 | {40100, nullptr, "IsUserAgreementCheckEnabled"}, | ||
| 26 | {40101, nullptr, "SetUserAgreementCheckEnabled"}, | ||
| 27 | {90100, nullptr, "GetStorageUsage"}, | ||
| 28 | {90200, nullptr, "GetStatistics"}, | ||
| 29 | {90201, nullptr, "GetThroughputHistory"}, | ||
| 30 | {90300, nullptr, "GetLastUploadError"}, | ||
| 31 | }; | ||
| 32 | // clang-format on | ||
| 33 | |||
| 34 | RegisterHandlers(functions); | ||
| 35 | } | ||
| 36 | |||
| 37 | private: | ||
| 38 | void SaveReportWithUser(Kernel::HLERequestContext& ctx) { | ||
| 39 | // TODO(ogniK): Do we want to add play report? | ||
| 40 | LOG_WARNING(Service_PREPO, "(STUBBED) called"); | ||
| 31 | 41 | ||
| 32 | IPC::ResponseBuilder rb{ctx, 2}; | 42 | IPC::ResponseBuilder rb{ctx, 2}; |
| 33 | rb.Push(RESULT_SUCCESS); | 43 | rb.Push(RESULT_SUCCESS); |
| 44 | } | ||
| 34 | }; | 45 | }; |
| 35 | 46 | ||
| 36 | void InstallInterfaces(SM::ServiceManager& service_manager) { | 47 | void InstallInterfaces(SM::ServiceManager& service_manager) { |
diff --git a/src/core/hle/service/prepo/prepo.h b/src/core/hle/service/prepo/prepo.h index f5a6aba6d..0e7b01331 100644 --- a/src/core/hle/service/prepo/prepo.h +++ b/src/core/hle/service/prepo/prepo.h | |||
| @@ -4,22 +4,12 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <memory> | 7 | namespace Service::SM { |
| 8 | #include <string> | 8 | class ServiceManager; |
| 9 | #include "core/hle/kernel/event.h" | 9 | } |
| 10 | #include "core/hle/service/service.h" | ||
| 11 | 10 | ||
| 12 | namespace Service::PlayReport { | 11 | namespace Service::PlayReport { |
| 13 | 12 | ||
| 14 | class PlayReport final : public ServiceFramework<PlayReport> { | ||
| 15 | public: | ||
| 16 | explicit PlayReport(const char* name); | ||
| 17 | ~PlayReport() = default; | ||
| 18 | |||
| 19 | private: | ||
| 20 | void SaveReportWithUser(Kernel::HLERequestContext& ctx); | ||
| 21 | }; | ||
| 22 | |||
| 23 | void InstallInterfaces(SM::ServiceManager& service_manager); | 13 | void InstallInterfaces(SM::ServiceManager& service_manager); |
| 24 | 14 | ||
| 25 | } // namespace Service::PlayReport | 15 | } // namespace Service::PlayReport |
diff --git a/src/core/settings.h b/src/core/settings.h index 08a16ef2c..0318d019c 100644 --- a/src/core/settings.h +++ b/src/core/settings.h | |||
| @@ -148,6 +148,7 @@ struct Values { | |||
| 148 | 148 | ||
| 149 | // Audio | 149 | // Audio |
| 150 | std::string sink_id; | 150 | std::string sink_id; |
| 151 | bool enable_audio_stretching; | ||
| 151 | std::string audio_device_id; | 152 | std::string audio_device_id; |
| 152 | float volume; | 153 | float volume; |
| 153 | 154 | ||
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index 3730e85b8..b0df154ca 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp | |||
| @@ -120,6 +120,9 @@ TelemetrySession::TelemetrySession() { | |||
| 120 | Telemetry::AppendOSInfo(field_collection); | 120 | Telemetry::AppendOSInfo(field_collection); |
| 121 | 121 | ||
| 122 | // Log user configuration information | 122 | // Log user configuration information |
| 123 | AddField(Telemetry::FieldType::UserConfig, "Audio_SinkId", Settings::values.sink_id); | ||
| 124 | AddField(Telemetry::FieldType::UserConfig, "Audio_EnableAudioStretching", | ||
| 125 | Settings::values.enable_audio_stretching); | ||
| 123 | AddField(Telemetry::FieldType::UserConfig, "Core_UseCpuJit", Settings::values.use_cpu_jit); | 126 | AddField(Telemetry::FieldType::UserConfig, "Core_UseCpuJit", Settings::values.use_cpu_jit); |
| 124 | AddField(Telemetry::FieldType::UserConfig, "Core_UseMultiCore", | 127 | AddField(Telemetry::FieldType::UserConfig, "Core_UseMultiCore", |
| 125 | Settings::values.use_multi_core); | 128 | Settings::values.use_multi_core); |
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 4d74bb395..4e75a72ec 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | add_executable(tests | 1 | add_executable(tests |
| 2 | common/param_package.cpp | 2 | common/param_package.cpp |
| 3 | common/ring_buffer.cpp | ||
| 3 | core/arm/arm_test_common.cpp | 4 | core/arm/arm_test_common.cpp |
| 4 | core/arm/arm_test_common.h | 5 | core/arm/arm_test_common.h |
| 5 | core/core_timing.cpp | 6 | core/core_timing.cpp |
diff --git a/src/tests/common/ring_buffer.cpp b/src/tests/common/ring_buffer.cpp new file mode 100644 index 000000000..f3fe57839 --- /dev/null +++ b/src/tests/common/ring_buffer.cpp | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <array> | ||
| 7 | #include <cstddef> | ||
| 8 | #include <numeric> | ||
| 9 | #include <thread> | ||
| 10 | #include <vector> | ||
| 11 | #include <catch2/catch.hpp> | ||
| 12 | #include "common/ring_buffer.h" | ||
| 13 | |||
| 14 | namespace Common { | ||
| 15 | |||
| 16 | TEST_CASE("RingBuffer: Basic Tests", "[common]") { | ||
| 17 | RingBuffer<char, 4, 1> buf; | ||
| 18 | |||
| 19 | // Pushing values into a ring buffer with space should succeed. | ||
| 20 | for (size_t i = 0; i < 4; i++) { | ||
| 21 | const char elem = static_cast<char>(i); | ||
| 22 | const size_t count = buf.Push(&elem, 1); | ||
| 23 | REQUIRE(count == 1); | ||
| 24 | } | ||
| 25 | |||
| 26 | REQUIRE(buf.Size() == 4); | ||
| 27 | |||
| 28 | // Pushing values into a full ring buffer should fail. | ||
| 29 | { | ||
| 30 | const char elem = static_cast<char>(42); | ||
| 31 | const size_t count = buf.Push(&elem, 1); | ||
| 32 | REQUIRE(count == 0); | ||
| 33 | } | ||
| 34 | |||
| 35 | REQUIRE(buf.Size() == 4); | ||
| 36 | |||
| 37 | // Popping multiple values from a ring buffer with values should succeed. | ||
| 38 | { | ||
| 39 | const std::vector<char> popped = buf.Pop(2); | ||
| 40 | REQUIRE(popped.size() == 2); | ||
| 41 | REQUIRE(popped[0] == 0); | ||
| 42 | REQUIRE(popped[1] == 1); | ||
| 43 | } | ||
| 44 | |||
| 45 | REQUIRE(buf.Size() == 2); | ||
| 46 | |||
| 47 | // Popping a single value from a ring buffer with values should succeed. | ||
| 48 | { | ||
| 49 | const std::vector<char> popped = buf.Pop(1); | ||
| 50 | REQUIRE(popped.size() == 1); | ||
| 51 | REQUIRE(popped[0] == 2); | ||
| 52 | } | ||
| 53 | |||
| 54 | REQUIRE(buf.Size() == 1); | ||
| 55 | |||
| 56 | // Pushing more values than space available should partially suceed. | ||
| 57 | { | ||
| 58 | std::vector<char> to_push(6); | ||
| 59 | std::iota(to_push.begin(), to_push.end(), 88); | ||
| 60 | const size_t count = buf.Push(to_push); | ||
| 61 | REQUIRE(count == 3); | ||
| 62 | } | ||
| 63 | |||
| 64 | REQUIRE(buf.Size() == 4); | ||
| 65 | |||
| 66 | // Doing an unlimited pop should pop all values. | ||
| 67 | { | ||
| 68 | const std::vector<char> popped = buf.Pop(); | ||
| 69 | REQUIRE(popped.size() == 4); | ||
| 70 | REQUIRE(popped[0] == 3); | ||
| 71 | REQUIRE(popped[1] == 88); | ||
| 72 | REQUIRE(popped[2] == 89); | ||
| 73 | REQUIRE(popped[3] == 90); | ||
| 74 | } | ||
| 75 | |||
| 76 | REQUIRE(buf.Size() == 0); | ||
| 77 | } | ||
| 78 | |||
| 79 | TEST_CASE("RingBuffer: Threaded Test", "[common]") { | ||
| 80 | RingBuffer<char, 4, 2> buf; | ||
| 81 | const char seed = 42; | ||
| 82 | const size_t count = 1000000; | ||
| 83 | size_t full = 0; | ||
| 84 | size_t empty = 0; | ||
| 85 | |||
| 86 | const auto next_value = [](std::array<char, 2>& value) { | ||
| 87 | value[0] += 1; | ||
| 88 | value[1] += 2; | ||
| 89 | }; | ||
| 90 | |||
| 91 | std::thread producer{[&] { | ||
| 92 | std::array<char, 2> value = {seed, seed}; | ||
| 93 | size_t i = 0; | ||
| 94 | while (i < count) { | ||
| 95 | if (const size_t c = buf.Push(&value[0], 1); c > 0) { | ||
| 96 | REQUIRE(c == 1); | ||
| 97 | i++; | ||
| 98 | next_value(value); | ||
| 99 | } else { | ||
| 100 | full++; | ||
| 101 | std::this_thread::yield(); | ||
| 102 | } | ||
| 103 | } | ||
| 104 | }}; | ||
| 105 | |||
| 106 | std::thread consumer{[&] { | ||
| 107 | std::array<char, 2> value = {seed, seed}; | ||
| 108 | size_t i = 0; | ||
| 109 | while (i < count) { | ||
| 110 | if (const std::vector<char> v = buf.Pop(1); v.size() > 0) { | ||
| 111 | REQUIRE(v.size() == 2); | ||
| 112 | REQUIRE(v[0] == value[0]); | ||
| 113 | REQUIRE(v[1] == value[1]); | ||
| 114 | i++; | ||
| 115 | next_value(value); | ||
| 116 | } else { | ||
| 117 | empty++; | ||
| 118 | std::this_thread::yield(); | ||
| 119 | } | ||
| 120 | } | ||
| 121 | }}; | ||
| 122 | |||
| 123 | producer.join(); | ||
| 124 | consumer.join(); | ||
| 125 | |||
| 126 | REQUIRE(buf.Size() == 0); | ||
| 127 | printf("RingBuffer: Threaded Test: full: %zu, empty: %zu\n", full, empty); | ||
| 128 | } | ||
| 129 | |||
| 130 | } // namespace Common | ||
diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h index 9176a8dbc..58f2904ce 100644 --- a/src/video_core/engines/shader_bytecode.h +++ b/src/video_core/engines/shader_bytecode.h | |||
| @@ -254,6 +254,15 @@ enum class TextureQueryType : u64 { | |||
| 254 | BorderColor = 22, | 254 | BorderColor = 22, |
| 255 | }; | 255 | }; |
| 256 | 256 | ||
| 257 | enum class TextureProcessMode : u64 { | ||
| 258 | None = 0, | ||
| 259 | LZ = 1, // Unknown, appears to be the same as none. | ||
| 260 | LB = 2, // Load Bias. | ||
| 261 | LL = 3, // Load LOD (LevelOfDetail) | ||
| 262 | LBA = 6, // Load Bias. The A is unknown, does not appear to differ with LB | ||
| 263 | LLA = 7 // Load LOD. The A is unknown, does not appear to differ with LL | ||
| 264 | }; | ||
| 265 | |||
| 257 | enum class IpaInterpMode : u64 { Linear = 0, Perspective = 1, Flat = 2, Sc = 3 }; | 266 | enum class IpaInterpMode : u64 { Linear = 0, Perspective = 1, Flat = 2, Sc = 3 }; |
| 258 | enum class IpaSampleMode : u64 { Default = 0, Centroid = 1, Offset = 2 }; | 267 | enum class IpaSampleMode : u64 { Default = 0, Centroid = 1, Offset = 2 }; |
| 259 | 268 | ||
| @@ -424,6 +433,45 @@ union Instruction { | |||
| 424 | } bfe; | 433 | } bfe; |
| 425 | 434 | ||
| 426 | union { | 435 | union { |
| 436 | BitField<48, 3, u64> pred48; | ||
| 437 | |||
| 438 | union { | ||
| 439 | BitField<20, 20, u64> entry_a; | ||
| 440 | BitField<39, 5, u64> entry_b; | ||
| 441 | BitField<45, 1, u64> neg; | ||
| 442 | BitField<46, 1, u64> uses_cc; | ||
| 443 | } imm; | ||
| 444 | |||
| 445 | union { | ||
| 446 | BitField<20, 14, u64> cb_index; | ||
| 447 | BitField<34, 5, u64> cb_offset; | ||
| 448 | BitField<56, 1, u64> neg; | ||
| 449 | BitField<57, 1, u64> uses_cc; | ||
| 450 | } hi; | ||
| 451 | |||
| 452 | union { | ||
| 453 | BitField<20, 14, u64> cb_index; | ||
| 454 | BitField<34, 5, u64> cb_offset; | ||
| 455 | BitField<39, 5, u64> entry_a; | ||
| 456 | BitField<45, 1, u64> neg; | ||
| 457 | BitField<46, 1, u64> uses_cc; | ||
| 458 | } rz; | ||
| 459 | |||
| 460 | union { | ||
| 461 | BitField<39, 5, u64> entry_a; | ||
| 462 | BitField<45, 1, u64> neg; | ||
| 463 | BitField<46, 1, u64> uses_cc; | ||
| 464 | } r1; | ||
| 465 | |||
| 466 | union { | ||
| 467 | BitField<28, 8, u64> entry_a; | ||
| 468 | BitField<37, 1, u64> neg; | ||
| 469 | BitField<38, 1, u64> uses_cc; | ||
| 470 | } r2; | ||
| 471 | |||
| 472 | } lea; | ||
| 473 | |||
| 474 | union { | ||
| 427 | BitField<0, 5, FlowCondition> cond; | 475 | BitField<0, 5, FlowCondition> cond; |
| 428 | } flow; | 476 | } flow; |
| 429 | 477 | ||
| @@ -478,6 +526,18 @@ union Instruction { | |||
| 478 | } psetp; | 526 | } psetp; |
| 479 | 527 | ||
| 480 | union { | 528 | union { |
| 529 | BitField<12, 3, u64> pred12; | ||
| 530 | BitField<15, 1, u64> neg_pred12; | ||
| 531 | BitField<24, 2, PredOperation> cond; | ||
| 532 | BitField<29, 3, u64> pred29; | ||
| 533 | BitField<32, 1, u64> neg_pred29; | ||
| 534 | BitField<39, 3, u64> pred39; | ||
| 535 | BitField<42, 1, u64> neg_pred39; | ||
| 536 | BitField<44, 1, u64> bf; | ||
| 537 | BitField<45, 2, PredOperation> op; | ||
| 538 | } pset; | ||
| 539 | |||
| 540 | union { | ||
| 481 | BitField<39, 3, u64> pred39; | 541 | BitField<39, 3, u64> pred39; |
| 482 | BitField<42, 1, u64> neg_pred; | 542 | BitField<42, 1, u64> neg_pred; |
| 483 | BitField<43, 1, u64> neg_a; | 543 | BitField<43, 1, u64> neg_a; |
| @@ -522,6 +582,7 @@ union Instruction { | |||
| 522 | BitField<28, 1, u64> array; | 582 | BitField<28, 1, u64> array; |
| 523 | BitField<29, 2, TextureType> texture_type; | 583 | BitField<29, 2, TextureType> texture_type; |
| 524 | BitField<31, 4, u64> component_mask; | 584 | BitField<31, 4, u64> component_mask; |
| 585 | BitField<55, 3, TextureProcessMode> process_mode; | ||
| 525 | 586 | ||
| 526 | bool IsComponentEnabled(size_t component) const { | 587 | bool IsComponentEnabled(size_t component) const { |
| 527 | return ((1ull << component) & component_mask) != 0; | 588 | return ((1ull << component) & component_mask) != 0; |
| @@ -726,6 +787,11 @@ public: | |||
| 726 | ISCADD_C, // Scale and Add | 787 | ISCADD_C, // Scale and Add |
| 727 | ISCADD_R, | 788 | ISCADD_R, |
| 728 | ISCADD_IMM, | 789 | ISCADD_IMM, |
| 790 | LEA_R1, | ||
| 791 | LEA_R2, | ||
| 792 | LEA_RZ, | ||
| 793 | LEA_IMM, | ||
| 794 | LEA_HI, | ||
| 729 | POPC_C, | 795 | POPC_C, |
| 730 | POPC_R, | 796 | POPC_R, |
| 731 | POPC_IMM, | 797 | POPC_IMM, |
| @@ -784,6 +850,7 @@ public: | |||
| 784 | ISET_C, | 850 | ISET_C, |
| 785 | ISET_IMM, | 851 | ISET_IMM, |
| 786 | PSETP, | 852 | PSETP, |
| 853 | PSET, | ||
| 787 | XMAD_IMM, | 854 | XMAD_IMM, |
| 788 | XMAD_CR, | 855 | XMAD_CR, |
| 789 | XMAD_RC, | 856 | XMAD_RC, |
| @@ -807,6 +874,7 @@ public: | |||
| 807 | IntegerSet, | 874 | IntegerSet, |
| 808 | IntegerSetPredicate, | 875 | IntegerSetPredicate, |
| 809 | PredicateSetPredicate, | 876 | PredicateSetPredicate, |
| 877 | PredicateSetRegister, | ||
| 810 | Conversion, | 878 | Conversion, |
| 811 | Xmad, | 879 | Xmad, |
| 812 | Unknown, | 880 | Unknown, |
| @@ -958,6 +1026,11 @@ private: | |||
| 958 | INST("0100110010100---", Id::SEL_C, Type::ArithmeticInteger, "SEL_C"), | 1026 | INST("0100110010100---", Id::SEL_C, Type::ArithmeticInteger, "SEL_C"), |
| 959 | INST("0101110010100---", Id::SEL_R, Type::ArithmeticInteger, "SEL_R"), | 1027 | INST("0101110010100---", Id::SEL_R, Type::ArithmeticInteger, "SEL_R"), |
| 960 | INST("0011100-10100---", Id::SEL_IMM, Type::ArithmeticInteger, "SEL_IMM"), | 1028 | INST("0011100-10100---", Id::SEL_IMM, Type::ArithmeticInteger, "SEL_IMM"), |
| 1029 | INST("0101101111011---", Id::LEA_R2, Type::ArithmeticInteger, "LEA_R2"), | ||
| 1030 | INST("0101101111010---", Id::LEA_R1, Type::ArithmeticInteger, "LEA_R1"), | ||
| 1031 | INST("001101101101----", Id::LEA_IMM, Type::ArithmeticInteger, "LEA_IMM"), | ||
| 1032 | INST("010010111101----", Id::LEA_RZ, Type::ArithmeticInteger, "LEA_RZ"), | ||
| 1033 | INST("00011000--------", Id::LEA_HI, Type::ArithmeticInteger, "LEA_HI"), | ||
| 961 | INST("0101000010000---", Id::MUFU, Type::Arithmetic, "MUFU"), | 1034 | INST("0101000010000---", Id::MUFU, Type::Arithmetic, "MUFU"), |
| 962 | INST("0100110010010---", Id::RRO_C, Type::Arithmetic, "RRO_C"), | 1035 | INST("0100110010010---", Id::RRO_C, Type::Arithmetic, "RRO_C"), |
| 963 | INST("0101110010010---", Id::RRO_R, Type::Arithmetic, "RRO_R"), | 1036 | INST("0101110010010---", Id::RRO_R, Type::Arithmetic, "RRO_R"), |
| @@ -1012,6 +1085,7 @@ private: | |||
| 1012 | INST("010110110101----", Id::ISET_R, Type::IntegerSet, "ISET_R"), | 1085 | INST("010110110101----", Id::ISET_R, Type::IntegerSet, "ISET_R"), |
| 1013 | INST("010010110101----", Id::ISET_C, Type::IntegerSet, "ISET_C"), | 1086 | INST("010010110101----", Id::ISET_C, Type::IntegerSet, "ISET_C"), |
| 1014 | INST("0011011-0101----", Id::ISET_IMM, Type::IntegerSet, "ISET_IMM"), | 1087 | INST("0011011-0101----", Id::ISET_IMM, Type::IntegerSet, "ISET_IMM"), |
| 1088 | INST("0101000010001---", Id::PSET, Type::PredicateSetRegister, "PSET"), | ||
| 1015 | INST("0101000010010---", Id::PSETP, Type::PredicateSetPredicate, "PSETP"), | 1089 | INST("0101000010010---", Id::PSETP, Type::PredicateSetPredicate, "PSETP"), |
| 1016 | INST("0011011-00------", Id::XMAD_IMM, Type::Xmad, "XMAD_IMM"), | 1090 | INST("0011011-00------", Id::XMAD_IMM, Type::Xmad, "XMAD_IMM"), |
| 1017 | INST("0100111---------", Id::XMAD_CR, Type::Xmad, "XMAD_CR"), | 1091 | INST("0100111---------", Id::XMAD_CR, Type::Xmad, "XMAD_CR"), |
diff --git a/src/video_core/renderer_base.cpp b/src/video_core/renderer_base.cpp index be17a2b9c..0df3725c2 100644 --- a/src/video_core/renderer_base.cpp +++ b/src/video_core/renderer_base.cpp | |||
| @@ -19,6 +19,7 @@ void RendererBase::RefreshBaseSettings() { | |||
| 19 | UpdateCurrentFramebufferLayout(); | 19 | UpdateCurrentFramebufferLayout(); |
| 20 | 20 | ||
| 21 | renderer_settings.use_framelimiter = Settings::values.use_frame_limit; | 21 | renderer_settings.use_framelimiter = Settings::values.use_frame_limit; |
| 22 | renderer_settings.set_background_color = true; | ||
| 22 | } | 23 | } |
| 23 | 24 | ||
| 24 | void RendererBase::UpdateCurrentFramebufferLayout() { | 25 | void RendererBase::UpdateCurrentFramebufferLayout() { |
diff --git a/src/video_core/renderer_base.h b/src/video_core/renderer_base.h index 2a357f9d0..2cd0738ff 100644 --- a/src/video_core/renderer_base.h +++ b/src/video_core/renderer_base.h | |||
| @@ -19,6 +19,7 @@ namespace VideoCore { | |||
| 19 | 19 | ||
| 20 | struct RendererSettings { | 20 | struct RendererSettings { |
| 21 | std::atomic_bool use_framelimiter{false}; | 21 | std::atomic_bool use_framelimiter{false}; |
| 22 | std::atomic_bool set_background_color{false}; | ||
| 22 | }; | 23 | }; |
| 23 | 24 | ||
| 24 | class RendererBase : NonCopyable { | 25 | class RendererBase : NonCopyable { |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index 29d61eccd..32001e44b 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | |||
| @@ -53,8 +53,6 @@ static VAddr TryGetCpuAddr(Tegra::GPUVAddr gpu_addr) { | |||
| 53 | params.width = Common::AlignUp(config.tic.Width(), GetCompressionFactor(params.pixel_format)); | 53 | params.width = Common::AlignUp(config.tic.Width(), GetCompressionFactor(params.pixel_format)); |
| 54 | params.height = Common::AlignUp(config.tic.Height(), GetCompressionFactor(params.pixel_format)); | 54 | params.height = Common::AlignUp(config.tic.Height(), GetCompressionFactor(params.pixel_format)); |
| 55 | params.unaligned_height = config.tic.Height(); | 55 | params.unaligned_height = config.tic.Height(); |
| 56 | params.cache_width = Common::AlignUp(params.width, 8); | ||
| 57 | params.cache_height = Common::AlignUp(params.height, 8); | ||
| 58 | params.target = SurfaceTargetFromTextureType(config.tic.texture_type); | 56 | params.target = SurfaceTargetFromTextureType(config.tic.texture_type); |
| 59 | 57 | ||
| 60 | switch (params.target) { | 58 | switch (params.target) { |
| @@ -89,8 +87,6 @@ static VAddr TryGetCpuAddr(Tegra::GPUVAddr gpu_addr) { | |||
| 89 | params.width = config.width; | 87 | params.width = config.width; |
| 90 | params.height = config.height; | 88 | params.height = config.height; |
| 91 | params.unaligned_height = config.height; | 89 | params.unaligned_height = config.height; |
| 92 | params.cache_width = Common::AlignUp(params.width, 8); | ||
| 93 | params.cache_height = Common::AlignUp(params.height, 8); | ||
| 94 | params.target = SurfaceTarget::Texture2D; | 90 | params.target = SurfaceTarget::Texture2D; |
| 95 | params.depth = 1; | 91 | params.depth = 1; |
| 96 | params.size_in_bytes = params.SizeInBytes(); | 92 | params.size_in_bytes = params.SizeInBytes(); |
| @@ -110,8 +106,6 @@ static VAddr TryGetCpuAddr(Tegra::GPUVAddr gpu_addr) { | |||
| 110 | params.width = zeta_width; | 106 | params.width = zeta_width; |
| 111 | params.height = zeta_height; | 107 | params.height = zeta_height; |
| 112 | params.unaligned_height = zeta_height; | 108 | params.unaligned_height = zeta_height; |
| 113 | params.cache_width = Common::AlignUp(params.width, 8); | ||
| 114 | params.cache_height = Common::AlignUp(params.height, 8); | ||
| 115 | params.target = SurfaceTarget::Texture2D; | 109 | params.target = SurfaceTarget::Texture2D; |
| 116 | params.depth = 1; | 110 | params.depth = 1; |
| 117 | params.size_in_bytes = params.SizeInBytes(); | 111 | params.size_in_bytes = params.SizeInBytes(); |
| @@ -122,7 +116,7 @@ static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_form | |||
| 122 | {GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, ComponentType::UNorm, false}, // ABGR8U | 116 | {GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, ComponentType::UNorm, false}, // ABGR8U |
| 123 | {GL_RGBA8, GL_RGBA, GL_BYTE, ComponentType::SNorm, false}, // ABGR8S | 117 | {GL_RGBA8, GL_RGBA, GL_BYTE, ComponentType::SNorm, false}, // ABGR8S |
| 124 | {GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, ComponentType::UInt, false}, // ABGR8UI | 118 | {GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, ComponentType::UInt, false}, // ABGR8UI |
| 125 | {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, ComponentType::UNorm, false}, // B5G6R5U | 119 | {GL_RGB8, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, ComponentType::UNorm, false}, // B5G6R5U |
| 126 | {GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, ComponentType::UNorm, | 120 | {GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, ComponentType::UNorm, |
| 127 | false}, // A2B10G10R10U | 121 | false}, // A2B10G10R10U |
| 128 | {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, ComponentType::UNorm, false}, // A1B5G5R5U | 122 | {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, ComponentType::UNorm, false}, // A1B5G5R5U |
| @@ -477,30 +471,27 @@ CachedSurface::CachedSurface(const SurfaceParams& params) | |||
| 477 | // Only pre-create the texture for non-compressed textures. | 471 | // Only pre-create the texture for non-compressed textures. |
| 478 | switch (params.target) { | 472 | switch (params.target) { |
| 479 | case SurfaceParams::SurfaceTarget::Texture1D: | 473 | case SurfaceParams::SurfaceTarget::Texture1D: |
| 480 | glTexImage1D(SurfaceTargetToGL(params.target), 0, format_tuple.internal_format, | 474 | glTexStorage1D(SurfaceTargetToGL(params.target), 1, format_tuple.internal_format, |
| 481 | rect.GetWidth(), 0, format_tuple.format, format_tuple.type, nullptr); | 475 | rect.GetWidth()); |
| 482 | break; | 476 | break; |
| 483 | case SurfaceParams::SurfaceTarget::Texture2D: | 477 | case SurfaceParams::SurfaceTarget::Texture2D: |
| 484 | glTexImage2D(SurfaceTargetToGL(params.target), 0, format_tuple.internal_format, | 478 | glTexStorage2D(SurfaceTargetToGL(params.target), 1, format_tuple.internal_format, |
| 485 | rect.GetWidth(), rect.GetHeight(), 0, format_tuple.format, | 479 | rect.GetWidth(), rect.GetHeight()); |
| 486 | format_tuple.type, nullptr); | ||
| 487 | break; | 480 | break; |
| 488 | case SurfaceParams::SurfaceTarget::Texture3D: | 481 | case SurfaceParams::SurfaceTarget::Texture3D: |
| 489 | case SurfaceParams::SurfaceTarget::Texture2DArray: | 482 | case SurfaceParams::SurfaceTarget::Texture2DArray: |
| 490 | glTexImage3D(SurfaceTargetToGL(params.target), 0, format_tuple.internal_format, | 483 | glTexStorage3D(SurfaceTargetToGL(params.target), 1, format_tuple.internal_format, |
| 491 | rect.GetWidth(), rect.GetHeight(), params.depth, 0, format_tuple.format, | 484 | rect.GetWidth(), rect.GetHeight(), params.depth); |
| 492 | format_tuple.type, nullptr); | ||
| 493 | break; | 485 | break; |
| 494 | default: | 486 | default: |
| 495 | LOG_CRITICAL(Render_OpenGL, "Unimplemented surface target={}", | 487 | LOG_CRITICAL(Render_OpenGL, "Unimplemented surface target={}", |
| 496 | static_cast<u32>(params.target)); | 488 | static_cast<u32>(params.target)); |
| 497 | UNREACHABLE(); | 489 | UNREACHABLE(); |
| 498 | glTexImage2D(GL_TEXTURE_2D, 0, format_tuple.internal_format, rect.GetWidth(), | 490 | glTexStorage2D(GL_TEXTURE_2D, 1, format_tuple.internal_format, rect.GetWidth(), |
| 499 | rect.GetHeight(), 0, format_tuple.format, format_tuple.type, nullptr); | 491 | rect.GetHeight()); |
| 500 | } | 492 | } |
| 501 | } | 493 | } |
| 502 | 494 | ||
| 503 | glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_MAX_LEVEL, 0); | ||
| 504 | glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 495 | glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 505 | glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 496 | glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 506 | glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 497 | glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| @@ -817,16 +808,20 @@ Surface RasterizerCacheOpenGL::RecreateSurface(const Surface& surface, | |||
| 817 | // Get a new surface with the new parameters, and blit the previous surface to it | 808 | // Get a new surface with the new parameters, and blit the previous surface to it |
| 818 | Surface new_surface{GetUncachedSurface(new_params)}; | 809 | Surface new_surface{GetUncachedSurface(new_params)}; |
| 819 | 810 | ||
| 820 | // If format is unchanged, we can do a faster blit without reinterpreting pixel data | 811 | if (params.pixel_format == new_params.pixel_format || |
| 821 | if (params.pixel_format == new_params.pixel_format) { | 812 | !Settings::values.use_accurate_framebuffers) { |
| 813 | // If the format is the same, just do a framebuffer blit. This is significantly faster than | ||
| 814 | // using PBOs. The is also likely less accurate, as textures will be converted rather than | ||
| 815 | // reinterpreted. | ||
| 816 | |||
| 822 | BlitTextures(surface->Texture().handle, params.GetRect(), new_surface->Texture().handle, | 817 | BlitTextures(surface->Texture().handle, params.GetRect(), new_surface->Texture().handle, |
| 823 | params.GetRect(), params.type, read_framebuffer.handle, | 818 | params.GetRect(), params.type, read_framebuffer.handle, |
| 824 | draw_framebuffer.handle); | 819 | draw_framebuffer.handle); |
| 825 | return new_surface; | 820 | } else { |
| 826 | } | 821 | // When use_accurate_framebuffers setting is enabled, perform a more accurate surface copy, |
| 822 | // where pixels are reinterpreted as a new format (without conversion). This code path uses | ||
| 823 | // OpenGL PBOs and is quite slow. | ||
| 827 | 824 | ||
| 828 | // When using accurate framebuffers, always copy old data to new surface, regardless of format | ||
| 829 | if (Settings::values.use_accurate_framebuffers) { | ||
| 830 | auto source_format = GetFormatTuple(params.pixel_format, params.component_type); | 825 | auto source_format = GetFormatTuple(params.pixel_format, params.component_type); |
| 831 | auto dest_format = GetFormatTuple(new_params.pixel_format, new_params.component_type); | 826 | auto dest_format = GetFormatTuple(new_params.pixel_format, new_params.component_type); |
| 832 | 827 | ||
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h index e660998d0..57ea8593b 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h | |||
| @@ -680,8 +680,8 @@ struct SurfaceParams { | |||
| 680 | 680 | ||
| 681 | /// Checks if surfaces are compatible for caching | 681 | /// Checks if surfaces are compatible for caching |
| 682 | bool IsCompatibleSurface(const SurfaceParams& other) const { | 682 | bool IsCompatibleSurface(const SurfaceParams& other) const { |
| 683 | return std::tie(pixel_format, type, cache_width, cache_height) == | 683 | return std::tie(pixel_format, type, width, height) == |
| 684 | std::tie(other.pixel_format, other.type, other.cache_width, other.cache_height); | 684 | std::tie(other.pixel_format, other.type, other.width, other.height); |
| 685 | } | 685 | } |
| 686 | 686 | ||
| 687 | VAddr addr; | 687 | VAddr addr; |
| @@ -696,10 +696,6 @@ struct SurfaceParams { | |||
| 696 | u32 unaligned_height; | 696 | u32 unaligned_height; |
| 697 | size_t size_in_bytes; | 697 | size_t size_in_bytes; |
| 698 | SurfaceTarget target; | 698 | SurfaceTarget target; |
| 699 | |||
| 700 | // Parameters used for caching only | ||
| 701 | u32 cache_width; | ||
| 702 | u32 cache_height; | ||
| 703 | }; | 699 | }; |
| 704 | 700 | ||
| 705 | }; // namespace OpenGL | 701 | }; // namespace OpenGL |
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index e350113f1..2d56370c7 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |||
| @@ -1505,6 +1505,73 @@ private: | |||
| 1505 | 1, 1); | 1505 | 1, 1); |
| 1506 | break; | 1506 | break; |
| 1507 | } | 1507 | } |
| 1508 | case OpCode::Id::LEA_R2: | ||
| 1509 | case OpCode::Id::LEA_R1: | ||
| 1510 | case OpCode::Id::LEA_IMM: | ||
| 1511 | case OpCode::Id::LEA_RZ: | ||
| 1512 | case OpCode::Id::LEA_HI: { | ||
| 1513 | std::string op_a; | ||
| 1514 | std::string op_b; | ||
| 1515 | std::string op_c; | ||
| 1516 | |||
| 1517 | switch (opcode->GetId()) { | ||
| 1518 | case OpCode::Id::LEA_R2: { | ||
| 1519 | op_a = regs.GetRegisterAsInteger(instr.gpr20); | ||
| 1520 | op_b = regs.GetRegisterAsInteger(instr.gpr39); | ||
| 1521 | op_c = std::to_string(instr.lea.r2.entry_a); | ||
| 1522 | break; | ||
| 1523 | } | ||
| 1524 | |||
| 1525 | case OpCode::Id::LEA_R1: { | ||
| 1526 | const bool neg = instr.lea.r1.neg != 0; | ||
| 1527 | op_a = regs.GetRegisterAsInteger(instr.gpr8); | ||
| 1528 | if (neg) | ||
| 1529 | op_a = "-(" + op_a + ')'; | ||
| 1530 | op_b = regs.GetRegisterAsInteger(instr.gpr20); | ||
| 1531 | op_c = std::to_string(instr.lea.r1.entry_a); | ||
| 1532 | break; | ||
| 1533 | } | ||
| 1534 | |||
| 1535 | case OpCode::Id::LEA_IMM: { | ||
| 1536 | const bool neg = instr.lea.imm.neg != 0; | ||
| 1537 | op_b = regs.GetRegisterAsInteger(instr.gpr8); | ||
| 1538 | if (neg) | ||
| 1539 | op_b = "-(" + op_b + ')'; | ||
| 1540 | op_a = std::to_string(instr.lea.imm.entry_a); | ||
| 1541 | op_c = std::to_string(instr.lea.imm.entry_b); | ||
| 1542 | break; | ||
| 1543 | } | ||
| 1544 | |||
| 1545 | case OpCode::Id::LEA_RZ: { | ||
| 1546 | const bool neg = instr.lea.rz.neg != 0; | ||
| 1547 | op_b = regs.GetRegisterAsInteger(instr.gpr8); | ||
| 1548 | if (neg) | ||
| 1549 | op_b = "-(" + op_b + ')'; | ||
| 1550 | op_a = regs.GetUniform(instr.lea.rz.cb_index, instr.lea.rz.cb_offset, | ||
| 1551 | GLSLRegister::Type::Integer); | ||
| 1552 | op_c = std::to_string(instr.lea.rz.entry_a); | ||
| 1553 | |||
| 1554 | break; | ||
| 1555 | } | ||
| 1556 | |||
| 1557 | case OpCode::Id::LEA_HI: | ||
| 1558 | default: { | ||
| 1559 | op_b = regs.GetRegisterAsInteger(instr.gpr8); | ||
| 1560 | op_a = std::to_string(instr.lea.imm.entry_a); | ||
| 1561 | op_c = std::to_string(instr.lea.imm.entry_b); | ||
| 1562 | LOG_CRITICAL(HW_GPU, "Unhandled LEA subinstruction: {}", opcode->GetName()); | ||
| 1563 | UNREACHABLE(); | ||
| 1564 | } | ||
| 1565 | } | ||
| 1566 | if (instr.lea.pred48 != static_cast<u64>(Pred::UnusedIndex)) { | ||
| 1567 | LOG_ERROR(HW_GPU, "Unhandled LEA Predicate"); | ||
| 1568 | UNREACHABLE(); | ||
| 1569 | } | ||
| 1570 | const std::string value = '(' + op_a + " + (" + op_b + "*(1 << " + op_c + ")))"; | ||
| 1571 | regs.SetRegisterToInteger(instr.gpr0, true, 0, value, 1, 1); | ||
| 1572 | |||
| 1573 | break; | ||
| 1574 | } | ||
| 1508 | default: { | 1575 | default: { |
| 1509 | LOG_CRITICAL(HW_GPU, "Unhandled ArithmeticInteger instruction: {}", | 1576 | LOG_CRITICAL(HW_GPU, "Unhandled ArithmeticInteger instruction: {}", |
| 1510 | opcode->GetName()); | 1577 | opcode->GetName()); |
| @@ -1786,15 +1853,47 @@ private: | |||
| 1786 | coord = "vec2 coords = vec2(" + x + ", " + y + ");"; | 1853 | coord = "vec2 coords = vec2(" + x + ", " + y + ");"; |
| 1787 | texture_type = Tegra::Shader::TextureType::Texture2D; | 1854 | texture_type = Tegra::Shader::TextureType::Texture2D; |
| 1788 | } | 1855 | } |
| 1856 | // TODO: make sure coordinates are always indexed to gpr8 and gpr20 is always bias | ||
| 1857 | // or lod. | ||
| 1858 | const std::string op_c = regs.GetRegisterAsFloat(instr.gpr20); | ||
| 1789 | 1859 | ||
| 1790 | const std::string sampler = GetSampler(instr.sampler, texture_type, false); | 1860 | const std::string sampler = GetSampler(instr.sampler, texture_type, false); |
| 1791 | // Add an extra scope and declare the texture coords inside to prevent | 1861 | // Add an extra scope and declare the texture coords inside to prevent |
| 1792 | // overwriting them in case they are used as outputs of the texs instruction. | 1862 | // overwriting them in case they are used as outputs of the texs instruction. |
| 1863 | |||
| 1793 | shader.AddLine("{"); | 1864 | shader.AddLine("{"); |
| 1794 | ++shader.scope; | 1865 | ++shader.scope; |
| 1795 | shader.AddLine(coord); | 1866 | shader.AddLine(coord); |
| 1796 | const std::string texture = "texture(" + sampler + ", coords)"; | 1867 | std::string texture; |
| 1797 | 1868 | ||
| 1869 | switch (instr.tex.process_mode) { | ||
| 1870 | case Tegra::Shader::TextureProcessMode::None: { | ||
| 1871 | texture = "texture(" + sampler + ", coords)"; | ||
| 1872 | break; | ||
| 1873 | } | ||
| 1874 | case Tegra::Shader::TextureProcessMode::LZ: { | ||
| 1875 | texture = "textureLod(" + sampler + ", coords, 0.0)"; | ||
| 1876 | break; | ||
| 1877 | } | ||
| 1878 | case Tegra::Shader::TextureProcessMode::LB: | ||
| 1879 | case Tegra::Shader::TextureProcessMode::LBA: { | ||
| 1880 | // TODO: Figure if A suffix changes the equation at all. | ||
| 1881 | texture = "texture(" + sampler + ", coords, " + op_c + ')'; | ||
| 1882 | break; | ||
| 1883 | } | ||
| 1884 | case Tegra::Shader::TextureProcessMode::LL: | ||
| 1885 | case Tegra::Shader::TextureProcessMode::LLA: { | ||
| 1886 | // TODO: Figure if A suffix changes the equation at all. | ||
| 1887 | texture = "textureLod(" + sampler + ", coords, " + op_c + ')'; | ||
| 1888 | break; | ||
| 1889 | } | ||
| 1890 | default: { | ||
| 1891 | texture = "texture(" + sampler + ", coords)"; | ||
| 1892 | LOG_CRITICAL(HW_GPU, "Unhandled texture process mode {}", | ||
| 1893 | static_cast<u32>(instr.tex.process_mode.Value())); | ||
| 1894 | UNREACHABLE(); | ||
| 1895 | } | ||
| 1896 | } | ||
| 1798 | size_t dest_elem{}; | 1897 | size_t dest_elem{}; |
| 1799 | for (size_t elem = 0; elem < 4; ++elem) { | 1898 | for (size_t elem = 0; elem < 4; ++elem) { |
| 1800 | if (!instr.tex.IsComponentEnabled(elem)) { | 1899 | if (!instr.tex.IsComponentEnabled(elem)) { |
| @@ -2087,6 +2186,30 @@ private: | |||
| 2087 | } | 2186 | } |
| 2088 | break; | 2187 | break; |
| 2089 | } | 2188 | } |
| 2189 | case OpCode::Type::PredicateSetRegister: { | ||
| 2190 | const std::string op_a = | ||
| 2191 | GetPredicateCondition(instr.pset.pred12, instr.pset.neg_pred12 != 0); | ||
| 2192 | const std::string op_b = | ||
| 2193 | GetPredicateCondition(instr.pset.pred29, instr.pset.neg_pred29 != 0); | ||
| 2194 | |||
| 2195 | const std::string second_pred = | ||
| 2196 | GetPredicateCondition(instr.pset.pred39, instr.pset.neg_pred39 != 0); | ||
| 2197 | |||
| 2198 | const std::string combiner = GetPredicateCombiner(instr.pset.op); | ||
| 2199 | |||
| 2200 | const std::string predicate = | ||
| 2201 | '(' + op_a + ") " + GetPredicateCombiner(instr.pset.cond) + " (" + op_b + ')'; | ||
| 2202 | const std::string result = '(' + predicate + ") " + combiner + " (" + second_pred + ')'; | ||
| 2203 | if (instr.pset.bf == 0) { | ||
| 2204 | const std::string value = '(' + result + ") ? 0xFFFFFFFF : 0"; | ||
| 2205 | regs.SetRegisterToInteger(instr.gpr0, false, 0, value, 1, 1); | ||
| 2206 | } else { | ||
| 2207 | const std::string value = '(' + result + ") ? 1.0 : 0.0"; | ||
| 2208 | regs.SetRegisterToFloat(instr.gpr0, 0, value, 1, 1); | ||
| 2209 | } | ||
| 2210 | |||
| 2211 | break; | ||
| 2212 | } | ||
| 2090 | case OpCode::Type::PredicateSetPredicate: { | 2213 | case OpCode::Type::PredicateSetPredicate: { |
| 2091 | const std::string op_a = | 2214 | const std::string op_a = |
| 2092 | GetPredicateCondition(instr.psetp.pred12, instr.psetp.neg_pred12 != 0); | 2215 | GetPredicateCondition(instr.psetp.pred12, instr.psetp.neg_pred12 != 0); |
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index ccff3e342..96d916b07 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp | |||
| @@ -369,6 +369,12 @@ void RendererOpenGL::DrawScreenTriangles(const ScreenInfo& screen_info, float x, | |||
| 369 | * Draws the emulated screens to the emulator window. | 369 | * Draws the emulated screens to the emulator window. |
| 370 | */ | 370 | */ |
| 371 | void RendererOpenGL::DrawScreen() { | 371 | void RendererOpenGL::DrawScreen() { |
| 372 | if (renderer_settings.set_background_color) { | ||
| 373 | // Update background color before drawing | ||
| 374 | glClearColor(Settings::values.bg_red, Settings::values.bg_green, Settings::values.bg_blue, | ||
| 375 | 0.0f); | ||
| 376 | } | ||
| 377 | |||
| 372 | const auto& layout = render_window.GetFramebufferLayout(); | 378 | const auto& layout = render_window.GetFramebufferLayout(); |
| 373 | const auto& screen = layout.screen; | 379 | const auto& screen = layout.screen; |
| 374 | 380 | ||
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index c43e79e78..d229225b4 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp | |||
| @@ -95,6 +95,8 @@ void Config::ReadValues() { | |||
| 95 | 95 | ||
| 96 | qt_config->beginGroup("Audio"); | 96 | qt_config->beginGroup("Audio"); |
| 97 | Settings::values.sink_id = qt_config->value("output_engine", "auto").toString().toStdString(); | 97 | Settings::values.sink_id = qt_config->value("output_engine", "auto").toString().toStdString(); |
| 98 | Settings::values.enable_audio_stretching = | ||
| 99 | qt_config->value("enable_audio_stretching", true).toBool(); | ||
| 98 | Settings::values.audio_device_id = | 100 | Settings::values.audio_device_id = |
| 99 | qt_config->value("output_device", "auto").toString().toStdString(); | 101 | qt_config->value("output_device", "auto").toString().toStdString(); |
| 100 | Settings::values.volume = qt_config->value("volume", 1).toFloat(); | 102 | Settings::values.volume = qt_config->value("volume", 1).toFloat(); |
| @@ -230,6 +232,7 @@ void Config::SaveValues() { | |||
| 230 | 232 | ||
| 231 | qt_config->beginGroup("Audio"); | 233 | qt_config->beginGroup("Audio"); |
| 232 | qt_config->setValue("output_engine", QString::fromStdString(Settings::values.sink_id)); | 234 | qt_config->setValue("output_engine", QString::fromStdString(Settings::values.sink_id)); |
| 235 | qt_config->setValue("enable_audio_stretching", Settings::values.enable_audio_stretching); | ||
| 233 | qt_config->setValue("output_device", QString::fromStdString(Settings::values.audio_device_id)); | 236 | qt_config->setValue("output_device", QString::fromStdString(Settings::values.audio_device_id)); |
| 234 | qt_config->setValue("volume", Settings::values.volume); | 237 | qt_config->setValue("volume", Settings::values.volume); |
| 235 | qt_config->endGroup(); | 238 | qt_config->endGroup(); |
diff --git a/src/yuzu/configuration/configure_audio.cpp b/src/yuzu/configuration/configure_audio.cpp index fbb813f6c..6ea59f2a3 100644 --- a/src/yuzu/configuration/configure_audio.cpp +++ b/src/yuzu/configuration/configure_audio.cpp | |||
| @@ -46,6 +46,8 @@ void ConfigureAudio::setConfiguration() { | |||
| 46 | } | 46 | } |
| 47 | ui->output_sink_combo_box->setCurrentIndex(new_sink_index); | 47 | ui->output_sink_combo_box->setCurrentIndex(new_sink_index); |
| 48 | 48 | ||
| 49 | ui->toggle_audio_stretching->setChecked(Settings::values.enable_audio_stretching); | ||
| 50 | |||
| 49 | // The device list cannot be pre-populated (nor listed) until the output sink is known. | 51 | // The device list cannot be pre-populated (nor listed) until the output sink is known. |
| 50 | updateAudioDevices(new_sink_index); | 52 | updateAudioDevices(new_sink_index); |
| 51 | 53 | ||
| @@ -67,6 +69,7 @@ void ConfigureAudio::applyConfiguration() { | |||
| 67 | Settings::values.sink_id = | 69 | Settings::values.sink_id = |
| 68 | ui->output_sink_combo_box->itemText(ui->output_sink_combo_box->currentIndex()) | 70 | ui->output_sink_combo_box->itemText(ui->output_sink_combo_box->currentIndex()) |
| 69 | .toStdString(); | 71 | .toStdString(); |
| 72 | Settings::values.enable_audio_stretching = ui->toggle_audio_stretching->isChecked(); | ||
| 70 | Settings::values.audio_device_id = | 73 | Settings::values.audio_device_id = |
| 71 | ui->audio_device_combo_box->itemText(ui->audio_device_combo_box->currentIndex()) | 74 | ui->audio_device_combo_box->itemText(ui->audio_device_combo_box->currentIndex()) |
| 72 | .toStdString(); | 75 | .toStdString(); |
diff --git a/src/yuzu/configuration/configure_audio.ui b/src/yuzu/configuration/configure_audio.ui index ef67890dc..a29a0e265 100644 --- a/src/yuzu/configuration/configure_audio.ui +++ b/src/yuzu/configuration/configure_audio.ui | |||
| @@ -31,6 +31,16 @@ | |||
| 31 | </item> | 31 | </item> |
| 32 | </layout> | 32 | </layout> |
| 33 | </item> | 33 | </item> |
| 34 | <item> | ||
| 35 | <widget class="QCheckBox" name="toggle_audio_stretching"> | ||
| 36 | <property name="toolTip"> | ||
| 37 | <string>This post-processing effect adjusts audio speed to match emulation speed and helps prevent audio stutter. This however increases audio latency.</string> | ||
| 38 | </property> | ||
| 39 | <property name="text"> | ||
| 40 | <string>Enable audio stretching</string> | ||
| 41 | </property> | ||
| 42 | </widget> | ||
| 43 | </item> | ||
| 34 | <item> | 44 | <item> |
| 35 | <layout class="QHBoxLayout"> | 45 | <layout class="QHBoxLayout"> |
| 36 | <item> | 46 | <item> |
diff --git a/src/yuzu/configuration/configure_gamelist.cpp b/src/yuzu/configuration/configure_gamelist.cpp index 1ae3423cf..0be030434 100644 --- a/src/yuzu/configuration/configure_gamelist.cpp +++ b/src/yuzu/configuration/configure_gamelist.cpp | |||
| @@ -2,47 +2,51 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "core/core.h" | 5 | #include <array> |
| 6 | #include <utility> | ||
| 7 | |||
| 8 | #include "common/common_types.h" | ||
| 6 | #include "core/settings.h" | 9 | #include "core/settings.h" |
| 7 | #include "ui_configure_gamelist.h" | 10 | #include "ui_configure_gamelist.h" |
| 8 | #include "ui_settings.h" | ||
| 9 | #include "yuzu/configuration/configure_gamelist.h" | 11 | #include "yuzu/configuration/configure_gamelist.h" |
| 12 | #include "yuzu/ui_settings.h" | ||
| 13 | |||
| 14 | namespace { | ||
| 15 | constexpr std::array<std::pair<u32, const char*>, 5> default_icon_sizes{{ | ||
| 16 | std::make_pair(0, QT_TR_NOOP("None")), | ||
| 17 | std::make_pair(32, QT_TR_NOOP("Small (32x32)")), | ||
| 18 | std::make_pair(64, QT_TR_NOOP("Standard (64x64)")), | ||
| 19 | std::make_pair(128, QT_TR_NOOP("Large (128x128)")), | ||
| 20 | std::make_pair(256, QT_TR_NOOP("Full Size (256x256)")), | ||
| 21 | }}; | ||
| 22 | |||
| 23 | constexpr std::array<const char*, 4> row_text_names{{ | ||
| 24 | QT_TR_NOOP("Filename"), | ||
| 25 | QT_TR_NOOP("Filetype"), | ||
| 26 | QT_TR_NOOP("Title ID"), | ||
| 27 | QT_TR_NOOP("Title Name"), | ||
| 28 | }}; | ||
| 29 | } // Anonymous namespace | ||
| 10 | 30 | ||
| 11 | ConfigureGameList::ConfigureGameList(QWidget* parent) | 31 | ConfigureGameList::ConfigureGameList(QWidget* parent) |
| 12 | : QWidget(parent), ui(new Ui::ConfigureGameList) { | 32 | : QWidget(parent), ui(new Ui::ConfigureGameList) { |
| 13 | ui->setupUi(this); | 33 | ui->setupUi(this); |
| 14 | 34 | ||
| 15 | static const std::vector<std::pair<u32, std::string>> default_icon_sizes{ | 35 | InitializeIconSizeComboBox(); |
| 16 | std::make_pair(0, "None"), std::make_pair(32, "Small"), | 36 | InitializeRowComboBoxes(); |
| 17 | std::make_pair(64, "Standard"), std::make_pair(128, "Large"), | ||
| 18 | std::make_pair(256, "Full Size"), | ||
| 19 | }; | ||
| 20 | |||
| 21 | for (const auto& size : default_icon_sizes) { | ||
| 22 | ui->icon_size_combobox->addItem(QString::fromStdString(size.second + " (" + | ||
| 23 | std::to_string(size.first) + "x" + | ||
| 24 | std::to_string(size.first) + ")"), | ||
| 25 | size.first); | ||
| 26 | } | ||
| 27 | |||
| 28 | static const std::vector<std::string> row_text_names{ | ||
| 29 | "Filename", | ||
| 30 | "Filetype", | ||
| 31 | "Title ID", | ||
| 32 | "Title Name", | ||
| 33 | }; | ||
| 34 | |||
| 35 | for (size_t i = 0; i < row_text_names.size(); ++i) { | ||
| 36 | ui->row_1_text_combobox->addItem(QString::fromStdString(row_text_names[i]), | ||
| 37 | QVariant::fromValue(i)); | ||
| 38 | ui->row_2_text_combobox->addItem(QString::fromStdString(row_text_names[i]), | ||
| 39 | QVariant::fromValue(i)); | ||
| 40 | } | ||
| 41 | 37 | ||
| 42 | this->setConfiguration(); | 38 | this->setConfiguration(); |
| 43 | } | 39 | } |
| 44 | 40 | ||
| 45 | ConfigureGameList::~ConfigureGameList() {} | 41 | ConfigureGameList::~ConfigureGameList() = default; |
| 42 | |||
| 43 | void ConfigureGameList::applyConfiguration() { | ||
| 44 | UISettings::values.show_unknown = ui->show_unknown->isChecked(); | ||
| 45 | UISettings::values.icon_size = ui->icon_size_combobox->currentData().toUInt(); | ||
| 46 | UISettings::values.row_1_text_id = ui->row_1_text_combobox->currentData().toUInt(); | ||
| 47 | UISettings::values.row_2_text_id = ui->row_2_text_combobox->currentData().toUInt(); | ||
| 48 | Settings::Apply(); | ||
| 49 | } | ||
| 46 | 50 | ||
| 47 | void ConfigureGameList::setConfiguration() { | 51 | void ConfigureGameList::setConfiguration() { |
| 48 | ui->show_unknown->setChecked(UISettings::values.show_unknown); | 52 | ui->show_unknown->setChecked(UISettings::values.show_unknown); |
| @@ -54,10 +58,39 @@ void ConfigureGameList::setConfiguration() { | |||
| 54 | ui->row_2_text_combobox->findData(UISettings::values.row_2_text_id)); | 58 | ui->row_2_text_combobox->findData(UISettings::values.row_2_text_id)); |
| 55 | } | 59 | } |
| 56 | 60 | ||
| 57 | void ConfigureGameList::applyConfiguration() { | 61 | void ConfigureGameList::changeEvent(QEvent* event) { |
| 58 | UISettings::values.show_unknown = ui->show_unknown->isChecked(); | 62 | if (event->type() == QEvent::LanguageChange) { |
| 59 | UISettings::values.icon_size = ui->icon_size_combobox->currentData().toUInt(); | 63 | RetranslateUI(); |
| 60 | UISettings::values.row_1_text_id = ui->row_1_text_combobox->currentData().toUInt(); | 64 | return; |
| 61 | UISettings::values.row_2_text_id = ui->row_2_text_combobox->currentData().toUInt(); | 65 | } |
| 62 | Settings::Apply(); | 66 | |
| 67 | QWidget::changeEvent(event); | ||
| 68 | } | ||
| 69 | |||
| 70 | void ConfigureGameList::RetranslateUI() { | ||
| 71 | ui->retranslateUi(this); | ||
| 72 | |||
| 73 | for (int i = 0; i < ui->icon_size_combobox->count(); i++) { | ||
| 74 | ui->icon_size_combobox->setItemText(i, tr(default_icon_sizes[i].second)); | ||
| 75 | } | ||
| 76 | |||
| 77 | for (int i = 0; i < ui->row_1_text_combobox->count(); i++) { | ||
| 78 | const QString name = tr(row_text_names[i]); | ||
| 79 | |||
| 80 | ui->row_1_text_combobox->setItemText(i, name); | ||
| 81 | ui->row_2_text_combobox->setItemText(i, name); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | void ConfigureGameList::InitializeIconSizeComboBox() { | ||
| 86 | for (const auto& size : default_icon_sizes) { | ||
| 87 | ui->icon_size_combobox->addItem(size.second, size.first); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | void ConfigureGameList::InitializeRowComboBoxes() { | ||
| 92 | for (size_t i = 0; i < row_text_names.size(); ++i) { | ||
| 93 | ui->row_1_text_combobox->addItem(row_text_names[i], QVariant::fromValue(i)); | ||
| 94 | ui->row_2_text_combobox->addItem(row_text_names[i], QVariant::fromValue(i)); | ||
| 95 | } | ||
| 63 | } | 96 | } |
diff --git a/src/yuzu/configuration/configure_gamelist.h b/src/yuzu/configuration/configure_gamelist.h index 94fba6373..ff7406c60 100644 --- a/src/yuzu/configuration/configure_gamelist.h +++ b/src/yuzu/configuration/configure_gamelist.h | |||
| @@ -23,6 +23,11 @@ public: | |||
| 23 | private: | 23 | private: |
| 24 | void setConfiguration(); | 24 | void setConfiguration(); |
| 25 | 25 | ||
| 26 | private: | 26 | void changeEvent(QEvent*) override; |
| 27 | void RetranslateUI(); | ||
| 28 | |||
| 29 | void InitializeIconSizeComboBox(); | ||
| 30 | void InitializeRowComboBoxes(); | ||
| 31 | |||
| 27 | std::unique_ptr<Ui::ConfigureGameList> ui; | 32 | std::unique_ptr<Ui::ConfigureGameList> ui; |
| 28 | }; | 33 | }; |
diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index ee1287028..839d58f59 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <QColorDialog> | ||
| 5 | #include "core/core.h" | 6 | #include "core/core.h" |
| 6 | #include "core/settings.h" | 7 | #include "core/settings.h" |
| 7 | #include "ui_configure_graphics.h" | 8 | #include "ui_configure_graphics.h" |
| @@ -16,6 +17,14 @@ ConfigureGraphics::ConfigureGraphics(QWidget* parent) | |||
| 16 | ui->frame_limit->setEnabled(Settings::values.use_frame_limit); | 17 | ui->frame_limit->setEnabled(Settings::values.use_frame_limit); |
| 17 | connect(ui->toggle_frame_limit, &QCheckBox::stateChanged, ui->frame_limit, | 18 | connect(ui->toggle_frame_limit, &QCheckBox::stateChanged, ui->frame_limit, |
| 18 | &QSpinBox::setEnabled); | 19 | &QSpinBox::setEnabled); |
| 20 | connect(ui->bg_button, &QPushButton::clicked, this, [this] { | ||
| 21 | const QColor new_bg_color = QColorDialog::getColor(bg_color); | ||
| 22 | if (!new_bg_color.isValid()) | ||
| 23 | return; | ||
| 24 | bg_color = new_bg_color; | ||
| 25 | ui->bg_button->setStyleSheet( | ||
| 26 | QString("QPushButton { background-color: %1 }").arg(bg_color.name())); | ||
| 27 | }); | ||
| 19 | } | 28 | } |
| 20 | 29 | ||
| 21 | ConfigureGraphics::~ConfigureGraphics() = default; | 30 | ConfigureGraphics::~ConfigureGraphics() = default; |
| @@ -65,6 +74,10 @@ void ConfigureGraphics::setConfiguration() { | |||
| 65 | ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit); | 74 | ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit); |
| 66 | ui->frame_limit->setValue(Settings::values.frame_limit); | 75 | ui->frame_limit->setValue(Settings::values.frame_limit); |
| 67 | ui->use_accurate_framebuffers->setChecked(Settings::values.use_accurate_framebuffers); | 76 | ui->use_accurate_framebuffers->setChecked(Settings::values.use_accurate_framebuffers); |
| 77 | bg_color = QColor::fromRgbF(Settings::values.bg_red, Settings::values.bg_green, | ||
| 78 | Settings::values.bg_blue); | ||
| 79 | ui->bg_button->setStyleSheet( | ||
| 80 | QString("QPushButton { background-color: %1 }").arg(bg_color.name())); | ||
| 68 | } | 81 | } |
| 69 | 82 | ||
| 70 | void ConfigureGraphics::applyConfiguration() { | 83 | void ConfigureGraphics::applyConfiguration() { |
| @@ -73,4 +86,7 @@ void ConfigureGraphics::applyConfiguration() { | |||
| 73 | Settings::values.use_frame_limit = ui->toggle_frame_limit->isChecked(); | 86 | Settings::values.use_frame_limit = ui->toggle_frame_limit->isChecked(); |
| 74 | Settings::values.frame_limit = ui->frame_limit->value(); | 87 | Settings::values.frame_limit = ui->frame_limit->value(); |
| 75 | Settings::values.use_accurate_framebuffers = ui->use_accurate_framebuffers->isChecked(); | 88 | Settings::values.use_accurate_framebuffers = ui->use_accurate_framebuffers->isChecked(); |
| 89 | Settings::values.bg_red = static_cast<float>(bg_color.redF()); | ||
| 90 | Settings::values.bg_green = static_cast<float>(bg_color.greenF()); | ||
| 91 | Settings::values.bg_blue = static_cast<float>(bg_color.blueF()); | ||
| 76 | } | 92 | } |
diff --git a/src/yuzu/configuration/configure_graphics.h b/src/yuzu/configuration/configure_graphics.h index 5497a55f7..9bda26fd6 100644 --- a/src/yuzu/configuration/configure_graphics.h +++ b/src/yuzu/configuration/configure_graphics.h | |||
| @@ -25,4 +25,5 @@ private: | |||
| 25 | 25 | ||
| 26 | private: | 26 | private: |
| 27 | std::unique_ptr<Ui::ConfigureGraphics> ui; | 27 | std::unique_ptr<Ui::ConfigureGraphics> ui; |
| 28 | QColor bg_color; | ||
| 28 | }; | 29 | }; |
diff --git a/src/yuzu/configuration/configure_graphics.ui b/src/yuzu/configuration/configure_graphics.ui index 3bc18c26e..8fc00af1b 100644 --- a/src/yuzu/configuration/configure_graphics.ui +++ b/src/yuzu/configuration/configure_graphics.ui | |||
| @@ -96,6 +96,27 @@ | |||
| 96 | </item> | 96 | </item> |
| 97 | </layout> | 97 | </layout> |
| 98 | </item> | 98 | </item> |
| 99 | <item> | ||
| 100 | <layout class="QHBoxLayout" name="horizontalLayout_6"> | ||
| 101 | <item> | ||
| 102 | <widget class="QLabel" name="bg_label"> | ||
| 103 | <property name="text"> | ||
| 104 | <string>Background Color:</string> | ||
| 105 | </property> | ||
| 106 | </widget> | ||
| 107 | </item> | ||
| 108 | <item> | ||
| 109 | <widget class="QPushButton" name="bg_button"> | ||
| 110 | <property name="maximumSize"> | ||
| 111 | <size> | ||
| 112 | <width>40</width> | ||
| 113 | <height>16777215</height> | ||
| 114 | </size> | ||
| 115 | </property> | ||
| 116 | </widget> | ||
| 117 | </item> | ||
| 118 | </layout> | ||
| 119 | </item> | ||
| 99 | </layout> | 120 | </layout> |
| 100 | </widget> | 121 | </widget> |
| 101 | </item> | 122 | </item> |
diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index 8c6e16d47..3b3b551bb 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp | |||
| @@ -366,7 +366,7 @@ void GameList::LoadCompatibilityList() { | |||
| 366 | QJsonDocument json = QJsonDocument::fromJson(string_content.toUtf8()); | 366 | QJsonDocument json = QJsonDocument::fromJson(string_content.toUtf8()); |
| 367 | QJsonArray arr = json.array(); | 367 | QJsonArray arr = json.array(); |
| 368 | 368 | ||
| 369 | for (const QJsonValue& value : arr) { | 369 | for (const QJsonValueRef& value : arr) { |
| 370 | QJsonObject game = value.toObject(); | 370 | QJsonObject game = value.toObject(); |
| 371 | 371 | ||
| 372 | if (game.contains("compatibility") && game["compatibility"].isDouble()) { | 372 | if (game.contains("compatibility") && game["compatibility"].isDouble()) { |
| @@ -374,9 +374,9 @@ void GameList::LoadCompatibilityList() { | |||
| 374 | QString directory = game["directory"].toString(); | 374 | QString directory = game["directory"].toString(); |
| 375 | QJsonArray ids = game["releases"].toArray(); | 375 | QJsonArray ids = game["releases"].toArray(); |
| 376 | 376 | ||
| 377 | for (const QJsonValue& value : ids) { | 377 | for (const QJsonValueRef& id_ref : ids) { |
| 378 | QJsonObject object = value.toObject(); | 378 | QJsonObject id_object = id_ref.toObject(); |
| 379 | QString id = object["id"].toString(); | 379 | QString id = id_object["id"].toString(); |
| 380 | compatibility_list.emplace( | 380 | compatibility_list.emplace( |
| 381 | id.toUpper().toStdString(), | 381 | id.toUpper().toStdString(), |
| 382 | std::make_pair(QString::number(compatibility), directory)); | 382 | std::make_pair(QString::number(compatibility), directory)); |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index e36914f14..05a4a55e8 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -447,6 +447,8 @@ QStringList GMainWindow::GetUnsupportedGLExtensions() { | |||
| 447 | unsupported_ext.append("ARB_texture_mirror_clamp_to_edge"); | 447 | unsupported_ext.append("ARB_texture_mirror_clamp_to_edge"); |
| 448 | if (!GLAD_GL_ARB_base_instance) | 448 | if (!GLAD_GL_ARB_base_instance) |
| 449 | unsupported_ext.append("ARB_base_instance"); | 449 | unsupported_ext.append("ARB_base_instance"); |
| 450 | if (!GLAD_GL_ARB_texture_storage) | ||
| 451 | unsupported_ext.append("ARB_texture_storage"); | ||
| 450 | 452 | ||
| 451 | // Extensions required to support some texture formats. | 453 | // Extensions required to support some texture formats. |
| 452 | if (!GLAD_GL_EXT_texture_compression_s3tc) | 454 | if (!GLAD_GL_EXT_texture_compression_s3tc) |
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index f00b5a66b..991abda2e 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp | |||
| @@ -108,6 +108,8 @@ void Config::ReadValues() { | |||
| 108 | 108 | ||
| 109 | // Audio | 109 | // Audio |
| 110 | Settings::values.sink_id = sdl2_config->Get("Audio", "output_engine", "auto"); | 110 | Settings::values.sink_id = sdl2_config->Get("Audio", "output_engine", "auto"); |
| 111 | Settings::values.enable_audio_stretching = | ||
| 112 | sdl2_config->GetBoolean("Audio", "enable_audio_stretching", true); | ||
| 111 | Settings::values.audio_device_id = sdl2_config->Get("Audio", "output_device", "auto"); | 113 | Settings::values.audio_device_id = sdl2_config->Get("Audio", "output_device", "auto"); |
| 112 | Settings::values.volume = sdl2_config->GetReal("Audio", "volume", 1); | 114 | Settings::values.volume = sdl2_config->GetReal("Audio", "volume", 1); |
| 113 | 115 | ||
diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h index 6ed9e7962..002a4ec15 100644 --- a/src/yuzu_cmd/default_ini.h +++ b/src/yuzu_cmd/default_ini.h | |||
| @@ -150,6 +150,12 @@ swap_screen = | |||
| 150 | # auto (default): Auto-select, null: No audio output, cubeb: Cubeb audio engine (if available) | 150 | # auto (default): Auto-select, null: No audio output, cubeb: Cubeb audio engine (if available) |
| 151 | output_engine = | 151 | output_engine = |
| 152 | 152 | ||
| 153 | # Whether or not to enable the audio-stretching post-processing effect. | ||
| 154 | # This effect adjusts audio speed to match emulation speed and helps prevent audio stutter, | ||
| 155 | # at the cost of increasing audio latency. | ||
| 156 | # 0: No, 1 (default): Yes | ||
| 157 | enable_audio_stretching = | ||
| 158 | |||
| 153 | # Which audio device to use. | 159 | # Which audio device to use. |
| 154 | # auto (default): Auto-select | 160 | # auto (default): Auto-select |
| 155 | output_device = | 161 | output_device = |
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp index 1c4717123..d213929bd 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | |||
| @@ -94,6 +94,8 @@ bool EmuWindow_SDL2::SupportsRequiredGLExtensions() { | |||
| 94 | unsupported_ext.push_back("ARB_texture_mirror_clamp_to_edge"); | 94 | unsupported_ext.push_back("ARB_texture_mirror_clamp_to_edge"); |
| 95 | if (!GLAD_GL_ARB_base_instance) | 95 | if (!GLAD_GL_ARB_base_instance) |
| 96 | unsupported_ext.push_back("ARB_base_instance"); | 96 | unsupported_ext.push_back("ARB_base_instance"); |
| 97 | if (!GLAD_GL_ARB_texture_storage) | ||
| 98 | unsupported_ext.push_back("ARB_texture_storage"); | ||
| 97 | 99 | ||
| 98 | // Extensions required to support some texture formats. | 100 | // Extensions required to support some texture formats. |
| 99 | if (!GLAD_GL_EXT_texture_compression_s3tc) | 101 | if (!GLAD_GL_EXT_texture_compression_s3tc) |