Skip to content

Add multipass pass support (buffers A-D) #43

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

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open

Add multipass pass support (buffers A-D) #43

wants to merge 23 commits into from

Conversation

Vipitis
Copy link
Collaborator

@Vipitis Vipitis commented Mar 17, 2025

the main part of #30

improvements over #30

with wgpu-py>=0.21 we can actually setup a swap chain with back/front textures by making use of view-usages. This avoids doing a texture to texture copy for every single render target (could be 5 per frame) and should be much faster. We do however need to redo the bind groups and render pipeline every single frame. I might explore to only have two bind group/render pipeline s and just swapping between then - it feels faster and might work but could be way more complex with some shaders that use all four buffers with reflexivity.

status

works and performs great, ready for review

todos: (might add more)

  • add additional examples (likely via json again)
  • make tests work
  • add additional tests (be aware of default device features ref: rework testsuite #31)
  • explain the user-facing API
  • figure out resizing (might be a copy to CPU, or a compute shader, or a some view/offset?)
  • document changes
  • require newer wgpu-py release!
  • cleanup

@Vipitis
Copy link
Collaborator Author

Vipitis commented Mar 21, 2025

it generally works, but I have tried a few complex shadertoys and run into various issues. For example this one https://www.shadertoy.com/view/Wf2SWK filickers really badly. I believe this might be an order of operations issue due to when we swap and when it actually gets drawn. Will need to look for more diagnostic shaders or write something myself.

Another issue could be initialization/clearing

@Vipitis Vipitis changed the title [WIP] Add multipass pass support (buffers A-D) Add multipass pass support (buffers A-D) Apr 3, 2025
@Vipitis
Copy link
Collaborator Author

Vipitis commented Apr 3, 2025

Should be nearly ready for review.
I made a little script to look for a good example and came across a shader with some odd issues, didn't have the time to dig around but I doubt it's directly related to how buffers are implemented: https://www.shadertoy.com/view/4dcGW2

(looks like the screenshot differs because of the difference in channel order. It used to be bgra hardcoded and can no change based on device to the perferred format. the existing screenshot is the wrong order anyway, so needs to be updated. But I think either the .snapshot method or the testing script should normalize it to RGB(A) based on ._format - will try this approach tomorrow)

@Vipitis Vipitis marked this pull request as ready for review April 3, 2025 22:39
@Vipitis
Copy link
Collaborator Author

Vipitis commented Apr 6, 2025

(looks like the screenshot differs because of the difference in channel order. It used to be bgra hardcoded and can no change based on device to the perferred format. the existing screenshot is the wrong order anyway, so needs to be updated. But I think either the .snapshot method or the testing script should normalize it to RGB(A) based on ._format - will try this approach tomorrow)

Turns out: it used to be bgra hardcoded, which no longer worked with offscreen in wgpu>0.19. So this PR moving to 0.21.1 needed to use the preferred (and more importantly a supported) format. Same root cause as pygfx/wgpu-py#698 actually

@Vipitis
Copy link
Collaborator Author

Vipitis commented May 7, 2025

@Korijn can you help with a review for this?

from .shadertoy import Shadertoy

__version__ = "0.1.0"
version_info = tuple(map(int, __version__.split(".")))
version_info = tuple(map(int, __version__.split("."))) # noqa
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a hint, you can keep your code clean from # noqa using the section at the bottom of your pyproject.toml file where you already have this:

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]

Just extend it with the specific warning you want to ignore.

Copy link
Contributor

@Korijn Korijn left a comment

Choose a reason for hiding this comment

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

I couldn't find any significant problems just by looking at the code. draw() where the texture swap happens looks super simple and elegant. Nice work!!

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

Successfully merging this pull request may close these issues.

2 participants