[PATCH 4/4] wined3d: Replace state_init helper with state_reset.

Rémi Bernon rbernon at codeweavers.com
Thu Feb 18 08:14:49 CST 2021


On 2/18/21 3:06 PM, Henri Verbeet wrote:
> On Thu, 18 Feb 2021 at 13:31, Rémi Bernon <rbernon at codeweavers.com> wrote:
>> @@ -2973,7 +2972,7 @@ struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device)
>>       cs->device = device;
>>       cs->serialize_commands = TRACE_ON(d3d_sync) || wined3d_settings.cs_multithreaded & WINED3D_CSMT_SERIALIZE;
>>
>> -    state_init(&cs->state, d3d_info, WINED3D_STATE_NO_REF | WINED3D_STATE_INIT_DEFAULT);
>> +    state_reset(&cs->state, d3d_info, WINED3D_STATE_NO_REF | WINED3D_STATE_INIT_DEFAULT);
>>
> I think reset and initialisation are conceptually different, and this
> is clearly an initialisation. More, there's no need for the memset()
> that state_reset() does here, since "cs" was allocated with
> heap_alloc_zero().
> 
>> @@ -6020,8 +6018,7 @@ HRESULT wined3d_device_init(struct wined3d_device *device, struct wined3d *wined
>>           hr = E_OUTOFMEMORY;
>>           goto err;
>>       }
>> -    memset(state, 0, sizeof(*state));
>> -    state_init(state, &adapter->d3d_info, WINED3D_STATE_INIT_DEFAULT);
>> +    state_reset(state, &adapter->d3d_info, WINED3D_STATE_INIT_DEFAULT);
>>
> Likewise.
> 
>> +void state_reset(struct wined3d_state *state, const struct wined3d_d3d_info *d3d_info, DWORD flags)
>> +{
>> +    memset(&state->flags, 0, sizeof(struct wined3d_state) - FIELD_OFFSET(struct wined3d_state, flags));
>> +    state_init(state, d3d_info, flags);
>> +}
> 
> Do we expect to ever change the flags on state_reset()? The "flags"
> parameter seems redundant. The memset() effectively clears the entire
> structure, except if we were to ever move the "flags" field to a
> different place in the structure. Any reason to not simply use
> "memset(state, 0, sizeof(*state));"?
> 

So I wanted to avoid adding a new helper, but would having both 
state_init and state_reset make more sense?
-- 
Rémi Bernon <rbernon at codeweavers.com>



More information about the wine-devel mailing list