diff mbox series

[FFmpeg-devel,4/4] lavc/vulkan: add SPIR-V compilation support

Message ID 20241004093137.139470-4-dev@lynne.ee
State New
Headers show
Series [FFmpeg-devel,1/4] lavfi/vulkan: remove redundant header | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 fail Make fate failed
andriy/make_x86 success Make finished
andriy/make_fate_x86 fail Make fate failed

Commit Message

Lynne Oct. 4, 2024, 9:31 a.m. UTC
This is the same as with libavfilter.

We will need SPIR-V compilation for at least three different things,
like the VC-2 encoder and decoder, AV1 film grain synthesis for
hardware with no support for it, and possibly other codecs.
---
 libavcodec/Makefile         |  4 ++++
 libavcodec/vulkan_glslang.c | 19 +++++++++++++++++++
 libavcodec/vulkan_shaderc.c | 19 +++++++++++++++++++
 3 files changed, 42 insertions(+)
 create mode 100644 libavcodec/vulkan_glslang.c
 create mode 100644 libavcodec/vulkan_shaderc.c

Comments

Marvin Scholz Oct. 4, 2024, 10:01 a.m. UTC | #1
On 4 Oct 2024, at 11:31, Lynne via ffmpeg-devel wrote:

> This is the same as with libavfilter.
>
> We will need SPIR-V compilation for at least three different things,
> like the VC-2 encoder and decoder, AV1 film grain synthesis for
> hardware with no support for it, and possibly other codecs.
> ---
>  libavcodec/Makefile         |  4 ++++
>  libavcodec/vulkan_glslang.c | 19 +++++++++++++++++++
>  libavcodec/vulkan_shaderc.c | 19 +++++++++++++++++++
>  3 files changed, 42 insertions(+)
>  create mode 100644 libavcodec/vulkan_glslang.c
>  create mode 100644 libavcodec/vulkan_shaderc.c
>
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index a253a9b160..7147ed0360 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1257,6 +1257,10 @@ OBJS-$(HAVE_THREADS)                   += pthread.o pthread_slice.o pthread_fram
>
>  OBJS-$(CONFIG_FRAME_THREAD_ENCODER)    += frame_thread_encoder.o
>
> +# vulkan libs
> +OBJS-$(CONFIG_LIBGLSLANG)              += vulkan_glslang.o
> +OBJS-$(CONFIG_LIBSHADERC)              += vulkan_shaderc.o
> +
>  # Windows resource file
>  SHLIBOBJS-$(HAVE_GNU_WINDRES)           += avcodecres.o
>
> diff --git a/libavcodec/vulkan_glslang.c b/libavcodec/vulkan_glslang.c
> new file mode 100644
> index 0000000000..9aa41567a3
> --- /dev/null
> +++ b/libavcodec/vulkan_glslang.c
> @@ -0,0 +1,19 @@
> +/*
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "libavutil/vulkan_glslang.c"
> diff --git a/libavcodec/vulkan_shaderc.c b/libavcodec/vulkan_shaderc.c
> new file mode 100644
> index 0000000000..9f60bf4dfd
> --- /dev/null
> +++ b/libavcodec/vulkan_shaderc.c
> @@ -0,0 +1,19 @@
> +/*
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "libavutil/vulkan_shaderc.c"

Wouldn’t this cause duplicate symbol issues with for example ff_vk_shaderc_init
being in both libavfilter and libavcodec?

> -- 
> 2.45.2.753.g447d99e1c3b
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Lynne Oct. 4, 2024, 10:41 a.m. UTC | #2
On 04/10/2024 12:01, epirat07@gmail.com wrote:
> On 4 Oct 2024, at 11:31, Lynne via ffmpeg-devel wrote:
> 
>> This is the same as with libavfilter.
>>
>> We will need SPIR-V compilation for at least three different things,
>> like the VC-2 encoder and decoder, AV1 film grain synthesis for
>> hardware with no support for it, and possibly other codecs.
>> ---
>>   libavcodec/Makefile         |  4 ++++
>>   libavcodec/vulkan_glslang.c | 19 +++++++++++++++++++
>>   libavcodec/vulkan_shaderc.c | 19 +++++++++++++++++++
>>   3 files changed, 42 insertions(+)
>>   create mode 100644 libavcodec/vulkan_glslang.c
>>   create mode 100644 libavcodec/vulkan_shaderc.c
>>
>> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
>> index a253a9b160..7147ed0360 100644
>> --- a/libavcodec/Makefile
>> +++ b/libavcodec/Makefile
>> @@ -1257,6 +1257,10 @@ OBJS-$(HAVE_THREADS)                   += pthread.o pthread_slice.o pthread_fram
>>
>>   OBJS-$(CONFIG_FRAME_THREAD_ENCODER)    += frame_thread_encoder.o
>>
>> +# vulkan libs
>> +OBJS-$(CONFIG_LIBGLSLANG)              += vulkan_glslang.o
>> +OBJS-$(CONFIG_LIBSHADERC)              += vulkan_shaderc.o
>> +
>>   # Windows resource file
>>   SHLIBOBJS-$(HAVE_GNU_WINDRES)           += avcodecres.o
>>
>> diff --git a/libavcodec/vulkan_glslang.c b/libavcodec/vulkan_glslang.c
>> new file mode 100644
>> index 0000000000..9aa41567a3
>> --- /dev/null
>> +++ b/libavcodec/vulkan_glslang.c
>> @@ -0,0 +1,19 @@
>> +/*
>> + * This file is part of FFmpeg.
>> + *
>> + * FFmpeg is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU Lesser General Public
>> + * License as published by the Free Software Foundation; either
>> + * version 2.1 of the License, or (at your option) any later version.
>> + *
>> + * FFmpeg is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> + * Lesser General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU Lesser General Public
>> + * License along with FFmpeg; if not, write to the Free Software
>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>> + */
>> +
>> +#include "libavutil/vulkan_glslang.c"
>> diff --git a/libavcodec/vulkan_shaderc.c b/libavcodec/vulkan_shaderc.c
>> new file mode 100644
>> index 0000000000..9f60bf4dfd
>> --- /dev/null
>> +++ b/libavcodec/vulkan_shaderc.c
>> @@ -0,0 +1,19 @@
>> +/*
>> + * This file is part of FFmpeg.
>> + *
>> + * FFmpeg is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU Lesser General Public
>> + * License as published by the Free Software Foundation; either
>> + * version 2.1 of the License, or (at your option) any later version.
>> + *
>> + * FFmpeg is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> + * Lesser General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU Lesser General Public
>> + * License along with FFmpeg; if not, write to the Free Software
>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>> + */
>> +
>> +#include "libavutil/vulkan_shaderc.c"
> 
> Wouldn’t this cause duplicate symbol issues with for example ff_vk_shaderc_init
> being in both libavfilter and libavcodec?

