OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
glfft.hpp
Go to the documentation of this file.
1 /* Copyright (C) 2015 Hans-Kristian Arntzen <maister@archlinux.us>
2  *
3  * Permission is hereby granted, free of charge,
4  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
5  * to deal in the Software without restriction, including without limitation the rights to
6  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8  *
9  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
12  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17  */
18 
19 #ifndef GLFFT_HPP__
20 #define GLFFT_HPP__
21 
22 #include "glfft_common.hpp"
23 #include "glfft_wisdom.hpp"
24 #include <vector>
25 #include <unordered_map>
26 #include <limits>
27 
32 
33 namespace GLFFT
34 {
35 
36 class FFT
37 {
38  public:
56  FFT(unsigned Nx, unsigned Ny,
57  Type type, Direction direction, Target input_target, Target output_target,
58  std::shared_ptr<ProgramCache> cache, const FFTOptions &options,
59  const FFTWisdom &wisdom = FFTWisdom());
60 
75  FFT(unsigned Nx, unsigned Ny, unsigned radix, unsigned p,
76  Mode mode, Target input_target, Target output_target,
77  std::shared_ptr<ProgramCache> cache, const FFTOptions &options);
78 
89 
105  double bench(GLuint output, GLuint input,
106  unsigned warmup_iterations, unsigned iterations, unsigned dispatches_per_iteration,
107  double max_time = std::numeric_limits<double>::max());
108 
110  double get_cost() const { return cost; }
111 
113  unsigned get_num_passes() const { return passes.size(); }
114 
116  unsigned get_dimension_x() const { return size_x; }
118  unsigned get_dimension_y() const { return size_y; }
119 
126  void set_texture_offset_scale(float offset_x, float offset_y, float scale_x, float scale_y)
127  {
128  texture.offset_x = offset_x;
129  texture.offset_y = offset_y;
130  texture.scale_x = scale_x;
131  texture.scale_y = scale_y;
132  }
133 
138  void set_input_buffer_range(GLintptr offset, GLsizei size)
139  {
140  ssbo.input.offset = offset;
141  ssbo.input.size = size;
142  }
143 
148  void set_input_aux_buffer_range(GLintptr offset, GLsizei size)
149  {
150  ssbo.input_aux.offset = offset;
151  ssbo.input_aux.size = size;
152  }
153 
158  void set_output_buffer_range(GLintptr offset, GLsizei size)
159  {
160  ssbo.output.offset = offset;
161  ssbo.output.size = size;
162  }
163 
168  void set_samplers(GLuint sampler0, GLuint sampler1 = 0)
169  {
170  texture.samplers[0] = sampler0;
171  texture.samplers[1] = sampler1;
172  }
173 
174  private:
175  struct Pass
176  {
178 
179  unsigned workgroups_x;
180  unsigned workgroups_y;
181  unsigned uv_scale_x;
183  GLbitfield barriers;
184  };
185 
186  double cost = 0.0;
187 
190  std::vector<Pass> passes;
191  std::shared_ptr<ProgramCache> cache;
192 
194  GLuint compile_compute_shader(const char *src);
195  static std::string load_shader_string(const char *path);
196  static void store_shader_string(const char *path, const std::string &source);
197 
199 
200  struct
201  {
202  float offset_x = 0.0f, offset_y = 0.0f, scale_x = 1.0f, scale_y = 1.0f;
203  GLuint samplers[2] = { 0, 0 };
204  } texture;
205 
206  struct
207  {
208  struct
209  {
210  GLintptr offset = 0;
211  GLsizei size = 0;
212  } input, input_aux, output;
213  } ssbo;
214  unsigned size_x, size_y;
215 };
216 
217 }
218 
219 #endif
static void store_shader_string(const char *path, const std::string &source)
Definition: glfft.cpp:709
void ** params
Definition: gl2ext.h:143
Buffer temp_buffer_image
Definition: glfft.hpp:189
void process(GLuint output, GLuint input, GLuint input_aux=0)
Process the FFT.
Definition: glfft.cpp:1028
GLintptr offset
Definition: glfft.hpp:210
float scale_x
Definition: glfft.hpp:202
static std::string load_shader_string(const char *path)
Definition: glfft.cpp:696
GLenum GLuint GLintptr offset
Definition: gl2ext.h:629
unsigned get_dimension_y() const
Returns Ny.
Definition: glfft.hpp:118
unsigned get_dimension_x() const
Returns Nx.
Definition: glfft.hpp:116
float offset_x
Definition: glfft.hpp:202
float offset_y
Definition: glfft.hpp:202
void set_input_aux_buffer_range(GLintptr offset, GLsizei size)
Set binding range for input_aux.
Definition: glfft.hpp:148
unsigned get_num_passes() const
Returns number of passes (glDispatchCompute) in a process() call.
Definition: glfft.hpp:113
Buffer temp_buffer
Definition: glfft.hpp:188
unsigned workgroups_y
Definition: glfft.hpp:180
unsigned uv_scale_x
Definition: glfft.hpp:181
Parameters parameters
Definition: glfft.hpp:177
GLenum mode
Definition: gl2ext.h:302
GLbitfield barriers
Definition: glfft.hpp:183
GLuint build_program(const Parameters &params)
Definition: glfft.cpp:715
double cost
Definition: glfft.hpp:186
FFT(unsigned Nx, unsigned Ny, Type type, Direction direction, Target input_target, Target output_target, std::shared_ptr< ProgramCache > cache, const FFTOptions &options, const FFTWisdom &wisdom=FFTWisdom())
Creates a full FFT.
Definition: glfft.cpp:498
void set_output_buffer_range(GLintptr offset, GLsizei size)
Set binding range for output.
Definition: glfft.hpp:158
GLuint program
Definition: glfft.hpp:182
GLuint compile_compute_shader(const char *src)
Definition: glfft.cpp:944
GLsizei GLsizei GLchar * source
Definition: gl2ext.h:877
double bench(GLuint output, GLuint input, unsigned warmup_iterations, unsigned iterations, unsigned dispatches_per_iteration, double max_time=std::numeric_limits< double >::max())
Run process() multiple times, timing the results.
Definition: glfft.cpp:997
Options for FFT implementation. Defaults for performance as conservative.
struct GLFFT::FFT::@1::@2 input
void set_input_buffer_range(GLintptr offset, GLsizei size)
Set binding range for input.
Definition: glfft.hpp:138
void set_texture_offset_scale(float offset_x, float offset_y, float scale_x, float scale_y)
Sets offset and scale parameters for normalized texel coordinates when sampling textures.
Definition: glfft.hpp:126
GLsizei size
Definition: glfft.hpp:211
GLenum GLuint texture
Definition: gl2ext.h:385
GLenum type
Definition: gl2ext.h:133
float max(float x, float y)
Definition: noise.cpp:29
struct GLFFT::FFT::@1::@2 output
GLuint get_program(const Parameters &params)
Definition: glfft.cpp:340
GLenum GLuint GLintptr GLsizeiptr size
Definition: gl2ext.h:629
unsigned size_y
Definition: glfft.hpp:214
void set_samplers(GLuint sampler0, GLuint sampler1=0)
Set samplers for input textures.
Definition: glfft.hpp:168
unsigned size_x
Definition: glfft.hpp:214
unsigned workgroups_x
Definition: glfft.hpp:179
struct GLFFT::FFT::@1::@2 input_aux
double get_cost() const
Returns cost for a process() call. Only used for debugging.
Definition: glfft.hpp:110
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
std::vector< Pass > passes
Definition: glfft.hpp:190
float scale_y
Definition: glfft.hpp:202
struct GLFFT::FFT::@0 texture
GLuint samplers[2]
Definition: glfft.hpp:203
struct GLFFT::FFT::@1 ssbo
GLenum src
Definition: gl2ext.h:304
std::shared_ptr< ProgramCache > cache
Definition: glfft.hpp:191