Skip to content

Commit a26761c

Browse files
committed
Merge branch 'master' into more_fft_utils
2 parents f74a361 + 0add2e3 commit a26761c

24 files changed

+460
-90
lines changed

3rdparty/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ option(WITH_JAVA "libjpeg-turbo" OFF)
180180
set(CMAKE_INSTALL_DOCDIR "${CMAKE_CURRENT_BINARY_DIR}/libjpeg-turbo/install/docdir")
181181
set(CMAKE_INSTALL_MANDIR "${CMAKE_CURRENT_BINARY_DIR}/libjpeg-turbo/install/mandir")
182182
add_subdirectory(libjpeg-turbo libjpeg-turbo EXCLUDE_FROM_ALL)
183+
NBL_TARGET_FORCE_ASSEMBLER_EXECUTABLE(simd ASM_NASM libjpeg-turbo/simd/)
184+
183185
unset(CMAKE_INSTALL_DOCDIR)
184186
unset(CMAKE_INSTALL_MANDIR)
185187

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ include(ExternalProject)
1313
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchains/android/build.cmake)
1414

1515
project(Nabla LANGUAGES CXX C)
16-
enable_language(C CXX ASM)
16+
enable_language(C CXX ASM ASM_NASM)
17+
18+
if(MSVC)
19+
enable_language(ASM_MASM)
20+
endif()
1721

1822
option(NBL_STATIC_BUILD "" OFF) # ON for static builds, OFF for shared
1923
option(NBL_DYNAMIC_MSVC_RUNTIME "" ON)
@@ -30,7 +34,7 @@ endif()
3034
if(NBL_STATIC_BUILD)
3135
message(STATUS "Static Nabla build enabled!")
3236
else()
33-
if(WIN32 AND MSVC)
37+
if(MSVC)
3438
if(NBL_DYNAMIC_MSVC_RUNTIME)
3539
message(STATUS "Shared Nabla build enabled!")
3640
else()

CMakePresets.json

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"minor": 29,
66
"patch": 2
77
},
8-
98
"configurePresets": [
109
{
1110
"name": "ci-configure-base",
@@ -109,21 +108,27 @@
109108
"inherits": "ci-configure-static-windows-base",
110109
"displayName": "[CI]: Static library target, Ninja multi-config generator",
111110
"description": "Configure as static library with Ninja multi-config generator",
112-
"generator": "Ninja Multi-Config"
111+
"generator": "Ninja Multi-Config",
112+
"cacheVariables": {
113+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
114+
}
113115
},
114116
{
115117
"name": "ci-configure-dynamic-ninja-multi",
116118
"inherits": "ci-configure-dynamic-windows-base",
117119
"displayName": "[CI]: Dynamic library target, Ninja multi-config generator",
118120
"description": "Configure as dynamic library with Ninja multi-config generator",
119-
"generator": "Ninja Multi-Config"
121+
"generator": "Ninja Multi-Config",
122+
"cacheVariables": {
123+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
124+
}
120125
},
121126
{
122127
"name": "user-configure-base",
123128
"hidden": true,
124129
"cacheVariables": {
125130
"NBL_CI_MODE": "OFF",
126-
"NBL_UPDATE_GIT_SUBMODULE": "ON",
131+
"NBL_UPDATE_GIT_SUBMODULE": "OFF",
127132
"NBL_RUN_TESTS": "OFF",
128133
"NBL_CPACK_CI": "OFF"
129134
}
@@ -193,14 +198,20 @@
193198
"inherits": "user-configure-static-windows-base",
194199
"displayName": "[USER]: Static library target, Ninja multi-config generator",
195200
"description": "Configure as static library with Ninja multi-config generator",
196-
"generator": "Ninja Multi-Config"
201+
"generator": "Ninja Multi-Config",
202+
"cacheVariables": {
203+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
204+
}
197205
},
198206
{
199207
"name": "user-configure-dynamic-ninja-multi",
200208
"inherits": "user-configure-dynamic-windows-base",
201209
"displayName": "[USER]: Dynamic library target, Ninja multi-config generator",
202210
"description": "Configure as dynamic library with Ninja multi-config generator",
203-
"generator": "Ninja Multi-Config"
211+
"generator": "Ninja Multi-Config",
212+
"cacheVariables": {
213+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
214+
}
204215
},
205216
{
206217
"name": "user-configure-static-ninja-release",
@@ -209,7 +220,8 @@
209220
"description": "Configure as static Release library with Ninja single-config generator",
210221
"generator": "Ninja",
211222
"cacheVariables": {
212-
"CMAKE_BUILD_TYPE": "Release"
223+
"CMAKE_BUILD_TYPE": "Release",
224+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
213225
}
214226
},
215227
{
@@ -219,7 +231,8 @@
219231
"description": "Configure as dynamic Release library with Ninja single-config generator",
220232
"generator": "Ninja",
221233
"cacheVariables": {
222-
"CMAKE_BUILD_TYPE": "Release"
234+
"CMAKE_BUILD_TYPE": "Release",
235+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
223236
}
224237
},
225238
{
@@ -229,7 +242,8 @@
229242
"description": "Configure as static RelWithDebInfo library with Ninja single-config generator",
230243
"generator": "Ninja",
231244
"cacheVariables": {
232-
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
245+
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
246+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
233247
}
234248
},
235249
{
@@ -239,7 +253,8 @@
239253
"description": "Configure as dynamic RelWithDebInfo library with Ninja single-config generator",
240254
"generator": "Ninja",
241255
"cacheVariables": {
242-
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
256+
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
257+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
243258
}
244259
},
245260
{
@@ -249,7 +264,8 @@
249264
"description": "Configure as static Debug library with Ninja single-config generator",
250265
"generator": "Ninja",
251266
"cacheVariables": {
252-
"CMAKE_BUILD_TYPE": "Debug"
267+
"CMAKE_BUILD_TYPE": "Debug",
268+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
253269
}
254270
},
255271
{
@@ -259,7 +275,8 @@
259275
"description": "Configure as dynamic Debug library with Ninja single-config generator",
260276
"generator": "Ninja",
261277
"cacheVariables": {
262-
"CMAKE_BUILD_TYPE": "Debug"
278+
"CMAKE_BUILD_TYPE": "Debug",
279+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
263280
}
264281
}
265282
],
@@ -413,7 +430,6 @@
413430
"displayName": "[USER]: Dynamic Debug library target, Ninja single-config generator",
414431
"description": "Build Nabla as dynamic Debug library with Ninja single-config generator"
415432
}
416-
417433
],
418434
"packagePresets": [
419435
{

cmake/common.cmake

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,4 +1321,15 @@ function(NBL_IMPORT_VS_CONFIG)
13211321
message(FATAL_ERORR "Cannot request importing VS config, doesn't meet requirements!")
13221322
endif()
13231323

1324-
endfunction()
1324+
endfunction()
1325+
1326+
macro(NBL_TARGET_FORCE_ASSEMBLER_EXECUTABLE _NBL_TARGET_ _NBL_ASM_DIALECT_ _NBL_PREPEND_PATH_TRANSFORM_)
1327+
get_target_property(_NBL_TARGET_SOURCES_ "${_NBL_TARGET_}" SOURCES)
1328+
list(FILTER _NBL_TARGET_SOURCES_ INCLUDE REGEX "\\.asm$")
1329+
list(TRANSFORM _NBL_TARGET_SOURCES_ PREPEND "${_NBL_PREPEND_PATH_TRANSFORM_}")
1330+
1331+
set_source_files_properties(${_NBL_TARGET_SOURCES_}
1332+
TARGET_DIRECTORY "${_NBL_TARGET_}"
1333+
PROPERTIES LANGUAGE "${_NBL_ASM_DIALECT_}"
1334+
)
1335+
endmacro()

docs/build/WINDOWS.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,23 @@ You also have options `BUILD_EXAMPLES` and `BUILD_TOOLS` which do exactly what t
4646

4747
For Windows *MSVC* required, *MinGW* build system maintenance will be delegated to the community.
4848

49-
### Ninja Multi-Config generator
49+
### Ninja Multi-Config generator & MSVC
5050

51-
The target toolset is MSVC. Before invoking CMake you need to [initialize VS's environment](https://learn.microsoft.com/en-us/cpp/build/cmake-presets-vs?view=msvc-170#sourcing-the-environment-when-building-with-command-line-generators-on-windows) by calling
51+
#### Command line
52+
53+
Open command line, init MSVC [toolset environment](https://learn.microsoft.com/en-us/cpp/build/cmake-presets-vs?view=msvc-170#sourcing-the-environment-when-building-with-command-line-generators-on-windows) by calling
5254

5355
```cmd
5456
vcvarsall.bat <platform>
5557
```
5658

57-
in your cmd (eg. `vcvarsall.bat x64` call will initialize environment for amd64, for more info go [here](https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170#vcvarsall-syntax)). Once initialization is done you can use Ninja CMake preset to build Nabla, eg.
59+
(eg. `vcvarsall.bat x64` call will initialize environment for amd64, for more info see [following](https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170#vcvarsall-syntax)). Once initialized fire a ninja preset.
5860

5961
```cmd
62+
cmake --preset user-configure-dynamic-ninja-multi
6063
cmake --build --preset user-build-dynamic-ninja-multi --config Debug -- --quiet
6164
```
6265

63-
The build preset will pick configure preset associated with it and invoke configure then build. Pay attention that if you don't initialize VS's environment the following will fail to compile with MSVC toolset.
66+
#### With Visual Studio
67+
68+
Follow VS [tutorial](https://learn.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=msvc-170).
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#ifndef _NBL_HLSL_FORMAT_OCTAHEDRAL_HLSL_
2+
#define _NBL_HLSL_FORMAT_OCTAHEDRAL_HLSL_
3+
4+
#include "nbl/builtin/hlsl/cpp_compat.hlsl"
5+
#include "nbl/builtin/hlsl/type_traits.hlsl"
6+
#include "nbl/builtin/hlsl/limits.hlsl"
7+
8+
namespace nbl
9+
{
10+
namespace hlsl
11+
{
12+
namespace format
13+
{
14+
15+
template<typename UintT, uint16_t Bits=sizeof(UintT)*4>
16+
struct octahedral// : enable_if_t<Bits*2>sizeof(UintT)||Bits*4<sizeof(UintT)> need a way to static_assert in SPIRV!
17+
{
18+
using this_t = octahedral<UintT,Bits>;
19+
using storage_t = UintT;
20+
21+
NBL_CONSTEXPR_STATIC_INLINE uint16_t BitsUsed = Bits;
22+
23+
bool operator==(const this_t other)
24+
{
25+
return storage==other.storage;
26+
}
27+
bool operator!=(const this_t other)
28+
{
29+
return storage==other.storage;
30+
}
31+
32+
storage_t storage;
33+
};
34+
35+
}
36+
37+
// https://www.shadertoy.com/view/Mtfyzl
38+
namespace impl
39+
{
40+
// TODO: remove after the `emulated_float` merge
41+
template<typename T, typename U>
42+
struct _static_cast_helper;
43+
44+
// decode
45+
template<typename float_t, typename UintT, uint16_t Bits>
46+
struct _static_cast_helper<vector<float_t,3>,format::octahedral<UintT,Bits> >
47+
{
48+
using T = vector<float_t,3>;
49+
using U = format::octahedral<UintT,Bits>;
50+
51+
T operator()(U val)
52+
{
53+
using storage_t = typename U::storage_t;
54+
const storage_t MaxVal = (storage_t(1)<<U::BitsUsed)-1u;
55+
56+
// NOTE: We Assume the top unused bits are clean!
57+
const vector<float_t,2> v = vector<float_t,2>(val.storage&MaxVal,val.storage>>U::BitsUsed) / (vector<float_t,2>(MaxVal,MaxVal)*0.5) - vector<float_t,2>(1,1);
58+
59+
// Rune Stubbe's version, much faster than original
60+
vector<float_t,3> nor = vector<float_t,3>(v,float_t(1)-abs(v.x)-abs(v.y));
61+
const float_t t = max(-nor.z,float_t(0));
62+
// TODO: improve the copysign with `^` and a sign mask
63+
nor.x += (nor.x>0.0) ? -t:t;
64+
nor.y += (nor.y>0.0) ? -t:t;
65+
66+
return normalize(nor);
67+
}
68+
};
69+
// encode
70+
template<typename UintT, uint16_t Bits, typename float_t>
71+
struct _static_cast_helper<format::octahedral<UintT,Bits>,vector<float_t,3> >
72+
{
73+
using T = format::octahedral<UintT,Bits>;
74+
using U = vector<float_t,3>;
75+
76+
T operator()(U nor)
77+
{
78+
nor /= (abs(nor.x) + abs(nor.y) + abs(nor.z));
79+
if (nor.z<float_t(0)) // TODO: faster sign copy
80+
nor.xy = (float_t(1)-abs(nor.yx))*sign(nor.xy);
81+
82+
vector<float_t,2> v = nor.xy*float_t(0.5)+vector<float_t,2>(0.5,0.5);
83+
84+
using storage_t = typename T::storage_t;
85+
const storage_t MaxVal = (storage_t(1)<<T::BitsUsed)-1u;
86+
const vector<storage_t,2> d = vector<storage_t,2>(v*float_t(MaxVal)+vector<float_t,2>(0.5,0.5));
87+
88+
T retval;
89+
retval.storage = (d.y<<T::BitsUsed)|d.x;
90+
return retval;
91+
}
92+
};
93+
}
94+
95+
}
96+
}
97+
#endif

0 commit comments

Comments
 (0)