[PATCH 1/6] d3dx9: Get rid of table lookup for converting between register indexes and offsets.

Matteo Bruni matteo.mystral at gmail.com
Mon May 29 17:59:19 CDT 2017


2017-05-29 20:32 GMT+02:00 Paul Gofman <gofmanp at gmail.com>:
> On 05/29/2017 09:19 PM, Matteo Bruni wrote:
>>
>> 2017-05-24 11:46 GMT+02:00 Paul Gofman <gofmanp at gmail.com>:
>>
>>>   static unsigned int get_reg_offset(unsigned int table, unsigned int
>>> offset)
>>>   {
>>> -    return offset / table_info[table].reg_component_count;
>>> +    return table == PRES_REGTAB_OBCONST ? offset : offset >> 2;
>>> +}
>>> +
>>> +static unsigned int get_offset_reg(unsigned int table, unsigned int
>>> reg_idx)
>>> +{
>>> +    return table == PRES_REGTAB_OBCONST ? reg_idx : reg_idx << 2;
>>>   }
>>
>> I suppose using an explicit division and multiplication here wouldn't
>> change the generated code, in which case I'd slightly prefer that. It
>> doesn't matter right now, just mentioning it for potentially similar
>> cases in the future.
>
> Yes, sure, if it would be constant literal for multiplication / division
> here.

Yeah, it should be a trivial optimization for the compiler and a tiny
bit clearer for the reader.

Not a big deal of course.

>>> @@ -1033,9 +1035,9 @@ static void set_constants(struct d3dx_regstore *rs,
>>> struct d3dx_const_tab *const
>>>                   unsigned int offset;
>>>
>>>                   offset = start_offset + i * major_stride + j;
>>> -                if (offset / table_info[table].reg_component_count >=
>>> rs->table_sizes[table])
>>> +                if (get_reg_offset(table, offset) >=
>>> rs->table_sizes[table])
>>>                   {
>>> -                    if (table_info[table].reg_component_count != 1)
>>> +                    if (table != PRES_REGTAB_OBCONST)
>>>                           FIXME("Output offset exceeds table size, name
>>> %s, component %u.\n",
>>>                                   debugstr_a(param->name), i);
>>>                       break;
>>
>> Not new and probably I just forgot the details, but, why would the
>> register component count matter for the FIXME?
>
> The length of the data to be copied to registers can be limited by
> RegisterCount in (pre)shader constant description. But when register is
> 4-value, the major count for output loop should already mind that (since we
> always have row count and column count <= 4). The only legitimate case we
> may need to break from the inner loop is boolean constant matrix setting. So
> actually fixme condition should never happen, though break from the inner
> loop on boolean constant setting may be required. I am changing this place
> in the next patches (I didn't send yet) when optimizing this place. I was
> actually going to add a bit more tests for this case along with the
> forthcoming changes, and I suspect a bug here (I actually need to
> effectively compare with constant register count and not with the table
> size). We have a test for full update with boolean matrices (which will not
> trigger the error here) but commit of individual matrices test probably
> will.

Right, that makes sense, including the likely bug you mention.

In theory it should be possible to do the FIXME check at init time.
Actually, the whole constant upload info could be precomputed. Just
putting it out there...



More information about the wine-devel mailing list