Commit Graph

877 Commits

Author SHA1 Message Date
renovate[bot] 3057aa59dd chore(deps): lock file maintenance rust dependencies 2023-06-25 21:53:00 -04:00
renovate[bot] f62dd17284 fix(deps): update rust crate indexmap to v2 2023-06-25 20:27:33 -04:00
Lord-McSweeney 8c40e97ab5 wgpu: nit: Fix incorrect label in blur filter 2023-06-26 00:00:03 +02:00
Nathan Adams fd4eaef2b6 wgpu: Don't create cacheAsBitmap for textures that are too large 2023-06-25 22:58:22 +02:00
Nathan Adams 628d8f66ad render: Add filters to BitmapCacheEntry 2023-06-25 21:58:46 +02:00
Nathan Adams 44c870ba91 wgpu: Move run_copy_pipeline to utils 2023-06-25 21:58:46 +02:00
Nathan Adams 4dde126e64 wgpu: Take in a &wgpu::Texture not our own texture as we don't need omore than that 2023-06-25 21:58:46 +02:00
Nathan Adams 0c71b83e36 wgpu: Don't perform copy inside Surface::apply_filter 2023-06-25 21:58:46 +02:00
Lord-McSweeney 08dfbc96be wgpu: Slight changes to blur filter 2023-06-24 16:55:40 +02:00
Nathan Adams f43560ab88 render: Switch to providing cacheAsBitmap entries all at once on submit frame 2023-06-24 01:42:04 +02:00
Nathan Adams 36aee1efcf wgpu: Specialise render_offscreen_for_cache to render directly to the texture 2023-06-24 01:42:04 +02:00
Nathan Adams 2594453831 render: Add render_offscreen_for_cache for more optimised CacheAsBitmap 2023-06-24 01:42:04 +02:00
Nathan Adams fe742194b1 core: Implement cacheAsBitmap behaviour 2023-06-24 01:42:04 +02:00
Nathan Adams 97c36b442a wgpu: Switch Multiply back to a complex shader, with dst.a==0 fix 2023-06-22 14:23:15 +02:00
TÖRÖK Attila 7bbaeb2a61 chore: Bump ouroboros to 0.17.0. 2023-06-17 18:49:05 -05:00
Nathan Adams 2427daf05c webgl: Don't hold onto an old copy of bitmap data for each image 2023-06-18 00:47:51 +02:00
Nathan Adams e9af73126f canvas: Refactor how BitmapData is made, to allow for empty bitmaps to be made later 2023-06-18 00:47:51 +02:00
Nathan Adams c374aaa19a canvas: Don't hold onto an old copy of bitmap data for each image 2023-06-18 00:47:51 +02:00
renovate[bot] 7a21756ddb chore(deps): lock file maintenance rust dependencies 2023-06-17 11:00:52 -05:00
Aaron Hill 69fce3f7f8
wpgu: Initial implementation of PixelBender shader execution (#11441)
* wpgu: Initial implementation of PixelBender shader execution

The implementation is split across four crates:
* `ruffle_render` now holds the main PixelBender bytecode parsing
   implementation (previously, this was in `ruffle_core`).
* `ruffle_core` holds some helper functions for converting between
   AVM2 `Value`s and the PixelBender vector types.
* `naga-pixelbender` (newly created) constructs a Naga `Module`
  from parsed PixelBender bytecode
* `ruffle_render_wgpu` sets up the render pipeline for the shader
  constructed by `naga-pixelbender`, and actually executes the shader.

The Actionscript-side shader parameters are passed in through uniforms.
This allows us to cache the compiled `naga::Module` and associated
wgpu types inside `ShaderData`, when it's first created. Each invocation
of a `ShaderJob` only needs to create a bind group and render pass.

Limitations:

* Only a few of the PixelBender opcodes are implemented - however, this is
enough to get Stemlands cannon rotation working, as well as a cool
"donut" shader that I found and included as a test.
* PixelBender matrix types are not supported.
* Only BitmapData is supported as an input/output type - Flash Player
  also supports using Vector and ByteArray
* ShaderJob execution is always synchronous.

* Adjust comments

* Address review comments
2023-06-15 22:50:24 +00:00
renovate[bot] fc933f485f fix(deps): update wasm-bindgen 2023-06-15 20:50:04 +02:00
Aaron Hill cd2c7f6f2f tests: Enable tracing_subscriber in tests
Previously, we weren't displaying any Ruffle logs when running tests.
2023-06-14 17:15:31 -05:00
renovate[bot] 438e6f36ff chore(deps): lock file maintenance rust dependencies 2023-06-12 08:50:07 +03:00
renovate[bot] a621472336 chore(deps): lock file maintenance rust dependencies 2023-06-09 20:17:25 +03:00
Aaron Hill d44c9cceb1 wgpu: Cache compiled naga-agal shader module
We use an `lru::LruCache` inside `ShaderModuleAgal`. This automatically
gives us the proper garbage-collection behavior (when the Flash
Program3D instance is garbage collected, we'll drop the
`ShaderModuleAgal` and the cache).

The cache is keyed on the data needed to compile the shader (vertex
attributes and sampler overrides). This lets us avoid shader
recompilations when a Stage3D program repeatedly uses the same
Program3D with different sampler overrides / vertex attribute formats.
2023-06-08 02:57:47 -05:00
renovate[bot] f1fe998869 chore(deps): lock file maintenance rust dependencies 2023-06-04 22:53:18 -05:00
Nathan Adams eb70a4f361 core: Update gc_arena to 63dab12871321e0e5ada10ff1f1de8f4cf1764f9 2023-06-03 09:11:06 +02:00
Aaron Hill 2cd518013c
wgpu: Don't skip alpha/erase blend modes for BitmapData.draw (#11323)
We can skip these when we're drawing to a fresh buffer, but not when we're blending over an existing BitmapData texture.
2023-06-02 21:16:05 +00:00
Aaron Hill 999e2f5b71 wgpu: Implement Context3D.setScissorRectangle 2023-06-02 14:56:14 -05:00
relrelb abb0e33431 chore: Use Rust's `OnceCell`/`OnceLock`
They were stabilized in Rust 1.70.0, which was released yesterday.
This removes the `once_cell` dependency.
2023-06-02 22:21:38 +03:00
Aaron Hill 12e078bb2d wgpu: Fix calculation of image row padding 2023-05-28 23:35:53 -05:00
Aaron Hill 2ae15b05e8 core: Store Color as an u32 instead of a i32
This is a packed ARGB value, so it doesn't make sense for it to be
signed.
2023-05-28 16:52:09 -05:00
Nathan Adams b29a784968 wgpu: Remove render callback as it's no longer used 2023-05-24 23:50:48 +02:00
Nathan Adams b9322ba93a desktop: Render game separately to UI, blit both onto surface 2023-05-24 23:50:48 +02:00
Mike Welsh c00b4bf55c desktop: Initial GUI work 2023-05-24 23:50:48 +02:00
Aaron Hill da8d5bce3c naga-agal: Fix bugs and add tests for new ops 2023-05-24 13:34:15 -05:00
Mike Welsh 3257cc44cf naga-agal: Implement m33 and m34 ops 2023-05-24 13:34:15 -05:00
Mike Welsh 35ef04eadc naga-agal: Implement kil op 2023-05-24 13:34:15 -05:00
Mike Welsh f97bb9c2f1 naga-agal: Implement log, exp, pow, ddx, ddy, min, rsq, sge ops 2023-05-24 13:34:15 -05:00
Aaron Hill cc567c4e40 agal: Correctly check vertex_input_expressions cache
We need to use the same logic that we use for `get_varying_pointer`,
since the AGAL shader can access vertex inputs in any order.
2023-05-23 17:20:29 -05:00
renovate[bot] 5d2477fe98 chore(deps): lock file maintenance rust dependencies 2023-05-22 19:12:08 +03:00
Aaron Hill 5d48484d99 agal: Add support for indirect register loads
These are poorly documented, but from looking at OpenFL
and AGALMiniAssembler, they allow performing loads of the
form `vc[va0.x + offset]` - that is, computing a dynamic register
number, instead of using the register number present in the opcode.
2023-05-21 09:40:11 -05:00
Aaron Hill 5d62ef90f2 wgpu: Use intermediate buffer for Context3DCommand::CopyBitmapToTexture
In a previous PR, I introduced an optimization that used
`copy_texture_to_texture` to copy directly from a BitmapData GPU
texture to a Stage3D GPU texture.

Unfortunately, this optimization is incorrect. A BitmapData GPU
texture can be modified at any time by normal AVM2 code - in
particular, in might be modified before we submit the encoded
`copy_texture_to_texture` command. This shows up in Sniper Team,
which re-uses BitmapData objects for multiple distinct textures.
The previous 'optimization' resulted in the wrong BitmapData contents
getting uploaded to a texture (since it was changed before the copy
command was submitted).
2023-05-20 17:38:26 -05:00
Aaron Hill 0864853d44 avm2: Allow passing `null` to `Context3D.setProgram`
This clears the vertex and fragment shader programs
(bringing the Context3D back to its initial state).
2023-05-20 16:23:03 -05:00
Aaron Hill 7619594b1c agal: Implement Float1 to vec4f conversion 2023-05-18 16:12:22 -05:00
Aaron Hill 7004e98b23 avm2: Don't validate Context3DVertexBufferFormat when buffer is null
This matches Flash Player's behavior - some SWFS try to pass in 'null'
for both the buffer and format.
2023-05-18 15:14:29 -05:00
iwannabethedev 8cd5414c5d
Fix overflow bug in `shape_utils::winding_number_line()` 2023-05-17 07:21:13 +03:00
renovate[bot] f969bdce71 fix(deps): update wasm-bindgen 2023-05-17 06:44:50 +03:00
relrelb 1065662e84 web: Use `JsValue::from_bool()` 2023-05-15 21:04:47 +03:00
Aaron Hill bd2be88711 wgpu: Fix MSAA and depth buffer handling in SetRenderToTexture
When multisampling is enabled, we should create a new multisampled texture,
and use the existing texture as the resolve buffer. We also need to
call `update_has_depth_texture` to keep our pipeline aware of whether
or not we currently have a depth buffer attached.

Makes progress on #10641 (it has a stack overflow after
this PR, due to an unrelated issue).
2023-05-15 09:34:30 -05:00
renovate[bot] 5b26d1b2ee fix(deps): update wasm-bindgen 2023-05-15 10:00:49 +03:00
relrelb 4a26ceb14b render: Use `swf::Point<Twips>` in more places 2023-05-14 22:48:41 +03:00
relrelb 220f8cd1cf render: Use `swf::Point<Twips>` in `shape_hit_test()` 2023-05-14 22:48:41 +03:00
relrelb 25a1d53f72 render: Use `swf::Point<Twips>` in `calculate_shape_bounds()` 2023-05-14 22:48:41 +03:00
relrelb 598c8cde0e render: Use `swf::Point<Twips>` in `DrawCommand::CurveTo` 2023-05-14 22:48:41 +03:00
relrelb 544e445d2f render: Use `swf::Point<Twips>` in `DrawCommand::LineTo` 2023-05-14 22:48:41 +03:00
relrelb e5c7d70f3f render: Use `swf::Point<Twips>` in `DrawCommand::MoveTo` 2023-05-14 22:48:41 +03:00
iwannabethedev a023e11098 render: Clean-up. 2023-05-12 22:42:44 +02:00
iwannabethedev 77e1cc96c2 render: Fix of panic in #10955. 2023-05-12 22:42:44 +02:00
relrelb 660acac427 swf: Use `PointDelta<Twips>` in `ShapeRecord` 2023-05-11 08:55:44 +03:00
relrelb b93a32af0f swf: Use `Point<Twips>` in `StyleChangeData::move_to`
No functionality change.
2023-05-11 08:55:44 +03:00
Aaron Hill e488cc9f7a wgpu: Allow unaligned writes to IndexBuffer3D
wgpu requires buffer copy sizes and offsets to be 4-byte aligned.
Unfortunately, ActionScript can perform 2-byte aligned uploads
into an IndexBuffer3D.

To support this, we now keep a copy of the IndexBuffer3D on the CPU.
When performing an upload to the buffer, we round the offset down
and the size up to the nearest 4-byte aligned value. The cpu buffer
is used to fill out the write with existing data, so that we don't
corrupt the contents of the GPU buffer.

To avoid introducing a new RefCell, I've changed IndexBuffer3D
to use a `Box` instead of an `Rc` to store the trait object.
This allows us to pass a mutable reference down to the backend.
2023-05-10 18:20:29 -05:00
Nathan Adams 2b6829692c wgpu: Resize textures if they're bigger than the system supports 2023-05-05 19:03:15 +02:00
Aaron Hill 22c13d41da wgpu: Use Context3DCommand by value 2023-05-05 11:43:43 -05:00
Nathan Adams c5293bd981 core: Don't actually apply a filter if it's unsupported, just copy 2023-05-03 21:15:48 +02:00
Nathan Adams 50a0298d30 render: Fix calculations in PixelRegion::clamp_with_intersection (+ new test) 2023-05-03 21:15:48 +02:00
Nathan Adams adabb81804 core: Introduce PixelRegion::clamp_with_intersection and made most operations with two overlapping regions use it 2023-05-03 21:15:48 +02:00
iwannabethedev 49962edf3a render: Fix obsolete/wrong documentation. 2023-05-03 09:26:37 +03:00
relrelb 85a9ec77c5 render: Fix wgpu renderer name 2023-05-03 01:12:19 +03:00
iwannabethedev 307f364d6f
web: Log used renderer
Log which renderer-backend was actually used in the
browser console.
2023-05-02 23:59:57 +03:00
relrelb 24079518d9 tests: Expand `Matrix` unit tests to cover `PointDelta`s 2023-04-29 22:29:37 +03:00
relrelb ef79d556b4 tests: Allow trailing commas in `Matrix` unit tests 2023-04-29 22:29:37 +03:00
relrelb 3046d68da1 swf: Introduce `PointDelta`
Generally, when transforming a difference between two points, `p1`
and `p2`, with a matrix `m`, we would like the following property
to hold:

```
m * (p1 - p2) == m * p1 - m * p2
```

Unfortunately, it wasn't like this before, because matrices have a
translation component, which is non-linear. In `m * p1 - m * p2`,
the translations of `m * p1` and `m * p2` are the same and therefore
cancel out each other. However, in `m * (p1 - p2)` the translation
stays.

In order to preserve this property, introduce a new `PointDelta`
type which is not subject to translation when transformed by a matrix.

For now, the following operations are supported:

* `Point - Point -> PointDelta`
* `Point + PointDelta -> Point`
* `Point += PointDelta`
* `Point - PointDelta -> Point`
* `Point -= PointDelta`

As a consequence, the expression `position + global_to_local_matrix * mouse_delta`
in `update_drag()` now ignores translation, which fixes #817.
2023-04-29 22:29:37 +03:00
relrelb 60ffe07ae7 chore: Use `swf::Point` in many places
Convert nearly all instances of `(Twips, Twips)` (maybe besides in
`shape_utils.rs`) to `swf::Point<Twips>`.
2023-04-27 22:14:03 +03:00
Aaron Hill 3bb8c8fb4f wgpu: Update wgpu to 0.16.0 and naga to 0.12.0 2023-04-25 09:24:53 -05:00
Nathan Adams d9241c914e chore: Hold wgpu and naga back until naga_oil updates to naga 0.12 2023-04-24 01:22:07 +02:00
renovate[bot] 3b3c08a354 chore(deps): lock file maintenance rust dependencies 2023-04-24 01:22:07 +02:00
Nathan Adams 4f4327b152 wgpu: Fix drawing a transparent bitmap with MSAA 2023-04-18 23:15:42 +02:00
Aaron Hill 962cf92223 avm2: Implement Context3D.setSamplerStateAt
This fixes pixelated backgrounds in Fancy Pants World 4 Part 3
2023-04-05 16:44:07 -07:00
Mike Welsh 7a6e6cf214 naga-agal: Add fractal shader test 2023-04-05 12:22:13 -07:00
Mike Welsh b578849958 naga-agal: Allow boolean binary ops with multiple components 2023-04-05 12:22:13 -07:00
Mike Welsh e92e530321 naga-agal: Support `abs` op 2023-04-05 12:22:13 -07:00
Mike Welsh 792cfd82c7 avm2: Implement `Context3D.setColorMask` 2023-04-05 12:22:13 -07:00
Mike Welsh e07bde884e render: Inline `CommandList` methods 2023-04-04 13:10:45 -07:00
Mike Welsh 7779416894 render: Fix masker-in-masker rendering
Flash does not support nested mask regions and instead merges them
into a single clip region.

For example, this occurs when using a dynamic text field as a mask.
One mask layer contains the glyphs, while the second layer is the
bounds of the text field. The text field bounds end up being
ignored when the text field is used as a mask, allowing the text
outside the bounds to be visible.

Add `CommandList::maskers_in_progress` to keep track of the mask
state and discard drawing commands for inner maskers.

Fixes #9664.
2023-04-04 13:10:45 -07:00
Nathan Adams 06bc4e1403 wgpu: Fix sync issue introduced in #9753 and added test 2023-04-04 11:11:57 -07:00
TÖRÖK Attila 2ad43994b8 video: Don't do colorspace conversion in the video backend 2023-04-04 00:15:07 -07:00
TÖRÖK Attila 493971ab8a render: Make RenderBackend::update_texture() take a Bitmap (like register_bitmap()) 2023-04-04 00:15:07 -07:00
TÖRÖK Attila c9a2c636c9 render/webgl: Make use of Bitmap::to_rgb() to avoid making an alpha channel for Yuv420p bitmaps 2023-04-04 00:15:07 -07:00
TÖRÖK Attila ba43b0930f render: Add Bitmap::to_rgb() 2023-04-04 00:15:07 -07:00
TÖRÖK Attila 5f94476b2a render: Add BitmapFormat::Yuv420p and BitmapFormat::Yuva420p 2023-04-04 00:15:07 -07:00
TÖRÖK Attila 322e17a5ab render: Bitmap::bytes_per_pixel() -> Bitmap::length_for_size() 2023-04-04 00:15:07 -07:00
Mike Welsh 549a06d00f wgpu: Slight optimization to color shader
The color doesn't change per pixel, so calculate the color in the
vertex stage instead of the fragment stage.
2023-04-03 14:33:37 -07:00
renovate[bot] cd3ad90d61 chore(deps): lock file maintenance rust dependencies 2023-04-02 22:00:49 -07:00
Aaron Hill a2fa362091 wgpu: Implement double buffering for Context3D
This matches the Context3D docs. Calling 'present' swaps
the buffers.

