feat(graphics): add double buffering with dirty region tracking#97
Merged
feat(graphics): add double buffering with dirty region tracking#97
Conversation
Implement Phase 1 of the graphics stack roadmap with double buffering support for the interactive shell framebuffer. Architecture: - DoubleBufferedFrameBuffer: heap-allocated shadow buffer with flush() - ShellFrameBuffer: Option<DoubleBufferedFrameBuffer> for lazy upgrade - Direct writes during early boot (before heap), double-buffered after Key features: - Shadow buffer allocated after heap init via upgrade_to_double_buffer() - Batched writes with dirty tracking for efficient flushing - Safe slice operations for shadow buffer, unsafe only for hardware copy - Zero warnings, no #[allow(dead_code)] annotations Files: - kernel/src/graphics/mod.rs - new graphics module - kernel/src/graphics/double_buffer.rs - DoubleBufferedFrameBuffer impl - kernel/src/logger.rs - ShellFrameBuffer with optional double buffering - kernel/src/main.rs - upgrade call after memory::init() Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Phase 2 of graphics stack: Enhanced framebuffer features - Add DirtyRegion struct for tracking modified rectangular areas - Implement partial flush that only copies dirty scanline regions - Add scroll_hardware_up for optimized scroll operations - Track modifications at pixel granularity in write_pixel - Reduce memory bandwidth by avoiding full buffer copies Performance improvement: Only flushing changed regions instead of the entire framebuffer (4MB at 1080p) on every character write. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Fixes issues identified by technical validation:
1. Fix coordinate bug in write_pixel dirty region marking:
- Changed from absolute buffer offset to within-scanline byte offset
- mark_region_dirty now receives x_byte_offset (x * bytes_per_pixel)
instead of byte_offset (which included row offset)
2. Add unit tests for DirtyRegion:
- dirty_region_new_is_empty: verifies new() creates empty region
- dirty_region_mark_expands: verifies mark_dirty sets correct bounds
- dirty_region_mark_unions: verifies multiple marks union correctly
- dirty_region_clear_resets: verifies clear() resets to empty
3. Add unit tests for DoubleBufferedFrameBuffer:
- double_buffer_new_not_dirty: verifies initial state
- double_buffer_mark_region_sets_dirty: verifies marking works
- double_buffer_flush_clears_dirty: verifies flush resets state
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds 5 tests to verify the core dirty region tracking behavior: 1. double_buffer_flush_copies_dirty_bytes - Verifies flush() actually copies bytes from shadow to hardware 2. double_buffer_flush_only_copies_dirty_region - Verifies non-dirty regions are NOT touched (partial flush works) 3. double_buffer_flush_full_copies_everything - Verifies flush_full() copies entire buffer regardless of dirty state 4. double_buffer_coordinate_interpretation - Guards against regression of x_byte_offset bug - Verifies x coordinates are within-row offsets, not absolute 5. double_buffer_scroll_hardware_up - Tests hardware buffer scroll operation These tests address validation feedback that the previous tests only verified state management but not the actual optimization behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements Phase 1 and Phase 2 of the graphics stack for tear-free shell rendering:
flush()copies to hardware.scroll_hardware_up()shifts hardware buffer directly for efficient scrolling.Test plan
interactiveandtestingfeatures)Changes
kernel/src/graphics/mod.rskernel/src/graphics/double_buffer.rskernel/src/logger.rskernel/src/lib.rskernel/src/main.rs🤖 Generated with Claude Code