Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Linux-dmabuf with n_planes > 1 #724

Merged
merged 2 commits into from
Mar 23, 2018
Merged

Linux-dmabuf with n_planes > 1 #724

merged 2 commits into from
Mar 23, 2018

Conversation

agx
Copy link
Contributor

@agx agx commented Mar 15, 2018

This aims to add support for formats with more than one plane like NV12.

Test plan

  • ./weston-simple-dmabuf-drm --import-format=NV12 (new functionality)
  • ./weston-simple-dmabuf-drm --import-format=XRGB (make sure old code still works)

The drivers I have don't support NV12 but maybe someone's does. Therefore marking as WiP since I can't really test it atm but I'll see if can come up with s.th. else that has more than one plane.

According to https://cgit.freedesktop.org/wayland/weston/commit/?id=ee58911912d88caacf340a5cb6a9e25fcba24996 freedreno supports NV12 if somebody running rootston on freedreno could test it that would be great.

render/egl.c Outdated
@@ -343,6 +337,52 @@ EGLImage wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
attribs[atti++] = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT;
attribs[atti++] = attributes->modifier[0] >> 32;
}

if (attributes->n_planes > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer to do this in some kind of loop rather than as 3 if-statements with copypasta'd bodies

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the same but since the constants vary (they have the plane number included) I went that way. Otherwise we'd have to setup all 5 constants upfront with 5 arrays:

pitch_ex_consts[] = [ EGL_DMABUF_PLANE0_PITCH_EX, EGL_DMABUF_PLANE1_EX, ...]

(same for fd, offset, modifier_lo, modifier_hi) and loop over these too or use some macro magic so I went for the open coded version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather set up the array like you suppose.

@agx agx changed the title [WiP] Linux-dmabuf with n_planes > 1 [NeedsTest] Linux-dmabuf with n_planes > 1 Mar 15, 2018
@agx agx mentioned this pull request Mar 15, 2018
@agx
Copy link
Contributor Author

agx commented Mar 16, 2018

It turns out egl on my intel advertises NV12 (#726) but not the buffer modifier used by weston-simple-dmabuf-drm (MOD_SAMSUNG_64_32_TILE). If I use another buffer modifier I get something rendered so it doesn't look too bad.

@emersion
Copy link
Member

Nice! Can you provide a weston-simple-dmabuf-drm patch so we can try it?

@agx
Copy link
Contributor Author

agx commented Mar 16, 2018

It really only disables the modifier atm:

agx/weston@4f788cf

so it displays only garbage but we can see that the multiple planes get added at least.

@agx
Copy link
Contributor Author

agx commented Mar 16, 2018

@emersion I have a more complete NV12 test client now

https://github.com/agx/weston/tree/nv12

it renders correctly on weston but rootston seems to pick up the first plane as RGB, I'll have a look

@agx
Copy link
Contributor Author

agx commented Mar 19, 2018

This renders correctly on my intel card. Besides @SirCmpwn comment I need to cleanup the last patch that handles GL_TEXTURE_EXTERNAL_OES.

render/egl.c Outdated
@@ -365,6 +359,52 @@ EGLImage wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl,
attribs[atti++] = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT;
attribs[atti++] = attributes->modifier[0] >> 32;
}

if (attributes->n_planes > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're adding plane 0 to the array twice.

@agx
Copy link
Contributor Author

agx commented Mar 20, 2018 via email

@agx agx force-pushed the linux-dmabuf-mp branch 2 times, most recently from 34e900c to dce155e Compare March 20, 2018 12:26
@agx agx mentioned this pull request Mar 20, 2018
@agx agx changed the title [NeedsTest] Linux-dmabuf with n_planes > 1 Linux-dmabuf with n_planes > 1 Mar 20, 2018
@agx
Copy link
Contributor Author

agx commented Mar 20, 2018

Depends on #736 which should go in first.

render/egl.c Outdated
}
}


attribs[atti++] = EGL_NONE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe adding an assertion here would be safer:

assert(atti < sizeof(attribs)/sizeof(attribs[0]));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the size of attribs is fixed we're safe but in case we change the number of planes we might forget to increase it so I added the assert.

@emersion
Copy link
Member

Is it expected that XRGB and NV12 don't render the same image?

@agx
Copy link
Contributor Author

agx commented Mar 21, 2018

@emersion where do we render a different image?

@emersion
Copy link
Member

I mean, weston-simple-dmabuf-drm --import-format=NV12 and weston-simple-dmabuf-drm --import-format=XRGB don't show the same image.

@agx
Copy link
Contributor Author

agx commented Mar 21, 2018

@SirCmpwn is using a loop for the attributes a must have? I do like the open coded version better since it makes it obvious what's happening. Once we support > 4 planes I would agree to not open code it.

@agx
Copy link
Contributor Author

agx commented Mar 21, 2018

@emersion ahh...thought so. Yes, I didn't bother to reproduce it exactly for the time being, it will make it simpler to find out which method is actually used.

@ascent12
Copy link
Member

I don't believe any format exists that has more than 4 planes. In fact, I don't know of any formats with more than 3, although I guess the 4th plane could be for an alpha channel or something.

I'd much prefer a loop as well. Unrolling is fine for maybe a few lines of code, but what's going on there is too much.
It wouldn't be hard to do it with an unnamed struct and an array.

@agx
Copy link
Contributor Author

agx commented Mar 21, 2018

@ascent12 I don't think we'll have more than 4 planes anytime soon either (in fact NV12 only uses two and for YUV we have more work ahead).

I'll use a loop then.

@agx
Copy link
Contributor Author

agx commented Mar 21, 2018

Removed the unrolled loop now

render/egl.c Outdated
EGL_DMA_BUF_PLANE ## N ## _PITCH_EXT, \
EGL_DMA_BUF_PLANE ## N ## _MODIFIER_LO_EXT, \
EGL_DMA_BUF_PLANE ## N ## _MODIFIER_HI_EXT \
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use macros, find another way

@ddevault
Copy link
Contributor

LGTM aside from the macro

@agx
Copy link
Contributor Author

agx commented Mar 21, 2018 via email

@emersion
Copy link
Member

Droped the macro in favour or spelled out constants.

It seems the macro is still here.

@agx
Copy link
Contributor Author

agx commented Mar 21, 2018 via email

@agx
Copy link
Contributor Author

agx commented Mar 23, 2018

Rebased against recent gles2 changes.

Copy link
Member

@emersion emersion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ddevault ddevault merged commit 7cc042f into swaywm:master Mar 23, 2018
@agx
Copy link
Contributor Author

agx commented Mar 23, 2018 via email

@ddevault
Copy link
Contributor

Thanks for the hard work!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants