@@ -76,4 +76,104 @@ void GpuIspShaderPass::configure(const struct PassConfig &passInputCfg, const st
passOutputCfg_ = passOutputCfg;
}
+int GpuIspShaderPass::initShaders(PixelFormat inputFormat, PixelFormat outputFormat)
+{
+ struct ShaderConfig shaderCfg;
+ GLenum err;
+ int ret;
+
+ /* Target gles 100 glsl requires "#version x" as first directive in shader */
+ egl_.pushEnv(shaderCfg.shaderEnv, "#version 100");
+
+ /* Specify GL_OES_EGL_image_external */
+ egl_.pushEnv(shaderCfg.shaderEnv, "#extension GL_OES_EGL_image_external: enable");
+
+ /*
+ * Tell shaders how to re-order output taking account of how the pixels
+ * are actually stored by EGL.
+ */
+ switch (outputFormat) {
+ case formats::ARGB8888:
+ case formats::XRGB8888:
+ break;
+ case formats::ABGR8888:
+ case formats::XBGR8888:
+ egl_.pushEnv(shaderCfg.shaderEnv, "#define SWAP_BLUE");
+ break;
+ default:
+ LOG(GpuShaderPass, Error) << "Unsupported output format";
+ return -EINVAL;
+ }
+
+ switch (inputFormat) {
+ case libcamera::formats::SBGGR8:
+ case libcamera::formats::SBGGR10_CSI2P:
+ case libcamera::formats::SBGGR12_CSI2P:
+ firstRed_x_ = 1.0;
+ firstRed_y_ = 1.0;
+ break;
+ case libcamera::formats::SGBRG8:
+ case libcamera::formats::SGBRG10_CSI2P:
+ case libcamera::formats::SGBRG12_CSI2P:
+ firstRed_x_ = 0.0;
+ firstRed_y_ = 1.0;
+ break;
+ case libcamera::formats::SGRBG8:
+ case libcamera::formats::SGRBG10_CSI2P:
+ case libcamera::formats::SGRBG12_CSI2P:
+ firstRed_x_ = 1.0;
+ firstRed_y_ = 0.0;
+ break;
+ case libcamera::formats::SRGGB8:
+ case libcamera::formats::SRGGB10_CSI2P:
+ case libcamera::formats::SRGGB12_CSI2P:
+ firstRed_x_ = 0.0;
+ firstRed_y_ = 0.0;
+ break;
+ default:
+ LOG(GpuShaderPass, Error) << "Unsupported input format";
+ return -EINVAL;
+ };
+
+ ret = selectShaders(shaderCfg, inputFormat, outputFormat);
+ if (ret) {
+ LOG(GpuShaderPass, Error) << "selectShaders fail";
+ return ret;
+ }
+
+ LOG(GpuShaderPass, Info) << "ShaderPass = " << typeid(this).name();
+
+ if (egl_.compileVertexShader(vertexShaderId_, shaderCfg.vertexShaderData,
+ shaderCfg.shaderEnv)) {
+ LOG(GpuShaderPass, Error) << "Compile vertex shader fail";
+ return -ENODEV;
+ }
+ utils::scope_exit vShaderGuard([&] { glDeleteShader(vertexShaderId_); });
+
+ if (egl_.compileFragmentShader(fragmentShaderId_, shaderCfg.fragmentShaderData,
+ shaderCfg.shaderEnv)) {
+ LOG(GpuShaderPass, Error) << "Compile fragment shader fail";
+ return -ENODEV;
+ }
+ utils::scope_exit fShaderGuard([&] { glDeleteShader(fragmentShaderId_); });
+
+ if (egl_.linkProgram(programId_, vertexShaderId_, fragmentShaderId_)) {
+ LOG(GpuShaderPass, Error) << "Linking program fail";
+ return -ENODEV;
+ }
+
+ egl_.dumpShaderSource(vertexShaderId_);
+ egl_.dumpShaderSource(fragmentShaderId_);
+
+ /* Ensure we set the programId_ */
+ glUseProgram(programId_);
+ err = glGetError();
+ if (err != GL_NO_ERROR) {
+ LOG(GpuShaderPass, Error) << "Use program error " << err;
+ return -ENODEV;
+ }
+
+ return getShaderVariableLocations();
+}
+
}
@@ -41,6 +41,12 @@ struct PassConfig {
Rectangle window;
};
+struct ShaderConfig {
+ std::span<const unsigned char> fragmentShaderData;
+ std::span<const unsigned char> vertexShaderData;
+ std::vector<std::string> shaderEnv;
+};
+
class GpuIspShaderPass : public Object
{
public:
@@ -51,7 +57,8 @@ public:
virtual int start();
virtual void stop();
virtual void configure(const struct PassConfig &passInputCfg, const struct PassConfig &passOutputCfg);
- virtual int initShaders(PixelFormat inputFormat, PixelFormat outputFormat) = 0;
+ virtual int initShaders(PixelFormat inputFormat, PixelFormat outputFormat);
+ virtual int selectShaders(struct ShaderConfig &shaderCfg, PixelFormat &inputFormat, PixelFormat &outputFormat) = 0;
virtual int getShaderVariableLocations(void) = 0;
virtual void setShaderVariableValues(eGLImage &eglImageIn, const DebayerParams ¶ms) = 0;
virtual const char *name() const { return "GpuIspShaderPass"; }
@@ -35,97 +35,39 @@ namespace libcamera {
LOG_DEFINE_CATEGORY(GpuShaderDemosiac)
-int GpuIspShaderPassDemosiac::initShaders(PixelFormat inputFormat, PixelFormat outputFormat)
+int GpuIspShaderPassDemosiac::selectShaders(struct ShaderConfig &shaderCfg, [[maybe_unused]]PixelFormat &inputFormat, [[maybe_unused]]PixelFormat &outputFormat)
{
- std::span<const unsigned char> fragmentShaderData;
- std::span<const unsigned char> vertexShaderData;
- std::vector<std::string> shaderEnv;
- GLenum err;
-
- /* Target gles 100 glsl requires "#version x" as first directive in shader */
- egl_.pushEnv(shaderEnv, "#version 100");
-
- /* Specify GL_OES_EGL_image_external */
- egl_.pushEnv(shaderEnv, "#extension GL_OES_EGL_image_external: enable");
-
/* LSC flag */
if (lscEnabled_)
- egl_.pushEnv(shaderEnv, "#define APPLY_LSC");
-
- /*
- * Tell shaders how to re-order output taking account of how the pixels
- * are actually stored by EGL.
- */
- switch (outputFormat) {
- case formats::ARGB8888:
- case formats::XRGB8888:
- break;
- case formats::ABGR8888:
- case formats::XBGR8888:
- egl_.pushEnv(shaderEnv, "#define SWAP_BLUE");
- break;
- default:
- LOG(GpuShaderDemosiac, Error) << "Unsupported output format";
- return -EINVAL;
- }
+ egl_.pushEnv(shaderCfg.shaderEnv, "#define APPLY_LSC");
/* Pixel location parameters */
glFormat_ = GL_LUMINANCE;
bytesPerPixel_ = 1;
shaderStridePixels_ = passInputCfg_.stride;
- switch (inputFormat) {
- case libcamera::formats::SBGGR8:
- case libcamera::formats::SBGGR10_CSI2P:
- case libcamera::formats::SBGGR12_CSI2P:
- firstRed_x_ = 1.0;
- firstRed_y_ = 1.0;
- break;
- case libcamera::formats::SGBRG8:
- case libcamera::formats::SGBRG10_CSI2P:
- case libcamera::formats::SGBRG12_CSI2P:
- firstRed_x_ = 0.0;
- firstRed_y_ = 1.0;
- break;
- case libcamera::formats::SGRBG8:
- case libcamera::formats::SGRBG10_CSI2P:
- case libcamera::formats::SGRBG12_CSI2P:
- firstRed_x_ = 1.0;
- firstRed_y_ = 0.0;
- break;
- case libcamera::formats::SRGGB8:
- case libcamera::formats::SRGGB10_CSI2P:
- case libcamera::formats::SRGGB12_CSI2P:
- firstRed_x_ = 0.0;
- firstRed_y_ = 0.0;
- break;
- default:
- LOG(GpuShaderDemosiac, Error) << "Unsupported input format";
- return -EINVAL;
- };
-
/* Shader selection */
switch (inputFormat) {
case libcamera::formats::SBGGR8:
case libcamera::formats::SGBRG8:
case libcamera::formats::SGRBG8:
case libcamera::formats::SRGGB8:
- fragmentShaderData = bayer_unpacked_frag;
- vertexShaderData = bayer_unpacked_vert;
+ shaderCfg.fragmentShaderData = bayer_unpacked_frag;
+ shaderCfg.vertexShaderData = bayer_unpacked_vert;
break;
case libcamera::formats::SBGGR10_CSI2P:
case libcamera::formats::SGBRG10_CSI2P:
case libcamera::formats::SGRBG10_CSI2P:
case libcamera::formats::SRGGB10_CSI2P:
- egl_.pushEnv(shaderEnv, "#define RAW10P");
+ egl_.pushEnv(shaderCfg.shaderEnv, "#define RAW10P");
if (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) {
- fragmentShaderData = bayer_unpacked_frag;
- vertexShaderData = bayer_unpacked_vert;
+ shaderCfg.fragmentShaderData = bayer_unpacked_frag;
+ shaderCfg.vertexShaderData = bayer_unpacked_vert;
glFormat_ = GL_RG;
bytesPerPixel_ = 2;
} else {
- fragmentShaderData = bayer_1x_packed_frag;
- vertexShaderData = identity_vert;
+ shaderCfg.fragmentShaderData = bayer_1x_packed_frag;
+ shaderCfg.vertexShaderData = identity_vert;
shaderStridePixels_ = passInputCfg_.size.width;
}
break;
@@ -133,50 +75,20 @@ int GpuIspShaderPassDemosiac::initShaders(PixelFormat inputFormat, PixelFormat o
case libcamera::formats::SGBRG12_CSI2P:
case libcamera::formats::SGRBG12_CSI2P:
case libcamera::formats::SRGGB12_CSI2P:
- egl_.pushEnv(shaderEnv, "#define RAW12P");
+ egl_.pushEnv(shaderCfg.shaderEnv, "#define RAW12P");
if (BayerFormat::fromPixelFormat(inputFormat).packing == BayerFormat::Packing::None) {
- fragmentShaderData = bayer_unpacked_frag;
- vertexShaderData = bayer_unpacked_vert;
+ shaderCfg.fragmentShaderData = bayer_unpacked_frag;
+ shaderCfg.vertexShaderData = bayer_unpacked_vert;
glFormat_ = GL_RG;
bytesPerPixel_ = 2;
} else {
- fragmentShaderData = bayer_1x_packed_frag;
- vertexShaderData = identity_vert;
+ shaderCfg.fragmentShaderData = bayer_1x_packed_frag;
+ shaderCfg.vertexShaderData = identity_vert;
shaderStridePixels_ = passInputCfg_.size.width;
}
break;
};
- if (egl_.compileVertexShader(vertexShaderId_, vertexShaderData,
- shaderEnv)) {
- LOG(GpuShaderDemosiac, Error) << "Compile vertex shader fail";
- return -ENODEV;
- }
- utils::scope_exit vShaderGuard([&] { glDeleteShader(vertexShaderId_); });
-
- if (egl_.compileFragmentShader(fragmentShaderId_, fragmentShaderData,
- shaderEnv)) {
- LOG(GpuShaderDemosiac, Error) << "Compile fragment shader fail";
- return -ENODEV;
- }
- utils::scope_exit fShaderGuard([&] { glDeleteShader(fragmentShaderId_); });
-
- if (egl_.linkProgram(programId_, vertexShaderId_, fragmentShaderId_)) {
- LOG(GpuShaderDemosiac, Error) << "Linking program fail";
- return -ENODEV;
- }
-
- egl_.dumpShaderSource(vertexShaderId_);
- egl_.dumpShaderSource(fragmentShaderId_);
-
- /* Ensure we set the programId_ */
- glUseProgram(programId_);
- err = glGetError();
- if (err != GL_NO_ERROR) {
- LOG(GpuShaderDemosiac, Error) << "Use program error " << err;
- return -ENODEV;
- }
-
if (lscEnabled_) {
constexpr unsigned int gridSize = DebayerParams::kLscGridSize;
constexpr unsigned int stride = gridSize * DebayerParams::kLscBytesPerCell;
@@ -186,8 +98,7 @@ int GpuIspShaderPassDemosiac::initShaders(PixelFormat inputFormat, PixelFormat o
egl_.createTexture2D(*eglImageLscLookup_, nullptr, GL_LINEAR);
}
- return getShaderVariableLocations();
-
+ return 0;
}
int GpuIspShaderPassDemosiac::getShaderVariableLocations(void)
@@ -34,9 +34,9 @@ public:
GpuIspShaderPassDemosiac(eGL& egl) : GpuIspShaderPass(egl) {};
/* Things that every ISP pipeline pass will need to do */
- int initShaders(PixelFormat inputFormat, PixelFormat outputFormat) override;
int getShaderVariableLocations(void) override;
void setShaderVariableValues(eGLImage &eglImageIn, const DebayerParams ¶ms) override;
+ int selectShaders(struct ShaderConfig &shaderCfg, PixelFormat &inputFormat, PixelFormat &outputFormat) override;
void setLscEnabled(bool enabled) { lscEnabled_ = enabled; }
void stop() override;
Shader initialisation has some common and some pass-specific logic that needs to happen. - Common: Environment setup such as defining top-level defines as flags to include features when compiling shaders. This will have to be consistent from one shader feeding the next. - Shader specific: Selecting which vertex, fragment and potentially compute shaders to run - populating the shader compile environment with any defines specific to that shader. - Common: Compiling and linking a shader program. Error checking and associating a compiled vertex/fragment or compute shader with a given programId_. Move the common code to the base class and have the base class call out to a pure virtual funtion that the derived class must implement. In this way GpuIspShaderPass::initShaders() calls the derived class GpuIspShaderPassDerivedClass::selectShader() while encapsulating that call in the afore mentioned common pieces of logic. Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> --- .../software_isp/gpu_pipeline_shader_pass.cpp | 100 +++++++++++++++ .../software_isp/gpu_pipeline_shader_pass.h | 9 +- .../gpu_pipeline_shader_pass_demosiac.cpp | 119 +++--------------- .../gpu_pipeline_shader_pass_demosiac.h | 2 +- 4 files changed, 124 insertions(+), 106 deletions(-)