shader_info.h 4.6 KB

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