2022-04-23 04:59:50 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-05-05 02:19:08 -03:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2021-05-07 06:31:30 -03:00
|
|
|
#include <utility>
|
2021-05-18 21:04:09 -03:00
|
|
|
#include <vector>
|
2021-05-07 06:31:30 -03:00
|
|
|
|
2025-04-09 19:11:22 -04:00
|
|
|
#include <fmt/ranges.h>
|
2021-05-05 02:19:08 -03:00
|
|
|
|
|
|
|
#include "shader_recompiler/backend/glasm/reg_alloc.h"
|
2021-05-19 16:32:03 -03:00
|
|
|
#include "shader_recompiler/stage.h"
|
2021-05-05 02:19:08 -03:00
|
|
|
|
2021-05-18 21:04:09 -03:00
|
|
|
namespace Shader {
|
|
|
|
struct Info;
|
2021-05-19 16:32:03 -03:00
|
|
|
struct Profile;
|
2021-05-21 02:12:32 -03:00
|
|
|
struct RuntimeInfo;
|
2021-05-19 16:32:03 -03:00
|
|
|
} // namespace Shader
|
2021-05-18 21:04:09 -03:00
|
|
|
|
|
|
|
namespace Shader::Backend {
|
|
|
|
struct Bindings;
|
|
|
|
}
|
|
|
|
|
2021-05-07 06:31:30 -03:00
|
|
|
namespace Shader::IR {
|
|
|
|
class Inst;
|
2021-05-08 16:28:52 -03:00
|
|
|
struct Program;
|
|
|
|
} // namespace Shader::IR
|
2021-05-07 06:31:30 -03:00
|
|
|
|
2021-05-05 02:19:08 -03:00
|
|
|
namespace Shader::Backend::GLASM {
|
|
|
|
|
|
|
|
class EmitContext {
|
|
|
|
public:
|
2021-05-21 02:12:32 -03:00
|
|
|
explicit EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_,
|
|
|
|
const RuntimeInfo& runtime_info_);
|
2021-05-05 02:19:08 -03:00
|
|
|
|
2021-05-07 06:31:30 -03:00
|
|
|
template <typename... Args>
|
2021-05-09 03:11:34 -03:00
|
|
|
void Add(const char* format_str, IR::Inst& inst, Args&&... args) {
|
2021-06-28 23:44:03 -04:00
|
|
|
code += fmt::format(fmt::runtime(format_str), reg_alloc.Define(inst),
|
|
|
|
std::forward<Args>(args)...);
|
2021-05-07 06:31:30 -03:00
|
|
|
// TODO: Remove this
|
|
|
|
code += '\n';
|
|
|
|
}
|
|
|
|
|
2021-05-09 18:03:01 -03:00
|
|
|
template <typename... Args>
|
|
|
|
void LongAdd(const char* format_str, IR::Inst& inst, Args&&... args) {
|
2021-06-28 23:44:03 -04:00
|
|
|
code += fmt::format(fmt::runtime(format_str), reg_alloc.LongDefine(inst),
|
|
|
|
std::forward<Args>(args)...);
|
2021-05-09 18:03:01 -03:00
|
|
|
// TODO: Remove this
|
|
|
|
code += '\n';
|
|
|
|
}
|
|
|
|
|
2021-05-07 06:31:30 -03:00
|
|
|
template <typename... Args>
|
2021-05-09 03:11:34 -03:00
|
|
|
void Add(const char* format_str, Args&&... args) {
|
2021-06-28 23:44:03 -04:00
|
|
|
code += fmt::format(fmt::runtime(format_str), std::forward<Args>(args)...);
|
2021-05-07 06:31:30 -03:00
|
|
|
// TODO: Remove this
|
|
|
|
code += '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string code;
|
2021-07-11 22:10:38 -04:00
|
|
|
RegAlloc reg_alloc{};
|
2021-05-22 18:29:43 -03:00
|
|
|
const Info& info;
|
2021-05-19 16:32:03 -03:00
|
|
|
const Profile& profile;
|
2021-05-21 02:12:32 -03:00
|
|
|
const RuntimeInfo& runtime_info;
|
2021-05-18 21:04:09 -03:00
|
|
|
|
2021-05-19 02:05:24 -03:00
|
|
|
std::vector<u32> texture_buffer_bindings;
|
2021-05-20 02:18:52 -03:00
|
|
|
std::vector<u32> image_buffer_bindings;
|
2021-05-18 21:04:09 -03:00
|
|
|
std::vector<u32> texture_bindings;
|
2021-05-20 02:18:52 -03:00
|
|
|
std::vector<u32> image_bindings;
|
2021-05-10 18:21:28 -03:00
|
|
|
|
2021-05-19 16:32:03 -03:00
|
|
|
Stage stage{};
|
2021-05-10 18:21:28 -03:00
|
|
|
std::string_view stage_name = "invalid";
|
2021-05-20 17:28:09 -03:00
|
|
|
std::string_view attrib_name = "invalid";
|
2021-05-26 16:00:36 -03:00
|
|
|
|
2021-06-21 01:07:10 -03:00
|
|
|
u32 num_safety_loop_vars{};
|
2021-05-26 16:00:36 -03:00
|
|
|
bool uses_y_direction{};
|
2021-05-05 02:19:08 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Shader::Backend::GLASM
|