shader_info.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 <bitset>
  7. #include "common/common_types.h"
  8. #include "shader_recompiler/frontend/ir/type.h"
  9. #include <boost/container/small_vector.hpp>
  10. #include <boost/container/static_vector.hpp>
  11. namespace Shader {
  12. enum class TextureType : u32 {
  13. Color1D,
  14. ColorArray1D,
  15. Color2D,
  16. ColorArray2D,
  17. Color3D,
  18. ColorCube,
  19. ColorArrayCube,
  20. Buffer,
  21. };
  22. constexpr u32 NUM_TEXTURE_TYPES = 8;
  23. enum class ImageFormat : u32 {
  24. Typeless,
  25. R8_UINT,
  26. R8_SINT,
  27. R16_UINT,
  28. R16_SINT,
  29. R32_UINT,
  30. R32G32_UINT,
  31. R32G32B32A32_UINT,
  32. };
  33. enum class Interpolation {
  34. Smooth,
  35. Flat,
  36. NoPerspective,
  37. };
  38. struct InputVarying {
  39. Interpolation interpolation{Interpolation::Smooth};
  40. bool used{false};
  41. };
  42. struct ConstantBufferDescriptor {
  43. u32 index;
  44. u32 count;
  45. };
  46. struct StorageBufferDescriptor {
  47. u32 cbuf_index;
  48. u32 cbuf_offset;
  49. u32 count;
  50. bool is_written;
  51. };
  52. struct TextureBufferDescriptor {
  53. bool has_secondary;
  54. u32 cbuf_index;
  55. u32 cbuf_offset;
  56. u32 secondary_cbuf_index;
  57. u32 secondary_cbuf_offset;
  58. u32 count;
  59. u32 size_shift;
  60. };
  61. using TextureBufferDescriptors = boost::container::small_vector<TextureBufferDescriptor, 6>;
  62. struct ImageBufferDescriptor {
  63. ImageFormat format;
  64. bool is_written;
  65. u32 cbuf_index;
  66. u32 cbuf_offset;
  67. u32 count;
  68. u32 size_shift;
  69. };
  70. using ImageBufferDescriptors = boost::container::small_vector<ImageBufferDescriptor, 2>;
  71. struct TextureDescriptor {
  72. TextureType type;
  73. bool is_depth;
  74. bool has_secondary;
  75. u32 cbuf_index;
  76. u32 cbuf_offset;
  77. u32 secondary_cbuf_index;
  78. u32 secondary_cbuf_offset;
  79. u32 count;
  80. u32 size_shift;
  81. };
  82. using TextureDescriptors = boost::container::small_vector<TextureDescriptor, 12>;
  83. struct ImageDescriptor {
  84. TextureType type;
  85. ImageFormat format;
  86. bool is_written;
  87. u32 cbuf_index;
  88. u32 cbuf_offset;
  89. u32 count;
  90. u32 size_shift;
  91. };
  92. using ImageDescriptors = boost::container::small_vector<ImageDescriptor, 4>;
  93. struct Info {
  94. static constexpr size_t MAX_CBUFS{18};
  95. static constexpr size_t MAX_SSBOS{32};
  96. bool uses_workgroup_id{};
  97. bool uses_local_invocation_id{};
  98. bool uses_invocation_id{};
  99. bool uses_sample_id{};
  100. bool uses_is_helper_invocation{};
  101. bool uses_subgroup_invocation_id{};
  102. bool uses_subgroup_shuffles{};
  103. std::array<bool, 30> uses_patches{};
  104. std::array<InputVarying, 32> input_generics{};
  105. bool loads_primitive_id{};
  106. bool loads_position{};
  107. bool loads_color_front_diffuse{};
  108. bool loads_fixed_fnc_textures{};
  109. bool loads_point_coord{};
  110. bool loads_instance_id{};
  111. bool loads_vertex_id{};
  112. bool loads_front_face{};
  113. bool loads_tess_coord{};
  114. bool loads_indexed_attributes{};
  115. std::array<bool, 8> stores_frag_color{};
  116. bool stores_sample_mask{};
  117. bool stores_frag_depth{};
  118. std::array<bool, 32> stores_generics{};
  119. bool stores_layer{};
  120. bool stores_viewport_index{};
  121. bool stores_point_size{};
  122. bool stores_position{};
  123. bool stores_color_front_diffuse{};
  124. bool stores_color_front_specular{};
  125. bool stores_color_back_diffuse{};
  126. bool stores_color_back_specular{};
  127. bool stores_fixed_fnc_textures{};
  128. bool stores_clip_distance{};
  129. bool stores_fog_coordinate{};
  130. bool stores_viewport_mask{};
  131. bool stores_tess_level_outer{};
  132. bool stores_tess_level_inner{};
  133. bool stores_indexed_attributes{};
  134. bool stores_global_memory{};
  135. bool uses_fp16{};
  136. bool uses_fp64{};
  137. bool uses_fp16_denorms_flush{};
  138. bool uses_fp16_denorms_preserve{};
  139. bool uses_fp32_denorms_flush{};
  140. bool uses_fp32_denorms_preserve{};
  141. bool uses_int8{};
  142. bool uses_int16{};
  143. bool uses_int64{};
  144. bool uses_image_1d{};
  145. bool uses_sampled_1d{};
  146. bool uses_sparse_residency{};
  147. bool uses_demote_to_helper_invocation{};
  148. bool uses_subgroup_vote{};
  149. bool uses_subgroup_mask{};
  150. bool uses_fswzadd{};
  151. bool uses_derivatives{};
  152. bool uses_typeless_image_reads{};
  153. bool uses_typeless_image_writes{};
  154. bool uses_image_buffers{};
  155. bool uses_shared_increment{};
  156. bool uses_shared_decrement{};
  157. bool uses_global_increment{};
  158. bool uses_global_decrement{};
  159. bool uses_atomic_f32_add{};
  160. bool uses_atomic_f16x2_add{};
  161. bool uses_atomic_f16x2_min{};
  162. bool uses_atomic_f16x2_max{};
  163. bool uses_atomic_f32x2_add{};
  164. bool uses_atomic_f32x2_min{};
  165. bool uses_atomic_f32x2_max{};
  166. bool uses_int64_bit_atomics{};
  167. bool uses_global_memory{};
  168. bool uses_atomic_image_u32{};
  169. IR::Type used_constant_buffer_types{};
  170. IR::Type used_storage_buffer_types{};
  171. u32 constant_buffer_mask{};
  172. std::array<u32, MAX_CBUFS> constant_buffer_used_sizes{};
  173. u32 nvn_buffer_base{};
  174. std::bitset<16> nvn_buffer_used{};
  175. boost::container::static_vector<ConstantBufferDescriptor, MAX_CBUFS>
  176. constant_buffer_descriptors;
  177. boost::container::static_vector<StorageBufferDescriptor, MAX_SSBOS> storage_buffers_descriptors;
  178. TextureBufferDescriptors texture_buffer_descriptors;
  179. ImageBufferDescriptors image_buffer_descriptors;
  180. TextureDescriptors texture_descriptors;
  181. ImageDescriptors image_descriptors;
  182. };
  183. } // namespace Shader