From 865b82af2c3e9d48d350827db622ddb02df16477 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20D=C3=B6singer?= Date: Fri, 3 Aug 2007 20:12:54 +0200 Subject: [PATCH] wined3d: Optimize bool and int pixel shader constants. --- dlls/wined3d/device.c | 30 +++++++++++++++++++++-- dlls/wined3d/stateblock.c | 54 ++++++++++++++++++++---------------------- dlls/wined3d/wined3d_private.h | 4 ++++ 3 files changed, 58 insertions(+), 30 deletions(-) diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index e4fdeb988d3..9165e71124f 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -482,6 +482,14 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface, object->contained_vs_consts_b[j] = j; } object->num_contained_vs_consts_b = MAX_CONST_B; + for(j = 0; j < MAX_CONST_I; j++) { + object->contained_ps_consts_i[j] = j; + } + object->num_contained_ps_consts_i = MAX_CONST_I; + for(j = 0; j < MAX_CONST_B; j++) { + object->contained_ps_consts_b[j] = j; + } + object->num_contained_ps_consts_b = MAX_CONST_B; } else if (Type == WINED3DSBT_PIXELSTATE) { @@ -493,10 +501,16 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface, /* Pixel Shader Constants */ for (i = 0; i < GL_LIMITS(pshader_constantsF); ++i) object->changed.pixelShaderConstantsF[i] = TRUE; - for (i = 0; i < MAX_CONST_B; ++i) + for (i = 0; i < MAX_CONST_B; ++i) { + object->contained_ps_consts_b[i] = i; object->changed.pixelShaderConstantsB[i] = TRUE; - for (i = 0; i < MAX_CONST_I; ++i) + } + object->num_contained_ps_consts_b = MAX_CONST_B; + for (i = 0; i < MAX_CONST_I; ++i) { + object->contained_ps_consts_i[i] = i; object->changed.pixelShaderConstantsI[i] = TRUE; + } + object->num_contained_ps_consts_i = MAX_CONST_I; for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) { object->changed.renderState[SavedPixelStates_R[i]] = TRUE; @@ -4359,6 +4373,18 @@ static HRESULT WINAPI IWineD3DDeviceImpl_EndStateBlock(IWineD3DDevice *iface, IW object->num_contained_vs_consts_b++; } } + for(i = 0; i < MAX_CONST_I; i++) { + if(object->changed.pixelShaderConstantsI[i]) { + object->contained_ps_consts_i[object->num_contained_ps_consts_i] = i; + object->num_contained_ps_consts_i++; + } + } + for(i = 0; i < MAX_CONST_B; i++) { + if(object->changed.pixelShaderConstantsB[i]) { + object->contained_ps_consts_b[object->num_contained_ps_consts_b] = i; + object->num_contained_ps_consts_b++; + } + } *ppStateBlock = (IWineD3DStateBlock*) object; This->isRecordingState = FALSE; diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index ba71dc32554..9ce8ea8822f 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -455,31 +455,29 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface) This->pixelShaderConstantF[i * 4 + 3] = targetStateBlock->pixelShaderConstantF[i * 4 + 3]; } } - + /* Pixel Shader Integer Constants */ - for (i = 0; i < MAX_CONST_I; ++i) { - if (This->changed.pixelShaderConstantsI[i]) { - TRACE("Setting %p from %p %d to { %d, %d, %d, %d }\n", This, targetStateBlock, i, - targetStateBlock->pixelShaderConstantI[i * 4], - targetStateBlock->pixelShaderConstantI[i * 4 + 1], - targetStateBlock->pixelShaderConstantI[i * 4 + 2], - targetStateBlock->pixelShaderConstantI[i * 4 + 3]); - - This->pixelShaderConstantI[i * 4] = targetStateBlock->pixelShaderConstantI[i * 4]; - This->pixelShaderConstantI[i * 4 + 1] = targetStateBlock->pixelShaderConstantI[i * 4 + 1]; - This->pixelShaderConstantI[i * 4 + 2] = targetStateBlock->pixelShaderConstantI[i * 4 + 2]; - This->pixelShaderConstantI[i * 4 + 3] = targetStateBlock->pixelShaderConstantI[i * 4 + 3]; - } + for (j = 0; j < This->num_contained_ps_consts_i; ++j) { + i = This->contained_ps_consts_i[j]; + TRACE("Setting %p from %p %d to { %d, %d, %d, %d }\n", This, targetStateBlock, i, + targetStateBlock->pixelShaderConstantI[i * 4], + targetStateBlock->pixelShaderConstantI[i * 4 + 1], + targetStateBlock->pixelShaderConstantI[i * 4 + 2], + targetStateBlock->pixelShaderConstantI[i * 4 + 3]); + + This->pixelShaderConstantI[i * 4] = targetStateBlock->pixelShaderConstantI[i * 4]; + This->pixelShaderConstantI[i * 4 + 1] = targetStateBlock->pixelShaderConstantI[i * 4 + 1]; + This->pixelShaderConstantI[i * 4 + 2] = targetStateBlock->pixelShaderConstantI[i * 4 + 2]; + This->pixelShaderConstantI[i * 4 + 3] = targetStateBlock->pixelShaderConstantI[i * 4 + 3]; } - + /* Pixel Shader Boolean Constants */ - for (i = 0; i < MAX_CONST_B; ++i) { - if (This->changed.pixelShaderConstantsB[i]) { - TRACE("Setting %p from %p %d to %s\n", This, targetStateBlock, i, - targetStateBlock->pixelShaderConstantB[i]? "TRUE":"FALSE"); + for (j = 0; j < This->num_contained_ps_consts_b; ++j) { + i = This->contained_ps_consts_b[j]; + TRACE("Setting %p from %p %d to %s\n", This, targetStateBlock, i, + targetStateBlock->pixelShaderConstantB[i]? "TRUE":"FALSE"); - This->pixelShaderConstantB[i] = targetStateBlock->pixelShaderConstantB[i]; - } + This->pixelShaderConstantB[i] = targetStateBlock->pixelShaderConstantB[i]; } /* Others + Render & Texture */ @@ -670,14 +668,14 @@ should really perform a delta so that only the changes get updated*/ IWineD3DDevice_SetPixelShaderConstantF(pDevice, i, This->pixelShaderConstantF + i * 4, 1); } - for (i = 0; i < MAX_CONST_I; ++i) { - if (This->changed.pixelShaderConstantsI[i]) - IWineD3DDevice_SetPixelShaderConstantI(pDevice, i, This->pixelShaderConstantI + i * 4, 1); + for (i = 0; i < This->num_contained_ps_consts_i; i++) { + IWineD3DDevice_SetPixelShaderConstantI(pDevice, This->contained_ps_consts_i[i], + This->pixelShaderConstantI + This->contained_ps_consts_i[i] * 4, 1); } - - for (i = 0; i < MAX_CONST_B; ++i) { - if (This->changed.pixelShaderConstantsB[i]) - IWineD3DDevice_SetPixelShaderConstantB(pDevice, i, This->pixelShaderConstantB + i, 1); + + for (i = 0; i < This->num_contained_ps_consts_b; i++) { + IWineD3DDevice_SetPixelShaderConstantB(pDevice, This->contained_ps_consts_b[i], + This->pixelShaderConstantB + This->contained_ps_consts_b[i], 1); } } diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 948cf2e23a3..62be55eb347 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1375,6 +1375,10 @@ struct IWineD3DStateBlockImpl unsigned int num_contained_vs_consts_i; DWORD contained_vs_consts_b[MAX_CONST_B]; unsigned int num_contained_vs_consts_b; + DWORD contained_ps_consts_i[MAX_CONST_I]; + unsigned int num_contained_ps_consts_i; + DWORD contained_ps_consts_b[MAX_CONST_B]; + unsigned int num_contained_ps_consts_b; }; extern void stateblock_savedstates_set( -- 2.11.4.GIT