shader_info.h 5.1 KB

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