2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-18 01:08:10 +02:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 23:09:55 -04:00
|
|
|
// Refer to the license.txt file included.
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2015-05-01 21:42:50 +02:00
|
|
|
// http://www.nvidia.com/object/General_FAQ.html#t6 !!!!!
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2015-05-27 02:18:22 -04:00
|
|
|
#include <atomic>
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2014-02-19 02:27:20 +01:00
|
|
|
#include "Common/Atomic.h"
|
2014-02-17 05:18:15 -05:00
|
|
|
#include "Common/ChunkFile.h"
|
2014-09-07 20:06:58 -05:00
|
|
|
#include "Common/CommonTypes.h"
|
2016-01-17 16:54:31 -05:00
|
|
|
#include "Common/Logging/Log.h"
|
2014-02-17 05:18:15 -05:00
|
|
|
#include "Core/ConfigManager.h"
|
2015-06-06 01:20:51 -04:00
|
|
|
#include "Core/Core.h"
|
2014-02-17 05:18:15 -05:00
|
|
|
#include "Core/CoreTiming.h"
|
|
|
|
|
#include "Core/HW/MMIO.h"
|
|
|
|
|
#include "Core/HW/ProcessorInterface.h"
|
2014-09-17 02:04:37 +01:00
|
|
|
#include "VideoCommon/BoundingBox.h"
|
2014-02-17 05:18:15 -05:00
|
|
|
#include "VideoCommon/CommandProcessor.h"
|
2015-01-30 14:48:23 -08:00
|
|
|
#include "VideoCommon/Fifo.h"
|
2014-02-17 05:18:15 -05:00
|
|
|
#include "VideoCommon/PixelEngine.h"
|
2012-06-17 13:58:29 +02:00
|
|
|
|
2010-06-09 01:37:08 +00:00
|
|
|
namespace PixelEngine
|
|
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
union UPEZConfReg {
|
|
|
|
|
u16 Hex;
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
u16 ZCompEnable : 1; // Z Comparator Enable
|
|
|
|
|
u16 Function : 3;
|
|
|
|
|
u16 ZUpdEnable : 1;
|
|
|
|
|
u16 : 11;
|
|
|
|
|
};
|
2010-06-09 01:37:08 +00:00
|
|
|
};
|
|
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
union UPEAlphaConfReg {
|
|
|
|
|
u16 Hex;
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
u16 BMMath : 1; // GX_BM_BLEND || GX_BM_SUBSTRACT
|
|
|
|
|
u16 BMLogic : 1; // GX_BM_LOGIC
|
|
|
|
|
u16 Dither : 1;
|
|
|
|
|
u16 ColorUpdEnable : 1;
|
|
|
|
|
u16 AlphaUpdEnable : 1;
|
|
|
|
|
u16 DstFactor : 3;
|
|
|
|
|
u16 SrcFactor : 3;
|
|
|
|
|
u16 Substract : 1; // Additive mode by default
|
|
|
|
|
u16 BlendOperator : 4;
|
|
|
|
|
};
|
2010-06-09 01:37:08 +00:00
|
|
|
};
|
|
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
union UPEDstAlphaConfReg {
|
|
|
|
|
u16 Hex;
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
u16 DstAlpha : 8;
|
|
|
|
|
u16 Enable : 1;
|
|
|
|
|
u16 : 7;
|
|
|
|
|
};
|
2010-06-09 01:37:08 +00:00
|
|
|
};
|
|
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
union UPEAlphaModeConfReg {
|
|
|
|
|
u16 Hex;
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
u16 Threshold : 8;
|
|
|
|
|
u16 CompareMode : 8;
|
|
|
|
|
};
|
2010-06-09 01:37:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// fifo Control Register
|
2016-06-24 10:43:46 +02:00
|
|
|
union UPECtrlReg {
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
u16 PETokenEnable : 1;
|
|
|
|
|
u16 PEFinishEnable : 1;
|
|
|
|
|
u16 PEToken : 1; // write only
|
|
|
|
|
u16 PEFinish : 1; // write only
|
|
|
|
|
u16 : 12;
|
|
|
|
|
};
|
|
|
|
|
u16 Hex;
|
|
|
|
|
UPECtrlReg() { Hex = 0; }
|
|
|
|
|
UPECtrlReg(u16 _hex) { Hex = _hex; }
|
2010-06-09 01:37:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// STATE_TO_SAVE
|
2016-06-24 10:43:46 +02:00
|
|
|
static UPEZConfReg m_ZConf;
|
|
|
|
|
static UPEAlphaConfReg m_AlphaConf;
|
|
|
|
|
static UPEDstAlphaConfReg m_DstAlphaConf;
|
2014-02-09 18:29:13 -05:00
|
|
|
static UPEAlphaModeConfReg m_AlphaModeConf;
|
2016-06-24 10:43:46 +02:00
|
|
|
static UPEAlphaReadReg m_AlphaRead;
|
|
|
|
|
static UPECtrlReg m_Control;
|
|
|
|
|
// static u16 m_Token; // token value most recently encountered
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2015-05-27 02:18:22 -04:00
|
|
|
static std::atomic<u32> s_signal_token_interrupt;
|
|
|
|
|
static std::atomic<u32> s_signal_finish_interrupt;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
|
static int et_SetTokenOnMainThread;
|
|
|
|
|
static int et_SetFinishOnMainThread;
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
INT_CAUSE_PE_TOKEN = 0x200, // GP Token
|
|
|
|
|
INT_CAUSE_PE_FINISH = 0x400, // GP Finished
|
2010-06-09 01:37:08 +00:00
|
|
|
};
|
|
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
void DoState(PointerWrap& p)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
p.Do(m_ZConf);
|
|
|
|
|
p.Do(m_AlphaConf);
|
|
|
|
|
p.Do(m_DstAlphaConf);
|
|
|
|
|
p.Do(m_AlphaModeConf);
|
|
|
|
|
p.Do(m_AlphaRead);
|
|
|
|
|
p.DoPOD(m_Control);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
p.Do(s_signal_token_interrupt);
|
|
|
|
|
p.Do(s_signal_finish_interrupt);
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-10 02:06:09 +12:00
|
|
|
static void UpdateInterrupts();
|
|
|
|
|
static void UpdateTokenInterrupt(bool active);
|
|
|
|
|
static void UpdateFinishInterrupt(bool active);
|
|
|
|
|
static void SetToken_OnMainThread(u64 userdata, s64 cyclesLate);
|
|
|
|
|
static void SetFinish_OnMainThread(u64 userdata, s64 cyclesLate);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
|
void Init()
|
|
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
m_Control.Hex = 0;
|
|
|
|
|
m_ZConf.Hex = 0;
|
|
|
|
|
m_AlphaConf.Hex = 0;
|
|
|
|
|
m_DstAlphaConf.Hex = 0;
|
|
|
|
|
m_AlphaModeConf.Hex = 0;
|
|
|
|
|
m_AlphaRead.Hex = 0;
|
2012-01-02 02:20:22 -08:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
s_signal_token_interrupt.store(0);
|
|
|
|
|
s_signal_finish_interrupt.store(0);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
et_SetTokenOnMainThread = CoreTiming::RegisterEvent("SetToken", SetToken_OnMainThread);
|
|
|
|
|
et_SetFinishOnMainThread = CoreTiming::RegisterEvent("SetFinish", SetFinish_OnMainThread);
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-02 16:08:09 +01:00
|
|
|
void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
// Directly mapped registers.
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
u32 addr;
|
|
|
|
|
u16* ptr;
|
|
|
|
|
} directly_mapped_vars[] = {
|
|
|
|
|
{PE_ZCONF, &m_ZConf.Hex},
|
|
|
|
|
{PE_ALPHACONF, &m_AlphaConf.Hex},
|
|
|
|
|
{PE_DSTALPHACONF, &m_DstAlphaConf.Hex},
|
|
|
|
|
{PE_ALPHAMODE, &m_AlphaModeConf.Hex},
|
|
|
|
|
{PE_ALPHAREAD, &m_AlphaRead.Hex},
|
|
|
|
|
};
|
|
|
|
|
for (auto& mapped_var : directly_mapped_vars)
|
|
|
|
|
{
|
|
|
|
|
mmio->Register(base | mapped_var.addr, MMIO::DirectRead<u16>(mapped_var.ptr),
|
|
|
|
|
MMIO::DirectWrite<u16>(mapped_var.ptr));
|
|
|
|
|
}
|
2013-10-29 01:23:17 -04:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
// Performance queries registers: read only, need to call the video backend
|
|
|
|
|
// to get the results.
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
u32 addr;
|
|
|
|
|
PerfQueryType pqtype;
|
|
|
|
|
} pq_regs[] = {
|
|
|
|
|
{PE_PERF_ZCOMP_INPUT_ZCOMPLOC_L, PQ_ZCOMP_INPUT_ZCOMPLOC},
|
|
|
|
|
{PE_PERF_ZCOMP_OUTPUT_ZCOMPLOC_L, PQ_ZCOMP_OUTPUT_ZCOMPLOC},
|
|
|
|
|
{PE_PERF_ZCOMP_INPUT_L, PQ_ZCOMP_INPUT},
|
|
|
|
|
{PE_PERF_ZCOMP_OUTPUT_L, PQ_ZCOMP_OUTPUT},
|
|
|
|
|
{PE_PERF_BLEND_INPUT_L, PQ_BLEND_INPUT},
|
|
|
|
|
{PE_PERF_EFB_COPY_CLOCKS_L, PQ_EFB_COPY_CLOCKS},
|
|
|
|
|
};
|
|
|
|
|
for (auto& pq_reg : pq_regs)
|
|
|
|
|
{
|
|
|
|
|
mmio->Register(base | pq_reg.addr, MMIO::ComplexRead<u16>([pq_reg](u32) {
|
|
|
|
|
return g_video_backend->Video_GetQueryResult(pq_reg.pqtype) & 0xFFFF;
|
|
|
|
|
}),
|
|
|
|
|
MMIO::InvalidWrite<u16>());
|
|
|
|
|
mmio->Register(base | (pq_reg.addr + 2), MMIO::ComplexRead<u16>([pq_reg](u32) {
|
|
|
|
|
return g_video_backend->Video_GetQueryResult(pq_reg.pqtype) >> 16;
|
|
|
|
|
}),
|
|
|
|
|
MMIO::InvalidWrite<u16>());
|
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
// Control register
|
|
|
|
|
mmio->Register(base | PE_CTRL_REGISTER, MMIO::DirectRead<u16>(&m_Control.Hex),
|
|
|
|
|
MMIO::ComplexWrite<u16>([](u32, u16 val) {
|
|
|
|
|
UPECtrlReg tmpCtrl(val);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
if (tmpCtrl.PEToken)
|
|
|
|
|
s_signal_token_interrupt.store(0);
|
2015-05-27 02:18:22 -04:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
if (tmpCtrl.PEFinish)
|
|
|
|
|
s_signal_finish_interrupt.store(0);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
m_Control.PETokenEnable = tmpCtrl.PETokenEnable;
|
|
|
|
|
m_Control.PEFinishEnable = tmpCtrl.PEFinishEnable;
|
|
|
|
|
m_Control.PEToken = 0; // this flag is write only
|
|
|
|
|
m_Control.PEFinish = 0; // this flag is write only
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
DEBUG_LOG(PIXELENGINE, "(w16) CTRL_REGISTER: 0x%04x", val);
|
|
|
|
|
UpdateInterrupts();
|
|
|
|
|
}));
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
// Token register, readonly.
|
|
|
|
|
mmio->Register(base | PE_TOKEN_REG, MMIO::DirectRead<u16>(&CommandProcessor::fifo.PEToken),
|
|
|
|
|
MMIO::InvalidWrite<u16>());
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
// BBOX registers, readonly and need to update a flag.
|
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
|
{
|
|
|
|
|
mmio->Register(base | (PE_BBOX_LEFT + 2 * i), MMIO::ComplexRead<u16>([i](u32) {
|
|
|
|
|
BoundingBox::active = false;
|
|
|
|
|
return g_video_backend->Video_GetBoundingBox(i);
|
|
|
|
|
}),
|
|
|
|
|
MMIO::InvalidWrite<u16>());
|
|
|
|
|
}
|
2014-02-02 16:08:09 +01:00
|
|
|
}
|
2010-12-13 07:56:54 +00:00
|
|
|
|
2016-04-10 02:06:09 +12:00
|
|
|
static void UpdateInterrupts()
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
// check if there is a token-interrupt
|
|
|
|
|
UpdateTokenInterrupt((s_signal_token_interrupt.load() & m_Control.PETokenEnable) != 0);
|
2013-10-29 01:23:17 -04:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
// check if there is a finish-interrupt
|
|
|
|
|
UpdateFinishInterrupt((s_signal_finish_interrupt.load() & m_Control.PEFinishEnable) != 0);
|
2010-12-13 07:56:54 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-10 02:06:09 +12:00
|
|
|
static void UpdateTokenInterrupt(bool active)
|
2010-12-13 07:56:54 +00:00
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
ProcessorInterface::SetInterrupt(INT_CAUSE_PE_TOKEN, active);
|
2010-12-13 07:56:54 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-10 02:06:09 +12:00
|
|
|
static void UpdateFinishInterrupt(bool active)
|
2010-12-13 07:56:54 +00:00
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
ProcessorInterface::SetInterrupt(INT_CAUSE_PE_FINISH, active);
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(mb2): Refactor SetTokenINT_OnMainThread(u64 userdata, int cyclesLate).
|
2014-02-16 23:51:41 -05:00
|
|
|
// Think about the right order between tokenVal and tokenINT... one day maybe.
|
|
|
|
|
// Cleanup++
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
|
// Called only if BPMEM_PE_TOKEN_INT_ID is ack by GP
|
2016-04-10 02:06:09 +12:00
|
|
|
static void SetToken_OnMainThread(u64 userdata, s64 cyclesLate)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
// XXX: No 16-bit atomic store available, so cheat and use 32-bit.
|
|
|
|
|
// That's what we've always done. We're counting on fifo.PEToken to be
|
|
|
|
|
// 4-byte padded.
|
|
|
|
|
Common::AtomicStore(*(volatile u32*)&CommandProcessor::fifo.PEToken, userdata & 0xffff);
|
|
|
|
|
INFO_LOG(PIXELENGINE, "VIDEO Backend raises INT_CAUSE_PE_TOKEN (btw, token: %04x)",
|
|
|
|
|
CommandProcessor::fifo.PEToken);
|
|
|
|
|
if (userdata >> 16)
|
|
|
|
|
{
|
|
|
|
|
s_signal_token_interrupt.store(1);
|
|
|
|
|
UpdateInterrupts();
|
|
|
|
|
}
|
|
|
|
|
CommandProcessor::SetInterruptTokenWaiting(false);
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-10 02:06:09 +12:00
|
|
|
static void SetFinish_OnMainThread(u64 userdata, s64 cyclesLate)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
s_signal_finish_interrupt.store(1);
|
|
|
|
|
UpdateInterrupts();
|
|
|
|
|
CommandProcessor::SetInterruptFinishWaiting(false);
|
2015-06-06 01:20:51 -04:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
Core::FrameUpdateOnCPUThread();
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetToken
|
|
|
|
|
// THIS IS EXECUTED FROM VIDEO THREAD
|
|
|
|
|
void SetToken(const u16 _token, const int _bSetTokenAcknowledge)
|
|
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
if (_bSetTokenAcknowledge) // set token INT
|
|
|
|
|
{
|
|
|
|
|
s_signal_token_interrupt.store(1);
|
|
|
|
|
}
|
Big Fifo Commit Part2: Now the fifo is more stable than my first commit, so is time...
- ReImplementing Single Core Mode like Dual Core Mode Style.
- Stage 1: My goal is, we have the Fifo, CommandProccessor code the more clear, maintenible and documented possible. When I quit dolphin I want any developer can continue with the work only reading the code.
* Big Refactoring: A lot of functions was changed the names, and modularized.
Now the FifoLoop and CatchUpGPU does not exist, was replaced by RunGpu() and RunGpuLoop().
The general idea is modeling the code like the real HW. The fifo is only a buffer where the Write Gather Pipe write the commands and from the Graphic Processor read these.
* Big Clean UP a lot of obsolete code and comments was deleted, like DcFakeWachDog, "Fifo very soon hack", etc.
In the stage 2, I will refactoring more code doing emphasis in the division of CommandProcessor, Fifo, Gpu Emulation. Beside I will comment all functions and variables in the code (Don't worry I will ask for English help for this part ;) )
Please test a lot SC mode and DC mode :)
Thank you so much for testing always and the patience. I don't like broke your favorite game but... you must believe me this part is very sensible, I only try to contribute for have a better and stable dolphin emulator.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7185 8ced0084-cf51-0410-be5f-012b33b47a6e
2011-02-17 04:25:21 +00:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
CommandProcessor::SetInterruptTokenWaiting(true);
|
2015-05-27 03:08:48 -04:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
if (!SConfig::GetInstance().bCPUThread || Fifo::UseDeterministicGPUThread())
|
|
|
|
|
CoreTiming::ScheduleEvent(0, et_SetTokenOnMainThread, _token | (_bSetTokenAcknowledge << 16));
|
|
|
|
|
else
|
|
|
|
|
CoreTiming::ScheduleEvent_Threadsafe(0, et_SetTokenOnMainThread,
|
|
|
|
|
_token | (_bSetTokenAcknowledge << 16));
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetFinish
|
|
|
|
|
// THIS IS EXECUTED FROM VIDEO THREAD (BPStructs.cpp) when a new frame has been drawn
|
|
|
|
|
void SetFinish()
|
|
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
CommandProcessor::SetInterruptFinishWaiting(true);
|
2015-05-27 03:08:48 -04:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
if (!SConfig::GetInstance().bCPUThread || Fifo::UseDeterministicGPUThread())
|
|
|
|
|
CoreTiming::ScheduleEvent(0, et_SetFinishOnMainThread, 0);
|
|
|
|
|
else
|
|
|
|
|
CoreTiming::ScheduleEvent_Threadsafe(0, et_SetFinishOnMainThread, 0);
|
2015-05-27 03:08:48 -04:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
INFO_LOG(PIXELENGINE, "VIDEO Set Finish");
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-15 03:23:35 +01:00
|
|
|
UPEAlphaReadReg GetAlphaReadMode()
|
|
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
return m_AlphaRead;
|
2014-02-15 03:23:35 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
} // end of namespace PixelEngine
|