[Mesa-dev] [PATCH 3/4] meta: Add flag MESA_META_SELECT_FEEDBACK

Chad Versace chad at chad-versace.us
Fri Oct 7 16:45:08 PDT 2011


On 10/07/2011 04:23 PM, Brian Paul wrote:
> On 10/07/2011 04:55 PM, Chad Versace wrote:
>> If this flag is set, then _mesa_meta_begin will save/restore the state of
>> GL_SELECT and GL_FEEDBACK render modes.
>>
>> Intel's futue resolve meta-ops will require this, since buffer resolves
>> may occur when the GL_RENDER_MODE is GL_SELECT.
>>
>> Signed-off-by: Chad Versace<chad at chad-versace.us>
>> ---
>>   src/mesa/drivers/common/meta.c |   26 ++++++++++++++++++++++++++
>>   src/mesa/drivers/common/meta.h |    1 +
>>   2 files changed, 27 insertions(+), 0 deletions(-)
>>
>> diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
>> index 5b73dcd..fc25f92 100644
>> --- a/src/mesa/drivers/common/meta.c
>> +++ b/src/mesa/drivers/common/meta.c
>> @@ -172,6 +172,11 @@ struct save_state
>>      struct gl_query_object *CondRenderQuery;
>>      GLenum CondRenderMode;
>>
>> +   /** MESA_META_SELECT_FEEDBACK */
>> +   GLenum RenderMode;
>> +   struct gl_selection Select;
>> +   struct gl_feedback Feedback;
>> +
>>      /** Miscellaneous (always disabled) */
>>      GLboolean Lighting;
>>   };
>> @@ -608,6 +613,17 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state)
>>        _mesa_EndConditionalRender();
>>      }
>>
>> +   if (state&  MESA_META_SELECT_FEEDBACK) {
>> +      save->RenderMode = ctx->RenderMode;
>> +      if (ctx->RenderMode == GL_SELECT) {
>> +     save->Select = ctx->Select; /* struct copy */
>> +     _mesa_RenderMode(GL_RENDER);
>> +      } else if (ctx->RenderMode == GL_FEEDBACK) {
>> +     save->Feedback = ctx->Feedback; /* struct copy */
>> +     _mesa_RenderMode(GL_RENDER);
>> +      }
>> +   }
>> +
>>      /* misc */
>>      {
>>         save->Lighting = ctx->Light.Enabled;
>> @@ -893,6 +909,16 @@ _mesa_meta_end(struct gl_context *ctx)
>>                         save->CondRenderMode);
>>      }
>>
>> +   if (state&  MESA_META_SELECT_FEEDBACK) {
>> +      if (save->RenderMode == GL_SELECT) {
>> +     ctx->Select = save->Select;
>> +     _mesa_RenderMode(GL_SELECT);
>> +      } else if (save->RenderMode == GL_FEEDBACK) {
>> +     ctx->Feedback = save->Feedback;
>> +     _mesa_RenderMode(GL_FEEDBACK);
>> +      }
>> +   }
> 
> You might need to switch the order of calling _mesa_RenderMode() and assigning the ctx->Feedback/Select state.  That is:
> 
>      _mesa_RenderMode(GL_FEEDBACK);
>      ctx->Feedback = save->Feedback;

My intuition also thought this was the correct order. But a Piglit test proved my intuition wrong.
> 
> I presume that after _mesa_meta_end() is called, we want the selection/feedback state to be just as it was before _mesa_meta_begin() was called, right?

Right.
 
> When _mesa_RenderMode() is called it mucks with various ctx->Select or ctx->Feedback fields.  So we need to assign/restore the old ctx->Select/Feedback state _after_ that if we want to restore things just as they were.
> 
> What do you think?
> 
> -Brian

_mesa_RenderMode clobbers and checks the state like this:
    current mode    new mode      clobbers                asserts
    --------------------------------------------------------------
    RENDER          *             nothing 
    SELECT          *             ctx.Select
    FEEDBACK        *             ctx.Feedback.Count
    *               RENDER                                nothing
    *               SELECT                                ctx.Select.BufferSize > 0
    *               FEEDBACK                              ctx.Feedback.BufferSize > 0
 
So in meta_begin, we need to save the state before calling glRenderMode in order to prevent the state from getting clobbered. And in meta_end, we need to restore the state before calling glRenderMode in order to prevent the assertions from failing.

-- 
Chad Versace
chad at chad-versace.us


More information about the mesa-dev mailing list