[PATCH 2/6] d3dx9: Use versioned parameter updates instead of 'dirty' flags.

Matteo Bruni matteo.mystral at gmail.com
Tue May 16 09:50:46 CDT 2017


2017-05-15 22:24 GMT+02:00 Paul Gofman <gofmanp at gmail.com>:
> On 05/15/2017 09:19 PM, Matteo Bruni wrote:
>>
>> 2017-05-12 14:24 GMT+02:00 Paul Gofman <gofmanp at gmail.com>:
>>
>>
>>> @@ -163,6 +163,7 @@ struct d3dx_const_tab
>>>       unsigned int const_set_size;
>>>       struct d3dx_const_param_eval_output *const_set;
>>>       const enum pres_reg_tables *regset2table;
>>> +    ULONG64 update_version;
>>>   };
>>
>> Is it necessary? Could you do without it, using the pass version instead?
>
> I think I can, but the reasons I did this were:
> 1. The logic in patch 5 (removing redundant constant table updates &
> preshader recomputes) won't work without it. Imagine an array selector with
> shader 1 selected, when after BeginPass() or Commit() it will update the
> version of pass. If another shader is selected later it might not get
> updated for the some parameter changes, so I will have to ultimately
> recompute all preshaders and reset constant table parameters on update_all,
> which I can avoid using this const_tab own version. Even if I manage to
> workaround this case with array selector somehow, redundant shader constant
> updates and preshaders recomputes can happen if different passes or
> techniques use the same shader

That seems like a good reason. Do you think it's possible to write a
test for it (i.e. does this kind of behavior have some visible effect
in black-box testing?)

>>>   struct d3dx_shared_data;
>>>
>>> @@ -213,6 +214,8 @@ struct d3dx_parameter
>>>       UINT bytes;
>>>       DWORD runtime_flags;
>>>       DWORD object_id;
>>> +    ULONG64 update_version;
>>> +    ULONG64 *update_version_counter;
>>
>> I don't like the "update_version_counter" name that much but I don't
>> have particularly good suggestions. pass_update_version?
>> current_update_version? parent_update_version? new_update_version?
>
> It is not a pass update version in my understanding, it relates to parameter
> or constant table update version as well. So maybe current_update_version?
> Or just version_counter, which looks consistent to how the same thing is
> often named in DBs?

Yeah, I like version_counter actually. Pick whatever you prefer.

> Do you mean a pointer in the update_version in the struct d3dx_parameter
> which will point to either shared data or the update version in the same
> parameter? I would like to avoid this if possible as it makes extra
> indirection for non-shared parameters. I don't have exact performance
> difference exactly for such a change though, but it looks like removing some
> indirections here and there (after a more global optimizations of
> set_constants function) gives some moderate improvement.

It would look a bit nicer though. Anyway, I don't really mind.

>     In the further optimization which I am testing I go bit more towards
> less indirection, e. g., in function is_const_tab_input_dirty() I use the
> fact that actually the parameters there are always top level.

Well, that's a simplification (which sounds good BTW), not really a
choice between two similar alternative options.

>>> +static ULONG64 get_effect_update_version_counter(struct
>>> d3dx9_base_effect *base)
>>> +{
>>> +    return
>>> get_update_version_counter(get_update_version_counter_ptr(base));
>>>   }
>>
>> Same naming caveat here.
>
> next_effect_update_version()?

Yeah, or something like that.

>>> -static void clear_dirty_params(struct d3dx9_base_effect *base)
>>> +static void set_dirty(struct d3dx_parameter *param)
>>>   {
>>> -    unsigned int i;
>>> +    struct d3dx_shared_data *shared_data;
>>> +    struct d3dx_parameter *top_param = param->top_level_param;
>>> +    ULONG64 new_update_version =
>>> get_update_version_counter(top_param->update_version_counter);
>>>
>>> -    for (i = 0; i < base->parameter_count; ++i)
>>> -        base->parameters[i].runtime_flags &= ~PARAMETER_FLAG_DIRTY;
>>> +    if ((shared_data = top_param->u.shared_data))
>>> +        shared_data->update_version = new_update_version;
>>> +    else
>>> +        top_param->update_version = new_update_version;
>>>   }
>>
>> Another option would be NOT to increment the effect / pool counter on
>> each set_dirty() but instead only increment it in BeginPass() and
>> CommitChanges(), after you're done with the update (or well, it's fine
>> at almost any point given that we don't have to care about races). It
>> seems a bit better to me, unless I'm overlooking something and it
>> won't work.
>
>     After this patch, set_dirty() is already completely out of any
> performance hot spots, as far as I could measure so far (though there are
> the other places like mainly set_constants that I was going to address too).
>
>     Not incrementing the version does not improve things much in terms of
> racing in my understanding. Since we don't have to support it within pool it
> should be ok either way. If we had to, we would also need to care for some
> way for atomic & fenced read even when not incrementing, and probably
> parallel BeginPass with Set... would make non-incrementing logic require
> additional sync.

No, I'm not suddenly starting to care about race conditions. :)

>     Not incrementing the version on update likely won't break anything, if
> to change the initialization a bit (increment version on effect creation)
> and carefully watch comparison condition for a sort of "off by one" errors.
> At least now I cannot figure out what can go wrong, though I need to test it
> more and to recheck the code paths thoroughly to be sure if it is ok. It
> looked natural to me to increase the version on parameter update. Don't you
> think that verifying the overall logic if we don't increment becomes a bit
> mind breaking? Incrementing the version every time makes the 'updated' check
> straightforward for any case, regardless of how parameters update sequence
> interfere with updates 'consuming' sequence. Otherwise we need to check all
> the possible use cases of "dirty" parameters to be sure.

AFAICS it shouldn't make any difference in behavior, unless there is
some bug lurking (and in that case exposing the bug would be a good
thing IMO).

>     Or if you suspect it may have some indirect performance impact (which I
> am keen to test) maybe I could test it as a separate change after some other
> (more severe) optimization, when I potentially can see this effect more
> clear?

Yeah, I don't see it having any measurable impact but it's still
unnecessary (if trivial) work.

I don't mind looking into it later, I mentioned it mostly to
doublecheck that we're on the same page.



More information about the wine-devel mailing list