aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Shader/Instructions
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2023-07-03 14:29:27 -0300
committerGitHub <noreply@github.com>2023-07-03 14:29:27 -0300
commit1c7a90ef359d9974e5bd257c4d8e9bf526a6966c (patch)
tree3ab1644927819b90b0aef78ed6749c6434150490 /src/Ryujinx.Graphics.Shader/Instructions
parent3b46bb73f781a011705ecbc8a1d3207dfb145829 (diff)
Stop identifying shader textures with handle and cbuf, use binding instead (#5266)
* Stop identifying shader textures with handle and cbuf, use binding instead * Remove now unused code * Consider image operations as having accurate type information too I don't know why that was not the case before * Fix missing unscale on InsertCoordNormalization, stop calling SetUsageFlagsForTextureQuery when not needed * Shader cache version bump * Change get texture methods to return descriptors created from ResourceManager state This is required to ensure that reserved textures and images will not be bound as a guest texture/image * Fix BindlessElimination.SetHandle inserting coords at the wrong place
Diffstat (limited to 'src/Ryujinx.Graphics.Shader/Instructions')
-rw-r--r--src/Ryujinx.Graphics.Shader/Instructions/InstEmitSurface.cs66
-rw-r--r--src/Ryujinx.Graphics.Shader/Instructions/InstEmitTexture.cs132
2 files changed, 83 insertions, 115 deletions
diff --git a/src/Ryujinx.Graphics.Shader/Instructions/InstEmitSurface.cs b/src/Ryujinx.Graphics.Shader/Instructions/InstEmitSurface.cs
index 78fc313d..0b929307 100644
--- a/src/Ryujinx.Graphics.Shader/Instructions/InstEmitSurface.cs
+++ b/src/Ryujinx.Graphics.Shader/Instructions/InstEmitSurface.cs
@@ -218,7 +218,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
return context.Copy(Register(srcB++, RegisterType.Gpr));
}
- Operand destOperand = dest != RegisterConsts.RegisterZeroIndex ? Register(dest, RegisterType.Gpr) : null;
+ Operand d = dest != RegisterConsts.RegisterZeroIndex ? Register(dest, RegisterType.Gpr) : null;
List<Operand> sourcesList = new();
@@ -277,17 +277,17 @@ namespace Ryujinx.Graphics.Shader.Instructions
flags |= TextureFlags.Bindless;
}
- TextureOperation operation = context.CreateTextureOperation(
+ int binding = isBindless ? 0 : context.Config.ResourceManager.GetTextureOrImageBinding(
Instruction.ImageAtomic,
type,
format,
flags,
- imm,
- 0,
- new[] { destOperand },
- sources);
+ TextureOperation.DefaultCbufSlot,
+ imm);
+
+ Operand res = context.ImageAtomic(type, format, flags, binding, sources);
- context.Add(operation);
+ context.Copy(d, res);
}
private static void EmitSuld(
@@ -383,21 +383,17 @@ namespace Ryujinx.Graphics.Shader.Instructions
Array.Resize(ref dests, outputIndex);
}
- TextureOperation operation = context.CreateTextureOperation(
+ TextureFormat format = isBindless ? TextureFormat.Unknown : context.Config.GetTextureFormat(handle);
+
+ int binding = isBindless ? 0 : context.Config.ResourceManager.GetTextureOrImageBinding(
Instruction.ImageLoad,
type,
+ format,
flags,
- handle,
- (int)componentMask,
- dests,
- sources);
-
- if (!isBindless)
- {
- operation.Format = context.Config.GetTextureFormat(handle);
- }
+ TextureOperation.DefaultCbufSlot,
+ handle);
- context.Add(operation);
+ context.ImageLoad(type, format, flags, binding, (int)componentMask, dests, sources);
}
else
{
@@ -430,17 +426,17 @@ namespace Ryujinx.Graphics.Shader.Instructions
Array.Resize(ref dests, outputIndex);
}
- TextureOperation operation = context.CreateTextureOperation(
+ TextureFormat format = GetTextureFormat(size);
+
+ int binding = isBindless ? 0 : context.Config.ResourceManager.GetTextureOrImageBinding(
Instruction.ImageLoad,
type,
- GetTextureFormat(size),
+ format,
flags,
- handle,
- compMask,
- dests,
- sources);
+ TextureOperation.DefaultCbufSlot,
+ handle);
- context.Add(operation);
+ context.ImageLoad(type, format, flags, binding, compMask, dests, sources);
switch (size)
{
@@ -552,17 +548,15 @@ namespace Ryujinx.Graphics.Shader.Instructions
flags |= TextureFlags.Bindless;
}
- TextureOperation operation = context.CreateTextureOperation(
+ int binding = isBindless ? 0 : context.Config.ResourceManager.GetTextureOrImageBinding(
Instruction.ImageAtomic,
type,
format,
flags,
- imm,
- 0,
- null,
- sources);
+ TextureOperation.DefaultCbufSlot,
+ imm);
- context.Add(operation);
+ context.ImageAtomic(type, format, flags, binding, sources);
}
private static void EmitSust(
@@ -681,17 +675,15 @@ namespace Ryujinx.Graphics.Shader.Instructions
flags |= TextureFlags.Coherent;
}
- TextureOperation operation = context.CreateTextureOperation(
+ int binding = isBindless ? 0 : context.Config.ResourceManager.GetTextureOrImageBinding(
Instruction.ImageStore,
type,
format,
flags,
- handle,
- 0,
- null,
- sources);
+ TextureOperation.DefaultCbufSlot,
+ handle);
- context.Add(operation);
+ context.ImageStore(type, format, flags, binding, sources);
}
private static int GetComponentSizeInBytesLog2(SuatomSize size)
diff --git a/src/Ryujinx.Graphics.Shader/Instructions/InstEmitTexture.cs b/src/Ryujinx.Graphics.Shader/Instructions/InstEmitTexture.cs
index 3701325e..7d3d22d8 100644
--- a/src/Ryujinx.Graphics.Shader/Instructions/InstEmitTexture.cs
+++ b/src/Ryujinx.Graphics.Shader/Instructions/InstEmitTexture.cs
@@ -324,16 +324,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
int handle = !isBindless ? imm : 0;
- TextureOperation operation = context.CreateTextureOperation(
- Instruction.TextureSample,
- type,
- flags,
- handle,
- componentMask,
- dests,
- sources);
-
- context.Add(operation);
+ EmitTextureSample(context, type, flags, handle, componentMask, dests, sources);
}
private static void EmitTexs(
@@ -657,16 +648,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
Array.Resize(ref dests, outputIndex);
}
- TextureOperation operation = context.CreateTextureOperation(
- Instruction.TextureSample,
- type,
- flags,
- handle,
- componentMask,
- dests,
- sources);
-
- context.Add(operation);
+ EmitTextureSample(context, type, flags, handle, componentMask, dests, sources);
if (isF16)
{
@@ -812,18 +794,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
Array.Resize(ref dests, outputIndex);
}
- int handle = imm;
-
- TextureOperation operation = context.CreateTextureOperation(
- Instruction.TextureSample,
- type,
- flags,
- handle,
- componentMask,
- dests,
- sources);
-
- context.Add(operation);
+ EmitTextureSample(context, type, flags, imm, componentMask, dests, sources);
}
private static void EmitTmml(
@@ -913,15 +884,21 @@ namespace Ryujinx.Graphics.Shader.Instructions
return Register(dest++, RegisterType.Gpr);
}
- int handle = imm;
+ int binding = isBindless ? 0 : context.Config.ResourceManager.GetTextureOrImageBinding(
+ Instruction.Lod,
+ type,
+ TextureFormat.Unknown,
+ flags,
+ TextureOperation.DefaultCbufSlot,
+ imm);
for (int compMask = componentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
{
if ((compMask & 1) != 0)
{
- Operand destOperand = GetDest();
+ Operand d = GetDest();
- if (destOperand == null)
+ if (d == null)
{
break;
}
@@ -930,28 +907,18 @@ namespace Ryujinx.Graphics.Shader.Instructions
if (compIndex >= 2)
{
context.Add(new CommentNode("Unsupported component z or w found"));
- context.Copy(destOperand, Const(0));
+ context.Copy(d, Const(0));
}
else
{
- Operand tempDest = Local();
-
- TextureOperation operation = context.CreateTextureOperation(
- Instruction.Lod,
- type,
- flags,
- handle,
- compIndex ^ 1, // The instruction component order is the inverse of GLSL's.
- new[] { tempDest },
- sources);
-
- context.Add(operation);
+ // The instruction component order is the inverse of GLSL's.
+ Operand res = context.Lod(type, flags, binding, compIndex ^ 1, sources);
- tempDest = context.FPMultiply(tempDest, ConstF(256.0f));
+ res = context.FPMultiply(res, ConstF(256.0f));
- Operand fixedPointValue = context.FP32ConvertToS32(tempDest);
+ Operand fixedPointValue = context.FP32ConvertToS32(res);
- context.Copy(destOperand, fixedPointValue);
+ context.Copy(d, fixedPointValue);
}
}
}
@@ -1081,18 +1048,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
Array.Resize(ref dests, outputIndex);
}
- int handle = imm;
-
- TextureOperation operation = context.CreateTextureOperation(
- Instruction.TextureSample,
- type,
- flags,
- handle,
- componentMask,
- dests,
- sources);
-
- context.Add(operation);
+ EmitTextureSample(context, type, flags, imm, componentMask, dests, sources);
}
private static void EmitTxq(
@@ -1111,10 +1067,6 @@ namespace Ryujinx.Graphics.Shader.Instructions
context.Config.SetUsedFeature(FeatureFlags.IntegerSampling);
- // TODO: Validate and use query.
- Instruction inst = Instruction.TextureSize;
- TextureFlags flags = isBindless ? TextureFlags.Bindless : TextureFlags.None;
-
Operand Ra()
{
if (srcA > RegisterConsts.RegisterZeroIndex)
@@ -1157,31 +1109,55 @@ namespace Ryujinx.Graphics.Shader.Instructions
type = context.Config.GpuAccessor.QuerySamplerType(imm);
}
+ TextureFlags flags = isBindless ? TextureFlags.Bindless : TextureFlags.None;
+
+ int binding = isBindless ? 0 : context.Config.ResourceManager.GetTextureOrImageBinding(
+ Instruction.TextureSize,
+ type,
+ TextureFormat.Unknown,
+ flags,
+ TextureOperation.DefaultCbufSlot,
+ imm);
+
for (int compMask = componentMask, compIndex = 0; compMask != 0; compMask >>= 1, compIndex++)
{
if ((compMask & 1) != 0)
{
- Operand destOperand = GetDest();
+ Operand d = GetDest();
- if (destOperand == null)
+ if (d == null)
{
break;
}
- TextureOperation operation = context.CreateTextureOperation(
- inst,
- type,
- flags,
- imm,
- compIndex,
- new[] { destOperand },
- sources);
+ // TODO: Validate and use query parameter.
+ Operand res = context.TextureSize(type, flags, binding, compIndex, sources);
- context.Add(operation);
+ context.Copy(d, res);
}
}
}
+ private static void EmitTextureSample(
+ EmitterContext context,
+ SamplerType type,
+ TextureFlags flags,
+ int handle,
+ int componentMask,
+ Operand[] dests,
+ Operand[] sources)
+ {
+ int binding = flags.HasFlag(TextureFlags.Bindless) ? 0 : context.Config.ResourceManager.GetTextureOrImageBinding(
+ Instruction.TextureSample,
+ type,
+ TextureFormat.Unknown,
+ flags,
+ TextureOperation.DefaultCbufSlot,
+ handle);
+
+ context.TextureSample(type, flags, binding, componentMask, dests, sources);
+ }
+
private static SamplerType ConvertSamplerType(TexDim dimensions)
{
return dimensions switch