summaryrefslogtreecommitdiffstats
path: root/src/video_core/shader/decode/register_set_predicate.cpp
blob: 796039cd922fbeabc47b1505766d89f287f0967f (plain) (blame)
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
51
// Copyright 2018 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include "common/assert.h"
#include "common/common_types.h"
#include "video_core/engines/shader_bytecode.h"
#include "video_core/shader/shader_ir.h"

namespace VideoCommon::Shader {

using Tegra::Shader::Instruction;
using Tegra::Shader::OpCode;

u32 ShaderIR::DecodeRegisterSetPredicate(BasicBlock& bb, u32 pc) {
    const Instruction instr = {program_code[pc]};
    const auto opcode = OpCode::Decode(instr);

    UNIMPLEMENTED_IF(instr.r2p.mode != Tegra::Shader::R2pMode::Pr);

    const Node apply_mask = [&]() {
        switch (opcode->get().GetId()) {
        case OpCode::Id::R2P_IMM:
            return Immediate(static_cast<u32>(instr.r2p.immediate_mask));
        default:
            UNREACHABLE();
            return Immediate(static_cast<u32>(instr.r2p.immediate_mask));
        }
    }();
    const Node mask =
        Operation(OperationCode::ULogicalShiftRight, NO_PRECISE, GetRegister(instr.gpr8),
                  Immediate(static_cast<u32>(instr.r2p.byte)));

    constexpr u32 programmable_preds = 7;
    for (u64 pred = 0; pred < programmable_preds; ++pred) {
        const Node shift = Immediate(1u << static_cast<u32>(pred));

        const Node apply_compare = Operation(OperationCode::UBitwiseAnd, NO_PRECISE, apply_mask, shift);
        const Node condition = Operation(OperationCode::LogicalUEqual, apply_compare, Immediate(0));

        const Node value_compare = Operation(OperationCode::UBitwiseAnd, NO_PRECISE, mask, shift);
        const Node value = Operation(OperationCode::LogicalUEqual, value_compare, Immediate(0));

        const Node code = Operation(OperationCode::LogicalAssign, GetPredicate(pred), value);
        bb.push_back(Conditional(condition, {code}));
    }

    return pc;
}

} // namespace VideoCommon::Shader