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

Reuse code for Metal and WGSL entry point legalization #6063

Merged

Conversation

fairywreath
Copy link
Contributor

@fairywreath fairywreath commented Jan 11, 2025

Related to #4657, related to #5933.

Reuse common code for Metal and WGSL entry point legalization.

Hoisting + packing is also currently not done for WGSL entry point parameters and they are required for #5933 as only struct entry points are given attributes. I will have a follow up fix for that as that change will break lots of test and I do not want to make this PR any bigger.

#4657 ultimately aims to also unify the legalization logic with C/CPP/CUDA backends - this PR is a good first step to unify the shading language backends.

@fairywreath fairywreath requested a review from a team as a code owner January 11, 2025 05:17
@fairywreath fairywreath changed the title Reuse code for metal and WGSL entry point legalization Reuse code for Metal and WGSL entry point legalization Jan 11, 2025
@fairywreath
Copy link
Contributor Author

fairywreath commented Jan 11, 2025

I recommend comparing/diffing the (old) individual implementations of the legalization in their separate files with the new unified implementation to make the review process easier.

@csyonghe csyonghe added the pr: non-breaking PRs without breaking changes label Jan 11, 2025
csyonghe
csyonghe previously approved these changes Jan 11, 2025
Copy link
Collaborator

@csyonghe csyonghe left a comment

Choose a reason for hiding this comment

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

It's great to see the duplicated code being removed. Thank you for putting together the cleanup!

I wonder if we can make this even cleaner by having a base class, and move all the metal/wgsl specific logic into derived classes?

source/slang/slang-ir-legalize-varying-params.cpp Outdated Show resolved Hide resolved
#include "slang-ir-clone.h"
#include "slang-ir-insts.h"
#include "slang-ir-util.h"
#include "slang-parameter-binding.h"

#include <set>
Copy link
Collaborator

Choose a reason for hiding this comment

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

this shouldn't be needed?

Copy link
Contributor Author

@fairywreath fairywreath Jan 11, 2025

Choose a reason for hiding this comment

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

std::set is actually used and was added here #4536. Looking at that PR's commit history, A custom TreeMap/TreeSet was considered but std::set ended up being used.

source/slang/slang-ir-legalize-varying-params.cpp Outdated Show resolved Hide resolved
@fairywreath
Copy link
Contributor Author

fairywreath commented Jan 11, 2025

I wonder if we can make this even cleaner by having a base class, and move all the metal/wgsl specific logic into derived classes?

Yes this is doable. Should I modify this PR or have these changes as a follow-up? I initially intended the unified implementation as close to the original ones as possible so the code changes are easy to see and so things don't break, but now that the checks all passed it should be easy to further improve the code.

@fairywreath
Copy link
Contributor Author

Yes this is doable. Should I modify this PR or have these changes as a follow-up?

I will update this PR - it should be easy to view the changes commit by commit so readability/reviewing is not an issue

@fairywreath fairywreath requested a review from csyonghe January 11, 2025 22:46
csyonghe
csyonghe previously approved these changes Jan 14, 2025
Copy link
Collaborator

@csyonghe csyonghe left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for the cleanup!

Our CPU/CUDA backend is in great need of a refactor to reuse the same varying legalization logic we have for other targets. We are missing a lot of legalization there. This PR is a good step towards the greater unification.

@csyonghe
Copy link
Collaborator

Looks like there are still conflicts.

@fairywreath
Copy link
Contributor Author

Sorry for the plethora of dirty commits but the last two commits are the only changes, the rest are reverted(I had incorrect merge commits). I had to move additional logic from #5963.

@fairywreath fairywreath requested a review from csyonghe January 15, 2025 01:39
@csyonghe csyonghe merged commit 9b977e5 into shader-slang:master Jan 15, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: non-breaking PRs without breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants