Skip to content

Commit 7085798

Browse files
committed
Use partial specialization
1 parent b6e0955 commit 7085798

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (C) 2023 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#ifndef _NBL_BUILTIN_HLSL_GLSL_BIT_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_GLSL_BIT_INCLUDED_
6+
7+
#include "nbl/builtin/hlsl/cpp_compat.hlsl"
8+
#include "nbl/builtin/hlsl/spirv_intrinsics/core.hlsl"
9+
10+
namespace nbl
11+
{
12+
namespace hlsl
13+
{
14+
namespace glsl
15+
{
16+
namespace impl
17+
{
18+
19+
#ifdef __HLSL_VERSION
20+
21+
template<typename T, bool isSigned, bool isIntegral>
22+
struct bitfieldExtract
23+
{
24+
T operator()( T val, uint32_t offsetBits, uint32_t numBits )
25+
{
26+
if( isIntegral )
27+
{
28+
static_assert( false, "T must be an integral type" );
29+
}
30+
if( isSigned )
31+
{
32+
return spirv::bitFieldSExtract<T>( val, offsetBits, numBits );
33+
}
34+
return spirv::bitFieldUExtract<T>( val, offsetBits, numBits );
35+
}
36+
};
37+
38+
}
39+
#endif
40+
41+
}
42+
}
43+
}
44+
}
45+
46+
#endif

include/nbl/builtin/hlsl/glsl_compat/core.hlsl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "nbl/builtin/hlsl/cpp_compat.hlsl"
88
#include "nbl/builtin/hlsl/spirv_intrinsics/core.hlsl"
9+
#include "nbl/builtin/hlsl/glsl_compat/bit.hlsl"
910

1011
namespace nbl
1112
{
@@ -59,13 +60,7 @@ T atomicCompSwap(NBL_REF_ARG(T) ptr, T comparator, T value)
5960
template<typename T>
6061
T bitfieldExtract( T val, uint32_t offsetBits, uint32_t numBits )
6162
{
62-
static_assert( is_integral<T>::value );
63-
if( is_unsigned<T>::value )
64-
{
65-
return spirv::bitFieldUExtract<T>( val, offsetBits, numBits );
66-
}
67-
//if( is_signed<T>::value )
68-
return spirv::bitFieldSExtract<T>( val, offsetBits, numBits );
63+
return impl::bitfieldExtract<T, is_signed<T>::value, is_integral<T>::value>( val, offsetBits, numBits );
6964
}
7065

7166
/**

0 commit comments

Comments
 (0)