Blender V4.3
gpu_state_private.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
11#include "BLI_utildefines.h"
12
13#include "GPU_state.hh"
14
16
17#include <cstring>
18
19namespace blender {
20namespace gpu {
21
22/* Encapsulate all pipeline state that we need to track.
23 * Try to keep small to reduce validation time. */
24union GPUState {
25 struct {
45 /* TODO(fclem): This should be a shader property. */
47 /* TODO(fclem): remove, old opengl features. */
50 };
51 /* Here to allow fast bit-wise ops. */
53};
54
55BLI_STATIC_ASSERT(sizeof(GPUState) == sizeof(uint64_t), "GPUState is too big.");
56
57inline bool operator==(const GPUState &a, const GPUState &b)
58{
59 return a.data == b.data;
60}
61
62inline bool operator!=(const GPUState &a, const GPUState &b)
63{
64 return !(a == b);
65}
66
67inline GPUState operator^(const GPUState &a, const GPUState &b)
68{
69 GPUState r;
70 r.data = a.data ^ b.data;
71 return r;
72}
73
74inline GPUState operator~(const GPUState &a)
75{
76 GPUState r;
77 r.data = ~a.data;
78 return r;
79}
80
81/* Mutable state that does not require pipeline change. */
83 struct {
84 /* Viewport State */
86 float depth_range[2];
88 /* TODO(fclem): should be passed as uniform to all shaders. */
97 /* IMPORTANT: ensure x64 struct alignment. */
98 };
99 /* Here to allow fast bit-wise ops. */
100 uint64_t data[3];
101};
102
104 "GPUStateMutable is too big.");
105
106inline bool operator==(const GPUStateMutable &a, const GPUStateMutable &b)
107{
108 return memcmp(&a, &b, sizeof(GPUStateMutable)) == 0;
109}
110
111inline bool operator!=(const GPUStateMutable &a, const GPUStateMutable &b)
112{
113 return !(a == b);
114}
115
117{
119 for (int i = 0; i < ARRAY_SIZE(a.data); i++) {
120 r.data[i] = a.data[i] ^ b.data[i];
121 }
122 return r;
123}
124
126{
128 for (int i = 0; i < ARRAY_SIZE(a.data); i++) {
129 r.data[i] = ~a.data[i];
130 }
131 return r;
132}
133
139 public:
142 bool use_bgl = false;
143
144 public:
145 StateManager();
146 virtual ~StateManager(){};
147
148 virtual void apply_state() = 0;
149 virtual void force_state() = 0;
150
151 virtual void issue_barrier(eGPUBarrier barrier_bits) = 0;
152
153 virtual void texture_bind(Texture *tex, GPUSamplerState sampler, int unit) = 0;
154 virtual void texture_unbind(Texture *tex) = 0;
155 virtual void texture_unbind_all() = 0;
156
157 virtual void image_bind(Texture *tex, int unit) = 0;
158 virtual void image_unbind(Texture *tex) = 0;
159 virtual void image_unbind_all() = 0;
160
162};
163
167class Fence {
168 protected:
169 bool signalled_ = false;
170
171 public:
172 Fence(){};
173 virtual ~Fence(){};
174
175 virtual void signal() = 0;
176 virtual void wait() = 0;
177};
178
179/* Syntactic sugar. */
180static inline GPUFence *wrap(Fence *pixbuf)
181{
182 return reinterpret_cast<GPUFence *>(pixbuf);
183}
184static inline Fence *unwrap(GPUFence *pixbuf)
185{
186 return reinterpret_cast<Fence *>(pixbuf);
187}
188static inline const Fence *unwrap(const GPUFence *pixbuf)
189{
190 return reinterpret_cast<const Fence *>(pixbuf);
191}
192
193} // namespace gpu
194} // namespace blender
#define BLI_STATIC_ASSERT(a, msg)
Definition BLI_assert.h:87
unsigned int uint
#define ARRAY_SIZE(arr)
eGPUBarrier
Definition GPU_state.hh:29
struct GPUFence GPUFence
virtual void wait()=0
virtual void signal()=0
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 image_bind(Texture *tex, int unit)=0
virtual void texture_bind(Texture *tex, GPUSamplerState sampler, int unit)=0
virtual void texture_unpack_row_length_set(uint len)=0
virtual void force_state()=0
local_group_size(16, 16) .push_constant(Type local_group_size(16, 16) .push_constant(Type input_tx sampler(1, ImageType::FLOAT_2D, "matte_tx") .image(0
local_group_size(16, 16) .push_constant(Type b
int len
GPUState operator^(const GPUState &a, const GPUState &b)
static Context * unwrap(GPUContext *ctx)
bool operator==(const GPUState &a, const GPUState &b)
static GPUContext * wrap(Context *ctx)
GPUState operator~(const GPUState &a)
bool operator!=(const GPUState &a, const GPUState &b)
unsigned int uint32_t
Definition stdint.h:80
unsigned char uint8_t
Definition stdint.h:78
unsigned __int64 uint64_t
Definition stdint.h:90