Some code cleanup

This commit is contained in:
gdkchan
2019-12-29 14:41:50 -03:00
committed by Thog
parent af8498d679
commit 654e617fe7
60 changed files with 432 additions and 591 deletions

View File

@ -1,4 +1,4 @@
using Ryujinx.Graphics.GAL.Texture;
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Gpu.Image;
using Ryujinx.Graphics.Gpu.Shader;
using Ryujinx.Graphics.Gpu.State;
@ -30,17 +30,17 @@ namespace Ryujinx.Graphics.Gpu.Engine
dispatchParams.UnpackBlockSizeY(),
dispatchParams.UnpackBlockSizeZ());
_context.Renderer.Pipeline.BindProgram(cs.HostProgram);
_context.Renderer.Pipeline.SetProgram(cs.HostProgram);
var samplerPool = state.Get<PoolState>(MethodOffset.SamplerPoolState);
_textureManager.SetComputeSamplerPool(samplerPool.Address.Pack(), samplerPool.MaximumId, dispatchParams.SamplerIndex);
TextureManager.SetComputeSamplerPool(samplerPool.Address.Pack(), samplerPool.MaximumId, dispatchParams.SamplerIndex);
var texturePool = state.Get<PoolState>(MethodOffset.TexturePoolState);
_textureManager.SetComputeTexturePool(texturePool.Address.Pack(), texturePool.MaximumId);
TextureManager.SetComputeTexturePool(texturePool.Address.Pack(), texturePool.MaximumId);
_textureManager.SetComputeTextureBufferIndex(state.Get<int>(MethodOffset.TextureBufferIndex));
TextureManager.SetComputeTextureBufferIndex(state.Get<int>(MethodOffset.TextureBufferIndex));
ShaderProgramInfo info = cs.Shader.Program.Info;
@ -57,7 +57,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
ulong gpuVa = dispatchParams.UniformBuffers[index].PackAddress();
ulong size = dispatchParams.UniformBuffers[index].UnpackSize();
_bufferManager.SetComputeUniformBuffer(index, gpuVa, size);
BufferManager.SetComputeUniformBuffer(index, gpuVa, size);
}
for (int index = 0; index < info.SBuffers.Count; index++)
@ -66,7 +66,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
sbEnableMask |= 1u << sb.Slot;
ulong sbDescAddress = _bufferManager.GetComputeUniformBufferAddress(0);
ulong sbDescAddress = BufferManager.GetComputeUniformBufferAddress(0);
int sbDescOffset = 0x310 + sb.Slot * 0x10;
@ -76,7 +76,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
SbDescriptor sbDescriptor = MemoryMarshal.Cast<byte, SbDescriptor>(sbDescriptorData)[0];
_bufferManager.SetComputeStorageBuffer(sb.Slot, sbDescriptor.PackAddress(), (uint)sbDescriptor.Size);
BufferManager.SetComputeStorageBuffer(sb.Slot, sbDescriptor.PackAddress(), (uint)sbDescriptor.Size);
}
ubEnableMask = 0;
@ -86,8 +86,8 @@ namespace Ryujinx.Graphics.Gpu.Engine
ubEnableMask |= 1u << info.CBuffers[index].Slot;
}
_bufferManager.SetComputeStorageBufferEnableMask(sbEnableMask);
_bufferManager.SetComputeUniformBufferEnableMask(ubEnableMask);
BufferManager.SetComputeStorageBufferEnableMask(sbEnableMask);
BufferManager.SetComputeUniformBufferEnableMask(ubEnableMask);
var textureBindings = new TextureBindingInfo[info.Textures.Count];
@ -107,7 +107,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
}
}
_textureManager.SetComputeTextures(textureBindings);
TextureManager.SetComputeTextures(textureBindings);
var imageBindings = new TextureBindingInfo[info.Images.Count];
@ -120,12 +120,12 @@ namespace Ryujinx.Graphics.Gpu.Engine
imageBindings[index] = new TextureBindingInfo(target, descriptor.HandleIndex);
}
_textureManager.SetComputeImages(imageBindings);
TextureManager.SetComputeImages(imageBindings);
_bufferManager.CommitComputeBindings();
_textureManager.CommitComputeBindings();
BufferManager.CommitComputeBindings();
TextureManager.CommitComputeBindings();
_context.Renderer.Pipeline.Dispatch(
_context.Renderer.Pipeline.DispatchCompute(
dispatchParams.UnpackGridSizeX(),
dispatchParams.UnpackGridSizeY(),
dispatchParams.UnpackGridSizeZ());

View File

@ -1,4 +1,4 @@
using Ryujinx.Graphics.GAL.Color;
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Gpu.State;
namespace Ryujinx.Graphics.Gpu.Engine
@ -9,7 +9,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
UpdateRenderTargetState(state, useControl: false);
_textureManager.CommitGraphicsBindings();
TextureManager.CommitGraphicsBindings();
bool clearDepth = (argument & 1) != 0;
bool clearStencil = (argument & 2) != 0;

View File

@ -68,7 +68,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
else
{
// Buffer to buffer copy.
_bufferManager.CopyBuffer(cbp.SrcAddress, cbp.DstAddress, (uint)size);
BufferManager.CopyBuffer(cbp.SrcAddress, cbp.DstAddress, (uint)size);
}
}
}

