mirror of
https://mirror.skon.top/https://github.com/FFmpeg/FFmpeg
synced 2026-04-30 13:50:50 +08:00
vulkan: support shader compression
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -25,6 +25,7 @@
|
||||
*.metallib.c
|
||||
*.spv
|
||||
*.spv.c
|
||||
*.spv.gz
|
||||
*.ptx
|
||||
*.ptx.c
|
||||
*.ptx.gz
|
||||
|
||||
2
configure
vendored
2
configure
vendored
@@ -4246,7 +4246,7 @@ avfilter_deps="avutil"
|
||||
avfilter_suggest="libm stdatomic spirv_library"
|
||||
avformat_deps="avcodec avutil"
|
||||
avformat_suggest="libm network zlib stdatomic"
|
||||
avutil_suggest="clock_gettime ffnvcodec gcrypt libm libdrm libmfx opencl openssl user32 vaapi vulkan videotoolbox corefoundation corevideo coremedia bcrypt stdatomic"
|
||||
avutil_suggest="clock_gettime ffnvcodec gcrypt libm zlib libdrm libmfx opencl openssl user32 vaapi vulkan videotoolbox corefoundation corevideo coremedia bcrypt stdatomic"
|
||||
swresample_deps="avutil"
|
||||
swresample_suggest="libm libsoxr stdatomic"
|
||||
swscale_deps="avutil"
|
||||
|
||||
@@ -134,8 +134,16 @@ RUN_MINIFY = $(M)sed 's!/\\*.*\\*/!!g' $< | tr '\n' ' ' | tr -s ' ' | sed 's/^ /
|
||||
%.spv: %.glsl
|
||||
$(COMPILE_GLSLC)
|
||||
|
||||
ifdef CONFIG_SHADER_COMPRESSION
|
||||
%.spv.gz: %.spv
|
||||
$(RUN_GZIP)
|
||||
|
||||
%.spv.c: %.spv.gz $(BIN2CEXE)
|
||||
$(RUN_BIN2C)
|
||||
else
|
||||
%.spv.c: %.spv $(BIN2CEXE)
|
||||
$(RUN_BIN2C)
|
||||
endif
|
||||
|
||||
%.metal.air: %.metal
|
||||
$(METALCC) $< -o $@
|
||||
@@ -239,7 +247,7 @@ SPVOBJS = $(filter %.spv.o,$(OBJS))
|
||||
PTXOBJS = $(filter %.ptx.o,$(OBJS))
|
||||
$(HOBJS): CCFLAGS += $(CFLAGS_HEADERS)
|
||||
checkheaders: $(HOBJS)
|
||||
.SECONDARY: $(HOBJS:.o=.c) $(SPVOBJS:.o=.c) $(SPVOBJS:.o=) $(PTXOBJS:.o=.c) $(PTXOBJS:.o=.gz) $(PTXOBJS:.o=)
|
||||
.SECONDARY: $(HOBJS:.o=.c) $(SPVOBJS:.o=.c) $(SPVOBJS:.o=.gz) $(SPVOBJS:.o=) $(PTXOBJS:.o=.c) $(PTXOBJS:.o=.gz) $(PTXOBJS:.o=)
|
||||
alltools: $(TOOLS)
|
||||
|
||||
$(HOSTOBJS): %.o: %.c
|
||||
@@ -258,7 +266,7 @@ $(TOOLOBJS): | tools
|
||||
|
||||
OUTDIRS := $(OUTDIRS) $(dir $(OBJS) $(HOBJS) $(HOSTOBJS) $(SHLIBOBJS) $(STLIBOBJS) $(TESTOBJS))
|
||||
|
||||
CLEANSUFFIXES = *.d *.gcda *.gcno *.h.c *.ho *.map *.o *.objs *.pc *.ptx *.ptx.gz *.ptx.c *.spv *.spv.c *.ver *.version *.html.gz *.html.c *.css.min.gz *.css.min *.css.c *$(DEFAULT_X86ASMD).asm *~ *.ilk *.pdb
|
||||
CLEANSUFFIXES = *.d *.gcda *.gcno *.h.c *.ho *.map *.o *.objs *.pc *.ptx *.ptx.gz *.ptx.c *.spv *.spv.gz *.spv.c *.ver *.version *.html.gz *.html.c *.css.min.gz *.css.min *.css.c *$(DEFAULT_X86ASMD).asm *~ *.ilk *.pdb
|
||||
LIBSUFFIXES = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a
|
||||
|
||||
define RULES
|
||||
|
||||
@@ -18,12 +18,17 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "avassert.h"
|
||||
#include "mem.h"
|
||||
|
||||
#include "vulkan.h"
|
||||
#include "libavutil/vulkan_loader.h"
|
||||
|
||||
#if CONFIG_SHADER_COMPRESSION
|
||||
#include "libavutil/zlib_utils.h"
|
||||
#endif
|
||||
|
||||
const VkComponentMapping ff_comp_identity_map = {
|
||||
.r = VK_COMPONENT_SWIZZLE_IDENTITY,
|
||||
.g = VK_COMPONENT_SWIZZLE_IDENTITY,
|
||||
@@ -2388,7 +2393,7 @@ int ff_vk_shader_link(FFVulkanContext *s, FFVulkanShader *shd,
|
||||
FFVulkanFunctions *vk = &s->vkfn;
|
||||
VkSpecializationMapEntry spec_entries[3];
|
||||
VkSpecializationInfo spec_info;
|
||||
size_t binary_size = 0;
|
||||
size_t input_size = spirv_len, binary_size = 0;
|
||||
|
||||
if (shd->precompiled) {
|
||||
if (!shd->specialization_info) {
|
||||
@@ -2414,6 +2419,16 @@ int ff_vk_shader_link(FFVulkanContext *s, FFVulkanShader *shd,
|
||||
memcpy(&spd[shd->specialization_info->dataSize],
|
||||
shd->lg_size, 3*sizeof(uint32_t));
|
||||
shd->specialization_info->dataSize += 3*sizeof(uint32_t);
|
||||
|
||||
#if CONFIG_SHADER_COMPRESSION
|
||||
uint8_t *out;
|
||||
size_t out_len;
|
||||
int ret = ff_zlib_expand(s, &out, &out_len, spirv, spirv_len);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
spirv = out;
|
||||
spirv_len = out_len;
|
||||
#endif
|
||||
}
|
||||
|
||||
err = init_descriptors(s, shd);
|
||||
@@ -2462,6 +2477,8 @@ int ff_vk_shader_link(FFVulkanContext *s, FFVulkanShader *shd,
|
||||
else
|
||||
av_log(s, AV_LOG_VERBOSE, "Shader linked, size:");
|
||||
|
||||
if (input_size != spirv_len)
|
||||
av_log(s, AV_LOG_VERBOSE, " %zu compressed,", input_size);
|
||||
av_log(s, AV_LOG_VERBOSE, " %zu SPIR-V", spirv_len);
|
||||
if (binary_size != spirv_len)
|
||||
av_log(s, AV_LOG_VERBOSE, ", %zu binary", spirv_len);
|
||||
@@ -2472,6 +2489,10 @@ end:
|
||||
shd->specialization_info->mapEntryCount -= 3;
|
||||
shd->specialization_info->dataSize -= 3*sizeof(uint32_t);
|
||||
}
|
||||
#if CONFIG_SHADER_COMPRESSION
|
||||
if (shd->precompiled)
|
||||
av_free((void *)spirv);
|
||||
#endif
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user