Skip to content

Commit

Permalink
vkCodecUtils: generate a static library
Browse files Browse the repository at this point in the history
  • Loading branch information
dabrain34 authored and zlatinski committed Nov 12, 2024
1 parent cc58176 commit a72c1aa
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 37 deletions.
14 changes: 1 addition & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -677,19 +677,7 @@ else()
PATTERN "*.a" EXCLUDE)
endif()

# Define a custom target to generate the dispatch table files
add_custom_target(GenerateDispatchTables
DEPENDS ${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.h
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.cpp
)

# Add the custom command to generate the dispatch tables
macro(generate_dispatch_table out)
add_custom_command(OUTPUT ${out}
COMMAND ${PYTHON_EXECUTABLE} ${SCRIPTS_DIR}/generate-dispatch-table.py ${out}
DEPENDS ${SCRIPTS_DIR}/generate-dispatch-table.py
)
endmacro()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/common/libs/VkCodecUtils)

if(BUILD_DECODER)
add_subdirectory(vk_video_decoder)
Expand Down
25 changes: 25 additions & 0 deletions common/libs/VkCodecUtils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Define a custom target to generate the dispatch table files
add_custom_target(GenerateDispatchTables
DEPENDS ${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.h
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.cpp
)

# Add the custom command to generate the dispatch tables
macro(generate_dispatch_table out)
add_custom_command(OUTPUT ${out}
COMMAND ${PYTHON_EXECUTABLE} ${SCRIPTS_DIR}/generate-dispatch-table.py ${out}
DEPENDS ${SCRIPTS_DIR}/generate-dispatch-table.py
)
endmacro()

set (gen_codec_utils_sources
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.cpp
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.h
)

generate_dispatch_table(${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.h)
generate_dispatch_table(${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.cpp)


# Create a static library from the generated file
add_library(GenCodecUtilsLib STATIC ${gen_codec_utils_sources})
6 changes: 0 additions & 6 deletions vk_video_decoder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ cmake_minimum_required(VERSION 3.0)

include(CheckCXXCompilerFlag)







add_dependencies(VkVideoUtils generate_helper_files)
target_include_directories(
VkVideoUtils PUBLIC
Expand Down
6 changes: 2 additions & 4 deletions vk_video_decoder/demos/vk-video-dec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@ macro(compile_cuda src)
)
endmacro()

generate_dispatch_table(${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.h)
generate_dispatch_table(${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.cpp)

set(sources
Main.cpp
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkShell/Shell.cpp
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkShell/ShellDirect.cpp
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkShell/Shell.h
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/Helpers.h
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.cpp
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.h
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/VulkanDeviceContext.cpp
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/VulkanDeviceContext.h
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/VulkanShaderCompiler.cpp
Expand Down Expand Up @@ -139,6 +135,8 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
endif()
endif()

list(APPEND libraries GenCodecUtilsLib)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)

list(APPEND includes PRIVATE ${VK_VIDEO_DECODER_LIBS_INCLUDE_ROOT})
Expand Down
7 changes: 2 additions & 5 deletions vk_video_encoder/demos/vk-video-enc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ macro(compile_cuda src)
)
endmacro()

generate_dispatch_table(${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.h)
generate_dispatch_table(${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.cpp)

set(sources
Main.cpp
${VK_VIDEO_ENCODER_LIBS_SOURCE_ROOT}/VkVideoEncoder/VkEncoderConfigH264.cpp
Expand All @@ -42,8 +39,6 @@ set(sources
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkShell/ShellDirect.cpp
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkShell/Shell.h
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/Helpers.h
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.cpp
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.h
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/VulkanDeviceContext.cpp
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/VulkanDeviceContext.h
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/VulkanShaderCompiler.cpp
Expand Down Expand Up @@ -170,6 +165,8 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
endif()
endif()

list(APPEND libraries GenCodecUtilsLib)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)

list(APPEND includes PRIVATE ${VK_VIDEO_DECODER_LIBS_INCLUDE_ROOT})
Expand Down
11 changes: 2 additions & 9 deletions vk_video_encoder/libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ if(WIN32)
add_definitions(-DVK_USE_PLATFORM_WIN32_KHR)
endif()

generate_dispatch_table(${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.h)
generate_dispatch_table(${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.cpp)

# Even though shaderc.hpp is a headers-only library, adding
# a dependency here will force clients of the library to rebuild
# when it changes.
Expand All @@ -53,8 +50,6 @@ set(LIBVKVIDEOENCODER
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/YCbCrConvUtilsCpu.cpp
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/YCbCrConvUtilsCpu.h
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/Helpers.h
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.cpp
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/HelpersDispatchTable.h
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/VulkanDeviceContext.cpp
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/VulkanDeviceContext.h
${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT}/VkCodecUtils/VulkanDeviceMemoryImpl.h
Expand Down Expand Up @@ -97,8 +92,7 @@ include_directories(BEFORE ${VULKAN_VIDEO_ENCODER_INCLUDE})
include_directories(BEFORE ${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT})

add_library(${VULKAN_VIDEO_ENCODER_LIB} SHARED ${LIBVKVIDEOENCODER})
# Ensure the library depends on the generation of these files
add_dependencies(${VULKAN_VIDEO_ENCODER_LIB} GenerateDispatchTables)
target_link_libraries(${VULKAN_VIDEO_ENCODER_LIB} GenCodecUtilsLib)

target_include_directories(${VULKAN_VIDEO_ENCODER_LIB} PUBLIC ${VULKAN_VIDEO_ENCODER_INCLUDE} ${VULKAN_VIDEO_ENCODER_INCLUDE}/../NvVideoParser PRIVATE include)
target_compile_definitions(${VULKAN_VIDEO_ENCODER_LIB}
Expand All @@ -121,8 +115,7 @@ if(WIN32)
endif()

add_library(${VULKAN_VIDEO_ENCODER_STATIC_LIB} STATIC ${LIBVKVIDEOENCODER})
# Ensure the library depends on the generation of these files
add_dependencies(${VULKAN_VIDEO_ENCODER_STATIC_LIB} GenerateDispatchTables)

target_include_directories(${VULKAN_VIDEO_ENCODER_STATIC_LIB} PUBLIC ${VULKAN_VIDEO_ENCODER_INCLUDE} ${VULKAN_VIDEO_ENCODER_INCLUDE}/../NvVideoParser PRIVATE include)

install(TARGETS ${VULKAN_VIDEO_ENCODER_LIB} ${VULKAN_VIDEO_ENCODER_STATIC_LIB}
Expand Down
2 changes: 2 additions & 0 deletions vk_video_encoder/test/vulkan-video-enc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
list(APPEND VULKAN_VIDEO_ENC_LIBRARIES PRIVATE -ldl -lrt -lpthread)
endif()

list(APPEND VULKAN_VIDEO_ENC_LIBRARIES GenCodecUtilsLib)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)

list(APPEND VULKAN_VIDEO_ENC_INCLUDES PRIVATE ${VK_VIDEO_COMMON_LIBS_SOURCE_ROOT})
Expand Down

0 comments on commit a72c1aa

Please sign in to comment.