2019-06-25 17:15:40 -07:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2019-06-24 16:46:49 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <optional>
|
2019-06-26 21:39:40 -07:00
|
|
|
#include <set>
|
2019-06-24 16:46:49 -07:00
|
|
|
|
|
|
|
#include "video_core/engines/shader_bytecode.h"
|
2019-06-28 19:59:43 -07:00
|
|
|
#include "video_core/shader/ast.h"
|
2019-08-16 13:25:02 -07:00
|
|
|
#include "video_core/shader/compiler_settings.h"
|
|
|
|
#include "video_core/shader/shader_ir.h"
|
2019-06-24 16:46:49 -07:00
|
|
|
|
|
|
|
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 {
|
2019-06-25 17:15:40 -07:00
|
|
|
return predicate == Pred::UnusedIndex && cc == ConditionCode::T;
|
|
|
|
}
|
2019-07-16 08:59:57 -07:00
|
|
|
|
2019-06-25 17:15:40 -07:00
|
|
|
bool operator==(const Condition& other) const {
|
|
|
|
return std::tie(predicate, cc) == std::tie(other.predicate, other.cc);
|
2019-06-24 16:46:49 -07:00
|
|
|
}
|
2019-07-16 08:59:57 -07:00
|
|
|
|
|
|
|
bool operator!=(const Condition& other) const {
|
|
|
|
return !operator==(other);
|
|
|
|
}
|
2019-06-24 16:46:49 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ShaderBlock {
|
|
|
|
struct Branch {
|
|
|
|
Condition cond{};
|
|
|
|
bool kills{};
|
|
|
|
s32 address{};
|
2019-07-16 08:59:57 -07:00
|
|
|
|
2019-06-24 16:46:49 -07:00
|
|
|
bool operator==(const Branch& b) const {
|
2019-06-25 17:15:40 -07:00
|
|
|
return std::tie(cond, kills, address) == std::tie(b.cond, b.kills, b.address);
|
2019-06-24 16:46:49 -07:00
|
|
|
}
|
2019-07-16 08:59:57 -07:00
|
|
|
|
|
|
|
bool operator!=(const Branch& b) const {
|
|
|
|
return !operator==(b);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
u32 start{};
|
|
|
|
u32 end{};
|
|
|
|
bool ignore_branch{};
|
|
|
|
Branch branch{};
|
|
|
|
|
2019-06-24 16:46:49 -07:00
|
|
|
bool operator==(const ShaderBlock& sb) const {
|
2019-06-25 17:15:40 -07:00
|
|
|
return std::tie(start, end, ignore_branch, branch) ==
|
|
|
|
std::tie(sb.start, sb.end, sb.ignore_branch, sb.branch);
|
2019-06-24 16:46:49 -07:00
|
|
|
}
|
2019-07-16 08:59:57 -07:00
|
|
|
|
|
|
|
bool operator!=(const ShaderBlock& sb) const {
|
|
|
|
return !operator==(sb);
|
|
|
|
}
|
2019-06-24 16:46:49 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ShaderCharacteristics {
|
2019-06-25 17:40:38 -07:00
|
|
|
std::list<ShaderBlock> blocks{};
|
2019-08-16 13:25:02 -07:00
|
|
|
std::set<u32> labels{};
|
2019-06-25 17:40:38 -07:00
|
|
|
u32 start{};
|
|
|
|
u32 end{};
|
2019-09-20 18:12:06 -07:00
|
|
|
ASTManager manager{true, true};
|
2019-08-16 13:25:02 -07:00
|
|
|
CompilerSettings settings{};
|
2019-06-24 16:46:49 -07:00
|
|
|
};
|
|
|
|
|
2019-10-15 15:05:50 -07:00
|
|
|
std::unique_ptr<ShaderCharacteristics> ScanFlow(const ProgramCode& program_code,
|
|
|
|
std::size_t program_size, u32 start_address,
|
2019-08-16 13:25:02 -07:00
|
|
|
const CompilerSettings& settings);
|
2019-06-24 16:46:49 -07:00
|
|
|
|
|
|
|
} // namespace VideoCommon::Shader
|