Skip to contentSkip to conversation

drm: Use horizontal and vertical chroma subsampling factor while calculating offsets in the physical address of framebuffer

PATCH In review Ayan Kumar Halder 2 participants 4 messages Aug 17, 2018 – Aug 20, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm: Use horizontal and vertical chroma subsampling factor while calculating offsets in the physical address of framebuffer

For multi-planar formats, while calculating offsets in planes with index greater than 0 (ie second plane, third plane, etc), one needs to divide (src_x * cpp) with horizontal chroma subsampling factor and (src_y * pitch) with vertical chroma subsampling factor.

The reason being that the planes contain subsampled (ie reduced) data (by a factor of 2) and thus the while calculating the byte position coresponding to the x and y co-ordinates, one needs to be divide it with the sampling factor.

---
 drivers/gpu/drm/drm_fb_cma_helper.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_fb_cma_helper.c +9 -2
index b127061..47e0e2f 100644
@@ -86,14 +86,21 @@ dma_addr_t drm_fb_cma_get_gem_addr(struct drm_framebuffer *fb,
 {
 	struct drm_gem_cma_object *obj;
 	dma_addr_t paddr;
+	u8 h_div = 1, v_div = 1;
 
 	obj = drm_fb_cma_get_gem_obj(fb, plane);
 	if (!obj)
 		return 0;
 
 	paddr = obj->paddr + fb->offsets[plane];
-	paddr += fb->format->cpp[plane] * (state->src_x >> 16);
-	paddr += fb->pitches[plane] * (state->src_y >> 16);
+
+	if (plane > 0) {
+		h_div = fb->format->hsub;
+		v_div = fb->format->vsub;
+	}
+
+	paddr += (fb->format->cpp[plane] * (state->src_x >> 16)) / h_div;
+	paddr += (fb->pitches[plane] * (state->src_y >> 16)) / v_div;
 
 	return paddr;
 }
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Ayan Kumar Halder

For multi-planar formats, while calculating offsets in planes with index greater than 0 (ie second plane, third plane, etc), one needs to divide (src_x * cpp) with horizontal chroma subsampling factor and (src_y * pitch) with vertical chroma subsampling factor.

The reason being that the planes contain subsampled (ie reduced) data (by a factor of 2) and thus the

drop the extraneous "the" at the end of the line.

Quoted 1 line

while calculating the byte position coresponding to the x and y co-ordinates, one needs to be

and drop the extraneous "be" at the end of this line.

Quoted 3 lines

divide it with the sampling factor.

Otherwise, it looks good to me!

Best regards,
Liviu

Quoted 35 lines
---
 drivers/gpu/drm/drm_fb_cma_helper.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_fb_cma_helper.c +9 -2
index b127061..47e0e2f 100644
@@ -86,14 +86,21 @@ dma_addr_t drm_fb_cma_get_gem_addr(struct drm_framebuffer *fb,
 {
 	struct drm_gem_cma_object *obj;
 	dma_addr_t paddr;
+	u8 h_div = 1, v_div = 1;
 
 	obj = drm_fb_cma_get_gem_obj(fb, plane);
 	if (!obj)
 		return 0;
 
 	paddr = obj->paddr + fb->offsets[plane];
-	paddr += fb->format->cpp[plane] * (state->src_x >> 16);
-	paddr += fb->pitches[plane] * (state->src_y >> 16);
+
+	if (plane > 0) {
+		h_div = fb->format->hsub;
+		v_div = fb->format->vsub;
+	}
+
+	paddr += (fb->format->cpp[plane] * (state->src_x >> 16)) / h_div;
+	paddr += (fb->pitches[plane] * (state->src_y >> 16)) / v_div;
 
 	return paddr;
 }
Signature · 1 line
2.7.4
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
#2 lore raw
Quoted 13 lines · Liviu Dudau
Quoted 5 lines · Ayan Kumar Halder

For multi-planar formats, while calculating offsets in planes with index greater than 0 (ie second plane, third plane, etc), one needs to divide (src_x * cpp) with horizontal chroma subsampling factor and (src_y * pitch) with vertical chroma subsampling factor.

The reason being that the planes contain subsampled (ie reduced) data (by a factor of 2) and thus the

drop the extraneous "the" at the end of the line.

Quoted 1 line

while calculating the byte position coresponding to the x and y co-ordinates, one needs to be

and drop the extraneous "be" at the end of this line.

Quoted 8 lines
Quoted 3 lines

divide it with the sampling factor.

Otherwise, it looks good to me!

Thanks Liviu. I will update the commit message and push this in drm-misc-next.

Quoted 33 lines

Best regards,
Liviu

Quoted 30 lines
---
 drivers/gpu/drm/drm_fb_cma_helper.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_fb_cma_helper.c +9 -2
index b127061..47e0e2f 100644
@@ -86,14 +86,21 @@ dma_addr_t drm_fb_cma_get_gem_addr(struct drm_framebuffer *fb,
 {
 	struct drm_gem_cma_object *obj;
 	dma_addr_t paddr;
+	u8 h_div = 1, v_div = 1;
 
 	obj = drm_fb_cma_get_gem_obj(fb, plane);
 	if (!obj)
 		return 0;
 
 	paddr = obj->paddr + fb->offsets[plane];
-	paddr += fb->format->cpp[plane] * (state->src_x >> 16);
-	paddr += fb->pitches[plane] * (state->src_y >> 16);
+
+	if (plane > 0) {
+		h_div = fb->format->hsub;
+		v_div = fb->format->vsub;
+	}
+
+	paddr += (fb->format->cpp[plane] * (state->src_x >> 16)) / h_div;
+	paddr += (fb->pitches[plane] * (state->src_y >> 16)) / v_div;
 
Quoted 19 lines
Quoted 5 lines
drivers/gpu/drm/drm_fb_cma_helper.c +0 -0
 	return paddr;
 }
Signature · 1 line
2.7.4
Signature · 12 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ??\_(???)_/??
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
Quoted 16 lines · Ayan Halder
Quoted 15 lines · Liviu Dudau
Quoted 5 lines · Ayan Kumar Halder

For multi-planar formats, while calculating offsets in planes with index greater than 0 (ie second plane, third plane, etc), one needs to divide (src_x * cpp) with horizontal chroma subsampling factor and (src_y * pitch) with vertical chroma subsampling factor.

The reason being that the planes contain subsampled (ie reduced) data (by a factor of 2) and thus the

drop the extraneous "the" at the end of the line.

Quoted 1 line

while calculating the byte position coresponding to the x and y co-ordinates, one needs to be

and drop the extraneous "be" at the end of this line.

Quoted 2 lines

divide it with the sampling factor.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Otherwise, it looks good to me!

Thanks Liviu. I will update the commit message and push this in drm-misc-next.

Worth waiting for another review before pushing.

Best regards,
Liviu

Quoted 39 lines
Quoted 39 lines

Best regards,
Liviu

Quoted 35 lines
---
 drivers/gpu/drm/drm_fb_cma_helper.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_fb_cma_helper.c +9 -2
index b127061..47e0e2f 100644
@@ -86,14 +86,21 @@ dma_addr_t drm_fb_cma_get_gem_addr(struct drm_framebuffer *fb,
 {
 	struct drm_gem_cma_object *obj;
 	dma_addr_t paddr;
+	u8 h_div = 1, v_div = 1;
 
 	obj = drm_fb_cma_get_gem_obj(fb, plane);
 	if (!obj)
 		return 0;
 
 	paddr = obj->paddr + fb->offsets[plane];
-	paddr += fb->format->cpp[plane] * (state->src_x >> 16);
-	paddr += fb->pitches[plane] * (state->src_y >> 16);
+
+	if (plane > 0) {
+		h_div = fb->format->hsub;
+		v_div = fb->format->vsub;
+	}
+
+	paddr += (fb->format->cpp[plane] * (state->src_x >> 16)) / h_div;
+	paddr += (fb->pitches[plane] * (state->src_y >> 16)) / v_div;
 
 	return paddr;
 }
Signature · 1 line
2.7.4
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