Skip to content

Commit 1def08d

Browse files
committed
GPU Display: Many minor fixes suggested by Claude
1 parent c81d959 commit 1def08d

19 files changed

Lines changed: 173 additions & 86 deletions

‎GPU/GPUTracking/Definitions/GPUSettingsList.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ AddOption(camYUp, bool, false, "", 0, "Orient the camera such that the y-axis is
500500
AddOption(cameraMode, int32_t, 0, "", 0, "Camera mode")
501501
AddOption(fullScreen, bool, false, "", 0, "Full Screen")
502502
AddOption(maximized, bool, true, "", 0, "Maximized window")
503-
AddOption(rendererCompatSmoothing, bool, false, "", 0, "Use compat smoothing (if available) of instad of shader for smooth lines / points")
503+
AddOption(rendererCompatSmoothing, bool, false, "", 0, "Use compat smoothing (if available) instead of shader for smooth lines / points")
504504
AddOption(drawQualityMSAA, int32_t, 0, "", 0, "MultiSample Anti Aliasing")
505505
AddOption(drawQualityDownsampleFSAA, int32_t, 0, "", 0, "Downsampling Anti Aliasing")
506506
AddOption(drawQualityVSync, bool, true, "", 0, "Enable Vertical Sync")

‎GPU/GPUTracking/display/GPUDisplay.cxx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,9 @@ void GPUDisplay::DrawGLScene_internal(float animateTime, bool renderToMixBuffer)
674674
nextViewMatrix = nextViewMatrix * *mModelMatrix;
675675
const float zFar = ((mParam->par.continuousTracking ? (mMaxClusterZ * GL_SCALE_FACTOR) : 8.f) + 50.f) * 2.f;
676676
const hmm_mat4 proj = HMM_Perspective(mCfgR.fov, (float)mBackend->mRenderWidth / (float)mBackend->mRenderHeight, 0.1f, zFar);
677-
mBackend->prepareDraw(proj, nextViewMatrix, doScreenshot || mRequestScreenshot, renderToMixBuffer, mixSlaveImage);
677+
if (!mBackend->prepareDraw(proj, nextViewMatrix, doScreenshot || mRequestScreenshot, renderToMixBuffer, mixSlaveImage)) {
678+
return; // No image available (e.g. hidden window), retry with the next frame
679+
}
678680
mBackend->pointSizeFactor(1);
679681
mBackend->lineWidthFactor(1);
680682

‎GPU/GPUTracking/display/backend/GPUDisplayBackend.cxx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ void GPUDisplayBackend::loadFont()
119119
return;
120120
}
121121
if (FT_New_Face(ft, fontName.c_str(), 0, &face)) {
122-
GPUError("Error loading freetypoe font");
122+
GPUError("Error loading freetype font");
123+
FT_Done_FreeType(ft);
123124
return;
124125
}
125126

@@ -134,6 +135,8 @@ void GPUDisplayBackend::loadFont()
134135
for (uint32_t i = 0; i < 128; i++) {
135136
if (FT_Load_Char(face, i, FT_LOAD_RENDER)) {
136137
GPUError("Error loading freetype symbol");
138+
FT_Done_Face(face);
139+
FT_Done_FreeType(ft);
137140
return;
138141
}
139142
const auto& glyph = face->glyph;

‎GPU/GPUTracking/display/backend/GPUDisplayBackend.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class GPUDisplayBackend
9090
void updateFontScale(float scale); // Rasterize the font again if the display (HiDPI) scale changed
9191
void ExitBackend();
9292
virtual void loadDataToGPU(size_t totalVertizes) = 0;
93-
virtual void prepareDraw(const hmm_mat4& proj, const hmm_mat4& view, bool requestScreenshot = false, bool toMixBuffer = false, float includeMixImage = 0.f) = 0;
93+
virtual bool prepareDraw(const hmm_mat4& proj, const hmm_mat4& view, bool requestScreenshot = false, bool toMixBuffer = false, float includeMixImage = 0.f) = 0; // Returns false if the frame must be skipped (no swapchain image available)
9494
virtual void finishDraw(bool doScreenshot, bool toMixBuffer = false, float includeMixImage = 0.f) = 0;
9595
virtual void finishFrame(bool doScreenshot, bool toMixBuffer = false, float includeMixImage = 0.f) = 0;
9696
virtual void prepareText() = 0;

‎GPU/GPUTracking/display/backend/GPUDisplayBackendNone.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class GPUDisplayBackendNone : public GPUDisplayBackend
3333
int32_t InitBackendA() override;
3434
void ExitBackendA() override {}
3535
void loadDataToGPU(size_t totalVertizes) override {}
36-
void prepareDraw(const hmm_mat4& proj, const hmm_mat4& view, bool requestScreenshot, bool toMixBuffer, float includeMixImage) override {}
36+
bool prepareDraw(const hmm_mat4& proj, const hmm_mat4& view, bool requestScreenshot, bool toMixBuffer, float includeMixImage) override { return true; }
3737
void finishDraw(bool doScreenshot, bool toMixBuffer, float includeMixImage) override {}
3838
void finishFrame(bool doScreenshot, bool toMixBuffer, float includeMixImage) override {}
3939
void prepareText() override {}

‎GPU/GPUTracking/display/backend/GPUDisplayBackendOpenGL.cxx‎

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ int32_t GPUDisplayBackendOpenGL::ExtInit()
6161
#endif
6262
}
6363

64+
bool GPUDisplayBackendOpenGL::canLimitToVSync() const
65+
{
66+
return mDisplay->frontend()->canSetVSync();
67+
}
68+
6469
bool GPUDisplayBackendOpenGL::CoreProfile()
6570
{
6671
#ifdef GPUCA_DISPLAY_OPENGL_CORE
@@ -471,11 +476,14 @@ void GPUDisplayBackendOpenGL::loadDataToGPU(size_t totalVertizes)
471476
}
472477
}
473478

474-
void GPUDisplayBackendOpenGL::prepareDraw(const hmm_mat4& proj, const hmm_mat4& view, bool requestScreenshot, bool toMixBuffer, float includeMixImage)
479+
bool GPUDisplayBackendOpenGL::prepareDraw(const hmm_mat4& proj, const hmm_mat4& view, bool requestScreenshot, bool toMixBuffer, float includeMixImage)
475480
{
476481
if (mDisplay->updateRenderPipeline() || mDownsampleFactor != getDownsampleFactor(requestScreenshot)) {
477482
updateRenderer(requestScreenshot);
478483
}
484+
if (toMixBuffer && !mMixBuffer.created) { // Only allocated when mixing is used, freed with the other offscreen buffers
485+
createFB(mMixBuffer, true, true, false, mRenderWidth, mRenderHeight);
486+
}
479487
if (mOffscreenBufferMSAA.created) {
480488
setFrameBuffer(mOffscreenBufferMSAA.fb_id);
481489
} else if (toMixBuffer) {
@@ -543,6 +551,7 @@ void GPUDisplayBackendOpenGL::prepareDraw(const hmm_mat4& proj, const hmm_mat4&
543551
CHKERR(glNamedBufferSubData(mFieldModelViewBuffer, 0, sizeof(modelViewProj), &modelViewProj));
544552
}
545553
}
554+
return true;
546555
}
547556

548557
void GPUDisplayBackendOpenGL::finishDraw(bool doScreenshot, bool toMixBuffer, float includeMixImage)
@@ -557,7 +566,7 @@ void GPUDisplayBackendOpenGL::finishDraw(bool doScreenshot, bool toMixBuffer, fl
557566
CHKERR(glUseProgram(0));
558567
}
559568

