Blender V4.3
vk_context.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
12
13#include "GHOST_Types.h"
14
16#include "vk_common.hh"
17#include "vk_debug.hh"
19#include "vk_resource_pool.hh"
20
21namespace blender::gpu {
22class VKFrameBuffer;
23class VKVertexAttributeObject;
24class VKBatch;
25class VKStateManager;
26class VKShader;
27class VKThreadData;
28
29class VKContext : public Context, NonCopyable {
30 private:
31 VkExtent2D vk_extent_ = {};
32 VkFormat swap_chain_format_ = {};
33 GPUTexture *surface_texture_ = nullptr;
34 void *ghost_context_;
35
36 /* Reusable data. Stored inside context to limit reallocations. */
37 render_graph::VKResourceAccessInfo access_info_ = {};
38
39 std::optional<std::reference_wrapper<VKThreadData>> thread_data_;
40
41 public:
43
44 VKContext(void *ghost_window,
45 void *ghost_context,
47 virtual ~VKContext();
48
49 void activate() override;
50 void deactivate() override;
51 void begin_frame() override;
52 void end_frame() override;
53
54 void flush() override;
55 void flush_render_graph();
56 void finish() override;
57
58 void memory_statistics_get(int *r_total_mem_kb, int *r_free_mem_kb) override;
59
60 void debug_group_begin(const char *, int) override;
61 void debug_group_end() override;
62 bool debug_capture_begin(const char *title) override;
63 void debug_capture_end() override;
64 void *debug_capture_scope_create(const char *name) override;
65 bool debug_capture_scope_begin(void *scope) override;
66 void debug_capture_scope_end(void *scope) override;
67
68 void debug_unbind_all_ubo() override;
69 void debug_unbind_all_ssbo() override;
70
71 bool has_active_framebuffer() const;
72 void activate_framebuffer(VKFrameBuffer &framebuffer);
75
83 void rendering_end();
84
86
91 void update_pipeline_data(GPUPrimType primitive,
93 render_graph::VKPipelineData &r_pipeline_data);
94
95 void sync_backbuffer();
96
97 static VKContext *get()
98 {
99 return static_cast<VKContext *>(Context::get());
100 }
101
105
106 static void swap_buffers_pre_callback(const GHOST_VulkanSwapChainData *data);
107 static void swap_buffers_post_callback();
108
109 private:
110 void swap_buffers_pre_handler(const GHOST_VulkanSwapChainData &data);
111 void swap_buffers_post_handler();
112
113 void update_pipeline_data(VKShader &shader,
114 VkPipeline vk_pipeline,
115 render_graph::VKPipelineData &r_pipeline_data);
116};
117
119{
120 return static_cast<const void *>(&a) == static_cast<const void *>(&b);
121}
122
123} // namespace blender::gpu
#define BLI_INLINE
GPUPrimType
static Context * get()
void debug_unbind_all_ssbo() override
render_graph::VKResourceAccessInfo & reset_and_get_access_info()
void debug_group_begin(const char *, int) override
Definition vk_debug.cc:22
void debug_group_end() override
Definition vk_debug.cc:27
void finish() override
render_graph::VKRenderGraph render_graph
Definition vk_context.hh:42
bool debug_capture_scope_begin(void *scope) override
Definition vk_debug.cc:70
void deactivate() override
void memory_statistics_get(int *r_total_mem_kb, int *r_free_mem_kb) override
void * debug_capture_scope_create(const char *name) override
Definition vk_debug.cc:65
bool debug_capture_begin(const char *title) override
Definition vk_debug.cc:32
void flush() override
static void swap_buffers_post_callback()
VKFrameBuffer * active_framebuffer_get() const
void activate() override
bool has_active_framebuffer() const
void debug_unbind_all_ubo() override
static void swap_buffers_pre_callback(const GHOST_VulkanSwapChainData *data)
void debug_capture_end() override
Definition vk_debug.cc:52
void activate_framebuffer(VKFrameBuffer &framebuffer)
void debug_capture_scope_end(void *scope) override
Definition vk_debug.cc:84
VKStateManager & state_manager_get() const
VKDescriptorSetTracker & descriptor_set_get()
void update_pipeline_data(render_graph::VKPipelineData &r_pipeline_data)
static VKContext * get()
Definition vk_context.hh:97
VKContext(void *ghost_window, void *ghost_context, render_graph::VKResourceStateTracker &resources)
Definition vk_context.cc:24
void begin_frame() override
VKDescriptorPools & descriptor_pools_get()
void end_frame() override
local_group_size(16, 16) .push_constant(Type b
bool operator==(const GPUState &a, const GPUState &b)