Skip to content

Commit

Permalink
Add flag to turn off SSBOs
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Jun 29, 2023
1 parent 548680c commit 31ca559
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions osu.Framework/FrameworkEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class FrameworkEnvironment
public static GraphicsSurfaceType? PreferredGraphicsSurface { get; }
public static string? PreferredGraphicsRenderer { get; }
public static int? StagingBufferType { get; }
public static bool NoStructuredBuffers { get; }

static FrameworkEnvironment()
{
Expand All @@ -25,6 +26,8 @@ static FrameworkEnvironment()

if (int.TryParse(Environment.GetEnvironmentVariable("OSU_GRAPHICS_STAGING_BUFFER_TYPE"), out int stagingBufferImplementation))
StagingBufferType = stagingBufferImplementation;

NoStructuredBuffers = Environment.GetEnvironmentVariable("OSU_GRAPHICS_NO_SSBO") == "1";
}
}
}
10 changes: 5 additions & 5 deletions osu.Framework/Graphics/Veldrid/Buffers/VeldridArrayBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public VeldridArrayBuffer(VeldridRenderer renderer, int length)
Length = length;
structureSize = (uint)Marshal.SizeOf(default(TData));

if (renderer.Device.Features.StructuredBuffer)
if (renderer.UseStructuredBuffers)
{
bufferData = new TData[length];
buffer = renderer.Factory.CreateBuffer(new BufferDescription(
Expand All @@ -47,19 +47,19 @@ public TData this[int index]
{
get
{
if (renderer.Device.Features.StructuredBuffer)
if (renderer.UseStructuredBuffers)
return bufferData![index];

return uniformBuffer!.Data;
}
set
{
if (renderer.Device.Features.StructuredBuffer)
if (renderer.UseStructuredBuffers)
{
if (bufferData![index].Equals(value))
return;

if (!renderer.Device.Features.StructuredBuffer)
if (!renderer.UseStructuredBuffers)
renderer.FlushCurrentBatch(FlushBatchSource.SetUniform);

bufferData[index] = value;
Expand All @@ -72,7 +72,7 @@ public TData this[int index]

public ResourceSet GetResourceSet(ResourceLayout layout)
{
if (renderer.Device.Features.StructuredBuffer)
if (renderer.UseStructuredBuffers)
return set ??= renderer.Factory.CreateResourceSet(new ResourceSetDescription(layout, buffer));

return uniformBuffer!.GetResourceSet(layout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private string loadFile(byte[]? bytes, bool mainFile)
internalIncludes += loadFile(store.GetRawData("Internal/sh_GlobalUniforms.h"), false) + "\n";
internalIncludes += loadFile(store.GetRawData("Internal/sh_MaskingInfo.h"), false) + "\n";

if (renderer.Device.Features.StructuredBuffer)
if (renderer.UseStructuredBuffers)
internalIncludes += loadFile(store.GetRawData("Internal/sh_MaskingBuffer_SSBO.h"), false) + "\n";
else
internalIncludes += loadFile(store.GetRawData("Internal/sh_MaskingBuffer_UBO.h"), false) + "\n";
Expand Down
2 changes: 2 additions & 0 deletions osu.Framework/Graphics/Veldrid/VeldridRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ protected internal override bool AllowTearing
set => Device.AllowTearing = value;
}

public bool UseStructuredBuffers => !FrameworkEnvironment.NoStructuredBuffers && Device.Features.StructuredBuffer;

public override bool IsDepthRangeZeroToOne => Device.IsDepthRangeZeroToOne;
public override bool IsUvOriginTopLeft => Device.IsUvOriginTopLeft;
public override bool IsClipSpaceYInverted => Device.IsClipSpaceYInverted;
Expand Down

0 comments on commit 31ca559

Please sign in to comment.