[Libva] [PATCH v1 0/9]Encoder Architecture Changes (Primarily AVC)

2017-01-13 Thread Pengfei Qu
Encoder architecture restructuring for H.264 (with some impact to HEVC now) on 
HSW+
* Improvements to the shaders
* Improvements to the B frame efficiency
* Improvements to the low bit rate mode
* Improved features in two stage VME/PAK pipeline

v1:
Reduce the patch number and re org for VME and MFX related patches.
Patch re org for VME pipeline
Patch re org for MFX pipeline
keep assert for internal logic and replace assert for input validation function.
Remove unnecessary comments and enum value.
Use the 64bit version OUT_BCS_RELOC64.
Move kernel binary into header file.
use misc parameter from encoder_context structure.


Pengfe (9):
  ENC: move gpe related function into src/i965_gpe_utils.h/c
  ENC: add common structure for AVC/HEVC encoder
  ENC: add const data/table for AVC encoder
  ENC: add AVC kernel binary on SKL
  ENC: add AVC common structure and functions
  ENC: add kernel related structure and define for AVC
  ENC: add VME pipeline for AVC encoder
  ENC: add MFX pipeline for AVC encoder
  ENC:support more quality level and switch to new AVC encoder solution
on SKL

 src/Makefile.am|10 +
 src/gen9_avc_const_def.c   |  1090 
 src/gen9_avc_const_def.h   |   115 +
 src/gen9_avc_encoder.c |  7630 +
 src/gen9_avc_encoder.h |  2339 
 src/gen9_avc_encoder_kernels.h | 12078 +++
 src/gen9_vp9_encoder.c |   154 +-
 src/gen9_vp9_encoder.h |10 -
 src/i965_avc_encoder_common.c  |   319 ++
 src/i965_avc_encoder_common.h  |   305 +
 src/i965_defines.h | 3 +
 src/i965_drv_video.c   | 8 +-
 src/i965_drv_video.h   | 2 +
 src/i965_encoder.c |52 +-
 src/i965_encoder_api.h |47 +
 src/i965_encoder_common.c  |   124 +
 src/i965_encoder_common.h  |   541 ++
 src/i965_gpe_utils.c   |   282 +
 src/i965_gpe_utils.h   |86 +
 19 files changed, 25027 insertions(+), 168 deletions(-)
 create mode 100755 src/gen9_avc_const_def.c
 create mode 100755 src/gen9_avc_const_def.h
 create mode 100755 src/gen9_avc_encoder.c
 create mode 100755 src/gen9_avc_encoder.h
 create mode 100755 src/gen9_avc_encoder_kernels.h
 create mode 100755 src/i965_avc_encoder_common.c
 create mode 100755 src/i965_avc_encoder_common.h
 create mode 100755 src/i965_encoder_api.h
 create mode 100755 src/i965_encoder_common.c
 create mode 100755 src/i965_encoder_common.h

-- 
2.7.4
___
Libva mailing list
Libva@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libva


[Libva] [PATCH v1 5/9] ENC: add AVC common structure and functions

2017-01-13 Thread Pengfei Qu
v1:add kernel pointer for different platform

Signed-off-by: Pengfei Qu 
Reviewed-by: Sean V Kelley
---
 src/i965_avc_encoder_common.c | 319 ++
 src/i965_avc_encoder_common.h | 305 
 src/i965_encoder_common.h |  30 ++--
 3 files changed, 643 insertions(+), 11 deletions(-)
 create mode 100755 src/i965_avc_encoder_common.c
 create mode 100755 src/i965_avc_encoder_common.h

diff --git a/src/i965_avc_encoder_common.c b/src/i965_avc_encoder_common.c
new file mode 100755
index 000..3fc2b54
--- /dev/null
+++ b/src/i965_avc_encoder_common.c
@@ -0,0 +1,319 @@
+
+/*
+ * Copyright ? 2016 Intel Corporation
+ *
+ * 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
+ * SOFTWAR
+ *
+ * Authors:
+ * Pengfei Qu 
+ *
+ */
+
+#include "i965_avc_encoder_common.h"
+int
+i965_avc_get_max_mbps(int level_idc)
+{
+int max_mbps = 11880;
+
+switch (level_idc) {
+case INTEL_AVC_LEVEL_2:
+max_mbps = 11880;
+break;
+
+case INTEL_AVC_LEVEL_21:
+max_mbps = 19800;
+break;
+
+case INTEL_AVC_LEVEL_22:
+max_mbps = 20250;
+break;
+
+case INTEL_AVC_LEVEL_3:
+max_mbps = 40500;
+break;
+
+case INTEL_AVC_LEVEL_31:
+max_mbps = 108000;
+break;
+
+case INTEL_AVC_LEVEL_32:
+max_mbps = 216000;
+break;
+
+case INTEL_AVC_LEVEL_4:
+case INTEL_AVC_LEVEL_41:
+max_mbps = 245760;
+break;
+
+case INTEL_AVC_LEVEL_42:
+max_mbps = 522240;
+break;
+
+case INTEL_AVC_LEVEL_5:
+max_mbps = 589824;
+break;
+
+case INTEL_AVC_LEVEL_51:
+max_mbps = 983040;
+break;
+
+case INTEL_AVC_LEVEL_52:
+max_mbps = 2073600;
+break;
+
+default:
+break;
+}
+
+return max_mbps;
+};
+
+unsigned int
+i965_avc_get_profile_level_max_frame(struct avc_param * param,
+   int level_idc)
+{
+double bits_per_mb, tmpf;
+int max_mbps, num_mb_per_frame;
+uint64_t max_byte_per_frame0, max_byte_per_frame1;
+unsigned int ret;
+unsigned int scale_factor = 4;
+
+
+if (level_idc >= INTEL_AVC_LEVEL_31 && level_idc <= INTEL_AVC_LEVEL_4)
+bits_per_mb = 96.0;
+else
+{
+bits_per_mb = 192.0;
+scale_factor = 2;
+
+}
+
+max_mbps = i965_avc_get_max_mbps(level_idc);
+num_mb_per_frame = param->frame_width_in_mbs * param->frame_height_in_mbs;
+
+tmpf = (double)num_mb_per_frame;
+
+if (tmpf < max_mbps / 172.0)
+tmpf = max_mbps / 172.0;
+
+max_byte_per_frame0 = (uint64_t)(tmpf * bits_per_mb);
+max_byte_per_frame1 = (uint64_t)(((double)max_mbps * 100) / 
param->frames_per_100s *bits_per_mb);
+
+/* TODO: check VAEncMiscParameterTypeMaxFrameSize */
+ret = (unsigned int)MIN(max_byte_per_frame0, max_byte_per_frame1);
+ret = (unsigned int)MIN(ret, param->frame_width_in_pixel * 
param->frame_height_in_pixel *3 /(2*scale_factor));
+
+return ret;
+}
+
+int
+i965_avc_calculate_initial_qp(struct avc_param * param)
+{
+float x0 = 0, y0 = 1.19f, x1 = 1.75f, y1 = 1.75f;
+unsigned frame_size;
+int qp, delat_qp;
+
+frame_size = (param->frame_width_in_pixel * param->frame_height_in_pixel * 
3 / 2);
+qp = (int)(1.0 / 1.2 * pow(10.0,
+   (log10(frame_size * 2.0 / 3.0 * 
((float)param->frames_per_100s) /
+  ((float)(param->target_bit_rate * 1000) 
* 100)) - x0) *
+   (y1 - y0) / (x1 - x0) + y0) + 0.5);
+qp += 2;
+delat_qp = (int)(9 - (param->vbv_buffer_size_in_bit * 
((float)param->frames_per_100s) /
+  ((float)(param->target_bit_rate * 1000) * 100)));
+if (delat_qp > 0)
+qp += delat_qp;
+
+qp = CLAMP(1, 51, qp);
+qp--;
+
+if (qp 

[Libva] [PATCH v1 2/9] ENC: add common structure for AVC/HEVC encoder

2017-01-13 Thread Pengfei Qu
add context init function for AVC encoder

Signed-off-by: Pengfei Qu 
Reviewed-by: Sean V Kelley
---
 src/i965_encoder_api.h|  47 
 src/i965_encoder_common.c | 124 +++
 src/i965_encoder_common.h | 533 ++
 3 files changed, 704 insertions(+)
 create mode 100755 src/i965_encoder_api.h
 create mode 100755 src/i965_encoder_common.c
 create mode 100755 src/i965_encoder_common.h

diff --git a/src/i965_encoder_api.h b/src/i965_encoder_api.h
new file mode 100755
index 000..ebb0edc
--- /dev/null
+++ b/src/i965_encoder_api.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * 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:
+ * Pengfei Qu 
+ *
+ */
+
+#ifndef _I965_ENCODER_API_H_
+#define _I965_ENCODER_API_H_
+
+#include 
+
+struct intel_encoder_context;
+struct hw_context;
+
+/* H264/AVC */
+extern Bool
+gen9_avc_vme_context_init(VADriverContextP ctx, struct intel_encoder_context 
*encoder_context);
+
+extern Bool
+gen9_avc_pak_context_init(VADriverContextP ctx, struct intel_encoder_context 
*encoder_context);
+
+extern VAStatus
+gen9_avc_coded_status(VADriverContextP ctx, char *buffer, struct hw_context 
*hw_context);
+
+#endif  // _I965_ENCODER_API_H_
diff --git a/src/i965_encoder_common.c b/src/i965_encoder_common.c
new file mode 100755
index 000..930aba9
--- /dev/null
+++ b/src/i965_encoder_common.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright ? 2016 Intel Corporation
+ *
+ * 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
+ * SOFTWAR
+ *
+ * Authors:
+ * Pengfei Qu 
+ *
+ */
+#include 
+#include 
+#include "intel_batchbuffer.h"
+#include "intel_driver.h"
+#include "i965_encoder_common.h"
+#include "i965_gpe_utils.h"
+
+
+const unsigned int table_enc_search_path[2][8][16] =
+{
+// I-Frame & P-Frame
+{
+// MEMethod: 0
+{
+0x120FF10F, 0x1E22E20D, 0x20E2FF10, 0x2EDD06FC, 0x11D33FF1, 
0xEB1FF33D, 0x4EF1F1F1, 0xF1F21211,
+0x0DE0, 0x11201F1F, 0x1105F1CF, 0x, 0x, 
0x, 0x, 0x
+},
+// MEMethod: 1
+{
+0x120FF10F, 0x1E22E20D, 0x20E2FF10, 0x2EDD06FC, 0x11D33FF1, 
0xEB1FF33D, 0x4EF1F1F1, 0xF1F21211,
+0x0DE0, 0x11201F1F, 0x1105F1CF, 0x, 0x, 
0x, 0x, 0x
+},
+// MEMethod: 2
+{
+0x, 0x, 0x, 0x, 0x, 
0x, 0x, 0x,
+0x, 0x, 0x, 0x, 0x, 
0x, 0x, 0x
+},
+// MEMethod: 3
+{
+0x01010101, 0x11010101, 0x01010101, 0x11010101, 0x01010101, 
0x11010101, 0x01010101, 0x11010101,
+0x01010101, 

[Libva] [PATCH v1 6/9] ENC: add kernel related structure and define for AVC

2017-01-13 Thread Pengfei Qu
Signed-off-by: Pengfei Qu 
Reviewed-by: Sean V Kelley
---
 src/gen9_avc_encoder.h | 2339 
 1 file changed, 2339 insertions(+)
 create mode 100755 src/gen9_avc_encoder.h

diff --git a/src/gen9_avc_encoder.h b/src/gen9_avc_encoder.h
new file mode 100755
index 000..404ee56
--- /dev/null
+++ b/src/gen9_avc_encoder.h
@@ -0,0 +1,2339 @@
+/*
+ * Copyright ? 2016 Intel Corporation
+ *
+ * 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
+ * SOFTWAR
+ *
+ * Authors:
+ *Pengfei Qu 
+ *
+ */
+
+#ifndef GEN9_AVC_ENCODER_H
+#define GEN9_AVC_ENCODER_H
+
+#include "i965_encoder_common.h"
+/*
+common structure and define
+gen9_avc_surface structure
+*/
+#define MAX_AVC_ENCODER_SURFACES64
+#define MAX_AVC_PAK_PASS_NUM4
+
+#define ENCODER_AVC_CONST_SURFACE_WIDTH 64
+#define ENCODER_AVC_CONST_SURFACE_HEIGHT 44
+#define WIDTH_IN_MACROBLOCKS(width) (ALIGN(width, 16) >> 4)
+
+#define AVC_BRC_HISTORY_BUFFER_SIZE 864
+#define AVC_BRC_CONSTANTSURFACE_SIZE1664
+#define AVC_ADAPTIVE_TX_DECISION_THRESHOLD   128
+#define AVC_MB_TEXTURE_THRESHOLD 1024
+#define AVC_SFD_COST_TABLE_BUFFER_SIZ52
+#define AVC_INVALID_ROUNDING_VALUE255
+
+/* BRC define */
+#define CLIP(x, min, max) \
+{   \
+(x) = (((x) > (max)) ? (max) : (((x) < (min)) ? (min) : (x)));  \
+}
+
+typedef struct _kernel_header_
+{
+uint32_t   reserved: 6;
+uint32_t   kernel_start_pointer: 26;
+} kernel_header;
+
+struct generic_search_path_delta
+{
+uint8_t search_path_delta_x:4;
+uint8_t search_path_delta_y:4;
+};
+
+struct scaling_param
+{
+VASurfaceID curr_pic;
+void*p_scaling_bti;
+struct object_surface   *input_surface;
+struct object_surface   *output_surface;
+uint32_tinput_frame_width;
+uint32_tinput_frame_height;
+uint32_toutput_frame_width;
+uint32_toutput_frame_height;
+uint32_tvert_line_stride;
+uint32_tvert_line_stride_offset;
+boolscaling_out_use_16unorm_surf_fmt;
+boolscaling_out_use_32unorm_surf_fmt;
+boolmbv_proc_stat_enabled;
+boolenable_mb_flatness_check;
+boolenable_mb_variance_output;
+boolenable_mb_pixel_average_output;
+booluse_4x_scaling;
+booluse_16x_scaling;
+booluse_32x_scaling;
+boolblk8x8_stat_enabled;
+struct i965_gpe_resource*pres_mbv_proc_stat_buffer;
+struct i965_gpe_resource*pres_flatness_check_surface;
+};
+
+struct avc_surface_param{
+uint32_t frame_width;
+uint32_t frame_height;
+};
+struct me_param{
+uint32_t hme_type;
+};
+struct wp_param{
+uint32_t ref_list_idx;
+};
+
+struct brc_param{
+struct i965_gpe_context * gpe_context_brc_frame_update;
+struct i965_gpe_context * gpe_context_mbenc;
+};
+
+struct mbenc_param{
+uint32_t frame_width_in_mb;
+uint32_t frame_height_in_mb;
+uint32_t mbenc_i_frame_dist_in_use;
+uint32_t mad_enable;
+uint32_t roi_enabled;
+uint32_t brc_enabled;
+uint32_t slice_height;
+uint32_t mb_const_data_buffer_in_use;
+uint32_t mb_qp_buffer_in_use;
+uint32_t mb_vproc_stats_enable;
+};
+
+struct gen9_surface_avc
+{
+VADriverContextP ctx;
+VASurfaceID scaled_4x_surface_id;
+struct object_surface *scaled_4x_surface_obj;
+VASurfaceID scaled_16x_surface_id;
+struct object_surface 

[Libva] [PATCH v1 9/9] ENC:support more quality level and switch to new AVC encoder solution on SKL

2017-01-13 Thread Pengfei Qu
Signed-off-by: Pengfei Qu 
Reviewed-by: Sean V Kelley
---
 src/Makefile.am  | 10 ++
 src/i965_drv_video.c |  8 ++--
 src/i965_drv_video.h |  2 ++
 src/i965_encoder.c   | 52 
 4 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 424812b..e0f3aec 100755
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -101,6 +101,10 @@ source_c = \
gen9_vp9_encoder_kernels.c  \
gen9_vp9_const_def.c  \
gen9_vp9_encoder.c  \
+   i965_avc_encoder_common.c  \
+   i965_encoder_common.c  \
+   gen9_avc_const_def.c  \
+   gen9_avc_encoder.c  \
intel_common_vpp_internal.c   \
$(NULL)
 
@@ -154,6 +158,12 @@ source_h = \
gen9_vp9_encapi.h   \
gen9_vp9_const_def.h  \
gen9_vp9_encoder_kernels.h   \
+   i965_encoder_api.h   \
+   i965_avc_encoder_common.h   \
+   i965_encoder_common.h   \
+   gen9_avc_encoder.h   \
+   gen9_avc_const_def.h  \
+   gen9_avc_encoder_kernels.h   \
intel_gen_vppapi.h   \
intel_common_vpp_internal.h   \
$(NULL)
diff --git a/src/i965_drv_video.c b/src/i965_drv_video.c
index cc37190..64cc0e2 100644
--- a/src/i965_drv_video.c
+++ b/src/i965_drv_video.c
@@ -911,6 +911,7 @@ i965_GetConfigAttributes(VADriverContextP ctx,
  VAConfigAttrib *attrib_list,  /* in/out */
  int num_attribs)
 {
+struct i965_driver_data * const i965 = i965_driver_data(ctx);
 VAStatus va_status;
 int i;
 
@@ -1003,8 +1004,11 @@ i965_GetConfigAttributes(VADriverContextP ctx,
 attrib_list[i].value = 1;
 if (profile == VAProfileH264ConstrainedBaseline ||
 profile == VAProfileH264Main ||
-profile == VAProfileH264High )
-attrib_list[i].value = ENCODER_QUALITY_RANGE;
+profile == VAProfileH264High ){
+attrib_list[i].value = ENCODER_QUALITY_RANGE;
+if(IS_GEN9(i965->intel.device_info))
+attrib_list[i].value = ENCODER_QUALITY_RANGE_AVC;
+}
 break;
 }
 break;
diff --git a/src/i965_drv_video.h b/src/i965_drv_video.h
index 7cba3a3..334b788 100644
--- a/src/i965_drv_video.h
+++ b/src/i965_drv_video.h
@@ -69,7 +69,9 @@
 #define DEFAULT_SATURATION  50
 
 #define ENCODER_QUALITY_RANGE 2
+#define ENCODER_QUALITY_RANGE_AVC 8
 #define ENCODER_DEFAULT_QUALITY   1
+#define ENCODER_DEFAULT_QUALITY_AVC   4
 #define ENCODER_HIGH_QUALITY  ENCODER_DEFAULT_QUALITY
 #define ENCODER_LOW_QUALITY   2
 
diff --git a/src/i965_encoder.c b/src/i965_encoder.c
index 0a648d4..6a32a3f 100644
--- a/src/i965_encoder.c
+++ b/src/i965_encoder.c
@@ -41,6 +41,7 @@
 #include "gen6_mfc.h"
 
 #include "i965_post_processing.h"
+#include "i965_encoder_api.h"
 
 static struct intel_fraction
 reduce_fraction(struct intel_fraction f)
@@ -789,9 +790,11 @@ 
intel_encoder_check_temporal_layer_structure(VADriverContextP ctx,
 
 static VAStatus
 intel_encoder_check_misc_parameter(VADriverContextP ctx,
+  VAProfile profile,
   struct encode_state *encode_state,
   struct intel_encoder_context 
*encoder_context)
 {
+struct i965_driver_data *i965 = i965_driver_data(ctx);
 VAStatus ret = VA_STATUS_SUCCESS;
 
 if (encode_state->misc_param[VAEncMiscParameterTypeQualityLevel][0] &&
@@ -800,12 +803,31 @@ intel_encoder_check_misc_parameter(VADriverContextP ctx,
 VAEncMiscParameterBufferQualityLevel* param_quality_level = 
(VAEncMiscParameterBufferQualityLevel*)pMiscParam->data;
 encoder_context->quality_level = param_quality_level->quality_level;
 
-if (encoder_context->quality_level == 0)
-encoder_context->quality_level = ENCODER_DEFAULT_QUALITY;
-else if (encoder_context->quality_level > 
encoder_context->quality_range) {
-ret = VA_STATUS_ERROR_INVALID_PARAMETER;
-goto out;
+switch (profile) {
+case VAProfileH264ConstrainedBaseline:
+case VAProfileH264Main:
+case VAProfileH264High:
+if (IS_SKL(i965->intel.device_info))
+{
+if (encoder_context->quality_level == 0)
+encoder_context->quality_level = 
ENCODER_DEFAULT_QUALITY_AVC;
+}
+else
+{
+if (encoder_context->quality_level == 0)
+encoder_context->quality_level = ENCODER_DEFAULT_QUALITY;
+}
+break;
+default:
+if (encoder_context->quality_level == 0)
+