Beatmup
cnn.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2020, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #include "../cnn_interface.h"
21 #include "../../../gpu/compute_program.h"
22 #include <string>
23 
24 namespace Beatmup {
25 
26  /**
27  x2 image upsampler using a convolutional neural network.
28  Implements a neural net inference using OpenGL ES 3.1-conformant shaders.
29  Used by Bitmap::Resampler. Only usable inside an AbstractTask, not intended to be directly used by the application.
30  */
32  private:
33  static const int STORAGE_SIZE = 14;
34 
35  class Layer {
36  private:
40  std::string sourceCodeTemplate;
42 
43  unsigned int wgSize[3]; // workgroup size along one axis
44  const int numInputs, numOutputs;
45  bool prepared;
46 
47  void prepare(GraphicPipeline& gpu, GL::TextureHandler* inputImage = nullptr);
48 
49  public:
50 
51  Layer(
53  std::string sourceCodeTemplate,
54  int inputZDim, int outputZDim,
55  bool pointwise = false
56  );
57  ~Layer();
58 
59  void process(GraphicPipeline& gpu, GL::TextureHandler& input, InternalBitmap** outputs);
60  unsigned int process(GraphicPipeline& gpu, InternalBitmap** inputs, GL::StorageBuffer& output, int numOutputParts);
61  void processPointwise(GraphicPipeline& gpu, GL::StorageBuffer& input, unsigned int inputStridePix, InternalBitmap** outputs, int width, int height);
62  void processPointwise(GraphicPipeline& gpu, GL::StorageBuffer& inputFeatures, unsigned int inputStridePix, GL::TextureHandler& inputImage, AbstractBitmap& outputImage);
63  };
64 
65  Layer
71 
74 
75  public:
78 
79  void process(GraphicPipeline& gpu, GL::TextureHandler& input, AbstractBitmap& output);
80  bool usesEs31Backend() const { return true; }
81  };
82 
83 }
A very basic class for any image.
Makes sure the bitmap content is accessible within an image processing task.
Definition: content_lock.h:34
Basic class: task and memory management, any kind of static data.
Definition: context.h:59
Layer(GraphicPipeline &gpu, GL::RecycleBin &recycleBin, BitmapContentLock &lock, std::string sourceCodeTemplate, int inputZDim, int outputZDim, bool pointwise=false)
Definition: cnn.cpp:65
void prepare(GraphicPipeline &gpu, GL::TextureHandler *inputImage=nullptr)
Definition: cnn.cpp:32
void process(GraphicPipeline &gpu, GL::TextureHandler &input, InternalBitmap **outputs)
Definition: cnn.cpp:95
GL::TextureHandler::TextureFormat inputFormat
Definition: cnn.h:39
void processPointwise(GraphicPipeline &gpu, GL::StorageBuffer &input, unsigned int inputStridePix, InternalBitmap **outputs, int width, int height)
Definition: cnn.cpp:160
GL::ComputeProgram * program
Definition: cnn.h:38
x2 image upsampler using a convolutional neural network.
Definition: cnn.h:31
GLES31X2UpsamplingNetwork(Context &ctx, GraphicPipeline &gpu)
Definition: cnn.cpp:269
void process(GraphicPipeline &gpu, GL::TextureHandler &input, AbstractBitmap &output)
Definition: cnn.cpp:213
InternalBitmap * storage[STORAGE_SIZE]
Definition: cnn.h:72
GL::StorageBuffer buffer
Definition: cnn.h:73
bool usesEs31Backend() const
Definition: cnn.h:80
static const int STORAGE_SIZE
Definition: cnn.h:33
GLSL compute program.
Stores references to GPU resources that will not be used anymore and needed to be recycled in a threa...
Definition: recycle_bin.h:34
TextureFormat
Texture format, specifies how the texture should be interpreted on the shader side.
Internal low-level GPU control API.
Definition: pipeline.h:33
Bitmap whose memory is managed by the Beatmup engine.
Interface of x2 image upsampling using a convolutional neural network on GPU.
Definition: cnn_interface.h:29
Beatmup::Context * ctx
jlong jint width
jlong jint jint height