Skip to content

Move fetched texture preparation to fetch worker - #6056

Open
LisaScheers wants to merge 10 commits into
secondlife:developfrom
LisaScheers:lis/async-non-upload-alpha-analysis
Open

Move fetched texture preparation to fetch worker#6056
LisaScheers wants to merge 10 commits into
secondlife:developfrom
LisaScheers:lis/async-non-upload-alpha-analysis

Conversation

@LisaScheers

Copy link
Copy Markdown
Contributor

Stack

Depends on #6031. This is a stacked follow-up; the follow-up change is the commit Move fetched texture preparation to fetch worker. The diff against develop will shrink when #6031 merges.

What changed

  • Queue alpha histogram and pick-mask preparation on the texture fetch worker after decode.
  • Carry preparation beside the exact decoded raw buffer through the fetch handoff and skip the redundant General-queue job.
  • Validate or invalidate preparation for stale, scaled, and local buffers while retaining the existing fallback.
  • Request early preparation only for eligible upload textures.

Why

analyzeAlpha() can take multiple milliseconds. #6031 removes it from the frame-critical GL path; this follow-up performs the work earlier on the fetch worker so main-thread upload scheduling does not need another preparation hop.

Validation

  • ReleaseOS universal viewer configured with Xcode and LL_TESTS=ON.
  • INTEGRATION_TEST_llimagegl_prepare: 4/4 passed.
  • Full secondlife-bin universal Release target: passed.

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

This PR advances the texture pipeline optimization stack by moving CPU-side upload preparation (alpha classification and pick-mask generation) earlier into the texture fetch worker flow, reducing main-thread scheduling overhead and avoiding redundant “General” queue preparation hops.

Changes:

  • Threads LLImageGL::TextureUploadPreparation alongside decoded raw buffers through LLTextureFetchLLViewerFetchedTexture to apply preparation directly before GL texture creation.
  • Adds LLImageGL::prepareForUpload() plus plumbing to apply/discard prepared metadata and skip re-running analyzeAlpha() / updatePickMask() when prepared.
  • Introduces an integration test validating preparation behavior (including odd dimensions) and wires it into llrender when LL_TESTS is enabled.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
indra/newview/llviewertexture.h Extends fetched-texture creation scheduling APIs to accept precomputed upload preparation metadata.
indra/newview/llviewertexture.cpp Applies/invalidates preparation during fetch-result processing and texture creation scheduling; retains a fallback worker path when needed.
indra/newview/lltexturefetch.h Extends fetch APIs to return and optionally compute upload preparation on the fetch side.
indra/newview/lltexturefetch.cpp Stores preparation in fetch workers, schedules preparation on the fetch request queue after decode, and hands results back to consumers.
indra/llrender/llimagegl.h Introduces TextureUploadPreparation struct and new APIs for preparation/apply/discard.
indra/llrender/llimagegl.cpp Implements preparation logic, consumes prepared results in setImage(), and updates pick-mask sizing math.
indra/llrender/tests/llimagegl_prepare_test.cpp Adds coverage for alpha classification and pick-mask packing, including odd width/height cases.
indra/llrender/CMakeLists.txt Registers the new integration test under LL_TESTS.
Comments suppressed due to low confidence (1)

indra/newview/lltexturefetch.cpp:2842

  • Same implicit-conversion concern as above: pass raw_image.get() explicitly when calling callbackUploadPreparation() in the fallback path.
        LLTextureFetchWorker* worker = getWorker(id);
        if (worker)
        {
            worker->callbackUploadPreparation(raw_image, {});
        }

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

Comment thread indra/newview/lltexturefetch.h
Comment thread indra/newview/lltexturefetch.cpp
# Conflicts:
#	indra/llrender/llimagegl.cpp
#	indra/llrender/llimagegl.h
#	indra/llrender/tests/llimagegl_prepare_test.cpp
#	indra/newview/llviewertexture.cpp
@LisaScheers
LisaScheers marked this pull request as ready for review July 27, 2026 20:17

@akleshchev akleshchev 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.

This doesn't seem to work right. I tried to upload a texture, scheduleUploadPreparation didn't get hit. I rezzed an abject and that triggered scheduleUploadPreparation. I'm not doing any uploading, yet I'm hitting upload preparation in scheduleCreateTexture.

At a minimum the naming is wrong and confusing (TextureUploadPreparation is no longer about upload), but from a 'mechanics' stadpoint, fetcher is already a thread with a bunch of workers, it should be issuing jobs to its own workers, not to the general pool. Or calculations can be done by/after decoder.

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