Skip to contentSkip to conversation

uxa/glamor: Enable the rest glamor rendering functions.

PATCH In review [email protected] 2 participants 9 messages Dec 13, 2011 – Dec 14, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 uxa/glamor: Enable the rest glamor rendering functions.

From: Zhigang Gong <[email protected]>

This commit enable all the rest glamor rendering functions. Tested with latest glamor master branch, can pass rendercheck.

One thing need to be pointed out is the picture's handling. Pictures support many different color formats, but glamor's texture only support a few color formats. And the most common scenario is that we create a pixmap with a color depth and then attach it to a picture which has a specific color format with the same color depth. But there is no way to change a texture's internal format after the texture was allocated. If you do that, the OpenGL will allocate a new texture. And then the glamor side and UXA side will be inconsitence. So for all the picture related operations, we can't fallback to UXA path directly, even it is rather a strainth forward operation. So for the get_image, Addtraps.., we have to add wrappers function for them to jump into glamor firstly.

---
 src/intel_uxa.c  |   14 +++++++-
 uxa/uxa-accel.c  |   88 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 uxa/uxa-glamor.h |   16 ++++++++-
 uxa/uxa-glyphs.c |   21 ++++++++++++
 uxa/uxa-priv.h   |    8 +++++
 uxa/uxa-render.c |   90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 uxa/uxa.c        |    4 +-
 7 files changed, 234 insertions(+), 7 deletions(-)
src/intel_uxa.c +12 -2
index e4a5270..a79affa 100644
@@ -1108,6 +1108,9 @@ intel_uxa_create_pixmap(ScreenPtr screen, int w, int h, int depth,
 				list_del(&priv->in_flight);
 				screen->ModifyPixmapHeader(pixmap, w, h, 0, 0, stride, NULL);
 				intel_set_pixmap_private(pixmap, priv);
+
+				if (!intel_glamor_create_textured_pixmap(pixmap))
+					intel_set_pixmap_bo(pixmap, NULL);
 				return pixmap;
 			}
 		}
@@ -1145,8 +1148,15 @@ intel_uxa_create_pixmap(ScreenPtr screen, int w, int h, int depth,
 		list_init(&priv->batch);
 		list_init(&priv->flush);
 		intel_set_pixmap_private(pixmap, priv);
-
-		intel_glamor_create_textured_pixmap(pixmap);
+		/* Create textured pixmap failed means glamor fail to create
+		 * a texture from the BO for some reasons, and then glamor
+		 * create a new texture attached to the pixmap, and all the
+		 * consequent rendering operations on this pixmap will never
+		 * fallback to UXA path, so we don't need to hold the useless
+		 * BO if it is the case.
+		 */
+		if (!intel_glamor_create_textured_pixmap(pixmap))
+			intel_set_pixmap_bo(pixmap, NULL);
 	}
 
 	return pixmap;
uxa/uxa-accel.c +87 -1

116 lines not on this page · raw message

uxa/uxa-glamor.h +14 -2
index 2c23098..71a9c29 100644
@@ -37,8 +37,20 @@
 #ifdef USE_GLAMOR
 #include "glamor.h"
 #else
-#define glamor_fill_spans_nf(...)  FALSE
-#define glamor_poly_fill_rect_nf(...) FALSE
+#define glamor_fill_spans_nf(...)	FALSE
+#define glamor_poly_fill_rect_nf(...)	FALSE
+#define glamor_put_image_nf(...)	FALSE
+#define glamor_copy_n_to_n_nf(...)	FALSE
+#define glamor_get_spans_nf(...)	FALSE
+#define glamor_set_spans_nf(...)	FALSE
+#define glamor_get_image_nf(...)	FALSE
+#define glamor_glyphs_nf(...)		FALSE
+#define glamor_glyph_unrealize(...)	;
+#define glamor_composite_nf(...)	FALSE
+#define glamor_composite_rects_nf(...)	FALSE
+#define glamor_trapezoids_nf(...)	FALSE
+#define glamor_triangles_nf(...)	FALSE
+#define glamor_add_traps_nf(...)	FALSE
 #endif
 
 #endif /* UXA_GLAMOR_H */
uxa/uxa-glyphs.c +21 -0
index 6c9ea0d..2156578 100644
@@ -65,6 +65,7 @@
 #include <stdlib.h>
 
 #include "uxa-priv.h"
+#include "uxa-glamor.h"
 #include "../src/common.h"
 
 #include "mipict.h"
@@ -304,6 +305,7 @@ uxa_glyph_unrealize(ScreenPtr screen,
 		    GlyphPtr glyph)
 {
 	struct uxa_glyph *priv;
+	uxa_screen_t *uxa_screen = uxa_get_screen(screen);
 
 	/* Use Lookup in case we have not attached to this glyph. */
 	priv = dixLookupPrivate(&glyph->devPrivates, &uxa_glyph_key);
@@ -314,6 +316,9 @@ uxa_glyph_unrealize(ScreenPtr screen,
 
 	uxa_glyph_set_private(glyph, NULL);
 	free(priv);
+
+	if (uxa_screen->info->flags & UXA_USE_GLAMOR)
+		glamor_glyph_unrealize(screen, glyph);
 }
 
 /* Cut and paste from render/glyph.c - probably should export it instead */
@@ -1062,6 +1067,22 @@ uxa_glyphs(CARD8 op,
 	int width, height, ret;
 	PicturePtr localDst = pDst;
 
+	if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+		uxa_picture_prepare_access(pDst, UXA_GLAMOR_ACCESS_RW);
+		uxa_picture_prepare_access(pSrc, UXA_GLAMOR_ACCESS_RO);
+		if (glamor_glyphs_nf(op,
+				     pSrc, pDst, maskFormat,
+				     xSrc, ySrc, nlist, list, glyphs)) {
+			uxa_picture_finish_access(pSrc, UXA_GLAMOR_ACCESS_RO);
+			uxa_picture_finish_access(pDst, UXA_GLAMOR_ACCESS_RW);
+			return;
+		} else {
+			uxa_picture_finish_access(pSrc, UXA_GLAMOR_ACCESS_RO);
+			uxa_picture_finish_access(pDst, UXA_GLAMOR_ACCESS_RO);
+			goto fallback;
+		}
+	}
+
 	if (!uxa_screen->info->prepare_composite ||
 	    uxa_screen->swappedOut ||
 	    uxa_screen->force_fallback ||
uxa/uxa-priv.h +8 -0
index a455f25..d6d857f 100644
@@ -292,6 +292,14 @@ void
 uxa_get_image(DrawablePtr pDrawable, int x, int y, int w, int h,
 	      unsigned int format, unsigned long planeMask, char *d);
 
+void
+uxa_get_spans(DrawablePtr pDrawable, int wMax, DDXPointPtr ppt,
+	      int *pwidth, int nspans, char *pdstStart);
+
+void
+uxa_add_traps(PicturePtr pPicture,
+	      INT16 x_off, INT16 y_off, int ntrap, xTrap * traps);
+
 extern const GCOps uxa_ops;
 
 #ifdef RENDER
uxa/uxa-render.c +90 -0

130 lines not on this page · raw message

uxa/uxa.c +2 -2
index 5a3c0be..5b3d709 100644
@@ -521,7 +521,7 @@ Bool uxa_driver_init(ScreenPtr screen, uxa_driver_t * uxa_driver)
 	screen->GetImage = uxa_get_image;
 
 	uxa_screen->SavedGetSpans = screen->GetSpans;
-	screen->GetSpans = uxa_check_get_spans;
+	screen->GetSpans = uxa_get_spans;
 
 	uxa_screen->SavedCopyWindow = screen->CopyWindow;
 	screen->CopyWindow = uxa_copy_window;
@@ -559,7 +559,7 @@ Bool uxa_driver_init(ScreenPtr screen, uxa_driver_t * uxa_driver)
 			ps->Trapezoids = uxa_trapezoids;
 
 			uxa_screen->SavedAddTraps = ps->AddTraps;
-			ps->AddTraps = uxa_check_add_traps;
+			ps->AddTraps = uxa_add_traps;
 		}
 	}
 #endif
