shader_info.h 5.5 KB

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