1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
|
/*
* Copyright (c) 2011 Intel Corporation. All Rights Reserved.
* Copyright (c) Imagination Technologies Limited, UK
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Authors:
* Zeng Li <zeng.li@intel.com>
*
*/
#include "psb_cmdbuf.h"
#include <unistd.h>
#include <stdio.h>
#include "hwdefs/mem_io.h"
#include "hwdefs/msvdx_offsets.h"
#include "hwdefs/reg_io2.h"
#include "hwdefs/msvdx_vec_reg_io2.h"
#include "hwdefs/msvdx_vdmc_reg_io2.h"
#include "hwdefs/msvdx_mtx_reg_io2.h"
#include "hwdefs/msvdx_dmac_linked_list.h"
#include "hwdefs/msvdx_rendec_mtx_slice_cntrl_reg_io2.h"
#include "hwdefs/msvdx_core_regs_io2.h"
#include "hwdefs/h264_macroblock_mem_io.h"
#include "hwdefs/dxva_cmdseq_msg.h"
#include "hwdefs/dxva_fw_ctrl.h"
#include "hwdefs/fwrk_msg_mem_io.h"
#include "hwdefs/dxva_msg.h"
#include "hwdefs/msvdx_cmds_io2.h"
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "psb_def.h"
#define H264_MACROBLOCK_DATA_SIZE 0x80
#define MSVDX_CMDS_BASE 0x1000
#define MSVDX_CORE_BASE 0x600
#define MSVDX_VEC_BASE 0x800
#define MSVDX_DEBLOCK_REG_SET 0x10000000
#define MSVDX_DEBLOCK_REG_GET 0x20000000
#define MSVDX_DEBLOCK_REG_POLLn 0x30000000
#define MSVDX_DEBLOCK_REG_POLLx 0x40000000
static int reg_set_count = 0;
static int reg_get_count = 0;
static int reg_poll_x = 0;
static int reg_poll_n = 0;
#define psb_deblock_reg_set(group, reg, value) \
*cmdbuf->regio_idx++ = (group##_##reg##_##OFFSET + group##_##BASE) | MSVDX_DEBLOCK_REG_SET; \
*cmdbuf->regio_idx++ = value; reg_set_count++;
#define psb_deblock_reg_set_RELOC( group, reg, buffer, buffer_offset, dst) \
*cmdbuf->regio_idx++ = (group##_##reg##_##OFFSET + group##_##BASE) | MSVDX_DEBLOCK_REG_SET; \
RELOC_REGIO(*cmdbuf->regio_idx++, buffer_offset, buffer, dst); reg_set_count++;
#define psb_deblock_reg_table_set(group, reg, index, value) \
*cmdbuf->regio_idx++ = ( (group##_##reg##_OFFSET + group##_##BASE + index*group##_##reg##_STRIDE) | MSVDX_DEBLOCK_REG_SET); \
*cmdbuf->regio_idx++ = value; reg_set_count++;
#define psb_deblock_reg_get(group, reg) \
*cmdbuf->regio_idx++ = (group##_##reg##_##OFFSET + group##_##BASE) | MSVDX_DEBLOCK_REG_GET; reg_get_count++;
#if 1
#define h264_pollForSpaceForNCommands(NumCommands)\
*cmdbuf->regio_idx++ = (MSVDX_CORE_CR_MSVDX_COMMAND_SPACE_OFFSET + MSVDX_CORE_BASE) | MSVDX_DEBLOCK_REG_POLLn; \
*cmdbuf->regio_idx++ = NumCommands; reg_poll_n++;
#else
#define h264_pollForSpaceForNCommands(NumCommands) /* Seems not needed, so just define it null */
#endif
#define PollForSpaceForXCommands \
*cmdbuf->regio_idx++ = (MSVDX_CORE_CR_MSVDX_COMMAND_SPACE_OFFSET + MSVDX_CORE_BASE) | MSVDX_DEBLOCK_REG_POLLx; reg_poll_x++;
typedef enum {
H264_BLOCKSIZE_16X16 = 0, /* 1 block */
H264_BLOCKSIZE_16X8 = 1, /* 2 blocks */
H264_BLOCKSIZE_8X16 = 2,
H264_BLOCKSIZE_8X8 = 3, /* 4 blocks */
H264_BLOCKSIZE_8X4 = 4,
H264_BLOCKSIZE_4X8 = 5,
H264_BLOCKSIZE_4X4 = 6
} h264_eBlockSize;
static uint32_t BlockDownsizeMap[] = {
1, 1, 3, 3, 3, 5, 5
};
static uint32_t BlocksToSendMap[] = {
1, 2, 2, 4, 4, 4, 4
};
static uint32_t BlockAddressMap[7][4] = {
{ 0 }, /* 16x16 */
{ 0, 2 }, /* 16x8 */
{ 0, 1 }, /* 8x16 */
{ 0, 1, 2, 3 }, /* 8x8 */
{ 0, 1, 2, 3 }, /* 8x4 */
{ 0, 1, 2, 3 }, /* 4x8 */
{ 0, 1, 2, 3 } /* 4x4 */
};
static uint32_t VectorsToSendMap[] = {
1, 1, 1, 1, 2, 2, 4
};
static uint32_t VectorOffsetMap[7][4] = {
{ 0 }, /* 16x16 */
{ 0 }, /* 16x8 */
{ 0 }, /* 8x16 */
{ 0 }, /* 8x8 */
{ 0, 2 }, /* 8x4 */
{ 0, 1 }, /* 4x8 */
{ 0, 1, 2, 3 } /* 4x4 */
};
static uint32_t Above1AboveTileMap[] = {
/* 9, 12, 8, 13 */
13, 12, 9, 8
};
static uint32_t CurrentAboveTileMap[] = {
/* 11, 14, 10, 15 */
15, 14, 11, 10
};
static uint32_t CurrentColTileMap[] = {
10, 15, 0, 5, 8, 13, 2, 7, 1, 4, 3, 6, 9, 12
};
static uint32_t ColBlockMap[] = {
2, 3, 0, 1
};
void
h264_above1InterBlockSequence(psb_cmdbuf_p cmdbuf, uint8_t* MbData)
{
uint32_t i, BlockNum, Mv, MvAddr, Value;
uint32_t Block8x8, blockType;
uint32_t InterBlockCmd;
uint32_t MotionVecCmd[16];
uint32_t BlockType[4] = {0};
uint32_t DpbIdx[4];
/* set MV vars to 0 */
for (i = 0; i < 16; i++) {
MotionVecCmd[i] = 0;
}
/* Read the size of blocks 2 and 3 and resize them so they are all ?x8 */
Value = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_ASO_BLOCK2_PREDICTION_SIZE);
if (Value > (sizeof(BlockDownsizeMap) / sizeof(uint32_t) - 1))
Value = sizeof(BlockDownsizeMap) / sizeof(uint32_t) - 1;
BlockType[2] = BlockDownsizeMap[Value];
Value = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_ASO_BLOCK3_PREDICTION_SIZE);
if (Value > (sizeof(BlockDownsizeMap) / sizeof(uint32_t) - 1))
Value = sizeof(BlockDownsizeMap) / sizeof(uint32_t) - 1;
BlockType[3] = BlockDownsizeMap[Value];
/* read motion vectors for the bottom row, but store them in the correct locn. for ?x8 blocks */
for (i = 0; i < 4; i++) {
Value = MEMIO_READ_TABLE_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_COMP_X_ABOVE, i);
REGIO_WRITE_FIELD(MotionVecCmd[Above1AboveTileMap[i]], MSVDX_CMDS, MOTION_VECTOR, MV_X, Value);
Value = MEMIO_READ_TABLE_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_COMP_Y_ABOVE, i);
REGIO_WRITE_FIELD(MotionVecCmd[Above1AboveTileMap[i]], MSVDX_CMDS, MOTION_VECTOR, MV_Y, Value);
}
/* read DPB index for blocks 2 and 3 */
for (i = 0; i < 2; i++) {
DpbIdx[ColBlockMap[i]] = MEMIO_READ_TABLE_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_DPB_IDX_COL, i);
}
/* Send commands required blocks */
for (BlockNum = BlocksToSendMap[BlockType[2]] / 2;
BlockNum < BlocksToSendMap[BlockType[2]];
BlockNum++) {
/* block address */
Block8x8 = BlockAddressMap[BlockType[2]][BlockNum];
/* block type */
blockType = BlockType[Block8x8];
InterBlockCmd = 0;
REGIO_WRITE_FIELD(InterBlockCmd, MSVDX_CMDS, INTER_BLOCK_PREDICTION, INTER_PRED_BLOCK_SIZE, blockType);
REGIO_WRITE_FIELD(InterBlockCmd, MSVDX_CMDS, INTER_BLOCK_PREDICTION, REF_INDEX_A_VALID, 1);
REGIO_WRITE_FIELD(InterBlockCmd, MSVDX_CMDS, INTER_BLOCK_PREDICTION, REF_INDEX_A, DpbIdx[Block8x8]);
/* send commands */
h264_pollForSpaceForNCommands(1 + VectorsToSendMap[blockType]);
psb_deblock_reg_table_set(MSVDX_CMDS, INTER_BLOCK_PREDICTION_ABOVE1, Block8x8, InterBlockCmd);
for (i = 0; i < VectorsToSendMap[blockType]; i++) {
/* only send forward MVs in baseline */
MvAddr = (2 * 4 * Block8x8) + VectorOffsetMap[blockType][i];
Mv = (4 * Block8x8) + VectorOffsetMap[blockType][i];
psb_deblock_reg_table_set(MSVDX_CMDS, MOTION_VECTOR_ABOVE1, MvAddr, MotionVecCmd[Mv]);
}
}
}
void
h264_currentInterBlockSequence(psb_cmdbuf_p cmdbuf, uint8_t * MbData)
{
uint32_t i, BlockNum, Mv, MvAddr, Value;
uint32_t Block8x8, blockType;
uint32_t InterBlockCmd;
uint32_t MotionVecCmd[16];
uint32_t BlockType[4];
uint32_t DpbIdx[4];
/* set MV vars to 0 */
for (i = 0; i < 16; i++) {
MotionVecCmd[i] = 0;
}
/* read block size */
BlockType[0] = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_ASO_BLOCK0_PREDICTION_SIZE);
BlockType[1] = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_ASO_BLOCK1_PREDICTION_SIZE);
BlockType[2] = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_ASO_BLOCK2_PREDICTION_SIZE);
BlockType[3] = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_ASO_BLOCK3_PREDICTION_SIZE);
/* read motion vectors in all 16 4x4 sub-blocks*/
for (i = 1; i < 3; i++) { /* get blocks 11 and 14 */
Value = MEMIO_READ_TABLE_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_COMP_X_ABOVE, i);
REGIO_WRITE_FIELD(MotionVecCmd[CurrentAboveTileMap[i]], MSVDX_CMDS, MOTION_VECTOR, MV_X, Value);
Value = MEMIO_READ_TABLE_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_COMP_Y_ABOVE, i);
REGIO_WRITE_FIELD(MotionVecCmd[CurrentAboveTileMap[i]], MSVDX_CMDS, MOTION_VECTOR, MV_Y, Value);
}
for (i = 0; i < 14; i++) {
Value = MEMIO_READ_TABLE_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_COMP_X_COL, i);
REGIO_WRITE_FIELD(MotionVecCmd[CurrentColTileMap[i]], MSVDX_CMDS, MOTION_VECTOR, MV_X, Value);
Value = MEMIO_READ_TABLE_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_COMP_Y_COL, i);
REGIO_WRITE_FIELD(MotionVecCmd[CurrentColTileMap[i]], MSVDX_CMDS, MOTION_VECTOR, MV_Y, Value);
}
/* read DPB index for all 4 blocks */
for (i = 0; i < 4; i++) {
DpbIdx[ColBlockMap[i]] = MEMIO_READ_TABLE_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_DPB_IDX_COL, i);
}
/* Send commands required blocks */
for (BlockNum = 0;
BlockNum < BlocksToSendMap[BlockType[0]];
BlockNum++) {
/* block address */
Block8x8 = BlockAddressMap[BlockType[0]][BlockNum];
/* block type */
blockType = BlockType[Block8x8];
InterBlockCmd = 0;
REGIO_WRITE_FIELD(InterBlockCmd, MSVDX_CMDS, INTER_BLOCK_PREDICTION, INTER_PRED_BLOCK_SIZE, blockType);
REGIO_WRITE_FIELD(InterBlockCmd, MSVDX_CMDS, INTER_BLOCK_PREDICTION, REF_INDEX_A_VALID, 1);
REGIO_WRITE_FIELD(InterBlockCmd, MSVDX_CMDS, INTER_BLOCK_PREDICTION, REF_INDEX_A, DpbIdx[Block8x8]);
/* send commands */
h264_pollForSpaceForNCommands(1 + VectorsToSendMap[blockType]);
psb_deblock_reg_table_set(MSVDX_CMDS, INTER_BLOCK_PREDICTION, Block8x8, InterBlockCmd);
for (i = 0; i < VectorsToSendMap[blockType]; i++) {
/* only send forward MVs in baseline */
MvAddr = (2 * 4 * Block8x8) + VectorOffsetMap[blockType][i];
Mv = (4 * Block8x8) + VectorOffsetMap[blockType][i];
psb_deblock_reg_table_set(MSVDX_CMDS, MOTION_VECTOR, MvAddr, MotionVecCmd[Mv]);
}
}
}
void
h264_currentIntraBlockPrediction(psb_cmdbuf_p cmdbuf, uint8_t * MbData, int bMbIsIPCM)
{
uint32_t BlockSizeY, BlockSizeC;
uint32_t IntraCmdY, IntraCmdC;
/* select block size I_PCM or I_16x16 */
BlockSizeY = (1 == bMbIsIPCM) ? 3 : 0;
/* select block size I_PCM or I_8x8 */
BlockSizeC = (1 == bMbIsIPCM) ? 3 : 1;
IntraCmdY = IntraCmdC = 0;
REGIO_WRITE_FIELD(
IntraCmdY,
MSVDX_CMDS, INTRA_BLOCK_PREDICTION,
INTRA_PRED_BLOCK_SIZE,
BlockSizeY);
REGIO_WRITE_FIELD(
IntraCmdC,
MSVDX_CMDS, INTRA_BLOCK_PREDICTION,
INTRA_PRED_BLOCK_SIZE,
BlockSizeC);
h264_pollForSpaceForNCommands(2);
psb_deblock_reg_table_set(MSVDX_CMDS, INTRA_BLOCK_PREDICTION, 0, IntraCmdY);
psb_deblock_reg_table_set(MSVDX_CMDS, INTRA_BLOCK_PREDICTION, 4, IntraCmdC);
}
void
h264_above1IntraBlockPrediction(psb_cmdbuf_p cmdbuf, uint8_t * MbData, int bMbIsIPCM)
{
uint32_t BlockSizeY;
uint32_t IntraCmdY;
/* select block size I_PCM or I_16x16 */
BlockSizeY = (1 == bMbIsIPCM) ? 3 : 0;
IntraCmdY = 0;
REGIO_WRITE_FIELD(
IntraCmdY,
MSVDX_CMDS, INTRA_BLOCK_PREDICTION_ABOVE1,
INTRA_PRED_BLOCK_SIZE_ABOVE1,
BlockSizeY);
h264_pollForSpaceForNCommands(1);
psb_deblock_reg_table_set(MSVDX_CMDS, INTRA_BLOCK_PREDICTION_ABOVE1, 0, IntraCmdY);
}
void
h264_macroblockCmdSequence(psb_cmdbuf_p cmdbuf, uint8_t * MbData, uint32_t X, uint32_t Y, int bCurrent)
{
int bMbIsIPCM;
uint32_t MbType;
uint32_t Value;
uint32_t MbNumberCmd, MbQuantCmd, MbTransZeroCmd;
/* Macroblock Type */
MbType = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_MBTYPE);
/* Macroblock Number */
/* no need for MB_ERROR_FLAG as error info is not stored */
/* no need for MB_FIELD_CODE as basline is always frame based */
MbNumberCmd = 0;
Value = (3 == MbType) ? 0 : MbType;
REGIO_WRITE_FIELD(MbNumberCmd, MSVDX_CMDS, MACROBLOCK_NUMBER, MB_CODE_TYPE, Value);
REGIO_WRITE_FIELD(MbNumberCmd, MSVDX_CMDS, MACROBLOCK_NUMBER, MB_NO_Y, Y);
REGIO_WRITE_FIELD(MbNumberCmd, MSVDX_CMDS, MACROBLOCK_NUMBER, MB_NO_X, X);
/* H264 Quant */
/* TRANSFORM_SIZE_8X8 always false in basline */
MbQuantCmd = 0;
Value = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_QP_CR);
REGIO_WRITE_FIELD(MbQuantCmd, MSVDX_CMDS, MACROBLOCK_H264_QUANT, MB_QUANT_CHROMA_CR, Value);
Value = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_QP_CB);
REGIO_WRITE_FIELD(MbQuantCmd, MSVDX_CMDS, MACROBLOCK_H264_QUANT, MB_QUANT_CHROMA_CB, Value);
Value = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_QP);
REGIO_WRITE_FIELD(MbQuantCmd, MSVDX_CMDS, MACROBLOCK_H264_QUANT, MB_QUANT_LUMA, Value);
/* send 2 commands */
h264_pollForSpaceForNCommands(2);
if (1 == bCurrent) {
/* Top and Left available flags are only sent for current MB */
Value = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_MB_AVAILABLE_TOP_FLAG);
Value = (1 == Value) ? 0 : 1;
REGIO_WRITE_FIELD(MbNumberCmd, MSVDX_CMDS, MACROBLOCK_NUMBER, MB_SLICE_TOP, Value);
Value = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_MB_AVAILABLE_LEFT_FLAG);
Value = (1 == Value) ? 0 : 1;
REGIO_WRITE_FIELD(MbNumberCmd, MSVDX_CMDS, MACROBLOCK_NUMBER, MB_SLICE_LHS, Value);
psb_deblock_reg_set(MSVDX_CMDS, MACROBLOCK_NUMBER, MbNumberCmd);
psb_deblock_reg_set(MSVDX_CMDS, MACROBLOCK_H264_QUANT, MbQuantCmd);
} else {
psb_deblock_reg_set(MSVDX_CMDS, MACROBLOCK_NUMBER_ABOVE1, MbNumberCmd);
psb_deblock_reg_set(MSVDX_CMDS, MACROBLOCK_H264_QUANT_ABOVE1, MbQuantCmd);
}
/* Prediction Block Sequence */
bMbIsIPCM = 0;
switch (MbType) {
case 3: /* IPCM */
bMbIsIPCM = 1;
/* deliberate drop through */
case 0: /* I */
if (1 == bCurrent) {
h264_currentIntraBlockPrediction(cmdbuf, MbData, bMbIsIPCM);
} else {
h264_above1IntraBlockPrediction(cmdbuf, MbData, bMbIsIPCM);
}
break;
case 1: /* P */
if (1 == bCurrent) {
h264_currentInterBlockSequence(cmdbuf, MbData);
} else {
h264_above1InterBlockSequence(cmdbuf, MbData);
}
break;
case 2: /* B */
default:
/* invalid MB type */
//IMG_ASSERT( 0 );
break;
}
/* Trasform Zero */
MbTransZeroCmd = 0;
Value = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_ASO_MB_TRANSFORM_ZERO);
REGIO_WRITE_FIELD(MbTransZeroCmd, MSVDX_CMDS, MACROBLOCK_BLOCK_TRANSFORM_ZERO, MB_BLOCK_TRANSFORM_ZERO, Value);
/* write last command */
h264_pollForSpaceForNCommands(1);
if (1 == bCurrent) {
psb_deblock_reg_set(MSVDX_CMDS, MACROBLOCK_BLOCK_TRANSFORM_ZERO, MbTransZeroCmd);
} else {
MbTransZeroCmd &= 0x0000CC00; /* only send for sub-blocks 10,11,14 and 15 */
psb_deblock_reg_set(MSVDX_CMDS, MACROBLOCK_BLOCK_TRANSFORM_ZERO_ABOVE1, MbTransZeroCmd);
}
}
uint32_t
h264_getCurrentSliceCmd(uint8_t* MbData)
{
uint32_t Value, Cmd;
Cmd = 0;
/* unpack data from stored MB + repack in command */
Value = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_COPY_DISABLE_DEBLOCK_FILTER_IDC);
REGIO_WRITE_FIELD(Cmd, MSVDX_CMDS, SLICE_PARAMS, DISABLE_DEBLOCK_FILTER_IDC, Value);
Value = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_COPY_H264_BE_SLICE0_ALPHA_CO_OFFSET_DIV2);
REGIO_WRITE_FIELD(Cmd, MSVDX_CMDS, SLICE_PARAMS, SLICE_ALPHA_CO_OFFSET_DIV2, Value);
Value = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_COPY_H264_BE_SLICE0_BETA_OFFSET_DIV2);
REGIO_WRITE_FIELD(Cmd, MSVDX_CMDS, SLICE_PARAMS, SLICE_BETA_OFFSET_DIV2, Value);
Value = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_COPY_H264_BE_SLICE0_FIELD_TYPE);
REGIO_WRITE_FIELD(Cmd, MSVDX_CMDS, SLICE_PARAMS, SLICE_FIELD_TYPE, Value);
Value = MEMIO_READ_FIELD(MbData, MSVDX_VEC_ENTDEC_VLRIF_H264_MB_UNIT_COPY_H264_BE_SLICE0_CODE_TYPE);
REGIO_WRITE_FIELD(Cmd, MSVDX_CMDS, SLICE_PARAMS, SLICE_CODE_TYPE, Value);
return Cmd;
}
int h264_secondPass(
psb_cmdbuf_p cmdbuf,
uint8_t * MbData,
uint32_t OperatingModeCmd,
uint32_t Width,
uint32_t Height
)
{
uint32_t i, PicSize;
uint32_t EndOfPictureCmd;
uint32_t EndOfSliceCmd;
uint32_t SliceCmd, OldSliceCmd;
uint32_t EnableReg;
uint8_t * CurrMb;
uint8_t * Above1Mb;
int bRetCode = 0;
PicSize = Width * Height;
/* End of Slice command */
EndOfSliceCmd = 0;
REGIO_WRITE_FIELD(EndOfSliceCmd, MSVDX_CMDS, END_SLICE_PICTURE, PICTURE_END, 0);
/* put vdeb into second pass mode */
/* send operating mode command for VDEB only */
REGIO_WRITE_FIELD(OperatingModeCmd, MSVDX_CMDS, OPERATING_MODE, ASYNC_MODE, 2); /* VDEB only */
h264_pollForSpaceForNCommands(1);
psb_deblock_reg_get(MSVDX_CORE, CR_MSVDX_COMMAND_SPACE);
psb_deblock_reg_set(MSVDX_CMDS, OPERATING_MODE, OperatingModeCmd);
PollForSpaceForXCommands;
/* Send Slice Command */
SliceCmd = h264_getCurrentSliceCmd(MbData);
h264_pollForSpaceForNCommands(2);
psb_deblock_reg_set(MSVDX_CMDS, SLICE_PARAMS, SliceCmd);
psb_deblock_reg_set(MSVDX_CMDS, SLICE_PARAMS_ABOVE1, SliceCmd);
/* process top row */
for (i = 0, CurrMb = MbData;
i < Width;
i++, CurrMb += H264_MACROBLOCK_DATA_SIZE) {
OldSliceCmd = SliceCmd;
SliceCmd = h264_getCurrentSliceCmd(CurrMb);
if (OldSliceCmd != SliceCmd) {
h264_pollForSpaceForNCommands(2);
psb_deblock_reg_set(MSVDX_CMDS, END_SLICE_PICTURE, EndOfSliceCmd);
psb_deblock_reg_set(MSVDX_CMDS, SLICE_PARAMS, SliceCmd);
}
h264_macroblockCmdSequence(cmdbuf, CurrMb, i, 0, 1);
}
/* process rest of picture */
for (Above1Mb = MbData;
i < PicSize;
i++, CurrMb += H264_MACROBLOCK_DATA_SIZE, Above1Mb += H264_MACROBLOCK_DATA_SIZE) {
OldSliceCmd = SliceCmd;
SliceCmd = h264_getCurrentSliceCmd(CurrMb);
if (OldSliceCmd != SliceCmd) {
h264_pollForSpaceForNCommands(2);
psb_deblock_reg_set(MSVDX_CMDS, END_SLICE_PICTURE, EndOfSliceCmd);
psb_deblock_reg_set(MSVDX_CMDS, SLICE_PARAMS, SliceCmd);
}
h264_macroblockCmdSequence(cmdbuf, Above1Mb, (i % Width), (i / Width) - 1, 0);
h264_macroblockCmdSequence(cmdbuf, CurrMb, (i % Width), (i / Width), 1);
}
/* send end of pic + restart back end */
EndOfPictureCmd = 0;
EnableReg = 0;
REGIO_WRITE_FIELD(EndOfPictureCmd, MSVDX_CMDS, END_SLICE_PICTURE, PICTURE_END, 1);
REGIO_WRITE_FIELD(EnableReg, MSVDX_VEC, CR_VEC_CONTROL, ENTDEC_ENABLE_BE, 1);
h264_pollForSpaceForNCommands(2);
psb_deblock_reg_set(MSVDX_CMDS, END_SLICE_PICTURE, EndOfSliceCmd);
psb_deblock_reg_set(MSVDX_CMDS, END_SLICE_PICTURE, EndOfPictureCmd);
//psb_deblock_reg_set( MSVDX_VEC, CR_VEC_CONTROL, EnableReg); /* this is not a command */
return bRetCode;
}
int psb_cmdbuf_second_pass(object_context_p obj_context,
uint32_t OperatingModeCmd,
unsigned char * pvParamBase,
uint32_t PicWidthInMbs,
uint32_t FrameHeightInMbs,
psb_buffer_p target_buffer,
uint32_t chroma_offset
)
{
int bRetVal = 1;
uint32_t Cmd, item_loc;
uint32_t *cmd_size;
psb_cmdbuf_p cmdbuf = obj_context->cmdbuf;
if (psb_buffer_map(&cmdbuf->regio_buf, &cmdbuf->regio_base)) {
//printf("map cmdbuf->regio_buf error\n");
return bRetVal;
}
item_loc = psb_cmdbuf_buffer_ref(cmdbuf, &cmdbuf->regio_buf);
cmdbuf->regio_idx = (uint32_t *)cmdbuf->regio_base;
cmd_size = cmdbuf->regio_idx++;
h264_pollForSpaceForNCommands(4);
psb_deblock_reg_set_RELOC(MSVDX_CMDS, LUMA_RECONSTRUCTED_PICTURE_BASE_ADDRESSES, target_buffer, target_buffer->buffer_ofs, item_loc);
psb_deblock_reg_set_RELOC(MSVDX_CMDS, CHROMA_RECONSTRUCTED_PICTURE_BASE_ADDRESSES, target_buffer, target_buffer->buffer_ofs + chroma_offset, item_loc);
Cmd = 0;
REGIO_WRITE_FIELD_LITE(Cmd, MSVDX_CMDS, DISPLAY_PICTURE_SIZE, DISPLAY_PICTURE_HEIGHT, (FrameHeightInMbs * 16) - 1);
REGIO_WRITE_FIELD_LITE(Cmd, MSVDX_CMDS, DISPLAY_PICTURE_SIZE, DISPLAY_PICTURE_WIDTH, (PicWidthInMbs * 16) - 1);
psb_deblock_reg_set(MSVDX_CMDS, DISPLAY_PICTURE_SIZE, Cmd);
Cmd = 0;
REGIO_WRITE_FIELD_LITE(Cmd, MSVDX_CMDS, CODED_PICTURE_SIZE, CODED_PICTURE_HEIGHT, (FrameHeightInMbs * 16) - 1);
REGIO_WRITE_FIELD_LITE(Cmd, MSVDX_CMDS, CODED_PICTURE_SIZE, CODED_PICTURE_WIDTH, (PicWidthInMbs * 16) - 1);
psb_deblock_reg_set(MSVDX_CMDS, CODED_PICTURE_SIZE, Cmd);
/* BRN25312 */
psb_deblock_reg_set(MSVDX_CMDS, VC1_LUMA_RANGE_MAPPING_BASE_ADDRESS, 0);
psb_deblock_reg_set(MSVDX_CMDS, VC1_CHROMA_RANGE_MAPPING_BASE_ADDRESS, 0);
psb_deblock_reg_set(MSVDX_CMDS, VC1_RANGE_MAPPING_FLAGS, 0);
/* process second pass */
bRetVal = h264_secondPass(cmdbuf,
(uint8_t*)pvParamBase,
OperatingModeCmd,
PicWidthInMbs,
FrameHeightInMbs);
*cmd_size = (cmdbuf->regio_idx - (uint32_t *)cmdbuf->regio_base - 1);
psb__information_message("DEBLOCK: REGIO size is %d\n", (uint32_t)(cmdbuf->regio_idx - (uint32_t *)cmdbuf->regio_base) - 1);
//printf("DEBLOCK: REGIO size is %d\n", (uint32_t)(cmdbuf->regio_idx - (uint32_t *)cmdbuf->regio_base) - 1);
psb_buffer_unmap(&cmdbuf->regio_buf);
return bRetVal;
}
|