Commit 70968e69 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Use a bitmask to store which bool and int constants are set.

Note that constants_set was never actually NULL for shader_glsl_load_constantsB() and shader_glsl_load_constantsI().
parent 0ae60765
...@@ -457,12 +457,12 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface, ...@@ -457,12 +457,12 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface,
object->num_contained_ps_consts_f = GL_LIMITS(pshader_constantsF); object->num_contained_ps_consts_f = GL_LIMITS(pshader_constantsF);
for (i = 0; i < MAX_CONST_B; ++i) { for (i = 0; i < MAX_CONST_B; ++i) {
object->contained_ps_consts_b[i] = i; object->contained_ps_consts_b[i] = i;
object->changed.pixelShaderConstantsB[i] = TRUE; object->changed.pixelShaderConstantsB |= (1 << i);
} }
object->num_contained_ps_consts_b = MAX_CONST_B; object->num_contained_ps_consts_b = MAX_CONST_B;
for (i = 0; i < MAX_CONST_I; ++i) { for (i = 0; i < MAX_CONST_I; ++i) {
object->contained_ps_consts_i[i] = i; object->contained_ps_consts_i[i] = i;
object->changed.pixelShaderConstantsI[i] = TRUE; object->changed.pixelShaderConstantsI |= (1 << i);
} }
object->num_contained_ps_consts_i = MAX_CONST_I; object->num_contained_ps_consts_i = MAX_CONST_I;
...@@ -514,13 +514,13 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface, ...@@ -514,13 +514,13 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateStateBlock(IWineD3DDevice* iface,
} }
object->num_contained_vs_consts_f = GL_LIMITS(vshader_constantsF); object->num_contained_vs_consts_f = GL_LIMITS(vshader_constantsF);
for (i = 0; i < MAX_CONST_B; ++i) { for (i = 0; i < MAX_CONST_B; ++i) {
object->changed.vertexShaderConstantsB[i] = TRUE;
object->contained_vs_consts_b[i] = i; object->contained_vs_consts_b[i] = i;
object->changed.vertexShaderConstantsB |= (1 << i);
} }
object->num_contained_vs_consts_b = MAX_CONST_B; object->num_contained_vs_consts_b = MAX_CONST_B;
for (i = 0; i < MAX_CONST_I; ++i) { for (i = 0; i < MAX_CONST_I; ++i) {
object->changed.vertexShaderConstantsI[i] = TRUE;
object->contained_vs_consts_i[i] = i; object->contained_vs_consts_i[i] = i;
object->changed.vertexShaderConstantsI |= (1 << i);
} }
object->num_contained_vs_consts_i = MAX_CONST_I; object->num_contained_vs_consts_i = MAX_CONST_I;
for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) { for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
...@@ -3538,7 +3538,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShaderConstantB( ...@@ -3538,7 +3538,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShaderConstantB(
TRACE("Set BOOL constant %u to %s\n", start + i, srcData[i]? "true":"false"); TRACE("Set BOOL constant %u to %s\n", start + i, srcData[i]? "true":"false");
for (i = start; i < cnt + start; ++i) { for (i = start; i < cnt + start; ++i) {
This->updateStateBlock->changed.vertexShaderConstantsB[i] = TRUE; This->updateStateBlock->changed.vertexShaderConstantsB |= (1 << i);
} }
IWineD3DDeviceImpl_MarkStateDirty(This, STATE_VERTEXSHADERCONSTANT); IWineD3DDeviceImpl_MarkStateDirty(This, STATE_VERTEXSHADERCONSTANT);
...@@ -3586,7 +3586,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShaderConstantI( ...@@ -3586,7 +3586,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShaderConstantI(
srcData[i*4], srcData[i*4+1], srcData[i*4+2], srcData[i*4+3]); srcData[i*4], srcData[i*4+1], srcData[i*4+2], srcData[i*4+3]);
for (i = start; i < cnt + start; ++i) { for (i = start; i < cnt + start; ++i) {
This->updateStateBlock->changed.vertexShaderConstantsI[i] = TRUE; This->updateStateBlock->changed.vertexShaderConstantsI |= (1 << i);
} }
IWineD3DDeviceImpl_MarkStateDirty(This, STATE_VERTEXSHADERCONSTANT); IWineD3DDeviceImpl_MarkStateDirty(This, STATE_VERTEXSHADERCONSTANT);
...@@ -3971,7 +3971,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShaderConstantB( ...@@ -3971,7 +3971,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShaderConstantB(
TRACE("Set BOOL constant %u to %s\n", start + i, srcData[i]? "true":"false"); TRACE("Set BOOL constant %u to %s\n", start + i, srcData[i]? "true":"false");
for (i = start; i < cnt + start; ++i) { for (i = start; i < cnt + start; ++i) {
This->updateStateBlock->changed.pixelShaderConstantsB[i] = TRUE; This->updateStateBlock->changed.pixelShaderConstantsB |= (1 << i);
} }
IWineD3DDeviceImpl_MarkStateDirty(This, STATE_PIXELSHADERCONSTANT); IWineD3DDeviceImpl_MarkStateDirty(This, STATE_PIXELSHADERCONSTANT);
...@@ -4019,7 +4019,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShaderConstantI( ...@@ -4019,7 +4019,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShaderConstantI(
srcData[i*4], srcData[i*4+1], srcData[i*4+2], srcData[i*4+3]); srcData[i*4], srcData[i*4+1], srcData[i*4+2], srcData[i*4+3]);
for (i = start; i < cnt + start; ++i) { for (i = start; i < cnt + start; ++i) {
This->updateStateBlock->changed.pixelShaderConstantsI[i] = TRUE; This->updateStateBlock->changed.pixelShaderConstantsI |= (1 << i);
} }
IWineD3DDeviceImpl_MarkStateDirty(This, STATE_PIXELSHADERCONSTANT); IWineD3DDeviceImpl_MarkStateDirty(This, STATE_PIXELSHADERCONSTANT);
...@@ -4903,25 +4903,29 @@ static HRESULT WINAPI IWineD3DDeviceImpl_EndStateBlock(IWineD3DDevice *iface, IW ...@@ -4903,25 +4903,29 @@ static HRESULT WINAPI IWineD3DDeviceImpl_EndStateBlock(IWineD3DDevice *iface, IW
} }
} }
for(i = 0; i < MAX_CONST_I; i++) { for(i = 0; i < MAX_CONST_I; i++) {
if(object->changed.vertexShaderConstantsI[i]) { if (object->changed.vertexShaderConstantsI & (1 << i))
{
object->contained_vs_consts_i[object->num_contained_vs_consts_i] = i; object->contained_vs_consts_i[object->num_contained_vs_consts_i] = i;
object->num_contained_vs_consts_i++; object->num_contained_vs_consts_i++;
} }
} }
for(i = 0; i < MAX_CONST_B; i++) { for(i = 0; i < MAX_CONST_B; i++) {
if(object->changed.vertexShaderConstantsB[i]) { if (object->changed.vertexShaderConstantsB & (1 << i))
{
object->contained_vs_consts_b[object->num_contained_vs_consts_b] = i; object->contained_vs_consts_b[object->num_contained_vs_consts_b] = i;
object->num_contained_vs_consts_b++; object->num_contained_vs_consts_b++;
} }
} }
for(i = 0; i < MAX_CONST_I; i++) { for(i = 0; i < MAX_CONST_I; i++) {
if(object->changed.pixelShaderConstantsI[i]) { if (object->changed.pixelShaderConstantsI & (1 << i))
{
object->contained_ps_consts_i[object->num_contained_ps_consts_i] = i; object->contained_ps_consts_i[object->num_contained_ps_consts_i] = i;
object->num_contained_ps_consts_i++; object->num_contained_ps_consts_i++;
} }
} }
for(i = 0; i < MAX_CONST_B; i++) { for(i = 0; i < MAX_CONST_B; i++) {
if(object->changed.pixelShaderConstantsB[i]) { if (object->changed.pixelShaderConstantsB & (1 << i))
{
object->contained_ps_consts_b[object->num_contained_ps_consts_b] = i; object->contained_ps_consts_b[object->num_contained_ps_consts_b] = i;
object->num_contained_ps_consts_b++; object->num_contained_ps_consts_b++;
} }
......
...@@ -291,27 +291,23 @@ static void shader_glsl_load_constantsF(IWineD3DBaseShaderImpl *This, const Wine ...@@ -291,27 +291,23 @@ static void shader_glsl_load_constantsF(IWineD3DBaseShaderImpl *This, const Wine
checkGLcall("glUniform4fvARB()"); checkGLcall("glUniform4fvARB()");
} }
/** /* Loads integer constants (aka uniforms) into the currently set GLSL program. */
* Loads integer constants (aka uniforms) into the currently set GLSL program.
* When @constants_set == NULL, it will load all the constants.
*/
static void shader_glsl_load_constantsI(IWineD3DBaseShaderImpl *This, const WineD3D_GL_Info *gl_info, static void shader_glsl_load_constantsI(IWineD3DBaseShaderImpl *This, const WineD3D_GL_Info *gl_info,
GLhandleARB programId, const GLhandleARB locations[MAX_CONST_I], unsigned int max_constants, const GLhandleARB locations[MAX_CONST_I], const int *constants, WORD constants_set)
const int *constants, const BOOL *constants_set)
{ {
unsigned int i; unsigned int i;
struct list* ptr; struct list* ptr;
for (i=0; i<max_constants; ++i) { for (i = 0; constants_set; constants_set >>= 1, ++i)
if (NULL == constants_set || constants_set[i]) { {
if (!(constants_set & 1)) continue;
TRACE_(d3d_constants)("Loading constants %u: %i, %i, %i, %i\n", TRACE_(d3d_constants)("Loading constants %u: %i, %i, %i, %i\n",
i, constants[i*4], constants[i*4+1], constants[i*4+2], constants[i*4+3]); i, constants[i*4], constants[i*4+1], constants[i*4+2], constants[i*4+3]);
/* We found this uniform name in the program - go ahead and send the data */ /* We found this uniform name in the program - go ahead and send the data */
GL_EXTCALL(glUniform4ivARB(locations[i], 1, &constants[i*4])); GL_EXTCALL(glUniform4ivARB(locations[i], 1, &constants[i*4]));
checkGLcall("glUniform4ivARB"); checkGLcall("glUniform4ivARB");
}
} }
/* Load immediate constants */ /* Load immediate constants */
...@@ -331,12 +327,9 @@ static void shader_glsl_load_constantsI(IWineD3DBaseShaderImpl *This, const Wine ...@@ -331,12 +327,9 @@ static void shader_glsl_load_constantsI(IWineD3DBaseShaderImpl *This, const Wine
} }
} }
/** /* Loads boolean constants (aka uniforms) into the currently set GLSL program. */
* Loads boolean constants (aka uniforms) into the currently set GLSL program.
* When @constants_set == NULL, it will load all the constants.
*/
static void shader_glsl_load_constantsB(IWineD3DBaseShaderImpl *This, const WineD3D_GL_Info *gl_info, static void shader_glsl_load_constantsB(IWineD3DBaseShaderImpl *This, const WineD3D_GL_Info *gl_info,
GLhandleARB programId, unsigned int max_constants, const BOOL *constants, const BOOL *constants_set) GLhandleARB programId, const BOOL *constants, WORD constants_set)
{ {
GLhandleARB tmp_loc; GLhandleARB tmp_loc;
unsigned int i; unsigned int i;
...@@ -345,20 +338,23 @@ static void shader_glsl_load_constantsB(IWineD3DBaseShaderImpl *This, const Wine ...@@ -345,20 +338,23 @@ static void shader_glsl_load_constantsB(IWineD3DBaseShaderImpl *This, const Wine
const char* prefix = is_pshader? "PB":"VB"; const char* prefix = is_pshader? "PB":"VB";
struct list* ptr; struct list* ptr;
for (i=0; i<max_constants; ++i) { /* TODO: Benchmark and see if it would be beneficial to store the
if (NULL == constants_set || constants_set[i]) { * locations of the constants to avoid looking up each time */
for (i = 0; constants_set; constants_set >>= 1, ++i)
{
if (!(constants_set & 1)) continue;
TRACE_(d3d_constants)("Loading constants %u: %i;\n", i, constants[i]); TRACE_(d3d_constants)("Loading constants %i: %i;\n", i, constants[i]);
/* TODO: Benchmark and see if it would be beneficial to store the /* TODO: Benchmark and see if it would be beneficial to store the
* locations of the constants to avoid looking up each time */ * locations of the constants to avoid looking up each time */
snprintf(tmp_name, sizeof(tmp_name), "%s[%u]", prefix, i); snprintf(tmp_name, sizeof(tmp_name), "%s[%i]", prefix, i);
tmp_loc = GL_EXTCALL(glGetUniformLocationARB(programId, tmp_name)); tmp_loc = GL_EXTCALL(glGetUniformLocationARB(programId, tmp_name));
if (tmp_loc != -1) { if (tmp_loc != -1)
/* We found this uniform name in the program - go ahead and send the data */ {
GL_EXTCALL(glUniform1ivARB(tmp_loc, 1, &constants[i])); /* We found this uniform name in the program - go ahead and send the data */
checkGLcall("glUniform1ivARB"); GL_EXTCALL(glUniform1ivARB(tmp_loc, 1, &constants[i]));
} checkGLcall("glUniform1ivARB");
} }
} }
...@@ -420,15 +416,12 @@ static void shader_glsl_load_constants( ...@@ -420,15 +416,12 @@ static void shader_glsl_load_constants(
stateBlock->vertexShaderConstantF, constant_locations, constant_list); stateBlock->vertexShaderConstantF, constant_locations, constant_list);
/* Load DirectX 9 integer constants/uniforms for vertex shader */ /* Load DirectX 9 integer constants/uniforms for vertex shader */
shader_glsl_load_constantsI(vshader, gl_info, programId, shader_glsl_load_constantsI(vshader, gl_info, prog->vuniformI_locations,
prog->vuniformI_locations, MAX_CONST_I, stateBlock->vertexShaderConstantI, stateBlock->changed.vertexShaderConstantsI);
stateBlock->vertexShaderConstantI,
stateBlock->changed.vertexShaderConstantsI);
/* Load DirectX 9 boolean constants/uniforms for vertex shader */ /* Load DirectX 9 boolean constants/uniforms for vertex shader */
shader_glsl_load_constantsB(vshader, gl_info, programId, MAX_CONST_B, shader_glsl_load_constantsB(vshader, gl_info, programId,
stateBlock->vertexShaderConstantB, stateBlock->vertexShaderConstantB, stateBlock->changed.vertexShaderConstantsB);
stateBlock->changed.vertexShaderConstantsB);
/* Upload the position fixup params */ /* Upload the position fixup params */
GL_EXTCALL(glUniform4fvARB(prog->posFixup_location, 1, &deviceImpl->posFixup[0])); GL_EXTCALL(glUniform4fvARB(prog->posFixup_location, 1, &deviceImpl->posFixup[0]));
...@@ -447,15 +440,12 @@ static void shader_glsl_load_constants( ...@@ -447,15 +440,12 @@ static void shader_glsl_load_constants(
stateBlock->pixelShaderConstantF, constant_locations, constant_list); stateBlock->pixelShaderConstantF, constant_locations, constant_list);
/* Load DirectX 9 integer constants/uniforms for pixel shader */ /* Load DirectX 9 integer constants/uniforms for pixel shader */
shader_glsl_load_constantsI(pshader, gl_info, programId, shader_glsl_load_constantsI(pshader, gl_info, prog->puniformI_locations,
prog->puniformI_locations, MAX_CONST_I, stateBlock->pixelShaderConstantI, stateBlock->changed.pixelShaderConstantsI);
stateBlock->pixelShaderConstantI,
stateBlock->changed.pixelShaderConstantsI);
/* Load DirectX 9 boolean constants/uniforms for pixel shader */ /* Load DirectX 9 boolean constants/uniforms for pixel shader */
shader_glsl_load_constantsB(pshader, gl_info, programId, MAX_CONST_B, shader_glsl_load_constantsB(pshader, gl_info, programId,
stateBlock->pixelShaderConstantB, stateBlock->pixelShaderConstantB, stateBlock->changed.pixelShaderConstantsB);
stateBlock->changed.pixelShaderConstantsB);
/* Upload the environment bump map matrix if needed. The needsbumpmat member specifies the texture stage to load the matrix from. /* Upload the environment bump map matrix if needed. The needsbumpmat member specifies the texture stage to load the matrix from.
* It can't be 0 for a valid texbem instruction. * It can't be 0 for a valid texbem instruction.
......
...@@ -87,10 +87,10 @@ static void stateblock_savedstates_copy(IWineD3DStateBlock* iface, SAVEDSTATES * ...@@ -87,10 +87,10 @@ static void stateblock_savedstates_copy(IWineD3DStateBlock* iface, SAVEDSTATES *
memcpy(dest->textureState, source->textureState, bsize * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1)); memcpy(dest->textureState, source->textureState, bsize * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
memcpy(dest->samplerState, source->samplerState, bsize * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1)); memcpy(dest->samplerState, source->samplerState, bsize * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
memcpy(dest->clipplane, source->clipplane, bsize * MAX_CLIPPLANES); memcpy(dest->clipplane, source->clipplane, bsize * MAX_CLIPPLANES);
memcpy(dest->pixelShaderConstantsB, source->pixelShaderConstantsB, bsize * MAX_CONST_B); dest->pixelShaderConstantsB = source->pixelShaderConstantsB;
memcpy(dest->pixelShaderConstantsI, source->pixelShaderConstantsI, bsize * MAX_CONST_I); dest->pixelShaderConstantsI = source->pixelShaderConstantsI;
memcpy(dest->vertexShaderConstantsB, source->vertexShaderConstantsB, bsize * MAX_CONST_B); dest->vertexShaderConstantsB = source->vertexShaderConstantsB;
memcpy(dest->vertexShaderConstantsI, source->vertexShaderConstantsI, bsize * MAX_CONST_I); dest->vertexShaderConstantsI = source->vertexShaderConstantsI;
/* Dynamically sized arrays */ /* Dynamically sized arrays */
memcpy(dest->pixelShaderConstantsF, source->pixelShaderConstantsF, bsize * GL_LIMITS(pshader_constantsF)); memcpy(dest->pixelShaderConstantsF, source->pixelShaderConstantsF, bsize * GL_LIMITS(pshader_constantsF));
...@@ -125,10 +125,10 @@ void stateblock_savedstates_set( ...@@ -125,10 +125,10 @@ void stateblock_savedstates_set(
memset(states->textureState, value, bsize * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1)); memset(states->textureState, value, bsize * MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1));
memset(states->samplerState, value, bsize * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1)); memset(states->samplerState, value, bsize * MAX_COMBINED_SAMPLERS * (WINED3D_HIGHEST_SAMPLER_STATE + 1));
memset(states->clipplane, value, bsize * MAX_CLIPPLANES); memset(states->clipplane, value, bsize * MAX_CLIPPLANES);
memset(states->pixelShaderConstantsB, value, bsize * MAX_CONST_B); states->pixelShaderConstantsB = value ? 0xffff : 0;
memset(states->pixelShaderConstantsI, value, bsize * MAX_CONST_I); states->pixelShaderConstantsI = value ? 0xffff : 0;
memset(states->vertexShaderConstantsB, value, bsize * MAX_CONST_B); states->vertexShaderConstantsB = value ? 0xffff : 0;
memset(states->vertexShaderConstantsI, value, bsize * MAX_CONST_I); states->vertexShaderConstantsI = value ? 0xffff : 0;
/* Dynamically sized arrays */ /* Dynamically sized arrays */
memset(states->pixelShaderConstantsF, value, bsize * GL_LIMITS(pshader_constantsF)); memset(states->pixelShaderConstantsF, value, bsize * GL_LIMITS(pshader_constantsF));
......
...@@ -1662,12 +1662,12 @@ typedef struct SAVEDSTATES { ...@@ -1662,12 +1662,12 @@ typedef struct SAVEDSTATES {
BOOL clipplane[MAX_CLIPPLANES]; BOOL clipplane[MAX_CLIPPLANES];
BOOL vertexDecl; BOOL vertexDecl;
BOOL pixelShader; BOOL pixelShader;
BOOL pixelShaderConstantsB[MAX_CONST_B]; WORD pixelShaderConstantsB;
BOOL pixelShaderConstantsI[MAX_CONST_I]; WORD pixelShaderConstantsI;
BOOL *pixelShaderConstantsF; BOOL *pixelShaderConstantsF;
BOOL vertexShader; BOOL vertexShader;
BOOL vertexShaderConstantsB[MAX_CONST_B]; WORD vertexShaderConstantsB;
BOOL vertexShaderConstantsI[MAX_CONST_I]; WORD vertexShaderConstantsI;
BOOL *vertexShaderConstantsF; BOOL *vertexShaderConstantsF;
BOOL scissorRect; BOOL scissorRect;
} SAVEDSTATES; } SAVEDSTATES;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment