2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00
yuzu/src/shader_recompiler/backend/glsl/reg_alloc.h

85 lines
1.8 KiB
C++
Raw Normal View History

2021-05-20 02:58:32 +01: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 07:00:12 +01:00
#include "common/bit_field.h"
2021-05-20 02:58:32 +01:00
#include "common/common_types.h"
namespace Shader::IR {
class Inst;
class Value;
2021-05-25 00:33:11 +01:00
enum class Type;
2021-05-20 02:58:32 +01:00
} // namespace Shader::IR
namespace Shader::Backend::GLSL {
2021-05-21 07:00:12 +01:00
enum class Type : u32 {
U1,
2021-05-25 06:52:02 +01:00
F16x2,
2021-05-21 07:00:12 +01:00
S32,
2021-05-22 06:52:03 +01:00
U32,
2021-05-21 07:00:12 +01:00
F32,
2021-05-22 06:52:03 +01:00
S64,
2021-05-21 07:00:12 +01:00
U64,
F64,
U32x2,
F32x2,
U32x4,
F32x4,
2021-05-21 07:00:12 +01:00
Void,
};
2021-05-20 02:58:32 +01:00
struct Id {
2021-05-21 07:00:12 +01:00
union {
u32 raw;
2021-05-26 01:55:06 +01:00
BitField<0, 1, u32> is_valid;
BitField<1, 1, u32> is_long;
BitField<2, 1, u32> is_spill;
BitField<3, 1, u32> is_condition_code;
BitField<4, 1, u32> is_null;
BitField<5, 27, u32> index;
2021-05-21 07:00:12 +01:00
};
bool operator==(Id rhs) const noexcept {
return raw == rhs.raw;
}
bool operator!=(Id rhs) const noexcept {
return !operator==(rhs);
}
2021-05-20 02:58:32 +01:00
};
2021-05-21 07:00:12 +01:00
static_assert(sizeof(Id) == sizeof(u32));
2021-05-20 02:58:32 +01:00
class RegAlloc {
public:
2021-05-24 23:35:37 +01:00
std::string Define(IR::Inst& inst);
std::string Define(IR::Inst& inst, Type type);
2021-05-25 00:33:11 +01:00
std::string Define(IR::Inst& inst, IR::Type type);
2021-05-20 02:58:32 +01: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-20 02:58:32 +01: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 07:00:12 +01:00
std::string GetType(Type type, u32 index);
2021-05-20 02:58:32 +01:00
2021-05-21 07:00:12 +01:00
Id Alloc();
2021-05-20 02:58:32 +01:00
void Free(Id id);
size_t num_used_registers{};
std::bitset<NUM_REGS> register_use{};
2021-05-21 07:00:12 +01:00
std::bitset<NUM_REGS> register_defined{};
2021-05-20 02:58:32 +01:00
};
} // namespace Shader::Backend::GLSL