560-
if (mDisplay->cfgR().drawQualityMSAA) {
569+
if (mOffscreenBufferMSAA.created) {
561570
uint32_t dstId = toMixBuffer ? mMixBuffer.fb_id : (mDownsampleFactor != 1 ? mOffscreenBuffer.fb_id : 0);
562571
CHKERR(glBlitNamedFramebuffer(mOffscreenBufferMSAA.fb_id, dstId, 0, 0, mRenderWidth, mRenderHeight, 0, 0, mRenderWidth, mRenderHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR));
563572
}
@@ -788,8 +797,8 @@ void GPUDisplayBackendOpenGL::OpenGLPrint(const char* s, float x, float y, float
788797
if (smoothFont()) {
789798
scale *= 0.25f; // Font size is 48 to have nice bitmap, scale to size 12
790799
}
791-
for (const char* c = s; *c; c++) {
792-
if ((int32_t)*c > (int32_t)mFontSymbols.size()) {
800+
for (const unsigned char* c = (const unsigned char*)s; *c; c++) {
801+
if ((int32_t)*c >= (int32_t)mFontSymbols.size()) {
793802
GPUError("Trying to draw unsupported symbol: %d > %d\n", (int32_t)*c, (int32_t)mFontSymbols.size());
794803
continue;
795804
}
@@ -838,20 +847,6 @@ void GPUDisplayBackendOpenGL::resizeScene(uint32_t width, uint32_t height)
838847
mScreenHeight = height;
839848

840849
updateRenderer(false);
841-
842-
float vertices[6][4] = {
843-
{0, (float)mRenderHeight, 0.0f, 1.0f},
844-
{0, 0, 0.0f, 0.0f},
845-
{(float)mRenderWidth, 0, 1.0f, 0.0f},
846-
{0, (float)mRenderHeight, 0.0f, 1.0f},
847-
{(float)mRenderWidth, 0, 1.0f, 0.0f},
848-
{(float)mRenderWidth, (float)mRenderHeight, 1.0f, 1.0f}};
849-
CHKERR(glBindBuffer(GL_ARRAY_BUFFER, VBO_texture));
850-
CHKERR(glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices));
851-
CHKERR(glBindBuffer(GL_ARRAY_BUFFER, 0));
852-
if (!mDisplay->useMultiVBO()) {
853-
CHKERR(glBindBuffer(GL_ARRAY_BUFFER, mVBOId[0])); // If we don't use multiple buffers, we keep the default buffer bound
854-
}
855850
}
856851

857852
void GPUDisplayBackendOpenGL::updateRenderer(bool withScreenshot)
@@ -866,6 +861,16 @@ void GPUDisplayBackendOpenGL::updateRenderer(bool withScreenshot)
866861
if (mDownsampleFactor != 1) {
867862
createFB(mOffscreenBuffer, mDownsampleFactor != 2, true, false, mRenderWidth, mRenderHeight); // Texture for shader downsampling (factor != 2), screenshot downsampling uses the shader only if this factor is != 2 as well
868863
}
869-
createFB(mMixBuffer, true, true, false, mRenderWidth, mRenderHeight);
870864
setQuality();
865+
866+
float vertices[6][4] = {// Mix quad at render size
867+
{0, (float)mRenderHeight, 0.0f, 1.0f},
868+
{0, 0, 0.0f, 0.0f},
869+
{(float)mRenderWidth, 0, 1.0f, 0.0f},
870+
{0, (float)mRenderHeight, 0.0f, 1.0f},
871+
{(float)mRenderWidth, 0, 1.0f, 0.0f},
872+
{(float)mRenderWidth, (float)mRenderHeight, 1.0f, 1.0f}};
873+
CHKERR(glBindBuffer(GL_ARRAY_BUFFER, VBO_texture));
874+
CHKERR(glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices));
875+
CHKERR(glBindBuffer(GL_ARRAY_BUFFER, mDisplay->useMultiVBO() ? 0 : mVBOId[0])); // If we don't use multiple buffers, we keep the default buffer bound (also called from prepareDraw before the vertex pointers are set)
871876
}

‎GPU/GPUTracking/display/backend/GPUDisplayBackendOpenGL.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class GPUDisplayBackendOpenGL : public GPUDisplayBackend
3535
~GPUDisplayBackendOpenGL() override = default;
3636
int32_t ExtInit() override;
3737
bool CoreProfile() override;
38-
bool canLimitToVSync() const override { return true; } // Buffer swap blocks with VSync
38+
bool canLimitToVSync() const override; // Buffer swap blocks with VSync, if the frontend can set the swap interval
3939
uint32_t DepthBits() override;
4040

4141
protected:
@@ -57,7 +57,7 @@ class GPUDisplayBackendOpenGL : public GPUDisplayBackend
5757
static int32_t checkProgramStatus(uint32_t program);
5858
void clearScreen(bool alphaOnly = false);
5959
void loadDataToGPU(size_t totalVertizes) override;
60-
void prepareDraw(const hmm_mat4& proj, const hmm_mat4& view, bool requestScreenshot, bool toMixBuffer, float includeMixImage) override;
60+
bool prepareDraw(const hmm_mat4& proj, const hmm_mat4& view, bool requestScreenshot, bool toMixBuffer, float includeMixImage) override;
6161
void resizeScene(uint32_t width, uint32_t height) override;
6262
void updateRenderer(bool withScreenshot);
6363
void ClearOffscreenBuffers();
@@ -101,9 +101,9 @@ class GPUDisplayBackendOpenGL : public GPUDisplayBackend
101101
uint32_t mFragmentShaderDownsample;
102102
uint32_t mGeometryShader;
103103
uint32_t mShaderProgram;
104-
uint32_t mShaderProgramSmoothPoint; // Points with fragmentSmoothPoint.frag, for smoothPoints in the core profile (no GL_POINT_SMOOTH)
104+
uint32_t mShaderProgramSmoothPoint; // Points with fragmentSmoothPoint.frag, for smoothPoints with the shader path (not rendererCompatSmoothing / GL_POINT_SMOOTH)
105105
bool mUseSmoothPointShader = false;
106-
uint32_t mShaderProgramSmoothLine; // Lines with vertexSmoothLine.vert / fragmentSmoothLine.frag, for smoothLines in the core profile (no GL_LINE_SMOOTH)
106+
uint32_t mShaderProgramSmoothLine; // Lines with vertexSmoothLine.vert / fragmentSmoothLine.frag, for smoothLines with the shader path (not rendererCompatSmoothing / GL_LINE_SMOOTH)
107107
bool mUseSmoothLineShader = false;
108108
uint32_t mShaderProgramText;
109109
uint32_t mShaderProgramTexture;

‎GPU/GPUTracking/display/backend/GPUDisplayBackendVulkan.cxx‎

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ void GPUDisplayBackendVulkan::createDevice()
571571
GPUInfo("Using physical Vulkan device %s", &deviceProperties.deviceName[0]);
572572
mMaxMSAAsupported = getMaxUsableSampleCount(deviceProperties);
573573
mStrictLines = deviceProperties.limits.strictLines;
574+
mMaxLineWidth = deviceProperties.limits.lineWidthRange[1];
575+
mMaxPointSize = deviceProperties.limits.pointSizeRange[1];
574576
mMaxRenderSize = std::min({deviceProperties.limits.maxImageDimension2D, deviceProperties.limits.maxFramebufferWidth, deviceProperties.limits.maxFramebufferHeight});
575577
mZSupported = (bool)(depth32FormatProperties.optimalTilingFeatures & vk::FormatFeatureFlagBits::eDepthStencilAttachment);
576578
mStencilSupported = (bool)(depth64FormatProperties.optimalTilingFeatures & vk::FormatFeatureFlagBits::eDepthStencilAttachment);
@@ -1196,7 +1198,9 @@ void GPUDisplayBackendVulkan::startFillCommandBuffer(vk::CommandBuffer& commandB
11961198
cmdBeginRendering(commandBuffer, mRenderWidth, mRenderHeight, colorAttachment, mZActive ? &depthAttachment : nullptr);
11971199

11981200
vk::DeviceSize offsets[] = {0};
1199-
commandBuffer.bindVertexBuffers(0, 1, &mVBO.buffer, offsets);
1201+
if (mVBO.size) {
1202+
commandBuffer.bindVertexBuffers(0, 1, &mVBO.buffer, offsets);
1203+
}
12001204
cmdPushDescriptors(commandBuffer, mPipelineLayout, mUniformBuffersMat[0][imageIndex]);
12011205
const float viewport[2] = {(float)mRenderWidth, (float)mRenderHeight};
12021206
commandBuffer.pushConstants(mPipelineLayout, vk::ShaderStageFlagBits::eVertex, 6 * sizeof(float), sizeof(viewport), viewport);
@@ -1399,6 +1403,10 @@ void GPUDisplayBackendVulkan::ExitBackendA()
13991403
}
14001404
clearTextureSampler();
14011405
clearDevice();
1406+
mCommandInfrastructureCreated = false; // Recreated by the next InitBackendA
1407+
mImageCount = 0;
1408+
mLastPresentId = 0;
1409+
mSwapChainSuboptimal = mFrameSkipped = false;
14021410
}
14031411

