D3DBase.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2010 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <d3d11.h>
  5. #include <d3d11_1.h>
  6. #include <d3dcompiler.h>
  7. #include <dxgi1_5.h>
  8. #include <fmt/format.h>
  9. #include <vector>
  10. #include <wrl/client.h>
  11. #include "Common/CommonTypes.h"
  12. #include "Common/HRWrap.h"
  13. namespace DX11
  14. {
  15. using Microsoft::WRL::ComPtr;
  16. class SwapChain;
  17. namespace D3D
  18. {
  19. extern ComPtr<IDXGIFactory> dxgi_factory;
  20. extern ComPtr<ID3D11Device> device;
  21. extern ComPtr<ID3D11Device1> device1;
  22. extern ComPtr<ID3D11DeviceContext> context;
  23. extern D3D_FEATURE_LEVEL feature_level;
  24. bool Create(u32 adapter_index, bool enable_debug_layer);
  25. void Destroy();
  26. // Returns a list of supported AA modes for the current device.
  27. std::vector<u32> GetAAModes(u32 adapter_index);
  28. // Checks for support of the given texture format.
  29. bool SupportsTextureFormat(DXGI_FORMAT format);
  30. // Checks for logic op support.
  31. bool SupportsLogicOp(u32 adapter_index);
  32. } // namespace D3D
  33. // Wrapper for HRESULT to be used with fmt. Note that we can't create a fmt::formatter directly
  34. // for HRESULT as HRESULT is simply a typedef on long and not a distinct type.
  35. // Unlike the version in Common, this variant also knows to call GetDeviceRemovedReason if needed.
  36. struct DX11HRWrap
  37. {
  38. constexpr explicit DX11HRWrap(HRESULT hr) : m_hr(hr) {}
  39. const HRESULT m_hr;
  40. };
  41. } // namespace DX11
  42. template <>
  43. struct fmt::formatter<DX11::DX11HRWrap>
  44. {
  45. constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
  46. template <typename FormatContext>
  47. auto format(const DX11::DX11HRWrap& hr, FormatContext& ctx) const
  48. {
  49. if (hr.m_hr == DXGI_ERROR_DEVICE_REMOVED && DX11::D3D::device != nullptr)
  50. {
  51. return fmt::format_to(ctx.out(), "{}\nDevice removal reason: {}", Common::HRWrap(hr.m_hr),
  52. Common::HRWrap(DX11::D3D::device->GetDeviceRemovedReason()));
  53. }
  54. else
  55. {
  56. return fmt::format_to(ctx.out(), "{}", Common::HRWrap(hr.m_hr));
  57. }
  58. }
  59. };