Skip to content
Open
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
48 changes: 36 additions & 12 deletions BuildTools/CMake/BuildUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,21 @@ function(set_common_target_properties TARGET)
custom_post_configure_target(${TARGET})
endif()

# Mark generated files as such to avoid "file not found" warnings in some IDEs in configuration stage
if (WEBGPU_SUPPORTED AND (NOT PLATFORM_WEB))
set(DAWN_GENERATED_HEADERS
${DAWN_BUILD_GEN_DIR}/include/dawn/webgpu.h
${DAWN_BUILD_GEN_DIR}/include/dawn/webgpu_cpp.h
${DAWN_BUILD_GEN_DIR}/include/dawn/webgpu_cpp_print.h
${DAWN_BUILD_GEN_DIR}/include/dawn/wire/client/webgpu.h
${DAWN_BUILD_GEN_DIR}/include/dawn/wire/client/webgpu_cpp.h
${DAWN_BUILD_GEN_DIR}/include/dawn/wire/client/webgpu_cpp_print.h
${DAWN_BUILD_GEN_DIR}/include/dawn/dawn_proc_table.h
${DAWN_BUILD_GEN_DIR}/include/webgpu/webgpu_cpp_chained_struct.h
)
set_source_files_properties(${DAWN_GENERATED_HEADERS} PROPERTIES GENERATED TRUE)
endif()

endfunction()

function(find_targets_in_directory _RESULT _DIR)
Expand Down Expand Up @@ -518,24 +533,33 @@ function(add_format_validation_target MODULE_NAME MODULE_ROOT_PATH IDE_FOLDER)

endfunction()

# FetchContent's GIT_SHALLOW option is buggy and does not actually do a shallow
# clone. This macro takes care of it.
macro(FetchContent_DeclareShallowGit Name GIT_REPOSITORY GitRepository GIT_TAG GitTag)
# The GIT_SHALLOW option in FetchContent is buggy and does not actually perform
# a shallow clone. This macro fixes that. Also, we do not want to clone all
# submodules to reduce download time, therefore an optional GIT_SUBMODULES
# argument specifies which submodules should be cloned (if omitted, all of them).
macro(FetchContent_DeclareShallowGit Name)
set(oneValueArgs GIT_REPOSITORY GIT_TAG)
set(multiValueArgs GIT_SUBMODULES)
cmake_parse_arguments(ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

include(FetchContent)
FetchContent_Declare(
"${Name}"

# This is what it'd look like if GIT_SHALLOW was indeed working:
#GIT_REPOSITORY "${GitRepository}"
#GIT_TAG "${GitTag}"
#GIT_SHALLOW ON
# This is what it'd look like if GIT_SHALLOW was indeed working:
#GIT_REPOSITORY "${ARG_GIT_REPOSITORY}"
#GIT_TAG "${ARG_GIT_TAG}"
#GIT_SHALLOW ON
#GIT_SUBMODULES "${ARG_GIT_SUBMODULES}"

# Manual download mode instead:
# Manual download mode instead:
FetchContent_Declare(
${Name}
DOWNLOAD_COMMAND
cd "${FETCHCONTENT_BASE_DIR}/${Name}-src" &&
git init &&
git fetch --depth=1 "${GitRepository}" "${GitTag}" &&
git reset --hard FETCH_HEAD
git remote add origin "${ARG_GIT_REPOSITORY}" &&
git fetch --depth=1 origin "${ARG_GIT_TAG}" &&
git checkout FETCH_HEAD &&
git submodule update --init --recursive --depth=1 ${ARG_GIT_SUBMODULES}
)
endmacro()

Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,13 @@ elseif(PLATFORM_ANDROID)
elseif(PLATFORM_LINUX)
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL is supported on Linux platform")
set(VULKAN_SUPPORTED TRUE CACHE INTERNAL "Vulkan is supported on Linux platform")
set(WEBGPU_SUPPORTED TRUE CACHE INTERNAL "WebGPU is supported on Linux platform via Dawn")
set(ARCHIVER_SUPPORTED TRUE CACHE INTERNAL "Archiver is supported on Linux platform")
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_LINUX=1)
elseif(PLATFORM_MACOS)
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL is supported on macOS platform")
set(VULKAN_SUPPORTED TRUE CACHE INTERNAL "Vulkan is enabled through MoltenVK on macOS platform")
set(WEBGPU_SUPPORTED TRUE CACHE INTERNAL "WebGPU is supported on macOS platform via Dawn")
set(ARCHIVER_SUPPORTED TRUE CACHE INTERNAL "Archiver is supported on macOS platform")
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_MACOS=1 PLATFORM_APPLE=1)
elseif(PLATFORM_IOS)
Expand Down
1 change: 0 additions & 1 deletion Common/interface/ParsingTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,6 @@ TokenIterType FindMatchingBracket(const TokenIterType& Start,
ClosingBracketType = TokenType::OpenSquareBracket;
SearchForward = false;
break;

case TokenType::ClosingAngleBracket:
ClosingBracketType = TokenType::OpenAngleBracket;
SearchForward = false;
Expand Down
7 changes: 7 additions & 0 deletions Graphics/Archiver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ if(WEBGPU_SUPPORTED)
target_link_libraries(Diligent-Archiver-static PRIVATE Diligent-GraphicsEngineWebGPU-static)
if (NOT PLATFORM_WEB)
target_link_libraries(Diligent-Archiver-static PRIVATE dawn_native dawn_proc)
# dawn_version's generated header propagates here as a source; re-mark it GENERATED in this scope (CMP0118 is OLD).
if (TARGET dawn_version)
get_target_property(DAWN_VERSION_HEADERS dawn_version INTERFACE_SOURCES)
if (DAWN_VERSION_HEADERS)
set_source_files_properties(${DAWN_VERSION_HEADERS} PROPERTIES GENERATED TRUE)
endif()
endif()
endif()
target_include_directories(Diligent-Archiver-static
PRIVATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ struct ShaderVariableBase : public ResourceVariableBaseInterface
const PipelineResourceDesc& ResDesc = pThis->GetDesc();

const SHADER_RESOURCE_VARIABLE_TYPE_FLAGS VarTypeFlag = static_cast<SHADER_RESOURCE_VARIABLE_TYPE_FLAGS>(1u << ResDesc.VarType);
if ((Flags & VarTypeFlag) == 0)
if ((static_cast<Uint32>(Flags) & static_cast<Uint32>(VarTypeFlag)) == 0)
return; // This variable type is not being processed

if ((StaleVarTypes & VarTypeFlag) != 0)
Expand Down
15 changes: 14 additions & 1 deletion Graphics/GraphicsEngineWebGPU/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ endif()

if (NOT PLATFORM_WEB)
list(APPEND PRIVATE_DEPENDENCIES dawn_native dawn_proc)

# dawn_version's generated header propagates here as a source; re-mark it GENERATED in this scope (CMP0118 is OLD).
if (TARGET dawn_version)
get_target_property(DAWN_VERSION_HEADERS dawn_version INTERFACE_SOURCES)
if (DAWN_VERSION_HEADERS)
set_source_files_properties(${DAWN_VERSION_HEADERS} PROPERTIES GENERATED TRUE)
endif()
endif()
endif()

target_link_libraries(Diligent-GraphicsEngineWebGPU-static
Expand Down Expand Up @@ -179,7 +187,12 @@ PRIVATE
)

if (PLATFORM_WEB)
target_link_options(Diligent-GraphicsEngineWebGPU-static PUBLIC "SHELL: -s USE_WEBGPU=1 -s USE_PTHREADS=1")
target_link_options(Diligent-GraphicsEngineWebGPU-static PUBLIC "SHELL: --use-port=emdawnwebgpu -s USE_PTHREADS=1")
target_compile_options(Diligent-GraphicsEngineWebGPU-static PUBLIC "--use-port=emdawnwebgpu")
# This is required only for IntelliSense to detect webgpu.h.
target_include_directories(Diligent-GraphicsEngineWebGPU-static PUBLIC
${EMSCRIPTEN_ROOT_PATH}/cache/ports/emdawnwebgpu/emdawnwebgpu_pkg/webgpu/include
)
endif()

target_compile_definitions(Diligent-GraphicsEngineWebGPU-shared PUBLIC DILIGENT_WEBGPU_SHARED=1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
/// Declaration of Diligent::DynamicMemoryManagerWebGPU class

#include <mutex>
#include <memory>
#include <vector>

#include "WebGPUObjectWrappers.hpp"
Expand Down Expand Up @@ -111,9 +112,9 @@ class DynamicMemoryManagerWebGPU
size_t m_CurrentOffset = 0;
WebGPUBufferWrapper m_wgpuBuffer;

std::mutex m_AvailablePagesMtx;
std::vector<Page> m_AvailablePages;
std::vector<Uint8> m_MappedData;
std::mutex m_AvailablePagesMtx;
std::vector<Page> m_AvailablePages;
std::unique_ptr<Uint8[]> m_MappedData;
};

} // namespace Diligent
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <vector>
#include <array>
#include <string>
#include <utility>

#include "EngineWebGPUImplTraits.hpp"
#include "PipelineStateBase.hpp"
Expand Down Expand Up @@ -85,11 +86,9 @@ class PipelineStateWebGPUImpl final : public PipelineStateBase<EngineWebGPUImplT
ShaderWebGPUImpl* const pShader;
std::string PatchedWGSL;

// Per-stage specialization constant entries, built from user input
// and WGSL override reflection during InitializePipeline().
// Entries reference names in the shader resource name pool,
// which is kept alive by ShaderWebGPUImpl.
std::vector<WGPUConstantEntry> SpecConstEntries;
// Per-stage specialization constants as (override @id string, value)
// pairs, materialized into WGPUConstantEntry[] at pipeline creation.
std::vector<std::pair<std::string, double>> SpecConstEntries;

ShaderStageInfo(ShaderWebGPUImpl* _pShader) :
Type{_pShader->GetDesc().ShaderType},
Expand Down
15 changes: 8 additions & 7 deletions Graphics/GraphicsEngineWebGPU/include/SwapChainWebGPUImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,23 @@ class SwapChainWebGPUImpl final : public SwapChainBase<ISwapChainWebGPU>

void ConfigureSurface();

void CreateBuffersAndViews();
void CreateDepthBufferView();

void RecreateSwapChain();

void ReleaseSwapChainResources();

void RecreateSwapChain();
void RequestAnimationFrame(Uint32 SyncInterval);

private:
class PresentCommand;
WGPUSurfaceGetCurrentTextureStatus AcquireSurfaceTexture();

private:
NativeWindow m_NativeWindow;
WebGPUSurfaceWrapper m_wgpuSurface;
RefCntAutoPtr<ITextureViewWebGPU> m_pBackBufferRTV;
RefCntAutoPtr<ITextureViewWebGPU> m_pBackBufferSRV;
RefCntAutoPtr<ITextureViewWebGPU> m_pDepthBufferDSV;
std::unique_ptr<PresentCommand> m_pCmdPresent;
bool m_VSyncEnabled = true;
bool m_VSyncEnabled = false;
Uint32 m_RequestedSyncInterval = 0;
};

} // namespace Diligent
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
/// Declaration of Diligent::UploadMemoryManagerWebGPU class

#include <mutex>
#include <vector>
#include <memory>
#include <atomic>
#include <vector>

#include "WebGPUObjectWrappers.hpp"
#include "BasicTypes.h"
Expand Down Expand Up @@ -83,13 +84,14 @@ class UploadMemoryManagerWebGPU

size_t GetSize() const
{
return m_Data.size();
return m_DataSize;
}

private:
UploadMemoryManagerWebGPU* m_pMgr = nullptr;
WebGPUBufferWrapper m_wgpuBuffer;
std::vector<Uint8> m_Data;
std::unique_ptr<Uint8[]> m_Data;
size_t m_DataSize = 0;
size_t m_CurrOffset = 0;
};

Expand Down
11 changes: 0 additions & 11 deletions Graphics/GraphicsEngineWebGPU/include/WebGPUStubs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,5 @@
#if PLATFORM_WEB

inline constexpr WGPUFeatureName WGPUFeatureName_ChromiumExperimentalTimestampQueryInsidePasses = static_cast<WGPUFeatureName>(0x000003EE);
inline constexpr WGPUFeatureName WGPUFeatureName_Unorm16TextureFormats = static_cast<WGPUFeatureName>(0x000003FB);
inline constexpr WGPUFeatureName WGPUFeatureName_Snorm16TextureFormats = static_cast<WGPUFeatureName>(0x000003FC);

