2018-04-26 02:11:26 +00:00
|
|
|
using Ryujinx.Graphics.Gal;
|
2018-09-08 17:51:50 +00:00
|
|
|
using Ryujinx.Graphics.Memory;
|
|
|
|
using Ryujinx.Graphics.Texture;
|
2018-10-27 18:46:17 +00:00
|
|
|
using System;
|
2018-04-26 02:11:26 +00:00
|
|
|
|
2018-09-08 17:51:50 +00:00
|
|
|
namespace Ryujinx.Graphics
|
2018-04-26 02:11:26 +00:00
|
|
|
{
|
2018-09-08 17:51:50 +00:00
|
|
|
public class NvGpuEngine2d : INvGpuEngine
|
2018-04-26 02:11:26 +00: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 18:53:23 +00:00
|
|
|
private NvGpu Gpu;
|
2018-04-26 02:11:26 +00: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 18:53:23 +00:00
|
|
|
public NvGpuEngine2d(NvGpu Gpu)
|
2018-04-26 02:11:26 +00:00
|
|
|
{
|
|
|
|
this.Gpu = Gpu;
|
|
|
|
|
2018-10-27 18:46:17 +00:00
|
|
|
Registers = new int[0x238];
|
2018-04-26 02:11:26 +00: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 18:53:23 +00:00
|
|
|
public void CallMethod(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
|
2018-04-26 02:11:26 +00:00
|
|
|
{
|
2018-10-27 18:46:17 +00:00
|
|
|
WriteRegister(PBEntry);
|
|
|
|
|
|
|
|
if ((NvGpuEngine2dReg)PBEntry.Method == NvGpuEngine2dReg.BlitSrcYInt)
|
2018-04-26 02:11:26 +00:00
|
|
|
{
|
2018-10-27 18:46:17 +00:00
|
|
|
TextureCopy(Vmm);
|
2018-04-26 02:11:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-27 18:46:17 +00:00
|
|
|
private void TextureCopy(NvGpuVmm Vmm)
|
2018-04-26 02:11:26 +00:00
|
|
|
{
|
|
|
|
CopyOperation Operation = (CopyOperation)ReadRegister(NvGpuEngine2dReg.CopyOperation);
|
|
|
|
|
2018-09-18 04:30:35 +00:00
|
|
|
int SrcFormat = ReadRegister(NvGpuEngine2dReg.SrcFormat);
|
2018-04-26 02:11:26 +00:00
|
|
|
bool SrcLinear = ReadRegister(NvGpuEngine2dReg.SrcLinear) != 0;
|
|
|
|
int SrcWidth = ReadRegister(NvGpuEngine2dReg.SrcWidth);
|
|
|
|
int SrcHeight = ReadRegister(NvGpuEngine2dReg.SrcHeight);
|
2018-07-19 05:30:21 +00:00
|
|
|
int SrcPitch = ReadRegister(NvGpuEngine2dReg.SrcPitch);
|
|
|
|
int SrcBlkDim = ReadRegister(NvGpuEngine2dReg.SrcBlockDimensions);
|
2018-04-26 02:11:26 +00:00
|
|
|
|
2018-09-18 04:30:35 +00:00
|
|
|
int DstFormat = ReadRegister(NvGpuEngine2dReg.DstFormat);
|
2018-04-26 02:11:26 +00:00
|
|
|
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);
|
|
|
|
|
2018-09-18 04:30:35 +00:00
|
|
|
GalImageFormat SrcImgFormat = ImageUtils.ConvertSurface((GalSurfaceFormat)SrcFormat);
|
|
|
|
GalImageFormat DstImgFormat = ImageUtils.ConvertSurface((GalSurfaceFormat)DstFormat);
|
2018-07-19 05:30:21 +00:00
|
|
|
|
2018-09-18 04:30:35 +00:00
|
|
|
GalMemoryLayout SrcLayout = GetLayout(SrcLinear);
|
|
|
|
GalMemoryLayout DstLayout = GetLayout(DstLinear);
|
2018-04-26 02:11:26 +00:00
|
|
|
|
2018-07-19 05:30:21 +00:00
|
|
|
int SrcBlockHeight = 1 << ((SrcBlkDim >> 4) & 0xf);
|
2018-04-26 02:11:26 +00:00
|
|
|
int DstBlockHeight = 1 << ((DstBlkDim >> 4) & 0xf);
|
|
|
|
|
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 18:53:23 +00:00
|
|
|
long SrcAddress = MakeInt64From2xInt32(NvGpuEngine2dReg.SrcAddress);
|
|
|
|
long DstAddress = MakeInt64From2xInt32(NvGpuEngine2dReg.DstAddress);
|
2018-04-26 02:11:26 +00:00
|
|
|
|
2018-07-19 05:30:21 +00:00
|
|
|
long SrcKey = Vmm.GetPhysicalAddress(SrcAddress);
|
|
|
|
long DstKey = Vmm.GetPhysicalAddress(DstAddress);
|
|
|
|
|
2018-09-18 04:30:35 +00:00
|
|
|
GalImage SrcTexture = new GalImage(
|
|
|
|
SrcWidth,
|
|
|
|
SrcHeight, 1,
|
|
|
|
SrcBlockHeight,
|
|
|
|
SrcLayout,
|
|
|
|
SrcImgFormat);
|
|
|
|
|
|
|
|
GalImage DstTexture = new GalImage(
|
|
|
|
DstWidth,
|
|
|
|
DstHeight, 1,
|
|
|
|
DstBlockHeight,
|
|
|
|
DstLayout,
|
|
|
|
DstImgFormat);
|
|
|
|
|
|
|
|
Gpu.ResourceManager.SendTexture(Vmm, SrcKey, SrcTexture);
|
|
|
|
Gpu.ResourceManager.SendTexture(Vmm, DstKey, DstTexture);
|
|
|
|
|
2018-10-27 18:46:17 +00:00
|
|
|
int Width = Math.Min(SrcWidth, DstWidth);
|
|
|
|
int Height = Math.Min(SrcHeight, DstHeight);
|
|
|
|
|
2018-09-18 04:30:35 +00:00
|
|
|
Gpu.Renderer.RenderTarget.Copy(
|
|
|
|
SrcKey,
|
|
|
|
DstKey,
|
|
|
|
0,
|
|
|
|
0,
|
2018-10-27 18:46:17 +00:00
|
|
|
Width,
|
|
|
|
Height,
|
2018-09-18 04:30:35 +00:00
|
|
|
0,
|
|
|
|
0,
|
2018-10-27 18:46:17 +00:00
|
|
|
Width,
|
|
|
|
Height);
|
2018-09-18 04:30:35 +00:00
|
|
|
}
|
2018-07-19 05:30:21 +00:00
|
|
|
|
2018-09-18 04:30:35 +00:00
|
|
|
private static GalMemoryLayout GetLayout(bool Linear)
|
|
|
|
{
|
|
|
|
return Linear
|
|
|
|
? GalMemoryLayout.Pitch
|
|
|
|
: GalMemoryLayout.BlockLinear;
|
2018-04-26 02:11:26 +00: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 18:53:23 +00:00
|
|
|
private void WriteRegister(NvGpuPBEntry PBEntry)
|
2018-04-26 02:11:26 +00: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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|