From 788ca6a411762035a6a7a88100c4b582b47ee82d Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 15 Jul 2020 00:01:10 -0300 Subject: Initial transform feedback support (#1370) * Initial transform feedback support * Some nits and fixes * Update ReportCounterType and Write method * Can't change shader or TFB bindings while TFB is active * Fix geometry shader input names with new naming --- Ryujinx.Graphics.Gpu/State/GpuState.cs | 19 +++++++-- Ryujinx.Graphics.Gpu/State/GpuStateTable.cs | 54 +++++++++++++------------ Ryujinx.Graphics.Gpu/State/MethodOffset.cs | 6 ++- Ryujinx.Graphics.Gpu/State/ReportCounterType.cs | 11 ++--- Ryujinx.Graphics.Gpu/State/TfBufferState.cs | 18 +++++++++ Ryujinx.Graphics.Gpu/State/TfState.cs | 15 +++++++ 6 files changed, 87 insertions(+), 36 deletions(-) create mode 100644 Ryujinx.Graphics.Gpu/State/TfBufferState.cs create mode 100644 Ryujinx.Graphics.Gpu/State/TfState.cs (limited to 'Ryujinx.Graphics.Gpu/State') diff --git a/Ryujinx.Graphics.Gpu/State/GpuState.cs b/Ryujinx.Graphics.Gpu/State/GpuState.cs index 264719b4..9e7d9492 100644 --- a/Ryujinx.Graphics.Gpu/State/GpuState.cs +++ b/Ryujinx.Graphics.Gpu/State/GpuState.cs @@ -346,7 +346,7 @@ namespace Ryujinx.Graphics.Gpu.State /// Register offset /// Index for indexed data /// The data at the specified location - public T Get(MethodOffset offset, int index) where T : struct + public T Get(MethodOffset offset, int index) where T : unmanaged { Register register = _registers[(int)offset]; @@ -364,11 +364,22 @@ namespace Ryujinx.Graphics.Gpu.State /// Type of the data /// Register offset /// The data at the specified location - public T Get(MethodOffset offset) where T : struct + public T Get(MethodOffset offset) where T : unmanaged { return MemoryMarshal.Cast(_memory.AsSpan().Slice((int)offset))[0]; } + /// + /// Gets a span of the data at a given register offset. + /// + /// Register offset + /// Length of the data in bytes + /// The data at the specified location + public Span GetSpan(MethodOffset offset, int length) + { + return MemoryMarshal.Cast(_memory.AsSpan().Slice((int)offset)).Slice(0, length); + } + /// /// Sets indexed data to a given register offset. /// @@ -376,7 +387,7 @@ namespace Ryujinx.Graphics.Gpu.State /// Register offset /// Index for indexed data /// The data to set - public void Set(MethodOffset offset, int index, T data) where T : struct + public void Set(MethodOffset offset, int index, T data) where T : unmanaged { Register register = _registers[(int)offset]; @@ -394,7 +405,7 @@ namespace Ryujinx.Graphics.Gpu.State /// Type of the data /// Register offset /// The data to set - public void Set(MethodOffset offset, T data) where T : struct + public void Set(MethodOffset offset, T data) where T : unmanaged { ReadOnlySpan intSpan = MemoryMarshal.Cast(MemoryMarshal.CreateReadOnlySpan(ref data, 1)); intSpan.CopyTo(_memory.AsSpan().Slice((int)offset, intSpan.Length)); diff --git a/Ryujinx.Graphics.Gpu/State/GpuStateTable.cs b/Ryujinx.Graphics.Gpu/State/GpuStateTable.cs index 65df5f4e..acc0fe85 100644 --- a/Ryujinx.Graphics.Gpu/State/GpuStateTable.cs +++ b/Ryujinx.Graphics.Gpu/State/GpuStateTable.cs @@ -53,32 +53,34 @@ namespace Ryujinx.Graphics.Gpu.State /// public static TableItem[] Table = new TableItem[] { - new TableItem(MethodOffset.RtColorState, typeof(RtColorState), Constants.TotalRenderTargets), - new TableItem(MethodOffset.ViewportTransform, typeof(ViewportTransform), Constants.TotalViewports), - new TableItem(MethodOffset.ViewportExtents, typeof(ViewportExtents), Constants.TotalViewports), - new TableItem(MethodOffset.VertexBufferDrawState, typeof(VertexBufferDrawState), 1), - new TableItem(MethodOffset.DepthBiasState, typeof(DepthBiasState), 1), - new TableItem(MethodOffset.ScissorState, typeof(ScissorState), Constants.TotalViewports), - new TableItem(MethodOffset.StencilBackMasks, typeof(StencilBackMasks), 1), - new TableItem(MethodOffset.RtDepthStencilState, typeof(RtDepthStencilState), 1), - new TableItem(MethodOffset.VertexAttribState, typeof(VertexAttribState), 16), - new TableItem(MethodOffset.RtDepthStencilSize, typeof(Size3D), 1), - new TableItem(MethodOffset.BlendEnable, typeof(Boolean32), Constants.TotalRenderTargets), - new TableItem(MethodOffset.StencilTestState, typeof(StencilTestState), 1), - new TableItem(MethodOffset.SamplerPoolState, typeof(PoolState), 1), - new TableItem(MethodOffset.TexturePoolState, typeof(PoolState), 1), - new TableItem(MethodOffset.StencilBackTestState, typeof(StencilBackTestState), 1), - new TableItem(MethodOffset.ShaderBaseAddress, typeof(GpuVa), 1), - new TableItem(MethodOffset.PrimitiveRestartState, typeof(PrimitiveRestartState), 1), - new TableItem(MethodOffset.IndexBufferState, typeof(IndexBufferState), 1), - new TableItem(MethodOffset.VertexBufferInstanced, typeof(Boolean32), 16), - new TableItem(MethodOffset.FaceState, typeof(FaceState), 1), - new TableItem(MethodOffset.RtColorMask, typeof(RtColorMask), Constants.TotalRenderTargets), - new TableItem(MethodOffset.VertexBufferState, typeof(VertexBufferState), 16), - new TableItem(MethodOffset.BlendConstant, typeof(ColorF), 1), - new TableItem(MethodOffset.BlendState, typeof(BlendState), Constants.TotalRenderTargets), - new TableItem(MethodOffset.VertexBufferEndAddress, typeof(GpuVa), 16), - new TableItem(MethodOffset.ShaderState, typeof(ShaderState), 6), + new TableItem(MethodOffset.TfBufferState, typeof(TfBufferState), Constants.TotalTransformFeedbackBuffers), + new TableItem(MethodOffset.TfState, typeof(TfState), Constants.TotalTransformFeedbackBuffers), + new TableItem(MethodOffset.RtColorState, typeof(RtColorState), Constants.TotalRenderTargets), + new TableItem(MethodOffset.ViewportTransform, typeof(ViewportTransform), Constants.TotalViewports), + new TableItem(MethodOffset.ViewportExtents, typeof(ViewportExtents), Constants.TotalViewports), + new TableItem(MethodOffset.VertexBufferDrawState, typeof(VertexBufferDrawState), 1), + new TableItem(MethodOffset.DepthBiasState, typeof(DepthBiasState), 1), + new TableItem(MethodOffset.ScissorState, typeof(ScissorState), Constants.TotalViewports), + new TableItem(MethodOffset.StencilBackMasks, typeof(StencilBackMasks), 1), + new TableItem(MethodOffset.RtDepthStencilState, typeof(RtDepthStencilState), 1), + new TableItem(MethodOffset.VertexAttribState, typeof(VertexAttribState), Constants.TotalVertexAttribs), + new TableItem(MethodOffset.RtDepthStencilSize, typeof(Size3D), 1), + new TableItem(MethodOffset.BlendEnable, typeof(Boolean32), Constants.TotalRenderTargets), + new TableItem(MethodOffset.StencilTestState, typeof(StencilTestState), 1), + new TableItem(MethodOffset.SamplerPoolState, typeof(PoolState), 1), + new TableItem(MethodOffset.TexturePoolState, typeof(PoolState), 1), + new TableItem(MethodOffset.StencilBackTestState, typeof(StencilBackTestState), 1), + new TableItem(MethodOffset.ShaderBaseAddress, typeof(GpuVa), 1), + new TableItem(MethodOffset.PrimitiveRestartState, typeof(PrimitiveRestartState), 1), + new TableItem(MethodOffset.IndexBufferState, typeof(IndexBufferState), 1), + new TableItem(MethodOffset.VertexBufferInstanced, typeof(Boolean32), Constants.TotalVertexBuffers), + new TableItem(MethodOffset.FaceState, typeof(FaceState), 1), + new TableItem(MethodOffset.RtColorMask, typeof(RtColorMask), Constants.TotalRenderTargets), + new TableItem(MethodOffset.VertexBufferState, typeof(VertexBufferState), Constants.TotalVertexBuffers), + new TableItem(MethodOffset.BlendConstant, typeof(ColorF), 1), + new TableItem(MethodOffset.BlendState, typeof(BlendState), Constants.TotalRenderTargets), + new TableItem(MethodOffset.VertexBufferEndAddress, typeof(GpuVa), Constants.TotalVertexBuffers), + new TableItem(MethodOffset.ShaderState, typeof(ShaderState), Constants.ShaderStages + 1), }; } } \ No newline at end of file diff --git a/Ryujinx.Graphics.Gpu/State/MethodOffset.cs b/Ryujinx.Graphics.Gpu/State/MethodOffset.cs index d7d5d903..b0eb6f32 100644 --- a/Ryujinx.Graphics.Gpu/State/MethodOffset.cs +++ b/Ryujinx.Graphics.Gpu/State/MethodOffset.cs @@ -28,10 +28,13 @@ namespace Ryujinx.Graphics.Gpu.State SyncpointAction = 0xb2, CopyBuffer = 0xc0, RasterizeEnable = 0xdf, + TfBufferState = 0xe0, CopyBufferParams = 0x100, + TfState = 0x1c0, CopyBufferSwizzle = 0x1c2, CopyBufferDstTexture = 0x1c3, CopyBufferSrcTexture = 0x1ca, + TfEnable = 0x1d1, RtColorState = 0x200, CopyTextureControl = 0x223, CopyRegion = 0x22c, @@ -116,6 +119,7 @@ namespace Ryujinx.Graphics.Gpu.State UniformBufferBindTessEvaluation = 0x914, UniformBufferBindGeometry = 0x91c, UniformBufferBindFragment = 0x924, - TextureBufferIndex = 0x982 + TextureBufferIndex = 0x982, + TfVaryingLocations = 0xa00 } } \ No newline at end of file diff --git a/Ryujinx.Graphics.Gpu/State/ReportCounterType.cs b/Ryujinx.Graphics.Gpu/State/ReportCounterType.cs index cface55d..6bde2844 100644 --- a/Ryujinx.Graphics.Gpu/State/ReportCounterType.cs +++ b/Ryujinx.Graphics.Gpu/State/ReportCounterType.cs @@ -11,18 +11,19 @@ namespace Ryujinx.Graphics.Gpu.State VertexShaderInvocations = 5, GeometryShaderInvocations = 7, GeometryShaderPrimitives = 9, + ZcullStats0 = 0xa, TransformFeedbackPrimitivesWritten = 0xb, + ZcullStats1 = 0xc, + ZcullStats2 = 0xe, ClipperInputPrimitives = 0xf, + ZcullStats3 = 0x10, ClipperOutputPrimitives = 0x11, PrimitivesGenerated = 0x12, FragmentShaderInvocations = 0x13, SamplesPassed = 0x15, + TransformFeedbackOffset = 0x1a, TessControlShaderInvocations = 0x1b, TessEvaluationShaderInvocations = 0x1d, - TessEvaluationShaderPrimitives = 0x1f, - ZcullStats0 = 0x2a, - ZcullStats1 = 0x2c, - ZcullStats2 = 0x2e, - ZcullStats3 = 0x30 + TessEvaluationShaderPrimitives = 0x1f } } \ No newline at end of file diff --git a/Ryujinx.Graphics.Gpu/State/TfBufferState.cs b/Ryujinx.Graphics.Gpu/State/TfBufferState.cs new file mode 100644 index 00000000..24dc0952 --- /dev/null +++ b/Ryujinx.Graphics.Gpu/State/TfBufferState.cs @@ -0,0 +1,18 @@ +namespace Ryujinx.Graphics.Gpu.State +{ + /// + /// Transform feedback buffer state. + /// + struct TfBufferState + { +#pragma warning disable CS0649 + public Boolean32 Enable; + public GpuVa Address; + public int Size; + public int Offset; + public uint Padding0; + public uint Padding1; + public uint Padding2; +#pragma warning restore CS0649 + } +} diff --git a/Ryujinx.Graphics.Gpu/State/TfState.cs b/Ryujinx.Graphics.Gpu/State/TfState.cs new file mode 100644 index 00000000..fb8b950b --- /dev/null +++ b/Ryujinx.Graphics.Gpu/State/TfState.cs @@ -0,0 +1,15 @@ +namespace Ryujinx.Graphics.Gpu.State +{ + /// + /// Transform feedback state. + /// + struct TfState + { +#pragma warning disable CS0649 + public int BufferIndex; + public int VaryingsCount; + public int Stride; + public uint Padding; +#pragma warning restore CS0649 + } +} -- cgit v1.2.3