imgui_impl_wgpu.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. // dear imgui: Renderer for WebGPU
  2. // This needs to be used along with a Platform Binding (e.g. GLFW)
  3. // (Please note that WebGPU is currently experimental, will not run on non-beta browsers, and may break.)
  4. // Implemented features:
  5. // [X] Renderer: User texture binding. Use 'WGPUTextureView' as ImTextureID. Read the FAQ about ImTextureID!
  6. // [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
  7. // [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
  8. // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
  9. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
  10. // Learn about Dear ImGui:
  11. // - FAQ https://dearimgui.com/faq
  12. // - Getting Started https://dearimgui.com/getting-started
  13. // - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
  14. // - Introduction, links and more at the top of imgui.cpp
  15. // CHANGELOG
  16. // (minor and older changes stripped away, please see git history for details)
  17. // 2024-10-14: Update Dawn support for change of string usages. (#8082, #8083)
  18. // 2024-10-07: Expose selected render state in ImGui_ImplWGPU_RenderState, which you can access in 'void* platform_io.Renderer_RenderState' during draw callbacks.
  19. // 2024-10-07: Changed default texture sampler to Clamp instead of Repeat/Wrap.
  20. // 2024-09-16: Added support for optional IMGUI_IMPL_WEBGPU_BACKEND_DAWN / IMGUI_IMPL_WEBGPU_BACKEND_WGPU define to handle ever-changing native implementations. (#7977)
  21. // 2024-01-22: Added configurable PipelineMultisampleState struct. (#7240)
  22. // 2024-01-22: (Breaking) ImGui_ImplWGPU_Init() now takes a ImGui_ImplWGPU_InitInfo structure instead of variety of parameters, allowing for easier further changes.
  23. // 2024-01-22: Fixed pipeline layout leak. (#7245)
  24. // 2024-01-17: Explicitly fill all of WGPUDepthStencilState since standard removed defaults.
  25. // 2023-07-13: Use WGPUShaderModuleWGSLDescriptor's code instead of source. use WGPUMipmapFilterMode_Linear instead of WGPUFilterMode_Linear. (#6602)
  26. // 2023-04-11: Align buffer sizes. Use WGSL shaders instead of precompiled SPIR-V.
  27. // 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).
  28. // 2023-01-25: Revert automatic pipeline layout generation (see https://github.com/gpuweb/gpuweb/issues/2470)
  29. // 2022-11-24: Fixed validation error with default depth buffer settings.
  30. // 2022-11-10: Fixed rendering when a depth buffer is enabled. Added 'WGPUTextureFormat depth_format' parameter to ImGui_ImplWGPU_Init().
  31. // 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
  32. // 2021-11-29: Passing explicit buffer sizes to wgpuRenderPassEncoderSetVertexBuffer()/wgpuRenderPassEncoderSetIndexBuffer().
  33. // 2021-08-24: Fixed for latest specs.
  34. // 2021-05-24: Add support for draw_data->FramebufferScale.
  35. // 2021-05-19: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
  36. // 2021-05-16: Update to latest WebGPU specs (compatible with Emscripten 2.0.20 and Chrome Canary 92).
  37. // 2021-02-18: Change blending equation to preserve alpha in output buffer.
  38. // 2021-01-28: Initial version.
  39. // When targeting native platforms (i.e. NOT emscripten), one of IMGUI_IMPL_WEBGPU_BACKEND_DAWN
  40. // or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be provided. See imgui_impl_wgpu.h for more details.
  41. #ifndef __EMSCRIPTEN__
  42. #if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) == defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
  43. #error exactly one of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be defined!
  44. #endif
  45. #else
  46. #if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) || defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
  47. #error neither IMGUI_IMPL_WEBGPU_BACKEND_DAWN nor IMGUI_IMPL_WEBGPU_BACKEND_WGPU may be defined if targeting emscripten!
  48. #endif
  49. #endif
  50. #include "imgui.h"
  51. #ifndef IMGUI_DISABLE
  52. #include "imgui_impl_wgpu.h"
  53. #include <limits.h>
  54. #include <webgpu/webgpu.h>
  55. // Dear ImGui prototypes from imgui_internal.h
  56. extern ImGuiID ImHashData(const void* data_p, size_t data_size, ImU32 seed = 0);
  57. #define MEMALIGN(_SIZE,_ALIGN) (((_SIZE) + ((_ALIGN) - 1)) & ~((_ALIGN) - 1)) // Memory align (copied from IM_ALIGN() macro).
  58. // WebGPU data
  59. struct RenderResources
  60. {
  61. WGPUTexture FontTexture = nullptr; // Font texture
  62. WGPUTextureView FontTextureView = nullptr; // Texture view for font texture
  63. WGPUSampler Sampler = nullptr; // Sampler for the font texture
  64. WGPUBuffer Uniforms = nullptr; // Shader uniforms
  65. WGPUBindGroup CommonBindGroup = nullptr; // Resources bind-group to bind the common resources to pipeline
  66. ImGuiStorage ImageBindGroups; // Resources bind-group to bind the font/image resources to pipeline (this is a key->value map)
  67. WGPUBindGroup ImageBindGroup = nullptr; // Default font-resource of Dear ImGui
  68. WGPUBindGroupLayout ImageBindGroupLayout = nullptr; // Cache layout used for the image bind group. Avoids allocating unnecessary JS objects when working with WebASM
  69. };
  70. struct FrameResources
  71. {
  72. WGPUBuffer IndexBuffer;
  73. WGPUBuffer VertexBuffer;
  74. ImDrawIdx* IndexBufferHost;
  75. ImDrawVert* VertexBufferHost;
  76. int IndexBufferSize;
  77. int VertexBufferSize;
  78. };
  79. struct Uniforms
  80. {
  81. float MVP[4][4];
  82. float Gamma;
  83. };
  84. struct ImGui_ImplWGPU_Data
  85. {
  86. ImGui_ImplWGPU_InitInfo initInfo;
  87. WGPUDevice wgpuDevice = nullptr;
  88. WGPUQueue defaultQueue = nullptr;
  89. WGPUTextureFormat renderTargetFormat = WGPUTextureFormat_Undefined;
  90. WGPUTextureFormat depthStencilFormat = WGPUTextureFormat_Undefined;
  91. WGPURenderPipeline pipelineState = nullptr;
  92. RenderResources renderResources;
  93. FrameResources* pFrameResources = nullptr;
  94. unsigned int numFramesInFlight = 0;
  95. unsigned int frameIndex = UINT_MAX;
  96. };
  97. // Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
  98. // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
  99. static ImGui_ImplWGPU_Data* ImGui_ImplWGPU_GetBackendData()
  100. {
  101. return ImGui::GetCurrentContext() ? (ImGui_ImplWGPU_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
  102. }
  103. //-----------------------------------------------------------------------------
  104. // SHADERS
  105. //-----------------------------------------------------------------------------
  106. static const char __shader_vert_wgsl[] = R"(
  107. struct VertexInput {
  108. @location(0) position: vec2<f32>,
  109. @location(1) uv: vec2<f32>,
  110. @location(2) color: vec4<f32>,
  111. };
  112. struct VertexOutput {
  113. @builtin(position) position: vec4<f32>,
  114. @location(0) color: vec4<f32>,
  115. @location(1) uv: vec2<f32>,
  116. };
  117. struct Uniforms {
  118. mvp: mat4x4<f32>,
  119. gamma: f32,
  120. };
  121. @group(0) @binding(0) var<uniform> uniforms: Uniforms;
  122. @vertex
  123. fn main(in: VertexInput) -> VertexOutput {
  124. var out: VertexOutput;
  125. out.position = uniforms.mvp * vec4<f32>(in.position, 0.0, 1.0);
  126. out.color = in.color;
  127. out.uv = in.uv;
  128. return out;
  129. }
  130. )";
  131. static const char __shader_frag_wgsl[] = R"(
  132. struct VertexOutput {
  133. @builtin(position) position: vec4<f32>,
  134. @location(0) color: vec4<f32>,
  135. @location(1) uv: vec2<f32>,
  136. };
  137. struct Uniforms {
  138. mvp: mat4x4<f32>,
  139. gamma: f32,
  140. };
  141. @group(0) @binding(0) var<uniform> uniforms: Uniforms;
  142. @group(0) @binding(1) var s: sampler;
  143. @group(1) @binding(0) var t: texture_2d<f32>;
  144. @fragment
  145. fn main(in: VertexOutput) -> @location(0) vec4<f32> {
  146. let color = in.color * textureSample(t, s, in.uv);
  147. let corrected_color = pow(color.rgb, vec3<f32>(uniforms.gamma));
  148. return vec4<f32>(corrected_color, color.a);
  149. }
  150. )";
  151. static void SafeRelease(ImDrawIdx*& res)
  152. {
  153. if (res)
  154. delete[] res;
  155. res = nullptr;
  156. }
  157. static void SafeRelease(ImDrawVert*& res)
  158. {
  159. if (res)
  160. delete[] res;
  161. res = nullptr;
  162. }
  163. static void SafeRelease(WGPUBindGroupLayout& res)
  164. {
  165. if (res)
  166. wgpuBindGroupLayoutRelease(res);
  167. res = nullptr;
  168. }
  169. static void SafeRelease(WGPUBindGroup& res)
  170. {
  171. if (res)
  172. wgpuBindGroupRelease(res);
  173. res = nullptr;
  174. }
  175. static void SafeRelease(WGPUBuffer& res)
  176. {
  177. if (res)
  178. wgpuBufferRelease(res);
  179. res = nullptr;
  180. }
  181. static void SafeRelease(WGPUPipelineLayout& res)
  182. {
  183. if (res)
  184. wgpuPipelineLayoutRelease(res);
  185. res = nullptr;
  186. }
  187. static void SafeRelease(WGPURenderPipeline& res)
  188. {
  189. if (res)
  190. wgpuRenderPipelineRelease(res);
  191. res = nullptr;
  192. }
  193. static void SafeRelease(WGPUSampler& res)
  194. {
  195. if (res)
  196. wgpuSamplerRelease(res);
  197. res = nullptr;
  198. }
  199. static void SafeRelease(WGPUShaderModule& res)
  200. {
  201. if (res)
  202. wgpuShaderModuleRelease(res);
  203. res = nullptr;
  204. }
  205. static void SafeRelease(WGPUTextureView& res)
  206. {
  207. if (res)
  208. wgpuTextureViewRelease(res);
  209. res = nullptr;
  210. }
  211. static void SafeRelease(WGPUTexture& res)
  212. {
  213. if (res)
  214. wgpuTextureRelease(res);
  215. res = nullptr;
  216. }
  217. static void SafeRelease(RenderResources& res)
  218. {
  219. SafeRelease(res.FontTexture);
  220. SafeRelease(res.FontTextureView);
  221. SafeRelease(res.Sampler);
  222. SafeRelease(res.Uniforms);
  223. SafeRelease(res.CommonBindGroup);
  224. SafeRelease(res.ImageBindGroup);
  225. SafeRelease(res.ImageBindGroupLayout);
  226. };
  227. static void SafeRelease(FrameResources& res)
  228. {
  229. SafeRelease(res.IndexBuffer);
  230. SafeRelease(res.VertexBuffer);
  231. SafeRelease(res.IndexBufferHost);
  232. SafeRelease(res.VertexBufferHost);
  233. }
  234. static WGPUProgrammableStageDescriptor ImGui_ImplWGPU_CreateShaderModule(const char* wgsl_source)
  235. {
  236. ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
  237. #ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN
  238. WGPUShaderSourceWGSL wgsl_desc = {};
  239. wgsl_desc.chain.sType = WGPUSType_ShaderSourceWGSL;
  240. wgsl_desc.code = { wgsl_source, WGPU_STRLEN };
  241. #else
  242. WGPUShaderModuleWGSLDescriptor wgsl_desc = {};
  243. wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor;
  244. wgsl_desc.code = wgsl_source;
  245. #endif
  246. WGPUShaderModuleDescriptor desc = {};
  247. desc.nextInChain = reinterpret_cast<WGPUChainedStruct*>(&wgsl_desc);
  248. WGPUProgrammableStageDescriptor stage_desc = {};
  249. stage_desc.module = wgpuDeviceCreateShaderModule(bd->wgpuDevice, &desc);
  250. #ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN
  251. stage_desc.entryPoint = { "main", WGPU_STRLEN };
  252. #else
  253. stage_desc.entryPoint = "main";
  254. #endif
  255. return stage_desc;
  256. }
  257. static WGPUBindGroup ImGui_ImplWGPU_CreateImageBindGroup(WGPUBindGroupLayout layout, WGPUTextureView texture)
  258. {
  259. ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
  260. WGPUBindGroupEntry image_bg_entries[] = { { nullptr, 0, 0, 0, 0, 0, texture } };
  261. WGPUBindGroupDescriptor image_bg_descriptor = {};
  262. image_bg_descriptor.layout = layout;
  263. image_bg_descriptor.entryCount = sizeof(image_bg_entries) / sizeof(WGPUBindGroupEntry);
  264. image_bg_descriptor.entries = image_bg_entries;
  265. return wgpuDeviceCreateBindGroup(bd->wgpuDevice, &image_bg_descriptor);
  266. }
  267. static void ImGui_ImplWGPU_SetupRenderState(ImDrawData* draw_data, WGPURenderPassEncoder ctx, FrameResources* fr)
  268. {
  269. ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
  270. // Setup orthographic projection matrix into our constant buffer
  271. // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right).
  272. {
  273. float L = draw_data->DisplayPos.x;
  274. float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
  275. float T = draw_data->DisplayPos.y;
  276. float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
  277. float mvp[4][4] =
  278. {
  279. { 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
  280. { 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
  281. { 0.0f, 0.0f, 0.5f, 0.0f },
  282. { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
  283. };
  284. wgpuQueueWriteBuffer(bd->defaultQueue, bd->renderResources.Uniforms, offsetof(Uniforms, MVP), mvp, sizeof(Uniforms::MVP));
  285. float gamma;
  286. switch (bd->renderTargetFormat)
  287. {
  288. case WGPUTextureFormat_ASTC10x10UnormSrgb:
  289. case WGPUTextureFormat_ASTC10x5UnormSrgb:
  290. case WGPUTextureFormat_ASTC10x6UnormSrgb:
  291. case WGPUTextureFormat_ASTC10x8UnormSrgb:
  292. case WGPUTextureFormat_ASTC12x10UnormSrgb:
  293. case WGPUTextureFormat_ASTC12x12UnormSrgb:
  294. case WGPUTextureFormat_ASTC4x4UnormSrgb:
  295. case WGPUTextureFormat_ASTC5x5UnormSrgb:
  296. case WGPUTextureFormat_ASTC6x5UnormSrgb:
  297. case WGPUTextureFormat_ASTC6x6UnormSrgb:
  298. case WGPUTextureFormat_ASTC8x5UnormSrgb:
  299. case WGPUTextureFormat_ASTC8x6UnormSrgb:
  300. case WGPUTextureFormat_ASTC8x8UnormSrgb:
  301. case WGPUTextureFormat_BC1RGBAUnormSrgb:
  302. case WGPUTextureFormat_BC2RGBAUnormSrgb:
  303. case WGPUTextureFormat_BC3RGBAUnormSrgb:
  304. case WGPUTextureFormat_BC7RGBAUnormSrgb:
  305. case WGPUTextureFormat_BGRA8UnormSrgb:
  306. case WGPUTextureFormat_ETC2RGB8A1UnormSrgb:
  307. case WGPUTextureFormat_ETC2RGB8UnormSrgb:
  308. case WGPUTextureFormat_ETC2RGBA8UnormSrgb:
  309. case WGPUTextureFormat_RGBA8UnormSrgb:
  310. gamma = 2.2f;
  311. break;
  312. default:
  313. gamma = 1.0f;
  314. }
  315. wgpuQueueWriteBuffer(bd->defaultQueue, bd->renderResources.Uniforms, offsetof(Uniforms, Gamma), &gamma, sizeof(Uniforms::Gamma));
  316. }
  317. // Setup viewport
  318. wgpuRenderPassEncoderSetViewport(ctx, 0, 0, draw_data->FramebufferScale.x * draw_data->DisplaySize.x, draw_data->FramebufferScale.y * draw_data->DisplaySize.y, 0, 1);
  319. // Bind shader and vertex buffers
  320. wgpuRenderPassEncoderSetVertexBuffer(ctx, 0, fr->VertexBuffer, 0, fr->VertexBufferSize * sizeof(ImDrawVert));
  321. wgpuRenderPassEncoderSetIndexBuffer(ctx, fr->IndexBuffer, sizeof(ImDrawIdx) == 2 ? WGPUIndexFormat_Uint16 : WGPUIndexFormat_Uint32, 0, fr->IndexBufferSize * sizeof(ImDrawIdx));
  322. wgpuRenderPassEncoderSetPipeline(ctx, bd->pipelineState);
  323. wgpuRenderPassEncoderSetBindGroup(ctx, 0, bd->renderResources.CommonBindGroup, 0, nullptr);
  324. // Setup blend factor
  325. WGPUColor blend_color = { 0.f, 0.f, 0.f, 0.f };
  326. wgpuRenderPassEncoderSetBlendConstant(ctx, &blend_color);
  327. }
  328. // Render function
  329. // (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
  330. void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder pass_encoder)
  331. {
  332. // Avoid rendering when minimized
  333. int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
  334. int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
  335. if (fb_width <= 0 || fb_height <= 0 || draw_data->CmdListsCount == 0)
  336. return;
  337. // FIXME: Assuming that this only gets called once per frame!
  338. // If not, we can't just re-allocate the IB or VB, we'll have to do a proper allocator.
  339. ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
  340. bd->frameIndex = bd->frameIndex + 1;
  341. FrameResources* fr = &bd->pFrameResources[bd->frameIndex % bd->numFramesInFlight];
  342. // Create and grow vertex/index buffers if needed
  343. if (fr->VertexBuffer == nullptr || fr->VertexBufferSize < draw_data->TotalVtxCount)
  344. {
  345. if (fr->VertexBuffer)
  346. {
  347. wgpuBufferDestroy(fr->VertexBuffer);
  348. wgpuBufferRelease(fr->VertexBuffer);
  349. }
  350. SafeRelease(fr->VertexBufferHost);
  351. fr->VertexBufferSize = draw_data->TotalVtxCount + 5000;
  352. WGPUBufferDescriptor vb_desc =
  353. {
  354. nullptr,
  355. "Dear ImGui Vertex buffer",
  356. #ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN
  357. WGPU_STRLEN,
  358. #endif
  359. WGPUBufferUsage_CopyDst | WGPUBufferUsage_Vertex,
  360. MEMALIGN(fr->VertexBufferSize * sizeof(ImDrawVert), 4),
  361. false
  362. };
  363. fr->VertexBuffer = wgpuDeviceCreateBuffer(bd->wgpuDevice, &vb_desc);
  364. if (!fr->VertexBuffer)
  365. return;
  366. fr->VertexBufferHost = new ImDrawVert[fr->VertexBufferSize];
  367. }
  368. if (fr->IndexBuffer == nullptr || fr->IndexBufferSize < draw_data->TotalIdxCount)
  369. {
  370. if (fr->IndexBuffer)
  371. {
  372. wgpuBufferDestroy(fr->IndexBuffer);
  373. wgpuBufferRelease(fr->IndexBuffer);
  374. }
  375. SafeRelease(fr->IndexBufferHost);
  376. fr->IndexBufferSize = draw_data->TotalIdxCount + 10000;
  377. WGPUBufferDescriptor ib_desc =
  378. {
  379. nullptr,
  380. "Dear ImGui Index buffer",
  381. #ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN
  382. WGPU_STRLEN,
  383. #endif
  384. WGPUBufferUsage_CopyDst | WGPUBufferUsage_Index,
  385. MEMALIGN(fr->IndexBufferSize * sizeof(ImDrawIdx), 4),
  386. false
  387. };
  388. fr->IndexBuffer = wgpuDeviceCreateBuffer(bd->wgpuDevice, &ib_desc);
  389. if (!fr->IndexBuffer)
  390. return;
  391. fr->IndexBufferHost = new ImDrawIdx[fr->IndexBufferSize];
  392. }
  393. // Upload vertex/index data into a single contiguous GPU buffer
  394. ImDrawVert* vtx_dst = (ImDrawVert*)fr->VertexBufferHost;
  395. ImDrawIdx* idx_dst = (ImDrawIdx*)fr->IndexBufferHost;
  396. for (int n = 0; n < draw_data->CmdListsCount; n++)
  397. {
  398. const ImDrawList* draw_list = draw_data->CmdLists[n];
  399. memcpy(vtx_dst, draw_list->VtxBuffer.Data, draw_list->VtxBuffer.Size * sizeof(ImDrawVert));
  400. memcpy(idx_dst, draw_list->IdxBuffer.Data, draw_list->IdxBuffer.Size * sizeof(ImDrawIdx));
  401. vtx_dst += draw_list->VtxBuffer.Size;
  402. idx_dst += draw_list->IdxBuffer.Size;
  403. }
  404. int64_t vb_write_size = MEMALIGN((char*)vtx_dst - (char*)fr->VertexBufferHost, 4);
  405. int64_t ib_write_size = MEMALIGN((char*)idx_dst - (char*)fr->IndexBufferHost, 4);
  406. wgpuQueueWriteBuffer(bd->defaultQueue, fr->VertexBuffer, 0, fr->VertexBufferHost, vb_write_size);
  407. wgpuQueueWriteBuffer(bd->defaultQueue, fr->IndexBuffer, 0, fr->IndexBufferHost, ib_write_size);
  408. // Setup desired render state
  409. ImGui_ImplWGPU_SetupRenderState(draw_data, pass_encoder, fr);
  410. // Setup render state structure (for callbacks and custom texture bindings)
  411. ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
  412. ImGui_ImplWGPU_RenderState render_state;
  413. render_state.Device = bd->wgpuDevice;
  414. render_state.RenderPassEncoder = pass_encoder;
  415. platform_io.Renderer_RenderState = &render_state;
  416. // Render command lists
  417. // (Because we merged all buffers into a single one, we maintain our own offset into them)
  418. int global_vtx_offset = 0;
  419. int global_idx_offset = 0;
  420. ImVec2 clip_scale = draw_data->FramebufferScale;
  421. ImVec2 clip_off = draw_data->DisplayPos;
  422. for (int n = 0; n < draw_data->CmdListsCount; n++)
  423. {
  424. const ImDrawList* draw_list = draw_data->CmdLists[n];
  425. for (int cmd_i = 0; cmd_i < draw_list->CmdBuffer.Size; cmd_i++)
  426. {
  427. const ImDrawCmd* pcmd = &draw_list->CmdBuffer[cmd_i];
  428. if (pcmd->UserCallback != nullptr)
  429. {
  430. // User callback, registered via ImDrawList::AddCallback()
  431. // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
  432. if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
  433. ImGui_ImplWGPU_SetupRenderState(draw_data, pass_encoder, fr);
  434. else
  435. pcmd->UserCallback(draw_list, pcmd);
  436. }
  437. else
  438. {
  439. // Bind custom texture
  440. ImTextureID tex_id = pcmd->GetTexID();
  441. ImGuiID tex_id_hash = ImHashData(&tex_id, sizeof(tex_id));
  442. auto bind_group = bd->renderResources.ImageBindGroups.GetVoidPtr(tex_id_hash);
  443. if (bind_group)
  444. {
  445. wgpuRenderPassEncoderSetBindGroup(pass_encoder, 1, (WGPUBindGroup)bind_group, 0, nullptr);
  446. }
  447. else
  448. {
  449. WGPUBindGroup image_bind_group = ImGui_ImplWGPU_CreateImageBindGroup(bd->renderResources.ImageBindGroupLayout, (WGPUTextureView)tex_id);
  450. bd->renderResources.ImageBindGroups.SetVoidPtr(tex_id_hash, image_bind_group);
  451. wgpuRenderPassEncoderSetBindGroup(pass_encoder, 1, image_bind_group, 0, nullptr);
  452. }
  453. // Project scissor/clipping rectangles into framebuffer space
  454. ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y);
  455. ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y);
  456. // Clamp to viewport as wgpuRenderPassEncoderSetScissorRect() won't accept values that are off bounds
  457. if (clip_min.x < 0.0f) { clip_min.x = 0.0f; }
  458. if (clip_min.y < 0.0f) { clip_min.y = 0.0f; }
  459. if (clip_max.x > fb_width) { clip_max.x = (float)fb_width; }
  460. if (clip_max.y > fb_height) { clip_max.y = (float)fb_height; }
  461. if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
  462. continue;
  463. // Apply scissor/clipping rectangle, Draw
  464. wgpuRenderPassEncoderSetScissorRect(pass_encoder, (uint32_t)clip_min.x, (uint32_t)clip_min.y, (uint32_t)(clip_max.x - clip_min.x), (uint32_t)(clip_max.y - clip_min.y));
  465. wgpuRenderPassEncoderDrawIndexed(pass_encoder, pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0);
  466. }
  467. }
  468. global_idx_offset += draw_list->IdxBuffer.Size;
  469. global_vtx_offset += draw_list->VtxBuffer.Size;
  470. }
  471. platform_io.Renderer_RenderState = nullptr;
  472. }
  473. static void ImGui_ImplWGPU_CreateFontsTexture()
  474. {
  475. // Build texture atlas
  476. ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
  477. ImGuiIO& io = ImGui::GetIO();
  478. unsigned char* pixels;
  479. int width, height, size_pp;
  480. io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height, &size_pp);
  481. // Upload texture to graphics system
  482. {
  483. WGPUTextureDescriptor tex_desc = {};
  484. #ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN
  485. tex_desc.label = { "Dear ImGui Font Texture", WGPU_STRLEN };
  486. #else
  487. tex_desc.label = "Dear ImGui Font Texture";
  488. #endif
  489. tex_desc.dimension = WGPUTextureDimension_2D;
  490. tex_desc.size.width = width;
  491. tex_desc.size.height = height;
  492. tex_desc.size.depthOrArrayLayers = 1;
  493. tex_desc.sampleCount = 1;
  494. tex_desc.format = WGPUTextureFormat_RGBA8Unorm;
  495. tex_desc.mipLevelCount = 1;
  496. tex_desc.usage = WGPUTextureUsage_CopyDst | WGPUTextureUsage_TextureBinding;
  497. bd->renderResources.FontTexture = wgpuDeviceCreateTexture(bd->wgpuDevice, &tex_desc);
  498. WGPUTextureViewDescriptor tex_view_desc = {};
  499. tex_view_desc.format = WGPUTextureFormat_RGBA8Unorm;
  500. tex_view_desc.dimension = WGPUTextureViewDimension_2D;
  501. tex_view_desc.baseMipLevel = 0;
  502. tex_view_desc.mipLevelCount = 1;
  503. tex_view_desc.baseArrayLayer = 0;
  504. tex_view_desc.arrayLayerCount = 1;
  505. tex_view_desc.aspect = WGPUTextureAspect_All;
  506. bd->renderResources.FontTextureView = wgpuTextureCreateView(bd->renderResources.FontTexture, &tex_view_desc);
  507. }
  508. // Upload texture data
  509. {
  510. WGPUImageCopyTexture dst_view = {};
  511. dst_view.texture = bd->renderResources.FontTexture;
  512. dst_view.mipLevel = 0;
  513. dst_view.origin = { 0, 0, 0 };
  514. dst_view.aspect = WGPUTextureAspect_All;
  515. WGPUTextureDataLayout layout = {};
  516. layout.offset = 0;
  517. layout.bytesPerRow = width * size_pp;
  518. layout.rowsPerImage = height;
  519. WGPUExtent3D size = { (uint32_t)width, (uint32_t)height, 1 };
  520. wgpuQueueWriteTexture(bd->defaultQueue, &dst_view, pixels, (uint32_t)(width * size_pp * height), &layout, &size);
  521. }
  522. // Create the associated sampler
  523. // (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
  524. {
  525. WGPUSamplerDescriptor sampler_desc = {};
  526. sampler_desc.minFilter = WGPUFilterMode_Linear;
  527. sampler_desc.magFilter = WGPUFilterMode_Linear;
  528. sampler_desc.mipmapFilter = WGPUMipmapFilterMode_Linear;
  529. sampler_desc.addressModeU = WGPUAddressMode_ClampToEdge;
  530. sampler_desc.addressModeV = WGPUAddressMode_ClampToEdge;
  531. sampler_desc.addressModeW = WGPUAddressMode_ClampToEdge;
  532. sampler_desc.maxAnisotropy = 1;
  533. bd->renderResources.Sampler = wgpuDeviceCreateSampler(bd->wgpuDevice, &sampler_desc);
  534. }
  535. // Store our identifier
  536. static_assert(sizeof(ImTextureID) >= sizeof(bd->renderResources.FontTexture), "Can't pack descriptor handle into TexID, 32-bit not supported yet.");
  537. io.Fonts->SetTexID((ImTextureID)bd->renderResources.FontTextureView);
  538. }
  539. static void ImGui_ImplWGPU_CreateUniformBuffer()
  540. {
  541. ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
  542. WGPUBufferDescriptor ub_desc =
  543. {
  544. nullptr,
  545. "Dear ImGui Uniform buffer",
  546. #ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN
  547. WGPU_STRLEN,
  548. #endif
  549. WGPUBufferUsage_CopyDst | WGPUBufferUsage_Uniform,
  550. MEMALIGN(sizeof(Uniforms), 16),
  551. false
  552. };
  553. bd->renderResources.Uniforms = wgpuDeviceCreateBuffer(bd->wgpuDevice, &ub_desc);
  554. }
  555. bool ImGui_ImplWGPU_CreateDeviceObjects()
  556. {
  557. ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
  558. if (!bd->wgpuDevice)
  559. return false;
  560. if (bd->pipelineState)
  561. ImGui_ImplWGPU_InvalidateDeviceObjects();
  562. // Create render pipeline
  563. WGPURenderPipelineDescriptor graphics_pipeline_desc = {};
  564. graphics_pipeline_desc.primitive.topology = WGPUPrimitiveTopology_TriangleList;
  565. graphics_pipeline_desc.primitive.stripIndexFormat = WGPUIndexFormat_Undefined;
  566. graphics_pipeline_desc.primitive.frontFace = WGPUFrontFace_CW;
  567. graphics_pipeline_desc.primitive.cullMode = WGPUCullMode_None;
  568. graphics_pipeline_desc.multisample = bd->initInfo.PipelineMultisampleState;
  569. // Bind group layouts
  570. WGPUBindGroupLayoutEntry common_bg_layout_entries[2] = {};
  571. common_bg_layout_entries[0].binding = 0;
  572. common_bg_layout_entries[0].visibility = WGPUShaderStage_Vertex | WGPUShaderStage_Fragment;
  573. common_bg_layout_entries[0].buffer.type = WGPUBufferBindingType_Uniform;
  574. common_bg_layout_entries[1].binding = 1;
  575. common_bg_layout_entries[1].visibility = WGPUShaderStage_Fragment;
  576. common_bg_layout_entries[1].sampler.type = WGPUSamplerBindingType_Filtering;
  577. WGPUBindGroupLayoutEntry image_bg_layout_entries[1] = {};
  578. image_bg_layout_entries[0].binding = 0;
  579. image_bg_layout_entries[0].visibility = WGPUShaderStage_Fragment;
  580. image_bg_layout_entries[0].texture.sampleType = WGPUTextureSampleType_Float;
  581. image_bg_layout_entries[0].texture.viewDimension = WGPUTextureViewDimension_2D;
  582. WGPUBindGroupLayoutDescriptor common_bg_layout_desc = {};
  583. common_bg_layout_desc.entryCount = 2;
  584. common_bg_layout_desc.entries = common_bg_layout_entries;
  585. WGPUBindGroupLayoutDescriptor image_bg_layout_desc = {};
  586. image_bg_layout_desc.entryCount = 1;
  587. image_bg_layout_desc.entries = image_bg_layout_entries;
  588. WGPUBindGroupLayout bg_layouts[2];
  589. bg_layouts[0] = wgpuDeviceCreateBindGroupLayout(bd->wgpuDevice, &common_bg_layout_desc);
  590. bg_layouts[1] = wgpuDeviceCreateBindGroupLayout(bd->wgpuDevice, &image_bg_layout_desc);
  591. WGPUPipelineLayoutDescriptor layout_desc = {};
  592. layout_desc.bindGroupLayoutCount = 2;
  593. layout_desc.bindGroupLayouts = bg_layouts;
  594. graphics_pipeline_desc.layout = wgpuDeviceCreatePipelineLayout(bd->wgpuDevice, &layout_desc);
  595. // Create the vertex shader
  596. WGPUProgrammableStageDescriptor vertex_shader_desc = ImGui_ImplWGPU_CreateShaderModule(__shader_vert_wgsl);
  597. graphics_pipeline_desc.vertex.module = vertex_shader_desc.module;
  598. graphics_pipeline_desc.vertex.entryPoint = vertex_shader_desc.entryPoint;
  599. // Vertex input configuration
  600. WGPUVertexAttribute attribute_desc[] =
  601. {
  602. { WGPUVertexFormat_Float32x2, (uint64_t)offsetof(ImDrawVert, pos), 0 },
  603. { WGPUVertexFormat_Float32x2, (uint64_t)offsetof(ImDrawVert, uv), 1 },
  604. { WGPUVertexFormat_Unorm8x4, (uint64_t)offsetof(ImDrawVert, col), 2 },
  605. };
  606. WGPUVertexBufferLayout buffer_layouts[1];
  607. buffer_layouts[0].arrayStride = sizeof(ImDrawVert);
  608. buffer_layouts[0].stepMode = WGPUVertexStepMode_Vertex;
  609. buffer_layouts[0].attributeCount = 3;
  610. buffer_layouts[0].attributes = attribute_desc;
  611. graphics_pipeline_desc.vertex.bufferCount = 1;
  612. graphics_pipeline_desc.vertex.buffers = buffer_layouts;
  613. // Create the pixel shader
  614. WGPUProgrammableStageDescriptor pixel_shader_desc = ImGui_ImplWGPU_CreateShaderModule(__shader_frag_wgsl);
  615. // Create the blending setup
  616. WGPUBlendState blend_state = {};
  617. blend_state.alpha.operation = WGPUBlendOperation_Add;
  618. blend_state.alpha.srcFactor = WGPUBlendFactor_One;
  619. blend_state.alpha.dstFactor = WGPUBlendFactor_OneMinusSrcAlpha;
  620. blend_state.color.operation = WGPUBlendOperation_Add;
  621. blend_state.color.srcFactor = WGPUBlendFactor_SrcAlpha;
  622. blend_state.color.dstFactor = WGPUBlendFactor_OneMinusSrcAlpha;
  623. WGPUColorTargetState color_state = {};
  624. color_state.format = bd->renderTargetFormat;
  625. color_state.blend = &blend_state;
  626. color_state.writeMask = WGPUColorWriteMask_All;
  627. WGPUFragmentState fragment_state = {};
  628. fragment_state.module = pixel_shader_desc.module;
  629. fragment_state.entryPoint = pixel_shader_desc.entryPoint;
  630. fragment_state.targetCount = 1;
  631. fragment_state.targets = &color_state;
  632. graphics_pipeline_desc.fragment = &fragment_state;
  633. // Create depth-stencil State
  634. WGPUDepthStencilState depth_stencil_state = {};
  635. depth_stencil_state.format = bd->depthStencilFormat;
  636. #ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN
  637. depth_stencil_state.depthWriteEnabled = WGPUOptionalBool_False;
  638. #else
  639. depth_stencil_state.depthWriteEnabled = false;
  640. #endif
  641. depth_stencil_state.depthCompare = WGPUCompareFunction_Always;
  642. depth_stencil_state.stencilFront.compare = WGPUCompareFunction_Always;
  643. depth_stencil_state.stencilFront.failOp = WGPUStencilOperation_Keep;
  644. depth_stencil_state.stencilFront.depthFailOp = WGPUStencilOperation_Keep;
  645. depth_stencil_state.stencilFront.passOp = WGPUStencilOperation_Keep;
  646. depth_stencil_state.stencilBack.compare = WGPUCompareFunction_Always;
  647. depth_stencil_state.stencilBack.failOp = WGPUStencilOperation_Keep;
  648. depth_stencil_state.stencilBack.depthFailOp = WGPUStencilOperation_Keep;
  649. depth_stencil_state.stencilBack.passOp = WGPUStencilOperation_Keep;
  650. // Configure disabled depth-stencil state
  651. graphics_pipeline_desc.depthStencil = (bd->depthStencilFormat == WGPUTextureFormat_Undefined) ? nullptr : &depth_stencil_state;
  652. bd->pipelineState = wgpuDeviceCreateRenderPipeline(bd->wgpuDevice, &graphics_pipeline_desc);
  653. ImGui_ImplWGPU_CreateFontsTexture();
  654. ImGui_ImplWGPU_CreateUniformBuffer();
  655. // Create resource bind group
  656. WGPUBindGroupEntry common_bg_entries[] =
  657. {
  658. { nullptr, 0, bd->renderResources.Uniforms, 0, MEMALIGN(sizeof(Uniforms), 16), 0, 0 },
  659. { nullptr, 1, 0, 0, 0, bd->renderResources.Sampler, 0 },
  660. };
  661. WGPUBindGroupDescriptor common_bg_descriptor = {};
  662. common_bg_descriptor.layout = bg_layouts[0];
  663. common_bg_descriptor.entryCount = sizeof(common_bg_entries) / sizeof(WGPUBindGroupEntry);
  664. common_bg_descriptor.entries = common_bg_entries;
  665. bd->renderResources.CommonBindGroup = wgpuDeviceCreateBindGroup(bd->wgpuDevice, &common_bg_descriptor);
  666. WGPUBindGroup image_bind_group = ImGui_ImplWGPU_CreateImageBindGroup(bg_layouts[1], bd->renderResources.FontTextureView);
  667. bd->renderResources.ImageBindGroup = image_bind_group;
  668. bd->renderResources.ImageBindGroupLayout = bg_layouts[1];
  669. bd->renderResources.ImageBindGroups.SetVoidPtr(ImHashData(&bd->renderResources.FontTextureView, sizeof(ImTextureID)), image_bind_group);
  670. SafeRelease(vertex_shader_desc.module);
  671. SafeRelease(pixel_shader_desc.module);
  672. SafeRelease(graphics_pipeline_desc.layout);
  673. SafeRelease(bg_layouts[0]);
  674. return true;
  675. }
  676. void ImGui_ImplWGPU_InvalidateDeviceObjects()
  677. {
  678. ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
  679. if (!bd->wgpuDevice)
  680. return;
  681. SafeRelease(bd->pipelineState);
  682. SafeRelease(bd->renderResources);
  683. ImGuiIO& io = ImGui::GetIO();
  684. io.Fonts->SetTexID(0); // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
  685. for (unsigned int i = 0; i < bd->numFramesInFlight; i++)
  686. SafeRelease(bd->pFrameResources[i]);
  687. }
  688. bool ImGui_ImplWGPU_Init(ImGui_ImplWGPU_InitInfo* init_info)
  689. {
  690. ImGuiIO& io = ImGui::GetIO();
  691. IMGUI_CHECKVERSION();
  692. IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
  693. // Setup backend capabilities flags
  694. ImGui_ImplWGPU_Data* bd = IM_NEW(ImGui_ImplWGPU_Data)();
  695. io.BackendRendererUserData = (void*)bd;
  696. #if defined(__EMSCRIPTEN__)
  697. io.BackendRendererName = "imgui_impl_webgpu_emscripten";
  698. #elif defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN)
  699. io.BackendRendererName = "imgui_impl_webgpu_dawn";
  700. #elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
  701. io.BackendRendererName = "imgui_impl_webgpu_wgpu";
  702. #else
  703. io.BackendRendererName = "imgui_impl_webgpu";
  704. #endif
  705. io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
  706. bd->initInfo = *init_info;
  707. bd->wgpuDevice = init_info->Device;
  708. bd->defaultQueue = wgpuDeviceGetQueue(bd->wgpuDevice);
  709. bd->renderTargetFormat = init_info->RenderTargetFormat;
  710. bd->depthStencilFormat = init_info->DepthStencilFormat;
  711. bd->numFramesInFlight = init_info->NumFramesInFlight;
  712. bd->frameIndex = UINT_MAX;
  713. bd->renderResources.FontTexture = nullptr;
  714. bd->renderResources.FontTextureView = nullptr;
  715. bd->renderResources.Sampler = nullptr;
  716. bd->renderResources.Uniforms = nullptr;
  717. bd->renderResources.CommonBindGroup = nullptr;
  718. bd->renderResources.ImageBindGroups.Data.reserve(100);
  719. bd->renderResources.ImageBindGroup = nullptr;
  720. bd->renderResources.ImageBindGroupLayout = nullptr;
  721. // Create buffers with a default size (they will later be grown as needed)
  722. bd->pFrameResources = new FrameResources[bd->numFramesInFlight];
  723. for (unsigned int i = 0; i < bd->numFramesInFlight; i++)
  724. {
  725. FrameResources* fr = &bd->pFrameResources[i];
  726. fr->IndexBuffer = nullptr;
  727. fr->VertexBuffer = nullptr;
  728. fr->IndexBufferHost = nullptr;
  729. fr->VertexBufferHost = nullptr;
  730. fr->IndexBufferSize = 10000;
  731. fr->VertexBufferSize = 5000;
  732. }
  733. return true;
  734. }
  735. void ImGui_ImplWGPU_Shutdown()
  736. {
  737. ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
  738. IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
  739. ImGuiIO& io = ImGui::GetIO();
  740. ImGui_ImplWGPU_InvalidateDeviceObjects();
  741. delete[] bd->pFrameResources;
  742. bd->pFrameResources = nullptr;
  743. wgpuQueueRelease(bd->defaultQueue);
  744. bd->wgpuDevice = nullptr;
  745. bd->numFramesInFlight = 0;
  746. bd->frameIndex = UINT_MAX;
  747. io.BackendRendererName = nullptr;
  748. io.BackendRendererUserData = nullptr;
  749. io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset;
  750. IM_DELETE(bd);
  751. }
  752. void ImGui_ImplWGPU_NewFrame()
  753. {
  754. ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
  755. if (!bd->pipelineState)
  756. ImGui_ImplWGPU_CreateDeviceObjects();
  757. }
  758. //-----------------------------------------------------------------------------
  759. #endif // #ifndef IMGUI_DISABLE