Skip to content

Commit

Permalink
WebGPU: Base implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailGorobets committed Jun 26, 2023
1 parent 51236cc commit 0f81d7a
Show file tree
Hide file tree
Showing 77 changed files with 9,104 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@
[submodule "ThirdParty/xxHash"]
path = ThirdParty/xxHash
url = https://github.com/DiligentGraphics/xxHash
[submodule "ThirdParty/webgpu"]
path = ThirdParty/webgpu
url = https://github.com/eliemichel/WebGPU-distribution
7 changes: 7 additions & 0 deletions BuildUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ if(PLATFORM_WIN32 OR PLATFORM_UNIVERSAL_WINDOWS)
if(METAL_SUPPORTED)
list(APPEND ENGINE_DLLS Diligent-GraphicsEngineMetal-shared)
endif()
if(WEBGPU_SUPPORTED)
list(APPEND ENGINE_DLLS Diligent-GraphicsEngineWebGPU-shared)
endif()
if(TARGET Diligent-Archiver-shared)
list(APPEND ENGINE_DLLS Diligent-Archiver-shared)
endif()
Expand Down Expand Up @@ -264,6 +267,10 @@ function(get_supported_backends _TARGETS)
if(METAL_SUPPORTED)
list(APPEND BACKENDS Diligent-GraphicsEngineMetal-${LIB_TYPE})
endif()
if(WEBGPU_SUPPORTED)
list(APPEND BACKENDS Diligent-GraphicsEngineWebGPU-${LIB_TYPE})
endif()

# ${_TARGETS} == ENGINE_LIBRARIES
# ${${_TARGETS}} == ${ENGINE_LIBRARIES}
set(${_TARGETS} ${${_TARGETS}} ${BACKENDS} PARENT_SCOPE)
Expand Down
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ set(GL_SUPPORTED FALSE CACHE INTERNAL "GL is not supported")
set(GLES_SUPPORTED FALSE CACHE INTERNAL "GLES is not supported")
set(VULKAN_SUPPORTED FALSE CACHE INTERNAL "Vulkan is not supported")
set(METAL_SUPPORTED FALSE CACHE INTERNAL "Metal is not supported")
set(WEBGPU_SUPPORTED FALSE CACHE INTERNAL "WebGPU is not supported")
set(ARCHIVER_SUPPORTED FALSE CACHE INTERNAL "Archiver is not supported")

set(DILIGENT_CORE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "DiligentCore module source directory")
Expand Down Expand Up @@ -156,6 +157,7 @@ if(PLATFORM_WIN32)

set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL is supported on Win32 platform")
set(VULKAN_SUPPORTED TRUE CACHE INTERNAL "Vulkan is supported on Win32 platform")
set(WEBGPU_SUPPORTED TRUE CACHE INTERNAL "WebGPU is supported on Win32 platform")
set(ARCHIVER_SUPPORTED TRUE CACHE INTERNAL "Archiver is supported on Win32 platform")
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_WIN32=1)
elseif(PLATFORM_UNIVERSAL_WINDOWS)
Expand Down Expand Up @@ -265,6 +267,7 @@ option(DILIGENT_NO_DIRECT3D12 "Disable Direct3D12 backend" OFF)
option(DILIGENT_NO_OPENGL "Disable OpenGL/GLES backend" OFF)
option(DILIGENT_NO_VULKAN "Disable Vulkan backend" OFF)
option(DILIGENT_NO_METAL "Disable Metal backend" OFF)
option(DILIGENT_NO_WEBGPU "Disable WebGPU backend" OFF)
option(DILIGENT_NO_ARCHIVER "Do not build archiver" OFF)
if(${DILIGENT_NO_DIRECT3D11})
set(D3D11_SUPPORTED FALSE CACHE INTERNAL "D3D11 backend is forcibly disabled")
Expand All @@ -282,11 +285,14 @@ endif()
if(${DILIGENT_NO_METAL})
set(METAL_SUPPORTED FALSE CACHE INTERNAL "Metal backend is forcibly disabled")
endif()
if(${DILIGENT_NO_WEBGPU})
set(WEBGPU_SUPPORTED FALSE CACHE INTERNAL "WebGPU backend is forcibly disabled")
endif()
if(${DILIGENT_NO_ARCHIVER})
set(ARCHIVER_SUPPORTED FALSE CACHE INTERNAL "Archiver is forcibly disabled")
endif()