I wasn't certain if we actually need a double-buffered depth
texture, but I included one just to be safe.
2023-04-02 19:24:23 -07:00
Aaron Hill 671ebdfa8f wgpu: Execute Context3D commands immediately
Now that most of the complicated Context3D methods have been
implemented, we can simplify the overall design. Instead of queueing
up commands and having `present` execute them in a loop, we
can execute each command immediately. The key insight is that
a `RenderPass` is only needed for `DrawTriangles`, so we don't
have to store it in `Context3D` and deal with complicated lifetime
issues.

The old behavior gave us implicit double-buffering behavior,
since nothing would get rendered until a 'present' call.
Now that a 'drawTriangles' call will immediately submit
a draw command, we need to implement actual double buffering.
This is done in the next commit.
2023-04-02 19:24:23 -07:00
Aaron Hill 7809000170 wgpu: Fix filter texture copy size calculation
I incorrectly changed this in #10373

Fixes #10380
2023-04-01 11:04:55 -05:00
Mike Welsh b62040884c core: Make `DisplayObject::global_to_local` fallible
* `global_to_local` returns `None` if the object has zero scale.
 * Adjust AVM `globalToLocal` methods to return the untransformed
   point on failure.
 * Add `DisplayObject::mouse_to_local` to handle AVM `mouseX`
   and `mouseY` coordinates. For zero scale objects, these end up
   returning values based on the twips-to-pixels scale,
   divided by 20.
2023-03-31 16:26:11 -07:00
Mike Welsh 54b7094c16 render: Make `Matrix::inverse` fallible
* Add `Matrix::determinant`.
 * Rename `Matrix::invert` to `inverse`.
 * `Matrix::inverse` return an `Option`, with `None` returned
    for non-invertible matrices.
 * AMV `Matrix::invert` duplicates the code as the behavior is
   different (works in f64 and not twips, etc.)
2023-03-31 16:26:11 -07:00
Nathan Adams adadb8a26d wgpu: Use swap_remove instead of remove for buffer pool 2023-03-31 16:57:52 +02:00