Commit graph

96 commits

Author SHA1 Message Date
Mira Grudzinska
d240044aae wg_engine: fix stroke trimming
Fix cases when begin < 0 - this require handling the stroke
in two parts: begin - 0 and 0 - end.
Improve trimming for simultaneous=true.
2024-09-30 16:44:22 +09:00
Mira Grudzinska
b3b619349d wg_engine: fix stroke trimming
Prevent crash for begin == end;
2024-09-30 16:44:22 +09:00
Sergii Liebodkin
47d3d7e7d5 wg_engine: geometry generating optimization
Streaming model for massive vertex and index creations: minimize memory allocations, range checks and other conditions
Reduce number of segments length calculations (sqrt) and bbox (min and max).
Update distances and bboxes on a whole buffer and only if necessary. For shapes without strokes compute distances not necessary at all. bbox can be updated only on the final stage of geometry workflow, but not on the each stage.
Using stack memory instead of heap. its more cache friendly and did not fragment memory, faster memory allocations (weak place of realization)
Using cache for points distances and whole path length. Updates only if necessary
Validation of geometry consistency executes only on the final stage of path life cicle. It more friendly for data streaming: no any conditions and branches.
Using binary search for strokes trimming
Pre-cached circles geometry for caps and joints
Refactored strokes elements generation functions. Code is more readable and modifiable in general. Can be easily fixed if some geometry issues will be finded
2024-09-30 16:44:22 +09:00
Hermet Park
319b3843a5 common: code refactoring
Properly renamed internal interfaces.
No logical changes.

- Compositor -> RenderCompositor
- Surface -> RenderSurface
2024-09-30 16:44:22 +09:00
Sergii Liebodkin
1daf6a010c wg_engine: fix strokes triangulation artifacts
Fixed detection of close vertices using comparison with epsilon and related artifacts in stencil buffer as extra pixels.
Fixed incorrect tessellation of curves using scaling.
2024-09-30 16:44:22 +09:00
Mira Grudzinska
8acb135cb0 wg_engine: fix vertices while line joining
Vertex ordering during line join needed adjustment.
Vertices were forming two partialy overlapping triangles
instead of a rectangle. The issue was rarely visible since
the resulting rectangle often overlapped significantly
with other rectangles.
2024-09-30 16:44:22 +09:00
Sergii Liebodkin
02ebfc1332 wg_engine: wrong gradient transformation fixed
issue: https://github.com/thorvg/thorvg/issues/2620
2024-09-30 16:44:22 +09:00
Jinny You
d42919ac1d wg_engine: Enable premultiplied canvas on browser
Emscripten 3.1.66 includes support for WebGPU's premultiplied canvas.

Surface configurations have been updated with premultiplied alpha mode to support this feature.

see: c82a307c61
2024-09-30 16:44:22 +09:00
Hermet Park
371139e220 renderer: blending refactoring++
- reordered the blending types to align with lottie spec.
- removed source over.
2024-09-30 16:44:22 +09:00
Hermet Park
403710ffbc sw_engine: cleaned up the blending operations.
Corrected the alpha interpolation order during blending.
This also corrected the hard mix blending result in the guitar sample.

issue: https://github.com/thorvg/thorvg/issues/2704
2024-09-30 16:44:22 +09:00
Sergii Liebodkin
785a75a1ca wg_engine: external device handles (web integration)
move instance, adapter and device creation from renderer to application
its necessary for web integration, because browser have its own mechanics to create hardware handles
this changes makes webgpu canvas more universal to use in case of system and web applications

issue: https://github.com/thorvg/thorvg/issues/2410
2024-09-30 16:44:22 +09:00
Hermet Park
44ca306841 sw_engine: fixed incorrect image blending operations
The anti-aliased outline color was incorrectly blended
at the multiply option.

The fix can be observed in the example:
'examples/lottie/resourcesguitar.json'

in order to do this, RenderMehthod::blend() method introduced
`bool direct` for figuring out the intermediate composition.
2024-09-30 16:44:22 +09:00
Sergii Liebodkin
adbb6be504 wg_engine: scene blending optimization
- used hardware blending stage for scene blending
- used AABB for scene blending
- reduced number of offfscreen buffers coping
- reduced number of render pass switching
- used render pipelines abilities to convert offscreen pixel format to screen pixel format
- removed unused shaders
2024-09-30 16:44:22 +09:00
Jinny You
dca095b3c1 wasm/infra: Add build scripts for WebGPU
New build script for WASM with WebGPU.

Run `wasm_webgpu_build.sh` to have WebGPU WASM binary
2024-09-30 16:44:21 +09:00
Sergii Liebodkin
356cae5e8a wg_engine: aabb based masking optimization
* used fragment shaders for mask applience instead of compute shaders
* less render targets swithing
* shape aabb based on transformed shape bbox
2024-09-30 16:44:21 +09:00
Hermet Park
0f17f6c69a common: spec out TexMap
Spec out this incomplete experimental feature,
this is a still promising one, we will reintroduce
this officially after 1.0 release

size: -2kb

issue: https://github.com/thorvg/thorvg/issues/1372
2024-09-30 16:44:21 +09:00
Sergii Liebodkin
9efab30b00 webgpu: shaders refactoring
Deep shader refactoring for the following purposes:
* used pre-calculated gradient texture instead of per-pixel gradient map computation
* used HW wrap samples for fill spread setting
* unified gradient shader types
* used single shader module for composition instead of signle module per composition type
* used single shader module for blending for each of fill type (solid, gradient, image) instaed of signle module per blend type
* much easier add new composition and blend equations
* get rided std::string uasge
* shaders code is more readable
2024-09-30 16:44:21 +09:00
Hermet Park
a25366b283 common: spec out Scene Clipper
Scene Clipper is an unusual feature
that is too unstable and ambiguous in ThorVG.

Users can achieve the same functionality
with multiple composed shapes instead of scene clipping.

size: -2.5kb

issues:
- https://github.com/thorvg/thorvg/issues/1548
- https://github.com/thorvg/thorvg/issues/1549
- https://github.com/thorvg/thorvg/issues/1573
2024-09-30 16:44:21 +09:00
Sergii Liebodkin
55d248a31d webgpu: light/dark mask mode support
[issues 2608: light/dark mask](#2608)

* CompositeMethod::LightMask
* CompositeMethod::DarkMask
2024-09-30 15:52:50 +09:00
Sergii Liebodkin
f281cc9e92 wg_engine: composition and blend optimization
* bind groups creation in real time removed - performance boost
* blend and composition shaders decomposed - performance boost
* shader modules and pipeline layouts generalized - less memory usage
* shared single stencil buffer used - less memory usage
* bind groups usage simplified
* general context API simplified and generalized
* all rendering logic moved into new composition class
* ready for hardware MSAA (in next steps)
* ready for direct mask applience (in next steps)
2024-09-30 15:52:44 +09:00
Sergii Liebodkin
cff78dc067 wg_engine: emscripten and browser support
[issues 2410: emscripten support](https://github.com/thorvg/thorvg/issues/2410)
- Research and prototype the Emscripten build with WebGPU.

meson setup script:
   meson setup builddir -Ddefault_library=static -Dloaders=all -Dsavers="all" -Dbindings="wasm_beta" -Dengines="wg_beta" --cross-file ./cross/wasm_webgpu.txt
2024-09-30 15:48:18 +09:00
Sergii Liebodkin
0004887225 wg_engine: introduce simultaneous flag support for strokes trimming
https://github.com/thorvg/thorvg/issues/2435
2024-09-30 15:48:18 +09:00
Hermet Park
ecabdc5ebc renderer: code refactoring
Replaced the transformation with
a strong associated data field.

This helps to reduce the binary size (-1k).
2024-09-30 15:39:52 +09:00
Hermet Park
157e873e83 common: code refactoring
Trimming the transform data pass,
from RenderTransform to Matrix.

No logical changes.
2024-09-30 15:39:46 +09:00
Sergii Liebodkin
e16dcdcb6d wg_engine: fix cubic generation artifacts (GradientStroke example)
[GradientStroke](https://github.com/thorvg/thorvg/issues/2435) example

More accurate coefitient computation
2024-09-30 15:35:28 +09:00
Sergii Liebodkin
8d150a17b4 wg_engine: fix fill spread artifacts
[issues 2435: ](FillSpread) example

Fixed range selector edged cases
2024-09-30 15:35:22 +09:00
Sergii Liebodkin
03b36cea7b wg_engine: ClipPath support
[issues 1479: ClipPath](#1479)

Supports ClipPath composition.
Clip path composition is an only composition type who doesn't ignore blend method.
Clip path is a combination of composition approach and blend approach using compute shader
2024-09-30 15:35:10 +09:00
Sergii Liebodkin
f7728a8b7a wg_engine: Viewport support
[issues 1479: Viewport](#1479)

Supports viewport settings and rectangular clip path.
Scissors cliping used as a way to clip viewport
2024-09-30 15:29:22 +09:00
Hermet Park
c9d1df3957 common/math: code refactoring
Replaced the prefix "math" with "tvg" namespace.
2024-09-30 15:22:38 +09:00
Sergii Liebodkin
aae722e7ba wg_engine: fix masking methods support
See Masking, InvMasking, LumaMasking, InvLumaMasking, MaskingMethods examples

sw/webgpu
2024-09-30 15:21:20 +09:00
Hermet Park
b00c55169e wg_engine: code refactoring
- apply thorvg compact coding style.
- separate private / public methods designated in sectors.
2024-09-30 12:56:51 +09:00
Sergii Liebodkin
a49a15af75 wg_engine: fix dispose render data in MT environment
Store desposed object in MT-safe list and then despose objects in sync stage
2024-09-30 12:56:45 +09:00
Hermet Park
4345d6b8a5 API: revise the APIs.
deprecate the `identifier()` APIs by replacing them with `type()`.

ThorVG is going to introduce an instance `id()`,
and this could be confused with the `identifier()` methods.

with this new type() method can reduce the memory size
by removing unncessary type data.

New Experimental C APIs:
- enum Tvg_Type
- Tvg_Result tvg_paint_get_type(const Tvg_Paint* paint, Tvg_Type* type)
- Tvg_Result tvg_gradient_get_type(const Tvg_Gradient* grad, Tvg_Type* type)

New Experimental C++ APIs:
- Type Paint::type() const
- Type Fill::type() const
- Type LinearGradient::type() const
- Type RadialGradient::type() const
- Type Shape::type() const
- Type Scene::type() const
- Type Picture::type() const
- Type Text::type() const

Deprecated C APIs:
- enum Tvg_Identifier
- Tvg_Result tvg_paint_get_identifier(const Tvg_Paint* paint, Tvg_Identifier* identifier)
- Tvg_Result tvg_gradient_get_identifier(const Tvg_Gradient* grad, Tvg_Identifier* identifier)

Deprecated C++ APIs:
- enum class Type
- uint32_t Paint::identifier() const
- uint32_t Fill::identifier() const
- static uint32_t Picture::identifier()
- static uint32_t Scene::identifier()
- static uint32_t Shape::identifier()
- static uint32_t LinearGradient:identifier()
- static uint32_T RadialGradient::identfier()

Removed Experimental APIs:
- static uint32_t Text::identifier()

issue: https://github.com/thorvg/thorvg/issues/1372
2024-09-30 12:55:16 +09:00
Sergii Liebodkin
e27ce23d4b wg_engine: fix blend methods support
Full review of blending support.
Support Solid color, Gradient fill and Image blending workflows

See Blending, SceneBlending, Opacity examples
2024-09-30 12:51:02 +09:00
Hermet Park
ce50165103 common: Fix a compilation failure on VS 2017
issue: https://github.com/thorvg/thorvg/issues/2512
2024-09-30 12:49:06 +09:00
Sergii Liebodkin
21286f679d wg_engine: fix scene opacity usage
Changed blend equation to make it the same as for referenced sw renderer.
2024-09-30 12:48:58 +09:00
Josh Soref
e3c66db301 common: fix 178+ spelling errors 2024-09-30 12:41:38 +09:00
Mira Grudzinska
66048b31b5 wg_engine: fix shapes closing
Shapes were incorrectly closed in certain cases -
the decision to close a shape or not should be based on
path commands rather than the number of points and
their distances from each other.
2024-06-27 14:42:27 +09:00
Sergii Liebodkin
119ca34219 wg_engine: force texture data writing on GPU side
Texture must be fully uploaded into GPU memory before we can use or destroy it.
This change force texture data updates
2024-06-27 14:42:27 +09:00
Sergii Liebodkin
58705281cd wg_engine: fix stroke mitter limit
Change the appliense of stroke mitter limit as in SVG spec

Before/After
2024-06-27 14:42:27 +09:00
Sergii Liebodkin
f40586bd3d wg_engine: fix incorrect geomatry
Fix computation of segments count for cubic curves.
Using screen coordinates of base points, instead of world coordinates
2024-06-27 14:42:27 +09:00
Sergii Liebodkin
9c9999169e wg_engine: fix scene rendering with blend
Fix allplience of the blend method, that setuped for scene, but not for a shape
Overlay blend func changed to be close to spec
2024-06-24 14:56:14 +09:00
Sergii Liebodkin
2725ccfcd7 wg_engine: skip shapes with zero opacity values
Skip shapes rendering, if opacity is 0 and if fill color for shape and strokes also equal to 0
This behavior is used in sw renderer and fix visual artifacts in referenced animations.
Also this rule fix composition results in case of AlphaMask and InvAlphaMask methods
2024-06-24 14:54:56 +09:00
Hermet Park
7008d26d05 wg_engine: --redundant code 2024-06-24 14:54:49 +09:00
Sergii Liebodkin
596845d1cf wg_engine: fix composition math
Fix AlphaMask, InvAlphaMask, LumaMask and InvLumaMask math
Fix double apllience of opacity value
2024-06-24 14:52:21 +09:00
Sergii Liebodkin
7bbd058bd7 wg_engine: fix fill rule usage
Fix wronk application of fill rule in a cases of terminated path (.close()/.moveTo())
2024-06-24 14:52:15 +09:00
Sergii Liebodkin
5cf7c756db wg_engine: fix strokes failers and visual atrifacts
Ignoring rezo-width strokes, single point strokes.
Fix visual artifacts in case of mitter joints.
2024-06-24 14:52:09 +09:00
Hermet Park
1d9adab607 infra: ++wg_native package dependency
Windows might need a own library linking method.
2024-06-24 14:50:55 +09:00
Sergii Liebodkin
9b4df3f0af wg_engine: fix model view matrix
In a case of compostions model view matrix did not apply samples count
2024-06-24 14:50:49 +09:00
Sergii Liebodkin
23d50fcda5 wg_engine: clear bbox mesh lists
when cleaning the geometry of an object, it is also necessary to clean the bounding boxes and store them in the pool
2024-06-24 14:50:42 +09:00