Blender V5.0
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
8
9#pragma once
10
11#include "BLI_utildefines.h"
12
13#include "GPU_state.hh"
14
16
17#include <cstring>
18
19namespace blender::gpu {
20
21/* Encapsulate all pipeline state that we need to track.
22 * Try to keep small to reduce validation time. */
23union GPUState {
24 struct {
26 uint32_t write_mask : 13;
28 uint32_t blend : 4;
30 uint32_t culling_test : 2;
32 uint32_t depth_test : 3;
34 uint32_t stencil_test : 3;
36 uint32_t stencil_op : 3;
38 uint32_t provoking_vert : 1;
40 uint32_t logic_op_xor : 1;
41 uint32_t invert_facing : 1;
42 uint32_t shadow_bias : 1;
44 uint32_t clip_control : 1;
46 /* TODO(fclem): This should be a shader property. */
47 uint32_t clip_distances : 3;
48 /* TODO(fclem): remove, old opengl features. */
49 uint32_t polygon_smooth : 1;
50 uint32_t line_smooth : 1;
51 };
52 /* Here to allow fast bit-wise ops. */
54};
55
56BLI_STATIC_ASSERT(sizeof(GPUState) == sizeof(uint64_t), "GPUState is too big.");
57
58inline bool operator==(const GPUState &a, const GPUState &b)
59{
60 return a.data == b.data;
61}
62
63inline bool operator!=(const GPUState &a, const GPUState &b)
64{
65 return !(a == b);
66}
67
68inline GPUState operator^(const GPUState &a, const GPUState &b)
69{
70 GPUState r;
71 r.data = a.data ^ b.data;
72 return r;
73}
74
75inline GPUState operator~(const GPUState &a)
76{
77 GPUState r;
78 r.data = ~a.data;
79 return r;
80}
81
82/* Mutable state that does not require pipeline change. */
84 struct {
85 /* Viewport State */
87 float depth_range[2];
89 /* TODO(fclem): should be passed as uniform to all shaders. */
97 uint8_t _pad0[5];
98 /* IMPORTANT: ensure x64 struct alignment. */
99 };
100 /* Here to allow fast bit-wise ops. */
102};
103
105 "GPUStateMutable is too big.");
106
107inline bool operator==(const GPUStateMutable &a, const GPUStateMutable &b)
108{
109 return a.data[0] == b.data[0] && a.data[1] == b.data[1] && a.data[2] == b.data[2];
110}
111
112inline bool operator!=(const GPUStateMutable &a, const GPUStateMutable &b)
113{
114 return !(a == b);
115}
116
118{
120 for (int i = 0; i < ARRAY_SIZE(a.data); i++) {
121 r.data[i] = a.data[i] ^ b.data[i];
122 }
123 return r;
124}
125
127{
129 for (int i = 0; i < ARRAY_SIZE(a.data); i++) {
130 r.data[i] = ~a.data[i];
131 }
132 return r;
133}
134
140 public:
143
144 /* Formats of all image units. */
145 std::array<TextureWriteFormat, GPU_MAX_IMAGE> image_formats;
146
147 StateManager();
148 virtual ~StateManager() = default;
149
150 virtual void apply_state() = 0;
151 virtual void force_state() = 0;
152
153 virtual void issue_barrier(GPUBarrier barrier_bits) = 0;
154
155 virtual void texture_bind(Texture *tex, GPUSamplerState sampler, int unit) = 0;
156 virtual void texture_unbind(Texture *tex) = 0;
157 virtual void texture_unbind_all() = 0;
158
159 virtual void image_bind(Texture *tex, int unit) = 0;
160 virtual void image_unbind(Texture *tex) = 0;
161 virtual void image_unbind_all() = 0;
162
164};
165
169class Fence {
170 protected:
171 bool signalled_ = false;
172
173 public:
174 Fence() = default;
175 virtual ~Fence() = default;
176
177 virtual void signal() = 0;
178 virtual void wait() = 0;
179};
180
181/* Syntactic sugar. */
182static inline GPUFence *wrap(Fence *fence)
183{
184 return reinterpret_cast<GPUFence *>(fence);
185}
186static inline Fence *unwrap(GPUFence *fence)
187{
188 return reinterpret_cast<Fence *>(fence);
189}
190static inline const Fence *unwrap(const GPUFence *fence)
191{
192 return reinterpret_cast<const Fence *>(fence);
193}
194
195} // namespace blender::gpu
#define BLI_STATIC_ASSERT(a, msg)
Definition BLI_assert.h:83
unsigned int uint
#define ARRAY_SIZE(arr)
GPUBarrier
Definition GPU_state.hh:29
unsigned long long int uint64_t
virtual void wait()=0
virtual ~Fence()=default
virtual void signal()=0
virtual void issue_barrier(GPUBarrier barrier_bits)=0
virtual void texture_unbind_all()=0
virtual void apply_state()=0
std::array< TextureWriteFormat, GPU_MAX_IMAGE > image_formats
virtual void texture_unbind(Texture *tex)=0
virtual void image_unbind_all()=0
virtual void image_unbind(Texture *tex)=0
virtual ~StateManager()=default
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
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)
i
Definition text_draw.cc:230
uint len