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

SDL3 GPU WebGPU Backend #12046

Open
wants to merge 85 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
850caed
Nuked my repo due to it being 600 commits ahead of upstream even thou…
klukaszek Nov 17, 2024
35afb6e
Got Point, Linear, and Aniso samplers working with Clamp and Repeat
klukaszek Nov 20, 2024
fd2e2f5
Began work on PushVertexUniformData. Investigated bug where certain G…
klukaszek Dec 16, 2024
b5b0b4e
Cleaned up logging in preparation for managing Uniform Buffers.
klukaszek Dec 21, 2024
37d08d1
Refactored buffer and texture data structures to be more simple as th…
klukaszek Dec 27, 2024
34f0a47
PushVertexUniformData() and PushFragmentUniformData() no longer cause…
klukaszek Dec 27, 2024
c380e4d
Fixed SDLToWGPUTextureUsageFlags() to properly handle bit flags inste…
klukaszek Dec 28, 2024
df19be0
Working on getting WebGPU_Blit() ready for implementation by solving …
klukaszek Dec 28, 2024
7605ea7
Implemented simple miscellaneous functions to knock them off of the c…
klukaszek Dec 28, 2024
9496c2e
Trying to get array layers working for 3D textures since WebGPU only …
klukaszek Jan 7, 2025
478b4cd
Implemented a blitting pipeline for WebGPU since there is no blit fun…
klukaszek Jan 8, 2025
ee68d05
Refactored to use SDL_GPU_BlitCommon instead of writing my own WebGPU…
klukaszek Jan 9, 2025
abae635
Made more progess on 2D texture array blitting. Now I need to investi…
klukaszek Jan 9, 2025
9b8e259
Refactored several calls to SDL_malloc to SDL_stack_alloc if data is …
klukaszek Jan 9, 2025
cecebf8
Feat: Added stencil reference adjustment
klukaszek Jan 10, 2025
fd085f6
Feat: Got BlitCube example working
klukaszek Jan 10, 2025
4fe10d0
Refactor: Eliminated many unnecessary dynamic memory allocations. Far…
klukaszek Jan 11, 2025
8a42bb4
Removed print statements that angered different test pipelines.
klukaszek Jan 14, 2025
51a5c38
Misc: Moved SDL3 WebGPU Checklist to src/gpu/webgpu/
klukaszek Jan 14, 2025
cb91daf
Misc: Moved SDL3 WebGPU Checklist to src/gpu/webgpu/
klukaszek Jan 14, 2025
140802a
Misc: Added SDL3 GPU ReadMe
klukaszek Jan 14, 2025
bcdc2d5
Misc: Added SDL3 GPU ReadMe
klukaszek Jan 14, 2025
9e6dc5a
Misc: Updated emscripten's version for the test pipeline.
klukaszek Jan 14, 2025
5565a59
Misc: Updated emscripten's version for the test pipeline.
klukaszek Jan 14, 2025
f967732
Misc: trying to get Emscripten test pipeline working.
klukaszek Jan 14, 2025
467c870
Fix: Rebased with upstream and solved a recently implemented bug with…
klukaszek Jan 21, 2025
c21747f
Feat: Made swapchain a static allocation.
klukaszek Jan 21, 2025
58e6140
Refactor: Removed Emscripten specific Swapchain logic. Now I manually…
klukaszek Jan 21, 2025
d570ca5
Feat: Implemented indirect drawing support for WebGPU.
klukaszek Jan 21, 2025
11d8ef7
Refactor: Added explicit loop termination while waiting for the devic…
klukaszek Jan 22, 2025
8d601ec
Refactor: Setting of viewport and scissor is done in WebGPU_BeginRend…
klukaszek Jan 22, 2025
a385d47
Misc: Added standard text to top of file.
klukaszek Jan 22, 2025
c226ca5
Misc: Changed some imports.
klukaszek Jan 22, 2025
2b22917
Misc: Changed some more imports.
klukaszek Jan 22, 2025
e24094d
Refactor: Changed default renderpass state initialization to better m…
klukaszek Jan 22, 2025
c1d8428
Refactor: Removed ~0u conversion as I had forgotten that I had resolv…
klukaszek Jan 22, 2025
d2fbc02
Refactor: Moved SDL_internal.h to the very top
klukaszek Jan 22, 2025
09523e4
Refactor: Started implementing fencing properly.
klukaszek Jan 23, 2025
8e72939
Refactor: Added fence pool and associated internal functions.
klukaszek Jan 23, 2025
bc4a11c
Refactor: Added uniform buffer pool.
klukaszek Jan 23, 2025
0533e73
Refactor: Implemented placeholder fencing logic. Has not actually bee…
klukaszek Jan 23, 2025
8fabcca
Nuked my repo due to it being 600 commits ahead of upstream even thou…
klukaszek Nov 17, 2024
56f9a9c
Got Point, Linear, and Aniso samplers working with Clamp and Repeat
klukaszek Nov 20, 2024
1f669f7
Began work on PushVertexUniformData. Investigated bug where certain G…
klukaszek Dec 16, 2024
9c1875c
Cleaned up logging in preparation for managing Uniform Buffers.
klukaszek Dec 21, 2024
60e2d73
Refactored buffer and texture data structures to be more simple as th…
klukaszek Dec 27, 2024
85b992d
PushVertexUniformData() and PushFragmentUniformData() no longer cause…
klukaszek Dec 27, 2024
8521e4e
Fixed SDLToWGPUTextureUsageFlags() to properly handle bit flags inste…
klukaszek Dec 28, 2024
733354f
Working on getting WebGPU_Blit() ready for implementation by solving …
klukaszek Dec 28, 2024
2f7f0eb
Implemented simple miscellaneous functions to knock them off of the c…
klukaszek Dec 28, 2024
01b4880
Trying to get array layers working for 3D textures since WebGPU only …
klukaszek Jan 7, 2025
70d2269
Implemented a blitting pipeline for WebGPU since there is no blit fun…
klukaszek Jan 8, 2025
3f8682b
Refactored to use SDL_GPU_BlitCommon instead of writing my own WebGPU…
klukaszek Jan 9, 2025
e93956d
Made more progess on 2D texture array blitting. Now I need to investi…
klukaszek Jan 9, 2025
a37c1c6
Refactored several calls to SDL_malloc to SDL_stack_alloc if data is …
klukaszek Jan 9, 2025
0c33fad
Feat: Added stencil reference adjustment
klukaszek Jan 10, 2025
600bff2
Feat: Got BlitCube example working
klukaszek Jan 10, 2025
283c5b9
Refactor: Eliminated many unnecessary dynamic memory allocations. Far…
klukaszek Jan 11, 2025
bca377b
Removed print statements that angered different test pipelines.
klukaszek Jan 14, 2025
5a0099a
Misc: Moved SDL3 WebGPU Checklist to src/gpu/webgpu/
klukaszek Jan 14, 2025
ea6f5fb
Misc: Moved SDL3 WebGPU Checklist to src/gpu/webgpu/
klukaszek Jan 14, 2025
8fa803d
Misc: Added SDL3 GPU ReadMe
klukaszek Jan 14, 2025
923b925
Misc: Added SDL3 GPU ReadMe
klukaszek Jan 14, 2025
07fcef4
Misc: Updated emscripten's version for the test pipeline.
klukaszek Jan 14, 2025
585b68a
Misc: Updated emscripten's version for the test pipeline.
klukaszek Jan 14, 2025
3d39bb9
Misc: trying to get Emscripten test pipeline working.
klukaszek Jan 14, 2025
c0fb4a5
Fix: Rebased with upstream and solved a recently implemented bug with…
klukaszek Jan 21, 2025
4e92ba2
Feat: Made swapchain a static allocation.
klukaszek Jan 21, 2025
abf5db8
Refactor: Removed Emscripten specific Swapchain logic. Now I manually…
klukaszek Jan 21, 2025
dd64914
Feat: Implemented indirect drawing support for WebGPU.
klukaszek Jan 21, 2025
0b3b440
Refactor: Added explicit loop termination while waiting for the devic…
klukaszek Jan 22, 2025
ebb99a2
Refactor: Setting of viewport and scissor is done in WebGPU_BeginRend…
klukaszek Jan 22, 2025
7960aa3
Misc: Added standard text to top of file.
klukaszek Jan 22, 2025
1cfb6af
Misc: Changed some imports.
klukaszek Jan 22, 2025
3988cd3
Misc: Changed some more imports.
klukaszek Jan 22, 2025
2dcd6c7
Refactor: Changed default renderpass state initialization to better m…
klukaszek Jan 22, 2025
2b4838b
Refactor: Removed ~0u conversion as I had forgotten that I had resolv…
klukaszek Jan 22, 2025
dbc8855
Refactor: Moved SDL_internal.h to the very top
klukaszek Jan 22, 2025
3ee7c13
Refactor: Started implementing fencing properly.
klukaszek Jan 23, 2025
e861a1e
Refactor: Added fence pool and associated internal functions.
klukaszek Jan 23, 2025
f61a114
Refactor: Added uniform buffer pool.
klukaszek Jan 23, 2025
0a941ea
Refactor: Implemented placeholder fencing logic. Has not actually bee…
klukaszek Jan 23, 2025
a4845c4
Merge branch 'working'
klukaszek Jan 28, 2025
ef1788b
WIP: Working on threaded command pool functionality
klukaszek Jan 30, 2025
30bbcee
Feat: Implemented command buffer pooling. Command buffers are not ful…
klukaszek Feb 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/gpu/webgpu/SDL_gpu_webgpu.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <[email protected]>

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

