Blender V5.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
8
9#pragma once
10
11#include "BLI_utildefines.hh"
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 {
28 uint32_t blend : 4;
40
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 /* TODO(fclem): should be passed as uniform to all shaders. */
87 float point_size;
89 float line_width;
94 uint8_t _pad0[5];
95 /* IMPORTANT: ensure x64 struct alignment. */
96 };
97 /* Here to allow fast bit-wise ops. */
99};
100
102 "GPUStateMutable is too big.");
103
104inline bool operator==(const GPUStateMutable &a, const GPUStateMutable &b)
105{
106 return a.data[0] == b.data[0] && a.data[1] == b.data[1];
107}
108
109inline bool operator!=(const GPUStateMutable &a, const GPUStateMutable &b)
110{
111 return !(a == b);
112}
113
115{
117 for (int i = 0; i < ARRAY_SIZE(a.data); i++) {
118 r.data[i] = a.data[i] ^ b.data[i];
119 }
120 return r;
121}
122
124{
126 for (int i = 0; i < ARRAY_SIZE(a.data); i++) {
127 r.data[i] = ~a.data[i];
128 }
129 return r;
130}
131
137 public:
140
141 /* Formats of all image units. */
142 std::array<TextureWriteFormat, GPU_MAX_IMAGE> image_formats;
143
144 StateManager();
145 virtual ~StateManager() = default;
146
147 virtual void apply_state() = 0;
148 virtual void force_state() = 0;
149
150 virtual void issue_barrier(GPUBarrier barrier_bits) = 0;
151
152 virtual void texture_bind(Texture *tex, GPUSamplerState 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};
160
164class Fence {
165 protected:
166 bool signalled_ = false;
167
168 public:
169 Fence() = default;
170 virtual ~Fence() = default;
171
172 virtual void signal() = 0;
173 virtual void wait() = 0;
174};
175
176/* Syntactic sugar. */
177static inline GPUFence *wrap(Fence *fence)
178{
179 return reinterpret_cast<GPUFence *>(fence);
180}
181static inline Fence *unwrap(GPUFence *fence)
182{
183 return reinterpret_cast<Fence *>(fence);
184}
185static inline const Fence *unwrap(const GPUFence *fence)
186{
187 return reinterpret_cast<const Fence *>(fence);
188}
189
190} // namespace blender::gpu
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 force_state()=0
#define sampler(slot)
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)
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 __int64 uint64_t
Definition BKE_text.h:91
unsigned int uint32_t
Definition BKE_text.h:81
unsigned char uint8_t
Definition BKE_text.h:79
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept