Pārlūkot izejas kodu

Backends: SDLGPU3: Rename GpuDevice->Device. Expose ImGui_ImplSDLGPU3_CreateDeviceObjects(), ImGui_ImplSDLGPU3_DestroyDeviceObjects(). Misc renaming. (#8163, #7998, #7988)

ocornut 6 mēneši atpakaļ
vecāks
revīzija
b4a5d1dc53

+ 62 - 65
backends/imgui_impl_sdlgpu3.cpp

@@ -21,13 +21,16 @@
 //   Calling the function is MANDATORY, otherwise the ImGui will not upload neither the vertex nor the index buffer for the GPU. See imgui_impl_sdlgpu3.cpp for more info.
 //   Calling the function is MANDATORY, otherwise the ImGui will not upload neither the vertex nor the index buffer for the GPU. See imgui_impl_sdlgpu3.cpp for more info.
 
 
 // CHANGELOG
 // CHANGELOG
-//  2025-01-09: SDL_Gpu: Added the SDL_GPU3 backend.
+//  2025-01-16: Renamed ImGui_ImplSDLGPU3_InitInfo::GpuDevice to Device.
+//  2025-01-09: SDL_GPU: Added the SDL_GPU3 backend.
 
 
 #include "imgui.h"
 #include "imgui.h"
 #ifndef IMGUI_DISABLE
 #ifndef IMGUI_DISABLE
 #include "imgui_impl_sdlgpu3.h"
 #include "imgui_impl_sdlgpu3.h"
 #include "imgui_impl_sdlgpu3_shaders.h"
 #include "imgui_impl_sdlgpu3_shaders.h"
 
 
+// SDL_GPU Data
+
 // Reusable buffers used for rendering 1 current in-flight frame, for ImGui_ImplSDLGPU3_RenderDrawData()
 // Reusable buffers used for rendering 1 current in-flight frame, for ImGui_ImplSDLGPU3_RenderDrawData()
 struct ImGui_ImplSDLGPU3_FrameData
 struct ImGui_ImplSDLGPU3_FrameData
 {
 {
@@ -37,10 +40,9 @@ struct ImGui_ImplSDLGPU3_FrameData
     uint32_t            IndexBufferSize  = 0;
     uint32_t            IndexBufferSize  = 0;
 };
 };
 
 
-// SDL_GPU Data
 struct ImGui_ImplSDLGPU3_Data
 struct ImGui_ImplSDLGPU3_Data
 {
 {
-    ImGui_ImplSDLGPU3_InitInfo   GPUInitInfo;
+    ImGui_ImplSDLGPU3_InitInfo   InitInfo;
 
 
     // Graphics pipeline & shaders
     // Graphics pipeline & shaders
     SDL_GPUShader*               VertexShader   = nullptr;
     SDL_GPUShader*               VertexShader   = nullptr;
@@ -57,8 +59,6 @@ struct ImGui_ImplSDLGPU3_Data
 };
 };
 
 
 // Forward Declarations
 // Forward Declarations
-static bool ImGui_ImplSDLGPU3_CreateDeviceObjects();
-static void ImGui_ImplSDLGPU3_DestroyDeviceObjects();
 static void ImGui_ImplSDLGPU3_DestroyFrameData();
 static void ImGui_ImplSDLGPU3_DestroyFrameData();
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -116,16 +116,16 @@ static void ImGui_ImplSDLGPU3_SetupRenderState(ImDrawData* draw_data, SDL_GPUGra
 static void CreateOrResizeBuffer(SDL_GPUBuffer** buffer, uint32_t* old_size, uint32_t new_size, SDL_GPUBufferUsageFlags usage)
 static void CreateOrResizeBuffer(SDL_GPUBuffer** buffer, uint32_t* old_size, uint32_t new_size, SDL_GPUBufferUsageFlags usage)
 {
 {
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
-    ImGui_ImplSDLGPU3_InitInfo* v = &bd->GPUInitInfo;
+    ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
 
 
-    SDL_WaitForGPUIdle(v->GpuDevice);
-    SDL_ReleaseGPUBuffer(v->GpuDevice, *buffer);
+    SDL_WaitForGPUIdle(v->Device);
+    SDL_ReleaseGPUBuffer(v->Device, *buffer);
 
 
     SDL_GPUBufferCreateInfo buffer_info = {};
     SDL_GPUBufferCreateInfo buffer_info = {};
     buffer_info.usage = usage;
     buffer_info.usage = usage;
     buffer_info.size = new_size;
     buffer_info.size = new_size;
     buffer_info.props = 0;
     buffer_info.props = 0;
-    *buffer = SDL_CreateGPUBuffer(v->GpuDevice, &buffer_info);
+    *buffer = SDL_CreateGPUBuffer(v->Device, &buffer_info);
     *old_size = new_size;
     *old_size = new_size;
     IM_ASSERT(*buffer != nullptr && "Failed to create GPU Buffer, call SDL_GetError() for more information");
     IM_ASSERT(*buffer != nullptr && "Failed to create GPU Buffer, call SDL_GetError() for more information");
 }
 }
@@ -142,7 +142,7 @@ void Imgui_ImplSDLGPU3_PrepareDrawData(ImDrawData* draw_data, SDL_GPUCommandBuff
         return;
         return;
 
 
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
-    ImGui_ImplSDLGPU3_InitInfo* v = &bd->GPUInitInfo;
+    ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
     ImGui_ImplSDLGPU3_FrameData* fd = &bd->MainWindowFrameData;
     ImGui_ImplSDLGPU3_FrameData* fd = &bd->MainWindowFrameData;
 
 
     uint32_t vertex_size = draw_data->TotalVtxCount * sizeof(ImDrawVert);
     uint32_t vertex_size = draw_data->TotalVtxCount * sizeof(ImDrawVert);
@@ -160,13 +160,13 @@ void Imgui_ImplSDLGPU3_PrepareDrawData(ImDrawData* draw_data, SDL_GPUCommandBuff
     index_transferbuffer_info.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;
     index_transferbuffer_info.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;
     index_transferbuffer_info.size = index_size;
     index_transferbuffer_info.size = index_size;
 
 
-    SDL_GPUTransferBuffer* vertex_transferbuffer = SDL_CreateGPUTransferBuffer(v->GpuDevice, &vertex_transferbuffer_info);
+    SDL_GPUTransferBuffer* vertex_transferbuffer = SDL_CreateGPUTransferBuffer(v->Device, &vertex_transferbuffer_info);
     IM_ASSERT(vertex_transferbuffer != nullptr && "Failed to create the vertex transfer buffer, call SDL_GetError() for more information");
     IM_ASSERT(vertex_transferbuffer != nullptr && "Failed to create the vertex transfer buffer, call SDL_GetError() for more information");
-    SDL_GPUTransferBuffer* index_transferbuffer = SDL_CreateGPUTransferBuffer(v->GpuDevice, &index_transferbuffer_info);
+    SDL_GPUTransferBuffer* index_transferbuffer = SDL_CreateGPUTransferBuffer(v->Device, &index_transferbuffer_info);
     IM_ASSERT(index_transferbuffer != nullptr && "Failed to create the index transfer buffer, call SDL_GetError() for more information");
     IM_ASSERT(index_transferbuffer != nullptr && "Failed to create the index transfer buffer, call SDL_GetError() for more information");
 
 
-    ImDrawVert* vtx_dst = (ImDrawVert*)SDL_MapGPUTransferBuffer(v->GpuDevice, vertex_transferbuffer, true);
-    ImDrawIdx*  idx_dst = (ImDrawIdx*)SDL_MapGPUTransferBuffer(v->GpuDevice, index_transferbuffer, true);
+    ImDrawVert* vtx_dst = (ImDrawVert*)SDL_MapGPUTransferBuffer(v->Device, vertex_transferbuffer, true);
+    ImDrawIdx*  idx_dst = (ImDrawIdx*)SDL_MapGPUTransferBuffer(v->Device, index_transferbuffer, true);
     for (int n = 0; n < draw_data->CmdListsCount; n++)
     for (int n = 0; n < draw_data->CmdListsCount; n++)
     {
     {
         const ImDrawList* draw_list = draw_data->CmdLists[n];
         const ImDrawList* draw_list = draw_data->CmdLists[n];
@@ -175,8 +175,8 @@ void Imgui_ImplSDLGPU3_PrepareDrawData(ImDrawData* draw_data, SDL_GPUCommandBuff
         vtx_dst += draw_list->VtxBuffer.Size;
         vtx_dst += draw_list->VtxBuffer.Size;
         idx_dst += draw_list->IdxBuffer.Size;
         idx_dst += draw_list->IdxBuffer.Size;
     }
     }
-    SDL_UnmapGPUTransferBuffer(v->GpuDevice, vertex_transferbuffer);
-    SDL_UnmapGPUTransferBuffer(v->GpuDevice, index_transferbuffer);
+    SDL_UnmapGPUTransferBuffer(v->Device, vertex_transferbuffer);
+    SDL_UnmapGPUTransferBuffer(v->Device, index_transferbuffer);
 
 
     SDL_GPUTransferBufferLocation vertex_buffer_location = {};
     SDL_GPUTransferBufferLocation vertex_buffer_location = {};
     vertex_buffer_location.offset = 0;
     vertex_buffer_location.offset = 0;
@@ -199,8 +199,8 @@ void Imgui_ImplSDLGPU3_PrepareDrawData(ImDrawData* draw_data, SDL_GPUCommandBuff
     SDL_UploadToGPUBuffer(copy_pass, &vertex_buffer_location, &vertex_buffer_region,true);
     SDL_UploadToGPUBuffer(copy_pass, &vertex_buffer_location, &vertex_buffer_region,true);
     SDL_UploadToGPUBuffer(copy_pass, &index_buffer_location, &index_buffer_region,true);
     SDL_UploadToGPUBuffer(copy_pass, &index_buffer_location, &index_buffer_region,true);
     SDL_EndGPUCopyPass(copy_pass);
     SDL_EndGPUCopyPass(copy_pass);
-    SDL_ReleaseGPUTransferBuffer(v->GpuDevice, index_transferbuffer);
-    SDL_ReleaseGPUTransferBuffer(v->GpuDevice, vertex_transferbuffer);
+    SDL_ReleaseGPUTransferBuffer(v->Device, index_transferbuffer);
+    SDL_ReleaseGPUTransferBuffer(v->Device, vertex_transferbuffer);
 }
 }
 
 
 void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffer* command_buffer, SDL_GPURenderPass* render_pass, SDL_GPUGraphicsPipeline* pipeline)
 void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffer* command_buffer, SDL_GPURenderPass* render_pass, SDL_GPUGraphicsPipeline* pipeline)
@@ -278,16 +278,16 @@ void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffe
     SDL_SetGPUScissor(render_pass, &scissor_rect);
     SDL_SetGPUScissor(render_pass, &scissor_rect);
 }
 }
 
 
