@@ -31,11 +31,33 @@ namespace nbl
31
31
namespace hlsl
32
32
{
33
33
34
+ #if 0 // enable this if you run into bit_cast not working for a non fundamental type
35
+ template<class T, class U>
36
+ enable_if_t<sizeof (T)==sizeof (U)&&(is_scalar_v<T>||is_vector_v<T>)==(is_scalar_v<U>||is_vector_v<U>),T> bit_cast (U val)
37
+ {
38
+ return spirv::bitcast<T,U>(val);
39
+ }
40
+ // unfortunately its impossible to deduce Storage Class right now,
41
+ // also this function will only work as long as `inout` behaves as `__restrict &` in DXC
42
+ template<class T, class U, uint32_t StorageClass>
43
+ enable_if_t<sizeof (T)==sizeof (U),T> bit_cast (inout U val)
44
+ {
45
+ using ptr_u_t = spirv::pointer_t<U,StorageClass>;
46
+ // get the address of U
47
+ ptr_u_t ptr_u = spirv::copyObject<StorageClass,U>(val);
48
+ using ptr_t_t = spirv::pointer_t<T,StorageClass>;
49
+ // reinterpret cast the pointers
50
+ ptr_t_t ptr_t = spirv::bitcast<ptr_t_t.ptr_u_t>(ptr_u);
51
+ // actually load and return the value
52
+ return spirv::load<T,ptr_t_t>(ptr_t);
53
+ }
54
+ #else
34
55
template<class T, class U>
35
56
enable_if_t<sizeof (T)==sizeof (U),T> bit_cast (U val)
36
57
{
37
58
return spirv::bitcast<T,U>(val);
38
59
}
60
+ #endif
39
61
40
62
template<typename T, typename S>
41
63
T rotl (T x, S s);
0 commit comments