Blender V5.3
gpu_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
11
12#pragma once
13
14#include "BLI_color_types.hh"
15#include "BLI_string_ref.hh"
16
17#include "GHOST_IContext.hh"
18#include "GHOST_IWindow.hh"
19
20#include "GPU_vertex_buffer.hh"
21
22namespace blender::gpu {
23
24class Context;
25
26class Batch;
27class Fence;
28class FrameBuffer;
29class IndexBuf;
30class PixelBuffer;
31class QueryPool;
32class Shader;
33class ShaderCompiler;
34class Texture;
35class TexturePool;
36class UniformBuf;
37class StorageBuf;
38class VertBuf;
39class TopLevelAS;
40class BottomLevelAS;
41class WorkInFlight;
42
44 protected:
46
47 public:
48 virtual ~GPUBackend() = default;
49
50 /* Called after the main context creation and activation. */
51 virtual void init_resources() = 0;
52 /* Called before the main context deletion and deactivation. */
53 virtual void delete_resources() = 0;
54
55 static GPUBackend *get();
56
58 {
59 return compiler_;
60 }
61
62 virtual void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) = 0;
63 virtual void compute_dispatch_indirect(StorageBuf *indirect_buf) = 0;
64
65 virtual Context *context_alloc(GHOST_IWindow *ghost_window, GHOST_IContext *ghost_context) = 0;
66
67 virtual Batch *batch_alloc() = 0;
68 virtual Fence *fence_alloc() = 0;
69 virtual WorkInFlight *work_in_flight_alloc(unsigned int max_in_flight) = 0;
70 virtual FrameBuffer *framebuffer_alloc(const char *name) = 0;
71 virtual IndexBuf *indexbuf_alloc() = 0;
72 virtual PixelBuffer *pixelbuf_alloc(size_t size) = 0;
73 virtual QueryPool *querypool_alloc() = 0;
74 virtual Shader *shader_alloc(const char *name) = 0;
75 virtual Texture *texture_alloc(const char *name) = 0;
77 virtual UniformBuf *uniformbuf_alloc(size_t size, const char *name) = 0;
78 virtual StorageBuf *storagebuf_alloc(size_t size, GPUUsageType usage, const char *name) = 0;
79 virtual VertBuf *vertbuf_alloc() = 0;
80 virtual TopLevelAS *tlas_alloc(const char *name) = 0;
81 virtual BottomLevelAS *blas_alloc(const char *name) = 0;
82 virtual void shader_cache_dir_clear_old() = 0;
83
84 /* Render Frame Coordination --
85 * Used for performing per-frame actions globally */
86 virtual void render_begin() = 0;
87 virtual void render_end() = 0;
88 virtual void render_step(bool force_resource_release = false) = 0;
89};
90
91namespace debug {
93
95{
96 if (name == "EEVEE") {
97 return ColorTheme4f(1.0, 0.5, 0.0, 1.0);
98 }
99 if (name == "External") {
100 return ColorTheme4f(0.0, 0.0, 1.0, 1.0);
101 }
102 if (name == "GpencilMode") {
103 return ColorTheme4f(1.0, 1.0, 0.0, 1.0);
104 }
105 if (name == "UV/Image") {
106 return ColorTheme4f(0.0, 1.0, 1.0, 1.0);
107 }
108 if (name == "Overlay") {
109 return ColorTheme4f(0.0, 1.0, 0.5, 1.0);
110 }
111 if (name == "Workbench") {
112 return ColorTheme4f(0.0, 0.7, 1.0, 1.0);
113 }
114 if (name == "Cycles") {
115 return ColorTheme4f(0.0, 0.5, 1.0, 1.0);
116 }
117 if (name == "BackBuffer.Blit") {
118 return ColorTheme4f(0.5, 0.7, 1.0, 1.0);
119 }
120 if (name == "Compositor") {
121 return ColorTheme4f(1.0, 0.5, 0.7, 1.0);
122 }
124}
125} // namespace debug
126} // namespace blender::gpu
virtual void init_resources()=0
virtual void render_end()=0
virtual Batch * batch_alloc()=0
virtual void render_step(bool force_resource_release=false)=0
virtual void compute_dispatch_indirect(StorageBuf *indirect_buf)=0
virtual void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len)=0
ShaderCompiler * compiler_
virtual void delete_resources()=0
virtual void render_begin()=0
virtual TexturePool * texturepool_alloc()=0
ShaderCompiler * get_compiler()
virtual PixelBuffer * pixelbuf_alloc(size_t size)=0
virtual QueryPool * querypool_alloc()=0
virtual Texture * texture_alloc(const char *name)=0
virtual FrameBuffer * framebuffer_alloc(const char *name)=0
virtual UniformBuf * uniformbuf_alloc(size_t size, const char *name)=0
virtual IndexBuf * indexbuf_alloc()=0
virtual StorageBuf * storagebuf_alloc(size_t size, GPUUsageType usage, const char *name)=0
virtual BottomLevelAS * blas_alloc(const char *name)=0
virtual void shader_cache_dir_clear_old()=0
virtual Context * context_alloc(GHOST_IWindow *ghost_window, GHOST_IContext *ghost_context)=0
virtual ~GPUBackend()=default
static GPUBackend * get()
virtual Fence * fence_alloc()=0
virtual WorkInFlight * work_in_flight_alloc(unsigned int max_in_flight)=0
virtual VertBuf * vertbuf_alloc()=0
virtual TopLevelAS * tlas_alloc(const char *name)=0
virtual Shader * shader_alloc(const char *name)=0
static ColorTheme4f get_debug_group_color(StringRefNull name)
static ColorTheme4f GPU_DEBUG_GROUP_COLOR_DEFAULT
ColorTheme4< float > ColorTheme4f