-bool ImGui_ImplSDLGPU3_CreateFontsTexture()
+void ImGui_ImplSDLGPU3_CreateFontsTexture()
 {
 {
     ImGuiIO& io = ImGui::GetIO();
     ImGuiIO& io = ImGui::GetIO();
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
-    ImGui_ImplSDLGPU3_InitInfo* v = &bd->GPUInitInfo;
+    ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
 
 
     // Destroy existing texture (if any)
     // Destroy existing texture (if any)
     if (bd->FontTexture)
     if (bd->FontTexture)
     {
     {
-        SDL_WaitForGPUIdle(v->GpuDevice);
+        SDL_WaitForGPUIdle(v->Device);
         ImGui_ImplSDLGPU3_DestroyFontsTexture();
         ImGui_ImplSDLGPU3_DestroyFontsTexture();
     }
     }
 
 
@@ -308,7 +308,7 @@ bool ImGui_ImplSDLGPU3_CreateFontsTexture()
         texture_info.num_levels = 1;
         texture_info.num_levels = 1;
         texture_info.sample_count = SDL_GPU_SAMPLECOUNT_1;
         texture_info.sample_count = SDL_GPU_SAMPLECOUNT_1;
 
 
-        bd->FontTexture = SDL_CreateGPUTexture(v->GpuDevice, &texture_info);
+        bd->FontTexture = SDL_CreateGPUTexture(v->Device, &texture_info);
         IM_ASSERT(bd->FontTexture && "Failed to create font texture, call SDL_GetError() for more info");
         IM_ASSERT(bd->FontTexture && "Failed to create font texture, call SDL_GetError() for more info");
     }
     }
 
 
