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;
|
2021-03-26 21:45:38 +00:00
|
|
|
Id sampled_type;
|
|
|
|
Id image_type;
|
2021-03-08 21:31:53 +00:00
|
|
|
};
|
|
|
|
|
2021-04-15 00:36:36 +00:00
|
|
|
struct ImageBufferDefinition {
|
|
|
|
Id id;
|
|
|
|
Id image_type;
|
|
|
|
};
|
|
|
|
|
2021-04-09 04:45:39 +00:00
|
|
|
struct ImageDefinition {
|
|
|
|
Id id;
|
|
|
|
Id image_type;
|
|
|
|
};
|
|
|
|
|
2021-03-09 20:14:57 +00:00
|
|
|
struct UniformDefinitions {
|
|
|
|
Id U8{};
|
|
|
|
Id S8{};
|
|
|
|
Id U16{};
|
|
|
|
Id S16{};
|
|
|
|
Id U32{};
|
|
|
|
Id F32{};
|
2021-04-04 05:31:09 +00:00
|
|
|
Id U32x2{};
|
2021-03-09 20:14:57 +00:00
|
|
|
};
|
|
|
|
|
2021-04-13 08:32:21 +00:00
|
|
|
struct StorageTypeDefinition {
|
|
|
|
Id array{};
|
|
|
|
Id element{};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StorageTypeDefinitions {
|
|
|
|
StorageTypeDefinition U8{};
|
|
|
|
StorageTypeDefinition S8{};
|
|
|
|
StorageTypeDefinition U16{};
|
|
|
|
StorageTypeDefinition S16{};
|
|
|
|
StorageTypeDefinition U32{};
|
|
|
|
StorageTypeDefinition U64{};
|
|
|
|
StorageTypeDefinition F32{};
|
|
|
|
StorageTypeDefinition U32x2{};
|
|
|
|
StorageTypeDefinition U32x4{};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StorageDefinitions {
|
|
|
|
Id U8{};
|
|
|
|
Id S8{};
|
|
|
|
Id U16{};
|
|
|
|
Id S16{};
|
|
|
|
Id U32{};
|
|
|
|
Id F32{};
|
|
|
|
Id U64{};
|
|
|
|
Id U32x2{};
|
|
|
|
Id U32x4{};
|
|
|
|
};
|
|
|
|
|
2021-04-14 04:04:59 +00:00
|
|
|
struct GenericElementInfo {
|
|
|
|
Id id{};
|
|
|
|
u32 first_element{};
|
|
|
|
u32 num_components{};
|
|
|
|
};
|
|
|
|
|
2021-02-16 07:10:22 +00:00
|
|
|
class EmitContext final : public Sirit::Module {
|
|
|
|
public:
|
2021-03-19 22:28:31 +00:00
|
|
|
explicit EmitContext(const Profile& profile, IR::Program& program, u32& binding);
|
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-03-24 04:33:45 +00:00
|
|
|
Stage stage{};
|
2021-02-22 02:42:38 +00:00
|
|
|
|
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-28 17:47:52 +00:00
|
|
|
Id f32_zero_value{};
|
2021-02-16 07:10:22 +00:00
|
|
|
|
2021-03-09 20:14:57 +00:00
|
|
|
UniformDefinitions uniform_types;
|
2021-04-13 08:32:21 +00:00
|
|
|
StorageTypeDefinitions storage_types;
|
2021-03-09 20:14:57 +00:00
|
|
|
|
2021-03-28 22:53:34 +00:00
|
|
|
Id private_u32{};
|
|
|
|
|
|
|
|
Id shared_u8{};
|
|
|
|
Id shared_u16{};
|
|
|
|
Id shared_u32{};
|
2021-04-13 08:32:21 +00:00
|
|
|
Id shared_u64{};
|
2021-03-28 22:53:34 +00:00
|
|
|
Id shared_u32x2{};
|
|
|
|
Id shared_u32x4{};
|
|
|
|
|
2021-03-19 22:28:31 +00:00
|
|
|
Id input_f32{};
|
2021-03-24 04:33:45 +00:00
|
|
|
Id input_u32{};
|
|
|
|
Id input_s32{};
|
|
|
|
|
2021-03-19 22:28:31 +00:00
|
|
|
Id output_f32{};
|
2021-04-16 19:31:15 +00:00
|
|
|
Id output_u32{};
|
2021-03-19 22:28:31 +00:00
|
|
|
|
2021-04-06 05:56:15 +00:00
|
|
|
Id image_buffer_type{};
|
|
|
|
Id sampled_texture_buffer_type{};
|
|
|
|
|
2021-03-09 20:14:57 +00:00
|
|
|
std::array<UniformDefinitions, Info::MAX_CBUFS> cbufs{};
|
2021-04-13 08:32:21 +00:00
|
|
|
std::array<StorageDefinitions, Info::MAX_SSBOS> ssbos{};
|
2021-04-06 05:56:15 +00:00
|
|
|
std::vector<Id> texture_buffers;
|
2021-04-15 00:36:36 +00:00
|
|
|
std::vector<ImageBufferDefinition> image_buffers;
|
2021-04-09 04:45:39 +00:00
|
|
|
std::vector<TextureDefinition> textures;
|
|
|
|
std::vector<ImageDefinition> images;
|
2021-02-16 07:10:22 +00:00
|
|
|
|
|
|
|
Id workgroup_id{};
|
|
|
|
Id local_invocation_id{};
|
2021-04-16 01:46:11 +00:00
|
|
|
Id invocation_id{};
|
2021-04-16 20:22:59 +00:00
|
|
|
Id sample_id{};
|
2021-04-11 22:16:12 +00:00
|
|
|
Id is_helper_invocation{};
|
2021-03-24 00:27:17 +00:00
|
|
|
Id subgroup_local_invocation_id{};
|
2021-04-04 08:17:17 +00:00
|
|
|
Id subgroup_mask_eq{};
|
|
|
|
Id subgroup_mask_lt{};
|
|
|
|
Id subgroup_mask_le{};
|
|
|
|
Id subgroup_mask_gt{};
|
|
|
|
Id subgroup_mask_ge{};
|
2021-03-20 22:11:56 +00:00
|
|
|
Id instance_id{};
|
|
|
|
Id instance_index{};
|
|
|
|
Id base_instance{};
|
|
|
|
Id vertex_id{};
|
|
|
|
Id vertex_index{};
|
|
|
|
Id base_vertex{};
|
2021-03-27 05:55:37 +00:00
|
|
|
Id front_face{};
|
2021-03-29 18:05:38 +00:00
|
|
|
Id point_coord{};
|
2021-04-16 01:46:11 +00:00
|
|
|
Id tess_coord{};
|
2021-03-30 19:52:06 +00:00
|
|
|
Id clip_distances{};
|
2021-04-14 21:09:18 +00:00
|
|
|
Id layer{};
|
2021-04-01 06:34:45 +00:00
|
|
|
Id viewport_index{};
|
2021-04-16 19:31:15 +00:00
|
|
|
Id viewport_mask{};
|
2021-04-16 04:55:06 +00:00
|
|
|
Id primitive_id{};
|
2021-03-29 18:05:38 +00:00
|
|
|
|
2021-03-29 02:23:45 +00:00
|
|
|
Id fswzadd_lut_a{};
|
|
|
|
Id fswzadd_lut_b{};
|
2021-02-16 07:10:22 +00:00
|
|
|
|
2021-04-04 04:47:14 +00:00
|
|
|
Id indexed_load_func{};
|
|
|
|
Id indexed_store_func{};
|
|
|
|
|
2021-03-28 22:53:34 +00:00
|
|
|
Id local_memory{};
|
|
|
|
|
|
|
|
Id shared_memory_u8{};
|
|
|
|
Id shared_memory_u16{};
|
|
|
|
Id shared_memory_u32{};
|
2021-04-13 08:32:21 +00:00
|
|
|
Id shared_memory_u64{};
|
2021-03-28 22:53:34 +00:00
|
|
|
Id shared_memory_u32x2{};
|
|
|
|
Id shared_memory_u32x4{};
|
2021-04-13 08:32:21 +00:00
|
|
|
|
2021-04-11 06:07:02 +00:00
|
|
|
Id shared_memory_u32_type{};
|
2021-03-28 22:53:34 +00:00
|
|
|
|
|
|
|
Id shared_store_u8_func{};
|
|
|
|
Id shared_store_u16_func{};
|
2021-04-11 06:07:02 +00:00
|
|
|
Id increment_cas_shared{};
|
|
|
|
Id increment_cas_ssbo{};
|
|
|
|
Id decrement_cas_shared{};
|
|
|
|
Id decrement_cas_ssbo{};
|
|
|
|
Id f32_add_cas{};
|
|
|
|
Id f16x2_add_cas{};
|
|
|
|
Id f16x2_min_cas{};
|
|
|
|
Id f16x2_max_cas{};
|
|
|
|
Id f32x2_add_cas{};
|
|
|
|
Id f32x2_min_cas{};
|
|
|
|
Id f32x2_max_cas{};
|
2021-03-28 22:53:34 +00:00
|
|
|
|
2021-03-19 22:28:31 +00:00
|
|
|
Id input_position{};
|
|
|
|
std::array<Id, 32> input_generics{};
|
|
|
|
|
2021-03-26 22:52:06 +00:00
|
|
|
Id output_point_size{};
|
2021-03-19 22:28:31 +00:00
|
|
|
Id output_position{};
|
2021-04-14 04:04:59 +00:00
|
|
|
std::array<std::array<GenericElementInfo, 4>, 32> output_generics{};
|
2021-03-19 22:28:31 +00:00
|
|
|
|
2021-04-16 01:46:11 +00:00
|
|
|
Id output_tess_level_outer{};
|
|
|
|
Id output_tess_level_inner{};
|
|
|
|
std::array<Id, 30> patches{};
|
|
|
|
|
2021-03-19 22:28:31 +00:00
|
|
|
std::array<Id, 8> frag_color{};
|
2021-03-24 00:27:17 +00:00
|
|
|
Id frag_depth{};
|
2021-03-19 22:28:31 +00:00
|
|
|
|
|
|
|
std::vector<Id> interfaces;
|
|
|
|
|
2021-02-16 07:10:22 +00:00
|
|
|
private:
|
|
|
|
void DefineCommonTypes(const Info& info);
|
|
|
|
void DefineCommonConstants();
|
2021-04-16 01:46:11 +00:00
|
|
|
void DefineInterfaces(const IR::Program& program);
|
2021-03-28 22:53:34 +00:00
|
|
|
void DefineLocalMemory(const IR::Program& program);
|
|
|
|
void DefineSharedMemory(const IR::Program& program);
|
2021-04-13 08:32:21 +00:00
|
|
|
void DefineSharedMemoryFunctions(const IR::Program& program);
|
2021-02-19 21:10:18 +00:00
|
|
|
void DefineConstantBuffers(const Info& info, u32& binding);
|
|
|
|
void DefineStorageBuffers(const Info& info, u32& binding);
|
2021-04-06 05:56:15 +00:00
|
|
|
void DefineTextureBuffers(const Info& info, u32& binding);
|
2021-04-15 00:36:36 +00:00
|
|
|
void DefineImageBuffers(const Info& info, u32& binding);
|
2021-04-06 23:14:55 +00:00
|
|
|
void DefineTextures(const Info& info, u32& binding);
|
2021-04-09 04:45:39 +00:00
|
|
|
void DefineImages(const Info& info, u32& binding);
|
2021-04-04 04:47:14 +00:00
|
|
|
void DefineAttributeMemAccess(const Info& info);
|
2021-02-16 07:10:22 +00:00
|
|
|
void DefineLabels(IR::Program& program);
|
2021-03-20 22:11:56 +00:00
|
|
|
|
2021-03-24 04:33:45 +00:00
|
|
|
void DefineInputs(const Info& info);
|
2021-04-16 01:46:11 +00:00
|
|
|
void DefineOutputs(const IR::Program& program);
|
2021-02-16 07:10:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Shader::Backend::SPIRV
|