wined3d: Optimize render states in the stateblock.

This commit is contained in:
Stefan Dösinger 2007-07-31 15:04:56 +02:00 committed by Alexandre Julliard
parent 28084c5f80
commit 93155ea087
3 changed files with 36 additions and 26 deletions

View File

@ -466,6 +466,11 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface,
light->enabledChanged = TRUE; light->enabledChanged = TRUE;
} }
} }
for(j = 1; j <= WINEHIGHEST_RENDER_STATE; j++) {
object->contained_render_states[j - 1] = j;
}
object->num_contained_render_states = WINEHIGHEST_RENDER_STATE;
} else if (Type == WINED3DSBT_PIXELSTATE) { } else if (Type == WINED3DSBT_PIXELSTATE) {
TRACE("PIXELSTATE => Pretend all pixel shates have changed\n"); TRACE("PIXELSTATE => Pretend all pixel shates have changed\n");
@ -480,10 +485,12 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface,
object->changed.pixelShaderConstantsB[i] = TRUE; object->changed.pixelShaderConstantsB[i] = TRUE;
for (i = 0; i < MAX_CONST_I; ++i) for (i = 0; i < MAX_CONST_I; ++i)
object->changed.pixelShaderConstantsI[i] = TRUE; object->changed.pixelShaderConstantsI[i] = TRUE;
for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) { for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
object->changed.renderState[SavedPixelStates_R[i]] = TRUE; object->changed.renderState[SavedPixelStates_R[i]] = TRUE;
object->contained_render_states[i] = SavedPixelStates_R[i];
} }
object->num_contained_render_states = NUM_SAVEDPIXELSTATES_R;
for (j = 0; j < MAX_TEXTURES; j++) { for (j = 0; j < MAX_TEXTURES; j++) {
for (i = 0; i < NUM_SAVEDPIXELSTATES_T; i++) { for (i = 0; i < NUM_SAVEDPIXELSTATES_T; i++) {
object->changed.textureState[j][SavedPixelStates_T[i]] = TRUE; object->changed.textureState[j][SavedPixelStates_T[i]] = TRUE;
@ -510,10 +517,12 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface,
object->changed.vertexShaderConstantsB[i] = TRUE; object->changed.vertexShaderConstantsB[i] = TRUE;
for (i = 0; i < MAX_CONST_I; ++i) for (i = 0; i < MAX_CONST_I; ++i)
object->changed.vertexShaderConstantsI[i] = TRUE; object->changed.vertexShaderConstantsI[i] = TRUE;
for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) { for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
object->changed.renderState[SavedVertexStates_R[i]] = TRUE; object->changed.renderState[SavedVertexStates_R[i]] = TRUE;
object->contained_render_states[i] = SavedVertexStates_R[i];
} }
object->num_contained_render_states = NUM_SAVEDVERTEXSTATES_R;
for (j = 0; j < MAX_TEXTURES; j++) { for (j = 0; j < MAX_TEXTURES; j++) {
for (i = 0; i < NUM_SAVEDVERTEXSTATES_T; i++) { for (i = 0; i < NUM_SAVEDVERTEXSTATES_T; i++) {
object->changed.textureState[j][SavedVertexStates_T[i]] = TRUE; object->changed.textureState[j][SavedVertexStates_T[i]] = TRUE;
@ -4301,6 +4310,8 @@ static HRESULT WINAPI IWineD3DDeviceImpl_BeginStateBlock(IWineD3DDevice *iface)
static HRESULT WINAPI IWineD3DDeviceImpl_EndStateBlock(IWineD3DDevice *iface, IWineD3DStateBlock** ppStateBlock) { static HRESULT WINAPI IWineD3DDeviceImpl_EndStateBlock(IWineD3DDevice *iface, IWineD3DStateBlock** ppStateBlock) {
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
unsigned int i;
IWineD3DStateBlockImpl *object = This->updateStateBlock;
if (!This->isRecordingState) { if (!This->isRecordingState) {
FIXME("(%p) not recording! returning error\n", This); FIXME("(%p) not recording! returning error\n", This);
@ -4308,7 +4319,14 @@ static HRESULT WINAPI IWineD3DDeviceImpl_EndStateBlock(IWineD3DDevice *iface, IW
return WINED3DERR_INVALIDCALL; return WINED3DERR_INVALIDCALL;
} }
*ppStateBlock = (IWineD3DStateBlock*)This->updateStateBlock; for(i = 1; i <= WINEHIGHEST_RENDER_STATE; i++) {
if(object->changed.renderState[i]) {
object->contained_render_states[object->num_contained_render_states] = i;
object->num_contained_render_states++;
}
}
*ppStateBlock = (IWineD3DStateBlock*) object;
This->isRecordingState = FALSE; This->isRecordingState = FALSE;
This->updateStateBlock = This->stateBlock; This->updateStateBlock = This->stateBlock;
IWineD3DStateBlock_AddRef((IWineD3DStateBlock*)This->updateStateBlock); IWineD3DStateBlock_AddRef((IWineD3DStateBlock*)This->updateStateBlock);

View File

@ -566,12 +566,10 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface)
} }
/* Render */ /* Render */
for (i = 1; i <= WINEHIGHEST_RENDER_STATE; i++) { for (i = 0; i <= This->num_contained_render_states; i++) {
TRACE("Updating renderState %d to %d\n",
if (This->changed.renderState[i] && (This->renderState[i] != targetStateBlock->renderState[i])) { This->contained_render_states[i], targetStateBlock->renderState[This->contained_render_states[i]]);
TRACE("Updating renderState %d to %d\n", i, targetStateBlock->renderState[i]); This->renderState[This->contained_render_states[i]] = targetStateBlock->renderState[This->contained_render_states[i]];
This->renderState[i] = targetStateBlock->renderState[i];
}
} }
/* Texture states */ /* Texture states */
@ -737,12 +735,6 @@ should really perform a delta so that only the changes get updated*/
} }
} }
/* Render */
for (i = 1; i <= WINEHIGHEST_RENDER_STATE; i++) {
if (This->changed.renderState[i])
IWineD3DDevice_SetRenderState(pDevice, i, This->renderState[i]);
}
/* Texture states */ /* Texture states */
for (j = 0; j < MAX_TEXTURES; j++) { /* Set The texture first, just in case it resets the states? */ for (j = 0; j < MAX_TEXTURES; j++) { /* Set The texture first, just in case it resets the states? */
/* TODO: move over to memcpy */ /* TODO: move over to memcpy */
@ -778,12 +770,6 @@ should really perform a delta so that only the changes get updated*/
} else if (This->blockType == WINED3DSBT_PIXELSTATE) { } else if (This->blockType == WINED3DSBT_PIXELSTATE) {
for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
if (This->changed.renderState[SavedPixelStates_R[i]])
IWineD3DDevice_SetRenderState(pDevice, SavedPixelStates_R[i], This->renderState[SavedPixelStates_R[i]]);
}
for (j = 0; j < MAX_TEXTURES; j++) { for (j = 0; j < MAX_TEXTURES; j++) {
for (i = 0; i < NUM_SAVEDPIXELSTATES_T; i++) { for (i = 0; i < NUM_SAVEDPIXELSTATES_T; i++) {
((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[j][SavedPixelStates_T[i]] = This->textureState[j][SavedPixelStates_T[i]]; ((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[j][SavedPixelStates_T[i]] = This->textureState[j][SavedPixelStates_T[i]];
@ -799,11 +785,6 @@ should really perform a delta so that only the changes get updated*/
} else if (This->blockType == WINED3DSBT_VERTEXSTATE) { } else if (This->blockType == WINED3DSBT_VERTEXSTATE) {
for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
if (This->changed.renderState[SavedVertexStates_R[i]])
IWineD3DDevice_SetRenderState(pDevice, SavedVertexStates_R[i], This->renderState[SavedVertexStates_R[i]]);
}
for (j = 0; j < MAX_TEXTURES; j++) { for (j = 0; j < MAX_TEXTURES; j++) {
for (i = 0; i < NUM_SAVEDVERTEXSTATES_T; i++) { for (i = 0; i < NUM_SAVEDVERTEXSTATES_T; i++) {
((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[j][SavedVertexStates_T[i]] = This->textureState[j][SavedVertexStates_T[i]]; ((IWineD3DDeviceImpl *)pDevice)->stateBlock->textureState[j][SavedVertexStates_T[i]] = This->textureState[j][SavedVertexStates_T[i]];
@ -821,6 +802,13 @@ should really perform a delta so that only the changes get updated*/
} else { } else {
FIXME("Unrecognized state block type %d\n", This->blockType); FIXME("Unrecognized state block type %d\n", This->blockType);
} }
/* Render */
for (i = 0; i <= This->num_contained_render_states; i++) {
IWineD3DDevice_SetRenderState(pDevice, This->contained_render_states[i],
This->renderState[This->contained_render_states[i]]);
}
stateblock_savedstates_copy(iface, &((IWineD3DDeviceImpl*)pDevice)->stateBlock->changed, &This->changed); stateblock_savedstates_copy(iface, &((IWineD3DDeviceImpl*)pDevice)->stateBlock->changed, &This->changed);
((IWineD3DDeviceImpl *)pDevice)->stateBlock->lowest_disabled_stage = MAX_TEXTURES - 1; ((IWineD3DDeviceImpl *)pDevice)->stateBlock->lowest_disabled_stage = MAX_TEXTURES - 1;
for(j = 0; j < MAX_TEXTURES - 1; j++) { for(j = 0; j < MAX_TEXTURES - 1; j++) {

View File

@ -1356,6 +1356,10 @@ struct IWineD3DStateBlockImpl
/* Scissor test rectangle */ /* Scissor test rectangle */
RECT scissorRect; RECT scissorRect;
/* Contained state management */
DWORD contained_render_states[WINEHIGHEST_RENDER_STATE + 1];
unsigned int num_contained_render_states;
}; };
extern void stateblock_savedstates_set( extern void stateblock_savedstates_set(