hfi_buffer_iris3.h 68 KB

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