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 // Match push()'s defensive style: assert the caller stays within the
55 // populated range. Callers iterate [0, size()) via begin()/end(), so a
56 // stray index is a programming error.
57 Q_ASSERT(i >= 0 && i < m_count);
58 return m_regions[static_cast<size_t>(i)];
59 }
60 const UboUploadRegion* begin() const
61 {
62 return m_regions.data();
63 }
64 const UboUploadRegion* end() const
65 {
66 return m_regions.data() + m_count;
67 }
68
69private:
70 std::array<UboUploadRegion, kCapacity> m_regions{};
71 int m_count = 0;
72};
73
84{
85 bool time = false;
86 bool timeHi = false;
87 bool sceneData = false;
88 bool appFields = false;
89};
90
98{
99 // ── Timing (overlay/animation) ─────────────────────────────────────
101 float time = 0.0f;
103 float timeHi = 0.0f;
104 float timeDelta = 0.0f;
105 int frame = 0;
106
107 // ── Feedback-buffer state (drives iFrame override) ─────────────────
108 bool bufferFeedback = false;
110
111 // ── Resolution ─────────────────────────────────────────────────────
112 float width = 0.0f;
113 float height = 0.0f;
114
115 // ── Mouse ──────────────────────────────────────────────────────────
116 float mouseX = 0.0f;
117 float mouseY = 0.0f;
118
119 // ── Direction signal ───────────────────────────────────────────────
120 bool isReversed = false;
121
122 // ── iDate throttle gating ──────────────────────────────────────────
125 bool didFullUploadOnce = false;
126 bool sceneDataDirty = false;
127
128 // ── Custom parameters / colors ─────────────────────────────────────
129 float customParams[8][4] = {};
130 float customColors[16][4] = {};
131
132 // ── Resolved channel / texture sizes (node resolves live) ──────────
134 float channelResolution[4][2] = {};
136 float textureResolution[4][2] = {};
137
138 // ── Audio ──────────────────────────────────────────────────────────
140
141 // ── NDC Y orientation (per render target) ──────────────────────────
148 bool yUpInNDC = false;
149
150 // ── Surface-only fields (BaseUniformProfile ignores these) ─────────
152 float qtOpacity = 1.0f;
154 float surfaceScale = 1.0f;
156 float surfaceFocused = 0.0f;
165 float hasBackdrop = 0.0f;
167 float surfaceSize[2] = {};
169 float surfaceFrameTopLeft[2] = {};
171 float surfaceFrameSize[2] = {};
180 float backdropRect[4] = {0.0f, 0.0f, 1.0f, 1.0f};
181};
182
195class PHOSPHORSHADERS_EXPORT IUboProfile
196{
197public:
198 virtual ~IUboProfile() = default;
199
202 virtual int baseSize() const = 0;
203
205 virtual const void* data() const = 0;
208 virtual void* mutableData() = 0;
209
212 virtual void fill(const UboFrameState& state) = 0;
213
216 {
217 UboUploadRegionList regions;
218 regions.push(UboUploadRegion{0, baseSize()});
219 return regions;
220 }
221
225 virtual UboUploadRegionList dirtyRegions(const UboDirtyFlags& flags) const = 0;
226
228 virtual bool hasAppFields() const
229 {
230 return false;
231 }
233 virtual void setAppField0(int /*value*/)
234 {
235 }
236 virtual void setAppField1(int /*value*/)
237 {
238 }
239};
240
241} // namespace PhosphorShaders
Pluggable UBO concern for the shared shader render engine.
Definition IUboProfile.h:196
virtual bool hasAppFields() const
Whether this profile exposes the two consumer escape-hatch int slots.
Definition IUboProfile.h:228
virtual void setAppField1(int)
Definition IUboProfile.h:236
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:215
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:233
virtual void * mutableData()=0
Mutable view — used by the node's multipass qt_Matrix pin/restore, which writes the leading mat4 dire...
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:60
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:64
int size() const
Definition IUboProfile.h:44
Definition ShaderEffect.h:33
Which conceptual blocks of the UBO changed since the last upload.
Definition IUboProfile.h:84
bool timeHi
Definition IUboProfile.h:86
bool appFields
Definition IUboProfile.h:88
bool sceneData
Definition IUboProfile.h:87
bool time
Definition IUboProfile.h:85
Snapshot of every node-side value a UBO profile's fill() may read for a single frame.
Definition IUboProfile.h:98
bool isReversed
Definition IUboProfile.h:120
int frame
Definition IUboProfile.h:105
float customColors[16][4]
Definition IUboProfile.h:130
float mouseY
Definition IUboProfile.h:117
float width
Definition IUboProfile.h:112
float surfaceScale
Logical→device pixel scale for the decorated surface.
Definition IUboProfile.h:154
float surfaceFrameTopLeft[2]
Frame top-left in device px.
Definition IUboProfile.h:169
float surfaceFocused
1.0 when the surface is focused, 0.0 otherwise.
Definition IUboProfile.h:156
float channelResolution[4][2]
iChannelResolution[i].xy — multipass buffer-channel output sizes.
Definition IUboProfile.h:134
float customParams[8][4]
Definition IUboProfile.h:129
float hasBackdrop
1.0 when a backdrop texture (the scene / wallpaper BEHIND the surface) is actually bound for this dra...
Definition IUboProfile.h:165
float timeDelta
Definition IUboProfile.h:104
float surfaceFrameSize[2]
Frame size in device px.
Definition IUboProfile.h:171
bool bufferFeedback
Definition IUboProfile.h:108
bool bufferFeedbackCleared
Definition IUboProfile.h:109
bool sceneDataDirty
Definition IUboProfile.h:126
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:148
float backdropRect[4]
The slice of the bound backdrop this surface samples, in normalized texture coords (xy = min,...
Definition IUboProfile.h:180
float textureResolution[4][2]
iTextureResolution[i].xy — user-texture slot sizes.
Definition IUboProfile.h:136
float mouseX
Definition IUboProfile.h:116
float timeHi
Wrap-offset high part.
Definition IUboProfile.h:103
float surfaceSize[2]
Decorated surface size in device px.
Definition IUboProfile.h:167
float qtOpacity
Per-surface opacity from the Qt scene graph.
Definition IUboProfile.h:152
bool didFullUploadOnce
Whether the first full upload has happened.
Definition IUboProfile.h:125
float time
Wrapped low part of elapsed seconds (m_time - m_timeHi).
Definition IUboProfile.h:101
int audioSpectrumSize
Definition IUboProfile.h:139
float height
Definition IUboProfile.h:113
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