yuzu/src/shader_recompiler/backend/glsl/reg_alloc.h

76 lines
1.6 KiB
C++
Raw Normal View History

2021-05-19 21:58:32 -04: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 02:00:12 -04:00
#include "common/bit_field.h"
2021-05-19 21:58:32 -04:00
#include "common/common_types.h"
namespace Shader::IR {
class Inst;
class Value;
} // namespace Shader::IR
namespace Shader::Backend::GLSL {
2021-05-21 02:00:12 -04:00
enum class Type : u32 {
U1,
2021-05-21 02:00:12 -04:00
U32,
S32,
F32,
U64,
F64,
U32x2,
F32x2,
2021-05-21 02:00:12 -04:00
Void,
};
2021-05-19 21:58:32 -04:00
struct Id {
2021-05-21 02:00:12 -04: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-19 21:58:32 -04:00
};
2021-05-21 02:00:12 -04:00
static_assert(sizeof(Id) == sizeof(u32));
2021-05-19 21:58:32 -04:00
class RegAlloc {
public:
2021-05-21 02:00:12 -04:00
std::string Define(IR::Inst& inst, Type type = Type::Void);
2021-05-19 21:58:32 -04:00
std::string Consume(const IR::Value& value);
/// 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-19 21:58:32 -04: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 02:00:12 -04:00
std::string GetType(Type type, u32 index);
2021-05-19 21:58:32 -04:00
2021-05-21 02:00:12 -04:00
Id Alloc();
2021-05-19 21:58:32 -04:00
void Free(Id id);
size_t num_used_registers{};
std::bitset<NUM_REGS> register_use{};
2021-05-21 02:00:12 -04:00
std::bitset<NUM_REGS> register_defined{};
2021-05-19 21:58:32 -04:00
};
} // namespace Shader::Backend::GLSL