Skip to content

Commit f75f284

Browse files
Merge branch 'master' into spirv_intrinsics
2 parents 216ede9 + 2ca31a5 commit f75f284

File tree

13 files changed

+480
-70
lines changed

13 files changed

+480
-70
lines changed

3rdparty/dxc/Readme.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# How to update the DXC module
2+
3+
## FIRST TIME SETUP: Make sure you have the correct remotes!
4+
5+
The following submodules as initialized on your system should have `origin` pointing at the `[email protected]:Devsh-Graphics-Programming` fork.
6+
7+
Then a remote `Khronos` for the SPIR-V submodules, and `Microsoft` for the DXC.
8+
9+
If they don't then you can correct that with `git remote add [RemoteName] [email protected]:[Organisation]/[Repo-Name].git` and `git remote remove [RemoteName]`
10+
11+
## IF YOU GET `There is no tracking information for the current branch`
12+
13+
just make the branch track the origin
14+
```
15+
git branch --set-upstream-to=origin/[BranchName] [BranchName]
16+
```
17+
18+
## Its Basically an Depth First Search with a Prologue and Epilogue
19+
20+
```
21+
checkout correct branch HEAD
22+
[optional] Merge latest stuff from original project
23+
recurse()
24+
commit
25+
push
26+
```
27+
28+
### First make sure you're on some Nabla branch Head
29+
30+
Just `git pull` and make sure you're tracking a branch.
31+
32+
### Make sure DXC is tracked and pointing at HEAD
33+
34+
```
35+
cd ./3rdparty/dxc/dxc
36+
git fetch
37+
git checkout devshFixes
38+
git pull
39+
```
40+
41+
### SPIR-V Headers: track & get latest head, merge latest upstream, commit and push
42+
43+
```
44+
cd ./external/SPIRV-Headers
45+
git fetch
46+
git checkout header_4_hlsl
47+
git pull
48+
git pull Khronos main
49+
git commit -m "latest Khronos `main` merge"
50+
git push
51+
```
52+
53+
### SPIR-V Tools: track & get latest head, merge latest upstream, commit and push
54+
55+
```
56+
cd ../SPIRV-Tools
57+
git fetch
58+
git checkout main
59+
git pull
60+
git pull Khronos main
61+
git commit -m "latest Khronos `main` merge"
62+
git push
63+
```
64+
65+
### Back to DXC and commit the submodule pointer changes
66+
67+
```
68+
cd ..
69+
git add .
70+
git commit -m "Update SPIR-V Headers and Tools"
71+
cd ..
72+
[optional] git pull Microsoft main
73+
[optional] git commit -m "merge upstream from Microsoft"
74+
git push
75+
```
76+
77+
The reason the upstream from Microsoft is optional is because it might break our Clang hacks like:
78+
- abuse of `__decltype`
79+
- `inout` working like a reference, but only sometimes
80+
- abuse of reference type
81+
82+
### Finally commit the change of DXC commit pointer to Nabla
83+
84+
```
85+
cd ..
86+
git add dxc
87+
git commit -m "Updated DXC"
88+
git push
89+
```

3rdparty/dxc/dxc

Submodule dxc updated 282 files

include/nbl/builtin/hlsl/bit.hlsl

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef _NBL_BUILTIN_HLSL_BIT_INCLUDED_
22
#define _NBL_BUILTIN_HLSL_BIT_INCLUDED_
33

4+
#include <nbl/builtin/hlsl/spirv_intrinsics/core.hlsl>
45
#include <nbl/builtin/hlsl/cpp_compat.hlsl>
56

67
#ifndef __HLSL_VERSION
@@ -12,6 +13,7 @@ namespace nbl::hlsl
1213
NBL_ALIAS_TEMPLATE_FUNCTION(std::rotl, rotl);
1314
NBL_ALIAS_TEMPLATE_FUNCTION(std::rotr, rotr);
1415
NBL_ALIAS_TEMPLATE_FUNCTION(std::countl_zero, countl_zero);
16+
NBL_ALIAS_TEMPLATE_FUNCTION(std::bit_cast, bit_cast);
1517

1618
}
1719
#else
@@ -20,6 +22,13 @@ namespace nbl
2022
namespace hlsl
2123
{
2224

25+
template<class T, class U>
26+
T bit_cast(U val)
27+
{
28+
static_assert(sizeof(T) <= sizeof(U));
29+
return spirv::bitcast<T, U>(val);
30+
}
31+
2332
template<typename T, typename S>
2433
T rotl(T x, S s);
2534
template<typename T, typename S>
@@ -57,21 +66,29 @@ T rotr(T x, S s)
5766
}
5867
}
5968

