Skip to content

Ice Cold Specialization 🧊 #18887

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tychedelia
Copy link
Contributor

Objective

Currently, specialization uses a combination of Changed and AssetChanged to determine whether changes to a mesh or material requires the entity to be re-specialized. This is inefficient as most changes to a mesh or material cannot and should not actually affect the material's pipeline descriptor. Indeed, given the signature of the specialize function, the only things that can affect the descriptor are the mesh key, vertex layout, and material key.

Solution

Use the mesh and material key to make all pipeline decisions. We still use change detection to select which entities may potentially require re-specialization, but then do an explicit check on their respective keys to determine whether specialization is actually necessary, greatly reducing unnecessary re-specializations when doing things like modifying a material's properties.

Testing

Ran some examples, this likely requires more substantive testing as these changes are highly likely to have broken something. Land early in 0.17 to make sure issues are rooted out on main.

@tychedelia tychedelia added A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 20, 2025
@tychedelia tychedelia requested a review from pcwalton April 20, 2025 22:16
@tychedelia tychedelia added this to the 0.17 milestone Apr 20, 2025
@tychedelia
Copy link
Contributor Author

I think we may need to add a change tick cache for vertex layouts as these were trivially previously being covered by AssetChanged<Mesh>.

Copy link
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-18887

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

Copy link
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-18887

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

Copy link
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-18887

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

}
} else {
mesh_key_cache.insert(*entity, mesh_key);
entity_specialization_ticks.insert(*entity, ticks.this_run());
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn’t the point to skip specialisation of the key didn’t change? One or the other of these branches looks wrong. Either this change tick was incremented suggesting that the key changed this run so specialisation is needed, which is wrong? Or the other branch incremented the change tick to indicate specialisation isn’t needed, which is wrong? Or I’m wrong :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants