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.
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2015-05-01 19:42:50 +00:00
|
|
|
// http://www.nvidia.com/object/General_FAQ.html#t6 !!!!!
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2017-09-02 17:23:26 +00:00
|
|
|
#include "VideoCommon/PixelEngine.h"
|
|
|
|
|
2016-08-10 07:44:08 +00:00
|
|
|
#include <mutex>
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/ChunkFile.h"
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "Common/Logging/Log.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
2015-06-06 05:20:51 +00:00
|
|
|
#include "Core/Core.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/CoreTiming.h"
|
|
|
|
#include "Core/HW/MMIO.h"
|
|
|
|
#include "Core/HW/ProcessorInterface.h"
|
2014-09-17 01:04:37 +00:00
|
|
|
#include "VideoCommon/BoundingBox.h"
|
2015-01-30 22:48:23 +00:00
|
|
|
#include "VideoCommon/Fifo.h"
|
2017-09-02 17:23:26 +00:00
|
|
|
#include "VideoCommon/PerfQueryBase.h"
|
|
|
|
#include "VideoCommon/VideoBackendBase.h"
|
2012-06-17 11:58:29 +00:00
|
|
|
|
2010-06-09 01:37:08 +00:00
|
|
|
namespace PixelEngine
|
|
|
|
{
|
2017-01-04 11:45:40 +00:00
|
|
|
union UPEZConfReg
|
|
|
|
{
|
2010-06-09 01:37:08 +00:00
|
|
|
u16 Hex;
|
2013-10-29 05:23:17 +00:00
|
|
|
struct
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2014-02-09 23:29:13 +00:00
|
|
|
u16 ZCompEnable : 1; // Z Comparator Enable
|
|
|
|
u16 Function : 3;
|
|
|
|
u16 ZUpdEnable : 1;
|
|
|
|
u16 : 11;
|
2010-06-09 01:37:08 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-04 11:45:40 +00:00
|
|
|
union UPEAlphaConfReg
|
|
|
|
{
|
2010-06-09 01:37:08 +00:00
|
|
|
u16 Hex;
|
2013-10-29 05:23:17 +00:00
|
|
|
struct
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2014-02-09 23:29:13 +00: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-09 01:37:08 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-04 11:45:40 +00:00
|
|
|
union UPEDstAlphaConfReg
|
|
|
|
{
|
2010-06-09 01:37:08 +00:00
|
|
|
u16 Hex;
|
2013-10-29 05:23:17 +00:00
|
|
|
struct
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2014-02-09 23:29:13 +00:00
|
|
|
u16 DstAlpha : 8;
|
|
|
|
u16 Enable : 1;
|
|
|
|
u16 : 7;
|
2010-06-09 01:37:08 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-04 11:45:40 +00:00
|
|
|
union UPEAlphaModeConfReg
|
|
|
|
{
|
2010-06-09 01:37:08 +00:00
|
|
|
u16 Hex;
|
2013-10-29 05:23:17 +00:00
|
|
|
struct
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2014-02-09 23:29:13 +00:00
|
|
|
u16 Threshold : 8;
|
|
|
|
u16 CompareMode : 8;
|
2010-06-09 01:37:08 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// fifo Control Register
|
2017-01-04 11:45:40 +00:00
|
|
|
union UPECtrlReg
|
|
|
|
{
|
2013-10-29 05:23:17 +00:00
|
|
|
struct
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2014-02-09 23:29:13 +00:00
|
|
|
u16 PETokenEnable : 1;
|
|
|
|
u16 PEFinishEnable : 1;
|
|
|
|
u16 PEToken : 1; // write only
|
|
|
|
u16 PEFinish : 1; // write only
|
|
|
|
u16 : 12;
|
2010-06-09 01:37:08 +00:00
|
|
|
};
|
|
|
|
u16 Hex;
|
|
|
|
UPECtrlReg() { Hex = 0; }
|
|
|
|
UPECtrlReg(u16 _hex) { Hex = _hex; }
|
|
|
|
};
|
|
|
|
|
|
|
|
// STATE_TO_SAVE
|
2014-02-09 23:29:13 +00: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;
|
2016-08-10 07:44:08 +00:00
|
|
|
|
2016-09-01 15:28:48 +00:00
|
|
|
static std::mutex s_token_finish_mutex;
|
2016-08-10 07:44:08 +00:00
|
|
|
static u16 s_token;
|
|
|
|
static u16 s_token_pending;
|
|
|
|
static bool s_token_interrupt_pending;
|
|
|
|
static bool s_finish_interrupt_pending;
|
|
|
|
static bool s_event_raised;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2016-08-08 20:35:01 +00:00
|
|
|
static bool s_signal_token_interrupt;
|
|
|
|
static bool s_signal_finish_interrupt;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2016-09-01 10:54:18 +00:00
|
|
|
static CoreTiming::EventType* et_SetTokenFinishOnMainThread;
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2014-02-09 21:03:16 +00:00
|
|
|
INT_CAUSE_PE_TOKEN = 0x200, // GP Token
|
|
|
|
INT_CAUSE_PE_FINISH = 0x400, // GP Finished
|
2010-06-09 01:37:08 +00: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 23:57:39 +00:00
|
|
|
p.DoPOD(m_Control);
|
2016-08-10 07:44:08 +00:00
|
|
|
|
|
|
|
p.Do(s_token);
|
|
|
|
p.Do(s_token_pending);
|
|
|
|
p.Do(s_token_interrupt_pending);
|
|
|
|
p.Do(s_finish_interrupt_pending);
|
|
|
|
p.Do(s_event_raised);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-05-27 06:18:22 +00:00
|
|
|
p.Do(s_signal_token_interrupt);
|
|
|
|
p.Do(s_signal_finish_interrupt);
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2016-04-09 14:06:09 +00:00
|
|
|
static void UpdateInterrupts();
|
2016-08-10 07:44:08 +00:00
|
|
|
static void SetTokenFinish_OnMainThread(u64 userdata, s64 cyclesLate);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
m_Control.Hex = 0;
|
2012-01-02 10:20:22 +00:00
|
|
|
m_ZConf.Hex = 0;
|
|
|
|
m_AlphaConf.Hex = 0;
|
|
|
|
m_DstAlphaConf.Hex = 0;
|
|
|
|
m_AlphaModeConf.Hex = 0;
|
|
|
|
m_AlphaRead.Hex = 0;
|
2016-08-10 07:44:08 +00:00
|
|
|
|
|
|
|
s_token = 0;
|
|
|
|
s_token_pending = 0;
|
|
|
|
s_token_interrupt_pending = false;
|
|
|
|
s_finish_interrupt_pending = false;
|
|
|
|
s_event_raised = false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-08-08 20:35:01 +00:00
|
|
|
s_signal_token_interrupt = false;
|
|
|
|
s_signal_finish_interrupt = false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-08-11 19:14:39 +00:00
|
|
|
et_SetTokenFinishOnMainThread =
|
|
|
|
CoreTiming::RegisterEvent("SetTokenFinish", SetTokenFinish_OnMainThread);
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2014-02-02 15:08:09 +00:00
|
|
|
void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2014-02-02 15:08:09 +00: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-09 01:37:08 +00:00
|
|
|
{
|
2014-02-02 15:08:09 +00:00
|
|
|
mmio->Register(base | mapped_var.addr, MMIO::DirectRead<u16>(mapped_var.ptr),
|
|
|
|
MMIO::DirectWrite<u16>(mapped_var.ptr));
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-02-02 15:08:09 +00: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-09 01:37:08 +00:00
|
|
|
{
|
2014-02-02 15:08:09 +00: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>());
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-02-02 15:08:09 +00:00
|
|
|
// Control register
|
|
|
|
mmio->Register(base | PE_CTRL_REGISTER, MMIO::DirectRead<u16>(&m_Control.Hex),
|
|
|
|
MMIO::ComplexWrite<u16>([](u32, u16 val) {
|
|
|
|
UPECtrlReg tmpCtrl(val);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-05-27 06:18:22 +00:00
|
|
|
if (tmpCtrl.PEToken)
|
2016-08-08 20:35:01 +00:00
|
|
|
s_signal_token_interrupt = false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-05-27 06:18:22 +00:00
|
|
|
if (tmpCtrl.PEFinish)
|
2016-08-08 20:35:01 +00:00
|
|
|
s_signal_finish_interrupt = false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2010-06-09 01:37:08 +00:00
|
|
|
m_Control.PETokenEnable = tmpCtrl.PETokenEnable;
|
|
|
|
m_Control.PEFinishEnable = tmpCtrl.PEFinishEnable;
|
2014-02-17 04:51:41 +00:00
|
|
|
m_Control.PEToken = 0; // this flag is write only
|
|
|
|
m_Control.PEFinish = 0; // this flag is write only
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2020-11-14 03:33:26 +00:00
|
|
|
DEBUG_LOG_FMT(PIXELENGINE, "(w16) CTRL_REGISTER: {:#06x}", val);
|
2010-06-09 01:37:08 +00:00
|
|
|
UpdateInterrupts();
|
2014-02-02 15:08:09 +00:00
|
|
|
}));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-02-02 15:08:09 +00:00
|
|
|
// Token register, readonly.
|
2017-01-27 06:43:54 +00:00
|
|
|
mmio->Register(base | PE_TOKEN_REG, MMIO::DirectRead<u16>(&s_token), MMIO::InvalidWrite<u16>());
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-02-02 15:08:09 +00: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) {
|
2019-12-05 15:58:03 +00:00
|
|
|
BoundingBox::Disable();
|
2014-11-13 22:26:49 +00:00
|
|
|
return g_video_backend->Video_GetBoundingBox(i);
|
2014-02-02 15:08:09 +00:00
|
|
|
}),
|
|
|
|
MMIO::InvalidWrite<u16>());
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
2014-02-02 15:08:09 +00:00
|
|
|
}
|
2010-12-13 07:56:54 +00:00
|
|
|
|
2016-04-09 14:06:09 +00:00
|
|
|
static void UpdateInterrupts()
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
|
|
|
// check if there is a token-interrupt
|
2016-08-08 20:35:01 +00:00
|
|
|
ProcessorInterface::SetInterrupt(INT_CAUSE_PE_TOKEN,
|
|
|
|
s_signal_token_interrupt && m_Control.PETokenEnable);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2010-06-09 01:37:08 +00:00
|
|
|
// check if there is a finish-interrupt
|
2016-08-08 20:35:01 +00:00
|
|
|
ProcessorInterface::SetInterrupt(INT_CAUSE_PE_FINISH,
|
|
|
|
s_signal_finish_interrupt && m_Control.PEFinishEnable);
|
2010-12-13 07:56:54 +00:00
|
|
|
}
|
|
|
|
|
2016-08-10 07:44:08 +00:00
|
|
|
static void SetTokenFinish_OnMainThread(u64 userdata, s64 cyclesLate)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2016-08-10 07:44:08 +00:00
|
|
|
std::unique_lock<std::mutex> lk(s_token_finish_mutex);
|
|
|
|
s_event_raised = false;
|
|
|
|
|
|
|
|
s_token = s_token_pending;
|
|
|
|
|
|
|
|
if (s_token_interrupt_pending)
|
|
|
|
{
|
|
|
|
s_token_interrupt_pending = false;
|
|
|
|
s_signal_token_interrupt = true;
|
|
|
|
UpdateInterrupts();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s_finish_interrupt_pending)
|
|
|
|
{
|
|
|
|
s_finish_interrupt_pending = false;
|
|
|
|
s_signal_finish_interrupt = true;
|
|
|
|
UpdateInterrupts();
|
|
|
|
lk.unlock();
|
|
|
|
Core::FrameUpdateOnCPUThread();
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2016-08-10 07:44:08 +00:00
|
|
|
// Raise the event handler above on the CPU thread.
|
|
|
|
// s_token_finish_mutex must be locked.
|
|
|
|
// THIS IS EXECUTED FROM VIDEO THREAD
|
|
|
|
static void RaiseEvent()
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2016-08-10 07:44:08 +00:00
|
|
|
if (s_event_raised)
|
|
|
|
return;
|
2015-06-06 05:20:51 +00:00
|
|
|
|
2016-08-10 07:44:08 +00:00
|
|
|
s_event_raised = true;
|
2016-07-07 13:52:08 +00:00
|
|
|
|
|
|
|
CoreTiming::FromThread from = CoreTiming::FromThread::NON_CPU;
|
2016-08-10 07:44:08 +00:00
|
|
|
if (!SConfig::GetInstance().bCPUThread || Fifo::UseDeterministicGPUThread())
|
2016-07-07 13:52:08 +00:00
|
|
|
from = CoreTiming::FromThread::CPU;
|
|
|
|
CoreTiming::ScheduleEvent(0, et_SetTokenFinishOnMainThread, 0, from);
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetToken
|
|
|
|
// THIS IS EXECUTED FROM VIDEO THREAD
|
2016-08-10 07:44:08 +00:00
|
|
|
void SetToken(const u16 token, const bool interrupt)
|
2010-06-09 01:37:08 +00:00
|
|
|
{
|
2020-11-14 03:33:26 +00:00
|
|
|
DEBUG_LOG_FMT(PIXELENGINE, "VIDEO Backend raises INT_CAUSE_PE_TOKEN (btw, token: {:04x})", token);
|
2016-08-08 20:35:01 +00:00
|
|
|
|
2016-08-10 07:44:08 +00:00
|
|
|
std::lock_guard<std::mutex> lk(s_token_finish_mutex);
|
|
|
|
|
|
|
|
s_token_pending = token;
|
|
|
|
s_token_interrupt_pending |= interrupt;
|
|
|
|
|
|
|
|
RaiseEvent();
|
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()
|
|
|
|
{
|
2020-11-14 03:33:26 +00:00
|
|
|
DEBUG_LOG_FMT(PIXELENGINE, "VIDEO Set Finish");
|
2016-08-10 07:44:08 +00:00
|
|
|
|
|
|
|
std::lock_guard<std::mutex> lk(s_token_finish_mutex);
|
|
|
|
|
|
|
|
s_finish_interrupt_pending |= true;
|
|
|
|
|
|
|
|
RaiseEvent();
|
2010-06-09 01:37:08 +00:00
|
|
|
}
|
|
|
|
|
2014-02-15 02:23:35 +00:00
|
|
|
UPEAlphaReadReg GetAlphaReadMode()
|
|
|
|
{
|
|
|
|
return m_AlphaRead;
|
|
|
|
}
|
|
|
|
|
2010-06-09 01:37:08 +00:00
|
|
|
} // end of namespace PixelEngine
|