60-
template<typename T>
61-
uint16_t countl_zero(T n)
69+
namespace impl
6270
{
63-
uint16_t result = 0u;
64-
for(int32_t bits_log2=6; bits_log2>=0; bits_log2--)
65-
{
66-
const uint16_t shift = bits_log2 ? uint16_t(1)<<(bits_log2-1) : 0;
67-
const uint64_t loMask = bits_log2 ? (1ull<<shift)-1 : 0;
68-
const bool chooseHigh = n&(loMask<<shift);
69-
n = uint16_t((chooseHigh ? (n>shift):n)&loMask);
71+
template<uint16_t bits>
72+
uint16_t clz(uint64_t N)
73+
{
74+
static const uint64_t SHIFT = bits>>1;
75+
static const uint64_t LO_MASK = (1ull<<SHIFT)-1;
76+
const bool CHOOSE_HIGH = N & (LO_MASK<<SHIFT);
77+
const uint64_t NEXT = (CHOOSE_HIGH ? (N>>SHIFT):N)&LO_MASK;
78+
const uint16_t value = uint16_t(clz<SHIFT>(NEXT) + (CHOOSE_HIGH ? 0:SHIFT));
79+
return value;
80+
}
7081

71-
result += uint16_t(chooseHigh ? 0ull : shift);
72-
}
7382

74-
return result;
83+
template<>
84+
uint16_t clz<1>(uint64_t N) { return uint16_t(1u-N&1); }
85+
86+
}
87+
88+
template<typename T>
89+
uint16_t countl_zero(T n)
90+
{
91+
return impl::clz<sizeof(T)*8>(n);
7592
}
7693

7794
}

include/nbl/builtin/hlsl/cpp_compat.hlsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#ifndef _NBL_BUILTIN_HLSL_CPP_COMPAT_INCLUDED_
22
#define _NBL_BUILTIN_HLSL_CPP_COMPAT_INCLUDED_
33

4+
#include <nbl/builtin/hlsl/macros.h>
45

56
#ifndef __HLSL_VERSION
67
#include <type_traits>
8+
#include <bit>
79

810
#define ARROW ->
911
#define NBL_CONSTEXPR constexpr
12+
#define NBL_CONSTEXPR_STATIC constexpr static
1013
#define NBL_CONSTEXPR_STATIC_INLINE constexpr static inline
1114

1215
#define NBL_ALIAS_TEMPLATE_FUNCTION(origFunctionName, functionAlias) \
@@ -33,7 +36,6 @@ using add_pointer = std::add_pointer<T>;
3336
// it includes vector and matrix
3437
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.h>
3538

36-
3739
#else
3840

3941
#define ARROW .arrow().

include/nbl/builtin/hlsl/cpp_compat/matrix.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ NBL_TYPEDEF_MATRICES_FOR_SCALAR(int64_t);
7474
NBL_TYPEDEF_MATRICES_FOR_SCALAR(uint16_t);
7575
NBL_TYPEDEF_MATRICES_FOR_SCALAR(uint32_t);
7676
NBL_TYPEDEF_MATRICES_FOR_SCALAR(uint64_t);
77-
// TODO: halfMxN with std::float16_t
77+
NBL_TYPEDEF_MATRICES_FOR_SCALAR(float16_t);
7878
NBL_TYPEDEF_MATRICES_FOR_SCALAR(float32_t);
7979
NBL_TYPEDEF_MATRICES_FOR_SCALAR(float64_t);
8080

include/nbl/builtin/hlsl/cpp_compat/vector.hlsl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <glm/glm.hpp>
88
#include <glm/detail/_swizzle.hpp>
99
#include <stdint.h>
10+
#include <openexr/IlmBase/Half/half.h>
1011

1112
namespace nbl::hlsl
1213
{
@@ -32,6 +33,12 @@ using uint32_t1 = vector<uint32_t, 1>;
3233

3334
// TODO: halfN -> needs class implementation or C++23 std:float16_t
3435

36+
using float16_t = half;
37+
using float16_t4 = vector<float16_t, 4>;
38+
using float16_t3 = vector<float16_t, 3>;
39+
using float16_t2 = vector<float16_t, 2>;
40+
using float16_t1 = vector<float16_t, 1>;
41+
3542
using float32_t = float;
3643
using float32_t4 = vector<float32_t, 4>;
3744
using float32_t3 = vector<float32_t, 3>;

0 commit comments

Comments
 (0)