2019-02-28 02:12:24 +01:00
|
|
|
using Ryujinx.Common.Logging;
|
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-12-03 03:38:47 +01:00
|
|
|
namespace Ryujinx.Graphics.Graphics3d
|
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);
|
2019-02-28 02:12:24 +01:00
|
|
|
int DstDepth = ReadRegister(NvGpuEngine2dReg.DstDepth);
|
|
|
|
int DstLayer = ReadRegister(NvGpuEngine2dReg.DstLayer);
|
2018-11-17 05:01:31 +01:00
|
|
|
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);
|
2019-02-28 02:12:24 +01:00
|
|
|
int SrcDepth = ReadRegister(NvGpuEngine2dReg.SrcDepth);
|
|
|
|
int SrcLayer = ReadRegister(NvGpuEngine2dReg.SrcLayer);
|
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);
|
|
|
|
|
2019-02-28 02:12:24 +01:00
|
|
|
bool IsSrcLayered = false;
|
|
|
|
bool IsDstLayered = false;
|
|
|
|
|
|
|
|
GalTextureTarget SrcTarget = GalTextureTarget.TwoD;
|
|
|
|
|
|
|
|
if (SrcDepth != 0)
|
|
|
|
{
|
|
|
|
SrcTarget = GalTextureTarget.TwoDArray;
|
|
|
|
SrcDepth++;
|
|
|
|
IsSrcLayered = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SrcDepth = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
GalTextureTarget DstTarget = GalTextureTarget.TwoD;
|
|
|
|
|
|
|
|
if (DstDepth != 0)
|
|
|
|
{
|
|
|
|
DstTarget = GalTextureTarget.TwoDArray;
|
|
|
|
DstDepth++;
|
|
|
|
IsDstLayered = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DstDepth = 1;
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
GalImage SrcTexture = new GalImage(
|
|
|
|
SrcWidth,
|
2019-02-28 02:12:24 +01:00
|
|
|
SrcHeight,
|
|
|
|
1, SrcDepth, 1,
|
|
|
|
SrcBlockHeight, 1,
|
2018-09-18 06:30:35 +02:00
|
|
|
SrcLayout,
|
2019-02-28 02:12:24 +01:00
|
|
|
SrcImgFormat,
|
|
|
|
SrcTarget);
|
2018-09-18 06:30:35 +02:00
|
|
|
|
|
|
|
GalImage DstTexture = new GalImage(
|
|
|
|
DstWidth,
|
2019-02-28 02:12:24 +01:00
|
|
|
DstHeight,
|
|
|
|
1, DstDepth, 1,
|
|
|
|
DstBlockHeight, 1,
|
2018-09-18 06:30:35 +02:00
|
|
|
DstLayout,
|
2019-02-28 02:12:24 +01:00
|
|
|
DstImgFormat,
|
|
|
|
DstTarget);
|
2018-09-18 06:30:35 +02:00
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
SrcTexture.Pitch = SrcPitch;
|
|
|
|
DstTexture.Pitch = DstPitch;
|
|
|
|
|
2019-02-28 02:12:24 +01:00
|
|
|
long GetLayerOffset(GalImage Image, int Layer)
|
|
|
|
{
|
|
|
|
int TargetMipLevel = Image.MaxMipmapLevel <= 1 ? 1 : Image.MaxMipmapLevel - 1;
|
|
|
|
return ImageUtils.GetLayerOffset(Image, TargetMipLevel) * Layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SrcLayerIndex = -1;
|
|
|
|
|
|
|
|
if (IsSrcLayered && Gpu.ResourceManager.TryGetTextureLayer(SrcKey, out SrcLayerIndex) && SrcLayerIndex != 0)
|
|
|
|
{
|
|
|
|
SrcKey = SrcKey - GetLayerOffset(SrcTexture, SrcLayerIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
int DstLayerIndex = -1;
|
|
|
|
|
|
|
|
if (IsDstLayered && Gpu.ResourceManager.TryGetTextureLayer(DstKey, out DstLayerIndex) && DstLayerIndex != 0)
|
|
|
|
{
|
|
|
|
DstKey = DstKey - GetLayerOffset(DstTexture, DstLayerIndex);
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
Gpu.ResourceManager.SendTexture(Vmm, SrcKey, SrcTexture);
|
|
|
|
Gpu.ResourceManager.SendTexture(Vmm, DstKey, DstTexture);
|
|
|
|
|
2019-02-28 02:12:24 +01:00
|
|
|
if (IsSrcLayered && SrcLayerIndex == -1)
|
|
|
|
{
|
|
|
|
for (int Layer = 0; Layer < SrcTexture.LayerCount; Layer++)
|
|
|
|
{
|
|
|
|
Gpu.ResourceManager.SetTextureArrayLayer(SrcKey + GetLayerOffset(SrcTexture, Layer), Layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
SrcLayerIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsDstLayered && DstLayerIndex == -1)
|
|
|
|
{
|
|
|
|
for (int Layer = 0; Layer < DstTexture.LayerCount; Layer++)
|
|
|
|
{
|
|
|
|
Gpu.ResourceManager.SetTextureArrayLayer(DstKey + GetLayerOffset(DstTexture, Layer), Layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
DstLayerIndex = 0;
|
|
|
|
}
|
|
|
|
|
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(
|
2019-02-28 02:12:24 +01:00
|
|
|
SrcTexture,
|
|
|
|
DstTexture,
|
2018-09-18 06:30:35 +02:00
|
|
|
SrcKey,
|
|
|
|
DstKey,
|
2019-02-28 02:12:24 +01:00
|
|
|
SrcLayerIndex,
|
|
|
|
DstLayerIndex,
|
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.
|
2019-02-28 02:12:24 +01:00
|
|
|
|
|
|
|
// FIXME: SUPPORT MULTILAYER CORRECTLY HERE (this will cause weird stuffs on the first layer)
|
2018-11-17 05:01:31 +01:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|