summaryrefslogtreecommitdiffstats
path: root/src/video_core/shader/control_flow.h
blob: f5d37a231f348f9ffd5c67638e06bd65454650c9 (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
#pragma once

#include <cstring>
#include <list>
#include <optional>
#include <vector>

#include "video_core/engines/shader_bytecode.h"
#include "video_core/shader/shader_ir.h"

namespace VideoCommon::Shader {

using Tegra::Shader::ConditionCode;
using Tegra::Shader::Pred;

constexpr s32 exit_branch = -1;

struct Condition {
    Pred predicate{Pred::UnusedIndex};
    ConditionCode cc{ConditionCode::T};

    bool IsUnconditional() const {
        return (predicate == Pred::UnusedIndex) && (cc == ConditionCode::T);
    }
};

struct ShaderBlock {
    ShaderBlock() {}
    ShaderBlock(const ShaderBlock& sb) = default;
    u32 start{};
    u32 end{};
    bool ignore_branch{};
    struct Branch {
        Condition cond{};
        bool kills{};
        s32 address{};
        bool operator==(const Branch& b) const {
            return std::memcmp(this, &b, sizeof(Branch)) == 0;
        }
    } branch;
    bool operator==(const ShaderBlock& sb) const {
        return std::memcmp(this, &sb, sizeof(ShaderBlock)) == 0;
    }
};

struct ShaderCharacteristics {
    std::list<ShaderBlock> blocks;
    bool decompilable{};
    u32 start;
    u32 end;
};

bool ScanFlow(const ProgramCode& program_code, u32 program_size, u32 start_address,
              ShaderCharacteristics& result_out);

} // namespace VideoCommon::Shader