2018-10-28 23:31:13 +01:00
|
|
|
using Ryujinx.Common;
|
2018-04-08 21:17:35 +02:00
|
|
|
using Ryujinx.Graphics.Gal;
|
2018-09-08 19:51:50 +02:00
|
|
|
using Ryujinx.Graphics.Memory;
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-18 01:57:08 +02:00
|
|
|
using Ryujinx.Graphics.Shader;
|
2018-09-08 19:51:50 +02:00
|
|
|
using Ryujinx.Graphics.Texture;
|
2018-04-08 21:17:35 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2018-12-03 03:38:47 +01:00
|
|
|
namespace Ryujinx.Graphics.Graphics3d
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-11-17 05:01:31 +01:00
|
|
|
class NvGpuEngine3d : INvGpuEngine
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
public int[] Registers { get; private set; }
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private NvGpu _gpu;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private Dictionary<int, NvGpuMethod> _methods;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
private struct ConstBuffer
|
|
|
|
{
|
|
|
|
public bool Enabled;
|
|
|
|
public long Position;
|
|
|
|
public int Size;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private ConstBuffer[][] _constBuffers;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-02 11:50:21 +01:00
|
|
|
// Viewport dimensions kept for scissor test limits
|
2019-03-04 02:45:25 +01:00
|
|
|
private int _viewportX0 = 0;
|
|
|
|
private int _viewportY0 = 0;
|
|
|
|
private int _viewportX1 = 0;
|
|
|
|
private int _viewportY1 = 0;
|
|
|
|
private int _viewportWidth = 0;
|
|
|
|
private int _viewportHeight = 0;
|
2019-01-13 22:26:42 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private int _currentInstance = 0;
|
2018-08-25 06:16:58 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public NvGpuEngine3d(NvGpu gpu)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu = gpu;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
Registers = new int[0xe00];
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_methods = new Dictionary<int, NvGpuMethod>();
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
void AddMethod(int meth, int count, int stride, NvGpuMethod method)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
while (count-- > 0)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_methods.Add(meth, method);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
meth += stride;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 20:53:23 +02:00
|
|
|
AddMethod(0x904, 5, 8, CbBind);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_constBuffers = new ConstBuffer[6][];
|
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
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
for (int index = 0; index < _constBuffers.Length; index++)
|
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
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_constBuffers[index] = new ConstBuffer[18];
|
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
|
|
|
}
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2018-10-25 23:30:09 +02:00
|
|
|
//Ensure that all components are enabled by default.
|
|
|
|
//FIXME: Is this correct?
|
|
|
|
WriteRegister(NvGpuEngine3dReg.ColorMaskN, 0x1111);
|
2018-11-14 22:50:31 +01:00
|
|
|
|
2018-11-17 05:10:51 +01:00
|
|
|
WriteRegister(NvGpuEngine3dReg.FrameBufferSrgb, 1);
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
WriteRegister(NvGpuEngine3dReg.FrontFace, (int)GalFrontFace.Cw);
|
2019-02-22 06:14:02 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
for (int index = 0; index < GalPipelineState.RenderTargetsCount; index++)
|
2018-11-14 22:50:31 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
WriteRegister(NvGpuEngine3dReg.IBlendNEquationRgb + index * 8, (int)GalBlendEquation.FuncAdd);
|
|
|
|
WriteRegister(NvGpuEngine3dReg.IBlendNFuncSrcRgb + index * 8, (int)GalBlendFactor.One);
|
|
|
|
WriteRegister(NvGpuEngine3dReg.IBlendNFuncDstRgb + index * 8, (int)GalBlendFactor.Zero);
|
|
|
|
WriteRegister(NvGpuEngine3dReg.IBlendNEquationAlpha + index * 8, (int)GalBlendEquation.FuncAdd);
|
|
|
|
WriteRegister(NvGpuEngine3dReg.IBlendNFuncSrcAlpha + index * 8, (int)GalBlendFactor.One);
|
|
|
|
WriteRegister(NvGpuEngine3dReg.IBlendNFuncDstAlpha + index * 8, (int)GalBlendFactor.Zero);
|
2018-11-14 22:50:31 +01:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public void CallMethod(NvGpuVmm vmm, GpuMethodCall methCall)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
if (_methods.TryGetValue(methCall.Method, out NvGpuMethod method))
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
method(vmm, methCall);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
WriteRegister(methCall);
|
2018-08-15 03:27:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void VertexEndGl(NvGpuVmm vmm, GpuMethodCall methCall)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-07-10 04:01:59 +02:00
|
|
|
LockCaches();
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
GalPipelineState state = new GalPipelineState();
|
2018-08-10 06:09:40 +02:00
|
|
|
|
2019-03-02 11:50:21 +01:00
|
|
|
// Framebuffer must be run configured because viewport dimensions may be used in other methods
|
2019-03-04 02:45:25 +01:00
|
|
|
SetFrameBuffer(state);
|
2019-03-02 11:50:21 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
for (int fbIndex = 0; fbIndex < 8; fbIndex++)
|
2019-03-02 11:50:21 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
SetFrameBuffer(vmm, fbIndex);
|
2019-03-02 11:50:21 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
SetFrontFace(state);
|
|
|
|
SetCullFace(state);
|
|
|
|
SetDepth(state);
|
|
|
|
SetStencil(state);
|
|
|
|
SetScissor(state);
|
|
|
|
SetBlending(state);
|
|
|
|
SetColorMask(state);
|
|
|
|
SetPrimitiveRestart(state);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
SetZeta(vmm);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-08-23 07:07:23 +02:00
|
|
|
SetRenderTargets();
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long[] keys = UploadShaders(vmm);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Shader.BindProgram();
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
UploadTextures(vmm, state, keys);
|
|
|
|
UploadConstBuffers(vmm, state, keys);
|
|
|
|
UploadVertexArrays(vmm, state);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
DispatchRender(vmm, state);
|
2018-07-10 04:01:59 +02:00
|
|
|
|
|
|
|
UnlockCaches();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void LockCaches()
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Buffer.LockCache();
|
|
|
|
_gpu.Renderer.Rasterizer.LockCaches();
|
|
|
|
_gpu.Renderer.Texture.LockCache();
|
2018-07-10 04:01:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void UnlockCaches()
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Buffer.UnlockCache();
|
|
|
|
_gpu.Renderer.Rasterizer.UnlockCaches();
|
|
|
|
_gpu.Renderer.Texture.UnlockCache();
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void ClearBuffers(NvGpuVmm vmm, GpuMethodCall methCall)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
int attachment = (methCall.Argument >> 6) & 0xf;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
GalClearBufferFlags flags = (GalClearBufferFlags)(methCall.Argument & 0x3f);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01: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);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
float depth = ReadRegisterFloat(NvGpuEngine3dReg.ClearDepth);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int stencil = ReadRegister(NvGpuEngine3dReg.ClearStencil);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
SetFrameBuffer(vmm, attachment);
|
2018-09-08 19:51:50 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
SetZeta(vmm);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-26 00:55:30 +02:00
|
|
|
SetRenderTargets();
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.RenderTarget.Bind();
|
2018-09-26 00:55:30 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Rasterizer.ClearBuffers(flags, attachment, red, green, blue, alpha, depth, stencil);
|
2018-10-17 23:02:23 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Pipeline.ResetDepthMask();
|
|
|
|
_gpu.Renderer.Pipeline.ResetColorMask(attachment);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void SetFrameBuffer(NvGpuVmm vmm, int fbIndex)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
long va = MakeInt64From2xInt32(NvGpuEngine3dReg.FrameBufferNAddress + fbIndex * 0x10);
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int surfFormat = ReadRegister(NvGpuEngine3dReg.FrameBufferNFormat + fbIndex * 0x10);
|
2018-08-20 03:25:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (va == 0 || surfFormat == 0)
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.RenderTarget.UnbindColor(fbIndex);
|
2018-08-20 03:25:26 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01: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 20:53:23 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int width = ReadRegister(NvGpuEngine3dReg.FrameBufferNWidth + fbIndex * 0x10);
|
|
|
|
int height = ReadRegister(NvGpuEngine3dReg.FrameBufferNHeight + fbIndex * 0x10);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int arrayMode = ReadRegister(NvGpuEngine3dReg.FrameBufferNArrayMode + fbIndex * 0x10);
|
|
|
|
int layerCount = arrayMode & 0xFFFF;
|
|
|
|
int layerStride = ReadRegister(NvGpuEngine3dReg.FrameBufferNLayerStride + fbIndex * 0x10);
|
|
|
|
int baseLayer = ReadRegister(NvGpuEngine3dReg.FrameBufferNBaseLayer + fbIndex * 0x10);
|
|
|
|
int blockDim = ReadRegister(NvGpuEngine3dReg.FrameBufferNBlockDim + fbIndex * 0x10);
|
2018-09-18 06:30:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int gobBlockHeight = 1 << ((blockDim >> 4) & 7);
|
2018-09-18 06:30:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
GalMemoryLayout layout = (GalMemoryLayout)((blockDim >> 12) & 1);
|
2018-09-18 06:30:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
float tx = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateX + fbIndex * 8);
|
|
|
|
float ty = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateY + fbIndex * 8);
|
2018-07-19 07:30:21 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
float sx = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleX + fbIndex * 8);
|
|
|
|
float sy = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleY + fbIndex * 8);
|
2018-07-19 07:30:21 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_viewportX0 = (int)MathF.Max(0, tx - MathF.Abs(sx));
|
|
|
|
_viewportY0 = (int)MathF.Max(0, ty - MathF.Abs(sy));
|
2018-07-19 07:30:21 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_viewportX1 = (int)(tx + MathF.Abs(sx));
|
|
|
|
_viewportY1 = (int)(ty + MathF.Abs(sy));
|
2018-07-19 07:30:21 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
GalImageFormat format = ImageUtils.ConvertSurface((GalSurfaceFormat)surfFormat);
|
2018-08-20 03:25:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
GalImage image = new GalImage(width, height, 1, 1, 1, gobBlockHeight, 1, layout, format, GalTextureTarget.TwoD);
|
2018-08-20 03:25:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.ResourceManager.SendColorBuffer(vmm, key, fbIndex, image);
|
2018-08-20 03:25:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.RenderTarget.SetViewport(fbIndex, _viewportX0, _viewportY0, _viewportX1 - _viewportX0, _viewportY1 - _viewportY0);
|
2018-09-18 06:30:35 +02:00
|
|
|
}
|
2018-07-19 07:30:21 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void SetFrameBuffer(GalPipelineState state)
|
2018-09-18 06:30:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
state.FramebufferSrgb = ReadRegisterBool(NvGpuEngine3dReg.FrameBufferSrgb);
|
2018-09-08 19:51:50 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
state.FlipX = GetFlipSign(NvGpuEngine3dReg.ViewportNScaleX);
|
|
|
|
state.FlipY = GetFlipSign(NvGpuEngine3dReg.ViewportNScaleY);
|
2018-11-17 05:01:31 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int screenYControl = ReadRegister(NvGpuEngine3dReg.ScreenYControl);
|
2018-11-17 05:01:31 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool negateY = (screenYControl & 1) != 0;
|
2018-11-17 05:01:31 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (negateY)
|
2018-11-17 05:01:31 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
state.FlipY = -state.FlipY;
|
2018-11-17 05:01:31 +01:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void SetZeta(NvGpuVmm vmm)
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
long va = MakeInt64From2xInt32(NvGpuEngine3dReg.ZetaAddress);
|
2018-09-18 06:30:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int zetaFormat = ReadRegister(NvGpuEngine3dReg.ZetaFormat);
|
2018-09-18 06:30:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int blockDim = ReadRegister(NvGpuEngine3dReg.ZetaBlockDimensions);
|
2018-09-18 06:30:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int gobBlockHeight = 1 << ((blockDim >> 4) & 7);
|
2018-08-20 03:25:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
GalMemoryLayout layout = (GalMemoryLayout)((blockDim >> 12) & 1); //?
|
2018-08-20 03:25:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool zetaEnable = ReadRegisterBool(NvGpuEngine3dReg.ZetaEnable);
|
2018-08-20 03:25:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (va == 0 || zetaFormat == 0 || !zetaEnable)
|
2018-08-20 03:25:26 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.RenderTarget.UnbindZeta();
|
2018-08-20 03:25:26 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long key = vmm.GetPhysicalAddress(va);
|
2018-09-01 16:54:56 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int width = ReadRegister(NvGpuEngine3dReg.ZetaHoriz);
|
|
|
|
int height = ReadRegister(NvGpuEngine3dReg.ZetaVert);
|
2018-08-20 03:25:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
GalImageFormat format = ImageUtils.ConvertZeta((GalZetaFormat)zetaFormat);
|
2018-08-20 03:25:26 +02:00
|
|
|
|
2019-02-28 02:12:24 +01:00
|
|
|
// TODO: Support non 2D?
|
2019-03-04 02:45:25 +01:00
|
|
|
GalImage image = new GalImage(width, height, 1, 1, 1, gobBlockHeight, 1, layout, format, GalTextureTarget.TwoD);
|
2018-09-08 19:51:50 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.ResourceManager.SendZetaBuffer(vmm, key, image);
|
2018-08-20 03:25:26 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private long[] UploadShaders(NvGpuVmm vmm)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
long[] keys = new long[5];
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long basePosition = MakeInt64From2xInt32(NvGpuEngine3dReg.ShaderAddress);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int index = 1;
|
2018-06-28 04:55:08 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int vpAControl = ReadRegister(NvGpuEngine3dReg.ShaderNControl);
|
2018-06-28 04:55:08 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool vpAEnable = (vpAControl & 1) != 0;
|
2018-06-28 04:55:08 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (vpAEnable)
|
2018-06-28 04:55:08 +02:00
|
|
|
{
|
|
|
|
//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.
|
2019-03-04 02:45:25 +01:00
|
|
|
int vpAOffset = ReadRegister(NvGpuEngine3dReg.ShaderNOffset);
|
|
|
|
int vpBOffset = ReadRegister(NvGpuEngine3dReg.ShaderNOffset + 0x10);
|
2018-06-28 04:55:08 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long vpAPos = basePosition + (uint)vpAOffset;
|
|
|
|
long vpBPos = basePosition + (uint)vpBOffset;
|
2018-06-28 04:55:08 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
keys[(int)GalShaderType.Vertex] = vpBPos;
|
2018-08-10 06:09:40 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Shader.Create(vmm, vpAPos, vpBPos, GalShaderType.Vertex);
|
|
|
|
_gpu.Renderer.Shader.Bind(vpBPos);
|
2018-06-28 04:55:08 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
index = 2;
|
2018-06-28 04:55:08 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
for (; index < 6; index++)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
GalShaderType type = GetTypeFromProgram(index);
|
2018-07-14 18:08:39 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int control = ReadRegister(NvGpuEngine3dReg.ShaderNControl + index * 0x10);
|
|
|
|
int offset = ReadRegister(NvGpuEngine3dReg.ShaderNOffset + index * 0x10);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
//Note: Vertex Program (B) is always enabled.
|
2019-03-04 02:45:25 +01:00
|
|
|
bool enable = (control & 1) != 0 || index == 1;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (!enable)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Shader.Unbind(type);
|
2018-07-14 18:08:39 +02:00
|
|
|
|
2018-04-08 21:17:35 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long key = basePosition + (uint)offset;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
keys[(int)type] = key;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Shader.Create(vmm, key, type);
|
|
|
|
_gpu.Renderer.Shader.Bind(key);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return keys;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private static GalShaderType GetTypeFromProgram(int program)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (program)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new ArgumentOutOfRangeException(nameof(program));
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void SetFrontFace(GalPipelineState state)
|
2018-07-05 20:47:29 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
float signX = GetFlipSign(NvGpuEngine3dReg.ViewportNScaleX);
|
|
|
|
float signY = GetFlipSign(NvGpuEngine3dReg.ViewportNScaleY);
|
2018-07-05 20:47:29 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
GalFrontFace frontFace = (GalFrontFace)ReadRegister(NvGpuEngine3dReg.FrontFace);
|
2018-07-05 20:47:29 +02:00
|
|
|
|
|
|
|
//Flipping breaks facing. Flipping front facing too fixes it
|
2019-03-04 02:45:25 +01:00
|
|
|
if (signX != signY)
|
2018-07-05 20:47:29 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (frontFace)
|
2018-07-05 20:47:29 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
case GalFrontFace.Cw: frontFace = GalFrontFace.Ccw; break;
|
|
|
|
case GalFrontFace.Ccw: frontFace = GalFrontFace.Cw; break;
|
2018-07-05 20:47:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
state.FrontFace = frontFace;
|
2018-07-05 20:47:29 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void SetCullFace(GalPipelineState state)
|
2018-06-27 06:32:28 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
state.CullFaceEnabled = ReadRegisterBool(NvGpuEngine3dReg.CullFaceEnable);
|
2018-07-05 20:47:29 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (state.CullFaceEnabled)
|
2018-07-05 20:47:29 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
state.CullFace = (GalCullFace)ReadRegister(NvGpuEngine3dReg.CullFace);
|
2018-07-05 20:47:29 +02:00
|
|
|
}
|
2018-06-27 06:32:28 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void SetDepth(GalPipelineState state)
|
2018-06-27 06:32:28 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
state.DepthTestEnabled = ReadRegisterBool(NvGpuEngine3dReg.DepthTestEnable);
|
2018-09-20 03:02:11 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
state.DepthWriteEnabled = ReadRegisterBool(NvGpuEngine3dReg.DepthWriteEnable);
|
2018-07-05 20:47:29 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (state.DepthTestEnabled)
|
2018-07-05 20:47:29 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
state.DepthFunc = (GalComparisonOp)ReadRegister(NvGpuEngine3dReg.DepthTestFunction);
|
2018-07-05 20:47:29 +02:00
|
|
|
}
|
2018-10-23 21:04:08 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
state.DepthRangeNear = ReadRegisterFloat(NvGpuEngine3dReg.DepthRangeNNear);
|
|
|
|
state.DepthRangeFar = ReadRegisterFloat(NvGpuEngine3dReg.DepthRangeNFar);
|
2018-07-05 20:47:29 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void SetStencil(GalPipelineState state)
|
2018-07-05 20:47:29 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
state.StencilTestEnabled = ReadRegisterBool(NvGpuEngine3dReg.StencilEnable);
|
2018-08-13 23:22:09 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (state.StencilTestEnabled)
|
2018-08-10 06:09:40 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
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 20:47:29 +02:00
|
|
|
}
|
2018-06-27 06:32:28 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void SetScissor(GalPipelineState state)
|
2019-01-13 22:26:42 +01:00
|
|
|
{
|
2019-03-02 11:50:21 +01:00
|
|
|
int count = 0;
|
2019-01-13 22:26:42 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
for (int index = 0; index < GalPipelineState.RenderTargetsCount; index++)
|
2019-01-13 22:26:42 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
state.ScissorTestEnabled[index] = ReadRegisterBool(NvGpuEngine3dReg.ScissorEnable + index * 4);
|
2019-01-13 22:26:42 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (state.ScissorTestEnabled[index])
|
2019-01-13 22:26:42 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
uint scissorHorizontal = (uint)ReadRegister(NvGpuEngine3dReg.ScissorHorizontal + index * 4);
|
|
|
|
uint scissorVertical = (uint)ReadRegister(NvGpuEngine3dReg.ScissorVertical + index * 4);
|
2019-01-13 22:26:42 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int left = (int)(scissorHorizontal & 0xFFFF); // Left, lower 16 bits
|
|
|
|
int right = (int)(scissorHorizontal >> 16); // Right, upper 16 bits
|
2019-01-13 22:26:42 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int bottom = (int)(scissorVertical & 0xFFFF); // Bottom, lower 16 bits
|
|
|
|
int top = (int)(scissorVertical >> 16); // Top, upper 16 bits
|
2019-01-13 22:26:42 +01:00
|
|
|
|
2019-03-02 11:50:21 +01:00
|
|
|
int width = Math.Abs(right - left);
|
|
|
|
int height = Math.Abs(top - bottom);
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
// If the scissor test covers the whole possible viewport, i.e. uninitialized, disable scissor test
|
2019-03-02 11:50:21 +01:00
|
|
|
if ((width > NvGpu.MaxViewportSize && height > NvGpu.MaxViewportSize) || width <= 0 || height <= 0)
|
2019-01-13 22:26:42 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
state.ScissorTestEnabled[index] = false;
|
2019-03-02 11:50:21 +01:00
|
|
|
continue;
|
|
|
|
}
|
2019-02-01 02:37:07 +01:00
|
|
|
|
2019-03-02 11:50:21 +01:00
|
|
|
// Keep track of how many scissor tests are active.
|
|
|
|
// If only 1, and it's the first user should apply to all viewports
|
|
|
|
count++;
|
|
|
|
|
|
|
|
// Flip X
|
2019-03-04 02:45:25 +01:00
|
|
|
if (state.FlipX == -1)
|
2019-03-02 11:50:21 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
left = _viewportX1 - (left - _viewportX0);
|
|
|
|
right = _viewportX1 - (right - _viewportX0);
|
2019-03-02 11:50:21 +01:00
|
|
|
}
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-18 01:57:08 +02:00
|
|
|
|
2019-03-02 11:50:21 +01:00
|
|
|
// Ensure X is in the right order
|
|
|
|
if (left > right)
|
|
|
|
{
|
|
|
|
int temp = left;
|
|
|
|
left = right;
|
|
|
|
right = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flip Y
|
2019-03-04 02:45:25 +01:00
|
|
|
if (state.FlipY == -1)
|
2019-03-02 11:50:21 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
bottom = _viewportY1 - (bottom - _viewportY0);
|
|
|
|
top = _viewportY1 - (top - _viewportY0);
|
2019-01-13 22:26:42 +01:00
|
|
|
}
|
2019-03-02 11:50:21 +01:00
|
|
|
|
|
|
|
// Ensure Y is in the right order
|
|
|
|
if (bottom > top)
|
|
|
|
{
|
|
|
|
int temp = top;
|
|
|
|
top = bottom;
|
|
|
|
bottom = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle out of active viewport dimensions
|
2019-03-04 02:45:25 +01:00
|
|
|
left = Math.Clamp(left, _viewportX0, _viewportX1);
|
|
|
|
right = Math.Clamp(right, _viewportX0, _viewportX1);
|
|
|
|
top = Math.Clamp(top, _viewportY0, _viewportY1);
|
|
|
|
bottom = Math.Clamp(bottom, _viewportY0, _viewportY1);
|
2019-03-02 11:50:21 +01:00
|
|
|
|
|
|
|
// Save values to state
|
2019-03-04 02:45:25 +01:00
|
|
|
state.ScissorTestX[index] = left;
|
|
|
|
state.ScissorTestY[index] = bottom;
|
2019-03-02 11:50:21 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
state.ScissorTestWidth[index] = right - left;
|
|
|
|
state.ScissorTestHeight[index] = top - bottom;
|
2019-01-13 22:26:42 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-02 11:50:21 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
state.ScissorTestCount = count;
|
2019-01-13 22:26:42 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void SetBlending(GalPipelineState state)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
bool blendIndependent = ReadRegisterBool(NvGpuEngine3dReg.BlendIndependent);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
state.BlendIndependent = blendIndependent;
|
2018-11-01 05:22:24 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
for (int index = 0; index < GalPipelineState.RenderTargetsCount; index++)
|
2018-06-02 05:50:56 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
if (blendIndependent)
|
2018-11-01 05:22:24 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
state.Blends[index].Enabled = ReadRegisterBool(NvGpuEngine3dReg.IBlendNEnable + index);
|
2018-11-01 05:22:24 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (state.Blends[index].Enabled)
|
2018-11-01 05:22:24 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
state.Blends[index].SeparateAlpha = ReadRegisterBool(NvGpuEngine3dReg.IBlendNSeparateAlpha + index * 8);
|
|
|
|
|
|
|
|
state.Blends[index].EquationRgb = ReadBlendEquation(NvGpuEngine3dReg.IBlendNEquationRgb + index * 8);
|
|
|
|
state.Blends[index].FuncSrcRgb = ReadBlendFactor (NvGpuEngine3dReg.IBlendNFuncSrcRgb + index * 8);
|
|
|
|
state.Blends[index].FuncDstRgb = ReadBlendFactor (NvGpuEngine3dReg.IBlendNFuncDstRgb + index * 8);
|
|
|
|
state.Blends[index].EquationAlpha = ReadBlendEquation(NvGpuEngine3dReg.IBlendNEquationAlpha + index * 8);
|
|
|
|
state.Blends[index].FuncSrcAlpha = ReadBlendFactor (NvGpuEngine3dReg.IBlendNFuncSrcAlpha + index * 8);
|
|
|
|
state.Blends[index].FuncDstAlpha = ReadBlendFactor (NvGpuEngine3dReg.IBlendNFuncDstAlpha + index * 8);
|
2018-11-01 05:22:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//It seems that even when independent blend is disabled, the first IBlend enable
|
|
|
|
//register is still set to indicate whenever blend is enabled or not (?).
|
2019-03-04 02:45:25 +01:00
|
|
|
state.Blends[index].Enabled = ReadRegisterBool(NvGpuEngine3dReg.IBlendNEnable);
|
2018-11-01 05:22:24 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (state.Blends[index].Enabled)
|
2018-11-01 05:22:24 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
state.Blends[index].SeparateAlpha = ReadRegisterBool(NvGpuEngine3dReg.BlendSeparateAlpha);
|
|
|
|
|
|
|
|
state.Blends[index].EquationRgb = ReadBlendEquation(NvGpuEngine3dReg.BlendEquationRgb);
|
|
|
|
state.Blends[index].FuncSrcRgb = ReadBlendFactor (NvGpuEngine3dReg.BlendFuncSrcRgb);
|
|
|
|
state.Blends[index].FuncDstRgb = ReadBlendFactor (NvGpuEngine3dReg.BlendFuncDstRgb);
|
|
|
|
state.Blends[index].EquationAlpha = ReadBlendEquation(NvGpuEngine3dReg.BlendEquationAlpha);
|
|
|
|
state.Blends[index].FuncSrcAlpha = ReadBlendFactor (NvGpuEngine3dReg.BlendFuncSrcAlpha);
|
|
|
|
state.Blends[index].FuncDstAlpha = ReadBlendFactor (NvGpuEngine3dReg.BlendFuncDstAlpha);
|
2018-11-01 05:22:24 +01:00
|
|
|
}
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private GalBlendEquation ReadBlendEquation(NvGpuEngine3dReg register)
|
2018-11-01 05:22:24 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return (GalBlendEquation)ReadRegister(register);
|
2018-11-01 05:22:24 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private GalBlendFactor ReadBlendFactor(NvGpuEngine3dReg register)
|
2018-11-01 05:22:24 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return (GalBlendFactor)ReadRegister(register);
|
2018-11-01 05:22:24 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void SetColorMask(GalPipelineState state)
|
2018-10-14 04:54:14 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
bool colorMaskCommon = ReadRegisterBool(NvGpuEngine3dReg.ColorMaskCommon);
|
2018-10-14 04:54:14 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
state.ColorMaskCommon = colorMaskCommon;
|
2018-10-17 23:02:23 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
for (int index = 0; index < GalPipelineState.RenderTargetsCount; index++)
|
2018-10-17 23:02:23 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
int colorMask = ReadRegister(NvGpuEngine3dReg.ColorMaskN + (colorMaskCommon ? 0 : index));
|
2018-10-17 23:02:23 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
state.ColorMasks[index].Red = ((colorMask >> 0) & 0xf) != 0;
|
|
|
|
state.ColorMasks[index].Green = ((colorMask >> 4) & 0xf) != 0;
|
|
|
|
state.ColorMasks[index].Blue = ((colorMask >> 8) & 0xf) != 0;
|
|
|
|
state.ColorMasks[index].Alpha = ((colorMask >> 12) & 0xf) != 0;
|
2018-10-17 23:02:23 +02:00
|
|
|
}
|
2018-10-14 04:54:14 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void SetPrimitiveRestart(GalPipelineState state)
|
2018-07-08 18:14:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
state.PrimitiveRestartEnabled = ReadRegisterBool(NvGpuEngine3dReg.PrimRestartEnable);
|
2018-07-08 18:14:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (state.PrimitiveRestartEnabled)
|
2018-07-08 18:14:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
state.PrimitiveRestartIndex = (uint)ReadRegister(NvGpuEngine3dReg.PrimRestartIndex);
|
2018-07-08 18:14:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-23 07:07:23 +02:00
|
|
|
private void SetRenderTargets()
|
|
|
|
{
|
2018-10-13 03:37:01 +02:00
|
|
|
//Commercial games do not seem to
|
2018-09-26 00:55:30 +02:00
|
|
|
//bool SeparateFragData = ReadRegisterBool(NvGpuEngine3dReg.RTSeparateFragData);
|
2018-08-23 07:07:23 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
uint control = (uint)(ReadRegister(NvGpuEngine3dReg.RtControl));
|
2018-08-23 07:07:23 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
uint count = control & 0xf;
|
2018-08-23 07:07:23 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (count > 0)
|
2018-09-26 00:55:30 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
int[] map = new int[count];
|
2018-08-23 07:07:23 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
for (int index = 0; index < count; index++)
|
2018-08-23 07:07:23 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
int shift = 4 + index * 3;
|
2018-08-23 07:07:23 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
map[index] = (int)((control >> shift) & 7);
|
2018-08-23 07:07:23 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.RenderTarget.SetMap(map);
|
2018-08-23 07:07:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.RenderTarget.SetMap(null);
|
2018-08-23 07:07:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void UploadTextures(NvGpuVmm vmm, GalPipelineState state, long[] keys)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
long baseShPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.ShaderAddress);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int textureCbIndex = ReadRegister(NvGpuEngine3dReg.TextureCbIndex);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
List<(long, GalImage, GalTextureSampler)> unboundTextures = new List<(long, GalImage, GalTextureSampler)>();
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
for (int index = 0; index < keys.Length; index++)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-18 01:57:08 +02:00
|
|
|
foreach (TextureDescriptor desc in _gpu.Renderer.Shader.GetTextureUsage(keys[index]))
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-18 01:57:08 +02:00
|
|
|
int textureHandle;
|
2018-08-13 23:22:09 +02:00
|
|
|
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-18 01:57:08 +02:00
|
|
|
if (desc.IsBindless)
|
2018-08-13 23:22:09 +02:00
|
|
|
{
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-18 01:57:08 +02:00
|
|
|
long position = _constBuffers[index][desc.CbufSlot].Position;
|
|
|
|
|
|
|
|
textureHandle = vmm.ReadInt32(position + desc.CbufOffset * 4);
|
2018-08-13 23:22:09 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-18 01:57:08 +02:00
|
|
|
long position = _constBuffers[index][textureCbIndex].Position;
|
2018-08-13 23:22:09 +02:00
|
|
|
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-18 01:57:08 +02:00
|
|
|
textureHandle = vmm.ReadInt32(position + desc.HandleIndex * 4);
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
unboundTextures.Add(UploadTexture(vmm, textureHandle));
|
2018-12-03 03:38:47 +01:00
|
|
|
}
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
for (int index = 0; index < unboundTextures.Count; index++)
|
2018-12-03 03:38:47 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
(long key, GalImage image, GalTextureSampler sampler) = unboundTextures[index];
|
2018-12-03 03:38:47 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (key == 0)
|
2018-12-03 03:38:47 +01:00
|
|
|
{
|
|
|
|
continue;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
2018-12-03 03:38:47 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Texture.Bind(key, index, image);
|
|
|
|
_gpu.Renderer.Texture.SetSampler(image, sampler);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private (long, GalImage, GalTextureSampler) UploadTexture(NvGpuVmm vmm, int textureHandle)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
if (textureHandle == 0)
|
2018-06-23 07:00:44 +02:00
|
|
|
{
|
2018-11-01 05:22:24 +01:00
|
|
|
//FIXME: Some games like puyo puyo will use handles with the value 0.
|
|
|
|
//This is a bug, most likely caused by sync issues.
|
2018-12-03 03:38:47 +01:00
|
|
|
return (0, default(GalImage), default(GalTextureSampler));
|
2018-06-23 07:00:44 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool linkedTsc = ReadRegisterBool(NvGpuEngine3dReg.LinkedTsc);
|
2018-11-17 05:01:31 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int ticIndex = (textureHandle >> 0) & 0xfffff;
|
2018-11-17 05:01:31 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int tscIndex = linkedTsc ? ticIndex : (textureHandle >> 20) & 0xfff;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long ticPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.TexHeaderPoolOffset);
|
|
|
|
long tscPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.TexSamplerPoolOffset);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ticPosition += ticIndex * 0x20;
|
|
|
|
tscPosition += tscIndex * 0x20;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
GalImage image = TextureFactory.MakeTexture(vmm, ticPosition);
|
2018-09-18 06:30:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
GalTextureSampler sampler = TextureFactory.MakeSampler(_gpu, vmm, tscPosition);
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long key = vmm.ReadInt64(ticPosition + 4) & 0xffffffffffff;
|
2018-04-13 20:12:58 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (image.Layout == GalMemoryLayout.BlockLinear)
|
2018-08-15 20:59:51 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
key &= ~0x1ffL;
|
2018-08-15 20:59:51 +02:00
|
|
|
}
|
2019-03-04 02:45:25 +01:00
|
|
|
else if (image.Layout == GalMemoryLayout.Pitch)
|
2018-04-13 20:12:58 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
key &= ~0x1fL;
|
2018-04-13 20:12:58 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
key = vmm.GetPhysicalAddress(key);
|
2018-06-09 02:15:56 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (key == -1)
|
2018-09-18 06:30:35 +02:00
|
|
|
{
|
|
|
|
//FIXME: Shouldn't ignore invalid addresses.
|
2018-12-03 03:38:47 +01:00
|
|
|
return (0, default(GalImage), default(GalTextureSampler));
|
2018-04-13 20:12:58 +02:00
|
|
|
}
|
2018-06-24 02:39:25 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.ResourceManager.SendTexture(vmm, key, image);
|
2018-09-18 06:30:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return (key, image, sampler);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void UploadConstBuffers(NvGpuVmm vmm, GalPipelineState state, long[] keys)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
for (int stage = 0; stage < keys.Length; stage++)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-18 01:57:08 +02:00
|
|
|
foreach (CBufferDescriptor desc in _gpu.Renderer.Shader.GetConstBufferUsage(keys[stage]))
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-18 01:57:08 +02:00
|
|
|
ConstBuffer cb = _constBuffers[stage][desc.Slot];
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (!cb.Enabled)
|
2018-08-15 20:59:51 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long key = vmm.GetPhysicalAddress(cb.Position);
|
2018-08-15 20:59:51 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (_gpu.ResourceManager.MemoryRegionModified(vmm, key, cb.Size, NvGpuBufferType.ConstBuffer))
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
if (vmm.TryGetHostAddress(cb.Position, cb.Size, out IntPtr cbPtr))
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Buffer.SetData(key, cb.Size, cbPtr);
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Buffer.SetData(key, vmm.ReadBytes(cb.Position, cb.Size));
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
2018-08-10 06:09:40 +02:00
|
|
|
|
New shader translator implementation (#654)
* Start implementing a new shader translator
* Fix shift instructions and a typo
* Small refactoring on StructuredProgram, move RemovePhis method to a separate class
* Initial geometry shader support
* Implement TLD4
* Fix -- There's no negation on FMUL32I
* Add constant folding and algebraic simplification optimizations, nits
* Some leftovers from constant folding
* Avoid cast for constant assignments
* Add a branch elimination pass, and misc small fixes
* Remove redundant branches, add expression propagation and other improvements on the code
* Small leftovers -- add missing break and continue, remove unused properties, other improvements
* Add null check to handle empty block cases on block visitor
* Add HADD2 and HMUL2 half float shader instructions
* Optimize pack/unpack sequences, some fixes related to half float instructions
* Add TXQ, TLD, TLDS and TLD4S shader texture instructions, and some support for bindless textures, some refactoring on codegen
* Fix copy paste mistake that caused RZ to be ignored on the AST instruction
* Add workaround for conditional exit, and fix half float instruction with constant buffer
* Add missing 0.0 source for TLDS.LZ variants
* Simplify the switch for TLDS.LZ
* Texture instructions related fixes
* Implement the HFMA instruction, and some misc. fixes
* Enable constant folding on UnpackHalf2x16 instructions
* Refactor HFMA to use OpCode* for opcode decoding rather than on the helper methods
* Remove the old shader translator
* Remove ShaderDeclInfo and other unused things
* Add dual vertex shader support
* Add ShaderConfig, used to pass shader type and maximum cbuffer size
* Move and rename some instruction enums
* Move texture instructions into a separate file
* Move operand GetExpression and locals management to OperandManager
* Optimize opcode decoding using a simple list and binary search
* Add missing condition for do-while on goto elimination
* Misc. fixes on texture instructions
* Simplify TLDS switch
* Address PR feedback, and a nit
2019-04-18 01:57:08 +02:00
|
|
|
state.ConstBufferKeys[stage][desc.Slot] = key;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void UploadVertexArrays(NvGpuVmm vmm, GalPipelineState state)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
long ibPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.IndexArrayAddress);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long iboKey = vmm.GetPhysicalAddress(ibPosition);
|
2018-07-08 21:55:15 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int indexEntryFmt = ReadRegister(NvGpuEngine3dReg.IndexArrayFormat);
|
|
|
|
int indexCount = ReadRegister(NvGpuEngine3dReg.IndexBatchCount);
|
|
|
|
int primCtrl = ReadRegister(NvGpuEngine3dReg.VertexBeginGl);
|
2018-10-13 03:37:01 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
GalPrimitiveType primType = (GalPrimitiveType)(primCtrl & 0xffff);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
GalIndexFormat indexFormat = (GalIndexFormat)indexEntryFmt;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int indexEntrySize = 1 << indexEntryFmt;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (indexEntrySize > 4)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new InvalidOperationException("Invalid index entry size \"" + indexEntrySize + "\"!");
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (indexCount != 0)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
int ibSize = indexCount * indexEntrySize;
|
2018-06-09 02:15:56 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool iboCached = _gpu.Renderer.Rasterizer.IsIboCached(iboKey, (uint)ibSize);
|
2018-06-09 02:15:56 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool usesLegacyQuads =
|
|
|
|
primType == GalPrimitiveType.Quads ||
|
|
|
|
primType == GalPrimitiveType.QuadStrip;
|
2018-10-13 03:37:01 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (!iboCached || _gpu.ResourceManager.MemoryRegionModified(vmm, iboKey, (uint)ibSize, NvGpuBufferType.Index))
|
2018-06-09 02:15:56 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
if (!usesLegacyQuads)
|
2018-10-13 03:37:01 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
if (vmm.TryGetHostAddress(ibPosition, ibSize, out IntPtr ibPtr))
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Rasterizer.CreateIbo(iboKey, ibSize, ibPtr);
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Rasterizer.CreateIbo(iboKey, ibSize, vmm.ReadBytes(ibPosition, ibSize));
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
2018-10-13 03:37:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
byte[] buffer = vmm.ReadBytes(ibPosition, ibSize);
|
2018-10-13 03:37:01 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (primType == GalPrimitiveType.Quads)
|
2018-10-13 03:37:01 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
buffer = QuadHelper.ConvertQuadsToTris(buffer, indexEntrySize, indexCount);
|
2018-10-13 03:37:01 +02:00
|
|
|
}
|
|
|
|
else /* if (PrimType == GalPrimitiveType.QuadStrip) */
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
buffer = QuadHelper.ConvertQuadStripToTris(buffer, indexEntrySize, indexCount);
|
2018-10-13 03:37:01 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Rasterizer.CreateIbo(iboKey, ibSize, buffer);
|
2018-10-13 03:37:01 +02:00
|
|
|
}
|
2018-06-09 02:15:56 +02:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (!usesLegacyQuads)
|
2018-10-13 03:37:01 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Rasterizer.SetIndexArray(ibSize, indexFormat);
|
2018-10-13 03:37:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
if (primType == GalPrimitiveType.Quads)
|
2018-10-13 03:37:01 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Rasterizer.SetIndexArray(QuadHelper.ConvertSizeQuadsToTris(ibSize), indexFormat);
|
2018-10-13 03:37:01 +02:00
|
|
|
}
|
|
|
|
else /* if (PrimType == GalPrimitiveType.QuadStrip) */
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Rasterizer.SetIndexArray(QuadHelper.ConvertSizeQuadStripToTris(ibSize), indexFormat);
|
2018-10-13 03:37:01 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
List<GalVertexAttrib>[] attribs = new List<GalVertexAttrib>[32];
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
for (int attr = 0; attr < 16; attr++)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
int packed = ReadRegister(NvGpuEngine3dReg.VertexAttribNFormat + attr);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int arrayIndex = packed & 0x1f;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (attribs[arrayIndex] == null)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
attribs[arrayIndex] = new List<GalVertexAttrib>();
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long vbPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.VertexArrayNAddress + arrayIndex * 4);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (vbPosition == 0)
|
2018-12-26 20:29:50 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool isConst = ((packed >> 6) & 1) != 0;
|
2018-10-13 03:37:01 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int offset = (packed >> 7) & 0x3fff;
|
2018-10-13 03:37:01 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
GalVertexAttribSize size = (GalVertexAttribSize)((packed >> 21) & 0x3f);
|
|
|
|
GalVertexAttribType type = (GalVertexAttribType)((packed >> 27) & 0x7);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool isRgba = ((packed >> 31) & 1) != 0;
|
2019-02-04 22:26:05 +01:00
|
|
|
|
2019-01-18 19:31:25 +01:00
|
|
|
// Check vertex array is enabled to avoid out of bounds exception when reading bytes
|
2019-03-04 02:45:25 +01:00
|
|
|
bool enable = (ReadRegister(NvGpuEngine3dReg.VertexArrayNControl + arrayIndex * 4) & 0x1000) != 0;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-10-13 03:37:01 +02:00
|
|
|
//Note: 16 is the maximum size of an attribute,
|
|
|
|
//having a component size of 32-bits with 4 elements (a vec4).
|
2019-03-04 02:45:25 +01:00
|
|
|
if (enable)
|
2019-01-18 19:31:25 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
byte[] data = vmm.ReadBytes(vbPosition + offset, 16);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
attribs[arrayIndex].Add(new GalVertexAttrib(attr, isConst, offset, data, size, type, isRgba));
|
2019-01-18 19:31:25 +01:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
state.VertexBindings = new GalVertexBinding[32];
|
2018-06-09 02:15:56 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
for (int index = 0; index < 32; index++)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
if (attribs[index] == null)
|
2018-06-09 02:15:56 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int control = ReadRegister(NvGpuEngine3dReg.VertexArrayNControl + index * 4);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool enable = (control & 0x1000) != 0;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (!enable)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long vbPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.VertexArrayNAddress + index * 4);
|
|
|
|
long vbEndPos = MakeInt64From2xInt32(NvGpuEngine3dReg.VertexArrayNEndAddr + index * 2);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int vertexDivisor = ReadRegister(NvGpuEngine3dReg.VertexArrayNDivisor + index * 4);
|
2018-08-25 06:16:58 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool instanced = ReadRegisterBool(NvGpuEngine3dReg.VertexArrayNInstance + index);
|
2018-07-08 21:55:15 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int stride = control & 0xfff;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (instanced && vertexDivisor != 0)
|
2018-08-25 06:16:58 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
vbPosition += stride * (_currentInstance / vertexDivisor);
|
2018-08-25 06:16:58 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (vbPosition > vbEndPos)
|
2018-08-25 06:16:58 +02:00
|
|
|
{
|
|
|
|
//Instance is invalid, ignore the draw call
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long vboKey = vmm.GetPhysicalAddress(vbPosition);
|
2018-08-25 06:16:58 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long vbSize = (vbEndPos - vbPosition) + 1;
|
|
|
|
int modifiedVbSize = (int)vbSize;
|
2018-04-29 22:58:38 +02:00
|
|
|
|
2019-01-01 18:08:15 +01:00
|
|
|
|
|
|
|
// If quads convert size to triangle length
|
2019-03-04 02:45:25 +01:00
|
|
|
if (stride == 0)
|
2019-01-01 18:08:15 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
if (primType == GalPrimitiveType.Quads)
|
2019-01-01 18:08:15 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
modifiedVbSize = QuadHelper.ConvertSizeQuadsToTris(modifiedVbSize);
|
2019-01-01 18:08:15 +01:00
|
|
|
}
|
2019-03-04 02:45:25 +01:00
|
|
|
else if (primType == GalPrimitiveType.QuadStrip)
|
2019-01-01 18:08:15 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
modifiedVbSize = QuadHelper.ConvertSizeQuadStripToTris(modifiedVbSize);
|
2019-01-01 18:08:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool vboCached = _gpu.Renderer.Rasterizer.IsVboCached(vboKey, modifiedVbSize);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (!vboCached || _gpu.ResourceManager.MemoryRegionModified(vmm, vboKey, vbSize, NvGpuBufferType.Vertex))
|
2018-06-09 02:15:56 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
if ((primType == GalPrimitiveType.Quads | primType == GalPrimitiveType.QuadStrip) && stride != 0)
|
2019-01-01 18:08:15 +01:00
|
|
|
{
|
|
|
|
// Convert quad buffer to triangles
|
2019-03-04 02:45:25 +01:00
|
|
|
byte[] data = vmm.ReadBytes(vbPosition, vbSize);
|
2019-01-01 18:08:15 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (primType == GalPrimitiveType.Quads)
|
2019-01-01 18:08:15 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
data = QuadHelper.ConvertQuadsToTris(data, stride, (int)(vbSize / stride));
|
2019-01-01 18:08:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
data = QuadHelper.ConvertQuadStripToTris(data, stride, (int)(vbSize / stride));
|
2019-01-01 18:08:15 +01:00
|
|
|
}
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Rasterizer.CreateVbo(vboKey, data);
|
2019-01-01 18:08:15 +01:00
|
|
|
}
|
2019-03-04 02:45:25 +01:00
|
|
|
else if (vmm.TryGetHostAddress(vbPosition, vbSize, out IntPtr vbPtr))
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Rasterizer.CreateVbo(vboKey, (int)vbSize, vbPtr);
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Rasterizer.CreateVbo(vboKey, vmm.ReadBytes(vbPosition, vbSize));
|
2018-11-28 23:18:09 +01:00
|
|
|
}
|
2018-06-09 02:15:56 +02:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
state.VertexBindings[index].Enabled = true;
|
|
|
|
state.VertexBindings[index].Stride = stride;
|
|
|
|
state.VertexBindings[index].VboKey = vboKey;
|
|
|
|
state.VertexBindings[index].Instanced = instanced;
|
|
|
|
state.VertexBindings[index].Divisor = vertexDivisor;
|
|
|
|
state.VertexBindings[index].Attribs = attribs[index].ToArray();
|
2018-06-09 02:15:56 +02:00
|
|
|
}
|
2018-08-10 06:09:40 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void DispatchRender(NvGpuVmm vmm, GalPipelineState state)
|
2018-08-10 06:09:40 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
int indexCount = ReadRegister(NvGpuEngine3dReg.IndexBatchCount);
|
|
|
|
int primCtrl = ReadRegister(NvGpuEngine3dReg.VertexBeginGl);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
GalPrimitiveType primType = (GalPrimitiveType)(primCtrl & 0xffff);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool instanceNext = ((primCtrl >> 26) & 1) != 0;
|
|
|
|
bool instanceCont = ((primCtrl >> 27) & 1) != 0;
|
2018-08-25 06:16:58 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (instanceNext && instanceCont)
|
2018-08-25 06:16:58 +02:00
|
|
|
{
|
|
|
|
throw new InvalidOperationException("GPU tried to increase and reset instance count at the same time");
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (instanceNext)
|
2018-08-25 06:16:58 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_currentInstance++;
|
2018-08-25 06:16:58 +02:00
|
|
|
}
|
2019-03-04 02:45:25 +01:00
|
|
|
else if (!instanceCont)
|
2018-08-25 06:16:58 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_currentInstance = 0;
|
2018-08-25 06:16:58 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
state.Instance = _currentInstance;
|
2018-08-25 06:16:58 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Pipeline.Bind(state);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.RenderTarget.Bind();
|
2018-09-26 00:55:30 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (indexCount != 0)
|
2018-06-09 02:15:56 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
int indexEntryFmt = ReadRegister(NvGpuEngine3dReg.IndexArrayFormat);
|
|
|
|
int indexFirst = ReadRegister(NvGpuEngine3dReg.IndexBatchFirst);
|
|
|
|
int vertexBase = ReadRegister(NvGpuEngine3dReg.VertexArrayElemBase);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long indexPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.IndexArrayAddress);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long iboKey = vmm.GetPhysicalAddress(indexPosition);
|
2018-06-29 01:48:18 +02:00
|
|
|
|
2018-10-13 03:37:01 +02:00
|
|
|
//Quad primitive types were deprecated on OpenGL 3.x,
|
|
|
|
//they are converted to a triangles index buffer on IB creation,
|
|
|
|
//so we should use the triangles type here too.
|
2019-03-04 02:45:25 +01:00
|
|
|
if (primType == GalPrimitiveType.Quads || primType == GalPrimitiveType.QuadStrip)
|
2018-10-13 03:37:01 +02:00
|
|
|
{
|
|
|
|
//Note: We assume that index first points to the first
|
|
|
|
//vertex of a quad, if it points to the middle of a
|
|
|
|
//quad (First % 4 != 0 for Quads) then it will not work properly.
|
2019-03-04 02:45:25 +01:00
|
|
|
if (primType == GalPrimitiveType.Quads)
|
2018-10-13 03:37:01 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
indexFirst = QuadHelper.ConvertSizeQuadsToTris(indexFirst);
|
2018-10-13 03:37:01 +02:00
|
|
|
}
|
2019-01-01 18:08:15 +01:00
|
|
|
else // QuadStrip
|
2018-10-13 03:37:01 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
indexFirst = QuadHelper.ConvertSizeQuadStripToTris(indexFirst);
|
2018-10-13 03:37:01 +02:00
|
|
|
}
|
2019-01-01 18:08:15 +01:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
primType = GalPrimitiveType.Triangles;
|
2018-10-13 03:37:01 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Rasterizer.DrawElements(iboKey, indexFirst, vertexBase, primType);
|
2018-06-09 02:15:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
int vertexFirst = ReadRegister(NvGpuEngine3dReg.VertexArrayFirst);
|
|
|
|
int vertexCount = ReadRegister(NvGpuEngine3dReg.VertexArrayCount);
|
2018-08-10 06:09:40 +02:00
|
|
|
|
2019-01-01 18:08:15 +01:00
|
|
|
//Quad primitive types were deprecated on OpenGL 3.x,
|
|
|
|
//they are converted to a triangles index buffer on IB creation,
|
|
|
|
//so we should use the triangles type here too.
|
2019-03-04 02:45:25 +01:00
|
|
|
if (primType == GalPrimitiveType.Quads || primType == GalPrimitiveType.QuadStrip)
|
2019-01-01 18:08:15 +01:00
|
|
|
{
|
|
|
|
//Note: We assume that index first points to the first
|
|
|
|
//vertex of a quad, if it points to the middle of a
|
|
|
|
//quad (First % 4 != 0 for Quads) then it will not work properly.
|
2019-03-04 02:45:25 +01:00
|
|
|
if (primType == GalPrimitiveType.Quads)
|
2019-01-01 18:08:15 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
vertexFirst = QuadHelper.ConvertSizeQuadsToTris(vertexFirst);
|
2019-01-01 18:08:15 +01:00
|
|
|
}
|
|
|
|
else // QuadStrip
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
vertexFirst = QuadHelper.ConvertSizeQuadStripToTris(vertexFirst);
|
2019-01-01 18:08:15 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
primType = GalPrimitiveType.Triangles;
|
|
|
|
vertexCount = QuadHelper.ConvertSizeQuadsToTris(vertexCount);
|
2019-01-01 18:08:15 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Rasterizer.DrawArrays(vertexFirst, vertexCount, primType);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
2018-08-13 23:22:09 +02:00
|
|
|
|
2019-03-02 11:50:21 +01:00
|
|
|
// Reset pipeline for host OpenGL calls
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Pipeline.Unbind(state);
|
2019-03-02 11:50:21 +01:00
|
|
|
|
2018-08-13 23:22:09 +02:00
|
|
|
//Is the GPU really clearing those registers after draw?
|
|
|
|
WriteRegister(NvGpuEngine3dReg.IndexBatchFirst, 0);
|
|
|
|
WriteRegister(NvGpuEngine3dReg.IndexBatchCount, 0);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-09-01 16:54:56 +02:00
|
|
|
private enum QueryMode
|
|
|
|
{
|
|
|
|
WriteSeq,
|
|
|
|
Sync,
|
|
|
|
WriteCounterAndTimestamp
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void QueryControl(NvGpuVmm vmm, GpuMethodCall methCall)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
WriteRegister(methCall);
|
2018-09-01 16:54:56 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long position = MakeInt64From2xInt32(NvGpuEngine3dReg.QueryAddress);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int seq = Registers[(int)NvGpuEngine3dReg.QuerySequence];
|
|
|
|
int ctrl = Registers[(int)NvGpuEngine3dReg.QueryControl];
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
QueryMode mode = (QueryMode)(ctrl & 3);
|
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
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (mode)
|
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
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
case QueryMode.WriteSeq: vmm.WriteInt32(position, seq); break;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-01 16:54:56 +02:00
|
|
|
case QueryMode.WriteCounterAndTimestamp:
|
|
|
|
{
|
|
|
|
//TODO: Implement counters.
|
2019-03-04 02:45:25 +01:00
|
|
|
long counter = 1;
|
2018-09-01 16:54:56 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long timestamp = PerformanceCounter.ElapsedMilliseconds;
|
2018-09-01 16:54:56 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
vmm.WriteInt64(position + 0, counter);
|
|
|
|
vmm.WriteInt64(position + 8, timestamp);
|
2018-09-01 16:54:56 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void CbData(NvGpuVmm vmm, GpuMethodCall methCall)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
long position = MakeInt64From2xInt32(NvGpuEngine3dReg.ConstBufferAddress);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int offset = ReadRegister(NvGpuEngine3dReg.ConstBufferOffset);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
vmm.WriteInt32(position + offset, methCall.Argument);
|
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
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
WriteRegister(NvGpuEngine3dReg.ConstBufferOffset, offset + 4);
|
2018-08-15 03:27:05 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.ResourceManager.ClearPbCache(NvGpuBufferType.ConstBuffer);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void CbBind(NvGpuVmm vmm, GpuMethodCall methCall)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
int stage = (methCall.Method - 0x904) >> 3;
|
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
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int index = methCall.Argument;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool enabled = (index & 1) != 0;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
index = (index >> 4) & 0x1f;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long position = MakeInt64From2xInt32(NvGpuEngine3dReg.ConstBufferAddress);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
long cbKey = vmm.GetPhysicalAddress(position);
|
2018-08-15 20:59:51 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int size = ReadRegister(NvGpuEngine3dReg.ConstBufferSize);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (!_gpu.Renderer.Buffer.IsCached(cbKey, size))
|
2018-08-10 06:09:40 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gpu.Renderer.Buffer.Create(cbKey, size);
|
2018-08-10 06:09:40 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
ConstBuffer cb = _constBuffers[stage][index];
|
2018-08-10 06:09:40 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (cb.Position != position || cb.Enabled != enabled || cb.Size != size)
|
2018-08-10 06:09:40 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_constBuffers[stage][index].Position = position;
|
|
|
|
_constBuffers[stage][index].Enabled = enabled;
|
|
|
|
_constBuffers[stage][index].Size = size;
|
2018-08-10 06:09:40 +02:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private float GetFlipSign(NvGpuEngine3dReg reg)
|
2018-07-05 20:47:29 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return MathF.Sign(ReadRegisterFloat(reg));
|
2018-07-05 20:47:29 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private long MakeInt64From2xInt32(NvGpuEngine3dReg reg)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
return
|
2019-03-04 02:45:25 +01:00
|
|
|
(long)Registers[(int)reg + 0] << 32 |
|
|
|
|
(uint)Registers[(int)reg + 1];
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void WriteRegister(GpuMethodCall methCall)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
Registers[methCall.Method] = methCall.Argument;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private int ReadRegister(NvGpuEngine3dReg reg)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return Registers[(int)reg];
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private float ReadRegisterFloat(NvGpuEngine3dReg reg)
|
2018-07-05 20:47:29 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return BitConverter.Int32BitsToSingle(ReadRegister(reg));
|
2018-07-05 20:47:29 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private bool ReadRegisterBool(NvGpuEngine3dReg reg)
|
2018-09-20 03:02:11 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return (ReadRegister(reg) & 1) != 0;
|
2018-09-20 03:02:11 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private void WriteRegister(NvGpuEngine3dReg reg, int value)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
Registers[(int)reg] = value;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-23 07:07:23 +02:00
|
|
|
}
|