2021-02-16 07:10:22 +00:00
|
|
|
// Copyright 2021 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
#include <sirit/sirit.h>
|
|
|
|
|
|
|
|
#include "shader_recompiler/frontend/ir/program.h"
|
2021-02-22 02:42:38 +00:00
|
|
|
#include "shader_recompiler/profile.h"
|
2021-03-09 20:14:57 +00:00
|
|
|
#include "shader_recompiler/shader_info.h"
|
2021-02-16 07:10:22 +00:00
|
|
|
|
|
|
|
namespace Shader::Backend::SPIRV {
|
|
|
|
|
|
|
|
using Sirit::Id;
|
|
|
|
|
|
|
|
class VectorTypes {
|
|
|
|
public:
|
|
|
|
void Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name);
|
|
|
|
|
|
|
|
[[nodiscard]] Id operator[](size_t size) const noexcept {
|
|
|
|
return defs[size - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::array<Id, 4> defs{};
|
|
|
|
};
|
|
|
|
|
2021-03-08 21:31:53 +00:00
|
|
|
struct TextureDefinition {
|
|
|
|
Id id;
|
|
|
|
Id type;
|
|
|
|
};
|
|
|
|
|
2021-03-09 20:14:57 +00:00
|
|
|
struct UniformDefinitions {
|
|
|
|
Id U8{};
|
|
|
|
Id S8{};
|
|
|
|
Id U16{};
|
|
|
|
Id S16{};
|
|
|
|
Id U32{};
|
|
|
|
Id F32{};
|
|
|
|
Id U64{};
|
|
|
|
};
|
|
|
|
|
2021-02-16 07:10:22 +00:00
|
|
|
class EmitContext final : public Sirit::Module {
|
|
|
|
public:
|
2021-02-22 02:42:38 +00:00
|
|
|
explicit EmitContext(const Profile& profile, IR::Program& program);
|
2021-02-16 07:10:22 +00:00
|
|
|
~EmitContext();
|
|
|
|
|
|
|
|
[[nodiscard]] Id Def(const IR::Value& value);
|
|
|
|
|
2021-02-22 02:42:38 +00:00
|
|
|
const Profile& profile;
|
|
|
|
|
2021-02-16 07:10:22 +00:00
|
|
|
Id void_id{};
|
|
|
|
Id U1{};
|
2021-03-09 20:14:57 +00:00
|
|
|
Id U8{};
|
|
|
|
Id S8{};
|
2021-02-19 21:10:18 +00:00
|
|
|
Id U16{};
|
2021-03-09 20:14:57 +00:00
|
|
|
Id S16{};
|
2021-02-19 21:10:18 +00:00
|
|
|
Id U64{};
|
2021-02-16 07:10:22 +00:00
|
|
|
VectorTypes F32;
|
|
|
|
VectorTypes U32;
|
|
|
|
VectorTypes F16;
|
|
|
|
VectorTypes F64;
|
|
|
|
|
|
|
|
Id true_value{};
|
|
|
|
Id false_value{};
|
|
|
|
Id u32_zero_value{};
|
|
|
|
|
2021-03-09 20:14:57 +00:00
|
|
|
UniformDefinitions uniform_types;
|
|
|
|
|
2021-02-16 07:10:22 +00:00
|
|
|
Id storage_u32{};
|
|
|
|
|
2021-03-09 20:14:57 +00:00
|
|
|
std::array<UniformDefinitions, Info::MAX_CBUFS> cbufs{};
|
2021-02-16 07:10:22 +00:00
|
|
|
std::array<Id, Info::MAX_SSBOS> ssbos{};
|
2021-03-08 21:31:53 +00:00
|
|
|
std::vector<TextureDefinition> textures;
|
2021-02-16 07:10:22 +00:00
|
|
|
|
|
|
|
Id workgroup_id{};
|
|
|
|
Id local_invocation_id{};
|
|
|
|
|
|
|
|
private:
|
|
|
|
void DefineCommonTypes(const Info& info);
|
|
|
|
void DefineCommonConstants();
|
|
|
|
void DefineSpecialVariables(const Info& info);
|
2021-02-19 21:10:18 +00:00
|
|
|
void DefineConstantBuffers(const Info& info, u32& binding);
|
2021-03-09 20:14:57 +00:00
|
|
|
void DefineConstantBuffers(const Info& info, Id UniformDefinitions::*member_type, u32 binding,
|
|
|
|
Id type, char type_char, u32 element_size);
|
2021-02-19 21:10:18 +00:00
|
|
|
void DefineStorageBuffers(const Info& info, u32& binding);
|
2021-03-08 21:31:53 +00:00
|
|
|
void DefineTextures(const Info& info, u32& binding);
|
2021-02-16 07:10:22 +00:00
|
|
|
void DefineLabels(IR::Program& program);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Shader::Backend::SPIRV
|