-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preload command speedup, Texture/buffer data flush, blit shader fix (#30
) * Move encoder state to be tied to command buffer, so preload and background cbs have their own encoder state * Texture buffer/data flush, blit shader fix
- Loading branch information
1 parent
7d5b4c5
commit 879c93c
Showing
13 changed files
with
411 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
using Ryujinx.Graphics.Metal; | ||
using SharpMetal.Metal; | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.Versioning; | ||
|
||
interface IEncoderFactory | ||
{ | ||
MTLRenderCommandEncoder CreateRenderCommandEncoder(); | ||
MTLComputeCommandEncoder CreateComputeCommandEncoder(); | ||
} | ||
|
||
/// <summary> | ||
/// Tracks active encoder object for a command buffer. | ||
/// </summary> | ||
[SupportedOSPlatform("macos")] | ||
class CommandBufferEncoder | ||
{ | ||
public EncoderType CurrentEncoderType { get; private set; } = EncoderType.None; | ||
|
||
public MTLBlitCommandEncoder BlitEncoder => new MTLBlitCommandEncoder(CurrentEncoder.Value); | ||
|
||
public MTLComputeCommandEncoder ComputeEncoder => new MTLComputeCommandEncoder(CurrentEncoder.Value); | ||
|
||
public MTLRenderCommandEncoder RenderEncoder => new MTLRenderCommandEncoder(CurrentEncoder.Value); | ||
|
||
internal MTLCommandEncoder? CurrentEncoder { get; private set; } | ||
|
||
private MTLCommandBuffer _commandBuffer; | ||
private IEncoderFactory _encoderFactory; | ||
|
||
public void Initialize(MTLCommandBuffer commandBuffer, IEncoderFactory encoderFactory) | ||
{ | ||
_commandBuffer = commandBuffer; | ||
_encoderFactory = encoderFactory; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public MTLRenderCommandEncoder EnsureRenderEncoder() | ||
{ | ||
if (CurrentEncoderType != EncoderType.Render) | ||
{ | ||
return BeginRenderPass(); | ||
} | ||
|
||
return RenderEncoder; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public MTLBlitCommandEncoder EnsureBlitEncoder() | ||
{ | ||
if (CurrentEncoderType != EncoderType.Blit) | ||
{ | ||
return BeginBlitPass(); | ||
} | ||
|
||
return BlitEncoder; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public MTLComputeCommandEncoder EnsureComputeEncoder() | ||
{ | ||
if (CurrentEncoderType != EncoderType.Compute) | ||
{ | ||
return BeginComputePass(); | ||
} | ||
|
||
return ComputeEncoder; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public bool TryGetRenderEncoder(out MTLRenderCommandEncoder encoder) | ||
{ | ||
if (CurrentEncoderType != EncoderType.Render) | ||
{ | ||
encoder = default; | ||
return false; | ||
} | ||
|
||
encoder = RenderEncoder; | ||
return true; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public bool TryGetBlitEncoder(out MTLBlitCommandEncoder encoder) | ||
{ | ||
if (CurrentEncoderType != EncoderType.Blit) | ||
{ | ||
encoder = default; | ||
return false; | ||
} | ||
|
||
encoder = BlitEncoder; | ||
return true; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public bool TryGetComputeEncoder(out MTLComputeCommandEncoder encoder) | ||
{ | ||
if (CurrentEncoderType != EncoderType.Compute) | ||
{ | ||
encoder = default; | ||
return false; | ||
} | ||
|
||
encoder = ComputeEncoder; | ||
return true; | ||
} | ||
|
||
public void EndCurrentPass() | ||
{ | ||
if (CurrentEncoder != null) | ||
{ | ||
switch (CurrentEncoderType) | ||
{ | ||
case EncoderType.Blit: | ||
BlitEncoder.EndEncoding(); | ||
CurrentEncoder = null; | ||
break; | ||
case EncoderType.Compute: | ||
ComputeEncoder.EndEncoding(); | ||
CurrentEncoder = null; | ||
break; | ||
case EncoderType.Render: | ||
RenderEncoder.EndEncoding(); | ||
CurrentEncoder = null; | ||
break; | ||
default: | ||
throw new InvalidOperationException(); | ||
} | ||
|
||
CurrentEncoderType = EncoderType.None; | ||
} | ||
} | ||
|
||
private MTLRenderCommandEncoder BeginRenderPass() | ||
{ | ||
EndCurrentPass(); | ||
|
||
var renderCommandEncoder = _encoderFactory.CreateRenderCommandEncoder(); | ||
|
||
CurrentEncoder = renderCommandEncoder; | ||
CurrentEncoderType = EncoderType.Render; | ||
|
||
return renderCommandEncoder; | ||
} | ||
|
||
private MTLBlitCommandEncoder BeginBlitPass() | ||
{ | ||
EndCurrentPass(); | ||
|
||
var descriptor = new MTLBlitPassDescriptor(); | ||
var blitCommandEncoder = _commandBuffer.BlitCommandEncoder(descriptor); | ||
|
||
CurrentEncoder = blitCommandEncoder; | ||
CurrentEncoderType = EncoderType.Blit; | ||
return blitCommandEncoder; | ||
} | ||
|
||
private MTLComputeCommandEncoder BeginComputePass() | ||
{ | ||
EndCurrentPass(); | ||
|
||
var computeCommandEncoder = _encoderFactory.CreateComputeCommandEncoder(); | ||
|
||
CurrentEncoder = computeCommandEncoder; | ||
CurrentEncoderType = EncoderType.Compute; | ||
return computeCommandEncoder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.