@@ -317,39 +317,37 @@ bool ImGui_ImplSDLGPU3_CreateFontsTexture()
 
 
     // Create all the upload structures and upload:
     // Create all the upload structures and upload:
     {
     {
-        SDL_GPUTransferBufferCreateInfo font_transferbuffer_info = {};
-        font_transferbuffer_info.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;
-        font_transferbuffer_info.size = upload_size;
+        SDL_GPUTransferBufferCreateInfo transferbuffer_info = {};
+        transferbuffer_info.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;
+        transferbuffer_info.size = upload_size;
 
 
-        SDL_GPUTransferBuffer* font_transferbuffer = SDL_CreateGPUTransferBuffer(v->GpuDevice, &font_transferbuffer_info);
-        IM_ASSERT(font_transferbuffer != nullptr && "Failed to create font transfer buffer, call SDL_GetError() for more information");
+        SDL_GPUTransferBuffer* transferbuffer = SDL_CreateGPUTransferBuffer(v->Device, &transferbuffer_info);
+        IM_ASSERT(transferbuffer != nullptr && "Failed to create font transfer buffer, call SDL_GetError() for more information");
 
 
-        void* texture_ptr = SDL_MapGPUTransferBuffer(v->GpuDevice, font_transferbuffer, false);
+        void* texture_ptr = SDL_MapGPUTransferBuffer(v->Device, transferbuffer, false);
         memcpy(texture_ptr, pixels, upload_size);
         memcpy(texture_ptr, pixels, upload_size);
-        SDL_UnmapGPUTransferBuffer(v->GpuDevice, font_transferbuffer);
+        SDL_UnmapGPUTransferBuffer(v->Device, transferbuffer);
 
 
-        SDL_GPUTextureTransferInfo font_transfer_info = {};
-        font_transfer_info.offset = 0;
-        font_transfer_info.transfer_buffer = font_transferbuffer;
+        SDL_GPUTextureTransferInfo transfer_info = {};
+        transfer_info.offset = 0;
+        transfer_info.transfer_buffer = transferbuffer;
 
 
-        SDL_GPUTextureRegion font_texture_region = {};
-        font_texture_region.texture = bd->FontTexture;
-        font_texture_region.w = width;
-        font_texture_region.h = height;
-        font_texture_region.d = 1;
+        SDL_GPUTextureRegion texture_region = {};
+        texture_region.texture = bd->FontTexture;
+        texture_region.w = width;
+        texture_region.h = height;
+        texture_region.d = 1;
 
 
-        SDL_GPUCommandBuffer* cmd = SDL_AcquireGPUCommandBuffer(v->GpuDevice);
+        SDL_GPUCommandBuffer* cmd = SDL_AcquireGPUCommandBuffer(v->Device);
         SDL_GPUCopyPass* copy_pass = SDL_BeginGPUCopyPass(cmd);
         SDL_GPUCopyPass* copy_pass = SDL_BeginGPUCopyPass(cmd);
-        SDL_UploadToGPUTexture(copy_pass, &font_transfer_info, &font_texture_region, false);
+        SDL_UploadToGPUTexture(copy_pass, &transfer_info, &texture_region, false);
         SDL_EndGPUCopyPass(copy_pass);
         SDL_EndGPUCopyPass(copy_pass);
         SDL_SubmitGPUCommandBuffer(cmd);
         SDL_SubmitGPUCommandBuffer(cmd);
-        SDL_ReleaseGPUTransferBuffer(v->GpuDevice, font_transferbuffer);
+        SDL_ReleaseGPUTransferBuffer(v->Device, transferbuffer);
     }
     }
 
 
     // Store our identifier
     // Store our identifier
     io.Fonts->SetTexID((ImTextureID)&bd->FontBinding);
     io.Fonts->SetTexID((ImTextureID)&bd->FontBinding);
