Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Header file for all AVC intra prediction kernels
  3.  * Copyright © <2010>, Intel Corporation.
  4.  *
  5.  * Permission is hereby granted, free of charge, to any person obtaining a
  6.  * copy of this software and associated documentation files (the
  7.  * "Software"), to deal in the Software without restriction, including
  8.  * without limitation the rights to use, copy, modify, merge, publish,
  9.  * distribute, sub license, and/or sell copies of the Software, and to
  10.  * permit persons to whom the Software is furnished to do so, subject to
  11.  * the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice (including the
  14.  * next paragraph) shall be included in all copies or substantial portions
  15.  * of the Software.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  20.  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
  21.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  22.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  23.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24.  *
  25.  * This file was originally licensed under the following license
  26.  *
  27.  *  Licensed under the Apache License, Version 2.0 (the "License");
  28.  *  you may not use this file except in compliance with the License.
  29.  *  You may obtain a copy of the License at
  30.  *
  31.  *      http://www.apache.org/licenses/LICENSE-2.0
  32.  *
  33.  *  Unless required by applicable law or agreed to in writing, software
  34.  *  distributed under the License is distributed on an "AS IS" BASIS,
  35.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  36.  *  See the License for the specific language governing permissions and
  37.  *  limitations under the License.
  38.  *
  39.  */
  40. #if !defined(__INTRA_HEADER__)  // Make sure this file is only included once
  41. #define __INTRA_HEADER__
  42.  
  43. // Module name: intra_header.inc
  44. //
  45. // Header file for all AVC intra prediction kernels
  46. //
  47. //      This header file defines everything that's specific to intra macroblock kernels
  48.  
  49.  
  50. //  ----------- Various data buffers and pointers ------------
  51. //
  52. //      I_PCM data buffer
  53. //
  54. #define         I_PCM_BUF_Y                     4
  55. #define         I_PCM_BUF_UV            12
  56.  
  57. #define         REG_I_PCM_BUF_Y         r4
  58. #define         REG_I_PCM_BUF_UV        r12
  59.  
  60. .declare    I_PCM_Y  Base=REG_I_PCM_BUF_Y  ElementSize=1 SrcRegion=REGION(16,1) Type=ub // 8-bit I_PCM Y data
  61. .declare    I_PCM_UV Base=REG_I_PCM_BUF_UV ElementSize=1 SrcRegion=REGION(16,1) Type=ub // 8-bit I_PCM U/V data
  62.  
  63. //      Intra macroblock error data blocks
  64. //
  65. #define     ERRBUF              4               // Starting GRF index for error data
  66. #define         REG_ERRBUF      r4
  67. .declare    MBBLOCKW Base=REG_ERRBUF ElementSize=2 SrcRegion=REGION(16,1) Type=w        // For 16-bit inter MB
  68. .declare    MBBLOCKD Base=REG_ERRBUF ElementSize=2 SrcRegion=REGION(16,1) Type=uw       // For use in "send" command
  69.  
  70. #define     PERROR              a0.2    // Pointer to macroblock error data
  71. #define     PERROR1             a0.3    // Pointer to macroblock error data used by instruction compression
  72. #define     PERROR_UD   a0.1    // Pointer to macroblock error data in DWORD unit
  73.  
  74. //      Intra macroblock reference data
  75. //
  76. #define         REG_INTRA_REF_TOP       r49             // Must be an odd numbered GRF register
  77. .declare    INTRA_REF_TOP0              Base=REG_INTRA_REF_TOP   ElementSize=1 SrcRegion=REGION(16,1) Type=ub
  78. .declare    INTRA_REF_TOP               Base=REG_INTRA_REF_TOP.4 ElementSize=1 SrcRegion=REGION(16,1) Type=ub
  79.                                                                                 // Actual top row reference data start at offset 4 in BYTE
  80. .declare    INTRA_REF_TOP_W             Base=REG_INTRA_REF_TOP.2 ElementSize=2 SrcRegion=REGION(16,1) Type=uw
  81.                                                                                 // Actual top row reference data start at offset 2 in WORD
  82. .declare    INTRA_REF_TOP_D             Base=REG_INTRA_REF_TOP ElementSize=4 DstRegion=<1> Type=ud      // Only used in "send" instruction
  83.  
  84. #define         INTRA_REF_LEFT_ID       50
  85. #define         REG_INTRA_REF_LEFT      r50
  86. .declare    INTRA_REF_LEFT0             Base=REG_INTRA_REF_LEFT ElementSize=1 SrcRegion=REGION(8,4) Type=ub
  87. .declare    INTRA_REF_LEFT              Base=REG_INTRA_REF_LEFT.3 ElementSize=1 SrcRegion=REGION(8,4) Type=ub
  88.                                                                                 // Actual left column reference data are located at offset 3 in BYTE
  89. .declare    INTRA_REF_LEFT_UV   Base=REG_INTRA_REF_LEFT.2 ElementSize=1 SrcRegion=REGION(8,4) Type=ub
  90.                                                                                 // Actual left column U/V reference data are located at offset 2 in BYTE
  91. .declare    INTRA_REF_LEFT_W    Base=REG_INTRA_REF_LEFT.1 ElementSize=2 SrcRegion=REGION(8,2) Type=uw
  92.                                                                                 // Actual left column reference data are located at offset 1 in WORD
  93. .declare    INTRA_REF_LEFT_D    Base=REG_INTRA_REF_LEFT ElementSize=4 DstRegion=<1> Type=ud     // Only used in "send" instruction
  94.  
  95. #define         PREF_LEFT               a0.4    // Pointer to left reference data
  96. #define         PREF_LEFT_UD    a0.2    // Pointer in DWORD to left reference data
  97.  
  98. #define         INTRA_TEMP_0    52
  99. #define         INTRA_TEMP_1    53
  100. #define         INTRA_TEMP_2    54
  101. #define         INTRA_TEMP_3    55
  102. #define         INTRA_TEMP_4    56
  103. #define         INTRA_TEMP_5    57
  104. #define         INTRA_TEMP_6    58
  105.  
  106. #define         REG_INTRA_TEMP_0        r52
  107. #define         REG_INTRA_TEMP_1        r53
  108. #define         REG_INTRA_TEMP_2        r54
  109. #define         REG_INTRA_TEMP_3        r55
  110. #define         REG_INTRA_TEMP_4        r56
  111. #define         REG_INTRA_TEMP_5        r57
  112. #define         REG_INTRA_TEMP_6        r58
  113. #define         REG_INTRA_TEMP_7        r59
  114. #define         REG_INTRA_TEMP_8        r60
  115.  
  116. // Destination registers for write commit
  117. #define         REG_WRITE_COMMIT_Y      r60.0
  118. #define         REG_WRITE_COMMIT_UV     r61.0
  119.  
  120. //  ----------- Various data buffers and pointers ------------
  121. //  R32 - R47 for predicted picture buffer (for both Y and U/V blocks)
  122. //
  123. #define     PREDBUF             32              // Starting GRF index for predicted buffer
  124. #define         REG_PREDBUF     r32
  125.  
  126. .declare    PRED_Y              Base=REG_PREDBUF ElementSize=1 SrcRegion=REGION(16,1) Type=ub   // Predicted Y picture
  127. .declare    PRED_YW             Base=REG_PREDBUF ElementSize=2 SrcRegion=REGION(16,1) Type=uw   // Predicted Y picture stored in WORD
  128. .declare    PRED_Y_FM   Base=REG_PREDBUF ElementSize=1 SrcRegion=REGION(16,1) Type=ub   // Predicted Y picture frame
  129. .declare    PRED_Y_TF   Base=REG_PREDBUF ElementSize=1 SrcRegion=REGION(16,1) Type=ub   // Predicted Y picture Top field
  130.  
  131. .declare    PRED_UV             Base=REG_PREDBUF ElementSize=1 SrcRegion=REGION(16,1) Type=ub   // Predicted U/V picture
  132. .declare    PRED_UVW    Base=REG_PREDBUF ElementSize=2 SrcRegion=REGION(16,1) Type=uw   // Predicted U/V picture stored in WORD
  133. .declare    PRED_UV_FM  Base=REG_PREDBUF ElementSize=1 SrcRegion=REGION(16,1) Type=ub   // Predicted U/V picture frame
  134. .declare    PRED_UV_TF  Base=REG_PREDBUF ElementSize=1 SrcRegion=REGION(16,1) Type=ub   // Predicted U/V picture top field
  135. .declare    PRED_UV_BF  Base=REG_PREDBUF.16 ElementSize=1 SrcRegion=REGION(16,1) Type=ub        // Predicted U/V picture bottom field
  136.  
  137. //  The same region will also be used as finally decoded Y blocks shared with U/V blocks
  138. //
  139. #define     DECBUF              32
  140. #define         REG_DECBUF      r32
  141. .declare    DEC_Y               Base=REG_DECBUF ElementSize=1 SrcRegion=REGION(16,1) Type=ub    // Decoded Y picture
  142. .declare    DEC_UV              Base=REG_DECBUF ElementSize=1 SrcRegion=REGION(16,1) Type=ub    // Decoded U/V P-/B-picture
  143. .declare    DEC_UD              Base=REG_DECBUF ElementSize=4 SrcRegion=REGION(8,1) Type=ud             // Decoded buffer in UD type
  144.  
  145. //      Reference buffer for intra_NxN prediction
  146. //
  147. #define         PRED_MODE       REG_INTRA_TEMP_0
  148. .declare    REF_TOP0    Base=REG_INTRA_TEMP_5   ElementSize=1 SrcRegion=REGION(16,1) Type=ub
  149. .declare    REF_TOP             Base=REG_INTRA_TEMP_5.4 ElementSize=1 SrcRegion=REGION(16,1) Type=ub
  150.                                                                         // Actual top reference data start from offset 3,i.e. p[-1,-1]
  151. .declare    REF_TOP_W   Base=REG_INTRA_TEMP_5 ElementSize=2 SrcRegion=REGION(16,1) Type=uw
  152. .declare    REF_TOP_D   Base=REG_INTRA_TEMP_5 ElementSize=4 SrcRegion=REGION(8,1) Type=ud
  153. .declare    REF_LEFT    Base=REG_INTRA_TEMP_6 ElementSize=1 SrcRegion=REGION(16,1) Type=ub
  154. .declare    REF_LEFT_D  Base=REG_INTRA_TEMP_6 ElementSize=4 SrcRegion=REGION(8,1) Type=ud
  155.  
  156. // For intra prediction plane mode
  157. //
  158. .declare    H1  Base=REG_INTRA_TEMP_0 ElementSize=2 SrcRegion=REGION(8,1) Type=w        // Make sure it's an even GRF
  159. .declare    H2  Base=REG_INTRA_TEMP_0.8 ElementSize=2 SrcRegion=REGION(8,1) Type=w
  160. .declare    V1  Base=REG_INTRA_TEMP_1 ElementSize=2 SrcRegion=REGION(8,1) Type=w        // Make sure it's the following odd GRF
  161. .declare    V2  Base=REG_INTRA_TEMP_1.8 ElementSize=2 SrcRegion=REGION(8,1) Type=w
  162.  
  163. .declare        CP      Base=REG_INTRA_TEMP_2 ElementSize=2 SrcRegion=REGION(16,1) Type=w
  164.  
  165. #define         PINTRAPRED_Y    a0.7    // Used as luma intra prediction mode pointer
  166. #define         PINTRAPRED_UV   a0.7    // Used as chroma intra prediction mode pointer
  167. #define         PINTRA4X4_Y             a0.4    // Used as luma intra_4x4 prediction mode pointer
  168.  
  169. #define         PBWDCOPY_4              a0.4    // a0.4 - a0.7 used in intra_4x4 prediction for moving data backward
  170. #define         PBWDCOPY_8              a0.6    // a0.6 - a0.7 used in intra_8x8 prediction for moving data backward
  171.  
  172. // For Intra_4x4 prediction mode
  173. //
  174. .declare    INTRA_4X4_MODE      Base=REG_INTRA_TEMP_1 ElementSize=4 SrcRegion=REGION(1,0) DstRegion=<1> Type=d  // Actually only need 1 DWORD
  175.  
  176. //  ----------- Intra CURBE constants ------------
  177. //
  178. #define         REG_CURBE1      r1
  179. #define         REG_CURBE2      r2
  180. #define         INTRA_4X4_OFFSET        1*GRFWIB                // 9 Bytes
  181. #define         INTRA_8X8_OFFSET        1*GRFWIB+12             // 9 Bytes starting sub-register r1.3:ud
  182. #define         INTRA_16X16_OFFSET      1*GRFWIB+24             // 4 Bytes starting sub-register r1.6:ud
  183. #define         INTRA_CHROMA_OFFSET     1*GRFWIB+28             // 4 Bytes starting sub-register r1.7:ud
  184.  
  185. #define         TOP_REF_OFFSET          REG_CURBE1.10   // r1.5:w
  186.  
  187. //      Constants used in plane intra prediction mode
  188. #define         XY_3    REG_CURBE2.4    // Stored BYTE constants x-3 for x=0...7, i.e. -3,-2,...3,4 for U/V, need duplicate to every other byte
  189. #define         XY_3_1  REG_CURBE2.5    // Stored BYTE constants x-3 for x=0...7, i.e. -3,-2,...3,4 for 2nd instruction in {Comp}
  190. #define         XY_7    REG_CURBE2.0    // Stored BYTE constants x-7 for x=0...15, i.e. -7,-6,...7,8 for Y
  191. #define         XY_7_1  REG_CURBE2.1    // Stored BYTE constants x-7 for x=0...15, i.e. -7,-6,...7,8 for 2nd instruction in {Comp}
  192.  
  193. #define         INV_SHIFT       REG_CURBE2.16
  194.  
  195. #define         INV_TRANS4      REG_CURBE2.20   // For reverse data transfer for intra_4x4 (0x00020406)
  196. #define         INV_TRANS48     REG_CURBE2.22   // For reverse data transfer for intra_4x4 (0x0002)
  197. #define         INV_TRANS8      REG_CURBE1.22   // For reverse data transfer for intra_8x8 (0x0001)
  198.  
  199. #define         INTRA_MODE      REG_CURBE2.24   // Offset to intra_Pred_4x4_Y from each sub-block
  200.  
  201. //  ----------- In-line parameters ------------
  202. //
  203. #define REG_INLINE      r3
  204.  
  205. #define INLINE_DW0      REG_INLINE.0<0;1,0>:ud
  206. #define INLINE_DW1      REG_INLINE.1<0;1,0>:ud
  207. #define INLINE_DW2      REG_INLINE.2<0;1,0>:ud
  208. #define INLINE_DW3      REG_INLINE.3<0;1,0>:ud
  209. #define INLINE_DW4      REG_INLINE.4<0;1,0>:ud
  210. #define INLINE_DW5      REG_INLINE.5<0;1,0>:ud
  211. #define INLINE_DW6      REG_INLINE.6<0;1,0>:ud
  212. #define INLINE_DW7      REG_INLINE.7<0;1,0>:ud
  213.  
  214. //      Intra macroblock in-line data
  215. //
  216. //      In-line DWORD 0
  217. #define REG_MBAFF_FIELD                         REG_INLINE.1    // :uw, can be added directly to lower-word of MSGDSC
  218. #define MBAFF_FIELD                                     BIT26+BIT25             // Bits 26:25 - MBAFF field macroblock flag
  219.                                                                                                         //  00 = Current macroblock is not an MBAFF field macroblock
  220.                                                                                                         //  11 = Current macroblock is an MBAFF field macroblock
  221.  
  222. #define REG_FIELD_PARITY                        INLINE_DW0
  223. #define FIELD_PARITY                            BIT24                   // Bit 24 - Macroblock field parity flag
  224.                                                                                                         //  0 = Current field is a top field
  225.                                                                                                         //  1 = Current field is a bottom field
  226.  
  227. #define REG_FIELD_MACROBLOCK_FLAG       INLINE_DW0
  228. #define FIELD_MACROBLOCK_FLAG           BIT14                   // Bit 14 - Field macroblock flag
  229.                                                                                                         //  0 = Current macroblock is not a field macroblock
  230.                                                                                                         //  1 = Current macroblock is a field macroblock
  231. #define REG_MACROBLOCK_TYPE                     INLINE_DW0
  232. #define MACROBLOCK_TYPE                         BIT12+BIT11+BIT10+BIT9+BIT8             // Bit 12:8 - Intra macroblock flag
  233.  
  234. #define REG_CHROMA_FORMAT_IDC           INLINE_DW0
  235. #define CHROMA_FORMAT_IDC                       BIT3+BIT2               // Bit 3:2 - Chroma format
  236.                                                                                                         // 00 = Luma only (Monochrome)
  237.                                                                                                         // 01 = YUV420
  238.                                                                                                         // 10 = YUV422
  239.                                                                                                         // 11 = YUV444
  240. #define REG_MBAFF_PIC                           INLINE_DW0
  241. #define MBAFF_PIC                                       BIT1                    // Bit 1 - MBAFF Frame picture
  242.                                                                                                         // 0 = Not an MBAFF frame picture
  243.                                                                                                         // 1 = An MBAFF frame picture
  244. #define REG_INTRA_PRED_8X8_BLK2_AVAIL_FLAG      INLINE_DW0
  245. #define INTRA_PRED_8X8_BLK2_AVAIL_FLAG  BIT4            // Bit 4: Pixel available for block 2 in an intra_8x8 MB.
  246.  
  247. //      In-line DWORD 1
  248. #define ORIX                    REG_INLINE.4    // :ub, H. origin of the macroblock in macroblock unit
  249. #define ORIY                    REG_INLINE.5    // :ub, V. origin of the macroblock in macroblock unit
  250.  
  251. //      In-line DWORD 2
  252. #define REG_CBPCYB                                      REG_INLINE.9    // :ub, Coded block pattern
  253. #define REG_CBPCY                                       INLINE_DW2              // Bits 13:8 - Coded block pattern
  254.                                                                                                         // reflect Y0, Y1, Y2, Y3, Cb4, Cr5
  255.                                                                                                         // Bit 13 - Y0
  256.                                                                                                         // Bit 12 - Y1
  257.                                                                                                         // Bit 11 - Y2
  258.                                                                                                         // Bit 10 - Y3
  259.                                                                                                         // Bit 9 - U4
  260.                                                                                                         // Bit 8 - V5
  261. #define CBP_MASK                                        0x3F00:ud               // Bit mask for all CBP bits
  262. #define CBP_Y_MASK                                      0x3C00:ud               // Bit mask for CBP Y bits
  263. #define CBP_UV_MASK                                     0x0300:ud               // Bit mask for CBP U/V bits
  264.  
  265. #define CBP_Y0_MASK                                     BIT13:ud                // Bit mask for CBP Y0 bit
  266. #define CBP_Y1_MASK                                     BIT12:ud                // Bit mask for CBP Y1 bit
  267. #define CBP_Y2_MASK                                     BIT11:ud                // Bit mask for CBP Y2 bit
  268. #define CBP_Y3_MASK                                     BIT10:ud                // Bit mask for CBP Y3 bit
  269. #define CBP_U_MASK                                      BIT9:ud                 // Bit mask for CBP U bit
  270. #define CBP_V_MASK                                      BIT8:ud                 // Bit mask for CBP V bit
  271.  
  272. //      In-line DWORD 3
  273. #define REG_INTRA_CHROMA_PRED_MODE      REG_INLINE.12   // :ub - Intra chroma prediction mode
  274. #define INTRA_CHROMA_PRED_MODE          BIT7+BIT6               // Bit 7:6 - Intra chroma prediction mode
  275.                                                                                                         // 00 = Intra DC prediction
  276.                                                                                                         // 01 = Intra horizontal prediction
  277.                                                                                                         // 10 = Intra vertical prediction
  278.                                                                                                         // 11 = Intra plane prediction
  279. #define INTRA_CHROMA_PRED_MODE_SHIFT    6                       // Intra chroma prediction mode shift
  280.  
  281. #define REG_INTRA_PRED_AVAIL_FLAG       INLINE_DW3
  282. #define INTRA_PRED_AVAIL_FLAG           BIT4+BIT3+BIT2+BIT1+BIT0        // Bits 4:0 - Intra prediction available flag
  283.                                                                                                         // Bit 0: Macroblock A (the left neighbor) entire or top half
  284.                                                                                                         // Bit 1: Macroblock B (the upper neighbor)
  285.                                                                                                         // Bit 2: Macroblock C (the above-right neighbor)
  286.                                                                                                         // Bit 3: Macroblock D (the above-left neighbor)
  287.                                                                                                         // Bit 4: Macroblock A (the left neighbor) bottom half
  288.                                                                                                         // Each bit is defined below
  289.                                                                                                         // 0 = The macroblock is not available for intra prediction
  290.                                                                                                         // 1 = The macroblock is available for intra prediction
  291. #define INTRA_PRED_LEFT_TH_AVAIL_FLAG   BIT0            // Bit 0: Macroblock A (the left neighbor) entire or top half
  292. #define INTRA_PRED_UP_AVAIL_FLAG                BIT1            // Bit 1: Macroblock B (the upper neighbor)
  293. #define INTRA_PRED_UP_RIGHT_AVAIL_FLAG  BIT2            // Bit 2: Macroblock C (the above-right neighbor)
  294. #define INTRA_PRED_UP_LEFT_AVAIL_FLAG   BIT3            // Bit 3: Macroblock D (the above-left neighbor)
  295. #define INTRA_PRED_LEFT_BH_AVAIL_FLAG   BIT4            // Bit 4: Macroblock A (the left neighbor) bottom half
  296. //#define INTRA_PRED_8X8_BLK2_AVAIL_FLAG        BIT5            // Bit 5: Pixel available for block 2 in an intra_8x8 MB.
  297. #define REG_INTRA_PRED_AVAIL_FLAG_BYTE  REG_INLINE.12   // Byte location of Intra_Pred_Avail_Flag
  298. #define REG_INTRA_PRED_AVAIL_FLAG_WORD  REG_INLINE.6    // Word location of Intra_Pred_Avail_Flag
  299.  
  300.  
  301. .declare    INTRA_PRED_MODE  Base=REG_INLINE.16 ElementSize=1 SrcRegion=REGION(16,1) Type=ub    // Intra prediction mode
  302.  
  303. // End of intra_header.inc
  304.  
  305. #endif  // !defined(__INTRA_HEADER__)
  306.  
  307.