Skip to content

Commit 29dadfb

Browse files
committed
Changes made to bit ordering function
1 parent bb3cae5 commit 29dadfb

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

include/nbl/builtin/hlsl/fft/common.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ complex_t<Scalar> twiddle(uint32_t k, uint32_t halfN)
2121
const Scalar kthRootAngleRadians = numbers::pi<Scalar> * Scalar(k) / Scalar(halfN);
2222
retVal.real( cos(kthRootAngleRadians) );
2323
if (! inverse)
24-
retVal.imag( sin(kthRootAngleRadians) );
25-
else
2624
retVal.imag( sin(-kthRootAngleRadians) );
25+
else
26+
retVal.imag( sin(kthRootAngleRadians) );
2727
return retVal;
2828
}
2929

include/nbl/builtin/hlsl/workgroup/fft.hlsl

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,33 +130,26 @@ enable_if_t<H <= N, uint32_t> bitShiftLeftHigher(uint32_t i)
130130
return mid | high | low;
131131
}
132132

133-
// For an N-bit number, mirrors it around the Nyquist frequency, which for the range [0, 2^N - 1] is precisely 2^(N - 1)
134-
template<uint32_t N>
135-
uint32_t mirror(uint32_t i)
136-
{
137-
return ((1 << N) - i) & ((1 << N) - 1)
138-
}
139-
140133
// This function maps the index `idx` in the output array of a Forward FFT to the index `freqIdx` in the DFT such that `DFT[freqIdx] = output[idx]`
141134
// This is because Cooley-Tukey + subgroup operations end up spewing out the outputs in a weird order
142135
template<uint16_t ElementsPerInvocation, uint32_t WorkgroupSize>
143-
uint32_t getFrequencyAt(uint32_t idx)
136+
uint32_t getFrequencyIndex(uint32_t outputIdx)
144137
{
145138
NBL_CONSTEXPR_STATIC_INLINE uint32_t ELEMENTS_PER_INVOCATION_LOG_2 = uint32_t(mpl::log2<ElementsPerInvocation>::value);
146139
NBL_CONSTEXPR_STATIC_INLINE uint32_t FFT_SIZE_LOG_2 = ELEMENTS_PER_INVOCATION_LOG_2 + uint32_t(mpl::log2<WorkgroupSize>::value);
147140

148-
return mirror<FFT_SIZE_LOG_2>(bitShiftRightHigher<FFT_SIZE_LOG_2, FFT_SIZE_LOG_2 - ELEMENTS_PER_INVOCATION_LOG_2 + 1>(glsl::bitfieldReverse<uint32_t>(idx) >> (32 - FFT_SIZE_LOG_2)));
141+
return bitShiftRightHigher<FFT_SIZE_LOG_2, FFT_SIZE_LOG_2 - ELEMENTS_PER_INVOCATION_LOG_2 + 1>(glsl::bitfieldReverse<uint32_t>(outputIdx) >> (32 - FFT_SIZE_LOG_2));
149142
}
150143

151144
// This function maps the index `freqIdx` in the DFT to the index `idx` in the output array of a Forward FFT such that `DFT[freqIdx] = output[idx]`
152-
// It is essentially the inverse of `getFrequencyAt`
145+
// It is essentially the inverse of `getFrequencyIndex`
153146
template<uint16_t ElementsPerInvocation, uint32_t WorkgroupSize>
154-
uint32_t getOutputAt(uint32_t freqIdx)
147+
uint32_t getOutputIndex(uint32_t freqIdx)
155148
{
156149
NBL_CONSTEXPR_STATIC_INLINE uint32_t ELEMENTS_PER_INVOCATION_LOG_2 = uint32_t(mpl::log2<ElementsPerInvocation>::value);
157150
NBL_CONSTEXPR_STATIC_INLINE uint32_t FFT_SIZE_LOG_2 = ELEMENTS_PER_INVOCATION_LOG_2 + uint32_t(mpl::log2<WorkgroupSize>::value);
158151

159-
return glsl::bitfieldReverse<uint32_t>(bitShiftLeftHigher<FFT_SIZE_LOG_2, FFT_SIZE_LOG_2 - ELEMENTS_PER_INVOCATION_LOG_2 + 1>(mirror<FFT_SIZE_LOG_2>(freqIdx))) >> (32 - FFT_SIZE_LOG_2);
152+
return glsl::bitfieldReverse<uint32_t>(bitShiftLeftHigher<FFT_SIZE_LOG_2, FFT_SIZE_LOG_2 - ELEMENTS_PER_INVOCATION_LOG_2 + 1>(freqIdx)) >> (32 - FFT_SIZE_LOG_2);
160153
}
161154

162155
} //namespace fft

0 commit comments

Comments
 (0)