Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
ShaderBindings.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 <QLatin1String>
9#include <QStringView>
10
36
37inline constexpr int kUniformBlock = 0;
38inline constexpr int kConsumer = 1;
39inline constexpr int kChannelBase = 2;
40inline constexpr int kChannelCount = kMaxBufferPasses;
41inline constexpr int kAudioSpectrum = kChannelBase + kChannelCount;
42inline constexpr int kUserTextureBase = kAudioSpectrum + 1;
43inline constexpr int kUserTextureCount = 4;
45inline constexpr int kDepth = kWallpaper + 1;
47inline constexpr int kReservedEnd = kDepth;
48inline constexpr int kExtraBase = kReservedEnd + 1;
74inline constexpr int kMaxBinding = 31;
76inline constexpr int kChannelResolutionSlots = 4;
77
78static_assert(kChannelCount == 8,
79 "the overlay and surface shared GLSL headers declare iChannel0..7; grow them with this "
80 "(pointer declares 0..3 for its own smaller cap, and animation declares none)");
81static_assert(kAudioSpectrum == 10 && kUserTextureBase == 11 && kWallpaper == 15 && kDepth == 16,
82 "the shared GLSL headers pin these literal bindings; update every family with this table");
83static_assert(kExtraBase <= kMaxBinding, "the reserved range must leave consumer slots");
84static_assert(kChannelResolutionSlots <= kChannelCount, "the UBO cannot describe channels that do not exist");
85// BOTH ENDS of the table, which the literal pins above leave open. Each of
86// these is a single-token edit away from compiling clean and breaking
87// something silently.
88static_assert(kUniformBlock == 0,
89 "the uniform block is binding 0 in every shared GLSL header and in the validator's own check");
90static_assert(kConsumer == 1 && kConsumer != kChannelBase,
91 "the consumer gap slot is binding 1; colliding it with kChannelBase would make a channel binding "
92 "claimable through setExtraBinding");
93static_assert(kChannelBase > kConsumer, "the channel run must start above the consumer gap slot");
94static_assert(kExtraBase > kDepth, "the consumer range must start strictly above the last library-managed binding");
95
99inline int expectedSamplerBinding(QStringView name)
100{
101 if (name.startsWith(QLatin1String("iChannel")) && name.size() == 9) {
102 const int n = name.at(8).digitValue();
103 return (n >= 0 && n < kChannelCount) ? kChannelBase + n : -1;
104 }
105 if (name.startsWith(QLatin1String("uTexture")) && name.size() == 9) {
106 const int n = name.at(8).digitValue();
107 return (n >= 0 && n < kUserTextureCount) ? kUserTextureBase + n : -1;
108 }
109 if (name == QLatin1String("uCursorSprite")) {
110 return kUserTextureBase;
111 }
112 if (name == QLatin1String("uAudioSpectrum")) {
113 return kAudioSpectrum;
114 }
115 if (name == QLatin1String("uWallpaper") || name == QLatin1String("uBackdrop")) {
116 return kWallpaper;
117 }
118 if (name == QLatin1String("uDepthBuffer")) {
119 return kDepth;
120 }
121 if (name == QLatin1String("uZoneLabels")) {
122 return kConsumer;
123 }
124 return -1;
125}
126
129inline constexpr bool isConsumerBinding(int binding) noexcept
130{
131 return binding == kConsumer || (binding >= kExtraBase && binding <= kMaxBinding);
132}
133
134} // namespace PhosphorShaders::Bindings
The ONE descriptor-binding layout every Qt-RHI shader family speaks (overlay, animation,...
Definition ShaderBindings.h:35
constexpr int kWallpaper
Definition ShaderBindings.h:44
constexpr int kChannelResolutionSlots
How many channel sizes the uniform block carries (iChannelResolution[4]).
Definition ShaderBindings.h:76
constexpr int kMaxBinding
Highest binding a consumer may claim.
Definition ShaderBindings.h:74
constexpr bool isConsumerBinding(int binding) noexcept
Whether binding is one a consumer may claim through setExtraBinding: the single gap slot,...
Definition ShaderBindings.h:129
constexpr int kChannelCount
Definition ShaderBindings.h:40
constexpr int kExtraBase
Definition ShaderBindings.h:48
constexpr int kUserTextureCount
Definition ShaderBindings.h:43
constexpr int kReservedEnd
Last binding the library manages; everything above is a consumer slot.
Definition ShaderBindings.h:47
constexpr int kUserTextureBase
Definition ShaderBindings.h:42
constexpr int kConsumer
Definition ShaderBindings.h:38
constexpr int kDepth
Definition ShaderBindings.h:45
constexpr int kUniformBlock
Definition ShaderBindings.h:37
constexpr int kAudioSpectrum
Definition ShaderBindings.h:41
constexpr int kChannelBase
Definition ShaderBindings.h:39
int expectedSamplerBinding(QStringView name)
The binding a canonical contract sampler must declare, or -1 when name is not a contract sampler (a c...
Definition ShaderBindings.h:99
constexpr int kMaxBufferPasses
Maximum number of multipass buffer passes a pack may declare.
Definition CustomParamsKey.h:68