1 // Copyright 2019 The libgav1 Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "src/dsp/dsp.h" 16 17 #include <mutex> // NOLINT (unapproved c++11 header) 18 19 #include "src/dsp/average_blend.h" 20 #include "src/dsp/cdef.h" 21 #include "src/dsp/convolve.h" 22 #include "src/dsp/distance_weighted_blend.h" 23 #include "src/dsp/film_grain.h" 24 #include "src/dsp/intra_edge.h" 25 #include "src/dsp/intrapred.h" 26 #include "src/dsp/intrapred_cfl.h" 27 #include "src/dsp/intrapred_directional.h" 28 #include "src/dsp/intrapred_filter.h" 29 #include "src/dsp/intrapred_smooth.h" 30 #include "src/dsp/inverse_transform.h" 31 #include "src/dsp/loop_filter.h" 32 #include "src/dsp/loop_restoration.h" 33 #include "src/dsp/mask_blend.h" 34 #include "src/dsp/motion_field_projection.h" 35 #include "src/dsp/motion_vector_search.h" 36 #include "src/dsp/obmc.h" 37 #include "src/dsp/super_res.h" 38 #include "src/dsp/warp.h" 39 #include "src/dsp/weight_mask.h" 40 #include "src/utils/cpu.h" 41 42 namespace libgav1 { 43 namespace dsp_internal { 44 DspInit_C()45void DspInit_C() { 46 dsp::AverageBlendInit_C(); 47 dsp::CdefInit_C(); 48 dsp::ConvolveInit_C(); 49 dsp::DistanceWeightedBlendInit_C(); 50 dsp::FilmGrainInit_C(); 51 dsp::IntraEdgeInit_C(); 52 dsp::IntraPredCflInit_C(); 53 dsp::IntraPredDirectionalInit_C(); 54 dsp::IntraPredFilterInit_C(); 55 dsp::IntraPredInit_C(); 56 dsp::IntraPredSmoothInit_C(); 57 dsp::InverseTransformInit_C(); 58 dsp::LoopFilterInit_C(); 59 dsp::LoopRestorationInit_C(); 60 dsp::MaskBlendInit_C(); 61 dsp::MotionFieldProjectionInit_C(); 62 dsp::MotionVectorSearchInit_C(); 63 dsp::ObmcInit_C(); 64 dsp::SuperResInit_C(); 65 dsp::WarpInit_C(); 66 dsp::WeightMaskInit_C(); 67 } 68 GetWritableDspTable(int bitdepth)69dsp::Dsp* GetWritableDspTable(int bitdepth) { 70 switch (bitdepth) { 71 case 8: { 72 static dsp::Dsp dsp_8bpp; 73 return &dsp_8bpp; 74 } 75 #if LIBGAV1_MAX_BITDEPTH >= 10 76 case 10: { 77 static dsp::Dsp dsp_10bpp; 78 return &dsp_10bpp; 79 } 80 #endif 81 #if LIBGAV1_MAX_BITDEPTH == 12 82 case 12: { 83 static dsp::Dsp dsp_12bpp; 84 return &dsp_12bpp; 85 } 86 #endif 87 } 88 return nullptr; 89 } 90 91 } // namespace dsp_internal 92 93 namespace dsp { 94 DspInit()95void DspInit() { 96 static std::once_flag once; 97 std::call_once(once, []() { 98 dsp_internal::DspInit_C(); 99 #if LIBGAV1_ENABLE_SSE4_1 || LIBGAV1_ENABLE_AVX2 100 const uint32_t cpu_features = GetCpuInfo(); 101 #if LIBGAV1_ENABLE_SSE4_1 102 if ((cpu_features & kSSE4_1) != 0) { 103 AverageBlendInit_SSE4_1(); 104 CdefInit_SSE4_1(); 105 ConvolveInit_SSE4_1(); 106 DistanceWeightedBlendInit_SSE4_1(); 107 FilmGrainInit_SSE4_1(); 108 IntraEdgeInit_SSE4_1(); 109 IntraPredCflInit_SSE4_1(); 110 IntraPredDirectionalInit_SSE4_1(); 111 IntraPredFilterInit_SSE4_1(); 112 IntraPredInit_SSE4_1(); 113 IntraPredCflInit_SSE4_1(); 114 IntraPredSmoothInit_SSE4_1(); 115 InverseTransformInit_SSE4_1(); 116 LoopFilterInit_SSE4_1(); 117 LoopRestorationInit_SSE4_1(); 118 MaskBlendInit_SSE4_1(); 119 MotionFieldProjectionInit_SSE4_1(); 120 MotionVectorSearchInit_SSE4_1(); 121 ObmcInit_SSE4_1(); 122 SuperResInit_SSE4_1(); 123 WarpInit_SSE4_1(); 124 WeightMaskInit_SSE4_1(); 125 #if LIBGAV1_MAX_BITDEPTH >= 10 126 LoopRestorationInit10bpp_SSE4_1(); 127 #endif // LIBGAV1_MAX_BITDEPTH >= 10 128 } 129 #endif // LIBGAV1_ENABLE_SSE4_1 130 #if LIBGAV1_ENABLE_AVX2 131 if ((cpu_features & kAVX2) != 0) { 132 CdefInit_AVX2(); 133 ConvolveInit_AVX2(); 134 LoopRestorationInit_AVX2(); 135 #if LIBGAV1_MAX_BITDEPTH >= 10 136 LoopRestorationInit10bpp_AVX2(); 137 #endif // LIBGAV1_MAX_BITDEPTH >= 10 138 } 139 #endif // LIBGAV1_ENABLE_AVX2 140 #endif // LIBGAV1_ENABLE_SSE4_1 || LIBGAV1_ENABLE_AVX2 141 #if LIBGAV1_ENABLE_NEON 142 AverageBlendInit_NEON(); 143 CdefInit_NEON(); 144 ConvolveInit_NEON(); 145 DistanceWeightedBlendInit_NEON(); 146 FilmGrainInit_NEON(); 147 IntraEdgeInit_NEON(); 148 IntraPredCflInit_NEON(); 149 IntraPredDirectionalInit_NEON(); 150 IntraPredFilterInit_NEON(); 151 IntraPredInit_NEON(); 152 IntraPredSmoothInit_NEON(); 153 InverseTransformInit_NEON(); 154 LoopFilterInit_NEON(); 155 LoopRestorationInit_NEON(); 156 MaskBlendInit_NEON(); 157 MotionFieldProjectionInit_NEON(); 158 MotionVectorSearchInit_NEON(); 159 ObmcInit_NEON(); 160 SuperResInit_NEON(); 161 WarpInit_NEON(); 162 WeightMaskInit_NEON(); 163 #if LIBGAV1_MAX_BITDEPTH >= 10 164 ConvolveInit10bpp_NEON(); 165 InverseTransformInit10bpp_NEON(); 166 LoopFilterInit10bpp_NEON(); 167 LoopRestorationInit10bpp_NEON(); 168 #endif // LIBGAV1_MAX_BITDEPTH >= 10 169 #endif // LIBGAV1_ENABLE_NEON 170 }); 171 } 172 GetDspTable(int bitdepth)173const Dsp* GetDspTable(int bitdepth) { 174 return dsp_internal::GetWritableDspTable(bitdepth); 175 } 176 177 } // namespace dsp 178 } // namespace libgav1 179