Signature · 1 line
1.7.4.4
#1 lore raw
Quoted 5 lines · On Tue, 13 Dec 2011 22:31:41 +0800, [email protected] wrote:

From: Zhigang Gong <[email protected]>

This commit enable all the rest glamor rendering functions. Tested with latest glamor master branch, can pass rendercheck.

Quoted 13 lines

One thing need to be pointed out is the picture's handling. Pictures support many different color formats, but glamor's texture only support a few color formats. And the most common scenario is that we create a pixmap with a color depth and then attach it to a picture which has a specific color format with the same color depth. But there is no way to change a texture's internal format after the texture was allocated. If you do that, the OpenGL will allocate a new texture. And then the glamor side and UXA side will be inconsitence. So for all the picture related operations, we can't fallback to UXA path directly, even it is rather a strainth forward operation. So for the get_image, Addtraps.., we have to add wrappers function for them to jump into glamor firstly.

Can we create multiple textures referencing the same bo but with different formats? Or are we going to run afoul of the coherency model with GL?
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#2 lore raw
Quoted 29 lines

-----Original Message-----
From: Chris Wilson [mailto:[email protected]]
Sent: Wednesday, December 14, 2011 2:20 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] uxa/glamor: Enable the rest glamor rendering functions.

Quoted 5 lines · On Tue, 13 Dec 2011 22:31:41 +0800, [email protected] wrote:

From: Zhigang Gong <[email protected]>

This commit enable all the rest glamor rendering functions. Tested with latest glamor master branch, can pass rendercheck.

Quoted 12 lines

One thing need to be pointed out is the picture's handling. Pictures support many different color formats, but glamor's texture only support a few color formats. And the most common scenario is that we create a pixmap with a color depth and then attach it to a picture which has a specific color format with the same color depth. But there is no way to change a texture's internal format after the texture was allocated.
If you do that, the OpenGL will allocate a new texture. And then the glamor side and UXA side will be inconsitence. So for all the picture related operations, we can't fallback to UXA path directly, even it is rather a strainth forward operation. So for the get_image, Addtraps.., we have to add wrappers function for them to jump into glamor firstly.

Quoted 2 lines

Can we create multiple textures referencing the same bo but with different formats?

AFAIK, it's impossible to match all possible picture formats to a OpenGL internal format.
We have to have a new texture attached to glamor for incompatible format. The
old texture is created from DDX's BO and has incorrect internal format. IMO, we
can't make any use of this wrong texture within glamor, so I just don't create it and
return a false to DDX layer to notify the DDX to unlink the BO. All the consequent
rendering operation on this pixmap will be handled within glamor scope and target
to the new texture with correct format.

Quoted 2 lines

Or are we going to run afoul of the coherency model with GL?

My understanding is, if the picture's format is incompatible with OpenGL's internal
format.

--Zhigang

Quoted 4 lines

-Chris

--
Chris Wilson, Intel Open Source Technology Centre

#3 lore raw
In reply to [email protected]
Quoted 4 lines · On Tue, 13 Dec 2011 22:31:41 +0800, [email protected] wrote:

From: Zhigang Gong <[email protected]>

This commit enable all the rest glamor rendering functions. Tested with latest glamor master branch, can pass rendercheck.

Hmm, it exposes an issue with keeping a bo cache independent of mesa and trying to feed it our own handles:

Region for name 6 already exists but is not compatible

The w/a for this would be:

src/intel_glamor.c +1 -0
index 0cf8ed7..2757fd6 100644
@@ -91,6 +91,7 @@ intel_glamor_create_textured_pixmap(PixmapPtr pixmap)
        priv = intel_get_pixmap_private(pixmap);
        if (glamor_egl_create_textured_pixmap(pixmap, priv->bo->handle,
                                              priv->stride)) {
+               drm_intel_bo_disable_reuse(priv->bo);
                priv->pinned = 1;
                return TRUE;
        } else

