-
Notifications
You must be signed in to change notification settings - Fork 2k
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
SDL3 GPU WebGPU Backend #12046
base: main
Are you sure you want to change the base?
SDL3 GPU WebGPU Backend #12046
Conversation
…gh all of the commits were the one I just rebased... Fixed everything back up.
…PU objects aren't being released via the bindings. Might be an actual bug with Emscripten's bindings specifically, need more info. Working on a solution for uniform functions in SDL3. WebGPU BindGroups make this specific approach tough to handle. Assume uniform struct is stored at group 0 binding 0, contents should be 1 buffer FOR NOW.
Improved logging for shader creation
…ere is no reason for them to mimic the Vulkan implementation. Added GPU API checklist. Next will be vertex and fragment uniform buffers. Updated checklist
… crashes, but nothing renders properly. Need to investigate further.
…ad of individual enums.
…a bunch of existing bugs with the backend. Still encountering a layerCount issue that I cannot verify. My debugger says the texture and texture view both have 4 layers, but the error says that the texture's array layer count is 1.
…allows views of 1 layer for color attachments...
…ctionality offered in WebGPU.
… pipelines. Now we create internal SDL pipelines and everything is handled nicely. 3D texture example still works.
…gate why the sampler isn't working in the Blit2DArray example.
…no longer needed outside of the frame. Minimizes heap resizing
… more static allocations now. Static allocations only occur on named object creation, and when dealing with PipelineLayouts. Planning on refactoring PipelineLayouts later.
… the emscripten keyboard event handlers when no hint was set.
… configure the surface. Elie Michel's surface configuration logic was added but the macros don't seem to want to work for me. I've added a temporary workaround since I am only testing Emscripten anyways.
… the emscripten keyboard event handlers when no hint was set.
… configure the surface. Elie Michel's surface configuration logic was added but the macros don't seem to want to work for me. I've added a temporary workaround since I am only testing Emscripten anyways.
…atch Vulkan implementation.
…ed this problem already.
…n tested but it compiles.
…ly implemented yet, but I have worked the existing pooling logic from the other backends to work with WebGPU. Makes use of mutexes and attempts to handle fences.
Note for commit: 30bbcee The abstracted
|
…ign with the Vulkan implemetation. Updated CreateDevice and DestroyDevice.
Took a quick look at the latest. In addition to cosmonaut's unresolved review comments, I have a few additional things to mention. First, the high level, non-WebGPU stuff:
For the WebGPU-specific logic:
As a general piece of advice, I highly recommend looking at all 3 backends (Vulkan, D3D12, Metal) when implementing a new system / filling out a new function to see how they each work. Metal is probably better to copy off of than Vulkan since it's a closer match for the higher-level WebGPU API, but please try to understand why we did things a certain way before copying them wholesale into the WebGPU driver. On that note, I strongly encourage you to ask questions if you're not totally sure why something is the way it is. We'll gladly fill you in on the rationale. You do not have to (and should not!) reinvent the wheel for this driver. |
Thanks for the feedback! As for the non-webgpu stuff I was planning on grabbing fresh copies of the upstream files and then force pushing them to fix that the diff issue. As for the WebGPU related things, I'll gladly revert the caching changes since they bloat the tab memory footprint significantly. I still haven't touched the shader binding logic but I took notes based on the shader wiki and have it as the biggest TODO on my list. I'll take a closer look at the Metal backend over the course of my break this week and hopefully get lots done! |
Description
Congrats on shipping SDL 3.20, and officially releasing SDL3!
Now that SDL3 has been released, I have decided to open a PR for my work for the WebGPU backend as suggested by @flibitijibibo.
Attached is a checklist of the API methods, as well as a checklist of working examples. (As of 2025-01-21).
Examples and more info can be found at: https://github.com/klukaszek/SDL3-WebGPU-Examples
(Based on https://github.com/TheSpydog/SDL_gpu_examples/)
A live demo can be found at: https://kylelukaszek.com/SDL3-WebGPU-Examples/.
My fork currently fails to pass the Emscripten pipeline test for some reason that I haven't taken the time to investigate yet. So that will probably have to be resolved before merging with main.
I'm probably gonna get to work on compute pipelines sometime soon if no one ends up working on that by the time I'm free again.
Shaders
This current implementation of the backend expects WGSL shaders since I have only tested on browsers, and browser implementations of WebGPU don't offer support for the SPIRV SType. Once native WGPU support becomes a priority, then this issue can be tackled.
API Checklist
General
Swapchains
Command Buffers and Fences
Note: WebGPU has no exposed fence API.
Buffers
Textures
Samplers
Debugging
Graphics Pipelines
Compute Pipelines
Shaders
Rendering
Copy Passes
Compute Passes
Fragment Stage
Vertex Stage
Rendering States
Composition
Example Checklist
Native WebGPU Support
I have not done any testing with native distributions of WebGPU (WGPU Native / Dawn), though I have implemented Elie Michel's surface selector logic sdl3webgpu.c for when someone wants to give it a test.
Warning:
The preprocessor macros in WebGPU_INTERNAL_CreateSurface() don't seem to work properly, and as a result, I hard coded in a workaround since I'm only testing on the web for the time being.
Existing Issue(s)
#10768