diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/command_classes/codecs/vp9.cpp | 102 | ||||
| -rw-r--r-- | src/video_core/command_classes/codecs/vp9.h | 10 |
2 files changed, 54 insertions, 58 deletions
diff --git a/src/video_core/command_classes/codecs/vp9.cpp b/src/video_core/command_classes/codecs/vp9.cpp index b3e98aa9f..aeb9866de 100644 --- a/src/video_core/command_classes/codecs/vp9.cpp +++ b/src/video_core/command_classes/codecs/vp9.cpp | |||
| @@ -197,6 +197,60 @@ constexpr std::array<s32, 254> map_lut{ | |||
| 197 | 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 18, 242, 243, 244, 245, 246, 247, | 197 | 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 18, 242, 243, 244, 245, 246, 247, |
| 198 | 248, 249, 250, 251, 252, 253, 19, | 198 | 248, 249, 250, 251, 252, 253, 19, |
| 199 | }; | 199 | }; |
| 200 | |||
| 201 | // 6.2.14 Tile size calculation | ||
| 202 | |||
| 203 | s32 CalcMinLog2TileCols(s32 frame_width) { | ||
| 204 | const s32 sb64_cols = (frame_width + 63) / 64; | ||
| 205 | s32 min_log2 = 0; | ||
| 206 | |||
| 207 | while ((64 << min_log2) < sb64_cols) { | ||
| 208 | min_log2++; | ||
| 209 | } | ||
| 210 | |||
| 211 | return min_log2; | ||
| 212 | } | ||
| 213 | |||
| 214 | s32 CalcMaxLog2TileCols(s32 frame_width) { | ||
| 215 | const s32 sb64_cols = (frame_width + 63) / 64; | ||
| 216 | s32 max_log2 = 1; | ||
| 217 | |||
| 218 | while ((sb64_cols >> max_log2) >= 4) { | ||
| 219 | max_log2++; | ||
| 220 | } | ||
| 221 | |||
| 222 | return max_log2 - 1; | ||
| 223 | } | ||
| 224 | |||
| 225 | // Recenters probability. Based on section 6.3.6 of VP9 Specification | ||
| 226 | s32 RecenterNonNeg(s32 new_prob, s32 old_prob) { | ||
| 227 | if (new_prob > old_prob * 2) { | ||
| 228 | return new_prob; | ||
| 229 | } | ||
| 230 | |||
| 231 | if (new_prob >= old_prob) { | ||
| 232 | return (new_prob - old_prob) * 2; | ||
| 233 | } | ||
| 234 | |||
| 235 | return (old_prob - new_prob) * 2 - 1; | ||
| 236 | } | ||
| 237 | |||
| 238 | // Adjusts old_prob depending on new_prob. Based on section 6.3.5 of VP9 Specification | ||
| 239 | s32 RemapProbability(s32 new_prob, s32 old_prob) { | ||
| 240 | new_prob--; | ||
| 241 | old_prob--; | ||
| 242 | |||
| 243 | std::size_t index{}; | ||
| 244 | |||
| 245 | if (old_prob * 2 <= 0xff) { | ||
| 246 | index = static_cast<std::size_t>(std::max(0, RecenterNonNeg(new_prob, old_prob) - 1)); | ||
| 247 | } else { | ||
| 248 | index = static_cast<std::size_t>( | ||
| 249 | std::max(0, RecenterNonNeg(0xff - 1 - new_prob, 0xff - 1 - old_prob) - 1)); | ||
| 250 | } | ||
| 251 | |||
| 252 | return map_lut[index]; | ||
| 253 | } | ||
| 200 | } // Anonymous namespace | 254 | } // Anonymous namespace |
| 201 | 255 | ||
| 202 | VP9::VP9(GPU& gpu) : gpu(gpu) {} | 256 | VP9::VP9(GPU& gpu) : gpu(gpu) {} |
| @@ -236,32 +290,6 @@ void VP9::WriteProbabilityDelta(VpxRangeEncoder& writer, u8 new_prob, u8 old_pro | |||
| 236 | EncodeTermSubExp(writer, delta); | 290 | EncodeTermSubExp(writer, delta); |
| 237 | } | 291 | } |
| 238 | 292 | ||
| 239 | s32 VP9::RemapProbability(s32 new_prob, s32 old_prob) { | ||
| 240 | new_prob--; | ||
| 241 | old_prob--; | ||
| 242 | |||
| 243 | std::size_t index{}; | ||
| 244 | |||
| 245 | if (old_prob * 2 <= 0xff) { | ||
| 246 | index = static_cast<std::size_t>(std::max(0, RecenterNonNeg(new_prob, old_prob) - 1)); | ||
| 247 | } else { | ||
| 248 | index = static_cast<std::size_t>( | ||
| 249 | std::max(0, RecenterNonNeg(0xff - 1 - new_prob, 0xff - 1 - old_prob) - 1)); | ||
| 250 | } | ||
| 251 | |||
| 252 | return map_lut[index]; | ||
| 253 | } | ||
| 254 | |||
| 255 | s32 VP9::RecenterNonNeg(s32 new_prob, s32 old_prob) { | ||
| 256 | if (new_prob > old_prob * 2) { | ||
| 257 | return new_prob; | ||
| 258 | } else if (new_prob >= old_prob) { | ||
| 259 | return (new_prob - old_prob) * 2; | ||
| 260 | } else { | ||
| 261 | return (old_prob - new_prob) * 2 - 1; | ||
| 262 | } | ||
| 263 | } | ||
| 264 | |||
| 265 | void VP9::EncodeTermSubExp(VpxRangeEncoder& writer, s32 value) { | 293 | void VP9::EncodeTermSubExp(VpxRangeEncoder& writer, s32 value) { |
| 266 | if (WriteLessThan(writer, value, 16)) { | 294 | if (WriteLessThan(writer, value, 16)) { |
| 267 | writer.Write(value, 4); | 295 | writer.Write(value, 4); |
| @@ -361,28 +389,6 @@ void VP9::WriteMvProbabilityUpdate(VpxRangeEncoder& writer, u8 new_prob, u8 old_ | |||
| 361 | } | 389 | } |
| 362 | } | 390 | } |
| 363 | 391 | ||
| 364 | s32 VP9::CalcMinLog2TileCols(s32 frame_width) { | ||
| 365 | const s32 sb64_cols = (frame_width + 63) / 64; | ||
| 366 | s32 min_log2 = 0; | ||
| 367 | |||
| 368 | while ((64 << min_log2) < sb64_cols) { | ||
| 369 | min_log2++; | ||
| 370 | } | ||
| 371 | |||
| 372 | return min_log2; | ||
| 373 | } | ||
| 374 | |||
| 375 | s32 VP9::CalcMaxLog2TileCols(s32 frameWidth) { | ||
| 376 | const s32 sb64_cols = (frameWidth + 63) / 64; | ||
| 377 | s32 max_log2 = 1; | ||
| 378 | |||
| 379 | while ((sb64_cols >> max_log2) >= 4) { | ||
| 380 | max_log2++; | ||
| 381 | } | ||
| 382 | |||
| 383 | return max_log2 - 1; | ||
| 384 | } | ||
| 385 | |||
| 386 | Vp9PictureInfo VP9::GetVp9PictureInfo(const NvdecCommon::NvdecRegisters& state) { | 392 | Vp9PictureInfo VP9::GetVp9PictureInfo(const NvdecCommon::NvdecRegisters& state) { |
| 387 | PictureInfo picture_info{}; | 393 | PictureInfo picture_info{}; |
| 388 | gpu.MemoryManager().ReadBlock(state.picture_info_offset, &picture_info, sizeof(PictureInfo)); | 394 | gpu.MemoryManager().ReadBlock(state.picture_info_offset, &picture_info, sizeof(PictureInfo)); |
diff --git a/src/video_core/command_classes/codecs/vp9.h b/src/video_core/command_classes/codecs/vp9.h index dc52ddbde..3826f2c95 100644 --- a/src/video_core/command_classes/codecs/vp9.h +++ b/src/video_core/command_classes/codecs/vp9.h | |||
| @@ -121,12 +121,6 @@ private: | |||
| 121 | /// Generates compressed header probability deltas in the bitstream writer | 121 | /// Generates compressed header probability deltas in the bitstream writer |
| 122 | void WriteProbabilityDelta(VpxRangeEncoder& writer, u8 new_prob, u8 old_prob); | 122 | void WriteProbabilityDelta(VpxRangeEncoder& writer, u8 new_prob, u8 old_prob); |
| 123 | 123 | ||
| 124 | /// Adjusts old_prob depending on new_prob. Based on section 6.3.5 of VP9 Specification | ||
| 125 | s32 RemapProbability(s32 new_prob, s32 old_prob); | ||
| 126 | |||
| 127 | /// Recenters probability. Based on section 6.3.6 of VP9 Specification | ||
| 128 | s32 RecenterNonNeg(s32 new_prob, s32 old_prob); | ||
| 129 | |||
| 130 | /// Inverse of 6.3.4 Decode term subexp | 124 | /// Inverse of 6.3.4 Decode term subexp |
| 131 | void EncodeTermSubExp(VpxRangeEncoder& writer, s32 value); | 125 | void EncodeTermSubExp(VpxRangeEncoder& writer, s32 value); |
| 132 | 126 | ||
| @@ -146,10 +140,6 @@ private: | |||
| 146 | /// Write motion vector probability updates. 6.3.17 in the spec | 140 | /// Write motion vector probability updates. 6.3.17 in the spec |
| 147 | void WriteMvProbabilityUpdate(VpxRangeEncoder& writer, u8 new_prob, u8 old_prob); | 141 | void WriteMvProbabilityUpdate(VpxRangeEncoder& writer, u8 new_prob, u8 old_prob); |
| 148 | 142 | ||
| 149 | /// 6.2.14 Tile size calculation | ||
| 150 | s32 CalcMinLog2TileCols(s32 frame_width); | ||
| 151 | s32 CalcMaxLog2TileCols(s32 frame_width); | ||
| 152 | |||
| 153 | /// Returns VP9 information from NVDEC provided offset and size | 143 | /// Returns VP9 information from NVDEC provided offset and size |
| 154 | Vp9PictureInfo GetVp9PictureInfo(const NvdecCommon::NvdecRegisters& state); | 144 | Vp9PictureInfo GetVp9PictureInfo(const NvdecCommon::NvdecRegisters& state); |
| 155 | 145 | ||