but that gives up all pretense of maintaining a bo cache. -Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#4 lore raw

src/intel_glamor.c index

Quoted 24 lines

-----Original Message-----
From: Chris Wilson [mailto:[email protected]]
Sent: Wednesday, December 14, 2011 2:45 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] uxa/glamor: Enable the rest glamor rendering functions.

Quoted 4 lines · On Tue, 13 Dec 2011 22:31:41 +0800, [email protected] wrote:

From: Zhigang Gong <[email protected]>

This commit enable all the rest glamor rendering functions. Tested with latest glamor master branch, can pass rendercheck.

Hmm, it exposes an issue with keeping a bo cache independent of mesa and trying to feed it our own handles:

Region for name 6 already exists but is not compatible

The w/a for this would be:

src/intel_glamor.c index renamed from src/intel_glamor.c +0 -0

0cf8ed7..2757fd6

Quoted 14 lines

100644

src/intel_glamor.c +1 -0
@@ -91,6 +91,7 @@ intel_glamor_create_textured_pixmap(PixmapPtr
 pixmap)
        priv = intel_get_pixmap_private(pixmap);
        if (glamor_egl_create_textured_pixmap(pixmap,
 priv->bo->handle,
                                              priv->stride)) {
+               drm_intel_bo_disable_reuse(priv->bo);
                priv->pinned = 1;
                return TRUE;
        } else
Quoted 1 line

but that gives up all pretense of maintaining a bo cache.

Yes, I think this impacts the performance. Actually, I noticed this problem and I
spent some time to track the root cause. If everything is ok, this error should
not be triggered. Although the same BO maybe reused to create a new pixmap, the previous pixmap which own this BO should be already destroyed. And the previous image created with the previous pixmap should be destroyed either.

And then, when we create a new pixmap/image with this BO, MESA should not find any exist image/region for this BO. But it does happen. I tracked further into
mesa internal and found that the previous image was not destroyed when we call eglDestroyImageKHR, as its reference count is decreased to zero. It's weird
for me. Further tracking shows that the root cause is when I use the texture(bind to
the image) as a shader's source texture, and call glDrawArrays to perform the
rendering, the texture's reference count will be increased by 1 before return
from glDrawArrays. And I failed to find any API to decrease it. Then this texture
can't be freed when destroy that texture and thus the image's reference count
will also remain 1 and can't be freed either.

The attached is a simple case to show this bug. It was modified from the eglkms.c
in mesa-demos.

I did send this issue to mesa-dev. Don't have a solution or explanation so far. Any
idea?

Quoted 4 lines

-Chris

--
Chris Wilson, Intel Open Source Technology Centre

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#5 lore raw
Quoted 39 lines · Zhigang Gong

src/intel_glamor.c index

Quoted 24 lines

-----Original Message-----
From: Chris Wilson [mailto:[email protected]]
Sent: Wednesday, December 14, 2011 2:45 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] uxa/glamor: Enable the rest glamor rendering functions.

Quoted 4 lines · On Tue, 13 Dec 2011 22:31:41 +0800, [email protected] wrote:

From: Zhigang Gong <[email protected]>

This commit enable all the rest glamor rendering functions. Tested with latest glamor master branch, can pass rendercheck.

Hmm, it exposes an issue with keeping a bo cache independent of mesa and trying to feed it our own handles:

Region for name 6 already exists but is not compatible

The w/a for this would be:

src/intel_glamor.c index renamed from src/intel_glamor.c +0 -0

0cf8ed7..2757fd6

Quoted 14 lines

100644

src/intel_glamor.c +1 -0
@@ -91,6 +91,7 @@ intel_glamor_create_textured_pixmap(PixmapPtr
 pixmap)
        priv = intel_get_pixmap_private(pixmap);
        if (glamor_egl_create_textured_pixmap(pixmap,
 priv->bo->handle,
                                              priv->stride)) {
+               drm_intel_bo_disable_reuse(priv->bo);
                priv->pinned = 1;
                return TRUE;
        } else
Quoted 9 lines
Quoted 1 line

but that gives up all pretense of maintaining a bo cache.

Yes, I think this impacts the performance. Actually, I noticed this problem and I
spent some time to track the root cause. If everything is ok, this error should
not be triggered. Although the same BO maybe reused to create a new pixmap, the previous pixmap which own this BO should be already destroyed. And the previous image created with the previous pixmap should be destroyed either.

Certainly it looks like glamor is taking all necessary steps to decouple the bo from the textures and renderbuffer upon pixmap finish. There is one other potential race here in that the ddx will mark the bo as purgeable as soon as it releases it back to the cache, but it may not yet have been submitted by mesa in its execbuffer. The kernel may choose to free the memory associated with the bo before that happens, and may rightfully complain the userspace is doing something silly.

Quoted 9 lines

And then, when we create a new pixmap/image with this BO, MESA should not find any exist image/region for this BO. But it does happen. I tracked further into
mesa internal and found that the previous image was not destroyed when we call eglDestroyImageKHR, as its reference count is decreased to zero. It's weird
for me. Further tracking shows that the root cause is when I use the texture(bind to
the image) as a shader's source texture, and call glDrawArrays to perform

Quoted 8 lines

the
rendering, the texture's reference count will be increased by 1 before return
from glDrawArrays. And I failed to find any API to decrease it. Then this texture
can't be freed when destroy that texture and thus the image's reference count
will also remain 1 and can't be freed either.

I'm looking at update_texture_state() which appears to hold onto a reference to the texobj until its slot is reused. If the object is simply destroyed and the unit disabled, the slot is skipped and the old reference remains. _mesa_update_state (which calls into update_texture_state) would seem to be only invoked upon a draw primitives. Binding a dummy texture/fb and doing a dummy render might be a little extreme as a workaround!
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#6 lore raw
Quoted 53 lines

-----Original Message-----
From: Chris Wilson [mailto:[email protected]]
Sent: Wednesday, December 14, 2011 7:12 PM
To: Zhigang Gong
Cc: [email protected]; [email protected]
Subject: RE: [PATCH] uxa/glamor: Enable the rest glamor rendering functions.

Quoted 9 lines · Zhigang Gong
Quoted 9 lines

-----Original Message-----
From: Chris Wilson [mailto:[email protected]]
Sent: Wednesday, December 14, 2011 2:45 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] uxa/glamor: Enable the rest glamor rendering functions.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines · On Tue, 13 Dec 2011 22:31:41 +0800, [email protected] wrote:

From: Zhigang Gong <[email protected]>

This commit enable all the rest glamor rendering functions. Tested with latest glamor master branch, can pass rendercheck.

Hmm, it exposes an issue with keeping a bo cache independent of

mesa

Quoted 4 lines
Quoted 4 lines

and trying to feed it our own handles:

Region for name 6 already exists but is not compatible

Quoted 8 lines

src/intel_glamor.c index

Quoted 3 lines

The w/a for this would be:

src/intel_glamor.c index renamed from src/intel_glamor.c +0 -0

0cf8ed7..2757fd6

src/intel_glamor.c

Quoted 4 lines

100644

src/intel_glamor.c +0 -0
@@ -91,6 +91,7 @@

intel_glamor_create_textured_pixmap(PixmapPtr

Quoted 12 lines
Quoted 11 lines
src/intel_glamor.c +1 -0
 pixmap)
        priv = intel_get_pixmap_private(pixmap);
        if (glamor_egl_create_textured_pixmap(pixmap,
 priv->bo->handle,
                                              priv->stride)) {
+               drm_intel_bo_disable_reuse(priv->bo);
                priv->pinned = 1;
                return TRUE;
        } else

but that gives up all pretense of maintaining a bo cache.

Quoted 8 lines
Quoted 6 lines

Yes, I think this impacts the performance. Actually, I noticed this problem and I spent some time to track the root cause. If everything is ok, this error should not be triggered. Although the same BO maybe reused to create a new pixmap, the previous pixmap which own this BO should be already destroyed. And the previous image created with the previous pixmap should be destroyed either.

Certainly it looks like glamor is taking all necessary steps to decouple

