Skip to content

Commit b46a32f

Browse files
committed
Addressing partial review comments
1 parent 9b0ccaf commit b46a32f

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define _HLSL_HLSL_INTRINSIC_HELPERS_H_
1111

1212
namespace hlsl {
13-
namespace __detail {
13+
namespace __dETAil {
1414

1515
constexpr vector<uint, 4> d3d_color_to_ubyte4_impl(vector<float, 4> V) {
1616
// Use the same scaling factor used by FXC, and DXC for DXIL
@@ -71,24 +71,24 @@ constexpr vector<T, L> reflect_vec_impl(vector<T, L> I, vector<T, L> N) {
7171
#endif
7272
}
7373

74-
template <typename T> constexpr T refract_impl(T I, T N, T eta) {
75-
T k = 1 - eta * eta * (1 - (N * I * N *I));
76-
if(k < 0)
74+
template <typename T> constexpr T refract_impl(T I, T N, T Eta) {
75+
T K = 1 - Eta * Eta * (1 - (N * I * N * I));
76+
if (K < 0)
7777
return 0;
7878
else
79-
return (eta * I - (eta * N * I + sqrt(k)) * N);
79+
return (Eta * I - (Eta * N * I + sqrt(K)) * N);
8080
}
8181

8282
template <typename T, int L>
83-
constexpr vector<T, L> refract_vec_impl(vector<T, L> I, vector<T, L> N, T eta) {
83+
constexpr vector<T, L> refract_vec_impl(vector<T, L> I, vector<T, L> N, T Eta) {
8484
#if (__has_builtin(__builtin_spirv_refract))
85-
return __builtin_spirv_refract(I, N, eta);
85+
return __builtin_spirv_refract(I, N, Eta);
8686
#else
87-
vector<T, L> k = 1 - eta * eta * (1 - dot(N, I) * dot(N, I));
88-
if(k < 0)
87+
vector<T, L> K = 1 - Eta * Eta * (1 - dot(N, I) * dot(N, I));
88+
if (K < 0)
8989
return 0;
9090
else
91-
return (eta * I - (eta * dot(N, I) + sqrt(k)) * N);
91+
return (Eta * I - (Eta * dot(N, I) + sqrt(K)) * N);
9292
#endif
9393
}
9494

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,8 @@ reflect(__detail::HLSL_FIXED_VECTOR<float, L> I,
487487
/// \param eta The refraction index.
488488
///
489489
/// The return value is a floating-point vector that represents the refraction
490-
/// using the refraction index, \a eta, for the direction of the entering ray, \a I,
491-
/// off a surface with the normal \a N.
490+
/// using the refraction index, \a eta, for the direction of the entering ray,
491+
/// \a I, off a surface with the normal \a N.
492492
///
493493
/// This function calculates the refraction vector using the following formulas:
494494
/// k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
@@ -515,7 +515,7 @@ const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
515515
template <typename T>
516516
const inline __detail::enable_if_t<
517517
__detail::is_arithmetic<T>::Value && __detail::is_same<float, T>::value, T>
518-
refract(T I, T N, T eta) {
518+
refract(T I, T N, T eta) {
519519
return __detail::refract_impl(I, N, eta);
520520
}
521521

clang/lib/Sema/SemaSPIRV.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(const TargetInfo &TI,
173173
QualType ArgTyB = B.get()->getType();
174174
auto *VTyB = ArgTyB->getAs<VectorType>();
175175
if (VTyB == nullptr) {
176-
SemaRef.Diag(A.get()->getBeginLoc(),
176+
SemaRef.Diag(B.get()->getBeginLoc(),
177177
diag::err_typecheck_convert_incompatible)
178178
<< ArgTyB
179179
<< SemaRef.Context.getVectorType(ArgTyB, 2, VectorKind::Generic) << 1
@@ -234,16 +234,14 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(const TargetInfo &TI,
234234
ExprResult C = TheCall->getArg(2);
235235
QualType ArgTyC = C.get()->getType();
236236
if (!ArgTyC->hasFloatingRepresentation()) {
237-
SemaRef.Diag(C.get()->getBeginLoc(),
238-
diag::err_builtin_invalid_arg_type)
237+
SemaRef.Diag(C.get()->getBeginLoc(), diag::err_builtin_invalid_arg_type)
239238
<< 3 << /* scalar or vector */ 5 << /* no int */ 0 << /* fp */ 1
240239
<< ArgTyC;
241240
return true;
242241
}
243242

244243
QualType RetTy = ArgTyA;
245244
TheCall->setType(RetTy);
246-
assert(RetTy == ArgTyA);
247245
break;
248246
}
249247
case SPIRV::BI__builtin_spirv_reflect: {

clang/test/CodeGenSPIRV/Builtins/refract.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
22

3-
// RUN: %clang_cc1 -O1 -triple spirv-pc-vulkan-compute %s -emit-llvm -o - | FileCheck %s
3+
// RUN: %clang_cc1 -triple spirv-pc-vulkan-compute %s -emit-llvm -o - | FileCheck %s
44

55
typedef float float2 __attribute__((ext_vector_type(2)));
66
typedef float float3 __attribute__((ext_vector_type(3)));

clang/test/SemaSPIRV/BuiltIns/refract-errors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ float2 test_no_second_arg(float2 p0) {
77
// expected-error@-1 {{too few arguments to function call, expected 3, have 1}}
88
}
99

10-
float2 test_too_few_arg(float2 p0) {
10+
float2 test_no_third_arg(float2 p0) {
1111
return __builtin_spirv_refract(p0, p0);
1212
// expected-error@-1 {{too few arguments to function call, expected 3, have 2}}
1313
}

0 commit comments

Comments
 (0)