Skip to content

Move texture upload preparation off the main thread - #6031

Merged
akleshchev merged 5 commits into
secondlife:developfrom
LisaScheers:lis/sl-async-texture-preparation
Jul 27, 2026
Merged

Move texture upload preparation off the main thread#6031
akleshchev merged 5 commits into
secondlife:developfrom
LisaScheers:lis/sl-async-texture-preparation

Conversation

@LisaScheers

@LisaScheers LisaScheers commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Description

Moves fetched-texture alpha classification and pick-mask generation off the frame-critical path when shared-context texture uploads are disabled.

The existing General worker pool computes the CPU-only upload metadata, then the main thread consumes it immediately before the GL upload. Explicit texture formats, unavailable queues, and shared-context uploads retain their existing paths. Prepared metadata is discarded if an upload becomes redundant.

A native Apple Silicon profile of the closely related Firestorm viewer placed LLViewerTextureList::updateImagesCreateTextures() on roughly 9% of main-thread samples, with LLImageGL::analyzeAlpha() and pick-mask generation running inside setImage(). The official develop branch contains the same code path.

Related Issues

  • Please link to a relevant GitHub issue for additional context.

Issue Link: None; opened as a draft for upstream performance evaluation.


Checklist

  • I have provided a clear title and detailed description for this pull request.
  • If useful, I have included media such as screenshots and video to show off my changes.
  • The PR is linked to a relevant issue with sufficient context.
  • I have tested the changes locally and verified they work as intended.
  • All new and existing tests pass.
  • Code follows the project's style guidelines.
  • Documentation has been updated if needed.
  • Any dependent changes have been merged and published in downstream modules.
  • I have reviewed the contributing guidelines.

Additional Notes

Validation performed:

  • clean git diff --check
  • exact stable patch-ID match with the Firestorm implementation
  • code-path review confirming the worker fallback and stale-result behavior

A full official viewer build was not available because this host lacks the autobuild dependency bundle and full Xcode toolchain. This remains a draft pending native build and benchmark coverage.

@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR introduces an asynchronous “upload preparation” step for textures, precomputing alpha-mask analysis and pick-mask generation off the main thread and applying the results during GL upload.

Changes:

  • Added LLImageGL::TextureUploadPreparation and APIs to prepare/apply/discard upload precomputation state.
  • Updated LLImageGL::setImage() to consume prepared results and skip redundant alpha/pick-mask work.
  • Updated LLViewerFetchedTexture::scheduleCreateTexture() to enqueue background preparation for eligible textures.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
indra/newview/llviewertexture.cpp Schedules background upload preparation and applies it before enqueuing texture creation.
indra/llrender/llimagegl.h Adds the upload-preparation struct, methods, and new members to store preparation state.
indra/llrender/llimagegl.cpp Implements preparation logic, integrates it into setImage(), and refactors alpha mask analysis into a helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread indra/llrender/llimagegl.cpp
Comment thread indra/llrender/llimagegl.cpp Outdated
Comment thread indra/llrender/llimagegl.cpp
Comment thread indra/llrender/llimagegl.cpp Outdated
@github-actions github-actions Bot added the cmake label Jul 27, 2026
Comment thread indra/llrender/llimagegl.cpp
@akleshchev
akleshchev requested a review from Copilot July 27, 2026 17:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread indra/llrender/llimagegl.h
@akleshchev akleshchev linked an issue Jul 27, 2026 that may be closed by this pull request
LisaScheers added a commit to LisaScheers/viewer that referenced this pull request Jul 27, 2026
@akleshchev

Copy link
Copy Markdown
Contributor

Thank you for the contribution! Merging.

@akleshchev
akleshchev merged commit 1c81813 into secondlife:develop Jul 27, 2026
12 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 27, 2026
@secondlife secondlife unlocked this conversation Jul 27, 2026
@akleshchev

akleshchev commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

I think you forgot mNeedsAlphaAndPickMask=false somewhere, a single image keeps restarting prepareForUpload job. Might also need a 'job created flag'.

Or forgot to hook up mAlphaAnalyzed and mPickMaskPrepared

@akleshchev

Copy link
Copy Markdown
Contributor

Sorry, but I'm going to revert this. I checked how this works in more detail and not only it doesn't work right, this is a very focused uploads-only solution for a general, upload-independent problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize LLImageGL::analyzeAlpha

3 participants