Commit Graph

313 Commits

Author SHA1 Message Date
Nathan Adams 533d104337 wgpu: Don't load or store the depth side of the depth buffer, we only care for stencil 2023-01-03 03:39:13 +01:00
Nathan Adams eaff82ea7e wgpu: Cleaned up some buffer binding api 2023-01-03 03:39:13 +01:00
Nathan Adams 28768f2ad8 render: Make CommandList a struct instead of a tuple 2023-01-03 03:39:13 +01:00
Nathan Adams 3dd9c4daa3 wgpu: Moved ColorAdjustments into its own bind group, and reuse ColorAdjustments::IDENTITY where we can 2023-01-03 03:39:13 +01:00
Nathan Adams 353a3116a4 wgpu: Define the sizes of uniforms upfront instead of at each call 2023-01-03 03:39:13 +01:00
Nathan Adams ae5d92693f wgpu: Moved DrawCommand handling to CommandRenderer::execute 2023-01-03 03:39:13 +01:00
Nathan Adams 7944b6dd9e wgpu: Inlined CommandRenderer::execute into Surface::draw_commands 2023-01-03 03:39:13 +01:00
Nathan Adams a71b5b4570 wgpu: Move command renderer to surface/commands.rs 2023-01-03 03:39:13 +01:00
Nathan Adams 0272eda121 wgpu: Refactor surface command target to its own file 2023-01-03 03:39:13 +01:00
Nathan Adams a657feadae wgpu: Clear out texture pool when resized 2023-01-03 03:39:13 +01:00
Nathan Adams cb6d72b49b wgpu: Split up gradient shader based on type and repeat 2023-01-03 03:39:13 +01:00
Nathan Adams a79e73fb12 wgpu: Clean up gradient shaders by bringing out common shared source into a same file 2023-01-03 03:39:13 +01:00
Nathan Adams b4c2030af8 wgpu: Appease beta clippy. again. 2023-01-03 03:39:13 +01:00
Nathan Adams 91561e8c35 wgpu: Reduce gradient.ratios uniform memory by 4x 2023-01-03 03:39:13 +01:00
Nathan Adams 312e72451f wgpu: Reduce gradient.colors uniform memory by 4x 2023-01-03 03:39:13 +01:00
Nathan Adams 986b95c50c wgpu: Share texture pool across all frames, and ensure targets are cleared properly 2023-01-03 03:39:13 +01:00
Nathan Adams c0ec5c5010 wgpu: Split up blend modes into their own shaders for performance 2023-01-03 03:39:13 +01:00
Nathan Adams 92a6c6bc76 wgpu: Add more debug labels within render passes 2023-01-03 03:39:13 +01:00
Nathan Adams 1863c93be1 wgpu: Add some more debug labels 2023-01-03 03:39:13 +01:00
Nathan Adams 257bbc8ec9 wgpu: Revert using same pool for whole frame - breaks bitmapdata.draw and I'm not sure why yet 2023-01-03 03:39:13 +01:00
Nathan Adams 0f676fc6ce wgpu: Simplify blend_buffers map creation 2023-01-03 03:39:13 +01:00
Nathan Adams ec7840f412 wgpu: Try harder to find render passes where we don't need depth 2023-01-03 03:39:13 +01:00
Nathan Adams c6045a4f24 wgpu: Multiply can't be trivial blend mode because of 0 alpha 2023-01-03 03:39:13 +01:00
Nathan Adams 342b9b9007 wgpu: Removed some needless copies in command iteration 2023-01-03 03:39:13 +01:00
Nathan Adams 81f4741300 wgpu: Default msaa on mobiles to 2x, same as webgl backend 2023-01-03 03:39:13 +01:00
Nathan Adams 7fb2ec096e wgpu: Don't wait for the entire frame to be drawn if we're just capturing a segment of the render list 2023-01-03 03:39:13 +01:00
Nathan Adams 75790606a0 wgpu: Share the buffer pool throughout the entire frame 2023-01-03 03:39:13 +01:00
Nathan Adams f253abdbd1 wgpu: Made Multiply, Add and Subtract blend modes use bitmap+blend 2023-01-03 03:39:13 +01:00
Nathan Adams e69d76fa41 wgpu: Cache Globals for a total draw frame, don't remake it if it's going to be the same values 2023-01-03 03:39:13 +01:00
Nathan Adams 03b62a93e6 wgpu: Pool textures during the same frame, and drop whatever we don't need immediately 2023-01-03 03:39:13 +01:00
Nathan Adams 4e51c9455e wgpu: Don't require VERTEX_WRITABLE_STORAGE which is unavailable on web 2023-01-03 03:39:13 +01:00
Nathan Adams 53b8907b78 wgpu: Optimise rendering blendables by queueing everything up in the same command buffer, allowing gpu to async where needed, instead of one command list at a time 2023-01-03 03:39:13 +01:00
Nathan Adams cb2b27ba03 wgpu: Don't create depth buffers, or use any depth testing, if we aren't expecting masks 2023-01-03 03:39:13 +01:00
Nathan Adams 05f49dd487 wgpu: Appease beta clippy 2023-01-03 03:39:13 +01:00
Nathan Adams b72dc1edd4 wgpu: Don't create blend buffers until they're needed 2023-01-03 03:39:13 +01:00
Nathan Adams 219fabbc0b wgpu: For trivial blends (ie Normal), just draw them as bitmaps with a blendstate 2023-01-03 03:39:13 +01:00
Nathan Adams 8311ddb0da wgpu: Allow for different sized subcommand list targets, but don't use them yet 2023-01-03 03:39:13 +01:00
Nathan Adams f48de7b34e wgpu: Always clear the first texture buffer to the desired color 2023-01-03 03:39:13 +01:00
Nathan Adams 7904c3d4f0 wgpu: Implement all blend modes 2023-01-03 03:39:13 +01:00
Nathan Adams f9333e2626 wgpu: Perform command rendering recursively and chunk up blends. Blends are still not implemented, it just copies to parent. 2023-01-03 03:39:13 +01:00
Nathan Adams 915040ba06 wgpu: Globals should now belong to the Surface and doesn't need to be mutable anymore 2023-01-03 03:39:13 +01:00
Nathan Adams d2185733b4 wgpu: Simplify Surface to no longer be an enum as there's not really many options anymore 2023-01-03 03:39:13 +01:00
Nathan Adams 4cdb8ec634 wgpu: Frame no longer owns UniformBuffer 2023-01-03 03:39:13 +01:00
Nathan Adams 1df82e8104 wgpu: Separated srgb out of Surface 2023-01-03 03:39:13 +01:00
Nathan Adams 4502f9b7ea wgpu: Removed blendmode stuff 2023-01-03 03:39:13 +01:00
Nathan Adams ded46e20e7 render: Replace PushBlendMode/PopBlendMode with Blend 2023-01-03 03:39:13 +01:00
relrelb bd9078addf chore: Fix `clippy::uninlined_format_args` lints 2022-12-15 08:59:38 +02:00
Aaron Hill 173a1a80cb Fix BitmapHandle downcasting in webgl and canvas backends
There were two issues:
1. We were accidentally calling `as_any` on `handle,` rather than
   `handle.0`
