[Mesa-dev] [PATCH 2/2] mesa: simplify code setting boolean uniforms

Ian Romanick idr at freedesktop.org
Thu Mar 19 10:52:39 PDT 2015


On 03/19/2015 10:45 AM, Brian Paul wrote:
> On 03/19/2015 09:26 AM, Matt Turner wrote:
>> On Thu, Mar 19, 2015 at 7:53 AM, Brian Paul <brianp at vmware.com> wrote:
>>> src[i] is a union.  Just check if src[i].u is non-zero to choose
>>> between ctx->Const.UniformBooleanTrue and zero.
>>> ---
>>>   src/mesa/main/uniform_query.cpp | 6 +-----
>>>   1 file changed, 1 insertion(+), 5 deletions(-)
>>>
>>> diff --git a/src/mesa/main/uniform_query.cpp
>>> b/src/mesa/main/uniform_query.cpp
>>> index 2ab5528..9ce45ee 100644
>>> --- a/src/mesa/main/uniform_query.cpp
>>> +++ b/src/mesa/main/uniform_query.cpp
>>> @@ -785,11 +785,7 @@ _mesa_uniform(struct gl_context *ctx, struct
>>> gl_shader_program *shProg,
>>>         const unsigned elems = components * count;
>>>
>>>         for (unsigned i = 0; i < elems; i++) {
>>> -        if (basicType == GLSL_TYPE_FLOAT) {
>>> -            dst[i].i = src[i].f != 0.0f ?
>>> ctx->Const.UniformBooleanTrue : 0;
>>
>> I guess this also handles -0.0f as well, which isn't 0u. I'm not sure
>> if that's desired behavior or not?
> 
> Good question.  But it seems a little far-fetched that a real app would
> rely on glUniform1f(loc, -0.0) to set a boolean to false.
> 
> I don't see any spec language about this case.

I'd have to go look, but I think the spec says if the value is equal to
zero it is false.  Since -0.0 == 0.0, -0.0 should produce false.  I
doubt there's a conformance test for this case, but it would be easy
enough to make a piglit test to try on other implementations.

> What do you think?
> 
> -Brian
> 
>>
>>> -        } else {
>>> -            dst[i].i = src[i].i != 0    ?
>>> ctx->Const.UniformBooleanTrue : 0;
>>> -        }
>>> +         dst[i].i = src[i].u ? ctx->Const.UniformBooleanTrue : 0;
>>>         }
>>>      }
>>>
>>> -- 
>>> 1.9.1
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev



More information about the mesa-dev mailing list