gl_device.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // Copyright 2019 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <cstddef>
  6. #include "common/common_types.h"
  7. #include "shader_recompiler/stage.h"
  8. namespace Settings {
  9. enum class ShaderBackend : u32;
  10. };
  11. namespace OpenGL {
  12. class Device {
  13. public:
  14. explicit Device();
  15. [[nodiscard]] std::string GetVendorName() const;
  16. u32 GetMaxUniformBuffers(Shader::Stage stage) const noexcept {
  17. return max_uniform_buffers[static_cast<size_t>(stage)];
  18. }
  19. size_t GetUniformBufferAlignment() const {
  20. return uniform_buffer_alignment;
  21. }
  22. size_t GetShaderStorageBufferAlignment() const {
  23. return shader_storage_alignment;
  24. }
  25. u32 GetMaxVertexAttributes() const {
  26. return max_vertex_attributes;
  27. }
  28. u32 GetMaxVaryings() const {
  29. return max_varyings;
  30. }
  31. u32 GetMaxComputeSharedMemorySize() const {
  32. return max_compute_shared_memory_size;
  33. }
  34. u32 GetMaxGLASMStorageBufferBlocks() const {
  35. return max_glasm_storage_buffer_blocks;
  36. }
  37. bool HasWarpIntrinsics() const {
  38. return has_warp_intrinsics;
  39. }
  40. bool HasShaderBallot() const {
  41. return has_shader_ballot;
  42. }
  43. bool HasVertexViewportLayer() const {
  44. return has_vertex_viewport_layer;
  45. }
  46. bool HasImageLoadFormatted() const {
  47. return has_image_load_formatted;
  48. }
  49. bool HasTextureShadowLod() const {
  50. return has_texture_shadow_lod;
  51. }
  52. bool HasVertexBufferUnifiedMemory() const {
  53. return has_vertex_buffer_unified_memory;
  54. }
  55. bool HasASTC() const {
  56. return has_astc;
  57. }
  58. bool HasVariableAoffi() const {
  59. return has_variable_aoffi;
  60. }
  61. bool HasComponentIndexingBug() const {
  62. return has_component_indexing_bug;
  63. }
  64. bool HasPreciseBug() const {
  65. return has_precise_bug;
  66. }
  67. bool HasBrokenTextureViewFormats() const {
  68. return has_broken_texture_view_formats;
  69. }
  70. bool HasFastBufferSubData() const {
  71. return has_fast_buffer_sub_data;
  72. }
  73. bool HasNvViewportArray2() const {
  74. return has_nv_viewport_array2;
  75. }
  76. bool HasDerivativeControl() const {
  77. return has_derivative_control;
  78. }
  79. bool HasDebuggingToolAttached() const {
  80. return has_debugging_tool_attached;
  81. }
  82. bool UseAssemblyShaders() const {
  83. return use_assembly_shaders;
  84. }
  85. bool UseAsynchronousShaders() const {
  86. return use_asynchronous_shaders;
  87. }
  88. bool UseDriverCache() const {
  89. return use_driver_cache;
  90. }
  91. bool HasDepthBufferFloat() const {
  92. return has_depth_buffer_float;
  93. }
  94. bool HasGeometryShaderPassthrough() const {
  95. return has_geometry_shader_passthrough;
  96. }
  97. bool HasNvGpuShader5() const {
  98. return has_nv_gpu_shader_5;
  99. }
  100. bool HasShaderInt64() const {
  101. return has_shader_int64;
  102. }
  103. bool HasAmdShaderHalfFloat() const {
  104. return has_amd_shader_half_float;
  105. }
  106. bool HasSparseTexture2() const {
  107. return has_sparse_texture_2;
  108. }
  109. bool IsWarpSizePotentiallyLargerThanGuest() const {
  110. return warp_size_potentially_larger_than_guest;
  111. }
  112. bool NeedsFastmathOff() const {
  113. return need_fastmath_off;
  114. }
  115. bool HasCbufFtouBug() const {
  116. return has_cbuf_ftou_bug;
  117. }
  118. Settings::ShaderBackend GetShaderBackend() const {
  119. return shader_backend;
  120. }
  121. bool IsAmd() const {
  122. return vendor_name == "ATI Technologies Inc.";
  123. }
  124. private:
  125. static bool TestVariableAoffi();
  126. static bool TestPreciseBug();
  127. std::array<u32, Shader::MaxStageTypes> max_uniform_buffers{};
  128. size_t uniform_buffer_alignment{};
  129. size_t shader_storage_alignment{};
  130. u32 max_vertex_attributes{};
  131. u32 max_varyings{};
  132. u32 max_compute_shared_memory_size{};
  133. u32 max_glasm_storage_buffer_blocks{};
  134. Settings::ShaderBackend shader_backend{};
  135. bool has_warp_intrinsics{};
  136. bool has_shader_ballot{};
  137. bool has_vertex_viewport_layer{};
  138. bool has_image_load_formatted{};
  139. bool has_texture_shadow_lod{};
  140. bool has_vertex_buffer_unified_memory{};
  141. bool has_astc{};
  142. bool has_variable_aoffi{};
  143. bool has_component_indexing_bug{};
  144. bool has_precise_bug{};
  145. bool has_broken_texture_view_formats{};
  146. bool has_fast_buffer_sub_data{};
  147. bool has_nv_viewport_array2{};
  148. bool has_derivative_control{};
  149. bool has_debugging_tool_attached{};
  150. bool use_assembly_shaders{};
  151. bool use_asynchronous_shaders{};
  152. bool use_driver_cache{};
  153. bool has_depth_buffer_float{};
  154. bool has_geometry_shader_passthrough{};
  155. bool has_nv_gpu_shader_5{};
  156. bool has_shader_int64{};
  157. bool has_amd_shader_half_float{};
  158. bool has_sparse_texture_2{};
  159. bool warp_size_potentially_larger_than_guest{};
  160. bool need_fastmath_off{};
  161. bool has_cbuf_ftou_bug{};
  162. std::string vendor_name;
  163. };
  164. } // namespace OpenGL