if(NOT (${D3D11_SUPPORTED} OR ${D3D12_SUPPORTED} OR ${GL_SUPPORTED} OR ${GLES_SUPPORTED} OR ${VULKAN_SUPPORTED} OR ${METAL_SUPPORTED}))
if(NOT (${D3D11_SUPPORTED} OR ${D3D12_SUPPORTED} OR ${GL_SUPPORTED} OR ${GLES_SUPPORTED} OR ${VULKAN_SUPPORTED} OR ${METAL_SUPPORTED} OR ${WEBGPU_SUPPORTED}))
message(FATAL_ERROR "No rendering backends are select to build")
endif()

Expand All @@ -297,6 +303,7 @@ message("GL_SUPPORTED: " ${GL_SUPPORTED})
message("GLES_SUPPORTED: " ${GLES_SUPPORTED})
message("VULKAN_SUPPORTED: " ${VULKAN_SUPPORTED})
message("METAL_SUPPORTED: " ${METAL_SUPPORTED})
message("WEBGPU_SUPPORTED: " ${WEBGPU_SUPPORTED})

target_compile_definitions(Diligent-PublicBuildSettings
INTERFACE
Expand All @@ -306,6 +313,7 @@ INTERFACE
GLES_SUPPORTED=$<BOOL:${GLES_SUPPORTED}>
VULKAN_SUPPORTED=$<BOOL:${VULKAN_SUPPORTED}>
METAL_SUPPORTED=$<BOOL:${METAL_SUPPORTED}>
WEBGPU_SUPPORTED=$<BOOL:${WEBGPU_SUPPORTED}>
)

foreach(DBG_CONFIG ${DEBUG_CONFIGURATIONS})
Expand Down
3 changes: 3 additions & 0 deletions Graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ if(GL_SUPPORTED OR GLES_SUPPORTED)
add_subdirectory(GraphicsEngineOpenGL)
endif()

if (WEBGPU_SUPPORTED)
add_subdirectory(GraphicsEngineWebGPU)
endif()

