[18/35] meson: Automatically generate glsl_shaders.h from specified shader programs
diff mbox series

Message ID 20250611013245.133785-19-bryan.odonoghue@linaro.org
State New
Headers show
Series
  • Add GLES 2.0 GPUISP to libcamera
Related show

Commit Message

Bryan O'Donoghue June 11, 2025, 1:32 a.m. UTC
Encode the bayer shader files into a header as part of the build process.
Qcam already compiles the shader files down into a QT resource file which
it references internally.

In order to share the debayering shader programs outside of qcam create a
generic header which both qcam and libcamera can operate from.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
 include/libcamera/internal/meson.build         | 10 ++++++++++
 include/libcamera/internal/shaders/meson.build | 10 ++++++++++
 utils/meson.build                              |  2 ++
 3 files changed, 22 insertions(+)
 create mode 100644 include/libcamera/internal/shaders/meson.build

Comments

Barnabás Pőcze June 17, 2025, 11:50 a.m. UTC | #1
Hi

2025. 06. 11. 3:32 keltezéssel, Bryan O'Donoghue írta:
> Encode the bayer shader files into a header as part of the build process.
> Qcam already compiles the shader files down into a QT resource file which
> it references internally.
> 
> In order to share the debayering shader programs outside of qcam create a
> generic header which both qcam and libcamera can operate from.
> 
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> ---
>   include/libcamera/internal/meson.build         | 10 ++++++++++
>   include/libcamera/internal/shaders/meson.build | 10 ++++++++++
>   utils/meson.build                              |  2 ++
>   3 files changed, 22 insertions(+)
>   create mode 100644 include/libcamera/internal/shaders/meson.build
> 
> diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
> index 33f318b2..c0b593bf 100644
> --- a/include/libcamera/internal/meson.build
> +++ b/include/libcamera/internal/meson.build
> @@ -1,6 +1,7 @@
>   # SPDX-License-Identifier: CC0-1.0
>   
>   subdir('tracepoints')
> +subdir('shaders')
>   
>   libcamera_internal_headers = files([
>       'bayer_format.h',
> @@ -57,5 +58,14 @@ tracepoints_h = custom_target(
>   
>   libcamera_internal_headers += tracepoints_h
>   
> +libcamera_shader_headers = custom_target(
> +    'gen-shader-headers',
> +    input : [shader_files],
> +    output : 'glsl_shaders.h',
> +    command : [gen_shader_headers, meson.project_source_root(), meson.project_build_root(), '@OUTPUT@', '@INPUT@'],

I think `@OUTPUT@` should expand to an absolute path, so is passing
`meson.project_build_root()` needed?

Or could we maybe replace both with a single `files('gen-shader-header.py')`?

Or maybe better, could be use just a single python script that takes a list
of files and generates the header file? E.g. currently changing the python
script will not trigger a rebuild.


Regards,
Barnabás Pőcze

> +)
> +
> +libcamera_internal_headers += libcamera_shader_headers
> +
>   subdir('converter')
>   subdir('software_isp')
> diff --git a/include/libcamera/internal/shaders/meson.build b/include/libcamera/internal/shaders/meson.build
> new file mode 100644
> index 00000000..386b342d
> --- /dev/null
> +++ b/include/libcamera/internal/shaders/meson.build
> @@ -0,0 +1,10 @@
> +# SPDX-License-Identifier: CC0-1.0
> +
> +# List of shader files to convert to header hex
> +# for the purposes of inclusion in OpenGL debayering
> +shader_files = files([
> +    'bayer_1x_packed.frag',
> +    'bayer_8.frag',
> +    'bayer_8.vert',
> +    'identity.vert',
> +])
> diff --git a/utils/meson.build b/utils/meson.build
> index 95d657ac..3deed8ad 100644
> --- a/utils/meson.build
> +++ b/utils/meson.build
> @@ -3,5 +3,7 @@
>   subdir('codegen')
>   subdir('ipu3')
>   
> +gen_shader_headers = files('gen-shader-headers.sh')
> +
>   ## Module signing
>   gen_ipa_priv_key = files('gen-ipa-priv-key.sh')
Bryan O'Donoghue June 17, 2025, 11:58 a.m. UTC | #2
On 17/06/2025 12:50, Barnabás Pőcze wrote:
>> +    command : [gen_shader_headers, meson.project_source_root(), 
>> meson.project_build_root(), '@OUTPUT@', '@INPUT@'],
> 
> I think `@OUTPUT@` should expand to an absolute path, so is passing
> `meson.project_build_root()` needed?

I can look at that.


> Or could we maybe replace both with a single `files('gen-shader- 
> header.py')`?
> 
> Or maybe better, could be use just a single python script that takes a list
> of files and generates the header file? E.g. currently changing the python
> script will not trigger a rebuild.

What I like personally about having a python script is it does one job, 
translating an input file into a C array - directly replacing xxd which 
I was previously using but, we agreed at some stage to replace with a 
script.

Is having everything in one script important to you ?

---
bod
Barnabás Pőcze June 17, 2025, 12:38 p.m. UTC | #3
2025. 06. 17. 13:58 keltezéssel, Bryan O'Donoghue írta:
> On 17/06/2025 12:50, Barnabás Pőcze wrote:
>>> +    command : [gen_shader_headers, meson.project_source_root(), meson.project_build_root(), '@OUTPUT@', '@INPUT@'],
>>
>> I think `@OUTPUT@` should expand to an absolute path, so is passing
>> `meson.project_build_root()` needed?
> 
> I can look at that.
> 
> 
>> Or could we maybe replace both with a single `files('gen-shader- header.py')`?
>>
>> Or maybe better, could be use just a single python script that takes a list
>> of files and generates the header file? E.g. currently changing the python
>> script will not trigger a rebuild.
> 
> What I like personally about having a python script is it does one job, translating an input file into a C array - directly replacing xxd which I was previously using but, we agreed at some stage to replace with a script.
> 
> Is having everything in one script important to you ?

The current setup seems more complicated to me than having a single that does just
what is needed. But either seems acceptable to me, let's see what others think.
But for the two script solution, please add `depend_files: [ ... ]` on the
`custom_target()` to consider the python script as well.


Regards,
Barnabás Pőcze

> 
> ---
> bod

Patch
diff mbox series

diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
index 33f318b2..c0b593bf 100644
--- a/include/libcamera/internal/meson.build
+++ b/include/libcamera/internal/meson.build
@@ -1,6 +1,7 @@ 
 # SPDX-License-Identifier: CC0-1.0
 
 subdir('tracepoints')
+subdir('shaders')
 
 libcamera_internal_headers = files([
     'bayer_format.h',
@@ -57,5 +58,14 @@  tracepoints_h = custom_target(
 
 libcamera_internal_headers += tracepoints_h
 
+libcamera_shader_headers = custom_target(
+    'gen-shader-headers',
+    input : [shader_files],
+    output : 'glsl_shaders.h',
+    command : [gen_shader_headers, meson.project_source_root(), meson.project_build_root(), '@OUTPUT@', '@INPUT@'],
+)
+
+libcamera_internal_headers += libcamera_shader_headers
+
 subdir('converter')
 subdir('software_isp')
diff --git a/include/libcamera/internal/shaders/meson.build b/include/libcamera/internal/shaders/meson.build
new file mode 100644
index 00000000..386b342d
--- /dev/null
+++ b/include/libcamera/internal/shaders/meson.build
@@ -0,0 +1,10 @@ 
+# SPDX-License-Identifier: CC0-1.0
+
+# List of shader files to convert to header hex
+# for the purposes of inclusion in OpenGL debayering
+shader_files = files([
+    'bayer_1x_packed.frag',
+    'bayer_8.frag',
+    'bayer_8.vert',
+    'identity.vert',
+])
diff --git a/utils/meson.build b/utils/meson.build
index 95d657ac..3deed8ad 100644
--- a/utils/meson.build
+++ b/utils/meson.build
@@ -3,5 +3,7 @@ 
 subdir('codegen')
 subdir('ipu3')
 
+gen_shader_headers = files('gen-shader-headers.sh')
+
 ## Module signing
 gen_ipa_priv_key = files('gen-ipa-priv-key.sh')