Pass texture set index everywhere

This commit is contained in:
Gabriel A 2024-05-24 18:13:48 -03:00
commit 566ad9209d
17 changed files with 182 additions and 67 deletions

View file

@ -1,4 +1,4 @@
using Ryujinx.Graphics.Shader.CodeGen; using Ryujinx.Graphics.Shader.CodeGen;
using System; using System;
namespace Ryujinx.Graphics.Shader namespace Ryujinx.Graphics.Shader

View file

@ -278,7 +278,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
flags |= TextureFlags.Bindless; flags |= TextureFlags.Bindless;
} }
int binding = isBindless ? 0 : context.ResourceManager.GetTextureOrImageBinding( SetBindingPair setAndBinding = isBindless ? default : context.ResourceManager.GetTextureOrImageBinding(
Instruction.ImageAtomic, Instruction.ImageAtomic,
type, type,
format, format,
@ -286,7 +286,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
TextureOperation.DefaultCbufSlot, TextureOperation.DefaultCbufSlot,
imm); imm);
Operand res = context.ImageAtomic(type, format, flags, binding, sources); Operand res = context.ImageAtomic(type, format, flags, setAndBinding, sources);
context.Copy(d, res); context.Copy(d, res);
} }
@ -389,7 +389,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
TextureFormat format = isBindless ? TextureFormat.Unknown : ShaderProperties.GetTextureFormat(context.TranslatorContext.GpuAccessor, handle); TextureFormat format = isBindless ? TextureFormat.Unknown : ShaderProperties.GetTextureFormat(context.TranslatorContext.GpuAccessor, handle);
int binding = isBindless ? 0 : context.ResourceManager.GetTextureOrImageBinding( SetBindingPair setAndBinding = isBindless ? default : context.ResourceManager.GetTextureOrImageBinding(
Instruction.ImageLoad, Instruction.ImageLoad,
type, type,
format, format,
@ -397,7 +397,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
TextureOperation.DefaultCbufSlot, TextureOperation.DefaultCbufSlot,
handle); handle);
context.ImageLoad(type, format, flags, binding, (int)componentMask, dests, sources); context.ImageLoad(type, format, flags, setAndBinding, (int)componentMask, dests, sources);
} }
else else
{ {
@ -432,7 +432,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
TextureFormat format = GetTextureFormat(size); TextureFormat format = GetTextureFormat(size);
int binding = isBindless ? 0 : context.ResourceManager.GetTextureOrImageBinding( SetBindingPair setAndBinding = isBindless ? default : context.ResourceManager.GetTextureOrImageBinding(
Instruction.ImageLoad, Instruction.ImageLoad,
type, type,
format, format,
@ -440,7 +440,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
TextureOperation.DefaultCbufSlot, TextureOperation.DefaultCbufSlot,
handle); handle);
context.ImageLoad(type, format, flags, binding, compMask, dests, sources); context.ImageLoad(type, format, flags, setAndBinding, compMask, dests, sources);
switch (size) switch (size)
{ {
@ -552,7 +552,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
flags |= TextureFlags.Bindless; flags |= TextureFlags.Bindless;
} }
int binding = isBindless ? 0 : context.ResourceManager.GetTextureOrImageBinding( SetBindingPair setAndBinding = isBindless ? default : context.ResourceManager.GetTextureOrImageBinding(
Instruction.ImageAtomic, Instruction.ImageAtomic,
type, type,
format, format,
@ -560,7 +560,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
TextureOperation.DefaultCbufSlot, TextureOperation.DefaultCbufSlot,
imm); imm);
context.ImageAtomic(type, format, flags, binding, sources); context.ImageAtomic(type, format, flags, setAndBinding, sources);
} }
private static void EmitSust( private static void EmitSust(
@ -679,7 +679,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
flags |= TextureFlags.Coherent; flags |= TextureFlags.Coherent;
} }
int binding = isBindless ? 0 : context.ResourceManager.GetTextureOrImageBinding( SetBindingPair setAndBinding = isBindless ? default : context.ResourceManager.GetTextureOrImageBinding(
Instruction.ImageStore, Instruction.ImageStore,
type, type,
format, format,
@ -687,7 +687,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
TextureOperation.DefaultCbufSlot, TextureOperation.DefaultCbufSlot,
handle); handle);
context.ImageStore(type, format, flags, binding, sources); context.ImageStore(type, format, flags, setAndBinding, sources);
} }
private static int GetComponentSizeInBytesLog2(SuatomSize size) private static int GetComponentSizeInBytesLog2(SuatomSize size)

