Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More fft utils #795

Merged
merged 45 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7ca1e7d
Merge branch 'master' into more_fft_utils
Fletterio Nov 11, 2024
e2df09a
Merge branch 'master' into more_fft_utils
Fletterio Nov 12, 2024
dcc537e
More changes following Bloom PR review
Fletterio Nov 13, 2024
65bbad8
Adds ternary op for complex numbers
Fletterio Nov 19, 2024
16d3261
Merge master
Fletterio Nov 19, 2024
13dd52d
Restore submodule pointer
Fletterio Nov 19, 2024
b31705d
Merge branch 'master' into more_fft_utils
Fletterio Nov 19, 2024
e618e58
Yet more utils, such as bitreversal
Fletterio Nov 23, 2024
58d8929
Add functionality for nabla unpacking trades when doing FFT of packed…
Fletterio Dec 3, 2024
cd07b9b
Share complex types between cpp and hlsl, add mirror trade functional…
Fletterio Dec 3, 2024
ea31887
Also add fast mul by i,-i to cpp
Fletterio Dec 4, 2024
53541ff
Modify ternary operator in complex and add it as a functional struct …
Fletterio Dec 5, 2024
fdba8ce
Point at examples test master to merge Nabla master
Fletterio Dec 5, 2024
620e601
Merge branch 'master' into more_fft_utils
Fletterio Dec 5, 2024
4a16b5d
padDimensions and getOutputBufferSize rewritten so they can be shared…
Fletterio Dec 6, 2024
e61ab7a
Forgot what changed
Fletterio Dec 7, 2024
20b4e3a
adds findLSB and findMSB from std.450 to glsl_compat.hlsl
Fletterio Dec 7, 2024
9abf1de
Require concepts for Accessors for FFT
Fletterio Dec 10, 2024
f3ad5e8
Change submodule pointer so it's not changed by CMake
Fletterio Dec 10, 2024
975a7b7
Fixed accessor concepts for FFT
Fletterio Dec 11, 2024
2dc70c1
Merge branch 'master' into more_fft_utils
Fletterio Dec 11, 2024
83e0cbd
- Differentiate concepts for FFT based on ElementsPerInvocationLog2,
Fletterio Dec 11, 2024
1412b01
Renamed some parameters so they better convey intent
Fletterio Dec 12, 2024
3b72975
Comment change
Fletterio Dec 13, 2024
6a22158
Update examples submodule pointer
Fletterio Dec 13, 2024
dc10958
Merge branch 'master' into more_fft_utils
Fletterio Dec 13, 2024
f44c8d9
Merge branch 'master' into more_fft_utils
Fletterio Dec 17, 2024
e9a5b8e
SharedMemAccessor concept update
Fletterio Dec 18, 2024
a933953
Merge master
Fletterio Dec 18, 2024
3359e34
- Make most of intutil shared, deprecate the versions that were in the.h
Fletterio Dec 20, 2024
18931dd
Roll back the GLSL bitreverse change, it was fine after all
Fletterio Dec 20, 2024
d1666d4
Merge branch 'master' into more_fft_utils
Fletterio Dec 20, 2024
9f0713c
Merge branch 'bitreverse_intrinsic' into more_fft_utils
Fletterio Dec 20, 2024
47f018a
Merge branch 'bitreverse_intrinsic' into more_fft_utils
Fletterio Dec 20, 2024
0e6e31a
Change fft bitReverse name, update examples pointer submodule
Fletterio Dec 20, 2024
2eb0ffd
Merge master
Fletterio Jan 6, 2025
6401e53
Addressed PR review comments
Fletterio Jan 10, 2025
fdb7904
Move some HLSL stuff to CPP-shared
Fletterio Jan 13, 2025
4463278
Merge branch 'master' into more_fft_utils
Fletterio Jan 13, 2025
6b8714d
Moved readme over
Fletterio Jan 14, 2025
d0ed313
Seeing iof this fixes Markdown issue in gh readme
Fletterio Jan 14, 2025
d4dc129
No line break sin latex math for gh readmes
Fletterio Jan 14, 2025
6edab6d
Even worse, no two $ math mode in latex readme
Fletterio Jan 14, 2025
036c7dd
Going insane at GH readme not parding this well
Fletterio Jan 14, 2025
e8f46dd
Fixed
Fletterio Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions include/nbl/builtin/hlsl/bitreverse.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef _NBL_BUILTIN_HLSL_BITREVERSE_INCLUDED_
#define _NBL_BUILTIN_HLSL_BITREVERSE_INCLUDED_


#include <nbl/builtin/hlsl/cpp_compat.hlsl>

namespace nbl
{
namespace hlsl
{

template<typename T, uint16_t Bits NBL_FUNC_REQUIRES(is_unsigned_v<T>&& Bits <= sizeof(T) * 8)
/**
* @brief Takes the binary representation of `value` as a string of `Bits` bits and returns a value of the same type resulting from reversing the string
*
* @tparam T Type of the value to operate on.
* @tparam Bits The length of the string of bits used to represent `value`.
*
* @param [in] value The value to bitreverse.
*/
T bitReverseAs(T value)
{
return bitReverse<T>(value) >> promote<T, scalar_type_t<T> >(scalar_type_t <T>(sizeof(T) * 8 - Bits));
}

template<typename T NBL_FUNC_REQUIRES(is_unsigned_v<T>)
/**
* @brief Takes the binary representation of `value` and returns a value of the same type resulting from reversing the string of bits as if it was `bits` long.
* Keep in mind `bits` cannot exceed `8 * sizeof(T)`.
*
* @tparam T type of the value to operate on.
*
* @param [in] value The value to bitreverse.
* @param [in] bits The length of the string of bits used to represent `value`.
*/
T bitReverseAs(T value, uint16_t bits)
{
return bitReverse<T>(value) >> promote<T, scalar_type_t<T> >(scalar_type_t <T>(sizeof(T) * 8 - bits));
}


}
}



#endif
252 changes: 252 additions & 0 deletions include/nbl/builtin/hlsl/fft/README.md

Large diffs are not rendered by default.

