2013-04-17 21:09:55 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2010-06-08 19:37:08 -06:00
|
|
|
|
|
|
|
|
|
|
|
// http://developer.nvidia.com/object/General_FAQ.html#t6 !!!!!
|
|
|
|
|
|
|
|
|
2014-02-18 18:27:20 -07:00
|
|
|
#include "Common/Atomic.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/ChunkFile.h"
|
2014-09-07 19:06:58 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/CoreTiming.h"
|
|
|
|
#include "Core/State.h"
|
|
|
|
#include "Core/HW/MMIO.h"
|
|
|
|
#include "Core/HW/ProcessorInterface.h"
|
|
|
|
#include "VideoCommon/CommandProcessor.h"
|
|
|
|
#include "VideoCommon/PixelEngine.h"
|
|
|
|
#include "VideoCommon/RenderBase.h"
|
|
|
|
#include "VideoCommon/VideoCommon.h"
|
2012-06-17 05:58:29 -06:00
|
|
|
|
2010-06-08 19:37:08 -06:00
|
|
|
namespace PixelEngine
|
|
|
|
{
|
|
|
|
|
|
|
|
union UPEZConfReg
|
|
|
|
{
|
|
|
|
u16 Hex;
|
2013-10-28 23:23:17 -06:00
|
|
|
struct
|
2010-06-08 19:37:08 -06:00
|
|
|
{
|
2014-02-09 16:29:13 -07:00
|
|
|
u16 ZCompEnable : 1; // Z Comparator Enable
|
|
|
|
u16 Function : 3;
|
|
|
|
u16 ZUpdEnable : 1;
|
|
|
|
u16 : 11;
|
2010-06-08 19:37:08 -06:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
union UPEAlphaConfReg
|
|
|
|
{
|
|
|
|
u16 Hex;
|
2013-10-28 23:23:17 -06:00
|
|
|
struct
|
2010-06-08 19:37:08 -06:00
|
|
|
{
|
2014-02-09 16:29:13 -07:00
|
|
|
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-08 19:37:08 -06:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
union UPEDstAlphaConfReg
|
|
|
|
{
|
|
|
|
u16 Hex;
|
2013-10-28 23:23:17 -06:00
|
|
|
struct
|
2010-06-08 19:37:08 -06:00
|
|
|
{
|
2014-02-09 16:29:13 -07:00
|
|
|
u16 DstAlpha : 8;
|
|
|
|
u16 Enable : 1;
|
|
|
|
u16 : 7;
|
2010-06-08 19:37:08 -06:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
union UPEAlphaModeConfReg
|
|
|
|
{
|
|
|
|
u16 Hex;
|
2013-10-28 23:23:17 -06:00
|
|
|
struct
|
2010-06-08 19:37:08 -06:00
|
|
|
{
|
2014-02-09 16:29:13 -07:00
|
|
|
u16 Threshold : 8;
|
|
|
|
u16 CompareMode : 8;
|
2010-06-08 19:37:08 -06:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// fifo Control Register
|
|
|
|
union UPECtrlReg
|
|
|
|
{
|
2013-10-28 23:23:17 -06:00
|
|
|
struct
|
2010-06-08 19:37:08 -06:00
|
|
|
{
|
2014-02-09 16:29:13 -07:00
|
|
|
u16 PETokenEnable : 1;
|
|
|
|
u16 PEFinishEnable : 1;
|
|
|
|
u16 PEToken : 1; // write only
|
|
|
|
u16 PEFinish : 1; // write only
|
|
|
|
u16 : 12;
|
2010-06-08 19:37:08 -06:00
|
|
|
};
|
|
|
|
u16 Hex;
|
|
|
|
UPECtrlReg() {Hex = 0; }
|
|
|
|
UPECtrlReg(u16 _hex) {Hex = _hex; }
|
|
|
|
};
|
|
|
|
|
|
|
|
// STATE_TO_SAVE
|
2014-02-09 16:29:13 -07:00
|
|
|
static UPEZConfReg m_ZConf;
|
|
|
|
static UPEAlphaConfReg m_AlphaConf;
|
|
|
|
static UPEDstAlphaConfReg m_DstAlphaConf;
|
|
|
|
static UPEAlphaModeConfReg m_AlphaModeConf;
|
|
|
|
static UPEAlphaReadReg m_AlphaRead;
|
|
|
|
static UPECtrlReg m_Control;
|
|
|
|
//static u16 m_Token; // token value most recently encountered
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2014-07-08 07:58:25 -06:00
|
|
|
static volatile u32 g_bSignalTokenInterrupt;
|
|
|
|
static volatile u32 g_bSignalFinishInterrupt;
|
2010-06-08 19:37:08 -06:00
|
|
|
|
|
|
|
static int et_SetTokenOnMainThread;
|
|
|
|
static int et_SetFinishOnMainThread;
|
|
|
|
|
2014-07-08 07:58:25 -06:00
|
|
|
static volatile u32 interruptSetToken = 0;
|
|
|
|
static volatile u32 interruptSetFinish = 0;
|
2010-12-13 00:56:54 -07:00
|
|
|
|
2010-06-08 19:37:08 -06:00
|
|
|
u16 bbox[4];
|
|
|
|
bool bbox_active;
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2014-02-09 14:03:16 -07:00
|
|
|
INT_CAUSE_PE_TOKEN = 0x200, // GP Token
|
|
|
|
INT_CAUSE_PE_FINISH = 0x400, // GP Finished
|
2010-06-08 19:37:08 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
void DoState(PointerWrap &p)
|
|
|
|
{
|
|
|
|
p.Do(m_ZConf);
|
|
|
|
p.Do(m_AlphaConf);
|
|
|
|
p.Do(m_DstAlphaConf);
|
|
|
|
p.Do(m_AlphaModeConf);
|
|
|
|
p.Do(m_AlphaRead);
|
2013-04-09 17:57:39 -06:00
|
|
|
p.DoPOD(m_Control);
|
2010-06-08 19:37:08 -06:00
|
|
|
|
|
|
|
p.Do(g_bSignalTokenInterrupt);
|
|
|
|
p.Do(g_bSignalFinishInterrupt);
|
2011-02-15 02:07:55 -07:00
|
|
|
p.Do(interruptSetToken);
|
|
|
|
p.Do(interruptSetFinish);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2010-06-08 19:37:08 -06:00
|
|
|
p.Do(bbox);
|
|
|
|
p.Do(bbox_active);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateInterrupts();
|
2010-12-13 00:56:54 -07:00
|
|
|
void UpdateTokenInterrupt(bool active);
|
|
|
|
void UpdateFinishInterrupt(bool active);
|
2010-06-08 19:37:08 -06:00
|
|
|
void SetToken_OnMainThread(u64 userdata, int cyclesLate);
|
|
|
|
void SetFinish_OnMainThread(u64 userdata, int cyclesLate);
|
|
|
|
|
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
m_Control.Hex = 0;
|
2012-01-02 03:20:22 -07:00
|
|
|
m_ZConf.Hex = 0;
|
|
|
|
m_AlphaConf.Hex = 0;
|
|
|
|
m_DstAlphaConf.Hex = 0;
|
|
|
|
m_AlphaModeConf.Hex = 0;
|
|
|
|
m_AlphaRead.Hex = 0;
|
|
|
|
|
2013-02-08 23:46:48 -07:00
|
|
|
g_bSignalTokenInterrupt = 0;
|
|
|
|
g_bSignalFinishInterrupt = 0;
|
|
|
|
interruptSetToken = 0;
|
|
|
|
interruptSetFinish = 0;
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2011-01-30 18:28:32 -07:00
|
|
|
et_SetTokenOnMainThread = CoreTiming::RegisterEvent("SetToken", SetToken_OnMainThread);
|
|
|
|
et_SetFinishOnMainThread = CoreTiming::RegisterEvent("SetFinish", SetFinish_OnMainThread);
|
2010-06-08 19:37:08 -06:00
|
|
|
|
|
|
|
bbox[0] = 0x80;
|
|
|
|
bbox[1] = 0xA0;
|
|
|
|
bbox[2] = 0x80;
|
|
|
|
bbox[3] = 0xA0;
|
|
|
|
|
|
|
|
bbox_active = false;
|
|
|
|
}
|
|
|
|
|
2014-02-02 08:08:09 -07:00
|
|
|
void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
|
2010-06-08 19:37:08 -06:00
|
|
|
{
|
2014-02-02 08:08:09 -07: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)
|
2010-06-08 19:37:08 -06:00
|
|
|
{
|
2014-02-02 08:08:09 -07:00
|
|
|
mmio->Register(base | mapped_var.addr,
|
|
|
|
MMIO::DirectRead<u16>(mapped_var.ptr),
|
|
|
|
MMIO::DirectWrite<u16>(mapped_var.ptr)
|
|
|
|
);
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2014-02-02 08:08:09 -07: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)
|
2010-06-08 19:37:08 -06:00
|
|
|
{
|
2014-02-02 08:08:09 -07:00
|
|
|
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>()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-08 19:37:08 -06:00
|
|
|
|
2014-02-16 21:51:41 -07:00
|
|
|
if (tmpCtrl.PEToken) g_bSignalTokenInterrupt = 0;
|
|
|
|
if (tmpCtrl.PEFinish) g_bSignalFinishInterrupt = 0;
|
2010-06-08 19:37:08 -06:00
|
|
|
|
|
|
|
m_Control.PETokenEnable = tmpCtrl.PETokenEnable;
|
|
|
|
m_Control.PEFinishEnable = tmpCtrl.PEFinishEnable;
|
2014-02-16 21:51:41 -07:00
|
|
|
m_Control.PEToken = 0; // this flag is write only
|
|
|
|
m_Control.PEFinish = 0; // this flag is write only
|
2010-06-08 19:37:08 -06:00
|
|
|
|
2014-02-02 08:08:09 -07:00
|
|
|
DEBUG_LOG(PIXELENGINE, "(w16) CTRL_REGISTER: 0x%04x", val);
|
2010-06-08 19:37:08 -06:00
|
|
|
UpdateInterrupts();
|
2014-02-02 08:08:09 -07:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
// Token register, readonly.
|
|
|
|
mmio->Register(base | PE_TOKEN_REG,
|
|
|
|
MMIO::DirectRead<u16>(&CommandProcessor::fifo.PEToken),
|
|
|
|
MMIO::InvalidWrite<u16>()
|
|
|
|
);
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
bbox_active = false;
|
|
|
|
return bbox[i];
|
|
|
|
}),
|
|
|
|
MMIO::InvalidWrite<u16>()
|
|
|
|
);
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|
2014-02-02 08:08:09 -07:00
|
|
|
}
|
2010-12-13 00:56:54 -07:00
|
|
|
|
2010-06-08 19:37:08 -06:00
|
|
|
void UpdateInterrupts()
|
|
|
|
{
|
|
|
|
// check if there is a token-interrupt
|
2010-12-13 00:56:54 -07:00
|
|
|
UpdateTokenInterrupt((g_bSignalTokenInterrupt & m_Control.PETokenEnable));
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2010-06-08 19:37:08 -06:00
|
|
|
// check if there is a finish-interrupt
|
2010-12-13 00:56:54 -07:00
|
|
|
UpdateFinishInterrupt((g_bSignalFinishInterrupt & m_Control.PEFinishEnable));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateTokenInterrupt(bool active)
|
|
|
|
{
|
2013-02-03 00:05:46 -07:00
|
|
|
ProcessorInterface::SetInterrupt(INT_CAUSE_PE_TOKEN, active);
|
2013-02-08 23:46:48 -07:00
|
|
|
Common::AtomicStore(interruptSetToken, active ? 1 : 0);
|
2010-12-13 00:56:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateFinishInterrupt(bool active)
|
|
|
|
{
|
2013-02-03 00:05:46 -07:00
|
|
|
ProcessorInterface::SetInterrupt(INT_CAUSE_PE_FINISH, active);
|
2013-02-08 23:46:48 -07:00
|
|
|
Common::AtomicStore(interruptSetFinish, active ? 1 : 0);
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(mb2): Refactor SetTokenINT_OnMainThread(u64 userdata, int cyclesLate).
|
2014-02-16 21:51:41 -07:00
|
|
|
// Think about the right order between tokenVal and tokenINT... one day maybe.
|
|
|
|
// Cleanup++
|
2010-06-08 19:37:08 -06:00
|
|
|
|
|
|
|
// Called only if BPMEM_PE_TOKEN_INT_ID is ack by GP
|
|
|
|
void SetToken_OnMainThread(u64 userdata, int cyclesLate)
|
|
|
|
{
|
2013-02-10 00:24:30 -07: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);
|
2013-02-03 00:05:46 -07:00
|
|
|
INFO_LOG(PIXELENGINE, "VIDEO Backend raises INT_CAUSE_PE_TOKEN (btw, token: %04x)", CommandProcessor::fifo.PEToken);
|
2013-02-10 00:24:30 -07:00
|
|
|
if (userdata >> 16)
|
2013-03-07 04:16:00 -07:00
|
|
|
{
|
|
|
|
Common::AtomicStore(*(volatile u32*)&g_bSignalTokenInterrupt, 1);
|
2010-06-08 19:37:08 -06:00
|
|
|
UpdateInterrupts();
|
2013-03-07 04:16:00 -07:00
|
|
|
}
|
2013-02-03 00:05:46 -07:00
|
|
|
CommandProcessor::interruptTokenWaiting = false;
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetFinish_OnMainThread(u64 userdata, int cyclesLate)
|
|
|
|
{
|
2013-02-16 00:30:20 -07:00
|
|
|
Common::AtomicStore(*(volatile u32*)&g_bSignalFinishInterrupt, 1);
|
2010-06-08 19:37:08 -06:00
|
|
|
UpdateInterrupts();
|
2010-12-13 00:56:54 -07:00
|
|
|
CommandProcessor::interruptFinishWaiting = false;
|
2011-02-09 21:47:02 -07:00
|
|
|
CommandProcessor::isPossibleWaitingSetDrawDone = false;
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetToken
|
|
|
|
// THIS IS EXECUTED FROM VIDEO THREAD
|
|
|
|
void SetToken(const u16 _token, const int _bSetTokenAcknowledge)
|
|
|
|
{
|
|
|
|
if (_bSetTokenAcknowledge) // set token INT
|
|
|
|
{
|
2013-02-03 05:52:18 -07:00
|
|
|
Common::AtomicStore(*(volatile u32*)&g_bSignalTokenInterrupt, 1);
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|
2013-02-03 00:05:46 -07:00
|
|
|
|
2013-02-10 00:24:30 -07:00
|
|
|
CommandProcessor::interruptTokenWaiting = true;
|
|
|
|
CoreTiming::ScheduleEvent_Threadsafe(0, et_SetTokenOnMainThread, _token | (_bSetTokenAcknowledge << 16));
|
2010-06-08 19:37:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetFinish
|
|
|
|
// THIS IS EXECUTED FROM VIDEO THREAD (BPStructs.cpp) when a new frame has been drawn
|
|
|
|
void SetFinish()
|
|
|
|
{
|
2010-12-13 00:56:54 -07:00
|
|
|
CommandProcessor::interruptFinishWaiting = true;
|
2011-01-30 18:28:32 -07:00
|
|
|
CoreTiming::ScheduleEvent_Threadsafe(0, et_SetFinishOnMainThread, 0);
|
2010-06-08 19:37:08 -06:00
|
|
|
INFO_LOG(PIXELENGINE, "VIDEO Set Finish");
|
|
|
|
}
|
|
|
|
|
2014-02-14 19:23:35 -07:00
|
|
|
UPEAlphaReadReg GetAlphaReadMode()
|
|
|
|
{
|
|
|
|
return m_AlphaRead;
|
|
|
|
}
|
|
|
|
|
2010-06-08 19:37:08 -06:00
|
|
|
} // end of namespace PixelEngine
|