handlePictureParameterBuffer(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf)
 {
    VAStatus vaStatus = VA_STATUS_SUCCESS;
+   enum pipe_video_format format =
+      u_reduce_video_profile(context->templat.profile);
 
-   switch (u_reduce_video_profile(context->templat.profile)) {
+   switch (format) {
    case PIPE_VIDEO_FORMAT_MPEG12:
       vlVaHandlePictureParameterBufferMPEG12(drv, context, buf);
       break;
 
    /* Create the decoder once max_references is known. */
    if (!context->decoder) {
-      enum pipe_video_format format =
-         u_reduce_video_profile(context->templat.profile);
-
       if (!context->target)
          return VA_STATUS_ERROR_INVALID_CONTEXT;
 
       context->needs_begin_frame = true;
    }
 
+   if (format == PIPE_VIDEO_FORMAT_VP9) {
+      context->decoder->width =
+         context->desc.vp9.picture_parameter.frame_width;
+      context->decoder->height =
+         context->desc.vp9.picture_parameter.frame_height;
+   }
+
    return vaStatus;
 }
 
 
 
    context->desc.vp9.picture_parameter.bit_depth = vp9->bit_depth;
 
-   for (i = 0 ; i < NUM_VP9_REFS ; i++)
-      vlVaGetReferenceFrame(drv, vp9->reference_frames[i], &context->desc.vp9.ref[i]);
+   for (i = 0 ; i < NUM_VP9_REFS ; i++) {
+      if (vp9->pic_fields.bits.frame_type == 0)
+         context->desc.vp9.ref[i] = NULL;
+      else
+         vlVaGetReferenceFrame(drv, vp9->reference_frames[i], &context->desc.vp9.ref[i]);
+   }
 
    if (!context->decoder && !context->templat.max_references)
       context->templat.max_references = NUM_VP9_REFS;