Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU Backend: Resource model refactor #310

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

samuelselleck
Copy link
Contributor

This is the start of refactoring pax-pixels and the engines RenderContext trait from this model:

fn fill(&mut self, path: Path, fill: Fill);

to this model:

fn make_fill(&self, path: Path, fill: Fill) -> Box<dyn FillResource>;
fn draw_fill(&mut self, resource: &dyn FillResource);

exact API pending. The goal of this is to not need to re-tesselate/re-upload image data to the GPU for each draw, but only on significant changes.

Next Steps:

  • currently, draw methods in pax-pixels/src/render_context look like this:
    pub fn fill_path(&mut self, path: Path, fill: Fill) {
        let options = FillOptions::tolerance(self.tolerance);
        let mut geometry = VertexBuffers::new();
        let mut geometry_builder =
            BuffersBuilder::new(&mut geometry, |vertex: FillVertex| GpuVertex {
                position: vertex.position().to_array(),
                normal: [0.0; 2],
                prim_id: 0,
            });
        match FillTessellator::new().tessellate_path(&path, &options, &mut geometry_builder) {
            Ok(_) => {}
            Err(e) => log::warn!("{:?}", e),
        };
        let mesh = self
            .mesh_renderer
            .make_mesh(&self.backend.device, &geometry, fill);

        // TODO code bellow becomes the "fill_path" method, everything above the "make_fill", returning the mesh resource
        // or a wrapper of it.
        
        let mut render_pass =
            Self::main_draw_render_pass(&self.backend, &self.stencil_renderer, &mut self.encoder);
        self.mesh_renderer.render_meshes(&mut render_pass, &[mesh]);
    }

change the RenderContext trait (in pax-runtime-api/src/lib.rs) to allow for the create/draw API, implement it for the CPU backend (in pax-runtime/src/engine/piet_render_context.rs). Convert all drawing primitives to use this new API. Convert the pax-pixels render_context API by braking methods like the above into two, and implement the trait for the GPU backend (in pax-runtime/src/engine/pax_pixels_render_context.rs).

  • Change pax-pixels to operate over multiple canvases, as to allow a DrawResource to be used between different canvases.
  • Don't create a new render pass for each new shape drawn, instead batch them until transforms/clips are applied, and only flush them then.

Other features still missing from pax-pixels:

  • Anti-aliasing
  • try to run on WebGL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant