gl_device.h 5.5 KB

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