-
-    return true;
 }
 }
 
 
 // You probably never need to call this, as it is called by ImGui_ImplSDLGPU3_CreateFontsTexture() and ImGui_ImplSDLGPU3_Shutdown().
 // You probably never need to call this, as it is called by ImGui_ImplSDLGPU3_CreateFontsTexture() and ImGui_ImplSDLGPU3_Shutdown().
@@ -357,10 +355,10 @@ void ImGui_ImplSDLGPU3_DestroyFontsTexture()
 {
 {
     ImGuiIO& io = ImGui::GetIO();
     ImGuiIO& io = ImGui::GetIO();
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
-    ImGui_ImplSDLGPU3_InitInfo* v = &bd->GPUInitInfo;
+    ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
     if (bd->FontTexture)
     if (bd->FontTexture)
     {
     {
-        SDL_ReleaseGPUTexture(v->GpuDevice, bd->FontTexture);
+        SDL_ReleaseGPUTexture(v->Device, bd->FontTexture);
         bd->FontBinding.texture = nullptr;
         bd->FontBinding.texture = nullptr;
         bd->FontTexture = nullptr;
         bd->FontTexture = nullptr;
     }
     }
@@ -371,9 +369,9 @@ static void Imgui_ImplSDLGPU3_CreateShaders()
 {
 {
     // Create the shader modules
     // Create the shader modules
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
-    ImGui_ImplSDLGPU3_InitInfo* v = &bd->GPUInitInfo;
+    ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
 
 
-    const char* driver = SDL_GetGPUDeviceDriver(v->GpuDevice);
+    const char* driver = SDL_GetGPUDeviceDriver(v->Device);
 
 
     SDL_GPUShaderCreateInfo vertex_shader_info = {};
     SDL_GPUShaderCreateInfo vertex_shader_info = {};
     vertex_shader_info.entrypoint = "main";
     vertex_shader_info.entrypoint = "main";
@@ -422,8 +420,8 @@ static void Imgui_ImplSDLGPU3_CreateShaders()
         fragment_shader_info.code_size = sizeof(metallib_fragment);
         fragment_shader_info.code_size = sizeof(metallib_fragment);
     }
     }
 #endif
 #endif
-    bd->VertexShader = SDL_CreateGPUShader(v->GpuDevice, &vertex_shader_info);
-    bd->FragmentShader = SDL_CreateGPUShader(v->GpuDevice, &fragment_shader_info);
+    bd->VertexShader = SDL_CreateGPUShader(v->Device, &vertex_shader_info);
+    bd->FragmentShader = SDL_CreateGPUShader(v->Device, &fragment_shader_info);
     IM_ASSERT(bd->VertexShader != nullptr && "Failed to create vertex shader, call SDL_GetError() for more information");
     IM_ASSERT(bd->VertexShader != nullptr && "Failed to create vertex shader, call SDL_GetError() for more information");
     IM_ASSERT(bd->FragmentShader != nullptr && "Failed to create fragment shader, call SDL_GetError() for more information");
     IM_ASSERT(bd->FragmentShader != nullptr && "Failed to create fragment shader, call SDL_GetError() for more information");
 }
 }
