summaryrefslogtreecommitdiffstats
path: root/src/video_core/shader/decode/half_set.cpp
blob: 848e4687404fbed5022ecfe47d739f986b9ced6e (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2018 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include <array>

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

namespace VideoCommon::Shader {

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

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

    if (instr.hset2.ftz == 0) {
        LOG_DEBUG(HW_GPU, "{} without FTZ is not implemented", opcode->get().GetName());
    }

    Node op_a = UnpackHalfFloat(GetRegister(instr.gpr8), instr.hset2.type_a);
    op_a = GetOperandAbsNegHalf(op_a, instr.hset2.abs_a, instr.hset2.negate_a);

    Node op_b = [&]() {
        switch (opcode->get().GetId()) {
        case OpCode::Id::HSET2_R:
            return GetRegister(instr.gpr20);
        default:
            UNREACHABLE();
            return Immediate(0);
        }
    }();
    op_b = UnpackHalfFloat(op_b, instr.hset2.type_b);
    op_b = GetOperandAbsNegHalf(op_b, instr.hset2.abs_b, instr.hset2.negate_b);

    const Node second_pred = GetPredicate(instr.hset2.pred39, instr.hset2.neg_pred);

    const Node comparison_pair = GetPredicateComparisonHalf(instr.hset2.cond, op_a, op_b);

    const OperationCode combiner = GetPredicateCombiner(instr.hset2.op);

    // HSET2 operates on each half float in the pack.
    std::array<Node, 2> values;
    for (u32 i = 0; i < 2; ++i) {
        const u32 raw_value = instr.hset2.bf ? 0x3c00 : 0xffff;
        const Node true_value = Immediate(raw_value << (i * 16));
        const Node false_value = Immediate(0);

        const Node comparison =
            Operation(OperationCode::LogicalPick2, comparison_pair, Immediate(i));
        const Node predicate = Operation(combiner, comparison, second_pred);

        values[i] =
            Operation(OperationCode::Select, NO_PRECISE, predicate, true_value, false_value);
    }

    const Node value = Operation(OperationCode::UBitwiseOr, NO_PRECISE, values[0], values[1]);
    SetRegister(bb, instr.gpr0, value);

    return pc;
}

} // namespace VideoCommon::Shader