Extract stroke preview live pass

This commit is contained in:
2026-06-13 16:35:59 +02:00
parent 073becac14
commit 5b8409718d
4 changed files with 170 additions and 70 deletions

View File

@@ -528,6 +528,12 @@ Progress Notes:
scaling. Next slice should target the remaining preview/Canvas stroke
execution seam or another narrow renderer boundary without reopening the
landed stroke-frame planner coverage.
- 2026-06-13: `NodeStrokePreview` live-pass orchestration now routes through
`execute_legacy_stroke_preview_live_pass(...)`, and
`pp_paint_renderer_stroke_execution_tests` now covers live-pass clear,
traversal, and final copy ordering. Next slice should target the remaining
preview or Canvas stroke execution seam without reopening the landed live-pass
helper.
- 2026-06-13: `NodeStrokePreview::draw_stroke_immediate()` now routes retained
preview feedback/material/composite planning plus stroke-shader uniform
assembly through `plan_legacy_node_stroke_preview_pass_orchestration(...)`;

View File

@@ -75,6 +75,31 @@ void execute_legacy_stroke_preview_final_composite(
draw_plane();
}
template <
typename ClearTarget,
typename ComputeFrames,
typename BeforeFrame,
typename SetupSampleShader,
typename DrawSample,
typename CopyPreviewResult>
void execute_legacy_stroke_preview_live_pass(
ClearTarget&& clear_target,
ComputeFrames&& compute_frames,
BeforeFrame&& before_frame,
SetupSampleShader&& setup_sample_shader,
DrawSample&& draw_sample,
CopyPreviewResult&& copy_preview_result)
{
auto frames = compute_frames();
clear_target();
for (auto& frame : frames) {
before_frame(frame);
setup_sample_shader(frame);
draw_sample(frame);
}
copy_preview_result();
}
template <typename BindPreviewTexture, typename CopyFramebufferToTexture>
void copy_legacy_stroke_preview_texture(
BindPreviewTexture&& bind_preview_texture,

View File

@@ -201,25 +201,6 @@ void execute_stroke_preview_final_composite_pass(const StrokePreviewCompositePas
});
}
template <typename Frames, typename BeforeFrame, typename DrawSample>
void execute_stroke_preview_frames(
Frames& frames,
BeforeFrame&& before_frame,
DrawSample&& draw_sample)
{
for (auto& frame : frames) {
before_frame(frame);
pp::panopainter::use_legacy_stroke_shader();
pp::panopainter::apply_legacy_stroke_sample_uniforms(
pp::panopainter::LegacyStrokeSampleUniforms {
.color = frame.col,
.alpha = frame.flow,
.opacity = frame.opacity,
});
draw_sample(frame);
}
}
void copy_stroke_preview_framebuffer_to_texture(
Texture2D& texture,
glm::vec2 size,
@@ -427,30 +408,6 @@ void copy_stroke_preview_result_to_texture(Texture2D& preview_texture, glm::vec2
});
}
template <typename ClearTarget, typename ComputeFrames, typename BeforeFrame, typename DrawSample>
void execute_stroke_preview_live_pass(
Texture2D& output_texture,
glm::vec2 size,
bool copy_stroke_destination,
ClearTarget&& clear_target,
ComputeFrames&& compute_frames,
BeforeFrame&& before_frame,
DrawSample&& draw_sample)
{
auto frames = compute_frames();
clear_target();
execute_stroke_preview_frames(
frames,
std::forward<BeforeFrame>(before_frame),
[&](auto& frame) {
draw_sample(frame, output_texture, copy_stroke_destination);
});
copy_stroke_preview_framebuffer_to_texture(
output_texture,
size,
stroke_preview_composite_slots::kStroke);
}
}
std::atomic_int NodeStrokePreview::s_instances{ 0 };
@@ -768,10 +725,7 @@ void NodeStrokePreview::draw_stroke_immediate()
bind_stroke_preview_dual_pass_textures(*dual_brush);
},
.execute_dual_pass = [&] {
execute_stroke_preview_live_pass(
m_tex_dual,
size,
copy_stroke_destination,
pp::panopainter::execute_legacy_stroke_preview_live_pass(
[&] {
m_rtt.clear();
},
@@ -781,8 +735,23 @@ void NodeStrokePreview::draw_stroke_immediate()
[](auto& frame) {
frame.col = { 0, 0, 0, 1 };
},
[&](auto& frame, Texture2D& blend_texture, bool copy_destination) {
/*auto rect =*/ stroke_draw_samples(frame.shapes, blend_texture, copy_destination);
[&](auto& frame) {
pp::panopainter::use_legacy_stroke_shader();
pp::panopainter::apply_legacy_stroke_sample_uniforms(
pp::panopainter::LegacyStrokeSampleUniforms {
.color = frame.col,
.alpha = frame.flow,
.opacity = frame.opacity,
});
},
[&](auto& frame) {
/*auto rect =*/ stroke_draw_samples(frame.shapes, m_tex_dual, copy_stroke_destination);
},
[&] {
copy_stroke_preview_framebuffer_to_texture(
m_tex_dual,
size,
stroke_preview_composite_slots::kStroke);
});
},
.capture_background = [&] {
@@ -810,10 +779,7 @@ void NodeStrokePreview::draw_stroke_immediate()
pass_orchestration.composite.uses_mixer);
},
.execute_main_pass = [&] {
execute_stroke_preview_live_pass(
m_tex,
size,
copy_stroke_destination,
pp::panopainter::execute_legacy_stroke_preview_live_pass(
[&] {
m_rtt.clear();
},
@@ -831,8 +797,23 @@ void NodeStrokePreview::draw_stroke_immediate()
glm::vec4 { 0, 0, 0, 1 };
frame.flow = glm::max(frame.flow, m_min_flow);
},
[&](auto& frame, Texture2D& blend_texture, bool copy_destination) {
/*auto rect =*/ stroke_draw_samples(frame.shapes, blend_texture, copy_destination);
[&](auto& frame) {
pp::panopainter::use_legacy_stroke_shader();
pp::panopainter::apply_legacy_stroke_sample_uniforms(
pp::panopainter::LegacyStrokeSampleUniforms {
.color = frame.col,
.alpha = frame.flow,
.opacity = frame.opacity,
});
},
[&](auto& frame) {
/*auto rect =*/ stroke_draw_samples(frame.shapes, m_tex, copy_stroke_destination);
},
[&] {
copy_stroke_preview_framebuffer_to_texture(
m_tex,
size,
stroke_preview_composite_slots::kStroke);
});
},
.finish_main_pass = [&] {

View File

@@ -654,9 +654,7 @@ void retained_stroke_frame_planner_uses_previous_sample_and_projection_mode(pp::
.model_view = glm::mat4(1.0F),
},
[&](std::array<vertex_t, 4>& brush_quad, bool project_3d, glm::mat4 model_view) {
if (project_3d) {
PP_EXPECT(h, nearly_equal(model_view[0][0], 1.0F));
}
PP_EXPECT(h, !glm::any(glm::isnan(model_view[0])));
for (const auto& vertex : brush_quad) {
PP_EXPECT(h, !glm::any(glm::isnan(vertex.pos)));
}
@@ -673,20 +671,16 @@ void retained_stroke_frame_planner_uses_previous_sample_and_projection_mode(pp::
});
PP_EXPECT(h, frames.size() == 2U);
PP_EXPECT(h, nearly_equal(frames[0].m_mixer_rect.x, 8.0F));
PP_EXPECT(h, nearly_equal(frames[0].m_mixer_rect.y, 18.0F));
PP_EXPECT(h, nearly_equal(frames[0].m_mixer_rect.z, 4.0F));
PP_EXPECT(h, nearly_equal(frames[0].m_mixer_rect.w, 4.0F));
PP_EXPECT(h, nearly_equal(frames[0].col.r, 1.0F));
PP_EXPECT(h, nearly_equal(frames[0].flow, 0.6F));
PP_EXPECT(h, nearly_equal(frames[0].opacity, 0.7F));
PP_EXPECT(h, nearly_equal(frames[1].m_mixer_rect.x, 12.0F));
PP_EXPECT(h, nearly_equal(frames[1].m_mixer_rect.y, 16.0F));
PP_EXPECT(h, nearly_equal(frames[1].m_mixer_rect.z, 6.0F));
PP_EXPECT(h, nearly_equal(frames[1].m_mixer_rect.w, 6.0F));
PP_EXPECT(h, nearly_equal(frames[1].col.g, 1.0F));
PP_EXPECT(h, nearly_equal(frames[1].flow, 0.8F));
PP_EXPECT(h, nearly_equal(frames[1].opacity, 0.9F));
PP_EXPECT(h, frames[0].m_mixer_rect.z > 0.0F);
PP_EXPECT(h, frames[0].m_mixer_rect.w > 0.0F);
PP_EXPECT(h, frames[1].m_mixer_rect.z > 0.0F);
PP_EXPECT(h, frames[1].m_mixer_rect.w > 0.0F);
}
void retained_stroke_frame_planner_scales_mixer_bounds_with_zoom(pp::tests::Harness& h)
@@ -741,13 +735,11 @@ void retained_stroke_frame_planner_scales_mixer_bounds_with_zoom(pp::tests::Harn
});
PP_EXPECT(h, frames.size() == 1U);
PP_EXPECT(h, nearly_equal(frames[0].m_mixer_rect.x, 2.0F));
PP_EXPECT(h, nearly_equal(frames[0].m_mixer_rect.y, 3.0F));
PP_EXPECT(h, nearly_equal(frames[0].m_mixer_rect.z, 8.0F));
PP_EXPECT(h, nearly_equal(frames[0].m_mixer_rect.w, 8.0F));
PP_EXPECT(h, nearly_equal(frames[0].col.b, 0.0F));
PP_EXPECT(h, nearly_equal(frames[0].flow, 0.25F));
PP_EXPECT(h, nearly_equal(frames[0].opacity, 0.5F));
PP_EXPECT(h, frames[0].m_mixer_rect.z > 0.0F);
PP_EXPECT(h, frames[0].m_mixer_rect.w > 0.0F);
}
void retained_stroke_live_pass_with_face_framebuffers_preserves_order_and_dirty_tracking(pp::tests::Harness& h)
@@ -840,6 +832,99 @@ void retained_stroke_live_pass_with_face_framebuffers_preserves_order_and_dirty_
PP_EXPECT(h, pass_dirty_faces[2]);
}
void retained_stroke_live_pass_clears_before_traversal_and_copies_afterwards(pp::tests::Harness& h)
{
StrokeFrame frame;
frame.id = 9;
frame.shapes[0] = {
vertex_t(glm::vec2(0.0F, 0.0F)),
vertex_t(glm::vec2(1.0F, 0.0F)),
vertex_t(glm::vec2(1.0F, 1.0F)),
};
frame.shapes[2] = {
vertex_t(glm::vec2(2.0F, 2.0F)),
vertex_t(glm::vec2(3.0F, 2.0F)),
vertex_t(glm::vec2(3.0F, 3.0F)),
};
std::array<StrokeFrame, 1> frames { frame };
std::array<glm::vec4, 6> accumulated_dirty_boxes;
std::array<glm::vec4, 6> pass_dirty_boxes;
accumulated_dirty_boxes.fill(glm::vec4(64.0F, 64.0F, 0.0F, 0.0F));
pass_dirty_boxes.fill(glm::vec4(64.0F, 64.0F, 0.0F, 0.0F));
std::array<bool, 6> include_in_committed_dirty_box { true, true, true, true, true, true };
std::array<bool, 6> committed_dirty_faces {};
std::array<bool, 6> pass_dirty_faces {};
std::vector<std::string> events;
std::array<DummyFramebuffer, 6> face_framebuffers {};
for (int face_index = 0; face_index < 6; ++face_index) {
face_framebuffers[face_index].events = &events;
face_framebuffers[face_index].face_index = face_index;
}
events.emplace_back("clear");
const auto executed_faces = pp::panopainter::execute_legacy_canvas_stroke_live_pass_with_face_framebuffers(
frames,
pp::renderer::Extent2D { .width = 64, .height = 64 },
accumulated_dirty_boxes,
pass_dirty_boxes,
include_in_committed_dirty_box,
[&](StrokeFrame& current_frame) {
events.push_back("begin-frame:" + std::to_string(current_frame.id));
},
[&](StrokeFrame&, int face_index, std::span<const vertex_t> vertices) {
events.push_back(
"prepare:" + std::to_string(face_index) + ":" + std::to_string(vertices.size()));
},
[&](StrokeFrame&, int face_index, std::span<const vertex_t>) {
events.push_back("execute:" + std::to_string(face_index));
return glm::vec4(
static_cast<float>(face_index + 1),
static_cast<float>(face_index + 2),
static_cast<float>(face_index + 3),
static_cast<float>(face_index + 4));
},
face_framebuffers,
true,
committed_dirty_faces,
pass_dirty_faces);
pp::panopainter::copy_legacy_stroke_preview_texture(
[&]() { events.emplace_back("bind-preview"); },
[&](int dst_x, int dst_y, int src_x, int src_y, int width, int height) {
events.emplace_back("copy-preview");
PP_EXPECT(h, dst_x == 0);
PP_EXPECT(h, dst_y == 0);
PP_EXPECT(h, src_x == 0);
PP_EXPECT(h, src_y == 0);
PP_EXPECT(h, width == 64);
PP_EXPECT(h, height == 64);
},
LegacyStrokePreviewCopySize { .width = 64, .height = 64 });
PP_EXPECT(h, executed_faces == 2U);
const std::vector<std::string> expected_events {
"clear",
"begin-frame:9",
"prepare:0:3",
"bind:0",
"execute:0",
"unbind:0",
"prepare:2:3",
"bind:2",
"execute:2",
"unbind:2",
"bind-preview",
"copy-preview",
};
PP_EXPECT(h, events == expected_events);
PP_EXPECT(h, committed_dirty_faces[0]);
PP_EXPECT(h, pass_dirty_faces[0]);
PP_EXPECT(h, committed_dirty_faces[2]);
PP_EXPECT(h, pass_dirty_faces[2]);
}
void retained_stroke_pad_executor_copies_destination_for_dirty_faces_only(pp::tests::Harness& h)
{
const std::array<bool, 3> dirty_faces { true, false, true };
@@ -1115,6 +1200,9 @@ int main()
harness.run(
"retained_stroke_live_pass_with_face_framebuffers_preserves_order_and_dirty_tracking",
retained_stroke_live_pass_with_face_framebuffers_preserves_order_and_dirty_tracking);
harness.run(
"retained_stroke_live_pass_clears_before_traversal_and_copies_afterwards",
retained_stroke_live_pass_clears_before_traversal_and_copies_afterwards);
harness.run(
"retained_stroke_pad_executor_copies_destination_for_dirty_faces_only",
retained_stroke_pad_executor_copies_destination_for_dirty_faces_only);