Repository navigation
fix(platform): draw lines wider than a texture from a window of them on Windows and Linux - #50
Merged
Merged
Conversation
…on Windows and Linux A monospaced or run-colored line of thousands of characters, such as a log line shown unwrapped, is wider than the 16384 device pixels a label texture holds: 4096 cells of 8 pixels at 150% are 49152. The Windows and Linux renderers rasterized such lines whole, so the frame asked for a texture past the bound, the error came back from the frame, and the window drew nothing again. macOS already draws these lines from a window of them (vivaui#178). Every renderer now picks that window by the same rule (platform.WideTextLabelWindow, the one viva_label_window keeps in native.m): the columns the viewport and the label's clip show, with as much margin on each side as they are wide, and the texture is kept while a scroll stays inside it. The skip is a whole number of device columns, so no glyph moves. Grid lines draw their pieces and ClearType spans from that skip, and the Direct2D batch, the label picture cache, the Vulkan uploader and the CPU scene all key on the window. A label no texture can hold, a line taller than one or an image larger than one, is now left undrawn instead of failing the frame, so one such label no longer stops the window drawing the others. Lithe reported the crash when opening a language server's log on Windows (1lck/Lithe-IDEA#2227).
This was referenced Nov 20, 2026
15 of 18 tasks
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upstream: vivaui#375 (the same commit on upstream
main54981a3c). This branch is that commit cherry-picked onto the fork'smain(d354e3c8). None of the 22 files it changes differ between the two bases. On this branch:go build ./...,go test ./internal/platform/... ./ui/... ./app/...on macOS, andgo vet ./internal/platform/... ./app/for windows and linux on amd64 and arm64 all pass.What this changes
A text label wider than the 16384 device pixels a texture holds, a monospaced or run-colored line included, is now drawn on Windows and Linux from a window of it, as macOS has drawn it since vivaui#178. A label no texture can hold is left undrawn instead of failing the frame.
internal/platformhas the rule every renderer uses:LabelTextureLimit/LabelTexturePixelsname the bound the backends already used.LabelTextureWidth(height)is the widest texture a label of that height gets.LabelTextureFitstests a size against it without a division, since it is asked of every label every frame.WideLabelWindowis the windowviva_label_windowinnative.mchooses: the visible columns, with as much margin on each side as they are wide, kept while a scroll stays inside the texture.WideTextLabelWindowgets the visible columns from the viewport and the label's clip.ShiftGridSpansmoves a grid line's ClearType spans onto the window.labelTexture.windowtakes the target's width. A label one texture holds pays aLabelTextureFitstest and keeps the window it had before. A wider line of any kind gets the wide window.gridandgridLCDdraw their pieces from-skip, the ClearType spans are planned in the line's columns and shifted onto the texture, and the per-span cut addslabel.skip.needsRastergathers the conditionsdrawandprepareLabelstested separately.rasterizeleaves a label without a texture instead of returninglabel texture exceeds bounded size.vulkanLabelTexturekeeps the window (skip,wide) and adroppedflag.needsUploadrasterizes a wide line again only when the visible columns leave its texture. A label scrolled out of view, or too tall for any texture, is not rasterized again every frame.textViewportis the frame's content width.textWindowpicks the same window. The soft scene draws a wide line again only when that window moves, andplaceLabeloffsets the picture byskip.-skip.drawRunsskips runs outside the window, and of a printable ASCII run draws only the cells in it, plus one either side for an italic's overhang.The skip is a whole number of device columns, so every glyph keeps the phase it has in the whole line.
Why
Lithe (1lck/Lithe-IDEA#2227) crashed on Windows when a language server's log was opened. The log shows lines unwrapped, and one of 4096 characters at 8 logical pixels a cell and 150% is 49152 device pixels wide. The Windows renderer rasterized a Mono or Runs label whole, so the frame returned
rasterize label N: windows: label texture exceeds bounded size, and the window loop stopped drawing anything again.textServices.drawon Linux had the same bound and the same failure. vivaui#178 fixed this for Metal only.How it was verified
test -z "$(gofmt -l $(git ls-files '*.go'))"go vet ./...on macOS: clean apart from the existingdidModifyRange:deprecation warning innative.m.go test ./... -count=1on macOS (Apple Silicon): 126 packages pass,internal/platform/darwinincluded.cmd/vivafails identically on54981a3cwithout this change:TestGeneratedRecipesAreCurrentandTestInstalledRecipesMatchReferenceSourcefail because componentgen reportscmd/viva/templates/select.go.txtas stale onmain.platform vet:
GOOS=windowsandGOOS=linux,GOARCH=amd64andarm64,go vet ./internal/platform/... ./app/.GOOS=windows go build ./...for amd64 and arm64.Windows: run on a real Windows 11 machine (AMD64, NT 10.0.26300, D3D11 hardware device, Go 1.26.3) over SSH.
internal/platform/windowspackage: 246 pass. The same 25 fail before and after this change: Backdrop, Resize, Redraw, FileDrop, SetTitle and similar tests, which need the interactive desktop an SSH session does not have.54981a3c,TestWideMonoLineIsDrawnFromAWindowOfItandTestLabelNoTextureHoldsDoesNotFailTheFrame, written against the API there, fail withrasterize label 0: windows: label texture exceeds bounded size.Linux: a native arm64 Ubuntu 24.04 container, with Mesa lavapipe for Vulkan and Pango/Cairo for the CPU renderer.
internal/platform/linuxpackage: 390 pass before and 394 after; the 4 extra are the new tests. One test fails in both,TestEnginePassesTheTextEngineContract, on the container's fonts.TestSetTitle*were skipped in both runs: they dereference a nil X connection without a display.54981a3c. There,textServices.drawreturnslinux: label texture exceeds bounded sizefor the same line.benchmarks before and after. Base and change were interleaved: 5 rounds,
-benchtime 500ms. Median ns/op. allocs/op are the same before and after, exceptPageSwitch, whose allocations vary from run to run on both sides (batched 1455–1461 before and 1452–1478 after, per-label 1237–1419 before and 1339–1421 after):All rows are within the runs' spread. A first version computed the wide window for every label every frame and cost
LabelPicturePageSwitch/cache=true/warm=true8%. The ordinary label's early test (LabelTextureFits, no division) brought that back.stripped binary size: not measured. Nothing new links; the change is internal code.
a real window: no interactive window. The renderers were driven offscreen on the machines above.
New tests:
internal/platform:TestLabelTextureWidthKeepsTheTextureBoundedalso checks thatLabelTextureFitsagrees withLabelTextureWidthat every edge.TestLabelVisibleColumnsCutsTheClipToTheLabel,TestWideLabelWindowKeepsTheVisibleColumnsWithAMargin,TestWideTextLabelWindowFollowsTheViewportAndTheClipandTestShiftGridSpansMovesTheColumnsOntoTheWindowcover the rule.TestWideLabelWindowFollowsTheViewport: a scroll inside the texture keeps it, and one past it windows again.TestWideMonoLineWindowHoldsThePixelsOfTheLine: a window's rasterized pixels are byte for byte the pixels of the start of the line at the same columns. This covers ClearType on and off, without and with runs, unscrolled and 1000 characters scrolled.TestWideMonoLineIsDrawnFromAWindowOfIt: the same through the whole renderer.TestLabelNoTextureHoldsDoesNotFailTheFrame.TestVulkanWideLabelWindowFollowsTheViewport.TestWideMonoLineIsDrawnFromAWindowOfIt, run on Vulkan and CPU, opaque and transparent, without and with runs.TestSoftSceneDrawsAWideLineFromWhatTheCanvasShows: after each scroll, the live canvas is byte for byte a fresh paint.TestLabelNoTextureHoldsDoesNotFailTheFrame.On Windows,
TestWideMonoLineIsDrawnFromAWindowOfItallows one level per channel and the Linux one does not:TestWideMonoLineWindowHoldsThePixelsOfTheLinechecks exactly.MIN_MAG_MIP_LINEAR. A quad that starts left of the target reaches the same texel centres through a different interpolation, and the hardware's 8-bit filter weights can mix 1/256 of a neighbouring texel in.Visual evidence
TextwithMonoand a 4096-character value, in a horizontally scrolling area at 150%.TestWideMonoLineIsDrawnFromAWindowOfIt(Windows and Linux) andTestWideMonoLineWindowHoldsThePixelsOfTheLine(Windows).Where the boundary sits
Framework capability. The texture bound belongs to Viva's renderers, and any application that shows a long line reaches it. macOS already handles it in
native.m, and this gives Windows and Linux the same window rule from one shared function.Cost
Nothing for a label one texture holds. It pays one
LabelTextureFitscomparison per frame, with no division and no allocation, and keeps the window and texture it had. The benchmarks above are unchanged within their spread.