14041412
// ---------------------------- USER CODE ----------------------------
@@ -1419,10 +1427,14 @@ void GPUDisplayBackendVulkan::loadDataToGPU(size_t totalVertizes)
14191427
{
14201428
mDevice.waitIdle();
14211429
clearVertexBuffers();
1422-
mVBO = createBuffer(totalVertizes * sizeof(mDisplay->vertexBuffer()[0][0]), mDisplay->vertexBuffer()[0].data(), vk::BufferUsageFlagBits::eVertexBuffer, 1);
1430+
if (totalVertizes) { // Zero-size buffers are invalid (empty event)
1431+
mVBO = createBuffer(totalVertizes * sizeof(mDisplay->vertexBuffer()[0][0]), mDisplay->vertexBuffer()[0].data(), vk::BufferUsageFlagBits::eVertexBuffer, 1);
1432+
}
14231433
if (mDisplay->cfgR().useGLIndirectDraw) {
14241434
fillIndirectCmdBuffer();
1425-
mIndirectCommandBuffer = createBuffer(mCmdBuffer.size() * sizeof(mCmdBuffer[0]), mCmdBuffer.data(), vk::BufferUsageFlagBits::eIndirectBuffer, 1);
1435+
if (mCmdBuffer.size()) {
1436+
mIndirectCommandBuffer = createBuffer(mCmdBuffer.size() * sizeof(mCmdBuffer[0]), mCmdBuffer.data(), vk::BufferUsageFlagBits::eIndirectBuffer, 1);
1437+
}
14261438
mCmdBuffer.clear();
14271439
}
14281440
needRecordCommandBuffers();
@@ -1456,25 +1468,27 @@ uint32_t GPUDisplayBackendVulkan::drawVertices(const vboList& v, const drawType
14561468
return count;
14571469
}
14581470

1459-
void GPUDisplayBackendVulkan::prepareDraw(const hmm_mat4& proj, const hmm_mat4& view, bool requestScreenshot, bool toMixBuffer, float includeMixImage)
1471+
bool GPUDisplayBackendVulkan::prepareDraw(const hmm_mat4& proj, const hmm_mat4& view, bool requestScreenshot, bool toMixBuffer, float includeMixImage)
14601472
{
14611473
if (mDisplay->updateDrawCommands() || toMixBuffer || includeMixImage > 0) {
14621474
needRecordCommandBuffers();
14631475
}
14641476

1477+
if (includeMixImage > 0.f && mFrameSkipped) {
1478+
return false; // The render to the mix buffer of this frame did not get an image
1479+
}
14651480
if (includeMixImage == 0.f) {
14661481
mCurrentFrame = (mCurrentFrame + 1) % mFramesInFlight;
14671482
waitTimeline(mFrameTimelineValue[mCurrentFrame]);
14681483
if (mLastPresentId > 1 && fpsLimitMode() == FPS_LIMIT_VSYNC) { // Refresh rate limit (FIFO): at most one frame queued (wait for the second-last present), keeps the rate if a frame misses the deadline, timeout in case the window is hidden
14691484
const vk::Result retVal = (vk::Result)VULKAN_HPP_DEFAULT_DISPATCHER.vkWaitForPresentKHR(static_cast<VkDevice>(mDevice), static_cast<VkSwapchainKHR>(mSwapChain), mLastPresentId - 1, 100'000'000);
1470-
if (retVal == vk::Result::eErrorOutOfDateKHR || retVal == vk::Result::eSuboptimalKHR) {
1471-
mMustUpdateSwapChain = true;
1472-
} else if (retVal != vk::Result::eTimeout) {
1485+
handleSwapChainResult(retVal);
1486+
if (retVal != vk::Result::eTimeout && retVal != vk::Result::eErrorOutOfDateKHR) {
14731487
CHKERR(retVal);
14741488
}
14751489
}
1476-
auto getImage = [&]() {
1477-
return mDevice.acquireNextImageKHR(mSwapChain, UINT64_MAX, mImageAvailableSemaphore[mCurrentFrame], VkFence(VK_NULL_HANDLE), &mCurrentImageIndex);
1490+
auto getImage = [&]() { // Timeout so that a hidden window cannot block the thread (which may also dispatch the window system events) forever
1491+
return mDevice.acquireNextImageKHR(mSwapChain, 100'000'000, mImageAvailableSemaphore[mCurrentFrame], VkFence(VK_NULL_HANDLE), &mCurrentImageIndex);
14781492
};
14791493

14801494
vk::Result retVal = vk::Result::eSuccess;
@@ -1492,7 +1506,12 @@ void GPUDisplayBackendVulkan::prepareDraw(const hmm_mat4& proj, const hmm_mat4&
14921506
recreateRendering(requestScreenshot, toMixBuffer);
14931507
retVal = getImage();
14941508
}
1495-
mMustUpdateSwapChain = retVal == vk::Result::eSuboptimalKHR;
1509+
mMustUpdateSwapChain = false;
1510+
handleSwapChainResult(retVal);
1511+
mFrameSkipped = retVal == vk::Result::eTimeout || retVal == vk::Result::eNotReady;
1512+
if (mFrameSkipped) {
1513+
return false;
1514+
}
14961515
CHKERR(retVal);
14971516
waitTimeline(mImageTimelineValue[mCurrentImageIndex]); // Previous frame using this image's resources (command buffers, uniform buffer, ...) finished
14981517
if (mPresentFences.size()) { // Previous present of this image done, its present semaphore can be signaled again
@@ -1519,6 +1538,17 @@ void GPUDisplayBackendVulkan::prepareDraw(const hmm_mat4& proj, const hmm_mat4&
15191538
if (!mCommandBufferUpToDate[mCurrentImageIndex]) {
15201539
startFillCommandBuffer(mCurrentCommandBuffer, mCurrentImageIndex, toMixBuffer);
15211540
}
1541+
return true;
1542+
}
1543+
1544+
void GPUDisplayBackendVulkan::handleSwapChainResult(vk::Result retVal)
1545+
{
1546+
if (retVal == vk::Result::eErrorOutOfDateKHR || (retVal == vk::Result::eSuboptimalKHR && !mSwapChainSuboptimal)) {
1547+
mMustUpdateSwapChain = true;
1548+
}
1549+
if (retVal == vk::Result::eSuboptimalKHR || retVal == vk::Result::eSuccess) {
1550+
mSwapChainSuboptimal = retVal == vk::Result::eSuboptimalKHR;
1551+
}
15221552
}
15231553

15241554
void GPUDisplayBackendVulkan::finishDraw(bool doScreenshot, bool toMixBuffer, float includeMixImage)
@@ -1588,10 +1618,13 @@ void GPUDisplayBackendVulkan::finishFrame(bool doScreenshot, bool toMixBuffer, f
15881618
presentFenceInfo = vk::SwapchainPresentFenceInfoKHR{1, &mPresentFences[mCurrentImageIndex], presentInfo.pNext};
15891619
presentInfo.pNext = &presentFenceInfo;
15901620
}
1591-
vk::Result retVal = mGraphicsQueue.presentKHR(&presentInfo);
1592-
if (retVal == vk::Result::eErrorOutOfDateKHR || retVal == vk::Result::eSuboptimalKHR) {
1593-
mMustUpdateSwapChain = true;
1594-
} else {
1621+
vk::Result retVal;
1622+
{
1623+
std::lock_guard<std::mutex> guard(mQueueMutex);
1624+
retVal = mGraphicsQueue.presentKHR(&presentInfo);
1625+
}
1626+
handleSwapChainResult(retVal);
1627+
if (retVal != vk::Result::eErrorOutOfDateKHR) {
15951628
CHKERR(retVal);
15961629
}
15971630
}
@@ -1740,7 +1773,7 @@ void GPUDisplayBackendVulkan::pointSizeFactor(float factor)
17401773
if (mCommandBufferUpToDate[mCurrentImageIndex]) {
17411774
return;
17421775
}
1743-
float size = mDisplay->cfgL().pointSize * mDownsampleFactor * factor + (mDisplay->cfgL().smoothPoints ? SMOOTH_POINT_EXTRA_SIZE : 0.f);
1776+
float size = std::min(mDisplay->cfgL().pointSize * mDownsampleFactor * factor + (mDisplay->cfgL().smoothPoints ? SMOOTH_POINT_EXTRA_SIZE : 0.f), mMaxPointSize);
17441777
mCurrentCommandBuffer.pushConstants(mPipelineLayout, vk::ShaderStageFlagBits::eVertex, sizeof(std::array<float, 4>), sizeof(size), &size);
17451778
}
17461779

@@ -1761,11 +1794,12 @@ void GPUDisplayBackendVulkan::lineWidthFactor(float factor)
17611794
}
17621795
float width = mDisplay->cfgL().lineWidth * mDownsampleFactor * factor;
17631796
if (useSmoothLineShader()) {
1764-
width += SMOOTH_LINE_EXTRA_WIDTH;
1797+
const float expand = mStrictLines ? 1.f : 1.4143f; // Non-strict wide lines may be parallelograms, widen so that the perpendicular width is covered
1798+
width = std::min(width + SMOOTH_LINE_EXTRA_WIDTH, mMaxLineWidth / expand); // The shader must see the width that is actually rasterized
17651799
mCurrentCommandBuffer.pushConstants(mPipelineLayout, vk::ShaderStageFlagBits::eVertex, 5 * sizeof(float), sizeof(width), &width);
1766-
width *= mStrictLines ? 1.f : 1.4143f; // Non-strict wide lines may be parallelograms, widen so that the perpendicular width is covered
1800+
width *= expand;
17671801
}
1768-
mCurrentCommandBuffer.setLineWidth(width);
1802+
mCurrentCommandBuffer.setLineWidth(std::min(width, mMaxLineWidth));
17691803
}
17701804

17711805
void GPUDisplayBackendVulkan::needRecordCommandBuffers()

0 commit comments

Comments
 (0)