2018-04-26 04:11:26 +02:00
|
|
|
using Ryujinx.Graphics.Gal;
|
2018-06-24 02:39:25 +02:00
|
|
|
using Ryujinx.HLE.Gpu.Memory;
|
|
|
|
using Ryujinx.HLE.Gpu.Texture;
|
2018-04-26 04:11:26 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2018-06-24 02:39:25 +02:00
|
|
|
namespace Ryujinx.HLE.Gpu.Engines
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2018-06-09 02:15:56 +02:00
|
|
|
class NvGpuEngine2d : INvGpuEngine
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
|
|
|
private enum CopyOperation
|
|
|
|
{
|
|
|
|
SrcCopyAnd,
|
|
|
|
RopAnd,
|
|
|
|
Blend,
|
|
|
|
SrcCopy,
|
|
|
|
Rop,
|
|
|
|
SrcCopyPremult,
|
|
|
|
BlendPremult
|
|
|
|
}
|
|
|
|
|
|
|
|
public int[] Registers { get; private set; }
|
|
|
|
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 20:53:23 +02:00
|
|
|
private NvGpu Gpu;
|
2018-04-26 04:11:26 +02:00
|
|
|
|
|
|
|
private Dictionary<int, NvGpuMethod> Methods;
|
|
|
|
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 20:53:23 +02:00
|
|
|
public NvGpuEngine2d(NvGpu Gpu)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
|
|
|
this.Gpu = Gpu;
|
|
|
|
|
|
|
|
Registers = new int[0xe00];
|
|
|
|
|
|
|
|
Methods = new Dictionary<int, NvGpuMethod>();
|
|
|
|
|
|
|
|
void AddMethod(int Meth, int Count, int Stride, NvGpuMethod Method)
|
|
|
|
{
|
|
|
|
while (Count-- > 0)
|
|
|
|
{
|
|
|
|
Methods.Add(Meth, Method);
|
|
|
|
|
|
|
|
Meth += Stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddMethod(0xb5, 1, 1, TextureCopy);
|
|
|
|
}
|
|
|
|
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 20:53:23 +02:00
|
|
|
public void CallMethod(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
|
|
|
if (Methods.TryGetValue(PBEntry.Method, out NvGpuMethod Method))
|
|
|
|
{
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 20:53:23 +02:00
|
|
|
Method(Vmm, PBEntry);
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WriteRegister(PBEntry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 20:53:23 +02:00
|
|
|
private void TextureCopy(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
|
|
|
CopyOperation Operation = (CopyOperation)ReadRegister(NvGpuEngine2dReg.CopyOperation);
|
|
|
|
|
|
|
|
bool SrcLinear = ReadRegister(NvGpuEngine2dReg.SrcLinear) != 0;
|
|
|
|
int SrcWidth = ReadRegister(NvGpuEngine2dReg.SrcWidth);
|
|
|
|
int SrcHeight = ReadRegister(NvGpuEngine2dReg.SrcHeight);
|
|
|
|
|
|
|
|
bool DstLinear = ReadRegister(NvGpuEngine2dReg.DstLinear) != 0;
|
|
|
|
int DstWidth = ReadRegister(NvGpuEngine2dReg.DstWidth);
|
|
|
|
int DstHeight = ReadRegister(NvGpuEngine2dReg.DstHeight);
|
|
|
|
int DstPitch = ReadRegister(NvGpuEngine2dReg.DstPitch);
|
|
|
|
int DstBlkDim = ReadRegister(NvGpuEngine2dReg.DstBlockDimensions);
|
|
|
|
|
|
|
|
TextureSwizzle DstSwizzle = DstLinear
|
|
|
|
? TextureSwizzle.Pitch
|
|
|
|
: TextureSwizzle.BlockLinear;
|
|
|
|
|
|
|
|
int DstBlockHeight = 1 << ((DstBlkDim >> 4) & 0xf);
|
|
|
|
|
2018-06-24 02:39:25 +02:00
|
|
|
long Key = Vmm.GetPhysicalAddress(MakeInt64From2xInt32(NvGpuEngine2dReg.SrcAddress));
|
2018-04-26 04:11:26 +02:00
|
|
|
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 20:53:23 +02:00
|
|
|
long SrcAddress = MakeInt64From2xInt32(NvGpuEngine2dReg.SrcAddress);
|
|
|
|
long DstAddress = MakeInt64From2xInt32(NvGpuEngine2dReg.DstAddress);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-06-24 02:39:25 +02:00
|
|
|
bool IsFbTexture = Gpu.Engine3d.IsFrameBufferPosition(Key);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
|
|
|
if (IsFbTexture && DstLinear)
|
|
|
|
{
|
|
|
|
DstSwizzle = TextureSwizzle.BlockLinear;
|
|
|
|
}
|
|
|
|
|
2018-06-24 02:39:25 +02:00
|
|
|
TextureInfo DstTexture = new TextureInfo(
|
2018-04-26 04:11:26 +02:00
|
|
|
DstAddress,
|
|
|
|
DstWidth,
|
|
|
|
DstHeight,
|
|
|
|
DstBlockHeight,
|
|
|
|
DstBlockHeight,
|
|
|
|
DstSwizzle,
|
|
|
|
GalTextureFormat.A8B8G8R8);
|
|
|
|
|
|
|
|
if (IsFbTexture)
|
|
|
|
{
|
2018-06-09 05:46:06 +02:00
|
|
|
//TODO: Change this when the correct frame buffer resolution is used.
|
|
|
|
//Currently, the frame buffer size is hardcoded to 1280x720.
|
|
|
|
SrcWidth = 1280;
|
|
|
|
SrcHeight = 720;
|
|
|
|
|
2018-06-24 02:39:25 +02:00
|
|
|
Gpu.Renderer.FrameBuffer.GetBufferData(Key, (byte[] Buffer) =>
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2018-06-09 05:46:06 +02:00
|
|
|
CopyTexture(
|
|
|
|
Vmm,
|
|
|
|
DstTexture,
|
|
|
|
Buffer,
|
|
|
|
SrcWidth,
|
|
|
|
SrcHeight);
|
2018-04-26 04:11:26 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
long Size = SrcWidth * SrcHeight * 4;
|
|
|
|
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 20:53:23 +02:00
|
|
|
byte[] Buffer = Vmm.ReadBytes(SrcAddress, Size);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-06-09 05:46:06 +02:00
|
|
|
CopyTexture(
|
|
|
|
Vmm,
|
|
|
|
DstTexture,
|
|
|
|
Buffer,
|
|
|
|
SrcWidth,
|
|
|
|
SrcHeight);
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-09 05:46:06 +02:00
|
|
|
private void CopyTexture(
|
2018-06-24 02:39:25 +02:00
|
|
|
NvGpuVmm Vmm,
|
|
|
|
TextureInfo Texture,
|
|
|
|
byte[] Buffer,
|
|
|
|
int Width,
|
|
|
|
int Height)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2018-06-09 05:46:06 +02:00
|
|
|
TextureWriter.Write(Vmm, Texture, Buffer, Width, Height);
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private long MakeInt64From2xInt32(NvGpuEngine2dReg Reg)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
(long)Registers[(int)Reg + 0] << 32 |
|
|
|
|
(uint)Registers[(int)Reg + 1];
|
|
|
|
}
|
|
|
|
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 20:53:23 +02:00
|
|
|
private void WriteRegister(NvGpuPBEntry PBEntry)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
|
|
|
int ArgsCount = PBEntry.Arguments.Count;
|
|
|
|
|
|
|
|
if (ArgsCount > 0)
|
|
|
|
{
|
|
|
|
Registers[PBEntry.Method] = PBEntry.Arguments[ArgsCount - 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private int ReadRegister(NvGpuEngine2dReg Reg)
|
|
|
|
{
|
|
|
|
return Registers[(int)Reg];
|
|
|
|
}
|
|
|
|
|
|
|
|
private void WriteRegister(NvGpuEngine2dReg Reg, int Value)
|
|
|
|
{
|
|
|
|
Registers[(int)Reg] = Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|