Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove closure allocations in VeldridStagingTexturePool #6373

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Remove closure allocations in VeldridStagingTexturePool
smoogipoo committed Sep 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit e44c2a661a2505b44aa0635c10562f0681687f05
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ public DeviceBufferPool(GraphicsPipeline pipeline, uint bufferSize, BufferUsage

public IPooledDeviceBuffer Get()
{
if (TryGet(_ => true, out IPooledDeviceBuffer? existing))
if (TryGet(out IPooledDeviceBuffer? existing))
return existing;

existing = new PooledDeviceBuffer(Pipeline, bufferSize, usage);
7 changes: 5 additions & 2 deletions osu.Framework/Graphics/Veldrid/VeldridStagingResourcePool.cs
Original file line number Diff line number Diff line change
@@ -32,7 +32,10 @@ protected VeldridStagingResourcePool(GraphicsPipeline pipeline, string name)
pipeline.ExecutionFinished += executionFinished;
}

protected bool TryGet(Predicate<T> match, [NotNullWhen(true)] out T? resource)
protected bool TryGet([NotNullWhen(true)] out T? resource)
=> TryGet<object>(static (_, _) => true, null, out resource);

protected bool TryGet<TState>(Func<T, TState?, bool> match, TState? state, [NotNullWhen(true)] out T? resource)
{
// Reverse iteration is important to prefer reusing recently returned textures.
// This avoids the case of a large pool being constantly cycled and therefore never
@@ -41,7 +44,7 @@ protected bool TryGet(Predicate<T> match, [NotNullWhen(true)] out T? resource)
{
var existing = available[i];

if (match(existing.Resource))
if (match(existing.Resource, state))
{
existing.FrameUsageIndex = currentExecutionIndex;

7 changes: 6 additions & 1 deletion osu.Framework/Graphics/Veldrid/VeldridStagingTexturePool.cs
Original file line number Diff line number Diff line change
@@ -15,12 +15,17 @@ public VeldridStagingTexturePool(GraphicsPipeline pipeline)

public Texture Get(int width, int height, PixelFormat format)
{
if (TryGet(t => t.Width >= width && t.Height >= height && t.Format == format, out var texture))
if (TryGet(match, new TextureLookup(width, height, format), out var texture))
return texture;

texture = Pipeline.Factory.CreateTexture(TextureDescription.Texture2D((uint)width, (uint)height, 1, 1, format, TextureUsage.Staging));
AddNewResource(texture);
return texture;
}

private static bool match(Texture texture, TextureLookup lookup)
=> texture.Width >= lookup.Width && texture.Height >= lookup.Height && texture.Format == lookup.Format;

private readonly record struct TextureLookup(int Width, int Height, PixelFormat Format);
}
}

Unchanged files with check annotations Beta

namespace FlappyDon.iOS
{
public static class Application

Check warning on line 6 in osu.Framework.Templates/templates/template-flappy/FlappyDon.iOS/Application.cs

GitHub Actions / Build only (iOS)

Missing XML comment for publicly visible type or member 'Application'

Check warning on line 6 in osu.Framework.Templates/templates/template-flappy/FlappyDon.iOS/Application.cs

GitHub Actions / Build only (iOS)

Missing XML comment for publicly visible type or member 'Application'
{
public static void Main(string[] args) => GameApplication.Main(new FlappyDonGame());

Check warning on line 8 in osu.Framework.Templates/templates/template-flappy/FlappyDon.iOS/Application.cs

GitHub Actions / Build only (iOS)

Missing XML comment for publicly visible type or member 'Application.Main(string[])'

Check warning on line 8 in osu.Framework.Templates/templates/template-flappy/FlappyDon.iOS/Application.cs

GitHub Actions / Build only (iOS)

Missing XML comment for publicly visible type or member 'Application.Main(string[])'
}
}
namespace TemplateGame.iOS
{
public static class Application

Check warning on line 9 in osu.Framework.Templates/templates/template-empty/TemplateGame.iOS/Application.cs

GitHub Actions / Build only (iOS)

Missing XML comment for publicly visible type or member 'Application'

Check warning on line 9 in osu.Framework.Templates/templates/template-empty/TemplateGame.iOS/Application.cs

GitHub Actions / Build only (iOS)

Missing XML comment for publicly visible type or member 'Application'
{
public static void Main(string[] args) => GameApplication.Main(new TemplateGameGame());

Check warning on line 11 in osu.Framework.Templates/templates/template-empty/TemplateGame.iOS/Application.cs

GitHub Actions / Build only (iOS)

Missing XML comment for publicly visible type or member 'Application.Main(string[])'

Check warning on line 11 in osu.Framework.Templates/templates/template-empty/TemplateGame.iOS/Application.cs

GitHub Actions / Build only (iOS)

Missing XML comment for publicly visible type or member 'Application.Main(string[])'
}
}