View file

@ -885,7 +885,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
return Register(dest++, RegisterType.Gpr); return Register(dest++, RegisterType.Gpr);
} }
int binding = isBindless ? 0 : context.ResourceManager.GetTextureOrImageBinding( SetBindingPair setAndBinding = isBindless ? default : context.ResourceManager.GetTextureOrImageBinding(
Instruction.Lod, Instruction.Lod,
type, type,
TextureFormat.Unknown, TextureFormat.Unknown,
@ -913,7 +913,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
else else
{ {
// The instruction component order is the inverse of GLSL's. // The instruction component order is the inverse of GLSL's.
Operand res = context.Lod(type, flags, binding, compIndex ^ 1, sources); Operand res = context.Lod(type, flags, setAndBinding, compIndex ^ 1, sources);
res = context.FPMultiply(res, ConstF(256.0f)); res = context.FPMultiply(res, ConstF(256.0f));
@ -1116,12 +1116,12 @@ namespace Ryujinx.Graphics.Shader.Instructions
} }
TextureFlags flags = isBindless ? TextureFlags.Bindless : TextureFlags.None; TextureFlags flags = isBindless ? TextureFlags.Bindless : TextureFlags.None;
int binding; SetBindingPair setAndBinding;
switch (query) switch (query)
{ {
case TexQuery.TexHeaderDimension: case TexQuery.TexHeaderDimension:
binding = isBindless ? 0 : context.ResourceManager.GetTextureOrImageBinding( setAndBinding = isBindless ? default : context.ResourceManager.GetTextureOrImageBinding(
Instruction.TextureQuerySize, Instruction.TextureQuerySize,
type, type,
TextureFormat.Unknown, TextureFormat.Unknown,
@ -1140,13 +1140,13 @@ namespace Ryujinx.Graphics.Shader.Instructions
break; break;
} }
context.Copy(d, context.TextureQuerySize(type, flags, binding, compIndex, sources)); context.Copy(d, context.TextureQuerySize(type, flags, setAndBinding, compIndex, sources));
} }
} }
break; break;
case TexQuery.TexHeaderTextureType: case TexQuery.TexHeaderTextureType:
binding = isBindless ? 0 : context.ResourceManager.GetTextureOrImageBinding( setAndBinding = isBindless ? default : context.ResourceManager.GetTextureOrImageBinding(
Instruction.TextureQuerySamples, Instruction.TextureQuerySamples,
type, type,
TextureFormat.Unknown, TextureFormat.Unknown,
@ -1171,7 +1171,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
if (d != null) if (d != null)
{ {
context.Copy(d, context.TextureQuerySamples(type, flags, binding, sources)); context.Copy(d, context.TextureQuerySamples(type, flags, setAndBinding, sources));
} }
} }
break; break;
@ -1191,7 +1191,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
Operand[] dests, Operand[] dests,
Operand[] sources) Operand[] sources)
{ {
int binding = flags.HasFlag(TextureFlags.Bindless) ? 0 : context.ResourceManager.GetTextureOrImageBinding( SetBindingPair setAndBinding = flags.HasFlag(TextureFlags.Bindless) ? default : context.ResourceManager.GetTextureOrImageBinding(
Instruction.TextureSample, Instruction.TextureSample,
type, type,
TextureFormat.Unknown, TextureFormat.Unknown,
@ -1199,7 +1199,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
TextureOperation.DefaultCbufSlot, TextureOperation.DefaultCbufSlot,
handle); handle);
context.TextureSample(type, flags, binding, componentMask, dests, sources); context.TextureSample(type, flags, setAndBinding, componentMask, dests, sources);
} }
private static SamplerType ConvertSamplerType(TexDim dimensions) private static SamplerType ConvertSamplerType(TexDim dimensions)

View file

