Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit 9d28e6e

Browse files
marcheuxhaihao
authored andcommittedSep 17, 2021
Avoid GPU crash with malformed streams
When streams are malformed, we can get p-frames without any reference picture. However the code still assumes 1 reference picture at least, which leads to a GPU crash. To protect against GPU crashes, we force 0 when we have no pictures. Do this on gen6, 7, 7.5 and 8. BUG=chromium:252389,chroimum:418024 TEST=go to youtube and play http://www.youtube.com/watch?v=6v2L2UGZJAM ; it doesn't crash Signed-off-by: Stéphane Marchesin <marcheu@chromium.org> Signed-off-by: Sean V Kelley <seanvk@posteo.de>
1 parent d87db21 commit 9d28e6e

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed
 

‎src/gen6_mfd.c

+11
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,8 @@ gen6_mfd_avc_slice_state(VADriverContextP ctx,
515515
int first_mb_in_slice = 0, first_mb_in_next_slice = 0;
516516
unsigned int chroma_log2_weight_denom, luma_log2_weight_denom;
517517
int slice_type;
518+
int num_surfaces = 0;
519+
int i;
518520

519521
if (slice_param->slice_type == SLICE_TYPE_I ||
520522
slice_param->slice_type == SLICE_TYPE_SI) {
@@ -552,6 +554,15 @@ gen6_mfd_avc_slice_state(VADriverContextP ctx,
552554
}
553555
}
554556

557+
/* Don't bind a surface which doesn't exist, that crashes the GPU */
558+
for (i = 0; i < ARRAY_ELEMS(gen6_mfd_context->reference_surface); i++)
559+
if (gen6_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID)
560+
num_surfaces ++;
561+
if (num_surfaces == 0) {
562+
num_ref_idx_l0 = 0;
563+
num_ref_idx_l1 = 0;
564+
}
565+
555566
first_mb_in_slice = slice_param->first_mb_in_slice;
556567
slice_hor_pos = first_mb_in_slice % width_in_mbs;
557568
slice_ver_pos = first_mb_in_slice / width_in_mbs;

‎src/gen75_mfd.c

+11
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,8 @@ gen75_mfd_avc_slice_state(VADriverContextP ctx,
837837
pic_param->seq_fields.bits.mb_adaptive_frame_field_flag);
838838
int first_mb_in_slice = 0, first_mb_in_next_slice = 0;
839839
int slice_type;
840+
int num_surfaces = 0;
841+
int i;
840842

841843
if (slice_param->slice_type == SLICE_TYPE_I ||
842844
slice_param->slice_type == SLICE_TYPE_SI) {
@@ -863,6 +865,15 @@ gen75_mfd_avc_slice_state(VADriverContextP ctx,
863865
num_ref_idx_l1 = slice_param->num_ref_idx_l1_active_minus1 + 1;
864866
}
865867

868+
/* Don't bind a surface which doesn't exist, that crashes the GPU */
869+
for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++)
870+
if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID)
871+
num_surfaces ++;
872+
if (num_surfaces == 0) {
873+
num_ref_idx_l0 = 0;
874+
num_ref_idx_l1 = 0;
875+
}
876+
866877
first_mb_in_slice = slice_param->first_mb_in_slice;
867878
slice_hor_pos = first_mb_in_slice % width_in_mbs;
868879
slice_ver_pos = first_mb_in_slice / width_in_mbs;

‎src/gen7_mfd.c

+11
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ gen7_mfd_avc_slice_state(VADriverContextP ctx,
531531
pic_param->seq_fields.bits.mb_adaptive_frame_field_flag);
532532
int first_mb_in_slice = 0, first_mb_in_next_slice = 0;
533533
int slice_type;
534+
int num_surfaces = 0;
535+
int i;
534536

535537
if (slice_param->slice_type == SLICE_TYPE_I ||
536538
slice_param->slice_type == SLICE_TYPE_SI) {
@@ -557,6 +559,15 @@ gen7_mfd_avc_slice_state(VADriverContextP ctx,
557559
num_ref_idx_l1 = slice_param->num_ref_idx_l1_active_minus1 + 1;
558560
}
559561

562+
/* Don't bind a surface which doesn't exist, that crashes the GPU */
563+
for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++)
564+
if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID)
565+
num_surfaces ++;
566+
if (num_surfaces == 0) {
567+
num_ref_idx_l0 = 0;
568+
num_ref_idx_l1 = 0;
569+
}
570+
560571
first_mb_in_slice = slice_param->first_mb_in_slice;
561572
slice_hor_pos = first_mb_in_slice % width_in_mbs;
562573
slice_ver_pos = first_mb_in_slice / width_in_mbs;

‎src/gen8_mfd.c

+11
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,8 @@ gen8_mfd_avc_slice_state(VADriverContextP ctx,
614614
pic_param->seq_fields.bits.mb_adaptive_frame_field_flag);
615615
int first_mb_in_slice = 0, first_mb_in_next_slice = 0;
616616
int slice_type;
617+
int num_surfaces = 0;
618+
int i;
617619

618620
if (slice_param->slice_type == SLICE_TYPE_I ||
619621
slice_param->slice_type == SLICE_TYPE_SI) {
@@ -640,6 +642,15 @@ gen8_mfd_avc_slice_state(VADriverContextP ctx,
640642
num_ref_idx_l1 = slice_param->num_ref_idx_l1_active_minus1 + 1;
641643
}
642644

645+
/* Don't bind a surface which doesn't exist, that crashes the GPU */
646+
for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++)
647+
if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID)
648+
num_surfaces ++;
649+
if (num_surfaces == 0) {
650+
num_ref_idx_l0 = 0;
651+
num_ref_idx_l1 = 0;
652+
}
653+
643654
first_mb_in_slice = slice_param->first_mb_in_slice;
644655
slice_hor_pos = first_mb_in_slice % width_in_mbs;
645656
slice_ver_pos = first_mb_in_slice / width_in_mbs;

0 commit comments

Comments
 (0)