-
Notifications
You must be signed in to change notification settings - Fork 2
Add async rendering scheduling support in RenderContentBaseSystem and refactor RenderTextSystem to use it #319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
…em and refactor RenderTextSystem Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
…stem Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, please review your code to ensure that the markAsyncRenderingCompleted()
function updates the surface
after it is called.
|
||
// Async rendering state tracking (thread-safe) | ||
mutable std::mutex async_state_mutex_; | ||
bool async_rendering_in_progress_ = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot WebContent
may be copied. You might consider wrapping it with shared_ptr
to ensure that the newly added fields function correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in commit e7758b7. Changed scheduleAsyncSurfaceUpdate()
to use std::shared_ptr<WebContent>
instead of reference capture to prevent the WebContent object from being destroyed during async operations. The lambda now safely captures the shared_ptr by value, ensuring the object remains valid throughout the async operation lifecycle.
if (shouldUseAsyncRendering(text, content)) | ||
{ | ||
// Schedule async rendering for heavy text operations (layout + SDF generation) | ||
scheduleAsyncSurfaceUpdate(entity, content, [this](ecs::EntityId asyncEntity, WebContent &asyncContent) -> bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot We need always to use async rendering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in commit e7758b7. Removed the conditional logic and now always use async rendering for all text. Simplified the implementation by removing renderTextSync()
and shouldUseAsyncRendering()
methods - all text rendering now goes through the async path regardless of complexity.
…dering, clarify surface updates Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Confirmed in commit e7758b7. The |
This PR implements async rendering scheduling to address performance bottlenecks where complex text rendering and SDF texture generation could block the main rendering loop, causing frame drops and UI stalls.
Problem
Currently, text rendering in
RenderTextSystem
performs all operations synchronously on the main thread:For large or complex text content, the SDF generation step could take significant time, making the UI unresponsive.
Solution
The implementation adds a generic async rendering scheduling system with three key components:
1. Thread-Safe Async State Management
Enhanced
WebContent
with mutex-protected async state tracking:2. Generic Async Scheduling Infrastructure
Added
scheduleAsyncSurfaceUpdate()
toRenderContentBaseSystem
for offloading any heavy rendering work:This method is designed to be generic enough for any async rendering operations beyond text. The method uses
shared_ptr
to ensure thread safety and prevent WebContent objects from being destroyed during async operations.3. Always-Async Text Rendering
Refactored
RenderTextSystem
to always use async rendering for all text operations:All text rendering now uses the async path regardless of complexity, ensuring consistent non-blocking behavior.
Thread Safety
The implementation ensures thread safety through:
std::mutex async_state_mutex_
shared_ptr
prevents WebContent destruction during async operationsUpdateTextureSystem
skips content with async operations in progressPerformance Impact
The changes maintain full backward compatibility - existing synchronous workflows continue unchanged.
Fixes #318.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.