@@ -431,7 +429,7 @@ static void Imgui_ImplSDLGPU3_CreateShaders()
 static void ImGui_ImplSDLGPU3_CreateGraphicsPipeline()
 static void ImGui_ImplSDLGPU3_CreateGraphicsPipeline()
 {
 {
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
-    ImGui_ImplSDLGPU3_InitInfo* v = &bd->GPUInitInfo;
+    ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
     Imgui_ImplSDLGPU3_CreateShaders();
     Imgui_ImplSDLGPU3_CreateShaders();
 
 
     SDL_GPUVertexBufferDescription vertex_buffer_desc[1];
     SDL_GPUVertexBufferDescription vertex_buffer_desc[1];
@@ -507,14 +505,14 @@ static void ImGui_ImplSDLGPU3_CreateGraphicsPipeline()
     pipeline_info.depth_stencil_state = depth_stencil_state;
     pipeline_info.depth_stencil_state = depth_stencil_state;
     pipeline_info.target_info = target_info;
     pipeline_info.target_info = target_info;
 
 
-    bd->Pipeline = SDL_CreateGPUGraphicsPipeline(v->GpuDevice, &pipeline_info);
+    bd->Pipeline = SDL_CreateGPUGraphicsPipeline(v->Device, &pipeline_info);
     IM_ASSERT(bd->Pipeline != nullptr && "Failed to create graphics pipeline, call SDL_GetError() for more information");
     IM_ASSERT(bd->Pipeline != nullptr && "Failed to create graphics pipeline, call SDL_GetError() for more information");
 }
 }
 
 
