<div dir="ltr"><div><div><div>Julien,<br><br></div>Mind if I ask what your use-case is? We've been talking about trying to remove tiled mapping from the driver and using blits instead. I don't want to suddenly drop someone off a performance cliff.<br><br></div>Thanks,<br><br></div>--Jason<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 14, 2017 at 3:05 AM, Julien Isorce <span dir="ltr"><<a href="mailto:julien.isorce@gmail.com" target="_blank">julien.isorce@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Already implemented for Gallium drivers.<br>
<br>
Useful for gbm_bo_(un)map.<br>
<br>
Tests:<br>
By porting wayland/weston/clients/simple-<wbr>dmabuf-drm.c to GBM.<br>
kmscube --mode=rgba<br>
kmscube --mode=nv12-1img<br>
kmscube --mode=nv12-2img<br>
piglit ext_image_dma_buf_import-<wbr>refcount -auto<br>
piglit ext_image_dma_buf_import-<wbr>transcode-nv12-as-r8-gr88 -auto<br>
piglit ext_image_dma_buf_import-<wbr>sample_rgb -fmt=XR24 -alpha-one -auto<br>
piglit ext_image_dma_buf_import-<wbr>sample_rgb -fmt=AR24 -auto<br>
piglit ext_image_dma_buf_import-<wbr>sample_yuv -fmt=NV12 -auto<br>
piglit ext_image_dma_buf_import-<wbr>sample_yuv -fmt=YU12 -auto<br>
piglit ext_image_dma_buf_import-<wbr>sample_yuv -fmt=YV12 -auto<br>
<br>
v2: add early return if (flag & MAP_INTERNAL_MASK)<br>
v3: take input rect into account and test with kmscube and piglit.<br>
v4: handle wraparound and bo reference.<br>
v5: indent, exclude 0 width and height on the boundary, map bo<br>
independently of the image.<br>
<br>
Signed-off-by: Julien Isorce <<a href="mailto:jisorce@oblong.com">jisorce@oblong.com</a>><br>
---<br>
src/mesa/drivers/dri/i965/<wbr>intel_screen.c | 65 ++++++++++++++++++++++++++++++<wbr>+-<br>
1 file changed, 63 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>intel_screen.c b/src/mesa/drivers/dri/i965/<wbr>intel_screen.c<br>
index cdc36ad..88bd982 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>intel_screen.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>intel_screen.c<br>
@@ -755,6 +755,67 @@ intel_create_image(__DRIscreen *dri_screen,<br>
loaderPrivate);<br>
}<br>
<br>
+static void *<br>
+intel_map_image(__DRIcontext *context, __DRIimage *image,<br>
+ int x0, int y0, int width, int height,<br>
+ unsigned int flags, int *stride, void **map_info)<br>
+{<br>
+ struct brw_context *brw = NULL;<br>
+ struct brw_bo *bo = NULL;<br>
+ void *raw_data = NULL;<br>
+ GLuint pix_w = 1;<br>
+ GLuint pix_h = 1;<br>
+ GLint pix_bytes = 1;<br>
+<br>
+ if (!context || !image || !stride || !map_info || *map_info)<br>
+ return NULL;<br>
+<br>
+ if (x0 < 0 || x0 >= image->width || width > image->width - x0)<br>
+ return NULL;<br>
+<br>
+ if (y0 < 0 || y0 >= image->height || height > image->height - y0)<br>
+ return NULL;<br>
+<br>
+ if (flags & MAP_INTERNAL_MASK)<br>
+ return NULL;<br>
+<br>
+ brw = context->driverPrivate;<br>
+ bo = image->bo;<br>
+<br>
+ assert(brw);<br>
+ assert(bo);<br>
+<br>
+ /* DRI flags and GL_MAP.*_BIT flags are the same, so just pass them on. */<br>
+ raw_data = brw_bo_map(brw, bo, flags);<br>
+ if (!raw_data)<br>
+ return NULL;<br>
+<br>
+ _mesa_get_format_block_size(<wbr>image->format, &pix_w, &pix_h);<br>
+ pix_bytes = _mesa_get_format_bytes(image-><wbr>format);<br>
+<br>
+ assert(pix_w);<br>
+ assert(pix_h);<br>
+ assert(pix_bytes > 0);<br>
+<br>
+ raw_data += ((x0 / pix_w) * pix_bytes) + (y0 / pix_h) * image->pitch;<br>
+<br>
+ brw_bo_reference(bo);<br>
+<br>
+ *stride = image->pitch;<br>
+ *map_info = bo;<br>
+<br>
+ return raw_data;<br>
+}<br>
+<br>
+static void<br>
+intel_unmap_image(__<wbr>DRIcontext *context, __DRIimage *image, void *map_info)<br>
+{<br>
+ struct brw_bo *bo = map_info;<br>
+<br>
+ brw_bo_unmap(bo);<br>
+ brw_bo_unreference(bo);<br>
+}<br>
+<br>
static __DRIimage *<br>
intel_create_image_with_<wbr>modifiers(__DRIscreen *dri_screen,<br>
int width, int height, int format,<br>
@@ -1305,8 +1366,8 @@ static const __DRIimageExtension intelImageExtension = {<br>
.createImageFromDmaBufs = intel_create_image_from_dma_<wbr>bufs,<br>
.blitImage = NULL,<br>
.getCapabilities = NULL,<br>
- .mapImage = NULL,<br>
- .unmapImage = NULL,<br>
+ .mapImage = intel_map_image,<br>
+ .unmapImage = intel_unmap_image,<br>
.createImageWithModifiers = intel_create_image_with_<wbr>modifiers,<br>
.createImageFromDmaBufs2 = intel_create_image_from_dma_<wbr>bufs2,<br>
.queryDmaBufFormats = intel_query_dma_buf_formats,<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.7.4<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div>