Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@bdero
Copy link
Member

@bdero bdero commented May 10, 2022

The cubemap support is done via a slice parameter. Slice order is the same for GLES and Metal (+x, -x, +y, -y, +z, -z; NDC is the same).
The included fixture is a scaled down CC0 Poly Haven HDRI.

It felt like the right time to throw some beefier shaders at impeller and maybe land a 3d-specific feature or two. :)

impeller_unittests --gtest_filter=Play/RendererTest.TheImpeller/Metal --timeout=0

image

2022-05-10.04-24-18.mp4

The shader fails to link at runtime for the GLES backend on MacOS for some reason (I haven't attempted to debug it yet).

@bdero bdero requested review from chinmaygarde and dnfield May 10, 2022 11:52
Copy link
Member

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

So excited about this. I'll figure out what is making the GLES compiler mad.

/// Primitive distance functions.
///

float SphereDistance(vec3 sample_position,
Copy link
Member

Choose a reason for hiding this comment

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

We should consider putting these in a header file with other useful utilities that we can import as needed. Our shaders so far have been extremely simple so it sort of didn't matter yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

So I've been thinking: Should we have a standard shader library that ships with impellerc itself and slowly graduate routines that get repeated use to it? Basically a directory that's always guaranteed to be in the include path and defines "namespaced" functions:

#include "impeller/distance.glsl"

...

float my_sphere = ImSphereDistance(space, vec3(0), 1.0);

Perhaps worth discussing over a bug (and not sure if this is the best naming convention :)). A few other things that are good candidates: Sampler mode emulation for legacy platforms (i.e. ClampToBorder), common sigmoids, erf, gaussian/normal distribution, color space conversions, cheap hash/noise functions, simplex noise.

Copy link
Member

Choose a reason for hiding this comment

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

The need for something like this is coming up in my work to address differences in coordinate spaces between OpenGL and Metal. https://docs.unity3d.com/Manual/SL-PlatformDifferences.html is probably recommended reading for inspiration as it documents some of the patterns you are thinking of as well as built-ins.

In any case, we can handle this at a later time. Just thought we might be at a point where our shaders are not so simple anymore.

cam_up * lens_uv.y * sin(fov));
}

void main() {
Copy link
Member

Choose a reason for hiding this comment

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

I tried to profile the performance of this kernel in the shader profiler but it only seems to be available on iOS and TVOS (and perhaps the M1 Macs)? It would be interesting to take a stab at optimizing this using a profiler. I bet there are many low hanging fruit.

Copy link
Member Author

@bdero bdero May 10, 2022

Choose a reason for hiding this comment

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

Oh definitely, this can get way faster. One particularly egregious example is that the rotations should be computed once, but they're computed during distance evaluation time (400x+ more evaluations than necessary).


// |Texture|
bool TextureGLES::SetContents(const uint8_t* contents, size_t length) {
bool TextureGLES::SetContents(const uint8_t* contents,
Copy link
Member

Choose a reason for hiding this comment

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

Verify that the slice is 0 if the descriptor format is anything but kTextureCube?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

#if IMPELLER_ENABLE_METAL // The shader fails to link in the GLES backend for
// some reason.
TEST_P(RendererTest, TheImpeller) {
using VS = ImpellerVertexShader;
Copy link
Member

Choose a reason for hiding this comment

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

There are two steps to take to disable the OpenGLES backend. The first is to make sure the test skips compilation (if you want it to of course). The second is to GTEST_SKIP the test with a message when the test is compiled and needs to be skipped at runtime. See the GTEST_SKIP pattern used for disabling the instancing test above. This is also why there is a presubmit failure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.


virtual void SetLabel(const std::string_view& label) = 0;

[[nodiscard]] virtual bool SetContents(const uint8_t* contents,
Copy link
Member

Choose a reason for hiding this comment

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

I think the subclass should verify the slice is appropriate for the descriptor before letting the subclasses set the contents for that slice. Perhaps add a new pure virtual OnSetContents and make this non-virtual?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed and done.

@dnfield
Copy link
Contributor

dnfield commented May 10, 2022

neeeeaaat

@bdero bdero merged commit 8933449 into flutter:main May 10, 2022
@bdero
Copy link
Member Author

bdero commented May 10, 2022

Huh... just realized the logo prisms are a bit too long. I thought something seemed off about it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants