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

Eager shader compilation #5606

Merged
merged 30 commits into from
Feb 21, 2023
Merged

Eager shader compilation #5606

merged 30 commits into from
Feb 21, 2023

Conversation

kazcw
Copy link
Contributor

@kazcw kazcw commented Feb 9, 2023

Pull Request Description

Start shader compilation eagerly, rather than wait until they are needed. Implements #5604.

Before:
image
We didn't compile shaders until we needed them, causing latency before new widgets can render.

After:
image
Shaders are done compiling before project_open finishes.

Checklist

Please include the following checklist in your PR:

  • The documentation has been updated if necessary.
  • All code conforms to the
    Scala,
    Java,
    and
    Rust
    style guides.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed: Enso GUI was tested when built using BOTH
      ./run ide build and ./run ide watch.

@kazcw kazcw self-assigned this Feb 9, 2023
@kazcw kazcw marked this pull request as draft February 9, 2023 19:54
@kazcw
Copy link
Contributor Author

kazcw commented Feb 9, 2023

A lot of shaders are missing the cache--putting this back in draft while I look into it.

@kazcw kazcw added the CI: No changelog needed Do not require a changelog entry for this PR. label Feb 9, 2023
@wdanilo
Copy link
Member

wdanilo commented Feb 9, 2023

This may be connected with one thing - when we move a shape system to a layer which did not have earlier this shape system, we might submit the shader again. I do not think that we are re-using the shaders in this situation. If this is the case, it might be good to improve it in this PR as well.

@enso-bot
Copy link

enso-bot bot commented Feb 10, 2023

Keziah Wesley reports a new STANDUP for today (2023-02-09):

Progress: Started working on eager shader compilation. Implemented support for persistent shaders, and compiling unpaired shaders. It should be finished by 2023-02-10.

Next Day: Next day I will be working on the #5606 task. Debug shader compile errors.

@farmaazon
Copy link
Contributor

I do not think that we are re-using the shaders in this situation.

I can confirm, that indeed we don't do that.

@enso-bot
Copy link

enso-bot bot commented Feb 14, 2023

Keziah Wesley reports a new 🔴 DELAY for the last Friday (2023-02-10):

Summary: There is 4 days delay in implementation of the Eager shader compilation (#5606) task.
It will cause 0 days delay for the delivery of this weekly plan.

Delay Cause: In initial estimate, I thought we had ready-to-compile shader code. Constructing the input declarations at application start will require refactoring some functionality.

@enso-bot
Copy link

enso-bot bot commented Feb 14, 2023

Keziah Wesley reports a new STANDUP for the last Friday (2023-02-10):

Progress: Using the Shape constructors to complete the shader programs, but constructing the shapes early is having some side effect that breaks rendering. It should be finished by 2023-02-14.

Next Day: Next day I will be working on the #5606 task. Debug why constructing Shapes breaks rendering.

@kazcw kazcw marked this pull request as ready for review February 14, 2023 23:01
@kazcw kazcw requested a review from mwu-tow as a code owner February 14, 2023 23:01
@enso-bot
Copy link

enso-bot bot commented Feb 14, 2023

Keziah Wesley reports a new STANDUP for yesterday (2023-02-13):

Progress: Debugging the render problem when shape constructors are run. It should be finished by 2023-02-14.

Next Day: Next day I will be working on the #5606 task. Finish the PR.

@enso-bot
Copy link

enso-bot bot commented Feb 14, 2023

Keziah Wesley reports a new STANDUP for today (2023-02-14):

Progress: Finished eager shader compilation working. It should be finished by 2023-02-14.

Next Day: Next day I will be working on the #5603 task. Profile and look for frontend optimization opportunities.

@kazcw
Copy link
Contributor Author

kazcw commented Feb 15, 2023

@wdanilo

This may be connected with one thing - when we move a shape system to a layer which did not have earlier this shape system, we might submit the shader again. I do not think that we are re-using the shaders in this situation. If this is the case, it might be good to improve it in this PR as well.

I think this is handled by the caching layer in the shader compiler driver--the same shader code won't be compiled more than once.

@kazcw kazcw added the CI: Keep up to date Automatically update this PR to the latest develop. label Feb 17, 2023
Copy link
Member

@wdanilo wdanilo left a comment

Choose a reason for hiding this comment

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

As always, beautiful and well written code ❤️

Few additional questions:

  1. Does this PR enable precompiled vertex shaders?
  2. Is there any callback when the shaders are ready? I want to use it for spinner hiding.

lib/rust/ensogl/core/src/display/shape/primitive/system.rs Outdated Show resolved Hide resolved
lib/rust/ensogl/core/src/display/symbol/gpu/shader.rs Outdated Show resolved Hide resolved
Comment on lines 210 to 225
#[profile(Task)]
pub fn instantiate_shaders() {
SHAPES_DEFINITIONS.with_borrow(|shapes| {
for shape in shapes {
let path = &shape.definition_path;
let preload = match path {
_ if path.starts_with("app/gui/view/debug_scene/") => false,
_ if path.starts_with("lib/rust/ensogl/example/") => false,
_ => true,
};
if preload {
let _shape = (shape.cons)();
}
}
});
}
Copy link
Member

Choose a reason for hiding this comment

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

This looks super hacky to me. What about this:

  1. Renaming app/gui/view/debug_scene/ to app/gui/view/examples/
  2. Renaming lib/rust/ensogl/example/ to lib/rust/ensogl/examples/
  3. Excluding here anything that has folder examples in path.
  4. Writing that in our docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a bit less hacky! Implemented.

lib/rust/ensogl/core/src/display/world.rs Outdated Show resolved Hide resolved
lib/rust/ensogl/core/src/system/gpu/shader.rs Show resolved Hide resolved
@kazcw kazcw added the CI: Ready to merge This PR is eligible for automatic merge label Feb 20, 2023
@kazcw
Copy link
Contributor Author

kazcw commented Feb 20, 2023

I don't think QA is applicable to this--it is tested by profiling and looking at the graph, which I have posted in the PR description above; so I'll merge as soon as I pass code owner review.

@kazcw
Copy link
Contributor Author

kazcw commented Feb 20, 2023

@wdanilo

1. Does this PR enable precompiled vertex shaders?

I haven't added support for offline vertex shader optimization; however I am eagerly linking the shader programs as well as compiling, so the shaders are ready to use when needed.

2. Is there any callback when the shaders are ready? I want to use it for spinner hiding.

The shader compiler has an on_idle mechanism, but that's very low-level. I'll write an async function in Scene that can be used to initiate compiling all the shaders, and await completion.

@wdanilo
Copy link
Member

wdanilo commented Feb 21, 2023

@kazcw can you add also vertex shader recompilation? It looks like it should just work with your changes now. Just test it out, if there would be problems, we will do it in separate PR (in such a case create a task for it pls). If its doable now, let's do it.

@kazcw
Copy link
Contributor Author

kazcw commented Feb 21, 2023

@wdanilo

@kazcw can you add also vertex shader recompilation? It looks like it should just work with your changes now. Just test it out, if there would be problems, we will do it in separate PR (in such a case create a task for it pls). If its doable now, let's do it.

It was almost working. The dummy input declarations we use for shader extraction needed to be stripped. Now using fully-optimized shaders!

I've also added async completion notification--you can use scene.prepare_to_render().await, which will finish when the shaders are ready (it is idempotent--if compilation has already been started, it will just wait and return when they're ready).

@wdanilo
Copy link
Member

wdanilo commented Feb 21, 2023

This is amazing!

@wdanilo wdanilo merged commit dd3ee76 into develop Feb 21, 2023
@wdanilo wdanilo deleted the wip/kw/eager-shaders branch February 21, 2023 23:29
@enso-bot
Copy link

enso-bot bot commented Feb 22, 2023

Keziah Wesley reports a new 🔴 DELAY for yesterday (2023-02-20):

Summary: There is 6 days delay in implementation of the Eager shader compilation (#5606) task.
It will cause 0 days delay for the delivery of this weekly plan.

Delay Cause: Review latency.

@enso-bot
Copy link

enso-bot bot commented Feb 22, 2023

Keziah Wesley reports a new STANDUP for yesterday (2023-02-20):

Progress: Addressed review on shader compilation--added a little more functionality. It should be finished by 2023-02-20.

Next Day: Next day I will be working on the #5669 task. Look in to text rendering.

@kazcw kazcw linked an issue Feb 23, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Keep up to date Automatically update this PR to the latest develop. CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pre-emptive shader compilation
3 participants