Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use texSubImage2D if not necessary to improve performance #10383

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

gfodor
Copy link

@gfodor gfodor commented Mar 27, 2024

Description of change

This PR updates the image uploader to use texImage2D instead of texSubImage2D when possible. In testing on my phone I see a significant performance improvement with this patch.

As per this discussion at least some time in the past it was acknowledged this was a problem: https://issues.chromium.org/issues/40469618#comment85

It's unclear if the fast path has been updated appropriately for texSubImage2D after that comment but in any case the performance improvement on my test device is noticable. (CPU utilization of my app went from 120-150% to 100-120%)

Pre-Merge Checklist
  • Tests and/or benchmarks are included (needed?)
  • Documentation is changed or added (needed?)
  • Lint process passed (npm run lint)
  • Tests passed (npm run test)

Copy link

codesandbox-ci bot commented Mar 27, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 754f735:

Sandbox Source
pixi.js-sandbox Configuration

Copy link
Collaborator

@ivanpopelyshev ivanpopelyshev left a comment

Choose a reason for hiding this comment

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

There should be a flag in this resource, and default value for it.

@GoodBoyDigital
Regardless, later, we'll need to make immutable textures too - texStorage2D makes things faster for sure

@gfodor
Copy link
Author

gfodor commented Mar 31, 2024 via email

@ivanpopelyshev
Copy link
Collaborator

Actually, I dont know :) the change was introduced by @GoodBoyDigital long time ago.

@Zyie Zyie added the v8 label Apr 2, 2024
@GoodBoyDigital
Copy link
Member

GoodBoyDigital commented Apr 2, 2024

this is an interesting one.

texImage2D: This function is used to define a two-dimensional texture image. It can initialize a texture from an array of data or from an HTML element (like img, canvas, video). When you call texImage2D, you're essentially creating a new texture or reinitializing an existing one, which includes allocating memory for the texture. If you are repeatedly calling texImage2D to update a texture with new images or data, it can be less efficient because it involves reallocating texture memory each time it's called.

texSubImage2D: This function updates a subset of a two-dimensional texture image, and it can be more efficient for updating textures because it does not require the texture's memory to be reallocated. Instead, it reuses the existing texture's memory allocation. This makes texSubImage2D particularly useful for scenarios where you need to frequently update textures with new data (like streaming video frames into a texture or updating a texture atlas), as it can offer better performance by avoiding unnecessary memory allocations.

on paper we should always strive for texSubImage2D.. but seems that might not be entirely true now?

@gfodor
Copy link
Author

gfodor commented Apr 2, 2024 via email

@GoodBoyDigital
Copy link
Member

i think @ivanpopelyshev has the best idea - lets add a flag to texture source. False by default, but make it true for video textures?
that way users have the options.

@gfodor would you mind updating the PR pls? Thanks man!!

@gfodor
Copy link
Author

gfodor commented Apr 11, 2024 via email

@GoodBoyDigital
Copy link
Member

following up on this one @gfodor - would be great to have this when you get some time! Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants