Commit graph

79 commits

Author SHA1 Message Date
Hermet Park
d6c80f538c renderer: add a new scene effect type - Fill
Fill is used for overriding the scene content color
with a given fill information. It's yet an Experimental API.

issue: https://github.com/thorvg/thorvg/issues/2718
2024-12-12 18:50:33 +09:00
Sergii Liebodkin
482bd50157 wg_engine: Improve resizing mechanics
In case of resizing recreate only render targets, but not all compositor handles
2024-12-11 12:08:47 +09:00
Hermet Park
6761c5c2a0 API: Replace the Canvas::clear() API with Canvas::remove() & draw()
Added a `clear` parameter to Canvas::draw(), allowing users to decide
whether to clear the target buffer before drawing.

To remove the paints from a canvas, please use Canvas::remove()

C++ API Removals:
- Result Canvas::clear(bool paints, bool buffer)

C++ API Modifications:
- Result Canvas::draw()
 -> Result Canvas::draw(bool clear)

C API Removals:
- Tvg_Result tvg_canvas_clear(bool paints, bool buffer)

C API Modifications:
- Tvg_Result tvg_canvas_draw(Tvg_Canvas* canvas)
 -> Tvg_Result tvg_canvas_draw(Tvg_Canvas* canvas, bool clear)

issue: https://github.com/thorvg/thorvg/issues/1372
2024-12-10 11:59:46 +09:00
Hermet Park
445000ba66 common: improve the rendering pipeline
enhanced the rendering composition target to better support features such as
alpha blending, blending, masking, post effects, and more.
This allows rasterizers to prepare the composition context with more precise control.

Additionally, resolved a crash in the software engine's post-effect process
caused by a buffer size mismatch during XY buffer flipping.

issue: https://github.com/thorvg/thorvg/issues/3009
issue: https://github.com/thorvg/thorvg/issues/2984
2024-12-04 22:31:37 +09:00
Sergii Liebodkin
07fbe56162 wg_engine: fixed scene blending equation and clear color rule
Issue: https://github.com/thorvg/thorvg/issues/2998
2024-12-04 11:39:57 +09:00
Sergii Liebodkin
13b976ee80 wg_engine: support resizing
Added abillity to resize target (surface)
In case of resizing only render targets handles recreated
Issue: https://github.com/thorvg/thorvg/issues/2985
2024-11-29 18:48:01 +09:00
Sergii Liebodkin
cf05128a96 wg_engine: revision of device creation policy
make valid device and instance as mandatory paramter for webgpu renderer
2024-11-29 18:48:01 +09:00
Sergii Liebodkin
77201546dd wg_engine: separate pipelines ans bind group layouts (refactoring)
The main reason of refactoring is to separate bind group sets and pipelines, and change owning of pipelines to compositor
2024-11-27 11:31:35 +02:00
Sergii Liebodkin
6c452c1fd3 wg_engine: fix resources disposing on context destroy
We must to dispose all paints render handles before the context will be destroyed to prevent handles leak
2024-11-26 11:34:42 +09:00
Hermet Park
877c524e5e renderer/sw_engine: fix omitted alpha multiplication in the dropshadow effect
When a scene has a valid opacity, it must be multiplied with the
direct dropshadow image to ensure correct rendering.
2024-11-23 01:03:39 +09:00
Sergii Liebodkin
3805f26aff wg_engine: multicanvas support
Added multicanas support
Issue https://github.com/thorvg/thorvg/issues/2745
2024-11-22 12:34:26 +09:00
Hermet Park
d3d085de15 renderer: code refactoring
- introduced RenderColor
- internal name changes to avoid conflicts
2024-11-20 22:13:27 +09:00
Sergii Liebodkin
52356b023d wg_engine: fix scene blending
In a case of scenes without masking white clear color used, instead of black color

Issue https://github.com/thorvg/thorvg/issues/2592
Issue https://github.com/thorvg/thorvg/issues/2921
2024-11-06 01:11:15 +09:00
Hermet Park
e0365142a7 renderer: support SceneEffect DropShadow
Apply a drop shadow effect with a Gaussian Blur filter.

API Addition:
 - enum class SceneEffect::DropShadow

Parameters:
 - color_R(int)[0 - 255]
 - color_G(int)[0 - 255]
 - color_B(int)[0 - 255]
 - opacity(int)[0 - 255]
 - angle(float)[0 - 360]
 - distance(float)
 - blur_sigma(float)[> 0]
 - quality(int)[0 - 100]

issue: https://github.com/thorvg/thorvg/issues/2718
2024-11-06 00:56:11 +09:00
Sergii Liebodkin
81cb7da9f3 wg_engine: MSAA support, part 1 - move blending to fragment shaders
Apply custom blending using fragment shaders instead of compute shaders.
2024-10-17 18:00:15 +09:00
Hermet Park
0a16152d75 api: renamed the composite with mask.
Since we've separated ClipPath and Masking,
Masking now has a distinct and independent purpose.

API Modification:
 - enum class CompositeMethod -> enum class MaskMethod
 - Result Paint::composite(std::unique_ptr<Paint> target, CompositeMethod method) -> Result Paint::mask(std::unique_ptr<Paint> target, MaskMethod method)
 - CompositeMethod Paint::mask(const Paint** target) const -> MaskMethod Paint::mask(const Paint** target) const

issue: https://github.com/thorvg/thorvg/issues/1372
2024-10-16 14:41:26 +09:00
Sergii Liebodkin
40cff2d6f5 wg_engine: fix long path support
created a singe shared instance of stoke generator in heap, instead of stack. No performace impact
2024-10-16 00:52:07 +09:00
Hermet Park
9bc900206b api: polish the thorvg API usages.
API Modification:
- SwCanvas::Colorspace -> ColorSpace

API Addition:
- ColorSpace::Unknown

issue: https://github.com/thorvg/thorvg/issues/1372
2024-10-12 15:38:03 +09:00
Hermet Park
a72ed0ddfa wg_engine: fixed resource leaks
issue: https://github.com/thorvg/thorvg/issues/2808
2024-10-04 14:20:51 +09:00
Sergii Liebodkin
3afb7be255 wg_engine: fix picture memory leak
picture mesh data was not released
2024-10-04 03:40:57 +09:00
Hermet Park
2558e5dc10 renderer: introduced SceneEffect feature
Scene effects are typically applied to modify
the final appearance of a rendered scene,
such as adding a blur effect.

Each effect would have a different number of parameters
to control its visual properties. The Scene::push() interface
 uses variadic arguments to accommodate various cases.

Users should refer to the SceneEffect API documentation
and pass the parameters exactly as required for the specific
effect type. For instance, GaussianBlur expects 3 parameters
which are:

- sigma(float)[greater than 0]
- direction(int)[both: 0 / horizontal: 1 / vertical: 2]
- border(int)[extend: 0 / wrap: 1]
- quality(int)[0 ~ 100]

and, scene->push(SceneEffect::GaussianBlur, 5.0f, 0, 0, 100);

New Experimental APIs:
- SceneEffect::ClearAll
- SceneEffect::GaussianBlur
- Result Scene::push(SceneEffect effect, ...);

Example:
- examples/SceneEffect

issue: https://github.com/thorvg/thorvg/issues/374
2024-09-29 15:04:22 +09:00
Sergii Liebodkin
ee6a7214d4 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-25 17:09:29 +09:00
Hermet Park
0e2d1dfcfa common: code refactoring
Properly renamed internal interfaces.
No logical changes.

- Compositor -> RenderCompositor
- Surface -> RenderSurface
2024-09-21 16:37:37 +09:00
Jinny You
fbe6d59c04 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-12 22:01:26 +09:00
Hermet Park
2a33096582 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-06 21:18:21 +09:00
Sergii Liebodkin
e2e4fc6964
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-06 13:08:58 +09:00
Hermet Park
38697022f0 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-08-30 00:53:44 +09:00
Sergii Liebodkin
732a2be7e8 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-08-28 18:33:07 +09:00
Sergii Liebodkin
0787e46635 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-08-20 16:23:31 +09:00
Hermet Park
5332876fe8 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-08-20 11:14:54 +09:00
Sergii Liebodkin
88b4f75e4f 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-08-13 11:52:45 +03:00
Hermet Park
407fc84796 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-08-13 10:21:54 +09:00
Sergii Liebodkin
a4bbf14371 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-08-09 14:30:17 +09:00
Sergii Liebodkin
6cd745dd2e 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-08-01 14:20:08 +09:00
Hermet Park
036ae3c2af renderer: code refactoring
Replaced the transformation with
a strong associated data field.

This helps to reduce the binary size (-1k).
2024-07-29 23:27:19 +09:00
Hermet Park
c4d89d0983 common: code refactoring
Trimming the transform data pass,
from RenderTransform to Matrix.

No logical changes.
2024-07-29 12:16:58 +09:00
Sergii Liebodkin
2c948a33d3 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-07-16 00:01:47 +09:00
Sergii Liebodkin
3223f17f9c 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-07-11 21:24:18 +09:00
Hermet Park
8be44e66d2 wg_engine: code refactoring
- apply thorvg compact coding style.
- separate private / public methods designated in sectors.
2024-07-06 11:37:57 +09:00
Sergii Liebodkin
1932107097 wg_engine: fix dispose render data in MT environment
Store desposed object in MT-safe list and then despose objects in sync stage
2024-07-06 11:22:30 +09:00
Hermet Park
889d1d1fa2 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-07-05 21:25:58 +09:00
Sergii Liebodkin
e7e6839571
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-07-04 16:19:50 +09:00
Sergii Liebodkin
1afe834021
wg_engine: fix scene opacity usage
Changed blend equation to make it the same as for referenced sw renderer.
2024-07-03 13:47:08 +09:00
Sergii Liebodkin
53de5f2ff7 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-20 19:03:42 +09:00
Sergii Liebodkin
03c6f43441 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-19 01:46:59 +09:00
Sergii Liebodkin
f97c16f94c 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-18 01:10:52 +09:00
Hermet Park
846ae09151 wg_engine: --redundant code 2024-06-17 15:59:53 +09:00
Sergii Liebodkin
a7f4d718f4 wg_engine: fix model view matrix
In a case of compostions model view matrix did not apply samples count
2024-06-13 10:46:36 +09:00
Sergii Liebodkin
9f08e4755c 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-13 10:46:36 +09:00
Sergii Liebodkin
7e493f91f2
wg_engine: cross-platform support
it provide changes public API for webgpu canvas interface to provide nessessary handles to native window for different platforms:

API Change:
- Result target(void *instance, void *surface, uint32_t w, uint32_t h) noexcept;
2024-06-12 12:39:37 +09:00