OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GLFFT::FFT Class Reference

#include <glfft.hpp>

Classes

struct  Pass
 

Public Member Functions

 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. More...
 
 FFT (unsigned Nx, unsigned Ny, unsigned radix, unsigned p, Mode mode, Target input_target, Target output_target, std::shared_ptr< ProgramCache > cache, const FFTOptions &options)
 Creates a single stage FFT. Used mostly internally for benchmarking partial FFTs. More...
 
void process (GLuint output, GLuint input, GLuint input_aux=0)
 Process the FFT. More...
 
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. More...
 
double get_cost () const
 Returns cost for a process() call. Only used for debugging. More...
 
unsigned get_num_passes () const
 Returns number of passes (glDispatchCompute) in a process() call. More...
 
unsigned get_dimension_x () const
 Returns Nx. More...
 
unsigned get_dimension_y () const
 Returns Ny. More...
 
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. More...
 
void set_input_buffer_range (GLintptr offset, GLsizei size)
 Set binding range for input. More...
 
void set_input_aux_buffer_range (GLintptr offset, GLsizei size)
 Set binding range for input_aux. More...
 
void set_output_buffer_range (GLintptr offset, GLsizei size)
 Set binding range for output. More...
 
void set_samplers (GLuint sampler0, GLuint sampler1=0)
 Set samplers for input textures. More...
 

Private Member Functions

GLuint build_program (const Parameters &params)
 
GLuint compile_compute_shader (const char *src)
 
GLuint get_program (const Parameters &params)
 

Static Private Member Functions

static std::string load_shader_string (const char *path)
 
static void store_shader_string (const char *path, const std::string &source)
 

Private Attributes

double cost = 0.0
 
Buffer temp_buffer
 
Buffer temp_buffer_image
 
std::vector< Passpasses
 
std::shared_ptr< ProgramCachecache
 
struct {
   float   offset_x = 0.0f
 
   float   offset_y = 0.0f
 
   float   scale_x = 1.0f
 
   float   scale_y = 1.0f
 
   GLuint   samplers [2] = { 0, 0 }
 
texture
 
struct {
   struct {
      GLintptr   offset = 0
 
      GLsizei   size = 0
 
   }   input
 
   struct {
      GLintptr   offset = 0
 
      GLsizei   size = 0
 
   }   input_aux
 
   struct {
      GLintptr   offset = 0
 