the

Quoted 6 lines

bo from the textures and renderbuffer upon pixmap finish. There is one other potential race here in that the ddx will mark the bo as purgeable as soon as it releases it back to the cache, but it may not yet have been submitted by mesa in its execbuffer. The kernel may choose to free the memory associated with the bo before that happens, and may rightfully complain the userspace is doing something silly.

Right, we do have this race if the kernel free the BO's memory prior to The mesa submit its execbuffer. Hmm. But I think that may not be a real problem, as once we call intel_set_pixmap_bo(pixmap, NULL) to unlink the bo from the pixmap, the BO will not be released at DRM layer immediately,
instead, it will be put on a in_flight list. And intel_batch_submit will empty the
list, considering after switching to glamor, each pixmap's batch buffer should
be empty, then the driver will only call intel_batch_submit at intel_flush_rendering
which is called from intel_uxa_block_handler and is after the intel_glamor_flush.
At intel_glamor_flush, it will do a glFlush, my understanding is glFlush should make sure the execbuffer was submitted to GPU. But I'm not very sure. Can you confirm that? Thanks.

Quoted 15 lines
Quoted 2 lines

And then, when we create a new pixmap/image with this BO, MESA

should

Quoted 11 lines

not find any exist image/region for this BO. But it does happen. I tracked further into mesa internal and found that the previous image was not destroyed when we call eglDestroyImageKHR, as its reference count is decreased to zero. It's weird for me. Further tracking shows that the root cause is when I use the texture(bind to the image) as a shader's source texture, and call glDrawArrays to perform the rendering, the texture's reference count will be increased by 1 before return from glDrawArrays. And I failed to find any API to decrease it. Then this texture can't be freed when destroy that texture and thus the image's reference count will also remain 1 and can't be freed either.

Quoted 7 lines

I'm looking at update_texture_state() which appears to hold onto a reference to the texobj until its slot is reused. If the object is simply destroyed and the unit disabled, the slot is skipped and the old reference remains. _mesa_update_state (which calls into update_texture_state) would seem to be only invoked upon a draw primitives. Binding a dummy texture/fb and doing a dummy render might be a little extreme as a workaround!

Thanks for providing this workaround, I did try that way with my simple test case, it works. I just wonder whether this is a bug of MESA.
I will implement it in glamor before we get a better solution.

Quoted 4 lines

-Chris

--
Chris Wilson, Intel Open Source Technology Centre

#7 lore raw
Quoted 69 lines · Zhigang Gong
Quoted 53 lines

-----Original Message-----
From: Chris Wilson [mailto:[email protected]]
Sent: Wednesday, December 14, 2011 7:12 PM
To: Zhigang Gong
Cc: [email protected]; [email protected]
Subject: RE: [PATCH] uxa/glamor: Enable the rest glamor rendering functions.

Quoted 9 lines · Zhigang Gong
Quoted 9 lines

-----Original Message-----
From: Chris Wilson [mailto:[email protected]]
Sent: Wednesday, December 14, 2011 2:45 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] uxa/glamor: Enable the rest glamor rendering functions.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines · On Tue, 13 Dec 2011 22:31:41 +0800, [email protected] wrote:

From: Zhigang Gong <[email protected]>

This commit enable all the rest glamor rendering functions. Tested with latest glamor master branch, can pass rendercheck.

Hmm, it exposes an issue with keeping a bo cache independent of

mesa

Quoted 4 lines
Quoted 4 lines

and trying to feed it our own handles:

Region for name 6 already exists but is not compatible

Quoted 8 lines

src/intel_glamor.c index

Quoted 3 lines

The w/a for this would be:

src/intel_glamor.c index renamed from src/intel_glamor.c +0 -0

0cf8ed7..2757fd6

src/intel_glamor.c

Quoted 4 lines

100644

src/intel_glamor.c +0 -0
@@ -91,6 +91,7 @@

