2021-05-20 03:58:32 +02:00
|
|
|
// Copyright 2021 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <bitset>
|
|
|
|
|
2021-05-21 08:00:12 +02:00
|
|
|
#include "common/bit_field.h"
|
2021-05-20 03:58:32 +02:00
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
|
|
namespace Shader::IR {
|
|
|
|
class Inst;
|
|
|
|
class Value;
|
|
|
|
} // namespace Shader::IR
|
|
|
|
|
|
|
|
namespace Shader::Backend::GLSL {
|
2021-05-21 08:00:12 +02:00
|
|
|
enum class Type : u32 {
|
2021-05-22 02:56:46 +02:00
|
|
|
U1,
|
2021-05-21 08:00:12 +02:00
|
|
|
S32,
|
2021-05-22 07:52:03 +02:00
|
|
|
U32,
|
2021-05-21 08:00:12 +02:00
|
|
|
F32,
|
2021-05-22 07:52:03 +02:00
|
|
|
S64,
|
2021-05-21 08:00:12 +02:00
|
|
|
U64,
|
|
|
|
F64,
|
2021-05-22 02:56:46 +02:00
|
|
|
U32x2,
|
|
|
|
F32x2,
|
2021-05-21 08:00:12 +02:00
|
|
|
Void,
|
|
|
|
};
|
2021-05-20 03:58:32 +02:00
|
|
|
|
|
|
|
struct Id {
|
2021-05-21 08:00:12 +02:00
|
|
|
union {
|
|
|
|
u32 raw;
|
|
|
|
BitField<0, 29, u32> index;
|
|
|
|
BitField<29, 1, u32> is_long;
|
|
|
|
BitField<30, 1, u32> is_spill;
|
|
|
|
BitField<31, 1, u32> is_condition_code;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool operator==(Id rhs) const noexcept {
|
|
|
|
return raw == rhs.raw;
|
|
|
|
}
|
|
|
|
bool operator!=(Id rhs) const noexcept {
|
|
|
|
return !operator==(rhs);
|
|
|
|
}
|
2021-05-20 03:58:32 +02:00
|
|
|
};
|
2021-05-21 08:00:12 +02:00
|
|
|
static_assert(sizeof(Id) == sizeof(u32));
|
2021-05-20 03:58:32 +02:00
|
|
|
|
|
|
|
class RegAlloc {
|
|
|
|
public:
|
2021-05-21 08:00:12 +02:00
|
|
|
std::string Define(IR::Inst& inst, Type type = Type::Void);
|
2021-05-20 03:58:32 +02:00
|
|
|
|
|
|
|
std::string Consume(const IR::Value& value);
|
|
|
|
|
2021-05-21 05:38:38 +02:00
|
|
|
/// Returns true if the instruction is expected to be aliased to another
|
|
|
|
static bool IsAliased(const IR::Inst& inst);
|
|
|
|
|
|
|
|
/// Returns the underlying value out of an alias sequence
|
|
|
|
static IR::Inst& AliasInst(IR::Inst& inst);
|
|
|
|
|
2021-05-20 03:58:32 +02:00
|
|
|
private:
|
|
|
|
static constexpr size_t NUM_REGS = 4096;
|
|
|
|
static constexpr size_t NUM_ELEMENTS = 4;
|
|
|
|
|
|
|
|
std::string Consume(IR::Inst& inst);
|
2021-05-21 08:00:12 +02:00
|
|
|
std::string GetType(Type type, u32 index);
|
2021-05-20 03:58:32 +02:00
|
|
|
|
2021-05-21 08:00:12 +02:00
|
|
|
Id Alloc();
|
2021-05-20 03:58:32 +02:00
|
|
|
void Free(Id id);
|
|
|
|
|
|
|
|
size_t num_used_registers{};
|
|
|
|
std::bitset<NUM_REGS> register_use{};
|
2021-05-21 08:00:12 +02:00
|
|
|
std::bitset<NUM_REGS> register_defined{};
|
2021-05-20 03:58:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Shader::Backend::GLSL
|