Debian Codegraph @

Source/Core/VideoBackends/Vulkan/VKGfx.h

raw symbols SCIP
1 // Copyright 2016 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <array>
7 #include <memory>
8 #include <string_view>
9
10 #include "Common/CommonTypes.h"
11 #include "VideoBackends/Vulkan/Constants.h"
12 #include "VideoCommon/AbstractGfx.h"
13 #include "VideoCommon/Constants.h"
14
15 namespace Vulkan
16 {
17 class SwapChain;
18 class StagingTexture2D;
19 class VKFramebuffer;
20 class VKPipeline;
21 class VKTexture;
22
23 class VKGfx final : public ::AbstractGfx
24 {
25 public:
26 VKGfx(std::unique_ptr<SwapChain> swap_chain, float backbuffer_scale);
27 ~VKGfx() override;
28
29 static VKGfx* GetInstance() { return static_cast<VKGfx*>(g_gfx.get()); }
30
31 bool IsHeadless() const override;
32
33 std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config,
34 std::string_view name) override;
35 std::unique_ptr<AbstractStagingTexture>
36 CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override;
37 std::unique_ptr<AbstractFramebuffer>
38 CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment,
39 std::vector<AbstractTexture*> additional_color_attachments) override;
40
41 std::unique_ptr<AbstractShader>
42 CreateShaderFromSource(ShaderStage stage, std::string_view source,
43 VideoCommon::ShaderIncluder* shader_includer,
44 std::string_view name) override;
45 std::unique_ptr<AbstractShader> CreateShaderFromBinary(ShaderStage stage, const void* data,
46 size_t length,
47 std::string_view name) override;
48 std::unique_ptr<NativeVertexFormat>
49 CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override;
50 std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config,
51 const void* cache_data = nullptr,
52 size_t cache_data_length = 0) override;
53
54 SwapChain* GetSwapChain() const { return m_swap_chain.get(); }
55
56 void Flush() override;
57 void WaitForGPUIdle() override;
58 void OnConfigChanged(u32 bits) override;
59
60 void ClearRegion(const MathUtil::Rectangle<int>& target_rc, bool color_enable, bool alpha_enable,
61 bool z_enable, u32 color, u32 z) override;
62
63 void SetPipeline(const AbstractPipeline* pipeline) override;
64 void SetFramebuffer(AbstractFramebuffer* framebuffer) override;
65 void SetAndDiscardFramebuffer(AbstractFramebuffer* framebuffer) override;
66 void SetAndClearFramebuffer(AbstractFramebuffer* framebuffer, const ClearColor& color_value = {},
67 float depth_value = 0.0f) override;
68 void SetScissorRect(const MathUtil::Rectangle<int>& rc) override;
69 void SetTexture(u32 index, const AbstractTexture* texture) override;
70 void SetSamplerState(u32 index, const SamplerState& state) override;
71 void SetComputeImageTexture(u32 index, AbstractTexture* texture, bool read, bool write) override;
72 void UnbindTexture(const AbstractTexture* texture) override;
73 void SetViewport(float x, float y, float width, float height, float near_depth,
74 float far_depth) override;
75 void Draw(u32 base_vertex, u32 num_vertices) override;
76 void DrawIndexed(u32 base_index, u32 num_indices, u32 base_vertex) override;
77 void DispatchComputeShader(const AbstractShader* shader, u32 groupsize_x, u32 groupsize_y,
78 u32 groupsize_z, u32 groups_x, u32 groups_y, u32 groups_z) override;
79 bool BindBackbuffer(const ClearColor& clear_color = {}) override;
80 void PresentBackbuffer() override;
81 void SetFullscreen(bool enable_fullscreen) override;
82 bool IsFullscreen() const override;
83
84 SurfaceInfo GetSurfaceInfo() const override;
85
86 // Completes the current render pass, executes the command buffer, and restores state ready for
87 // next render. Use when you want to kick the current buffer to make room for new data.
88 void ExecuteCommandBuffer(bool execute_off_thread, bool wait_for_completion = false);
89
90 private:
91 void CheckForSurfaceChange();
92 void CheckForSurfaceResize();
93
94 void ResetSamplerStates();
95
96 void OnSwapChainResized();
97 void BindFramebuffer(VKFramebuffer* fb);
98
99 std::unique_ptr<SwapChain> m_swap_chain;
100 float m_backbuffer_scale;
101
102 // Keep a copy of sampler states to avoid cache lookups every draw
103 std::array<SamplerState, VideoCommon::MAX_PIXEL_SHADER_SAMPLERS> m_sampler_states = {};
104 };
105 } // namespace Vulkan