mirror of
https://github.com/ocornut/imgui.git
synced 2026-05-28 03:25:25 +08:00
Backends, Examples: removed Emscripten < 4.0.10 support. Removed IMGUI_IMPL_WEBGPU_BACKEND_WGPU. Amends. (#9281, #8381)
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
|
// 2026-03-09: Removed support for Emscripten < 4.0.10. (#9281)
|
||||||
// 2025-10-16: Update to compile with Dawn and Emscripten's 4.0.10+ '--use-port=emdawnwebgpu' ports. (#8381, #8898)
|
// 2025-10-16: Update to compile with Dawn and Emscripten's 4.0.10+ '--use-port=emdawnwebgpu' ports. (#8381, #8898)
|
||||||
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
|
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
|
||||||
// 2025-06-12: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. (#8465)
|
// 2025-06-12: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. (#8465)
|
||||||
@@ -58,6 +59,9 @@
|
|||||||
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) == defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) == defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
||||||
#error Exactly one of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be defined!
|
#error Exactly one of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be defined!
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(__EMSCRIPTEN__) && defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
||||||
|
#error Emscripten <4.0.10 with '-sUSE_WEBGPU=1' is not supported anymore.
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN
|
#ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN
|
||||||
// Dawn renamed WGPUProgrammableStageDescriptor to WGPUComputeState (see: https://github.com/webgpu-native/webgpu-headers/pull/413)
|
// Dawn renamed WGPUProgrammableStageDescriptor to WGPUComputeState (see: https://github.com/webgpu-native/webgpu-headers/pull/413)
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
// When targeting native platforms:
|
// When targeting native platforms:
|
||||||
// - One of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU *must* be provided.
|
// - One of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU *must* be provided.
|
||||||
// When targeting Emscripten:
|
// When targeting Emscripten:
|
||||||
// - We now defaults to IMGUI_IMPL_WEBGPU_BACKEND_DAWN is Emscripten version is 4.0.10+, which correspond to using Emscripten '--use-port=emdawnwebgpu'.
|
// - We now defaults to IMGUI_IMPL_WEBGPU_BACKEND_DAWN and requires Emscripten 4.0.10+, which correspond to using Emscripten '--use-port=emdawnwebgpu'.
|
||||||
|
// - Emscripten < 4.0.10 is not supported anymore (old '-sUSE_WEBGPU=1' option).
|
||||||
// - We can still define IMGUI_IMPL_WEBGPU_BACKEND_WGPU to use Emscripten '-s USE_WEBGPU=1' which is marked as obsolete by Emscripten.
|
// - We can still define IMGUI_IMPL_WEBGPU_BACKEND_WGPU to use Emscripten '-s USE_WEBGPU=1' which is marked as obsolete by Emscripten.
|
||||||
// Add #define to your imconfig.h file, or as a compilation flag in your build system.
|
// Add #define to your imconfig.h file, or as a compilation flag in your build system.
|
||||||
// This requirement may be removed once WebGPU stabilizes and backends converge on a unified interface.
|
// This requirement may be removed once WebGPU stabilizes and backends converge on a unified interface.
|
||||||
@@ -96,7 +97,7 @@ const char* ImGui_ImplWGPU_GetAdapterTypeName(WGPUAdapterType type);
|
|||||||
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN)
|
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN)
|
||||||
const char* ImGui_ImplWGPU_GetDeviceLostReasonName(WGPUDeviceLostReason type);
|
const char* ImGui_ImplWGPU_GetDeviceLostReasonName(WGPUDeviceLostReason type);
|
||||||
const char* ImGui_ImplWGPU_GetErrorTypeName(WGPUErrorType type);
|
const char* ImGui_ImplWGPU_GetErrorTypeName(WGPUErrorType type);
|
||||||
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) && !defined(__EMSCRIPTEN__)
|
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
||||||
const char* ImGui_ImplWGPU_GetLogLevelName(WGPULogLevel level);
|
const char* ImGui_ImplWGPU_GetLogLevelName(WGPULogLevel level);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -94,12 +94,14 @@ Other Changes:
|
|||||||
- SDLGPU3: removed unnecessary call to SDL_WaitForGPUIdle when releasing
|
- SDLGPU3: removed unnecessary call to SDL_WaitForGPUIdle when releasing
|
||||||
vertex/index buffers. (#9262) [@jaenis]
|
vertex/index buffers. (#9262) [@jaenis]
|
||||||
- WebGPU: fixed version check for Emscripten 5.0.0+.
|
- WebGPU: fixed version check for Emscripten 5.0.0+.
|
||||||
|
- WebGPU: removed support for Emscripten <4.0.10. (#9281) [@ypujante]
|
||||||
- Examples:
|
- Examples:
|
||||||
- Emscripten: added `tabindex=-1` to canvas in our shell_minimal.htm. Without it,
|
- Emscripten: added `tabindex=-1` to canvas in our shell_minimal.htm. Without it,
|
||||||
the canvas was not focusable in the DOM, which in turn make some backends
|
the canvas was not focusable in the DOM, which in turn make some backends
|
||||||
(e.g. pongasoft/emscripten-glfw) not receive focus loss events. (#9259) [@pthom]
|
(e.g. pongasoft/emscripten-glfw) not receive focus loss events. (#9259) [@pthom]
|
||||||
- WGPU: fixed undefined behaviors in example code for requesting adapter
|
- WebGPU: fixed undefined behaviors in example code for requesting adapter
|
||||||
and device. (#9246, #9256) [@r-lyeh]
|
and device. (#9246, #9256) [@r-lyeh]
|
||||||
|
- GLFW/SDL2/SDL3+WebGPU: removed suport for Emscripten <4.0.10. (#9281) [@ypujante]
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
|
|||||||
@@ -60,9 +60,10 @@ For the WASM code produced by Emscripten to work correctly, it will also be nece
|
|||||||
CMake checks the EMSCRIPEN version then:
|
CMake checks the EMSCRIPEN version then:
|
||||||
- if EMS >= 4.0.10 uses `--use-port=emdawnwebgpu` flag to build
|
- if EMS >= 4.0.10 uses `--use-port=emdawnwebgpu` flag to build
|
||||||
- it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
|
- it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
|
||||||
- if EMS < 4.0.10 the build aborts (`-sUSE_WEBGPU=1` is no longer supported in ImGui)
|
- if EMS < 4.0.10 the build aborts (`-sUSE_WEBGPU=1` is no longer supported by our examples and our WGPU backend)
|
||||||
|
|
||||||
#### Generate Emscripten using external WebGPU library (emdawnwebgpu_pkg)
|
#### Generate Emscripten using external WebGPU library (emdawnwebgpu_pkg)
|
||||||
|
|
||||||
- `emcmake cmake -G Ninja -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path_to_emdawnwebgpu_pkg" -B where_to_build_dir`
|
- `emcmake cmake -G Ninja -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path_to_emdawnwebgpu_pkg" -B where_to_build_dir`
|
||||||
- it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
|
- it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
|
||||||
- *To use external WebGPU library it's necessary to have EMS >= 4.0.10 or the minimum requirements specified by the package:*
|
- *To use external WebGPU library it's necessary to have EMS >= 4.0.10 or the minimum requirements specified by the package:*
|
||||||
|
|||||||
@@ -341,17 +341,6 @@ static WGPUDevice RequestDevice(wgpu::Instance& instance, wgpu::Adapter& adapter
|
|||||||
return acquired_device.MoveToCHandle();
|
return acquired_device.MoveToCHandle();
|
||||||
}
|
}
|
||||||
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
// Adapter and device initialization via JS
|
|
||||||
EM_ASYNC_JS( void, getAdapterAndDeviceViaJS, (),
|
|
||||||
{
|
|
||||||
if (!navigator.gpu)
|
|
||||||
throw Error("WebGPU not supported.");
|
|
||||||
const adapter = await navigator.gpu.requestAdapter();
|
|
||||||
const device = await adapter.requestDevice();
|
|
||||||
Module.preinitializedWebGPUDevice = device;
|
|
||||||
} );
|
|
||||||
#else // __EMSCRIPTEN__
|
|
||||||
static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void* userdata1, void* userdata2)
|
static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void* userdata1, void* userdata2)
|
||||||
{
|
{
|
||||||
if (status == WGPURequestAdapterStatus_Success)
|
if (status == WGPURequestAdapterStatus_Success)
|
||||||
@@ -408,7 +397,6 @@ static WGPUDevice RequestDevice(WGPUInstance& instance, WGPUAdapter& adapter)
|
|||||||
IM_ASSERT(local_device && "Error on Device request");
|
IM_ASSERT(local_device && "Error on Device request");
|
||||||
return local_device;
|
return local_device;
|
||||||
}
|
}
|
||||||
#endif // __EMSCRIPTEN__
|
|
||||||
#endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU
|
#endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU
|
||||||
|
|
||||||
bool InitWGPU(GLFWwindow* window)
|
bool InitWGPU(GLFWwindow* window)
|
||||||
@@ -458,23 +446,6 @@ bool InitWGPU(GLFWwindow* window)
|
|||||||
instanceDesc.requiredFeatures = &timedWaitAny;
|
instanceDesc.requiredFeatures = &timedWaitAny;
|
||||||
wgpu_instance = wgpuCreateInstance(&instanceDesc);
|
wgpu_instance = wgpuCreateInstance(&instanceDesc);
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
getAdapterAndDeviceViaJS();
|
|
||||||
|
|
||||||
wgpu_device = emscripten_webgpu_get_device();
|
|
||||||
IM_ASSERT(wgpu_device != nullptr && "Error creating the Device");
|
|
||||||
|
|
||||||
WGPUSurfaceDescriptorFromCanvasHTMLSelector html_surface_desc = {};
|
|
||||||
html_surface_desc.chain.sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector;
|
|
||||||
html_surface_desc.selector = "#canvas";
|
|
||||||
|
|
||||||
WGPUSurfaceDescriptor surface_desc = {};
|
|
||||||
surface_desc.nextInChain = &html_surface_desc.chain;
|
|
||||||
|
|
||||||
// Create the surface.
|
|
||||||
wgpu_surface = wgpuInstanceCreateSurface(wgpu_instance, &surface_desc);
|
|
||||||
preferred_fmt = wgpuSurfaceGetPreferredFormat(wgpu_surface, {} /* adapter */);
|
|
||||||
#else // __EMSCRIPTEN__
|
|
||||||
wgpuSetLogCallback(
|
wgpuSetLogCallback(
|
||||||
[](WGPULogLevel level, WGPUStringView msg, void* userdata) { fprintf(stderr, "%s: %.*s\n", ImGui_ImplWGPU_GetLogLevelName(level), (int)msg.length, msg.data); }, nullptr
|
[](WGPULogLevel level, WGPUStringView msg, void* userdata) { fprintf(stderr, "%s: %.*s\n", ImGui_ImplWGPU_GetLogLevelName(level), (int)msg.length, msg.data); }, nullptr
|
||||||
);
|
);
|
||||||
@@ -494,7 +465,6 @@ bool InitWGPU(GLFWwindow* window)
|
|||||||
wgpuSurfaceGetCapabilities(wgpu_surface, adapter, &surface_capabilities);
|
wgpuSurfaceGetCapabilities(wgpu_surface, adapter, &surface_capabilities);
|
||||||
|
|
||||||
preferred_fmt = surface_capabilities.formats[0];
|
preferred_fmt = surface_capabilities.formats[0];
|
||||||
#endif // __EMSCRIPTEN__
|
|
||||||
#endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU
|
#endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU
|
||||||
|
|
||||||
wgpu_surface_configuration.presentMode = WGPUPresentMode_Fifo;
|
wgpu_surface_configuration.presentMode = WGPUPresentMode_Fifo;
|
||||||
|
|||||||
@@ -60,9 +60,10 @@ For the WASM code produced by Emscripten to work correctly, it will also be nece
|
|||||||
CMake checks the EMSCRIPEN version then:
|
CMake checks the EMSCRIPEN version then:
|
||||||
- if EMS >= 4.0.10 uses `--use-port=emdawnwebgpu` flag to build
|
- if EMS >= 4.0.10 uses `--use-port=emdawnwebgpu` flag to build
|
||||||
- it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
|
- it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
|
||||||
- if EMS < 4.0.10 the build aborts (`-sUSE_WEBGPU=1` is no longer supported in ImGui)
|
- if EMS < 4.0.10 the build aborts (`-sUSE_WEBGPU=1` is no longer supported by our examples and our WGPU backend)
|
||||||
|
|
||||||
#### Generate Emscripten using external WebGPU library (emdawnwebgpu_pkg)
|
#### Generate Emscripten using external WebGPU library (emdawnwebgpu_pkg)
|
||||||
|
|
||||||
- `emcmake cmake -G Ninja -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path_to_emdawnwebgpu_pkg" -B where_to_build_dir`
|
- `emcmake cmake -G Ninja -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path_to_emdawnwebgpu_pkg" -B where_to_build_dir`
|
||||||
- it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
|
- it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
|
||||||
- *To use external WebGPU library it's necessary to have EMS >= 4.0.10 or the minimum requirements specified by the package:*
|
- *To use external WebGPU library it's necessary to have EMS >= 4.0.10 or the minimum requirements specified by the package:*
|
||||||
|
|||||||
@@ -325,17 +325,6 @@ static WGPUDevice RequestDevice(wgpu::Instance& instance, wgpu::Adapter& adapter
|
|||||||
return acquired_device.MoveToCHandle();
|
return acquired_device.MoveToCHandle();
|
||||||
}
|
}
|
||||||
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
// Adapter and device initialization via JS
|
|
||||||
EM_ASYNC_JS( void, getAdapterAndDeviceViaJS, (),
|
|
||||||
{
|
|
||||||
if (!navigator.gpu)
|
|
||||||
throw Error("WebGPU not supported.");
|
|
||||||
const adapter = await navigator.gpu.requestAdapter();
|
|
||||||
const device = await adapter.requestDevice();
|
|
||||||
Module.preinitializedWebGPUDevice = device;
|
|
||||||
} );
|
|
||||||
#else // __EMSCRIPTEN__
|
|
||||||
static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void* userdata1, void* userdata2)
|
static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void* userdata1, void* userdata2)
|
||||||
{
|
{
|
||||||
if (status == WGPURequestAdapterStatus_Success)
|
if (status == WGPURequestAdapterStatus_Success)
|
||||||
@@ -392,7 +381,6 @@ static WGPUDevice RequestDevice(WGPUInstance& instance, WGPUAdapter& adapter)
|
|||||||
IM_ASSERT(local_device && "Error on Device request");
|
IM_ASSERT(local_device && "Error on Device request");
|
||||||
return local_device;
|
return local_device;
|
||||||
}
|
}
|
||||||
#endif // __EMSCRIPTEN__
|
|
||||||
#endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU
|
#endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU
|
||||||
|
|
||||||
static bool InitWGPU(SDL_Window* window)
|
static bool InitWGPU(SDL_Window* window)
|
||||||
@@ -443,23 +431,6 @@ static bool InitWGPU(SDL_Window* window)
|
|||||||
instanceDesc.requiredFeatures = &timedWaitAny;
|
instanceDesc.requiredFeatures = &timedWaitAny;
|
||||||
wgpu_instance = wgpuCreateInstance(&instanceDesc);
|
wgpu_instance = wgpuCreateInstance(&instanceDesc);
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
getAdapterAndDeviceViaJS();
|
|
||||||
|
|
||||||
wgpu_device = emscripten_webgpu_get_device();
|
|
||||||
assert(wgpu_device != nullptr && "Error creating the Device");
|
|
||||||
|
|
||||||
WGPUSurfaceDescriptorFromCanvasHTMLSelector html_surface_desc = {};
|
|
||||||
html_surface_desc.chain.sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector;
|
|
||||||
html_surface_desc.selector = "#canvas";
|
|
||||||
|
|
||||||
WGPUSurfaceDescriptor surface_desc = {};
|
|
||||||
surface_desc.nextInChain = &html_surface_desc.chain;
|
|
||||||
|
|
||||||
// Create the surface.
|
|
||||||
wgpu_surface = wgpuInstanceCreateSurface(wgpu_instance, &surface_desc);
|
|
||||||
preferred_fmt = wgpuSurfaceGetPreferredFormat(wgpu_surface, {} /* adapter */);
|
|
||||||
#else // __EMSCRIPTEN__
|
|
||||||
wgpuSetLogCallback(
|
wgpuSetLogCallback(
|
||||||
[](WGPULogLevel level, WGPUStringView msg, void* userdata) { fprintf(stderr, "%s: %.*s\n", ImGui_ImplWGPU_GetLogLevelName(level), (int)msg.length, msg.data); }, nullptr
|
[](WGPULogLevel level, WGPUStringView msg, void* userdata) { fprintf(stderr, "%s: %.*s\n", ImGui_ImplWGPU_GetLogLevelName(level), (int)msg.length, msg.data); }, nullptr
|
||||||
);
|
);
|
||||||
@@ -479,7 +450,6 @@ static bool InitWGPU(SDL_Window* window)
|
|||||||
wgpuSurfaceGetCapabilities(wgpu_surface, adapter, &surface_capabilities);
|
wgpuSurfaceGetCapabilities(wgpu_surface, adapter, &surface_capabilities);
|
||||||
|
|
||||||
preferred_fmt = surface_capabilities.formats[0];
|
preferred_fmt = surface_capabilities.formats[0];
|
||||||
#endif // __EMSCRIPTEN__
|
|
||||||
#endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU
|
#endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU
|
||||||
|
|
||||||
wgpu_surface_configuration.presentMode = WGPUPresentMode_Fifo;
|
wgpu_surface_configuration.presentMode = WGPUPresentMode_Fifo;
|
||||||
|
|||||||
@@ -60,9 +60,10 @@ For the WASM code produced by Emscripten to work correctly, it will also be nece
|
|||||||
CMake checks the EMSCRIPEN version then:
|
CMake checks the EMSCRIPEN version then:
|
||||||
- if EMS >= 4.0.10 uses `--use-port=emdawnwebgpu` flag to build
|
- if EMS >= 4.0.10 uses `--use-port=emdawnwebgpu` flag to build
|
||||||
- it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
|
- it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
|
||||||
- if EMS < 4.0.10 the build aborts (`-sUSE_WEBGPU=1` is no longer supported in ImGui)
|
- if EMS < 4.0.10 the build aborts (`-sUSE_WEBGPU=1` is no longer supported by our examples and our WGPU backend
|
||||||
|
|
||||||
#### Generate Emscripten using external WebGPU library (emdawnwebgpu_pkg)
|
#### Generate Emscripten using external WebGPU library (emdawnwebgpu_pkg)
|
||||||
|
|
||||||
- `emcmake cmake -G Ninja -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path_to_emdawnwebgpu_pkg" -B where_to_build_dir`
|
- `emcmake cmake -G Ninja -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path_to_emdawnwebgpu_pkg" -B where_to_build_dir`
|
||||||
- it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
|
- it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
|
||||||
- *To use external WebGPU library it's necessary to have EMS >= 4.0.10 or the minimum requirements specified by the package:*
|
- *To use external WebGPU library it's necessary to have EMS >= 4.0.10 or the minimum requirements specified by the package:*
|
||||||
|
|||||||
@@ -336,17 +336,6 @@ static WGPUDevice RequestDevice(wgpu::Instance& instance, wgpu::Adapter& adapter
|
|||||||
return acquired_device.MoveToCHandle();
|
return acquired_device.MoveToCHandle();
|
||||||
}
|
}
|
||||||
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
// Adapter and device initialization via JS
|
|
||||||
EM_ASYNC_JS( void, getAdapterAndDeviceViaJS, (),
|
|
||||||
{
|
|
||||||
if (!navigator.gpu)
|
|
||||||
throw Error("WebGPU not supported.");
|
|
||||||
const adapter = await navigator.gpu.requestAdapter();
|
|
||||||
const device = await adapter.requestDevice();
|
|
||||||
Module.preinitializedWebGPUDevice = device;
|
|
||||||
} );
|
|
||||||
#else // __EMSCRIPTEN__
|
|
||||||
static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void* userdata1, void* userdata2)
|
static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void* userdata1, void* userdata2)
|
||||||
{
|
{
|
||||||
if (status == WGPURequestAdapterStatus_Success)
|
if (status == WGPURequestAdapterStatus_Success)
|
||||||
@@ -403,7 +392,6 @@ static WGPUDevice RequestDevice(WGPUInstance& instance, WGPUAdapter& adapter)
|
|||||||
IM_ASSERT(local_device && "Error on Device request");
|
IM_ASSERT(local_device && "Error on Device request");
|
||||||
return local_device;
|
return local_device;
|
||||||
}
|
}
|
||||||
#endif // __EMSCRIPTEN__
|
|
||||||
#endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU
|
#endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU
|
||||||
|
|
||||||
static bool InitWGPU(SDL_Window* window)
|
static bool InitWGPU(SDL_Window* window)
|
||||||
@@ -454,23 +442,6 @@ static bool InitWGPU(SDL_Window* window)
|
|||||||
instanceDesc.requiredFeatures = &timedWaitAny;
|
instanceDesc.requiredFeatures = &timedWaitAny;
|
||||||
wgpu_instance = wgpuCreateInstance(&instanceDesc);
|
wgpu_instance = wgpuCreateInstance(&instanceDesc);
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
getAdapterAndDeviceViaJS();
|
|
||||||
|
|
||||||
wgpu_device = emscripten_webgpu_get_device();
|
|
||||||
IM_ASSERT(wgpu_device != nullptr && "Error creating the Device");
|
|
||||||
|
|
||||||
WGPUSurfaceDescriptorFromCanvasHTMLSelector html_surface_desc = {};
|
|
||||||
html_surface_desc.chain.sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector;
|
|
||||||
html_surface_desc.selector = "#canvas";
|
|
||||||
|
|
||||||
WGPUSurfaceDescriptor surface_desc = {};
|
|
||||||
surface_desc.nextInChain = &html_surface_desc.chain;
|
|
||||||
|
|
||||||
// Create the surface.
|
|
||||||
wgpu_surface = wgpuInstanceCreateSurface(wgpu_instance, &surface_desc);
|
|
||||||
preferred_fmt = wgpuSurfaceGetPreferredFormat(wgpu_surface, {} /* adapter */);
|
|
||||||
#else // __EMSCRIPTEN__
|
|
||||||
wgpuSetLogCallback(
|
wgpuSetLogCallback(
|
||||||
[](WGPULogLevel level, WGPUStringView msg, void* userdata) { fprintf(stderr, "%s: %.*s\n", ImGui_ImplWGPU_GetLogLevelName(level), (int)msg.length, msg.data); }, nullptr
|
[](WGPULogLevel level, WGPUStringView msg, void* userdata) { fprintf(stderr, "%s: %.*s\n", ImGui_ImplWGPU_GetLogLevelName(level), (int)msg.length, msg.data); }, nullptr
|
||||||
);
|
);
|
||||||
@@ -490,7 +461,6 @@ static bool InitWGPU(SDL_Window* window)
|
|||||||
wgpuSurfaceGetCapabilities(wgpu_surface, adapter, &surface_capabilities);
|
wgpuSurfaceGetCapabilities(wgpu_surface, adapter, &surface_capabilities);
|
||||||
|
|
||||||
preferred_fmt = surface_capabilities.formats[0];
|
preferred_fmt = surface_capabilities.formats[0];
|
||||||
#endif // __EMSCRIPTEN__
|
|
||||||
#endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU
|
#endif // IMGUI_IMPL_WEBGPU_BACKEND_WGPU
|
||||||
|
|
||||||
wgpu_surface_configuration.presentMode = WGPUPresentMode_Fifo;
|
wgpu_surface_configuration.presentMode = WGPUPresentMode_Fifo;
|
||||||
|
|||||||
Reference in New Issue
Block a user