Support res scale on images, correctly blacklist for SUST, move logic out of backend. (#1657)

* Support res scale on images, correctly blacklist for SUST, move logic
out of backend.

* Fix Typo
This commit is contained in:
riperiperi 2020-11-02 19:53:23 +00:00 committed by GitHub
parent 11a7c99764
commit e1da7df207
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 199 additions and 78 deletions

View file

@ -84,7 +84,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
AppendLine("}" + suffix);
}
public int FindTextureDescriptorIndex(AstTextureOperation texOp)
private int FindDescriptorIndex(List<TextureDescriptor> list, AstTextureOperation texOp)
{
AstOperand operand = texOp.GetSource(0) as AstOperand;
bool bindless = (texOp.Flags & TextureFlags.Bindless) > 0;
@ -92,13 +92,24 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
int cBufSlot = bindless ? operand.CbufSlot : 0;
int cBufOffset = bindless ? operand.CbufOffset : 0;
return TextureDescriptors.FindIndex(descriptor =>
return list.FindIndex(descriptor =>
descriptor.Type == texOp.Type &&
descriptor.HandleIndex == texOp.Handle &&
descriptor.Format == texOp.Format &&
descriptor.CbufSlot == cBufSlot &&
descriptor.CbufOffset == cBufOffset);
}
public int FindTextureDescriptorIndex(AstTextureOperation texOp)
{
return FindDescriptorIndex(TextureDescriptors, texOp);
}
public int FindImageDescriptorIndex(AstTextureOperation texOp)
{
return FindDescriptorIndex(ImageDescriptors, texOp);
}
public StructuredFunction GetFunction(int id)
{
return _info.Functions[id];

View file

@ -509,7 +509,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
{
string stage = OperandManager.GetShaderStagePrefix(context.Config.Stage);
int scaleElements = context.TextureDescriptors.Count;
int scaleElements = context.TextureDescriptors.Count + context.ImageDescriptors.Count;
if (context.Config.Stage == ShaderStage.Fragment)
{

View file

@ -47,6 +47,43 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
texCall += ", " + str;
}
string ApplyScaling(string vector)
{
int index = context.FindImageDescriptorIndex(texOp);
TextureUsageFlags flags = TextureUsageFlags.NeedsScaleValue;
if ((context.Config.Stage == ShaderStage.Fragment || context.Config.Stage == ShaderStage.Compute) &&
texOp.Inst == Instruction.ImageLoad &&
!isBindless &&
!isIndexed)
{
// Image scales start after texture ones.
int scaleIndex = context.TextureDescriptors.Count + index;
if (pCount == 3 && isArray)
{
// The array index is not scaled, just x and y.
vector = "ivec3(Helper_TexelFetchScale((" + vector + ").xy, " + scaleIndex + "), (" + vector + ").z)";
}
else if (pCount == 2 && !isArray)
{
vector = "Helper_TexelFetchScale(" + vector + ", " + scaleIndex + ")";
}
else
{
flags |= TextureUsageFlags.ResScaleUnsupported;
}
}
else
{
flags |= TextureUsageFlags.ResScaleUnsupported;
}
context.ImageDescriptors[index] = context.ImageDescriptors[index].SetFlag(flags);
return vector;
}
if (pCount > 1)
{
string[] elems = new string[pCount];
@ -56,7 +93,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
elems[index] = Src(VariableType.S32);
}
Append("ivec" + pCount + "(" + string.Join(", ", elems) + ")");
Append(ApplyScaling("ivec" + pCount + "(" + string.Join(", ", elems) + ")"));
}
else
{
@ -404,28 +441,35 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
if (intCoords)
{
int index = context.FindTextureDescriptorIndex(texOp);
TextureUsageFlags flags = TextureUsageFlags.NeedsScaleValue;
if ((context.Config.Stage == ShaderStage.Fragment || context.Config.Stage == ShaderStage.Compute) &&
(texOp.Flags & TextureFlags.Bindless) == 0 &&
texOp.Type != SamplerType.Indexed)
!isBindless &&
!isIndexed)
{
if (pCount == 3 && isArray)
{
// The array index is not scaled, just x and y.
return "ivec3(Helper_TexelFetchScale((" + vector + ").xy, " + index + "), (" + vector + ").z)";
vector = "ivec3(Helper_TexelFetchScale((" + vector + ").xy, " + index + "), (" + vector + ").z)";
}
else if (pCount == 2 && !isArray)
{
return "Helper_TexelFetchScale(" + vector + ", " + index + ")";
vector = "Helper_TexelFetchScale(" + vector + ", " + index + ")";
}
else
{
flags |= TextureUsageFlags.ResScaleUnsupported;
}
}
else
{
// Resolution scaling cannot be applied to this texture right now.
// Flag so that we know to blacklist scaling on related textures when binding them.
flags |= TextureUsageFlags.ResScaleUnsupported;
}
// Resolution scaling cannot be applied to this texture right now.
// Flag so that we know to blacklist scaling on related textures when binding them.
TextureDescriptor descriptor = context.TextureDescriptors[index];
descriptor.Flags |= TextureUsageFlags.ResScaleUnsupported;
context.TextureDescriptors[index] = descriptor;
context.TextureDescriptors[index] = context.TextureDescriptors[index].SetFlag(flags);
}
return vector;