@ -8,7 +8,9 @@ namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
public TextureFormat Format { get; set; } public TextureFormat Format { get; set; }
public TextureFlags Flags { get; private set; } public TextureFlags Flags { get; private set; }
public int Set { get; private set; }
public int Binding { get; private set; } public int Binding { get; private set; }
public int SamplerSet { get; private set; }
public int SamplerBinding { get; private set; } public int SamplerBinding { get; private set; }
public TextureOperation( public TextureOperation(
@ -16,6 +18,7 @@ namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
SamplerType type, SamplerType type,
TextureFormat format, TextureFormat format,
TextureFlags flags, TextureFlags flags,
int set,
int binding, int binding,
int compIndex, int compIndex,
Operand[] dests, Operand[] dests,
@ -24,24 +27,28 @@ namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
Type = type; Type = type;
Format = format; Format = format;
Flags = flags; Flags = flags;
Set = set;
Binding = binding; Binding = binding;
SamplerSet = -1;
SamplerBinding = -1; SamplerBinding = -1;
} }
public void TurnIntoArray(int binding) public void TurnIntoArray(SetBindingPair setAndBinding)
{ {
Flags &= ~TextureFlags.Bindless; Flags &= ~TextureFlags.Bindless;
Binding = binding; Set = setAndBinding.SetIndex;
Binding = setAndBinding.Binding;
} }
public void TurnIntoArray(int textureBinding, int samplerBinding) public void TurnIntoArray(SetBindingPair textureSetAndBinding, SetBindingPair samplerSetAndBinding)
{ {
TurnIntoArray(textureBinding); TurnIntoArray(textureSetAndBinding);
SamplerBinding = samplerBinding; SamplerSet = samplerSetAndBinding.SetIndex;
SamplerBinding = samplerSetAndBinding.Binding;
} }
public void SetBinding(int binding) public void SetBinding(SetBindingPair setAndBinding)
{ {
if ((Flags & TextureFlags.Bindless) != 0) if ((Flags & TextureFlags.Bindless) != 0)
{ {
@ -50,7 +57,8 @@ namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
RemoveSource(0); RemoveSource(0);
} }
Binding = binding; Set = setAndBinding.SetIndex;
Binding = setAndBinding.Binding;
} }
public void SetLodLevelFlag() public void SetLodLevelFlag()

View file

@ -38,4 +38,4 @@ namespace Ryujinx.Graphics.Shader
return !(left == right); return !(left == right);
} }
} }
} }

View file

@ -8,7 +8,9 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
public TextureFormat Format { get; } public TextureFormat Format { get; }
public TextureFlags Flags { get; } public TextureFlags Flags { get; }
public int Set { get; }
public int Binding { get; } public int Binding { get; }
public int SamplerSet { get; }
public int SamplerBinding { get; } public int SamplerBinding { get; }
public bool IsSeparate => SamplerBinding >= 0; public bool IsSeparate => SamplerBinding >= 0;
@ -18,7 +20,9 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
SamplerType type, SamplerType type,
TextureFormat format, TextureFormat format,
TextureFlags flags, TextureFlags flags,
int set,
int binding, int binding,
int samplerSet,
int samplerBinding, int samplerBinding,
int index, int index,
params IAstNode[] sources) : base(inst, StorageKind.None, false, index, sources, sources.Length) params IAstNode[] sources) : base(inst, StorageKind.None, false, index, sources, sources.Length)
@ -26,7 +30,9 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
Type = type; Type = type;
Format = format; Format = format;
Flags = flags; Flags = flags;
Set = set;
Binding = binding; Binding = binding;
SamplerSet = samplerSet;
SamplerBinding = samplerBinding; SamplerBinding = samplerBinding;
} }
} }

View file

@ -169,7 +169,17 @@ namespace Ryujinx.Graphics.Shader.StructuredIr
AstTextureOperation GetAstTextureOperation(TextureOperation texOp) AstTextureOperation GetAstTextureOperation(TextureOperation texOp)
{ {
return new AstTextureOperation(inst, texOp.Type, texOp.Format, texOp.Flags, texOp.Binding, texOp.SamplerBinding, texOp.Index, sources); return new AstTextureOperation(
inst,
texOp.Type,
texOp.Format,
texOp.Flags,
texOp.Set,
texOp.Binding,
texOp.SamplerSet,
texOp.SamplerBinding,
texOp.Index,
sources);
} }
int componentsCount = BitOperations.PopCount((uint)operation.Index); int componentsCount = BitOperations.PopCount((uint)operation.Index);

