Blender V4.3
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
9#pragma once
10
11#include "gpu_backend.hh"
12
13#include "BLI_vector.hh"
14
15#ifdef WITH_RENDERDOC
16# include "renderdoc_api.hh"
17#endif
18
19#include "gl_batch.hh"
21#include "gl_compute.hh"
22#include "gl_context.hh"
23#include "gl_drawlist.hh"
24#include "gl_framebuffer.hh"
25#include "gl_index_buffer.hh"
26#include "gl_query.hh"
27#include "gl_shader.hh"
28#include "gl_storage_buffer.hh"
29#include "gl_texture.hh"
30#include "gl_uniform_buffer.hh"
31#include "gl_vertex_buffer.hh"
32
33namespace blender {
34namespace gpu {
35
36class GLBackend : public GPUBackend {
37 private:
38 GLSharedOrphanLists shared_orphan_list_;
39#ifdef WITH_RENDERDOC
41#endif
42
43 GLShaderCompiler compiler_;
44
45 public:
47 {
48 /* platform_init needs to go first. */
49 GLBackend::platform_init();
50
51 GLBackend::capabilities_init();
53 }
55 {
56 GLBackend::platform_exit();
57 }
58
59 void delete_resources() override
60 {
61 /* Delete any resources with context active. */
63 }
64
65 static GLBackend *get()
66 {
67 return static_cast<GLBackend *>(GPUBackend::get());
68 }
69
71 {
72 return &compiler_;
73 }
74
75 void samplers_update() override
76 {
78 };
79
80 Context *context_alloc(void *ghost_window, void * /*ghost_context*/) override
81 {
82 return new GLContext(ghost_window, shared_orphan_list_);
83 };
84
85 Batch *batch_alloc() override
86 {
87 return new GLBatch();
88 };
89
90 DrawList *drawlist_alloc(int list_length) override
91 {
92 return new GLDrawList(list_length);
93 };
94
95 Fence *fence_alloc() override
96 {
97 return new GLFence();
98 };
99
100 FrameBuffer *framebuffer_alloc(const char *name) override
101 {
102 return new GLFrameBuffer(name);
103 };
104
106 {
107 return new GLIndexBuf();
108 };
109
110 PixelBuffer *pixelbuf_alloc(size_t size) override
111 {
112 return new GLPixelBuffer(size);
113 };
114
116 {
117 return new GLQueryPool();
118 };
119
120 Shader *shader_alloc(const char *name) override
121 {
122 return new GLShader(name);
123 };
124
125 Texture *texture_alloc(const char *name) override
126 {
127 return new GLTexture(name);
128 };
129
130 UniformBuf *uniformbuf_alloc(size_t size, const char *name) override
131 {
132 return new GLUniformBuf(size, name);
133 };
134
135 StorageBuf *storagebuf_alloc(size_t size, GPUUsageType usage, const char *name) override
136 {
137 return new GLStorageBuf(size, usage, name);
138 };
139
141 {
142 return new GLVertBuf();
143 };
144
146 {
147 return shared_orphan_list_;
148 };
149
150 void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) override
151 {
153 GLCompute::dispatch(groups_x_len, groups_y_len, groups_z_len);
154 }
155
156 void compute_dispatch_indirect(StorageBuf *indirect_buf) override
157 {
159
160 dynamic_cast<GLStorageBuf *>(indirect_buf)->bind_as(GL_DISPATCH_INDIRECT_BUFFER);
161 /* This barrier needs to be here as it only work on the currently bound indirect buffer. */
162 glMemoryBarrier(GL_COMMAND_BARRIER_BIT);
163
164 glDispatchComputeIndirect((GLintptr)0);
165 /* Unbind. */
166 glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, 0);
167 }
168
170 {
171#if BLI_SUBPROCESS_SUPPORT
172 GL_shader_cache_dir_clear_old();
173#endif
174 }
175
176 /* Render Frame Coordination */
177 void render_begin() override{};
178 void render_end() override{};
179 void render_step() override{};
180
181 bool debug_capture_begin(const char *title);
182 void debug_capture_end();
183
184 private:
185 static void platform_init();
186 static void platform_exit();
187
188 static void capabilities_init();
189};
190
191} // namespace gpu
192} // namespace blender
GLSharedOrphanLists & shared_orphan_list_get()
Fence * fence_alloc() override
Definition gl_backend.hh:95
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
VertBuf * vertbuf_alloc() override
Texture * texture_alloc(const char *name) override
void render_end() override
GLShaderCompiler * get_compiler()
Definition gl_backend.hh:70
void render_step() override
static GLBackend * get()
Definition gl_backend.hh:65
DrawList * drawlist_alloc(int list_length) override
Definition gl_backend.hh:90
Batch * batch_alloc() override
Definition gl_backend.hh:85
void render_begin() override
void samplers_update() override
Definition gl_backend.hh:75
bool debug_capture_begin(const char *title)
Definition gl_debug.cc:409
void delete_resources() override
Definition gl_backend.hh:59
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:80
UniformBuf * uniformbuf_alloc(size_t size, const char *name) 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()