-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Refactor canvas context to allow presenting as image #586
Merged
Conversation
This file contains 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
almarklein
changed the title
Refactor canvas context to allow presening as image
Refactor canvas context to allow presenting as image
Sep 16, 2024
I have more plans with the GUI subpackage, but I'll apply/propose these in separate pr's. |
@Korijn this is ready for review. |
Korijn
reviewed
Sep 20, 2024
Korijn
approved these changes
Sep 20, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice improvements!
10 tasks
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.
Background
This is a first step in the "update propagation" work. One of the goals of that work is to clearly separate rendering from events. And thus webgpu API from canvas API. A thought that played through my mind was to implement the
wgpu.gui
in a separate package. I don't think I want to go that far (for now), but I definitely want to avoid leaking any wgpu-specifics into the gui subpackage.Problem
The CanvasContext is the thing that ties webgpu and the gui layer together. It enables webgpu to draw into a GUI window. This works ok as it is, but e.g. the offscreen canvas implements its own version of a CanvasContext, which is an abstraction leak.
Proposal
This PR refactors the
CanvasContext
as well as theWgpuCanvasInterface
so that the canvas can indicate how it wants the canvas to draw into it. It can either let it draw to the screen, or provide the canvas with the resulting image.This makes offscreen canvases less special, so they won't have to hack their own fake context. It also allows other canvases to use images where it makes sense, e.g. a Tk backend, or Qt on Wayland, etc.
Details
The
WgpuCanvasInterface.get_surface_info()
returns a dict. That dict has at least a "method" field, which is either "screen" or "image". When it is "screen", it also provides "window" (and "display" too on Linux), like it did before. The dict can also provide capabilities like "formats" to indicate supported texture formats.The
WgpuCanvasInterface.present_image()
method must be implemented if a canvas wants to support the image method.Benchmarks
FPS measurements (with
max_fps=999
). Shown are fps for screen / image. Using a light scene (cube) and a heavy one (sponza).Observations:
Remarks:
Tasks
Can we get rid oflaterCanvasContext.present()
, since its not official webgpu api?Changelog
WgpuOffscreenCanvasBase
class is removed. Offscreen canvases can be implemented by returning the appropriate dict incanvas.get_surface_info()
and implementingcanvas.present_image()
.canvas.get_surface_info()
method is renamedcanvas.get_present_info()
and must the returned dict has new specifications.canvas.present_image()
method can be implemented to support presenting via an image.