KhronosGroup / Vulkan-Samples

One stop solution for all Vulkan samples
Apache License 2.0
4.18k stars 625 forks source link

compile third_party/ktx/lib/basisu/zstd/zstd.c failed when -Og is passed #1089

Open sandy-lcq opened 2 months ago

sandy-lcq commented 2 months ago

Hi,

I am compiling Vulkan Sample with yocto project, and found that when -Og is passed to the compile command, the build will failed with following error, without -Og, it can build success. Error: In function 'ZSTD_compressBlock_lazy_generic', inlined from 'ZSTD_compressBlock_lazy2' at /mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/ktx/lib/basisu/zstd/zstd.c:21900:12: /mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/ktx/lib/basisu/zstd/zstd.c:21551:30: error: inlining failed in call to 'always_inline' 'ZSTD_HcFindBestMatch_selectMLS': function not considered for inlining 21551 | FORCE_INLINE_TEMPLATE size_t ZSTD_HcFindBestMatch_selectMLS ( | ^~~~~~~~~~ /mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/ktx/lib/basisu/zstd/zstd.c:21736:32: note: called from here 21736 | size_t const ml2 = searchMax(ms, ip, iend, &offsetFound); | ^~~~~~~~~ ....

The whole compile command : /mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/recipe-sysroot-native/usr/bin/x86_64-wrs-linux/x86_64-wrs-linux-gcc --sysroot=/mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/recipe-sysroot -DBASISD_SUPPORT_KTX2_ZSTD=0 -DBASISU_NO_ITERATOR_DEBUG_LEVEL -DKTX_FEATURE_WRITE=0 -DLIBKTX -DROOT_PATH_SIZE=35 -DVK_NO_PROTOTYPES -DVK_USE_PLATFORM_DISPLAY_KHR -I/mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/ktx/include -I/mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/ktx/lib -I/mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/ktx/lib/basisu/zstd -I/mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/ktx/lib/basisu/transcoder -I/mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/ktx/other_include -I/mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/vulkan/include -m64 -march=core2 -mtune=core2 -msse3 -mfpmath=sse -fstack-protector-strong -Og -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/recipe-sysroot -Og -g -feliminate-unused-debug-types -fcanon-prefix-map -fmacro-prefix-map=/mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git=/usr/src/debug/vulkan-samples/git -fdebug-prefix-map=/mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git=/usr/src/debug/vulkan-samples/git -fmacro-prefix-map=/mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/build=/usr/src/debug/vulkan-samples/git -fdebug-prefix-map=/mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/build=/usr/src/debug/vulkan-samples/git -fdebug-prefix-map=/mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/recipe-sysroot= -fmacro-prefix-map=/mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/recipe-sysroot= -fdebug-prefix-map=/mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/recipe-sysroot-native= -pipe -DNDEBUG -fPIC -MD -MT third_party/CMakeFiles/ktx.dir/ktx/lib/basisu/zstd/zstd.c.o -MF third_party/CMakeFiles/ktx.dir/ktx/lib/basisu/zstd/zstd.c.o.d -o third_party/CMakeFiles/ktx.dir/ktx/lib/basisu/zstd/zstd.c.o -c /mnt/lts24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/ktx/lib/basisu/zstd/zstd.c

gcc version gcc version 13.2.0 (GCC)

Analyze Refer https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107931, we can know, it is not suggest to use always_inline + indirect function call. zstd.c should be changed to fix this. For linux, Eg: -FORCE_INLINE_TEMPLATE size_t ZSTD_HcFindBestMatch_extDictselectMLS ( +static __inline_\ size_t ZSTD_HcFindBestMatch_extDict_selectMLS (

I checked latest https://github.com/KhronosGroup/KTX-Software, seems above line already not existed, since zstd.c is updated. So should we update ktx? and I am not sure if latest ktx have similar issue.

SaschaWillems commented 1 month ago

Before we update the KTX submodule in our repo, can you make sure that the latest KTX version actually compiles with your setup?

sandy-lcq commented 1 month ago

Hi,

I tired to verify above issue with latest stable version v4.3.2 of KTX-Software. But since changes between current ktx and v4.3.2, third_party/CMakeLists.txt is not suitable for v4.3.2, eg: there is no lib/stream.h in v4.3.2, so I cannot do the whole compile of vulkan-samples with v4.3.2. Then I switched to just compile with following command to verify if the issue still exist with v4.3.2's zstd.c: /mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/recipe-sysroot-native/usr/bin/x86_64-wrs-linux/x86_64-wrs-linux-gcc --sysroot=/mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/recipe-sysroot -DBASISD_SUPPORT_KTX2_ZSTD=0 -DBASISU_NO_ITERATOR_DEBUG_LEVEL -DKTX_FEATURE_WRITE=0 -DLIBKTX -DROOT_PATH_SIZE=35 -DVK_NO_PROTOTYPES -DVK_USE_PLATFORM_DISPLAY_KHR -I/mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/ktx/include -I/mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/ktx/lib -I/mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/ktx/lib/basisu/zstd -I/mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/ktx/lib/basisu/transcoder -I/mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/ktx/other_include -I/mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/vulkan/include -m64 -march=core2 -mtune=core2 -msse3 -mfpmath=sse -fstack-protector-strong -Og -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/recipe-sysroot -Og -g -feliminate-unused-debug-types -fcanon-prefix-map -fmacro-prefix-map=/mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git=/usr/src/debug/vulkan-samples/git -fdebug-prefix-map=/mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git=/usr/src/debug/vulkan-samples/git -fmacro-prefix-map=/mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/build=/usr/src/debug/vulkan-samples/git -fdebug-prefix-map=/mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/build=/usr/src/debug/vulkan-samples/git -fdebug-prefix-map=/mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/recipe-sysroot= -fmacro-prefix-map=/mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/recipe-sysroot= -fdebug-prefix-map=/mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/recipe-sysroot-native= -pipe -DNDEBUG -fPIC -MD -MT third_party/zstd.c.o -MF third_party/zstd.c.o.d -o third_party/zstd.c.o -c /mnt/24/build/tmp-glibc/work/core2-64-wrs-linux/vulkan-samples/git/git/third_party/ktx/lib/basisu/zstd/zstd.c

And it compiled successfully, and zstd.c.o and zstd.c.o.d is generated.

SaschaWillems commented 1 month ago

Thanks for confirming. We will update ktx to a newer version, but no ETA on that.

SaschaWillems commented 1 week ago

Can you check if https://github.com/KhronosGroup/Vulkan-Samples/pull/1139 compiles for you? That updates to the latest KTX release.

sandy-lcq commented 1 week ago

Hi, @SaschaWillems

I tested with ktx_update branch, https://github.com/SaschaWillems/Vulkan-Samples/tree/ktx_update. Above issue fixed, it can compile successfully.

Thanks

SaschaWillems commented 1 week ago

Thank you very much for confirming. So once we merge that PR this issue will be solved.