-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[HLSL][DXIL] Implement refract
intrinsic
#136026
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
raoanag
wants to merge
9
commits into
llvm:main
Choose a base branch
from
raoanag:user/raoanag/refract
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6ce233a
Refract implementation
raoanag 83d69dd
Adding dxil tests
raoanag 83c4f5a
Update CodeGen checks
raoanag 1853e3d
fix tests
raoanag dff5181
adding new lines to EOF
raoanag 3d87d6d
Addressing partial review comments
raoanag e3c1b0a
modularize SemaSPIRV.cpp
raoanag d8b079c
clang-format
raoanag d1e1fe9
Remove O1 flag from refract test
raoanag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
#define _HLSL_HLSL_INTRINSIC_HELPERS_H_ | ||
|
||
namespace hlsl { | ||
namespace __detail { | ||
namespace __dETAil { | ||
raoanag marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
constexpr vector<uint, 4> d3d_color_to_ubyte4_impl(vector<float, 4> V) { | ||
// Use the same scaling factor used by FXC, and DXC for DXIL | ||
|
@@ -71,6 +71,27 @@ constexpr vector<T, L> reflect_vec_impl(vector<T, L> I, vector<T, L> N) { | |
#endif | ||
} | ||
|
||
template <typename T> constexpr T refract_impl(T I, T N, T Eta) { | ||
T K = 1 - Eta * Eta * (1 - (N * I * N * I)); | ||
if (K < 0) | ||
return 0; | ||
else | ||
return (Eta * I - (Eta * N * I + sqrt(K)) * N); | ||
} | ||
|
||
template <typename T, int L> | ||
constexpr vector<T, L> refract_vec_impl(vector<T, L> I, vector<T, L> N, T Eta) { | ||
#if (__has_builtin(__builtin_spirv_refract)) | ||
return __builtin_spirv_refract(I, N, Eta); | ||
#else | ||
vector<T, L> K = 1 - Eta * Eta * (1 - dot(N, I) * dot(N, I)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should really be storing |
||
if (K < 0) | ||
return 0; | ||
else | ||
return (Eta * I - (Eta * dot(N, I) + sqrt(K)) * N); | ||
#endif | ||
} | ||
|
||
template <typename T> constexpr T fmod_impl(T X, T Y) { | ||
#if !defined(__DIRECTX__) | ||
return __builtin_elementwise_fmod(X, Y); | ||
|
@@ -126,7 +147,7 @@ template <typename T> constexpr vector<T, 4> lit_impl(T NDotL, T NDotH, T M) { | |
return Result; | ||
} | ||
|
||
} // namespace __detail | ||
} // namespace __dETAil | ||
raoanag marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} // namespace hlsl | ||
|
||
#endif // _HLSL_HLSL_INTRINSIC_HELPERS_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You need to add
CustomTypeChecking
.