22 #ifdef ENABLE_PROFILING
23 #include "../../../utils/profiler.h"
30 #ifndef BEATMUP_OPENGLVERSION_GLES20
34 std::string code =
"#version 310 es\n";
38 case GL::TextureHandler::TextureFormat::Rx8:
39 case GL::TextureHandler::TextureFormat::RGBx8:
40 case GL::TextureHandler::TextureFormat::RGBAx8:
41 case GL::TextureHandler::TextureFormat::Rx32f:
42 case GL::TextureHandler::TextureFormat::RGBx32f:
43 case GL::TextureHandler::TextureFormat::RGBAx32f:
44 code +=
"#define beatmupSampler sampler2D\n";
46 case GL::TextureHandler::TextureFormat::OES_Ext:
48 "#extension GL_OES_EGL_image_external_essl3 : require\n"
49 "#define beatmupSampler samplerExternalOES\n"
50 "#define texelFetch texture\n";
59 program->make(gpu, code + sourceCodeTemplate);
67 int inputZDim,
int outputZDim,
bool pointwise
69 recycleBin(recycleBin), lock(lock), sourceCodeTemplate(sourceCodeTemplate), numInputs(inputZDim / 4), numOutputs(outputZDim / 4), prepared(false)
76 const unsigned int yLimit = std::min<unsigned int>(
77 std::sqrt(totalLimit /
wgSize[2]),
83 wgSize[0] = std::min<unsigned int>(
91 recycleBin.put(program);
102 for (
int i = 0; i < numOutputs; ++i) {
106 gpu.
bind(*outputs[i], i,
false,
true);
110 program->setInteger(
"image", 0);
117 program->dispatch(gpu, xWorkgroups, yWorkgroups, 1);
120 for (
int i = 0; i < numOutputs; ++i)
121 lock.unlock(outputs[i]);
129 program->enable(gpu);
133 for (
int i = 0; i < numInputs; ++i) {
138 program->setIntegerArray(
"inFeatures", 0, numInputs);
144 const unsigned int outputSize = xWorkgroups * wgSize[0] * yWorkgroups * wgSize[1] * (numOutputs * numOutputParts * 4);
150 program->dispatch(gpu, xWorkgroups, yWorkgroups, 1);
153 for (
int i = 0; i < numInputs; ++i)
154 lock.unlock(inputs[i]);
156 return xWorkgroups * wgSize[0];
164 program->enable(gpu);
168 program->setUnsignedInteger(
"inputStride", inputStridePix);
171 for (
int i = 0; i < numOutputs; ++i) {
175 gpu.
bind(*outputs[i], i,
false,
true);
182 program->dispatch(gpu, xWorkgroups, yWorkgroups, 1);
185 for (
int i = 0; i < numOutputs; ++i)
186 lock.unlock(outputs[i]);
191 prepare(gpu, &inputImage);
194 program->enable(gpu);
197 gpu.
bind(output, 1,
false,
true);
200 inputFeatures.
bind(gpu, 0);
202 program->setUnsignedInteger(
"inputStride", inputStridePix);
203 program->setVector2(
"d1", 1.0f / inputImage.
getWidth(), 1.0f / inputImage.
getHeight());
209 program->dispatch(gpu, xWorkgroups, yWorkgroups, 1);
217 #ifdef ENABLE_PROFILING
225 #ifdef ENABLE_PROFILING
236 #ifdef ENABLE_PROFILING
244 #ifdef ENABLE_PROFILING
253 #ifdef ENABLE_PROFILING
262 #ifdef ENABLE_PROFILING
264 profiler.
report(std::cout);
A very basic class for any image.
Makes sure the bitmap content is accessible within an image processing task.
void lock(GraphicPipeline *gpu, AbstractBitmap *input, AbstractBitmap *output)
Basic class: task and memory management, any kind of static data.
Layer(GraphicPipeline &gpu, GL::RecycleBin &recycleBin, BitmapContentLock &lock, std::string sourceCodeTemplate, int inputZDim, int outputZDim, bool pointwise=false)
void prepare(GraphicPipeline &gpu, GL::TextureHandler *inputImage=nullptr)
void process(GraphicPipeline &gpu, GL::TextureHandler &input, InternalBitmap **outputs)
void processPointwise(GraphicPipeline &gpu, GL::StorageBuffer &input, unsigned int inputStridePix, InternalBitmap **outputs, int width, int height)
GL::ComputeProgram * program
GLES31X2UpsamplingNetwork(Context &ctx, GraphicPipeline &gpu)
~GLES31X2UpsamplingNetwork()
void process(GraphicPipeline &gpu, GL::TextureHandler &input, AbstractBitmap &output)
InternalBitmap * storage[STORAGE_SIZE]
static const int STORAGE_SIZE
Stores references to GPU resources that will not be used anymore and needed to be recycled in a threa...
void bind(GraphicPipeline &gpu, int unit) const
void allocate(GraphicPipeline &gpu, const size_t sizeBytes, const void *data=nullptr)
size_t getCurrentCapacity() const
virtual const int getHeight() const =0
Height of the texture in pixels.
virtual const TextureFormat getTextureFormat() const =0
Returns the texture format specifying how the shader must interpret the data.
virtual const int getWidth() const =0
Width of the texture in pixels.
Internal low-level GPU control API.
void switchMode(Mode mode)
Switches GPU mode.
int getLimit(Limit limit) const
@ INFERENCE
Textures are feature maps computed in fragment shaders.
void flush()
Waits until all operations submitted to GPU are finished.
void bind(GL::TextureHandler &texture, size_t texUnit, const TextureParam param)
Bitmap whose memory is managed by the Beatmup engine.
const int getHeight() const
Height of the texture in pixels.
void reshape(int width, int height)
Changes bitmap size.
Collects running time statistics of multiple tracks.
void report(std::ostream &, ReportType type=ReportType::FULL) const
Exception thrown when texture format does not match any supported format.
@ QuadByte
4 channels of 8 bits per pixel (like RGBA), unsigned integer values
@ INTERP_LINEAR
bilinear pixel interpolation
@ INTERP_NEAREST
nearest neighbor pixel interpolation
std::string to_string(Beatmup::NNets::ActivationFunction function)
#define ceili(x, y)
integer division x/y with ceiling
ctx getGpuRecycleBin() -> emptyBin()
return bitmap getHeight()