OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
glfft_common.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 // For the most part used by the implementation.
20 
21 #ifndef GLFFT_COMMON_HPP__
22 #define GLFFT_COMMON_HPP__
23 
24 #include "glfft_interface.hpp"
25 #include <functional>
26 #include <cstddef>
27 #include <cstdlib>
28 #include <string>
29 #include <cstring>
30 #include <memory>
31 #include <unordered_map>
32 
33 namespace GLFFT
34 {
35 
37 {
39  Forward = -1,
44  Inverse = 1
45 };
46 
47 enum Mode
48 {
53 
56 };
57 
58 enum Type
59 {
69 };
70 
71 enum Target
72 {
82 };
83 
84 struct Parameters
85 {
86  unsigned workgroup_size_x;
87  unsigned workgroup_size_y;
88  unsigned workgroup_size_z;
89  unsigned radix;
90  unsigned vector_size;
95  bool p1;
100 
101  bool operator==(const Parameters &other) const
102  {
103  return std::memcmp(this, &other, sizeof(Parameters)) == 0;
104  }
105 };
106 
110 {
111  struct Performance
112  {
116  unsigned workgroup_size_x = 4;
120  unsigned workgroup_size_y = 1;
122  unsigned vector_size = 2;
125  bool shared_banked = false;
126  } performance;
127 
128  struct Type
129  {
131  bool fp16 = false;
133  bool input_fp16 = false;
135  bool output_fp16 = false;
137  bool normalize = false;
138  } type;
139 };
140 
141 }
142 
143 namespace std
144 {
145  template<>
146  struct hash<GLFFT::Parameters>
147  {
148  std::size_t operator()(const GLFFT::Parameters &params) const
149  {
150  std::size_t h = 0;
151  hash<uint8_t> hasher;
152  for (std::size_t i = 0; i < sizeof(GLFFT::Parameters); i++)
153  {
154  h ^= hasher(reinterpret_cast<const uint8_t*>(&params)[i]);
155  }
156 
157  return h;
158  }
159  };
160 }
161 
162 namespace GLFFT
163 {
164 
165 class Buffer
166 {
167  public:
168  Buffer() = default;
169  ~Buffer();
170 
172  Buffer& operator=(Buffer &&buffer);
173  Buffer(Buffer &&buffer);
174 
175  void init(const void *data, size_t size, GLenum access);
176 
177  inline GLuint get() const { return name; }
178 
179  private:
181 };
182 
183 class Texture
184 {
185  public:
186  Texture() = default;
187  ~Texture();
188 
189  Texture(GLuint tex);
192 
193  void init(unsigned width, unsigned height, unsigned levels, GLenum internal_format,
194  GLenum wrap_s = GL_REPEAT, GLenum wrap_t = GL_REPEAT,
195  GLenum min_filter = GL_NEAREST, GLenum mag_filter = GL_NEAREST);
196  void upload(const void *data, GLenum format, GLenum type,
197  unsigned x_off, unsigned y_off, unsigned width, unsigned height);
198 
199  inline GLuint get() const { return name; }
200 
201  private:
203 };
204 
205 class Program
206 {
207  public:
208  Program() = default;
209  ~Program();
210 
211  Program(GLuint prog);
212  Program& operator=(Program &&prog);
213  Program(Program &&prog);
214 
215  inline GLuint get() const { return name; }
216 
217  private:
219 };
220 
222 {
223  public:
224  GLuint find_program(const Parameters &parameters) const;
225  void insert_program(const Parameters &parameters, GLuint program);
226 
227  size_t cache_size() const { return programs.size(); }
228 
229  private:
230  std::unordered_map<Parameters, Program> programs;
231 };
232 
233 }
234 
235 #endif
236 
void ** params
Definition: gl2ext.h:143
Buffer()=default
Inverse FFT transform.
Forward FFT transform.
GLenum access
Definition: gl2ext.h:1958
Buffer & operator=(Buffer &&buffer)
GLint GLsizei GLsizei height
Definition: gl2ext.h:179
void upload(const void *data, GLenum format, GLenum type, unsigned x_off, unsigned y_off, unsigned width, unsigned height)
bool normalize
Whether to apply 1 / N normalization factor.
std::size_t operator()(const GLFFT::Parameters &params) const
Complex-to-real transform. N / 2 + 1 complex values are used per row with a stride of N complex sampl...
void init(unsigned width, unsigned height, unsigned levels, GLenum internal_format, GLenum wrap_s=GL_REPEAT, GLenum wrap_t=GL_REPEAT, GLenum min_filter=GL_NEAREST, GLenum mag_filter=GL_NEAREST)
GLint GLsizei GLsizei GLenum format
Definition: gl2ext.h:179
bool input_fp16
Whether input SSBO is a packed 2xfp16 format. Otherwise, regular FP32.
GLuint find_program(const Parameters &parameters) const
Definition: glfft.cpp:322
Texture & operator=(Texture &&texture)
unsigned vector_size
Vector size. Very GPU dependent. "Scalar" GPUs prefer 2 here, vector GPUs prefer 4 (and maybe 8)...
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
Definition: gl2ext.h:179
bool fp16
Whether internal shader should be mediump float.
bool operator==(const Parameters &other) const
unsigned workgroup_size_y
unsigned workgroup_size_z
Real-to-complex transform. N / 2 + 1 complex output samples are created per row with a stride of N co...
unsigned workgroup_size_x
Options for FFT implementation. Defaults for performance as conservative.
Program & operator=(Program &&prog)
bool output_fp16
Whether output SSBO is a packed 2xfp16 format. Otherwise, regular FP32.
void init(const void *data, size_t size, GLenum access)
GLfloat GLfloat GLfloat GLfloat h
Definition: gl2ext.h:2701
GL_SHADER_STORAGE_BUFFER.
GLsizei levels
Definition: gl2ext.h:1816
GLenum GLuint texture
Definition: gl2ext.h:385
GLenum type
Definition: gl2ext.h:133
Regular complex-to-complex transform.
GLenum GLuint GLintptr GLsizeiptr size
Definition: gl2ext.h:629
GLuint name
Definition: gl2ext.h:139
size_t cache_size() const
GLenum GLuint buffer
Definition: gl2ext.h:628
Texture()=default
GLint GLsizei width
Definition: gl2ext.h:179
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
GLuint program
Definition: gl2ext.h:1475
void insert_program(const Parameters &parameters, GLuint program)
Definition: glfft.cpp:335
struct GLFFT::FFTOptions::Type type
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
Program()=default
struct GLFFT::FFTOptions::Performance performance
std::unordered_map< Parameters, Program > programs