Skip to content

Commit d5caa91

Browse files
TianmiChensysopenci
authored andcommitted
Use VADRMPRIMESurfaceDescriptor to create surface
This change is to replace VASurfaceAttribExternalBuffers with VADRMPRIMESurfaceDescriptor in va surface creation. With VADRMPRIMESurfaceDescriptor, the tile info can be specified explicitly and sent to media driver. width iGPU, tileY is being used by default and there is no need to set this info, but with dGPU, tile info should be set. Tracked-On: OAM-108862 Signed-off-by: Chen, Tianmi <tianmi.chen@intel.com>
1 parent 36f1915 commit d5caa91

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

c2_utils/src/mfx_va_allocator.cpp

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@
3535

3636
#define IS_PRIME_VALID(prime) ((prime >= 0) ? true : false)
3737

38+
#define DRM_FORMAT_MOD_VENDOR_INTEL 0x01
39+
40+
#define fourcc_mod_code(vendor, val) \
41+
((((__u64)DRM_FORMAT_MOD_VENDOR_## vendor) << 56) | ((val) & 0x00ffffffffffffffULL))
42+
43+
#define I915_FORMAT_MOD_4_TILED fourcc_mod_code(INTEL, 9)
44+
#define I915_FORMAT_MOD_Y_TILED fourcc_mod_code(INTEL, 2)
45+
46+
#define fourcc_code(a, b, c, d) ((__u32)(a) | ((__u32)(b) << 8) | \
47+
((__u32)(c) << 16) | ((__u32)(d) << 24))
48+
49+
#define DRM_FORMAT_NV12 fourcc_code('N', 'V', '1', '2') /* 2x2 subsampled Cr:Cb plane */
50+
#define DRM_FORMAT_NV21 fourcc_code('N', 'V', '2', '1') /* 2x2 subsampled Cb:Cr plane */
51+
#define DRM_FORMAT_YVU420 fourcc_code('Y', 'V', '1', '2') /* 2x2 subsampled Cr (1) and Cb (2) planes */
52+
#define DRM_FORMAT_P010 fourcc_code('P', '0', '1', '0') /* 2x2 subsampled Cr:Cb plane 10 bits per channel */
53+
#define DRM_FORMAT_RGBA8888 fourcc_code('R', 'A', '2', '4') /* [31:0] R:G:B:A 8:8:8:8 little endian */
54+
#define DRM_FORMAT_RGBX8888 fourcc_code('R', 'X', '2', '4') /* [31:0] R:G:B:x 8:8:8:8 little endian */
55+
#define DRM_FORMAT_BGRA8888 fourcc_code('B', 'A', '2', '4') /* [31:0] B:G:R:A 8:8:8:8 little endian */
56+
3857
static unsigned int ConvertMfxFourccToVAFormat(mfxU32 fourcc)
3958
{
4059
switch (fourcc) {
@@ -111,6 +130,27 @@ static mfxU32 ConvertVAFourccToVARTFormat(mfxU32 va_fourcc)
111130
}
112131
}
113132

133+
static mfxU32 ConvertVAFourccToDrmFormat(mfxU32 va_fourcc)
134+
{
135+
switch (va_fourcc)
136+
{
137+
case VA_FOURCC_NV12:
138+
return DRM_FORMAT_NV12;
139+
case VA_FOURCC_YV12:
140+
return DRM_FORMAT_YVU420;
141+
case VA_FOURCC_RGBA:
142+
return DRM_FORMAT_RGBA8888;
143+
case VA_FOURCC_BGRA:
144+
return DRM_FORMAT_BGRA8888;
145+
case VA_FOURCC_RGBX:
146+
return DRM_FORMAT_RGBX8888;
147+
case VA_FOURCC_P010:
148+
return DRM_FORMAT_P010;
149+
default:
150+
return 0;
151+
}
152+
}
153+
114154
MfxVaFrameAllocator::MfxVaFrameAllocator(VADisplay dpy)
115155
: m_dpy(dpy)
116156
{
@@ -505,7 +545,6 @@ mfxStatus MfxVaFrameAllocator::CreateSurfaceFromGralloc(const IMfxGrallocModule:
505545
MFX_DEBUG_TRACE_U32(info.pitches[i]);
506546
}
507547

508-
509548
mfxU32 width = decode_target ? info.allocWidth : info.width;
510549
mfxU32 height = decode_target ? info.allocHeight : info.height;
511550

@@ -515,6 +554,7 @@ mfxStatus MfxVaFrameAllocator::CreateSurfaceFromGralloc(const IMfxGrallocModule:
515554
VASurfaceAttrib attribs[2];
516555
MFX_ZERO_MEMORY(attribs);
517556

557+
#if 0
518558
VASurfaceAttribExternalBuffers surfExtBuf;
519559
MFX_ZERO_MEMORY(surfExtBuf);
520560

@@ -553,6 +593,40 @@ mfxStatus MfxVaFrameAllocator::CreateSurfaceFromGralloc(const IMfxGrallocModule:
553593
attribs[1].flags = VA_SURFACE_ATTRIB_SETTABLE;
554594
attribs[1].value.type = VAGenericValueTypePointer;
555595
attribs[1].value.value.p = (void *)&surfExtBuf;
596+
#else
597+
VADRMPRIMESurfaceDescriptor desc;
598+
MFX_ZERO_MEMORY(desc);
599+
600+
desc.fourcc = va_fourcc;
601+
desc.width = width;
602+
desc.height = height;
603+
desc.num_objects = 1;
604+
desc.objects[0].fd = info.prime;
605+
desc.objects[0].size = decode_target ? info.pitches[0] * ((height + 31) & ~31) * 1.5 : info.pitches[0] * ((height + 15) & ~15) * 1.5;
606+
desc.objects[0].drm_format_modifier = I915_FORMAT_MOD_Y_TILED;
607+
//desc.objects[0].drm_format_modifier = I915_FORMAT_MOD_4_TILED;
608+
desc.num_layers = 1;
609+
desc.layers[0].drm_format = ConvertVAFourccToDrmFormat(va_fourcc);
610+
desc.layers[0].num_planes = info.planes_count;
611+
desc.layers[0].object_index[0] = 0;
612+
desc.layers[0].offset[0] = 0;
613+
desc.layers[0].offset[1] = decode_target ? info.pitches[0] * ((height + 31) & ~31) : info.pitches[0] * ((height + 15) & ~15);
614+
desc.layers[0].offset[2] = 0;
615+
desc.layers[0].offset[3] = 0;
616+
desc.layers[0].pitch[0] = info.pitches[0];
617+
desc.layers[0].pitch[1] = info.pitches[1];
618+
desc.layers[0].pitch[2] = 0;
619+
desc.layers[0].pitch[3] = 0;
620+
621+
attribs[0].type = (VASurfaceAttribType)VASurfaceAttribMemoryType;
622+
attribs[0].flags = VA_SURFACE_ATTRIB_SETTABLE;
623+
attribs[0].value.type = VAGenericValueTypeInteger;
624+
attribs[0].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2;
625+
attribs[1].type = VASurfaceAttribExternalBufferDescriptor;
626+
attribs[1].flags = VA_SURFACE_ATTRIB_SETTABLE;
627+
attribs[1].value.type = VAGenericValueTypePointer;
628+
attribs[1].value.value.p = (void *)&desc;
629+
#endif
556630

557631
VAStatus va_res = vaCreateSurfaces(m_dpy, rt_format,
558632
width, height,

0 commit comments

Comments
 (0)