2018-04-26 04:11:26 +02:00
|
|
|
using Ryujinx.Graphics.Gal;
|
2018-09-08 19:51:50 +02:00
|
|
|
using Ryujinx.Graphics.Memory;
|
|
|
|
using Ryujinx.Graphics.Texture;
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
namespace Ryujinx.Graphics
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2018-11-17 05:01:31 +01: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
|
|
|
|
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;
|
|
|
|
|
2018-10-27 20:46:17 +02:00
|
|
|
Registers = new int[0x238];
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
public void CallMethod(NvGpuVmm Vmm, GpuMethodCall MethCall)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2018-11-17 05:01:31 +01:00
|
|
|
WriteRegister(MethCall);
|
2018-10-27 20:46:17 +02:00
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
if ((NvGpuEngine2dReg)MethCall.Method == NvGpuEngine2dReg.BlitSrcYInt)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2018-10-27 20:46:17 +02:00
|
|
|
TextureCopy(Vmm);
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-27 20:46:17 +02:00
|
|
|
private void TextureCopy(NvGpuVmm Vmm)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
|
|
|
CopyOperation Operation = (CopyOperation)ReadRegister(NvGpuEngine2dReg.CopyOperation);
|
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
int DstFormat = ReadRegister(NvGpuEngine2dReg.DstFormat);
|
|
|
|
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 06:30:35 +02:00
|
|
|
int SrcFormat = ReadRegister(NvGpuEngine2dReg.SrcFormat);
|
2018-04-26 04:11:26 +02:00
|
|
|
bool SrcLinear = ReadRegister(NvGpuEngine2dReg.SrcLinear) != 0;
|
|
|
|
int SrcWidth = ReadRegister(NvGpuEngine2dReg.SrcWidth);
|
|
|
|
int SrcHeight = ReadRegister(NvGpuEngine2dReg.SrcHeight);
|
2018-07-19 07:30:21 +02:00
|
|
|
int SrcPitch = ReadRegister(NvGpuEngine2dReg.SrcPitch);
|
|
|
|
int SrcBlkDim = ReadRegister(NvGpuEngine2dReg.SrcBlockDimensions);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
int DstBlitX = ReadRegister(NvGpuEngine2dReg.BlitDstX);
|
|
|
|
int DstBlitY = ReadRegister(NvGpuEngine2dReg.BlitDstY);
|
|
|
|
int DstBlitW = ReadRegister(NvGpuEngine2dReg.BlitDstW);
|
|
|
|
int DstBlitH = ReadRegister(NvGpuEngine2dReg.BlitDstH);
|
|
|
|
|
2018-11-29 00:09:44 +01:00
|
|
|
long BlitDuDx = ReadRegisterFixed1_31_32(NvGpuEngine2dReg.BlitDuDxFract);
|
|
|
|
long BlitDvDy = ReadRegisterFixed1_31_32(NvGpuEngine2dReg.BlitDvDyFract);
|
|
|
|
|
|
|
|
long SrcBlitX = ReadRegisterFixed1_31_32(NvGpuEngine2dReg.BlitSrcXFract);
|
|
|
|
long SrcBlitY = ReadRegisterFixed1_31_32(NvGpuEngine2dReg.BlitSrcYFract);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
GalImageFormat SrcImgFormat = ImageUtils.ConvertSurface((GalSurfaceFormat)SrcFormat);
|
|
|
|
GalImageFormat DstImgFormat = ImageUtils.ConvertSurface((GalSurfaceFormat)DstFormat);
|
2018-07-19 07:30:21 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
GalMemoryLayout SrcLayout = GetLayout(SrcLinear);
|
|
|
|
GalMemoryLayout DstLayout = GetLayout(DstLinear);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-07-19 07:30:21 +02:00
|
|
|
int SrcBlockHeight = 1 << ((SrcBlkDim >> 4) & 0xf);
|
2018-04-26 04:11:26 +02: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 20:53:23 +02:00
|
|
|
long SrcAddress = MakeInt64From2xInt32(NvGpuEngine2dReg.SrcAddress);
|
|
|
|
long DstAddress = MakeInt64From2xInt32(NvGpuEngine2dReg.DstAddress);
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-07-19 07:30:21 +02:00
|
|
|
long SrcKey = Vmm.GetPhysicalAddress(SrcAddress);
|
|
|
|
long DstKey = Vmm.GetPhysicalAddress(DstAddress);
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
GalImage SrcTexture = new GalImage(
|
|
|
|
SrcWidth,
|
|
|
|
SrcHeight, 1,
|
|
|
|
SrcBlockHeight,
|
|
|
|
SrcLayout,
|
|
|
|
SrcImgFormat);
|
|
|
|
|
|
|
|
GalImage DstTexture = new GalImage(
|
|
|
|
DstWidth,
|
|
|
|
DstHeight, 1,
|
|
|
|
DstBlockHeight,
|
|
|
|
DstLayout,
|
|
|
|
DstImgFormat);
|
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
SrcTexture.Pitch = SrcPitch;
|
|
|
|
DstTexture.Pitch = DstPitch;
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
Gpu.ResourceManager.SendTexture(Vmm, SrcKey, SrcTexture);
|
|
|
|
Gpu.ResourceManager.SendTexture(Vmm, DstKey, DstTexture);
|
|
|
|
|
2018-11-29 00:09:44 +01:00
|
|
|
int SrcBlitX1 = (int)(SrcBlitX >> 32);
|
|
|
|
int SrcBlitY1 = (int)(SrcBlitY >> 32);
|
|
|
|
|
|
|
|
int SrcBlitX2 = (int)(SrcBlitX + DstBlitW * BlitDuDx >> 32);
|
|
|
|
int SrcBlitY2 = (int)(SrcBlitY + DstBlitH * BlitDvDy >> 32);
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
Gpu.Renderer.RenderTarget.Copy(
|
|
|
|
SrcKey,
|
|
|
|
DstKey,
|
2018-11-29 00:09:44 +01:00
|
|
|
SrcBlitX1,
|
|
|
|
SrcBlitY1,
|
|
|
|
SrcBlitX2,
|
|
|
|
SrcBlitY2,
|
2018-11-17 05:01:31 +01:00
|
|
|
DstBlitX,
|
|
|
|
DstBlitY,
|
|
|
|
DstBlitX + DstBlitW,
|
|
|
|
DstBlitY + DstBlitH);
|
|
|
|
|
|
|
|
//Do a guest side copy aswell. This is necessary when
|
|
|
|
//the texture is modified by the guest, however it doesn't
|
|
|
|
//work when resources that the gpu can write to are copied,
|
|
|
|
//like framebuffers.
|
|
|
|
ImageUtils.CopyTexture(
|
|
|
|
Vmm,
|
|
|
|
SrcTexture,
|
|
|
|
DstTexture,
|
|
|
|
SrcAddress,
|
|
|
|
DstAddress,
|
2018-11-29 00:09:44 +01:00
|
|
|
SrcBlitX1,
|
|
|
|
SrcBlitY1,
|
2018-11-17 05:01:31 +01:00
|
|
|
DstBlitX,
|
|
|
|
DstBlitY,
|
|
|
|
DstBlitW,
|
|
|
|
DstBlitH);
|
|
|
|
|
|
|
|
Vmm.IsRegionModified(DstKey, ImageUtils.GetSize(DstTexture), NvGpuBufferType.Texture);
|
2018-09-18 06:30:35 +02:00
|
|
|
}
|
2018-07-19 07:30:21 +02:00
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
private static GalMemoryLayout GetLayout(bool Linear)
|
|
|
|
{
|
|
|
|
return Linear
|
|
|
|
? GalMemoryLayout.Pitch
|
|
|
|
: GalMemoryLayout.BlockLinear;
|
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];
|
|
|
|
}
|
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
private void WriteRegister(GpuMethodCall MethCall)
|
2018-04-26 04:11:26 +02:00
|
|
|
{
|
2018-11-17 05:01:31 +01:00
|
|
|
Registers[MethCall.Method] = MethCall.Argument;
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
|
|
|
|
2018-11-29 00:09:44 +01:00
|
|
|
private long ReadRegisterFixed1_31_32(NvGpuEngine2dReg Reg)
|
|
|
|
{
|
|
|
|
long Low = (uint)ReadRegister(Reg + 0);
|
|
|
|
long High = (uint)ReadRegister(Reg + 1);
|
|
|
|
|
|
|
|
return Low | (High << 32);
|
|
|
|
}
|
|
|
|
|
2018-04-26 04:11:26 +02:00
|
|
|
private int ReadRegister(NvGpuEngine2dReg Reg)
|
|
|
|
{
|
|
|
|
return Registers[(int)Reg];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|