Blender  V3.3
gpu_state_private.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. */
3 
8 #pragma once
9 
10 #include "BLI_utildefines.h"
11 
12 #include "GPU_state.h"
13 
14 #include "gpu_texture_private.hh"
15 
16 #include <cstring>
17 
18 namespace blender {
19 namespace gpu {
20 
21 /* Encapsulate all pipeline state that we need to track.
22  * Try to keep small to reduce validation time. */
23 union GPUState {
24  struct {
44  /* TODO(fclem): This should be a shader property. */
46  /* TODO(fclem): remove, old opengl features. */
49  };
50  /* Here to allow fast bit-wise ops. */
52 };
53 
54 BLI_STATIC_ASSERT(sizeof(GPUState) == sizeof(uint64_t), "GPUState is too big.");
55 
56 inline bool operator==(const GPUState &a, const GPUState &b)
57 {
58  return a.data == b.data;
59 }
60 
61 inline bool operator!=(const GPUState &a, const GPUState &b)
62 {
63  return !(a == b);
64 }
65 
66 inline GPUState operator^(const GPUState &a, const GPUState &b)
67 {
68  GPUState r;
69  r.data = a.data ^ b.data;
70  return r;
71 }
72 
73 inline GPUState operator~(const GPUState &a)
74 {
75  GPUState r;
76  r.data = ~a.data;
77  return r;
78 }
79 
80 /* Mutable state that does not require pipeline change. */
82  struct {
83  /* Viewport State */
85  float depth_range[2];
87  /* TODO(fclem): should be passed as uniform to all shaders. */
88  float point_size;
90  float line_width;
96  /* IMPORTANT: ensure x64 struct alignment. */
97  };
98  /* Here to allow fast bit-wise ops. */
100 };
101 
103  "GPUStateMutable is too big.");
104 
105 inline bool operator==(const GPUStateMutable &a, const GPUStateMutable &b)
106 {
107  return memcmp(&a, &b, sizeof(GPUStateMutable)) == 0;
108 }
109 
110 inline bool operator!=(const GPUStateMutable &a, const GPUStateMutable &b)
111 {
112  return !(a == b);
113 }
114 
116 {
118  for (int i = 0; i < ARRAY_SIZE(a.data); i++) {
119  r.data[i] = a.data[i] ^ b.data[i];
120  }
121  return r;
122 }
123 
125 {
127  for (int i = 0; i < ARRAY_SIZE(a.data); i++) {
128  r.data[i] = ~a.data[i];
129  }
130  return r;
131 }
132 
138  public:
141  bool use_bgl = false;
142 
143  public:
144  StateManager();
145  virtual ~StateManager(){};
146 
147  virtual void apply_state() = 0;
148  virtual void force_state() = 0;
149 
150  virtual void issue_barrier(eGPUBarrier barrier_bits) = 0;
151 
152  virtual void texture_bind(Texture *tex, eGPUSamplerState sampler, int unit) = 0;
153  virtual void texture_unbind(Texture *tex) = 0;
154  virtual void texture_unbind_all() = 0;
155 
156  virtual void image_bind(Texture *tex, int unit) = 0;
157  virtual void image_unbind(Texture *tex) = 0;
158  virtual void image_unbind_all() = 0;
159 
161 };
162 
163 } // namespace gpu
164 } // namespace blender
unsigned int uint
Definition: BLI_sys_types.h:67
#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:24
eGPUSamplerState
Definition: GPU_texture.h:25
virtual void texture_unbind_all()=0
virtual void issue_barrier(eGPUBarrier barrier_bits)=0
virtual void apply_state()=0
virtual void texture_unbind(Texture *tex)=0
virtual void image_unbind_all()=0
virtual void image_unbind(Texture *tex)=0
virtual void texture_bind(Texture *tex, eGPUSamplerState sampler, int unit)=0
virtual void image_bind(Texture *tex, int unit)=0
virtual void texture_unpack_row_length_set(uint len)=0
virtual void force_state()=0
int len
Definition: draw_manager.c:108
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
static unsigned a[3]
Definition: RandGen.cpp:78
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)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
unsigned int uint32_t
Definition: stdint.h:80
unsigned char uint8_t
Definition: stdint.h:78
unsigned __int64 uint64_t
Definition: stdint.h:90