diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/citra/config.cpp | 3 | ||||
| -rw-r--r-- | src/citra/default_ini.h | 3 | ||||
| -rw-r--r-- | src/citra_qt/config.cpp | 4 | ||||
| -rw-r--r-- | src/core/hw/gpu.cpp | 63 | ||||
| -rw-r--r-- | src/core/hw/gpu.h | 1 | ||||
| -rw-r--r-- | src/core/settings.h | 1 | ||||
| -rw-r--r-- | src/video_core/command_processor.cpp | 5 |
7 files changed, 50 insertions, 30 deletions
diff --git a/src/citra/config.cpp b/src/citra/config.cpp index b9d6441be..2bf0dff35 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp | |||
| @@ -58,7 +58,8 @@ void Config::ReadValues() { | |||
| 58 | 58 | ||
| 59 | // Core | 59 | // Core |
| 60 | Settings::values.cpu_core = glfw_config->GetInteger("Core", "cpu_core", Core::CPU_Interpreter); | 60 | Settings::values.cpu_core = glfw_config->GetInteger("Core", "cpu_core", Core::CPU_Interpreter); |
| 61 | Settings::values.gpu_refresh_rate = glfw_config->GetInteger("Core", "gpu_refresh_rate", 60); | 61 | Settings::values.gpu_refresh_rate = glfw_config->GetInteger("Core", "gpu_refresh_rate", 30); |
| 62 | Settings::values.frame_skip = glfw_config->GetInteger("Core", "frame_skip", 0); | ||
| 62 | 63 | ||
| 63 | // Data Storage | 64 | // Data Storage |
| 64 | Settings::values.use_virtual_sd = glfw_config->GetBoolean("Data Storage", "use_virtual_sd", true); | 65 | Settings::values.use_virtual_sd = glfw_config->GetBoolean("Data Storage", "use_virtual_sd", true); |
diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h index a281c536f..f41020f7b 100644 --- a/src/citra/default_ini.h +++ b/src/citra/default_ini.h | |||
| @@ -28,7 +28,8 @@ pad_sright = | |||
| 28 | 28 | ||
| 29 | [Core] | 29 | [Core] |
| 30 | cpu_core = ## 0: Interpreter (default), 1: FastInterpreter (experimental) | 30 | cpu_core = ## 0: Interpreter (default), 1: FastInterpreter (experimental) |
| 31 | gpu_refresh_rate = ## 60 (default) | 31 | gpu_refresh_rate = ## 30 (default) |
| 32 | frame_skip = ## 0: No frameskip (default), 1 : 2x frameskip, 2 : 4x frameskip, etc. | ||
| 32 | 33 | ||
| 33 | [Data Storage] | 34 | [Data Storage] |
| 34 | use_virtual_sd = | 35 | use_virtual_sd = |
diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp index 0fea8e4f9..1596c08d7 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/config.cpp | |||
| @@ -44,7 +44,8 @@ void Config::ReadValues() { | |||
| 44 | 44 | ||
| 45 | qt_config->beginGroup("Core"); | 45 | qt_config->beginGroup("Core"); |
| 46 | Settings::values.cpu_core = qt_config->value("cpu_core", Core::CPU_Interpreter).toInt(); | 46 | Settings::values.cpu_core = qt_config->value("cpu_core", Core::CPU_Interpreter).toInt(); |
| 47 | Settings::values.gpu_refresh_rate = qt_config->value("gpu_refresh_rate", 60).toInt(); | 47 | Settings::values.gpu_refresh_rate = qt_config->value("gpu_refresh_rate", 30).toInt(); |
| 48 | Settings::values.frame_skip = qt_config->value("frame_skip", 0).toInt(); | ||
| 48 | qt_config->endGroup(); | 49 | qt_config->endGroup(); |
| 49 | 50 | ||
| 50 | qt_config->beginGroup("Data Storage"); | 51 | qt_config->beginGroup("Data Storage"); |
| @@ -80,6 +81,7 @@ void Config::SaveValues() { | |||
| 80 | qt_config->beginGroup("Core"); | 81 | qt_config->beginGroup("Core"); |
| 81 | qt_config->setValue("cpu_core", Settings::values.cpu_core); | 82 | qt_config->setValue("cpu_core", Settings::values.cpu_core); |
| 82 | qt_config->setValue("gpu_refresh_rate", Settings::values.gpu_refresh_rate); | 83 | qt_config->setValue("gpu_refresh_rate", Settings::values.gpu_refresh_rate); |
| 84 | qt_config->setValue("frame_skip", Settings::values.frame_skip); | ||
| 83 | qt_config->endGroup(); | 85 | qt_config->endGroup(); |
| 84 | 86 | ||
| 85 | qt_config->beginGroup("Data Storage"); | 87 | qt_config->beginGroup("Data Storage"); |
diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp index 7e70b34c1..dd619cb16 100644 --- a/src/core/hw/gpu.cpp +++ b/src/core/hw/gpu.cpp | |||
| @@ -21,10 +21,14 @@ namespace GPU { | |||
| 21 | 21 | ||
| 22 | Regs g_regs; | 22 | Regs g_regs; |
| 23 | 23 | ||
| 24 | static u64 frame_ticks = 0; ///< 268MHz / 60 frames per second | 24 | bool g_skip_frame = false; ///< True if the current frame was skipped |
| 25 | static u32 cur_line = 0; ///< Current vertical screen line | 25 | |
| 26 | static u64 last_frame_ticks = 0; ///< CPU tick count from last frame | 26 | static u64 frame_ticks = 0; ///< 268MHz / gpu_refresh_rate frames per second |
| 27 | static u64 last_update_tick = 0; ///< CPU ticl count from last GPU update | 27 | static u64 line_ticks = 0; ///< Number of ticks for a screen line |
| 28 | static u32 cur_line = 0; ///< Current screen line | ||
| 29 | static u64 last_update_tick = 0; ///< CPU ticl count from last GPU update | ||
| 30 | static u64 frame_count = 0; ///< Number of frames drawn | ||
| 31 | static bool last_skip_frame = false; ///< True if the last frame was skipped | ||
| 28 | 32 | ||
| 29 | template <typename T> | 33 | template <typename T> |
| 30 | inline void Read(T &var, const u32 raw_addr) { | 34 | inline void Read(T &var, const u32 raw_addr) { |
| @@ -178,38 +182,40 @@ template void Write<u8>(u32 addr, const u8 data); | |||
| 178 | void Update() { | 182 | void Update() { |
| 179 | auto& framebuffer_top = g_regs.framebuffer_config[0]; | 183 | auto& framebuffer_top = g_regs.framebuffer_config[0]; |
| 180 | 184 | ||
| 181 | // Update the frame after a certain number of CPU ticks have elapsed. This assumes that the | ||
| 182 | // active frame in memory is always complete to render. There also may be issues with this | ||
| 183 | // becoming out-of-synch with GSP synchrinization code (as follows). At this time, this seems to | ||
| 184 | // be the most effective solution for both homebrew and retail applications. With retail, this | ||
| 185 | // could be moved below (and probably would guarantee more accurate synchronization). However, | ||
| 186 | // primitive homebrew relies on a vertical blank interrupt to happen inevitably (regardless of a | ||
| 187 | // threading reschedule). | ||
| 188 | |||
| 189 | if ((Core::g_app_core->GetTicks() - last_frame_ticks) > (GPU::frame_ticks)) { | ||
| 190 | VideoCore::g_renderer->SwapBuffers(); | ||
| 191 | last_frame_ticks = Core::g_app_core->GetTicks(); | ||
| 192 | } | ||
| 193 | |||
| 194 | // Synchronize GPU on a thread reschedule: Because we cannot accurately predict a vertical | 185 | // Synchronize GPU on a thread reschedule: Because we cannot accurately predict a vertical |
| 195 | // blank, we need to simulate it. Based on testing, it seems that retail applications work more | 186 | // blank, we need to simulate it. Based on testing, it seems that retail applications work more |
| 196 | // accurately when this is signalled between thread switches. | 187 | // accurately when this is signalled between thread switches. |
| 197 | 188 | ||
| 198 | if (HLE::g_reschedule) { | 189 | if (HLE::g_reschedule) { |
| 199 | u64 current_ticks = Core::g_app_core->GetTicks(); | 190 | u64 current_ticks = Core::g_app_core->GetTicks(); |
| 200 | u64 line_ticks = (GPU::frame_ticks / framebuffer_top.height) * 16; | 191 | u32 num_lines = static_cast<u32>((current_ticks - last_update_tick) / line_ticks); |
| 201 | 192 | ||
| 202 | //// Synchronize line... | 193 | // Synchronize line... |
| 203 | if ((current_ticks - last_update_tick) >= line_ticks) { | 194 | if (num_lines > 0) { |
| 204 | GSP_GPU::SignalInterrupt(GSP_GPU::InterruptId::PDC0); | 195 | GSP_GPU::SignalInterrupt(GSP_GPU::InterruptId::PDC0); |
| 205 | cur_line++; | 196 | cur_line += num_lines; |
| 206 | last_update_tick += line_ticks; | 197 | last_update_tick += (num_lines * line_ticks); |
| 207 | } | 198 | } |
| 208 | 199 | ||
| 209 | // Synchronize frame... | 200 | // Synchronize frame... |
| 210 | if (cur_line >= framebuffer_top.height) { | 201 | if (cur_line >= framebuffer_top.height) { |
| 211 | cur_line = 0; | 202 | cur_line = 0; |
| 212 | VideoCore::g_renderer->SwapBuffers(); | 203 | frame_count++; |
| 204 | last_skip_frame = g_skip_frame; | ||
| 205 | g_skip_frame = (frame_count & Settings::values.frame_skip) != 0; | ||
| 206 | |||
| 207 | // Swap buffers based on the frameskip mode, which is a little bit tricky. When | ||
| 208 | // a frame is being skipped, nothing is being rendered to the internal framebuffer(s). | ||
| 209 | // So, we should only swap frames if the last frame was rendered. The rules are: | ||
| 210 | // - If frameskip == 0 (disabled), always swap buffers | ||
| 211 | // - If frameskip == 1, swap buffers every other frame (starting from the first frame) | ||
| 212 | // - If frameskip > 1, swap buffers every frameskip^n frames (starting from the second frame) | ||
| 213 | |||
| 214 | if ((((Settings::values.frame_skip != 1) ^ last_skip_frame) && last_skip_frame != g_skip_frame) || | ||
| 215 | Settings::values.frame_skip == 0) { | ||
| 216 | VideoCore::g_renderer->SwapBuffers(); | ||
| 217 | } | ||
| 218 | |||
| 213 | GSP_GPU::SignalInterrupt(GSP_GPU::InterruptId::PDC1); | 219 | GSP_GPU::SignalInterrupt(GSP_GPU::InterruptId::PDC1); |
| 214 | } | 220 | } |
| 215 | } | 221 | } |
| @@ -217,10 +223,6 @@ void Update() { | |||
| 217 | 223 | ||
| 218 | /// Initialize hardware | 224 | /// Initialize hardware |
| 219 | void Init() { | 225 | void Init() { |
| 220 | frame_ticks = 268123480 / Settings::values.gpu_refresh_rate; | ||
| 221 | cur_line = 0; | ||
| 222 | last_update_tick = last_frame_ticks = Core::g_app_core->GetTicks(); | ||
| 223 | |||
| 224 | auto& framebuffer_top = g_regs.framebuffer_config[0]; | 226 | auto& framebuffer_top = g_regs.framebuffer_config[0]; |
| 225 | auto& framebuffer_sub = g_regs.framebuffer_config[1]; | 227 | auto& framebuffer_sub = g_regs.framebuffer_config[1]; |
| 226 | 228 | ||
| @@ -249,6 +251,13 @@ void Init() { | |||
| 249 | framebuffer_sub.color_format = Regs::PixelFormat::RGB8; | 251 | framebuffer_sub.color_format = Regs::PixelFormat::RGB8; |
| 250 | framebuffer_sub.active_fb = 0; | 252 | framebuffer_sub.active_fb = 0; |
| 251 | 253 | ||
| 254 | frame_ticks = 268123480 / Settings::values.gpu_refresh_rate; | ||
| 255 | line_ticks = (GPU::frame_ticks / framebuffer_top.height); | ||
| 256 | cur_line = 0; | ||
| 257 | last_update_tick = Core::g_app_core->GetTicks(); | ||
| 258 | last_skip_frame = false; | ||
| 259 | g_skip_frame = false; | ||
| 260 | |||
| 252 | LOG_DEBUG(HW_GPU, "initialized OK"); | 261 | LOG_DEBUG(HW_GPU, "initialized OK"); |
| 253 | } | 262 | } |
| 254 | 263 | ||
diff --git a/src/core/hw/gpu.h b/src/core/hw/gpu.h index 68f11bfcb..292f496c1 100644 --- a/src/core/hw/gpu.h +++ b/src/core/hw/gpu.h | |||
| @@ -241,6 +241,7 @@ ASSERT_REG_POSITION(command_processor_config, 0x00638); | |||
| 241 | static_assert(sizeof(Regs) == 0x1000 * sizeof(u32), "Invalid total size of register set"); | 241 | static_assert(sizeof(Regs) == 0x1000 * sizeof(u32), "Invalid total size of register set"); |
| 242 | 242 | ||
| 243 | extern Regs g_regs; | 243 | extern Regs g_regs; |
| 244 | extern bool g_skip_frame; | ||
| 244 | 245 | ||
| 245 | template <typename T> | 246 | template <typename T> |
| 246 | void Read(T &var, const u32 addr); | 247 | void Read(T &var, const u32 addr); |
diff --git a/src/core/settings.h b/src/core/settings.h index 4808872ae..4b8928847 100644 --- a/src/core/settings.h +++ b/src/core/settings.h | |||
| @@ -31,6 +31,7 @@ struct Values { | |||
| 31 | // Core | 31 | // Core |
| 32 | int cpu_core; | 32 | int cpu_core; |
| 33 | int gpu_refresh_rate; | 33 | int gpu_refresh_rate; |
| 34 | int frame_skip; | ||
| 34 | 35 | ||
| 35 | // Data Storage | 36 | // Data Storage |
| 36 | bool use_virtual_sd; | 37 | bool use_virtual_sd; |
diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp index 2083357fe..9602779f4 100644 --- a/src/video_core/command_processor.cpp +++ b/src/video_core/command_processor.cpp | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include "primitive_assembly.h" | 9 | #include "primitive_assembly.h" |
| 10 | #include "vertex_shader.h" | 10 | #include "vertex_shader.h" |
| 11 | #include "core/hle/service/gsp_gpu.h" | 11 | #include "core/hle/service/gsp_gpu.h" |
| 12 | #include "core/hw/gpu.h" | ||
| 12 | 13 | ||
| 13 | #include "debug_utils/debug_utils.h" | 14 | #include "debug_utils/debug_utils.h" |
| 14 | 15 | ||
| @@ -31,6 +32,10 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) { | |||
| 31 | if (id >= registers.NumIds()) | 32 | if (id >= registers.NumIds()) |
| 32 | return; | 33 | return; |
| 33 | 34 | ||
| 35 | // If we're skipping this frame, only allow trigger IRQ | ||
| 36 | if (GPU::g_skip_frame && id != PICA_REG_INDEX(trigger_irq)) | ||
| 37 | return; | ||
| 38 | |||
| 34 | // TODO: Figure out how register masking acts on e.g. vs_uniform_setup.set_value | 39 | // TODO: Figure out how register masking acts on e.g. vs_uniform_setup.set_value |
| 35 | u32 old_value = registers[id]; | 40 | u32 old_value = registers[id]; |
| 36 | registers[id] = (old_value & ~mask) | (value & mask); | 41 | registers[id] = (old_value & ~mask) | (value & mask); |