2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:09:55 +00:00
|
|
|
// 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
|
|
|
|
2019-06-20 11:42:16 +00:00
|
|
|
#include <array>
|
|
|
|
|
2017-06-13 12:06:08 +00:00
|
|
|
#include "Common/BitField.h"
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-04-16 21:51:18 +00:00
|
|
|
#include "VideoCommon/CPMemory.h"
|
2016-01-31 19:51:55 +00:00
|
|
|
|
|
|
|
class DataReader;
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2017-01-04 11:34:27 +00:00
|
|
|
constexpr size_t NUM_XF_COLOR_CHANNELS = 2;
|
|
|
|
|
2008-12-08 04:46:09 +00:00
|
|
|
// Lighting
|
2009-09-02 21:00:45 +00:00
|
|
|
|
2015-09-01 14:56:51 +00:00
|
|
|
// Projection
|
|
|
|
enum : u32
|
|
|
|
{
|
|
|
|
XF_TEXPROJ_ST = 0,
|
|
|
|
XF_TEXPROJ_STQ = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
// Input form
|
|
|
|
enum : u32
|
|
|
|
{
|
|
|
|
XF_TEXINPUT_AB11 = 0,
|
|
|
|
XF_TEXINPUT_ABC1 = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
// Texture generation type
|
|
|
|
enum : u32
|
|
|
|
{
|
|
|
|
XF_TEXGEN_REGULAR = 0,
|
|
|
|
XF_TEXGEN_EMBOSS_MAP = 1, // Used when bump mapping
|
|
|
|
XF_TEXGEN_COLOR_STRGBC0 = 2,
|
|
|
|
XF_TEXGEN_COLOR_STRGBC1 = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
// Source row
|
|
|
|
enum : u32
|
|
|
|
{
|
|
|
|
XF_SRCGEOM_INROW = 0, // Input is abc
|
|
|
|
XF_SRCNORMAL_INROW = 1, // Input is abc
|
|
|
|
XF_SRCCOLORS_INROW = 2,
|
|
|
|
XF_SRCBINORMAL_T_INROW = 3, // Input is abc
|
|
|
|
XF_SRCBINORMAL_B_INROW = 4, // Input is abc
|
|
|
|
XF_SRCTEX0_INROW = 5,
|
|
|
|
XF_SRCTEX1_INROW = 6,
|
|
|
|
XF_SRCTEX2_INROW = 7,
|
|
|
|
XF_SRCTEX3_INROW = 8,
|
|
|
|
XF_SRCTEX4_INROW = 9,
|
|
|
|
XF_SRCTEX5_INROW = 10,
|
|
|
|
XF_SRCTEX6_INROW = 11,
|
|
|
|
XF_SRCTEX7_INROW = 12
|
|
|
|
};
|
|
|
|
|
|
|
|
// Control source
|
|
|
|
enum : u32
|
|
|
|
{
|
|
|
|
GX_SRC_REG = 0,
|
|
|
|
GX_SRC_VTX = 1
|
|
|
|
};
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2015-09-01 14:56:51 +00:00
|
|
|
// Light diffuse attenuation function
|
|
|
|
enum : u32
|
|
|
|
{
|
|
|
|
LIGHTDIF_NONE = 0,
|
|
|
|
LIGHTDIF_SIGN = 1,
|
|
|
|
LIGHTDIF_CLAMP = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
// Light attenuation function
|
|
|
|
enum : u32
|
|
|
|
{
|
|
|
|
LIGHTATTN_NONE = 0, // No attenuation
|
|
|
|
LIGHTATTN_SPEC = 1, // Point light attenuation
|
|
|
|
LIGHTATTN_DIR = 2, // Directional light attenuation
|
|
|
|
LIGHTATTN_SPOT = 3 // Spot light attenuation
|
|
|
|
};
|
|
|
|
|
|
|
|
// Projection type
|
|
|
|
enum : u32
|
|
|
|
{
|
|
|
|
GX_PERSPECTIVE = 0,
|
|
|
|
GX_ORTHOGRAPHIC = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
// Registers and register ranges
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
XFMEM_POSMATRICES = 0x000,
|
|
|
|
XFMEM_POSMATRICES_END = 0x100,
|
|
|
|
XFMEM_NORMALMATRICES = 0x400,
|
|
|
|
XFMEM_NORMALMATRICES_END = 0x460,
|
|
|
|
XFMEM_POSTMATRICES = 0x500,
|
|
|
|
XFMEM_POSTMATRICES_END = 0x600,
|
|
|
|
XFMEM_LIGHTS = 0x600,
|
|
|
|
XFMEM_LIGHTS_END = 0x680,
|
|
|
|
XFMEM_ERROR = 0x1000,
|
|
|
|
XFMEM_DIAG = 0x1001,
|
|
|
|
XFMEM_STATE0 = 0x1002,
|
|
|
|
XFMEM_STATE1 = 0x1003,
|
|
|
|
XFMEM_CLOCK = 0x1004,
|
|
|
|
XFMEM_CLIPDISABLE = 0x1005,
|
|
|
|
XFMEM_SETGPMETRIC = 0x1006,
|
|
|
|
XFMEM_VTXSPECS = 0x1008,
|
|
|
|
XFMEM_SETNUMCHAN = 0x1009,
|
|
|
|
XFMEM_SETCHAN0_AMBCOLOR = 0x100a,
|
|
|
|
XFMEM_SETCHAN1_AMBCOLOR = 0x100b,
|
|
|
|
XFMEM_SETCHAN0_MATCOLOR = 0x100c,
|
|
|
|
XFMEM_SETCHAN1_MATCOLOR = 0x100d,
|
|
|
|
XFMEM_SETCHAN0_COLOR = 0x100e,
|
|
|
|
XFMEM_SETCHAN1_COLOR = 0x100f,
|
|
|
|
XFMEM_SETCHAN0_ALPHA = 0x1010,
|
|
|
|
XFMEM_SETCHAN1_ALPHA = 0x1011,
|
|
|
|
XFMEM_DUALTEX = 0x1012,
|
|
|
|
XFMEM_SETMATRIXINDA = 0x1018,
|
|
|
|
XFMEM_SETMATRIXINDB = 0x1019,
|
|
|
|
XFMEM_SETVIEWPORT = 0x101a,
|
|
|
|
XFMEM_SETZSCALE = 0x101c,
|
|
|
|
XFMEM_SETZOFFSET = 0x101f,
|
|
|
|
XFMEM_SETPROJECTION = 0x1020,
|
|
|
|
// XFMEM_SETPROJECTIONB = 0x1021,
|
|
|
|
// XFMEM_SETPROJECTIONC = 0x1022,
|
|
|
|
// XFMEM_SETPROJECTIOND = 0x1023,
|
|
|
|
// XFMEM_SETPROJECTIONE = 0x1024,
|
|
|
|
// XFMEM_SETPROJECTIONF = 0x1025,
|
|
|
|
// XFMEM_SETPROJECTIONORTHO1 = 0x1026,
|
|
|
|
// XFMEM_SETPROJECTIONORTHO2 = 0x1027,
|
|
|
|
XFMEM_SETNUMTEXGENS = 0x103f,
|
|
|
|
XFMEM_SETTEXMTXINFO = 0x1040,
|
|
|
|
XFMEM_SETPOSMTXINFO = 0x1050,
|
|
|
|
};
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2017-01-04 11:45:40 +00:00
|
|
|
union LitChannel
|
|
|
|
{
|
2017-06-13 12:06:08 +00:00
|
|
|
BitField<0, 1, u32> matsource;
|
|
|
|
BitField<1, 1, u32> enablelighting;
|
|
|
|
BitField<2, 4, u32> lightMask0_3;
|
|
|
|
BitField<6, 1, u32> ambsource;
|
|
|
|
BitField<7, 2, u32> diffusefunc; // LIGHTDIF_X
|
|
|
|
BitField<9, 2, u32> attnfunc; // LIGHTATTN_X
|
|
|
|
BitField<11, 4, u32> lightMask4_7;
|
|
|
|
u32 hex;
|
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
unsigned int GetFullLightMask() const
|
|
|
|
{
|
|
|
|
return enablelighting ? (lightMask0_3 | (lightMask4_7 << 4)) : 0;
|
|
|
|
}
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
2017-01-04 11:45:40 +00:00
|
|
|
union INVTXSPEC
|
|
|
|
{
|
2013-03-20 01:51:12 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
u32 numcolors : 2;
|
|
|
|
u32 numnormals : 2; // 0 - nothing, 1 - just normal, 2 - normals and binormals
|
|
|
|
u32 numtextures : 4;
|
|
|
|
u32 unused : 24;
|
|
|
|
};
|
|
|
|
u32 hex;
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
2017-01-04 11:45:40 +00:00
|
|
|
union TexMtxInfo
|
|
|
|
{
|
2017-06-13 12:06:08 +00:00
|
|
|
BitField<0, 1, u32> unknown; //
|
|
|
|
BitField<1, 1, u32> projection; // XF_TEXPROJ_X
|
|
|
|
BitField<2, 1, u32> inputform; // XF_TEXINPUT_X
|
|
|
|
BitField<3, 1, u32> unknown2; //
|
|
|
|
BitField<4, 3, u32> texgentype; // XF_TEXGEN_X
|
|
|
|
BitField<7, 5, u32> sourcerow; // XF_SRCGEOM_X
|
|
|
|
BitField<12, 3, u32> embosssourceshift; // what generated texcoord to use
|
|
|
|
BitField<15, 3, u32> embosslightshift; // light index that is used
|
2013-03-20 01:51:12 +00:00
|
|
|
u32 hex;
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
2017-01-04 11:45:40 +00:00
|
|
|
union PostMtxInfo
|
|
|
|
{
|
2017-06-13 12:06:08 +00:00
|
|
|
BitField<0, 6, u32> index; // base row of dual transform matrix
|
|
|
|
BitField<6, 2, u32> unused; //
|
|
|
|
BitField<8, 1, u32> normalize; // normalize before send operation
|
2013-03-20 01:51:12 +00:00
|
|
|
u32 hex;
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
2017-01-04 11:45:40 +00:00
|
|
|
union NumColorChannel
|
|
|
|
{
|
2011-02-05 18:25:34 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
u32 numColorChans : 2;
|
|
|
|
};
|
|
|
|
u32 hex;
|
|
|
|
};
|
|
|
|
|
2017-01-04 11:45:40 +00:00
|
|
|
union NumTexGen
|
|
|
|
{
|
2011-02-05 18:25:34 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
u32 numTexGens : 4;
|
|
|
|
};
|
|
|
|
u32 hex;
|
|
|
|
};
|
|
|
|
|
2017-01-04 11:45:40 +00:00
|
|
|
union DualTexInfo
|
|
|
|
{
|
2011-02-05 18:25:34 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
u32 enabled : 1;
|
|
|
|
};
|
|
|
|
u32 hex;
|
|
|
|
};
|
2009-07-26 09:52:35 +00:00
|
|
|
|
|
|
|
struct Light
|
|
|
|
{
|
2013-10-29 05:23:17 +00:00
|
|
|
u32 useless[3];
|
2014-05-30 12:54:16 +00:00
|
|
|
u8 color[4];
|
|
|
|
float cosatt[3]; // cos attenuation
|
|
|
|
float distatt[3]; // dist attenuation
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-01-04 11:45:40 +00:00
|
|
|
union
|
|
|
|
{
|
2013-04-24 13:21:54 +00:00
|
|
|
struct
|
|
|
|
{
|
2009-07-26 09:52:35 +00:00
|
|
|
float dpos[3];
|
2013-03-20 01:51:12 +00:00
|
|
|
float ddir[3]; // specular lights only
|
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2013-04-24 13:21:54 +00:00
|
|
|
struct
|
|
|
|
{
|
2013-03-20 01:51:12 +00:00
|
|
|
float sdir[3];
|
|
|
|
float shalfangle[3]; // specular lights only
|
|
|
|
};
|
|
|
|
};
|
2009-07-26 09:52:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Viewport
|
|
|
|
{
|
|
|
|
float wd;
|
|
|
|
float ht;
|
2011-04-11 01:49:32 +00:00
|
|
|
float zRange;
|
2009-07-26 09:52:35 +00:00
|
|
|
float xOrig;
|
|
|
|
float yOrig;
|
|
|
|
float farZ;
|
|
|
|
};
|
|
|
|
|
2013-01-24 12:10:13 +00:00
|
|
|
struct Projection
|
|
|
|
{
|
2019-06-20 11:42:16 +00:00
|
|
|
using Raw = std::array<float, 6>;
|
|
|
|
|
|
|
|
Raw rawProjection;
|
2013-01-24 12:10:13 +00:00
|
|
|
u32 type; // only GX_PERSPECTIVE or GX_ORTHOGRAPHIC are allowed
|
|
|
|
};
|
|
|
|
|
2014-04-27 18:59:04 +00:00
|
|
|
struct XFMemory
|
2014-04-16 21:51:18 +00:00
|
|
|
{
|
2017-01-04 11:34:27 +00:00
|
|
|
float posMatrices[256]; // 0x0000 - 0x00ff
|
|
|
|
u32 unk0[768]; // 0x0100 - 0x03ff
|
|
|
|
float normalMatrices[96]; // 0x0400 - 0x045f
|
|
|
|
u32 unk1[160]; // 0x0460 - 0x04ff
|
|
|
|
float postMatrices[256]; // 0x0500 - 0x05ff
|
|
|
|
Light lights[8]; // 0x0600 - 0x067f
|
|
|
|
u32 unk2[2432]; // 0x0680 - 0x0fff
|
|
|
|
u32 error; // 0x1000
|
|
|
|
u32 diag; // 0x1001
|
|
|
|
u32 state0; // 0x1002
|
|
|
|
u32 state1; // 0x1003
|
|
|
|
u32 xfClock; // 0x1004
|
|
|
|
u32 clipDisable; // 0x1005
|
|
|
|
u32 perf0; // 0x1006
|
|
|
|
u32 perf1; // 0x1007
|
|
|
|
INVTXSPEC hostinfo; // 0x1008 number of textures,colors,normals from vertex input
|
|
|
|
NumColorChannel numChan; // 0x1009
|
|
|
|
u32 ambColor[NUM_XF_COLOR_CHANNELS]; // 0x100a, 0x100b
|
|
|
|
u32 matColor[NUM_XF_COLOR_CHANNELS]; // 0x100c, 0x100d
|
|
|
|
LitChannel color[NUM_XF_COLOR_CHANNELS]; // 0x100e, 0x100f
|
|
|
|
LitChannel alpha[NUM_XF_COLOR_CHANNELS]; // 0x1010, 0x1011
|
|
|
|
DualTexInfo dualTexTrans; // 0x1012
|
|
|
|
u32 unk3; // 0x1013
|
|
|
|
u32 unk4; // 0x1014
|
|
|
|
u32 unk5; // 0x1015
|
|
|
|
u32 unk6; // 0x1016
|
|
|
|
u32 unk7; // 0x1017
|
|
|
|
TMatrixIndexA MatrixIndexA; // 0x1018
|
|
|
|
TMatrixIndexB MatrixIndexB; // 0x1019
|
|
|
|
Viewport viewport; // 0x101a - 0x101f
|
|
|
|
Projection projection; // 0x1020 - 0x1026
|
|
|
|
u32 unk8[24]; // 0x1027 - 0x103e
|
|
|
|
NumTexGen numTexGen; // 0x103f
|
|
|
|
TexMtxInfo texMtxInfo[8]; // 0x1040 - 0x1047
|
|
|
|
u32 unk9[8]; // 0x1048 - 0x104f
|
|
|
|
PostMtxInfo postMtxInfo[8]; // 0x1050 - 0x1057
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
2018-10-08 05:34:41 +00:00
|
|
|
static_assert(sizeof(XFMemory) == sizeof(u32) * 0x1058);
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-04-27 18:59:04 +00:00
|
|
|
extern XFMemory xfmem;
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-11-27 22:53:11 +00:00
|
|
|
void LoadXFReg(u32 transferSize, u32 address, DataReader src);
|
2008-12-25 20:07:13 +00:00
|
|
|
void LoadIndexedXF(u32 val, int array);
|
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 PreprocessIndexedXF(u32 val, int refarray);
|