Blender  V3.3
gpu_context_private.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2016 by Mike Erwin. All rights reserved. */
3 
10 #pragma once
11 
12 #include "MEM_guardedalloc.h"
13 
14 #include "GPU_context.h"
15 
16 #include "gpu_debug_private.hh"
18 #include "gpu_immediate_private.hh"
19 #include "gpu_shader_private.hh"
20 #include "gpu_state_private.hh"
21 
22 #include <pthread.h>
23 
24 struct GPUMatrixState;
25 
26 namespace blender::gpu {
27 
28 class Context {
29  public:
31  Shader *shader = nullptr;
32  FrameBuffer *active_fb = nullptr;
35  Immediate *imm = nullptr;
36 
44  FrameBuffer *back_left = nullptr;
45  FrameBuffer *front_left = nullptr;
46  FrameBuffer *back_right = nullptr;
48 
50 
51  protected:
53  pthread_t thread_;
54  bool is_active_;
57 
58  public:
59  Context();
60  virtual ~Context();
61 
62  static Context *get();
63 
64  virtual void activate() = 0;
65  virtual void deactivate() = 0;
66  virtual void begin_frame() = 0;
67  virtual void end_frame() = 0;
68 
69  /* Will push all pending commands to the GPU. */
70  virtual void flush() = 0;
71  /* Will wait until the GPU has finished executing all command. */
72  virtual void finish() = 0;
73 
74  virtual void memory_statistics_get(int *total_mem, int *free_mem) = 0;
75 
76  virtual void debug_group_begin(const char *, int){};
77  virtual void debug_group_end(){};
78 
79  bool is_active_on_thread();
80 };
81 
82 /* Syntactic sugar. */
83 static inline GPUContext *wrap(Context *ctx)
84 {
85  return reinterpret_cast<GPUContext *>(ctx);
86 }
87 static inline Context *unwrap(GPUContext *ctx)
88 {
89  return reinterpret_cast<Context *>(ctx);
90 }
91 static inline const Context *unwrap(const GPUContext *ctx)
92 {
93  return reinterpret_cast<const Context *>(ctx);
94 }
95 
96 } // namespace blender::gpu
struct GPUContext GPUContext
Definition: GPU_context.h:27
Read Guarded memory(de)allocation.
virtual void debug_group_begin(const char *, int)
static Context * get()
Definition: gpu_context.cc:82
virtual void finish()=0
GPUMatrixState * matrix_state
virtual void activate()=0
virtual void memory_statistics_get(int *total_mem, int *free_mem)=0
virtual void end_frame()=0
virtual void begin_frame()=0
virtual void debug_group_end()
virtual void deactivate()=0
virtual void flush()=0
static GPUContext * wrap(Context *ctx)
static Context * unwrap(GPUContext *ctx)