D3DMain.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // Copyright 2008 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "VideoBackends/D3D/VideoBackend.h"
  4. #include <memory>
  5. #include <string>
  6. #include "Common/Common.h"
  7. #include "Common/CommonTypes.h"
  8. #include "Common/MsgHandler.h"
  9. #include "Common/StringUtil.h"
  10. #include "VideoBackends/D3D/D3DBase.h"
  11. #include "VideoBackends/D3D/D3DBoundingBox.h"
  12. #include "VideoBackends/D3D/D3DGfx.h"
  13. #include "VideoBackends/D3D/D3DPerfQuery.h"
  14. #include "VideoBackends/D3D/D3DSwapChain.h"
  15. #include "VideoBackends/D3D/D3DVertexManager.h"
  16. #include "VideoBackends/D3DCommon/D3DCommon.h"
  17. #include "VideoCommon/AbstractGfx.h"
  18. #include "VideoCommon/FramebufferManager.h"
  19. #include "VideoCommon/ShaderCache.h"
  20. #include "VideoCommon/TextureCacheBase.h"
  21. #include "VideoCommon/VideoCommon.h"
  22. #include "VideoCommon/VideoConfig.h"
  23. namespace DX11
  24. {
  25. std::string VideoBackend::GetName() const
  26. {
  27. return NAME;
  28. }
  29. std::string VideoBackend::GetDisplayName() const
  30. {
  31. return _trans("Direct3D 11");
  32. }
  33. std::optional<std::string> VideoBackend::GetWarningMessage() const
  34. {
  35. std::optional<std::string> result;
  36. // If relevant, show a warning about partial DX11.1 support
  37. // This is being called BEFORE FillBackendInfo is called for this backend,
  38. // so query for logic op support manually
  39. bool supportsLogicOp = false;
  40. if (D3DCommon::LoadLibraries())
  41. {
  42. supportsLogicOp = D3D::SupportsLogicOp(g_Config.iAdapter);
  43. D3DCommon::UnloadLibraries();
  44. }
  45. if (!supportsLogicOp)
  46. {
  47. result = _trans("The Direct3D 11 renderer requires support for features not supported by your "
  48. "system configuration. You may still use this backend, but you will encounter "
  49. "graphical artifacts in certain games.\n"
  50. "\n"
  51. "Do you really want to switch to Direct3D 11? If unsure, select 'No'.");
  52. }
  53. return result;
  54. }
  55. void VideoBackend::InitBackendInfo(const WindowSystemInfo& wsi)
  56. {
  57. if (!D3DCommon::LoadLibraries())
  58. return;
  59. FillBackendInfo();
  60. D3DCommon::UnloadLibraries();
  61. }
  62. void VideoBackend::FillBackendInfo()
  63. {
  64. g_Config.backend_info.api_type = APIType::D3D;
  65. g_Config.backend_info.MaxTextureSize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
  66. g_Config.backend_info.bUsesLowerLeftOrigin = false;
  67. g_Config.backend_info.bSupportsExclusiveFullscreen = true;
  68. g_Config.backend_info.bSupportsDualSourceBlend = true;
  69. g_Config.backend_info.bSupportsPrimitiveRestart = true;
  70. g_Config.backend_info.bSupportsGeometryShaders = true;
  71. g_Config.backend_info.bSupportsComputeShaders = false;
  72. g_Config.backend_info.bSupports3DVision = true;
  73. g_Config.backend_info.bSupportsPostProcessing = true;
  74. g_Config.backend_info.bSupportsPaletteConversion = true;
  75. g_Config.backend_info.bSupportsClipControl = true;
  76. g_Config.backend_info.bSupportsDepthClamp = true;
  77. g_Config.backend_info.bSupportsReversedDepthRange = false;
  78. g_Config.backend_info.bSupportsMultithreading = false;
  79. g_Config.backend_info.bSupportsGPUTextureDecoding = true;
  80. g_Config.backend_info.bSupportsCopyToVram = true;
  81. g_Config.backend_info.bSupportsLargePoints = false;
  82. g_Config.backend_info.bSupportsDepthReadback = true;
  83. g_Config.backend_info.bSupportsPartialDepthCopies = false;
  84. g_Config.backend_info.bSupportsBitfield = false;
  85. g_Config.backend_info.bSupportsDynamicSamplerIndexing = false;
  86. g_Config.backend_info.bSupportsFramebufferFetch = false;
  87. g_Config.backend_info.bSupportsBackgroundCompiling = true;
  88. g_Config.backend_info.bSupportsST3CTextures = true;
  89. g_Config.backend_info.bSupportsBPTCTextures = true;
  90. g_Config.backend_info.bSupportsEarlyZ = true;
  91. g_Config.backend_info.bSupportsBBox = true;
  92. g_Config.backend_info.bSupportsFragmentStoresAndAtomics = true;
  93. g_Config.backend_info.bSupportsGSInstancing = true;
  94. g_Config.backend_info.bSupportsSSAA = true;
  95. g_Config.backend_info.bSupportsShaderBinaries = true;
  96. g_Config.backend_info.bSupportsPipelineCacheData = false;
  97. g_Config.backend_info.bSupportsCoarseDerivatives = true;
  98. g_Config.backend_info.bSupportsTextureQueryLevels = true;
  99. g_Config.backend_info.bSupportsLodBiasInSampler = true;
  100. g_Config.backend_info.bSupportsLogicOp = D3D::SupportsLogicOp(g_Config.iAdapter);
  101. g_Config.backend_info.bSupportsSettingObjectNames = true;
  102. g_Config.backend_info.bSupportsPartialMultisampleResolve = true;
  103. g_Config.backend_info.bSupportsDynamicVertexLoader = false;
  104. g_Config.backend_info.bSupportsHDROutput = true;
  105. g_Config.backend_info.Adapters = D3DCommon::GetAdapterNames();
  106. g_Config.backend_info.AAModes = D3D::GetAAModes(g_Config.iAdapter);
  107. // Override optional features if we are actually booting.
  108. if (D3D::device)
  109. {
  110. g_Config.backend_info.bSupportsST3CTextures =
  111. D3D::SupportsTextureFormat(DXGI_FORMAT_BC1_UNORM) &&
  112. D3D::SupportsTextureFormat(DXGI_FORMAT_BC2_UNORM) &&
  113. D3D::SupportsTextureFormat(DXGI_FORMAT_BC3_UNORM);
  114. g_Config.backend_info.bSupportsBPTCTextures = D3D::SupportsTextureFormat(DXGI_FORMAT_BC7_UNORM);
  115. // Features only supported with a FL11.0+ device.
  116. const bool shader_model_5_supported = D3D::feature_level >= D3D_FEATURE_LEVEL_11_0;
  117. g_Config.backend_info.bSupportsEarlyZ = shader_model_5_supported;
  118. g_Config.backend_info.bSupportsBBox = shader_model_5_supported;
  119. g_Config.backend_info.bSupportsFragmentStoresAndAtomics = shader_model_5_supported;
  120. g_Config.backend_info.bSupportsGSInstancing = shader_model_5_supported;
  121. g_Config.backend_info.bSupportsSSAA = shader_model_5_supported;
  122. g_Config.backend_info.bSupportsGPUTextureDecoding = shader_model_5_supported;
  123. }
  124. }
  125. bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
  126. {
  127. if (!D3D::Create(g_Config.iAdapter, g_Config.bEnableValidationLayer))
  128. return false;
  129. FillBackendInfo();
  130. UpdateActiveConfig();
  131. std::unique_ptr<SwapChain> swap_chain;
  132. if (wsi.render_surface && !(swap_chain = SwapChain::Create(wsi)))
  133. {
  134. PanicAlertFmtT("Failed to create D3D swap chain");
  135. ShutdownShared();
  136. D3D::Destroy();
  137. return false;
  138. }
  139. auto gfx = std::make_unique<DX11::Gfx>(std::move(swap_chain), wsi.render_surface_scale);
  140. auto vertex_manager = std::make_unique<VertexManager>();
  141. auto perf_query = std::make_unique<PerfQuery>();
  142. auto bounding_box = std::make_unique<D3DBoundingBox>();
  143. return InitializeShared(std::move(gfx), std::move(vertex_manager), std::move(perf_query),
  144. std::move(bounding_box));
  145. }
  146. void VideoBackend::Shutdown()
  147. {
  148. ShutdownShared();
  149. D3D::Destroy();
  150. }
  151. } // namespace DX11