No. For completely identical objects like we have here, the linker 
deduplicates while linking.
This is how vulkan.c is also handled across libavutil, libavfilter and 
libavcodec. We also handle something else in the same way, but I don't 
remember what.
Martin Storsjö Oct. 4, 2024, 11:04 a.m. UTC | #3
On Fri, 4 Oct 2024, Lynne via ffmpeg-devel wrote:

> On 04/10/2024 12:01, epirat07@gmail.com wrote:
>> On 4 Oct 2024, at 11:31, Lynne via ffmpeg-devel wrote:
>> 
>>> This is the same as with libavfilter.
>>> 
>>> We will need SPIR-V compilation for at least three different things,
>>> like the VC-2 encoder and decoder, AV1 film grain synthesis for
>>> hardware with no support for it, and possibly other codecs.
>>> ---
>>>   libavcodec/Makefile         |  4 ++++
>>>   libavcodec/vulkan_glslang.c | 19 +++++++++++++++++++
>>>   libavcodec/vulkan_shaderc.c | 19 +++++++++++++++++++
>>>   3 files changed, 42 insertions(+)
>>>   create mode 100644 libavcodec/vulkan_glslang.c
>>>   create mode 100644 libavcodec/vulkan_shaderc.c
>>> 
>>> diff --git a/libavcodec/vulkan_shaderc.c b/libavcodec/vulkan_shaderc.c
>>> new file mode 100644
>>> index 0000000000..9f60bf4dfd
>>> --- /dev/null
>>> +++ b/libavcodec/vulkan_shaderc.c
>>> @@ -0,0 +1,19 @@
>>> +/*
>>> + * This file is part of FFmpeg.
>>> + *
>>> + * FFmpeg is free software; you can redistribute it and/or
>>> + * modify it under the terms of the GNU Lesser General Public
>>> + * License as published by the Free Software Foundation; either
>>> + * version 2.1 of the License, or (at your option) any later version.
>>> + *
>>> + * FFmpeg is distributed in the hope that it will be useful,
>>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>>> + * Lesser General Public License for more details.
>>> + *
>>> + * You should have received a copy of the GNU Lesser General Public
>>> + * License along with FFmpeg; if not, write to the Free Software
>>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
>>> 02110-1301 USA
>>> + */
>>> +
>>> +#include "libavutil/vulkan_shaderc.c"
>> 
>> Wouldn’t this cause duplicate symbol issues with for example 
>> ff_vk_shaderc_init
>> being in both libavfilter and libavcodec?
>
> No. For completely identical objects like we have here, the linker 
> deduplicates while linking.

Not quite...

A linker doesn't deduplicate things wrt static libraries; it's the other 
way around. With a static library, the linker only pulls in specifically 
the object files that are needed to fulfill some missing symbol. As long 
as both objects provide the exact same set of symbols, there's no 
collision and no issue with duplicates.

If you have two objects that provide a differing set of symbols, you may 
end up pulling in both object files, and you have such a conflict.

If a static library is linked with flags like --wholearchive, forcing the 
linker to pull in all object files (as if they were specified directly on 
the linker command line), you'd also hit the same conflict. (Not that we 
usually do this, though.)

> This is how vulkan.c is also handled across libavutil, libavfilter and 
> libavcodec. We also handle something else in the same way, but I don't 
> remember what.

I'm not sure about these cases, but we have a slightly similar thing with 
e.g. log2_tab.c, which contains an ff_ prefixed symbol; for static-only 
builds, we only provide the object file in libavutil, as it will be 
accessible to other libraries from there. For shared library builds, we 
include the object in the other shared libraries, so that the symbols 
(which aren't visible/exported across shared libraries) won't need to be 
accessed across shared libraries.

// Martin
diff mbox series

Patch

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a253a9b160..7147ed0360 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1257,6 +1257,10 @@  OBJS-$(HAVE_THREADS)                   += pthread.o pthread_slice.o pthread_fram
 
 OBJS-$(CONFIG_FRAME_THREAD_ENCODER)    += frame_thread_encoder.o
 
+# vulkan libs
+OBJS-$(CONFIG_LIBGLSLANG)              += vulkan_glslang.o
+OBJS-$(CONFIG_LIBSHADERC)              += vulkan_shaderc.o
+
 # Windows resource file
 SHLIBOBJS-$(HAVE_GNU_WINDRES)           += avcodecres.o
 
diff --git a/libavcodec/vulkan_glslang.c b/libavcodec/vulkan_glslang.c
new file mode 100644
index 0000000000..9aa41567a3
--- /dev/null
+++ b/libavcodec/vulkan_glslang.c
@@ -0,0 +1,19 @@ 
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/vulkan_glslang.c"
diff --git a/libavcodec/vulkan_shaderc.c b/libavcodec/vulkan_shaderc.c
new file mode 100644
index 0000000000..9f60bf4dfd
--- /dev/null
+++ b/libavcodec/vulkan_shaderc.c
@@ -0,0 +1,19 @@ 
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/vulkan_shaderc.c"