aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/Translation/Optimizations/BindlessElimination.cs
blob: 9515c349cd3a06d5c8da0b57c34db0eb246265da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
using System.Collections.Generic;

namespace Ryujinx.Graphics.Shader.Translation.Optimizations
{
    class BindlessElimination
    {
        public static void RunPass(BasicBlock block)
        {
            // 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;
                }

                if (!(texOp.GetSource(0).AsgOp is Operation handleCombineOp))
                {
                    continue;
                }

                if (handleCombineOp.Inst != Instruction.BitwiseOr)
                {
                    continue;
                }

                Operand src0 = handleCombineOp.GetSource(0);
                Operand src1 = handleCombineOp.GetSource(1);

                if (src0.Type != OperandType.ConstantBuffer || src0.GetCbufSlot() != 2 ||
                    src1.Type != OperandType.ConstantBuffer || src1.GetCbufSlot() != 2)
                {
                    continue;
                }

                texOp.SetHandle(src0.GetCbufOffset() | (src1.GetCbufOffset() << 16));
            }
        }
    }
}