<div class="gmail_quote">On Mon, Feb 14, 2011 at 6:47 PM, José Fonseca <span dir="ltr"><<a href="mailto:jfonseca@vmware.com">jfonseca@vmware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On Sun, 2011-02-13 at 23:58 -0800, Dave Airlie wrote:<br>
> >> if(buf->base.base.size < size)<br>
> >> return 0;<br>
> >><br>
> >> @@ -242,13 +240,10 @@ pb_cache_is_buffer_compat(struct pb_cache_buffer<br>
> >> *buf,<br>
> >> if(!pb_check_usage(desc->usage, buf->base.base.usage))<br>
> >> return 0;<br>
> >><br>
> >> - map = pb_map(buf->buffer, PB_USAGE_DONTBLOCK, NULL);<br>
> >> - if (!map) {<br>
> >> - return -1;<br>
> >> - }<br>
> >> + if (buf->mgr->base.is_buffer_busy)<br>
> >> + if (buf->mgr->base.is_buffer_busy(&buf->mgr->base, buf->buffer))<br>
> >> + return -1;<br>
> ><br>
> > Oops, this is wrong. I will locally replace any occurences of<br>
> > "buf->mgr->base(.)" with "buf->mgr->provider(->)", which is how it was meant<br>
> > to be, but the idea remains the same. Please review.<br>
<br>
</div>Marek, I don't understand what you want to do here: you removed the<br>
pb_map, but you left the pb_unmap, and what will happen if<br>
is_buffer_busy is not defined?<br></blockquote><div><br>I didn't leave the pb_unmap call, it was removed too, I just cut it off in my second email, since it wasn't relevant to the typo. Sorry about that. So there's only one way: is_buffer_busy.<br>
<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im"><br>
><br>
> I actually suggested this originally, but Jose I think preferred using<br>
> the dontblock to the buffer mapping.<br>
<br>
</div>I'd prefer that there is one way of doing this, but I didn't/don't feel<br>
strong about this. IMO, having two ways, PB_USAGE_DONTBLOCK and<br>
is_buffer_busy, is not cleaner that just PB_USAGE_DONTBLOCK, even if<br>
is_buffer_busy is conceptually cleaner.<br></blockquote><div><br>The thing is mapping a buffer just to know whether it's being used is unnecessary, and the mapping itself may be slower than a simple is_busy query.<br>
<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
Marek, Would adding an inline function, pb_is_buffer_busy, that calls<br>
pb_map(PB_USAGE_DONTBLOCK)+pb_unmap inside work for you?<br>
<br>
Another way, would be to add is_buffer_busy and have the default<br>
implementation to do pb_map/pb_unmap.<br></blockquote><div><br>I can add a piece of code that uses pb_map/pb_unmap if the is_buffer_busy hook is not set, so that the original behavior is preserved. Would that be ok with you? Here's a new patch:<br>
<br><br> pb_bufmgr_cache: add is_buffer_busy hook and use it instead of non-blocking map<br> <br> This is cleaner and implementing the hook is optional.<br><br>diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr.h b/src/gallium/auxiliary/pipebuffer/pb_bufm<br>
index 2ef0216..960068c 100644<br>--- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr.h<br>+++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr.h<br>@@ -82,6 +82,10 @@ struct pb_manager<br> */<br> void<br> (*flush)( struct pb_manager *mgr );<br>
+<br>+ boolean<br>+ (*is_buffer_busy)( struct pb_manager *mgr,<br>+ struct pb_buffer *buf );<br> };<br> <br> <br>diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c b/src/gallium/auxiliary/pipebuffer/p<br>
index a6eb403..25accef 100644<br>--- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c<br>+++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c<br>@@ -227,8 +227,6 @@ pb_cache_is_buffer_compat(struct pb_cache_buffer *buf,<br>
pb_size size,<br> const struct pb_desc *desc)<br> {<br>- void *map;<br>-<br> if(buf->base.base.size < size)<br> return 0;<br> <br>@@ -242,13 +240,18 @@ pb_cache_is_buffer_compat(struct pb_cache_buffer *buf,<br>
if(!pb_check_usage(desc->usage, buf->base.base.usage))<br> return 0;<br> <br>- map = pb_map(buf->buffer, PB_USAGE_DONTBLOCK, NULL);<br>- if (!map) {<br>- return -1;<br>+ if (buf->mgr->provider->is_buffer_busy) {<br>
+ if (buf->mgr->provider->is_buffer_busy(buf->mgr->provider, buf->buffer))<br>+ return -1;<br>+ } else {<br>+ void *ptr = pb_map(buf->buffer, PB_USAGE_DONTBLOCK, NULL);<br>+<br>+ if (!ptr)<br>
+ return -1;<br>+<br>+ pb_unmap(buf->buffer);<br> }<br> <br>- pb_unmap(buf->buffer);<br>- <br> return 1;<br> }<br><br>Marek<br></div></div>