diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs index e240d6495..ac4a7c1ab 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs @@ -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) diff --git a/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs b/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs index be95e4531..85bd8ab48 100644 --- a/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs +++ b/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs @@ -154,9 +154,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv } } - private static void DeclareSamplers(CodeGenContext context, IReadOnlyDictionary samplers) + private static void DeclareSamplers(CodeGenContext context, IReadOnlyDictionary 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 images) + private static void DeclareImages(CodeGenContext context, IReadOnlyDictionary 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 { diff --git a/src/Ryujinx.Graphics.Shader/StructuredIr/SetBindingPairWithType.cs b/src/Ryujinx.Graphics.Shader/StructuredIr/SetBindingPairWithType.cs new file mode 100644 index 000000000..67213c495 --- /dev/null +++ b/src/Ryujinx.Graphics.Shader/StructuredIr/SetBindingPairWithType.cs @@ -0,0 +1,48 @@ +using System; + +namespace Ryujinx.Graphics.Shader +{ + readonly struct SetBindingPairWithType : IEquatable + { + 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)); + } + } +} diff --git a/src/Ryujinx.Graphics.Shader/StructuredIr/ShaderProperties.cs b/src/Ryujinx.Graphics.Shader/StructuredIr/ShaderProperties.cs index 62013ac98..05b6faee8 100644 --- a/src/Ryujinx.Graphics.Shader/StructuredIr/ShaderProperties.cs +++ b/src/Ryujinx.Graphics.Shader/StructuredIr/ShaderProperties.cs @@ -6,15 +6,15 @@ namespace Ryujinx.Graphics.Shader.StructuredIr { private readonly Dictionary _constantBuffers; private readonly Dictionary _storageBuffers; - private readonly Dictionary _textures; - private readonly Dictionary _images; + private readonly Dictionary _textures; + private readonly Dictionary _images; private readonly Dictionary _localMemories; private readonly Dictionary _sharedMemories; public IReadOnlyDictionary ConstantBuffers => _constantBuffers; public IReadOnlyDictionary StorageBuffers => _storageBuffers; - public IReadOnlyDictionary Textures => _textures; - public IReadOnlyDictionary Images => _images; + public IReadOnlyDictionary Textures => _textures; + public IReadOnlyDictionary Images => _images; public IReadOnlyDictionary LocalMemories => _localMemories; public IReadOnlyDictionary SharedMemories => _sharedMemories; @@ -22,8 +22,8 @@ namespace Ryujinx.Graphics.Shader.StructuredIr { _constantBuffers = new Dictionary(); _storageBuffers = new Dictionary(); - _textures = new Dictionary(); - _images = new Dictionary(); + _textures = new Dictionary(); + _images = new Dictionary(); _localMemories = new Dictionary(); _sharedMemories = new Dictionary(); } @@ -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)