2. Calling `as_any` can invoke the wrong implementation, depending on
   what traits are in scope. We want the method implemented on the
   underlying type (`RegistryData`) to be used, but if `Downcast` is
   explicitly imported, then we appear to invoke it on the trait object
   `dyn BitmapHandleImpl` itself (using the fact that trait objects
   themselves implement `Any`). We now explicitly call the generated
   method on the trait object, which avoids this issue.
2022-12-04 14:53:00 -06: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
Adrian Wielgosik 0861153626 swf: make Clippy happy 2022-12-03 22:18:22 +01:00
Aaron Hill b8745f0ff1 avm2: Partially implement Stage3D for wgpu backend
This PR implements core 'stage3D' APIs. We are now able
to render at least two demos from the Context3D docs - a simple
triangle render, and a rotating cube.

Implemented in this PR:
* Stage3D access and Context3D creation
* IndexBuffer3D and VertexBuffer3D creation, uploading, and usage
* Program3D uploading and usage (via `naga-agal`)
* Context3D: configureBackBuffer, clear, drawTriangles, and present

Not yet implemented:
* Any 'dispose()' methods
* Depth and stencil buffers
* Context3D texture apis
* Scissor rectangle

General implementation strategy:

A new `Object` variant is added for each of the Stage3D objects
(VertexBuffer3D, Program3D, etc). This stores a handle to the
parent `Context3D`, and (depending on the object) a handle
to the underlying native resource, via `Rc<dyn
SomeRenderBackendTrait>`).

Calling methods on Context3D does not usually result in an immediate
call to a `wgpu` method. Instead, we queue up commands in our
`Context3D` instance, and execute them all on a call to `present`.
This avoids some nasty wgpu lifetime issues, and is very similar
to the approah we use for normal rendering.

The actual rendering happens on a `Texture`, with dimensions
determined by `createBackBuffer`. During 'Stage' rendering,
we render all of these Stage3D textures *behind* the normal
stage (but in front of the overall stage background color).
2022-11-25 21:43:00 -07:00
Aaron Hill 104b2265f2 Fix rebase fallout 2022-11-25 16:08:42 -07: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
relrelb b3cdd6dda1 Revert "wgpu: Use `Depth32FloatStencil8` over `Depth24PlusStencil8`"
This reverts commit 37f171de06.
2022-11-03 20:42:39 +02:00
Aaron Hill 68471723b3 core: Fix clippy format string lint 2022-10-27 08:49:39 +03:00
Aaron Hill 45515be0a3 render: Improve support for BitmapData.draw
This PR fixes a numbe of interconnected bugs:
* We weren't consistently uploading a dirty BitmapData to the render
  backend before drawing to/from it.
* BitmapData.draw should *not* add a fill color - it should draw over
  the current contents of the BitmapData
* After drawing to a non-transparent BitmapData, we need to manually
  set the opacity back to 255 for each pixel (the drawing process
  takes transparency into account, but the opacity information is
  thrown away at the end).
2022-10-17 12:53:38 -05:00
relrelb 37f171de06 wgpu: Use `Depth32FloatStencil8` over `Depth24PlusStencil8`
Credit to @crumblingstatue.

Per `wgpu` documentation, the latter has wider support than the former.