View file

@ -124,7 +124,7 @@ namespace Ryujinx.Graphics.Shader.Translation
this.TextureSample( this.TextureSample(
SamplerType.TextureBuffer, SamplerType.TextureBuffer,
TextureFlags.IntCoords, TextureFlags.IntCoords,
ResourceManager.Reservations.IndexBufferTextureBinding, ResourceManager.Reservations.GetIndexBufferTextureSetAndBinding(),
1, 1,
new[] { vertexIndexVr }, new[] { vertexIndexVr },
new[] { this.IAdd(ibBaseOffset, outputVertexOffset) }); new[] { this.IAdd(ibBaseOffset, outputVertexOffset) });
@ -145,7 +145,7 @@ namespace Ryujinx.Graphics.Shader.Translation
this.TextureSample( this.TextureSample(
SamplerType.TextureBuffer, SamplerType.TextureBuffer,
TextureFlags.IntCoords, TextureFlags.IntCoords,
ResourceManager.Reservations.TopologyRemapBufferTextureBinding, ResourceManager.Reservations.GetTopologyRemapBufferTextureSetAndBinding(),
1, 1,
new[] { vertexIndex }, new[] { vertexIndex },
new[] { this.IAdd(baseVertex, Const(index)) }); new[] { this.IAdd(baseVertex, Const(index)) });

View file

