yuzu/src/shader_recompiler/backend/spirv/emit_context.h

156 lines
3.4 KiB
C++
Raw Normal View History

2021-02-16 08:10:22 +01: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"
#include "shader_recompiler/profile.h"
2021-03-09 21:14:57 +01:00
#include "shader_recompiler/shader_info.h"
2021-02-16 08:10:22 +01: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{};
};
struct TextureDefinition {
Id id;
Id sampled_type;
Id image_type;
};
2021-03-09 21:14:57 +01:00
struct UniformDefinitions {
Id U8{};
Id S8{};
Id U16{};
Id S16{};
Id U32{};
Id F32{};
Id U64{};
};
2021-02-16 08:10:22 +01:00
class EmitContext final : public Sirit::Module {
public:
explicit EmitContext(const Profile& profile, IR::Program& program, u32& binding);
2021-02-16 08:10:22 +01:00
~EmitContext();
[[nodiscard]] Id Def(const IR::Value& value);
const Profile& profile;
Stage stage{};
2021-02-16 08:10:22 +01:00
Id void_id{};
Id U1{};
2021-03-09 21:14:57 +01:00
Id U8{};
Id S8{};
2021-02-19 22:10:18 +01:00
Id U16{};
2021-03-09 21:14:57 +01:00
Id S16{};
2021-02-19 22:10:18 +01:00
Id U64{};
2021-02-16 08:10:22 +01:00
VectorTypes F32;
VectorTypes U32;
VectorTypes F16;
VectorTypes F64;
Id true_value{};
Id false_value{};
Id u32_zero_value{};
2021-03-28 19:47:52 +02:00
Id f32_zero_value{};
2021-02-16 08:10:22 +01:00
2021-03-09 21:14:57 +01:00
UniformDefinitions uniform_types;
Id private_u32{};
Id shared_u8{};
Id shared_u16{};
Id shared_u32{};
Id shared_u32x2{};
Id shared_u32x4{};
Id input_f32{};
Id input_u32{};
Id input_s32{};
Id output_f32{};
2021-02-16 08:10:22 +01:00
Id storage_u32{};
2021-03-09 21:14:57 +01:00
std::array<UniformDefinitions, Info::MAX_CBUFS> cbufs{};
2021-02-16 08:10:22 +01:00
std::array<Id, Info::MAX_SSBOS> ssbos{};
std::vector<TextureDefinition> textures;
2021-02-16 08:10:22 +01:00
Id workgroup_id{};
Id local_invocation_id{};
2021-03-24 01:27:17 +01:00
Id subgroup_local_invocation_id{};
Id instance_id{};
Id instance_index{};
Id base_instance{};
Id vertex_id{};
Id vertex_index{};
Id base_vertex{};
2021-03-27 06:55:37 +01:00
Id front_face{};
2021-03-29 20:05:38 +02:00
Id point_coord{};
2021-03-30 21:52:06 +02:00
Id clip_distances{};
2021-04-01 08:34:45 +02:00
Id viewport_index{};
2021-03-29 20:05:38 +02:00
2021-03-29 04:23:45 +02:00
Id fswzadd_lut_a{};
Id fswzadd_lut_b{};
2021-02-16 08:10:22 +01:00
Id local_memory{};
Id shared_memory_u8{};
Id shared_memory_u16{};
Id shared_memory_u32{};
Id shared_memory_u32x2{};
Id shared_memory_u32x4{};
Id shared_store_u8_func{};
Id shared_store_u16_func{};
Id input_position{};
std::array<Id, 32> input_generics{};
2021-03-26 23:52:06 +01:00
Id output_point_size{};
Id output_position{};
std::array<Id, 32> output_generics{};
std::array<Id, 8> frag_color{};
2021-03-24 01:27:17 +01:00
Id frag_depth{};
std::vector<Id> interfaces;
2021-02-16 08:10:22 +01:00
private:
void DefineCommonTypes(const Info& info);
void DefineCommonConstants();
void DefineInterfaces(const Info& info);
void DefineLocalMemory(const IR::Program& program);
void DefineSharedMemory(const IR::Program& program);
2021-02-19 22:10:18 +01:00
void DefineConstantBuffers(const Info& info, u32& binding);
void DefineStorageBuffers(const Info& info, u32& binding);
void DefineTextures(const Info& info, u32& binding);
2021-02-16 08:10:22 +01:00
void DefineLabels(IR::Program& program);
void DefineConstantBuffers(const Info& info, Id UniformDefinitions::*member_type, u32 binding,
Id type, char type_char, u32 element_size);
void DefineInputs(const Info& info);
void DefineOutputs(const Info& info);
2021-02-16 08:10:22 +01:00
};
} // namespace Shader::Backend::SPIRV