emit_context.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Copyright 2021 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <string_view>
  7. #include <sirit/sirit.h>
  8. #include "shader_recompiler/frontend/ir/program.h"
  9. #include "shader_recompiler/profile.h"
  10. #include "shader_recompiler/shader_info.h"
  11. namespace Shader::Backend::SPIRV {
  12. using Sirit::Id;
  13. class VectorTypes {
  14. public:
  15. void Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name);
  16. [[nodiscard]] Id operator[](size_t size) const noexcept {
  17. return defs[size - 1];
  18. }
  19. private:
  20. std::array<Id, 4> defs{};
  21. };
  22. struct TextureDefinition {
  23. Id id;
  24. Id type;
  25. };
  26. struct UniformDefinitions {
  27. Id U8{};
  28. Id S8{};
  29. Id U16{};
  30. Id S16{};
  31. Id U32{};
  32. Id F32{};
  33. Id U64{};
  34. };
  35. class EmitContext final : public Sirit::Module {
  36. public:
  37. explicit EmitContext(const Profile& profile, IR::Program& program, u32& binding);
  38. ~EmitContext();
  39. [[nodiscard]] Id Def(const IR::Value& value);
  40. const Profile& profile;
  41. Stage stage{};
  42. Id void_id{};
  43. Id U1{};
  44. Id U8{};
  45. Id S8{};
  46. Id U16{};
  47. Id S16{};
  48. Id U64{};
  49. VectorTypes F32;
  50. VectorTypes U32;
  51. VectorTypes F16;
  52. VectorTypes F64;
  53. Id true_value{};
  54. Id false_value{};
  55. Id u32_zero_value{};
  56. UniformDefinitions uniform_types;
  57. Id input_f32{};
  58. Id input_u32{};
  59. Id input_s32{};
  60. Id output_f32{};
  61. Id storage_u32{};
  62. std::array<UniformDefinitions, Info::MAX_CBUFS> cbufs{};
  63. std::array<Id, Info::MAX_SSBOS> ssbos{};
  64. std::vector<TextureDefinition> textures;
  65. Id workgroup_id{};
  66. Id local_invocation_id{};
  67. Id subgroup_local_invocation_id{};
  68. Id instance_id{};
  69. Id instance_index{};
  70. Id base_instance{};
  71. Id vertex_id{};
  72. Id vertex_index{};
  73. Id base_vertex{};
  74. Id input_position{};
  75. std::array<Id, 32> input_generics{};
  76. Id output_position{};
  77. std::array<Id, 32> output_generics{};
  78. std::array<Id, 8> frag_color{};
  79. Id frag_depth{};
  80. std::vector<Id> interfaces;
  81. private:
  82. void DefineCommonTypes(const Info& info);
  83. void DefineCommonConstants();
  84. void DefineInterfaces(const Info& info);
  85. void DefineConstantBuffers(const Info& info, u32& binding);
  86. void DefineStorageBuffers(const Info& info, u32& binding);
  87. void DefineTextures(const Info& info, u32& binding);
  88. void DefineLabels(IR::Program& program);
  89. void DefineConstantBuffers(const Info& info, Id UniformDefinitions::*member_type, u32 binding,
  90. Id type, char type_char, u32 element_size);
  91. void DefineInputs(const Info& info);
  92. void DefineOutputs(const Info& info);
  93. };
  94. } // namespace Shader::Backend::SPIRV