Update resource manager to allow overlapping image bindings with different sampler types

This commit is contained in:
Gabriel A 2023-10-29 15:21:38 -03:00
parent ae0bb5040e
commit 0d79a84bcf
4 changed files with 65 additions and 17 deletions

View file

@ -494,7 +494,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
}
else
{
context.Properties.Textures.TryGetValue(SetBindingPair.Unpack(texOp.Binding), out TextureDefinition definition);
context.Properties.Textures.TryGetValue(SetBindingPairWithType.Unpack(texOp.Binding, texOp.Type), out TextureDefinition definition);
bool hasLod = !definition.Type.HasFlag(SamplerType.Multisample) && (definition.Type & SamplerType.Mask) != SamplerType.TextureBuffer;
string texCall;
@ -710,12 +710,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
private static string GetSamplerName(ShaderProperties resourceDefinitions, AstTextureOperation texOp)
{
return resourceDefinitions.Textures[SetBindingPair.Unpack(texOp.Binding)].Name;
return resourceDefinitions.Textures[SetBindingPairWithType.Unpack(texOp.Binding, texOp.Type)].Name;
}
private static string GetImageName(ShaderProperties resourceDefinitions, AstTextureOperation texOp)
{
return resourceDefinitions.Images[SetBindingPair.Unpack(texOp.Binding)].Name;
return resourceDefinitions.Images[SetBindingPairWithType.Unpack(texOp.Binding, texOp.Type)].Name;
}
private static string GetMask(int index)

View file

@ -154,9 +154,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
}
}
private static void DeclareSamplers(CodeGenContext context, IReadOnlyDictionary<SetBindingPair, TextureDefinition> samplers)
private static void DeclareSamplers(CodeGenContext context, IReadOnlyDictionary<SetBindingPairWithType, TextureDefinition> samplers)
{
foreach ((SetBindingPair sbPair, var sampler) in samplers)
foreach ((SetBindingPairWithType sbPair, var sampler) in samplers)
{
int setIndex = context.TargetApi == TargetApi.Vulkan ? sampler.Set : 0;
@ -203,7 +203,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
if (sampler.ArraySize != 1)
{
context.BindlessTextures[sampler.Type & ~(SamplerType.Shadow | SamplerType.Separate)] = (imageType, sampledImageType, sampledImagePointerType, sampledImageVariable);
context.BindlessTextures[sbPair.Type] = (imageType, sampledImageType, sampledImagePointerType, sampledImageVariable);
}
else
{
@ -218,9 +218,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
}
}
private static void DeclareImages(CodeGenContext context, IReadOnlyDictionary<SetBindingPair, TextureDefinition> images)
private static void DeclareImages(CodeGenContext context, IReadOnlyDictionary<SetBindingPairWithType, TextureDefinition> images)
{
foreach ((SetBindingPair sbPair, var image) in images)
foreach ((SetBindingPairWithType sbPair, var image) in images)
{
int setIndex = context.TargetApi == TargetApi.Vulkan ? image.Set : 0;
@ -254,7 +254,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
if (image.ArraySize != 1)
{
context.BindlessImages[image.Type] = (imageType, imagePointerType, imageVariable);
context.BindlessImages[sbPair.Type] = (imageType, imagePointerType, imageVariable);
}
else
{

View file

@ -0,0 +1,48 @@
using System;
namespace Ryujinx.Graphics.Shader
{
readonly struct SetBindingPairWithType : IEquatable<SetBindingPairWithType>
{
public int Set { get; }
public int Binding { get; }
public SamplerType Type { get; }
public SetBindingPairWithType(int set, int binding, SamplerType type)
{
Set = set;
Binding = binding;
Type = type;
}
public override bool Equals(object obj)
{
return base.Equals(obj);
}
public bool Equals(SetBindingPairWithType other)
{
return other.Set == Set && other.Binding == Binding && other.Type == Type;
}
public override int GetHashCode()
{
return HashCode.Combine(Set, Binding, Type);
}
public int Pack()
{
return Pack(Set, Binding);
}
public static int Pack(int set, int binding)
{
return (ushort)set | (checked((ushort)binding) << 16);
}
public static SetBindingPairWithType Unpack(int packed, SamplerType type)
{
return new((ushort)packed, (ushort)((uint)packed >> 16), type & ~(SamplerType.Shadow | SamplerType.Separate));
}
}
}

View file

@ -6,15 +6,15 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
{
private readonly Dictionary<SetBindingPair, BufferDefinition> _constantBuffers;
private readonly Dictionary<SetBindingPair, BufferDefinition> _storageBuffers;
private readonly Dictionary<SetBindingPair, TextureDefinition> _textures;
private readonly Dictionary<SetBindingPair, TextureDefinition> _images;
private readonly Dictionary<SetBindingPairWithType, TextureDefinition> _textures;
private readonly Dictionary<SetBindingPairWithType, TextureDefinition> _images;
private readonly Dictionary<int, MemoryDefinition> _localMemories;
private readonly Dictionary<int, MemoryDefinition> _sharedMemories;
public IReadOnlyDictionary<SetBindingPair, BufferDefinition> ConstantBuffers => _constantBuffers;
public IReadOnlyDictionary<SetBindingPair, BufferDefinition> StorageBuffers => _storageBuffers;
public IReadOnlyDictionary<SetBindingPair, TextureDefinition> Textures => _textures;
public IReadOnlyDictionary<SetBindingPair, TextureDefinition> Images => _images;
public IReadOnlyDictionary<SetBindingPairWithType, TextureDefinition> Textures => _textures;
public IReadOnlyDictionary<SetBindingPairWithType, TextureDefinition> Images => _images;
public IReadOnlyDictionary<int, MemoryDefinition> LocalMemories => _localMemories;
public IReadOnlyDictionary<int, MemoryDefinition> SharedMemories => _sharedMemories;
@ -22,8 +22,8 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
{
_constantBuffers = new Dictionary<SetBindingPair, BufferDefinition>();
_storageBuffers = new Dictionary<SetBindingPair, BufferDefinition>();
_textures = new Dictionary<SetBindingPair, TextureDefinition>();
_images = new Dictionary<SetBindingPair, TextureDefinition>();
_textures = new Dictionary<SetBindingPairWithType, TextureDefinition>();
_images = new Dictionary<SetBindingPairWithType, TextureDefinition>();
_localMemories = new Dictionary<int, MemoryDefinition>();
_sharedMemories = new Dictionary<int, MemoryDefinition>();
}
@ -40,12 +40,12 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
public void AddOrUpdateTexture(TextureDefinition definition)
{
_textures[new(definition.Set, definition.Binding)] = definition;
_textures[new(definition.Set, definition.Binding, definition.Type & ~(SamplerType.Shadow | SamplerType.Separate))] = definition;
}
public void AddOrUpdateImage(TextureDefinition definition)
{
_images[new(definition.Set, definition.Binding)] = definition;
_images[new(definition.Set, definition.Binding, definition.Type & ~(SamplerType.Shadow | SamplerType.Separate))] = definition;
}
public int AddLocalMemory(MemoryDefinition definition)