1# Copyright (c) 2017-2021, Intel Corporation 2# 3# Permission is hereby granted, free of charge, to any person obtaining a 4# copy of this software and associated documentation files (the "Software"), 5# to deal in the Software without restriction, including without limitation 6# the rights to use, copy, modify, merge, publish, distribute, sublicense, 7# and/or sell copies of the Software, and to permit persons to whom the 8# Software is furnished to do so, subject to the following conditions: 9# 10# The above copyright notice and this permission notice shall be included 11# in all copies or substantial portions of the Software. 12# 13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 17# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 18# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 19# OTHER DEALINGS IN THE SOFTWARE. 20 21if (BUILD_KERNELS) 22 # Here we define build steps to generate c-array binary shaders (kernels) 23 # and their header files. If you don't use BUILD_KERNELS option these 24 # kernels will just be used from pre-built form. If you will regenerate 25 # kernels you may notice the difference from the per-built kernels in git-diff. 26 27 function(platform_to_genx platform genx kind) 28 if(platform STREQUAL "gen11") 29 set(genx "11" PARENT_SCOPE) 30 set(kind "" PARENT_SCOPE) 31 elseif(platform STREQUAL "gen11_icllp") 32 set(genx "11" PARENT_SCOPE) 33 set(kind "icllp" PARENT_SCOPE) 34 elseif(platform STREQUAL "gen12_tgllp") 35 set(genx "12" PARENT_SCOPE) 36 set(kind "tgllp" PARENT_SCOPE) 37 endif() 38 endfunction() 39 40 41 42 # This function describes object files generated by cmc from the given input cm-file. 43 # If cm-file has changed, it may be required to adjust this function. 44 function(get_cm_dat_objs file objs) 45 get_filename_component(name ${src} NAME) 46 if(name STREQUAL "downscale_kernel_genx.cpp") 47 set(objs 48 downscale_kernel_genx_0.dat 49 downscale_kernel_genx_1.dat 50 PARENT_SCOPE) 51 elseif(name STREQUAL "hme_kernel_genx.cpp") 52 set(objs 53 hme_kernel_genx_0.dat 54 hme_kernel_genx_1.dat 55 hme_kernel_genx_2.dat 56 PARENT_SCOPE) 57 elseif(name STREQUAL "downscale_convert_kernel_genx.cpp") 58 set(objs 59 downscale_convert_kernel_genx_0.dat 60 PARENT_SCOPE) 61 else() 62 set(objs "" PARENT_SCOPE) 63 endif() 64 endfunction() 65 66 # Function parses the given c-file and extracts the value from the defined macro. 67 # Parser expects the first occurence in the following format: 68 # "#define name xxx" - whitespaces are important!! 69 function(get_c_macro_int file name value) 70 file(STRINGS ${file} value_str REGEX "#define ${name}" LIMIT_COUNT 1) 71 if(value_str STREQUAL "") # old style version 72 message(FATAL_ERROR "Failed to find macro ${name} in the file: ${file}") 73 endif() 74 string(REPLACE "#define ${name} " "" value_str ${value_str}) 75 set(${value} ${value_str} PARENT_SCOPE) 76 endfunction() 77 78 # Function generates kernel for the specified platform. It assumes that generated 79 # kernel should be placed in the certain directory (see ${krn_dir}). 80 function(gen_kernel_from_cm name platform index sources) 81 platform_to_genx(${platform} genx kind) 82 83 set(krn ig${name}krn_g${genx}) 84 set(krn_dir ${CMAKE_SOURCE_DIR}/media_driver/agnostic/${platform}/codec/kernel_free) 85 set(out_dir "${CMAKE_CURRENT_BINARY_DIR}/kernels/codec/${platform}") 86 87 message("krn: ${krn}") 88 message("krn_dir: ${krn_dir}") 89 message("out_dir: ${out_dir}") 90 91 add_custom_command( 92 OUTPUT ${out_dir} 93 COMMAND ${CMAKE_COMMAND} -E make_directory ${out_dir} 94 COMMENT "Create codec kernels output directory: ${out_dir}") 95 96 # Compiling all the given sources 97 set(dats "") 98 set(cm_genx ${platform}) 99 if(cm_genx STREQUAL "gen11") 100 # Forcing gen11lp platform for the whole gen11 family since LP instruction set 101 # is a subset of other platforms in the family. 102 set(cm_genx "gen11lp") 103 endif() 104 foreach(src ${sources}) 105 get_cm_dat_objs(${src} objs) # there are other otputs from cmc command, but we use only .dat 106 add_custom_command( 107 OUTPUT ${objs} 108 DEPENDS ${out_dir} ${src} 109 WORKING_DIRECTORY ${out_dir} 110 COMMAND ${CMC} 111 -c -Qxcm -Qxcm_jit_target=${cm_genx} 112 -mCM_emit_common_isa -mCM_no_input_reorder -mCM_jit_option="-nocompaction" 113 ${src} 114 COMMENT "Compiling ${src}..." 115 ) 116 set(dats ${dats} ${objs}) 117 endforeach() 118 119 # Generating source from the .krn file 120 get_c_macro_int(${CMAKE_CURRENT_LIST_DIR}/common/codec/kernel/codeckrnheader.h 121 "IDR_CODEC_TOTAL_NUM_KERNELS" IDR_CODEC_TOTAL_NUM_KERNELS) 122 add_custom_command( 123 OUTPUT ${krn_dir}/${krn}.c ${krn_dir}/${krn}.h 124 DEPENDS KernelBinToSource ${CMAKE_CURRENT_LIST_DIR}/common/codec/kernel/merge.py ${dats} 125 WORKING_DIRECTORY ${out_dir} 126 COMMAND ${PYTHON} ${CMAKE_CURRENT_LIST_DIR}/common/codec/kernel/merge.py -o ${krn}.krn ${dats} 127 # ${index} is needed to match a description in the following file: 128 # media_driver/agnostic/common/codec/kernel/codeckrnheader.h 129 COMMAND KernelBinToSource -i ${krn}.krn -o ${krn_dir}/ -v ${krn} -index ${index} -t ${IDR_CODEC_TOTAL_NUM_KERNELS} 130 COMMENT "Generate source file from krn") 131 endfunction() 132 133 # Function generates vp cmfc kernel for the specified platform. It assumes that generated 134 # kernel should be placed in the certain directory (see ${krn_dir}). 135 function(gen_vpkernel_from_cm name platform) 136 platform_to_genx(${platform} genx kind) 137 138 set(krn ig${name}krn_g${genx}_${kind}_cmfc) 139 set(krnpatch ig${name}krn_g${genx}_${kind}_cmfcpatch) 140 set(krn_dir ${CMAKE_SOURCE_DIR}/media_driver/agnostic/${platform}/vp/kernel_free) 141 set(link_file ${krn_dir}/component_release/LinkFile.txt) 142 set(out_dir ${CMAKE_SOURCE_DIR}/media_driver/agnostic/${platform}/vp/kernel_free/cache_kernel) 143 set(kernel_dir ${out_dir}/kernel) 144 set(patch_dir ${out_dir}/fcpatch) 145 set(kernel_hex_dir ${kernel_dir}/hex) 146 set(patch_hex_dir ${patch_dir}/hex) 147 set(krn_header ${CMAKE_CURRENT_LIST_DIR}/common/vp/kernel/${name}krnheader.h) 148 149 add_custom_command( 150 OUTPUT ${out_dir} ${kernel_dir} ${patch_dir} ${kernel_hex_dir} ${patch_hex_dir} 151 COMMAND ${CMAKE_COMMAND} -E make_directory ${out_dir} 152 COMMAND ${CMAKE_COMMAND} -E make_directory ${kernel_dir} 153 COMMAND ${CMAKE_COMMAND} -E make_directory ${patch_dir} 154 COMMAND ${CMAKE_COMMAND} -E make_directory ${kernel_hex_dir} 155 COMMAND ${CMAKE_COMMAND} -E make_directory ${patch_hex_dir} 156 COMMENT "Creating VP cmfc kernels output directory") 157 158 # Compiling all the sources in the kernel source directory. 159 file(GLOB_RECURSE srcs ${krn_dir}/Source/*.cpp) 160 161 set(objsname "") 162 set(cm_genx ${kind}) 163 164 foreach(src ${srcs}) 165 get_filename_component(obj ${src} NAME_WE) # there are other outputs from cmc command, but we use only .dat and .fcpatch 166 if(obj STREQUAL "EOT" OR obj STREQUAL "Secure_Block_Copy") # "EOT" and "Secure_Block_Copy" don't generate the related .fcpatch file. 167 add_custom_command( 168 OUTPUT ${out_dir}/${obj}_0.dat 169 DEPENDS ${src} ${out_dir} 170 WORKING_DIRECTORY ${out_dir} 171 COMMAND ${CMC} 172 -c -Qxcm -Qxcm_jit_target=${cm_genx} -I ${krn_dir}/Source/ -I ${krn_dir}/Source/Common -I ${krn_dir}/Source/Components 173 -I ${krn_dir}/Source/Core_Kernels -Qxcm_jit_option="-nocompaction" -mCM_emit_common_isa -mCM_no_input_reorder -mCM_unique_labels=MDF_FC -mCM_printregusage 174 ${src}) 175 else() 176 add_custom_command( 177 OUTPUT ${out_dir}/${obj}_0.dat ${out_dir}/${obj}.fcpatch 178 DEPENDS ${src} ${out_dir} 179 WORKING_DIRECTORY ${out_dir} 180 COMMAND ${CMC} 181 -c -Qxcm -Qxcm_jit_target=${cm_genx} -I ${krn_dir}/Source/ -I ${krn_dir}/Source/Common -I ${krn_dir}/Source/Components 182 -I ${krn_dir}/Source/Core_Kernels -Qxcm_jit_option="-nocompaction" -mCM_emit_common_isa -mCM_no_input_reorder -mCM_unique_labels=MDF_FC -mCM_printregusage 183 ${src}) 184 endif() 185 set(objsname ${objsname} ${obj}) 186 endforeach() 187 188 #Generate the .hex files from the .dat files by using KrnToHex. 189 set(hexs "") 190 191 foreach(objname ${objsname}) 192 add_custom_command( 193 OUTPUT ${kernel_dir}/${objname}.krn 194 DEPENDS ${out_dir}/${objname}_0.dat ${kernel_dir} 195 WORKING_DIRECTORY ${out_dir} 196 COMMAND ${CMAKE_COMMAND} -E copy ${out_dir}/${objname}_0.dat ${kernel_dir}/${objname}.krn 197 ) 198 endforeach() 199 200 foreach(objname ${objsname}) 201 add_custom_command( 202 OUTPUT ${kernel_hex_dir}/${objname}.hex 203 DEPENDS KrnToHex ${kernel_dir}/${objname}.krn ${kernel_hex_dir} 204 WORKING_DIRECTORY ${kernel_dir} 205 COMMAND KrnToHex ${kernel_dir}/${objname}.krn 206 COMMAND ${CMAKE_COMMAND} -E copy ${kernel_dir}/${objname}.hex ${kernel_hex_dir}/${objname}.hex 207 COMMAND ${CMAKE_COMMAND} -E remove ${kernel_dir}/${objname}.hex 208 COMMENT "Generate the hex files of cmfc kernel") 209 set(hexs ${hexs} ${kernel_hex_dir}/${objname}.hex) 210 endforeach() 211 212 ##Generate the .hex files from the .fcpatch files by using KrnToHex. 213 214 list(REMOVE_ITEM objsname "EOT" "Secure_Block_Copy") # Remove "EOT" and "Secure_Block_Copy". 215 216 foreach(objname ${objsname}) 217 add_custom_command( 218 OUTPUT ${patch_dir}/${objname}.krn 219 DEPENDS ${out_dir}/${objname}.fcpatch ${patch_dir} 220 WORKING_DIRECTORY ${out_dir} 221 COMMAND ${CMAKE_COMMAND} -E copy ${out_dir}/${objname}.fcpatch ${patch_dir}/${objname}.krn 222 ) 223 endforeach() 224 225 set(fcpatch_hexs "") 226 foreach(objname ${objsname}) 227 add_custom_command( 228 OUTPUT ${patch_hex_dir}/${objname}.hex 229 DEPENDS KrnToHex ${patch_dir}/${objname}.krn ${patch_hex_dir} 230 WORKING_DIRECTORY ${patch_dir} 231 COMMAND KrnToHex ${patch_dir}/${objname}.krn 232 COMMAND ${CMAKE_COMMAND} -E copy ${patch_dir}/${objname}.hex ${patch_hex_dir}/${objname}.hex 233 COMMAND ${CMAKE_COMMAND} -E remove ${patch_dir}/${objname}.hex 234 COMMENT "Generate the hex files of cmfc patch") 235 set(fcpatch_hexs ${fcpatch_hexs} ${patch_hex_dir}/${objname}.hex) 236 endforeach() 237 238 # Generating the .bin files for cmfc kernel and patch respectively. 239 240 add_custom_command( 241 OUTPUT ${kernel_hex_dir}/${krn}.bin ${krn_header} 242 DEPENDS GenDmyHex GenKrnBin ${hexs} ${link_file} #Generate the dummy hexs from the pre-built header 243 WORKING_DIRECTORY ${kernel_hex_dir} 244 COMMAND GenDmyHex ${kernel_hex_dir} ${krn_header} 245 COMMAND ${CMAKE_COMMAND} -E copy ${link_file} ${kernel_hex_dir} 246 COMMAND GenKrnBin ${kernel_hex_dir} ${name} ${genx} tgllp_cmfc 247 COMMAND ${CMAKE_COMMAND} -E copy ${krn}.h ${krn_header}) 248 249 add_custom_command( 250 OUTPUT ${patch_hex_dir}/${krnpatch}.bin 251 DEPENDS GenKrnBin ${fcpatch_hexs} ${link_file} 252 WORKING_DIRECTORY ${patch_hex_dir} 253 COMMAND ${CMAKE_COMMAND} -E copy ${link_file} ${patch_hex_dir} 254 COMMAND GenKrnBin ${patch_hex_dir} ${name} ${genx} tgllp_cmfcpatch) 255 256 # Generating kernel source files for cmfc kernel and patch. 257 258 add_custom_command( 259 OUTPUT ${krn_dir}/cmfc/${krn}.c ${krn_dir}/cmfc/${krn}.h 260 DEPENDS KernelBinToSource ${kernel_hex_dir}/${krn}.bin 261 COMMAND KernelBinToSource -i ${kernel_hex_dir}/${krn}.bin -o ${krn_dir}/cmfc) 262 263 add_custom_command( 264 OUTPUT ${krn_dir}/cmfcpatch/${krnpatch}.c ${krn_dir}/cmfcpatch/${krnpatch}.h 265 DEPENDS KernelBinToSource ${patch_hex_dir}/${krnpatch}.bin 266 COMMAND KernelBinToSource -i ${patch_hex_dir}/${krnpatch}.bin -o ${krn_dir}/cmfcpatch) 267 endfunction() 268 269 # List of kernel sources to build. 270 # NOTE: Order is important!! It should match the order in which sub-kernels are described 271 # in the corresponding strcuture in the driver. For example, HME kernel should 272 # match HmeDsScoreboardKernelHeaderG11 273 list(APPEND HME_KRN_SOURCES 274 ${CMAKE_CURRENT_LIST_DIR}/gen11/codec/kernel_free/Source/downscale_kernel_genx.cpp 275 ${CMAKE_CURRENT_LIST_DIR}/gen11/codec/kernel_free/Source/hme_kernel_genx.cpp 276 ${CMAKE_CURRENT_LIST_DIR}/gen11/codec/kernel_free/Source/downscale_convert_kernel_genx.cpp) 277 278 get_c_macro_int(${CMAKE_CURRENT_LIST_DIR}/common/codec/kernel/codeckrnheader.h 279 "IDR_CODEC_HME_DS_SCOREBOARD_KERNEL" IDR_CODEC_HME_DS_SCOREBOARD_KERNEL) 280 281 if(GEN11_ICLLP) 282 #gen_kernel_from_asm(vp gen11_icllp) 283 #gen_kernel_from_cm(codec gen11 ${IDR_CODEC_HME_DS_SCOREBOARD_KERNEL} "${HME_KRN_SOURCES}") 284 endif() 285 286 if(GEN12_TGLLP) 287 #gen_vpkernel_from_cm(vp gen12_tgllp) 288 endif() 289endif() 290 291media_include_subdirectory(common) 292 293if(GEN8) 294 media_include_subdirectory(gen8) 295endif() 296 297if(GEN8_BDW) 298 media_include_subdirectory(gen8_bdw) 299endif() 300 301if(GEN9) 302 media_include_subdirectory(gen9) 303endif() 304 305if(GEN9_CML) 306 media_include_subdirectory(gen9_cml) 307endif() 308 309if(GEN9_CMPV) 310 media_include_subdirectory(gen9_cmpv) 311endif() 312 313if(GEN9_BXT) 314 media_include_subdirectory(gen9_bxt) 315endif() 316 317if(GEN9_SKL) 318 media_include_subdirectory(gen9_skl) 319endif() 320 321if(GEN9_GLK) 322 media_include_subdirectory(gen9_glk) 323endif() 324 325if(GEN9_KBL) 326 media_include_subdirectory(gen9_kbl) 327endif() 328 329if(GEN11) 330 media_include_subdirectory(gen11) 331endif() 332 333if(GEN11_ICLLP) 334 media_include_subdirectory(gen11_icllp) 335endif() 336 337if(GEN11_JSL) 338 media_include_subdirectory(gen11_jsl_ehl) 339endif() 340 341if(GEN12) 342 media_include_subdirectory(gen12) 343 media_include_subdirectory(g12) 344 media_include_subdirectory(../media_softlet/agnostic/gen12) 345endif() 346 347if(GEN12_TGLLP) 348 media_include_subdirectory(gen12_tgllp) 349endif() 350 351if(GEN12) 352media_include_subdirectory(Xe_M) 353media_include_subdirectory(Xe_R) 354endif() 355 356include(${MEDIA_EXT}/agnostic/media_srcs_ext.cmake OPTIONAL) 357