swscale/vulkan: compile SPIR-V backed only if SPIR-V headers are found

Instead of making Vulkan depend on the headers, make the compilation of
the SPIR-V backend depend on the headers.

Sponsored-by: Sovereign Tech Fund
This commit is contained in:
Lynne committed 2026-04-04 19:02:27 +00:00
1 parent 69fc910777
commit 2b6fbcad6d
4 files changed
+34 -12

No files matched your search

Vendored
+8 -3
View File
@@ -2496,6 +2496,8 @@ HEADERS_LIST="
valgrind_valgrind_h
windows_h
winsock2_h
spirv_headers_spirv_h
spirv_unified1_spirv_h
"
INTRINSICS_LIST="
@@ -7796,9 +7798,6 @@ enabled vdpau &&
check_lib vdpau_x11 "vdpau/vdpau.h vdpau/vdpau_x11.h" vdp_device_create_x11 -lvdpau -lX11
# Check for the Vulkan headers
if enabled vulkan; then
check_cpp_condition vulkan "spirv/unified1/spirv.h" "defined(SPV_VERSION)"
fi
if enabled_all vulkan vulkan_static; then
check_pkg_config vulkan "vulkan >= 1.3.277" "vulkan/vulkan.h" "defined VK_VERSION_1_3" ||
check_lib vulkan "vulkan/vulkan.h" vkGetInstanceProcAddr -lvulkan
@@ -7856,6 +7855,12 @@ else
disable libglslang libshaderc spirv_library spirv_compiler
fi
if enabled vulkan; then
check_headers spirv-headers/spirv.h ||
check_headers spirv/unified1/spirv.h ||
warn "spirv-headers not found, swscale SPIR-V backend unavailable"
fi
if enabled x86; then
case $target_os in
freebsd|mingw32*|mingw64*|win32|win64|linux|cygwin*)
+4 -2
View File
@@ -34,7 +34,9 @@ extern const SwsOpBackend backend_c;
extern const SwsOpBackend backend_murder;
extern const SwsOpBackend backend_aarch64;
extern const SwsOpBackend backend_x86;
#if HAVE_SPIRV_HEADERS_SPIRV_H || HAVE_SPIRV_UNIFIED1_SPIRV_H
extern const SwsOpBackend backend_spirv;
#endif
#if CONFIG_LIBSHADERC || CONFIG_LIBGLSLANG
extern const SwsOpBackend backend_glsl;
#endif
@@ -47,11 +49,11 @@ const SwsOpBackend * const ff_sws_op_backends[] = {
&backend_x86,
#endif
&backend_c,
#if CONFIG_VULKAN
#if HAVE_SPIRV_HEADERS_SPIRV_H || HAVE_SPIRV_UNIFIED1_SPIRV_H
&backend_spirv,
#endif
#if CONFIG_LIBSHADERC || CONFIG_LIBGLSLANG
&backend_glsl,
#endif
#endif
NULL
};
+13 -7
View File
@@ -25,7 +25,10 @@
#include "../swscale_internal.h"
#include "ops.h"
#if HAVE_SPIRV_HEADERS_SPIRV_H || HAVE_SPIRV_UNIFIED1_SPIRV_H
#include "spvasm.h"
#endif
static void ff_sws_vk_uninit(AVRefStructOpaque opaque, void *obj)
{
@@ -204,6 +207,7 @@ fail:
return err;
}
#if HAVE_SPIRV_HEADERS_SPIRV_H || HAVE_SPIRV_UNIFIED1_SPIRV_H
struct DitherData {
int size;
int arr_1d_id;
@@ -883,6 +887,7 @@ static int add_ops_spirv(VulkanPriv *p, FFVulkanOpsCtx *s,
return ff_vk_shader_link(&s->vkctx, shd, spvbuf, len, "main");
}
#endif
#if CONFIG_LIBSHADERC || CONFIG_LIBGLSLANG
static void add_desc_read_write(FFVulkanDescriptorSetBinding *out_desc,
@@ -1159,19 +1164,18 @@ static int compile(SwsContext *sws, SwsOpList *ops, SwsCompiledOp *out, int glsl
}
if (glsl) {
err = AVERROR(ENOTSUP);
#if CONFIG_LIBSHADERC || CONFIG_LIBGLSLANG
err = add_ops_glsl(p, s, ops, &p->shd);
if (err < 0)
goto fail;
#else
err = AVERROR(ENOTSUP);
goto fail;
#endif
} else {
err = AVERROR(ENOTSUP);
#if HAVE_SPIRV_HEADERS_SPIRV_H || HAVE_SPIRV_UNIFIED1_SPIRV_H
err = add_ops_spirv(p, s, ops, &p->shd);
if (err < 0)
goto fail;
#endif
}
if (err < 0)
goto fail;
err = ff_vk_shader_register_exec(&s->vkctx, &p->e, &p->shd);
if (err < 0)
@@ -1196,6 +1200,7 @@ fail:
return err;
}
#if HAVE_SPIRV_HEADERS_SPIRV_H || HAVE_SPIRV_UNIFIED1_SPIRV_H
static int compile_spirv(SwsContext *sws, SwsOpList *ops, SwsCompiledOp *out)
{
return compile(sws, ops, out, 0);
@@ -1206,6 +1211,7 @@ const SwsOpBackend backend_spirv = {
.compile = compile_spirv,
.hw_format = AV_PIX_FMT_VULKAN,
};
#endif
#if CONFIG_LIBSHADERC || CONFIG_LIBGLSLANG
static int compile_glsl(SwsContext *sws, SwsOpList *ops, SwsCompiledOp *out)
+9
View File
@@ -23,11 +23,20 @@
#include <stdint.h>
#include <string.h>
#include "config.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/avassert.h"
#if HAVE_SPIRV_HEADERS_SPIRV_H
#include <spirv-headers/spirv.h>
#include <spirv-headers/GLSL.std.450.h>
#endif
#if HAVE_SPIRV_UNIFIED1_SPIRV_H
#include <spirv/unified1/spirv.h>
#include <spirv/unified1/GLSL.std.450.h>
#endif
/* COUNT_ARGS: counts variadic macro arguments, including zero.
* The sentinel 0 is prepended so the compound literal is never empty,