summaryrefslogtreecommitdiff
path: root/src/core/hw/gpu.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2014-12-28 22:39:17 -0500
committerGravatar bunnei2014-12-28 22:39:17 -0500
commit487a80f9f70f5972aaf53fd855e17c07deb4819f (patch)
tree2ce60ca2c34aca3e4c19395562df0dbbeb7c19f6 /src/core/hw/gpu.cpp
parentMerge pull request #355 from lioncash/simp (diff)
parentGPU: Implement frameskip and remove forced framebuffer swap hack. (diff)
downloadyuzu-487a80f9f70f5972aaf53fd855e17c07deb4819f.tar.gz
yuzu-487a80f9f70f5972aaf53fd855e17c07deb4819f.tar.xz
yuzu-487a80f9f70f5972aaf53fd855e17c07deb4819f.zip
Merge pull request #347 from bunnei/frameskip
Frameskip
Diffstat (limited to 'src/core/hw/gpu.cpp')
-rw-r--r--src/core/hw/gpu.cpp63
1 files changed, 36 insertions, 27 deletions
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
22Regs g_regs; 22Regs g_regs;
23 23
24static u64 frame_ticks = 0; ///< 268MHz / 60 frames per second 24bool g_skip_frame = false; ///< True if the current frame was skipped
25static u32 cur_line = 0; ///< Current vertical screen line 25
26static u64 last_frame_ticks = 0; ///< CPU tick count from last frame 26static u64 frame_ticks = 0; ///< 268MHz / gpu_refresh_rate frames per second
27static u64 last_update_tick = 0; ///< CPU ticl count from last GPU update 27static u64 line_ticks = 0; ///< Number of ticks for a screen line
28static u32 cur_line = 0; ///< Current screen line
29static u64 last_update_tick = 0; ///< CPU ticl count from last GPU update
30static u64 frame_count = 0; ///< Number of frames drawn
31static bool last_skip_frame = false; ///< True if the last frame was skipped
28 32
29template <typename T> 33template <typename T>
30inline void Read(T &var, const u32 raw_addr) { 34inline void Read(T &var, const u32 raw_addr) {
@@ -178,38 +182,40 @@ template void Write<u8>(u32 addr, const u8 data);
178void Update() { 182void 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
219void Init() { 225void 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