intel_glamor_create_textured_pixmap(PixmapPtr

Quoted 12 lines
Quoted 11 lines
src/intel_glamor.c +1 -0
 pixmap)
        priv = intel_get_pixmap_private(pixmap);
        if (glamor_egl_create_textured_pixmap(pixmap,
 priv->bo->handle,
                                              priv->stride)) {
+               drm_intel_bo_disable_reuse(priv->bo);
                priv->pinned = 1;
                return TRUE;
        } else

but that gives up all pretense of maintaining a bo cache.

Quoted 8 lines
Quoted 6 lines

Yes, I think this impacts the performance. Actually, I noticed this problem and I spent some time to track the root cause. If everything is ok, this error should not be triggered. Although the same BO maybe reused to create a new pixmap, the previous pixmap which own this BO should be already destroyed. And the previous image created with the previous pixmap should be destroyed either.

Certainly it looks like glamor is taking all necessary steps to decouple

the

Quoted 6 lines

bo from the textures and renderbuffer upon pixmap finish. There is one other potential race here in that the ddx will mark the bo as purgeable as soon as it releases it back to the cache, but it may not yet have been submitted by mesa in its execbuffer. The kernel may choose to free the memory associated with the bo before that happens, and may rightfully complain the userspace is doing something silly.

Quoted 16 lines

Right, we do have this race if the kernel free the BO's memory prior to The mesa submit its execbuffer. Hmm. But I think that may not be a real problem, as once we call intel_set_pixmap_bo(pixmap, NULL) to unlink the bo from the pixmap, the BO will not be released at DRM layer immediately,
instead, it will be put on a in_flight list. And intel_batch_submit will empty the
list, considering after switching to glamor, each pixmap's batch buffer should
be empty, then the driver will only call intel_batch_submit at intel_flush_rendering
which is called from intel_uxa_block_handler and is after the intel_glamor_flush.
At intel_glamor_flush, it will do a glFlush, my understanding is glFlush should make sure the execbuffer was submitted to GPU. But I'm not very sure. Can you confirm that? Thanks.

It shouldn't go on the in-flight list because we're not using intel_batchbuffer any more and so it will not be referenced by the batch.

This patch along with calling dispatch->glFlush() after deleting the textured pixmap is enough to silence the warning inside mesa and prevent the purgeable race:

(quoted diff) +0 -0

b/src/mesa/drivers/dri/intel/intel_context.c
index 068b305..347a5d6 100644

src/mesa/drivers/dri/intel/intel_context.c +3 -0
@@ -34,6 +34,7 @@
 #include "main/imports.h"
 #include "main/points.h"
 #include "main/renderbuffer.h"
+#include "main/state.h"
 
 #include "swrast/swrast.h"
 #include "swrast_setup/swrast_setup.h"
@@ -527,6 +528,8 @@ intel_glFlush(struct gl_context *ctx)
    intel_flush_front(ctx);
    if (intel->is_front_buffer_rendering)
       intel->need_throttle = true;
+
+   _mesa_update_state(ctx);
 }
 
src/mesa/main/texstate.c +2 -0
index 7cd2858..4bcaec0 100644
@@ -557,6 +557,7 @@ update_texture_state( struct gl_context *ctx )
 
       if (enabledTargets == 0x0) {
          /* neither vertex nor fragment processing uses this unit */
+	 _mesa_reference_texobj(&texUnit->_Current, NULL);
          continue;
       }
 
@@ -592,6 +593,7 @@ update_texture_state( struct gl_context *ctx )
          }
          else {
             /* fixed-function: texture unit is really disabled */
+	    _mesa_reference_texobj(&texUnit->_Current, NULL);
             continue;
          }
       }
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#8 lore raw
In reply to [email protected]
Quoted 4 lines · On Tue, 13 Dec 2011 22:31:41 +0800, [email protected] wrote:

From: Zhigang Gong <[email protected]>

This commit enable all the rest glamor rendering functions. Tested with latest glamor master branch, can pass rendercheck.

Sure enough, it passes rendercheck. Well done!

However, glyph rendering is off, the characters look incorrectly scaled and slightly out-of-position. And it will eventually chase a NULL pointer inside glamor's glyph cache.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre