@@ -84,6 +84,8 @@ int GpuIspShaderPassBlcNormalise::selectShaders(struct ShaderConfig &shaderCfg,
break;
};
+ LOG(GpuShaderBlc, Info) << "ShaderPass = " << typeid(this).name() << " selected shader pair ";
+
return 0;
}
@@ -95,15 +97,14 @@ int GpuIspShaderPassBlcNormalise::getShaderVariableLocations(void)
textureUniformStep_ = glGetUniformLocation(programId_, "tex_step");
textureUniformSize_ = glGetUniformLocation(programId_, "tex_size");
textureUniformStrideFactor_ = glGetUniformLocation(programId_, "stride_factor");
- textureUniformBayerFirstRed_ = glGetUniformLocation(programId_, "tex_bayer_first_red");
textureUniformProjMatrix_ = glGetUniformLocation(programId_, "proj_matrix");
+ blackLevelUniformDataIn_ = glGetUniformLocation(programId_, "blacklevel");
LOG(GpuShaderBlc, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_
<< " tex_y " << textureUniformBayerDataIn_
<< " tex_step " << textureUniformStep_
<< " tex_size " << textureUniformSize_
<< " stride_factor " << textureUniformStrideFactor_
- << " tex_bayer_first_red " << textureUniformBayerFirstRed_
<< " proj_matrix " << textureUniformProjMatrix_;
/* TODO: trap errors */
@@ -169,13 +170,11 @@ void GpuIspShaderPassBlcNormalise::setShaderVariableValues(eGLImage &eglImageIn,
/*
* These values are:
- * firstRed = tex_bayer_first_red - bayer_8.vert
* imgSize = tex_size - bayer_8.vert
* step = tex_step - bayer_8.vert
* Stride = stride_factor identity.vert
* textureUniformProjMatri = No scaling
*/
- glUniform2fv(textureUniformBayerFirstRed_, 1, firstRed);
glUniform2fv(textureUniformSize_, 1, imgSize);
glUniform2fv(textureUniformStep_, 1, Step);
glUniform1f(textureUniformStrideFactor_, Stride);
@@ -185,8 +184,7 @@ void GpuIspShaderPassBlcNormalise::setShaderVariableValues(eGLImage &eglImageIn,
<< " tex_y " << textureUniformBayerDataIn_
<< " tex_step " << textureUniformStep_
<< " tex_size " << textureUniformSize_
- << " stride_factor " << textureUniformStrideFactor_
- << " tex_bayer_first_red " << textureUniformBayerFirstRed_;
+ << " stride_factor " << textureUniformStrideFactor_;
LOG(GpuShaderBlc, Debug) << "textureUniformY_ = 0 "
<< " firstRed.x " << firstRed[0]
@@ -202,6 +200,7 @@ void GpuIspShaderPassBlcNormalise::setShaderVariableValues(eGLImage &eglImageIn,
* 0 = Red, 1 = Green, 2 = Blue
*/
glUniform3f(blackLevelUniformDataIn_, params.blackLevel[0], params.blackLevel[1], params.blackLevel[2]);
+
LOG(GpuShaderBlc, Debug) << " blackLevelUniformDataIn_ " << blackLevelUniformDataIn_ << " data " << params.blackLevel;
return;
@@ -42,18 +42,18 @@ int GpuIspShaderPassDemosiac::selectShaders(struct ShaderConfig &shaderCfg, [[ma
egl_.pushEnv(shaderCfg.shaderEnv, "#define APPLY_LSC");
/* Pixel location parameters */
- glFormat_ = GL_LUMINANCE;
+ glFormat_ = GL_R16F; //todo: not all systems support floating point framebuffers so gl_luminance will be default unless indicated by interrogation
bytesPerPixel_ = 1;
shaderStridePixels_ = passInputCfg_.stride;
- /* Shader selection */
+ shaderCfg.fragmentShaderData = bayer_unpacked_frag;
+ shaderCfg.vertexShaderData = bayer_unpacked_vert;
+
switch (inputFormat) {
case libcamera::formats::SBGGR8:
case libcamera::formats::SGBRG8:
case libcamera::formats::SGRBG8:
case libcamera::formats::SRGGB8:
- shaderCfg.fragmentShaderData = bayer_unpacked_frag;
- shaderCfg.vertexShaderData = bayer_unpacked_vert;
break;
case libcamera::formats::SBGGR10_CSI2P:
case libcamera::formats::SGBRG10_CSI2P:
@@ -61,13 +61,9 @@ int GpuIspShaderPassDemosiac::selectShaders(struct ShaderConfig &shaderCfg, [[ma
case libcamera::formats::SRGGB10_CSI2P:
egl_.pushEnv(shaderCfg.shaderEnv, "#define RAW10P");
if (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) {
- shaderCfg.fragmentShaderData = bayer_unpacked_frag;
- shaderCfg.vertexShaderData = bayer_unpacked_vert;
glFormat_ = GL_RG;
bytesPerPixel_ = 2;
} else {
- shaderCfg.fragmentShaderData = bayer_1x_packed_frag;
- shaderCfg.vertexShaderData = identity_vert;
shaderStridePixels_ = passInputCfg_.size.width;
}
break;
@@ -77,13 +73,9 @@ int GpuIspShaderPassDemosiac::selectShaders(struct ShaderConfig &shaderCfg, [[ma
case libcamera::formats::SRGGB12_CSI2P:
egl_.pushEnv(shaderCfg.shaderEnv, "#define RAW12P");
if (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) {
- shaderCfg.fragmentShaderData = bayer_unpacked_frag;
- shaderCfg.vertexShaderData = bayer_unpacked_vert;
glFormat_ = GL_RG;
bytesPerPixel_ = 2;
} else {
- shaderCfg.fragmentShaderData = bayer_1x_packed_frag;
- shaderCfg.vertexShaderData = identity_vert;
shaderStridePixels_ = passInputCfg_.size.width;
}
break;
@@ -98,6 +90,8 @@ int GpuIspShaderPassDemosiac::selectShaders(struct ShaderConfig &shaderCfg, [[ma
egl_.createTexture2D(*eglImageLscLookup_, nullptr, GL_LINEAR);
}
+ LOG(GpuShaderDemosiac, Info) << "ShaderPass = " << typeid(this).name() << " selected shader pair ";
+
return 0;
}
@@ -109,26 +103,23 @@ int GpuIspShaderPassDemosiac::getShaderVariableLocations(void)
textureUniformBayerDataIn_ = glGetUniformLocation(programId_, "tex_y");
awbUniformDataIn_ = glGetUniformLocation(programId_, "awb");
ccmUniformDataIn_ = glGetUniformLocation(programId_, "ccm");
- blackLevelUniformDataIn_ = glGetUniformLocation(programId_, "blacklevel");
gammaUniformDataIn_ = glGetUniformLocation(programId_, "gamma");
contrastExpUniformDataIn_ = glGetUniformLocation(programId_, "contrastExp");
textureUniformLsc_ = glGetUniformLocation(programId_, "lsc_tex");
- textureUniformStep_ = glGetUniformLocation(programId_, "tex_step");
- textureUniformSize_ = glGetUniformLocation(programId_, "tex_size");
textureUniformStrideFactor_ = glGetUniformLocation(programId_, "stride_factor");
textureUniformBayerFirstRed_ = glGetUniformLocation(programId_, "tex_bayer_first_red");
textureUniformProjMatrix_ = glGetUniformLocation(programId_, "proj_matrix");
+ textureUniformBayerDataIn_ = glGetUniformLocation(programId_, "tex_y");
+ textureUniformStep_ = glGetUniformLocation(programId_, "tex_step");
+ textureUniformSize_ = glGetUniformLocation(programId_, "tex_size");
LOG(GpuShaderDemosiac, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_
<< " tex_y " << textureUniformBayerDataIn_
<< " awb " << awbUniformDataIn_
<< " ccm " << ccmUniformDataIn_
- << " blacklevel " << blackLevelUniformDataIn_
<< " gamma " << gammaUniformDataIn_
<< " contrastExp " << contrastExpUniformDataIn_
- << " tex_step " << textureUniformStep_
- << " tex_size " << textureUniformSize_
<< " stride_factor " << textureUniformStrideFactor_
<< " tex_bayer_first_red " << textureUniformBayerFirstRed_
<< " proj_matrix " << textureUniformProjMatrix_;
@@ -210,8 +201,6 @@ void GpuIspShaderPassDemosiac::setShaderVariableValues(eGLImage &eglImageIn, con
LOG(GpuShaderDemosiac, Debug) << "vertexIn " << attributeVertex_ << " textureIn " << attributeTexture_
<< " tex_y " << textureUniformBayerDataIn_
- << " tex_step " << textureUniformStep_
- << " tex_size " << textureUniformSize_
<< " stride_factor " << textureUniformStrideFactor_
<< " tex_bayer_first_red " << textureUniformBayerFirstRed_;
@@ -240,8 +229,6 @@ void GpuIspShaderPassDemosiac::setShaderVariableValues(eGLImage &eglImageIn, con
/*
* 0 = Red, 1 = Green, 2 = Blue
*/
- glUniform3f(blackLevelUniformDataIn_, params.blackLevel[0], params.blackLevel[1], params.blackLevel[2]);
- LOG(GpuShaderDemosiac, Debug) << " blackLevelUniformDataIn_ " << blackLevelUniformDataIn_ << " data " << params.blackLevel;
glUniform3f(awbUniformDataIn_, params.gains[0], params.gains[1], params.gains[2]);
LOG(GpuShaderDemosiac, Debug) << " awbUniformDataIn_ " << awbUniformDataIn_ << " data " << params.gains;
@@ -53,9 +53,6 @@ private:
/* Represent per-frame CCM as a uniform vector of floats 3 x 3 */
GLint ccmUniformDataIn_;
- /* Black Level compensation */
- GLint blackLevelUniformDataIn_;
-
/* Gamma */
GLint gammaUniformDataIn_;
@@ -29,6 +29,8 @@
namespace libcamera {
+LOG_DEFINE_CATEGORY(SoftwareIspInstanceGpu)
+
/**
* \class SoftwareIspInstanceGpu
* \brief Class for debayering using an EGL Shader
@@ -91,7 +93,7 @@ int SoftwareIspInstanceGpu::getInputConfig(PixelFormat inputFormat, DebayerInput
return 0;
}
- LOG(SoftwareIspInstance, Debug)
+ LOG(SoftwareIspInstanceGpu, Debug)
<< "Unsupported input format " << inputFormat;
return -EINVAL;
@@ -127,7 +129,7 @@ int SoftwareIspInstanceGpu::configure(const StreamConfiguration &inputCfg,
const Size &stats_pattern_size = stats_->patternSize();
if (inputConfig_.patternSize.width != stats_pattern_size.width ||
inputConfig_.patternSize.height != stats_pattern_size.height) {
- LOG(SoftwareIspInstance, Error)
+ LOG(SoftwareIspInstanceGpu, Error)
<< "mismatching stats and debayer pattern sizes for "
<< inputCfg.pixelFormat;
return -EINVAL;
@@ -141,7 +143,7 @@ int SoftwareIspInstanceGpu::configure(const StreamConfiguration &inputCfg,
height_ = inputCfg.size.height;
if (outputCfgs.size() != 1) {
- LOG(SoftwareIspInstance, Error)
+ LOG(SoftwareIspInstanceGpu, Error)
<< "Unsupported number of output streams: "
<< outputCfgs.size();
return -EINVAL;
@@ -153,7 +155,7 @@ int SoftwareIspInstanceGpu::configure(const StreamConfiguration &inputCfg,
strideAndFrameSize(outputCfg.pixelFormat, outputCfg.size);
if (!outSizeRange.contains(outputCfg.size) || outputConfig_.stride != outputCfg.stride) {
- LOG(SoftwareIspInstance, Error)
+ LOG(SoftwareIspInstanceGpu, Error)
<< "Invalid output size/stride: "
<< "\n " << outputCfg.size << " (" << outSizeRange << ")"
<< "\n " << outputCfg.stride << " (" << outputConfig_.stride << ")";
@@ -182,9 +184,12 @@ int SoftwareIspInstanceGpu::configure(const StreamConfiguration &inputCfg,
/* Configure for one pass */
PassConfig rawSensorIn = { inputCfg.size, inputConfig_.stride, inputPixelFormat_, window };
+ PassConfig pingPongOut = { inputCfg.size, inputCfg.size.width, inputPixelFormat_, Rectangle(inputCfg.size) };
+ PassConfig pingPongIn = pingPongOut;
PassConfig rgbaOut = { outputCfg.size, outputConfig_.stride, outputPixelFormat_, Rectangle(nativeOutputSize_) };
- gpuIspShaderPassDemosiac_.configure(rawSensorIn, rgbaOut);
+ gpuIspShaderPassBlcNormalise_.configure(rawSensorIn, pingPongOut);
+ gpuIspShaderPassDemosiac_.configure(pingPongIn, rgbaOut);
return 0;
}
@@ -240,11 +245,11 @@ eGLImage *SoftwareIspInstanceGpu::getCachedInputFrameBuffer(FrameBuffer *input,
if (cache_miss) {
if (eglImageInCache_.size() >= inputBufferCount_) {
eglImageInCache_.pop_front();
- LOG(SoftwareIspInstance, Debug) << "Input cache " << inputBufferCount_ << " exceeded evicted entry";
+ LOG(SoftwareIspInstanceGpu, Debug) << "Input cache " << inputBufferCount_ << " exceeded evicted entry";
}
- eglImageInCache_.emplace_back(fd, std::make_unique<eGLImage>(gpuIspShaderPassDemosiac_.glFormat_,
- inputConfig_.stride / gpuIspShaderPassDemosiac_.getBytesPerPixel(),
+ eglImageInCache_.emplace_back(fd, std::make_unique<eGLImage>(gpuIspShaderPassBlcNormalise_.glFormat_,
+ inputConfig_.stride / gpuIspShaderPassBlcNormalise_.getBytesPerPixel(),
height_, inputConfig_.stride, GL_TEXTURE0, 0));
eglImageIn = eglImageInCache_.back().second.get();
@@ -252,7 +257,7 @@ eGLImage *SoftwareIspInstanceGpu::getCachedInputFrameBuffer(FrameBuffer *input,
return eglImageIn;
if (eglImageInCache_.size() == 1)
- LOG(SoftwareIspInstance, Info)
+ LOG(SoftwareIspInstanceGpu, Info)
<< "Importing input DMABuf failed, falling back to upload";
} else if (!eglImageIn->dmabuf_import_failed_) {
egl_.activateBindTexture(*eglImageIn);
@@ -263,7 +268,7 @@ eGLImage *SoftwareIspInstanceGpu::getCachedInputFrameBuffer(FrameBuffer *input,
inDmaSyncer->emplace(input->planes()[0].fd, DmaSyncer::SyncType::Read);
inMapped->emplace(input, MappedFrameBuffer::MapFlag::Read);
if (!inMapped->value().isValid()) {
- LOG(SoftwareIspInstance, Error) << "mmap-ing buffer(s) failed";
+ LOG(SoftwareIspInstanceGpu, Error) << "mmap-ing buffer(s) failed";
if (cache_miss) {
eglImageInCache_.pop_back();
}
@@ -294,7 +299,7 @@ eGLImage *SoftwareIspInstanceGpu::getCachedOutputFrameBuffer(FrameBuffer *output
if (cache_miss) {
if (eglImageOutCache_.size() >= outputBufferCount_) {
eglImageOutCache_.pop_front();
- LOG(SoftwareIspInstance, Debug) << "Output cache " << outputBufferCount_ << " exceeded evicted entry";
+ LOG(SoftwareIspInstanceGpu, Debug) << "Output cache " << outputBufferCount_ << " exceeded evicted entry";
}
eglImageOutCache_.emplace_back(fd, std::make_unique<eGLImage>(GL_RGBA, outputSize_.width,
@@ -323,9 +328,19 @@ int SoftwareIspInstanceGpu::processGPU(FrameBuffer *input, FrameBuffer *output,
if (!eglImageOut)
return -ENOMEM;
- pipelineResult = gpuIspShaderPassDemosiac_.process(*eglImageIn, *eglImageOut, width_, height_, params);
+ pipelineResult = gpuIspShaderPassBlcNormalise_.process(*eglImageIn, *eglImagePingPong_[0], width_, height_, params);
+ if (pipelineResult) {
+ LOG(SoftwareIspInstanceGpu, Error) << "BlcNormalise fail";
+ return pipelineResult;
+ }
- return pipelineResult;
+ pipelineResult = gpuIspShaderPassDemosiac_.process(*eglImagePingPong_[0], *eglImageOut, width_, height_, params);
+ if (pipelineResult) {
+ LOG(SoftwareIspInstanceGpu, Error) << "Demosiac fail";
+ return pipelineResult;
+ }
+
+ return 0;
}
void SoftwareIspInstanceGpu::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams ¶ms)
@@ -343,7 +358,7 @@ void SoftwareIspInstanceGpu::process(uint32_t frame, FrameBuffer *input, FrameBu
std::optional<DmaSyncer> inDmaSyncer;
if (processGPU(input, output, params, &inMapped, &inDmaSyncer)) {
- LOG(SoftwareIspInstance, Error) << "debayerGPU failed";
+ LOG(SoftwareIspInstanceGpu, Error) << "debayerGPU failed";
goto error;
}
@@ -390,14 +405,17 @@ int SoftwareIspInstanceGpu::start()
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits);
- LOG(SoftwareIspInstance, Debug) << "Available fragment shader texture units " << maxTextureImageUnits;
+ LOG(SoftwareIspInstanceGpu, Debug) << "Available fragment shader texture units " << maxTextureImageUnits;
if (initBayerShaders(inputPixelFormat_, outputPixelFormat_))
return -EINVAL;
/* Intermediary ping/pong textures */
- eglImagePingPong_[0] = std::make_unique<eGLImage>(gpuIspShaderPassDemosiac_.glFormat_, outputSize_.width, outputSize_.height, outputConfig_.stride, GL_TEXTURE1, 1);
- eglImagePingPong_[1] = std::make_unique<eGLImage>(gpuIspShaderPassDemosiac_.glFormat_, outputSize_.width, outputSize_.height, outputConfig_.stride, GL_TEXTURE2, 2);
+ eglImagePingPong_[0] = std::make_unique<eGLImage>(gpuIspShaderPassDemosiac_.glFormat_, width_, height_, outputConfig_.stride, GL_TEXTURE1, 1);
+ eglImagePingPong_[1] = std::make_unique<eGLImage>(gpuIspShaderPassDemosiac_.glFormat_, width_, height_, outputConfig_.stride, GL_TEXTURE2, 2);
+
+ egl_.createOutputTexture2D(*eglImagePingPong_[0]);
+ egl_.createOutputTexture2D(*eglImagePingPong_[1]);
return 0;
}
@@ -432,7 +450,7 @@ SizeRange SoftwareIspInstanceGpu::sizes(PixelFormat inputFormat, const Size &inp
*/
if (inputSize.width < (3 * patternSize.width) ||
inputSize.height < (2 * borderHeight + patternSize.height)) {
- LOG(SoftwareIspInstance, Warning)
+ LOG(SoftwareIspInstanceGpu, Warning)
<< "Input format size too small: " << inputSize;
return {};
}
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> --- ...gpu_pipeline_shader_pass_blc_normalise.cpp | 11 ++-- .../gpu_pipeline_shader_pass_demosiac.cpp | 31 ++++------- .../gpu_pipeline_shader_pass_demosiac.h | 3 -- .../software_isp_instance_gpu.cpp | 54 ++++++++++++------- 4 files changed, 50 insertions(+), 49 deletions(-)