-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Add cubemap support and shader demo #33226
Conversation
chinmaygarde
left a comment
There was a problem hiding this 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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
impeller/renderer/texture.h
Outdated
|
|
||
| virtual void SetLabel(const std::string_view& label) = 0; | ||
|
|
||
| [[nodiscard]] virtual bool SetContents(const uint8_t* contents, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed and done.
|
Huh... just realized the logo prisms are a bit too long. I thought something seemed off about it. |

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. :)
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).