shader_info.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <array>
  5. #include <bitset>
  6. #include <map>
  7. #include "common/common_types.h"
  8. #include "shader_recompiler/frontend/ir/type.h"
  9. #include "shader_recompiler/varying_state.h"
  10. #include <boost/container/small_vector.hpp>
  11. #include <boost/container/static_vector.hpp>
  12. namespace Shader {
  13. enum class ReplaceConstant : u32 {
  14. BaseInstance,
  15. BaseVertex,
  16. DrawID,
  17. };
  18. enum class TextureType : u32 {
  19. Color1D,
  20. ColorArray1D,
  21. Color2D,
  22. ColorArray2D,
  23. Color3D,
  24. ColorCube,
  25. ColorArrayCube,
  26. Buffer,
  27. Color2DRect,
  28. };
  29. constexpr u32 NUM_TEXTURE_TYPES = 9;
  30. enum class TexturePixelFormat : u32 {
  31. A8B8G8R8_SNORM,
  32. R8_SNORM,
  33. R8G8_SNORM,
  34. R16G16B16A16_SNORM,
  35. R16G16_SNORM,
  36. R16_SNORM,
  37. OTHER
  38. };
  39. enum class ImageFormat : u32 {
  40. Typeless,
  41. R8_UINT,
  42. R8_SINT,
  43. R16_UINT,
  44. R16_SINT,
  45. R32_UINT,
  46. R32G32_UINT,
  47. R32G32B32A32_UINT,
  48. };
  49. enum class Interpolation {
  50. Smooth,
  51. Flat,
  52. NoPerspective,
  53. };
  54. struct ConstantBufferDescriptor {
  55. u32 index;
  56. u32 count;
  57. auto operator<=>(const ConstantBufferDescriptor&) const = default;
  58. };
  59. struct StorageBufferDescriptor {
  60. u32 cbuf_index;
  61. u32 cbuf_offset;
  62. u32 count;
  63. bool is_written;
  64. auto operator<=>(const StorageBufferDescriptor&) const = default;
  65. };
  66. struct TextureBufferDescriptor {
  67. bool has_secondary;
  68. u32 cbuf_index;
  69. u32 cbuf_offset;
  70. u32 shift_left;
  71. u32 secondary_cbuf_index;
  72. u32 secondary_cbuf_offset;
  73. u32 secondary_shift_left;
  74. u32 count;
  75. u32 size_shift;
  76. auto operator<=>(const TextureBufferDescriptor&) const = default;
  77. };
  78. using TextureBufferDescriptors = boost::container::small_vector<TextureBufferDescriptor, 6>;
  79. struct ImageBufferDescriptor {
  80. ImageFormat format;
  81. bool is_written;
  82. bool is_read;
  83. u32 cbuf_index;
  84. u32 cbuf_offset;
  85. u32 count;
  86. u32 size_shift;
  87. auto operator<=>(const ImageBufferDescriptor&) const = default;
  88. };
  89. using ImageBufferDescriptors = boost::container::small_vector<ImageBufferDescriptor, 2>;
  90. struct TextureDescriptor {
  91. TextureType type;
  92. bool is_depth;
  93. bool is_multisample;
  94. bool has_secondary;
  95. u32 cbuf_index;
  96. u32 cbuf_offset;
  97. u32 shift_left;
  98. u32 secondary_cbuf_index;
  99. u32 secondary_cbuf_offset;
  100. u32 secondary_shift_left;
  101. u32 count;
  102. u32 size_shift;
  103. auto operator<=>(const TextureDescriptor&) const = default;
  104. };
  105. using TextureDescriptors = boost::container::small_vector<TextureDescriptor, 12>;
  106. struct ImageDescriptor {
  107. TextureType type;
  108. ImageFormat format;
  109. bool is_written;
  110. bool is_read;
  111. u32 cbuf_index;
  112. u32 cbuf_offset;
  113. u32 count;
  114. u32 size_shift;
  115. auto operator<=>(const ImageDescriptor&) const = default;
  116. };
  117. using ImageDescriptors = boost::container::small_vector<ImageDescriptor, 4>;
  118. struct Info {
  119. static constexpr size_t MAX_INDIRECT_CBUFS{14};
  120. static constexpr size_t MAX_CBUFS{18};
  121. static constexpr size_t MAX_SSBOS{32};
  122. bool uses_workgroup_id{};
  123. bool uses_local_invocation_id{};
  124. bool uses_invocation_id{};
  125. bool uses_invocation_info{};
  126. bool uses_sample_id{};
  127. bool uses_is_helper_invocation{};
  128. bool uses_subgroup_invocation_id{};
  129. bool uses_subgroup_shuffles{};
  130. std::array<bool, 30> uses_patches{};
  131. std::array<Interpolation, 32> interpolation{};
  132. VaryingState loads;
  133. VaryingState stores;
  134. VaryingState passthrough;
  135. std::map<IR::Attribute, IR::Attribute> legacy_stores_mapping;
  136. bool loads_indexed_attributes{};
  137. std::array<bool, 8> stores_frag_color{};
  138. bool stores_sample_mask{};
  139. bool stores_frag_depth{};
  140. bool stores_tess_level_outer{};
  141. bool stores_tess_level_inner{};
  142. bool stores_indexed_attributes{};
  143. bool stores_global_memory{};
  144. bool uses_local_memory{};
  145. bool uses_fp16{};
  146. bool uses_fp64{};
  147. bool uses_fp16_denorms_flush{};
  148. bool uses_fp16_denorms_preserve{};
  149. bool uses_fp32_denorms_flush{};
  150. bool uses_fp32_denorms_preserve{};
  151. bool uses_int8{};
  152. bool uses_int16{};
  153. bool uses_int64{};
  154. bool uses_image_1d{};
  155. bool uses_sampled_1d{};
  156. bool uses_sparse_residency{};
  157. bool uses_demote_to_helper_invocation{};
  158. bool uses_subgroup_vote{};
  159. bool uses_subgroup_mask{};
  160. bool uses_fswzadd{};
  161. bool uses_derivatives{};
  162. bool uses_typeless_image_reads{};
  163. bool uses_typeless_image_writes{};
  164. bool uses_image_buffers{};
  165. bool uses_shared_increment{};
  166. bool uses_shared_decrement{};
  167. bool uses_global_increment{};
  168. bool uses_global_decrement{};
  169. bool uses_atomic_f32_add{};
  170. bool uses_atomic_f16x2_add{};
  171. bool uses_atomic_f16x2_min{};
  172. bool uses_atomic_f16x2_max{};
  173. bool uses_atomic_f32x2_add{};
  174. bool uses_atomic_f32x2_min{};
  175. bool uses_atomic_f32x2_max{};
  176. bool uses_atomic_s32_min{};
  177. bool uses_atomic_s32_max{};
  178. bool uses_int64_bit_atomics{};
  179. bool uses_global_memory{};
  180. bool uses_atomic_image_u32{};
  181. bool uses_shadow_lod{};
  182. bool uses_rescaling_uniform{};
  183. bool uses_cbuf_indirect{};
  184. bool uses_render_area{};
  185. IR::Type used_constant_buffer_types{};
  186. IR::Type used_storage_buffer_types{};
  187. IR::Type used_indirect_cbuf_types{};
  188. u32 constant_buffer_mask{};
  189. std::array<u32, MAX_CBUFS> constant_buffer_used_sizes{};
  190. u32 nvn_buffer_base{};
  191. std::bitset<16> nvn_buffer_used{};
  192. bool requires_layer_emulation{};
  193. IR::Attribute emulated_layer{};
  194. u32 used_clip_distances{};
  195. boost::container::static_vector<ConstantBufferDescriptor, MAX_CBUFS>
  196. constant_buffer_descriptors;
  197. boost::container::static_vector<StorageBufferDescriptor, MAX_SSBOS> storage_buffers_descriptors;
  198. TextureBufferDescriptors texture_buffer_descriptors;
  199. ImageBufferDescriptors image_buffer_descriptors;
  200. TextureDescriptors texture_descriptors;
  201. ImageDescriptors image_descriptors;
  202. };
  203. template <typename Descriptors>
  204. u32 NumDescriptors(const Descriptors& descriptors) {
  205. u32 num{};
  206. for (const auto& desc : descriptors) {
  207. num += desc.count;
  208. }
  209. return num;
  210. }
  211. } // namespace Shader