Fixes #8295, #8296.
2022-10-15 23:35:44 +03:00
relrelb 183b8adbf0 wgpu: Bump to `0.14.0`
Also bump `raw-window-handle` to `0.5`, as now required.
2022-10-14 21:49:40 +03:00
Aaron Hill 491ffbbf09 wgpu: Fix argument order when calling `BitmapSamplers.get_sampler` 2022-10-13 15:07:53 -05:00
relrelb a9dedf759a chore: Fix `clap` update
As described in https://github.com/clap-rs/clap/blob/master/CHANGELOG.md#400---2022-09-28.
2022-10-05 21:33:34 +03:00
Aaron Hill 12b0bffd12 wgpu: Remove `width` and `height` fields from our `Texture` wrapper struct
These are duplicates of fields in `Bitmap`
2022-09-26 15:00:26 -05:00
Aaron Hill 423d7e4cc4 render: Treat `update_texture` with invalid `BitmapHandle` as an error
This should be impossible to trigger from ActionScript, so
we shouldn't ignore it.
2022-09-16 22:03:15 -06:00
Nathan Adams 92044c9c02 wgpu: Merge bitmap bind groups 2 and 3 2022-09-11 09:07:53 +02:00
Nathan Adams d867a370fc wgpu: Cache direct bitmap draw bind groups (smoothing vs not) 2022-09-11 09:07:53 +02:00
Nathan Adams 57ddb6bdcb wgpu: Refactor out bitmap bind group from drawtype 2022-09-11 09:07:53 +02:00
Nathan Adams 2d48d78990 wgpu: Removed redundant _pipeline suffix in Pipelines 2022-09-11 09:07:53 +02:00
Nathan Adams a38cadfd39 wgpu: Cache shape pipelines per texture format & msaa 2022-09-11 09:07:53 +02:00
Nathan Adams a8ff81ee38 wgpu: Make vertex buffer descriptions const 2022-09-11 09:07:53 +02:00
Aaron Hill b62c17577b wgpu: Switch to arena 2022-09-11 09:07:53 +02:00
Nathan Adams c63aa2cfc8 wgpu: Moved Draw creation outside of backend 2022-09-11 09:07:53 +02:00
Nathan Adams b2e02db72f wgpu: Extracted a create_texture_transforms method 2022-09-11 09:07:53 +02:00
Nathan Adams e7e0905647 wgpu: Moved Mesh, Draw and DrawType to their own file, and code that constructs a DrawType there too 2022-09-11 09:07:53 +02:00
Nathan Adams f36bcac742 wgpu: Move actual frame rendering to Surface, deduplicates some code 2022-09-11 09:07:53 +02:00
Nathan Adams b2ecd39648 wgpu: Enable MSAA for offscreen textures 2022-09-11 09:07:53 +02:00
Nathan Adams 69aba474e1 wgpu: Split off srgb and msaa code from backend to a Surface enum 2022-09-11 09:07:53 +02:00
Nathan Adams 03f7719c49 wgpu: Move quad into its own structure under Descriptors 2022-09-11 09:07:53 +02:00
Nathan Adams a8e8b01a6c wgpu: Use a static buffer for srgb transform uniforms, reworked it from Frame 2022-09-11 09:07:53 +02:00
Nathan Adams a1d1da5d25 wgpu: Simplify stencil usage from Frame's perspective 2022-09-11 09:07:53 +02:00
Nathan Adams 794b30e10e wgpu: Split draw_x into prep_x and draw 2022-09-11 09:07:53 +02:00
Nathan Adams 91f3230a45 wgpu: Split off Frame into CommandRenderer and Frame - command renderer translates commands into draw calls on frame 2022-09-11 09:07:53 +02:00
Nathan Adams 22ba32b785 wgpu: Remove target from Frame 2022-09-11 09:07:53 +02:00
Nathan Adams 8616c898cc wgpu: Remove globals from Frame 2022-09-11 09:07:53 +02:00
Nathan Adams 14ecc98780 wgpu: Pass quad vbo/ibo as slices 2022-09-11 09:07:53 +02:00
Nathan Adams 09172c8b12 wgpu: Simplified rendering code down to 'apply transform, draw x' 2022-09-11 09:07:53 +02:00
Nathan Adams 5f671c0018 wgpu: Fixed panic if rendering to a texture smaller than 1x1 2022-09-11 09:07:53 +02:00
Nathan Adams d5ab88f40d wgpu: Make buffer blocks Pin<Box<Block>> 2022-09-11 09:07:53 +02:00
Nathan Adams 08471c6fb7 wgpu: Don't keep setting globals bind group, it only needs to be set once 2022-09-11 09:07:53 +02:00
Nathan Adams 41239039eb wgpu: Moved all bind group layouts into their own struct 2022-09-11 09:07:53 +02:00
Nathan Adams f33e6904cd wgpu: Moved bind layouts out of Pipelines, they don't change 2022-09-11 09:07:53 +02:00
Nathan Adams 39e1224bda wgpu: Don't recompile shaders for each Pipelines 2022-09-11 09:07:53 +02:00
Nathan Adams 7e013183a7 wgpu: Removed Descriptors::pipelines, we don't need 3 pipelines 2022-09-11 09:07:53 +02:00
Nathan Adams 8b6c6f8a62 wgpu: Removed DescriptorsTargetData::surface_format and frame_buffer_format as they aren't needed to be target specific 2022-09-11 09:07:53 +02:00
Nathan Adams 6755e1ccbd wgpu: Pass the pipelines to frame instead of deciding based on a macro 2022-09-11 09:07:53 +02:00
Nathan Adams 13657e16ca wgpu: Make render_offscreen use its own Frame instead of making a whole new renderer backend 2022-09-11 09:07:53 +02:00
Nathan Adams 697369536c wgpu: Split off code that actually renders a frame 2022-09-11 09:07:53 +02:00
Nathan Adams 267ea0fd13 render: Introduced render commands, moved to a command list model instead of direct rendering 2022-09-11 09:07:53 +02:00
Nathan Adams c7f420dde5 wgpu: Moved WgpuRenderBackend into backend.rs 2022-09-11 09:07:53 +02:00
Nathan Adams 70d96654d7 wgpu: Move descriptors out into its own file 2022-09-11 09:07:53 +02:00
Aaron Hill 2f81f5814d render: Add `premultiplied_alpha` parameter for image capture
When rendering offscreen, we want the resulting image to use
premultiplied alpha, since the image will be stored in a texture.

However, when capturing an image in the exporter or test framework,
we want to use straight alpha, so that the resulting image can
be saved as a PNG.

Previously, we incorrectly used straight alpha everywhere, resulting
in incorrect output when using BitmapData.draw with transparency.
2022-09-09 15:46:48 -07:00