Skip to content

Commit

Permalink
Add WebGPU stub backend code.
Browse files Browse the repository at this point in the history
Introduce Enums to support WebGPU.
Start to use header files from dawn.
  • Loading branch information
sidreesshah committed Mar 5, 2025
1 parent eb1e2db commit 86e71f3
Show file tree
Hide file tree
Showing 13 changed files with 601 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ public enum TargetApi {
OPENGL (0x1),
VULKAN (0x2),
METAL (0x4),
ALL (0x7);
WEBGPU (0x8),
ALL (0x15);

final int number;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ public enum Backend {
* Selects the Metal driver if the platform supports it.
*/
METAL,
/**
* Select the WebGPU driver if platform supports it.
*/
WEBGPU,
/**
* Selects the no-op driver for testing purposes.
*/
Expand Down
17 changes: 17 additions & 0 deletions filament/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ if (FILAMENT_SUPPORTS_VULKAN)
endif()
endif()

if (FILAMENT_SUPPORTS_WEBGPU)
list(APPEND SRCS
src/webgpu/WebGPUDriver.cpp
src/webgpu/WebGPUDriver.h
src/webgpu/WebGPUPlatform.cpp
src/webgpu/WebGPUPlatform.h
)
endif()

# ==================================================================================================
# Definitions
# ==================================================================================================
Expand Down Expand Up @@ -339,6 +348,10 @@ if (FILAMENT_SUPPORTS_VULKAN)
target_link_libraries(${TARGET} PRIVATE SPIRV-Headers)
endif()

if (FILAMENT_SUPPORTS_WEBGPU)
target_link_libraries(${TARGET} PRIVATE webgpu_dawn dawncpp_headers)
endif()

if (FILAMENT_SUPPORTS_METAL)
target_link_libraries(${TARGET} PUBLIC "-framework Metal -framework CoreVideo")
endif()
Expand Down Expand Up @@ -426,6 +439,10 @@ install(TARGETS ${TARGET} ${INSTALL_TYPE} DESTINATION lib/${DIST_DIR})
install(TARGETS vkshaders ${INSTALL_TYPE} DESTINATION lib/${DIST_DIR})
install(DIRECTORY ${PUBLIC_HDR_DIR}/backend DESTINATION include)

if (FILAMENT_SUPPORTS_WEBGPU)
install(TARGETS webgpu_dawn ${INSTALL_TYPE} DESTINATION lib/${DIST_DIR})
endif()

# ==================================================================================================
# Test
# ==================================================================================================
Expand Down
5 changes: 4 additions & 1 deletion filament/backend/include/backend/DriverEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ enum class Backend : uint8_t {
OPENGL = 1, //!< Selects the OpenGL/ES driver (default on Android)
VULKAN = 2, //!< Selects the Vulkan driver if the platform supports it (default on Linux/Windows)
METAL = 3, //!< Selects the Metal driver if the platform supports it (default on MacOS/iOS).
NOOP = 4, //!< Selects the no-op driver for testing purposes.
WEBGPU = 4, //!< Selects the Webgpu driver if the platform supports webgpu.
NOOP = 5, //!< Selects the no-op driver for testing purposes.
};

enum class TimerQueryResult : int8_t {
Expand All @@ -163,6 +164,8 @@ static constexpr const char* backendToString(Backend backend) {
return "Vulkan";
case Backend::METAL:
return "Metal";
case Backend::WEBGPU:
return "WebGPU";
default:
return "Unknown";
}
Expand Down
10 changes: 10 additions & 0 deletions filament/backend/src/PlatformFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ filament::backend::Platform* createDefaultMetalPlatform();
#endif

#include "noop/PlatformNoop.h"
#if defined(FILAMENT_SUPPORTS_WEBGPU)
#include "webgpu/WebGPUPlatform.h"
#endif

namespace filament::backend {

Expand Down Expand Up @@ -106,6 +109,13 @@ Platform* PlatformFactory::create(Backend* backend) noexcept {
return nullptr;
#endif
}
if (*backend == Backend::WEBGPU) {
#if defined(FILAMENT_SUPPORTS_WEBGPU)
return new WebGPUPlatform();
#else
return nullptr;
#endif
}
if (*backend == Backend::METAL) {
#if defined(FILAMENT_SUPPORTS_METAL)
return createDefaultMetalPlatform();
Expand Down
Loading

0 comments on commit 86e71f3

Please sign in to comment.