Project
Loading...
Searching...
No Matches
GPUDisplayBackend.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#include "GPUDisplayBackend.h"
17
19#ifdef GPUCA_BUILD_EVENT_DISPLAY_OPENGL
21#endif
22#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
24#endif
25
26#ifdef GPUCA_BUILD_EVENT_DISPLAY_FREETYPE
27#include <ft2build.h>
28#include FT_FREETYPE_H
29#ifdef GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
30#if !__has_include(<fontconfig/fontconfig.h>)
31#undef GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
32#else
33#include <fontconfig/fontconfig.h>
34#endif
35#endif
36#endif
37
38#include "GPUDisplay.h"
39#include "GPULogging.h"
40#include "GPUTPCGeometry.h"
41#include <string>
42
43using namespace o2::gpu;
44
47
49{
50#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
51 if (strcmp(type, "vulkan") == 0 || strcmp(type, "auto") == 0) {
52 return new GPUDisplayBackendVulkan;
53 } else
54#endif
55#ifdef GPUCA_BUILD_EVENT_DISPLAY_OPENGL
56 if (strcmp(type, "opengl") == 0 || strcmp(type, "auto") == 0) {
57 return new GPUDisplayBackendOpenGL;
58 } else
59#endif
60 if (strcmp(type, "none") == 0) {
61 return new GPUDisplayBackendNone;
62 } else {
63 GPUError("Requested renderer not available");
64 }
65 return nullptr;
66}
67
69{
71 if (retVal) {
72 return retVal;
73 }
74 if (!mDisplay->cfg().noFreetype) {
75 loadFont();
76 }
77 return retVal;
78}
79
81{
82 if (mFreetypeInitialized && scale != mFontRasterScale) {
85 loadFont();
86 }
87}
88
90{
91 std::string fontName = mDisplay->cfg().font;
92#ifdef GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
93 FcInit();
94 FcConfig* config = FcInitLoadConfigAndFonts();
95 FcPattern* pat = FcNameParse((const FcChar8*)fontName.c_str());
96 FcConfigSubstitute(config, pat, FcMatchPattern);
97 FcDefaultSubstitute(pat);
98 FcResult result;
99 FcPattern* font = FcFontMatch(config, pat, &result);
100 if (font && result == 0) {
101 FcChar8* file = nullptr;
102 if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {
103 fontName = (char*)file;
104 }
105 } else {
106 GPUError("Coult not find font for pattern %s", fontName.c_str());
107 }
108 FcPatternDestroy(font);
109 FcPatternDestroy(pat);
110 FcConfigDestroy(config);
111 FcFini();
112#endif // GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
113
114#ifdef GPUCA_BUILD_EVENT_DISPLAY_FREETYPE
115 FT_Library ft;
116 FT_Face face;
117 if (FT_Init_FreeType(&ft)) {
118 GPUError("Error initializing freetype");
119 return;
120 }
121 if (FT_New_Face(ft, fontName.c_str(), 0, &face)) {
122 GPUError("Error loading freetype font");
123 FT_Done_FreeType(ft);
124 return;
125 }
126
127 int32_t fontSize = mDisplay->cfg().fontSize;
129 if (smoothFont()) {
130 fontSize *= 4; // Font size scaled by 4, can be downsampled
131 }
133 FT_Set_Pixel_Sizes(face, 0, (uint32_t)(fontSize * mFontRasterScale + 0.5f)); // Rasterize at physical pixel size for HiDPI
134
135 for (uint32_t i = 0; i < SOLID_GLYPH; i++) {
136 if (FT_Load_Char(face, i, FT_LOAD_RENDER)) {
137 GPUError("Error loading freetype symbol");
138 FT_Done_Face(face);
139 FT_Done_FreeType(ft);
140 return;
141 }
142 const auto& glyph = face->glyph;
143 if (i == 'M') {
144 mFontCharWidth = (glyph->advance.x >> 6) * (smoothFont() ? 0.25f : 1.f) / mFontRasterScale; // As in GLPrintText of the backends
145 }
146 addFontSymbol(i, glyph->bitmap.width, glyph->bitmap.rows, glyph->bitmap_left, glyph->bitmap_top, glyph->advance.x, glyph->bitmap.buffer);
147 }
148 std::vector<uint8_t> solid(8 * 8, 255);
149 addFontSymbol(SOLID_GLYPH, 8, 8, 0, 0, 0, solid.data());
151 FT_Done_Face(face);
152 FT_Done_FreeType(ft);
154#endif // GPUCA_BUILD_EVENT_DISPLAY_FREETYPE
155}
156
161
163{
164 auto retVal = std::move(mScreenshotPixels);
165 mScreenshotPixels = std::vector<char>();
166 return retVal;
167}
168
170{
171 mIndirectSectorOffset.resize(GPUTPCGeometry::NSECTORS);
172 size_t total = 0;
173 for (uint32_t iSector = 0; iSector < GPUTPCGeometry::NSECTORS; iSector++) {
175 total += mDisplay->vertexBufferStart()[iSector].size();
176 }
177 mCmdBuffer.resize(total);
178 for (uint32_t iSector = 0; iSector < GPUTPCGeometry::NSECTORS; iSector++) {
179 for (uint32_t k = 0; k < mDisplay->vertexBufferStart()[iSector].size(); k++) {
181 }
182 }
183}
184
186{
187 const auto& cfg = mDisplay->cfgR();
188 if (cfg.fpsLimit == FPS_LIMIT_VSYNC) {
189 return !cfg.drawQualityVSync ? FPS_LIMIT_NONE : (canLimitToVSync() ? FPS_LIMIT_VSYNC : FPS_LIMIT_RATE);
190 }
191 return cfg.fpsLimit;
192}
193
195{
196 float factor = 1.0f;
197 int32_t fsaa = mDisplay->cfgR().drawQualityDownsampleFSAA;
198 int32_t screenshotScale = mDisplay->cfgR().screenshotScaleFactor;
199 if (fsaa) {
200 factor *= fsaa;
201 }
202 if (screenshotScale && screenshot) {
203 factor *= screenshotScale;
204 }
205 return factor;
206}
207
209{
210 return mDisplay->cfg().smoothFont < 0 ? (mDisplay->cfg().fontSize > 12) : mDisplay->cfg().smoothFont;
211}
212
213void GPUDisplayBackend::GLDrawLine(float x0, float y0, float x1, float y1, float width, const float* color)
214{
215 const float dx = x1 - x0, dy = y1 - y0, length = std::sqrt(dx * dx + dy * dy);
216 if (length == 0.f) {
217 return;
218 }
219 const float nx = -dy / length * width * 0.5f, ny = dx / length * width * 0.5f; // Perpendicular, half the width
220 GLDrawQuad({{x0 + nx, y0 + ny}, {x0 - nx, y0 - ny}, {x1 - nx, y1 - ny}, {x1 + nx, y1 + ny}}, color);
221}
222
223uint32_t GPUDisplayBackend::GLDrawConsole(float verticalFraction, std::span<const std::string> previous, const std::string& current, int32_t cursorPos, uint32_t scroll)
224{
226 return 1;
227 }
228 const float scale = mDisplay->frontend()->getDisplayScale();
229 const float colorValue = mDisplay->cfgL().invertColors ? 0.f : 1.f;
230 float textColor[4] = {colorValue, colorValue, colorValue, 1.f};
231 const float backgroundColor[4] = {1.f - colorValue, 1.f - colorValue, 1.f - colorValue, mDisplay->cfg().internal.consoleAlpha};
232 const float width = mScreenWidth, top = mScreenHeight, bottom = top * (1.f - verticalFraction);
233 GLDrawQuad({{0.f, bottom}, {width, bottom}, {width, top}, {0.f, top}}, backgroundColor);
234 GLDrawLine(0.f, bottom, width, bottom, scale, textColor);
235
236 static constexpr float MARGIN = 6.f; // Logical pixels from the text to the left border and to the line
237 const float lineHeight = std::max(20, mDisplay->drawTextFontSize() + 4) * scale; // As the info text of GPUDisplay
238 const float descent = 0.25f * mDisplay->drawTextFontSize() * scale; // Below the baseline, approximately
239 const size_t maxChars = mFontCharWidth > 0.f ? std::max(0.f, (width / scale - 2 * MARGIN) / mFontCharWidth) : SIZE_MAX; // Longer lines are cut
240 float y = bottom + (0.5f + MARGIN) * scale + descent; // Baseline of the lowest line, MARGIN above the line (half its width)
241 if (cursorPos >= 0 && (size_t)cursorPos < maxChars && mFontCharWidth > 0.f) { // Monospace font: position from the character width
242 const float x0 = (MARGIN + cursorPos * mFontCharWidth) * scale, x1 = x0 + mFontCharWidth * scale;
243 const float y1 = y - 0.5f * descent, y0 = y1 - 3.f * scale;
244 GLDrawQuad({{x0, y0}, {x1, y0}, {x1, y1}, {x0, y1}}, textColor); // Solid underline, 3 logical pixels, below the baseline
245 }
246 const uint32_t nFit = std::max(1.f, std::floor((top - y + descent) / lineHeight) - 1.f); // Lines above the current one that fit, as in the loop
247 scroll = std::min<size_t>(scroll, previous.size());
248 for (size_t i = 0; i <= previous.size() - scroll && y + lineHeight - descent <= top; i++, y += lineHeight) {
249 const std::string& text = i == 0 ? current : previous[previous.size() - scroll - i];
250 if (!text.empty() && maxChars) {
251 GLPrintText(text.c_str(), MARGIN * scale, y, textColor, scale / mFontRasterScale, std::min(text.size(), maxChars));
252 }
253 }
254 return nFit;
255}
unsigned int uint32_t
int32_t i
uint32_t iSector
int32_t retVal
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h configStandalone Internal display display_internal Number of updates the Qt GUI may send ahead of the last one the display has before it waits for the display Opacity of the console background Number of console lines the history is shortened to this when it reaches twice the size Time in seconds an info message fades out after setInfoTime h OpenGL display display Font size Do not use Freetype for font Renderer for event Frontend to use for event ROOT macros used as track filter Console script file
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by factor
virtual void addFontSymbol(int32_t symbol, int32_t sizex, int32_t sizey, int32_t offsetx, int32_t offsety, int32_t advance, void *data)=0
void GLDrawLine(float x0, float y0, float x1, float y1, float width, const float *color)
std::vector< char > getPixels()
virtual bool canLimitToVSync() const
static constexpr int32_t SOLID_GLYPH
vecpod< DrawArraysIndirectCommand > mCmdBuffer
std::vector< int32_t > mIndirectSectorOffset
virtual void GLPrintText(const char *s, float x, float y, float *color, float scale, uint32_t nCharacters)=0
uint32_t GLDrawConsole(float verticalFraction, std::span< const std::string > previous, const std::string &current, int32_t cursorPos, uint32_t scroll)
static GPUDisplayBackend * getBackend(const char *type)
std::vector< char > mScreenshotPixels
virtual void ExitBackendA()=0
virtual void initializeTextDrawing()=0
virtual int32_t InitBackendA()=0
float getDownsampleFactor(bool screenshot=false)
virtual void GLDrawQuad(const float(&corners)[4][2], const float *color)=0
virtual float getDisplayScale() const
const GPUSettingsDisplayLight & cfgL() const
Definition GPUDisplay.h:73
const GPUSettingsDisplayRenderer & cfgR() const
Definition GPUDisplay.h:72
int32_t & drawTextFontSize()
Definition GPUDisplay.h:90
GPUDisplayFrontend * frontend()
Definition GPUDisplay.h:89
const vecpod< uint32_t > * vertexBufferCount() const
Definition GPUDisplay.h:81
const GPUSettingsDisplay & cfg() const
Definition GPUDisplay.h:75
vecpod< int32_t > * vertexBufferStart()
Definition GPUDisplay.h:80
GLuint64EXT * result
Definition glcorearb.h:5662
GLuint GLfloat GLfloat GLfloat GLfloat y1
Definition glcorearb.h:5034
GLsizeiptr size
Definition glcorearb.h:659
GLuint color
Definition glcorearb.h:1272
GLuint GLfloat GLfloat GLfloat x1
Definition glcorearb.h:5034
GLdouble GLdouble GLdouble GLdouble top
Definition glcorearb.h:4077
GLenum GLuint GLint GLenum face
Definition glcorearb.h:3184
GLint GLsizei width
Definition glcorearb.h:270
GLint y
Definition glcorearb.h:270
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
GLint GLint bottom
Definition glcorearb.h:1979
GLuint GLfloat x0
Definition glcorearb.h:5034
GLenum GLsizeiptr fontSize
Definition glcorearb.h:5519
GLenum const void * fontName
Definition glcorearb.h:5473
GLuint GLfloat GLfloat y0
Definition glcorearb.h:5034