View File

@ -3,6 +3,8 @@ using Ryujinx.Graphics.Gpu.State;
namespace Ryujinx.Graphics.Gpu.Engine
{
using Texture = Image.Texture;
partial class Methods
{
private void CopyTexture(GpuState state, int argument)
@ -10,7 +12,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
var dstCopyTexture = state.Get<CopyTexture>(MethodOffset.CopyDstTexture);
var srcCopyTexture = state.Get<CopyTexture>(MethodOffset.CopySrcTexture);
Image.Texture srcTexture = _textureManager.FindOrCreateTexture(srcCopyTexture);
Texture srcTexture = TextureManager.FindOrCreateTexture(srcCopyTexture);
if (srcTexture == null)
{
@ -25,7 +27,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
dstCopyTexture.Format = RtFormat.D32Float;
}
Image.Texture dstTexture = _textureManager.FindOrCreateTexture(dstCopyTexture);
Texture dstTexture = TextureManager.FindOrCreateTexture(dstCopyTexture);
if (dstTexture == null)
{
@ -76,7 +78,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
srcCopyTexture.Height++;
srcTexture = _textureManager.FindOrCreateTexture(srcCopyTexture);
srcTexture = TextureManager.FindOrCreateTexture(srcCopyTexture);
srcRegion = new Extents2D(
srcRegion.X1 - srcTexture.Info.Width,

View File

@ -41,11 +41,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
ulong address = uniformBuffer.Address.Pack();
_bufferManager.SetGraphicsUniformBuffer((int)type, index, address, (uint)uniformBuffer.Size);
BufferManager.SetGraphicsUniformBuffer((int)type, index, address, (uint)uniformBuffer.Size);
}
else
{
_bufferManager.SetGraphicsUniformBuffer((int)type, index, 0, 0);
BufferManager.SetGraphicsUniformBuffer((int)type, index, 0, 0);
}
}
}

View File

@ -1,8 +1,5 @@
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.GAL.Blend;
using Ryujinx.Graphics.GAL.DepthStencil;
using Ryujinx.Graphics.GAL.InputAssembler;
using Ryujinx.Graphics.GAL.Texture;
using Ryujinx.Graphics.Gpu.Image;
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Gpu.Shader;
@ -13,19 +10,18 @@ using System.Runtime.InteropServices;
namespace Ryujinx.Graphics.Gpu.Engine
{
using Texture = Image.Texture;
partial class Methods
{
private GpuContext _context;
private readonly GpuContext _context;
private ShaderCache _shaderCache;
private readonly ShaderCache _shaderCache;
private ShaderProgramInfo[] _currentProgramInfo;
private readonly ShaderProgramInfo[] _currentProgramInfo;
private BufferManager _bufferManager;
private TextureManager _textureManager;
public BufferManager BufferManager => _bufferManager;
public TextureManager TextureManager => _textureManager;
public BufferManager BufferManager { get; }
public TextureManager TextureManager { get; }
private bool _isAnyVbInstanced;
private bool _vsUsesInstanceId;
@ -38,8 +34,8 @@ namespace Ryujinx.Graphics.Gpu.Engine
_currentProgramInfo = new ShaderProgramInfo[Constants.TotalShaderStages];
_bufferManager = new BufferManager(context);
_textureManager = new TextureManager(context);
BufferManager = new BufferManager(context);
TextureManager = new TextureManager(context);
}
public void RegisterCallbacks(GpuState state)
@ -183,8 +179,8 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
UpdateStorageBuffers();
_bufferManager.CommitBindings();
_textureManager.CommitGraphicsBindings();
BufferManager.CommitBindings();
TextureManager.CommitGraphicsBindings();
}
private void UpdateStorageBuffers()
@ -202,7 +198,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
BufferDescriptor sb = info.SBuffers[index];
ulong sbDescAddress = _bufferManager.GetGraphicsUniformBufferAddress(stage, 0);
ulong sbDescAddress = BufferManager.GetGraphicsUniformBufferAddress(stage, 0);
int sbDescOffset = 0x110 + stage * 0x100 + sb.Slot * 0x10;
@ -212,7 +208,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
SbDescriptor sbDescriptor = MemoryMarshal.Cast<byte, SbDescriptor>(sbDescriptorData)[0];
_bufferManager.SetGraphicsStorageBuffer(stage, sb.Slot, sbDescriptor.PackAddress(), (uint)sbDescriptor.Size);
BufferManager.SetGraphicsStorageBuffer(stage, sb.Slot, sbDescriptor.PackAddress(), (uint)sbDescriptor.Size);
}
}
}
@ -236,17 +232,14 @@ namespace Ryujinx.Graphics.Gpu.Engine
if (index >= count || !IsRtEnabled(colorState))
{
_textureManager.SetRenderTargetColor(index, null);
TextureManager.SetRenderTargetColor(index, null);
continue;
}
Image.Texture color = _textureManager.FindOrCreateTexture(
colorState,
samplesInX,
samplesInY);
Texture color = TextureManager.FindOrCreateTexture(colorState, samplesInX, samplesInY);
_textureManager.SetRenderTargetColor(index, color);
TextureManager.SetRenderTargetColor(index, color);
if (color != null)
{
@ -256,21 +249,17 @@ namespace Ryujinx.Graphics.Gpu.Engine
bool dsEnable = state.Get<Boolean32>(MethodOffset.RtDepthStencilEnable);
Image.Texture depthStencil = null;
Texture depthStencil = null;
if (dsEnable)
{
var dsState = state.Get<RtDepthStencilState>(MethodOffset.RtDepthStencilState);
var dsSize = state.Get<Size3D> (MethodOffset.RtDepthStencilSize);
depthStencil = _textureManager.FindOrCreateTexture(
dsState,
dsSize,
samplesInX,
samplesInY);
depthStencil = TextureManager.FindOrCreateTexture(dsState, dsSize, samplesInX, samplesInY);
}
_textureManager.SetRenderTargetDepthStencil(depthStencil);
TextureManager.SetRenderTargetDepthStencil(depthStencil);
if (depthStencil != null)
{
@ -335,8 +324,8 @@ namespace Ryujinx.Graphics.Gpu.Engine
// the maximum supported viewport dimensions.
// This must be compensated on the shader, by dividing the vertex position
// by the maximum viewport dimensions.
float maxSize = (float)_context.Capabilities.MaximumViewportDimensions;
float halfMaxSize = (float)_context.Capabilities.MaximumViewportDimensions * 0.5f;
float maxSize = _context.Capabilities.MaximumViewportDimensions;
float halfMaxSize = _context.Capabilities.MaximumViewportDimensions * 0.5f;
region = new RectangleF(-halfMaxSize, -halfMaxSize, maxSize, maxSize * yFlip);
}
@ -362,7 +351,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
float units = state.Get<float>(MethodOffset.DepthBiasUnits);
float clamp = state.Get<float>(MethodOffset.DepthBiasClamp);
PolygonModeMask enables = 0;
PolygonModeMask enables;
enables = (depthBias.PointEnable ? PolygonModeMask.Point : 0);
enables |= (depthBias.LineEnable ? PolygonModeMask.Line : 0);
@ -435,16 +424,16 @@ namespace Ryujinx.Graphics.Gpu.Engine
? texturePool.MaximumId
: samplerPool.MaximumId;
_textureManager.SetGraphicsSamplerPool(samplerPool.Address.Pack(), maximumId, samplerIndex);
TextureManager.SetGraphicsSamplerPool(samplerPool.Address.Pack(), maximumId, samplerIndex);
}
private void UpdateTexturePoolState(GpuState state)
{
var texturePool = state.Get<PoolState>(MethodOffset.TexturePoolState);
_textureManager.SetGraphicsTexturePool(texturePool.Address.Pack(), texturePool.MaximumId);
TextureManager.SetGraphicsTexturePool(texturePool.Address.Pack(), texturePool.MaximumId);
_textureManager.SetGraphicsTextureBufferIndex(state.Get<int>(MethodOffset.TextureBufferIndex));
TextureManager.SetGraphicsTextureBufferIndex(state.Get<int>(MethodOffset.TextureBufferIndex));
}
private void UpdateVertexAttribState(GpuState state)
@ -457,7 +446,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
if (!FormatTable.TryGetAttribFormat(vertexAttrib.UnpackFormat(), out Format format))
{
// TODO: warning.
Logger.PrintError(LogClass.Gpu, $"Invalid attribute format 0x{vertexAttrib.UnpackFormat():X}.");
format = Format.R32G32B32A32Float;
}
@ -468,7 +457,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
format);
}
_context.Renderer.Pipeline.BindVertexAttribs(vertexAttribs);
_context.Renderer.Pipeline.SetVertexAttribs(vertexAttribs);
}
private void UpdatePrimitiveRestartState(GpuState state)
@ -504,7 +493,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
case IndexType.UInt: size *= 4; break;
}
_bufferManager.SetIndexBuffer(gpuVa, size, indexBuffer.Type);
BufferManager.SetIndexBuffer(gpuVa, size, indexBuffer.Type);
// The index buffer affects the vertex buffer size calculation, we
// need to ensure that they are updated.
@ -521,7 +510,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
if (!vertexBuffer.UnpackEnable())
{
_bufferManager.SetVertexBuffer(index, 0, 0, 0, 0);
BufferManager.SetVertexBuffer(index, 0, 0, 0, 0);
continue;
}
@ -557,7 +546,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
size = (ulong)((firstInstance + drawState.First + drawState.Count) * stride);
}
_bufferManager.SetVertexBuffer(index, address, size, stride, divisor);
BufferManager.SetVertexBuffer(index, address, size, stride, divisor);
}
}
@ -580,7 +569,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
var colorMask = state.Get<RtColorMask>(MethodOffset.RtColorMask, rtColorMaskShared ? 0 : index);
uint componentMask = 0;
uint componentMask;
componentMask = (colorMask.UnpackRed() ? 1u : 0u);
componentMask |= (colorMask.UnpackGreen() ? 2u : 0u);
@ -597,8 +586,6 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
bool blendIndependent = state.Get<Boolean32>(MethodOffset.BlendIndependent);
BlendState[] blends = new BlendState[8];
for (int index = 0; index < 8; index++)
{
BlendDescriptor descriptor;
@ -632,7 +619,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
blend.AlphaDstFactor);
}
_context.Renderer.Pipeline.BindBlendState(index, descriptor);
_context.Renderer.Pipeline.SetBlendState(index, descriptor);
}
}
@ -704,7 +691,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
}
}
_textureManager.SetGraphicsTextures(stage, textureBindings);
TextureManager.SetGraphicsTextures(stage, textureBindings);
var imageBindings = new TextureBindingInfo[info.Images.Count];
@ -717,7 +704,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
imageBindings[index] = new TextureBindingInfo(target, descriptor.HandleIndex);
}
_textureManager.SetGraphicsImages(stage, imageBindings);
TextureManager.SetGraphicsImages(stage, imageBindings);
uint sbEnableMask = 0;
uint ubEnableMask = 0;
@ -732,11 +719,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
ubEnableMask |= 1u << info.CBuffers[index].Slot;
}
_bufferManager.SetGraphicsStorageBufferEnableMask(stage, sbEnableMask);
_bufferManager.SetGraphicsUniformBufferEnableMask(stage, ubEnableMask);
BufferManager.SetGraphicsStorageBufferEnableMask(stage, sbEnableMask);
BufferManager.SetGraphicsUniformBufferEnableMask(stage, ubEnableMask);
}
_context.Renderer.Pipeline.BindProgram(gs.HostProgram);
_context.Renderer.Pipeline.SetProgram(gs.HostProgram);
}
public bool GetViewportTransformEnable(GpuState state)
@ -796,7 +783,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
private void InvalidateTextures(GpuState state, int argument)
{
_textureManager.Flush();
TextureManager.Flush();
}
private void TextureBarrierTiled(GpuState state, int argument)