Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/cute_graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,14 @@ CF_API void CF_CALL cf_texture_update_mip(CF_Texture texture, void* data, int si
*/
CF_API void CF_CALL cf_generate_mipmaps(CF_Texture texture);

/**
* @function cf_gpu_sync
* @category graphics
* @brief Submits the command buffer, waits for GPU completion via fence, then reacquires.
* @remarks Forces GPU/CPU serialization.
*/
CF_API void CF_CALL cf_gpu_sync(void);

/**
* @function cf_texture_handle
* @category graphics
Expand Down
1 change: 1 addition & 0 deletions src/cute_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,3 +747,4 @@ CF_DISPATCH_SHIM_VOID(dispatch_compute, (CF_ComputeShader shader, CF_Material ma
CF_DISPATCH_SHIM(void*, create_draw_sampler, (CF_Filter filter), filter)
CF_DISPATCH_SHIM_VOID(destroy_draw_sampler, (void* sampler), sampler)
CF_DISPATCH_SHIM_VOID(set_sampler_override, (void* sampler), sampler)
CF_DISPATCH_SHIM_VOID(gpu_sync, (), )
5 changes: 5 additions & 0 deletions src/cute_graphics_gles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,11 @@ void cf_gles_flush()
glFlush();
}

void cf_gles_gpu_sync()
{
glFinish();
}

void cf_gles_set_vsync(bool true_turn_on_vsync)
{
SDL_GL_SetSwapInterval(true_turn_on_vsync ? 1 : 0);
Expand Down
11 changes: 11 additions & 0 deletions src/cute_graphics_sdlgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,17 @@ void cf_sdlgpu_flush()
}
}

void cf_sdlgpu_gpu_sync()
{
s_end_active_pass();
if (g_ctx.cmd) {
SDL_GPUFence *fence = SDL_SubmitGPUCommandBufferAndAcquireFence(g_ctx.cmd);
SDL_WaitForGPUFences(g_ctx.device, true, &fence, 1);
SDL_ReleaseGPUFence(g_ctx.device, fence);
g_ctx.cmd = SDL_AcquireGPUCommandBuffer(g_ctx.device);
Comment on lines +818 to +822

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Wait for in-flight GPU work when no command buffer

On the SDL backend this sync path only blocks when g_ctx.cmd is non-null, but cf_sdlgpu_end_frame clears g_ctx.cmd after submitting the frame (src/cute_graphics_sdlgpu.cpp:884-885), so calling public cf_gpu_sync between frames becomes a no-op even though GPU work may still be running. That violates the documented "GPU/CPU serialization" behavior and can produce incorrect timing/synchronization results compared with the GLES path (glFinish).

Useful? React with 👍 / 👎.

}
}

void cf_sdlgpu_set_vsync(bool vsync)
{
SDL_SetGPUSwapchainParameters(g_ctx.device, g_ctx.window, SDL_GPU_SWAPCHAINCOMPOSITION_SDR, vsync ? SDL_GPU_PRESENTMODE_VSYNC : SDL_GPU_PRESENTMODE_IMMEDIATE);
Expand Down
2 changes: 2 additions & 0 deletions src/internal/cute_graphics_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ SDL_GPUCommandBuffer* cf_sdlgpu_get_command_buffer();
void cf_sdlgpu_attach(SDL_Window* window);
bool cf_sdlgpu_supports_msaa(int sample_count);
void cf_sdlgpu_flush();
void cf_sdlgpu_gpu_sync();
void cf_sdlgpu_set_vsync(bool true_turn_on_vsync);
void cf_sdlgpu_set_vsync_mailbox(bool true_turn_on_vsync);
void cf_sdlgpu_begin_frame();
Expand All @@ -255,6 +256,7 @@ SDL_GLContext cf_gles_get_gl_context();
void cf_gles_attach(SDL_Window* window);
bool cf_gles_supports_msaa(int sample_count);
void cf_gles_flush();
void cf_gles_gpu_sync();
void cf_gles_set_vsync(bool true_turn_on_vsync);
void cf_gles_begin_frame();
void cf_gles_blit_canvas(CF_Canvas canvas);
Expand Down
Loading