@ -618,12 +618,21 @@ namespace Ryujinx.Graphics.Shader.Translation
SamplerType type, SamplerType type,
TextureFormat format, TextureFormat format,
TextureFlags flags, TextureFlags flags,
int binding, SetBindingPair setAndBinding,
Operand[] sources) Operand[] sources)
{ {
Operand dest = Local(); Operand dest = Local();
context.Add(new TextureOperation(Instruction.ImageAtomic, type, format, flags, binding, 0, new[] { dest }, sources)); context.Add(new TextureOperation(
Instruction.ImageAtomic,
type,
format,
flags,
setAndBinding.SetIndex,
setAndBinding.Binding,
0,
new[] { dest },
sources));
return dest; return dest;
} }
@ -633,12 +642,21 @@ namespace Ryujinx.Graphics.Shader.Translation
SamplerType type, SamplerType type,
TextureFormat format, TextureFormat format,
TextureFlags flags, TextureFlags flags,
int binding, SetBindingPair setAndBinding,
int compMask, int compMask,
Operand[] dests, Operand[] dests,
Operand[] sources) Operand[] sources)
{ {
context.Add(new TextureOperation(Instruction.ImageLoad, type, format, flags, binding, compMask, dests, sources)); context.Add(new TextureOperation(
Instruction.ImageLoad,
type,
format,
flags,
setAndBinding.SetIndex,
setAndBinding.Binding,
compMask,
dests,
sources));
} }
public static void ImageStore( public static void ImageStore(
@ -646,10 +664,19 @@ namespace Ryujinx.Graphics.Shader.Translation
SamplerType type, SamplerType type,
TextureFormat format, TextureFormat format,
TextureFlags flags, TextureFlags flags,
int binding, SetBindingPair setAndBinding,
Operand[] sources) Operand[] sources)
{ {
context.Add(new TextureOperation(Instruction.ImageStore, type, format, flags, binding, 0, null, sources)); context.Add(new TextureOperation(
Instruction.ImageStore,
type,
format,
flags,
setAndBinding.SetIndex,
setAndBinding.Binding,
0,
null,
sources));
} }
public static Operand IsNan(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32) public static Operand IsNan(this EmitterContext context, Operand a, Instruction fpType = Instruction.FP32)
@ -718,13 +745,22 @@ namespace Ryujinx.Graphics.Shader.Translation
this EmitterContext context, this EmitterContext context,
SamplerType type, SamplerType type,
TextureFlags flags, TextureFlags flags,
int binding, SetBindingPair setAndBinding,
int compIndex, int compIndex,
Operand[] sources) Operand[] sources)
{ {
Operand dest = Local(); Operand dest = Local();
context.Add(new TextureOperation(Instruction.Lod, type, TextureFormat.Unknown, flags, binding, compIndex, new[] { dest }, sources)); context.Add(new TextureOperation(
Instruction.Lod,
type,
TextureFormat.Unknown,
flags,
setAndBinding.SetIndex,
setAndBinding.Binding,
compIndex,
new[] { dest },
sources));
return dest; return dest;
} }
@ -889,24 +925,42 @@ namespace Ryujinx.Graphics.Shader.Translation
this EmitterContext context, this EmitterContext context,
SamplerType type, SamplerType type,
TextureFlags flags, TextureFlags flags,
int binding, SetBindingPair setAndBinding,
int compMask, int compMask,
Operand[] dests, Operand[] dests,
Operand[] sources) Operand[] sources)
{ {
context.Add(new TextureOperation(Instruction.TextureSample, type, TextureFormat.Unknown, flags, binding, compMask, dests, sources)); context.Add(new TextureOperation(
Instruction.TextureSample,
type,
TextureFormat.Unknown,
flags,
setAndBinding.SetIndex,
setAndBinding.Binding,
compMask,
dests,
sources));
} }
public static Operand TextureQuerySamples( public static Operand TextureQuerySamples(
this EmitterContext context, this EmitterContext context,
SamplerType type, SamplerType type,
TextureFlags flags, TextureFlags flags,
int binding, SetBindingPair setAndBinding,
Operand[] sources) Operand[] sources)
{ {
Operand dest = Local(); Operand dest = Local();
context.Add(new TextureOperation(Instruction.TextureQuerySamples, type, TextureFormat.Unknown, flags, binding, 0, new[] { dest }, sources)); context.Add(new TextureOperation(
Instruction.TextureQuerySamples,
type,
TextureFormat.Unknown,
flags,
setAndBinding.SetIndex,
setAndBinding.Binding,
0,
new[] { dest },
sources));
return dest; return dest;
} }
@ -915,13 +969,22 @@ namespace Ryujinx.Graphics.Shader.Translation
this EmitterContext context, this EmitterContext context,
SamplerType type, SamplerType type,
TextureFlags flags, TextureFlags flags,
int binding, SetBindingPair setAndBinding,
int compIndex, int compIndex,
Operand[] sources) Operand[] sources)
{ {
Operand dest = Local(); Operand dest = Local();
context.Add(new TextureOperation(Instruction.TextureQuerySize, type, TextureFormat.Unknown, flags, binding, compIndex, new[] { dest }, sources)); context.Add(new TextureOperation(
Instruction.TextureQuerySize,
type,
TextureFormat.Unknown,
flags,
setAndBinding.SetIndex,
setAndBinding.Binding,
compIndex,
new[] { dest },
sources));
return dest; return dest;
} }

View file

@ -91,7 +91,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
bool hasSampler = !texOp.Inst.IsImage(); bool hasSampler = !texOp.Inst.IsImage();
int textureBinding = resourceManager.GetTextureOrImageBinding( SetBindingPair textureSetAndBinding = resourceManager.GetTextureOrImageBinding(
texOp.Inst, texOp.Inst,
texOp.Type, texOp.Type,
texOp.Format, texOp.Format,
@ -111,7 +111,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
texOp.InsertSource(1, samplerIndex); texOp.InsertSource(1, samplerIndex);
int samplerBinding = resourceManager.GetTextureOrImageBinding( SetBindingPair samplerSetAndBinding = resourceManager.GetTextureOrImageBinding(
texOp.Inst, texOp.Inst,
SamplerType.None, SamplerType.None,
texOp.Format, texOp.Format,
@ -120,11 +120,11 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
TextureHandle.PackOffsets(0, 0, TextureHandleType.Direct), TextureHandle.PackOffsets(0, 0, TextureHandleType.Direct),
samplerPoolLength); samplerPoolLength);
texOp.TurnIntoArray(textureBinding, samplerBinding); texOp.TurnIntoArray(textureSetAndBinding, samplerSetAndBinding);
} }
else else
{ {
texOp.TurnIntoArray(textureBinding); texOp.TurnIntoArray(textureSetAndBinding);
} }
return true; return true;
@ -445,7 +445,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
} }
} }
int binding = resourceManager.GetTextureOrImageBinding( SetBindingPair setAndBinding = resourceManager.GetTextureOrImageBinding(
texOp.Inst, texOp.Inst,
texOp.Type, texOp.Type,
texOp.Format, texOp.Format,
@ -453,7 +453,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
cbufSlot, cbufSlot,
cbufOffset); cbufOffset);
texOp.SetBinding(binding); texOp.SetBinding(setAndBinding);
} }
} }
} }

