Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
SurfaceShaderUniforms.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
7
8#include <cstddef>
9
10namespace PhosphorSurfaceShaders {
11
38struct alignas(16) SurfaceUniforms
39{
40 // Transform + opacity from the Qt scene graph (same lead as BaseUniforms).
41 float qt_Matrix[16]; // mat4: 64 bytes at offset 0
42 float qt_Opacity; // float: 4 bytes at offset 64
43
44 // Host-provided surface state.
45 float uSurfaceScale; // float: 4 bytes at offset 68 (logical→device px)
46 float uSurfaceFocused; // float: 4 bytes at offset 72 (1.0 focused / 0.0 not)
47 float iTime; // float: 4 bytes at offset 76 (continuous seconds; animated packs)
48
49 // Surface geometry, device px (see surface_uniforms.glsl for semantics).
50 float uSurfaceSize[2]; // vec2: 8 bytes at offset 80
51 float uSurfaceFrameTopLeft[2]; // vec2: 8 bytes at offset 88
52 float uSurfaceFrameSize[2]; // vec2: 8 bytes at offset 96
53
54 // 1.0 when the host bound something behind the surface: the captured scene
55 // on the compositor, or the desktop wallpaper as a stand-in on a daemon or
56 // preview host. 0.0 when nothing was bound. needsBackdrop packs gate their
57 // styling on this rather than on which runtime they are on.
58 float uHasBackdrop; // float: 4 bytes at offset 104 (1 when the host bound a backdrop, else 0)
59
60 // Legacy: a constant 1.0 on BOTH runtimes, kept so the layout and the
61 // pack-facing name survive. It no longer carries the window's
62 // rule-resolved opacity — that was the retired handlesOpacity contract —
63 // and a host fading a whole decoration does it through qt_Opacity. See
64 // kUSurfaceOpacity in SurfaceShaderContract.h.
65 float uSurfaceOpacity; // float: 4 bytes at offset 108 (constant 1.0)
66
67 // Pack-declared parameters (float/int/bool → customParams, colours →
68 // customColors), addressed by the registry-generated `p_<id>` preambles.
69 float customParams[8][4]; // vec4[8]: 128 bytes at offset 112
70 float customColors[16][4]; // vec4[16]: 256 bytes at offset 240
71
72 // Multipass: iChannelResolution[i] = buffer-pass output texture size (.xy).
73 //
74 // The FIRST FOUR channels only, while the pass budget is eight. Widening
75 // this would move every offset below it and break the 672-byte layout the
76 // GLSL branch pins, so a pass reading iChannel4..7 sizes it with
77 // textureSize() instead. The static_assert below ties the count to
78 // Bindings::kChannelResolutionSlots, which the offset asserts cannot: they
79 // catch a resize of THIS member and not the reverse drift, the constant
80 // being bumped while this mirror and surface_uniforms.glsl stay at four.
81 float iChannelResolution[4][4]; // vec4[4]: 64 bytes at offset 496
82
83 // Audio spectrum bar count (0 when audio is disabled). This UBO is the
84 // DAEMON's layout: the daemon writes this member for every surface item when
85 // CAVA is on. The KWin effect uses no UBO and pushes the same value as a
86 // loose `iAudioSpectrumSize` uniform from its own CAVA provider. The
87 // uAudioSpectrum sampler (binding 10) lives in surface_audio.glsl, not the
88 // UBO; only the size is a UBO member. A pack reads it via surface_audio.glsl
89 // (audioBar / getBass).
90 int iAudioSpectrumSize; // int: 4 bytes at offset 560
91 int _pad_after_audioSpectrum[3]; // std140 pads to the 16-byte-aligned vec4 below
92
93 // Cursor position for hover-reactive packs. .xy in the surface texture's
94 // top-down device-px space (negative when off-surface / no hover source),
95 // .zw = .xy normalized by uSurfaceSize. The daemon consumer defaults its
96 // inherited iMouse to (-1, -1) so an un-hovered surface carries the
97 // off-surface sentinel rather than a phantom top-left hover.
98 float iMouse[4]; // vec4: 16 bytes at offset 576
99
100 // User texture sizes: iTextureResolution[i].xy = the pixel size of
101 // uTexture<i>, bindings 11-14. Index 0 is the surface's own content, so a
102 // pack's metadata slot N, which feeds uTexture<N+1>, has its size at index
103 // N+1. The node resolves these live, same as the overlay UBO.
104 float iTextureResolution[4][4]; // vec4[4]: 64 bytes at offset 592
105
106 // The sub-rect of the bound backdrop this surface samples, in normalized
107 // texture coords (xy = min, zw = size). (0, 0, 1, 1) is the whole texture.
108 //
109 // The compositor captures its backdrop over the window's own canvas, so its
110 // branch needs no such mapping (it has its own uBackdropRect for a
111 // different job: clamping to the VALID part of the capture). A daemon or
112 // preview host instead binds one big shared image — the desktop wallpaper —
113 // for every surface, so each one has to be told which part of it lies
114 // behind it. Without that, every surface samples the whole desktop squeezed
115 // into its own box.
116 //
117 // APPENDED deliberately: every member above keeps its offset, so the pinned
118 // static_asserts and the GLSL block's stated offsets are all still true.
119 float uBackdropRect[4]; // vec4: 16 bytes at offset 656
120}; // total 672 bytes
121
122static_assert(sizeof(SurfaceUniforms) == 672, "SurfaceUniforms must be exactly 672 bytes (surface UBO contract)");
123
124static_assert(offsetof(SurfaceUniforms, qt_Matrix) == 0, "SurfaceUniforms::qt_Matrix must remain at std140 offset 0");
125static_assert(offsetof(SurfaceUniforms, qt_Opacity) == 64,
126 "SurfaceUniforms::qt_Opacity must remain at std140 offset 64");
127static_assert(offsetof(SurfaceUniforms, uSurfaceScale) == 68,
128 "SurfaceUniforms::uSurfaceScale must remain at std140 offset 68");
129static_assert(offsetof(SurfaceUniforms, uSurfaceFocused) == 72,
130 "SurfaceUniforms::uSurfaceFocused must remain at std140 offset 72");
131static_assert(offsetof(SurfaceUniforms, iTime) == 76, "SurfaceUniforms::iTime must remain at std140 offset 76");
132static_assert(offsetof(SurfaceUniforms, uSurfaceSize) == 80,
133 "SurfaceUniforms::uSurfaceSize must remain at std140 offset 80");
134static_assert(offsetof(SurfaceUniforms, uSurfaceFrameTopLeft) == 88,
135 "SurfaceUniforms::uSurfaceFrameTopLeft must remain at std140 offset 88");
136static_assert(offsetof(SurfaceUniforms, uSurfaceFrameSize) == 96,
137 "SurfaceUniforms::uSurfaceFrameSize must remain at std140 offset 96");
138static_assert(offsetof(SurfaceUniforms, uHasBackdrop) == 104,
139 "SurfaceUniforms::uHasBackdrop must remain at std140 offset 104");
140static_assert(offsetof(SurfaceUniforms, uSurfaceOpacity) == 108,
141 "SurfaceUniforms::uSurfaceOpacity must remain at std140 offset 108");
142static_assert(offsetof(SurfaceUniforms, customParams) == 112,
143 "SurfaceUniforms::customParams must remain at std140 offset 112");
144static_assert(offsetof(SurfaceUniforms, customColors) == 240,
145 "SurfaceUniforms::customColors must remain at std140 offset 240");
146static_assert(offsetof(SurfaceUniforms, iChannelResolution) == 496,
147 "SurfaceUniforms::iChannelResolution must remain at std140 offset 496");
148static_assert(offsetof(SurfaceUniforms, iAudioSpectrumSize) == 560,
149 "SurfaceUniforms::iAudioSpectrumSize must remain at std140 offset 560");
150static_assert(offsetof(SurfaceUniforms, iMouse) == 576, "SurfaceUniforms::iMouse must remain at std140 offset 576");
151static_assert(offsetof(SurfaceUniforms, iTextureResolution) == 592,
152 "SurfaceUniforms::iTextureResolution must remain at std140 offset 592");
153static_assert(offsetof(SurfaceUniforms, uBackdropRect) == 656,
154 "SurfaceUniforms::uBackdropRect must remain at std140 offset 656");
155
156// The offset asserts above catch a resize of iChannelResolution. This catches
157// the drift in the other direction: the shared constant being raised while this
158// mirror and data/surface/shared/surface_uniforms.glsl stay at four, which is
159// the direction the channel work moves in. Raising the constant means moving
160// every offset below this member, so it has to be a deliberate edit here.
162 == static_cast<std::size_t>(PhosphorShaders::Bindings::kChannelResolutionSlots),
163 "SurfaceUniforms::iChannelResolution must carry Bindings::kChannelResolutionSlots elements; "
164 "growing the constant means relaying this struct and the GLSL branch it mirrors");
165
166} // namespace PhosphorSurfaceShaders
constexpr int kChannelResolutionSlots
How many channel sizes the uniform block carries (iChannelResolution[4]).
Definition ShaderBindings.h:76
Definition DecorationProfile.h:31
C++ mirror of the SURFACE shader contract's daemon UBO block — the #else (non-PLASMAZONES_KWIN) branc...
Definition SurfaceShaderUniforms.h:39
float uSurfaceScale
Definition SurfaceShaderUniforms.h:45
float uSurfaceOpacity
Definition SurfaceShaderUniforms.h:65
float qt_Opacity
Definition SurfaceShaderUniforms.h:42
float iMouse[4]
Definition SurfaceShaderUniforms.h:98
float uHasBackdrop
Definition SurfaceShaderUniforms.h:58
float customColors[16][4]
Definition SurfaceShaderUniforms.h:70
float uBackdropRect[4]
Definition SurfaceShaderUniforms.h:119
float iTime
Definition SurfaceShaderUniforms.h:47
float qt_Matrix[16]
Definition SurfaceShaderUniforms.h:41
float iTextureResolution[4][4]
Definition SurfaceShaderUniforms.h:104
int iAudioSpectrumSize
Definition SurfaceShaderUniforms.h:90
float customParams[8][4]
Definition SurfaceShaderUniforms.h:69
float uSurfaceSize[2]
Definition SurfaceShaderUniforms.h:50
int _pad_after_audioSpectrum[3]
Definition SurfaceShaderUniforms.h:91
float uSurfaceFrameTopLeft[2]
Definition SurfaceShaderUniforms.h:51
float iChannelResolution[4][4]
Definition SurfaceShaderUniforms.h:81
float uSurfaceFocused
Definition SurfaceShaderUniforms.h:46
float uSurfaceFrameSize[2]
Definition SurfaceShaderUniforms.h:52