Skip to content

Commit c3326d2

Browse files
lay the groundwork for half-float storage choice
1 parent 73e2537 commit c3326d2

File tree

7 files changed

+58
-18
lines changed

7 files changed

+58
-18
lines changed

examples_tests/49.ComputeFFT/fft_convolve_ifft.comp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
layout(local_size_x=_NBL_GLSL_WORKGROUP_SIZE_, local_size_y=1, local_size_z=1) in;
22

3+
#include <nbl/builtin/glsl/ext/FFT/types.glsl>
34

4-
#include <nbl/builtin/glsl/math/complex.glsl>
55
// Input and Output Descriptor
66
layout(set=0, binding=0) buffer restrict InputOutputBuffer
77
{
8-
nbl_glsl_complex inoutData[];
8+
nbl_glsl_ext_FFT_storage_t inoutData[];
99
};
1010
#define _NBL_GLSL_EXT_FFT_INPUT_DESCRIPTOR_DEFINED_
1111
#define _NBL_GLSL_EXT_FFT_OUTPUT_DESCRIPTOR_DEFINED_
@@ -25,6 +25,7 @@ nbl_glsl_ext_FFT_Parameters_t nbl_glsl_ext_FFT_getParameters()
2525
}
2626
#define _NBL_GLSL_EXT_FFT_GET_PARAMETERS_DEFINED_
2727

28+
// do I need to unrestrict these buffers?
2829
#define inData inoutData
2930
#define outData inoutData
3031
#define _NBL_GLSL_EXT_FFT_MAIN_DEFINED_

examples_tests/49.ComputeFFT/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ R"===(#version 430 core
3535
3636
#define _NBL_GLSL_WORKGROUP_SIZE_ %u
3737
#define _NBL_GLSL_EXT_FFT_MAX_DIM_SIZE_ %u
38+
#define _NBL_GLSL_EXT_FFT_HALF_STORAGE_ %u
3839
3940
#include "%s"
4041
@@ -48,6 +49,7 @@ R"===(#version 430 core
4849
reinterpret_cast<char*>(shader->getPointer()),shader->getSize(), sourceFmt,
4950
DEFAULT_WORK_GROUP_SIZE,
5051
maxPaddedDimensionSize,
52+
0u,
5153
includeMainName
5254
);
5355

@@ -596,10 +598,12 @@ int main()
596598
const FFTClass::PaddingType fftPadding[2] = {FFTClass::PaddingType::CLAMP_TO_EDGE,FFTClass::PaddingType::CLAMP_TO_EDGE}; // TODO
597599
const auto passes = FFTClass::buildParameters(false,srcNumChannels,srcDim,fftPushConstants,fftDispatchInfo,fftPadding);
598600
{
601+
fftPushConstants[1].output_strides = fftPushConstants[1].input_strides;
599602
fftPushConstants[2] = fftPushConstants[0];
600603
{
601604
fftPushConstants[2].input_dimensions.w ^= 0x80000000u;
602605
fftPushConstants[2].input_dimensions.w &= 0xfffffffdu;
606+
fftPushConstants[2].input_strides = fftPushConstants[1].output_strides;
603607
}
604608
fftDispatchInfo[2] = fftDispatchInfo[0];
605609
}

examples_tests/49.ComputeFFT/normalization.comp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#version 430 core
22
layout(local_size_x=16, local_size_y=16, local_size_z=1) in;
33

4-
#include "nbl/builtin/glsl/math/complex.glsl"
4+
#include <nbl/builtin/glsl/ext/FFT/types.glsl>
55

66
layout(set=0, binding=0) restrict readonly buffer InBuffer
77
{
8-
nbl_glsl_complex in_data[];
8+
nbl_glsl_ext_FFT_storage_t in_data[];
99
};
1010

1111
layout(set=0, binding=1, rg16f) uniform image2D NormalizedKernel[3];
@@ -18,9 +18,9 @@ layout(push_constant) uniform PushConstants
1818

