Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 17 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,7 @@ elseif(EMSCRIPTEN)
set(SDL_VIDEO_DRIVER_EMSCRIPTEN 1)
sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/emscripten/*.c")
set(HAVE_SDL_VIDEO TRUE)

#enable webgpu
if(SDL_GPU AND SDL_WEBGPU)
set(SDL_RENDER_WEBGPU ON)
Expand Down Expand Up @@ -1902,8 +1903,8 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
if(SDL_WEBGPU) # Native platform WebGPU handling
set(SDL_VIDEO_WEBGPU 1)

# This should probably require a compilation flag with the path but for now
# SDL3/SDL_webgpu.h points to wgpu/ for the webgpu header.
# # This should probably require a compilation flag with the path but for now
# # SDL3/SDL_webgpu.h points to wgpu/ for the webgpu header.
# The user must provide a wgpu library of their choice.
set(SDL_WEBGPU_PATH "wgpu" CACHE PATH
"Path to WebGPU library (must contain include/ and lib/ directories)")
Expand All @@ -1919,12 +1920,18 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
REQUIRED
)
find_library(WEBGPU_LIBRARY
NAMES wgpu_native
NAMES wgpu_native webgpu_dawn
PATHS "${SDL_WEBGPU_PATH}/lib/"
NO_DEFAULT_PATH
REQUIRED
)

if(WEBGPU_LIBRARY MATCHES "webgpu_dawn")
add_compile_definitions(SDL_WEBGPU_DAWN=1)
elseif(WEBGPU_LIBRARY MATCHES "wgpu_native")
add_compile_definitions(SDL_WEBGPU_WGPU=1)
endif()

# Add to build system
sdl_include_directories(PRIVATE SYSTEM "${WEBGPU_INCLUDE_DIR}")
sdl_link_dependency(WebGPU LIBS "${WEBGPU_LIBRARY}")
Expand Down Expand Up @@ -2151,6 +2158,7 @@ elseif(WINDOWS)
set(HAVE_RENDER_VULKAN TRUE)
endif()
endif()

if(SDL_WEBGPU) # Native platform WebGPU handling
set(SDL_VIDEO_WEBGPU 1)
# This should probably require a compilation flag with the path but for now
Expand All @@ -2169,11 +2177,16 @@ elseif(WINDOWS)
REQUIRED
)
find_library(WEBGPU_LIBRARY
NAMES wgpu_native
NAMES wgpu_native webgpu_dawn
PATHS "${SDL_WEBGPU_PATH}/lib/"
NO_DEFAULT_PATH
REQUIRED
)
if(WEBGPU_LIBRARY MATCHES "webgpu_dawn")
add_compile_definitions(SDL_WEBGPU_DAWN=1)
elseif(WEBGPU_LIBRARY MATCHES "wgpu_native")
add_compile_definitions(SDL_WEBGPU_WGPU=1)
endif()

# Add include directories
sdl_include_directories(PRIVATE SYSTEM "${WEBGPU_INCLUDE_DIR}")
Expand Down
21 changes: 6 additions & 15 deletions include/SDL3/SDL_webgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,14 @@
* # CategoryWebGPU
**/

/*
NOTE: Some of the enum conversion functions are a nightmare to manage between the different flavours of webgpu.h

wgpu-native source code pulls it's header from here: https://github.com/webgpu-native/webgpu-headers/blob/main/webgpu.h
however the header provided in the release version of the library: https://github.com/gfx-rs/wgpu-native/releases
have some changes to the enum values that kind of screw everything up.

Gotta wait until the header is finalized to get this fixed.

webgpu.h from webgpu-headers SHOULD work for all backends, except for Emscripten and wgpu-native apparently!
So as I suspected, Dawn would have been the best pick to work with like I had originally done before swapping to wgpu-native out of convenience.
*/
// wgpu-native and Dawn install as `include/` and `lib/`. `include/` will contain a directory `webgpu/`
#ifdef SDL_WEBGPU_DAWN
#include "../../wgpu/include/dawn/dawn.h"
#endif

#ifndef __EMSCRIPTEN__
// #include "../../wgpu/include/webgpu/webgpu.h"
#ifdef SDL_WEBGPU_WGPU
#include "../../wgpu/include/webgpu/wgpu.h"
#endif // webgpu.h is provided by emscripten when using emcc with -sUSE_WEBGPU=1
#endif

#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_video.h>
Expand Down
Loading
Loading