| 1 | /* |
| 2 | * Copyright (c) 2019, Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included |
| 12 | * in all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | */ |
| 22 | //! |
| 23 | //! \file vphal_render_hdr_g11.cpp |
| 24 | //! \brief Common interface and structure used in HDR for GEN11 |
| 25 | //! \details Common interface and structure used in HDR for GEN11 Fixed Function Vebox 3DLut |
| 26 | //! |
| 27 | #if !EMUL |
| 28 | |
| 29 | #include "vphal_render_hdr_3dlut_g12.h" |
| 30 | #include "renderhal.h" |
| 31 | #include "mos_interface.h" |
| 32 | |
| 33 | static const std::string DumpRoot("C:\\temp\\"); |
| 34 | static const std::string OutputDumpDirectory(DumpRoot + "Output\\"); |
| 35 | static const std::string Hdr3DLutKernelName("hdr_3dlut"); |
| 36 | |
| 37 | static const bool enableDump = false; |
| 38 | static const int32_t lutWidth = 65*2; |
| 39 | static const int32_t lutHeight = 65 * 128; |
| 40 | static const int32_t lutSize = 65; |
| 41 | |
| 42 | static const float ccm_identity[12] = { 1.0f, 0.0f, 0.0f, 0.0f, |
| 43 | 0.0f, 1.0f, 0.0f, 0.0f, |
| 44 | 0.0f, 0.0f, 1.0f, 0.0f }; |
| 45 | |
| 46 | static float color_matrix_calculation[3][4] = {0.0f}; |
| 47 | |
| 48 | template <typename T>void mat_3by3_inv(T *m1, T *m2) |
| 49 | { |
| 50 | double a11, a12, a13, a21, a22, a23, a31, a32, a33; |
| 51 | double det, det_inv; |
| 52 | |
| 53 | a11 = *m1; |
| 54 | a12 = *(m1 + 1); |
| 55 | a13 = *(m1 + 2); |
| 56 | a21 = *(m1 + 3); |
| 57 | a22 = *(m1 + 4); |
| 58 | a23 = *(m1 + 5); |
| 59 | a31 = *(m1 + 6); |
| 60 | a32 = *(m1 + 7); |
| 61 | a33 = *(m1 + 8); |
| 62 | |
| 63 | det = a11 * (a33*a22 - a32 * a23) - a21 * (a33*a12 - a32 * a13) + a31 * (a12*a23 - a13 * a22); |
| 64 | |
| 65 | det_inv = 1 / det; |
| 66 | |
| 67 | *m2 = (float)(det_inv*(a33*a22 - a32 * a23)); |
| 68 | *(m2 + 1) = (float)(-det_inv * (a33*a12 - a32 * a13)); |
| 69 | *(m2 + 2) = (float)(det_inv*(a12*a23 - a13 * a22)); |
| 70 | *(m2 + 3) = (float)(-det_inv * (a33*a21 - a31 * a23)); |
| 71 | *(m2 + 4) = (float)(det_inv*(a33*a11 - a31 * a13)); |
| 72 | *(m2 + 5) = (float)(-det_inv * (a23*a11 - a21 * a13)); |
| 73 | *(m2 + 6) = (float)(det_inv*(a32*a21 - a31 * a22)); |
| 74 | *(m2 + 7) = (float)(-det_inv * (a32*a11 - a31 * a12)); |
| 75 | *(m2 + 8) = (float)(det_inv*(a22*a11 - a21 * a12)); |
| 76 | } |
| 77 | |
| 78 | template <typename T>void mat_mul_float(T *m1, T *m2, T *m3, short m_size, short n_size, short l_size) |
| 79 | { |
| 80 | int i, j, k, Tjn, Tjl, off3; |
| 81 | float *m1_offs, *m2_offs, *m2_k_offs, *m3_offs; |
| 82 | |
| 83 | for (j = 0; j < m_size; j++) |
| 84 | { |
| 85 | Tjn = j * n_size; |
| 86 | Tjl = j * l_size; |
| 87 | for (k = 0; k < l_size; k++) |
| 88 | { |
| 89 | off3 = Tjl + k; |
| 90 | m3_offs = m3 + off3; |
| 91 | *m3_offs = 0; |
| 92 | m2_k_offs = m2 + k; |
| 93 | m1_offs = m1 + Tjn; |
| 94 | for (i = 0; i < n_size; i++) |
| 95 | { |
| 96 | m2_offs = m2_k_offs + i * l_size; |
| 97 | *m3_offs += *m1_offs * *m2_offs; |
| 98 | m1_offs++; |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | static void CalcCCMMatrix() |
| 105 | { |
| 106 | float mat_rgb2xyz_src[3][3] = {}, mat_rgb2xyz_dst[3][3] = {}; |
| 107 | float mat_xyz[3][3] = {}, mat_invxyz[3][3] = {}; |
| 108 | float matW[3] = {}, matE[3] = {}; |
| 109 | |
| 110 | float fccmSrcZR, fccmSrcZG, fccmSrcZB, fccmSrcZW; |
| 111 | float fccmDstZR, fccmDstZG, fccmDstZB, fccmDstZW; |
| 112 | |
| 113 | const float fccmSrcXR = 0.708000000000000f; |
| 114 | const float fccmSrcYR = 0.292000000000000f; |
| 115 | const float fccmSrcXG = 0.170000000000000f; |
| 116 | const float fccmSrcYG = 0.797000000000000f; |
| 117 | const float fccmSrcXB = 0.131000000000000f; |
| 118 | const float fccmSrcYB = 0.046000000000000f; |
| 119 | const float fccmSrcXW = 0.312700000000000f; |
| 120 | const float fccmSrcYW = 0.329000000000000f; |
| 121 | const float fccmDstXR = 0.640000000000000f; |
| 122 | const float fccmDstYR = 0.330000000000000f; |
| 123 | const float fccmDstXG = 0.300000000000000f; |
| 124 | const float fccmDstYG = 0.600000000000000f; |
| 125 | const float fccmDstXB = 0.150000000000000f; |
| 126 | const float fccmDstYB = 0.060000000000000f; |
| 127 | const float fccmDstXW = 0.312700000000000f; |
| 128 | const float FccmDstYW = 0.329000000000000f; |
| 129 | |
| 130 | fccmSrcZR = 1 - fccmSrcXR - fccmSrcYR; |
| 131 | fccmSrcZG = 1 - fccmSrcXG - fccmSrcYG; |
| 132 | fccmSrcZB = 1 - fccmSrcXB - fccmSrcYB; |
| 133 | fccmSrcZW = 1 - fccmSrcXW - fccmSrcYW; |
| 134 | |
| 135 | mat_xyz[0][0] = fccmSrcXR; |
| 136 | mat_xyz[0][1] = fccmSrcXG; |
| 137 | mat_xyz[0][2] = fccmSrcXB; |
| 138 | mat_xyz[1][0] = fccmSrcYR; |
| 139 | mat_xyz[1][1] = fccmSrcYG; |
| 140 | mat_xyz[1][2] = fccmSrcYB; |
| 141 | mat_xyz[2][0] = fccmSrcZR; |
| 142 | mat_xyz[2][1] = fccmSrcZG; |
| 143 | mat_xyz[2][2] = fccmSrcZB; |
| 144 | |
| 145 | mat_3by3_inv(mat_xyz[0], mat_invxyz[0]); |
| 146 | |
| 147 | matW[0] = fccmSrcXW / fccmSrcYW; |
| 148 | matW[1] = 1; |
| 149 | matW[2] = fccmSrcZW / fccmSrcYW; |
| 150 | |
| 151 | mat_mul_float(mat_invxyz[0], matW, matE, 3, 3, 1); |
| 152 | |
| 153 | mat_rgb2xyz_src[0][0] = matE[0] * fccmSrcXR; |
| 154 | mat_rgb2xyz_src[1][0] = matE[0] * fccmSrcYR; |
| 155 | mat_rgb2xyz_src[2][0] = matE[0] * fccmSrcZR; |
| 156 | mat_rgb2xyz_src[0][1] = matE[1] * fccmSrcXG; |
| 157 | mat_rgb2xyz_src[1][1] = matE[1] * fccmSrcYG; |
| 158 | mat_rgb2xyz_src[2][1] = matE[1] * fccmSrcZG; |
| 159 | mat_rgb2xyz_src[0][2] = matE[2] * fccmSrcXB; |
| 160 | mat_rgb2xyz_src[1][2] = matE[2] * fccmSrcYB; |
| 161 | mat_rgb2xyz_src[2][2] = matE[2] * fccmSrcZB; |
| 162 | |
| 163 | fccmDstZR = 1 - fccmDstXR - fccmDstYR; |
| 164 | fccmDstZG = 1 - fccmDstXG - fccmDstYG; |
| 165 | fccmDstZB = 1 - fccmDstXB - fccmDstYB; |
| 166 | fccmDstZW = 1 - fccmDstXW - FccmDstYW; |
| 167 | |
| 168 | mat_xyz[0][0] = fccmDstXR; |
| 169 | mat_xyz[0][1] = fccmDstXG; |
| 170 | mat_xyz[0][2] = fccmDstXB; |
| 171 | mat_xyz[1][0] = fccmDstYR; |
| 172 | mat_xyz[1][1] = fccmDstYG; |
| 173 | mat_xyz[1][2] = fccmDstYB; |
| 174 | mat_xyz[2][0] = fccmDstZR; |
| 175 | mat_xyz[2][1] = fccmDstZG; |
| 176 | mat_xyz[2][2] = fccmDstZB; |
| 177 | |
| 178 | mat_3by3_inv(mat_xyz[0], mat_invxyz[0]); |
| 179 | |
| 180 | matW[0] = fccmDstXW / FccmDstYW; |
| 181 | matW[1] = 1; |
| 182 | matW[2] = fccmDstZW / FccmDstYW; |
| 183 | |
| 184 | mat_mul_float(mat_invxyz[0], matW, matE, 3, 3, 1); |
| 185 | |
| 186 | mat_rgb2xyz_dst[0][0] = matE[0] * fccmDstXR; |
| 187 | mat_rgb2xyz_dst[1][0] = matE[0] * fccmDstYR; |
| 188 | mat_rgb2xyz_dst[2][0] = matE[0] * fccmDstZR; |
| 189 | mat_rgb2xyz_dst[0][1] = matE[1] * fccmDstXG; |
| 190 | mat_rgb2xyz_dst[1][1] = matE[1] * fccmDstYG; |
| 191 | mat_rgb2xyz_dst[2][1] = matE[1] * fccmDstZG; |
| 192 | mat_rgb2xyz_dst[0][2] = matE[2] * fccmDstXB; |
| 193 | mat_rgb2xyz_dst[1][2] = matE[2] * fccmDstYB; |
| 194 | mat_rgb2xyz_dst[2][2] = matE[2] * fccmDstZB; |
| 195 | |
| 196 | float mat_invrgb2xyz_dst[3][3]; |
| 197 | mat_3by3_inv(mat_rgb2xyz_dst[0], mat_invrgb2xyz_dst[0]); |
| 198 | |
| 199 | float CCMmat[3][3]; |
| 200 | mat_mul_float(mat_invrgb2xyz_dst[0], mat_rgb2xyz_src[0], CCMmat[0], 3, 3, 3); |
| 201 | |
| 202 | color_matrix_calculation[0][0] = CCMmat[0][0]; |
| 203 | color_matrix_calculation[0][1] = CCMmat[0][1]; |
| 204 | color_matrix_calculation[0][2] = CCMmat[0][2]; |
| 205 | color_matrix_calculation[0][3] = 0.0f; |
| 206 | color_matrix_calculation[1][0] = CCMmat[1][0]; |
| 207 | color_matrix_calculation[1][1] = CCMmat[1][1]; |
| 208 | color_matrix_calculation[1][2] = CCMmat[1][2]; |
| 209 | color_matrix_calculation[1][3] = 0.0f; |
| 210 | color_matrix_calculation[2][0] = CCMmat[2][0]; |
| 211 | color_matrix_calculation[2][1] = CCMmat[2][1]; |
| 212 | color_matrix_calculation[2][2] = CCMmat[2][2]; |
| 213 | color_matrix_calculation[2][3] = 0.0f; |
| 214 | } |
| 215 | |
| 216 | Hdr3DLutCmRenderG12::Hdr3DLutCmRenderG12(uint32_t *kernelBinary, uint32_t kernelSize, CmContext *cmContext) : |
| 217 | VPCmRenderer("Hdr3DLutCmRenderG12", cmContext), |
| 218 | m_cmProgram(nullptr), |
| 219 | m_cmKernel(nullptr), |
| 220 | m_cmPayload(nullptr) |
| 221 | { |
| 222 | m_cmProgram = LoadProgram(kernelBinary, kernelSize); |
| 223 | |
| 224 | VPHAL_RENDER_CHK_NULL_NO_STATUS_RETURN(cmContext); |
| 225 | if (!m_cmProgram) |
| 226 | { |
| 227 | VPHAL_RENDER_ASSERTMESSAGE("Hdr3DLutCmRenderG12 [%s]: CM LoadProgram error %d\n"); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | CmDevice *dev = cmContext->GetCmDevice(); |
| 232 | int result = dev->CreateKernel(m_cmProgram, _NAME(hdr_3dlut), m_cmKernel); |
| 233 | if (result != CM_SUCCESS) |
| 234 | { |
| 235 | VPHAL_RENDER_ASSERTMESSAGE("Hdr3DLutCmRenderG12 [%s]: CM CreateKernel error %d\n", mName.c_str(), result); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | Hdr3DLutCmRenderG12::~Hdr3DLutCmRenderG12() |
| 240 | { |
| 241 | VPHAL_RENDER_CHK_NULL_NO_STATUS_RETURN(m_cmContext); |
| 242 | CmDevice *dev = m_cmContext->GetCmDevice(); |
| 243 | if (m_cmKernel) |
| 244 | { |
| 245 | dev->DestroyKernel(m_cmKernel); |
| 246 | } |
| 247 | |
| 248 | if (m_cmProgram) |
| 249 | { |
| 250 | dev->DestroyProgram(m_cmProgram); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | void Hdr3DLutCmRenderG12::AttachPayload(void *payload) |
| 255 | { |
| 256 | m_cmPayload = static_cast<Hdr3DLutPayload *>(payload); |
| 257 | } |
| 258 | |
| 259 | CmKernel* Hdr3DLutCmRenderG12::GetKernelToRun(std::string &name) |
| 260 | { |
| 261 | name = Hdr3DLutKernelName; |
| 262 | return m_cmKernel; |
| 263 | } |
| 264 | |
| 265 | void Hdr3DLutCmRenderG12::GetThreadSpaceDimension(int &tsWidth, int &tsHeight, int &tsColor) |
| 266 | { |
| 267 | #define BLOCK_WIDTH 16 |
| 268 | #define BLOCK_HEIGHT 8 |
| 269 | |
| 270 | tsWidth = 65; |
| 271 | tsHeight = 65; |
| 272 | tsColor = 1; |
| 273 | } |
| 274 | |
| 275 | void Hdr3DLutCmRenderG12::PrepareKernel(CmKernel *kernel) |
| 276 | { |
| 277 | kernel->SetKernelArg(0, sizeof(SurfaceIndex), m_cmPayload->hdr3DLutSurface->GetCmSurfaceIndex()); |
| 278 | kernel->SetKernelArg(1, sizeof(SurfaceIndex), m_cmPayload->hdrCoefSurface->GetCmSurfaceIndex()); |
| 279 | kernel->SetKernelArg(2, sizeof(uint16_t), &m_cmPayload->hdr3DLutSurfaceWidth); |
| 280 | kernel->SetKernelArg(3, sizeof(uint16_t), &m_cmPayload->hdr3DLutSurfaceHeight); |
| 281 | } |
| 282 | |
| 283 | Hdr3DLutGeneratorG12::Hdr3DLutGeneratorG12(PRENDERHAL_INTERFACE renderHal, uint32_t *kernelBinary, uint32_t kernelSize) : |
| 284 | m_renderHal(renderHal), |
| 285 | m_hdr3DLutSurface(nullptr), |
| 286 | m_hdrCoefSurface(nullptr), |
| 287 | m_hdr3DLutCmRender(nullptr), |
| 288 | m_hdrcoefBuffer(nullptr), |
| 289 | m_bHdr3DLutInit(false), |
| 290 | m_savedMaxDLL(1000), |
| 291 | m_savedMaxCLL(4000), |
| 292 | m_savedHdrMode(VPHAL_HDR_MODE_NONE) |
| 293 | { |
| 294 | VPHAL_RENDER_CHK_NULL_NO_STATUS_RETURN(m_renderHal); |
| 295 | VPHAL_RENDER_CHK_NULL_NO_STATUS_RETURN(m_renderHal->pOsInterface); |
| 296 | m_cmContext = MOS_New(CmContext, m_renderHal->pOsInterface); |
| 297 | |
| 298 | VPHAL_RENDER_NORMALMESSAGE("Hdr3DLutGeneratorG12 Constructor!"); |
| 299 | |
| 300 | m_kernelBinary = kernelBinary; |
| 301 | m_kernelSize = kernelSize; |
| 302 | } |
| 303 | |
| 304 | Hdr3DLutGeneratorG12::~Hdr3DLutGeneratorG12() |
| 305 | { |
| 306 | FreeResources(); |
| 307 | |
| 308 | MOS_Delete(m_hdr3DLutCmRender); |
| 309 | |
| 310 | MOS_Delete(m_eventManager); |
| 311 | |
| 312 | MOS_Delete(m_cmContext); |
| 313 | |
| 314 | VPHAL_RENDER_NORMALMESSAGE("Hdr3DLutGeneratorG12 Destructor!"); |
| 315 | } |
| 316 | |
| 317 | void Hdr3DLutGeneratorG12::AllocateResources() |
| 318 | { |
| 319 | const int32_t coefWidth = 8; |
| 320 | const int32_t coefHeight = 8; |
| 321 | const int32_t lutWidth = 65*2; |
| 322 | const int32_t lutHeight = 65 * 128; |
| 323 | |
| 324 | // Allocate Coefficient Surface in GPU memory |
| 325 | m_hdrCoefSurface = MOS_New(VpCmSurfaceHolder<CmSurface2D>, coefWidth, coefHeight, 1, GMM_FORMAT_B8G8R8A8_UNORM_TYPE, m_cmContext); |
| 326 | // Allocate Coefficient Surface in CPU memory |
| 327 | m_hdrcoefBuffer = MOS_NewArray(float, coefWidth * coefHeight); |
| 328 | |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | bool Hdr3DLutGeneratorG12::IsObjectVaild() |
| 333 | { |
| 334 | if (!m_cmContext) |
| 335 | { |
| 336 | return false; |
| 337 | } |
| 338 | if (!m_cmContext->GetCmDevice()) |
| 339 | { |
| 340 | return false; |
| 341 | } |
| 342 | if (!m_cmContext->GetCmQueue()) |
| 343 | { |
| 344 | return false; |
| 345 | } |
| 346 | if (!m_cmContext->GetCmVebox()) |
| 347 | { |
| 348 | return false; |
| 349 | } |
| 350 | return true; |
| 351 | } |
| 352 | |
| 353 | void Hdr3DLutGeneratorG12::FreeResources() |
| 354 | { |
| 355 | MOS_Delete(m_hdr3DLutSurface); |
| 356 | MOS_Delete(m_hdrCoefSurface); |
| 357 | MOS_DeleteArray(m_hdrcoefBuffer); |
| 358 | MOS_DeleteArray(m_hdr3DLutSysBuffer); |
| 359 | } |
| 360 | |
| 361 | void Hdr3DLutGeneratorG12::InitCoefSurface(const uint32_t maxDLL, const uint32_t maxCLL, const VPHAL_HDR_MODE hdrMode) |
| 362 | { |
| 363 | int32_t oetfCurve = 0, tmMode = 0, tmSrcType = 0; |
| 364 | float ccmMatrix[12] = { 0.0 }; |
| 365 | float tmMaxCLL = 0.0f, tmMaxDLL = 0.0f; |
| 366 | |
| 367 | tmMaxCLL = (float)maxCLL; |
| 368 | tmMaxDLL = (float)maxDLL; |
| 369 | |
| 370 | if (hdrMode == VPHAL_HDR_MODE_TONE_MAPPING) // H2S |
| 371 | { |
| 372 | CalcCCMMatrix(); |
| 373 | MOS_SecureMemcpy(ccmMatrix, sizeof(float) * 12, color_matrix_calculation, sizeof(float) * 12); |
| 374 | |
| 375 | if (maxDLL > 800) |
| 376 | { |
| 377 | tmMode = (TONE_MAPPING_MODE)TONE_MAPPING_MODE_H2E; |
| 378 | VPHAL_RENDER_NORMALMESSAGE("Change curve to H2E, maxDLL %d", maxDLL); |
| 379 | } |
| 380 | else |
| 381 | { |
| 382 | tmMode = (TONE_MAPPING_MODE)TONE_MAPPING_MODE_H2S; |
| 383 | } |
| 384 | oetfCurve = (OETF_CURVE_TYPE)OETF_SRGB; |
| 385 | tmSrcType = (TONE_MAPPING_SOURCE_TYPE)TONE_MAPPING_SOURCE_PSEUDO_Y_BT709; |
| 386 | } |
| 387 | else // H2H |
| 388 | { |
| 389 | MOS_SecureMemcpy(ccmMatrix, sizeof(float) * 12, ccm_identity, sizeof(float) * 12); |
| 390 | |
| 391 | tmMode = (TONE_MAPPING_MODE)TONE_MAPPING_MODE_H2H; |
| 392 | oetfCurve = (OETF_CURVE_TYPE)OETF_CURVE_HDR_2084; |
| 393 | tmSrcType = (TONE_MAPPING_SOURCE_TYPE)TONE_MAPPING_SOURCE_PSEUDO_Y_BT709; |
| 394 | } |
| 395 | |
| 396 | // Fill Coefficient Surface: Media kernel define the layout of coefficients. Please don't change it. |
| 397 | const uint32_t pos_coef[17] = { 7, 16, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 29, 54, 55, 62, 63 }; |
| 398 | |
| 399 | // OETF curve |
| 400 | ((int*)m_hdrcoefBuffer)[pos_coef[0]] = oetfCurve; |
| 401 | // CCM |
| 402 | m_hdrcoefBuffer[pos_coef[1]] = ccmMatrix[0]; |
| 403 | m_hdrcoefBuffer[pos_coef[2]] = ccmMatrix[1]; |
| 404 | m_hdrcoefBuffer[pos_coef[3]] = ccmMatrix[2]; |
| 405 | m_hdrcoefBuffer[pos_coef[4]] = ccmMatrix[3]; |
| 406 | m_hdrcoefBuffer[pos_coef[5]] = ccmMatrix[4]; |
| 407 | m_hdrcoefBuffer[pos_coef[6]] = ccmMatrix[5]; |
| 408 | m_hdrcoefBuffer[pos_coef[7]] = ccmMatrix[6]; |
| 409 | m_hdrcoefBuffer[pos_coef[8]] = ccmMatrix[7]; |
| 410 | m_hdrcoefBuffer[pos_coef[9]] = ccmMatrix[8]; |
| 411 | m_hdrcoefBuffer[pos_coef[10]] = ccmMatrix[9]; |
| 412 | m_hdrcoefBuffer[pos_coef[11]] = ccmMatrix[10]; |
| 413 | m_hdrcoefBuffer[pos_coef[12]] = ccmMatrix[11]; |
| 414 | // TM Source Type |
| 415 | ((int*)m_hdrcoefBuffer)[pos_coef[13]] = tmSrcType; |
| 416 | // TM Mode |
| 417 | ((int*)m_hdrcoefBuffer)[pos_coef[14]] = tmMode; |
| 418 | // Max CLL and DLL |
| 419 | m_hdrcoefBuffer[pos_coef[15]] = tmMaxCLL; |
| 420 | m_hdrcoefBuffer[pos_coef[16]] = tmMaxDLL; |
| 421 | } |
| 422 | |
| 423 | void Hdr3DLutGeneratorG12::Render(const uint32_t maxDLL, const uint32_t maxCLL, const VPHAL_HDR_MODE hdrMode, const PVPHAL_SURFACE p3DLutSurface) |
| 424 | { |
| 425 | MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 426 | PMOS_INTERFACE pOsInterface = nullptr; |
| 427 | |
| 428 | VPHAL_RENDER_CHK_NULL_NO_STATUS(m_renderHal); |
| 429 | VPHAL_RENDER_CHK_NULL_NO_STATUS(p3DLutSurface); |
| 430 | |
| 431 | pOsInterface = m_renderHal->pOsInterface; |
| 432 | VPHAL_RENDER_CHK_NULL_NO_STATUS(pOsInterface); |
| 433 | |
| 434 | if (nullptr == m_hdr3DLutCmRender) |
| 435 | { |
| 436 | m_eventManager = MOS_New(EventManager, "EventManager", m_cmContext); |
| 437 | VPHAL_RENDER_CHK_NULL_NO_STATUS(m_cmContext); |
| 438 | |
| 439 | m_hdr3DLutCmRender = MOS_New(Hdr3DLutCmRenderG12, m_kernelBinary, m_kernelSize, m_cmContext); |
| 440 | AllocateResources(); |
| 441 | |
| 442 | VPHAL_RENDER_NORMALMESSAGE("Hdr3DLutGeneratorG12 Init Hdr3DLutCmRenderG12 and Allocate Necessary Resources!"); |
| 443 | } |
| 444 | |
| 445 | if (maxCLL != m_savedMaxCLL || maxDLL != m_savedMaxDLL || hdrMode != m_savedHdrMode) |
| 446 | { |
| 447 | m_savedMaxCLL = maxCLL; |
| 448 | m_savedMaxDLL = maxDLL; |
| 449 | m_savedHdrMode = hdrMode; |
| 450 | |
| 451 | InitCoefSurface(maxDLL, maxCLL, hdrMode); |
| 452 | m_hdrCoefSurface->GetCmSurface()->WriteSurface((uint8_t*)m_hdrcoefBuffer, nullptr); |
| 453 | |
| 454 | Hdr3DLutCmRenderG12::Hdr3DLutPayload hdr3DLutPayload = { 0 }; |
| 455 | hdr3DLutPayload.hdr3DLutSurface = MOS_New(VpCmSurfaceHolder<CmBuffer>, p3DLutSurface, m_cmContext); |
| 456 | hdr3DLutPayload.hdrCoefSurface = m_hdrCoefSurface; |
| 457 | hdr3DLutPayload.hdr3DLutSurfaceWidth = lutSize; |
| 458 | hdr3DLutPayload.hdr3DLutSurfaceHeight = lutSize; |
| 459 | |
| 460 | VPHAL_RENDER_CHK_NULL_NO_STATUS(m_cmContext); |
| 461 | m_cmContext->ConnectEventListener(m_eventManager); |
| 462 | m_hdr3DLutCmRender->Render(&hdr3DLutPayload); |
| 463 | m_cmContext->FlushBatchTask(false); |
| 464 | m_cmContext->ConnectEventListener(nullptr); |
| 465 | |
| 466 | if (enableDump) |
| 467 | { |
| 468 | // Dump 3DLut Surface |
| 469 | int32_t width = 0, height = 0, depth = 0; |
| 470 | hdr3DLutPayload.hdr3DLutSurface->GetSurfaceDimentions(width, height, depth); |
| 471 | hdr3DLutPayload.hdr3DLutSurface->DumpSurfaceToFile(OutputDumpDirectory + "3DLutSurface" + std::to_string(width) + "x" + std::to_string(height) + ".dat"); |
| 472 | // Dump Coefficient Surface(including CCM, Tone Mapping Type etc.) |
| 473 | m_hdrCoefSurface->GetSurfaceDimentions(width, height, depth); |
| 474 | m_hdrCoefSurface->DumpSurfaceToFile(OutputDumpDirectory + "CoffSurface" + std::to_string(width) + "x" + std::to_string(height) + ".dat"); |
| 475 | } |
| 476 | MOS_Delete(hdr3DLutPayload.hdr3DLutSurface); |
| 477 | } |
| 478 | |
| 479 | VPHAL_RENDER_NORMALMESSAGE("Hdr3DLutGeneratorG12 Render maxCLL %d, maxDLL %d, hdrMode: %d!", maxCLL, maxDLL, hdrMode); |
| 480 | |
| 481 | finish: |
| 482 | return; |
| 483 | } |
| 484 | #endif |