View file

@ -221,7 +221,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
private static void TurnIntoArray(ResourceManager resourceManager, TextureOperation texOp, int cbufSlot, int handleIndex, int length) private static void TurnIntoArray(ResourceManager resourceManager, TextureOperation texOp, int cbufSlot, int handleIndex, int length)
{ {
int binding = resourceManager.GetTextureOrImageBinding( SetBindingPair setAndBinding = resourceManager.GetTextureOrImageBinding(
texOp.Inst, texOp.Inst,
texOp.Type, texOp.Type,
texOp.Format, texOp.Format,
@ -230,7 +230,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
handleIndex, handleIndex,
length); length);
texOp.TurnIntoArray(binding); texOp.TurnIntoArray(setAndBinding);
} }
} }
} }

View file

@ -221,7 +221,7 @@ namespace Ryujinx.Graphics.Shader.Translation
return false; return false;
} }
public int GetTextureOrImageBinding( public SetBindingPair GetTextureOrImageBinding(
Instruction inst, Instruction inst,
SamplerType type, SamplerType type,
TextureFormat format, TextureFormat format,
@ -243,7 +243,7 @@ namespace Ryujinx.Graphics.Shader.Translation
format = TextureFormat.Unknown; format = TextureFormat.Unknown;
} }
int binding = GetTextureOrImageBinding( SetBindingPair setAndBinding = GetTextureOrImageBinding(
cbufSlot, cbufSlot,
handle, handle,
arrayLength, arrayLength,
@ -258,10 +258,10 @@ namespace Ryujinx.Graphics.Shader.Translation
_gpuAccessor.RegisterTexture(handle, cbufSlot); _gpuAccessor.RegisterTexture(handle, cbufSlot);
return binding; return setAndBinding;
} }
private int GetTextureOrImageBinding( private SetBindingPair GetTextureOrImageBinding(
int cbufSlot, int cbufSlot,
int handle, int handle,
int arrayLength, int arrayLength,
@ -381,7 +381,7 @@ namespace Ryujinx.Graphics.Shader.Translation
Properties.AddOrUpdateTexture(definition); Properties.AddOrUpdateTexture(definition);
} }
return binding; return new SetBindingPair(setIndex, binding);
} }
private static TextureMeta MergeTextureMeta(TextureMeta meta, TextureMeta existingMeta) private static TextureMeta MergeTextureMeta(TextureMeta meta, TextureMeta existingMeta)

View file