1919
void main()
2020
{
21-
nbl_glsl_complex value = in_data[nbl_glsl_dot(gl_GlobalInvocationID,pc.strides.xyz)];
21+
nbl_glsl_complex value = nbl_glsl_ext_FFT_storage_t_get(in_data[nbl_glsl_dot(gl_GlobalInvocationID,pc.strides.xyz)]);
2222

23-
const float power = length(in_data[0]);
23+
const float power = length(nbl_glsl_ext_FFT_storage_t_get(in_data[0]));
2424

2525
const uvec2 coord = bitfieldReverse(gl_GlobalInvocationID.xy)>>pc.bitreverse_shift.xy;
2626
const nbl_glsl_complex shift = nbl_glsl_expImaginary(-nbl_glsl_PI*float(coord.x+coord.y));

include/nbl/builtin/glsl/ext/FFT/default_compute_fft.comp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ layout(local_size_x=_NBL_GLSL_WORKGROUP_SIZE_, local_size_y=1, local_size_z=1) i
44
#endif
55

66

7-
#include <nbl/builtin/glsl/math/complex.glsl>
7+
#include <nbl/builtin/glsl/ext/FFT/types.glsl>
88

99

1010
// Input Descriptor
@@ -22,7 +22,7 @@ layout(local_size_x=_NBL_GLSL_WORKGROUP_SIZE_, local_size_y=1, local_size_z=1) i
2222

2323
layout(set=_NBL_GLSL_EXT_FFT_INPUT_SET_DEFINED_, binding=_NBL_GLSL_EXT_FFT_INPUT_BINDING_DEFINED_) readonly restrict buffer InputBuffer
2424
{
25-
nbl_glsl_complex inData[];
25+
nbl_glsl_ext_FFT_storage_t inData[];
2626
};
2727
#endif
2828

@@ -37,16 +37,13 @@ layout(set=_NBL_GLSL_EXT_FFT_INPUT_SET_DEFINED_, binding=_NBL_GLSL_EXT_FFT_INPUT
3737

3838
#ifndef _NBL_GLSL_EXT_FFT_OUTPUT_DESCRIPTOR_DEFINED_
3939
#define _NBL_GLSL_EXT_FFT_OUTPUT_DESCRIPTOR_DEFINED_
40-
layout(set=_NBL_GLSL_EXT_FFT_OUTPUT_SET_DEFINED_, binding=_NBL_GLSL_EXT_FFT_OUTPUT_BINDING_DEFINED_) restrict buffer OutputBuffer
40+
layout(set=_NBL_GLSL_EXT_FFT_OUTPUT_SET_DEFINED_, binding=_NBL_GLSL_EXT_FFT_OUTPUT_BINDING_DEFINED_) writeonly restrict buffer OutputBuffer
4141
{
42-
nbl_glsl_complex outData[];
42+
nbl_glsl_ext_FFT_storage_t outData[];
4343
};
4444
#endif
4545

4646

47-
#include <nbl/builtin/glsl/ext/FFT/parameters.glsl>
48-
49-
5047
#ifndef _NBL_GLSL_EXT_FFT_PUSH_CONSTANTS_DEFINED_
5148
layout(push_constant) uniform PushConstants
5249
{
@@ -67,7 +64,7 @@ layout(push_constant) uniform PushConstants
6764
void nbl_glsl_ext_FFT_setData(in uvec3 coordinate, in uint channel, in nbl_glsl_complex complex_value)
6865
{
6966
const uint index = nbl_glsl_dot(uvec4(coordinate,channel),nbl_glsl_ext_FFT_Parameters_t_getOutputStrides());
70-
outData[index] = complex_value;
67+
nbl_glsl_ext_FFT_storage_t_set(outData[index],complex_value);
7168
}
7269
#define _NBL_GLSL_EXT_FFT_SET_DATA_DEFINED_
7370
#endif
@@ -87,7 +84,7 @@ nbl_glsl_complex nbl_glsl_ext_FFT_getPaddedData(in uvec3 coordinate, in uint cha
8784
}
8885

8986
const uint index = nbl_glsl_dot(uvec4(coordinate,channel),nbl_glsl_ext_FFT_Parameters_t_getInputStrides());
90-
return inData[index];
87+
return nbl_glsl_ext_FFT_storage_t_get(inData[index]);
9188
}
9289
#define _NBL_GLSL_EXT_FFT_GET_PADDED_DATA_DEFINED_
9390
#endif
@@ -101,6 +98,6 @@ nbl_glsl_complex nbl_glsl_ext_FFT_getPaddedData(in uvec3 coordinate, in uint cha
10198
void main()
10299
{
103100
for(uint ch=0u; ch<=nbl_glsl_ext_FFT_Parameters_t_getMaxChannel(); ++ch)
104-
nbl_glsl_ext_FFT(nbl_glsl_ext_FFT_Parameters_t_getIsInverse(), ch);
101+
nbl_glsl_ext_FFT(nbl_glsl_ext_FFT_Parameters_t_getIsInverse(),ch);
105102
}
106103
#endif
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#ifndef _NBL_GLSL_EXT_FFT_TYPES_INCLUDED_
5+
#define _NBL_GLSL_EXT_FFT_TYPES_INCLUDED_
6+
7+
#include <nbl/builtin/glsl/math/complex.glsl>
8+
9+
#if _NBL_GLSL_EXT_FFT_HALF_STORAGE_!=0
10+
#define nbl_glsl_ext_FFT_storage_t uint
11+
12+
nbl_glsl_complex nbl_glsl_ext_FFT_storage_t_get(in nbl_glsl_ext_FFT_storage_t _in)
13+
{
14+
return unpackHalf2x16(_in);
15+
}
16+
void nbl_glsl_ext_FFT_storage_t_set(out nbl_glsl_ext_FFT_storage_t _out, in nbl_glsl_complex _in)
17+
{
18+
_out = packHalf2x16(_in);
19+
}
20+
#else
21+
#define nbl_glsl_ext_FFT_storage_t nbl_glsl_complex
22+
23+
nbl_glsl_complex nbl_glsl_ext_FFT_storage_t_get(in nbl_glsl_ext_FFT_storage_t _in)
24+
{
25+
return _in;
26+
}
27+
void nbl_glsl_ext_FFT_storage_t_set(out nbl_glsl_ext_FFT_storage_t _out, in nbl_glsl_complex _in)
28+
{
29+
_out = _in;
30+
}
31+
#endif
32+
33+
#include <nbl/builtin/glsl/ext/FFT/parameters.glsl>
34+
35+
#endif

src/nbl/builtin/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ set(nbl_resources_to_embed
139139
"nbl/builtin/glsl/ext/FFT/fft.glsl"
140140
"nbl/builtin/glsl/ext/FFT/parameters_struct.glsl"
141141
"nbl/builtin/glsl/ext/FFT/parameters.glsl"
142+
"nbl/builtin/glsl/ext/FFT/types.glsl"
142143
"nbl/builtin/glsl/ext/LumaMeter/common.glsl"
143144
"nbl/builtin/glsl/ext/LumaMeter/impl.glsl"
144145
"nbl/builtin/glsl/ext/ToneMapper/operators.glsl"

src/nbl/ext/FFT/FFT.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,21 @@ R"===(#version 430 core
7070
7171
#define _NBL_GLSL_WORKGROUP_SIZE_ %u
7272
#define _NBL_GLSL_EXT_FFT_MAX_DIM_SIZE_ %u
73+
#define _NBL_GLSL_EXT_FFT_HALF_STORAGE_ %u
7374
7475
layout(local_size_x=_NBL_GLSL_WORKGROUP_SIZE_, local_size_y=1, local_size_z=1) in;
7576
#include "nbl/builtin/glsl/ext/FFT/default_compute_fft.comp"
7677
7778
)===";
7879

79-
constexpr size_t extraSize = 8u*2u;
80+
constexpr size_t extraSize = 8u*2u+1u;
8081

8182
auto source = core::make_smart_refctd_ptr<ICPUBuffer>(strlen(sourceFmt)+extraSize+1u);
8283
snprintf(
8384
reinterpret_cast<char*>(source->getPointer()),source->getSize(), sourceFmt,
8485
DEFAULT_WORK_GROUP_SIZE,
85-
maxPaddedDimensionSize
86+
maxPaddedDimensionSize,
87+
0u
8688
);
8789

8890
auto shader = driver->createGPUShader(core::make_smart_refctd_ptr<ICPUShader>(std::move(source),asset::ICPUShader::buffer_contains_glsl));

0 commit comments

Comments
 (0)