      GLsizei   size = 0
 
   }   output
 
ssbo
 
unsigned size_x
 
unsigned size_y
 

Detailed Description

Definition at line 36 of file glfft.hpp.

Constructor & Destructor Documentation

FFT::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.

All buffer allocation done by GLFFT will be done in constructor. Will throw if invalid parameters are passed.

Parameters
NxNumber of samples in horizontal dimension.
NyNumber of samples in vertical dimension.
typeThe transform type.
directionForward, inverse or inverse with convolution. For real-to-complex and complex-to-real transforms, the transform type must match.
input_targetGL object type of input target. For real-to-complex with texture as input, ImageReal is used.
output_targetGL object type of output target. For complex-to-real with texture as output, ImageReal is used.
cacheA program cache for caching the GLFFT programs created.
optionsFFT options such as performance related parameters and types.
wisdomGLFFT wisdom which can override performance related options (options.performance is used as a fallback).

Definition at line 498 of file glfft.cpp.

FFT::FFT ( unsigned  Nx,
unsigned  Ny,
unsigned  radix,
unsigned  p,
Mode  mode,
Target  input_target,
Target  output_target,
std::shared_ptr< ProgramCache cache,
const FFTOptions options 
)

Creates a single stage FFT. Used mostly internally for benchmarking partial FFTs.

All buffer allocation done by GLFFT will be done in constructor. Will throw if invalid parameters are passed.

Parameters
NxNumber of samples in horizontal dimension.
NyNumber of samples in vertical dimension.
radixThe FFT radix to use.
pWhich P-factor to use. Essentially, p == 1 will trigger "first pass" paths, p > 1 will trigger generic paths.
modeThe transform mode.
input_targetGL object type of input target. For real-to-complex with texture as input, ImageReal is used.
output_targetGL object type of output target. For complex-to-real with texture as output, ImageReal is used.
cacheA program cache for caching the GLFFT programs created.
optionsFFT options such as performance related parameters and types.

Definition at line 376 of file glfft.cpp.

Member Function Documentation

double FFT::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.

Mostly used internally by GLFFT wisdom, glfft_cli's bench, and so on.

Parameters
outputOutput buffer or image. NOTE: For images, the texture must be using immutable storage, i.e. glTexStorage2D!
inputInput buffer or texture.
warmup_iterationsNumber of iterations to run to "warm" up GL, ensures we don't hit recompilations or similar when benching.
iterationsNumber of iterations to run the benchmark. Each iteration will ensure timing with a glFinish() followed by timing.
dispatches_per_iterationNumber of calls to process() we should do per iteration.
max_timeThe max time the benchmark should run. Will be checked after each iteration is complete.
Returns
Average GPU time per process() call.

Definition at line 997 of file glfft.cpp.

GLuint FFT::build_program ( const Parameters params)
private

Definition at line 715 of file glfft.cpp.

GLuint FFT::compile_compute_shader ( const char *  src)
private

Definition at line 944 of file glfft.cpp.

double GLFFT::FFT::get_cost ( ) const
inline

Returns cost for a process() call. Only used for debugging.

Definition at line 110 of file glfft.hpp.

unsigned GLFFT::FFT::get_dimension_x ( ) const
inline

Returns Nx.

Definition at line 116 of file glfft.hpp.

unsigned GLFFT::FFT::get_dimension_y ( ) const
inline

Returns Ny.

Definition at line 118 of file glfft.hpp.

unsigned GLFFT::FFT::get_num_passes ( ) const
inline

Returns number of passes (glDispatchCompute) in a process() call.

Definition at line 113 of file glfft.hpp.

GLuint FFT::get_program ( const Parameters params)
private

Definition at line 340 of file glfft.cpp.

string FFT::load_shader_string ( const char *  path)
staticprivate

Definition at line 696 of file glfft.cpp.

void FFT::process ( GLuint  output,
GLuint  input,
GLuint  input_aux = 0 
)

Process the FFT.

The type of object passed here must match what FFT was initialized with.

Parameters
outputOutput buffer or image. NOTE: For images, the texture must be using immutable storage, i.e. glTexStorage2D!
inputInput buffer or texture.
input_auxIf using convolution transform type, the content of input and input_aux will be multiplied together.

Definition at line 1028 of file glfft.cpp.

void GLFFT::FFT::set_input_aux_buffer_range ( GLintptr  offset,
GLsizei  size 
)
inline

Set binding range for input_aux.

If input_aux is an SSBO, set a custom binding range to be passed to glBindBufferRange. By default, the entire buffer is bound.

Definition at line 148 of file glfft.hpp.

void GLFFT::FFT::set_input_buffer_range ( GLintptr  offset,
GLsizei  size 
)
inline

Set binding range for input.

If input is an SSBO, set a custom binding range to be passed to glBindBufferRange. By default, the entire buffer is bound.

Definition at line 138 of file glfft.hpp.

void GLFFT::FFT::set_output_buffer_range ( GLintptr  offset,
GLsizei  size 
)
inline

Set binding range for output.

If output buffer is an SSBO, set a custom binding range to be passed to glBindBufferRange. By default, the entire buffer is bound.

Definition at line 158 of file glfft.hpp.

void GLFFT::FFT::set_samplers ( GLuint  sampler0,
GLuint  sampler1 = 0 
)
inline

Set samplers for input textures.

Set sampler objects to be used for input and input_aux if textures are used as input. By default, sampler object 0 will be used (inheriting sampler parameters from the texture object itself).

Definition at line 168 of file glfft.hpp.

void GLFFT::FFT::set_texture_offset_scale ( float  offset_x,
float  offset_y,
float  scale_x,
float  scale_y 
)
inline

Sets offset and scale parameters for normalized texel coordinates when sampling textures.

By default, these values are 0.5 / size (samples in the center of texel (0, 0)). Scale is 1.0 / size, so it steps one texel for each coordinate in the FFT transform. Setting this to something custom is useful to get downsampling with GL_LINEAR -> FFT transform without having to downsample the texture first, then FFT.

Definition at line 126 of file glfft.hpp.

void FFT::store_shader_string ( const char *  path,
const std::string &  source 
)
staticprivate

Definition at line 709 of file glfft.cpp.

Member Data Documentation

std::shared_ptr<ProgramCache> GLFFT::FFT::cache
private

Definition at line 191 of file glfft.hpp.

double GLFFT::FFT::cost = 0.0
private

Definition at line 186 of file glfft.hpp.

struct { ... } GLFFT::FFT::input
struct { ... } GLFFT::FFT::input_aux
GLintptr GLFFT::FFT::offset = 0

Definition at line 210 of file glfft.hpp.

float GLFFT::FFT::offset_x = 0.0f

Definition at line 202 of file glfft.hpp.

float GLFFT::FFT::offset_y = 0.0f

Definition at line 202 of file glfft.hpp.

struct { ... } GLFFT::FFT::output
std::vector<Pass> GLFFT::FFT::passes
private

Definition at line 190 of file glfft.hpp.

GLuint GLFFT::FFT::samplers[2] = { 0, 0 }

Definition at line 203 of file glfft.hpp.

float GLFFT::FFT::scale_x = 1.0f

Definition at line 202 of file glfft.hpp.

float GLFFT::FFT::scale_y = 1.0f

Definition at line 202 of file glfft.hpp.

GLsizei GLFFT::FFT::size = 0

Definition at line 211 of file glfft.hpp.

unsigned GLFFT::FFT::size_x
private

Definition at line 214 of file glfft.hpp.

unsigned GLFFT::FFT::size_y
private

Definition at line 214 of file glfft.hpp.

struct { ... } GLFFT::FFT::ssbo
Buffer GLFFT::FFT::temp_buffer
private

Definition at line 188 of file glfft.hpp.

Buffer GLFFT::FFT::temp_buffer_image
private

Definition at line 189 of file glfft.hpp.

struct { ... } GLFFT::FFT::texture

The documentation for this class was generated from the following files: