Skip to content

Commit c548f2c

Browse files
committed
GPU Display: Many minor fixes suggested by Claude
1 parent 7f25ca0 commit c548f2c

19 files changed

Lines changed: 177 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: 56 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,11 @@ void GPUDisplayBackendVulkan::ExitBackendA()
13991403
}
14001404
clearTextureSampler();
14011405
clearDevice();
1406+
mCommandInfrastructureCreated = false;
1407+
mImageCount = 0;
1408+
mLastPresentId = 0;
1409+
mSwapChainSuboptimal = 0;
1410+
mFrameSkipped = false;
14021411
}
14031412

14041413
// ---------------------------- USER CODE ----------------------------
@@ -1419,10 +1428,14 @@ void GPUDisplayBackendVulkan::loadDataToGPU(size_t totalVertizes)
14191428
{
14201429
mDevice.waitIdle();
14211430
clearVertexBuffers();
1422-
mVBO = createBuffer(totalVertizes * sizeof(mDisplay->vertexBuffer()[0][0]), mDisplay->vertexBuffer()[0].data(), vk::BufferUsageFlagBits::eVertexBuffer, 1);
1431+
if (totalVertizes) { // Zero-size buffers are invalid (empty event)
1432+
mVBO = createBuffer(totalVertizes * sizeof(mDisplay->vertexBuffer()[0][0]), mDisplay->vertexBuffer()[0].data(), vk::BufferUsageFlagBits::eVertexBuffer, 1);
1433+
}
14231434
if (mDisplay->cfgR().useGLIndirectDraw) {
14241435
fillIndirectCmdBuffer();
1425-
mIndirectCommandBuffer = createBuffer(mCmdBuffer.size() * sizeof(mCmdBuffer[0]), mCmdBuffer.data(), vk::BufferUsageFlagBits::eIndirectBuffer, 1);
1436+
if (mCmdBuffer.size()) {
1437+
mIndirectCommandBuffer = createBuffer(mCmdBuffer.size() * sizeof(mCmdBuffer[0]), mCmdBuffer.data(), vk::BufferUsageFlagBits::eIndirectBuffer, 1);
1438+
}
14261439
mCmdBuffer.clear();
14271440
}
14281441
needRecordCommandBuffers();
@@ -1456,25 +1469,27 @@ uint32_t GPUDisplayBackendVulkan::drawVertices(const vboList& v, const drawType
14561469
return count;
14571470
}
14581471

1459-
void GPUDisplayBackendVulkan::prepareDraw(const hmm_mat4& proj, const hmm_mat4& view, bool requestScreenshot, bool toMixBuffer, float includeMixImage)
1472+
bool GPUDisplayBackendVulkan::prepareDraw(const hmm_mat4& proj, const hmm_mat4& view, bool requestScreenshot, bool toMixBuffer, float includeMixImage)
14601473
{
14611474
if (mDisplay->updateDrawCommands() || toMixBuffer || includeMixImage > 0) {
14621475
needRecordCommandBuffers();
14631476
}
14641477

1478+
if (includeMixImage > 0.f && mFrameSkipped) {
1479+
return false; // The render to the mix buffer of this frame did not get an image
1480+
}
14651481
if (includeMixImage == 0.f) {
14661482
mCurrentFrame = (mCurrentFrame + 1) % mFramesInFlight;
14671483
waitTimeline(mFrameTimelineValue[mCurrentFrame]);
14681484
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
14691485
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) {
1486+
handleSwapChainResult(retVal, 1);
1487+
if (retVal != vk::Result::eTimeout && retVal != vk::Result::eErrorOutOfDateKHR) {
14731488
CHKERR(retVal);
14741489
}
14751490
}
1476-
auto getImage = [&]() {
1477-
return mDevice.acquireNextImageKHR(mSwapChain, UINT64_MAX, mImageAvailableSemaphore[mCurrentFrame], VkFence(VK_NULL_HANDLE), &mCurrentImageIndex);
1491+
auto getImage = [&]() { // Timeout so that a hidden window cannot block the thread (which may also dispatch the window system events) forever
1492+
return mDevice.acquireNextImageKHR(mSwapChain, 100'000'000, mImageAvailableSemaphore[mCurrentFrame], VkFence(VK_NULL_HANDLE), &mCurrentImageIndex);
14781493
};
14791494

14801495
vk::Result retVal = vk::Result::eSuccess;
@@ -1491,8 +1506,13 @@ void GPUDisplayBackendVulkan::prepareDraw(const hmm_mat4& proj, const hmm_mat4&
14911506
if (mustUpdateSwapChain) {
14921507
recreateRendering(requestScreenshot, toMixBuffer);
14931508
retVal = getImage();
1509+
mMustUpdateSwapChain = false;
1510+
}
1511+
handleSwapChainResult(retVal, 2);
1512+
mFrameSkipped = retVal == vk::Result::eTimeout || retVal == vk::Result::eNotReady || retVal == vk::Result::eErrorOutOfDateKHR;
1513+
if (mFrameSkipped) {
1514+
return false;
14941515
}
1495-
mMustUpdateSwapChain = retVal == vk::Result::eSuboptimalKHR;
14961516
CHKERR(retVal);
14971517
waitTimeline(mImageTimelineValue[mCurrentImageIndex]); // Previous frame using this image's resources (command buffers, uniform buffer, ...) finished
14981518
if (mPresentFences.size()) { // Previous present of this image done, its present semaphore can be signaled again
@@ -1519,6 +1539,20 @@ void GPUDisplayBackendVulkan::prepareDraw(const hmm_mat4& proj, const hmm_mat4&
15191539
if (!mCommandBufferUpToDate[mCurrentImageIndex]) {
15201540
startFillCommandBuffer(mCurrentCommandBuffer, mCurrentImageIndex, toMixBuffer);
15211541
}
1542+
return true;
1543+
}
1544+
1545+
void GPUDisplayBackendVulkan::handleSwapChainResult(vk::Result retVal, uint8_t suboptimalBit)
1546+
{
1547+
if (retVal == vk::Result::eErrorOutOfDateKHR || (retVal == vk::Result::eSuboptimalKHR && !(mSwapChainSuboptimal & suboptimalBit))) {
1548+
mMustUpdateSwapChain = true;
1549+
if (retVal == vk::Result::eSuboptimalKHR) {
1550+
mSwapChainSuboptimal |= suboptimalBit;
1551+
}
1552+
}
1553+
if (retVal == vk::Result::eSuccess && !mMustUpdateSwapChain) {
1554+
mSwapChainSuboptimal &= ~suboptimalBit;
1555+
}
15221556
}
15231557

15241558
void GPUDisplayBackendVulkan::finishDraw(bool doScreenshot, bool toMixBuffer, float includeMixImage)
@@ -1588,10 +1622,13 @@ void GPUDisplayBackendVulkan::finishFrame(bool doScreenshot, bool toMixBuffer, f
15881622
presentFenceInfo = vk::SwapchainPresentFenceInfoKHR{1, &mPresentFences[mCurrentImageIndex], presentInfo.pNext};
15891623
presentInfo.pNext = &presentFenceInfo;
15901624
}
1591-
vk::Result retVal = mGraphicsQueue.presentKHR(&presentInfo);
1592-
if (retVal == vk::Result::eErrorOutOfDateKHR || retVal == vk::Result::eSuboptimalKHR) {
1593-
mMustUpdateSwapChain = true;
1594-
} else {
1625+
vk::Result retVal;
1626+
{
1627+
std::lock_guard<std::mutex> guard(mQueueMutex);
1628+
retVal = mGraphicsQueue.presentKHR(&presentInfo);
1629+
}
1630+
handleSwapChainResult(retVal, 4);
1631+
if (retVal != vk::Result::eErrorOutOfDateKHR) {
15951632
CHKERR(retVal);
15961633
}
15971634
}
@@ -1740,7 +1777,7 @@ void GPUDisplayBackendVulkan::pointSizeFactor(float factor)
17401777
if (mCommandBufferUpToDate[mCurrentImageIndex]) {
17411778
return;
17421779
}
1743-
float size = mDisplay->cfgL().pointSize * mDownsampleFactor * factor + (mDisplay->cfgL().smoothPoints ? SMOOTH_POINT_EXTRA_SIZE : 0.f);
1780+
float size = std::min(mDisplay->cfgL().pointSize * mDownsampleFactor * factor + (mDisplay->cfgL().smoothPoints ? SMOOTH_POINT_EXTRA_SIZE : 0.f), mMaxPointSize);
17441781
mCurrentCommandBuffer.pushConstants(mPipelineLayout, vk::ShaderStageFlagBits::eVertex, sizeof(std::array<float, 4>), sizeof(size), &size);
17451782
}
17461783

@@ -1761,11 +1798,12 @@ void GPUDisplayBackendVulkan::lineWidthFactor(float factor)
17611798
}
17621799
float width = mDisplay->cfgL().lineWidth * mDownsampleFactor * factor;
17631800
if (useSmoothLineShader()) {
1764-
width += SMOOTH_LINE_EXTRA_WIDTH;
1801+
const float expand = mStrictLines ? 1.f : 1.4143f; // Non-strict wide lines may be parallelograms, widen so that the perpendicular width is covered
1802+
width = std::min(width + SMOOTH_LINE_EXTRA_WIDTH, mMaxLineWidth / expand); // The shader must see the width that is actually rasterized
17651803
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
1804+
width *= expand;
17671805
}
1768-
mCurrentCommandBuffer.setLineWidth(width);
1806+
mCurrentCommandBuffer.setLineWidth(std::min(width, mMaxLineWidth));
17691807
}
17701808

17711809
void GPUDisplayBackendVulkan::needRecordCommandBuffers()

0 commit comments

Comments
 (0)