aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Gpu/Engine
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2021-11-10 15:37:49 -0300
committerGitHub <noreply@github.com>2021-11-10 15:37:49 -0300
commit611bec6e44effa90554c95ed1fe4dd4812893947 (patch)
tree679e67c1253f88c3ceef9a98a6109ebede39e352 /Ryujinx.Graphics.Gpu/Engine
parentbc00a251dd14f7cce4023a42bb76d23165755006 (diff)
Implement DrawTexture functionality (#2747)
* Implement DrawTexture functionality * Non-NVIDIA support * Disable some features that should not affect draw texture (slow path) * Remove space from shader source * Match 2D engine names * Fix resolution scale and add missing XML docs * Disable transform feedback for draw texture fallback
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Engine')
-rw-r--r--Ryujinx.Graphics.Gpu/Engine/Threed/DrawManager.cs59
-rw-r--r--Ryujinx.Graphics.Gpu/Engine/Threed/ThreedClass.cs10
-rw-r--r--Ryujinx.Graphics.Gpu/Engine/Threed/ThreedClassState.cs13
3 files changed, 81 insertions, 1 deletions
diff --git a/Ryujinx.Graphics.Gpu/Engine/Threed/DrawManager.cs b/Ryujinx.Graphics.Gpu/Engine/Threed/DrawManager.cs
index a060c6c9..518e71ad 100644
--- a/Ryujinx.Graphics.Gpu/Engine/Threed/DrawManager.cs
+++ b/Ryujinx.Graphics.Gpu/Engine/Threed/DrawManager.cs
@@ -320,6 +320,65 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
}
/// <summary>
+ /// Performs a texture draw with a source texture and sampler ID, along with source
+ /// and destination coordinates and sizes.
+ /// </summary>
+ /// <param name="engine">3D engine where this method is being called</param>
+ /// <param name="argument">Method call argument</param>
+ public void DrawTexture(ThreedClass engine, int argument)
+ {
+ static float FixedToFloat(int fixedValue)
+ {
+ return fixedValue * (1f / 4096);
+ }
+
+ float dstX0 = FixedToFloat(_state.State.DrawTextureDstX);
+ float dstY0 = FixedToFloat(_state.State.DrawTextureDstY);
+ float dstWidth = FixedToFloat(_state.State.DrawTextureDstWidth);
+ float dstHeight = FixedToFloat(_state.State.DrawTextureDstHeight);
+
+ // TODO: Confirm behaviour on hardware.
+ // When this is active, the origin appears to be on the bottom.
+ if (_state.State.YControl.HasFlag(YControl.NegateY))
+ {
+ dstY0 -= dstHeight;
+ }
+
+ float dstX1 = dstX0 + dstWidth;
+ float dstY1 = dstY0 + dstHeight;
+
+ float srcX0 = FixedToFloat(_state.State.DrawTextureSrcX);
+ float srcY0 = FixedToFloat(_state.State.DrawTextureSrcY);
+ float srcX1 = ((float)_state.State.DrawTextureDuDx / (1UL << 32)) * dstWidth + srcX0;
+ float srcY1 = ((float)_state.State.DrawTextureDvDy / (1UL << 32)) * dstHeight + srcY0;
+
+ engine.UpdateState();
+
+ int textureId = _state.State.DrawTextureTextureId;
+ int samplerId = _state.State.DrawTextureSamplerId;
+
+ (var texture, var sampler) = _channel.TextureManager.GetGraphicsTextureAndSampler(textureId, samplerId);
+
+ srcX0 *= texture.ScaleFactor;
+ srcY0 *= texture.ScaleFactor;
+ srcX1 *= texture.ScaleFactor;
+ srcY1 *= texture.ScaleFactor;
+
+ float dstScale = _channel.TextureManager.RenderTargetScale;
+
+ dstX0 *= dstScale;
+ dstY0 *= dstScale;
+ dstX1 *= dstScale;
+ dstY1 *= dstScale;
+
+ _context.Renderer.Pipeline.DrawTexture(
+ texture?.HostTexture,
+ sampler?.HostSampler,
+ new Extents2DF(srcX0, srcY0, srcX1, srcY1),
+ new Extents2DF(dstX0, dstY0, dstX1, dstY1));
+ }
+
+ /// <summary>
/// Performs a indirect multi-draw, with parameters from a GPU buffer.
/// </summary>
/// <param name="engine">3D engine where this method is being called</param>
diff --git a/Ryujinx.Graphics.Gpu/Engine/Threed/ThreedClass.cs b/Ryujinx.Graphics.Gpu/Engine/Threed/ThreedClass.cs
index 5478704a..f3061c73 100644
--- a/Ryujinx.Graphics.Gpu/Engine/Threed/ThreedClass.cs
+++ b/Ryujinx.Graphics.Gpu/Engine/Threed/ThreedClass.cs
@@ -36,6 +36,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
{ nameof(ThreedClassState.SyncpointAction), new RwCallback(IncrementSyncpoint, null) },
{ nameof(ThreedClassState.TextureBarrier), new RwCallback(TextureBarrier, null) },
{ nameof(ThreedClassState.TextureBarrierTiled), new RwCallback(TextureBarrierTiled, null) },
+ { nameof(ThreedClassState.DrawTextureSrcY), new RwCallback(DrawTexture, null) },
{ nameof(ThreedClassState.VbElementU8), new RwCallback(VbElementU8, null) },
{ nameof(ThreedClassState.VbElementU16), new RwCallback(VbElementU16, null) },
{ nameof(ThreedClassState.VbElementU32), new RwCallback(VbElementU32, null) },
@@ -252,6 +253,15 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
}
/// <summary>
+ /// Draws a texture, without needing to specify shader programs.
+ /// </summary>
+ /// <param name="argument">Method call argument</param>
+ private void DrawTexture(int argument)
+ {
+ _drawManager.DrawTexture(this, argument);
+ }
+
+ /// <summary>
/// Pushes four 8-bit index buffer elements.
/// </summary>
/// <param name="argument">Method call argument</param>
diff --git a/Ryujinx.Graphics.Gpu/Engine/Threed/ThreedClassState.cs b/Ryujinx.Graphics.Gpu/Engine/Threed/ThreedClassState.cs
index 58bc0957..165f5072 100644
--- a/Ryujinx.Graphics.Gpu/Engine/Threed/ThreedClassState.cs
+++ b/Ryujinx.Graphics.Gpu/Engine/Threed/ThreedClassState.cs
@@ -743,7 +743,18 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
public fixed uint ReservedF94[19];
public RtDepthStencilState RtDepthStencilState;
public ScreenScissorState ScreenScissorState;
- public fixed uint ReservedFFC[89];
+ public fixed uint ReservedFFC[33];
+ public int DrawTextureDstX;
+ public int DrawTextureDstY;
+ public int DrawTextureDstWidth;
+ public int DrawTextureDstHeight;
+ public long DrawTextureDuDx;
+ public long DrawTextureDvDy;
+ public int DrawTextureSamplerId;
+ public int DrawTextureTextureId;
+ public int DrawTextureSrcX;
+ public int DrawTextureSrcY;
+ public fixed uint Reserved10B0[44];
public Array16<VertexAttribState> VertexAttribState;
public fixed uint Reserved11A0[31];
public RtControl RtControl;