2018-04-08 12:17:35 -07:00
|
|
|
using Ryujinx.Graphics.Gal;
|
2018-06-23 17:39:25 -07:00
|
|
|
using Ryujinx.HLE.Gpu.Memory;
|
|
|
|
using Ryujinx.HLE.Gpu.Texture;
|
2018-04-08 12:17:35 -07:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2018-06-23 17:39:25 -07:00
|
|
|
namespace Ryujinx.HLE.Gpu.Engines
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-06-08 17:15:56 -07:00
|
|
|
class NvGpuEngine3d : INvGpuEngine
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
|
|
|
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 11:53:23 -07:00
|
|
|
private NvGpu Gpu;
|
2018-04-08 12:17:35 -07:00
|
|
|
|
|
|
|
private Dictionary<int, NvGpuMethod> Methods;
|
|
|
|
|
|
|
|
private struct ConstBuffer
|
|
|
|
{
|
|
|
|
public bool Enabled;
|
|
|
|
public long Position;
|
|
|
|
public int Size;
|
|
|
|
}
|
|
|
|
|
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 11:53:23 -07:00
|
|
|
private ConstBuffer[][] ConstBuffers;
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-04-13 11:12:58 -07:00
|
|
|
private HashSet<long> FrameBuffers;
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-07-28 21:39:15 -07:00
|
|
|
private List<long>[] UploadedKeys;
|
|
|
|
|
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 11:53:23 -07:00
|
|
|
public NvGpuEngine3d(NvGpu Gpu)
|
2018-04-08 12:17:35 -07: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(0x585, 1, 1, VertexEndGl);
|
|
|
|
AddMethod(0x674, 1, 1, ClearBuffers);
|
|
|
|
AddMethod(0x6c3, 1, 1, QueryControl);
|
|
|
|
AddMethod(0x8e4, 16, 1, CbData);
|
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 11:53:23 -07:00
|
|
|
AddMethod(0x904, 5, 8, CbBind);
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
ConstBuffers = new ConstBuffer[6][];
|
|
|
|
|
|
|
|
for (int Index = 0; Index < ConstBuffers.Length; Index++)
|
|
|
|
{
|
|
|
|
ConstBuffers[Index] = new ConstBuffer[18];
|
|
|
|
}
|
2018-04-13 11:12:58 -07:00
|
|
|
|
|
|
|
FrameBuffers = new HashSet<long>();
|
2018-07-28 21:39:15 -07:00
|
|
|
|
|
|
|
UploadedKeys = new List<long>[(int)NvGpuBufferType.Count];
|
|
|
|
|
|
|
|
for (int i = 0; i < UploadedKeys.Length; i++)
|
|
|
|
{
|
|
|
|
UploadedKeys[i] = new List<long>();
|
|
|
|
}
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
public void CallMethod(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
Method(Vmm, PBEntry);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WriteRegister(PBEntry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-14 18:27:05 -07:00
|
|
|
public void ResetCache()
|
|
|
|
{
|
|
|
|
foreach (List<long> Uploaded in UploadedKeys)
|
|
|
|
{
|
|
|
|
Uploaded.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 11:53:23 -07:00
|
|
|
private void VertexEndGl(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-07-09 19:01:59 -07:00
|
|
|
LockCaches();
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
GalPipelineState State = new GalPipelineState();
|
|
|
|
|
|
|
|
SetFlip(State);
|
|
|
|
SetFrontFace(State);
|
|
|
|
SetCullFace(State);
|
|
|
|
SetDepth(State);
|
|
|
|
SetStencil(State);
|
|
|
|
SetAlphaBlending(State);
|
|
|
|
SetPrimitiveRestart(State);
|
|
|
|
|
2018-08-22 22:07:23 -07:00
|
|
|
for (int FbIndex = 0; FbIndex < 8; FbIndex++)
|
|
|
|
{
|
|
|
|
SetFrameBuffer(Vmm, 0);
|
|
|
|
}
|
|
|
|
|
2018-08-19 18:25:26 -07:00
|
|
|
SetZeta(Vmm);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-08-22 22:07:23 -07:00
|
|
|
SetRenderTargets();
|
|
|
|
|
2018-06-23 17:39:25 -07:00
|
|
|
long[] Keys = UploadShaders(Vmm);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-06-23 17:39:25 -07:00
|
|
|
Gpu.Renderer.Shader.BindProgram();
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
UploadTextures(Vmm, State, Keys);
|
2018-08-15 11:59:51 -07:00
|
|
|
UploadConstBuffers(Vmm, State, Keys);
|
2018-08-09 21:09:40 -07:00
|
|
|
UploadVertexArrays(Vmm, State);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
DispatchRender(Vmm, State);
|
2018-07-09 19:01:59 -07:00
|
|
|
|
|
|
|
UnlockCaches();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void LockCaches()
|
|
|
|
{
|
2018-08-09 21:09:40 -07:00
|
|
|
Gpu.Renderer.Buffer.LockCache();
|
2018-07-09 19:01:59 -07:00
|
|
|
Gpu.Renderer.Rasterizer.LockCaches();
|
|
|
|
Gpu.Renderer.Texture.LockCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UnlockCaches()
|
|
|
|
{
|
2018-08-09 21:09:40 -07:00
|
|
|
Gpu.Renderer.Buffer.UnlockCache();
|
2018-07-09 19:01:59 -07:00
|
|
|
Gpu.Renderer.Rasterizer.UnlockCaches();
|
|
|
|
Gpu.Renderer.Texture.UnlockCache();
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
private void ClearBuffers(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
|
|
|
int Arg0 = PBEntry.Arguments[0];
|
|
|
|
|
|
|
|
int FbIndex = (Arg0 >> 6) & 0xf;
|
|
|
|
|
|
|
|
GalClearBufferFlags Flags = (GalClearBufferFlags)(Arg0 & 0x3f);
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
float Red = ReadRegisterFloat(NvGpuEngine3dReg.ClearNColor + 0);
|
|
|
|
float Green = ReadRegisterFloat(NvGpuEngine3dReg.ClearNColor + 1);
|
|
|
|
float Blue = ReadRegisterFloat(NvGpuEngine3dReg.ClearNColor + 2);
|
|
|
|
float Alpha = ReadRegisterFloat(NvGpuEngine3dReg.ClearNColor + 3);
|
|
|
|
|
|
|
|
float Depth = ReadRegisterFloat(NvGpuEngine3dReg.ClearDepth);
|
|
|
|
|
|
|
|
int Stencil = ReadRegister(NvGpuEngine3dReg.ClearStencil);
|
|
|
|
|
2018-06-27 20:11:49 -07:00
|
|
|
SetFrameBuffer(Vmm, FbIndex);
|
2018-08-19 18:25:26 -07:00
|
|
|
SetZeta(Vmm);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
Gpu.Renderer.Rasterizer.ClearBuffers(
|
|
|
|
Flags,
|
2018-08-19 18:25:26 -07:00
|
|
|
FbIndex,
|
2018-08-09 21:09:40 -07:00
|
|
|
Red, Green, Blue, Alpha,
|
|
|
|
Depth,
|
|
|
|
Stencil);
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
private void SetFrameBuffer(NvGpuVmm Vmm, int FbIndex)
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
long VA = MakeInt64From2xInt32(NvGpuEngine3dReg.FrameBufferNAddress + FbIndex * 0x10);
|
2018-04-13 11:12:58 -07:00
|
|
|
|
2018-08-19 18:25:26 -07:00
|
|
|
int Format = ReadRegister(NvGpuEngine3dReg.FrameBufferNFormat + FbIndex * 0x10);
|
|
|
|
|
|
|
|
if (VA == 0 || Format == 0)
|
|
|
|
{
|
|
|
|
Gpu.Renderer.FrameBuffer.UnbindColor(FbIndex);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-27 20:11:49 -07:00
|
|
|
long Key = Vmm.GetPhysicalAddress(VA);
|
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 11:53:23 -07:00
|
|
|
|
2018-06-27 20:11:49 -07:00
|
|
|
FrameBuffers.Add(Key);
|
2018-04-13 11:12:58 -07:00
|
|
|
|
|
|
|
int Width = ReadRegister(NvGpuEngine3dReg.FrameBufferNWidth + FbIndex * 0x10);
|
|
|
|
int Height = ReadRegister(NvGpuEngine3dReg.FrameBufferNHeight + FbIndex * 0x10);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-08-19 18:25:26 -07:00
|
|
|
float TX = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateX + FbIndex * 8);
|
|
|
|
float TY = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateY + FbIndex * 8);
|
2018-07-18 22:30:21 -07:00
|
|
|
|
2018-08-19 18:25:26 -07:00
|
|
|
float SX = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleX + FbIndex * 8);
|
|
|
|
float SY = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleY + FbIndex * 8);
|
2018-07-18 22:30:21 -07:00
|
|
|
|
|
|
|
int VpX = (int)MathF.Max(0, TX - MathF.Abs(SX));
|
|
|
|
int VpY = (int)MathF.Max(0, TY - MathF.Abs(SY));
|
|
|
|
|
|
|
|
int VpW = (int)(TX + MathF.Abs(SX)) - VpX;
|
|
|
|
int VpH = (int)(TY + MathF.Abs(SY)) - VpY;
|
|
|
|
|
2018-08-19 18:25:26 -07:00
|
|
|
GalImageFormat ImageFormat = ImageFormatConverter.ConvertFrameBuffer((GalFrameBufferFormat)Format);
|
|
|
|
|
|
|
|
GalImage Image = new GalImage(Width, Height, ImageFormat);
|
|
|
|
|
|
|
|
long Size = TextureHelper.GetTextureSize(Image);
|
|
|
|
|
|
|
|
Gpu.Renderer.Texture.CreateFb(Key, Size, Image);
|
|
|
|
Gpu.Renderer.FrameBuffer.BindColor(Key, FbIndex);
|
2018-07-18 22:30:21 -07:00
|
|
|
|
|
|
|
Gpu.Renderer.FrameBuffer.SetViewport(VpX, VpY, VpW, VpH);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-08-19 18:25:26 -07:00
|
|
|
private void SetZeta(NvGpuVmm Vmm)
|
|
|
|
{
|
|
|
|
long ZA = MakeInt64From2xInt32(NvGpuEngine3dReg.ZetaAddress);
|
|
|
|
|
|
|
|
int Format = ReadRegister(NvGpuEngine3dReg.ZetaFormat);
|
|
|
|
|
|
|
|
bool ZetaEnable = (ReadRegister(NvGpuEngine3dReg.ZetaEnable) & 1) != 0;
|
|
|
|
|
|
|
|
if (ZA == 0 || Format == 0 || !ZetaEnable)
|
|
|
|
{
|
|
|
|
Gpu.Renderer.FrameBuffer.UnbindZeta();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
long Key = Vmm.GetPhysicalAddress(ZA);
|
|
|
|
|
|
|
|
int Width = ReadRegister(NvGpuEngine3dReg.ZetaHoriz);
|
|
|
|
int Height = ReadRegister(NvGpuEngine3dReg.ZetaVert);
|
|
|
|
|
|
|
|
GalImageFormat ImageFormat = ImageFormatConverter.ConvertZeta((GalZetaFormat)Format);
|
|
|
|
|
|
|
|
GalImage Image = new GalImage(Width, Height, ImageFormat);
|
|
|
|
|
|
|
|
long Size = TextureHelper.GetTextureSize(Image);
|
|
|
|
|
|
|
|
Gpu.Renderer.Texture.CreateFb(Key, Size, Image);
|
|
|
|
Gpu.Renderer.FrameBuffer.BindZeta(Key);
|
|
|
|
}
|
|
|
|
|
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 11:53:23 -07:00
|
|
|
private long[] UploadShaders(NvGpuVmm Vmm)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-06-23 17:39:25 -07:00
|
|
|
long[] Keys = new long[5];
|
2018-04-08 12:17:35 -07:00
|
|
|
|
|
|
|
long BasePosition = MakeInt64From2xInt32(NvGpuEngine3dReg.ShaderAddress);
|
|
|
|
|
2018-06-27 19:55:08 -07:00
|
|
|
int Index = 1;
|
|
|
|
|
|
|
|
int VpAControl = ReadRegister(NvGpuEngine3dReg.ShaderNControl);
|
|
|
|
|
|
|
|
bool VpAEnable = (VpAControl & 1) != 0;
|
|
|
|
|
|
|
|
if (VpAEnable)
|
|
|
|
{
|
|
|
|
//Note: The maxwell supports 2 vertex programs, usually
|
|
|
|
//only VP B is used, but in some cases VP A is also used.
|
|
|
|
//In this case, it seems to function as an extra vertex
|
|
|
|
//shader stage.
|
|
|
|
//The graphics abstraction layer has a special overload for this
|
|
|
|
//case, which should merge the two shaders into one vertex shader.
|
|
|
|
int VpAOffset = ReadRegister(NvGpuEngine3dReg.ShaderNOffset);
|
|
|
|
int VpBOffset = ReadRegister(NvGpuEngine3dReg.ShaderNOffset + 0x10);
|
|
|
|
|
|
|
|
long VpAPos = BasePosition + (uint)VpAOffset;
|
|
|
|
long VpBPos = BasePosition + (uint)VpBOffset;
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
Keys[(int)GalShaderType.Vertex] = VpBPos;
|
|
|
|
|
2018-06-27 19:55:08 -07:00
|
|
|
Gpu.Renderer.Shader.Create(Vmm, VpAPos, VpBPos, GalShaderType.Vertex);
|
|
|
|
Gpu.Renderer.Shader.Bind(VpBPos);
|
|
|
|
|
|
|
|
Index = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; Index < 6; Index++)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-07-14 09:08:39 -07:00
|
|
|
GalShaderType Type = GetTypeFromProgram(Index);
|
|
|
|
|
2018-04-08 12:17:35 -07:00
|
|
|
int Control = ReadRegister(NvGpuEngine3dReg.ShaderNControl + Index * 0x10);
|
|
|
|
int Offset = ReadRegister(NvGpuEngine3dReg.ShaderNOffset + Index * 0x10);
|
|
|
|
|
|
|
|
//Note: Vertex Program (B) is always enabled.
|
|
|
|
bool Enable = (Control & 1) != 0 || Index == 1;
|
|
|
|
|
|
|
|
if (!Enable)
|
|
|
|
{
|
2018-07-14 09:08:39 -07:00
|
|
|
Gpu.Renderer.Shader.Unbind(Type);
|
|
|
|
|
2018-04-08 12:17:35 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-06-23 17:39:25 -07:00
|
|
|
long Key = BasePosition + (uint)Offset;
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-07-14 09:08:39 -07:00
|
|
|
Keys[(int)Type] = Key;
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-07-14 09:08:39 -07:00
|
|
|
Gpu.Renderer.Shader.Create(Vmm, Key, Type);
|
2018-06-23 17:39:25 -07:00
|
|
|
Gpu.Renderer.Shader.Bind(Key);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-06-23 17:39:25 -07:00
|
|
|
return Keys;
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private static GalShaderType GetTypeFromProgram(int Program)
|
|
|
|
{
|
|
|
|
switch (Program)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 1: return GalShaderType.Vertex;
|
|
|
|
case 2: return GalShaderType.TessControl;
|
|
|
|
case 3: return GalShaderType.TessEvaluation;
|
|
|
|
case 4: return GalShaderType.Geometry;
|
|
|
|
case 5: return GalShaderType.Fragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(Program));
|
|
|
|
}
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
private void SetFlip(GalPipelineState State)
|
|
|
|
{
|
|
|
|
State.FlipX = GetFlipSign(NvGpuEngine3dReg.ViewportNScaleX);
|
|
|
|
State.FlipY = GetFlipSign(NvGpuEngine3dReg.ViewportNScaleY);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetFrontFace(GalPipelineState State)
|
2018-07-05 11:47:29 -07:00
|
|
|
{
|
2018-07-18 22:30:21 -07:00
|
|
|
float SignX = GetFlipSign(NvGpuEngine3dReg.ViewportNScaleX);
|
|
|
|
float SignY = GetFlipSign(NvGpuEngine3dReg.ViewportNScaleY);
|
2018-07-05 11:47:29 -07:00
|
|
|
|
|
|
|
GalFrontFace FrontFace = (GalFrontFace)ReadRegister(NvGpuEngine3dReg.FrontFace);
|
|
|
|
|
|
|
|
//Flipping breaks facing. Flipping front facing too fixes it
|
|
|
|
if (SignX != SignY)
|
|
|
|
{
|
|
|
|
switch (FrontFace)
|
|
|
|
{
|
|
|
|
case GalFrontFace.CW:
|
|
|
|
FrontFace = GalFrontFace.CCW;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GalFrontFace.CCW:
|
|
|
|
FrontFace = GalFrontFace.CW;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
State.FrontFace = FrontFace;
|
2018-07-05 11:47:29 -07:00
|
|
|
}
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
private void SetCullFace(GalPipelineState State)
|
2018-06-26 21:32:28 -07:00
|
|
|
{
|
2018-08-09 21:09:40 -07:00
|
|
|
State.CullFaceEnabled = (ReadRegister(NvGpuEngine3dReg.CullFaceEnable) & 1) != 0;
|
2018-07-05 11:47:29 -07:00
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
if (State.CullFaceEnabled)
|
2018-07-05 11:47:29 -07:00
|
|
|
{
|
2018-08-09 21:09:40 -07:00
|
|
|
State.CullFace = (GalCullFace)ReadRegister(NvGpuEngine3dReg.CullFace);
|
2018-07-05 11:47:29 -07:00
|
|
|
}
|
2018-06-26 21:32:28 -07:00
|
|
|
}
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
private void SetDepth(GalPipelineState State)
|
2018-06-26 21:32:28 -07:00
|
|
|
{
|
2018-08-09 21:09:40 -07:00
|
|
|
State.DepthTestEnabled = (ReadRegister(NvGpuEngine3dReg.DepthTestEnable) & 1) != 0;
|
2018-07-05 11:47:29 -07:00
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
if (State.DepthTestEnabled)
|
2018-07-05 11:47:29 -07:00
|
|
|
{
|
2018-08-09 21:09:40 -07:00
|
|
|
State.DepthFunc = (GalComparisonOp)ReadRegister(NvGpuEngine3dReg.DepthTestFunction);
|
2018-07-05 11:47:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
private void SetStencil(GalPipelineState State)
|
2018-07-05 11:47:29 -07:00
|
|
|
{
|
2018-08-09 21:09:40 -07:00
|
|
|
State.StencilTestEnabled = (ReadRegister(NvGpuEngine3dReg.StencilEnable) & 1) != 0;
|
2018-08-13 14:22:09 -07:00
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
if (State.StencilTestEnabled)
|
|
|
|
{
|
|
|
|
State.StencilBackFuncFunc = (GalComparisonOp)ReadRegister(NvGpuEngine3dReg.StencilBackFuncFunc);
|
|
|
|
State.StencilBackFuncRef = ReadRegister(NvGpuEngine3dReg.StencilBackFuncRef);
|
|
|
|
State.StencilBackFuncMask = (uint)ReadRegister(NvGpuEngine3dReg.StencilBackFuncMask);
|
|
|
|
State.StencilBackOpFail = (GalStencilOp)ReadRegister(NvGpuEngine3dReg.StencilBackOpFail);
|
|
|
|
State.StencilBackOpZFail = (GalStencilOp)ReadRegister(NvGpuEngine3dReg.StencilBackOpZFail);
|
|
|
|
State.StencilBackOpZPass = (GalStencilOp)ReadRegister(NvGpuEngine3dReg.StencilBackOpZPass);
|
|
|
|
State.StencilBackMask = (uint)ReadRegister(NvGpuEngine3dReg.StencilBackMask);
|
|
|
|
|
|
|
|
State.StencilFrontFuncFunc = (GalComparisonOp)ReadRegister(NvGpuEngine3dReg.StencilFrontFuncFunc);
|
|
|
|
State.StencilFrontFuncRef = ReadRegister(NvGpuEngine3dReg.StencilFrontFuncRef);
|
|
|
|
State.StencilFrontFuncMask = (uint)ReadRegister(NvGpuEngine3dReg.StencilFrontFuncMask);
|
|
|
|
State.StencilFrontOpFail = (GalStencilOp)ReadRegister(NvGpuEngine3dReg.StencilFrontOpFail);
|
|
|
|
State.StencilFrontOpZFail = (GalStencilOp)ReadRegister(NvGpuEngine3dReg.StencilFrontOpZFail);
|
|
|
|
State.StencilFrontOpZPass = (GalStencilOp)ReadRegister(NvGpuEngine3dReg.StencilFrontOpZPass);
|
|
|
|
State.StencilFrontMask = (uint)ReadRegister(NvGpuEngine3dReg.StencilFrontMask);
|
2018-07-05 11:47:29 -07:00
|
|
|
}
|
2018-06-26 21:32:28 -07:00
|
|
|
}
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
private void SetAlphaBlending(GalPipelineState State)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-04-13 11:12:58 -07:00
|
|
|
//TODO: Support independent blend properly.
|
2018-08-09 21:09:40 -07:00
|
|
|
State.BlendEnabled = (ReadRegister(NvGpuEngine3dReg.IBlendNEnable) & 1) != 0;
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
if (State.BlendEnabled)
|
2018-06-01 20:50:56 -07:00
|
|
|
{
|
2018-08-09 21:09:40 -07:00
|
|
|
State.BlendSeparateAlpha = (ReadRegister(NvGpuEngine3dReg.IBlendNSeparateAlpha) & 1) != 0;
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
State.BlendEquationRgb = (GalBlendEquation)ReadRegister(NvGpuEngine3dReg.IBlendNEquationRgb);
|
|
|
|
State.BlendFuncSrcRgb = (GalBlendFactor)ReadRegister(NvGpuEngine3dReg.IBlendNFuncSrcRgb);
|
|
|
|
State.BlendFuncDstRgb = (GalBlendFactor)ReadRegister(NvGpuEngine3dReg.IBlendNFuncDstRgb);
|
|
|
|
State.BlendEquationAlpha = (GalBlendEquation)ReadRegister(NvGpuEngine3dReg.IBlendNEquationAlpha);
|
|
|
|
State.BlendFuncSrcAlpha = (GalBlendFactor)ReadRegister(NvGpuEngine3dReg.IBlendNFuncSrcAlpha);
|
|
|
|
State.BlendFuncDstAlpha = (GalBlendFactor)ReadRegister(NvGpuEngine3dReg.IBlendNFuncDstAlpha);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
private void SetPrimitiveRestart(GalPipelineState State)
|
2018-07-08 09:14:35 -07:00
|
|
|
{
|
2018-08-09 21:09:40 -07:00
|
|
|
State.PrimitiveRestartEnabled = (ReadRegister(NvGpuEngine3dReg.PrimRestartEnable) & 1) != 0;
|
2018-07-08 09:14:35 -07:00
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
if (State.PrimitiveRestartEnabled)
|
2018-07-08 09:14:35 -07:00
|
|
|
{
|
2018-08-09 21:09:40 -07:00
|
|
|
State.PrimitiveRestartIndex = (uint)ReadRegister(NvGpuEngine3dReg.PrimRestartIndex);
|
2018-07-08 09:14:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-22 22:07:23 -07:00
|
|
|
private void SetRenderTargets()
|
|
|
|
{
|
|
|
|
bool SeparateFragData = (ReadRegister(NvGpuEngine3dReg.RTSeparateFragData) & 1) != 0;
|
|
|
|
|
|
|
|
if (SeparateFragData)
|
|
|
|
{
|
|
|
|
uint Control = (uint)(ReadRegister(NvGpuEngine3dReg.RTControl));
|
|
|
|
|
|
|
|
uint Count = Control & 0xf;
|
|
|
|
|
|
|
|
int[] Map = new int[Count];
|
|
|
|
|
|
|
|
for (int i = 0; i < Count; i++)
|
|
|
|
{
|
|
|
|
int Shift = 4 + i * 3;
|
|
|
|
|
|
|
|
Map[i] = (int)((Control >> Shift) & 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
Gpu.Renderer.FrameBuffer.SetMap(Map);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Gpu.Renderer.FrameBuffer.SetMap(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
private void UploadTextures(NvGpuVmm Vmm, GalPipelineState State, long[] Keys)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
|
|
|
long BaseShPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.ShaderAddress);
|
|
|
|
|
|
|
|
int TextureCbIndex = ReadRegister(NvGpuEngine3dReg.TextureCbIndex);
|
|
|
|
|
2018-08-13 14:22:09 -07:00
|
|
|
int TexIndex = 0;
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-06-23 17:39:25 -07:00
|
|
|
for (int Index = 0; Index < Keys.Length; Index++)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-06-23 17:39:25 -07:00
|
|
|
foreach (ShaderDeclInfo DeclInfo in Gpu.Renderer.Shader.GetTextureUsage(Keys[Index]))
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-08-13 14:22:09 -07:00
|
|
|
long Position;
|
|
|
|
|
|
|
|
if (DeclInfo.IsCb)
|
|
|
|
{
|
|
|
|
Position = ConstBuffers[Index][DeclInfo.Cbuf].Position;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Position = ConstBuffers[Index][TextureCbIndex].Position;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TextureHandle = Vmm.ReadInt32(Position + DeclInfo.Index * 4);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-08-13 14:22:09 -07:00
|
|
|
UploadTexture(Vmm, TexIndex, TextureHandle);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
|
|
|
TexIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 14:22:09 -07:00
|
|
|
private void UploadTexture(NvGpuVmm Vmm, int TexIndex, int TextureHandle)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-06-22 22:00:44 -07:00
|
|
|
if (TextureHandle == 0)
|
|
|
|
{
|
|
|
|
//TODO: Is this correct?
|
|
|
|
//Some games like puyo puyo will have 0 handles.
|
|
|
|
//It may be just normal behaviour or a bug caused by sync issues.
|
|
|
|
//The game does initialize the value properly after through.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-08 12:17:35 -07:00
|
|
|
int TicIndex = (TextureHandle >> 0) & 0xfffff;
|
|
|
|
int TscIndex = (TextureHandle >> 20) & 0xfff;
|
|
|
|
|
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 11:53:23 -07:00
|
|
|
long TicPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.TexHeaderPoolOffset);
|
|
|
|
long TscPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.TexSamplerPoolOffset);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
|
|
|
TicPosition += TicIndex * 0x20;
|
|
|
|
TscPosition += TscIndex * 0x20;
|
|
|
|
|
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 11:53:23 -07:00
|
|
|
GalTextureSampler Sampler = TextureFactory.MakeSampler(Gpu, Vmm, TscPosition);
|
2018-04-13 11:12:58 -07:00
|
|
|
|
2018-07-08 12:55:15 -07:00
|
|
|
long Key = Vmm.ReadInt64(TicPosition + 4) & 0xffffffffffff;
|
2018-04-13 11:12:58 -07:00
|
|
|
|
2018-07-08 12:55:15 -07:00
|
|
|
Key = Vmm.GetPhysicalAddress(Key);
|
2018-06-08 17:15:56 -07:00
|
|
|
|
2018-08-15 11:59:51 -07:00
|
|
|
if (Key == -1)
|
|
|
|
{
|
|
|
|
//FIXME: Should'nt ignore invalid addresses.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-08 12:55:15 -07:00
|
|
|
if (IsFrameBufferPosition(Key))
|
2018-04-13 11:12:58 -07:00
|
|
|
{
|
|
|
|
//This texture is a frame buffer texture,
|
|
|
|
//we shouldn't read anything from memory and bind
|
|
|
|
//the frame buffer texture instead, since we're not
|
|
|
|
//really writing anything to memory.
|
2018-07-08 12:55:15 -07:00
|
|
|
Gpu.Renderer.FrameBuffer.BindTexture(Key, TexIndex);
|
2018-04-13 11:12:58 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-19 18:25:26 -07:00
|
|
|
GalImage NewImage = TextureFactory.MakeTexture(Vmm, TicPosition);
|
2018-06-08 17:15:56 -07:00
|
|
|
|
2018-08-19 18:25:26 -07:00
|
|
|
long Size = (uint)TextureHelper.GetTextureSize(NewImage);
|
2018-06-08 17:15:56 -07:00
|
|
|
|
2018-06-23 17:39:25 -07:00
|
|
|
bool HasCachedTexture = false;
|
|
|
|
|
2018-08-19 18:25:26 -07:00
|
|
|
if (Gpu.Renderer.Texture.TryGetCachedTexture(Key, Size, out GalImage Image))
|
2018-06-08 17:15:56 -07:00
|
|
|
{
|
2018-08-19 18:25:26 -07:00
|
|
|
if (NewImage.Equals(Image) && !QueryKeyUpload(Vmm, Key, Size, NvGpuBufferType.Texture))
|
2018-06-08 17:15:56 -07:00
|
|
|
{
|
2018-06-23 17:39:25 -07:00
|
|
|
Gpu.Renderer.Texture.Bind(Key, TexIndex);
|
2018-06-08 17:15:56 -07:00
|
|
|
|
2018-06-23 17:39:25 -07:00
|
|
|
HasCachedTexture = true;
|
2018-06-08 17:15:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-23 17:39:25 -07:00
|
|
|
if (!HasCachedTexture)
|
|
|
|
{
|
|
|
|
byte[] Data = TextureFactory.GetTextureData(Vmm, TicPosition);
|
2018-04-13 11:12:58 -07:00
|
|
|
|
2018-08-19 18:25:26 -07:00
|
|
|
Gpu.Renderer.Texture.Create(Key, Data, NewImage);
|
2018-06-23 17:39:25 -07:00
|
|
|
}
|
2018-06-08 17:15:56 -07:00
|
|
|
|
2018-06-23 17:39:25 -07:00
|
|
|
Gpu.Renderer.Texture.Bind(Key, TexIndex);
|
2018-04-13 11:12:58 -07:00
|
|
|
}
|
2018-06-23 17:39:25 -07:00
|
|
|
|
|
|
|
Gpu.Renderer.Texture.SetSampler(Sampler);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-08-15 11:59:51 -07:00
|
|
|
private void UploadConstBuffers(NvGpuVmm Vmm, GalPipelineState State, long[] Keys)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-08-15 11:59:51 -07:00
|
|
|
for (int Stage = 0; Stage < Keys.Length; Stage++)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-08-15 11:59:51 -07:00
|
|
|
foreach (ShaderDeclInfo DeclInfo in Gpu.Renderer.Shader.GetConstBufferUsage(Keys[Stage]))
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-08-15 11:59:51 -07:00
|
|
|
ConstBuffer Cb = ConstBuffers[Stage][DeclInfo.Cbuf];
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-08-15 11:59:51 -07:00
|
|
|
if (!Cb.Enabled)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-08-15 11:59:51 -07:00
|
|
|
long Key = Vmm.GetPhysicalAddress(Cb.Position);
|
|
|
|
|
|
|
|
if (QueryKeyUpload(Vmm, Key, Cb.Size, NvGpuBufferType.ConstBuffer))
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-08-15 11:59:51 -07:00
|
|
|
IntPtr Source = Vmm.GetHostAddress(Cb.Position, Cb.Size);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
Gpu.Renderer.Buffer.SetData(Key, Cb.Size, Source);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
2018-08-09 21:09:40 -07:00
|
|
|
|
2018-08-15 11:59:51 -07:00
|
|
|
State.ConstBufferKeys[Stage][DeclInfo.Cbuf] = Key;
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
private void UploadVertexArrays(NvGpuVmm Vmm, GalPipelineState State)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
|
|
|
long IndexPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.IndexArrayAddress);
|
|
|
|
|
2018-07-08 12:55:15 -07:00
|
|
|
long IboKey = Vmm.GetPhysicalAddress(IndexPosition);
|
|
|
|
|
2018-06-23 17:39:25 -07:00
|
|
|
int IndexEntryFmt = ReadRegister(NvGpuEngine3dReg.IndexArrayFormat);
|
|
|
|
int IndexCount = ReadRegister(NvGpuEngine3dReg.IndexBatchCount);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-06-23 17:39:25 -07:00
|
|
|
GalIndexFormat IndexFormat = (GalIndexFormat)IndexEntryFmt;
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-06-23 17:39:25 -07:00
|
|
|
int IndexEntrySize = 1 << IndexEntryFmt;
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-06-23 17:39:25 -07:00
|
|
|
if (IndexEntrySize > 4)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
|
2018-06-18 06:59:03 -07:00
|
|
|
if (IndexCount != 0)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
2018-06-23 17:39:25 -07:00
|
|
|
int IbSize = IndexCount * IndexEntrySize;
|
2018-06-08 17:15:56 -07:00
|
|
|
|
2018-07-08 12:55:15 -07:00
|
|
|
bool IboCached = Gpu.Renderer.Rasterizer.IsIboCached(IboKey, (uint)IbSize);
|
2018-06-08 17:15:56 -07:00
|
|
|
|
2018-07-28 21:39:15 -07:00
|
|
|
if (!IboCached || QueryKeyUpload(Vmm, IboKey, (uint)IbSize, NvGpuBufferType.Index))
|
2018-06-08 17:15:56 -07:00
|
|
|
{
|
2018-07-19 12:02:51 -07:00
|
|
|
IntPtr DataAddress = Vmm.GetHostAddress(IndexPosition, IbSize);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-07-19 12:02:51 -07:00
|
|
|
Gpu.Renderer.Rasterizer.CreateIbo(IboKey, IbSize, DataAddress);
|
2018-06-08 17:15:56 -07:00
|
|
|
}
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-07-09 19:01:59 -07:00
|
|
|
Gpu.Renderer.Rasterizer.SetIndexArray(IbSize, IndexFormat);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
List<GalVertexAttrib>[] Attribs = new List<GalVertexAttrib>[32];
|
|
|
|
|
|
|
|
for (int Attr = 0; Attr < 16; Attr++)
|
|
|
|
{
|
|
|
|
int Packed = ReadRegister(NvGpuEngine3dReg.VertexAttribNFormat + Attr);
|
|
|
|
|
|
|
|
int ArrayIndex = Packed & 0x1f;
|
|
|
|
|
|
|
|
if (Attribs[ArrayIndex] == null)
|
|
|
|
{
|
|
|
|
Attribs[ArrayIndex] = new List<GalVertexAttrib>();
|
|
|
|
}
|
|
|
|
|
|
|
|
Attribs[ArrayIndex].Add(new GalVertexAttrib(
|
2018-04-29 13:58:38 -07:00
|
|
|
Attr,
|
2018-04-08 12:17:35 -07:00
|
|
|
((Packed >> 6) & 0x1) != 0,
|
|
|
|
(Packed >> 7) & 0x3fff,
|
|
|
|
(GalVertexAttribSize)((Packed >> 21) & 0x3f),
|
|
|
|
(GalVertexAttribType)((Packed >> 27) & 0x7),
|
|
|
|
((Packed >> 31) & 0x1) != 0));
|
|
|
|
}
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
State.VertexBindings = new GalVertexBinding[32];
|
2018-06-08 17:15:56 -07:00
|
|
|
|
2018-04-08 12:17:35 -07:00
|
|
|
for (int Index = 0; Index < 32; Index++)
|
|
|
|
{
|
2018-06-08 17:15:56 -07:00
|
|
|
if (Attribs[Index] == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2018-04-25 19:11:26 -07:00
|
|
|
|
2018-04-08 12:17:35 -07:00
|
|
|
int Control = ReadRegister(NvGpuEngine3dReg.VertexArrayNControl + Index * 4);
|
|
|
|
|
|
|
|
bool Enable = (Control & 0x1000) != 0;
|
|
|
|
|
|
|
|
if (!Enable)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
long VertexPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.VertexArrayNAddress + Index * 4);
|
|
|
|
long VertexEndPos = MakeInt64From2xInt32(NvGpuEngine3dReg.VertexArrayNEndAddr + Index * 2);
|
|
|
|
|
2018-07-08 12:55:15 -07:00
|
|
|
long VboKey = Vmm.GetPhysicalAddress(VertexPosition);
|
|
|
|
|
2018-04-29 13:58:38 -07:00
|
|
|
int Stride = Control & 0xfff;
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-06-26 21:32:28 -07:00
|
|
|
long VbSize = (VertexEndPos - VertexPosition) + 1;
|
2018-04-29 13:58:38 -07:00
|
|
|
|
2018-07-08 12:55:15 -07:00
|
|
|
bool VboCached = Gpu.Renderer.Rasterizer.IsVboCached(VboKey, VbSize);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-07-28 21:39:15 -07:00
|
|
|
if (!VboCached || QueryKeyUpload(Vmm, VboKey, VbSize, NvGpuBufferType.Vertex))
|
2018-06-08 17:15:56 -07:00
|
|
|
{
|
2018-07-19 12:02:51 -07:00
|
|
|
IntPtr DataAddress = Vmm.GetHostAddress(VertexPosition, VbSize);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-07-19 12:02:51 -07:00
|
|
|
Gpu.Renderer.Rasterizer.CreateVbo(VboKey, (int)VbSize, DataAddress);
|
2018-06-08 17:15:56 -07:00
|
|
|
}
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
State.VertexBindings[Index].Enabled = true;
|
|
|
|
State.VertexBindings[Index].Stride = Stride;
|
|
|
|
State.VertexBindings[Index].VboKey = VboKey;
|
|
|
|
State.VertexBindings[Index].Attribs = Attribs[Index].ToArray();
|
2018-06-08 17:15:56 -07:00
|
|
|
}
|
2018-08-09 21:09:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private void DispatchRender(NvGpuVmm Vmm, GalPipelineState State)
|
|
|
|
{
|
|
|
|
int IndexCount = ReadRegister(NvGpuEngine3dReg.IndexBatchCount);
|
|
|
|
int PrimCtrl = ReadRegister(NvGpuEngine3dReg.VertexBeginGl);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-06-08 17:15:56 -07:00
|
|
|
GalPrimitiveType PrimType = (GalPrimitiveType)(PrimCtrl & 0xffff);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
Gpu.Renderer.Pipeline.Bind(State);
|
|
|
|
|
2018-06-08 17:15:56 -07:00
|
|
|
if (IndexCount != 0)
|
|
|
|
{
|
2018-08-09 21:09:40 -07:00
|
|
|
int IndexEntryFmt = ReadRegister(NvGpuEngine3dReg.IndexArrayFormat);
|
|
|
|
int IndexFirst = ReadRegister(NvGpuEngine3dReg.IndexBatchFirst);
|
|
|
|
int VertexBase = ReadRegister(NvGpuEngine3dReg.VertexArrayElemBase);
|
|
|
|
|
|
|
|
long IndexPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.IndexArrayAddress);
|
|
|
|
|
|
|
|
long IboKey = Vmm.GetPhysicalAddress(IndexPosition);
|
2018-06-28 16:48:18 -07:00
|
|
|
|
2018-07-08 12:55:15 -07:00
|
|
|
Gpu.Renderer.Rasterizer.DrawElements(IboKey, IndexFirst, VertexBase, PrimType);
|
2018-06-08 17:15:56 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-09 21:09:40 -07:00
|
|
|
int VertexFirst = ReadRegister(NvGpuEngine3dReg.VertexArrayFirst);
|
|
|
|
int VertexCount = ReadRegister(NvGpuEngine3dReg.VertexArrayCount);
|
|
|
|
|
2018-06-23 17:39:25 -07:00
|
|
|
Gpu.Renderer.Rasterizer.DrawArrays(VertexFirst, VertexCount, PrimType);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
2018-08-13 14:22:09 -07:00
|
|
|
|
|
|
|
//Is the GPU really clearing those registers after draw?
|
|
|
|
WriteRegister(NvGpuEngine3dReg.IndexBatchFirst, 0);
|
|
|
|
WriteRegister(NvGpuEngine3dReg.IndexBatchCount, 0);
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
private void QueryControl(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
long Position = MakeInt64From2xInt32(NvGpuEngine3dReg.QueryAddress);
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
int Seq = Registers[(int)NvGpuEngine3dReg.QuerySequence];
|
|
|
|
int Ctrl = Registers[(int)NvGpuEngine3dReg.QueryControl];
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
int Mode = Ctrl & 3;
|
|
|
|
|
|
|
|
if (Mode == 0)
|
|
|
|
{
|
|
|
|
//Write mode.
|
|
|
|
Vmm.WriteInt32(Position, Seq);
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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 11:53:23 -07:00
|
|
|
private void CbData(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
long Position = MakeInt64From2xInt32(NvGpuEngine3dReg.ConstBufferAddress);
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
int Offset = ReadRegister(NvGpuEngine3dReg.ConstBufferOffset);
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
foreach (int Arg in PBEntry.Arguments)
|
|
|
|
{
|
|
|
|
Vmm.WriteInt32(Position + Offset, Arg);
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
Offset += 4;
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
|
|
|
|
WriteRegister(NvGpuEngine3dReg.ConstBufferOffset, Offset);
|
2018-08-14 18:27:05 -07:00
|
|
|
|
|
|
|
UploadedKeys[(int)NvGpuBufferType.ConstBuffer].Clear();
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
private void CbBind(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
|
2018-04-08 12:17:35 -07: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 11:53:23 -07:00
|
|
|
int Stage = (PBEntry.Method - 0x904) >> 3;
|
|
|
|
|
2018-04-08 12:17:35 -07:00
|
|
|
int Index = PBEntry.Arguments[0];
|
|
|
|
|
|
|
|
bool Enabled = (Index & 1) != 0;
|
|
|
|
|
|
|
|
Index = (Index >> 4) & 0x1f;
|
|
|
|
|
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 11:53:23 -07:00
|
|
|
long Position = MakeInt64From2xInt32(NvGpuEngine3dReg.ConstBufferAddress);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-08-15 11:59:51 -07:00
|
|
|
long CbKey = Vmm.GetPhysicalAddress(Position);
|
|
|
|
|
2018-08-09 21:09:40 -07:00
|
|
|
int Size = ReadRegister(NvGpuEngine3dReg.ConstBufferSize);
|
2018-04-08 12:17:35 -07:00
|
|
|
|
2018-08-15 11:59:51 -07:00
|
|
|
if (!Gpu.Renderer.Buffer.IsCached(CbKey, Size))
|
2018-08-09 21:09:40 -07:00
|
|
|
{
|
2018-08-15 11:59:51 -07:00
|
|
|
Gpu.Renderer.Buffer.Create(CbKey, Size);
|
2018-08-09 21:09:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ConstBuffer Cb = ConstBuffers[Stage][Index];
|
|
|
|
|
|
|
|
if (Cb.Position != Position || Cb.Enabled != Enabled || Cb.Size != Size)
|
|
|
|
{
|
|
|
|
ConstBuffers[Stage][Index].Position = Position;
|
|
|
|
ConstBuffers[Stage][Index].Enabled = Enabled;
|
|
|
|
ConstBuffers[Stage][Index].Size = Size;
|
|
|
|
}
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
|
|
|
|
2018-07-05 11:47:29 -07:00
|
|
|
private float GetFlipSign(NvGpuEngine3dReg Reg)
|
|
|
|
{
|
|
|
|
return MathF.Sign(ReadRegisterFloat(Reg));
|
|
|
|
}
|
|
|
|
|
2018-04-08 12:17:35 -07:00
|
|
|
private long MakeInt64From2xInt32(NvGpuEngine3dReg 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 11:53:23 -07:00
|
|
|
private void WriteRegister(NvGpuPBEntry PBEntry)
|
2018-04-08 12:17:35 -07:00
|
|
|
{
|
|
|
|
int ArgsCount = PBEntry.Arguments.Count;
|
|
|
|
|
|
|
|
if (ArgsCount > 0)
|
|
|
|
{
|
|
|
|
Registers[PBEntry.Method] = PBEntry.Arguments[ArgsCount - 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private int ReadRegister(NvGpuEngine3dReg Reg)
|
|
|
|
{
|
|
|
|
return Registers[(int)Reg];
|
|
|
|
}
|
|
|
|
|
2018-07-05 11:47:29 -07:00
|
|
|
private float ReadRegisterFloat(NvGpuEngine3dReg Reg)
|
|
|
|
{
|
|
|
|
return BitConverter.Int32BitsToSingle(ReadRegister(Reg));
|
|
|
|
}
|
|
|
|
|
2018-04-08 12:17:35 -07:00
|
|
|
private void WriteRegister(NvGpuEngine3dReg Reg, int Value)
|
|
|
|
{
|
|
|
|
Registers[(int)Reg] = Value;
|
|
|
|
}
|
2018-04-13 11:12:58 -07:00
|
|
|
|
|
|
|
public bool IsFrameBufferPosition(long Position)
|
|
|
|
{
|
|
|
|
return FrameBuffers.Contains(Position);
|
|
|
|
}
|
2018-07-28 21:39:15 -07:00
|
|
|
|
|
|
|
private bool QueryKeyUpload(NvGpuVmm Vmm, long Key, long Size, NvGpuBufferType Type)
|
|
|
|
{
|
|
|
|
List<long> Uploaded = UploadedKeys[(int)Type];
|
|
|
|
|
|
|
|
if (Uploaded.Contains(Key))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Uploaded.Add(Key);
|
|
|
|
|
|
|
|
return Vmm.IsRegionModified(Key, Size, Type);
|
|
|
|
}
|
2018-04-08 12:17:35 -07:00
|
|
|
}
|
2018-08-22 22:07:23 -07:00
|
|
|
}
|