Commit Graph

18 Commits

Author SHA1 Message Date
Nathan Adams e614265c17 core: Move fill_rect from BitmapData to bitmap_data_operations, fixed a bug when using non-standard values, and added better tests for fill_rect showing the bug 2023-03-31 16:57:52 +02:00
Nathan Adams 311a165149 wgpu: Reintroduce texture promoting; only preassign buffer when the texture is frequently written/&read 2023-03-31 16:57:52 +02:00
Nathan Adams 6e859891af render: Take in dirty region in update_texture, only upload those pixels 2023-03-31 16:57:52 +02:00
Nathan Adams 137593b6a6 render: Extract (u32, u32, u32, u32) to PixelRegion 2023-03-31 16:57:52 +02:00
Nathan Adams e0bd911f2f render: Only copy a possible dirty area for bitmapdata.draw & read 2023-03-31 16:57:52 +02:00
Aaron Hill 1edcbe438d core: Avoid several BitmapData GPU -> CPU sync
We don't need to perform a sync when getting the width/height,
getting or setting the 'disposed' status, or uploading to
a Context3D texture.

The Context3D change (using `copy_texture_to_texture` instead
of relying on the CPU pixels) has the added advantage of avoiding
a validation error when our source image row length isn't aligned
to `COPY_BYTES_PER_ROW_ALIGNMENT`

This dramatically speeds up the Fancy Pants World 4 loading time
(on a branch with my XML prs merged). Without this change, my
machine spends around 10 seconds on a blank white screen after
clicking 'Play'. With this change, the time spent on that screen
is reduced to around 1-2 seconds.
2023-03-17 04:56:03 -05:00
Nathan Adams b527054a1e
render: Make retrieve_offscreen_texture pass the raw buffer (#9936) 2023-03-13 00:00:42 +00:00
Aaron Hill 2748b95c86 avm2: Improve Stage3D support for textures, register types, and opcodes
This is a very large diff, but most of it comes from test files and
output.

This PR ads partial support for the following Stage3D shader features:
* Normal (square), rectangle, and cube textures
* Varying and temporary registers
* Lots of opcodes

The combination of these allows us to get a raytracing program
fully working in Ruffle. I've included it as image test.
Currently, this test is very slow (about 90 seconds on my machine),
as the code I'm using (https://github.com/saharan/OGSL) includes
its own shader language and compiler. THe raytracing demo
first compiles its own shader language to AGAL, and then starts
rendering the scene.

Limitations:
* Many opcodes are still unimplemented
* Most non-default texture options (e.g. mipmaps) are not implemented
2023-03-03 15:58:46 -06:00
Nathan Adams a3a7f79f04 render: Switch from log to tracing 2023-02-05 18:02:19 +01:00
Aaron Hill e2954821ea
core: Take two - delay reading image back from render backend using `SyncHandle` (#9184)
* Take two: Delay reading image back from render backend using `SyncHandle`

This allows us to avoid blocking immediately after a `BitmapData.draw` call.
Instead, we only attempt to use the `SyncHandle` when performing an operation
that requires the CPU-side pixels (e.g. BitmapData.getPixel or BitmapData.setPixel).

In the best case, the SWF will never explicitly access the pixels of
the target BitmapData, removing the need to ever copy back the render backend
image to our BitmapData. If the SWF doesn't require access to the pixels immediately,
we can delay copying the pixels until they're actually needed, hopefully allowing
the render backend to finish processing the BitmapData.draw operation in
the backenground before we need the result.

Now that the CPU and GPU pixels can be intentionally out of sync with
each other, we need to ensure that we don't accidentally expose 'stale'
CPU-side pixels to ActionScript (which needs to remain unaware of
our internal laziness). We now use a wrapper type `BitmapDataWrapper`
to enforce that the `SyncHandle` is consumed before accessing the
underlying `BitmapData.

* core: Skip GPU->CPU sync for source and target BitmapData during draw

* Introduce DirtyState enum
2023-01-21 21:08:04 +00:00
Nathan Adams 9cd850d30e render: Make render_offscreen return a sync handle which can be used to get the texture at a later time 2023-01-11 16:53:33 -05:00
Aaron Hill 10491a1be9 core: Store data in `BitmapData` instead of `Bitmap`
This makes `Bitmap` delegate to `BitmapData` for
all of the bitmap-related information (handle, width, and height).
As a result, we now unconditionally store a `BitmapData` in `Bitmap`.

As a result, swapping the underling `BitmapData` instance will
automatically change the properties (and rendered image) of a `Bitmap`.

This required some refactoring in the render backends in order to
get access to a `BitmapHandle` through `BitmapData`.
2023-01-03 18:01:41 -07:00
Aaron Hill 1b3070ab85 core: Make `BitmapHandle` hold a trait object instead of an id
`BitmapHandle` now holds `Arc<dyn BitmapHandleImpl>`.
This allows us to move all of the per-bitmap backend data into
`BitmapHandle`, instead of holding an id to a backend-specific
hashmap.

This fixes the memory leak issue with bitmaps. Once the AVM side of a
bitmap (`Bitmap`/`BitmapData`) gets garbage-collected, the
`BitmapHandle` will get dropped, freeing all of the GPU resources
assoicated with the bitmap.
2022-12-03 19:44:44 -06:00
Aaron Hill 3bef8c4fd6 render: Remove `get_bitmap_pixels` and store data in `Character::Bitmap`
We only called `get_bitmap_pixels` when creating a `BitmapData`
for an SWF-provided `Bitmap`. We now store the initial pixels
in `Character::Bitmap`, and use them to initialize a `BitmapData`
when needed.

This lets us simplify the wgpu backend, which no longer needs
to store a `Bitmap` object. In addition to saving space for
`BitmapData` objects that lack an SWF `Bitmap`, this will make
it easier to move data from `bitmap_registry` into `BitmapHandle`
itself.
2022-11-25 16:08:42 -07:00
Aaron Hill bdadb17a95 render: Don't use BitmapHandle in tessellator
Currently, we rely on ShapeTessellator being able to get a BitmapHandle
without a RenderBackend. With the upcoming BitmapData refactor,
we will always need a RenderBackend to get a BitmapHandle, which creates
borrow-checker issues in ShapeTessellator (which is stored in a
RenderBackend).

To solve this, we split BitmapSource.bitmap into two methods -
BitmapSource.bitmap and BitmapSource.bitmap_handle. ShapeTessellator
continues to use BitmapSource.bitmap, and uses the u16 bitmap id
instead of a BitmapHandle. The BitmapSource.bitmap_handle method
is used inside each render backend to convert the id to a BitmapHandle,
avoiding borrow-checker issues.
2022-11-21 21:04:40 -07:00
Aaron Hill 7218146e04 avm2: Implement BitmapData.dispose
We now check if a BitmapData has been disposed by checking
for a zero width or height (which cannot happen otherwise).
As a result, we no longer need the 'disposed' field on the AVM1
BitmapData object.
2022-09-07 11:02:53 -07:00
relrelb 0d6462cfab render: Remove `gc-arena` dependency
It was only used to make structs `#[derive(gc_arena::Collect)]`, and
generally it doesn't make much sense that `render` needs to be GC-aware.
So instead annotate `render` fields in `core` with `#[collect(require_static)]`.
2022-09-02 09:49:18 -07:00
Nathan Adams bc0c7cbccb render: Made new render crate, moved Bitmap stuff to it 2022-08-14 18:38:14 -07:00