Skip to content

Commit

Permalink
WebGPU: Base Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailGorobets committed Jan 6, 2024
1 parent 68362a8 commit 3ddc8f2
Show file tree
Hide file tree
Showing 107 changed files with 11,231 additions and 7 deletions.
7 changes: 7 additions & 0 deletions BuildTools/CMake/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 @@ -183,6 +184,7 @@ endif()
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 @@ -288,6 +290,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 @@ -305,11 +308,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 @@ -320,6 +326,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})
message("")

target_compile_definitions(Diligent-PublicBuildSettings
Expand All @@ -330,6 +337,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 @@ -1311,7 +1311,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 @@ -1322,14 +1322,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 @@ -1340,6 +1341,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 @@ -1585,6 +1585,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 @@ -4022,6 +4023,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
154 changes: 154 additions & 0 deletions Graphics/GraphicsEngineWebGPU/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
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/BufferViewWebGPU.h
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/QueueSignalPoolWebGPU.cpp
src/RenderDeviceWebGPUImpl.cpp
src/RenderPassWebGPUImpl.cpp
src/SamplerWebGPUImpl.cpp
src/ShaderWebGPUImpl.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
)

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)

set_target_properties(Diligent-GraphicsEngineWebGPU-shared PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)

set_target_properties(Diligent-GraphicsEngineWebGPU-static PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)

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
libtint
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 3ddc8f2

Please sign in to comment.