Blender V5.0
gl_backend.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "GPU_capabilities.hh"
12#include "GPU_platform.hh"
13
14#include "gpu_backend.hh"
15
16#include "BLI_threads.h"
17#include "BLI_vector.hh"
18
20
21#ifdef WITH_RENDERDOC
22# include "renderdoc_api.hh"
23#endif
24
25#include "gl_batch.hh"
27#include "gl_compute.hh"
28#include "gl_context.hh"
29#include "gl_framebuffer.hh"
30#include "gl_index_buffer.hh"
31#include "gl_query.hh"
32#include "gl_shader.hh"
33#include "gl_storage_buffer.hh"
34#include "gl_texture.hh"
35#include "gl_uniform_buffer.hh"
36#include "gl_vertex_buffer.hh"
37
38namespace blender {
39namespace gpu {
40
41class GLBackend : public GPUBackend {
42 private:
43 GLSharedOrphanLists shared_orphan_list_;
44#ifdef WITH_RENDERDOC
46#endif
47
48 public:
50 {
51 /* platform_init needs to go first. */
52 GLBackend::platform_init();
53
54 GLBackend::capabilities_init();
56 }
58 {
59 GLBackend::platform_exit();
60 }
61
62 void init_resources() override
63 {
64 if (GCaps.use_subprocess_shader_compilations) {
65 compiler_ = MEM_new<GLSubprocessShaderCompiler>(__func__);
66 }
67 else {
68 compiler_ = MEM_new<GLShaderCompiler>(__func__);
69 }
70 };
71
72 void delete_resources() override
73 {
74 /* Delete any resources with context active. */
76 MEM_delete(compiler_);
77 }
78
79 static GLBackend *get()
80 {
81 return static_cast<GLBackend *>(GPUBackend::get());
82 }
83
84 void samplers_update() override
85 {
87 };
88
89 Context *context_alloc(void *ghost_window, void * /*ghost_context*/) override
90 {
91 return new GLContext(ghost_window, shared_orphan_list_);
92 };
93
94 Batch *batch_alloc() override
95 {
96 return new GLBatch();
97 };
98
99 Fence *fence_alloc() override
100 {
101 return new GLFence();
102 };
103
104 FrameBuffer *framebuffer_alloc(const char *name) override
105 {
106 return new GLFrameBuffer(name);
107 };
108
110 {
111 return new GLIndexBuf();
112 };
113
115 {
116 return new GLPixelBuffer(size);
117 };
118
120 {
121 return new GLQueryPool();
122 };
123
124 Shader *shader_alloc(const char *name) override
125 {
126 return new GLShader(name);
127 };
128
129 Texture *texture_alloc(const char *name) override
130 {
131 return new GLTexture(name);
132 };
133
134 UniformBuf *uniformbuf_alloc(size_t size, const char *name) override
135 {
136 return new GLUniformBuf(size, name);
137 };
138
139 StorageBuf *storagebuf_alloc(size_t size, GPUUsageType usage, const char *name) override
140 {
141 return new GLStorageBuf(size, usage, name);
142 };
143
145 {
146 return new GLVertBuf();
147 };
148
150 {
151 return shared_orphan_list_;
152 };
153
154 void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) override
155 {
157 GLCompute::dispatch(groups_x_len, groups_y_len, groups_z_len);
158 }
159
160 void compute_dispatch_indirect(StorageBuf *indirect_buf) override
161 {
163
164 dynamic_cast<GLStorageBuf *>(indirect_buf)->bind_as(GL_DISPATCH_INDIRECT_BUFFER);
165 /* This barrier needs to be here as it only work on the currently bound indirect buffer. */
166 glMemoryBarrier(GL_COMMAND_BARRIER_BIT);
167
168 glDispatchComputeIndirect((GLintptr)0);
169 /* Unbind. */
170 glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, 0);
171 }
172
174 {
175#if BLI_SUBPROCESS_SUPPORT
176 GL_shader_cache_dir_clear_old();
177#endif
178 }
179
180 /* Render Frame Coordination */
181 void render_begin() override {};
182 void render_end() override {};
183 void render_step(bool /*force_resource_release*/) override {};
184
185 bool debug_capture_begin(const char *title);
186 void debug_capture_end();
187
188 private:
189 static void platform_init();
190 static void platform_exit();
191
192 static void capabilities_init();
193};
194
195} // namespace gpu
196} // namespace blender
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
GLSharedOrphanLists & shared_orphan_list_get()
Fence * fence_alloc() override
Definition gl_backend.hh:99
void compute_dispatch_indirect(StorageBuf *indirect_buf) override
Shader * shader_alloc(const char *name) override
IndexBuf * indexbuf_alloc() override
StorageBuf * storagebuf_alloc(size_t size, GPUUsageType usage, const char *name) override
void shader_cache_dir_clear_old() override
void init_resources() override
Definition gl_backend.hh:62
VertBuf * vertbuf_alloc() override
Texture * texture_alloc(const char *name) override
void render_end() override
static GLBackend * get()
Definition gl_backend.hh:79
Batch * batch_alloc() override
Definition gl_backend.hh:94
void render_begin() override
void samplers_update() override
Definition gl_backend.hh:84
bool debug_capture_begin(const char *title)
Definition gl_debug.cc:483
void delete_resources() override
Definition gl_backend.hh:72
QueryPool * querypool_alloc() override
PixelBuffer * pixelbuf_alloc(size_t size) override
void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) override
Context * context_alloc(void *ghost_window, void *) override
Definition gl_backend.hh:89
UniformBuf * uniformbuf_alloc(size_t size, const char *name) override
void render_step(bool) override
FrameBuffer * framebuffer_alloc(const char *name) override
static void dispatch(int group_x_len, int group_y_len, int group_z_len)
Definition gl_compute.cc:15
static GLStateManager * state_manager_active_get()
static GLContext * get()
void apply_state() override
Definition gl_state.cc:54
static void samplers_init()
static void samplers_update()
static void samplers_free()
static GPUBackend * get()
ShaderCompiler * compiler_
GPUCapabilities GCaps
const char * name