68 changes: 45 additions & 23 deletions include/nbl/builtin/hlsl/fft/common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,63 @@ namespace hlsl
namespace fft
{

// template parameter N controls the number of dimensions of the input
// template parameter M controls the number of dimensions to pad up to PoT
// "axes" indicates which dimensions to pad up to PoT
template <uint16_t N, uint16_t M NBL_FUNC_REQUIRES(M <= N)
inline vector<uint64_t, 3> padDimensions(NBL_CONST_REF_ARG(vector<uint32_t, N>) dimensions, NBL_CONST_REF_ARG(vector<uint16_t, M>) axes, bool realFFT = false)

template <uint16_t N NBL_FUNC_REQUIRES(N > 0 && N <= 4)
/**
* @brief Returns the size of the full FFT computed, in terms of number of complex elements.
*
* @tparam N Number of dimensions of the signal to perform FFT on.
*
* @param [in] dimensions Size of the signal.
* @param [in] realFFT Indicates whether the signal is real. False by default.
* @param [in] firstAxis Indicates which axis the FFT is performed on first. Only relevant for real-valued signals. Must be less than N. 0 by default.
*/
inline vector<uint64_t, N> padDimensions(NBL_CONST_REF_ARG(vector<uint32_t, N>) dimensions, bool realFFT = false, uint16_t firstAxis = 0u)
{
vector<uint32_t, N> newDimensions = dimensions;
uint16_t axisCount = 0;
for (uint16_t i = 0u; i < M; i++)
for (uint16_t i = 0u; i < N; i++)
{
newDimensions[i] = hlsl::roundUpToPoT(newDimensions[i]);
if (realFFT && !axisCount++)
newDimensions[i] /= 2;
}
if (realFFT)
newDimensions[firstAxis] /= 2;
return newDimensions;
}

// template parameter N controls the number of dimensions of the input
// template parameter M controls the number of dimensions we run an FFT along AND store the result
// "axes" indicates which dimensions we run an FFT along AND store the result
template <uint16_t N, uint16_t M NBL_FUNC_REQUIRES(M <= N)
inline uint64_t getOutputBufferSize(NBL_CONST_REF_ARG(vector<uint32_t, N>) inputDimensions, uint32_t numChannels, NBL_CONST_REF_ARG(vector<uint16_t, M>) axes, bool realFFT = false, bool halfFloats = false)
template <uint16_t N NBL_FUNC_REQUIRES(N > 0 && N <= 4)
/**
* @brief Returns the size required by a buffer to hold the result of the FFT of a signal after a certain pass.
*
* @tparam N Number of dimensions of the signal to perform FFT on.
*
* @param [in] numChannels Number of channels of the signal.
* @param [in] inputDimensions Size of the signal.
* @param [in] passIx Which pass the size is being computed for.
* @param [in] axisPassOrder Order of the axis in which the FFT is computed in. Default is xyzw.
* @param [in] realFFT True if the signal is real. False by default.
* @param [in] halfFloats True if using half-precision floats. False by default.
*/
inline uint64_t getOutputBufferSize(
uint32_t numChannels,
NBL_CONST_REF_ARG(vector<uint32_t, N>) inputDimensions,
uint16_t passIx,
NBL_CONST_REF_ARG(vector<uint16_t, N>) axisPassOrder = _static_cast<vector<uint16_t, N> >(uint16_t4(0, 1, 2, 3)),
bool realFFT = false,
bool halfFloats = false
)
{
const vector<uint64_t, 3> paddedDims = padDimensions<N, M>(inputDimensions, axes);
const uint64_t numberOfComplexElements = paddedDims[0] * paddedDims[1] * paddedDims[2] * uint64_t(numChannels);
const vector<uint32_t, N> paddedDimensions = padDimensions<N>(inputDimensions, realFFT, axisPassOrder[0]);
vector<bool, N> axesDone = promote<vector<bool, N>, bool>(false);
for (uint16_t i = 0; i <= passIx; i++)
axesDone[axisPassOrder[i]] = true;
const vector<uint32_t, N> passOutputDimension = lerp(inputDimensions, paddedDimensions, axesDone);
uint64_t numberOfComplexElements = uint64_t(numChannels);
for (uint16_t i = 0; i < N; i++)
numberOfComplexElements *= uint64_t(passOutputDimension[i]);
return numberOfComplexElements * (halfFloats ? sizeof(complex_t<float16_t>) : sizeof(complex_t<float32_t>));
}


// Computes the kth element in the group of N roots of unity
// Notice 0 <= k < N/2, rotating counterclockwise in the forward (DIF) transform and clockwise in the inverse (DIT)
template<bool inverse, typename Scalar>
Expand Down Expand Up @@ -95,13 +124,6 @@ void unpack(NBL_REF_ARG(complex_t<Scalar>) lo, NBL_REF_ARG(complex_t<Scalar>) hi
lo = x;
}

// Bit-reverses T as a binary string of length given by Bits
template<typename T, uint16_t Bits NBL_FUNC_REQUIRES(is_integral_v<T> && Bits <= sizeof(T) * 8)
T bitReverseAs(T value)
{
return hlsl::bitReverse<uint32_t>(value) >> (sizeof(T) * 8 - Bits);
}

}
}
}
Expand Down
4 changes: 0 additions & 4 deletions include/nbl/builtin/hlsl/glsl_compat/core.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
#include "nbl/builtin/hlsl/cpp_compat/basic.h"
#include "nbl/builtin/hlsl/spirv_intrinsics/core.hlsl"
#include "nbl/builtin/hlsl/type_traits.hlsl"
<<<<<<< HEAD
#include "nbl/builtin/hlsl/bit.hlsl"
=======
#include "nbl/builtin/hlsl/spirv_intrinsics/glsl.std.450.hlsl"
>>>>>>> master

namespace nbl
{
Expand Down
3 changes: 1 addition & 2 deletions include/nbl/builtin/hlsl/math/intutil.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ NBL_CONSTEXPR_FORCED_INLINE_FUNC Integer align(Integer alignment, Integer size,
return address = nextAlignedAddr;
}

// ------------------------------------- CPP ONLY ----------------------------------------------------------
#ifndef __HLSL_VERSION

// Have to wait for the HLSL patch for `is_enum`. Would also have to figure out how to do it without initializer lists for HLSL use.

//! Get bitmask from variadic arguments passed.
/*
For example if you were to create bitmask for vertex attributes
Expand Down
Loading