Improve Linux/Mesa support#12
Open
jonpepler wants to merge 1 commit into
Open
Conversation
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.
Fix Hullcam frame capture on Linux / Mesa (all-white JPEGs)
Hullcam frames arrive as all-white JPEGs on native Linux installs (tested: Steam Deck SteamOS 3.x, native KSP 1.12.5 Linux). Metadata (camera name, speed, altitude) flows correctly; only the rendered pixels are broken.
Three bugs in
TrackingCamera.SendCameraImage()compound on Linux where they happen to be masked on Windows/D3D:Graphics.CopyTexture(RT, Tex2D)followed byAsyncGPUReadback.Request(Tex2D, 0)relies on the driver implicitly synchronising the GPU→GPU copy before the readback. Mesa's OpenGL driver doesn't guarantee that ordering; readback returns without error but the destinationTexture2Dcontains uninitialised pixels - which read back as pure white in ARGB32.Task.Run+ContinueWithrunningLoadRawTextureDataandEncodeToJPGoff the main thread. Unity's texture APIs are main-thread-only per Unity's docs. D3D tolerates it; Mesa doesn't.request.GetData<byte>()into aTaskclosure. The returnedNativeArray<byte>is only valid inside the readback callback's synchronous scope; once it returns the backing allocation is disposed. The.ContinueWiththread-pool task reads freed memory.Diagnostic evidence
A debug build logging
AsyncGPUReadback.Request(TargetCamRenderTexture, 0, …)directly (skipping theGraphics.CopyTextureintermediate) showed 100% of readbacks returninghasError=trueon Mesa. The upstream copy-to-Tex2D-first path sidesteps that specific error but loses the pixel data a different way, hence all-white frames rather than no frames at all.Fix
Replace the async dance with the canonical synchronous capture pattern:
Synchronous
ReadPixelsblocks the main thread for ~1–2 ms per Hullcam frame at 768x768.Compatibility
Strictly better-behaved on all platforms, not Linux-specific. Windows/D3D users see identical results with no regression.
Testing