@ -11,6 +11,8 @@ namespace Ryujinx.Graphics.Shader.Translation
public const int MaxVertexBufferTextures = 32; public const int MaxVertexBufferTextures = 32;
private const int TextureSetIndex = 2; // TODO: Get from GPU accessor.
public int VertexInfoConstantBufferBinding { get; } public int VertexInfoConstantBufferBinding { get; }
public int VertexOutputStorageBufferBinding { get; } public int VertexOutputStorageBufferBinding { get; }
public int GeometryVertexOutputStorageBufferBinding { get; } public int GeometryVertexOutputStorageBufferBinding { get; }
@ -163,6 +165,21 @@ namespace Ryujinx.Graphics.Shader.Translation
return _vertexBufferTextureBaseBinding + vaLocation; return _vertexBufferTextureBaseBinding + vaLocation;
} }
public SetBindingPair GetVertexBufferTextureSetAndBinding(int vaLocation)
{
return new SetBindingPair(TextureSetIndex, GetVertexBufferTextureBinding(vaLocation));
}
public SetBindingPair GetIndexBufferTextureSetAndBinding()
{
return new SetBindingPair(TextureSetIndex, IndexBufferTextureBinding);
}
public SetBindingPair GetTopologyRemapBufferTextureSetAndBinding()
{
return new SetBindingPair(TextureSetIndex, TopologyRemapBufferTextureBinding);
}
internal bool TryGetOffset(StorageKind storageKind, int location, int component, out int offset) internal bool TryGetOffset(StorageKind storageKind, int location, int component, out int offset)
{ {
return _offsets.TryGetValue(new IoDefinition(storageKind, IoVariable.UserDefined, location, component), out offset); return _offsets.TryGetValue(new IoDefinition(storageKind, IoVariable.UserDefined, location, component), out offset);

View file

@ -182,6 +182,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
texOp.Type, texOp.Type,
texOp.Format, texOp.Format,
texOp.Flags, texOp.Flags,
texOp.Set,
texOp.Binding, texOp.Binding,
index, index,
new[] { coordSize }, new[] { coordSize },
@ -251,6 +252,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
texOp.Type, texOp.Type,
texOp.Format, texOp.Format,
texOp.Flags, texOp.Flags,
texOp.Set,
texOp.Binding, texOp.Binding,
index, index,
new[] { coordSize }, new[] { coordSize },
@ -471,6 +473,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
texOp.Type, texOp.Type,
texOp.Format, texOp.Format,
texOp.Flags & ~(TextureFlags.Offset | TextureFlags.Offsets), texOp.Flags & ~(TextureFlags.Offset | TextureFlags.Offsets),
texOp.Set,
texOp.Binding, texOp.Binding,
1 << 3, // W component: i=0, j=0 1 << 3, // W component: i=0, j=0
new[] { dests[destIndex++] }, new[] { dests[destIndex++] },
@ -527,6 +530,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
texOp.Type, texOp.Type,
texOp.Format, texOp.Format,
texOp.Flags & ~(TextureFlags.Offset | TextureFlags.Offsets), texOp.Flags & ~(TextureFlags.Offset | TextureFlags.Offsets),
texOp.Set,
texOp.Binding, texOp.Binding,
componentIndex, componentIndex,
dests, dests,
@ -573,6 +577,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
texOp.Type, texOp.Type,
texOp.Format, texOp.Format,
texOp.Flags, texOp.Flags,
texOp.Set,
texOp.Binding, texOp.Binding,
index, index,
new[] { texSizes[index] }, new[] { texSizes[index] },
@ -603,6 +608,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
texOp.Type, texOp.Type,
texOp.Format, texOp.Format,
texOp.Flags, texOp.Flags,
texOp.Set,
texOp.Binding, texOp.Binding,
0, 0,
new[] { lod }, new[] { lod },
@ -633,6 +639,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
texOp.Type, texOp.Type,
texOp.Format, texOp.Format,
texOp.Flags, texOp.Flags,
texOp.Set,
texOp.Binding, texOp.Binding,
index, index,
new[] { texSizes[index] }, new[] { texSizes[index] },

View file

@ -54,6 +54,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
{ {
bool needsSextNorm = context.Definitions.IsAttributePackedRgb10A2Signed(location); bool needsSextNorm = context.Definitions.IsAttributePackedRgb10A2Signed(location);
SetBindingPair setAndBinding = context.ResourceManager.Reservations.GetVertexBufferTextureSetAndBinding(location);
Operand temp = needsSextNorm ? Local() : dest; Operand temp = needsSextNorm ? Local() : dest;
Operand vertexElemOffset = GenerateVertexOffset(context.ResourceManager, node, location, 0); Operand vertexElemOffset = GenerateVertexOffset(context.ResourceManager, node, location, 0);
@ -62,7 +63,8 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
SamplerType.TextureBuffer, SamplerType.TextureBuffer,
TextureFormat.Unknown, TextureFormat.Unknown,
TextureFlags.IntCoords, TextureFlags.IntCoords,
context.ResourceManager.Reservations.GetVertexBufferTextureBinding(location), setAndBinding.SetIndex,
setAndBinding.Binding,
1 << component, 1 << component,
new[] { temp }, new[] { temp },
new[] { vertexElemOffset })); new[] { vertexElemOffset }));
@ -75,6 +77,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
} }
else else
{ {
SetBindingPair setAndBinding = context.ResourceManager.Reservations.GetVertexBufferTextureSetAndBinding(location);
Operand temp = component > 0 ? Local() : dest; Operand temp = component > 0 ? Local() : dest;
Operand vertexElemOffset = GenerateVertexOffset(context.ResourceManager, node, location, component); Operand vertexElemOffset = GenerateVertexOffset(context.ResourceManager, node, location, component);
@ -83,7 +86,8 @@ namespace Ryujinx.Graphics.Shader.Translation.Transforms
SamplerType.TextureBuffer, SamplerType.TextureBuffer,
TextureFormat.Unknown, TextureFormat.Unknown,
TextureFlags.IntCoords, TextureFlags.IntCoords,
context.ResourceManager.Reservations.GetVertexBufferTextureBinding(location), setAndBinding.SetIndex,
setAndBinding.Binding,
1, 1,
new[] { temp }, new[] { temp },
new[] { vertexElemOffset })); new[] { vertexElemOffset }));

