On 14 May 2012 16:50, Ian Romanick <span dir="ltr">&lt;<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 05/14/2012 02:13 PM, Paul Berry wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Just to update the list: I had an in-person meeting with Eric, Ian, and<br>
Ken today to discuss the design of the patch series and decide what to<br>
do about it.  We agreed to go ahead and push the patches to master as<br>
is, and to make further improvements as time goes on.<br>
<br>
Specific improvements that were discussed:<br>
<br>
- I seem to be the only person who thinks it makes sense for the<br>
brw_blorp_params class to contain an exec() function.  In the interest<br>
of avoiding a rebasing nightmare, I will go ahead with the patches as<br>
they are, and submitt a follow up patch which replaces<br>
brw_blorp_params::exec() with a global function brw_blorp_exec(const<br>
brw_blorp_params *).<br>
</blockquote>
<br></div>
Part of the issue was that &quot;exec&quot; isn&#39;t a terrific name, and exec&#39;ing a set of parameters doesn&#39;t have implicit meaning.  My preference was for a function, similar to what you mention, called brw_blorp_do_blit or similar.<br>
</blockquote><div><br>I&#39;m not going to try to change your mind, but in the spirit of clarifying the method that was behind my madness:<br><br>I did not have the clarity of mind during our discussion today to point out that in creating the brw_blorp_params class, I was in fact trying to follow a standard design pattern, the Gang of Four &quot;command&quot; pattern (<a href="http://en.wikipedia.org/wiki/Command_pattern">http://en.wikipedia.org/wiki/Command_pattern</a>).  The idea of that pattern is to encapsulate all of the information necessary to perform an action into a class; this allows the action to be treated as a first class object.  The usual reasons why it might be useful for the action to be a first class object are so that it can be stored in an undo history, so that its execution can be deferred, restarted, or repeated, or so that some other part of the program can take the opportunity to tweak the parameters before the action is performed.  In this particular case the benefit is that the various phases of the action can be performed by different functions without an explosion of parameter passing, and so that actions that share some, but not all, of their implementation (HiZ ops and blits, in this case) can be implemented by using a base class with virtual functions.  It&#39;s also possible that in the future, the blorp engine might be able to record the last command it executed, so that it can compare that to the command it&#39;s being asked to execute and avoid some redundant pipeline setup.  In the command pattern, it is conventional to make the function that performs the action a member of the command class and to call it &quot;exec&quot; or &quot;execute&quot;.  So from my point of view, this function name actually *does* have an implicit meaning.  I&#39;m aware, of course, that most of my fellow Mesa developers don&#39;t share my respect for Gang of Four-style design :)<br>
<br>(Note that in a strict implementation of the &quot;command&quot; pattern there are other auxiliary classes involved, but I thought that would be way too heavyweight for this purpose). <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>
If I see foo-&gt;exec() or exec(foo) in a pipe of code, I have to go look at the declaration of foo to know what&#39;s going on.  If I see do_some_action(foo) it&#39;s a bit more obvious.</blockquote><div><br>In this particular case (and in most uses of the command pattern, IMHO), the declaration is right next to the exec() call, so this isn&#39;t a problem.  E.g.:<br>
<br>   /* Do the blit */<br>   brw_blorp_blit_params params(brw_context(ctx), src_mt, dst_mt,<br>                                srcX0, srcY0, dstX0, dstY0, dstX1, dstY1,<br>                                mirror_x, mirror_y);<br>
   params.exec(intel);<br><br>I agree that it looks kind of hokey, though.  Other alternatives I considered included:<br><br>- Make intel_context a class, and make executing a blorp action a method on that class, so that last line would have been something like &quot;intel-&gt;do_blorp_op(params);&quot;.  Incidentally, I think we would get a lot of benefits out of making brw_context, intel_context, and gl_context a class hierarchy; for example, macros like OUT_BATCH() would become ordinary member functions, and we wouldn&#39;t have to do anywhere near as many explicit conversions between the three context types.  Also, the virtual function tables that we currently code up explicitly would be automatically created by the compiler, so we would have much less risk of problems like forgetting to dispatch through the virtual function table, forgetting to initialize a function pointer properly, or initializing a function pointer at the wrong time.  Of course, this would have been *way* too big a change to try to slip into this patch series.  By orders of magnitude.<br>
<br>- Make a base class to represent the Blorp engine, with a derived class for Gen6 and a derived class for Gen7.  The appropriate object would be created at context creation time.  Then, instead of calling &quot;params.exec(intel);&quot;, you would do &quot;brw-&gt;blorp-&gt;exec(params);&quot;.  I largely dismissed this option because I had already done so much refactoring of the HiZ code that it seemed like it was time to settle down and actually implement some new functionality.  But I would still be open to it if people like the idea.<br>
</div></div>