Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make WebGPU backend portable to emscripten, Dawn, and wgpu-native #6188

Closed
Closed
Changes from 2 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
24 changes: 23 additions & 1 deletion backends/imgui_impl_wgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 2023-04-11: Align buffer sizes. Use WGSL shaders instead of precompiled SPIR-V.
// 2023-04-11: Align buffer sizes. Use WGSL shaders instead of precompiled SPIR-V. Adapt to wgpu-native backend. Define WEBGPU_BACKEND_WGPU when using the wgpu-backend.
// 2023-04-11: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
// 2023-01-25: Revert automatic pipeline layout generation (see https://github.com/gpuweb/gpuweb/issues/2470)
// 2022-11-24: Fixed validation error with default depth buffer settings.
Expand All @@ -32,6 +32,20 @@
#include <limits.h>
#include <webgpu/webgpu.h>

// These differences of implementation should vanish as soon as WebGPU gets in version 1.0 stable
#ifdef WEBGPU_BACKEND_WGPU
#include <webgpu/wgpu.h>
#define wgpuBindGroupLayoutRelease wgpuBindGroupLayoutDrop
#define wgpuBindGroupRelease wgpuBindGroupDrop
#define wgpuRenderPipelineRelease wgpuRenderPipelineDrop
#define wgpuSamplerRelease wgpuSamplerDrop
#define wgpuShaderModuleRelease wgpuShaderModuleDrop
#define wgpuTextureViewRelease wgpuTextureViewDrop
#define wgpuTextureRelease wgpuTextureDrop
#define wgpuBufferRelease wgpuBufferDrop
#define wgpuQueueRelease(...)
#endif // WEBGPU_BACKEND_WGPU

// Dear ImGui prototypes from imgui_internal.h
extern ImGuiID ImHashData(const void* data_p, size_t data_size, ImU32 seed = 0);
#define MEMALIGN(_SIZE,_ALIGN) (((_SIZE) + ((_ALIGN) - 1)) & ~((_ALIGN) - 1)) // Memory align (copied from IM_ALIGN() macro).
Expand Down Expand Up @@ -230,7 +244,11 @@ static WGPUProgrammableStageDescriptor ImGui_ImplWGPU_CreateShaderModule(const c

WGPUShaderModuleWGSLDescriptor wgsl_desc = {};
wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor;
#if defined(WEBGPU_BACKEND_WGPU)
eliemichel marked this conversation as resolved.
Show resolved Hide resolved
wgsl_desc.code = wgsl_source;
#else
wgsl_desc.source = wgsl_source;
#endif

WGPUShaderModuleDescriptor desc = {};
desc.nextInChain = reinterpret_cast<WGPUChainedStruct*>(&wgsl_desc);
Expand Down Expand Up @@ -511,7 +529,11 @@ static void ImGui_ImplWGPU_CreateFontsTexture()
WGPUSamplerDescriptor sampler_desc = {};
sampler_desc.minFilter = WGPUFilterMode_Linear;
sampler_desc.magFilter = WGPUFilterMode_Linear;
#if defined(WEBGPU_BACKEND_WGPU)
sampler_desc.mipmapFilter = WGPUMipmapFilterMode_Linear;
eliemichel marked this conversation as resolved.
Show resolved Hide resolved
#else
sampler_desc.mipmapFilter = WGPUFilterMode_Linear;
#endif
sampler_desc.addressModeU = WGPUAddressMode_Repeat;
sampler_desc.addressModeV = WGPUAddressMode_Repeat;
sampler_desc.addressModeW = WGPUAddressMode_Repeat;
Expand Down