Skip to content

Conversation

@dfrg
Copy link
Collaborator

@dfrg dfrg commented May 10, 2022

This is a rough but functioning cut of a new scene API supporting both retained, composable fragments and the initial foundation for a resource framework. In addition, this includes a C API that is (for now) designed specifically for rendering glyphs on Metal.

There are no significant changes to existing code, but the PR is large and will definitely require some (perhaps not so) fine tuning before merging.

dfrg added 13 commits April 11, 2022 05:30
This commit implements actual rendering for the new piet-scene crate.

In particular, it adds a new EncodedSceneRef type in piet_gpu::encoder to store references to the raw stream data. This is used as a proxy for both PietGpuRenderContext and piet_scene::scene::Scene to feed data into the renderer.

Much of this is still hacky for expedience and because the intention is to be a transitional state that maintains both interfaces until we can move to the new scene API and add a wrapper for the traditional piet API.

The general structure and relationships between these crates need further discussion.
This exposes a new uniform API for generating scene fragments for glyph outlines.
This allows rendering from raw stream data and may be temporary depending on the crate structure after the traditional piet api is removed.
First cut at a public C api that supports glyph rendering on Metal targets.
Changes the return mutability for pgpu_glyph_provider_get()
This should fix channel swizzling on M1 and restore functionality on Intel
@dfrg dfrg requested a review from raphlinus May 10, 2022 08:31
Copy link
Contributor

@raphlinus raphlinus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me, and quite ambitious the way it subsumes so much of the encoding task. I have some suggestions for improvements, but none blocking - I'd be happy to build future stuff on top of this, and continue to iterate quality-of-life features such as kurbo conversions.

@@ -0,0 +1,140 @@
#include <cstdarg>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file is auto-generated? It's actually a bit hard to tell as some of the comments look hand-written. In any case, would it be possible to add a line at or near the top explaining what's going on?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is auto-generated. I'll configure the generator to add a comment at the top marking it as such.

pinot = "0.1.5"
moscato = "0.1.2"

# remove these and move demo to another directory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this comment be labeled "TODO"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Good catch. I'm happy to just remove the binary altogether along with its dependencies. I believe we discussed adding a more structured example framework to the project and it seems like "soon" might be a good time to do that.


pub fn rgb<C: Into<f64>>(r: C, g: C, b: C) -> Self {
Self::rgb8(
(r.into() / 255.0) as u8,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth looking at the piet sources for this. This conversion neither rounds nor clamps to (0..=255) so I don't think it's quite ideal. Given that it's low level, it might not be important surfacing the float versions here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for not pointing out that all of these divisions should be multiplications anyway :) Clearly I never made use of the float versions. I'll go ahead and drop them.

}

pub fn to_premul_u32(self) -> u32 {
let a = self.a as f64 / 255.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually write this as a multiplication by (1.0 / 255.0), as this generates divsd (checked in godbolt). Also I think it would be better with rounding.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always nice to facilitate better codegen. Will make both of these changes.

@@ -0,0 +1,225 @@
// Copyright 2022 The piet-gpu authors.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of this code seems pretty familiar. That's ok, but maybe it should say something like "based in part on kurbo."

Similarly, a pretty common pattern would be to have kurbo as an optional dependency, and have conversions in place. I'm not sure that should be done this round, perhaps in future. I think the Rust traits for approximate conversions (f64->f32 and friends) were still a bit controversial last time I took a serious look at this, not sure if that's been settled by now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did pull most of the Affine functions from kurbo. I'll add an attribution.

Happy to prep another PR adding the optional dependency along with the conversions and changing some signatures to take impl Into<T> for the appropriate types.

dfrg added 2 commits May 10, 2022 20:07
* Change pgpu-render header file generator to add a comment noting that the file is auto-generated
* Remove bin target and associated dependencies from piet-scene crate
* Remove FP constructors from the Color type
* Better codegen and rounding in Color::to_premul_u32()
* Add kurbo attribution for piet_scene::geometry module
@dfrg dfrg merged commit f5a721d into linebender:master May 11, 2022
@dfrg dfrg deleted the fragments branch May 18, 2022 19:25
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.

2 participants