hardware/intel/intel-driver
Revision | 652f141474c42c31d50ff21591829ab8e8a35917 (tree) |
---|---|
Time | 2015-03-19 11:01:29 |
Author | Zhong Li <zhong.li@inte...> |
Commiter | Xiang, Haihao |
MPEG2 ENC: Remove gen9 pak pipeline code
SKL pak pipeline of mpeg2 encoding is same as gen8,
so remove the redundant code
Signed-off-by: Zhong Li <zhong.li@intel.com>
(cherry picked from commit ac46de469dd5eeaed34be0510631228a07748ec3)
@@ -1620,742 +1620,6 @@ gen9_mfc_avc_encode_picture(VADriverContextP ctx, | ||
1620 | 1620 | return VA_STATUS_SUCCESS; |
1621 | 1621 | } |
1622 | 1622 | |
1623 | -/* | |
1624 | - * MPEG-2 | |
1625 | - */ | |
1626 | - | |
1627 | -static const int | |
1628 | -va_to_gen9_mpeg2_picture_type[3] = { | |
1629 | - 1, /* I */ | |
1630 | - 2, /* P */ | |
1631 | - 3 /* B */ | |
1632 | -}; | |
1633 | - | |
1634 | -static void | |
1635 | -gen9_mfc_mpeg2_pic_state(VADriverContextP ctx, | |
1636 | - struct intel_encoder_context *encoder_context, | |
1637 | - struct encode_state *encode_state) | |
1638 | -{ | |
1639 | - struct intel_batchbuffer *batch = encoder_context->base.batch; | |
1640 | - struct gen6_mfc_context *mfc_context = encoder_context->mfc_context; | |
1641 | - VAEncPictureParameterBufferMPEG2 *pic_param; | |
1642 | - int width_in_mbs = (mfc_context->surface_state.width + 15) / 16; | |
1643 | - int height_in_mbs = (mfc_context->surface_state.height + 15) / 16; | |
1644 | - VAEncSliceParameterBufferMPEG2 *slice_param = NULL; | |
1645 | - | |
1646 | - assert(encode_state->pic_param_ext && encode_state->pic_param_ext->buffer); | |
1647 | - pic_param = (VAEncPictureParameterBufferMPEG2 *)encode_state->pic_param_ext->buffer; | |
1648 | - slice_param = (VAEncSliceParameterBufferMPEG2 *)encode_state->slice_params_ext[0]->buffer; | |
1649 | - | |
1650 | - BEGIN_BCS_BATCH(batch, 13); | |
1651 | - OUT_BCS_BATCH(batch, MFX_MPEG2_PIC_STATE | (13 - 2)); | |
1652 | - OUT_BCS_BATCH(batch, | |
1653 | - (pic_param->f_code[1][1] & 0xf) << 28 | /* f_code[1][1] */ | |
1654 | - (pic_param->f_code[1][0] & 0xf) << 24 | /* f_code[1][0] */ | |
1655 | - (pic_param->f_code[0][1] & 0xf) << 20 | /* f_code[0][1] */ | |
1656 | - (pic_param->f_code[0][0] & 0xf) << 16 | /* f_code[0][0] */ | |
1657 | - pic_param->picture_coding_extension.bits.intra_dc_precision << 14 | | |
1658 | - pic_param->picture_coding_extension.bits.picture_structure << 12 | | |
1659 | - pic_param->picture_coding_extension.bits.top_field_first << 11 | | |
1660 | - pic_param->picture_coding_extension.bits.frame_pred_frame_dct << 10 | | |
1661 | - pic_param->picture_coding_extension.bits.concealment_motion_vectors << 9 | | |
1662 | - pic_param->picture_coding_extension.bits.q_scale_type << 8 | | |
1663 | - pic_param->picture_coding_extension.bits.intra_vlc_format << 7 | | |
1664 | - pic_param->picture_coding_extension.bits.alternate_scan << 6); | |
1665 | - OUT_BCS_BATCH(batch, | |
1666 | - 0 << 14 | /* LoadSlicePointerFlag, 0 means only loading bitstream pointer once */ | |
1667 | - va_to_gen9_mpeg2_picture_type[pic_param->picture_type] << 9 | | |
1668 | - 0); | |
1669 | - OUT_BCS_BATCH(batch, | |
1670 | - 1 << 31 | /* slice concealment */ | |
1671 | - (height_in_mbs - 1) << 16 | | |
1672 | - (width_in_mbs - 1)); | |
1673 | - | |
1674 | - if (slice_param && slice_param->quantiser_scale_code >= 14) | |
1675 | - OUT_BCS_BATCH(batch, (3 << 1) | (1 << 4) | (5 << 8) | (1 << 12)); | |
1676 | - else | |
1677 | - OUT_BCS_BATCH(batch, 0); | |
1678 | - | |
1679 | - OUT_BCS_BATCH(batch, 0); | |
1680 | - OUT_BCS_BATCH(batch, | |
1681 | - 0xFFF << 16 | /* InterMBMaxSize */ | |
1682 | - 0xFFF << 0 | /* IntraMBMaxSize */ | |
1683 | - 0); | |
1684 | - OUT_BCS_BATCH(batch, 0); | |
1685 | - OUT_BCS_BATCH(batch, 0); | |
1686 | - OUT_BCS_BATCH(batch, 0); | |
1687 | - OUT_BCS_BATCH(batch, 0); | |
1688 | - OUT_BCS_BATCH(batch, 0); | |
1689 | - OUT_BCS_BATCH(batch, 0); | |
1690 | - ADVANCE_BCS_BATCH(batch); | |
1691 | -} | |
1692 | - | |
1693 | -static void | |
1694 | -gen9_mfc_mpeg2_qm_state(VADriverContextP ctx, struct intel_encoder_context *encoder_context) | |
1695 | -{ | |
1696 | - unsigned char intra_qm[64] = { | |
1697 | - 8, 16, 19, 22, 26, 27, 29, 34, | |
1698 | - 16, 16, 22, 24, 27, 29, 34, 37, | |
1699 | - 19, 22, 26, 27, 29, 34, 34, 38, | |
1700 | - 22, 22, 26, 27, 29, 34, 37, 40, | |
1701 | - 22, 26, 27, 29, 32, 35, 40, 48, | |
1702 | - 26, 27, 29, 32, 35, 40, 48, 58, | |
1703 | - 26, 27, 29, 34, 38, 46, 56, 69, | |
1704 | - 27, 29, 35, 38, 46, 56, 69, 83 | |
1705 | - }; | |
1706 | - | |
1707 | - unsigned char non_intra_qm[64] = { | |
1708 | - 16, 16, 16, 16, 16, 16, 16, 16, | |
1709 | - 16, 16, 16, 16, 16, 16, 16, 16, | |
1710 | - 16, 16, 16, 16, 16, 16, 16, 16, | |
1711 | - 16, 16, 16, 16, 16, 16, 16, 16, | |
1712 | - 16, 16, 16, 16, 16, 16, 16, 16, | |
1713 | - 16, 16, 16, 16, 16, 16, 16, 16, | |
1714 | - 16, 16, 16, 16, 16, 16, 16, 16, | |
1715 | - 16, 16, 16, 16, 16, 16, 16, 16 | |
1716 | - }; | |
1717 | - | |
1718 | - gen9_mfc_qm_state(ctx, MFX_QM_MPEG_INTRA_QUANTIZER_MATRIX, (unsigned int *)intra_qm, 16, encoder_context); | |
1719 | - gen9_mfc_qm_state(ctx, MFX_QM_MPEG_NON_INTRA_QUANTIZER_MATRIX, (unsigned int *)non_intra_qm, 16,encoder_context); | |
1720 | -} | |
1721 | - | |
1722 | -static void | |
1723 | -gen9_mfc_mpeg2_fqm_state(VADriverContextP ctx, struct intel_encoder_context *encoder_context) | |
1724 | -{ | |
1725 | - unsigned short intra_fqm[64] = { | |
1726 | - 65536/0x8, 65536/0x10, 65536/0x13, 65536/0x16, 65536/0x16, 65536/0x1a, 65536/0x1a, 65536/0x1b, | |
1727 | - 65536/0x10, 65536/0x10, 65536/0x16, 65536/0x16, 65536/0x1a, 65536/0x1b, 65536/0x1b, 65536/0x1d, | |
1728 | - 65536/0x13, 65536/0x16, 65536/0x1a, 65536/0x1a, 65536/0x1b, 65536/0x1d, 65536/0x1d, 65536/0x23, | |
1729 | - 65536/0x16, 65536/0x18, 65536/0x1b, 65536/0x1b, 65536/0x13, 65536/0x20, 65536/0x22, 65536/0x26, | |
1730 | - 65536/0x1a, 65536/0x1b, 65536/0x13, 65536/0x13, 65536/0x20, 65536/0x23, 65536/0x26, 65536/0x2e, | |
1731 | - 65536/0x1b, 65536/0x1d, 65536/0x22, 65536/0x22, 65536/0x23, 65536/0x28, 65536/0x2e, 65536/0x38, | |
1732 | - 65536/0x1d, 65536/0x22, 65536/0x22, 65536/0x25, 65536/0x28, 65536/0x30, 65536/0x38, 65536/0x45, | |
1733 | - 65536/0x22, 65536/0x25, 65536/0x26, 65536/0x28, 65536/0x30, 65536/0x3a, 65536/0x45, 65536/0x53, | |
1734 | - }; | |
1735 | - | |
1736 | - unsigned short non_intra_fqm[64] = { | |
1737 | - 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, | |
1738 | - 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, | |
1739 | - 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, | |
1740 | - 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, | |
1741 | - 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, | |
1742 | - 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, | |
1743 | - 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, | |
1744 | - 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, | |
1745 | - }; | |
1746 | - | |
1747 | - gen9_mfc_fqm_state(ctx, MFX_QM_MPEG_INTRA_QUANTIZER_MATRIX, (unsigned int *)intra_fqm, 32, encoder_context); | |
1748 | - gen9_mfc_fqm_state(ctx, MFX_QM_MPEG_NON_INTRA_QUANTIZER_MATRIX, (unsigned int *)non_intra_fqm, 32, encoder_context); | |
1749 | -} | |
1750 | - | |
1751 | -static void | |
1752 | -gen9_mfc_mpeg2_slicegroup_state(VADriverContextP ctx, | |
1753 | - struct intel_encoder_context *encoder_context, | |
1754 | - int x, int y, | |
1755 | - int next_x, int next_y, | |
1756 | - int is_fisrt_slice_group, | |
1757 | - int is_last_slice_group, | |
1758 | - int intra_slice, | |
1759 | - int qp, | |
1760 | - struct intel_batchbuffer *batch) | |
1761 | -{ | |
1762 | - struct gen6_mfc_context *mfc_context = encoder_context->mfc_context; | |
1763 | - | |
1764 | - if (batch == NULL) | |
1765 | - batch = encoder_context->base.batch; | |
1766 | - | |
1767 | - BEGIN_BCS_BATCH(batch, 8); | |
1768 | - | |
1769 | - OUT_BCS_BATCH(batch, MFC_MPEG2_SLICEGROUP_STATE | (8 - 2)); | |
1770 | - OUT_BCS_BATCH(batch, | |
1771 | - 0 << 31 | /* MbRateCtrlFlag */ | |
1772 | - !!is_last_slice_group << 19 | /* IsLastSliceGrp */ | |
1773 | - 1 << 17 | /* Insert Header before the first slice group data */ | |
1774 | - 1 << 16 | /* SliceData PresentFlag: always 1 */ | |
1775 | - 1 << 15 | /* TailPresentFlag: always 1 */ | |
1776 | - 0 << 14 | /* FirstSliceHdrDisabled: slice header for each slice */ | |
1777 | - !!intra_slice << 13 | /* IntraSlice */ | |
1778 | - !!intra_slice << 12 | /* IntraSliceFlag */ | |
1779 | - 0); | |
1780 | - OUT_BCS_BATCH(batch, | |
1781 | - next_y << 24 | | |
1782 | - next_x << 16 | | |
1783 | - y << 8 | | |
1784 | - x << 0 | | |
1785 | - 0); | |
1786 | - OUT_BCS_BATCH(batch, qp); /* FIXME: SliceGroupQp */ | |
1787 | - /* bitstream pointer is only loaded once for the first slice of a frame when | |
1788 | - * LoadSlicePointerFlag is 0 | |
1789 | - */ | |
1790 | - OUT_BCS_BATCH(batch, mfc_context->mfc_indirect_pak_bse_object.offset); | |
1791 | - OUT_BCS_BATCH(batch, 0); /* FIXME: */ | |
1792 | - OUT_BCS_BATCH(batch, 0); /* FIXME: CorrectPoints */ | |
1793 | - OUT_BCS_BATCH(batch, 0); /* FIXME: CVxxx */ | |
1794 | - | |
1795 | - ADVANCE_BCS_BATCH(batch); | |
1796 | -} | |
1797 | - | |
1798 | -static int | |
1799 | -gen9_mfc_mpeg2_pak_object_intra(VADriverContextP ctx, | |
1800 | - struct intel_encoder_context *encoder_context, | |
1801 | - int x, int y, | |
1802 | - int first_mb_in_slice, | |
1803 | - int last_mb_in_slice, | |
1804 | - int first_mb_in_slice_group, | |
1805 | - int last_mb_in_slice_group, | |
1806 | - int mb_type, | |
1807 | - int qp_scale_code, | |
1808 | - int coded_block_pattern, | |
1809 | - unsigned char target_size_in_word, | |
1810 | - unsigned char max_size_in_word, | |
1811 | - struct intel_batchbuffer *batch) | |
1812 | -{ | |
1813 | - int len_in_dwords = 9; | |
1814 | - | |
1815 | - if (batch == NULL) | |
1816 | - batch = encoder_context->base.batch; | |
1817 | - | |
1818 | - BEGIN_BCS_BATCH(batch, len_in_dwords); | |
1819 | - | |
1820 | - OUT_BCS_BATCH(batch, MFC_MPEG2_PAK_OBJECT | (len_in_dwords - 2)); | |
1821 | - OUT_BCS_BATCH(batch, | |
1822 | - 0 << 24 | /* PackedMvNum */ | |
1823 | - 0 << 20 | /* MvFormat */ | |
1824 | - 7 << 17 | /* CbpDcY/CbpDcU/CbpDcV */ | |
1825 | - 0 << 15 | /* TransformFlag: frame DCT */ | |
1826 | - 0 << 14 | /* FieldMbFlag */ | |
1827 | - 1 << 13 | /* IntraMbFlag */ | |
1828 | - mb_type << 8 | /* MbType: Intra */ | |
1829 | - 0 << 2 | /* SkipMbFlag */ | |
1830 | - 0 << 0 | /* InterMbMode */ | |
1831 | - 0); | |
1832 | - OUT_BCS_BATCH(batch, y << 16 | x); | |
1833 | - OUT_BCS_BATCH(batch, | |
1834 | - max_size_in_word << 24 | | |
1835 | - target_size_in_word << 16 | | |
1836 | - coded_block_pattern << 6 | /* CBP */ | |
1837 | - 0); | |
1838 | - OUT_BCS_BATCH(batch, | |
1839 | - last_mb_in_slice << 31 | | |
1840 | - first_mb_in_slice << 30 | | |
1841 | - 0 << 27 | /* EnableCoeffClamp */ | |
1842 | - last_mb_in_slice_group << 26 | | |
1843 | - 0 << 25 | /* MbSkipConvDisable */ | |
1844 | - first_mb_in_slice_group << 24 | | |
1845 | - 0 << 16 | /* MvFieldSelect */ | |
1846 | - qp_scale_code << 0 | | |
1847 | - 0); | |
1848 | - OUT_BCS_BATCH(batch, 0); /* MV[0][0] */ | |
1849 | - OUT_BCS_BATCH(batch, 0); /* MV[1][0] */ | |
1850 | - OUT_BCS_BATCH(batch, 0); /* MV[0][1] */ | |
1851 | - OUT_BCS_BATCH(batch, 0); /* MV[1][1] */ | |
1852 | - | |
1853 | - ADVANCE_BCS_BATCH(batch); | |
1854 | - | |
1855 | - return len_in_dwords; | |
1856 | -} | |
1857 | - | |
1858 | -/* Byte offset */ | |
1859 | -#define MPEG2_INTER_MV_OFFSET 48 | |
1860 | - | |
1861 | -static struct _mv_ranges | |
1862 | -{ | |
1863 | - int low; /* in the unit of 1/2 pixel */ | |
1864 | - int high; /* in the unit of 1/2 pixel */ | |
1865 | -} mv_ranges[] = { | |
1866 | - {0, 0}, | |
1867 | - {-16, 15}, | |
1868 | - {-32, 31}, | |
1869 | - {-64, 63}, | |
1870 | - {-128, 127}, | |
1871 | - {-256, 255}, | |
1872 | - {-512, 511}, | |
1873 | - {-1024, 1023}, | |
1874 | - {-2048, 2047}, | |
1875 | - {-4096, 4095} | |
1876 | -}; | |
1877 | - | |
1878 | -static int | |
1879 | -mpeg2_motion_vector(int mv, int pos, int display_max, int f_code) | |
1880 | -{ | |
1881 | - if (mv + pos * 16 * 2 < 0 || | |
1882 | - mv + (pos + 1) * 16 * 2 > display_max * 2) | |
1883 | - mv = 0; | |
1884 | - | |
1885 | - if (f_code > 0 && f_code < 10) { | |
1886 | - if (mv < mv_ranges[f_code].low) | |
1887 | - mv = mv_ranges[f_code].low; | |
1888 | - | |
1889 | - if (mv > mv_ranges[f_code].high) | |
1890 | - mv = mv_ranges[f_code].high; | |
1891 | - } | |
1892 | - | |
1893 | - return mv; | |
1894 | -} | |
1895 | - | |
1896 | -static int | |
1897 | -gen9_mfc_mpeg2_pak_object_inter(VADriverContextP ctx, | |
1898 | - struct encode_state *encode_state, | |
1899 | - struct intel_encoder_context *encoder_context, | |
1900 | - unsigned int *msg, | |
1901 | - int width_in_mbs, int height_in_mbs, | |
1902 | - int x, int y, | |
1903 | - int first_mb_in_slice, | |
1904 | - int last_mb_in_slice, | |
1905 | - int first_mb_in_slice_group, | |
1906 | - int last_mb_in_slice_group, | |
1907 | - int qp_scale_code, | |
1908 | - unsigned char target_size_in_word, | |
1909 | - unsigned char max_size_in_word, | |
1910 | - struct intel_batchbuffer *batch) | |
1911 | -{ | |
1912 | - VAEncPictureParameterBufferMPEG2 *pic_param = (VAEncPictureParameterBufferMPEG2 *)encode_state->pic_param_ext->buffer; | |
1913 | - int len_in_dwords = 9; | |
1914 | - short *mvptr, mvx0, mvy0, mvx1, mvy1; | |
1915 | - | |
1916 | - if (batch == NULL) | |
1917 | - batch = encoder_context->base.batch; | |
1918 | - | |
1919 | - mvptr = (short *)((unsigned char *)msg + MPEG2_INTER_MV_OFFSET);; | |
1920 | - mvx0 = mpeg2_motion_vector(mvptr[0] / 2, x, width_in_mbs * 16, pic_param->f_code[0][0]); | |
1921 | - mvy0 = mpeg2_motion_vector(mvptr[1] / 2, y, height_in_mbs * 16, pic_param->f_code[0][0]); | |
1922 | - mvx1 = mpeg2_motion_vector(mvptr[2] / 2, x, width_in_mbs * 16, pic_param->f_code[1][0]); | |
1923 | - mvy1 = mpeg2_motion_vector(mvptr[3] / 2, y, height_in_mbs * 16, pic_param->f_code[1][0]); | |
1924 | - | |
1925 | - BEGIN_BCS_BATCH(batch, len_in_dwords); | |
1926 | - | |
1927 | - OUT_BCS_BATCH(batch, MFC_MPEG2_PAK_OBJECT | (len_in_dwords - 2)); | |
1928 | - OUT_BCS_BATCH(batch, | |
1929 | - 2 << 24 | /* PackedMvNum */ | |
1930 | - 7 << 20 | /* MvFormat */ | |
1931 | - 7 << 17 | /* CbpDcY/CbpDcU/CbpDcV */ | |
1932 | - 0 << 15 | /* TransformFlag: frame DCT */ | |
1933 | - 0 << 14 | /* FieldMbFlag */ | |
1934 | - 0 << 13 | /* IntraMbFlag */ | |
1935 | - 1 << 8 | /* MbType: Frame-based */ | |
1936 | - 0 << 2 | /* SkipMbFlag */ | |
1937 | - 0 << 0 | /* InterMbMode */ | |
1938 | - 0); | |
1939 | - OUT_BCS_BATCH(batch, y << 16 | x); | |
1940 | - OUT_BCS_BATCH(batch, | |
1941 | - max_size_in_word << 24 | | |
1942 | - target_size_in_word << 16 | | |
1943 | - 0x3f << 6 | /* CBP */ | |
1944 | - 0); | |
1945 | - OUT_BCS_BATCH(batch, | |
1946 | - last_mb_in_slice << 31 | | |
1947 | - first_mb_in_slice << 30 | | |
1948 | - 0 << 27 | /* EnableCoeffClamp */ | |
1949 | - last_mb_in_slice_group << 26 | | |
1950 | - 0 << 25 | /* MbSkipConvDisable */ | |
1951 | - first_mb_in_slice_group << 24 | | |
1952 | - 0 << 16 | /* MvFieldSelect */ | |
1953 | - qp_scale_code << 0 | | |
1954 | - 0); | |
1955 | - | |
1956 | - OUT_BCS_BATCH(batch, (mvx0 & 0xFFFF) | mvy0 << 16); /* MV[0][0] */ | |
1957 | - OUT_BCS_BATCH(batch, (mvx1 & 0xFFFF) | mvy1 << 16); /* MV[1][0] */ | |
1958 | - OUT_BCS_BATCH(batch, 0); /* MV[0][1] */ | |
1959 | - OUT_BCS_BATCH(batch, 0); /* MV[1][1] */ | |
1960 | - | |
1961 | - ADVANCE_BCS_BATCH(batch); | |
1962 | - | |
1963 | - return len_in_dwords; | |
1964 | -} | |
1965 | - | |
1966 | -static void | |
1967 | -intel_mfc_mpeg2_pipeline_header_programing(VADriverContextP ctx, | |
1968 | - struct encode_state *encode_state, | |
1969 | - struct intel_encoder_context *encoder_context, | |
1970 | - struct intel_batchbuffer *slice_batch) | |
1971 | -{ | |
1972 | - struct gen6_mfc_context *mfc_context = encoder_context->mfc_context; | |
1973 | - int idx = va_enc_packed_type_to_idx(VAEncPackedHeaderMPEG2_SPS); | |
1974 | - | |
1975 | - if (encode_state->packed_header_data[idx]) { | |
1976 | - VAEncPackedHeaderParameterBuffer *param = NULL; | |
1977 | - unsigned int *header_data = (unsigned int *)encode_state->packed_header_data[idx]->buffer; | |
1978 | - unsigned int length_in_bits; | |
1979 | - | |
1980 | - assert(encode_state->packed_header_param[idx]); | |
1981 | - param = (VAEncPackedHeaderParameterBuffer *)encode_state->packed_header_param[idx]->buffer; | |
1982 | - length_in_bits = param->bit_length; | |
1983 | - | |
1984 | - mfc_context->insert_object(ctx, | |
1985 | - encoder_context, | |
1986 | - header_data, | |
1987 | - ALIGN(length_in_bits, 32) >> 5, | |
1988 | - length_in_bits & 0x1f, | |
1989 | - 5, /* FIXME: check it */ | |
1990 | - 0, | |
1991 | - 0, | |
1992 | - 0, /* Needn't insert emulation bytes for MPEG-2 */ | |
1993 | - slice_batch); | |
1994 | - } | |
1995 | - | |
1996 | - idx = va_enc_packed_type_to_idx(VAEncPackedHeaderMPEG2_PPS); | |
1997 | - | |
1998 | - if (encode_state->packed_header_data[idx]) { | |
1999 | - VAEncPackedHeaderParameterBuffer *param = NULL; | |
2000 | - unsigned int *header_data = (unsigned int *)encode_state->packed_header_data[idx]->buffer; | |
2001 | - unsigned int length_in_bits; | |
2002 | - | |
2003 | - assert(encode_state->packed_header_param[idx]); | |
2004 | - param = (VAEncPackedHeaderParameterBuffer *)encode_state->packed_header_param[idx]->buffer; | |
2005 | - length_in_bits = param->bit_length; | |
2006 | - | |
2007 | - mfc_context->insert_object(ctx, | |
2008 | - encoder_context, | |
2009 | - header_data, | |
2010 | - ALIGN(length_in_bits, 32) >> 5, | |
2011 | - length_in_bits & 0x1f, | |
2012 | - 5, /* FIXME: check it */ | |
2013 | - 0, | |
2014 | - 0, | |
2015 | - 0, /* Needn't insert emulation bytes for MPEG-2 */ | |
2016 | - slice_batch); | |
2017 | - } | |
2018 | -} | |
2019 | - | |
2020 | -static void | |
2021 | -gen9_mfc_mpeg2_pipeline_slice_group(VADriverContextP ctx, | |
2022 | - struct encode_state *encode_state, | |
2023 | - struct intel_encoder_context *encoder_context, | |
2024 | - int slice_index, | |
2025 | - VAEncSliceParameterBufferMPEG2 *next_slice_group_param, | |
2026 | - struct intel_batchbuffer *slice_batch) | |
2027 | -{ | |
2028 | - struct gen6_vme_context *vme_context = encoder_context->vme_context; | |
2029 | - struct gen6_mfc_context *mfc_context = encoder_context->mfc_context; | |
2030 | - VAEncSequenceParameterBufferMPEG2 *seq_param = (VAEncSequenceParameterBufferMPEG2 *)encode_state->seq_param_ext->buffer; | |
2031 | - VAEncSliceParameterBufferMPEG2 *slice_param = NULL; | |
2032 | - unsigned char tail_delimiter[] = {MPEG2_DELIMITER0, MPEG2_DELIMITER1, MPEG2_DELIMITER2, MPEG2_DELIMITER3, MPEG2_DELIMITER4, 0, 0, 0}; | |
2033 | - unsigned char section_delimiter[] = {0x0, 0x0, 0x0, 0x0}; | |
2034 | - int width_in_mbs = ALIGN(seq_param->picture_width, 16) / 16; | |
2035 | - int height_in_mbs = ALIGN(seq_param->picture_height, 16) / 16; | |
2036 | - int i, j; | |
2037 | - int h_start_pos, v_start_pos, h_next_start_pos, v_next_start_pos; | |
2038 | - unsigned int *msg = NULL; | |
2039 | - unsigned char *msg_ptr = NULL; | |
2040 | - | |
2041 | - slice_param = (VAEncSliceParameterBufferMPEG2 *)encode_state->slice_params_ext[slice_index]->buffer; | |
2042 | - h_start_pos = slice_param->macroblock_address % width_in_mbs; | |
2043 | - v_start_pos = slice_param->macroblock_address / width_in_mbs; | |
2044 | - assert(h_start_pos + slice_param->num_macroblocks <= width_in_mbs); | |
2045 | - | |
2046 | - dri_bo_map(vme_context->vme_output.bo , 0); | |
2047 | - msg_ptr = (unsigned char *)vme_context->vme_output.bo->virtual; | |
2048 | - | |
2049 | - if (next_slice_group_param) { | |
2050 | - h_next_start_pos = next_slice_group_param->macroblock_address % width_in_mbs; | |
2051 | - v_next_start_pos = next_slice_group_param->macroblock_address / width_in_mbs; | |
2052 | - } else { | |
2053 | - h_next_start_pos = 0; | |
2054 | - v_next_start_pos = height_in_mbs; | |
2055 | - } | |
2056 | - | |
2057 | - gen9_mfc_mpeg2_slicegroup_state(ctx, | |
2058 | - encoder_context, | |
2059 | - h_start_pos, | |
2060 | - v_start_pos, | |
2061 | - h_next_start_pos, | |
2062 | - v_next_start_pos, | |
2063 | - slice_index == 0, | |
2064 | - next_slice_group_param == NULL, | |
2065 | - slice_param->is_intra_slice, | |
2066 | - slice_param->quantiser_scale_code, | |
2067 | - slice_batch); | |
2068 | - | |
2069 | - if (slice_index == 0) | |
2070 | - intel_mfc_mpeg2_pipeline_header_programing(ctx, encode_state, encoder_context, slice_batch); | |
2071 | - | |
2072 | - /* Insert '00' to make sure the header is valid */ | |
2073 | - mfc_context->insert_object(ctx, | |
2074 | - encoder_context, | |
2075 | - (unsigned int*)section_delimiter, | |
2076 | - 1, | |
2077 | - 8, /* 8bits in the last DWORD */ | |
2078 | - 1, /* 1 byte */ | |
2079 | - 1, | |
2080 | - 0, | |
2081 | - 0, | |
2082 | - slice_batch); | |
2083 | - | |
2084 | - for (i = 0; i < encode_state->slice_params_ext[slice_index]->num_elements; i++) { | |
2085 | - /* PAK for each macroblocks */ | |
2086 | - for (j = 0; j < slice_param->num_macroblocks; j++) { | |
2087 | - int h_pos = (slice_param->macroblock_address + j) % width_in_mbs; | |
2088 | - int v_pos = (slice_param->macroblock_address + j) / width_in_mbs; | |
2089 | - int first_mb_in_slice = (j == 0); | |
2090 | - int last_mb_in_slice = (j == slice_param->num_macroblocks - 1); | |
2091 | - int first_mb_in_slice_group = (i == 0 && j == 0); | |
2092 | - int last_mb_in_slice_group = (i == encode_state->slice_params_ext[slice_index]->num_elements - 1 && | |
2093 | - j == slice_param->num_macroblocks - 1); | |
2094 | - | |
2095 | - msg = (unsigned int *)(msg_ptr + (slice_param->macroblock_address + j) * vme_context->vme_output.size_block); | |
2096 | - | |
2097 | - if (slice_param->is_intra_slice) { | |
2098 | - gen9_mfc_mpeg2_pak_object_intra(ctx, | |
2099 | - encoder_context, | |
2100 | - h_pos, v_pos, | |
2101 | - first_mb_in_slice, | |
2102 | - last_mb_in_slice, | |
2103 | - first_mb_in_slice_group, | |
2104 | - last_mb_in_slice_group, | |
2105 | - 0x1a, | |
2106 | - slice_param->quantiser_scale_code, | |
2107 | - 0x3f, | |
2108 | - 0, | |
2109 | - 0xff, | |
2110 | - slice_batch); | |
2111 | - } else { | |
2112 | - int inter_rdo, intra_rdo; | |
2113 | - inter_rdo = msg[AVC_INTER_RDO_OFFSET] & AVC_RDO_MASK; | |
2114 | - intra_rdo = msg[AVC_INTRA_RDO_OFFSET] & AVC_RDO_MASK; | |
2115 | - | |
2116 | - if (intra_rdo < inter_rdo) | |
2117 | - gen9_mfc_mpeg2_pak_object_intra(ctx, | |
2118 | - encoder_context, | |
2119 | - h_pos, v_pos, | |
2120 | - first_mb_in_slice, | |
2121 | - last_mb_in_slice, | |
2122 | - first_mb_in_slice_group, | |
2123 | - last_mb_in_slice_group, | |
2124 | - 0x1a, | |
2125 | - slice_param->quantiser_scale_code, | |
2126 | - 0x3f, | |
2127 | - 0, | |
2128 | - 0xff, | |
2129 | - slice_batch); | |
2130 | - else | |
2131 | - gen9_mfc_mpeg2_pak_object_inter(ctx, | |
2132 | - encode_state, | |
2133 | - encoder_context, | |
2134 | - msg, | |
2135 | - width_in_mbs, height_in_mbs, | |
2136 | - h_pos, v_pos, | |
2137 | - first_mb_in_slice, | |
2138 | - last_mb_in_slice, | |
2139 | - first_mb_in_slice_group, | |
2140 | - last_mb_in_slice_group, | |
2141 | - slice_param->quantiser_scale_code, | |
2142 | - 0, | |
2143 | - 0xff, | |
2144 | - slice_batch); | |
2145 | - } | |
2146 | - } | |
2147 | - | |
2148 | - slice_param++; | |
2149 | - } | |
2150 | - | |
2151 | - dri_bo_unmap(vme_context->vme_output.bo); | |
2152 | - | |
2153 | - /* tail data */ | |
2154 | - if (next_slice_group_param == NULL) { /* end of a picture */ | |
2155 | - mfc_context->insert_object(ctx, | |
2156 | - encoder_context, | |
2157 | - (unsigned int *)tail_delimiter, | |
2158 | - 2, | |
2159 | - 8, /* 8bits in the last DWORD */ | |
2160 | - 5, /* 5 bytes */ | |
2161 | - 1, | |
2162 | - 1, | |
2163 | - 0, | |
2164 | - slice_batch); | |
2165 | - } else { /* end of a lsice group */ | |
2166 | - mfc_context->insert_object(ctx, | |
2167 | - encoder_context, | |
2168 | - (unsigned int *)section_delimiter, | |
2169 | - 1, | |
2170 | - 8, /* 8bits in the last DWORD */ | |
2171 | - 1, /* 1 byte */ | |
2172 | - 1, | |
2173 | - 1, | |
2174 | - 0, | |
2175 | - slice_batch); | |
2176 | - } | |
2177 | -} | |
2178 | - | |
2179 | -/* | |
2180 | - * A batch buffer for all slices, including slice state | |
2181 | - * slice insert object and slice pak object commands | |
2182 | - */ | |
2183 | -static dri_bo * | |
2184 | -gen9_mfc_mpeg2_software_slice_batchbuffer(VADriverContextP ctx, | |
2185 | - struct encode_state *encode_state, | |
2186 | - struct intel_encoder_context *encoder_context) | |
2187 | -{ | |
2188 | - struct gen6_mfc_context *mfc_context = encoder_context->mfc_context; | |
2189 | - struct intel_batchbuffer *batch; | |
2190 | - VAEncSliceParameterBufferMPEG2 *next_slice_group_param = NULL; | |
2191 | - dri_bo *batch_bo; | |
2192 | - int i; | |
2193 | - | |
2194 | - batch = mfc_context->aux_batchbuffer; | |
2195 | - batch_bo = batch->buffer; | |
2196 | - | |
2197 | - for (i = 0; i < encode_state->num_slice_params_ext; i++) { | |
2198 | - if (i == encode_state->num_slice_params_ext - 1) | |
2199 | - next_slice_group_param = NULL; | |
2200 | - else | |
2201 | - next_slice_group_param = (VAEncSliceParameterBufferMPEG2 *)encode_state->slice_params_ext[i + 1]->buffer; | |
2202 | - | |
2203 | - gen9_mfc_mpeg2_pipeline_slice_group(ctx, encode_state, encoder_context, i, next_slice_group_param, batch); | |
2204 | - } | |
2205 | - | |
2206 | - intel_batchbuffer_align(batch, 8); | |
2207 | - | |
2208 | - BEGIN_BCS_BATCH(batch, 2); | |
2209 | - OUT_BCS_BATCH(batch, 0); | |
2210 | - OUT_BCS_BATCH(batch, MI_BATCH_BUFFER_END); | |
2211 | - ADVANCE_BCS_BATCH(batch); | |
2212 | - | |
2213 | - dri_bo_reference(batch_bo); | |
2214 | - intel_batchbuffer_free(batch); | |
2215 | - mfc_context->aux_batchbuffer = NULL; | |
2216 | - | |
2217 | - return batch_bo; | |
2218 | -} | |
2219 | - | |
2220 | -static void | |
2221 | -gen9_mfc_mpeg2_pipeline_picture_programing(VADriverContextP ctx, | |
2222 | - struct encode_state *encode_state, | |
2223 | - struct intel_encoder_context *encoder_context) | |
2224 | -{ | |
2225 | - struct gen6_mfc_context *mfc_context = encoder_context->mfc_context; | |
2226 | - | |
2227 | - mfc_context->pipe_mode_select(ctx, MFX_FORMAT_MPEG2, encoder_context); | |
2228 | - mfc_context->set_surface_state(ctx, encoder_context); | |
2229 | - mfc_context->ind_obj_base_addr_state(ctx, encoder_context); | |
2230 | - gen9_mfc_pipe_buf_addr_state(ctx, encoder_context); | |
2231 | - gen9_mfc_bsp_buf_base_addr_state(ctx, encoder_context); | |
2232 | - gen9_mfc_mpeg2_pic_state(ctx, encoder_context, encode_state); | |
2233 | - gen9_mfc_mpeg2_qm_state(ctx, encoder_context); | |
2234 | - gen9_mfc_mpeg2_fqm_state(ctx, encoder_context); | |
2235 | -} | |
2236 | - | |
2237 | -static void | |
2238 | -gen9_mfc_mpeg2_pipeline_programing(VADriverContextP ctx, | |
2239 | - struct encode_state *encode_state, | |
2240 | - struct intel_encoder_context *encoder_context) | |
2241 | -{ | |
2242 | - struct intel_batchbuffer *batch = encoder_context->base.batch; | |
2243 | - dri_bo *slice_batch_bo; | |
2244 | - | |
2245 | - slice_batch_bo = gen9_mfc_mpeg2_software_slice_batchbuffer(ctx, encode_state, encoder_context); | |
2246 | - | |
2247 | - // begin programing | |
2248 | - intel_batchbuffer_start_atomic_bcs(batch, 0x4000); | |
2249 | - intel_batchbuffer_emit_mi_flush(batch); | |
2250 | - | |
2251 | - // picture level programing | |
2252 | - gen9_mfc_mpeg2_pipeline_picture_programing(ctx, encode_state, encoder_context); | |
2253 | - | |
2254 | - BEGIN_BCS_BATCH(batch, 4); | |
2255 | - OUT_BCS_BATCH(batch, MI_BATCH_BUFFER_START | (1 << 8) | (1 << 0)); | |
2256 | - OUT_BCS_RELOC(batch, | |
2257 | - slice_batch_bo, | |
2258 | - I915_GEM_DOMAIN_COMMAND, 0, | |
2259 | - 0); | |
2260 | - OUT_BCS_BATCH(batch, 0); | |
2261 | - OUT_BCS_BATCH(batch, 0); | |
2262 | - ADVANCE_BCS_BATCH(batch); | |
2263 | - | |
2264 | - // end programing | |
2265 | - intel_batchbuffer_end_atomic(batch); | |
2266 | - | |
2267 | - dri_bo_unreference(slice_batch_bo); | |
2268 | -} | |
2269 | - | |
2270 | -static VAStatus | |
2271 | -intel_mfc_mpeg2_prepare(VADriverContextP ctx, | |
2272 | - struct encode_state *encode_state, | |
2273 | - struct intel_encoder_context *encoder_context) | |
2274 | -{ | |
2275 | - struct gen6_mfc_context *mfc_context = encoder_context->mfc_context; | |
2276 | - struct object_surface *obj_surface; | |
2277 | - struct object_buffer *obj_buffer; | |
2278 | - struct i965_coded_buffer_segment *coded_buffer_segment; | |
2279 | - VAStatus vaStatus = VA_STATUS_SUCCESS; | |
2280 | - dri_bo *bo; | |
2281 | - int i; | |
2282 | - | |
2283 | - /* reconstructed surface */ | |
2284 | - obj_surface = encode_state->reconstructed_object; | |
2285 | - i965_check_alloc_surface_bo(ctx, obj_surface, 1, VA_FOURCC('N','V','1','2'), SUBSAMPLE_YUV420); | |
2286 | - mfc_context->pre_deblocking_output.bo = obj_surface->bo; | |
2287 | - dri_bo_reference(mfc_context->pre_deblocking_output.bo); | |
2288 | - mfc_context->surface_state.width = obj_surface->orig_width; | |
2289 | - mfc_context->surface_state.height = obj_surface->orig_height; | |
2290 | - mfc_context->surface_state.w_pitch = obj_surface->width; | |
2291 | - mfc_context->surface_state.h_pitch = obj_surface->height; | |
2292 | - | |
2293 | - /* forward reference */ | |
2294 | - obj_surface = encode_state->reference_objects[0]; | |
2295 | - | |
2296 | - if (obj_surface && obj_surface->bo) { | |
2297 | - mfc_context->reference_surfaces[0].bo = obj_surface->bo; | |
2298 | - dri_bo_reference(mfc_context->reference_surfaces[0].bo); | |
2299 | - } else | |
2300 | - mfc_context->reference_surfaces[0].bo = NULL; | |
2301 | - | |
2302 | - /* backward reference */ | |
2303 | - obj_surface = encode_state->reference_objects[1]; | |
2304 | - | |
2305 | - if (obj_surface && obj_surface->bo) { | |
2306 | - mfc_context->reference_surfaces[1].bo = obj_surface->bo; | |
2307 | - dri_bo_reference(mfc_context->reference_surfaces[1].bo); | |
2308 | - } else { | |
2309 | - mfc_context->reference_surfaces[1].bo = mfc_context->reference_surfaces[0].bo; | |
2310 | - | |
2311 | - if (mfc_context->reference_surfaces[1].bo) | |
2312 | - dri_bo_reference(mfc_context->reference_surfaces[1].bo); | |
2313 | - } | |
2314 | - | |
2315 | - for (i = 2; i < ARRAY_ELEMS(mfc_context->reference_surfaces); i++) { | |
2316 | - mfc_context->reference_surfaces[i].bo = mfc_context->reference_surfaces[i & 1].bo; | |
2317 | - | |
2318 | - if (mfc_context->reference_surfaces[i].bo) | |
2319 | - dri_bo_reference(mfc_context->reference_surfaces[i].bo); | |
2320 | - } | |
2321 | - | |
2322 | - /* input YUV surface */ | |
2323 | - obj_surface = encode_state->input_yuv_object; | |
2324 | - mfc_context->uncompressed_picture_source.bo = obj_surface->bo; | |
2325 | - dri_bo_reference(mfc_context->uncompressed_picture_source.bo); | |
2326 | - | |
2327 | - /* coded buffer */ | |
2328 | - obj_buffer = encode_state->coded_buf_object; | |
2329 | - bo = obj_buffer->buffer_store->bo; | |
2330 | - mfc_context->mfc_indirect_pak_bse_object.bo = bo; | |
2331 | - mfc_context->mfc_indirect_pak_bse_object.offset = I965_CODEDBUFFER_HEADER_SIZE; | |
2332 | - mfc_context->mfc_indirect_pak_bse_object.end_offset = ALIGN(obj_buffer->size_element - 0x1000, 0x1000); | |
2333 | - dri_bo_reference(mfc_context->mfc_indirect_pak_bse_object.bo); | |
2334 | - | |
2335 | - /* set the internal flag to 0 to indicate the coded size is unknown */ | |
2336 | - dri_bo_map(bo, 1); | |
2337 | - coded_buffer_segment = (struct i965_coded_buffer_segment *)bo->virtual; | |
2338 | - coded_buffer_segment->mapped = 0; | |
2339 | - coded_buffer_segment->codec = encoder_context->codec; | |
2340 | - dri_bo_unmap(bo); | |
2341 | - | |
2342 | - return vaStatus; | |
2343 | -} | |
2344 | - | |
2345 | -static VAStatus | |
2346 | -gen9_mfc_mpeg2_encode_picture(VADriverContextP ctx, | |
2347 | - struct encode_state *encode_state, | |
2348 | - struct intel_encoder_context *encoder_context) | |
2349 | -{ | |
2350 | - gen9_mfc_init(ctx, encode_state, encoder_context); | |
2351 | - intel_mfc_mpeg2_prepare(ctx, encode_state, encoder_context); | |
2352 | - /*Programing bcs pipeline*/ | |
2353 | - gen9_mfc_mpeg2_pipeline_programing(ctx, encode_state, encoder_context); | |
2354 | - gen9_mfc_run(ctx, encode_state, encoder_context); | |
2355 | - | |
2356 | - return VA_STATUS_SUCCESS; | |
2357 | -} | |
2358 | - | |
2359 | 1623 | static void |
2360 | 1624 | gen9_mfc_context_destroy(void *context) |
2361 | 1625 | { |
@@ -2429,12 +1693,6 @@ static VAStatus gen9_mfc_pipeline(VADriverContextP ctx, | ||
2429 | 1693 | vaStatus = gen9_mfc_avc_encode_picture(ctx, encode_state, encoder_context); |
2430 | 1694 | break; |
2431 | 1695 | |
2432 | - /* FIXME: add for other profile */ | |
2433 | - case VAProfileMPEG2Simple: | |
2434 | - case VAProfileMPEG2Main: | |
2435 | - vaStatus = gen9_mfc_mpeg2_encode_picture(ctx, encode_state, encoder_context); | |
2436 | - break; | |
2437 | - | |
2438 | 1696 | default: |
2439 | 1697 | vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE; |
2440 | 1698 | break; |
@@ -2449,14 +1707,13 @@ Bool gen9_mfc_context_init(VADriverContextP ctx, struct intel_encoder_context *e | ||
2449 | 1707 | |
2450 | 1708 | #if MFC_SOFTWARE_HASWELL |
2451 | 1709 | if ((encoder_context->codec == CODEC_H264) || |
2452 | - (encoder_context->codec == CODEC_H264_MVC) || | |
2453 | - (encoder_context->codec == CODEC_MPEG2)) { | |
2454 | - | |
1710 | + (encoder_context->codec == CODEC_H264_MVC)) { | |
2455 | 1711 | return gen8_mfc_context_init(ctx, encoder_context); |
2456 | 1712 | } |
2457 | 1713 | #endif |
2458 | 1714 | |
2459 | - if (encoder_context->codec == CODEC_VP8) | |
1715 | + if ((encoder_context->codec == CODEC_VP8) || | |
1716 | + (encoder_context->codec == CODEC_MPEG2)) | |
2460 | 1717 | return gen8_mfc_context_init(ctx, encoder_context); |
2461 | 1718 | |
2462 | 1719 | mfc_context = calloc(1, sizeof(struct gen6_mfc_context)); |