mirror of
https://github.com/ocornut/imgui.git
synced 2026-05-13 08:54:51 +00:00
Backends: WebGPU: detect WGSL support at runtime instead of excluding WGVK at compile time. (#9387)
Previously WGVK was hard-disabled from WGSL via #if !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGVK), forcing the SPIRV fallback unconditionally. Now the WGSL path is attempted on all backends and an empty stage_desc is returned when the module fails to compile letting the existing SPIRV fallback at the call site kick in.
This commit is contained in:
@@ -328,11 +328,31 @@ static WGPUProgrammableStageDescriptor ImGui_ImplWGPU_CreateShaderModuleWGSL(con
|
||||
WGPUShaderModuleDescriptor desc = {};
|
||||
desc.nextInChain = (WGPUChainedStruct*)&wgsl_desc;
|
||||
|
||||
// Detect shader compilation errors by using an error scope.
|
||||
// Flag to be passed into the validation callback `userdata1` pointer.
|
||||
int validation_error = 0;
|
||||
wgpuDevicePushErrorScope(bd->wgpuDevice, WGPUErrorFilter_Validation);
|
||||
WGPUShaderModule module = wgpuDeviceCreateShaderModule(bd->wgpuDevice, &desc);
|
||||
WGPUPopErrorScopeCallbackInfo pop_cb = {};
|
||||
pop_cb.mode = WGPUCallbackMode_AllowSpontaneous;
|
||||
pop_cb.callback = [](WGPUPopErrorScopeStatus, WGPUErrorType type, WGPUStringView, void* userdata1, void*)
|
||||
{
|
||||
if (type == WGPUErrorType_Validation)
|
||||
*static_cast<int*>(userdata1) = 1;
|
||||
};
|
||||
pop_cb.userdata1 = &validation_error;
|
||||
wgpuDevicePopErrorScope(bd->wgpuDevice, pop_cb);
|
||||
|
||||
WGPUProgrammableStageDescriptor stage_desc = {};
|
||||
#if !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGVK)
|
||||
stage_desc.module = wgpuDeviceCreateShaderModule(bd->wgpuDevice, &desc);
|
||||
stage_desc.entryPoint = { "main", WGPU_STRLEN };
|
||||
#endif
|
||||
if (module && !validation_error)
|
||||
{
|
||||
stage_desc.module = module;
|
||||
stage_desc.entryPoint = { "main", WGPU_STRLEN };
|
||||
}
|
||||
else if (module)
|
||||
{
|
||||
wgpuShaderModuleRelease(module);
|
||||
}
|
||||
return stage_desc;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user