hfi_buffer_iris2.h 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2021,, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __HFI_BUFFER_IRIS2__
  6. #define __HFI_BUFFER_IRIS2__
  7. #include <linux/types.h>
  8. #include "hfi_property.h"
  9. typedef u8 HFI_U8;
  10. typedef s8 HFI_S8;
  11. typedef u16 HFI_U16;
  12. typedef s16 HFI_S16;
  13. typedef u32 HFI_U32;
  14. typedef s32 HFI_S32;
  15. typedef u64 HFI_U64;
  16. typedef HFI_U32 HFI_BOOL;
  17. #ifndef MIN
  18. #define MIN(x, y) (((x) < (y)) ? (x) : (y))
  19. #endif
  20. #ifndef MAX
  21. #define MAX(x, y) (((x) > (y)) ? (x) : (y))
  22. #endif
  23. /*
  24. * Default buffer size alignment value
  25. */
  26. #define HFI_ALIGNMENT_4096 (4096)
  27. #define BUF_SIZE_ALIGN_16 (16)
  28. #define BUF_SIZE_ALIGN_32 (32)
  29. #define BUF_SIZE_ALIGN_64 (64)
  30. #define BUF_SIZE_ALIGN_128 (128)
  31. #define BUF_SIZE_ALIGN_256 (256)
  32. #define BUF_SIZE_ALIGN_512 (512)
  33. #define BUF_SIZE_ALIGN_4096 (4096)
  34. /*
  35. * Macro to align a to b
  36. */
  37. #define HFI_ALIGN(a, b) (((b) & ((b) - 1)) ? (((a) + (b) - 1) / \
  38. (b) * (b)) : (((a) + (b) - 1) & (~((b) - 1))))
  39. #define HFI_WORKMODE_1 1 /* stage 1 */
  40. #define HFI_WORKMODE_2 2 /* stage 2 */
  41. /*
  42. * Default ubwc metadata buffer stride and height alignment values
  43. */
  44. #define HFI_DEFAULT_METADATA_STRIDE_MULTIPLE (64)
  45. #define HFI_DEFAULT_METADATA_BUFFERHEIGHT_MULTIPLE (16)
  46. /*
  47. * Level 2 Comment: "Default Parameters for Firmware "
  48. * This section defines all the default constants used by Firmware
  49. * for any encoding session:
  50. * 1. Bitstream Restriction VUI: TRUE
  51. * 2. Picture Order Count: 2 (for all profiles except B frame case)
  52. * 3. Constrained intra pred flag : TRUE (if Intra-refresh (IR) is enabled)
  53. */
  54. /*
  55. * Level 2 Comment: "Tile dimensions(in pixels) macros for
  56. * different color formats"
  57. * @datatypes
  58. * @sa
  59. */
  60. #define HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_HEIGHT (8)
  61. #define HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_WIDTH (32)
  62. #define HFI_COLOR_FORMAT_YUV420_NV12_UBWC_UV_TILE_HEIGHT (8)
  63. #define HFI_COLOR_FORMAT_YUV420_NV12_UBWC_UV_TILE_WIDTH (16)
  64. #define HFI_COLOR_FORMAT_YUV420_TP10_UBWC_Y_TILE_HEIGHT (4)
  65. #define HFI_COLOR_FORMAT_YUV420_TP10_UBWC_Y_TILE_WIDTH (48)
  66. #define HFI_COLOR_FORMAT_YUV420_TP10_UBWC_UV_TILE_HEIGHT (4)
  67. #define HFI_COLOR_FORMAT_YUV420_TP10_UBWC_UV_TILE_WIDTH (24)
  68. #define HFI_COLOR_FORMAT_RGBA8888_UBWC_TILE_HEIGHT (4)
  69. #define HFI_COLOR_FORMAT_RGBA8888_UBWC_TILE_WIDTH (16)
  70. /*
  71. * Level 2 Comment: "Macros to calculate YUV strides and size"
  72. * @datatypes
  73. * HFI_UNCOMPRESSED_FORMAT_SUPPORTED_TYPE
  74. * HFI_UNCOMPRESSED_PLANE_INFO_TYPE
  75. * HFI_UNCOMPRESSED_PLANE_CONSTRAINTS_TYPE
  76. * @sa
  77. * HFI_PROPERTY_PARAM_UNCOMPRESSED_FORMAT_SUPPORTED
  78. */
  79. /*
  80. * Luma stride calculation for YUV420, NV12/NV21, NV12_UBWC color format
  81. * Stride arrived at here is the minimum required stride. Host may
  82. * set a stride higher than the one calculated here, till the stride
  83. * is a multiple of "nStrideMultiples" in
  84. * HFI_UNCOMPRESSED_PLANE_CONSTRAINTS_TYPE
  85. */
  86. #define HFI_NV12_IL_CALC_Y_STRIDE(stride, frame_width, stride_multiple) \
  87. stride = HFI_ALIGN(frame_width, stride_multiple)
  88. /*
  89. * Luma plane height calculation for YUV420 NV12/NV21, NV12_UBWC color format
  90. * Luma plane height used by the host needs to be either equal
  91. * to higher than the value calculated here
  92. */
  93. #define HFI_NV12_IL_CALC_Y_BUFHEIGHT(buf_height, frame_height, \
  94. min_buf_height_multiple) buf_height = HFI_ALIGN(frame_height, \
  95. min_buf_height_multiple)
  96. /*
  97. * Chroma stride calculation for NV12/NV21, NV12_UBWC color format
  98. */
  99. #define HFI_NV12_IL_CALC_UV_STRIDE(stride, frame_width, stride_multiple) \
  100. stride = HFI_ALIGN(frame_width, stride_multiple)
  101. /*
  102. * Chroma plane height calculation for NV12/NV21, NV12_UBWC color format
  103. */
  104. #define HFI_NV12_IL_CALC_UV_BUFHEIGHT(buf_height, frame_height, \
  105. min_buf_height_multiple) buf_height = HFI_ALIGN(((frame_height + 1) \
  106. >> 1), min_buf_height_multiple)
  107. /*
  108. * Minimum buffer size that needs to be allocated for current
  109. * frame dimensions for NV12/N21 Linear format
  110. * (calcualtion includes both luma and chroma plane)
  111. */
  112. #define HFI_NV12_IL_CALC_BUF_SIZE(buf_size, y_bufSize, y_stride, y_buf_height, \
  113. uv_buf_size, uv_stride, uv_buf_height) \
  114. y_bufSize = (y_stride * y_buf_height); \
  115. uv_buf_size = (uv_stride * uv_buf_height); \
  116. buf_size = HFI_ALIGN(y_bufSize + uv_buf_size, HFI_ALIGNMENT_4096)
  117. /*
  118. * Minimum Luma buffer size that needs to be allocated for current
  119. * frame dimensions NV12_UBWC format
  120. */
  121. #define HFI_NV12_UBWC_IL_CALC_Y_BUF_SIZE(y_bufSize, y_stride, y_buf_height) \
  122. y_bufSize = HFI_ALIGN(y_stride * y_buf_height, HFI_ALIGNMENT_4096)
  123. /*
  124. * Minimum chroma buffer size that needs to be allocated for current
  125. * frame dimensions NV12_UBWC format
  126. */
  127. #define HFI_NV12_UBWC_IL_CALC_UV_BUF_SIZE(uv_buf_size, \
  128. uv_stride, uv_buf_height) \
  129. uv_buf_size = HFI_ALIGN(uv_stride * uv_buf_height, HFI_ALIGNMENT_4096)
  130. /*
  131. * This is for sdm845 onwards:
  132. * Ver2.0: Minimum buffer size that needs to be allocated for current
  133. * frame dimensions NV12_UBWC format (including interlace UBWC)
  134. * (calculation includes all data & metadata planes)
  135. */
  136. #define HFI_NV12_UBWC_IL_CALC_BUF_SIZE_V2(buf_size,\
  137. frame_width, frame_height, y_stride_multiple,\
  138. y_buffer_height_multiple, uv_stride_multiple, \
  139. uv_buffer_height_multiple, y_metadata_stride_multiple, \
  140. y_metadata_buffer_height_multiple, \
  141. uv_metadata_stride_multiple, uv_metadata_buffer_height_multiple) \
  142. do \
  143. { \
  144. HFI_U32 y_buf_size, uv_buf_size, y_meta_size, uv_meta_size; \
  145. HFI_U32 stride, _height; \
  146. HFI_U32 half_height = (frame_height + 1) >> 1; \
  147. HFI_NV12_IL_CALC_Y_STRIDE(stride, frame_width,\
  148. y_stride_multiple); \
  149. HFI_NV12_IL_CALC_Y_BUFHEIGHT(_height, half_height,\
  150. y_buffer_height_multiple); \
  151. HFI_NV12_UBWC_IL_CALC_Y_BUF_SIZE(y_buf_size, stride, _height);\
  152. HFI_NV12_IL_CALC_UV_STRIDE(stride, frame_width, \
  153. uv_stride_multiple); \
  154. HFI_NV12_IL_CALC_UV_BUFHEIGHT(_height, half_height, \
  155. uv_buffer_height_multiple); \
  156. HFI_NV12_UBWC_IL_CALC_UV_BUF_SIZE(uv_buf_size, stride, _height);\
  157. HFI_UBWC_CALC_METADATA_PLANE_STRIDE(stride, frame_width,\
  158. y_metadata_stride_multiple, \
  159. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_WIDTH);\
  160. HFI_UBWC_METADATA_PLANE_BUFHEIGHT(_height, half_height, \
  161. y_metadata_buffer_height_multiple,\
  162. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_HEIGHT);\
  163. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(y_meta_size, stride, \
  164. _height); \
  165. HFI_UBWC_UV_METADATA_PLANE_STRIDE(stride, frame_width,\
  166. uv_metadata_stride_multiple, \
  167. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_UV_TILE_WIDTH); \
  168. HFI_UBWC_UV_METADATA_PLANE_BUFHEIGHT(_height, half_height,\
  169. uv_metadata_buffer_height_multiple,\
  170. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_UV_TILE_HEIGHT);\
  171. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(uv_meta_size, stride, \
  172. _height); \
  173. buf_size = (y_buf_size + uv_buf_size + y_meta_size + \
  174. uv_meta_size) << 1;\
  175. } while (0)
  176. /*
  177. * Luma stride calculation for YUV420_TP10 color format
  178. * Stride arrived at here is the minimum required stride. Host may
  179. * set a stride higher than the one calculated here, till the stride
  180. * is a multiple of "nStrideMultiples" in
  181. * HFI_UNCOMPRESSED_PLANE_CONSTRAINTS_TYPE
  182. */
  183. #define HFI_YUV420_TP10_CALC_Y_STRIDE(stride, frame_width, stride_multiple) \
  184. stride = HFI_ALIGN(frame_width, 192); \
  185. stride = HFI_ALIGN(stride * 4 / 3, stride_multiple)
  186. /*
  187. * Luma plane height calculation for YUV420_TP10 linear & UBWC color format
  188. * Luma plane height used by the host needs to be either equal
  189. * to higher than the value calculated here
  190. */
  191. #define HFI_YUV420_TP10_CALC_Y_BUFHEIGHT(buf_height, frame_height, \
  192. min_buf_height_multiple) \
  193. buf_height = HFI_ALIGN(frame_height, min_buf_height_multiple)
  194. /*
  195. * Chroma stride calculation for YUV420_TP10 linear & UBWC color format
  196. */
  197. #define HFI_YUV420_TP10_CALC_UV_STRIDE(stride, frame_width, stride_multiple) \
  198. stride = HFI_ALIGN(frame_width, 192); \
  199. stride = HFI_ALIGN(stride * 4 / 3, stride_multiple)
  200. /*
  201. * Chroma plane height calculation for YUV420_TP10 linear & UBWC color format
  202. */
  203. #define HFI_YUV420_TP10_CALC_UV_BUFHEIGHT(buf_height, frame_height, \
  204. min_buf_height_multiple) \
  205. buf_height = HFI_ALIGN(((frame_height + 1) >> 1), \
  206. min_buf_height_multiple)
  207. /*
  208. * Minimum buffer size that needs to be allocated for current
  209. * frame dimensions for YUV420_TP10 linear format
  210. * (calcualtion includes both luma and chroma plane)
  211. */
  212. #define HFI_YUV420_TP10_CALC_BUF_SIZE(buf_size, y_buf_size, y_stride,\
  213. y_buf_height, uv_buf_size, uv_stride, uv_buf_height) \
  214. y_buf_size = (y_stride * y_buf_height); \
  215. uv_buf_size = (uv_stride * uv_buf_height); \
  216. buf_size = y_buf_size + uv_buf_size
  217. /*
  218. * Minimum Luma data buffer size that needs to be allocated for current
  219. * frame dimensions YUV420_TP10_UBWC format
  220. */
  221. #define HFI_YUV420_TP10_UBWC_CALC_Y_BUF_SIZE(y_buf_size, y_stride, \
  222. y_buf_height) \
  223. y_buf_size = HFI_ALIGN(y_stride * y_buf_height, HFI_ALIGNMENT_4096)
  224. /*
  225. * Minimum chroma data buffer size that needs to be allocated for current
  226. * frame dimensions YUV420_TP10_UBWC format
  227. */
  228. #define HFI_YUV420_TP10_UBWC_CALC_UV_BUF_SIZE(uv_buf_size, uv_stride, \
  229. uv_buf_height) \
  230. uv_buf_size = HFI_ALIGN(uv_stride * uv_buf_height, HFI_ALIGNMENT_4096)
  231. /*
  232. * Minimum buffer size that needs to be allocated for current
  233. * frame dimensions NV12_UBWC format
  234. * (calculation includes all data & metadata planes)
  235. */
  236. #define HFI_YUV420_TP10_UBWC_CALC_BUF_SIZE(buf_size, y_stride, y_buf_height, \
  237. uv_stride, uv_buf_height, y_md_stride, y_md_height, uv_md_stride, \
  238. uv_md_height)\
  239. do \
  240. { \
  241. HFI_U32 y_data_size, uv_data_size, y_md_size, uv_md_size; \
  242. HFI_YUV420_TP10_UBWC_CALC_Y_BUF_SIZE(y_data_size, y_stride,\
  243. y_buf_height); \
  244. HFI_YUV420_TP10_UBWC_CALC_UV_BUF_SIZE(uv_data_size, uv_stride, \
  245. uv_buf_height); \
  246. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(y_md_size, y_md_stride, \
  247. y_md_height); \
  248. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(uv_md_size, uv_md_stride, \
  249. uv_md_height); \
  250. buf_size = y_data_size + uv_data_size + y_md_size + \
  251. uv_md_size; \
  252. } while (0)
  253. /*
  254. * Luma stride calculation for YUV420_P010 color format
  255. * Stride arrived at here is the minimum required stride. Host may
  256. * set a stride higher than the one calculated here, till the stride
  257. * is a multiple of "nStrideMultiples" in
  258. * HFI_UNCOMPRESSED_PLANE_CONSTRAINTS_TYPE
  259. */
  260. #define HFI_YUV420_P010_CALC_Y_STRIDE(stride, frame_width, stride_multiple) \
  261. stride = HFI_ALIGN(frame_width * 2, stride_multiple)
  262. /*
  263. * Luma plane height calculation for YUV420_P010 linear color format
  264. * Luma plane height used by the host needs to be either equal
  265. * to higher than the value calculated here
  266. */
  267. #define HFI_YUV420_P010_CALC_Y_BUFHEIGHT(buf_height, frame_height, \
  268. min_buf_height_multiple) \
  269. buf_height = HFI_ALIGN(frame_height, min_buf_height_multiple)
  270. /*
  271. * Chroma stride calculation for YUV420_P010 linear color format
  272. */
  273. #define HFI_YUV420_P010_CALC_UV_STRIDE(stride, frame_width, stride_multiple) \
  274. stride = HFI_ALIGN(frame_width * 2, stride_multiple)
  275. /*
  276. * Chroma plane height calculation for YUV420_P010 linear color format
  277. */
  278. #define HFI_YUV420_P010_CALC_UV_BUFHEIGHT(buf_height, frame_height, \
  279. min_buf_height_multiple) \
  280. buf_height = HFI_ALIGN(((frame_height + 1) >> 1), \
  281. min_buf_height_multiple)
  282. /*
  283. * Minimum buffer size that needs to be allocated for current
  284. * frame dimensions for YUV420_P010 linear format
  285. * (calculation includes both luma and chroma plane)
  286. */
  287. #define HFI_YUV420_P010_CALC_BUF_SIZE(buf_size, y_data_size, y_stride, \
  288. y_buf_height, uv_data_size, uv_stride, uv_buf_height) \
  289. do \
  290. { \
  291. y_data_size = HFI_ALIGN(y_stride * y_buf_height, \
  292. HFI_ALIGNMENT_4096);\
  293. uv_data_size = HFI_ALIGN(uv_stride * uv_buf_height, \
  294. HFI_ALIGNMENT_4096); \
  295. buf_size = y_data_size + uv_data_size; \
  296. } while (0)
  297. /*
  298. * Plane stride calculation for RGB888/BGR888 color format
  299. * Stride arrived at here is the minimum required stride. Host may
  300. * set a stride higher than the one calculated here, till the stride
  301. * is a multiple of "nStrideMultiples" in
  302. * HFI_UNCOMPRESSED_PLANE_CONSTRAINTS_TYPE
  303. */
  304. #define HFI_RGB888_CALC_STRIDE(stride, frame_width, stride_multiple) \
  305. stride = ((frame_width * 3) + stride_multiple - 1) & \
  306. (0xffffffff - (stride_multiple - 1))
  307. /*
  308. * Plane height calculation for RGB888/BGR888 color format
  309. * Luma plane height used by the host needs to be either equal
  310. * to higher than the value calculated here
  311. */
  312. #define HFI_RGB888_CALC_BUFHEIGHT(buf_height, frame_height, \
  313. min_buf_height_multiple) \
  314. buf_height = ((frame_height + min_buf_height_multiple - 1) & \
  315. (0xffffffff - (min_buf_height_multiple - 1)))
  316. /*
  317. * Minimum buffer size that needs to be allocated for current
  318. * frame dimensions for RGB888/BGR888 format
  319. */
  320. #define HFI_RGB888_CALC_BUF_SIZE(buf_size, stride, buf_height) \
  321. buf_size = ((stride) * (buf_height))
  322. /*
  323. * Plane stride calculation for RGBA8888 color format
  324. * Stride arrived at here is the minimum required stride. Host may
  325. * set a stride higher than the one calculated here, till the stride
  326. * is a multiple of "nStrideMultiples" in
  327. * HFI_UNCOMPRESSED_PLANE_CONSTRAINTS_TYPE
  328. */
  329. #define HFI_RGBA8888_CALC_STRIDE(stride, frame_width, stride_multiple) \
  330. stride = HFI_ALIGN((frame_width << 2), stride_multiple)
  331. /*
  332. * Plane height calculation for RGBA8888 color format
  333. * Luma plane height used by the host needs to be either equal
  334. * to higher than the value calculated here
  335. */
  336. #define HFI_RGBA8888_CALC_BUFHEIGHT(buf_height, frame_height, \
  337. min_buf_height_multiple) \
  338. buf_height = HFI_ALIGN(frame_height, min_buf_height_multiple)
  339. /*
  340. * Minimum buffer size that needs to be allocated for current
  341. * frame dimensions for RGBA8888 format
  342. */
  343. #define HFI_RGBA8888_CALC_BUF_SIZE(buf_size, stride, buf_height) \
  344. buf_size = (stride) * (buf_height)
  345. /*
  346. * Minimum buffer size that needs to be allocated for current
  347. * frame dimensions for data plane of RGBA8888_UBWC format
  348. */
  349. #define HFI_RGBA8888_UBWC_CALC_DATA_PLANE_BUF_SIZE(buf_size, stride, \
  350. buf_height) \
  351. buf_size = HFI_ALIGN((stride) * (buf_height), HFI_ALIGNMENT_4096)
  352. /*
  353. * Minimum buffer size that needs to be allocated for current
  354. * frame dimensions for of RGBA8888_UBWC format
  355. */
  356. #define HFI_RGBA8888_UBWC_BUF_SIZE(buf_size, data_buf_size, \
  357. metadata_buffer_size, stride, buf_height, _metadata_tride, \
  358. _metadata_buf_height) \
  359. HFI_RGBA8888_UBWC_CALC_DATA_PLANE_BUF_SIZE(data_buf_size, \
  360. stride, buf_height); \
  361. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(metadata_buffer_size, \
  362. _metadata_tride, _metadata_buf_height); \
  363. buf_size = data_buf_size + metadata_buffer_size
  364. /*
  365. * Metadata plane stride calculation for all UBWC color formats
  366. * Should be used for Y metadata Plane & all single plane color
  367. * formats. Stride arrived at here is the minimum required
  368. * stride. Host may set a stride higher than the one calculated
  369. * here, till the stride is a multiple of
  370. * "_metadata_trideMultiple" in
  371. * HFI_UNCOMPRESSED_PLANE_CONSTRAINTS_TYPE Default
  372. * metadataDataStrideMultiple = 64
  373. */
  374. #define HFI_UBWC_CALC_METADATA_PLANE_STRIDE(metadata_stride, frame_width,\
  375. metadata_stride_multiple, tile_width_in_pels) \
  376. metadata_stride = HFI_ALIGN(((frame_width + (tile_width_in_pels - 1)) /\
  377. tile_width_in_pels), metadata_stride_multiple)
  378. /*
  379. * Metadata plane height calculation for all UBWC color formats
  380. * Should be used for Y metadata Plane & all single plane color
  381. * formats. Plane height used by the host needs to be either
  382. * equal to higher than the value calculated here
  383. * Default metadataHeightMultiple = 16
  384. */
  385. #define HFI_UBWC_METADATA_PLANE_BUFHEIGHT(metadata_buf_height, frame_height, \
  386. metadata_height_multiple, tile_height_in_pels) \
  387. metadata_buf_height = HFI_ALIGN(((frame_height + \
  388. (tile_height_in_pels - 1)) / tile_height_in_pels), \
  389. metadata_height_multiple)
  390. /*
  391. * UV Metadata plane stride calculation for NV12_UBWC color
  392. * format. Stride arrived at here is the minimum required
  393. * stride. Host may set a stride higher than the one calculated
  394. * here, till the stride is a multiple of
  395. * "_metadata_trideMultiple" in
  396. * HFI_UNCOMPRESSED_PLANE_CONSTRAINTS_TYPE Default
  397. * metadataDataStrideMultiple = 64
  398. */
  399. #define HFI_UBWC_UV_METADATA_PLANE_STRIDE(metadata_stride, frame_width, \
  400. metadata_stride_multiple, tile_width_in_pels) \
  401. metadata_stride = HFI_ALIGN(((((frame_width + 1) >> 1) +\
  402. (tile_width_in_pels - 1)) / tile_width_in_pels), \
  403. metadata_stride_multiple)
  404. /*
  405. * UV Metadata plane height calculation for NV12_UBWC color
  406. * format. Plane height used by the host needs to be either
  407. * equal to higher than the value calculated here Default
  408. * metadata_height_multiple = 16
  409. */
  410. #define HFI_UBWC_UV_METADATA_PLANE_BUFHEIGHT(metadata_buf_height, frame_height,\
  411. metadata_height_multiple, tile_height_in_pels) \
  412. metadata_buf_height = HFI_ALIGN(((((frame_height + 1) >> 1) + \
  413. (tile_height_in_pels - 1)) / tile_height_in_pels), \
  414. metadata_height_multiple)
  415. /*
  416. * Minimum metadata buffer size that needs to be allocated for
  417. * current frame dimensions for each metadata plane.
  418. * This macro applies to all UBWC color format
  419. */
  420. #define HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(buffer_size, _metadata_tride, \
  421. _metadata_buf_height) \
  422. buffer_size = HFI_ALIGN(_metadata_tride * _metadata_buf_height, \
  423. HFI_ALIGNMENT_4096)
  424. #define BUFFER_ALIGNMENT_512_BYTES 512
  425. #define BUFFER_ALIGNMENT_256_BYTES 256
  426. #define BUFFER_ALIGNMENT_128_BYTES 128
  427. #define BUFFER_ALIGNMENT_64_BYTES 64
  428. #define BUFFER_ALIGNMENT_32_BYTES 32
  429. #define BUFFER_ALIGNMENT_16_BYTES 16
  430. #define BUFFER_ALIGNMENT_8_BYTES 8
  431. #define BUFFER_ALIGNMENT_4_BYTES 4
  432. #define VENUS_DMA_ALIGNMENT BUFFER_ALIGNMENT_256_BYTES
  433. #define MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE 64
  434. #define MAX_FE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE 64
  435. #define MAX_FE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE 64
  436. #define MAX_FE_NBR_DATA_LUMA_LINE_BUFFER_SIZE 640
  437. #define MAX_FE_NBR_DATA_CB_LINE_BUFFER_SIZE 320
  438. #define MAX_FE_NBR_DATA_CR_LINE_BUFFER_SIZE 320
  439. #define MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE (128 / 8)
  440. #define MAX_SE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE (128 / 8)
  441. #define MAX_SE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE (128 / 8)
  442. #define MAX_PE_NBR_DATA_LCU64_LINE_BUFFER_SIZE (64 * 2 * 3)
  443. #define MAX_PE_NBR_DATA_LCU32_LINE_BUFFER_SIZE (32 * 2 * 3)
  444. #define MAX_PE_NBR_DATA_LCU16_LINE_BUFFER_SIZE (16 * 2 * 3)
  445. /* Begin of IRIS2 */
  446. /*
  447. * VPSS internal buffer definition
  448. * Only for 1:1 DS ratio case
  449. */
  450. #define MAX_TILE_COLUMNS 32 /* 8K/256 */
  451. /*
  452. * For all buffer size calculators using num_vpp_pipes,
  453. * use per chipset "static" pipe count.
  454. * Note that this applies to all use-cases,
  455. * e.g. buffer sizes for interlace decode
  456. * will be calculated using 4 vpp pipes on Kona,
  457. * even though interlace decode uses single vpp pipe.
  458. * __________________________________________________________
  459. * |_____________Target_____________|_______numVPPpipes_______|
  460. * | IRIS2(e.g. Kona) | 4 |
  461. * | IRIS2(e.g. Cedros) | 2 |
  462. * |_______IRIS2(e.g. Bitra)________|___________1_____________|
  463. */
  464. #define SIZE_VPSS_LB(Size, frame_width, frame_height, num_vpp_pipes) \
  465. do \
  466. { \
  467. HFI_U32 vpss_4tap_top_buffer_size, vpss_div2_top_buffer_size, \
  468. vpss_4tap_left_buffer_size, vpss_div2_left_buffer_size; \
  469. HFI_U32 opb_wr_top_line_luma_buffer_size, \
  470. opb_wr_top_line_chroma_buffer_size, \
  471. opb_lb_wr_llb_y_buffer_size,\
  472. opb_lb_wr_llb_uv_buffer_size; \
  473. HFI_U32 macrotiling_size; \
  474. vpss_4tap_top_buffer_size = vpss_div2_top_buffer_size = \
  475. vpss_4tap_left_buffer_size = vpss_div2_left_buffer_size = 0; \
  476. macrotiling_size = 32; \
  477. opb_wr_top_line_luma_buffer_size = HFI_ALIGN(frame_width, \
  478. macrotiling_size) / macrotiling_size * 256; \
  479. opb_wr_top_line_luma_buffer_size = \
  480. HFI_ALIGN(opb_wr_top_line_luma_buffer_size, \
  481. VENUS_DMA_ALIGNMENT) + (MAX_TILE_COLUMNS - 1) * 256; \
  482. opb_wr_top_line_luma_buffer_size = \
  483. MAX(opb_wr_top_line_luma_buffer_size, (32 * \
  484. HFI_ALIGN(frame_height, 8))); \
  485. opb_wr_top_line_chroma_buffer_size = \
  486. opb_wr_top_line_luma_buffer_size;\
  487. opb_lb_wr_llb_uv_buffer_size = opb_lb_wr_llb_y_buffer_size = \
  488. HFI_ALIGN((HFI_ALIGN(frame_height, 8) / (4 / 2)) * 64,\
  489. BUFFER_ALIGNMENT_32_BYTES); \
  490. Size = num_vpp_pipes * 2 * (vpss_4tap_top_buffer_size + \
  491. vpss_div2_top_buffer_size) + \
  492. 2 * (vpss_4tap_left_buffer_size + \
  493. vpss_div2_left_buffer_size) + \
  494. opb_wr_top_line_luma_buffer_size + \
  495. opb_wr_top_line_chroma_buffer_size + \
  496. opb_lb_wr_llb_uv_buffer_size + \
  497. opb_lb_wr_llb_y_buffer_size; \
  498. } while (0)
  499. /*
  500. * H264d internal buffer definition
  501. */
  502. #define VPP_CMD_MAX_SIZE (1 << 20)
  503. #define NUM_HW_PIC_BUF 32
  504. #define BIN_BUFFER_THRESHOLD (1280 * 736)
  505. #define H264D_MAX_SLICE 1800
  506. #define SIZE_H264D_BUFTAB_T (256) /* sizeof(h264d_buftab_t) aligned to 256 */
  507. #define SIZE_H264D_HW_PIC_T (1 << 11) /* sizeof(h264d_hw_pic_t) 32 aligned */
  508. #define SIZE_H264D_BSE_CMD_PER_BUF (32 * 4)
  509. #define SIZE_H264D_VPP_CMD_PER_BUF (512)
  510. /* Line Buffer definitions */
  511. /* one for luma and 1/2 for each chroma */
  512. #define SIZE_H264D_LB_FE_TOP_DATA(frame_width, frame_height) \
  513. (MAX_FE_NBR_DATA_LUMA_LINE_BUFFER_SIZE * HFI_ALIGN(frame_width, 16) * 3)
  514. #define SIZE_H264D_LB_FE_TOP_CTRL(frame_width, frame_height) \
  515. (MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * ((frame_width + 15) >> 4))
  516. #define SIZE_H264D_LB_FE_LEFT_CTRL(frame_width, frame_height) \
  517. (MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * ((frame_height + 15) >> 4))
  518. #define SIZE_H264D_LB_SE_TOP_CTRL(frame_width, frame_height) \
  519. (MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * ((frame_width + 15) >> 4))
  520. #define SIZE_H264D_LB_SE_LEFT_CTRL(frame_width, frame_height) \
  521. (MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * ((frame_height + 15) >> 4))
  522. #define SIZE_H264D_LB_PE_TOP_DATA(frame_width, frame_height) \
  523. (MAX_PE_NBR_DATA_LCU64_LINE_BUFFER_SIZE * ((frame_width + 15) >> 4))
  524. #define SIZE_H264D_LB_VSP_TOP(frame_width, frame_height) \
  525. ((((frame_width + 15) >> 4) << 7))
  526. #define SIZE_H264D_LB_RECON_DMA_METADATA_WR(frame_width, frame_height) \
  527. (HFI_ALIGN(frame_height, 16) * 32)
  528. #define SIZE_H264D_QP(frame_width, frame_height) \
  529. (((frame_width + 63) >> 6) * ((frame_height + 63) >> 6) * 128)
  530. #define SIZE_HW_PIC(size_per_buf) \
  531. (NUM_HW_PIC_BUF * size_per_buf)
  532. #define SIZE_H264D_BSE_CMD_BUF(_size, frame_width, frame_height) \
  533. do \
  534. { /* this could change alignment */ \
  535. HFI_U32 _height = HFI_ALIGN(frame_height, \
  536. BUFFER_ALIGNMENT_32_BYTES); \
  537. _size = MIN((((_height + 15) >> 4) * 3 * 4), H264D_MAX_SLICE) *\
  538. SIZE_H264D_BSE_CMD_PER_BUF; \
  539. } while (0)
  540. #define SIZE_H264D_VPP_CMD_BUF(_size, frame_width, frame_height) \
  541. do \
  542. { /* this could change alignment */ \
  543. HFI_U32 _height = HFI_ALIGN(frame_height, \
  544. BUFFER_ALIGNMENT_32_BYTES); \
  545. _size = MIN((((_height + 15) >> 4) * 3 * 4), H264D_MAX_SLICE) * \
  546. SIZE_H264D_VPP_CMD_PER_BUF; \
  547. if (_size > VPP_CMD_MAX_SIZE) { _size = VPP_CMD_MAX_SIZE; } \
  548. } while (0)
  549. #define HFI_BUFFER_COMV_H264D(coMV_size, frame_width, \
  550. frame_height, _yuv_bufcount_min) \
  551. do \
  552. { \
  553. HFI_U32 frame_width_in_mbs = ((frame_width + 15) >> 4); \
  554. HFI_U32 frame_height_in_mbs = ((frame_height + 15) >> 4); \
  555. HFI_U32 col_mv_aligned_width = (frame_width_in_mbs << 7); \
  556. HFI_U32 col_zero_aligned_width = (frame_width_in_mbs << 2); \
  557. HFI_U32 col_zero_size = 0, size_colloc = 0; \
  558. col_mv_aligned_width = HFI_ALIGN(col_mv_aligned_width, \
  559. BUFFER_ALIGNMENT_16_BYTES); \
  560. col_zero_aligned_width = HFI_ALIGN(col_zero_aligned_width, \
  561. BUFFER_ALIGNMENT_16_BYTES); \
  562. col_zero_size = col_zero_aligned_width * \
  563. ((frame_height_in_mbs + 1) >> 1); \
  564. col_zero_size = HFI_ALIGN(col_zero_size, \
  565. BUFFER_ALIGNMENT_64_BYTES); \
  566. col_zero_size <<= 1; \
  567. col_zero_size = HFI_ALIGN(col_zero_size, \
  568. BUFFER_ALIGNMENT_512_BYTES); \
  569. size_colloc = col_mv_aligned_width * ((frame_height_in_mbs + \
  570. 1) >> 1); \
  571. size_colloc = HFI_ALIGN(size_colloc, \
  572. BUFFER_ALIGNMENT_64_BYTES); \
  573. size_colloc <<= 1; \
  574. size_colloc = HFI_ALIGN(size_colloc, \
  575. BUFFER_ALIGNMENT_512_BYTES); \
  576. size_colloc += (col_zero_size + SIZE_H264D_BUFTAB_T * 2); \
  577. coMV_size = size_colloc * (_yuv_bufcount_min); \
  578. coMV_size += BUFFER_ALIGNMENT_512_BYTES; \
  579. } while (0)
  580. #define HFI_BUFFER_NON_COMV_H264D(_size, frame_width, frame_height, \
  581. num_vpp_pipes) \
  582. do \
  583. { \
  584. HFI_U32 _size_bse, _size_vpp; \
  585. SIZE_H264D_BSE_CMD_BUF(_size_bse, frame_width, frame_height); \
  586. SIZE_H264D_VPP_CMD_BUF(_size_vpp, frame_width, frame_height); \
  587. _size = HFI_ALIGN(_size_bse, VENUS_DMA_ALIGNMENT) + \
  588. HFI_ALIGN(_size_vpp, VENUS_DMA_ALIGNMENT) + \
  589. HFI_ALIGN(SIZE_HW_PIC(SIZE_H264D_HW_PIC_T), \
  590. VENUS_DMA_ALIGNMENT); \
  591. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  592. } while (0)
  593. #define HFI_BUFFER_LINE_H264D(_size, frame_width, frame_height, \
  594. is_opb, num_vpp_pipes) \
  595. do \
  596. { \
  597. HFI_U32 vpss_lb_size = 0; \
  598. _size = HFI_ALIGN(SIZE_H264D_LB_FE_TOP_DATA(frame_width, \
  599. frame_height), VENUS_DMA_ALIGNMENT) + \
  600. HFI_ALIGN(SIZE_H264D_LB_FE_TOP_CTRL(frame_width, \
  601. frame_height), VENUS_DMA_ALIGNMENT) + \
  602. HFI_ALIGN(SIZE_H264D_LB_FE_LEFT_CTRL(frame_width, \
  603. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  604. HFI_ALIGN(SIZE_H264D_LB_SE_TOP_CTRL(frame_width, \
  605. frame_height), VENUS_DMA_ALIGNMENT) + \
  606. HFI_ALIGN(SIZE_H264D_LB_SE_LEFT_CTRL(frame_width, \
  607. frame_height), VENUS_DMA_ALIGNMENT) * \
  608. num_vpp_pipes + \
  609. HFI_ALIGN(SIZE_H264D_LB_PE_TOP_DATA(frame_width, \
  610. frame_height), VENUS_DMA_ALIGNMENT) + \
  611. HFI_ALIGN(SIZE_H264D_LB_VSP_TOP(frame_width, \
  612. frame_height), VENUS_DMA_ALIGNMENT) + \
  613. HFI_ALIGN(SIZE_H264D_LB_RECON_DMA_METADATA_WR\
  614. (frame_width, frame_height), \
  615. VENUS_DMA_ALIGNMENT) * 2 + HFI_ALIGN(SIZE_H264D_QP\
  616. (frame_width, frame_height), VENUS_DMA_ALIGNMENT); \
  617. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  618. if (is_opb) \
  619. { \
  620. SIZE_VPSS_LB(vpss_lb_size, frame_width, frame_height, \
  621. num_vpp_pipes); \
  622. } \
  623. _size = HFI_ALIGN((_size + vpss_lb_size), \
  624. VENUS_DMA_ALIGNMENT); \
  625. } while (0)
  626. #define H264_CABAC_HDR_RATIO_HD_TOT 1
  627. #define H264_CABAC_RES_RATIO_HD_TOT 3
  628. /*
  629. * some content need more bin buffer,
  630. * but limit buffer size for high resolution
  631. */
  632. #define SIZE_H264D_HW_BIN_BUFFER(_size, frame_width, frame_height, \
  633. delay, num_vpp_pipes) \
  634. do \
  635. { \
  636. HFI_U32 size_yuv, size_bin_hdr, size_bin_res; \
  637. size_yuv = ((frame_width * frame_height) <= \
  638. BIN_BUFFER_THRESHOLD) ?\
  639. ((BIN_BUFFER_THRESHOLD * 3) >> 1) : \
  640. ((frame_width * frame_height * 3) >> 1); \
  641. size_bin_hdr = size_yuv * H264_CABAC_HDR_RATIO_HD_TOT; \
  642. size_bin_res = size_yuv * H264_CABAC_RES_RATIO_HD_TOT; \
  643. size_bin_hdr = size_bin_hdr * (((((HFI_U32)(delay)) & 31) /\
  644. 10) + 2) / 2; \
  645. size_bin_res = size_bin_res * (((((HFI_U32)(delay)) & 31) /\
  646. 10) + 2) / 2; \
  647. size_bin_hdr = HFI_ALIGN(size_bin_hdr / num_vpp_pipes,\
  648. VENUS_DMA_ALIGNMENT) * num_vpp_pipes; \
  649. size_bin_res = HFI_ALIGN(size_bin_res / num_vpp_pipes, \
  650. VENUS_DMA_ALIGNMENT) * num_vpp_pipes; \
  651. _size = size_bin_hdr + size_bin_res; \
  652. } while (0)
  653. #define HFI_BUFFER_BIN_H264D(_size, frame_width, frame_height, is_interlaced, \
  654. delay, num_vpp_pipes) \
  655. do \
  656. { \
  657. HFI_U32 n_aligned_w = HFI_ALIGN(frame_width, \
  658. BUFFER_ALIGNMENT_16_BYTES);\
  659. HFI_U32 n_aligned_h = HFI_ALIGN(frame_height, \
  660. BUFFER_ALIGNMENT_16_BYTES); \
  661. if (!is_interlaced) \
  662. { \
  663. SIZE_H264D_HW_BIN_BUFFER(_size, n_aligned_w, \
  664. n_aligned_h, delay, num_vpp_pipes); \
  665. } \
  666. else \
  667. { \
  668. _size = 0; \
  669. } \
  670. } while (0)
  671. #define NUM_SLIST_BUF_H264 (256 + 32)
  672. #define SIZE_SLIST_BUF_H264 (512)
  673. #define SIZE_SEI_USERDATA (4096)
  674. #define HFI_BUFFER_PERSIST_H264D(_size) \
  675. _size = HFI_ALIGN((SIZE_SLIST_BUF_H264 * NUM_SLIST_BUF_H264 + \
  676. NUM_HW_PIC_BUF * SIZE_SEI_USERDATA), VENUS_DMA_ALIGNMENT)
  677. /*
  678. * H265d internal buffer definition
  679. */
  680. #define LCU_MAX_SIZE_PELS 64
  681. #define LCU_MIN_SIZE_PELS 16
  682. #define H265D_MAX_SLICE 1200
  683. #define SIZE_H265D_HW_PIC_T SIZE_H264D_HW_PIC_T
  684. #define SIZE_H265D_BSE_CMD_PER_BUF (16 * sizeof(HFI_U32))
  685. #define SIZE_H265D_VPP_CMD_PER_BUF (256)
  686. #define SIZE_H265D_LB_FE_TOP_DATA(frame_width, frame_height) \
  687. (MAX_FE_NBR_DATA_LUMA_LINE_BUFFER_SIZE * \
  688. (HFI_ALIGN(frame_width, 64) + 8) * 2)
  689. #define SIZE_H265D_LB_FE_TOP_CTRL(frame_width, frame_height) \
  690. (MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * \
  691. (HFI_ALIGN(frame_width, LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS))
  692. #define SIZE_H265D_LB_FE_LEFT_CTRL(frame_width, frame_height) \
  693. (MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE * \
  694. (HFI_ALIGN(frame_height, LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS))
  695. #define SIZE_H265D_LB_SE_TOP_CTRL(frame_width, frame_height) \
  696. ((LCU_MAX_SIZE_PELS / 8 * (128 / 8)) * ((frame_width + 15) >> 4))
  697. #define SIZE_H265D_LB_SE_LEFT_CTRL(frame_width, frame_height) \
  698. (MAX(((frame_height + 16 - 1) / 8) * \
  699. MAX_SE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE, \
  700. MAX(((frame_height + 32 - 1) / 8) * \
  701. MAX_SE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE, \
  702. ((frame_height + 64 - 1) / 8) * \
  703. MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE)))
  704. #define SIZE_H265D_LB_PE_TOP_DATA(frame_width, frame_height) \
  705. (MAX_PE_NBR_DATA_LCU64_LINE_BUFFER_SIZE * (HFI_ALIGN(frame_width, \
  706. LCU_MIN_SIZE_PELS) / LCU_MIN_SIZE_PELS))
  707. #define SIZE_H265D_LB_VSP_TOP(frame_width, frame_height) \
  708. (((frame_width + 63) >> 6) * 128)
  709. #define SIZE_H265D_LB_VSP_LEFT(frame_width, frame_height) \
  710. (((frame_height + 63) >> 6) * 128)
  711. #define SIZE_H265D_LB_RECON_DMA_METADATA_WR(frame_width, frame_height) \
  712. SIZE_H264D_LB_RECON_DMA_METADATA_WR(frame_width, frame_height)
  713. #define SIZE_H265D_QP(frame_width, frame_height) \
  714. SIZE_H264D_QP(frame_width, frame_height)
  715. #define SIZE_H265D_BSE_CMD_BUF(_size, frame_width, frame_height)\
  716. do \
  717. { \
  718. _size = HFI_ALIGN(((HFI_ALIGN(frame_width, \
  719. LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS) * \
  720. (HFI_ALIGN(frame_height, LCU_MAX_SIZE_PELS) /\
  721. LCU_MIN_SIZE_PELS)) * NUM_HW_PIC_BUF, VENUS_DMA_ALIGNMENT); \
  722. _size = MIN(_size, H265D_MAX_SLICE + 1); \
  723. _size = 2 * _size * SIZE_H265D_BSE_CMD_PER_BUF; \
  724. } while (0)
  725. #define SIZE_H265D_VPP_CMD_BUF(_size, frame_width, frame_height) \
  726. do \
  727. { \
  728. _size = HFI_ALIGN(((HFI_ALIGN(frame_width, LCU_MAX_SIZE_PELS) /\
  729. LCU_MIN_SIZE_PELS) * (HFI_ALIGN(frame_height, \
  730. LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS)) * \
  731. NUM_HW_PIC_BUF, VENUS_DMA_ALIGNMENT); \
  732. _size = MIN(_size, H265D_MAX_SLICE + 1); \
  733. _size = HFI_ALIGN(_size, 4); \
  734. _size = 2 * _size * SIZE_H265D_VPP_CMD_PER_BUF; \
  735. if (_size > VPP_CMD_MAX_SIZE) \
  736. { \
  737. _size = VPP_CMD_MAX_SIZE; \
  738. } \
  739. } while (0)
  740. #define HFI_BUFFER_COMV_H265D(_size, frame_width, frame_height, \
  741. _yuv_bufcount_min) \
  742. do \
  743. { \
  744. _size = HFI_ALIGN(((((frame_width + 15) >> 4) * \
  745. ((frame_height + 15) >> 4)) << 8), \
  746. BUFFER_ALIGNMENT_512_BYTES); \
  747. _size *= _yuv_bufcount_min; \
  748. _size += BUFFER_ALIGNMENT_512_BYTES; \
  749. } while (0)
  750. #define HDR10_HIST_EXTRADATA_SIZE (4 * 1024)
  751. /* c2 divide this into NON_COMV and LINE */
  752. #define HFI_BUFFER_NON_COMV_H265D(_size, frame_width, frame_height, \
  753. num_vpp_pipes) \
  754. do \
  755. { \
  756. HFI_U32 _size_bse, _size_vpp; \
  757. SIZE_H265D_BSE_CMD_BUF(_size_bse, frame_width, \
  758. frame_height); \
  759. SIZE_H265D_VPP_CMD_BUF(_size_vpp, frame_width, \
  760. frame_height); \
  761. _size = HFI_ALIGN(_size_bse, VENUS_DMA_ALIGNMENT) + \
  762. HFI_ALIGN(_size_vpp, VENUS_DMA_ALIGNMENT) + \
  763. HFI_ALIGN(NUM_HW_PIC_BUF * 20 * 22 * 4, \
  764. VENUS_DMA_ALIGNMENT) + \
  765. HFI_ALIGN(2 * sizeof(HFI_U16) * \
  766. (HFI_ALIGN(frame_width, LCU_MAX_SIZE_PELS) / \
  767. LCU_MIN_SIZE_PELS) * (HFI_ALIGN(frame_height, \
  768. LCU_MAX_SIZE_PELS) / LCU_MIN_SIZE_PELS), \
  769. VENUS_DMA_ALIGNMENT) + \
  770. HFI_ALIGN(SIZE_HW_PIC(SIZE_H265D_HW_PIC_T), \
  771. VENUS_DMA_ALIGNMENT) + \
  772. HDR10_HIST_EXTRADATA_SIZE; \
  773. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  774. } while (0)
  775. #define HFI_BUFFER_LINE_H265D(_size, frame_width, frame_height, \
  776. is_opb, num_vpp_pipes) \
  777. do \
  778. { \
  779. HFI_U32 vpss_lb_size = 0; \
  780. _size = HFI_ALIGN(SIZE_H265D_LB_FE_TOP_DATA(frame_width, \
  781. frame_height), VENUS_DMA_ALIGNMENT) + \
  782. HFI_ALIGN(SIZE_H265D_LB_FE_TOP_CTRL(frame_width, \
  783. frame_height), VENUS_DMA_ALIGNMENT) + \
  784. HFI_ALIGN(SIZE_H265D_LB_FE_LEFT_CTRL(frame_width, \
  785. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  786. HFI_ALIGN(SIZE_H265D_LB_SE_LEFT_CTRL(frame_width, \
  787. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  788. HFI_ALIGN(SIZE_H265D_LB_SE_TOP_CTRL(frame_width, \
  789. frame_height), VENUS_DMA_ALIGNMENT) + \
  790. HFI_ALIGN(SIZE_H265D_LB_PE_TOP_DATA(frame_width, \
  791. frame_height), VENUS_DMA_ALIGNMENT) + \
  792. HFI_ALIGN(SIZE_H265D_LB_VSP_TOP(frame_width, \
  793. frame_height), VENUS_DMA_ALIGNMENT) + \
  794. HFI_ALIGN(SIZE_H265D_LB_VSP_LEFT(frame_width, \
  795. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  796. HFI_ALIGN(SIZE_H265D_LB_RECON_DMA_METADATA_WR\
  797. (frame_width, frame_height), \
  798. VENUS_DMA_ALIGNMENT) * 4 + \
  799. HFI_ALIGN(SIZE_H265D_QP(frame_width, frame_height),\
  800. VENUS_DMA_ALIGNMENT); \
  801. if (is_opb) \
  802. { \
  803. SIZE_VPSS_LB(vpss_lb_size, frame_width, frame_height,\
  804. num_vpp_pipes); \
  805. } \
  806. _size = HFI_ALIGN((_size + vpss_lb_size), \
  807. VENUS_DMA_ALIGNMENT); \
  808. } while (0)
  809. #define H265_CABAC_HDR_RATIO_HD_TOT 2
  810. #define H265_CABAC_RES_RATIO_HD_TOT 2
  811. /*
  812. * some content need more bin buffer,
  813. * but limit buffer size for high resolution
  814. */
  815. #define SIZE_H265D_HW_BIN_BUFFER(_size, frame_width, frame_height, \
  816. delay, num_vpp_pipes) \
  817. do \
  818. { \
  819. HFI_U32 size_yuv, size_bin_hdr, size_bin_res; \
  820. size_yuv = ((frame_width * frame_height) <= \
  821. BIN_BUFFER_THRESHOLD) ? \
  822. ((BIN_BUFFER_THRESHOLD * 3) >> 1) : \
  823. ((frame_width * frame_height * 3) >> 1); \
  824. size_bin_hdr = size_yuv * H265_CABAC_HDR_RATIO_HD_TOT; \
  825. size_bin_res = size_yuv * H265_CABAC_RES_RATIO_HD_TOT; \
  826. size_bin_hdr = size_bin_hdr * \
  827. (((((HFI_U32)(delay)) & 31) / 10) + 2) / 2; \
  828. size_bin_res = size_bin_res * \
  829. (((((HFI_U32)(delay)) & 31) / 10) + 2) / 2; \
  830. size_bin_hdr = HFI_ALIGN(size_bin_hdr / \
  831. num_vpp_pipes, VENUS_DMA_ALIGNMENT) * \
  832. num_vpp_pipes; \
  833. size_bin_res = HFI_ALIGN(size_bin_res / num_vpp_pipes,\
  834. VENUS_DMA_ALIGNMENT) * num_vpp_pipes; \
  835. _size = size_bin_hdr + size_bin_res; \
  836. } while (0)
  837. #define HFI_BUFFER_BIN_H265D(_size, frame_width, frame_height, \
  838. is_interlaced, delay, num_vpp_pipes) \
  839. do \
  840. { \
  841. HFI_U32 n_aligned_w = HFI_ALIGN(frame_width, \
  842. BUFFER_ALIGNMENT_16_BYTES); \
  843. HFI_U32 n_aligned_h = HFI_ALIGN(frame_height, \
  844. BUFFER_ALIGNMENT_16_BYTES); \
  845. if (!is_interlaced) \
  846. { \
  847. SIZE_H265D_HW_BIN_BUFFER(_size, n_aligned_w, \
  848. n_aligned_h, delay, num_vpp_pipes); \
  849. } \
  850. else \
  851. { \
  852. _size = 0; \
  853. } \
  854. } while (0)
  855. #define SIZE_SLIST_BUF_H265 (1 << 10)
  856. #define NUM_SLIST_BUF_H265 (80 + 20)
  857. #define H265_NUM_TILE_COL 32
  858. #define H265_NUM_TILE_ROW 128
  859. #define H265_NUM_TILE (H265_NUM_TILE_ROW * H265_NUM_TILE_COL + 1)
  860. #define HFI_BUFFER_PERSIST_H265D(_size) \
  861. _size = HFI_ALIGN((SIZE_SLIST_BUF_H265 * NUM_SLIST_BUF_H265 + \
  862. H265_NUM_TILE * sizeof(HFI_U32) + NUM_HW_PIC_BUF * SIZE_SEI_USERDATA),\
  863. VENUS_DMA_ALIGNMENT)
  864. /*
  865. * VPxd internal buffer definition
  866. */
  867. #define SIZE_VPXD_LB_FE_LEFT_CTRL(frame_width, frame_height) \
  868. MAX(((frame_height + 15) >> 4) * \
  869. MAX_FE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE, \
  870. MAX(((frame_height + 31) >> 5) * \
  871. MAX_FE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE, \
  872. ((frame_height + 63) >> 6) * MAX_FE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE))
  873. #define SIZE_VPXD_LB_FE_TOP_CTRL(frame_width, frame_height) \
  874. (((HFI_ALIGN(frame_width, 64) + 8) * 10 * 2)) /* + small line */
  875. #define SIZE_VPXD_LB_SE_TOP_CTRL(frame_width, frame_height) \
  876. (((frame_width + 15) >> 4) * MAX_FE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE)
  877. #define SIZE_VPXD_LB_SE_LEFT_CTRL(frame_width, frame_height) \
  878. MAX(((frame_height + 15) >> 4) * \
  879. MAX_SE_NBR_CTRL_LCU16_LINE_BUFFER_SIZE,\
  880. MAX(((frame_height + 31) >> 5) * \
  881. MAX_SE_NBR_CTRL_LCU32_LINE_BUFFER_SIZE, \
  882. ((frame_height + 63) >> 6) * MAX_SE_NBR_CTRL_LCU64_LINE_BUFFER_SIZE))
  883. #define SIZE_VPXD_LB_RECON_DMA_METADATA_WR(frame_width, frame_height) \
  884. HFI_ALIGN((HFI_ALIGN(frame_height, 8) / (4 / 2)) * 64,\
  885. BUFFER_ALIGNMENT_32_BYTES)
  886. #define SIZE_MP2D_LB_FE_TOP_DATA(frame_width, frame_height) \
  887. ((HFI_ALIGN(frame_width, 16) + 8) * 10 * 2)
  888. #define SIZE_VP9D_LB_FE_TOP_DATA(frame_width, frame_height) \
  889. ((HFI_ALIGN(HFI_ALIGN(frame_width, 8), 64) + 8) * 10 * 2)
  890. #define SIZE_MP2D_LB_PE_TOP_DATA(frame_width, frame_height) \
  891. ((HFI_ALIGN(frame_width, 16) >> 4) * 64)
  892. #define SIZE_VP9D_LB_PE_TOP_DATA(frame_width, frame_height) \
  893. ((HFI_ALIGN(HFI_ALIGN(frame_width, 8), 64) >> 6) * 176)
  894. #define SIZE_MP2D_LB_VSP_TOP(frame_width, frame_height) \
  895. (((HFI_ALIGN(frame_width, 16) >> 4) * 64 / 2) + 256)
  896. #define SIZE_VP9D_LB_VSP_TOP(frame_width, frame_height) \
  897. ((((HFI_ALIGN(HFI_ALIGN(frame_width, 8), 64) >> 6) * 64 * 8) + 256))
  898. /* sizeof(VP9_COL_MV_BUFFER) */
  899. #define HFI_IRIS2_VP9D_COMV_SIZE \
  900. ((((8192 + 63) >> 6) * ((4320 + 63) >> 6) * 8 * 8 * 2 * 8))
  901. #define HFI_IRIS2_VP9D_LB_SIZE(_size, frame_width, frame_height, num_vpp_pipes)\
  902. do \
  903. { \
  904. _size = HFI_ALIGN(SIZE_VPXD_LB_FE_LEFT_CTRL(frame_width, \
  905. frame_height),VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  906. HFI_ALIGN(SIZE_VPXD_LB_SE_LEFT_CTRL(frame_width, frame_height),\
  907. VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  908. HFI_ALIGN(SIZE_VP9D_LB_VSP_TOP(frame_width, frame_height), \
  909. VENUS_DMA_ALIGNMENT) + \
  910. HFI_ALIGN(SIZE_VPXD_LB_FE_TOP_CTRL(frame_width, frame_height), \
  911. VENUS_DMA_ALIGNMENT) + 2 * \
  912. HFI_ALIGN(SIZE_VPXD_LB_RECON_DMA_METADATA_WR \
  913. (frame_width, frame_height), VENUS_DMA_ALIGNMENT) + \
  914. HFI_ALIGN(SIZE_VPXD_LB_SE_TOP_CTRL(frame_width, frame_height), \
  915. VENUS_DMA_ALIGNMENT) + \
  916. HFI_ALIGN(SIZE_VP9D_LB_PE_TOP_DATA(frame_width, frame_height), \
  917. VENUS_DMA_ALIGNMENT) + \
  918. HFI_ALIGN(SIZE_VP9D_LB_FE_TOP_DATA(frame_width, frame_height), \
  919. VENUS_DMA_ALIGNMENT); \
  920. } while (0)
  921. /* _yuv_bufcount_min = MAX(Min YUV Buffer count,
  922. * (HFI_PROPERTY_PARAM_VDEC_VPP_DELAY + 1))
  923. */
  924. #define HFI_BUFFER_LINE_VP9D(_size, frame_width, frame_height, \
  925. _yuv_bufcount_min, is_opb, num_vpp_pipes) \
  926. do \
  927. { \
  928. HFI_U32 _lb_size = 0; \
  929. HFI_U32 vpss_lb_size = 0; \
  930. HFI_IRIS2_VP9D_LB_SIZE(_lb_size, frame_width, frame_height,\
  931. num_vpp_pipes); \
  932. if (is_opb) \
  933. { \
  934. SIZE_VPSS_LB(vpss_lb_size, frame_width, frame_height, \
  935. num_vpp_pipes); \
  936. } \
  937. _size = _lb_size + vpss_lb_size + HDR10_HIST_EXTRADATA_SIZE; \
  938. } while (0)
  939. #define VPX_DECODER_FRAME_CONCURENCY_LVL (2)
  940. #define VPX_DECODER_FRAME_BIN_HDR_BUDGET_RATIO 1 / 2
  941. #define VPX_DECODER_FRAME_BIN_RES_BUDGET_RATIO 3 / 2
  942. #define HFI_BUFFER_BIN_VP9D(_size, frame_width, frame_height, \
  943. is_interlaced, num_vpp_pipes) \
  944. do \
  945. { \
  946. HFI_U32 _size_yuv = HFI_ALIGN(frame_width, \
  947. BUFFER_ALIGNMENT_16_BYTES) *\
  948. HFI_ALIGN(frame_height, BUFFER_ALIGNMENT_16_BYTES) * 3 / 2; \
  949. if (!is_interlaced) \
  950. { \
  951. /* binbuffer1_size + binbufer2_size */ \
  952. _size = HFI_ALIGN(((MAX(_size_yuv, \
  953. ((BIN_BUFFER_THRESHOLD * 3) >> 1)) * \
  954. VPX_DECODER_FRAME_BIN_HDR_BUDGET_RATIO * \
  955. VPX_DECODER_FRAME_CONCURENCY_LVL) / num_vpp_pipes), \
  956. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(((MAX(_size_yuv, \
  957. ((BIN_BUFFER_THRESHOLD * 3) >> 1)) * \
  958. VPX_DECODER_FRAME_BIN_RES_BUDGET_RATIO * \
  959. VPX_DECODER_FRAME_CONCURENCY_LVL) / num_vpp_pipes), \
  960. VENUS_DMA_ALIGNMENT); \
  961. _size = _size * num_vpp_pipes; \
  962. } \
  963. else \
  964. { \
  965. _size = 0; \
  966. } \
  967. } while (0)
  968. #define VP9_NUM_FRAME_INFO_BUF 32
  969. #define VP9_NUM_PROBABILITY_TABLE_BUF (VP9_NUM_FRAME_INFO_BUF + 4)
  970. #define VP9_PROB_TABLE_SIZE (3840)
  971. #define VP9_UDC_HEADER_BUF_SIZE (3 * 128)
  972. #define MAX_SUPERFRAME_HEADER_LEN (34)
  973. #define CCE_TILE_OFFSET_SIZE HFI_ALIGN(32 * 4 * 4, BUFFER_ALIGNMENT_32_BYTES)
  974. #define HFI_BUFFER_PERSIST_VP9D(_size) \
  975. _size = HFI_ALIGN(VP9_NUM_PROBABILITY_TABLE_BUF * VP9_PROB_TABLE_SIZE, \
  976. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(HFI_IRIS2_VP9D_COMV_SIZE, \
  977. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(MAX_SUPERFRAME_HEADER_LEN, \
  978. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(VP9_UDC_HEADER_BUF_SIZE, \
  979. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(VP9_NUM_FRAME_INFO_BUF * \
  980. CCE_TILE_OFFSET_SIZE, VENUS_DMA_ALIGNMENT)
  981. /*
  982. * MP2d internal buffer definition
  983. */
  984. #define HFI_BUFFER_LINE_MP2D(_size, frame_width, frame_height, \
  985. _yuv_bufcount_min, is_opb, num_vpp_pipes) \
  986. do \
  987. { \
  988. HFI_U32 vpss_lb_size = 0; \
  989. _size = HFI_ALIGN(SIZE_VPXD_LB_FE_LEFT_CTRL(frame_width, \
  990. frame_height), VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  991. HFI_ALIGN(SIZE_VPXD_LB_SE_LEFT_CTRL(frame_width, frame_height),\
  992. VENUS_DMA_ALIGNMENT) * num_vpp_pipes + \
  993. HFI_ALIGN(SIZE_MP2D_LB_VSP_TOP(frame_width, frame_height),\
  994. VENUS_DMA_ALIGNMENT) + HFI_ALIGN(SIZE_VPXD_LB_FE_TOP_CTRL\
  995. (frame_width, frame_height), VENUS_DMA_ALIGNMENT) + \
  996. 2 * HFI_ALIGN(SIZE_VPXD_LB_RECON_DMA_METADATA_WR(frame_width,\
  997. frame_height), VENUS_DMA_ALIGNMENT) + \
  998. HFI_ALIGN(SIZE_VPXD_LB_SE_TOP_CTRL(frame_width, frame_height),\
  999. VENUS_DMA_ALIGNMENT) + \
  1000. HFI_ALIGN(SIZE_MP2D_LB_PE_TOP_DATA(frame_width, frame_height), \
  1001. VENUS_DMA_ALIGNMENT) + \
  1002. HFI_ALIGN(SIZE_MP2D_LB_FE_TOP_DATA(frame_width, frame_height), \
  1003. VENUS_DMA_ALIGNMENT); \
  1004. if (is_opb) \
  1005. { \
  1006. SIZE_VPSS_LB(vpss_lb_size, frame_width, frame_height, \
  1007. num_vpp_pipes); \
  1008. } \
  1009. _size += vpss_lb_size; \
  1010. } while (0)
  1011. #define HFI_BUFFER_BIN_MP2D(_size, frame_width, frame_height, is_interlaced) 0
  1012. #define QMATRIX_SIZE (sizeof(HFI_U32) * 128 + 256)
  1013. #define MP2D_QPDUMP_SIZE 115200
  1014. #define HFI_BUFFER_PERSIST_MP2D(_size) \
  1015. _size = QMATRIX_SIZE + MP2D_QPDUMP_SIZE;
  1016. /* Begin of IRIS2 Encoder */
  1017. /*
  1018. * Encoder Output Bitstream Buffer definition
  1019. * To match with driver Calculation,
  1020. * the output bitstream = YUV/4 for larger than 4K size.
  1021. */
  1022. #define HFI_BUFFER_BITSTREAM_ENC(size, frame_width, frame_height, \
  1023. rc_type, is_ten_bit) \
  1024. do \
  1025. { \
  1026. HFI_U32 aligned_width, aligned_height, bitstream_size; \
  1027. aligned_width = HFI_ALIGN(frame_width, 32); \
  1028. aligned_height = HFI_ALIGN(frame_height, 32); \
  1029. bitstream_size = aligned_width * aligned_height * 3; \
  1030. if (aligned_width * aligned_height > (4096 * 2176)) \
  1031. { \
  1032. bitstream_size = (bitstream_size >> 3); \
  1033. } \
  1034. else if (bitstream_size > (1280 * 720)) \
  1035. { \
  1036. bitstream_size = (bitstream_size >> 2); \
  1037. } \
  1038. else \
  1039. { \
  1040. bitstream_size = (bitstream_size << 1);\
  1041. } \
  1042. if ((rc_type == HFI_RC_CQ) || (rc_type == HFI_RC_OFF)) \
  1043. { \
  1044. bitstream_size = (bitstream_size << 1);\
  1045. } \
  1046. if (is_ten_bit) \
  1047. { \
  1048. bitstream_size = (bitstream_size) + \
  1049. (bitstream_size >> 2); \
  1050. } \
  1051. size = HFI_ALIGN(bitstream_size, HFI_ALIGNMENT_4096); \
  1052. } while (0)
  1053. #define SIZE_ROI_METADATA_ENC(size_roi, frame_width, frame_height, lcu_size)\
  1054. do \
  1055. { \
  1056. HFI_U32 width_in_lcus = 0, height_in_lcus = 0, n_shift = 0; \
  1057. while (lcu_size && !(lcu_size & 0x1)) \
  1058. { \
  1059. n_shift++; \
  1060. lcu_size = lcu_size >> 1; \
  1061. } \
  1062. width_in_lcus = (frame_width + (lcu_size - 1)) >> n_shift; \
  1063. height_in_lcus = (frame_height + (lcu_size - 1)) >> n_shift; \
  1064. size_roi = (((width_in_lcus + 7) >> 3) << 3) * \
  1065. height_in_lcus * 2 + 256; \
  1066. } while (0)
  1067. /*
  1068. * Encoder Input Extradata Buffer definition
  1069. */
  1070. #define HFI_BUFFER_INPUT_METADATA_ENC(size, frame_width, frame_height, \
  1071. is_roi_enabled, lcu_size) \
  1072. do \
  1073. { \
  1074. HFI_U32 roi_size = 0; \
  1075. if (is_roi_enabled) \
  1076. { \
  1077. SIZE_ROI_METADATA_ENC(roi_size, frame_width, \
  1078. frame_height, lcu_size); \
  1079. } \
  1080. size = roi_size + 16384; \
  1081. size = HFI_ALIGN(size, HFI_ALIGNMENT_4096); \
  1082. } while (0)
  1083. #define HFI_BUFFER_INPUT_METADATA_H264E(size_metadata, frame_width, \
  1084. frame_height, is_roi_enabled) \
  1085. do \
  1086. { \
  1087. HFI_BUFFER_INPUT_METADATA_ENC(size_metadata, frame_width, \
  1088. frame_height, is_roi_enabled, 16); \
  1089. }while (0)
  1090. #define HFI_BUFFER_INPUT_METADATA_H265E(size_metadata, frame_width, \
  1091. frame_height, is_roi_enabled) \
  1092. do \
  1093. { \
  1094. HFI_BUFFER_INPUT_METADATA_ENC(size_metadata, frame_width, \
  1095. frame_height, is_roi_enabled, 32); \
  1096. } while (0)
  1097. #define HFI_BUFFER_ARP_ENC(size) \
  1098. do \
  1099. { \
  1100. size = 204800; \
  1101. } while (0)
  1102. /*
  1103. * Encoder Scratch Buffer definition
  1104. */
  1105. #define HFI_MAX_COL_FRAME 6
  1106. #define HFI_VENUS_VENC_TRE_WB_BUFF_SIZE (65 << 4) // bytes
  1107. #define HFI_VENUS_VENC_DB_LINE_BUFF_PER_MB 512
  1108. #define HFI_VENUS_VPPSG_MAX_REGISTERS 2048
  1109. #define HFI_VENUS_WIDTH_ALIGNMENT 128
  1110. #define HFI_VENUS_WIDTH_TEN_BIT_ALIGNMENT 192
  1111. #define HFI_VENUS_HEIGHT_ALIGNMENT 32
  1112. #define VENUS_METADATA_STRIDE_MULTIPLE 64
  1113. #define VENUS_METADATA_HEIGHT_MULTIPLE 16
  1114. #ifndef SYSTEM_LAL_TILE10
  1115. #define SYSTEM_LAL_TILE10 192
  1116. #endif
  1117. /*
  1118. * Host uses following macro to calculate num_ref for encoder
  1119. * Here: _total_hp_layers = HFI_PROPERTY_PARAM_VENC_HIER_P_MAX_NUM_ENH_LAYER + 1
  1120. * Here: _total_hb_layers = HFI_PROPERTY_PARAM_VENC_HIER_B_MAX_NUM_ENH_LAYER + 1
  1121. */
  1122. #define HFI_IRIS2_ENC_RECON_BUF_COUNT(num_recon, n_bframe, ltr_count, \
  1123. _total_hp_layers, _total_hb_layers, hybrid_hp, codec_standard) \
  1124. do \
  1125. { \
  1126. HFI_U32 num_ref = 1; \
  1127. if (n_bframe) \
  1128. num_ref = 2; \
  1129. if (ltr_count) \
  1130. /* B and LTR can't be at same time */\
  1131. num_ref = num_ref + ltr_count; \
  1132. if (_total_hp_layers) \
  1133. { \
  1134. if (hybrid_hp) \
  1135. /* LTR and B-frame not supported with hybrid HP */\
  1136. num_ref = (_total_hp_layers - 1); \
  1137. if (codec_standard == HFI_CODEC_ENCODE_HEVC) \
  1138. num_ref = (_total_hp_layers + 1) / 2 + \
  1139. ltr_count; \
  1140. else if (codec_standard == HFI_CODEC_ENCODE_AVC && \
  1141. _total_hp_layers <= 4) \
  1142. num_ref = (2 ^ (_total_hp_layers - 1)) - 1 + \
  1143. ltr_count; \
  1144. else \
  1145. /* AVC normal HP and TotalHPLayer>4.*/ \
  1146. /* This is NPOR. uses MMCO. */ \
  1147. num_ref = (_total_hp_layers + 1) / 2 + \
  1148. ltr_count; \
  1149. } \
  1150. if (_total_hb_layers >= 2) \
  1151. { \
  1152. num_ref = (2 ^ (_total_hb_layers - 1)) / 2 + 1; \
  1153. } \
  1154. num_recon = num_ref + 1; \
  1155. } while (0)
  1156. #define SIZE_BIN_BITSTREAM_ENC(_size, frame_width, frame_height, \
  1157. work_mode, lcu_size) \
  1158. do \
  1159. { \
  1160. HFI_U32 size_aligned_width = 0, size_aligned_height = 0; \
  1161. HFI_U32 bitstream_size_eval = 0; \
  1162. size_aligned_width = HFI_ALIGN((frame_width), lcu_size); \
  1163. size_aligned_height = HFI_ALIGN((frame_height), lcu_size); \
  1164. if (work_mode == HFI_WORKMODE_2) \
  1165. { \
  1166. bitstream_size_eval = (((size_aligned_width) * \
  1167. (size_aligned_height)*3 * 5) >> 2); \
  1168. if (size_aligned_width * size_aligned_height > \
  1169. (4096 * 2176)) \
  1170. { \
  1171. bitstream_size_eval = \
  1172. (bitstream_size_eval >> 3); \
  1173. } \
  1174. else if (bitstream_size_eval > (352 * 288 * 4)) \
  1175. { \
  1176. bitstream_size_eval = \
  1177. (bitstream_size_eval >> 2); \
  1178. } \
  1179. } \
  1180. else \
  1181. { \
  1182. bitstream_size_eval = size_aligned_width * \
  1183. size_aligned_height * 3; \
  1184. } \
  1185. _size = HFI_ALIGN(bitstream_size_eval, VENUS_DMA_ALIGNMENT); \
  1186. } while (0)
  1187. #define SIZE_ENC_SINGLE_PIPE(size, bitbin_size, num_vpp_pipes, \
  1188. frame_height, frame_width) \
  1189. do \
  1190. { \
  1191. HFI_U32 size_single_pipe_eval = 0, sao_bin_buffer_size = 0, \
  1192. _padded_bin_sz = 0; \
  1193. if (num_vpp_pipes > 2) \
  1194. { \
  1195. size_single_pipe_eval = bitbin_size / 2; \
  1196. } \
  1197. else \
  1198. { \
  1199. size_single_pipe_eval = bitbin_size; \
  1200. } \
  1201. size_single_pipe_eval = HFI_ALIGN(size_single_pipe_eval, \
  1202. VENUS_DMA_ALIGNMENT); \
  1203. sao_bin_buffer_size = (64 * ((((frame_width) + \
  1204. BUFFER_ALIGNMENT_32_BYTES) * ((frame_height) +\
  1205. BUFFER_ALIGNMENT_32_BYTES)) >> 10)) + 384; \
  1206. _padded_bin_sz = HFI_ALIGN(size_single_pipe_eval, \
  1207. VENUS_DMA_ALIGNMENT);\
  1208. size_single_pipe_eval = sao_bin_buffer_size + _padded_bin_sz; \
  1209. size_single_pipe_eval = HFI_ALIGN(size_single_pipe_eval, \
  1210. VENUS_DMA_ALIGNMENT); \
  1211. size = size_single_pipe_eval; \
  1212. } while (0)
  1213. #define HFI_BUFFER_BIN_ENC(_size, frame_width, frame_height, lcu_size, \
  1214. work_mode, num_vpp_pipes) \
  1215. do \
  1216. { \
  1217. HFI_U32 bitstream_size = 0, total_bitbin_buffers = 0, \
  1218. size_single_pipe = 0, bitbin_size = 0; \
  1219. SIZE_BIN_BITSTREAM_ENC(bitstream_size, frame_width, \
  1220. frame_height, work_mode, lcu_size); \
  1221. if (work_mode == HFI_WORKMODE_2) \
  1222. { \
  1223. total_bitbin_buffers = 3; \
  1224. bitbin_size = bitstream_size * 17 / 10; \
  1225. bitbin_size = HFI_ALIGN(bitbin_size, \
  1226. VENUS_DMA_ALIGNMENT); \
  1227. } \
  1228. else \
  1229. { \
  1230. total_bitbin_buffers = 1; \
  1231. bitbin_size = bitstream_size; \
  1232. } \
  1233. SIZE_ENC_SINGLE_PIPE(size_single_pipe, bitbin_size, \
  1234. num_vpp_pipes, frame_height, frame_width); \
  1235. bitbin_size = size_single_pipe * num_vpp_pipes; \
  1236. _size = HFI_ALIGN(bitbin_size, VENUS_DMA_ALIGNMENT) * \
  1237. total_bitbin_buffers + 512; \
  1238. } while (0)
  1239. #define HFI_BUFFER_BIN_H264E(_size, frame_width, frame_height, \
  1240. work_mode, num_vpp_pipes) \
  1241. do \
  1242. { \
  1243. HFI_BUFFER_BIN_ENC(_size, frame_width, frame_height, 16, \
  1244. work_mode, num_vpp_pipes); \
  1245. } while (0)
  1246. #define HFI_BUFFER_BIN_H265E(_size, frame_width, frame_height, \
  1247. work_mode, num_vpp_pipes) \
  1248. do \
  1249. { \
  1250. HFI_BUFFER_BIN_ENC(_size, frame_width, frame_height, 32,\
  1251. work_mode, num_vpp_pipes); \
  1252. } while (0)
  1253. #define SIZE_ENC_SLICE_INFO_BUF(num_lcu_in_frame) HFI_ALIGN((256 + \
  1254. (num_lcu_in_frame << 4)), VENUS_DMA_ALIGNMENT)
  1255. #define SIZE_LINE_BUF_CTRL(frame_width_coded) \
  1256. HFI_ALIGN(frame_width_coded, VENUS_DMA_ALIGNMENT)
  1257. #define SIZE_LINE_BUF_CTRL_ID2(frame_width_coded) \
  1258. HFI_ALIGN(frame_width_coded, VENUS_DMA_ALIGNMENT)
  1259. #define SIZE_LINEBUFF_DATA(_size, is_ten_bit, frame_width_coded) \
  1260. do \
  1261. { \
  1262. _size = is_ten_bit ? (((((10 * (frame_width_coded) +\
  1263. 1024) + (VENUS_DMA_ALIGNMENT - 1)) & \
  1264. (~(VENUS_DMA_ALIGNMENT - 1))) * 1) + \
  1265. (((((10 * (frame_width_coded) + 1024) >> 1) + \
  1266. (VENUS_DMA_ALIGNMENT - 1)) & (~(VENUS_DMA_ALIGNMENT - 1))) * \
  1267. 2)) : (((((8 * (frame_width_coded) + 1024) + \
  1268. (VENUS_DMA_ALIGNMENT - 1)) \
  1269. & (~(VENUS_DMA_ALIGNMENT - 1))) * 1) + \
  1270. (((((8 * (frame_width_coded) +\
  1271. 1024) >> 1) + (VENUS_DMA_ALIGNMENT - 1)) & \
  1272. (~(VENUS_DMA_ALIGNMENT - 1))) * 2)); \
  1273. } while (0)
  1274. #define SIZE_LEFT_LINEBUFF_CTRL(_size, standard, frame_height_coded, \
  1275. num_vpp_pipes_enc) \
  1276. do \
  1277. { \
  1278. _size = (standard == HFI_CODEC_ENCODE_HEVC) ? \
  1279. (((frame_height_coded) + \
  1280. (BUF_SIZE_ALIGN_32)) / BUF_SIZE_ALIGN_32 * 4 * 16) : \
  1281. (((frame_height_coded) + 15) / 16 * 5 * 16); \
  1282. if ((num_vpp_pipes_enc) > 1) \
  1283. { \
  1284. _size += BUFFER_ALIGNMENT_512_BYTES; \
  1285. _size = HFI_ALIGN(_size, BUFFER_ALIGNMENT_512_BYTES) *\
  1286. (num_vpp_pipes_enc); \
  1287. } \
  1288. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1289. } while (0)
  1290. #define SIZE_LEFT_LINEBUFF_RECON_PIX(_size, is_ten_bit, frame_height_coded, \
  1291. num_vpp_pipes_enc) \
  1292. do \
  1293. { \
  1294. _size = (((is_ten_bit + 1) * 2 * (frame_height_coded) + \
  1295. VENUS_DMA_ALIGNMENT) + \
  1296. (VENUS_DMA_ALIGNMENT << (num_vpp_pipes_enc - 1)) - 1) & \
  1297. (~((VENUS_DMA_ALIGNMENT << (num_vpp_pipes_enc - 1)) - 1)) * 1; \
  1298. } while (0)
  1299. #define SIZE_TOP_LINEBUFF_CTRL_FE(_size, frame_width_coded, standard) \
  1300. do \
  1301. { \
  1302. _size = (standard == HFI_CODEC_ENCODE_HEVC) ? (64 * \
  1303. ((frame_width_coded) >> 5)) : (VENUS_DMA_ALIGNMENT + 16 * \
  1304. ((frame_width_coded) >> 4)); \
  1305. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1306. } while (0)
  1307. #define SIZE_LEFT_LINEBUFF_CTRL_FE(frame_height_coded, num_vpp_pipes_enc) \
  1308. ((((VENUS_DMA_ALIGNMENT + 64 * ((frame_height_coded) >> 4)) + \
  1309. (VENUS_DMA_ALIGNMENT << (num_vpp_pipes_enc - 1)) - 1) & \
  1310. (~((VENUS_DMA_ALIGNMENT << (num_vpp_pipes_enc - 1)) - 1)) * 1) * \
  1311. num_vpp_pipes_enc)
  1312. #define SIZE_LEFT_LINEBUFF_METADATA_RECON_Y(_size, frame_height_coded, \
  1313. is_ten_bit, num_vpp_pipes_enc) \
  1314. do \
  1315. { \
  1316. _size = ((VENUS_DMA_ALIGNMENT + 64 * ((frame_height_coded) / \
  1317. (8 * (is_ten_bit ? 4 : 8))))); \
  1318. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1319. _size = (_size * num_vpp_pipes_enc); \
  1320. } while (0)
  1321. #define SIZE_LEFT_LINEBUFF_METADATA_RECON_UV(_size, frame_height_coded, \
  1322. is_ten_bit, num_vpp_pipes_enc) \
  1323. do \
  1324. { \
  1325. _size = ((VENUS_DMA_ALIGNMENT + 64 * ((frame_height_coded) / \
  1326. (4 * (is_ten_bit ? 4 : 8))))); \
  1327. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1328. _size = (_size * num_vpp_pipes_enc); \
  1329. } while (0)
  1330. #define SIZE_LINEBUFF_RECON_PIX(_size, is_ten_bit, frame_width_coded) \
  1331. do \
  1332. { \
  1333. _size = ((is_ten_bit ? 3 : 2) * (frame_width_coded)); \
  1334. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT); \
  1335. } while (0)
  1336. #define SIZE_SLICE_CMD_BUFFER (HFI_ALIGN(20480, VENUS_DMA_ALIGNMENT))
  1337. #define SIZE_SPS_PPS_SLICE_HDR (2048 + 4096)
  1338. #define SIZE_FRAME_RC_BUF_SIZE(_size, standard, frame_height_coded, \
  1339. num_vpp_pipes_enc) \
  1340. do \
  1341. { \
  1342. _size = (standard == HFI_CODEC_ENCODE_HEVC) ? (256 + 16 * \
  1343. (14 + ((((frame_height_coded) >> 5) + 7) >> 3))) : \
  1344. (256 + 16 * (14 + ((((frame_height_coded) >> 4) + 7) >> 3))); \
  1345. _size *= 6; /* multiply by max numtilescol */ \
  1346. if (num_vpp_pipes_enc > 1) \
  1347. { \
  1348. _size = HFI_ALIGN(_size, VENUS_DMA_ALIGNMENT) \
  1349. * num_vpp_pipes_enc;\
  1350. } \
  1351. _size = HFI_ALIGN(_size, BUFFER_ALIGNMENT_512_BYTES) * \
  1352. HFI_MAX_COL_FRAME; \
  1353. } while (0)
  1354. #define ENC_BITCNT_BUF_SIZE(num_lcu_in_frame) HFI_ALIGN((256 + \
  1355. (4 * (num_lcu_in_frame))), VENUS_DMA_ALIGNMENT)
  1356. #define ENC_BITMAP_BUF_SIZE(num_lcu_in_frame) HFI_ALIGN((256 + \
  1357. ((num_lcu_in_frame) >> 3)), VENUS_DMA_ALIGNMENT)
  1358. #define SIZE_LINE_BUF_SDE(frame_width_coded) HFI_ALIGN((256 + \
  1359. (16 * ((frame_width_coded) >> 4))), VENUS_DMA_ALIGNMENT)
  1360. #define SIZE_SE_STATS_BUF(_size, frame_width_coded, frame_height_coded, \
  1361. num_lcu_in_frame) \
  1362. do \
  1363. { \
  1364. if (((frame_width_coded) * (frame_height_coded)) > \
  1365. (4096 * 2160)) \
  1366. { \
  1367. _size = 0; \
  1368. } \
  1369. else if (((frame_width_coded) * (frame_height_coded)) > \
  1370. (1920 * 1088)) \
  1371. { \
  1372. _size = (40 * 4 * num_lcu_in_frame + 256 + 256); \
  1373. } \
  1374. else \
  1375. { \
  1376. _size = (1024 * num_lcu_in_frame + 256 + 256); \
  1377. } \
  1378. _size = HFI_ALIGN(se_stats_buf_size, VENUS_DMA_ALIGNMENT) * 2; \
  1379. } while (0)
  1380. #define SIZE_BSE_SLICE_CMD_BUF ((((8192 << 2) + 7) & (~7)) * 6)
  1381. #define SIZE_BSE_REG_BUF ((((512 << 3) + 7) & (~7)) * 4)
  1382. #define SIZE_VPP_REG_BUF ((((HFI_VENUS_VPPSG_MAX_REGISTERS << 3) +\
  1383. 31) & (~31)) * 10)
  1384. #define SIZE_LAMBDA_LUT (256 * 11)
  1385. #define SIZE_OVERRIDE_BUF(num_lcumb) (HFI_ALIGN(((16 * (((num_lcumb) + 7)\
  1386. >> 3))), VENUS_DMA_ALIGNMENT) * 2)
  1387. #define SIZE_IR_BUF(num_lcu_in_frame) HFI_ALIGN((((((num_lcu_in_frame) << 1) + 7) &\
  1388. (~7)) * 3), VENUS_DMA_ALIGNMENT)
  1389. #define SIZE_VPSS_LINE_BUF(num_vpp_pipes_enc, frame_height_coded, \
  1390. frame_width_coded) \
  1391. (HFI_ALIGN(((((((8192) >> 2) << 5) * (num_vpp_pipes_enc)) + 64) + \
  1392. (((((MAX((frame_width_coded), (frame_height_coded)) + 3) >> 2) << 5) +\
  1393. 256) * 16)), VENUS_DMA_ALIGNMENT))
  1394. #define SIZE_TOP_LINE_BUF_FIRST_STG_SAO(frame_width_coded) \
  1395. HFI_ALIGN((16 * ((frame_width_coded) >> 5)), VENUS_DMA_ALIGNMENT)
  1396. #define HFI_BUFFER_LINE_ENC(_size, frame_width, frame_height, is_ten_bit, \
  1397. num_vpp_pipes_enc, lcu_size, standard) \
  1398. do \
  1399. { \
  1400. HFI_U32 width_in_lcus = 0, height_in_lcus = 0, \
  1401. frame_width_coded = 0, frame_height_coded = 0; \
  1402. HFI_U32 line_buff_data_size = 0, left_line_buff_ctrl_size = 0, \
  1403. left_line_buff_recon_pix_size = 0, \
  1404. top_line_buff_ctrl_fe_size = 0; \
  1405. HFI_U32 left_line_buff_metadata_recon__y__size = 0, \
  1406. left_line_buff_metadata_recon__uv__size = 0, \
  1407. line_buff_recon_pix_size = 0; \
  1408. width_in_lcus = ((frame_width) + (lcu_size)-1) / (lcu_size); \
  1409. height_in_lcus = ((frame_height) + (lcu_size)-1) / (lcu_size); \
  1410. frame_width_coded = width_in_lcus * (lcu_size); \
  1411. frame_height_coded = height_in_lcus * (lcu_size); \
  1412. SIZE_LINEBUFF_DATA(line_buff_data_size, is_ten_bit, \
  1413. frame_width_coded);\
  1414. SIZE_LEFT_LINEBUFF_CTRL(left_line_buff_ctrl_size, standard, \
  1415. frame_height_coded, num_vpp_pipes_enc); \
  1416. SIZE_LEFT_LINEBUFF_RECON_PIX(left_line_buff_recon_pix_size, \
  1417. is_ten_bit, frame_height_coded, num_vpp_pipes_enc); \
  1418. SIZE_TOP_LINEBUFF_CTRL_FE(top_line_buff_ctrl_fe_size, \
  1419. frame_width_coded, standard); \
  1420. SIZE_LEFT_LINEBUFF_METADATA_RECON_Y\
  1421. (left_line_buff_metadata_recon__y__size, \
  1422. frame_height_coded, is_ten_bit, num_vpp_pipes_enc); \
  1423. SIZE_LEFT_LINEBUFF_METADATA_RECON_UV\
  1424. (left_line_buff_metadata_recon__uv__size, \
  1425. frame_height_coded, is_ten_bit, num_vpp_pipes_enc); \
  1426. SIZE_LINEBUFF_RECON_PIX(line_buff_recon_pix_size, is_ten_bit,\
  1427. frame_width_coded); \
  1428. _size = SIZE_LINE_BUF_CTRL(frame_width_coded) + \
  1429. SIZE_LINE_BUF_CTRL_ID2(frame_width_coded) + \
  1430. line_buff_data_size + \
  1431. left_line_buff_ctrl_size + \
  1432. left_line_buff_recon_pix_size + \
  1433. top_line_buff_ctrl_fe_size + \
  1434. left_line_buff_metadata_recon__y__size + \
  1435. left_line_buff_metadata_recon__uv__size + \
  1436. line_buff_recon_pix_size + \
  1437. SIZE_LEFT_LINEBUFF_CTRL_FE(frame_height_coded, \
  1438. num_vpp_pipes_enc) + SIZE_LINE_BUF_SDE(frame_width_coded) + \
  1439. SIZE_VPSS_LINE_BUF(num_vpp_pipes_enc, frame_height_coded, \
  1440. frame_width_coded) + \
  1441. SIZE_TOP_LINE_BUF_FIRST_STG_SAO(frame_width_coded); \
  1442. } while (0)
  1443. #define HFI_BUFFER_LINE_H264E(_size, frame_width, frame_height, is_ten_bit, \
  1444. num_vpp_pipes) \
  1445. do \
  1446. { \
  1447. HFI_BUFFER_LINE_ENC(_size, frame_width, frame_height, 0, \
  1448. num_vpp_pipes, 16, HFI_CODEC_ENCODE_AVC); \
  1449. } while (0)
  1450. #define HFI_BUFFER_LINE_H265E(_size, frame_width, frame_height, is_ten_bit, \
  1451. num_vpp_pipes) \
  1452. do \
  1453. { \
  1454. HFI_BUFFER_LINE_ENC(_size, frame_width, frame_height, \
  1455. is_ten_bit, num_vpp_pipes, 32, HFI_CODEC_ENCODE_HEVC); \
  1456. } while (0)
  1457. #define HFI_BUFFER_COMV_ENC(_size, frame_width, frame_height, lcu_size, \
  1458. num_ref, standard) \
  1459. do \
  1460. { \
  1461. HFI_U32 size_colloc_mv = 0, size_colloc_rc = 0; \
  1462. HFI_U32 mb_width = ((frame_width) + 15) >> 4; \
  1463. HFI_U32 mb_height = ((frame_height) + 15) >> 4; \
  1464. HFI_U32 width_in_lcus = ((frame_width) + (lcu_size)-1) /\
  1465. (lcu_size); \
  1466. HFI_U32 height_in_lcus = ((frame_height) + (lcu_size)-1) / \
  1467. (lcu_size); \
  1468. HFI_U32 num_lcu_in_frame = width_in_lcus * height_in_lcus; \
  1469. size_colloc_mv = (standard == HFI_CODEC_ENCODE_HEVC) ? \
  1470. (16 * ((num_lcu_in_frame << 2) + BUFFER_ALIGNMENT_32_BYTES)) : \
  1471. (3 * 16 * (width_in_lcus * height_in_lcus +\
  1472. BUFFER_ALIGNMENT_32_BYTES)); \
  1473. size_colloc_mv = HFI_ALIGN(size_colloc_mv, \
  1474. VENUS_DMA_ALIGNMENT) * (num_ref + 1); \
  1475. size_colloc_rc = (((mb_width + 7) >> 3) * 16 * 2 * mb_height); \
  1476. size_colloc_rc = HFI_ALIGN(size_colloc_rc, \
  1477. VENUS_DMA_ALIGNMENT) * HFI_MAX_COL_FRAME; \
  1478. _size = size_colloc_mv + size_colloc_rc; \
  1479. } while (0)
  1480. #define HFI_BUFFER_COMV_H264E(_size, frame_width, frame_height, num_ref) \
  1481. do \
  1482. { \
  1483. HFI_BUFFER_COMV_ENC(_size, frame_width, frame_height, 16, \
  1484. num_ref, HFI_CODEC_ENCODE_AVC); \
  1485. } while (0)
  1486. #define HFI_BUFFER_COMV_H265E(_size, frame_width, frame_height, num_ref) \
  1487. do \
  1488. { \
  1489. HFI_BUFFER_COMV_ENC(_size, frame_width, frame_height, 32,\
  1490. num_ref, HFI_CODEC_ENCODE_HEVC); \
  1491. } while (0)
  1492. #define HFI_BUFFER_NON_COMV_ENC(_size, frame_width, frame_height, \
  1493. num_vpp_pipes_enc, lcu_size, standard) \
  1494. do \
  1495. { \
  1496. HFI_U32 width_in_lcus = 0, height_in_lcus = 0, \
  1497. frame_width_coded = 0, frame_height_coded = 0, \
  1498. num_lcu_in_frame = 0, num_lcumb = 0; \
  1499. HFI_U32 frame_rc_buf_size = 0, \
  1500. se_stats_buf_size = 0; \
  1501. width_in_lcus = ((frame_width) + (lcu_size)-1) / (lcu_size); \
  1502. height_in_lcus = ((frame_height) + (lcu_size)-1) / (lcu_size); \
  1503. num_lcu_in_frame = width_in_lcus * height_in_lcus; \
  1504. frame_width_coded = width_in_lcus * (lcu_size); \
  1505. frame_height_coded = height_in_lcus * (lcu_size); \
  1506. num_lcumb = (frame_height_coded / lcu_size) * \
  1507. ((frame_width_coded + lcu_size * 8) / lcu_size); \
  1508. SIZE_FRAME_RC_BUF_SIZE(frame_rc_buf_size, standard, \
  1509. frame_height_coded, num_vpp_pipes_enc); \
  1510. SIZE_SE_STATS_BUF(se_stats_buf_size, frame_width_coded, \
  1511. frame_height_coded, num_lcu_in_frame); \
  1512. _size = SIZE_ENC_SLICE_INFO_BUF(num_lcu_in_frame) + \
  1513. SIZE_SLICE_CMD_BUFFER + \
  1514. SIZE_SPS_PPS_SLICE_HDR + \
  1515. frame_rc_buf_size + \
  1516. ENC_BITCNT_BUF_SIZE(num_lcu_in_frame) + \
  1517. ENC_BITMAP_BUF_SIZE(num_lcu_in_frame) + \
  1518. se_stats_buf_size + \
  1519. SIZE_BSE_SLICE_CMD_BUF + \
  1520. SIZE_BSE_REG_BUF + \
  1521. SIZE_VPP_REG_BUF + \
  1522. SIZE_LAMBDA_LUT + \
  1523. SIZE_OVERRIDE_BUF(num_lcumb) + \
  1524. SIZE_IR_BUF(num_lcu_in_frame); \
  1525. } while (0)
  1526. #define HFI_BUFFER_NON_COMV_H264E(_size, frame_width, frame_height, \
  1527. num_vpp_pipes_enc) \
  1528. do \
  1529. { \
  1530. HFI_BUFFER_NON_COMV_ENC(_size, frame_width, frame_height, \
  1531. num_vpp_pipes_enc, 16, HFI_CODEC_ENCODE_AVC); \
  1532. } while (0)
  1533. #define HFI_BUFFER_NON_COMV_H265E(_size, frame_width, frame_height, \
  1534. num_vpp_pipes_enc) \
  1535. do \
  1536. { \
  1537. HFI_BUFFER_NON_COMV_ENC(_size, frame_width, frame_height, \
  1538. num_vpp_pipes_enc, 32, HFI_CODEC_ENCODE_HEVC); \
  1539. } while (0)
  1540. #define SIZE_ENC_REF_BUFFER(size, frame_width, frame_height) \
  1541. do \
  1542. { \
  1543. HFI_U32 u_buffer_width = 0, u_buffer_height = 0, \
  1544. u_chroma_buffer_height = 0; \
  1545. u_buffer_height = HFI_ALIGN(frame_height, \
  1546. HFI_VENUS_HEIGHT_ALIGNMENT); \
  1547. u_chroma_buffer_height = frame_height >> 1; \
  1548. u_chroma_buffer_height = HFI_ALIGN(u_chroma_buffer_height, \
  1549. HFI_VENUS_HEIGHT_ALIGNMENT); \
  1550. u_buffer_width = HFI_ALIGN(frame_width, \
  1551. HFI_VENUS_WIDTH_ALIGNMENT); \
  1552. size = (u_buffer_height + u_chroma_buffer_height) * \
  1553. u_buffer_width; \
  1554. } while (0)
  1555. #define SIZE_ENC_TEN_BIT_REF_BUFFER(size, frame_width, frame_height) \
  1556. do \
  1557. { \
  1558. HFI_U32 ref_buf_height = 0, ref_luma_stride_in_bytes = 0, \
  1559. u_ref_stride = 0, luma_size = 0, ref_chrm_height_in_bytes = 0, \
  1560. chroma_size = 0, ref_buf_size = 0; \
  1561. ref_buf_height = (frame_height + \
  1562. (HFI_VENUS_HEIGHT_ALIGNMENT - 1)) \
  1563. & (~(HFI_VENUS_HEIGHT_ALIGNMENT - 1)); \
  1564. ref_luma_stride_in_bytes = ((frame_width + \
  1565. SYSTEM_LAL_TILE10 - 1) / SYSTEM_LAL_TILE10) * \
  1566. SYSTEM_LAL_TILE10; \
  1567. u_ref_stride = 4 * (ref_luma_stride_in_bytes / 3); \
  1568. u_ref_stride = (u_ref_stride + (BUF_SIZE_ALIGN_128 - 1)) &\
  1569. (~(BUF_SIZE_ALIGN_128 - 1)); \
  1570. luma_size = ref_buf_height * u_ref_stride; \
  1571. ref_chrm_height_in_bytes = (((frame_height + 1) >> 1) + \
  1572. (BUF_SIZE_ALIGN_32 - 1)) & (~(BUF_SIZE_ALIGN_32 - 1)); \
  1573. chroma_size = u_ref_stride * ref_chrm_height_in_bytes; \
  1574. luma_size = (luma_size + (BUF_SIZE_ALIGN_4096 - 1)) & \
  1575. (~(BUF_SIZE_ALIGN_4096 - 1)); \
  1576. chroma_size = (chroma_size + (BUF_SIZE_ALIGN_4096 - 1)) & \
  1577. (~(BUF_SIZE_ALIGN_4096 - 1)); \
  1578. ref_buf_size = luma_size + chroma_size; \
  1579. size = ref_buf_size; \
  1580. } while (0)
  1581. /*
  1582. * Encoder Scratch2 Buffer definition
  1583. */
  1584. #define HFI_BUFFER_DPB_ENC(_size, frame_width, frame_height, is_ten_bit) \
  1585. do \
  1586. { \
  1587. HFI_U32 metadata_stride, metadata_buf_height, meta_size_y, \
  1588. meta_size_c; \
  1589. HFI_U32 ten_bit_ref_buf_size = 0, ref_buf_size = 0; \
  1590. if (!is_ten_bit) \
  1591. { \
  1592. SIZE_ENC_REF_BUFFER(ref_buf_size, frame_width, \
  1593. frame_height); \
  1594. HFI_UBWC_CALC_METADATA_PLANE_STRIDE(metadata_stride, \
  1595. (frame_width), 64, \
  1596. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_WIDTH); \
  1597. HFI_UBWC_METADATA_PLANE_BUFHEIGHT(metadata_buf_height, \
  1598. (frame_height), 16, \
  1599. HFI_COLOR_FORMAT_YUV420_NV12_UBWC_Y_TILE_HEIGHT); \
  1600. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(meta_size_y, \
  1601. metadata_stride, metadata_buf_height); \
  1602. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(meta_size_c, \
  1603. metadata_stride, metadata_buf_height); \
  1604. _size = ref_buf_size + meta_size_y + meta_size_c; \
  1605. } \
  1606. else \
  1607. { \
  1608. SIZE_ENC_TEN_BIT_REF_BUFFER(ten_bit_ref_buf_size, \
  1609. frame_width, frame_height); \
  1610. HFI_UBWC_CALC_METADATA_PLANE_STRIDE(metadata_stride, \
  1611. frame_width, VENUS_METADATA_STRIDE_MULTIPLE, \
  1612. HFI_COLOR_FORMAT_YUV420_TP10_UBWC_Y_TILE_WIDTH); \
  1613. HFI_UBWC_METADATA_PLANE_BUFHEIGHT(metadata_buf_height, \
  1614. frame_height, VENUS_METADATA_HEIGHT_MULTIPLE, \
  1615. HFI_COLOR_FORMAT_YUV420_TP10_UBWC_Y_TILE_HEIGHT); \
  1616. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(meta_size_y, \
  1617. metadata_stride, metadata_buf_height); \
  1618. HFI_UBWC_METADATA_PLANE_BUFFER_SIZE(meta_size_c, \
  1619. metadata_stride, metadata_buf_height); \
  1620. _size = ten_bit_ref_buf_size + meta_size_y + \
  1621. meta_size_c; \
  1622. } \
  1623. } while (0)
  1624. #define HFI_BUFFER_DPB_H264E(_size, frame_width, frame_height) \
  1625. do \
  1626. { \
  1627. HFI_BUFFER_DPB_ENC(_size, frame_width, frame_height, 0); \
  1628. } while (0)
  1629. #define HFI_BUFFER_DPB_H265E(_size, frame_width, frame_height, is_ten_bit) \
  1630. do \
  1631. { \
  1632. HFI_BUFFER_DPB_ENC(_size, frame_width, frame_height, is_ten_bit); \
  1633. } while (0)
  1634. #define HFI_BUFFER_VPSS_ENC(vpss_size, frame_width, frame_height, ds_enable, \
  1635. rot_enable, flip_enable, is_ten_bit) \
  1636. do \
  1637. { \
  1638. HFI_U32 vpss_size = 0; \
  1639. if (ds_enable) \
  1640. { \
  1641. if (rot_enable) \
  1642. { \
  1643. HFI_BUFFER_DPB_ENC(vpss_size, frame_height, \
  1644. frame_width, is_ten_bit); \
  1645. } \
  1646. else if (flip_enable) \
  1647. { \
  1648. HFI_BUFFER_DPB_ENC(vpss_size, frame_width, \
  1649. frame_height, is_ten_bit); \
  1650. } \
  1651. else \
  1652. { \
  1653. vpss_size = 0; \
  1654. } \
  1655. vpss_size = vpss_size; \
  1656. } \
  1657. else \
  1658. { \
  1659. vpss_size = vpss_size; \
  1660. } \
  1661. } while (0)
  1662. /* End of IRIS2 */
  1663. #endif /* __HFI_BUFFER_IRIS2__ */