Blender  V2.93
gpu_state_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  * Copyright 2020, Blender Foundation.
17  */
18 
23 #pragma once
24 
25 #include "BLI_utildefines.h"
26 
27 #include "GPU_state.h"
28 
29 #include "gpu_texture_private.hh"
30 
31 #include <cstring>
32 
33 namespace blender {
34 namespace gpu {
35 
36 /* Encapsulate all pipeline state that we need to track.
37  * Try to keep small to reduce validation time. */
38 union GPUState {
39  struct {
59  /* TODO(fclem): This should be a shader property. */
61  /* TODO(fclem): remove, old opengl features. */
64  };
65  /* Here to allow fast bitwise ops. */
67 };
68 
69 BLI_STATIC_ASSERT(sizeof(GPUState) == sizeof(uint64_t), "GPUState is too big.");
70 
71 inline bool operator==(const GPUState &a, const GPUState &b)
72 {
73  return a.data == b.data;
74 }
75 
76 inline bool operator!=(const GPUState &a, const GPUState &b)
77 {
78  return !(a == b);
79 }
80 
81 inline GPUState operator^(const GPUState &a, const GPUState &b)
82 {
83  GPUState r;
84  r.data = a.data ^ b.data;
85  return r;
86 }
87 
88 inline GPUState operator~(const GPUState &a)
89 {
90  GPUState r;
91  r.data = ~a.data;
92  return r;
93 }
94 
95 /* Mutable state that does not require pipeline change. */
97  struct {
98  /* Viewport State */
100  float depth_range[2];
102  /* TODO(fclem): should be passed as uniform to all shaders. */
103  float point_size;
105  float line_width;
111  /* IMPORTANT: ensure x64 struct alignment. */
112  };
113  /* Here to allow fast bit-wise ops. */
115 };
116 
118  "GPUStateMutable is too big.");
119 
120 inline bool operator==(const GPUStateMutable &a, const GPUStateMutable &b)
121 {
122  return memcmp(&a, &b, sizeof(GPUStateMutable)) == 0;
123 }
124 
125 inline bool operator!=(const GPUStateMutable &a, const GPUStateMutable &b)
126 {
127  return !(a == b);
128 }
129 
131 {
133  for (int i = 0; i < ARRAY_SIZE(a.data); i++) {
134  r.data[i] = a.data[i] ^ b.data[i];
135  }
136  return r;
137 }
138 
140 {
142  for (int i = 0; i < ARRAY_SIZE(a.data); i++) {
143  r.data[i] = ~a.data[i];
144  }
145  return r;
146 }
147 
153  public:
156  bool use_bgl = false;
157 
158  public:
159  StateManager();
160  virtual ~StateManager(){};
161 
162  virtual void apply_state(void) = 0;
163  virtual void force_state(void) = 0;
164 
165  virtual void issue_barrier(eGPUBarrier barrier_bits) = 0;
166 
167  virtual void texture_bind(Texture *tex, eGPUSamplerState sampler, int unit) = 0;
168  virtual void texture_unbind(Texture *tex) = 0;
169  virtual void texture_unbind_all(void) = 0;
170 
171  virtual void image_bind(Texture *tex, int unit) = 0;
172  virtual void image_unbind(Texture *tex) = 0;
173  virtual void image_unbind_all(void) = 0;
174 
176 };
177 
178 } // namespace gpu
179 } // namespace blender
unsigned int uint
Definition: BLI_sys_types.h:83
#define ARRAY_SIZE(arr)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
eGPUBarrier
Definition: GPU_state.h:38
eGPUSamplerState
Definition: GPU_texture.h:40
virtual void issue_barrier(eGPUBarrier barrier_bits)=0
virtual void force_state(void)=0
virtual void texture_unbind(Texture *tex)=0
virtual void image_unbind(Texture *tex)=0
virtual void texture_unbind_all(void)=0
virtual void image_unbind_all(void)=0
virtual void texture_bind(Texture *tex, eGPUSamplerState sampler, int unit)=0
virtual void image_bind(Texture *tex, int unit)=0
virtual void apply_state(void)=0
virtual void texture_unpack_row_length_set(uint len)=0
static unsigned a[3]
Definition: RandGen.cpp:92
GPUState operator^(const GPUState &a, const GPUState &b)
bool operator==(const GPUState &a, const GPUState &b)
BLI_STATIC_ASSERT(sizeof(GPUState)==sizeof(uint64_t), "GPUState is too big.")
GPUState operator~(const GPUState &a)
bool operator!=(const GPUState &a, const GPUState &b)
unsigned int uint32_t
Definition: stdint.h:83
unsigned char uint8_t
Definition: stdint.h:81
unsigned __int64 uint64_t
Definition: stdint.h:93
uint len