This Pull Request introduces significant performance optimizations, architectural stability enhancements, and advanced vector/text composting features to the ProGPU graphics engine. It also adds three new compatibility shims (SkiaSharp, GDI+, and WPF DrawingContext) to allow drop-in replacement on the GPU.
- Problem: Direct disposal of WebGPU handles (
GpuTexture,GpuBuffer) on arbitrary garbage collection finalizer threads caused deadlocks or thread-unsafety crashes because WebGPU commands must run on the render thread. - Solution: Implemented a thread-safe deferred disposal queue inside
WgpuContext. Native handles are queued during garbage collection finalization, and the render loop thread safely drains and releases them synchronously during the frame render cycle. This resolved a memory leak of up to 28.6 GB under continuous redraw tests. - Cleanup: Removed redundant/unsafe custom finalizers from managers like
ComputeAcceleratorandGlyphAtlas.
- Anti-Artifacting: Replaced standard winding interval calculations in
GlyphRasterizerShaderandPathRasterizerShaderwith Precise Direction-Aware Half-Open Winding Intervals to prevent dropout seams and horizontal line artifacts at curve/line boundaries:- Upward Crossing (
deriv_y > 0.0): Evaluated on[0.0, 1.0)(inclusive of start, exclusive of end). - Downward Crossing (
deriv_y < 0.0): Evaluated on(0.0, 1.0](exclusive of start, inclusive of end).
- Upward Crossing (
- Optimization: Integrated a pipeline cache in
RenderPipelineCache.csto reuse compiled WebGPU shader pipelines and avoid compilation overhead.
- Blending & Clipping: Implemented a blend mode stack, hierarchical geometry clipping masks, and opacity masks in
Compositor.cs. - Offscreen Texture Caching: Integrated offscreen texture caching to optimize rendering performance for nested visual layers and prevent redundant drawing of unchanged sub-trees.
- Winding Correction: Fixed boundary crossing mathematical logic within the
Hatchshader to align with the precise winding rules.
- Outline Caching: Added outline and Y-axis flipped outline caches (
_glyphOutlineCacheand_flippedOutlineCache) inTtfFont.csto avoid parsing glyph geometries from TTF byte arrays multiple times. - Glyph Flipping: Implemented
GetFlippedGlyphOutlineto flip coordinates along the Y-axis, conforming with WebGPU screen space coordinate projection. - SVG Arc Support: Implemented SVG elliptical arc (
'A'/'a') path segment parsing inPathGeometry.csand compilation inPathAtlas.cs.
- Corner Radius: Added
CornerRadiussupport toProGpuHostControlwith rounded-rectangle clip path pushes in the AvaloniaRenderoverride. - Context Reuse: Updated
ProGpuHostControlto share the activeWgpuContextinstance. - Type Safety: Refactored the UI composition communication to use a strongly-typed
RenderStatestruct instead of a genericTuple.
- Drop-in Parity: Created a swappable baseline SkiaSharp API dependency mapping matching Avalonia's minimal rendering requirements (canvases, surfaces, typefaces, paints, paths, and text blobs).
- ReadPixels Support: Implemented native texture pixel readback (
ReadPixelsinGpuTexture.cs) utilizing asynchronous mapping to pull unpadded frame pixels back to the CPU cleanly.
- Graphics & Vectors: Implemented a swappable class library for GDI+ (
System.Drawing.Common) mappingDrawLine,DrawRectangle,FillRectangle,DrawEllipse,FillEllipse,DrawPolygon,DrawPath,DrawString,MeasureString, andDrawImagedirectly onto the GPU command queue. - Offscreen Bitmaps: Backed
BitmapandImageentirely by WebGPU texture targets. Drawing is accumulated on the GPU and read back only when requested. - Diagnostics Preview: Created a visual page (
GdiShowcasePage.cs) to showcase GDI drawings and operations in the gallery app.
- WPF Parity: Added a swappable class library (
PresentationCore) under the standard WPF namespaces (System.Windows,System.Windows.Media,System.Windows.Media.Imaging). - Media Primitives: Maps standard primitives (
DrawLine,DrawRectangle,DrawRoundedRectangle,DrawEllipse,DrawGeometry,DrawImage,DrawText,DrawGlyphRun) directly onto the GPU recorded command streams. - State Stack: Manages a local transform matrix, opacity, and clipping geometry stack, resolving struct mutation writebacks for commands.
- Showcase Preview: Created an interactive page (
WpfShowcasePage.cs) showing grid lines, StreamGeometry stars, transforms, opacities, and formatted text blocks.
- GPGPU Solver: Implemented 100% GPU-bound analytical path boolean solvers (Union, Intersect, Difference, XOR, Reverse Difference) without CPU curve flattening or triangulation.
- Anti-Artifacting & Precision Fixes: Resolved chord intersections near endpoints using boundary perturbation, relaxed endpoint containment intervals, and dynamic 16-step subdivision for curved chords.
- Image Filters: Built a custom compositor pipeline to execute GPU-bound effects (e.g. Blur, Grayscale, Invert, Sepia, Brightness, Contrast) via customized shaders.
- Demo Gallery: Added an interactive UI page enabling users to tweak filter properties live and see the rendering performance.
- Retina Snapping: Implemented physical pixel boundary snapping for glyph positions, eliminating font-rendering blurriness and improving readability at standard/retina DPI levels.
- WebGPU WGSL Engine: Created a custom compositor drawing extension
ShaderToyExtensionPipeline(registered underIDrawingExtension.ShaderToy = 11) to execute custom fragment shaders backed by WebGPU. - ShaderToy Compatibility: Created
ShaderToyControlsimulating the standard ShaderToy environment, supporting standard input uniforms (resolutioniResolution, timeiTime, framesiFrame, and mouse positioniMouse). - Interactive Editor UI: Built
ShaderToyPlaygroundPageconsisting of a live WebGPU canvas, Preset dropdown loaded with rich graphics presets (Cosmic Waves, Star Nest, Raymarched Torus SDF), real-time Timeline control, monospaced text editor, and a live compiler log diagnostics console. - Panic Protection: Subscribed to static
WgpuContext.OnWebGpuErrorevents to catch shader compilation errors safely and skip pipeline creation when errors occur, preventing underlying WebGPU/Rust panics from aborting the host process. - Headless Testing: Implemented headless unit tests to verify the ShaderToy Playground page and compilation pipeline under testing environments.
cb10f7cbackend: Implement deferred native resource disposal queue and finalizer safety81160dcbackend: Implement precise direction-aware winding intersection rules and pipeline cache optimizationsf52bd12scene: Add render commands for clipping, opacity masking, blend modes, and fix boundary crossings in Hatch shader0e5f6b6compositor: Implement blend mode stack, geometry clipping masks, opacity masks, and offscreen texture caching3b860eatext: Implement glyph outline caching and coordinate flipping along Y-axiscb67354vector: Implement SVG elliptical arc path segment parsing and GPU compiler support3c424e2cleanup: Remove redundant finalizers from compute accelerator and glyph atlas7d13f40ui: Refactor ProGpuHostControl and fix WinUI Control template override64f724ashim: Implement SkiaSharp compatibility API and drawing context integration3bff12cvector: Implement GPU-accelerated analytical Path Boolean operationsa51c0e0backend: Fix Path Ops rendering artifacts via boundary perturbation, endpoint relaxation, and dynamic chord stepse84bea6Improve text rendering performance and quality via instanced snapping and subpixel positioning8cd692aImplement high performance GPU-accelerated Image Effects Engine and demo pagefd7df1cImplement System.Drawing.Common (GDI+) shim library using ProGPU drawing context backend90bac10samples: Add GDI Shim Showcase Pagea6f1c8esamples: Add Glyph Run Showcase Page4ae7378backend: Fix shaders DPI scaling for text snapping and glyph rendering3f575b6shim: Implement PresentationCore WPF DrawingContext compatibility shimda76db2samples: Add WPF DrawingContext Shim Showcase Page and register in MainWindow626bad1tests: Add headless unit test verifying WPF Showcase Page rendering3c53832docs: Update PR Summary with GDI+ and WPF DrawingContext shim details94cb793Implement ShaderToyControl WinUI control for real-time WebGPU shader executioncc7861bAdd Text property to RichEditBox for raw string getting and settingd7cc550Implement ShaderToyPlaygroundPage gallery page with editor, preset selection, and error consoleb0b0374Integrate ShaderToy Playground page inside navigation drawera259b2eRelocate ShaderToyControl to ProGPU.Samples to resolve project circular dependencies66577abFix StackPanel ambiguity, ComboBox SelectedIndex, and Border properties in ShaderToyPlaygroundPage.csabd4e7fAdd headless test verifying ShaderToy Playground page rendering1f44bcfExpose WebGPU compiler/validation error event and deferred render pipeline disposal helpersb499186Implement and register ShaderToyExtensionPipeline compositor backend for fragment shader rendering441a735Remove IsTabStop from ShaderToyControl to fix FrameworkElement compilation5cd061cFix StackOverflowException by removing redundant animation propagation loop in ShaderToyPlaygroundPage5534c20Protect pipeline creation from compilation failures to prevent wgpu abort panics, and fix Preset 1 swizzling style