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

True bindless #14

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/Ryujinx.Graphics.GAL/Capabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public readonly struct Capabilities
public readonly string VendorName;

public readonly bool HasFrontFacingBug;
public readonly bool HasUnsizedDescriptorArrayBug;
public readonly bool HasVectorIndexingBug;
public readonly bool NeedsFragmentOutputSpecialization;
public readonly bool ReduceShaderPrecision;
Expand All @@ -24,6 +25,7 @@ public readonly struct Capabilities
public readonly bool SupportsScaledVertexFormats;
public readonly bool SupportsSnormBufferTextureFormat;
public readonly bool Supports5BitComponentFormat;
public readonly bool SupportsBindlessTextures;
public readonly bool SupportsBlendEquationAdvanced;
public readonly bool SupportsFragmentShaderInterlock;
public readonly bool SupportsFragmentShaderOrderingIntel;
Expand Down Expand Up @@ -64,6 +66,7 @@ public Capabilities(
TargetApi api,
string vendorName,
bool hasFrontFacingBug,
bool hasUnsizedDescriptorArrayBug,
bool hasVectorIndexingBug,
bool needsFragmentOutputSpecialization,
bool reduceShaderPrecision,
Expand All @@ -79,6 +82,7 @@ public Capabilities(
bool supportsScaledVertexFormats,
bool supportsSnormBufferTextureFormat,
bool supports5BitComponentFormat,
bool supportsBindlessTextures,
bool supportsBlendEquationAdvanced,
bool supportsFragmentShaderInterlock,
bool supportsFragmentShaderOrderingIntel,
Expand Down Expand Up @@ -115,6 +119,7 @@ public Capabilities(
Api = api;
VendorName = vendorName;
HasFrontFacingBug = hasFrontFacingBug;
HasUnsizedDescriptorArrayBug = hasUnsizedDescriptorArrayBug;
HasVectorIndexingBug = hasVectorIndexingBug;
NeedsFragmentOutputSpecialization = needsFragmentOutputSpecialization;
ReduceShaderPrecision = reduceShaderPrecision;
Expand All @@ -130,6 +135,7 @@ public Capabilities(
SupportsScaledVertexFormats = supportsScaledVertexFormats;
SupportsSnormBufferTextureFormat = supportsSnormBufferTextureFormat;
Supports5BitComponentFormat = supports5BitComponentFormat;
SupportsBindlessTextures = supportsBindlessTextures;
SupportsBlendEquationAdvanced = supportsBlendEquationAdvanced;
SupportsFragmentShaderInterlock = supportsFragmentShaderInterlock;
SupportsFragmentShaderOrderingIntel = supportsFragmentShaderOrderingIntel;
Expand Down
4 changes: 4 additions & 0 deletions src/Ryujinx.Graphics.GAL/IPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ void DrawIndexed(

void EndTransformFeedback();

void RegisterBindlessSampler(int samplerId, ISampler sampler);
void RegisterBindlessTexture(int textureId, ITexture texture, float textureScale);
void RegisterBindlessTextureAndSampler(int textureId, ITexture texture, float textureScale, int samplerId, ISampler sampler);

void SetAlphaTest(bool enable, float reference, CompareOp op);

void SetBlendState(AdvancedBlendDescriptor blend);
Expand Down
3 changes: 3 additions & 0 deletions src/Ryujinx.Graphics.GAL/Multithreading/CommandHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ void Register<T>(CommandType commandType) where T : unmanaged, IGALCommand, IGAL
Register<DrawTextureCommand>(CommandType.DrawTexture);
Register<EndHostConditionalRenderingCommand>(CommandType.EndHostConditionalRendering);
Register<EndTransformFeedbackCommand>(CommandType.EndTransformFeedback);
Register<RegisterBindlessSamplerCommand>(CommandType.RegisterBindlessSampler);
Register<RegisterBindlessTextureCommand>(CommandType.RegisterBindlessTexture);
Register<RegisterBindlessTextureAndSamplerCommand>(CommandType.RegisterBindlessTextureAndSampler);
Register<SetAlphaTestCommand>(CommandType.SetAlphaTest);
Register<SetBlendStateAdvancedCommand>(CommandType.SetBlendStateAdvanced);
Register<SetBlendStateCommand>(CommandType.SetBlendState);
Expand Down
3 changes: 3 additions & 0 deletions src/Ryujinx.Graphics.GAL/Multithreading/CommandType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ enum CommandType : byte
DrawTexture,
EndHostConditionalRendering,
EndTransformFeedback,
RegisterBindlessSampler,
RegisterBindlessTexture,
RegisterBindlessTextureAndSampler,
SetAlphaTest,
SetBlendStateAdvanced,
SetBlendState,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Ryujinx.Graphics.GAL.Multithreading.Model;
using Ryujinx.Graphics.GAL.Multithreading.Resources;

namespace Ryujinx.Graphics.GAL.Multithreading.Commands
{
struct RegisterBindlessSamplerCommand : IGALCommand, IGALCommand<RegisterBindlessSamplerCommand>
{
public readonly CommandType CommandType => CommandType.RegisterBindlessSampler;
private int _samplerId;
private TableRef<ISampler> _sampler;

public void Set(int samplerId, TableRef<ISampler> sampler)
{
_samplerId = samplerId;
_sampler = sampler;
}

public static void Run(ref RegisterBindlessSamplerCommand command, ThreadedRenderer threaded, IRenderer renderer)
{
renderer.Pipeline.RegisterBindlessSampler(command._samplerId, command._sampler.GetAs<ThreadedSampler>(threaded)?.Base);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Ryujinx.Graphics.GAL.Multithreading.Model;
using Ryujinx.Graphics.GAL.Multithreading.Resources;

namespace Ryujinx.Graphics.GAL.Multithreading.Commands
{
struct RegisterBindlessTextureAndSamplerCommand : IGALCommand, IGALCommand<RegisterBindlessTextureAndSamplerCommand>
{
public readonly CommandType CommandType => CommandType.RegisterBindlessTextureAndSampler;
private int _textureId;
private int _samplerId;
private TableRef<ITexture> _texture;
private TableRef<ISampler> _sampler;
private float _textureScale;

public void Set(int textureId, TableRef<ITexture> texture, float textureScale, int samplerId, TableRef<ISampler> sampler)
{
_textureId = textureId;
_samplerId = samplerId;
_textureScale = textureScale;
_texture = texture;
_sampler = sampler;
}

public static void Run(ref RegisterBindlessTextureAndSamplerCommand command, ThreadedRenderer threaded, IRenderer renderer)
{
renderer.Pipeline.RegisterBindlessTextureAndSampler(
command._textureId,
command._texture.GetAs<ThreadedTexture>(threaded)?.Base,
command._textureScale,
command._samplerId,
command._sampler.GetAs<ThreadedSampler>(threaded)?.Base);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Ryujinx.Graphics.GAL.Multithreading.Model;
using Ryujinx.Graphics.GAL.Multithreading.Resources;

namespace Ryujinx.Graphics.GAL.Multithreading.Commands
{
struct RegisterBindlessTextureCommand : IGALCommand, IGALCommand<RegisterBindlessTextureCommand>
{
public readonly CommandType CommandType => CommandType.RegisterBindlessTexture;
private int _textureId;
private TableRef<ITexture> _texture;
private float _textureScale;

public void Set(int textureId, TableRef<ITexture> texture, float textureScale)
{
_textureId = textureId;
_texture = texture;
_textureScale = textureScale;
}

public static void Run(ref RegisterBindlessTextureCommand command, ThreadedRenderer threaded, IRenderer renderer)
{
renderer.Pipeline.RegisterBindlessTexture(command._textureId, command._texture.GetAs<ThreadedTexture>(threaded)?.Base, command._textureScale);
}
}
}
18 changes: 18 additions & 0 deletions src/Ryujinx.Graphics.GAL/Multithreading/ThreadedPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ public void EndTransformFeedback()
_renderer.QueueCommand();
}

public void RegisterBindlessSampler(int samplerId, ISampler sampler)
{
_renderer.New<RegisterBindlessSamplerCommand>().Set(samplerId, Ref(sampler));
_renderer.QueueCommand();
}

public void RegisterBindlessTexture(int textureId, ITexture texture, float textureScale)
{
_renderer.New<RegisterBindlessTextureCommand>().Set(textureId, Ref(texture), textureScale);
_renderer.QueueCommand();
}

public void RegisterBindlessTextureAndSampler(int textureId, ITexture texture, float textureScale, int samplerId, ISampler sampler)
{
_renderer.New<RegisterBindlessTextureAndSamplerCommand>().Set(textureId, Ref(texture), textureScale, samplerId, Ref(sampler));
_renderer.QueueCommand();
}

public void SetAlphaTest(bool enable, float reference, CompareOp op)
{
_renderer.New<SetAlphaTestCommand>().Set(enable, reference, op);
Expand Down
7 changes: 5 additions & 2 deletions src/Ryujinx.Graphics.GAL/ShaderInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ namespace Ryujinx.Graphics.GAL
public struct ShaderInfo
{
public int FragmentOutputMap { get; }
public bool HasBindless { get; }
public ResourceLayout ResourceLayout { get; }
public ProgramPipelineState? State { get; }
public bool FromCache { get; set; }

public ShaderInfo(int fragmentOutputMap, ResourceLayout resourceLayout, ProgramPipelineState state, bool fromCache = false)
public ShaderInfo(int fragmentOutputMap, bool hasBindless, ResourceLayout resourceLayout, ProgramPipelineState state, bool fromCache = false)
{
FragmentOutputMap = fragmentOutputMap;
HasBindless = hasBindless;
ResourceLayout = resourceLayout;
State = state;
FromCache = fromCache;
}

public ShaderInfo(int fragmentOutputMap, ResourceLayout resourceLayout, bool fromCache = false)
public ShaderInfo(int fragmentOutputMap, bool hasBindless, ResourceLayout resourceLayout, bool fromCache = false)
{
FragmentOutputMap = fragmentOutputMap;
HasBindless = hasBindless;
ResourceLayout = resourceLayout;
State = null;
FromCache = fromCache;
Expand Down
30 changes: 30 additions & 0 deletions src/Ryujinx.Graphics.Gpu/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,39 @@ static class Constants
/// </summary>
public const int DriverReservedUniformBuffer = 0;

/// <summary>
/// Number of the uniform buffer reserved by the driver to store texture binding handles.
/// </summary>
public const int DriverReserveTextureBindingsBuffer = 2;

/// <summary>
/// Maximum size that an storage buffer is assumed to have when the correct size is unknown.
/// </summary>
public const ulong MaxUnknownStorageSize = 0x100000;

/// <summary>
/// Maximum width and height for 1D, 2D and cube textures, including array and multisample variants.
/// </summary>
public const int MaxTextureSize = 0x4000;

/// <summary>
/// Maximum width, height and depth for 3D textures.
/// </summary>
public const int Max3DTextureSize = 0x800;

/// <summary>
/// Maximum layers for array textures.
/// </summary>
public const int MaxArrayTextureLayers = 0x800;

/// <summary>
/// Maximum width (effectively the size in pixels) for buffer textures.
/// </summary>
public const int MaxBufferTextureSize = 0x8000000;

/// <summary>
/// Alignment in bytes for pitch linear textures.
/// </summary>
public const int LinearStrideAlignment = 0x20;
}
}
1 change: 0 additions & 1 deletion src/Ryujinx.Graphics.Gpu/Engine/Compute/ComputeClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ private void SendSignalingPcasB(int argument)

// Should never return false for mismatching spec state, since the shader was fetched above.
_channel.TextureManager.CommitComputeBindings(cs.SpecializationState);

_channel.BufferManager.CommitComputeBindings();

_context.Renderer.Pipeline.DispatchCompute(qmd.CtaRasterWidth, qmd.CtaRasterHeight, qmd.CtaRasterDepth);
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Gpu/Engine/ShaderTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static class ShaderTexture
/// <returns>Texture target value</returns>
public static Target GetTarget(SamplerType type)
{
type &= ~(SamplerType.Indexed | SamplerType.Shadow);
type &= ~SamplerType.Shadow;

switch (type)
{
Expand Down
Loading
Loading