Repository navigation
Conversation
|
there are were many headaches around the type conversion which aren't well documented... but I got to the cube in the end. self._internal.getMappedRange(offset=js_offset, size=data.nbytes)vs self._internal.getMappedRange(0, size)And the error you get is about browser_cube.mp4I will hopefully find some more time this coming week to continue and maybe get some more interesting examples to run (pygfx?/fastplotlib?). |
|
super exciting to get imgui working with a few tweaks imgui_example.mp4cc @pthom thanks a lot for your article I read a few weeks ago, that motivated me to give it a try here! |
|
@Vipitis : many thanks for the info, that looks very promising. Please keep me in the loop! |
|
I was expecting codegen to come a long way here. The codegen knows when the arguments of a function were actually wrapped in a dict in IDL, so we can generate the code to reconstruct the dict before passing it to the JS WebGPU API call. |
|
I also think that codegen can do a lot, I just need to give it a try. The def some_function(self, *args, **kwargs):
js_args = to_js(args, eager_converter=js_acccessor)
js_kwrags = to_js(kwargs, eager_converter=js_accessor, dict_converter=Object.from_entries)
self._internal.someFunction(*js_args, js_kwargs) |
|
Whatever way this goes, what I care most about, is that when the IDL changes for a certain method, it will place some FIXME comment in the code for the JS backend, so that we won't forget to update that method there. |
|
I feel like I have finally moved passt all the headaches and found a "general" approach to most functions. I switched to the pyodide dev branch as the upcoming 0.29 release makes changes to how dictionaries are converted... which has been a ton of pain and the upcoming version seems to work much better. I couldn't find any release timeline so it might still be month until there is a release... Also got started with a codegen prototype and I am feeling confident this is largely going to work, depends on how much time I find in the coming week. There was also some weirdness with css scaled canvas for click events and resizing with the imgui example - so the rendercanvas PR likely needs some more fixes, I will see if I can find time for that too. |
|
@Vipitis are the stack switching problems you mentioned related to the async methods? Are there any other bottlenecks left? |
|
@Alex-PLACET from what I can see pyjs has nothing to do with pyodide, right? I suspect it would need its own backend, or maybe it can be made to Just Work with the compiled backend. Do you know whether pyjs compiles to Emscriptem or Wasi? |
|
@almarklein pyjs is used in emscripten-forge packages, not pyodide. |
Yes stack switching enables the pyodide
There will be more issues, especially along the spec/native divide and doing zero copies for performance etc. But I'd say the majority of examples already work with no changes to usercode. |
|
@Vipitis @Alex-PLACET it looks like it would be possible to support the browser through wgpu! This would require a new version of Emscripten released just last week. I have a POC that suggest that it works, but to tell for sure, we'd need to wait for Pyodide to adopt that new Emscripten version. It would also require a change in how the binding works; we'd need an extension module instead of a dll that we cfii into, but we want to go there anyway for other reasons (performance being one). |
|
that will be interesting to see. But is this wgpu directly or wgpu-native? My understanding was that wgpu already compiles to wasm (maybe compatible with pyodide on the newer releases), but wgpu-native currently doesn't. (perhaps that is also possible soon?). If it's the former, won't we need the whole mapping layer to wgpu? |
|
@almarklein can you tell us more, which version of emscripten is needed ? On Emscripten-forge we are currently moving to 6.0.8 |
Either, really, as long as its compiled as an extension module. Though I am leaning towards binding to wgpu directly via pyo3.
Good to know you're moving to 6.0.8! Current research status:
I'll post more details later, when I submit my PR to wgpu. |
|
@almarklein Ok, don't hesitate to ping me on your pullrequest. I will check on my side if we can move to 6.0.10 soon. |
That could be nice to be able to test our new backend. Though I imagine much more is needed to run wgpu-py in PyJS, being fully typed and all that?
Just to be clear, we still have to develop the new wgpu-pyo3 backend first :) I think it's worth continuing with the current PR, since it's already close, and it means we can compare the two approaches and select the "best" one eventually. For PyJS it's probably easier to wait for the new backend. |
…raised correctly)
| # print("Git status:\n" + git_status) | ||
| for line in git_status.splitlines(): | ||
| assert not line.strip().startswith("M wgpu/"), "Git has open changes!" | ||
| assert not line.strip().startswith("M wgpu/resources/"), "Git has open changes!" |
There was a problem hiding this comment.
I suppose this is done temporary during dev. Would be good to have a proper way for this 🤔
There was a problem hiding this comment.
I have to check the commits, but something was complaining when building the wheel. IIRC it might have been the codegen report being different because I skipp the C codegen (which takes a bit) when launching pyodide examples
…n imgui, pygfx picking buffer and buffers not unmapping.
|
Idea: rather than try to codegen as much as we can, only codegen the public API. The rest is manual code (we can simply use the currently generated api). Then, we use mypy to validate that we use the WebGPU API correctly. How? We generate the JS WebGPU API, but in typed Python. So we get a Maybe use this for the new wgpu backend also: less/simpler codegen, rely on validation by using types. |
|
That sounds like a good approach and maybe what I was going for in a more convoluted way (using the struts for descriptors to handle default values). I am currently hunting down a race condition where a buffer isn't unmapped before submission and I am not sure if this is a pyodide bug (hoping for 315 to just fix all of it magically). It's happening during FPL examples that use imgui when you right click. And the pygfy get pixel info call is happening multiple times (maybe during an event callback?). pygfx ensures the unmap with |
|
What browser do you use to test it on? If Chrome, you're essentially testing against Dawn, which may behave slightly differently than wgpu ... could be worth checking race conditions like that on both FF and Chrome. |
|
I think there finally is a solution to the Didn't get to test all examples in pygfy or fpl yet, but at least the right click menus now work... so maybe this is it? Perhaps it would help to run test suites with pyodide to see where remaining problems are. |
docs preview
Potentially remaining tasks
jswriter.pyas aPatcherand add the comment injectortexture.create_view()is might be the wrong dimension : local pyodide preview fastplotlib/fastplotlib#1052 (comment)new weekend, new project...
I think there is two options to get wgpu-py into the browser: compile wgpu-native for wasm and package that, or call the js backend directly. I run into compilation errors with the rust code, so gave up there... but:
basically autocompleted my way through errors to see what kind of patterns are needed... everything around moving data requires more effort. While pyodide provides some functions, they feel buggy and unpredictable.
It is likely possible to codegen the vast majority of this and then fix up all the api diff - might get to that over the next few days.
structs have potential to make this easier.
I changed some of the examples to auto layout since I couldn't get
.create_bindgroup_layout()to work - and you don't need it with auto layout.works with pygfx/rendercanvas#115

couldn't get the cube example to work just yet, but triangle does - so the potential is there
more to come