if(ARCHIVER_SUPPORTED)
add_subdirectory(Archiver)
Expand Down
6 changes: 4 additions & 2 deletions Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ const char* GetDeviceFeatureStateString(DEVICE_FEATURE_STATE State, bool bGetFul

const char* GetRenderDeviceTypeString(RENDER_DEVICE_TYPE DeviceType, bool bGetEnumString)
{
static_assert(RENDER_DEVICE_TYPE_COUNT == 7, "Did you add a new device type? Please update the switch below.");
static_assert(RENDER_DEVICE_TYPE_COUNT == 8, "Did you add a new device type? Please update the switch below.");
switch (DeviceType)
{
// clang-format off
Expand All @@ -1259,14 +1259,15 @@ const char* GetRenderDeviceTypeString(RENDER_DEVICE_TYPE DeviceType, bool bGetEn
case RENDER_DEVICE_TYPE_GLES: return bGetEnumString ? "RENDER_DEVICE_TYPE_GLES" : "OpenGLES"; break;
case RENDER_DEVICE_TYPE_VULKAN: return bGetEnumString ? "RENDER_DEVICE_TYPE_VULKAN" : "Vulkan"; break;
case RENDER_DEVICE_TYPE_METAL: return bGetEnumString ? "RENDER_DEVICE_TYPE_METAL" : "Metal"; break;
case RENDER_DEVICE_TYPE_WEBGPU: return bGetEnumString ? "RENDER_DEVICe_TYPE_WEBGPU" : "WebGPU"; break;
// clang-format on
default: UNEXPECTED("Unknown/unsupported device type"); return "UNKNOWN";
}
}

const char* GetRenderDeviceTypeShortString(RENDER_DEVICE_TYPE DeviceType, bool Capital)
{
static_assert(RENDER_DEVICE_TYPE_COUNT == 7, "Did you add a new device type? Please update the switch below.");
static_assert(RENDER_DEVICE_TYPE_COUNT == 8, "Did you add a new device type? Please update the switch below.");
switch (DeviceType)
{
// clang-format off
Expand All @@ -1277,6 +1278,7 @@ const char* GetRenderDeviceTypeShortString(RENDER_DEVICE_TYPE DeviceType, bool C
case RENDER_DEVICE_TYPE_GLES: return Capital ? "GLES" : "gles"; break;
case RENDER_DEVICE_TYPE_VULKAN: return Capital ? "VK" : "vk"; break;
case RENDER_DEVICE_TYPE_METAL: return Capital ? "MTL" : "mtl"; break;
case RENDER_DEVICE_TYPE_WEBGPU: return Capital ? "WEBGPU" : "webgpu"; break;
// clang-format on
default: UNEXPECTED("Unknown/unsupported device type"); return "UNKNOWN";
}
Expand Down
21 changes: 21 additions & 0 deletions Graphics/GraphicsEngine/interface/GraphicsTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,7 @@ enum RENDER_DEVICE_TYPE
RENDER_DEVICE_TYPE_GLES, ///< OpenGLES device
RENDER_DEVICE_TYPE_VULKAN, ///< Vulkan device
RENDER_DEVICE_TYPE_METAL, ///< Metal device
RENDER_DEVICE_TYPE_WEBGPU, ///< WebGPU device
RENDER_DEVICE_TYPE_COUNT ///< The total number of device types
};

Expand Down Expand Up @@ -3846,6 +3847,26 @@ struct EngineMtlCreateInfo DILIGENT_DERIVE(EngineCreateInfo)
};
typedef struct EngineMtlCreateInfo EngineMtlCreateInfo;

/// Attributes of the WebGPU-based engine implementation
struct EngineWebGPUCreateInfo DILIGENT_DERIVE(EngineCreateInfo)

///
Uint32 QueueSignalPoolSize DEFAULT_INITIALIZER(32);

///
Uint32 DynamicHeapPageSize DEFAULT_INITIALIZER(4 << 20);

#if DILIGENT_CPP_INTERFACE
EngineWebGPUCreateInfo() noexcept :
EngineWebGPUCreateInfo{EngineCreateInfo{}}
{}

explicit EngineWebGPUCreateInfo(const EngineCreateInfo &EngineCI) noexcept :
EngineCreateInfo{EngineCI}
{}
#endif
};
typedef struct EngineWebGPUCreateInfo EngineWebGPUCreateInfo;

/// Box
struct Box
Expand Down
2 changes: 1 addition & 1 deletion Graphics/GraphicsEngine/src/DeviceObjectArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Diligent

DeviceObjectArchive::DeviceType RenderDeviceTypeToArchiveDeviceType(RENDER_DEVICE_TYPE Type)
{
static_assert(RENDER_DEVICE_TYPE_COUNT == 7, "Did you add a new render device type? Please handle it here.");
static_assert(RENDER_DEVICE_TYPE_COUNT == 8, "Did you add a new render device type? Please handle it here.");
switch (Type)
{
// clang-format off
Expand Down
142 changes: 142 additions & 0 deletions Graphics/GraphicsEngineWebGPU/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
cmake_minimum_required (VERSION 3.10)

project(Diligent-GraphicsEngineWebGPU CXX)

set(INCLUDE
include/AttachmentCleanerWebGPU.hpp
include/BufferViewWebGPUImpl.hpp
include/BufferWebGPUImpl.hpp
include/DeviceContextWebGPUImpl.hpp
include/EngineWebGPUImplTraits.hpp
include/FenceWebGPUImpl.hpp
include/FramebufferWebGPUImpl.hpp
include/pch.h
include/PipelineResourceAttribsWebGPU.hpp
include/PipelineResourceSignatureWebGPUImpl.hpp
include/PipelineStateWebGPUImpl.hpp
include/QueryManagerWebGPU.hpp
include/QueryWebGPUImpl.hpp
include/QueueSignalPoolWebGPU.hpp
include/RenderDeviceWebGPUImpl.hpp
include/RenderPassWebGPUImpl.hpp
include/SamplerWebGPUImpl.hpp
include/ShaderResourceBindingWebGPUImpl.hpp
include/ShaderResourceCacheWebGPU.hpp
include/ShaderVariableManagerWebGPU.hpp
include/ShaderWebGPUImpl.hpp
include/SharedMemoryManagerWebGPU.hpp
include/SwapChainWebGPUImpl.hpp
include/TextureViewWebGPUImpl.hpp
include/TextureWebGPUImpl.hpp
include/WebGPUObjectWrappers.hpp
include/WebGPUTypeConversions.hpp
)

set(INTERFACE
interface/BufferWebGPU.h
interface/DeviceContextWebGPU.h
interface/EngineFactoryWebGPU.h
interface/RenderDeviceWebGPU.h
interface/SamplerWebGPU.h
interface/SwapChainWebGPU.h
interface/TextureViewWebGPU.h
interface/TextureWebGPU.h
)

set(SRC
src/AttachmentCleanerWebGPU.cpp
src/BufferViewWebGPUImpl.cpp
src/BufferWebGPUImpl.cpp
src/DeviceContextWebGPUImpl.cpp
src/EngineFactoryWebGPU.cpp
src/FenceWebGPUImpl.cpp
src/FramebufferWebGPUImpl.cpp
src/QueryManagerWebGPU.cpp
src/QueryWebGPUImpl.cpp
src/RenderDeviceWebGPUImpl.cpp
src/RenderPassWebGPUImpl.cpp
src/SamplerWebGPUImpl.cpp
src/SharedMemoryManagerWebGPU.cpp
src/SwapChainWebGPUImpl.cpp
src/TextureViewWebGPUImpl.cpp
src/TextureWebGPUImpl.cpp
src/WebGPUTypeConversions.cpp
)

set(DLL_SRC
src/DLLMain.cpp
src/GraphicsEngineWebGPU.def
)

add_library(Diligent-GraphicsEngineWebGPUInterface INTERFACE)
target_link_libraries (Diligent-GraphicsEngineWebGPUInterface INTERFACE Diligent-GraphicsEngineInterface)
target_include_directories(Diligent-GraphicsEngineWebGPUInterface INTERFACE interface)

add_library(Diligent-GraphicsEngineWebGPU-static STATIC
${SRC} ${INTERFACE} ${INCLUDE}
readme.md
)

target_precompile_headers(Diligent-GraphicsEngineWebGPU-static PRIVATE include/pch.h)

add_library(Diligent-GraphicsEngineWebGPU-shared SHARED
readme.md
)

if(MSVC)
target_sources(Diligent-GraphicsEngineWebGPU-shared PRIVATE ${DLL_SRC})
endif()

set_dll_output_name(Diligent-GraphicsEngineWebGPU-shared GraphicsEngineWebGPU)

set_common_target_properties(Diligent-GraphicsEngineWebGPU-shared)
set_common_target_properties(Diligent-GraphicsEngineWebGPU-static)

target_include_directories(Diligent-GraphicsEngineWebGPU-static
PRIVATE
include
)

target_link_libraries(Diligent-GraphicsEngineWebGPU-static
PRIVATE
Diligent-BuildSettings
Diligent-TargetPlatform
Diligent-Common
Diligent-GraphicsEngine
Diligent-GraphicsEngineNextGenBase
Diligent-ShaderTools
webgpu
PUBLIC
Diligent-GraphicsEngineWebGPUInterface
)

target_link_libraries(Diligent-GraphicsEngineWebGPU-shared
PRIVATE
Diligent-BuildSettings
Diligent-GraphicsEngineWebGPU-static
PUBLIC
Diligent-GraphicsEngineWebGPUInterface
)
target_compile_definitions(Diligent-GraphicsEngineWebGPU-shared PUBLIC ENGINE_DLL=1)
target_copy_webgpu_binaries(Diligent-GraphicsEngineWebGPU-shared)

source_group("src" FILES ${SRC})
source_group("dll" FILES ${DLL_SRC})
source_group("include" FILES ${INCLUDE})
source_group("interface" FILES ${INTERFACE})

set_target_properties(Diligent-GraphicsEngineWebGPU-static PROPERTIES
FOLDER DiligentCore/Graphics
)
set_target_properties(Diligent-GraphicsEngineWebGPU-shared PROPERTIES
FOLDER DiligentCore/Graphics
)

set_source_files_properties(
readme.md PROPERTIES HEADER_FILE_ONLY TRUE
)

if(DILIGENT_INSTALL_CORE)
install_core_lib(Diligent-GraphicsEngineWebGPU-shared)
install_core_lib(Diligent-GraphicsEngineWebGPU-static)
endif()
Loading

0 comments on commit 0f81d7a

Please sign in to comment.