Blender V4.3
gpu_context_private.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2016 by Mike Erwin. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11#pragma once
12
13#include "MEM_guardedalloc.h"
14
15#include "GPU_context.hh"
16
17#include "gpu_debug_private.hh"
20#include "gpu_shader_private.hh"
21#include "gpu_state_private.hh"
22
23#include <pthread.h>
24
25struct GPUMatrixState;
26
27namespace blender::gpu {
28
29class Context {
30 public:
32 Shader *shader = nullptr;
36 Immediate *imm = nullptr;
37
39
51
53 bool debug_is_capturing = false;
54
55 /* GPUContext counter used to assign a unique ID to each GPUContext.
56 * NOTE(Metal): This is required by the Metal Backend, as a bug exists in the global OS shader
57 * cache wherein compilation of identical source from two distinct threads can result in an
58 * invalid cache collision, result in a broken shader object. Appending the unique context ID
59 * onto compiled sources ensures the source hashes are different. */
60 static int context_counter;
61 int context_id = 0;
62
63 GPUStorageBuf *printf_buf = nullptr;
64
65 protected:
67 pthread_t thread_;
71
72 public:
73 Context();
74 virtual ~Context();
75
76 static Context *get();
77
78 virtual void activate() = 0;
79 virtual void deactivate() = 0;
80 virtual void begin_frame() = 0;
81 virtual void end_frame() = 0;
82
83 /* Will push all pending commands to the GPU. */
84 virtual void flush() = 0;
85 /* Will wait until the GPU has finished executing all command. */
86 virtual void finish() = 0;
87
88 virtual void memory_statistics_get(int *r_total_mem, int *r_free_mem) = 0;
89
90 virtual void debug_group_begin(const char *, int){};
91 virtual void debug_group_end(){};
92
93 /* Returns true if capture successfully started. */
94 virtual bool debug_capture_begin(const char *title) = 0;
95 virtual void debug_capture_end() = 0;
96 virtual void *debug_capture_scope_create(const char *name) = 0;
97 virtual bool debug_capture_scope_begin(void *scope) = 0;
98 virtual void debug_capture_scope_end(void *scope) = 0;
99
100 /* Consider all buffers slot empty after these call for error checking.
101 * But doesn't really free them. */
102 virtual void debug_unbind_all_ubo() = 0;
103 virtual void debug_unbind_all_ssbo() = 0;
104
105 bool is_active_on_thread();
106};
107
108/* Syntactic sugar. */
109static inline GPUContext *wrap(Context *ctx)
110{
111 return reinterpret_cast<GPUContext *>(ctx);
112}
113static inline Context *unwrap(GPUContext *ctx)
114{
115 return reinterpret_cast<Context *>(ctx);
116}
117static inline const Context *unwrap(const GPUContext *ctx)
118{
119 return reinterpret_cast<const Context *>(ctx);
120}
121
122} // namespace blender::gpu
Read Guarded memory(de)allocation.
struct GPUContext GPUContext
virtual void debug_unbind_all_ssbo()=0
virtual void debug_group_begin(const char *, int)
static Context * get()
virtual void debug_capture_scope_end(void *scope)=0
virtual void memory_statistics_get(int *r_total_mem, int *r_free_mem)=0
virtual void finish()=0
virtual void debug_unbind_all_ubo()=0
GPUMatrixState * matrix_state
virtual bool debug_capture_scope_begin(void *scope)=0
virtual void * debug_capture_scope_create(const char *name)=0
virtual void debug_capture_end()=0
virtual bool debug_capture_begin(const char *title)=0
virtual void activate()=0
virtual void end_frame()=0
virtual void begin_frame()=0
virtual void deactivate()=0
virtual void flush()=0
static Context * unwrap(GPUContext *ctx)
static GPUContext * wrap(Context *ctx)