VideoConfig.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. // Copyright 2008 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. // IMPORTANT: UI etc should modify g_Config. Graphics code should read g_ActiveConfig.
  4. // The reason for this is to get rid of race conditions etc when the configuration
  5. // changes in the middle of a frame. This is done by copying g_Config to g_ActiveConfig
  6. // at the start of every frame. Noone should ever change members of g_ActiveConfig
  7. // directly.
  8. #pragma once
  9. #include <optional>
  10. #include <string>
  11. #include <vector>
  12. #include "Common/CommonTypes.h"
  13. #include "VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.h"
  14. #include "VideoCommon/VideoCommon.h"
  15. constexpr int EFB_SCALE_AUTO_INTEGRAL = 0;
  16. enum class AspectMode : int
  17. {
  18. Auto, // ~4:3 or ~16:9 (auto detected)
  19. ForceWide, // ~16:9
  20. ForceStandard, // ~4:3
  21. Stretch,
  22. Custom, // Forced relative custom AR
  23. CustomStretch, // Forced absolute custom AR
  24. Raw, // Forced squared pixels
  25. };
  26. enum class StereoMode : int
  27. {
  28. Off,
  29. SBS,
  30. TAB,
  31. Anaglyph,
  32. QuadBuffer,
  33. Passive
  34. };
  35. enum class ShaderCompilationMode : int
  36. {
  37. Synchronous,
  38. SynchronousUberShaders,
  39. AsynchronousUberShaders,
  40. AsynchronousSkipRendering
  41. };
  42. enum class TextureFilteringMode : int
  43. {
  44. Default,
  45. Nearest,
  46. Linear,
  47. };
  48. enum class OutputResamplingMode : int
  49. {
  50. Default,
  51. Bilinear,
  52. BSpline,
  53. MitchellNetravali,
  54. CatmullRom,
  55. SharpBilinear,
  56. AreaSampling,
  57. };
  58. enum class ColorCorrectionRegion : int
  59. {
  60. SMPTE_NTSCM,
  61. SYSTEMJ_NTSCJ,
  62. EBU_PAL,
  63. };
  64. enum class TriState : int
  65. {
  66. Off,
  67. On,
  68. Auto
  69. };
  70. enum class FrameDumpResolutionType : int
  71. {
  72. // Window resolution (not including potential back buffer black borders)
  73. WindowResolution,
  74. // The aspect ratio corrected XFB resolution (XFB pixels might not have been square)
  75. XFBAspectRatioCorrectedResolution,
  76. // The raw unscaled XFB resolution (based on "internal resolution" scale)
  77. XFBRawResolution,
  78. };
  79. // Bitmask containing information about which configuration has changed for the backend.
  80. enum ConfigChangeBits : u32
  81. {
  82. CONFIG_CHANGE_BIT_HOST_CONFIG = (1 << 0),
  83. CONFIG_CHANGE_BIT_MULTISAMPLES = (1 << 1),
  84. CONFIG_CHANGE_BIT_STEREO_MODE = (1 << 2),
  85. CONFIG_CHANGE_BIT_TARGET_SIZE = (1 << 3),
  86. CONFIG_CHANGE_BIT_ANISOTROPY = (1 << 4),
  87. CONFIG_CHANGE_BIT_FORCE_TEXTURE_FILTERING = (1 << 5),
  88. CONFIG_CHANGE_BIT_VSYNC = (1 << 6),
  89. CONFIG_CHANGE_BIT_BBOX = (1 << 7),
  90. CONFIG_CHANGE_BIT_ASPECT_RATIO = (1 << 8),
  91. CONFIG_CHANGE_BIT_POST_PROCESSING_SHADER = (1 << 9),
  92. CONFIG_CHANGE_BIT_HDR = (1 << 10),
  93. };
  94. // NEVER inherit from this class.
  95. struct VideoConfig final
  96. {
  97. VideoConfig() = default;
  98. void Refresh();
  99. void VerifyValidity();
  100. // General
  101. bool bVSync = false;
  102. bool bVSyncActive = false;
  103. bool bWidescreenHack = false;
  104. AspectMode aspect_mode{};
  105. int custom_aspect_width = 1;
  106. int custom_aspect_height = 1;
  107. AspectMode suggested_aspect_mode{};
  108. u32 widescreen_heuristic_transition_threshold = 0;
  109. float widescreen_heuristic_aspect_ratio_slop = 0.f;
  110. float widescreen_heuristic_standard_ratio = 0.f;
  111. float widescreen_heuristic_widescreen_ratio = 0.f;
  112. bool bCrop = false; // Aspect ratio controls.
  113. bool bShaderCache = false;
  114. // Enhancements
  115. u32 iMultisamples = 0;
  116. bool bSSAA = false;
  117. int iEFBScale = 0;
  118. TextureFilteringMode texture_filtering_mode = TextureFilteringMode::Default;
  119. OutputResamplingMode output_resampling_mode = OutputResamplingMode::Default;
  120. int iMaxAnisotropy = 0;
  121. std::string sPostProcessingShader;
  122. bool bForceTrueColor = false;
  123. bool bDisableCopyFilter = false;
  124. bool bArbitraryMipmapDetection = false;
  125. float fArbitraryMipmapDetectionThreshold = 0;
  126. bool bHDR = false;
  127. // Color Correction
  128. struct
  129. {
  130. // Color Space Correction:
  131. bool bCorrectColorSpace = false;
  132. ColorCorrectionRegion game_color_space = ColorCorrectionRegion::SMPTE_NTSCM;
  133. // Gamma Correction:
  134. bool bCorrectGamma = false;
  135. float fGameGamma = 2.35f;
  136. bool bSDRDisplayGammaSRGB = true;
  137. // Custom gamma when the display is not sRGB
  138. float fSDRDisplayCustomGamma = 2.2f;
  139. // HDR:
  140. // 203 is a good default value that matches the brightness of many SDR screens.
  141. // It's also the value recommended by the ITU.
  142. float fHDRPaperWhiteNits = 203.f;
  143. } color_correction;
  144. // Information
  145. bool bShowFPS = false;
  146. bool bShowFTimes = false;
  147. bool bShowVPS = false;
  148. bool bShowVTimes = false;
  149. bool bShowGraphs = false;
  150. bool bShowSpeed = false;
  151. bool bShowSpeedColors = false;
  152. int iPerfSampleUSec = 0;
  153. bool bShowNetPlayPing = false;
  154. bool bShowNetPlayMessages = false;
  155. bool bOverlayStats = false;
  156. bool bOverlayProjStats = false;
  157. bool bOverlayScissorStats = false;
  158. bool bTexFmtOverlayEnable = false;
  159. bool bTexFmtOverlayCenter = false;
  160. bool bLogRenderTimeToFile = false;
  161. // Render
  162. bool bWireFrame = false;
  163. bool bDisableFog = false;
  164. // Utility
  165. bool bDumpTextures = false;
  166. bool bDumpMipmapTextures = false;
  167. bool bDumpBaseTextures = false;
  168. bool bHiresTextures = false;
  169. bool bCacheHiresTextures = false;
  170. bool bDumpEFBTarget = false;
  171. bool bDumpXFBTarget = false;
  172. bool bDumpFramesAsImages = false;
  173. bool bUseFFV1 = false;
  174. std::string sDumpCodec;
  175. std::string sDumpPixelFormat;
  176. std::string sDumpEncoder;
  177. std::string sDumpFormat;
  178. std::string sDumpPath;
  179. FrameDumpResolutionType frame_dumps_resolution_type =
  180. FrameDumpResolutionType::XFBAspectRatioCorrectedResolution;
  181. bool bBorderlessFullscreen = false;
  182. bool bEnableGPUTextureDecoding = false;
  183. bool bPreferVSForLinePointExpansion = false;
  184. int iBitrateKbps = 0;
  185. bool bGraphicMods = false;
  186. std::optional<GraphicsModGroupConfig> graphics_mod_config;
  187. // Hacks
  188. bool bEFBAccessEnable = false;
  189. bool bEFBAccessDeferInvalidation = false;
  190. bool bPerfQueriesEnable = false;
  191. bool bBBoxEnable = false;
  192. bool bForceProgressive = false;
  193. bool bCPUCull = false;
  194. bool bEFBEmulateFormatChanges = false;
  195. bool bSkipEFBCopyToRam = false;
  196. bool bSkipXFBCopyToRam = false;
  197. bool bDisableCopyToVRAM = false;
  198. bool bDeferEFBCopies = false;
  199. bool bImmediateXFB = false;
  200. bool bSkipPresentingDuplicateXFBs = false;
  201. bool bCopyEFBScaled = false;
  202. int iSafeTextureCache_ColorSamples = 0;
  203. float fAspectRatioHackW = 1; // Initial value needed for the first frame
  204. float fAspectRatioHackH = 1;
  205. bool bEnablePixelLighting = false;
  206. bool bFastDepthCalc = false;
  207. bool bVertexRounding = false;
  208. bool bVISkip = false;
  209. int iEFBAccessTileSize = 0;
  210. int iSaveTargetId = 0; // TODO: Should be dropped
  211. u32 iMissingColorValue = 0;
  212. bool bFastTextureSampling = false;
  213. #ifdef __APPLE__
  214. bool bNoMipmapping = false; // Used by macOS fifoci to work around an M1 bug
  215. #endif
  216. // Stereoscopy
  217. StereoMode stereo_mode{};
  218. bool stereo_per_eye_resolution_full = false;
  219. int iStereoDepth = 0;
  220. int iStereoConvergence = 0;
  221. int iStereoConvergencePercentage = 0;
  222. bool bStereoSwapEyes = false;
  223. bool bStereoEFBMonoDepth = false;
  224. int iStereoDepthPercentage = 0;
  225. // D3D only config, mostly to be merged into the above
  226. int iAdapter = 0;
  227. // Metal only config
  228. TriState iManuallyUploadBuffers = TriState::Auto;
  229. TriState iUsePresentDrawable = TriState::Auto;
  230. // Enable API validation layers, currently only supported with Vulkan.
  231. bool bEnableValidationLayer = false;
  232. // Multithreaded submission, currently only supported with Vulkan.
  233. bool bBackendMultithreading = true;
  234. // Early command buffer execution interval in number of draws.
  235. // Currently only supported with Vulkan.
  236. int iCommandBufferExecuteInterval = 0;
  237. // Shader compilation settings.
  238. bool bWaitForShadersBeforeStarting = false;
  239. ShaderCompilationMode iShaderCompilationMode{};
  240. // Number of shader compiler threads.
  241. // 0 disables background compilation.
  242. // -1 uses an automatic number based on the CPU threads.
  243. int iShaderCompilerThreads = 0;
  244. int iShaderPrecompilerThreads = 0;
  245. // Loading custom drivers on Android
  246. std::string customDriverLibraryName;
  247. // Static config per API
  248. // TODO: Move this out of VideoConfig
  249. struct
  250. {
  251. APIType api_type = APIType::Nothing;
  252. std::string DisplayName;
  253. std::vector<std::string> Adapters; // for D3D
  254. std::vector<u32> AAModes;
  255. // TODO: merge AdapterName and Adapters array
  256. std::string AdapterName; // for OpenGL
  257. u32 MaxTextureSize = 16384;
  258. bool bUsesLowerLeftOrigin = false;
  259. bool bUsesExplictQuadBuffering = false;
  260. bool bSupportsExclusiveFullscreen = false;
  261. bool bSupportsDualSourceBlend = false;
  262. bool bSupportsPrimitiveRestart = false;
  263. bool bSupportsGeometryShaders = false;
  264. bool bSupportsComputeShaders = false;
  265. bool bSupports3DVision = false;
  266. bool bSupportsEarlyZ = false; // needed by PixelShaderGen, so must stay in VideoCommon
  267. bool bSupportsBindingLayout = false; // Needed by ShaderGen, so must stay in VideoCommon
  268. bool bSupportsBBox = false;
  269. bool bSupportsGSInstancing = false; // Needed by GeometryShaderGen, so must stay in VideoCommon
  270. bool bSupportsPostProcessing = false;
  271. bool bSupportsPaletteConversion = false;
  272. bool bSupportsClipControl = false; // Needed by VertexShaderGen, so must stay in VideoCommon
  273. bool bSupportsSSAA = false;
  274. bool bSupportsFragmentStoresAndAtomics = false; // a.k.a. OpenGL SSBOs a.k.a. Direct3D UAVs
  275. bool bSupportsDepthClamp = false; // Needed by VertexShaderGen, so must stay in VideoCommon
  276. bool bSupportsReversedDepthRange = false;
  277. bool bSupportsLogicOp = false;
  278. bool bSupportsMultithreading = false;
  279. bool bSupportsGPUTextureDecoding = false;
  280. bool bSupportsST3CTextures = false;
  281. bool bSupportsCopyToVram = false;
  282. bool bSupportsBitfield = false; // Needed by UberShaders, so must stay in VideoCommon
  283. // Needed by UberShaders, so must stay in VideoCommon
  284. bool bSupportsDynamicSamplerIndexing = false;
  285. bool bSupportsBPTCTextures = false;
  286. bool bSupportsFramebufferFetch = false; // Used as an alternative to dual-source blend on GLES
  287. bool bSupportsBackgroundCompiling = false;
  288. bool bSupportsLargePoints = false;
  289. bool bSupportsPartialDepthCopies = false;
  290. bool bSupportsDepthReadback = false;
  291. bool bSupportsShaderBinaries = false;
  292. bool bSupportsPipelineCacheData = false;
  293. bool bSupportsCoarseDerivatives = false;
  294. bool bSupportsTextureQueryLevels = false;
  295. bool bSupportsLodBiasInSampler = false;
  296. bool bSupportsSettingObjectNames = false;
  297. bool bSupportsPartialMultisampleResolve = false;
  298. bool bSupportsDynamicVertexLoader = false;
  299. bool bSupportsVSLinePointExpand = false;
  300. bool bSupportsGLLayerInFS = true;
  301. bool bSupportsHDROutput = false;
  302. } backend_info;
  303. // Utility
  304. bool UseVSForLinePointExpand() const
  305. {
  306. if (!backend_info.bSupportsVSLinePointExpand)
  307. return false;
  308. if (!backend_info.bSupportsGeometryShaders)
  309. return true;
  310. return bPreferVSForLinePointExpansion;
  311. }
  312. bool MultisamplingEnabled() const { return iMultisamples > 1; }
  313. bool ExclusiveFullscreenEnabled() const
  314. {
  315. return backend_info.bSupportsExclusiveFullscreen && !bBorderlessFullscreen;
  316. }
  317. bool UseGPUTextureDecoding() const
  318. {
  319. return backend_info.bSupportsGPUTextureDecoding && bEnableGPUTextureDecoding;
  320. }
  321. bool UseVertexRounding() const { return bVertexRounding && iEFBScale != 1; }
  322. bool ManualTextureSamplingWithCustomTextureSizes() const
  323. {
  324. // If manual texture sampling is disabled, we don't need to do anything.
  325. if (bFastTextureSampling)
  326. return false;
  327. // Hi-res textures break the wrapping logic used by manual texture sampling, as a texture's
  328. // size won't match the size the game sets.
  329. if (bHiresTextures)
  330. return true;
  331. // Hi-res EFB copies (but not native-resolution EFB copies at higher internal resolutions)
  332. // also result in different texture sizes that need special handling.
  333. if (iEFBScale != 1 && bCopyEFBScaled)
  334. return true;
  335. // Stereoscopic 3D changes the number of layers some textures have (EFB copies have 2 layers,
  336. // while game textures still have 1), meaning bounds checks need to be added.
  337. if (stereo_mode != StereoMode::Off)
  338. return true;
  339. // Otherwise, manual texture sampling can use the sizes games specify directly.
  340. return false;
  341. }
  342. bool UsingUberShaders() const;
  343. u32 GetShaderCompilerThreads() const;
  344. u32 GetShaderPrecompilerThreads() const;
  345. float GetCustomAspectRatio() const { return (float)custom_aspect_width / custom_aspect_height; }
  346. };
  347. extern VideoConfig g_Config;
  348. extern VideoConfig g_ActiveConfig;
  349. // Called every frame.
  350. void UpdateActiveConfig();
  351. void CheckForConfigChanges();