// File: /webgpu/SDL_gpu_webgpu.c
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please include the standard text from https://github.com/libsdl-org/SDL/blob/main/include/SDL3/SDL_copying.h and add any copyright attribution you'd like here.

Copy link
Author

Choose a reason for hiding this comment

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

Link: a385d47

// Author: Kyle Lukaszek
// Email: kylelukaszek [at] gmail [dot] com
Expand Down Expand Up @@ -1966,11 +1987,6 @@ static SDL_GPUCommandBuffer *WebGPU_AcquireCommandBuffer(SDL_GPURenderer *driver
commandBuffer->renderer = renderer;
commandBuffer->common.device = renderer->sdlDevice;

int width, height;
SDL_GetWindowSize(renderer->claimedWindows[0]->window, &width, &height);
commandBuffer->currentViewport = (WebGPUViewport){ 0, 0, width, height, 0.0, 1.0 };
commandBuffer->currentScissor = (WebGPURect){ 0, 0, width, height };

SDL_zero(commandBuffer->layerViews);
commandBuffer->layerViewCount = 0;

Expand Down Expand Up @@ -2090,6 +2106,11 @@ void WebGPU_BeginRenderPass(SDL_GPUCommandBuffer *commandBuffer,
return;
}

int width, height;
SDL_GetWindowSize(wgpu_cmd_buf->renderer->claimedWindows[0]->window, &width, &height);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is still not right, the viewport and scissor should be set to the smallest size of bound render targets. Please reference how the other backends implemented this.

Copy link
Author

Choose a reason for hiding this comment

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

Ah I get it now! I'll return to this after some rest I think.

I read up on the Vulkan implementation and will follow that one tomorrow.

Copy link
Author

@klukaszek klukaszek Jan 22, 2025

Choose a reason for hiding this comment

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

Link: e24094d

It's still not 1-to-1 with the Vulkan backend but the viewport and scissor now use the smallest available size of all bound render targets.

It also now sets the other default states for the render pass.

wgpu_cmd_buf->currentViewport = (WebGPUViewport){ 0, 0, width, height, 0.0, 1.0 };
wgpu_cmd_buf->currentScissor = (WebGPURect){ 0, 0, width, height };

// Handle color attachments
WGPURenderPassColorAttachment colorAttachments[colorAttachmentCount];
for (uint32_t i = 0; i < colorAttachmentCount; i++) {
Expand Down