Debian Codegraph @

Source/Core/VideoCommon/VideoConfig.h

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