Blender  V2.93
gpu_context_private.hh
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2016 by Mike Erwin.
17  * All rights reserved.
18  */
19 
26 #pragma once
27 
28 #include "MEM_guardedalloc.h"
29 
30 #include "GPU_context.h"
31 
32 #include "gpu_debug_private.hh"
34 #include "gpu_immediate_private.hh"
35 #include "gpu_shader_private.hh"
36 #include "gpu_state_private.hh"
37 
38 #include <pthread.h>
39 
40 struct GPUMatrixState;
41 
42 namespace blender::gpu {
43 
44 class Context {
45  public:
52 
64 
66 
67  protected:
69  pthread_t thread_;
70  bool is_active_;
73 
74  public:
75  Context();
76  virtual ~Context();
77 
78  static Context *get(void);
79 
80  virtual void activate(void) = 0;
81  virtual void deactivate(void) = 0;
82 
83  /* Will push all pending commands to the GPU. */
84  virtual void flush(void) = 0;
85  /* Will wait until the GPU has finished executing all command. */
86  virtual void finish(void) = 0;
87 
88  virtual void memory_statistics_get(int *total_mem, int *free_mem) = 0;
89 
90  virtual void debug_group_begin(const char *, int){};
91  virtual void debug_group_end(void){};
92 
93  bool is_active_on_thread(void);
94 };
95 
96 /* Syntactic sugar. */
97 static inline GPUContext *wrap(Context *ctx)
98 {
99  return reinterpret_cast<GPUContext *>(ctx);
100 }
101 static inline Context *unwrap(GPUContext *ctx)
102 {
103  return reinterpret_cast<Context *>(ctx);
104 }
105 static inline const Context *unwrap(const GPUContext *ctx)
106 {
107  return reinterpret_cast<const Context *>(ctx);
108 }
109 
110 } // namespace blender::gpu
struct GPUContext GPUContext
Definition: GPU_context.h:44
Read Guarded memory(de)allocation.
virtual void finish(void)=0
virtual void debug_group_end(void)
virtual void debug_group_begin(const char *, int)
virtual void deactivate(void)=0
GPUMatrixState * matrix_state
virtual void activate(void)=0
static Context * get(void)
Definition: gpu_context.cc:88
virtual void memory_statistics_get(int *total_mem, int *free_mem)=0
virtual void flush(void)=0
bool is_active_on_thread(void)
Definition: gpu_context.cc:83
static GPUContext * wrap(Context *ctx)
static Context * unwrap(GPUContext *ctx)