View file

@ -412,8 +412,8 @@ namespace Ryujinx.Graphics.Shader.Translation
if (Stage == ShaderStage.Vertex) if (Stage == ShaderStage.Vertex)
{ {
int ibBinding = resourceManager.Reservations.IndexBufferTextureBinding; SetBindingPair ibSetAndBinding = resourceManager.Reservations.GetIndexBufferTextureSetAndBinding();
TextureDefinition indexBuffer = new(2, ibBinding, "ib_data", SamplerType.TextureBuffer); TextureDefinition indexBuffer = new(ibSetAndBinding.SetIndex, ibSetAndBinding.Binding, "ib_data", SamplerType.TextureBuffer);
resourceManager.Properties.AddOrUpdateTexture(indexBuffer); resourceManager.Properties.AddOrUpdateTexture(indexBuffer);
int inputMap = _program.AttributeUsage.UsedInputAttributes; int inputMap = _program.AttributeUsage.UsedInputAttributes;
@ -421,8 +421,8 @@ namespace Ryujinx.Graphics.Shader.Translation
while (inputMap != 0) while (inputMap != 0)
{ {
int location = BitOperations.TrailingZeroCount(inputMap); int location = BitOperations.TrailingZeroCount(inputMap);
int binding = resourceManager.Reservations.GetVertexBufferTextureBinding(location); SetBindingPair setAndBinding = resourceManager.Reservations.GetVertexBufferTextureSetAndBinding(location);
TextureDefinition vaBuffer = new(2, binding, $"vb_data{location}", SamplerType.TextureBuffer); TextureDefinition vaBuffer = new(setAndBinding.SetIndex, setAndBinding.Binding, $"vb_data{location}", SamplerType.TextureBuffer);
resourceManager.Properties.AddOrUpdateTexture(vaBuffer); resourceManager.Properties.AddOrUpdateTexture(vaBuffer);
inputMap &= ~(1 << location); inputMap &= ~(1 << location);
@ -430,8 +430,8 @@ namespace Ryujinx.Graphics.Shader.Translation
} }
else if (Stage == ShaderStage.Geometry) else if (Stage == ShaderStage.Geometry)
{ {
int trbBinding = resourceManager.Reservations.TopologyRemapBufferTextureBinding; SetBindingPair trbSetAndBinding = resourceManager.Reservations.GetTopologyRemapBufferTextureSetAndBinding();
TextureDefinition remapBuffer = new(2, trbBinding, "trb_data", SamplerType.TextureBuffer); TextureDefinition remapBuffer = new(trbSetAndBinding.SetIndex, trbSetAndBinding.Binding, "trb_data", SamplerType.TextureBuffer);
resourceManager.Properties.AddOrUpdateTexture(remapBuffer); resourceManager.Properties.AddOrUpdateTexture(remapBuffer);
int geometryVbOutputSbBinding = resourceManager.Reservations.GeometryVertexOutputStorageBufferBinding; int geometryVbOutputSbBinding = resourceManager.Reservations.GeometryVertexOutputStorageBufferBinding;

View file

@ -1,4 +1,4 @@
using CommandLine; using CommandLine;
using Ryujinx.Graphics.Shader; using Ryujinx.Graphics.Shader;
using Ryujinx.Graphics.Shader.Translation; using Ryujinx.Graphics.Shader.Translation;
using System; using System;