shader_info.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 "common/common_types.h"
  7. #include "shader_recompiler/frontend/ir/type.h"
  8. #include "shader_recompiler/varying_state.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 ConstantBufferDescriptor {
  39. u32 index;
  40. u32 count;
  41. };
  42. struct StorageBufferDescriptor {
  43. u32 cbuf_index;
  44. u32 cbuf_offset;
  45. u32 count;
  46. bool is_written;
  47. };
  48. struct TextureBufferDescriptor {
  49. bool has_secondary;
  50. u32 cbuf_index;
  51. u32 cbuf_offset;
  52. u32 secondary_cbuf_index;
  53. u32 secondary_cbuf_offset;
  54. u32 count;
  55. u32 size_shift;
  56. };
  57. using TextureBufferDescriptors = boost::container::small_vector<TextureBufferDescriptor, 6>;
  58. struct ImageBufferDescriptor {
  59. ImageFormat format;
  60. bool is_written;
  61. bool is_read;
  62. u32 cbuf_index;
  63. u32 cbuf_offset;
  64. u32 count;
  65. u32 size_shift;
  66. };
  67. using ImageBufferDescriptors = boost::container::small_vector<ImageBufferDescriptor, 2>;
  68. struct TextureDescriptor {
  69. TextureType type;
  70. bool is_depth;
  71. bool has_secondary;
  72. u32 cbuf_index;
  73. u32 cbuf_offset;
  74. u32 secondary_cbuf_index;
  75. u32 secondary_cbuf_offset;
  76. u32 count;
  77. u32 size_shift;
  78. };
  79. using TextureDescriptors = boost::container::small_vector<TextureDescriptor, 12>;
  80. struct ImageDescriptor {
  81. TextureType type;
  82. ImageFormat format;
  83. bool is_written;
  84. bool is_read;
  85. u32 cbuf_index;
  86. u32 cbuf_offset;
  87. u32 count;
  88. u32 size_shift;
  89. };
  90. using ImageDescriptors = boost::container::small_vector<ImageDescriptor, 4>;
  91. struct Info {
  92. static constexpr size_t MAX_INDIRECT_CBUFS{14};
  93. static constexpr size_t MAX_CBUFS{18};
  94. static constexpr size_t MAX_SSBOS{32};
  95. bool uses_workgroup_id{};
  96. bool uses_local_invocation_id{};
  97. bool uses_invocation_id{};
  98. bool uses_sample_id{};
  99. bool uses_is_helper_invocation{};
  100. bool uses_subgroup_invocation_id{};
  101. bool uses_subgroup_shuffles{};
  102. std::array<bool, 30> uses_patches{};
  103. std::array<Interpolation, 32> interpolation{};
  104. VaryingState loads;
  105. VaryingState stores;
  106. VaryingState passthrough;
  107. bool loads_indexed_attributes{};
  108. std::array<bool, 8> stores_frag_color{};
  109. bool stores_sample_mask{};
  110. bool stores_frag_depth{};
  111. bool stores_tess_level_outer{};
  112. bool stores_tess_level_inner{};
  113. bool stores_indexed_attributes{};
  114. bool stores_global_memory{};
  115. bool uses_fp16{};
  116. bool uses_fp64{};
  117. bool uses_fp16_denorms_flush{};
  118. bool uses_fp16_denorms_preserve{};
  119. bool uses_fp32_denorms_flush{};
  120. bool uses_fp32_denorms_preserve{};
  121. bool uses_int8{};
  122. bool uses_int16{};
  123. bool uses_int64{};
  124. bool uses_image_1d{};
  125. bool uses_sampled_1d{};
  126. bool uses_sparse_residency{};
  127. bool uses_demote_to_helper_invocation{};
  128. bool uses_subgroup_vote{};
  129. bool uses_subgroup_mask{};
  130. bool uses_fswzadd{};
  131. bool uses_derivatives{};
  132. bool uses_typeless_image_reads{};
  133. bool uses_typeless_image_writes{};
  134. bool uses_image_buffers{};
  135. bool uses_shared_increment{};
  136. bool uses_shared_decrement{};
  137. bool uses_global_increment{};
  138. bool uses_global_decrement{};
  139. bool uses_atomic_f32_add{};
  140. bool uses_atomic_f16x2_add{};
  141. bool uses_atomic_f16x2_min{};
  142. bool uses_atomic_f16x2_max{};
  143. bool uses_atomic_f32x2_add{};
  144. bool uses_atomic_f32x2_min{};
  145. bool uses_atomic_f32x2_max{};
  146. bool uses_atomic_s32_min{};
  147. bool uses_atomic_s32_max{};
  148. bool uses_int64_bit_atomics{};
  149. bool uses_global_memory{};
  150. bool uses_atomic_image_u32{};
  151. bool uses_shadow_lod{};
  152. bool uses_rescaling_uniform{};
  153. bool uses_cbuf_indirect{};
  154. IR::Type used_constant_buffer_types{};
  155. IR::Type used_storage_buffer_types{};
  156. IR::Type used_indirect_cbuf_types{};
  157. u32 constant_buffer_mask{};
  158. std::array<u32, MAX_CBUFS> constant_buffer_used_sizes{};
  159. u32 nvn_buffer_base{};
  160. std::bitset<16> nvn_buffer_used{};
  161. boost::container::static_vector<ConstantBufferDescriptor, MAX_CBUFS>
  162. constant_buffer_descriptors;
  163. boost::container::static_vector<StorageBufferDescriptor, MAX_SSBOS> storage_buffers_descriptors;
  164. TextureBufferDescriptors texture_buffer_descriptors;
  165. ImageBufferDescriptors image_buffer_descriptors;
  166. TextureDescriptors texture_descriptors;
  167. ImageDescriptors image_descriptors;
  168. };
  169. template <typename Descriptors>
  170. u32 NumDescriptors(const Descriptors& descriptors) {
  171. u32 num{};
  172. for (const auto& desc : descriptors) {
  173. num += desc.count;
  174. }
  175. return num;
  176. }
  177. } // namespace Shader