diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2021-11-10 15:37:49 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-10 15:37:49 -0300 |
| commit | 611bec6e44effa90554c95ed1fe4dd4812893947 (patch) | |
| tree | 679e67c1253f88c3ceef9a98a6109ebede39e352 /Ryujinx.Graphics.Gpu/Engine/Threed/DrawManager.cs | |
| parent | bc00a251dd14f7cce4023a42bb76d23165755006 (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/Threed/DrawManager.cs')
| -rw-r--r-- | Ryujinx.Graphics.Gpu/Engine/Threed/DrawManager.cs | 59 |
1 files changed, 59 insertions, 0 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> |
