From d73e3285dea2bb352f3a9c0696120091f0b95f0e Mon Sep 17 00:00:00 2001 From: Basil Fierz Date: Wed, 25 Jan 2023 21:45:03 +0100 Subject: [PATCH] Backends: WebGU: Revert the implicit render pipeline layout generation as introduced in 83bdfef (#6117, #4116, #3632) The feature was removed from WebGPU (https://github.com/gpuweb/gpuweb/issues/2470) --- backends/imgui_impl_wgpu.cpp | 38 +++++++++++++++++++++++++++++++----- docs/CHANGELOG.txt | 2 ++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/backends/imgui_impl_wgpu.cpp b/backends/imgui_impl_wgpu.cpp index 3282cf364..11c1a3760 100644 --- a/backends/imgui_impl_wgpu.cpp +++ b/backends/imgui_impl_wgpu.cpp @@ -13,6 +13,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 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. // 2022-11-10: Fixed rendering when a depth buffer is enabled. Added 'WGPUTextureFormat depth_format' parameter to ImGui_ImplWGPU_Init(). // 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11. @@ -554,7 +555,38 @@ bool ImGui_ImplWGPU_CreateDeviceObjects() graphics_pipeline_desc.multisample.count = 1; graphics_pipeline_desc.multisample.mask = UINT_MAX; graphics_pipeline_desc.multisample.alphaToCoverageEnabled = false; - graphics_pipeline_desc.layout = nullptr; // Use automatic layout generation + + // Bind group layouts + WGPUBindGroupLayoutEntry common_bg_layout_entries[2] = {}; + common_bg_layout_entries[0].binding = 0; + common_bg_layout_entries[0].visibility = WGPUShaderStage_Vertex; + common_bg_layout_entries[0].buffer.type = WGPUBufferBindingType_Uniform; + common_bg_layout_entries[1].binding = 1; + common_bg_layout_entries[1].visibility = WGPUShaderStage_Fragment; + common_bg_layout_entries[1].sampler.type = WGPUSamplerBindingType_Filtering; + + WGPUBindGroupLayoutEntry image_bg_layout_entries[1] = {}; + image_bg_layout_entries[0].binding = 0; + image_bg_layout_entries[0].visibility = WGPUShaderStage_Fragment; + image_bg_layout_entries[0].texture.sampleType = WGPUTextureSampleType_Float; + image_bg_layout_entries[0].texture.viewDimension = WGPUTextureViewDimension_2D; + + WGPUBindGroupLayoutDescriptor common_bg_layout_desc = {}; + common_bg_layout_desc.entryCount = 2; + common_bg_layout_desc.entries = common_bg_layout_entries; + + WGPUBindGroupLayoutDescriptor image_bg_layout_desc = {}; + image_bg_layout_desc.entryCount = 1; + image_bg_layout_desc.entries = image_bg_layout_entries; + + WGPUBindGroupLayout bg_layouts[2]; + bg_layouts[0] = wgpuDeviceCreateBindGroupLayout(g_wgpuDevice, &common_bg_layout_desc); + bg_layouts[1] = wgpuDeviceCreateBindGroupLayout(g_wgpuDevice, &image_bg_layout_desc); + + WGPUPipelineLayoutDescriptor layout_desc = {}; + layout_desc.bindGroupLayoutCount = 2; + layout_desc.bindGroupLayouts = bg_layouts; + graphics_pipeline_desc.layout = wgpuDeviceCreatePipelineLayout(g_wgpuDevice, &layout_desc); // Create the vertex shader WGPUProgrammableStageDescriptor vertex_shader_desc = ImGui_ImplWGPU_CreateShaderModule(__glsl_shader_vert_spv, sizeof(__glsl_shader_vert_spv) / sizeof(uint32_t)); @@ -620,10 +652,6 @@ bool ImGui_ImplWGPU_CreateDeviceObjects() ImGui_ImplWGPU_CreateUniformBuffer(); // Create resource bind group - WGPUBindGroupLayout bg_layouts[2]; - bg_layouts[0] = wgpuRenderPipelineGetBindGroupLayout(g_pipelineState, 0); - bg_layouts[1] = wgpuRenderPipelineGetBindGroupLayout(g_pipelineState, 1); - WGPUBindGroupEntry common_bg_entries[] = { { nullptr, 0, g_resources.Uniforms, 0, sizeof(Uniforms), 0, 0 }, diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 7bbafa7e3..6d8fabe01 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -57,6 +57,8 @@ All changes: - Misc: Tolerate zero delta-time under Emscripten as backends are imprecise in their values for io.DeltaTime, and browser features such as "privacy.resistFingerprinting=true" can exacerbate that. (#6114, #3644) +- Backend: WebGPU: Fix building for latest WebGPU specs (remove implicit layout generation). + (#6117, #4116, #3632) [@tonygrue, @bfierz] - Examples: Win32: Fixed examples using RegisterClassW() since 1.89 to also call DefWindowProcW() instead of DefWindowProc() so that title text are correctly converted when application is compiled without /DUNICODE. (#5725, #5961, #5975) [@markreidvfx]