wined3d: Optimize float constants in stateblocks.

oldstable
Stefan Dösinger 2007-08-03 20:26:29 +02:00 committed by Alexandre Julliard
parent 59fb2928b8
commit b21c785482
3 changed files with 60 additions and 32 deletions

View File

@ -474,6 +474,10 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface,
object->contained_transform_states[j - 1] = j;
}
object->num_contained_transform_states = HIGHEST_TRANSFORMSTATE;
for(j = 0; j < GL_LIMITS(vshader_constantsF); j++) {
object->contained_vs_consts_f[j] = j;
}
object->num_contained_vs_consts_f = GL_LIMITS(vshader_constantsF);
for(j = 0; j < MAX_CONST_I; j++) {
object->contained_vs_consts_i[j] = j;
}
@ -482,6 +486,10 @@ 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 < GL_LIMITS(pshader_constantsF); j++) {
object->contained_ps_consts_f[j] = j;
}
object->num_contained_ps_consts_f = GL_LIMITS(pshader_constantsF);
for(j = 0; j < MAX_CONST_I; j++) {
object->contained_ps_consts_i[j] = j;
}
@ -513,8 +521,11 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface,
object->changed.pixelShader = TRUE;
/* Pixel Shader Constants */
for (i = 0; i < GL_LIMITS(pshader_constantsF); ++i)
for (i = 0; i < GL_LIMITS(vshader_constantsF); ++i) {
object->contained_ps_consts_f[i] = i;
object->changed.pixelShaderConstantsF[i] = TRUE;
}
object->num_contained_ps_consts_f = GL_LIMITS(vshader_constantsF);
for (i = 0; i < MAX_CONST_B; ++i) {
object->contained_ps_consts_b[i] = i;
object->changed.pixelShaderConstantsB[i] = TRUE;
@ -556,8 +567,11 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface,
object->changed.vertexShader = TRUE;
/* Vertex Shader Constants */
for (i = 0; i < GL_LIMITS(vshader_constantsF); ++i)
for (i = 0; i < GL_LIMITS(vshader_constantsF); ++i) {
object->changed.vertexShaderConstantsF[i] = TRUE;
object->contained_vs_consts_f[i] = i;
}
object->num_contained_vs_consts_f = GL_LIMITS(vshader_constantsF);
for (i = 0; i < MAX_CONST_B; ++i) {
object->changed.vertexShaderConstantsB[i] = TRUE;
object->contained_vs_consts_b[i] = i;
@ -4386,6 +4400,12 @@ static HRESULT WINAPI IWineD3DDeviceImpl_EndStateBlock(IWineD3DDevice *iface, IW
object->num_contained_transform_states++;
}
}
for(i = 0; i < GL_LIMITS(vshader_constantsF); i++) {
if(object->changed.vertexShaderConstantsF[i]) {
object->contained_vs_consts_f[object->num_contained_vs_consts_f] = i;
object->num_contained_vs_consts_f++;
}
}
for(i = 0; i < MAX_CONST_I; i++) {
if(object->changed.vertexShaderConstantsI[i]) {
object->contained_vs_consts_i[object->num_contained_vs_consts_i] = i;

View File

@ -48,6 +48,10 @@ HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object) {
WINED3D_MEMCHECK(object->vertexShaderConstantF);
object->changed.vertexShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOL) * GL_LIMITS(vshader_constantsF));
WINED3D_MEMCHECK(object->changed.vertexShaderConstantsF);
object->contained_vs_consts_f = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * GL_LIMITS(vshader_constantsF));
WINED3D_MEMCHECK(object->contained_vs_consts_f);
object->contained_ps_consts_f = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * GL_LIMITS(pshader_constantsF));
WINED3D_MEMCHECK(object->contained_ps_consts_f);
list_init(&object->set_vconstantsF);
list_init(&object->set_pconstantsF);
@ -274,6 +278,8 @@ static ULONG WINAPI IWineD3DStateBlockImpl_Release(IWineD3DStateBlock *iface) {
HeapFree(GetProcessHeap(), 0, This->changed.vertexShaderConstantsF);
HeapFree(GetProcessHeap(), 0, This->pixelShaderConstantF);
HeapFree(GetProcessHeap(), 0, This->changed.pixelShaderConstantsF);
HeapFree(GetProcessHeap(), 0, This->contained_vs_consts_f);
HeapFree(GetProcessHeap(), 0, This->contained_ps_consts_f);
LIST_FOR_EACH_ENTRY_SAFE(constant, constant2, &This->set_vconstantsF, constants_entry, entry) {
HeapFree(GetProcessHeap(), 0, constant);
@ -347,19 +353,18 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface)
}
/* Vertex Shader Float Constants */
for (i = 0; i < GL_LIMITS(vshader_constantsF); ++i) {
if (This->changed.vertexShaderConstantsF[i]) {
TRACE("Setting %p from %p %d to { %f, %f, %f, %f }\n", This, targetStateBlock, i,
targetStateBlock->vertexShaderConstantF[i * 4],
targetStateBlock->vertexShaderConstantF[i * 4 + 1],
targetStateBlock->vertexShaderConstantF[i * 4 + 2],
targetStateBlock->vertexShaderConstantF[i * 4 + 3]);
for (j = 0; j < This->num_contained_vs_consts_f; ++j) {
i = This->contained_vs_consts_f[j];
TRACE("Setting %p from %p %d to { %f, %f, %f, %f }\n", This, targetStateBlock, i,
targetStateBlock->vertexShaderConstantF[i * 4],
targetStateBlock->vertexShaderConstantF[i * 4 + 1],
targetStateBlock->vertexShaderConstantF[i * 4 + 2],
targetStateBlock->vertexShaderConstantF[i * 4 + 3]);
This->vertexShaderConstantF[i * 4] = targetStateBlock->vertexShaderConstantF[i * 4];
This->vertexShaderConstantF[i * 4 + 1] = targetStateBlock->vertexShaderConstantF[i * 4 + 1];
This->vertexShaderConstantF[i * 4 + 2] = targetStateBlock->vertexShaderConstantF[i * 4 + 2];
This->vertexShaderConstantF[i * 4 + 3] = targetStateBlock->vertexShaderConstantF[i * 4 + 3];
}
This->vertexShaderConstantF[i * 4] = targetStateBlock->vertexShaderConstantF[i * 4];
This->vertexShaderConstantF[i * 4 + 1] = targetStateBlock->vertexShaderConstantF[i * 4 + 1];
This->vertexShaderConstantF[i * 4 + 2] = targetStateBlock->vertexShaderConstantF[i * 4 + 2];
This->vertexShaderConstantF[i * 4 + 3] = targetStateBlock->vertexShaderConstantF[i * 4 + 3];
}
/* Vertex Shader Integer Constants */
@ -441,19 +446,18 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface)
}
/* Pixel Shader Float Constants */
for (i = 0; i < GL_LIMITS(pshader_constantsF); ++i) {
if (This->changed.pixelShaderConstantsF[i]) {
TRACE("Setting %p from %p %d to { %f, %f, %f, %f }\n", This, targetStateBlock, i,
targetStateBlock->pixelShaderConstantF[i * 4],
targetStateBlock->pixelShaderConstantF[i * 4 + 1],
targetStateBlock->pixelShaderConstantF[i * 4 + 2],
targetStateBlock->pixelShaderConstantF[i * 4 + 3]);
for (j = 0; j < This->num_contained_ps_consts_f; ++j) {
i = This->contained_ps_consts_f[j];
TRACE("Setting %p from %p %d to { %f, %f, %f, %f }\n", This, targetStateBlock, i,
targetStateBlock->pixelShaderConstantF[i * 4],
targetStateBlock->pixelShaderConstantF[i * 4 + 1],
targetStateBlock->pixelShaderConstantF[i * 4 + 2],
targetStateBlock->pixelShaderConstantF[i * 4 + 3]);
This->pixelShaderConstantF[i * 4] = targetStateBlock->pixelShaderConstantF[i * 4];
This->pixelShaderConstantF[i * 4 + 1] = targetStateBlock->pixelShaderConstantF[i * 4 + 1];
This->pixelShaderConstantF[i * 4 + 2] = targetStateBlock->pixelShaderConstantF[i * 4 + 2];
This->pixelShaderConstantF[i * 4 + 3] = targetStateBlock->pixelShaderConstantF[i * 4 + 3];
}
This->pixelShaderConstantF[i * 4] = targetStateBlock->pixelShaderConstantF[i * 4];
This->pixelShaderConstantF[i * 4 + 1] = targetStateBlock->pixelShaderConstantF[i * 4 + 1];
This->pixelShaderConstantF[i * 4 + 2] = targetStateBlock->pixelShaderConstantF[i * 4 + 2];
This->pixelShaderConstantF[i * 4 + 3] = targetStateBlock->pixelShaderConstantF[i * 4 + 3];
}
/* Pixel Shader Integer Constants */
@ -639,9 +643,9 @@ should really perform a delta so that only the changes get updated*/
}
/* Vertex Shader Constants */
for (i = 0; i < GL_LIMITS(vshader_constantsF); ++i) {
if (This->changed.vertexShaderConstantsF[i])
IWineD3DDevice_SetVertexShaderConstantF(pDevice, i, This->vertexShaderConstantF + i * 4, 1);
for (i = 0; i < This->num_contained_vs_consts_f; i++) {
IWineD3DDevice_SetVertexShaderConstantF(pDevice, This->contained_vs_consts_f[i],
This->vertexShaderConstantF + This->contained_vs_consts_f[i] * 4, 1);
}
for (i = 0; i < This->num_contained_vs_consts_i; i++) {
@ -663,9 +667,9 @@ should really perform a delta so that only the changes get updated*/
}
/* Pixel Shader Constants */
for (i = 0; i < GL_LIMITS(pshader_constantsF); ++i) {
if (This->changed.pixelShaderConstantsF[i])
IWineD3DDevice_SetPixelShaderConstantF(pDevice, i, This->pixelShaderConstantF + i * 4, 1);
for (i = 0; i < This->num_contained_ps_consts_f; i++) {
IWineD3DDevice_SetPixelShaderConstantF(pDevice, This->contained_ps_consts_f[i],
This->pixelShaderConstantF + This->contained_ps_consts_f[i] * 4, 1);
}
for (i = 0; i < This->num_contained_ps_consts_i; i++) {

View File

@ -1380,10 +1380,14 @@ 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_vs_consts_f;
unsigned int num_contained_vs_consts_f;
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;
DWORD *contained_ps_consts_f;
unsigned int num_contained_ps_consts_f;
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];