Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
IUboProfile.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorShaders/phosphorshaders_export.h>
7
8#include <QtGlobal>
9
10#include <array>
11#include <cstddef>
12
13namespace PhosphorShaders {
14
19{
20 int offset = 0;
21 int size = 0;
22};
23
29{
30public:
31 static constexpr int kCapacity = 4;
32
33 void push(const UboUploadRegion& region)
34 {
35 // Debug-assert AND release-guard the same bound: a profile emitting
36 // more than kCapacity regions is a programming error, and silently
37 // dropping the overflow (worst case: one region skipped this frame)
38 // beats writing out of bounds.
39 Q_ASSERT(m_count < kCapacity);
40 if (m_count < kCapacity) {
41 m_regions[static_cast<size_t>(m_count++)] = region;
42 }
43 }
44 int size() const
45 {
46 return m_count;
47 }
48 bool empty() const
49 {
50 return m_count == 0;
51 }
52 const UboUploadRegion& operator[](int i) const
53 {
54 // Debug-assert AND release-guard the same bound, which is what
55 // "match push()'s defensive style" was supposed to mean: the assert
56 // alone compiles out under NDEBUG and left an out-of-bounds read on
57 // the std::array. Production consumers iterate via begin()/end(); the
58 // indexed form is used by the profile tests.
59 Q_ASSERT(i >= 0 && i < m_count);
60 if (i < 0 || i >= m_count) {
61 static const UboUploadRegion empty{};
62 return empty;
63 }
64 return m_regions[static_cast<size_t>(i)];
65 }
66 const UboUploadRegion* begin() const
67 {
68 return m_regions.data();
69 }
70 const UboUploadRegion* end() const
71 {
72 return m_regions.data() + m_count;
73 }
74
75private:
76 std::array<UboUploadRegion, kCapacity> m_regions{};
77 int m_count = 0;
78};
79
90{
91 bool time = false;
92 bool timeHi = false;
93 bool sceneData = false;
94 bool appFields = false;
95};
96
104{
105 // ── Timing (overlay/animation) ─────────────────────────────────────
107 float time = 0.0f;
109 float timeHi = 0.0f;
110 float timeDelta = 0.0f;
111 int frame = 0;
112
113 // ── Feedback-buffer state (drives iFrame override) ─────────────────
114 bool bufferFeedback = false;
116
117 // ── Resolution ─────────────────────────────────────────────────────
118 float width = 0.0f;
119 float height = 0.0f;
120
121 // ── Mouse ──────────────────────────────────────────────────────────
122 float mouseX = 0.0f;
123 float mouseY = 0.0f;
124
125 // ── Direction signal ───────────────────────────────────────────────
126 bool isReversed = false;
127
128 // ── iDate throttle gating ──────────────────────────────────────────
131 bool didFullUploadOnce = false;
132 bool sceneDataDirty = false;
133
134 // ── Custom parameters / colors ─────────────────────────────────────
135 float customParams[8][4] = {};
136 float customColors[16][4] = {};
137
138 // ── Resolved channel / texture sizes (node resolves live) ──────────
140 float channelResolution[4][2] = {};
142 float textureResolution[4][2] = {};
143
144 // ── Audio ──────────────────────────────────────────────────────────
146
147 // ── NDC Y orientation (per render target) ──────────────────────────
154 bool yUpInNDC = false;
155
156 // ── Surface-only fields (BaseUniformProfile ignores these) ─────────
158 float qtOpacity = 1.0f;
160 float surfaceScale = 1.0f;
162 float surfaceFocused = 0.0f;
171 float hasBackdrop = 0.0f;
173 float surfaceSize[2] = {};
175 float surfaceFrameTopLeft[2] = {};
177 float surfaceFrameSize[2] = {};
186 float backdropRect[4] = {0.0f, 0.0f, 1.0f, 1.0f};
187};
188
201class PHOSPHORSHADERS_EXPORT IUboProfile
202{
203public:
204 virtual ~IUboProfile() = default;
205
208 virtual int baseSize() const = 0;
209
211 virtual const void* data() const = 0;
214 virtual void* mutableData() = 0;
215
218 virtual void fill(const UboFrameState& state) = 0;
219
222 {
223 UboUploadRegionList regions;
224 regions.push(UboUploadRegion{0, baseSize()});
225 return regions;
226 }
227
231 virtual UboUploadRegionList dirtyRegions(const UboDirtyFlags& flags) const = 0;
232
234 virtual bool hasAppFields() const
235 {
236 return false;
237 }
238
239 virtual void setAppField0(int /*value*/)
240 {
241 }
242 virtual void setAppField1(int /*value*/)
243 {
244 }
245
262 {
263 return false;
264 }
265
273 virtual bool readsQtOpacity() const
274 {
275 return false;
276 }
277};
278
279} // namespace PhosphorShaders
Pluggable UBO concern for the shared shader render engine.
Definition IUboProfile.h:202
virtual bool hasAppFields() const
Whether this profile exposes the two consumer escape-hatch int slots.
Definition IUboProfile.h:234
virtual void setAppField1(int)
Definition IUboProfile.h:242
virtual void fill(const UboFrameState &state)=0
Populate the UBO from a per-frame node snapshot.
virtual const void * data() const =0
Read-only view of the filled UBO bytes (for updateDynamicBuffer).
virtual UboUploadRegionList fullUploadRegions() const
Region(s) covering the whole base struct, for the first (full) upload.
Definition IUboProfile.h:221
virtual UboUploadRegionList dirtyRegions(const UboDirtyFlags &flags) const =0
Region(s) to upload for the given dirty flags, reproducing the legacy broader-subsumes-narrower dispa...
virtual int baseSize() const =0
Byte size of the base UBO region (sizeof the concrete struct).
virtual ~IUboProfile()=default
virtual void setAppField0(int)
Write the consumer's escape-hatch int slots. No-op by default.
Definition IUboProfile.h:239
virtual bool consumeSelfRefreshedSceneHeader()
Whether the last fill() wrote a field the caller's own dirty flags do not know about,...
Definition IUboProfile.h:261
virtual void * mutableData()=0
Mutable view — used by the node's multipass qt_Matrix pin/restore, which writes the leading mat4 dire...
virtual bool readsQtOpacity() const
Whether fill() writes UboFrameState::qtOpacity into the buffer.
Definition IUboProfile.h:273
Fixed-capacity list of upload regions.
Definition IUboProfile.h:29
static constexpr int kCapacity
Definition IUboProfile.h:31
const UboUploadRegion * begin() const
Definition IUboProfile.h:66
const UboUploadRegion & operator[](int i) const
Definition IUboProfile.h:52
void push(const UboUploadRegion &region)
Definition IUboProfile.h:33
bool empty() const
Definition IUboProfile.h:48
const UboUploadRegion * end() const
Definition IUboProfile.h:70
int size() const
Definition IUboProfile.h:44
Definition ShaderProfile.h:21
Which conceptual blocks of the UBO changed since the last upload.
Definition IUboProfile.h:90
bool timeHi
Definition IUboProfile.h:92
bool appFields
Definition IUboProfile.h:94
bool sceneData
Definition IUboProfile.h:93
bool time
Definition IUboProfile.h:91
Snapshot of every node-side value a UBO profile's fill() may read for a single frame.
Definition IUboProfile.h:104
bool isReversed
Definition IUboProfile.h:126
int frame
Definition IUboProfile.h:111
float customColors[16][4]
Definition IUboProfile.h:136
float mouseY
Definition IUboProfile.h:123
float width
Definition IUboProfile.h:118
float surfaceScale
Logical→device pixel scale for the decorated surface.
Definition IUboProfile.h:160
float surfaceFrameTopLeft[2]
Frame top-left in device px.
Definition IUboProfile.h:175
float surfaceFocused
1.0 when the surface is focused, 0.0 otherwise.
Definition IUboProfile.h:162
float channelResolution[4][2]
iChannelResolution[i].xy — multipass buffer-channel output sizes.
Definition IUboProfile.h:140
float customParams[8][4]
Definition IUboProfile.h:135
float hasBackdrop
1.0 when a backdrop texture (the scene / wallpaper BEHIND the surface) is actually bound for this dra...
Definition IUboProfile.h:171
float timeDelta
Definition IUboProfile.h:110
float surfaceFrameSize[2]
Frame size in device px.
Definition IUboProfile.h:177
bool bufferFeedback
Definition IUboProfile.h:114
bool bufferFeedbackCleared
Definition IUboProfile.h:115
bool sceneDataDirty
Definition IUboProfile.h:132
bool yUpInNDC
True when this draw should carry the NDC Y-flip: a Y-up-in-NDC backend (OpenGL, rhi->isYUpInNDC()) AN...
Definition IUboProfile.h:154
float backdropRect[4]
The slice of the bound backdrop this surface samples, in normalized texture coords (xy = min,...
Definition IUboProfile.h:186
float textureResolution[4][2]
iTextureResolution[i].xy — user-texture slot sizes.
Definition IUboProfile.h:142
float mouseX
Definition IUboProfile.h:122
float timeHi
Wrap-offset high part.
Definition IUboProfile.h:109
float surfaceSize[2]
Decorated surface size in device px.
Definition IUboProfile.h:173
float qtOpacity
Per-surface opacity from the Qt scene graph.
Definition IUboProfile.h:158
bool didFullUploadOnce
Whether the first full upload has happened.
Definition IUboProfile.h:131
float time
Wrapped low part of elapsed seconds (m_time - m_timeHi).
Definition IUboProfile.h:107
int audioSpectrumSize
Definition IUboProfile.h:145
float height
Definition IUboProfile.h:119
A contiguous byte range inside the UBO to (re)upload via QRhiResourceUpdateBatch::updateDynamicBuffer...
Definition IUboProfile.h:19
int offset
Definition IUboProfile.h:20
int size
Definition IUboProfile.h:21