-bool ImGui_ImplSDLGPU3_CreateDeviceObjects()
+void ImGui_ImplSDLGPU3_CreateDeviceObjects()
 {
 {
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
-    ImGui_ImplSDLGPU3_InitInfo* v = &bd->GPUInitInfo;
+    ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
 
 
     if (!bd->FontSampler)
     if (!bd->FontSampler)
     {
     {
@@ -533,23 +531,22 @@ bool ImGui_ImplSDLGPU3_CreateDeviceObjects()
         sampler_info.max_anisotropy = 1.0f;
         sampler_info.max_anisotropy = 1.0f;
         sampler_info.enable_compare = false;
         sampler_info.enable_compare = false;
 
 
-        bd->FontSampler = SDL_CreateGPUSampler(v->GpuDevice, &sampler_info);
+        bd->FontSampler = SDL_CreateGPUSampler(v->Device, &sampler_info);
         bd->FontBinding.sampler = bd->FontSampler;
         bd->FontBinding.sampler = bd->FontSampler;
         IM_ASSERT(bd->FontSampler != nullptr && "Failed to create font sampler, call SDL_GetError() for more information");
         IM_ASSERT(bd->FontSampler != nullptr && "Failed to create font sampler, call SDL_GetError() for more information");
     }
     }
 
 
     ImGui_ImplSDLGPU3_CreateGraphicsPipeline();
     ImGui_ImplSDLGPU3_CreateGraphicsPipeline();
-
-    return true;
+    ImGui_ImplSDLGPU3_CreateFontsTexture();
 }
 }
 
 
 void ImGui_ImplSDLGPU3_DestroyFrameData()
 void ImGui_ImplSDLGPU3_DestroyFrameData()
 {
 {
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
-    ImGui_ImplSDLGPU3_InitInfo* v = &bd->GPUInitInfo;
+    ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
 
 
-    SDL_ReleaseGPUBuffer(v->GpuDevice, bd->MainWindowFrameData.VertexBuffer);
-    SDL_ReleaseGPUBuffer(v->GpuDevice, bd->MainWindowFrameData.IndexBuffer);
+    SDL_ReleaseGPUBuffer(v->Device, bd->MainWindowFrameData.VertexBuffer);
+    SDL_ReleaseGPUBuffer(v->Device, bd->MainWindowFrameData.IndexBuffer);
     bd->MainWindowFrameData.VertexBuffer = nullptr;
     bd->MainWindowFrameData.VertexBuffer = nullptr;
     bd->MainWindowFrameData.IndexBuffer = nullptr;
     bd->MainWindowFrameData.IndexBuffer = nullptr;
     bd->MainWindowFrameData.VertexBufferSize = 0;
     bd->MainWindowFrameData.VertexBufferSize = 0;
@@ -559,15 +556,15 @@ void ImGui_ImplSDLGPU3_DestroyFrameData()
 void ImGui_ImplSDLGPU3_DestroyDeviceObjects()
 void ImGui_ImplSDLGPU3_DestroyDeviceObjects()
 {
 {
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
     ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
-    ImGui_ImplSDLGPU3_InitInfo* v = &bd->GPUInitInfo;
+    ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
 
 
     ImGui_ImplSDLGPU3_DestroyFrameData();
     ImGui_ImplSDLGPU3_DestroyFrameData();
     ImGui_ImplSDLGPU3_DestroyFontsTexture();
     ImGui_ImplSDLGPU3_DestroyFontsTexture();
 
 
-    if (bd->VertexShader)   { SDL_ReleaseGPUShader(v->GpuDevice, bd->VertexShader); bd->VertexShader = nullptr;}
-    if (bd->FragmentShader) { SDL_ReleaseGPUShader(v->GpuDevice, bd->FragmentShader); bd->FragmentShader = nullptr;}
-    if (bd->FontSampler)    { SDL_ReleaseGPUSampler(v->GpuDevice, bd->FontSampler); bd->FontSampler = nullptr;}
-    if (bd->Pipeline)       { SDL_ReleaseGPUGraphicsPipeline(v->GpuDevice, bd->Pipeline); bd->Pipeline = nullptr;}
+    if (bd->VertexShader)   { SDL_ReleaseGPUShader(v->Device, bd->VertexShader); bd->VertexShader = nullptr;}
+    if (bd->FragmentShader) { SDL_ReleaseGPUShader(v->Device, bd->FragmentShader); bd->FragmentShader = nullptr;}
+    if (bd->FontSampler)    { SDL_ReleaseGPUSampler(v->Device, bd->FontSampler); bd->FontSampler = nullptr;}
+    if (bd->Pipeline)       { SDL_ReleaseGPUGraphicsPipeline(v->Device, bd->Pipeline); bd->Pipeline = nullptr;}
 }
 }
 
 
 bool ImGui_ImplSDLGPU3_Init(ImGui_ImplSDLGPU3_InitInfo* info)
 bool ImGui_ImplSDLGPU3_Init(ImGui_ImplSDLGPU3_InitInfo* info)
@@ -582,10 +579,10 @@ bool ImGui_ImplSDLGPU3_Init(ImGui_ImplSDLGPU3_InitInfo* info)
     io.BackendRendererName = "imgui_impl_sdlgpu3";
     io.BackendRendererName = "imgui_impl_sdlgpu3";
     io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset;  // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
     io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset;  // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
 
 
-    IM_ASSERT(info->GpuDevice != nullptr);
+    IM_ASSERT(info->Device != nullptr);
     IM_ASSERT(info->ColorTargetFormat != SDL_GPU_TEXTUREFORMAT_INVALID);
     IM_ASSERT(info->ColorTargetFormat != SDL_GPU_TEXTUREFORMAT_INVALID);
 
 
-    bd->GPUInitInfo = *info;
+    bd->InitInfo = *info;
 
 
     ImGui_ImplSDLGPU3_CreateDeviceObjects();
     ImGui_ImplSDLGPU3_CreateDeviceObjects();
 
 

+ 11 - 8
backends/imgui_impl_sdlgpu3.h

@@ -29,18 +29,21 @@
 // - Remember to set ColorTargetFormat to the correct format. If you're rendering to the swapchain, call SDL_GetGPUSwapchainTextureFormat to query the right value
 // - Remember to set ColorTargetFormat to the correct format. If you're rendering to the swapchain, call SDL_GetGPUSwapchainTextureFormat to query the right value
 struct ImGui_ImplSDLGPU3_InitInfo
 struct ImGui_ImplSDLGPU3_InitInfo
 {
 {
-    SDL_GPUDevice*       GpuDevice          = nullptr;
+    SDL_GPUDevice*       Device             = nullptr;
     SDL_GPUTextureFormat ColorTargetFormat  = SDL_GPU_TEXTUREFORMAT_INVALID;
     SDL_GPUTextureFormat ColorTargetFormat  = SDL_GPU_TEXTUREFORMAT_INVALID;
     SDL_GPUSampleCount   MSAASamples        = SDL_GPU_SAMPLECOUNT_1;
     SDL_GPUSampleCount   MSAASamples        = SDL_GPU_SAMPLECOUNT_1;
 };
 };
 
 
 // Follow "Getting Started" link and check examples/ folder to learn about using backends!
 // Follow "Getting Started" link and check examples/ folder to learn about using backends!
-IMGUI_IMPL_API bool    ImGui_ImplSDLGPU3_Init(ImGui_ImplSDLGPU3_InitInfo* info);
-IMGUI_IMPL_API void    ImGui_ImplSDLGPU3_Shutdown();
-IMGUI_IMPL_API void    ImGui_ImplSDLGPU3_NewFrame();
-IMGUI_IMPL_API void    Imgui_ImplSDLGPU3_PrepareDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffer* command_buffer);
-IMGUI_IMPL_API void    ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffer* command_buffer, SDL_GPURenderPass* render_pass, SDL_GPUGraphicsPipeline* pipeline = nullptr);
-IMGUI_IMPL_API bool    ImGui_ImplSDLGPU3_CreateFontsTexture();
-IMGUI_IMPL_API void    ImGui_ImplSDLGPU3_DestroyFontsTexture();
+IMGUI_IMPL_API bool     ImGui_ImplSDLGPU3_Init(ImGui_ImplSDLGPU3_InitInfo* info);
+IMGUI_IMPL_API void     ImGui_ImplSDLGPU3_Shutdown();
+IMGUI_IMPL_API void     ImGui_ImplSDLGPU3_NewFrame();
+IMGUI_IMPL_API void     Imgui_ImplSDLGPU3_PrepareDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffer* command_buffer);
+IMGUI_IMPL_API void     ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffer* command_buffer, SDL_GPURenderPass* render_pass, SDL_GPUGraphicsPipeline* pipeline = nullptr);
+
+IMGUI_IMPL_API void     ImGui_ImplSDLGPU3_CreateDeviceObjects();
+IMGUI_IMPL_API void     ImGui_ImplSDLGPU3_DestroyDeviceObjects();
+IMGUI_IMPL_API void     ImGui_ImplSDLGPU3_CreateFontsTexture();
+IMGUI_IMPL_API void     ImGui_ImplSDLGPU3_DestroyFontsTexture();
 
 
 #endif // #ifndef IMGUI_DISABLE
 #endif // #ifndef IMGUI_DISABLE

+ 6 - 1
docs/CHANGELOG.txt

@@ -41,6 +41,9 @@ HOW TO UPDATE?
 
 
 Breaking changes:
 Breaking changes:
 
 
+- Backends: SDLGPU3: Renamed ImGui_ImplSDLGPU3_InitInfo::GpuDevice to Device
+  for consistency. (#8163, #7998, #7988)
+
 Other changes:
 Other changes:
 
 
 - ImDrawList: texture baked storage for thick line reduced from ~64x64 to ~32x32. (#3245)
 - ImDrawList: texture baked storage for thick line reduced from ~64x64 to ~32x32. (#3245)
@@ -48,6 +51,8 @@ Other changes:
   provided example, to reduce latency.
   provided example, to reduce latency.
 - Examples: Vulkan: better handle VK_SUBOPTIMAL_KHR being returned by
 - Examples: Vulkan: better handle VK_SUBOPTIMAL_KHR being returned by
   vkAcquireNextImageKHR() or vkQueuePresentKHR(). (#7825, #7831) [@NostraMagister]
   vkAcquireNextImageKHR() or vkQueuePresentKHR(). (#7825, #7831) [@NostraMagister]
+- Backends: SDLGPU3: Exposed ImGui_ImplSDLGPU3_CreateDeviceObjects()/_DestroyDeviceObjects().
+  Removed return value from ImGui_ImplSDLGPU3_CreateFontsTexture(). (#8163, #7998, #7988)
 - Backends: DirectX12: Texture upload use the command queue provided in
 - Backends: DirectX12: Texture upload use the command queue provided in
   ImGui_ImplDX12_InitInfo instead of creating its own.
   ImGui_ImplDX12_InitInfo instead of creating its own.
 
 
@@ -110,7 +115,7 @@ Other changes:
 - Demo: Added label edition to Property Editor demo + fix an ID issue. (#8266) [@moritz-h]
 - Demo: Added label edition to Property Editor demo + fix an ID issue. (#8266) [@moritz-h]
 - Misc: Fixed misc/cpp/imgui_stdlib.h/.cpp not supporting IMGUI_DISABLE. (#8294) [@juur]
 - Misc: Fixed misc/cpp/imgui_stdlib.h/.cpp not supporting IMGUI_DISABLE. (#8294) [@juur]
 - Misc: Fixed MinGW builds not using UTF-8 friendly _wfopen(). (#8300)
 - Misc: Fixed MinGW builds not using UTF-8 friendly _wfopen(). (#8300)
-- Backends: SDL_GPU for SDL3: Added backend for SDL_GPU! (#8163, #7998, #7988) [@DeltaW0x].
+- Backends: SDLGPU3 for SDL3: Added backend for SDL_GPU! (#8163, #7998, #7988) [@DeltaW0x].
 - Backends: SDL3: Added ImGui_ImplSDL3_InitForSDLGPU() for consistency, even
 - Backends: SDL3: Added ImGui_ImplSDL3_InitForSDLGPU() for consistency, even
   though it is currently not doing anything particular. (#8163, #7998, #7988)
   though it is currently not doing anything particular. (#8163, #7998, #7988)
 - Backends: Allegro5: Avoid calling al_set_mouse_cursor() repeatedly since it appears
 - Backends: Allegro5: Avoid calling al_set_mouse_cursor() repeatedly since it appears

+ 1 - 1
examples/example_sdl3_sdlgpu3/main.cpp

@@ -69,7 +69,7 @@ int main(int, char**)
     // Setup Platform/Renderer backends
     // Setup Platform/Renderer backends
     ImGui_ImplSDL3_InitForSDLGPU(window);
     ImGui_ImplSDL3_InitForSDLGPU(window);
     ImGui_ImplSDLGPU3_InitInfo init_info = {};
     ImGui_ImplSDLGPU3_InitInfo init_info = {};
-    init_info.GpuDevice = gpu_device;
+    init_info.Device = gpu_device;
     init_info.ColorTargetFormat = SDL_GetGPUSwapchainTextureFormat(gpu_device, window);
     init_info.ColorTargetFormat = SDL_GetGPUSwapchainTextureFormat(gpu_device, window);
     init_info.MSAASamples = SDL_GPU_SAMPLECOUNT_1;
     init_info.MSAASamples = SDL_GPU_SAMPLECOUNT_1;
     ImGui_ImplSDLGPU3_Init(&init_info);
     ImGui_ImplSDLGPU3_Init(&init_info);