inline constexpr WGPUTextureFormat WGPUTextureFormat_R16Unorm = static_cast<WGPUTextureFormat>(0x00000060);
inline constexpr WGPUTextureFormat WGPUTextureFormat_R16Snorm = static_cast<WGPUTextureFormat>(0x00000063);
inline constexpr WGPUTextureFormat WGPUTextureFormat_RG16Unorm = static_cast<WGPUTextureFormat>(0x00000061);
inline constexpr WGPUTextureFormat WGPUTextureFormat_RG16Snorm = static_cast<WGPUTextureFormat>(0x00000064);
inline constexpr WGPUTextureFormat WGPUTextureFormat_RGBA16Unorm = static_cast<WGPUTextureFormat>(0x00000062);
inline constexpr WGPUTextureFormat WGPUTextureFormat_RGBA16Snorm = static_cast<WGPUTextureFormat>(0x00000065);

inline constexpr WGPUSurfaceGetCurrentTextureStatus WGPUSurfaceGetCurrentTextureStatus_Error = static_cast<WGPUSurfaceGetCurrentTextureStatus>(0x00000007);

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "DepthStencilState.h"
#include "RasterizerState.h"
#include "InputLayout.h"
#include "TextureView.h"

namespace Diligent
{
Expand Down Expand Up @@ -81,6 +82,10 @@ WGPUShaderStage ShaderStagesToWGPUShaderStageFlags(SHADER_TYPE Stages);

WGPUVertexStepMode InputElementFrequencyToWGPUVertexStepMode(INPUT_ELEMENT_FREQUENCY StepRate);

WGPUComponentSwizzle TextureComponentSwizzleToWGPUComponentSwizzle(TEXTURE_COMPONENT_SWIZZLE Swizzle);

WGPUTextureComponentSwizzle TextureComponentMappingToWGPUTextureComponentSwizzle(const TextureComponentMapping& Mapping);

inline WGPUOptionalBool BoolToWGPUOptionalBool(bool Value)
{
return Value ? WGPUOptionalBool_True : WGPUOptionalBool_False;
Expand Down
44 changes: 5 additions & 39 deletions Graphics/GraphicsEngineWebGPU/include/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,50 +32,18 @@
#pragma once

#include <string>
#include <cstring>
#include <algorithm>

#include <webgpu/webgpu.h>

#if PLATFORM_WEB

using WGPUOptionalBool = bool;
using WGPUShaderSourceWGSL = WGPUShaderModuleWGSLDescriptor;
using WGPUStringView = const char*;
using WGPUSurfaceSourceCanvasHTMLSelector_Emscripten = WGPUSurfaceDescriptorFromCanvasHTMLSelector;
using WGPUSurfaceSourceCanvasHTMLSelector_Emscripten = WGPUEmscriptenSurfaceSourceCanvasHTMLSelector;

constexpr bool WGPUOptionalBool_True = true;
constexpr bool WGPUOptionalBool_False = false;
constexpr WGPUSType WGPUSType_SurfaceSourceCanvasHTMLSelector_Emscripten = WGPUSType_EmscriptenSurfaceSourceCanvasHTMLSelector;

constexpr WGPUSType WGPUSType_ShaderSourceWGSL = WGPUSType_ShaderModuleWGSLDescriptor;
constexpr WGPUSType WGPUSType_SurfaceSourceCanvasHTMLSelector_Emscripten = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector;

constexpr WGPUBufferBindingType WGPUBufferBindingType_BindingNotUsed = WGPUBufferBindingType_Undefined;
constexpr WGPUSamplerBindingType WGPUSamplerBindingType_BindingNotUsed = WGPUSamplerBindingType_Undefined;
constexpr WGPUTextureSampleType WGPUTextureSampleType_BindingNotUsed = WGPUTextureSampleType_Undefined;
constexpr WGPUStorageTextureAccess WGPUStorageTextureAccess_BindingNotUsed = WGPUStorageTextureAccess_Undefined;

constexpr WGPUFeatureName WGPUFeatureName_DualSourceBlending = static_cast<WGPUFeatureName>(0x00050008);

inline bool WGPUStringViewValid(WGPUStringView Str)
{
return Str != nullptr && Str[0] != '\0';
}

inline const char* WGPUStringViewToString(WGPUStringView Str)
{
return Str;
}

inline WGPUStringView GetWGPUStringView(const std::string& Str)
{
return Str.c_str();
}

inline WGPUStringView GetWGPUStringView(const char* Str)
{
return Str;
}

#else
#endif

inline bool WGPUStringViewValid(const WGPUStringView& Str)
{
Expand All @@ -102,5 +70,3 @@ inline WGPUStringView GetWGPUStringView(const char* Str)
{
return {Str, Str ? strlen(Str) : 0};
}

#endif
Loading
Loading