Skip to content

Commit ea92e4b

Browse files
committed
FFT Parameters
1 parent f0c6554 commit ea92e4b

File tree

5 files changed

+40
-20
lines changed

5 files changed

+40
-20
lines changed

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@
1212
layout(local_size_x=_NBL_GLSL_WORKGROUP_SIZE_, local_size_y=1, local_size_z=1) in;
1313

1414

15+
#define _NBL_GLSL_EXT_FFT_GET_PARAMETERS_DEFINED_
1516
#define _NBL_GLSL_EXT_FFT_GET_DATA_DEFINED_
1617
#define _NBL_GLSL_EXT_FFT_SET_DATA_DEFINED_
1718
#define _NBL_GLSL_EXT_FFT_GET_PADDED_DATA_DEFINED_
1819
#include "nbl/builtin/glsl/ext/FFT/fft.glsl"
1920

2021
// Input Descriptor
2122

22-
struct nbl_glsl_ext_FFT_input_t
23-
{
24-
vec2 complex_value;
25-
};
26-
2723
#ifndef _NBL_GLSL_EXT_FFT_INPUT_SET_DEFINED_
2824
#define _NBL_GLSL_EXT_FFT_INPUT_SET_DEFINED_ 0
2925
#endif
@@ -33,12 +29,12 @@ struct nbl_glsl_ext_FFT_input_t
3329
#endif
3430

3531
#ifndef _NBL_GLSL_EXT_FFT_INPUT_DESCRIPTOR_DEFINED_
32+
#define _NBL_GLSL_EXT_FFT_INPUT_DESCRIPTOR_DEFINED_
3633

3734
#if USE_SSBO_FOR_INPUT > 0
38-
#define _NBL_GLSL_EXT_FFT_INPUT_DESCRIPTOR_DEFINED_
3935
layout(set=_NBL_GLSL_EXT_FFT_INPUT_SET_DEFINED_, binding=_NBL_GLSL_EXT_FFT_INPUT_BINDING_DEFINED_) readonly restrict buffer InputBuffer
4036
{
41-
nbl_glsl_ext_FFT_input_t inData[];
37+
nbl_glsl_complex inData[];
4238
};
4339
#else
4440
layout(set=_NBL_GLSL_EXT_FFT_INPUT_SET_DEFINED_, binding=_NBL_GLSL_EXT_FFT_INPUT_BINDING_DEFINED_) uniform sampler2D inputImage;
@@ -48,12 +44,6 @@ layout(set=_NBL_GLSL_EXT_FFT_INPUT_SET_DEFINED_, binding=_NBL_GLSL_EXT_FFT_INPUT
4844

4945
// Output Descriptor
5046

51-
struct nbl_glsl_ext_FFT_output_t
52-
{
53-
vec2 complex_value;
54-
};
55-
56-
5747
#ifndef _NBL_GLSL_EXT_FFT_OUTPUT_SET_DEFINED_
5848
#define _NBL_GLSL_EXT_FFT_OUTPUT_SET_DEFINED_ 0
5949
#endif
@@ -66,22 +56,27 @@ struct nbl_glsl_ext_FFT_output_t
6656
#define _NBL_GLSL_EXT_FFT_OUTPUT_DESCRIPTOR_DEFINED_
6757
layout(set=_NBL_GLSL_EXT_FFT_OUTPUT_SET_DEFINED_, binding=_NBL_GLSL_EXT_FFT_OUTPUT_BINDING_DEFINED_) restrict buffer OutputBuffer
6858
{
69-
nbl_glsl_ext_FFT_output_t outData[];
59+
nbl_glsl_complex outData[];
7060
};
7161
#endif
7262

7363
// Get/Set Data Function
7464

65+
nbl_glsl_ext_FFT_Parameters_t nbl_glsl_ext_FFT_getParameters() {
66+
nbl_glsl_ext_FFT_Parameters_t ret;
67+
return ret;
68+
}
69+
7570
nbl_glsl_complex nbl_glsl_ext_FFT_getData(in uvec3 coordinate, in uint channel)
7671
{
77-
vec2 retValue = vec2(0, 0);
72+
nbl_glsl_complex retValue = nbl_glsl_complex(0, 0);
7873
#if USE_SSBO_FOR_INPUT > 0
7974
uvec3 dimension = pc.dimension;
8075
uint index = channel * (dimension.x * dimension.y * dimension.z) + coordinate.z * (dimension.x * dimension.y) + coordinate.y * (dimension.x) + coordinate.x;
81-
retValue = inData[index].complex_value;
76+
retValue = inData[index];
8277
#else
8378
vec4 texelValue= texelFetch(inputImage, ivec2(coordinate.xy), 0);
84-
retValue = vec2(texelValue[channel], 0.0f);
79+
retValue = nbl_glsl_complex(texelValue[channel], 0.0f);
8580
#endif
8681
return retValue;
8782
}
@@ -90,7 +85,7 @@ void nbl_glsl_ext_FFT_setData(in uvec3 coordinate, in uint channel, in nbl_glsl_
9085
{
9186
uvec3 dimension = pc.padded_dimension;
9287
uint index = channel * (dimension.x * dimension.y * dimension.z) + coordinate.z * (dimension.x * dimension.y) + coordinate.y * (dimension.x) + coordinate.x;
93-
outData[index].complex_value = complex_value;
88+
outData[index] = complex_value;
9489
}
9590

9691
nbl_glsl_complex nbl_glsl_ext_FFT_getPaddedData(in uvec3 coordinate, in uint channel) {

include/nbl/builtin/glsl/ext/FFT/fft.glsl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// Shared Memory
1111
#include <nbl/builtin/glsl/workgroup/shared_arithmetic.glsl>
1212
#include <nbl/builtin/glsl/math/functions.glsl>
13+
#include <nbl/builtin/glsl/ext/FFT/parameters.glsl>
1314

1415

1516
#ifndef _NBL_GLSL_EXT_FFT_MAX_DIM_SIZE_
@@ -56,6 +57,11 @@ layout(push_constant) uniform PushConstants
5657
} pc;
5758
#endif
5859

60+
#ifndef _NBL_GLSL_EXT_FFT_GET_PARAMETERS_DECLARED_
61+
#define _NBL_GLSL_EXT_FFT_GET_PARAMETERS_DECLARED_
62+
nbl_glsl_ext_FFT_Parameters_t nbl_glsl_ext_FFT_getParameters();
63+
#endif
64+
5965
#ifndef _NBL_GLSL_EXT_FFT_GET_DATA_DECLARED_
6066
#define _NBL_GLSL_EXT_FFT_GET_DATA_DECLARED_
6167
vec2 nbl_glsl_ext_FFT_getData(in uvec3 coordinate, in uint channel);
@@ -71,6 +77,9 @@ void nbl_glsl_ext_FFT_setData(in uvec3 coordinate, in uint channel, in vec2 comp
7177
vec2 nbl_glsl_ext_FFT_getPaddedData(in uvec3 coordinate, in uint channel);
7278
#endif
7379

80+
#ifndef _NBL_GLSL_EXT_FFT_GET_PARAMETERS_DEFINED_
81+
#error "You need to define `nbl_glsl_ext_FFT_getParameters` and mark `_NBL_GLSL_EXT_FFT_GET_PARAMETERS_DEFINED_`!"
82+
#endif
7483
#ifndef _NBL_GLSL_EXT_FFT_GET_DATA_DEFINED_
7584
#error "You need to define `nbl_glsl_ext_FFT_getData` and mark `_NBL_GLSL_EXT_FFT_GET_DATA_DEFINED_`!"
7685
#endif
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
5+
#ifndef _NBL_GLSL_EXT_FFT_PARAMETERS_INCLUDED_
6+
#define _NBL_GLSL_EXT_FFT_PARAMETERS_INCLUDED_
7+
8+
struct nbl_glsl_ext_FFT_Parameters_t
9+
{
10+
uvec3 dimension;
11+
uint direction_isInverse_paddingType; // packed into a uint
12+
uvec3 padded_dimension;
13+
};
14+
15+
#endif

src/nbl/builtin/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ set(nbl_resources_to_embed
130130
#"nbl/builtin/glsl/ext/.glsl"
131131
"nbl/builtin/glsl/ext/FFT/default_compute_fft.comp"
132132
"nbl/builtin/glsl/ext/FFT/fft.glsl"
133+
"nbl/builtin/glsl/ext/FFT/parameters.glsl"
133134
"nbl/builtin/glsl/ext/FFT/normalization.comp"
134135
"nbl/builtin/glsl/ext/LumaMeter/common.glsl"
135136
"nbl/builtin/glsl/ext/LumaMeter/impl.glsl"

src/nbl/ext/FFT/FFT.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ R"===(#version 430 core
107107
const size_t extraSize = 32 + 32 + 32 + 32;
108108

109109
const uint32_t maxItemsPerThread = (maxPaddedDimensionSize - 1u) / (DEFAULT_WORK_GROUP_SIZE) + 1u;
110-
const uint32_t useSSBO = (DataType::SSBO == inputType) ? 1 : 0;
110+
const uint32_t useSSBOforInput = (DataType::SSBO == inputType) ? 1 : 0;
111111
auto shader = core::make_smart_refctd_ptr<ICPUBuffer>(strlen(sourceFmt)+extraSize+1u);
112112
snprintf(
113113
reinterpret_cast<char*>(shader->getPointer()),shader->getSize(), sourceFmt,
114-
useSSBO,
114+
useSSBOforInput,
115115
DEFAULT_WORK_GROUP_SIZE,
116116
maxPaddedDimensionSize,
117117
maxItemsPerThread

0 commit comments

Comments
 (0)