Skip to content

Commit 9b84509

Browse files
committed
pragma to silence warning (kind of not working?), beta wo check
1 parent d6e6e94 commit 9b84509

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

include/nbl/builtin/hlsl/bxdf/common.hlsl

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -927,20 +927,28 @@ struct beta
927927
}
928928

929929
// removed values that cancel out in beta
930+
static T __call_wo_check(T x, T y)
931+
{
932+
const T l2x = hlsl::log2<T>(x);
933+
const T l2y = hlsl::log2<T>(y);
934+
const T l2xy = hlsl::log2<T>(x+y);
935+
936+
return hlsl::exp2<T>((x - T(0.5)) * l2x + (y - T(0.5)) * l2y - (x + y - T(0.5)) * l2xy +
937+
numbers::inv_ln2<T> * (__series_part(x) + __series_part(y) - __series_part(x+y)) + T(1.32574806473616));
938+
}
939+
930940
static T __call(T x, T y)
931941
{
932942
assert(x >= T(0.999) && y >= T(0.999));
933943

944+
#pragma dxc diagnostic push
945+
#pragma dxc diagnostic ignored "-Wliteral-range"
934946
const T thresholds[4] = { 0, 5e5, 1e6, 1e15 }; // threshold values gotten from testing when the function returns nan/inf/1
947+
#pragma dxc diagnostic pop
935948
if (x+y > thresholds[mpl::find_lsb_v<sizeof(T)>])
936949
return T(0.0);
937950

938-
const T l2x = hlsl::log2<T>(x);
939-
const T l2y = hlsl::log2<T>(y);
940-
const T l2xy = hlsl::log2<T>(x+y);
941-
942-
return hlsl::exp2<T>((x - T(0.5)) * l2x + (y - T(0.5)) * l2y - (x + y - T(0.5)) * l2xy +
943-
numbers::inv_ln2<T> * (__series_part(x) + __series_part(y) - __series_part(x+y)) + T(1.32574806473616));
951+
return __call_wo_check(x, y);
944952
}
945953
};
946954
}
@@ -951,6 +959,12 @@ T beta(NBL_CONST_REF_ARG(T) x, NBL_CONST_REF_ARG(T) y)
951959
return impl::beta<T>::__call(x, y)/impl::beta<T>::__call(1.0, 1.0);
952960
}
953961

962+
template<typename T>
963+
T beta_wo_check(NBL_CONST_REF_ARG(T) x, NBL_CONST_REF_ARG(T) y)
964+
{
965+
return impl::beta<T>::__call_wo_check(x, y)/impl::beta<T>::__call_wo_check(1.0, 1.0);
966+
}
967+
954968
}
955969
}
956970
}

include/nbl/builtin/hlsl/bxdf/ndf/ggx.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ struct GGX<T,false NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
146146
return 0.0;
147147
scalar_type onePlusLambda_V = scalar_type(0.5) * (devsh_v / NdotV + scalar_type(1.0));
148148
scalar_type onePlusLambda_L = scalar_type(0.5) * (devsh_l / NdotL + scalar_type(1.0));
149-
G2_over_G1 = bxdf::beta<scalar_type>(onePlusLambda_L, onePlusLambda_V) * onePlusLambda_V;
149+
G2_over_G1 = bxdf::beta_wo_check<scalar_type>(onePlusLambda_L, onePlusLambda_V) * onePlusLambda_V;
150150
}
151151
else
152152
{
@@ -245,7 +245,7 @@ struct GGX<T,true NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
245245
return 0.0;
246246
scalar_type onePlusLambda_V = scalar_type(0.5) * (devsh_v / NdotV + scalar_type(1.0));
247247
scalar_type onePlusLambda_L = scalar_type(0.5) * (devsh_l / NdotL + scalar_type(1.0));
248-
G2_over_G1 = bxdf::beta<scalar_type>(onePlusLambda_L, onePlusLambda_V) * onePlusLambda_V;
248+
G2_over_G1 = bxdf::beta_wo_check<scalar_type>(onePlusLambda_L, onePlusLambda_V) * onePlusLambda_V;
249249
}
250250
else
251251
{

include/nbl/builtin/hlsl/tgmath/impl.hlsl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,10 @@ struct l2gamma_helper<T NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
539539
// implementation derived from Numerical Recipes in C, transformed for log2
540540
static T __call(T x)
541541
{
542-
// TODO: need a way to silence warning about thresholds being too large for T
543-
// affected by DXC issue: https://github.com/microsoft/DirectXShaderCompiler/issues/7722
542+
#pragma dxc diagnostic push
543+
#pragma dxc diagnostic ignored "-Wliteral-range"
544544
const T thresholds[4] = { 0, 5e4, 1e36, 1e305 }; // threshold values gotten from testing when the function returns nan/inf
545+
#pragma dxc diagnostic pop
545546
if (x > thresholds[mpl::find_lsb_v<sizeof(T)>])
546547
return bit_cast<T>(numeric_limits<T>::infinity);
547548

@@ -583,7 +584,10 @@ struct beta_helper<T NBL_PARTIAL_REQ_BOT(concepts::FloatingPointScalar<T>) >
583584
// implementation from Numerical Recipes in C, 2nd ed.
584585
static T __call(T v1, T v2)
585586
{
587+
#pragma dxc diagnostic push
588+
#pragma dxc diagnostic ignored "-Wliteral-range"
586589
const T thresholds[4] = { 0, 2e4, 1e6, 1e15 }; // threshold values gotten from testing when the function returns nan/inf/1
590+
#pragma dxc diagnostic pop
587591
if (v1+v2 > thresholds[mpl::find_lsb_v<sizeof(T)>])
588592
return T(0.0);
589593

0 commit comments

Comments
 (0)