Module: wine Branch: master Commit: 59fb2928b8ba6dd0a4ffdd0fd5fd629533ab4b52 URL: http://source.winehq.org/git/wine.git/?a=commit;h=59fb2928b8ba6dd0a4ffdd0fd5...
Author: Stefan Dösinger stefan@codeweavers.com Date: Fri Aug 3 20:23:52 2007 +0200
wined3d: Optimize sampler states in stateblocks.
---
dlls/wined3d/device.c | 27 ++++++++++++++++++++-- dlls/wined3d/stateblock.c | 46 ++++++++++++++------------------------- dlls/wined3d/wined3d_private.h | 2 + 3 files changed, 43 insertions(+), 32 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 4c53c8a..4e7a83b 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -497,6 +497,13 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface, object->num_contained_tss_states++; } } + for(i = 0; i < MAX_COMBINED_SAMPLERS; i++) { + for(j = 1; j <= WINED3D_HIGHEST_SAMPLER_STATE; j++) { + object->contained_sampler_states[object->num_contained_sampler_states].stage = i; + object->contained_sampler_states[object->num_contained_sampler_states].state = j; + object->num_contained_sampler_states++; + } + }
} else if (Type == WINED3DSBT_PIXELSTATE) {
@@ -532,10 +539,12 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface, object->num_contained_tss_states++; } } - for (j = 0 ; j < 16; j++) { + for (j = 0 ; j < MAX_COMBINED_SAMPLERS; j++) { for (i =0; i < NUM_SAVEDPIXELSTATES_S;i++) { - object->changed.samplerState[j][SavedPixelStates_S[i]] = TRUE; + object->contained_sampler_states[object->num_contained_sampler_states].stage = j; + object->contained_sampler_states[object->num_contained_sampler_states].state = SavedPixelStates_S[i]; + object->num_contained_sampler_states++; } }
@@ -572,9 +581,12 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface, object->num_contained_tss_states++; } } - for (j = 0 ; j < 16; j++){ + for (j = 0 ; j < MAX_COMBINED_SAMPLERS; j++){ for (i =0; i < NUM_SAVEDVERTEXSTATES_S;i++) { object->changed.samplerState[j][SavedVertexStates_S[i]] = TRUE; + object->contained_sampler_states[object->num_contained_sampler_states].stage = j; + object->contained_sampler_states[object->num_contained_sampler_states].state = SavedVertexStates_S[i]; + object->num_contained_sampler_states++; } }
@@ -4407,6 +4419,15 @@ static HRESULT WINAPI IWineD3DDeviceImpl_EndStateBlock(IWineD3DDevice *iface, IW } } } + for(i = 0; i < MAX_COMBINED_SAMPLERS; i++){ + for (j = 1; j < WINED3D_HIGHEST_SAMPLER_STATE; j++) { + if(object->changed.samplerState[i][j]) { + object->contained_sampler_states[object->num_contained_sampler_states].stage = i; + object->contained_sampler_states[object->num_contained_sampler_states].state = j; + object->num_contained_sampler_states++; + } + } + }
*ppStateBlock = (IWineD3DStateBlock*) object; This->isRecordingState = FALSE; diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index ef05dd2..1de46f2 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -583,14 +583,15 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface) TRACE("Updating texture %d to %p (was %p)\n", j, targetStateBlock->textures[j], This->textures[j]); This->textures[j] = targetStateBlock->textures[j]; } - for (i = 1; i <= WINED3D_HIGHEST_SAMPLER_STATE ; i++){ /* States are 1 based */ - if (This->changed.samplerState[j][i]) { - TRACE("Updating sampler state %d,%d to %d (was %d)\n", - j, i, targetStateBlock->samplerState[j][i], - This->samplerState[j][i]); - This->samplerState[j][i] = targetStateBlock->samplerState[j][i]; - } - } + } + + for (j = 0; j < This->num_contained_sampler_states; j++) { + DWORD stage = This->contained_sampler_states[j].stage; + DWORD state = This->contained_sampler_states[j].state; + TRACE("Updating sampler state %d,%d to %d (was %d)\n", + stage, state, targetStateBlock->samplerState[stage][state], + This->samplerState[stage][state]); + This->samplerState[stage][state] = targetStateBlock->samplerState[stage][state]; } }
@@ -738,33 +739,12 @@ should really perform a delta so that only the changes get updated*/ IWineD3DDevice_SetTexture(pDevice, WINED3DVERTEXTEXTURESAMPLER0 + j - MAX_FRAGMENT_SAMPLERS, This->textures[j]); } } - for (i = 1; i <= WINED3D_HIGHEST_SAMPLER_STATE; i++){ - if (This->changed.samplerState[j][i]) { - ((IWineD3DDeviceImpl *)pDevice)->stateBlock->samplerState[j][i] = This->samplerState[j][i]; - ((IWineD3DDeviceImpl *)pDevice)->stateBlock->changed.samplerState[j][i] = TRUE; - } - } - /* SetTexture catches nop changes, so the above call does not assure that the sampler is updated */ - IWineD3DDeviceImpl_MarkStateDirty((IWineD3DDeviceImpl *)pDevice, STATE_SAMPLER(j)); }
} else if (This->blockType == WINED3DSBT_PIXELSTATE) {
- for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) { - for (i = 0; i < NUM_SAVEDPIXELSTATES_S; i++) { - ((IWineD3DDeviceImpl *)pDevice)->stateBlock->samplerState[j][SavedPixelStates_S[i]] = This->samplerState[j][SavedPixelStates_S[i]]; - } - } - } else if (This->blockType == WINED3DSBT_VERTEXSTATE) {
- for (j = 0; j < MAX_COMBINED_SAMPLERS; j++) { - for (i = 0; i < NUM_SAVEDVERTEXSTATES_S; i++) { - ((IWineD3DDeviceImpl *)pDevice)->stateBlock->samplerState[j][SavedVertexStates_S[i]] = This->samplerState[j][SavedVertexStates_S[i]]; - } - } - - } else { FIXME("Unrecognized state block type %d\n", This->blockType); } @@ -783,6 +763,14 @@ should really perform a delta so that only the changes get updated*/ /* TODO: Record a display list to apply all gl states. For now apply by brute force */ IWineD3DDeviceImpl_MarkStateDirty((IWineD3DDeviceImpl *)pDevice, STATE_TEXTURESTAGE(stage, state)); } + /* Sampler states */ + for (i = 0; i < This->num_contained_sampler_states; i++) { + DWORD stage = This->contained_sampler_states[i].stage; + DWORD state = This->contained_sampler_states[i].state; + ((IWineD3DDeviceImpl *)pDevice)->stateBlock->samplerState[stage][state] = This->samplerState[stage][state]; + ((IWineD3DDeviceImpl *)pDevice)->stateBlock->changed.samplerState[stage][state] = TRUE; + IWineD3DDeviceImpl_MarkStateDirty((IWineD3DDeviceImpl *)pDevice, STATE_SAMPLER(stage)); + }
((IWineD3DDeviceImpl *)pDevice)->stateBlock->lowest_disabled_stage = MAX_TEXTURES - 1; for(j = 0; j < MAX_TEXTURES - 1; j++) { diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index c2b5af3..c2b1d58 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1386,6 +1386,8 @@ struct IWineD3DStateBlockImpl unsigned int num_contained_ps_consts_b; struct StageState contained_tss_states[MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE)]; unsigned int num_contained_tss_states; + struct StageState contained_sampler_states[MAX_COMBINED_SAMPLERS * WINED3D_HIGHEST_SAMPLER_STATE]; + unsigned int num_contained_sampler_states; };
extern void stateblock_savedstates_set(