mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 13:27:45 -07:00
Rejigger some FIFO buffer variables to be more rational.
videoBuffer -> s_video_buffer size -> s_video_buffer_write_ptr g_pVideoData -> g_video_buffer_read_ptr (impl moved to Fifo.cpp) This eradicates the wonderful use of 'size' as a global name, and makes it clear that s_video_buffer_write_ptr and g_video_buffer_read_ptr are the two ends of the FIFO buffer s_video_buffer. Oh, and remove a useless namespace {}.
This commit is contained in:
parent
e86ddacb18
commit
0ae9e398c8
@ -57,7 +57,7 @@ static void DecodePrimitiveStream(u32 iBufferSize)
|
||||
{
|
||||
while (streamSize > 0 && iBufferSize >= vertexSize)
|
||||
{
|
||||
g_pVideoData += vertexSize;
|
||||
g_video_buffer_read_ptr += vertexSize;
|
||||
iBufferSize -= vertexSize;
|
||||
streamSize--;
|
||||
}
|
||||
@ -94,26 +94,26 @@ static void ReadXFData(u32 iBufferSize)
|
||||
|
||||
static void ExecuteDisplayList(u32 addr, u32 count)
|
||||
{
|
||||
u8 *videoDataSave = g_pVideoData;
|
||||
u8 *videoDataSave = g_video_buffer_read_ptr;
|
||||
|
||||
u8 *dlStart = Memory::GetPointer(addr);
|
||||
|
||||
g_pVideoData = dlStart;
|
||||
g_video_buffer_read_ptr = dlStart;
|
||||
|
||||
while (OpcodeDecoder::CommandRunnable(count))
|
||||
{
|
||||
OpcodeDecoder::Run(count);
|
||||
|
||||
// if data was read by the opcode decoder then the video data pointer changed
|
||||
u32 readCount = (u32)(g_pVideoData - dlStart);
|
||||
dlStart = g_pVideoData;
|
||||
u32 readCount = (u32)(g_video_buffer_read_ptr - dlStart);
|
||||
dlStart = g_video_buffer_read_ptr;
|
||||
|
||||
_assert_msg_(VIDEO, count >= readCount, "Display list underrun");
|
||||
|
||||
count -= readCount;
|
||||
}
|
||||
|
||||
g_pVideoData = videoDataSave;
|
||||
g_video_buffer_read_ptr = videoDataSave;
|
||||
}
|
||||
|
||||
static void DecodeStandard(u32 bufferSize)
|
||||
|
@ -57,7 +57,7 @@ void DoState(PointerWrap &p)
|
||||
p.Do(interruptWaiting);
|
||||
|
||||
// Is this right?
|
||||
p.DoArray(g_pVideoData,writePos);
|
||||
p.DoArray(g_video_buffer_read_ptr,writePos);
|
||||
}
|
||||
|
||||
static void UpdateInterrupts_Wrapper(u64 userdata, int cyclesLate)
|
||||
@ -95,7 +95,7 @@ void Init()
|
||||
interruptSet = false;
|
||||
interruptWaiting = false;
|
||||
|
||||
g_pVideoData = nullptr;
|
||||
g_video_buffer_read_ptr = nullptr;
|
||||
g_bSkipCurrentFrame = false;
|
||||
}
|
||||
|
||||
@ -311,7 +311,7 @@ bool RunBuffer()
|
||||
|
||||
_dbg_assert_(COMMANDPROCESSOR, writePos >= readPos);
|
||||
|
||||
g_pVideoData = &commandBuffer[readPos];
|
||||
g_video_buffer_read_ptr = &commandBuffer[readPos];
|
||||
|
||||
u32 availableBytes = writePos - readPos;
|
||||
|
||||
@ -322,7 +322,7 @@ bool RunBuffer()
|
||||
OpcodeDecoder::Run(availableBytes);
|
||||
|
||||
// if data was read by the opcode decoder then the video data pointer changed
|
||||
readPos = (u32)(g_pVideoData - &commandBuffer[0]);
|
||||
readPos = (u32)(g_video_buffer_read_ptr - &commandBuffer[0]);
|
||||
_dbg_assert_(VIDEO, writePos >= readPos);
|
||||
availableBytes = writePos - readPos;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include "VideoCommon/VertexManagerBase.h"
|
||||
|
||||
extern u8* g_pVideoData;
|
||||
extern u8* g_video_buffer_read_ptr;
|
||||
|
||||
#if _M_SSE >= 0x301 && !(defined __GNUC__ && !defined __SSSE3__)
|
||||
#include <tmmintrin.h>
|
||||
@ -14,20 +14,20 @@ extern u8* g_pVideoData;
|
||||
|
||||
__forceinline void DataSkip(u32 skip)
|
||||
{
|
||||
g_pVideoData += skip;
|
||||
g_video_buffer_read_ptr += skip;
|
||||
}
|
||||
|
||||
// probably unnecessary
|
||||
template <int count>
|
||||
__forceinline void DataSkip()
|
||||
{
|
||||
g_pVideoData += count;
|
||||
g_video_buffer_read_ptr += count;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__forceinline T DataPeek(int _uOffset)
|
||||
{
|
||||
auto const result = Common::FromBigEndian(*reinterpret_cast<T*>(g_pVideoData + _uOffset));
|
||||
auto const result = Common::FromBigEndian(*reinterpret_cast<T*>(g_video_buffer_read_ptr + _uOffset));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -58,8 +58,8 @@ __forceinline T DataRead()
|
||||
class DataReader
|
||||
{
|
||||
public:
|
||||
inline DataReader() : buffer(g_pVideoData), offset(0) {}
|
||||
inline ~DataReader() { g_pVideoData += offset; }
|
||||
inline DataReader() : buffer(g_video_buffer_read_ptr), offset(0) {}
|
||||
inline ~DataReader() { g_video_buffer_read_ptr += offset; }
|
||||
template <typename T> inline T Read()
|
||||
{
|
||||
const T result = Common::FromBigEndian(*(T*)(buffer + offset));
|
||||
@ -94,14 +94,14 @@ __forceinline u32 DataReadU32()
|
||||
|
||||
__forceinline u32 DataReadU32Unswapped()
|
||||
{
|
||||
u32 tmp = *(u32*)g_pVideoData;
|
||||
g_pVideoData += 4;
|
||||
u32 tmp = *(u32*)g_video_buffer_read_ptr;
|
||||
g_video_buffer_read_ptr += 4;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
__forceinline u8* DataGetPosition()
|
||||
{
|
||||
return g_pVideoData;
|
||||
return g_video_buffer_read_ptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -22,21 +22,22 @@
|
||||
|
||||
bool g_bSkipCurrentFrame = false;
|
||||
|
||||
namespace
|
||||
{
|
||||
static volatile bool GpuRunningState = false;
|
||||
static volatile bool EmuRunningState = false;
|
||||
static std::mutex m_csHWVidOccupied;
|
||||
// STATE_TO_SAVE
|
||||
static u8 *videoBuffer;
|
||||
static int size = 0;
|
||||
} // namespace
|
||||
static u8* s_video_buffer;
|
||||
static u8* s_video_buffer_write_ptr;
|
||||
|
||||
// Note: during display list execution, temporarily points to the list instead
|
||||
// of inside s_video_buffer.
|
||||
u8* g_video_buffer_read_ptr;
|
||||
|
||||
void Fifo_DoState(PointerWrap &p)
|
||||
{
|
||||
p.DoArray(videoBuffer, FIFO_SIZE);
|
||||
p.Do(size);
|
||||
p.DoPointer(g_pVideoData, videoBuffer);
|
||||
p.DoArray(s_video_buffer, FIFO_SIZE);
|
||||
p.DoPointer(s_video_buffer_write_ptr, s_video_buffer);
|
||||
p.DoPointer(g_video_buffer_read_ptr, s_video_buffer);
|
||||
p.Do(g_bSkipCurrentFrame);
|
||||
}
|
||||
|
||||
@ -61,8 +62,8 @@ void Fifo_PauseAndLock(bool doLock, bool unpauseOnUnlock)
|
||||
|
||||
void Fifo_Init()
|
||||
{
|
||||
videoBuffer = (u8*)AllocateMemoryPages(FIFO_SIZE);
|
||||
size = 0;
|
||||
s_video_buffer = (u8*)AllocateMemoryPages(FIFO_SIZE);
|
||||
s_video_buffer_write_ptr = s_video_buffer;
|
||||
GpuRunningState = false;
|
||||
Common::AtomicStore(CommandProcessor::VITicks, CommandProcessor::m_cpClockOrigin);
|
||||
}
|
||||
@ -70,18 +71,18 @@ void Fifo_Init()
|
||||
void Fifo_Shutdown()
|
||||
{
|
||||
if (GpuRunningState) PanicAlert("Fifo shutting down while active");
|
||||
FreeMemoryPages(videoBuffer, FIFO_SIZE);
|
||||
videoBuffer = nullptr;
|
||||
FreeMemoryPages(s_video_buffer, FIFO_SIZE);
|
||||
s_video_buffer = nullptr;
|
||||
}
|
||||
|
||||
u8* GetVideoBufferStartPtr()
|
||||
{
|
||||
return videoBuffer;
|
||||
return s_video_buffer;
|
||||
}
|
||||
|
||||
u8* GetVideoBufferEndPtr()
|
||||
{
|
||||
return &videoBuffer[size];
|
||||
return s_video_buffer_write_ptr;
|
||||
}
|
||||
|
||||
void Fifo_SetRendering(bool enabled)
|
||||
@ -111,26 +112,27 @@ void EmulatorState(bool running)
|
||||
// Description: RunGpuLoop() sends data through this function.
|
||||
void ReadDataFromFifo(u8* _uData, u32 len)
|
||||
{
|
||||
if (size + len >= FIFO_SIZE)
|
||||
if (len > (s_video_buffer + FIFO_SIZE - s_video_buffer_write_ptr))
|
||||
{
|
||||
int pos = (int)(g_pVideoData - videoBuffer);
|
||||
size -= pos;
|
||||
if (size + len > FIFO_SIZE)
|
||||
size_t size = s_video_buffer_write_ptr - g_video_buffer_read_ptr;
|
||||
if (len > FIFO_SIZE - size)
|
||||
{
|
||||
PanicAlert("FIFO out of bounds (size = %i, len = %i at %08x)", size, len, pos);
|
||||
PanicAlert("FIFO out of bounds (existing %lu + new %lu > %lu)", (unsigned long) size, (unsigned long) len, (unsigned long) FIFO_SIZE);
|
||||
return;
|
||||
}
|
||||
memmove(&videoBuffer[0], &videoBuffer[pos], size);
|
||||
g_pVideoData = videoBuffer;
|
||||
memmove(s_video_buffer, g_video_buffer_read_ptr, size);
|
||||
s_video_buffer_write_ptr = s_video_buffer + size;
|
||||
g_video_buffer_read_ptr = s_video_buffer;
|
||||
}
|
||||
// Copy new video instructions to videoBuffer for future use in rendering the new picture
|
||||
memcpy(videoBuffer + size, _uData, len);
|
||||
size += len;
|
||||
// Copy new video instructions to s_video_buffer for future use in rendering the new picture
|
||||
memcpy(s_video_buffer_write_ptr, _uData, len);
|
||||
s_video_buffer_write_ptr += len;
|
||||
}
|
||||
|
||||
void ResetVideoBuffer()
|
||||
{
|
||||
g_pVideoData = videoBuffer;
|
||||
size = 0;
|
||||
g_video_buffer_read_ptr = s_video_buffer;
|
||||
s_video_buffer_write_ptr = s_video_buffer;
|
||||
}
|
||||
|
||||
|
||||
@ -181,7 +183,7 @@ void RunGpuLoop()
|
||||
|
||||
Common::AtomicStore(fifo.CPReadPointer, readPtr);
|
||||
Common::AtomicAdd(fifo.CPReadWriteDistance, -32);
|
||||
if ((GetVideoBufferEndPtr() - g_pVideoData) == 0)
|
||||
if ((GetVideoBufferEndPtr() - g_video_buffer_read_ptr) == 0)
|
||||
Common::AtomicStore(fifo.SafeCPReadPointer, fifo.CPReadPointer);
|
||||
}
|
||||
|
||||
|
@ -31,12 +31,11 @@
|
||||
#include "VideoCommon/XFMemory.h"
|
||||
|
||||
|
||||
u8* g_pVideoData = nullptr;
|
||||
bool g_bRecordFifoData = false;
|
||||
|
||||
static u32 InterpretDisplayList(u32 address, u32 size)
|
||||
{
|
||||
u8* old_pVideoData = g_pVideoData;
|
||||
u8* old_pVideoData = g_video_buffer_read_ptr;
|
||||
u8* startAddress = Memory::GetPointer(address);
|
||||
|
||||
u32 cycles = 0;
|
||||
@ -44,12 +43,12 @@ static u32 InterpretDisplayList(u32 address, u32 size)
|
||||
// Avoid the crash if Memory::GetPointer failed ..
|
||||
if (startAddress != nullptr)
|
||||
{
|
||||
g_pVideoData = startAddress;
|
||||
g_video_buffer_read_ptr = startAddress;
|
||||
|
||||
// temporarily swap dl and non-dl (small "hack" for the stats)
|
||||
Statistics::SwapDL();
|
||||
|
||||
u8 *end = g_pVideoData + size;
|
||||
u8 *end = g_video_buffer_read_ptr + size;
|
||||
cycles = OpcodeDecoder_Run(end);
|
||||
INCSTAT(stats.thisFrame.numDListsCalled);
|
||||
|
||||
@ -58,7 +57,7 @@ static u32 InterpretDisplayList(u32 address, u32 size)
|
||||
}
|
||||
|
||||
// reset to the old pointer
|
||||
g_pVideoData = old_pVideoData;
|
||||
g_video_buffer_read_ptr = old_pVideoData;
|
||||
|
||||
return cycles;
|
||||
}
|
||||
@ -107,8 +106,8 @@ static void UnknownOpcode(u8 cmd_byte, void *buffer, bool preprocess)
|
||||
|
||||
static u32 Decode(u8* end)
|
||||
{
|
||||
u8 *opcodeStart = g_pVideoData;
|
||||
if (g_pVideoData == end)
|
||||
u8 *opcodeStart = g_video_buffer_read_ptr;
|
||||
if (g_video_buffer_read_ptr == end)
|
||||
return 0;
|
||||
|
||||
u8 cmd_byte = DataReadU8();
|
||||
@ -121,7 +120,7 @@ static u32 Decode(u8* end)
|
||||
|
||||
case GX_LOAD_CP_REG: //0x08
|
||||
{
|
||||
if (end - g_pVideoData < 1 + 4)
|
||||
if (end - g_video_buffer_read_ptr < 1 + 4)
|
||||
return 0;
|
||||
cycles = 12;
|
||||
u8 sub_cmd = DataReadU8();
|
||||
@ -133,11 +132,11 @@ static u32 Decode(u8* end)
|
||||
|
||||
case GX_LOAD_XF_REG:
|
||||
{
|
||||
if (end - g_pVideoData < 4)
|
||||
if (end - g_video_buffer_read_ptr < 4)
|
||||
return 0;
|
||||
u32 Cmd2 = DataReadU32();
|
||||
int transfer_size = ((Cmd2 >> 16) & 15) + 1;
|
||||
if ((size_t) (end - g_pVideoData) < transfer_size * sizeof(u32))
|
||||
if ((size_t) (end - g_video_buffer_read_ptr) < transfer_size * sizeof(u32))
|
||||
return 0;
|
||||
cycles = 18 + 6 * transfer_size;
|
||||
u32 xf_address = Cmd2 & 0xFFFF;
|
||||
@ -148,25 +147,25 @@ static u32 Decode(u8* end)
|
||||
break;
|
||||
|
||||
case GX_LOAD_INDX_A: //used for position matrices
|
||||
if (end - g_pVideoData < 4)
|
||||
if (end - g_video_buffer_read_ptr < 4)
|
||||
return 0;
|
||||
cycles = 6;
|
||||
LoadIndexedXF(DataReadU32(), 0xC);
|
||||
break;
|
||||
case GX_LOAD_INDX_B: //used for normal matrices
|
||||
if (end - g_pVideoData < 4)
|
||||
if (end - g_video_buffer_read_ptr < 4)
|
||||
return 0;
|
||||
cycles = 6;
|
||||
LoadIndexedXF(DataReadU32(), 0xD);
|
||||
break;
|
||||
case GX_LOAD_INDX_C: //used for postmatrices
|
||||
if (end - g_pVideoData < 4)
|
||||
if (end - g_video_buffer_read_ptr < 4)
|
||||
return 0;
|
||||
cycles = 6;
|
||||
LoadIndexedXF(DataReadU32(), 0xE);
|
||||
break;
|
||||
case GX_LOAD_INDX_D: //used for lights
|
||||
if (end - g_pVideoData < 4)
|
||||
if (end - g_video_buffer_read_ptr < 4)
|
||||
return 0;
|
||||
cycles = 6;
|
||||
LoadIndexedXF(DataReadU32(), 0xF);
|
||||
@ -174,7 +173,7 @@ static u32 Decode(u8* end)
|
||||
|
||||
case GX_CMD_CALL_DL:
|
||||
{
|
||||
if (end - g_pVideoData < 8)
|
||||
if (end - g_video_buffer_read_ptr < 8)
|
||||
return 0;
|
||||
u32 address = DataReadU32();
|
||||
u32 count = DataReadU32();
|
||||
@ -196,7 +195,7 @@ static u32 Decode(u8* end)
|
||||
// In skipped_frame case: We have to let BP writes through because they set
|
||||
// tokens and stuff. TODO: Call a much simplified LoadBPReg instead.
|
||||
{
|
||||
if (end - g_pVideoData < 4)
|
||||
if (end - g_video_buffer_read_ptr < 4)
|
||||
return 0;
|
||||
cycles = 12;
|
||||
u32 bp_cmd = DataReadU32();
|
||||
@ -211,7 +210,7 @@ static u32 Decode(u8* end)
|
||||
{
|
||||
cycles = 1600;
|
||||
// load vertices
|
||||
if (end - g_pVideoData < 2)
|
||||
if (end - g_video_buffer_read_ptr < 2)
|
||||
return 0;
|
||||
u16 numVertices = DataReadU16();
|
||||
|
||||
@ -219,7 +218,7 @@ static u32 Decode(u8* end)
|
||||
cmd_byte & GX_VAT_MASK, // Vertex loader index (0 - 7)
|
||||
(cmd_byte & GX_PRIMITIVE_MASK) >> GX_PRIMITIVE_SHIFT,
|
||||
numVertices,
|
||||
end - g_pVideoData,
|
||||
end - g_video_buffer_read_ptr,
|
||||
g_bSkipCurrentFrame))
|
||||
{
|
||||
return 0;
|
||||
@ -235,14 +234,14 @@ static u32 Decode(u8* end)
|
||||
|
||||
// Display lists get added directly into the FIFO stream
|
||||
if (g_bRecordFifoData && cmd_byte != GX_CMD_CALL_DL)
|
||||
FifoRecorder::GetInstance().WriteGPCommand(opcodeStart, u32(g_pVideoData - opcodeStart));
|
||||
FifoRecorder::GetInstance().WriteGPCommand(opcodeStart, u32(g_video_buffer_read_ptr - opcodeStart));
|
||||
|
||||
return cycles;
|
||||
}
|
||||
|
||||
void OpcodeDecoder_Init()
|
||||
{
|
||||
g_pVideoData = GetVideoBufferStartPtr();
|
||||
g_video_buffer_read_ptr = GetVideoBufferStartPtr();
|
||||
}
|
||||
|
||||
|
||||
@ -255,11 +254,11 @@ u32 OpcodeDecoder_Run(u8* end)
|
||||
u32 totalCycles = 0;
|
||||
while (true)
|
||||
{
|
||||
u8* old = g_pVideoData;
|
||||
u8* old = g_video_buffer_read_ptr;
|
||||
u32 cycles = Decode(end);
|
||||
if (cycles == 0)
|
||||
{
|
||||
g_pVideoData = old;
|
||||
g_video_buffer_read_ptr = old;
|
||||
break;
|
||||
}
|
||||
totalCycles += cycles;
|
||||
|
@ -74,7 +74,7 @@ protected:
|
||||
|
||||
void ResetPointers()
|
||||
{
|
||||
g_pVideoData = &input_memory[0];
|
||||
g_video_buffer_read_ptr = &input_memory[0];
|
||||
VertexManager::s_pCurBufferPointer = &output_memory[0];
|
||||
m_input_pos = m_output_pos = 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user