| 1 | /* |
| 2 | * Copyright (c) 2017-2020, 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 codechal_decode_sfc_avc_g12.cpp |
| 24 | //! \brief Implements the decode interface extension for CSC and scaling via SFC for AVC decoder for G12+ platform. |
| 25 | //! \details Downsampling in this case is supported by the SFC fixed function HW unit. |
| 26 | //! |
| 27 | |
| 28 | #include "codechal_decoder.h" |
| 29 | #include "codechal_decode_sfc_avc_g12.h" |
| 30 | #include "codechal_mmc.h" |
| 31 | |
| 32 | MOS_STATUS CodechalAvcSfcStateG12::SetSfcStateParams( |
| 33 | PMHW_SFC_STATE_PARAMS sfcStateParams, |
| 34 | PMHW_SFC_OUT_SURFACE_PARAMS outSurfaceParams) |
| 35 | { |
| 36 | CODECHAL_HW_FUNCTION_ENTER; |
| 37 | |
| 38 | CODECHAL_HW_CHK_STATUS_RETURN(CodechalSfcState::SetSfcStateParams(sfcStateParams, outSurfaceParams)); |
| 39 | |
| 40 | if (m_mmcEnabled) |
| 41 | { |
| 42 | MOS_MEMCOMP_STATE mmcMode = MOS_MEMCOMP_DISABLED; |
| 43 | CODECHAL_HW_CHK_STATUS_RETURN(m_osInterface->pfnGetMemoryCompressionMode(m_osInterface, &m_sfcOutputSurface->OsResource, &mmcMode)); |
| 44 | sfcStateParams->bMMCEnable = (mmcMode != MOS_MEMCOMP_DISABLED) ? true : false; |
| 45 | sfcStateParams->MMCMode = (mmcMode == MOS_MEMCOMP_RC) ? MOS_MMC_RC : MOS_MMC_MC; |
| 46 | CODECHAL_HW_CHK_STATUS_RETURN(m_osInterface->pfnGetMemoryCompressionFormat( |
| 47 | m_osInterface, &m_sfcOutputSurface->OsResource, &outSurfaceParams->dwCompressionFormat)); |
| 48 | } |
| 49 | |
| 50 | return MOS_STATUS_SUCCESS; |
| 51 | } |
| 52 | |
| 53 | MOS_STATUS CodechalAvcSfcStateG12::AddSfcCommands( |
| 54 | PMOS_COMMAND_BUFFER cmdBuffer) |
| 55 | { |
| 56 | CODECHAL_HW_FUNCTION_ENTER; |
| 57 | |
| 58 | CODECHAL_HW_CHK_NULL_RETURN(cmdBuffer); |
| 59 | |
| 60 | if (m_sfcPipeOut == false) |
| 61 | { |
| 62 | return MOS_STATUS_SUCCESS; |
| 63 | } |
| 64 | |
| 65 | MHW_SFC_LOCK_PARAMS sfcLockParams; |
| 66 | MOS_ZeroMemory(&sfcLockParams, sizeof(sfcLockParams)); |
| 67 | |
| 68 | sfcLockParams.sfcPipeMode = m_sfcPipeMode; |
| 69 | sfcLockParams.bOutputToMemory = ((MhwSfcInterface::SFC_PIPE_MODE_VEBOX != m_sfcPipeMode) && !m_jpegInUse); |
| 70 | |
| 71 | MHW_SFC_STATE_PARAMS_G12 sfcStateParams; |
| 72 | MOS_ZeroMemory(&sfcStateParams, sizeof(sfcStateParams)); |
| 73 | MHW_SFC_OUT_SURFACE_PARAMS sfcOutSurfaceParams; |
| 74 | MOS_ZeroMemory(&sfcOutSurfaceParams, sizeof(sfcOutSurfaceParams)); |
| 75 | CODECHAL_HW_CHK_STATUS_RETURN(SetSfcStateParams(&sfcStateParams, &sfcOutSurfaceParams)); |
| 76 | |
| 77 | CODECHAL_HW_CHK_STATUS_RETURN(m_sfcInterface->AddSfcLock(cmdBuffer, &sfcLockParams)); |
| 78 | CODECHAL_HW_CHK_STATUS_RETURN(m_sfcInterface->AddSfcState(cmdBuffer, &sfcStateParams, &sfcOutSurfaceParams)); |
| 79 | |
| 80 | if (m_scaling) |
| 81 | { |
| 82 | CODECHAL_HW_CHK_STATUS_RETURN(SetSfcAvsStateParams()); |
| 83 | CODECHAL_HW_CHK_STATUS_RETURN(m_sfcInterface->AddSfcAvsState(cmdBuffer, &m_avsState)); |
| 84 | CODECHAL_HW_CHK_STATUS_RETURN(m_sfcInterface->AddSfcAvsLumaTable(cmdBuffer, &m_lumaTable)); |
| 85 | CODECHAL_HW_CHK_STATUS_RETURN(m_sfcInterface->AddSfcAvsChromaTable(cmdBuffer, &m_chromaTable)); |
| 86 | } |
| 87 | |
| 88 | if (m_csc) |
| 89 | { |
| 90 | MHW_SFC_IEF_STATE_PARAMS sfcIefStateParams; |
| 91 | MOS_ZeroMemory(&sfcIefStateParams, sizeof(sfcIefStateParams)); |
| 92 | CODECHAL_HW_CHK_STATUS_RETURN(SetSfcIefStateParams(&sfcIefStateParams)); |
| 93 | CODECHAL_HW_CHK_STATUS_RETURN(m_sfcInterface->AddSfcIefState(cmdBuffer, &sfcIefStateParams)); |
| 94 | } |
| 95 | |
| 96 | CODECHAL_HW_CHK_STATUS_RETURN(m_sfcInterface->AddSfcFrameStart(cmdBuffer, m_sfcPipeMode)); |
| 97 | |
| 98 | return MOS_STATUS_SUCCESS; |
| 99 | } |
| 100 | |
| 101 | bool CodechalAvcSfcStateG12::IsSfcFormatSupported( |
| 102 | MOS_FORMAT inputFormat, |
| 103 | MOS_FORMAT outputFormat) |
| 104 | { |
| 105 | if ((inputFormat != Format_NV12) && |
| 106 | (inputFormat != Format_400P) && |
| 107 | (inputFormat != Format_IMC3) && |
| 108 | (inputFormat != Format_422H) && |
| 109 | (inputFormat != Format_444P) && |
| 110 | (inputFormat != Format_P010) && |
| 111 | (inputFormat != Format_YUY2) && |
| 112 | (inputFormat != Format_AYUV) && |
| 113 | (inputFormat != Format_Y210) && |
| 114 | (inputFormat != Format_Y410) && |
| 115 | (inputFormat != Format_P016) && |
| 116 | (inputFormat != Format_Y216) && |
| 117 | (inputFormat != Format_Y416)) |
| 118 | { |
| 119 | CODECHAL_DECODE_ASSERTMESSAGE("Unsupported Input Format '0x%08x' for SFC.", inputFormat); |
| 120 | return false; |
| 121 | } |
| 122 | |
| 123 | if ((outputFormat != Format_A8R8G8B8) && |
| 124 | (outputFormat != Format_NV12) && |
| 125 | (outputFormat != Format_P010) && |
| 126 | (outputFormat != Format_YUY2) && |
| 127 | (outputFormat != Format_AYUV) && |
| 128 | (outputFormat != Format_P016) && |
| 129 | (outputFormat != Format_Y210) && |
| 130 | (outputFormat != Format_Y216) && |
| 131 | (outputFormat != Format_Y410) && |
| 132 | (outputFormat != Format_Y416)) |
| 133 | { |
| 134 | CODECHAL_DECODE_ASSERTMESSAGE("Unsupported Output Format '0x%08x' for SFC.", outputFormat); |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | MOS_STATUS CodechalAvcSfcStateG12::CheckAndInitialize( |
| 142 | DecodeProcessingParams *decProcessingParams, |
| 143 | PCODEC_AVC_PIC_PARAMS picParams, |
| 144 | uint32_t width, |
| 145 | uint32_t height, |
| 146 | bool deblockingEnabled) |
| 147 | { |
| 148 | MOS_STATUS status = MOS_STATUS_SUCCESS; |
| 149 | |
| 150 | status = CodechalAvcSfcState::CheckAndInitialize(decProcessingParams,picParams,width, height, deblockingEnabled); |
| 151 | |
| 152 | if(m_sfcPipeOut) |
| 153 | { |
| 154 | m_histogramSurface = decProcessingParams->m_histogramSurface; |
| 155 | } |
| 156 | |
| 157 | return status; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | MOS_STATUS CodechalAvcSfcStateG12::UpdateInputInfo( |
| 162 | PMHW_SFC_STATE_PARAMS sfcStateParams) |
| 163 | { |
| 164 | MOS_STATUS status = MOS_STATUS_SUCCESS; |
| 165 | |
| 166 | status = CodechalAvcSfcState::UpdateInputInfo(sfcStateParams); |
| 167 | |
| 168 | PMHW_SFC_STATE_PARAMS_G12 sfcStateParamsG12 = static_cast<PMHW_SFC_STATE_PARAMS_G12>(sfcStateParams); |
| 169 | |
| 170 | sfcStateParamsG12->histogramSurface = m_histogramSurface; |
| 171 | |
| 172 | return status; |
| 173 | } |