0
0
Fork 0
mirror of https://github.com/GreemDev/Ryujinx.git synced 2024-12-23 02:15:49 +00:00

Add XML documentation to Ryujinx.Graphics.Gpu.Engine

This commit is contained in:
gdkchan 2019-12-31 16:19:44 -03:00 committed by Thog
parent d1c0a64e6a
commit 4a4e2f7c72
12 changed files with 305 additions and 1 deletions

View file

@ -10,6 +10,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
partial class Methods
{
/// <summary>
/// Dispatches compute work.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
public void Dispatch(GpuState state, int argument)
{
uint dispatchParamsAddress = (uint)state.Get<int>(MethodOffset.DispatchParamsAddress);

View file

@ -4,22 +4,36 @@ using System.Runtime.InteropServices;
namespace Ryujinx.Graphics.Gpu.Engine
{
/// <summary>
/// Compute uniform buffer parameters.
/// </summary>
struct UniformBufferParams
{
public int AddressLow;
public int AddressHighAndSize;
/// <summary>
/// Packs the split address to a 64-bits integer.
/// </summary>
/// <returns>Uniform buffer GPU virtual address</returns>
public ulong PackAddress()
{
return (uint)AddressLow | ((ulong)(AddressHighAndSize & 0xff) << 32);
}
/// <summary>
/// Unpacks the uniform buffer size in bytes.
/// </summary>
/// <returns>Uniform buffer size in bytes</returns>
public ulong UnpackSize()
{
return (ulong)((AddressHighAndSize >> 15) & 0x1ffff);
}
}
/// <summary>
/// Compute dispatch parameters.
/// </summary>
struct ComputeParams
{
public int Unknown0;
@ -61,6 +75,9 @@ namespace Ryujinx.Graphics.Gpu.Engine
private UniformBufferParams _uniformBuffer6;
private UniformBufferParams _uniformBuffer7;
/// <summary>
/// Uniform buffer parameters.
/// </summary>
public Span<UniformBufferParams> UniformBuffers
{
get
@ -89,36 +106,65 @@ namespace Ryujinx.Graphics.Gpu.Engine
public int Unknown62;
public int Unknown63;
/// <summary>
/// Unpacks the work group X size.
/// </summary>
/// <returns>Work group X size</returns>
public int UnpackGridSizeX()
{
return GridSizeX & 0x7fffffff;
}
/// <summary>
/// Unpacks the work group Y size.
/// </summary>
/// <returns>Work group Y size</returns>
public int UnpackGridSizeY()
{
return GridSizeYZ & 0xffff;
}
/// <summary>
/// Unpacks the work group Z size.
/// </summary>
/// <returns>Work group Z size</returns>
public int UnpackGridSizeZ()
{
return (GridSizeYZ >> 16) & 0xffff;
}
/// <summary>
/// Unpacks the local group X size.
/// </summary>
/// <returns>Local group X size</returns>
public int UnpackBlockSizeX()
{
return (BlockSizeX >> 16) & 0xffff;
}
/// <summary>
/// Unpacks the local group Y size.
/// </summary>
/// <returns>Local group Y size</returns>
public int UnpackBlockSizeY()
{
return BlockSizeYZ & 0xffff;
}
/// <summary>
/// Unpacks the local group Z size.
/// </summary>
/// <returns>Local group Z size</returns>
public int UnpackBlockSizeZ()
{
return (BlockSizeYZ >> 16) & 0xffff;
}
/// <summary>
/// Unpacks the uniform buffers enable mask.
/// Each bit set on the mask indicates that the respective buffer index is enabled.
/// </summary>
/// <returns>Uniform buffers enable mask</returns>
public uint UnpackUniformBuffersEnableMask()
{
return (uint)UniformBuffersConfig & 0xff;

View file

@ -19,6 +19,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
private int[] _buffer;
/// <summary>
/// Launches Inline-to-Memory engine DMA copy.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
public void LaunchDma(GpuState state, int argument)
{
_params = state.Get<Inline2MemoryParams>(MethodOffset.I2mParams);
@ -42,6 +47,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
_finished = false;
}
/// <summary>
/// Pushes a word of data to the Inline-to-Memory engine.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
public void LoadInlineData(GpuState state, int argument)
{
if (!_finished)
@ -55,6 +65,9 @@ namespace Ryujinx.Graphics.Gpu.Engine
}
}
/// <summary>
/// Performs actual copy of the inline data after the transfer is finished.
/// </summary>
private void FinishTransfer()
{
Span<byte> data = MemoryMarshal.Cast<int, byte>(_buffer).Slice(0, _size);

View file

@ -5,6 +5,12 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
partial class Methods
{
/// <summary>
/// Clears the current color and depth-stencil buffers.
/// Which buffers should be cleared is also specified on the argument.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
private void Clear(GpuState state, int argument)
{
UpdateRenderTargetState(state, useControl: false);

View file

@ -6,6 +6,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
partial class Methods
{
/// <summary>
/// Performs a buffer to buffer, or buffer to texture copy.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
private void CopyBuffer(GpuState state, int argument)
{
var cbp = state.Get<CopyBufferParams>(MethodOffset.CopyBufferParams);

View file

@ -7,6 +7,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
partial class Methods
{
/// <summary>
/// Performs a texture to texture copy.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
private void CopyTexture(GpuState state, int argument)
{
var dstCopyTexture = state.Get<CopyTexture>(MethodOffset.CopyDstTexture);

View file

@ -22,8 +22,17 @@ namespace Ryujinx.Graphics.Gpu.Engine
private int _instanceIndex;
/// <summary>
/// Primitive type of the current draw.
/// </summary>
public PrimitiveType PrimitiveType { get; private set; }
/// <summary>
/// Finishes draw call.
/// This draws geometry on the bound buffers based on the current GPU state.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
private void DrawEnd(GpuState state, int argument)
{
if (_instancedDrawPending)
@ -86,6 +95,12 @@ namespace Ryujinx.Graphics.Gpu.Engine
}
}
/// <summary>
/// Starts draw.
/// This sets primitive type and instanced draw parameters.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
private void DrawBegin(GpuState state, int argument)
{
if ((argument & (1 << 26)) != 0)
@ -106,11 +121,24 @@ namespace Ryujinx.Graphics.Gpu.Engine
PrimitiveType = type;
}
/// <summary>
/// Sets the index buffer count.
/// This also sets internal state that indicates that the next draw is a indexed draw.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
private void SetIndexBufferCount(GpuState state, int argument)
{
_drawIndexed = true;
}
/// <summary>
/// Perform any deferred draws.
/// This is used for instanced draws.
/// Since each instance is a separate draw, we defer the draw and accumulate the instance count.
/// Once we detect the last instanced draw, then we perform the host instanced draw,
/// with the accumulated instance count.
/// </summary>
public void PerformDeferredDraws()
{
// Perform any pending instanced draw.

View file

@ -10,6 +10,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
private ulong _runningCounter;
/// <summary>
/// Writes a GPU counter to guest memory.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
private void Report(GpuState state, int argument)
{
ReportMode mode = (ReportMode)(argument & 3);
@ -23,6 +28,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
}
}
/// <summary>
/// Writes a GPU semaphore value to guest memory.
/// </summary>
/// <param name="state">Current GPU state</param>
private void ReportSemaphore(GpuState state)
{
var rs = state.Get<ReportState>(MethodOffset.ReportState);
@ -32,12 +41,21 @@ namespace Ryujinx.Graphics.Gpu.Engine
_context.AdvanceSequence();
}
/// <summary>
/// Packed GPU counter data (including GPU timestamp) in memory.
/// </summary>
private struct CounterData
{
public ulong Counter;
public ulong Timestamp;
}
/// <summary>
/// Writes a GPU counter to guest memory.
/// This also writes the current timestamp value.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="type">Counter to be written to memory</param>
private void ReportCounter(GpuState state, ReportCounterType type)
{
CounterData counterData = new CounterData();
@ -83,6 +101,12 @@ namespace Ryujinx.Graphics.Gpu.Engine
_context.MemoryAccessor.Write(rs.Address.Pack(), data);
}
/// <summary>
/// Converts a nanoseconds timestamp value to Maxwell time ticks.
/// The frequency is approximately 1.63Hz.
/// </summary>
/// <param name="nanoseconds">Timestamp in nanoseconds</param>
/// <returns>Maxwell ticks</returns>
private static ulong ConvertNanosecondsToTicks(ulong nanoseconds)
{
// We need to divide first to avoid overflows.

View file

@ -5,6 +5,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
partial class Methods
{
/// <summary>
/// Resets the value of a internal GPU counter back to zero.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
private void ResetCounter(GpuState state, int argument)
{
ResetCounterType type = (ResetCounterType)argument;

View file

@ -4,31 +4,62 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
partial class Methods
{
/// <summary>
/// Binds a uniform buffer for the vertex shader stage.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
private void UniformBufferBindVertex(GpuState state, int argument)
{
UniformBufferBind(state, argument, ShaderType.Vertex);
}
/// <summary>
/// Binds a uniform buffer for the tessellation control shader stage.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
private void UniformBufferBindTessControl(GpuState state, int argument)
{
UniformBufferBind(state, argument, ShaderType.TessellationControl);
}
/// <summary>
/// Binds a uniform buffer for the tessellation evaluation shader stage.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
private void UniformBufferBindTessEvaluation(GpuState state, int argument)
{
UniformBufferBind(state, argument, ShaderType.TessellationEvaluation);
}
/// <summary>
/// Binds a uniform buffer for the geometry shader stage.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
private void UniformBufferBindGeometry(GpuState state, int argument)
{
UniformBufferBind(state, argument, ShaderType.Geometry);
}
/// <summary>
/// Binds a uniform buffer for the fragment shader stage.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
private void UniformBufferBindFragment(GpuState state, int argument)
{
UniformBufferBind(state, argument, ShaderType.Fragment);
}
/// <summary>
///Binds a uniform buffer for the specified shader stage.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
/// <param name="type">Shader stage that will access the uniform buffer</param>
private void UniformBufferBind(GpuState state, int argument, ShaderType type)
{
bool enable = (argument & 1) != 0;

View file

@ -4,6 +4,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
partial class Methods
{
/// <summary>
/// Updates the uniform buffer data with inline data.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">New uniform buffer data word</param>
private void UniformBufferUpdate(GpuState state, int argument)
{
var uniformBuffer = state.Get<UniformBufferState>(MethodOffset.UniformBufferState);

View file

@ -12,6 +12,9 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
using Texture = Image.Texture;
/// <summary>
/// GPU method implementations.
/// </summary>
partial class Methods
{
private readonly GpuContext _context;
@ -20,12 +23,23 @@ namespace Ryujinx.Graphics.Gpu.Engine
private readonly ShaderProgramInfo[] _currentProgramInfo;
public BufferManager BufferManager { get; }
/// <summary>
/// GPU buffer manager.
/// </summary>
public BufferManager BufferManager { get; }
/// <summary>
/// GPU texture manager.
/// </summary>
public TextureManager TextureManager { get; }
private bool _isAnyVbInstanced;
private bool _vsUsesInstanceId;
/// <summary>
/// Creates a new instance of the GPU methods class.
/// </summary>
/// <param name="context">GPU context</param>
public Methods(GpuContext context)
{
_context = context;
@ -38,6 +52,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
TextureManager = new TextureManager(context);
}
/// <summary>
/// Register callback for GPU method calls that triggers an action on the GPU.
/// </summary>
/// <param name="state">GPU state where the triggers will be registered</param>
public void RegisterCallbacks(GpuState state)
{
state.RegisterCallback(MethodOffset.LaunchDma, LaunchDma);
@ -72,6 +90,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
state.RegisterCallback(MethodOffset.UniformBufferBindFragment, UniformBufferBindFragment);
}
/// <summary>
/// Updates host state based on the current guest GPU state.
/// </summary>
/// <param name="state">Guest GPU state</param>
private void UpdateState(GpuState state)
{
// Shaders must be the first one to be updated if modified, because
@ -175,6 +197,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
CommitBindings();
}
/// <summary>
/// Ensures that the bindings are visible to the host GPU.
/// This actually performs the binding using the host graphics API.
/// </summary>
private void CommitBindings()
{
UpdateStorageBuffers();
@ -183,6 +209,9 @@ namespace Ryujinx.Graphics.Gpu.Engine
TextureManager.CommitGraphicsBindings();
}
/// <summary>
/// Updates storage buffer bindings.
/// </summary>
private void UpdateStorageBuffers()
{
for (int stage = 0; stage < _currentProgramInfo.Length; stage++)
@ -213,6 +242,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
}
}
/// <summary>
/// Updates render targets (color and depth-stencil buffers) based on current render target state.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="useControl">Use draw buffers information from render target control register</param>
private void UpdateRenderTargetState(GpuState state, bool useControl)
{
var rtControl = state.Get<RtControl>(MethodOffset.RtControl);
@ -267,12 +301,21 @@ namespace Ryujinx.Graphics.Gpu.Engine
}
}
/// <summary>
/// Checks if a render target color buffer is used.
/// </summary>
/// <param name="colorState">Color buffer information</param>
/// <returns>True if the specified buffer is enabled/used, false otherwise</returns>
private static bool IsRtEnabled(RtColorState colorState)
{
// Colors are disabled by writing 0 to the format.
return colorState.Format != 0 && colorState.WidthOrStride != 0;
}
/// <summary>
/// Updates host depth test state based on current GPU state.
/// </summary>
/// <param name="state">Current GPU state</param>
private void UpdateDepthTestState(GpuState state)
{
_context.Renderer.Pipeline.SetDepthTest(new DepthTestDescriptor(
@ -281,6 +324,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
state.Get<CompareOp>(MethodOffset.DepthTestFunc)));
}
/// <summary>
/// Updates host viewport transform and clipping state based on current GPU state.
/// </summary>
/// <param name="state">Current GPU state</param>
private void UpdateViewportTransform(GpuState state)
{
DepthMode depthMode = state.Get<DepthMode>(MethodOffset.DepthMode);
@ -343,6 +390,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
_context.Renderer.Pipeline.SetViewports(0, viewports);
}
/// <summary>
/// Updates host depth bias (also called polygon offset) state based on current GPU state.
/// </summary>
/// <param name="state">Current GPU state</param>
private void UpdateDepthBiasState(GpuState state)
{
var depthBias = state.Get<DepthBiasState>(MethodOffset.DepthBiasState);
@ -360,6 +411,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
_context.Renderer.Pipeline.SetDepthBias(enables, factor, units, clamp);
}
/// <summary>
/// Updates host stencil test state based on current GPU state.
/// </summary>
/// <param name="state">Current GPU state</param>
private void UpdateStencilTestState(GpuState state)
{
var backMasks = state.Get<StencilBackMasks> (MethodOffset.StencilBackMasks);
@ -413,6 +468,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
backMask));
}
/// <summary>
/// Updates current sampler pool address and size based on guest GPU state.
/// </summary>
/// <param name="state">Current GPU state</param>
private void UpdateSamplerPoolState(GpuState state)
{
var texturePool = state.Get<PoolState>(MethodOffset.TexturePoolState);
@ -427,6 +486,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
TextureManager.SetGraphicsSamplerPool(samplerPool.Address.Pack(), maximumId, samplerIndex);
}
/// <summary>
/// Updates current texture pool address and size based on guest GPU state.
/// </summary>
/// <param name="state">Current GPU state</param>
private void UpdateTexturePoolState(GpuState state)
{
var texturePool = state.Get<PoolState>(MethodOffset.TexturePoolState);
@ -436,6 +499,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
TextureManager.SetGraphicsTextureBufferIndex(state.Get<int>(MethodOffset.TextureBufferIndex));
}
/// <summary>
/// Updates host vertex attributes based on guest GPU state.
/// </summary>
/// <param name="state">Current GPU state</param>
private void UpdateVertexAttribState(GpuState state)
{
VertexAttribDescriptor[] vertexAttribs = new VertexAttribDescriptor[16];
@ -460,6 +527,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
_context.Renderer.Pipeline.SetVertexAttribs(vertexAttribs);
}
/// <summary>
/// Updates host primitive restart based on guest GPU state.
/// </summary>
/// <param name="state">Current GPU state</param>
private void UpdatePrimitiveRestartState(GpuState state)
{
PrimitiveRestartState primitiveRestart = state.Get<PrimitiveRestartState>(MethodOffset.PrimitiveRestartState);
@ -469,6 +540,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
primitiveRestart.Index);
}
/// <summary>
/// Updates host index buffer binding based on guest GPU state.
/// </summary>
/// <param name="state">Current GPU state</param>
private void UpdateIndexBufferState(GpuState state)
{
var indexBuffer = state.Get<IndexBufferState>(MethodOffset.IndexBufferState);
@ -500,6 +575,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
UpdateVertexBufferState(state);
}
/// <summary>
/// Updates host vertex buffer bindings based on guest GPU state.
/// </summary>
/// <param name="state">Current GPU state</param>
private void UpdateVertexBufferState(GpuState state)
{
_isAnyVbInstanced = false;
@ -550,6 +629,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
}
}
/// <summary>
/// Updates host face culling and orientation based on guest GPU state.
/// </summary>
/// <param name="state">Current GPU state</param>
private void UpdateFaceState(GpuState state)
{
var face = state.Get<FaceState>(MethodOffset.FaceState);
@ -559,6 +642,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
_context.Renderer.Pipeline.SetFrontFace(face.FrontFace);
}
/// <summary>
/// Updates host render target color masks, based on guest GPU state.
/// This defines with color channels are written to each color buffer.
/// </summary>
/// <param name="state">Current GPU state</param>
private void UpdateRtColorMask(GpuState state)
{
bool rtColorMaskShared = state.Get<Boolean32>(MethodOffset.RtColorMaskShared);
@ -582,6 +670,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
_context.Renderer.Pipeline.SetRenderTargetColorMasks(componentMasks);
}
/// <summary>
/// Updates host render target color buffer blending state, based on guest state.
/// </summary>
/// <param name="state">Current GPU state</param>
private void UpdateBlendState(GpuState state)
{
bool blendIndependent = state.Get<Boolean32>(MethodOffset.BlendIndependent);
@ -623,6 +715,9 @@ namespace Ryujinx.Graphics.Gpu.Engine
}
}
/// <summary>
/// Storage buffer address and size information.
/// </summary>
private struct SbDescriptor
{
public uint AddressLow;
@ -636,6 +731,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
}
}
/// <summary>
/// Updates host shaders based on the guest GPU state.
/// </summary>
/// <param name="state">Current GPU state</param>
private void UpdateShaderState(GpuState state)
{
ShaderAddresses addresses = new ShaderAddresses();
@ -726,6 +825,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
_context.Renderer.Pipeline.SetProgram(gs.HostProgram);
}
/// <summary>
/// Gets viewport transform enable.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <returns>Viewport transform enable</returns>
public bool GetViewportTransformEnable(GpuState state)
{
// FIXME: We should read ViewportTransformEnable, but it seems that some games writes 0 there?
@ -734,6 +838,11 @@ namespace Ryujinx.Graphics.Gpu.Engine
return true;
}
/// <summary>
/// Gets texture target from a sampler type.
/// </summary>
/// <param name="type">Sampler type</param>
/// <returns>Texture target value</returns>
private static Target GetTarget(SamplerType type)
{
type &= ~(SamplerType.Indexed | SamplerType.Shadow);
@ -776,16 +885,38 @@ namespace Ryujinx.Graphics.Gpu.Engine
return Target.Texture2D;
}
/// <summary>
/// Issues a texture barrier.
/// This waits until previous texture writes from the GPU to finish, before
/// performing new operations with said textures.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
private void TextureBarrier(GpuState state, int argument)
{
_context.Renderer.Pipeline.TextureBarrier();
}
/// <summary>
/// Invalidates all modified textures on the cache.
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="argument">Method call argument</param>
private void InvalidateTextures(GpuState state, int argument)
{
TextureManager.Flush();
}
/// <summary>
/// Issues a texture barrier.
/// This waits until previous texture writes from the GPU to finish, before
/// performing new operations with said textures.
/// This performs a per-tile wait, it is only valid if both the previous write
/// and current access has the same access patterns.
/// This may be faster than the regular barrier on tile-based rasterizers.
/// </summary>
/// <param name="state"></param>
/// <param name="argument"></param>
private void TextureBarrierTiled(GpuState state, int argument)
{
_context.Renderer.Pipeline.TextureBarrierTiled();