2020-05-27 10:07:10 -04:00
|
|
|
|
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
|
|
|
|
{
|
|
|
|
|
class BindlessElimination
|
|
|
|
|
{
|
2020-07-03 19:48:44 -04:00
|
|
|
|
private const int NvnTextureBufferSlot = 2;
|
|
|
|
|
|
|
|
|
|
public static void RunPass(BasicBlock block, ShaderConfig config)
|
2020-05-27 10:07:10 -04:00
|
|
|
|
{
|
|
|
|
|
// We can turn a bindless into regular access by recognizing the pattern
|
|
|
|
|
// produced by the compiler for separate texture and sampler.
|
|
|
|
|
// We check for the following conditions:
|
|
|
|
|
// - The handle is the result of a bitwise OR logical operation.
|
|
|
|
|
// - Both sources of the OR operation comes from CB2 (used by NVN to hold texture handles).
|
|
|
|
|
for (LinkedListNode<INode> node = block.Operations.First; node != null; node = node.Next)
|
|
|
|
|
{
|
|
|
|
|
if (!(node.Value is TextureOperation texOp))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((texOp.Flags & TextureFlags.Bindless) == 0)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-03 19:48:44 -04:00
|
|
|
|
if (texOp.Inst == Instruction.TextureSample)
|
2020-05-27 10:07:10 -04:00
|
|
|
|
{
|
2020-07-03 19:48:44 -04:00
|
|
|
|
if (!(texOp.GetSource(0).AsgOp is Operation handleCombineOp))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-05-27 10:07:10 -04:00
|
|
|
|
|
2020-07-03 19:48:44 -04:00
|
|
|
|
if (handleCombineOp.Inst != Instruction.BitwiseOr)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-05-27 10:07:10 -04:00
|
|
|
|
|
2020-07-03 19:48:44 -04:00
|
|
|
|
Operand src0 = handleCombineOp.GetSource(0);
|
|
|
|
|
Operand src1 = handleCombineOp.GetSource(1);
|
2020-05-27 10:07:10 -04:00
|
|
|
|
|
2020-07-03 19:48:44 -04:00
|
|
|
|
if (src0.Type != OperandType.ConstantBuffer || src0.GetCbufSlot() != NvnTextureBufferSlot ||
|
|
|
|
|
src1.Type != OperandType.ConstantBuffer || src1.GetCbufSlot() != NvnTextureBufferSlot)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
texOp.SetHandle(src0.GetCbufOffset() | (src1.GetCbufOffset() << 16));
|
2020-05-27 10:07:10 -04:00
|
|
|
|
}
|
2020-07-03 19:48:44 -04:00
|
|
|
|
else if (texOp.Inst == Instruction.ImageLoad || texOp.Inst == Instruction.ImageStore)
|
|
|
|
|
{
|
|
|
|
|
Operand src0 = texOp.GetSource(0);
|
2020-05-27 10:07:10 -04:00
|
|
|
|
|
2020-07-03 19:48:44 -04:00
|
|
|
|
if (src0.Type == OperandType.ConstantBuffer && src0.GetCbufSlot() == NvnTextureBufferSlot)
|
|
|
|
|
{
|
|
|
|
|
texOp.SetHandle(src0.GetCbufOffset());
|
|
|
|
|
texOp.Format = config.GetTextureFormat(texOp.Handle);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-27 10:07:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|