hfi_buffer_iris2.h 64 KB

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