Beatmup
Beatmup::GLES31X2UpsamplingNetwork Class Reference

x2 image upsampler using a convolutional neural network. More...

#include <cnn.h>

Inheritance diagram for Beatmup::GLES31X2UpsamplingNetwork:
Beatmup::X2UpsamplingNetwork Beatmup::BitmapContentLock

Classes

class  Layer
 

Public Member Functions

 GLES31X2UpsamplingNetwork (Context &ctx, GraphicPipeline &gpu)
 
 ~GLES31X2UpsamplingNetwork ()
 
void process (GraphicPipeline &gpu, GL::TextureHandler &input, AbstractBitmap &output)
 
bool usesEs31Backend () const
 
- Public Member Functions inherited from Beatmup::X2UpsamplingNetwork
virtual ~X2UpsamplingNetwork ()
 

Private Attributes

Layer layer1_0
 
Layer layer1_1
 
Layer layer2_0
 
Layer layer2_1
 
Layer layer2_2
 
Layer layer2_3
 
Layer layer3
 
Layer layer4_0
 
Layer layer4_1
 
Layer layer5
 
InternalBitmapstorage [STORAGE_SIZE]
 
GL::StorageBuffer buffer
 

Static Private Attributes

static const int STORAGE_SIZE = 14
 

Additional Inherited Members

- Private Member Functions inherited from Beatmup::BitmapContentLock
 BitmapContentLock ()
 
 ~BitmapContentLock ()
 
void readLock (GraphicPipeline *gpu, AbstractBitmap *bitmap, ProcessingTarget target)
 Locks content of a bitmap for reading using a specific processing target device. More...
 
void writeLock (GraphicPipeline *gpu, AbstractBitmap *bitmap, ProcessingTarget target)
 Locks content of a bitmap for writing using a specific processing target device. More...
 
void unlock (AbstractBitmap *bitmap)
 Drops a lock to the bitmap. More...
 
void unlockAll ()
 Unlocks all the locked bitmaps unconditionally. More...
 
template<const ProcessingTarget target>
void lock (GraphicPipeline *gpu, AbstractBitmap *input, AbstractBitmap *output)
 
void lock (GraphicPipeline *gpu, ProcessingTarget target, AbstractBitmap *input, AbstractBitmap *output)
 
template<const ProcessingTarget target>
void lock (GraphicPipeline *gpu, std::initializer_list< AbstractBitmap * > read, std::initializer_list< AbstractBitmap * > write)
 
template<typename ... Args>
void unlock (AbstractBitmap *first, Args ... others)
 

Detailed Description

x2 image upsampler using a convolutional neural network.

Implements a neural net inference using OpenGL ES 3.1-conformant shaders. Used by Bitmap::Resampler. Only usable inside an AbstractTask, not intended to be directly used by the application.

Definition at line 31 of file cnn.h.

Constructor & Destructor Documentation

◆ GLES31X2UpsamplingNetwork()

GLES31X2UpsamplingNetwork::GLES31X2UpsamplingNetwork ( Context ctx,
GraphicPipeline gpu 
)

Definition at line 269 of file cnn.cpp.

269  :
270 #define STRINGIFY(...) #__VA_ARGS__
271 
272  layer1_0(gpu, *ctx.getGpuRecycleBin(), *this,
273 #include "l1-0.glsl"
274  , 1, 24
275  ),
276  layer1_1(gpu, *ctx.getGpuRecycleBin(), *this,
277 #include "l1-1.glsl"
278  , 1, 24
279  ),
280 
281  layer2_0(gpu, *ctx.getGpuRecycleBin(), *this,
282 #include "l2-0.glsl"
283  , 12, 8
284  ),
285  layer2_1(gpu, *ctx.getGpuRecycleBin(), *this,
286 #include "l2-1.glsl"
287  , 12, 8
288  ),
289  layer2_2(gpu, *ctx.getGpuRecycleBin(), *this,
290 #include "l2-2.glsl"
291  , 12, 8
292  ),
293  layer2_3(gpu, *ctx.getGpuRecycleBin(), *this,
294 #include "l2-3.glsl"
295  , 12, 8
296  ),
297 
298  layer3(gpu, *ctx.getGpuRecycleBin(), *this,
299 #include "l3.glsl"
300  , 32, 24, true
301  ),
302 
303  layer4_0(gpu, *ctx.getGpuRecycleBin(), *this,
304 #include "l4-0.glsl"
305  , 12, 8
306  ),
307  layer4_1(gpu, *ctx.getGpuRecycleBin(), *this,
308 #include "l4-1.glsl"
309  , 12, 8
310  ),
311 
312  layer5(gpu, *ctx.getGpuRecycleBin(), *this,
313 #include "l5.glsl"
314  , 16, 1, true
315  ),
316 
318 {
319  for (int i = 0; i < STORAGE_SIZE; ++i)
320  storage[i] = new InternalBitmap(ctx, PixelFormat::QuadByte, 64, 64, false);
321 }
GL::RecycleBin * getGpuRecycleBin() const
Definition: context.cpp:340
InternalBitmap * storage[STORAGE_SIZE]
Definition: cnn.h:72
GL::StorageBuffer buffer
Definition: cnn.h:73
static const int STORAGE_SIZE
Definition: cnn.h:33
Bitmap whose memory is managed by the Beatmup engine.
@ QuadByte
4 channels of 8 bits per pixel (like RGBA), unsigned integer values
Beatmup::Context * ctx

◆ ~GLES31X2UpsamplingNetwork()

GLES31X2UpsamplingNetwork::~GLES31X2UpsamplingNetwork ( )

Definition at line 324 of file cnn.cpp.

324  {
325  for (int i = 0; i < STORAGE_SIZE; ++i)
326  delete storage[i];
327 }

Member Function Documentation

◆ process()

void GLES31X2UpsamplingNetwork::process ( GraphicPipeline gpu,
GL::TextureHandler input,
AbstractBitmap output 
)
virtual

Implements Beatmup::X2UpsamplingNetwork.

Definition at line 213 of file cnn.cpp.

213  {
214  // disable alpha blend
216 
217 #ifdef ENABLE_PROFILING
218  Profiler profiler;
219  profiler("layer 1");
220 #endif
221 
222  layer1_0.process(gpu, input, storage + 0);
223  layer1_1.process(gpu, input, storage + 6);
224 
225 #ifdef ENABLE_PROFILING
226  gpu.flush();
227  profiler.lap();
228  profiler("layer 2");
229 #endif
230 
231  layer2_0.process(gpu, storage, buffer, 4);
232  layer2_1.process(gpu, storage + 3, buffer, 4);
233  layer2_2.process(gpu, storage + 6, buffer, 4);
234  unsigned int stride = layer2_3.process(gpu, storage + 9, buffer, 4);
235 
236 #ifdef ENABLE_PROFILING
237  gpu.flush();
238  profiler.lap();
239  profiler("layer 3");
240 #endif
241 
242  layer3.processPointwise(gpu, buffer, stride, storage, input.getWidth(), input.getHeight());
243 
244 #ifdef ENABLE_PROFILING
245  gpu.flush();
246  profiler.lap();
247  profiler("layer 4");
248 #endif
249 
250  layer4_0.process(gpu, storage, buffer, 2);
251  stride = layer4_1.process(gpu, storage + 3, buffer, 2);
252 
253 #ifdef ENABLE_PROFILING
254  gpu.flush();
255  profiler.lap();
256  profiler("layer 5");
257 #endif
258 
259  layer5.processPointwise(gpu, buffer, stride, input, output);
260 
261  gpu.flush();
262 #ifdef ENABLE_PROFILING
263  profiler.lap();
264  profiler.report(std::cout);
265 #endif
266 }
void process(GraphicPipeline &gpu, GL::TextureHandler &input, InternalBitmap **outputs)
Definition: cnn.cpp:95
void processPointwise(GraphicPipeline &gpu, GL::StorageBuffer &input, unsigned int inputStridePix, InternalBitmap **outputs, int width, int height)
Definition: cnn.cpp:160
virtual const int getHeight() const =0
Height of the texture in pixels.
virtual const int getWidth() const =0
Width of the texture in pixels.
void switchMode(Mode mode)
Switches GPU mode.
Definition: pipeline.cpp:941
@ INFERENCE
Textures are feature maps computed in fragment shaders.
void flush()
Waits until all operations submitted to GPU are finished.
Definition: pipeline.cpp:931
Collects running time statistics of multiple tracks.
Definition: profiler.h:31
void report(std::ostream &, ReportType type=ReportType::FULL) const
Definition: profiler.cpp:56

◆ usesEs31Backend()

bool Beatmup::GLES31X2UpsamplingNetwork::usesEs31Backend ( ) const
inlinevirtual

Implements Beatmup::X2UpsamplingNetwork.

Definition at line 80 of file cnn.h.

80 { return true; }

Member Data Documentation

◆ STORAGE_SIZE

const int Beatmup::GLES31X2UpsamplingNetwork::STORAGE_SIZE = 14
staticprivate

Definition at line 33 of file cnn.h.

◆ layer1_0

Layer Beatmup::GLES31X2UpsamplingNetwork::layer1_0
private

Definition at line 66 of file cnn.h.

◆ layer1_1

Layer Beatmup::GLES31X2UpsamplingNetwork::layer1_1
private

Definition at line 66 of file cnn.h.

◆ layer2_0

Layer Beatmup::GLES31X2UpsamplingNetwork::layer2_0
private

Definition at line 67 of file cnn.h.

◆ layer2_1

Layer Beatmup::GLES31X2UpsamplingNetwork::layer2_1
private

Definition at line 67 of file cnn.h.

◆ layer2_2

Layer Beatmup::GLES31X2UpsamplingNetwork::layer2_2
private

Definition at line 67 of file cnn.h.

◆ layer2_3

Layer Beatmup::GLES31X2UpsamplingNetwork::layer2_3
private

Definition at line 67 of file cnn.h.

◆ layer3

Layer Beatmup::GLES31X2UpsamplingNetwork::layer3
private

Definition at line 68 of file cnn.h.

◆ layer4_0

Layer Beatmup::GLES31X2UpsamplingNetwork::layer4_0
private

Definition at line 69 of file cnn.h.

◆ layer4_1

Layer Beatmup::GLES31X2UpsamplingNetwork::layer4_1
private

Definition at line 69 of file cnn.h.

◆ layer5

Layer Beatmup::GLES31X2UpsamplingNetwork::layer5
private

Definition at line 70 of file cnn.h.

◆ storage

InternalBitmap* Beatmup::GLES31X2UpsamplingNetwork::storage[STORAGE_SIZE]
private

Definition at line 72 of file cnn.h.

◆ buffer

GL::StorageBuffer Beatmup::GLES31X2UpsamplingNetwork::buffer
private

Definition at line 73 of file cnn.h.


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