|
51 | 51 |
|
52 | 52 | #ifndef IMGUI_DISABLE |
53 | 53 | #include "imgui_impl_wgpu.h" |
| 54 | +#include <limits.h> |
| 55 | +#include <stdio.h> |
| 56 | +#include <webgpu/webgpu.h> |
54 | 57 |
|
55 | 58 | // One of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be provided. See imgui_impl_wgpu.h for more details. |
56 | 59 | #if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) == defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) |
|
63 | 66 | #define IMGUI_IMPL_WEBGPU_BACKEND_WGPU_EMSCRIPTEN |
64 | 67 | #endif |
65 | 68 |
|
66 | | -#include <limits.h> |
67 | | -#include <webgpu/webgpu.h> |
68 | | - |
69 | 69 | #ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN |
70 | 70 | // Dawn renamed WGPUProgrammableStageDescriptor to WGPUComputeState (see: https://github.com/webgpu-native/webgpu-headers/pull/413) |
71 | 71 | // Using type alias until WGPU adopts the same naming convention (#8369) |
@@ -920,6 +920,102 @@ void ImGui_ImplWGPU_NewFrame() |
920 | 920 | // Those are currently used by our example applications. |
921 | 921 | //------------------------------------------------------------------------- |
922 | 922 |
|
| 923 | +bool ImGui_ImplWGPU_IsSurfaceStatusError(WGPUSurfaceGetCurrentTextureStatus status) |
| 924 | +{ |
| 925 | +#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) |
| 926 | + return (status == WGPUSurfaceGetCurrentTextureStatus_Error); |
| 927 | +#else |
| 928 | + return (status == WGPUSurfaceGetCurrentTextureStatus_OutOfMemory || status == WGPUSurfaceGetCurrentTextureStatus_DeviceLost); |
| 929 | +#endif |
| 930 | +} |
| 931 | + |
| 932 | +bool ImGui_ImplWGPU_IsSurfaceStatusSubOptimal(WGPUSurfaceGetCurrentTextureStatus status) |
| 933 | +{ |
| 934 | +#if defined(__EMSCRIPTEN__) && !defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) |
| 935 | + return (status == WGPUSurfaceGetCurrentTextureStatus_Timeout || status == WGPUSurfaceGetCurrentTextureStatus_Outdated || status == WGPUSurfaceGetCurrentTextureStatus_Lost); |
| 936 | +#else |
| 937 | + return (status == WGPUSurfaceGetCurrentTextureStatus_Timeout || status == WGPUSurfaceGetCurrentTextureStatus_Outdated || status == WGPUSurfaceGetCurrentTextureStatus_Lost || status == WGPUSurfaceGetCurrentTextureStatus_SuccessSuboptimal); |
| 938 | +#endif |
| 939 | +} |
| 940 | + |
| 941 | +// Helpers to obtain a string |
| 942 | +#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) |
| 943 | +const char* ImGui_ImplWGPU_GetErrorTypeName(WGPUErrorType type) |
| 944 | +{ |
| 945 | + switch (type) |
| 946 | + { |
| 947 | + case WGPUErrorType_Validation: return "Validation"; |
| 948 | + case WGPUErrorType_OutOfMemory: return "OutOfMemory"; |
| 949 | + case WGPUErrorType_Unknown: return "Unknown"; |
| 950 | + case WGPUErrorType_Internal: return "Internal"; |
| 951 | + default: return "Unknown"; |
| 952 | + } |
| 953 | +} |
| 954 | +const char* ImGui_ImplWGPU_GetDeviceLostReasonName(WGPUDeviceLostReason type) |
| 955 | +{ |
| 956 | + switch (type) |
| 957 | + { |
| 958 | + case WGPUDeviceLostReason_Unknown: return "Unknown"; |
| 959 | + case WGPUDeviceLostReason_Destroyed: return "Destroyed"; |
| 960 | + case WGPUDeviceLostReason_CallbackCancelled: return "CallbackCancelled"; |
| 961 | + case WGPUDeviceLostReason_FailedCreation: return "FailedCreation"; |
| 962 | + default: return "Unknown"; |
| 963 | + } |
| 964 | +} |
| 965 | +#elif !defined(__EMSCRIPTEN__) |
| 966 | +const char* ImGui_ImplWGPU_GetLogLevelName(WGPULogLevel level) |
| 967 | +{ |
| 968 | + switch (level) |
| 969 | + { |
| 970 | + case WGPULogLevel_Error: return "Error"; |
| 971 | + case WGPULogLevel_Warn: return "Warn"; |
| 972 | + case WGPULogLevel_Info: return "Info"; |
| 973 | + case WGPULogLevel_Debug: return "Debug"; |
| 974 | + case WGPULogLevel_Trace: return "Trace"; |
| 975 | + default: return "Unknown"; |
| 976 | + } |
| 977 | +} |
| 978 | +#endif |
| 979 | + |
| 980 | +const char* ImGui_ImplWGPU_GetBackendTypeName(WGPUBackendType type) |
| 981 | +{ |
| 982 | + switch (type) |
| 983 | + { |
| 984 | + case WGPUBackendType_WebGPU: return "WebGPU"; |
| 985 | + case WGPUBackendType_D3D11: return "D3D11"; |
| 986 | + case WGPUBackendType_D3D12: return "D3D12"; |
| 987 | + case WGPUBackendType_Metal: return "Metal"; |
| 988 | + case WGPUBackendType_Vulkan: return "Vulkan"; |
| 989 | + case WGPUBackendType_OpenGL: return "OpenGL"; |
| 990 | + case WGPUBackendType_OpenGLES: return "OpenGLES"; |
| 991 | + default: return "Unknown"; |
| 992 | + } |
| 993 | +} |
| 994 | + |
| 995 | +const char* ImGui_ImplWGPU_GetAdapterTypeName(WGPUAdapterType type) |
| 996 | +{ |
| 997 | + switch (type) |
| 998 | + { |
| 999 | + case WGPUAdapterType_DiscreteGPU: return "DiscreteGPU"; |
| 1000 | + case WGPUAdapterType_IntegratedGPU: return "IntegratedGPU"; |
| 1001 | + case WGPUAdapterType_CPU: return "CPU"; |
| 1002 | + default: return "Unknown"; |
| 1003 | + } |
| 1004 | +} |
| 1005 | + |
| 1006 | +void ImGui_ImplWGPU_DebugPrintAdapterInfo(const WGPUAdapter& adapter) |
| 1007 | +{ |
| 1008 | + WGPUAdapterInfo info = {}; |
| 1009 | + wgpuAdapterGetInfo(adapter, &info); |
| 1010 | + printf("description: \"%.*s\"\n", (int)info.description.length, info.description.data); |
| 1011 | + printf("vendor: \"%.*s\", vendorID: %x\n", (int)info.vendor.length, info.vendor.data, info.vendorID); |
| 1012 | + printf("architecture: \"%.*s\"\n", (int) info.architecture.length, info.architecture.data); |
| 1013 | + printf("device: \"%.*s\", deviceID: %x\n", (int)info.device.length, info.device.data, info.deviceID); |
| 1014 | + printf("backendType: \"%s\"\n", ImGui_ImplWGPU_GetBackendTypeName(info.backendType)); |
| 1015 | + printf("adapterType: \"%s\"\n", ImGui_ImplWGPU_GetAdapterTypeName(info.adapterType)); |
| 1016 | + wgpuAdapterInfoFreeMembers(info); |
| 1017 | +} |
| 1018 | + |
923 | 1019 | #if defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) || defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) && !defined(__EMSCRIPTEN__) |
924 | 1020 |
|
925 | 1021 | #if defined(__APPLE__) |
|
0 commit comments