2013-04-18 03:09:55 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-10-21 06:01:38 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
|
2008-12-08 04:46:09 +00:00
|
|
|
#define GX_NOP 0x00
|
|
|
|
|
|
|
|
#define GX_LOAD_BP_REG 0x61
|
|
|
|
#define GX_LOAD_CP_REG 0x08
|
|
|
|
#define GX_LOAD_XF_REG 0x10
|
|
|
|
#define GX_LOAD_INDX_A 0x20
|
|
|
|
#define GX_LOAD_INDX_B 0x28
|
|
|
|
#define GX_LOAD_INDX_C 0x30
|
|
|
|
#define GX_LOAD_INDX_D 0x38
|
|
|
|
|
|
|
|
#define GX_CMD_CALL_DL 0x40
|
2009-08-09 11:03:58 +00:00
|
|
|
#define GX_CMD_UNKNOWN_METRICS 0x44
|
2008-12-08 04:46:09 +00:00
|
|
|
#define GX_CMD_INVL_VC 0x48
|
|
|
|
|
|
|
|
#define GX_PRIMITIVE_MASK 0x78
|
|
|
|
#define GX_PRIMITIVE_SHIFT 3
|
|
|
|
#define GX_VAT_MASK 0x07
|
|
|
|
|
2014-05-08 23:53:18 +00:00
|
|
|
// These values are the values extracted using GX_PRIMITIVE_MASK
|
|
|
|
// and GX_PRIMITIVE_SHIFT.
|
|
|
|
// GX_DRAW_QUADS_2 behaves the same way as GX_DRAW_QUADS.
|
2009-07-26 09:52:35 +00:00
|
|
|
#define GX_DRAW_QUADS 0x0 // 0x80
|
2014-05-08 23:53:18 +00:00
|
|
|
#define GX_DRAW_QUADS_2 0x1 // 0x88
|
2009-07-26 09:52:35 +00:00
|
|
|
#define GX_DRAW_TRIANGLES 0x2 // 0x90
|
|
|
|
#define GX_DRAW_TRIANGLE_STRIP 0x3 // 0x98
|
|
|
|
#define GX_DRAW_TRIANGLE_FAN 0x4 // 0xA0
|
|
|
|
#define GX_DRAW_LINES 0x5 // 0xA8
|
|
|
|
#define GX_DRAW_LINE_STRIP 0x6 // 0xB0
|
|
|
|
#define GX_DRAW_POINTS 0x7 // 0xB8
|
2011-03-27 02:55:08 +00:00
|
|
|
|
|
|
|
extern bool g_bRecordFifoData;
|
|
|
|
|
2008-12-08 04:46:09 +00:00
|
|
|
void OpcodeDecoder_Init();
|
|
|
|
void OpcodeDecoder_Shutdown();
|
2014-09-03 19:49:15 +00:00
|
|
|
u32 OpcodeDecoder_Run(u8* end);
|
Add the 'desynced GPU thread' mode.
It's a relatively big commit (less big with -w), but it's hard to test
any of this separately...
The basic problem is that in netplay or movies, the state of the CPU
must be deterministic, including when the game receives notification
that the GPU has processed FIFO data. Dual core mode notifies the game
whenever the GPU thread actually gets around to doing the work, so it
isn't deterministic. Single core mode is because it notifies the game
'instantly' (after processing the data synchronously), but it's too slow
for many systems and games.
My old dc-netplay branch worked as follows: everything worked as normal
except the state of the CP registers was a lie, and the CPU thread only
delivered results when idle detection triggered (waiting for the GPU if
they weren't ready at that point). Usually, a game is idle iff all the
work for the frame has been done, except for a small amount of work
depending on the GPU result, so neither the CPU or the GPU waiting on
the other affected performance much. However, it's possible that the
game could be waiting for some earlier interrupt, and any of several
games which, for whatever reason, never went into a detectable idle
(even when I tried to improve the detection) would never receive results
at all. (The current method should have better compatibility, but it
also has slightly higher overhead and breaks some other things, so I
want to reimplement this, hopefully with less impact on the code, in the
future.)
With this commit, the basic idea is that the CPU thread acts as if the
work has been done instantly, like single core mode, but actually hands
it off asynchronously to the GPU thread (after backing up some data that
the game might change in memory before it's actually done). Since the
work isn't done, any feedback from the GPU to the CPU, such as real
XFB/EFB copies (virtual are OK), EFB pokes, performance queries, etc. is
broken; but most games work with these options disabled, and there is no
need to try to detect what the CPU thread is doing.
Technically: when the flag g_use_deterministic_gpu_thread (currently
stuck on) is on, the CPU thread calls RunGpu like in single core mode.
This function synchronously copies the data from the FIFO to the
internal video buffer and updates the CP registers, interrupts, etc.
However, instead of the regular ReadDataFromFifo followed by running the
opcode decoder, it runs ReadDataFromFifoOnCPU ->
OpcodeDecoder_Preprocess, which relatively quickly scans through the
FIFO data, detects SetFinish calls etc., which are immediately fired,
and saves certain associated data from memory (e.g. display lists) in
AuxBuffers (a parallel stream to the main FIFO, which is a bit slow at
the moment), before handing the data off to the GPU thread to actually
render. That makes up the bulk of this commit.
In various circumstances, including the aforementioned EFB pokes and
performance queries as well as swap requests (i.e. the end of a frame -
we don't want the CPU potentially pumping out frames too quickly and the
GPU falling behind*), SyncGPU is called to wait for actual completion.
The overhead mainly comes from OpcodeDecoder_Preprocess (which is,
again, synchronous), as well as the actual copying.
Currently, display lists and such are escrowed from main memory even
though they usually won't change over the course of a frame, and
textures are not even though they might, resulting in a small chance of
graphical glitches. When the texture locking (i.e. fault on write) code
lands, I can make this all correct and maybe a little faster.
* This suggests an alternate determinism method of just delaying results
until a short time before the end of each frame. For all I know this
might mostly work - I haven't tried it - but if any significant work
hinges on the competion of render to texture etc., the frame will be
missed.
2014-08-28 02:56:19 +00:00
|
|
|
void OpcodeDecoder_Preprocess(u8* write_ptr);
|