Debian Codegraph @

Source/Core/VideoBackends/D3D/DXTexture.h

raw symbols SCIP
1 // Copyright 2017 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <d3d11_4.h>
7 #include <memory>
8 #include <string>
9 #include <string_view>
10 #include <vector>
11
12 #include "Common/CommonTypes.h"
13
14 #include "VideoBackends/D3D/D3DBase.h"
15 #include "VideoCommon/AbstractFramebuffer.h"
16 #include "VideoCommon/AbstractGfx.h"
17 #include "VideoCommon/AbstractStagingTexture.h"
18 #include "VideoCommon/AbstractTexture.h"
19
20 namespace DX11
21 {
22 class DXTexture final : public AbstractTexture
23 {
24 public:
25 ~DXTexture() override;
26
27 static std::unique_ptr<DXTexture> Create(const TextureConfig& config, std::string_view name);
28 static std::unique_ptr<DXTexture> CreateAdopted(ComPtr<ID3D11Texture2D> texture);
29
30 void CopyRectangleFromTexture(const AbstractTexture* src,
31 const MathUtil::Rectangle<int>& src_rect, u32 src_layer,
32 u32 src_level, const MathUtil::Rectangle<int>& dst_rect,
33 u32 dst_layer, u32 dst_level) override;
34 void ResolveFromTexture(const AbstractTexture* src, const MathUtil::Rectangle<int>& rect,
35 u32 layer, u32 level) override;
36 void Load(u32 level, u32 width, u32 height, u32 row_length, const u8* buffer, size_t buffer_size,
37 u32 layer) override;
38
39 ID3D11Texture2D* GetD3DTexture() const { return m_texture.Get(); }
40 ID3D11ShaderResourceView* GetD3DSRV() const { return m_srv.Get(); }
41 ID3D11UnorderedAccessView* GetD3DUAV() const { return m_uav.Get(); }
42
43 private:
44 DXTexture(const TextureConfig& config, ComPtr<ID3D11Texture2D> texture, std::string_view name);
45
46 bool CreateSRV();
47 bool CreateUAV();
48
49 ComPtr<ID3D11Texture2D> m_texture;
50 ComPtr<ID3D11ShaderResourceView> m_srv;
51 ComPtr<ID3D11UnorderedAccessView> m_uav;
52 std::string m_name;
53 };
54
55 class DXStagingTexture final : public AbstractStagingTexture
56 {
57 public:
58 DXStagingTexture() = delete;
59 ~DXStagingTexture() override;
60
61 void CopyFromTexture(const AbstractTexture* src, const MathUtil::Rectangle<int>& src_rect,
62 u32 src_layer, u32 src_level,
63 const MathUtil::Rectangle<int>& dst_rect) override;
64 void CopyToTexture(const MathUtil::Rectangle<int>& src_rect, AbstractTexture* dst,
65 const MathUtil::Rectangle<int>& dst_rect, u32 dst_layer,
66 u32 dst_level) override;
67
68 bool Map() override;
69 void Unmap() override;
70 void Flush() override;
71
72 static std::unique_ptr<DXStagingTexture> Create(StagingTextureType type,
73 const TextureConfig& config);
74
75 private:
76 DXStagingTexture(StagingTextureType type, const TextureConfig& config,
77 ComPtr<ID3D11Texture2D> tex);
78
79 ComPtr<ID3D11Texture2D> m_tex = nullptr;
80 };
81
82 class DXFramebuffer final : public AbstractFramebuffer
83 {
84 public:
85 DXFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment,
86 std::vector<AbstractTexture*> additional_color_attachments,
87 AbstractTextureFormat color_format, AbstractTextureFormat depth_format, u32 width,
88 u32 height, u32 layers, u32 samples, ComPtr<ID3D11RenderTargetView> rtv,
89 ComPtr<ID3D11RenderTargetView> integer_rtv, ComPtr<ID3D11DepthStencilView> dsv,
90 std::vector<ComPtr<ID3D11RenderTargetView>> additional_rtvs);
91 ~DXFramebuffer() override;
92
93 ID3D11RenderTargetView* const* GetRTVArray() const { return m_render_targets_raw.data(); }
94 ID3D11RenderTargetView* const* GetIntegerRTVArray() const { return m_integer_rtv.GetAddressOf(); }
95 UINT GetNumRTVs() const { return static_cast<UINT>(m_render_targets_raw.size()); }
96 ID3D11DepthStencilView* GetDSV() const { return m_dsv.Get(); }
97
98 void Unbind();
99 void Clear(const ClearColor& color_value, float depth_value);
100
101 static std::unique_ptr<DXFramebuffer>
102 Create(DXTexture* color_attachment, DXTexture* depth_attachment,
103 std::vector<AbstractTexture*> additional_color_attachments);
104
105 protected:
106 std::vector<ComPtr<ID3D11RenderTargetView>> m_render_targets;
107 std::vector<ID3D11RenderTargetView*> m_render_targets_raw;
108 ComPtr<ID3D11RenderTargetView> m_integer_rtv;
109 ComPtr<ID3D11DepthStencilView> m_dsv;
110 };
111
112 } // namespace DX11