<div dir="ltr">Shengquan,<div><br></div><div>Thanks for the sample code. I have some follow-up questions:</div><div><br></div><div>1. Can I use VA_RT_FORMAT_RGB32 as the pixel format for vaCreateSurfaces? It'll be simpler since normally the 2D texture is in ARGB format.</div><div>2. Do I have to align the picture width and height, i.e., can I just use 1920x1080 for a full HD picture?</div><div><br></div><div>Best</div><div>Christine</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 25, 2016 at 3:46 AM, Yuan, Shengquan <span dir="ltr"><<a href="mailto:shengquan.yuan@intel.com" target="_blank">shengquan.yuan@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">For vaCreateContext, I think render_targets/num_render_targets are optional (it depends on driver implementation), and the surface of vaBeginPicture can a brand-new
surface<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">VAStatus vaCreateContext (<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> VADisplay dpy,<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> VAConfigID config_id,<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> int picture_width,<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> int picture_height,<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> int flag,<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> VASurfaceID *render_targets,<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> int num_render_targets,<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> VAContextID *context /* out */<u></u><u></u></span></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">);<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">DMA buffer can be imported through VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME, e.g.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> VASurfaceAttribExternalBuffers buf;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> VASurfaceAttribType type,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> VASurfaceAttrib attrib_list[2]<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> unsigned long prime_fd; /* an input variable, it is the imported prime fd from other process */<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> int stride = frame_width_aligned, height_aligned = frame_height_aligned;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> if (stride == 0)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> stride = frame_width_mbaligned;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> if (height_aligned == 0)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> height_aligned = frame_height_mbaligned;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.pixel_format = VA_FOURCC_NV12;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.width = frame_width_mbaligned;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.height = frame_height_mbaligned;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.data_size = stride * height_aligned * 1.5;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.num_buffers = 1; /* import only 1 buffer */<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.num_planes = 3;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.pitches[0] = stride;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.pitches[1] = stride;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.pitches[2] = stride;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.pitches[3] = 0;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.offsets[0] = 0;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.offsets[1] = stride * height_aligned;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.offsets[2] = buf.offsets[1];<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.offsets[3] = 0;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.buffers = &prime_fd;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.flags = 0;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> buf.private_data = NULL;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> attrib_list[0].type = (VASurfaceAttribType)VASurfaceAttribMemoryType;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> attrib_list[0].flags = VA_SURFACE_ATTRIB_SETTABLE;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> attrib_list[0].value.type = VAGenericValueTypeInteger;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> attrib_list[0].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> attrib_list[1].type = (VASurfaceAttribType)VASurfaceAttribExternalBufferDescriptor;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> attrib_list[1].flags = VA_SURFACE_ATTRIB_SETTABLE;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> attrib_list[1].value.type = VAGenericValueTypePointer;<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:10.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">attrib_list[1].value.value.p = (void *)buf;<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:10.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">vaCreateSurfaces(<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:10.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> va_dpy,<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:10.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> VA_RT_FORMAT_YUV420,<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:10.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> frame_width_mbaligned, frame_height_mbaligned,<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:10.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> &surface_id, 1,<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:10.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> &attrib_list, 2);<u></u><u></u></span></p>
<p class="MsoNormal" style="text-indent:10.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><a name="m_-3275825310711099550__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></a></p>
<p class="MsoNormal"><a name="m_-3275825310711099550______replyseparator"></a><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Libva [mailto:<a href="mailto:libva-bounces@lists.freedesktop.org" target="_blank">libva-bounces@lists.freedesktop.org</a>]
<b>On Behalf Of </b>Anon<br>
<b>Sent:</b> Wednesday, May 25, 2016 2:23 PM<br>
<b>To:</b> <a href="mailto:libva@lists.freedesktop.org" target="_blank">libva@lists.freedesktop.org</a><br>
<b>Subject:</b> [Libva] encode surfaces created from prime fd (backed by OpenGL 2D texture)<u></u><u></u></span></p><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Hi All,<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I want to implement the following use case on Intel Haswell CPU with HD graphics:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">offscreen OpenGL rendering to OpenGL 2D texture -> use <span style="color:black">EGL_MESA_image_dma_buf_export to export the texture as prime fd -> vaCreateSurfaces from the prime fd -> use vaapi to hw acclerate h264 encoding</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">Is this supported by the latest va-api and libva-intel-driver release (i.e., 1.7.0)? If so, is there any example I can start with?</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">I did read the sample application h264encode.c and thought it might be a good starting point. However, the first major issue I encountered is when creating context through vaCreateContext, a number of pre-allocated
va surfaces are required and thus statically associated with the new va context. However, with prime fd, the fd will change so a new va surface is created with every new prime fd. I don't see any API can be used to dynamically add/remove va surfaces after
the context is created. Can you please give me some suggestions?</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">Best,</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black">Kristine</span><u></u><u></u></p>
</div>
</div>
</div></div></div>
</div>
</blockquote></div><br></div>