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

Support constref parameters passing. #3249

Merged
merged 5 commits into from
Sep 29, 2023
Merged

Conversation

csyonghe
Copy link
Collaborator

@csyonghe csyonghe commented Sep 28, 2023

This PR adds support for __constref parameter modifier to specify that a parameter should be passed by const reference.
A constref parameter is treated as an immutable value.
Adds [constref] attribute that can be used to mark a function to make this parameter passed by const reference.

Make NonCopyable type passed by constref by default.
Also makes sure constref parameters doesn't lead to redundant load/stores in auto-diffed functions.

Add tests for mixing use of __constref and no_diff in a differentiable function.

saipraveenb25
saipraveenb25 previously approved these changes Sep 28, 2023
Copy link
Collaborator

@saipraveenb25 saipraveenb25 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!

Just to clarify, constref isn't going to mix with differentiable types?

@csyonghe
Copy link
Collaborator Author

I haven't tested, but it is likely not going to work to have a differentiable constref parameter. We need to handle that carefully if we decide to support it.

@csyonghe
Copy link
Collaborator Author

One way to support it is to convert it to a normal in parameter.

@csyonghe
Copy link
Collaborator Author

OK, I added checks to prevent forming a constref differentiable parameter, including this and normal parameters.

@csyonghe csyonghe merged commit b7d318f into shader-slang:master Sep 29, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants