仍然闪烁

This commit is contained in:
2026-08-02 18:58:35 +08:00
parent ffaca5b05f
commit 9a39f88427
54 changed files with 2257 additions and 2424 deletions
+23 -22
View File
@@ -1,4 +1,5 @@
#include "Explicit_Frame_Flow.h"
#include "Explicit_Renderable_Runtime.h"
#include "../../architecture/Render_Time.h"
#include "../../architecture/Update_Completion.h"
@@ -11,13 +12,13 @@ struct Explicit_Render_Surface_Handle final : Render_Frame_Surface_Handle {
};
struct Explicit_Present_Surface_Handle final {
explicit Explicit_Present_Surface_Handle(std::shared_ptr<Render_Output> output) : output_value(std::move(output)) {}
explicit Explicit_Present_Surface_Handle(std::shared_ptr<const Render_Output> output) : output_value(std::move(output)) {}
[[nodiscard]] Render_Output* output() const {
return output_value.get();
return const_cast<Render_Output*>(output_value.get());
}
std::shared_ptr<Render_Output> output_value;
std::shared_ptr<const Render_Output> output_value;
};
Explicit_Render_Surface_Handle* explicit_handle(Render_Frame_Surface& surface) {
@@ -42,8 +43,8 @@ void Explicit_Frame_Flow::attach(Frame_Flow_Host& host_value) {
host = &host_value;
}
Renderable_Runtime_Strategy Explicit_Frame_Flow::renderable_runtime_strategy() const {
return Renderable_Runtime_Strategy::Explicit;
std::unique_ptr<Renderable_Runtime> Explicit_Frame_Flow::create_renderable_runtime(Renderable& owner) const {
return make_explicit_renderable_runtime(owner);
}
Frame_Flow_Runtime_Snapshot Explicit_Frame_Flow::runtime_snapshot(std::uint64_t now_ns, bool destroying) const {
@@ -52,7 +53,7 @@ Frame_Flow_Runtime_Snapshot Explicit_Frame_Flow::runtime_snapshot(std::uint64_t
manual_request_pending.load(std::memory_order_acquire),
render_job_active.load(std::memory_order_acquire),
frame_ready.load(std::memory_order_acquire),
present_active.load(std::memory_order_acquire),
false,
now_ns
};
}
@@ -70,13 +71,13 @@ void Explicit_Frame_Flow::cancel_all_update_states() {
}
pending_requests.clear();
}
std::shared_ptr<Render_Output> output;
std::shared_ptr<const Render_Output> output;
{
std::lock_guard<std::mutex> lock(surface_mutex);
output = std::move(present_surface);
output = present_surface;
}
if (output)
cancel_update_states(output->presented_update_states);
cancel_update_states(const_cast<Render_Output*>(output.get())->presented_update_states);
}
Render_Frame_Surface Explicit_Frame_Flow::begin_render_frame() {
@@ -114,7 +115,7 @@ Render_Surface_Publish_Result Explicit_Frame_Flow::publish_rendered_frame(Render
result.update_request_id = handle->output->metadata->update_request_id;
result.update_request_time = now_ns;
}
std::shared_ptr<Render_Output> output = std::move(handle->output);
std::shared_ptr<const Render_Output> output = std::move(handle->output);
Size size = output ? output->image.size() : Size{};
{
std::lock_guard<std::mutex> lock(surface_mutex);
@@ -130,17 +131,18 @@ Render_Surface_Publish_Result Explicit_Frame_Flow::publish_rendered_frame(Render
Render_Surface_Publish_Result Explicit_Frame_Flow::request_present(std::uint64_t now_ns) {
Render_Surface_Publish_Result result;
std::shared_ptr<Render_Output> output;
std::shared_ptr<const Render_Output> output;
{
std::lock_guard<std::mutex> lock(surface_mutex);
output = present_surface;
}
if (!output)
return result;
if (output->metadata) {
output->metadata->update_request_id = ++next_present_request_id;
output->metadata->update_request_time_ns = now_ns;
result.update_request_id = output->metadata->update_request_id;
Render_Output* mutable_output = const_cast<Render_Output*>(output.get());
if (mutable_output->metadata) {
mutable_output->metadata->update_request_id = ++next_present_request_id;
mutable_output->metadata->update_request_time_ns = now_ns;
result.update_request_id = mutable_output->metadata->update_request_id;
result.update_request_time = now_ns;
}
paint_request_pending.store(true, std::memory_order_release);
@@ -152,18 +154,19 @@ Render_Surface_Publish_Result Explicit_Frame_Flow::request_present(std::uint64_t
Present_Surface_Lease Explicit_Frame_Flow::begin_present(std::uint64_t now_ns, std::shared_ptr<Frame_Lifecycle_Record>& returned_frame_record) {
returned_frame_record.reset();
std::shared_ptr<Render_Output> output;
std::shared_ptr<const Render_Output> output;
{
std::lock_guard<std::mutex> lock(surface_mutex);
output = present_surface;
}
if (!output || present_active.exchange(true, std::memory_order_acq_rel))
if (!output)
return {};
bool is_new = frame_ready.exchange(false, std::memory_order_acq_rel);
bool pending = paint_request_pending.exchange(false, std::memory_order_acq_rel);
if (is_new && output->metadata) {
output->metadata->transition_23_ns = now_ns;
output->metadata->present_queue_wait_ns = now_ns > output->metadata->transition_12_ns ? now_ns - output->metadata->transition_12_ns : 0;
Render_Output* mutable_output = const_cast<Render_Output*>(output.get());
if (is_new && mutable_output->metadata) {
mutable_output->metadata->transition_23_ns = now_ns;
mutable_output->metadata->present_queue_wait_ns = now_ns > mutable_output->metadata->transition_12_ns ? now_ns - mutable_output->metadata->transition_12_ns : 0;
}
return Present_Surface_Lease_Access::from_handle<Explicit_Present_Surface_Handle>(
is_new,
@@ -184,7 +187,6 @@ std::shared_ptr<Frame_Lifecycle_Record> Explicit_Frame_Flow::end_present(Present
complete_update_states(output->presented_update_states, Update_Stage::Presented);
}
Present_Surface_Lease_Access::reset(surface);
present_active.store(false, std::memory_order_release);
return record;
}
@@ -256,7 +258,6 @@ void Explicit_Frame_Flow::shutdown() {
manual_request_pending.store(false, std::memory_order_release);
render_job_active.store(false, std::memory_order_release);
frame_ready.store(false, std::memory_order_release);
present_active.store(false, std::memory_order_release);
paint_request_pending.store(false, std::memory_order_release);
}