KiCad PCB EDA Suite
Loading...
Searching...
No Matches
frame_packet.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef RHI_FRAME_PACKET_H
21#define RHI_FRAME_PACKET_H
22
23#include <rhi/rhi_handle.h>
24#include <gal/definitions.h>
25
26#include <algorithm>
27#include <array>
28#include <cstddef>
29#include <cstdint>
30#include <memory>
31#include <vector>
32
33
34namespace KIGFX
35{
36
37enum class RHI_LINE_PIPELINE_KIND : uint8_t
38{
41};
42
54
56constexpr int RHI_SHAPES = RHI_SHAPE_POLYGON + 1;
57
61using RHI_SHAPE_COUNTS = std::array<uint32_t, RHI_SHAPES>;
62
66struct alignas( 16 ) GRID_UBO_DATA
67{
68 float invProjection[16] = {};
69 float viewport[2] = {};
70 float gridOrigin[2] = {};
71 float gridSpacing[2] = {};
72 float gridAngle = 0.0f;
73 int gridStyle = 0;
74 float gridColor[4] = {};
75 float axisColorX[4] = {};
76 float axisColorY[4] = {};
77 float minorLineWidth = 1.0f;
78 float majorLineWorld = 2.0f;
79 int gridTick = 10;
80 float renderScale = 1.0f;
81 float worldPixelSize = 1.0f;
82 float _pad0[3] = {};
83
84 bool operator==( const GRID_UBO_DATA& aOther ) const = default;
85};
86
87
91struct alignas( 16 ) CURSOR_UBO_DATA
92{
93 float cursorPos[2] = {};
94 float viewport[2] = {};
95 float crosshairColor[4] = {};
96 float snapColor[4] = {};
97 float crosshairWidth = 1.0f;
98 float snapRadius = 5.0f;
99 int showSnap = 0;
100 int cursorType = 1;
101 float cursorSize = 80.0f;
102 float _pad0[3] = {};
103};
104
105
109struct alignas( 16 ) FRAME_UBO_DATA
110{
111 float projection[16] = {};
112 float viewport[2] = {};
113 float viewScale = 0.0f;
114 float renderScale = 1.0f;
115
116 bool operator==( const FRAME_UBO_DATA& aOther ) const = default;
117};
118
119
129
130
138{
139 bool negative = false;
142
143 bool Empty() const
144 {
145 return std::ranges::all_of( count, []( uint32_t aCount ) { return aCount == 0; } );
146 }
147};
148
149
155{
156 float toward[3] = { 0.0f, 0.0f, 0.0f };
157 float keep = 1.0f;
158
159 bool operator==( const RHI_LAYER_DIM& aOther ) const = default;
160};
161
162static_assert( sizeof( RHI_LAYER_DIM ) == 16, "RHI_LAYER_DIM is one vec4 of push constants" );
163
164
165struct RHI_RUN_TABLE;
166
167
172{
173 float depth = 0.0f;
174
179 float alpha = 1.0f;
180
184 bool hasNegatives = false;
185
190
198
199 uint32_t bitmapStart = 0;
200 uint32_t bitmapCount = 0;
201
205 std::array<RHI_BufferHandle, RHI_SHAPES> buffer;
206 std::array<RHI_BufferHandle, RHI_SHAPES> negBuffer;
207
212 float depthNear = 0.0f;
213 float depthFar = 1.0f;
214
219 bool singleCoverage = false;
220 bool depthKnockout = false;
221
225 bool overlayAlpha = false;
226
231 bool difference = false;
232
234
238 uint32_t runStart = 0;
239 uint32_t runCount = 0;
240
244 std::shared_ptr<const RHI_RUN_TABLE> cullRuns;
245
246 bool NeedsTempFBO() const { return alpha < 1.0f || ( hasNegatives && !depthKnockout ) || difference; }
247
248 bool HasGeometry() const
249 {
250 for( int shape = 0; shape < RHI_SHAPES; ++shape )
251 {
252 if( count[shape] > 0 || negCount[shape] > 0 )
253 return true;
254 }
255
256 return bitmapCount > 0;
257 }
258};
259
260
266{
268
272 std::array<RHI_BufferHandle, RHI_SHAPES> buffer;
275
276 std::vector<BITMAP_DRAW_DESC> bitmapDraws;
277 std::vector<LAYER_RANGE> layerRanges;
278 std::vector<POLARITY_RUN> polarityRuns;
279
280 bool drawGrid = false;
281 bool drawCursor = false;
282 bool reuseStaticFBO = false;
283 bool reuseDynamicFBO = false;
284
288 bool gridFirst = false;
289
294 bool relativeDepth = false;
295
300 bool testAgainstStatic = false;
301
305 static constexpr float RELATIVE_DEPTH_RANGE = 16.0f;
306
311 uint32_t supersampleFactor = 1;
312
316 uint64_t bufferGeneration = 0;
317
318 float backgroundColor[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
319
323
324 bool HasGeometry() const
325 {
326 return std::ranges::any_of( count, []( uint32_t aCount ) { return aCount > 0; } ) || !bitmapDraws.empty();
327 }
328};
329
330
364
365
366} // namespace KIGFX
367
368
369#endif // RHI_FRAME_PACKET_H
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
RHI_LINE_PIPELINE_KIND
RHI_SHAPE
Shapes a frame draws, each with its own array and pipelines.
@ RHI_SHAPE_POLYGON
@ RHI_SHAPE_TRACK
@ RHI_SHAPE_PAD
@ RHI_SHAPE_ARC
RENDER_TARGET
RENDER_TARGET: Possible rendering targets.
Definition definitions.h:32
@ TARGET_CACHED
Main rendering target (cached)
Definition definitions.h:33
std::array< uint32_t, RHI_SHAPES > RHI_SHAPE_COUNTS
Elements of each shape, indexed by RHI_SHAPE.
constexpr int RHI_INSTANCED_SHAPES
constexpr int RHI_SHAPES
RHI_HANDLE< RHI_TAG_TEXTURE > RHI_TextureHandle
Definition rhi_handle.h:84
RHI_HANDLE< RHI_TAG_BUFFER > RHI_BufferHandle
Definition rhi_handle.h:83
One textured bitmap quad with its own vertex buffer and texture.
RHI_TextureHandle texture
RHI_BufferHandle vertexBuffer
Cursor uniform block matching the CursorUBO layout in cursor.frag (std140).
float cursorPos[2]
NDC [-1, 1].
float cursorSize
small cross extent in pixels
int cursorType
0 = small cross, 1 = fullscreen, 2 = diagonal 45°
GPU geometry of one frame, built by GAL_MODERN after EndDrawing() and passed through the FRAME_MAILBO...
RHI_LINE_PIPELINE_KIND linePipelineKind
RHI_SHAPE_COUNTS negCount
FRAME_UBO_DATA frameUBO
bool gridFirst
Draw the grid before the layers instead of over them.
bool relativeDepth
Element depth is relative to its layer's slice in LAYER_RANGE::depthNear, and the projection scales d...
RHI_SHAPE_COUNTS count
uint64_t bufferGeneration
Generation of the producer's buffers this descriptor was built from.
bool testAgainstStatic
Slices share the static target's layer order mapping, so this target can be depth tested against a co...
std::vector< LAYER_RANGE > layerRanges
uint32_t supersampleFactor
Layer FBO scale that the present blit downsamples.
std::vector< POLARITY_RUN > polarityRuns
static constexpr float RELATIVE_DEPTH_RANGE
Largest depth offset an element can have from its layer when relativeDepth is set.
CURSOR_UBO_DATA cursorUBO
std::vector< BITMAP_DRAW_DESC > bitmapDraws
std::array< RHI_BufferHandle, RHI_SHAPES > buffer
Each shape's buffer, normal elements before negatives.
Everything the render thread needs to draw one frame of a window.
FRAME_DRAW_DESC staticDrawDesc
TARGET_CACHED ranges go to staticDrawDesc and the rest to dynamicDrawDesc.
uint64_t bufferGeneration
Oldest buffer generation either descriptor uses, so resources retired before it are unreferenced.
FRAME_DRAW_DESC drawDesc
FRAME_DRAW_DESC dynamicDrawDesc
uint64_t inputSerial
Inputs that had reached the canvas when this packet was built, so a frame answering one is never held...
uint64_t staticEpoch
Content generation of each pool.
Per-frame uniform block matching FrameUBO in frame_ubo.glsl (std140).
float projection[16]
column-major for GLSL
bool operator==(const FRAME_UBO_DATA &aOther) const =default
float viewScale
the view's scale, which levels of detail are compared with
float renderScale
target texels per viewport pixel, above 1 in a supersampled target
Grid uniform block matching the GridUBO layout in grid.frag (std140).
float gridSpacing[2]
visible spacing from GetVisibleGridSize
float minorLineWidth
pixels, at least 1 and drawn rounded to whole pixels
float majorLineWorld
world units, see GAL::gridMinorLineWidth()
float worldPixelSize
world units that majorLineWorld is divided by
int gridStyle
0 = lines, 1 = dots, 2 = small cross
int gridTick
coarse grid multiplier
float renderScale
as FRAME_UBO_DATA::renderScale
bool operator==(const GRID_UBO_DATA &aOther) const =default
One layer's instance ranges within the flat GPU buffers, normal instances before negatives.
std::array< RHI_BufferHandle, RHI_SHAPES > buffer
Buffers a retained scene layer owns per shape.
RHI_SHAPE_COUNTS negStart
bool difference
A diff layer (GAL::StartDiffLayer) that replaces what is under it with the colour difference,...
bool HasGeometry() const
bool overlayAlpha
Elements flagged RHI_INSTANCE_OVERLAY_ALPHA, drawn with RHI_GAL_PIPELINES::GetPremultipliedVariant.
RHI_SHAPE_COUNTS count
std::shared_ptr< const RHI_RUN_TABLE > cullRuns
Bounds of the range's buffers so off-screen runs are skipped.
bool hasNegatives
Subtractive instances go through a temp FBO so their erasure stays within the layer.
bool singleCoverage
Draw straight into the target using the range's own depth slice, either taking each pixel once at tra...
std::array< RHI_BufferHandle, RHI_SHAPES > negBuffer
bool NeedsTempFBO() const
float depthNear
Depth slice the range is drawn into.
float alpha
Compositing alpha.
RHI_LAYER_DIM dim
RHI_SHAPE_COUNTS negCount
RENDER_TARGET target
Picks the static (cached) or dynamic scene pool for this range.
RHI_SHAPE_COUNTS start
Each shape's normal elements, then for an instanced shape its negatives.
uint32_t runStart
The range's runs in FRAME_DRAW_DESC::polarityRuns, none when its order does not matter.
A stretch of one layer range drawn in one polarity.
RHI_SHAPE_COUNTS start
RHI_SHAPE_COUNTS count
Fade of a whole layer towards a colour, laid out as the push constants of layer_dim....
float keep
1 leaves the layer as it is
bool operator==(const RHI_LAYER_DIM &aOther) const =default
Runs of each array a layer range draws from, indexed by element / RHI_CULL_RUN_LENGTH.