wined3d: Store integer uniform locations.

This commit is contained in:
Stefan Dösinger 2007-11-06 23:36:10 +01:00 committed by Alexandre Julliard
parent bfec6c352d
commit 6fd4f8f699
2 changed files with 23 additions and 23 deletions

View File

@ -230,15 +230,12 @@ static void shader_glsl_load_constantsI(
IWineD3DBaseShaderImpl* This, IWineD3DBaseShaderImpl* This,
WineD3D_GL_Info *gl_info, WineD3D_GL_Info *gl_info,
GLhandleARB programId, GLhandleARB programId,
GLhandleARB locations[MAX_CONST_I],
unsigned max_constants, unsigned max_constants,
int* constants, int* constants,
BOOL* constants_set) { BOOL* constants_set) {
GLhandleARB tmp_loc;
int i; int i;
char tmp_name[8];
char is_pshader = shader_is_pshader_version(This->baseShader.hex_version);
const char* prefix = is_pshader? "PI":"VI";
struct list* ptr; struct list* ptr;
for (i=0; i<max_constants; ++i) { for (i=0; i<max_constants; ++i) {
@ -247,15 +244,9 @@ static void shader_glsl_load_constantsI(
TRACE_(d3d_constants)("Loading constants %i: %i, %i, %i, %i\n", TRACE_(d3d_constants)("Loading constants %i: %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]);
/* TODO: Benchmark and see if it would be beneficial to store the /* We found this uniform name in the program - go ahead and send the data */
* locations of the constants to avoid looking up each time */ GL_EXTCALL(glUniform4ivARB(locations[i], 1, &constants[i*4]));
snprintf(tmp_name, sizeof(tmp_name), "%s[%i]", prefix, i); checkGLcall("glUniform4ivARB");
tmp_loc = GL_EXTCALL(glGetUniformLocationARB(programId, tmp_name));
if (tmp_loc != -1) {
/* We found this uniform name in the program - go ahead and send the data */
GL_EXTCALL(glUniform4ivARB(tmp_loc, 1, &constants[i*4]));
checkGLcall("glUniform4ivARB");
}
} }
} }
@ -269,13 +260,9 @@ static void shader_glsl_load_constantsI(
TRACE_(d3d_constants)("Loading local constants %i: %i, %i, %i, %i\n", idx, TRACE_(d3d_constants)("Loading local constants %i: %i, %i, %i, %i\n", idx,
values[0], values[1], values[2], values[3]); values[0], values[1], values[2], values[3]);
snprintf(tmp_name, sizeof(tmp_name), "%s[%i]", prefix, idx); /* We found this uniform name in the program - go ahead and send the data */
tmp_loc = GL_EXTCALL(glGetUniformLocationARB(programId, tmp_name)); GL_EXTCALL(glUniform4ivARB(locations[idx], 1, values));
if (tmp_loc != -1) { checkGLcall("glUniform4ivARB");
/* We found this uniform name in the program - go ahead and send the data */
GL_EXTCALL(glUniform4ivARB(tmp_loc, 1, values));
checkGLcall("glUniform4ivARB");
}
ptr = list_next(&This->baseShader.constantsI, ptr); ptr = list_next(&This->baseShader.constantsI, ptr);
} }
} }
@ -375,7 +362,8 @@ 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, MAX_CONST_I, shader_glsl_load_constantsI(vshader, gl_info, programId,
prog->vuniformI_locations, MAX_CONST_I,
stateBlock->vertexShaderConstantI, stateBlock->vertexShaderConstantI,
stateBlock->changed.vertexShaderConstantsI); stateBlock->changed.vertexShaderConstantsI);
@ -393,7 +381,7 @@ void shader_glsl_load_constants(
IWineD3DBaseShaderImpl* pshader = (IWineD3DBaseShaderImpl*) stateBlock->pixelShader; IWineD3DBaseShaderImpl* pshader = (IWineD3DBaseShaderImpl*) stateBlock->pixelShader;
constant_locations = stateBlock->glsl_program->puniformF_locations; constant_locations = prog->puniformF_locations;
constant_list = &stateBlock->set_pconstantsF; constant_list = &stateBlock->set_pconstantsF;
/* Load pixel shader samplers */ /* Load pixel shader samplers */
@ -404,7 +392,8 @@ 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, MAX_CONST_I, shader_glsl_load_constantsI(pshader, gl_info, programId,
prog->puniformI_locations, MAX_CONST_I,
stateBlock->pixelShaderConstantI, stateBlock->pixelShaderConstantI,
stateBlock->changed.pixelShaderConstantsI); stateBlock->changed.pixelShaderConstantsI);
@ -3036,11 +3025,19 @@ static void set_glsl_shader_program(IWineD3DDevice *iface, BOOL use_ps, BOOL use
snprintf(glsl_name, sizeof(glsl_name), "VC[%i]", i); snprintf(glsl_name, sizeof(glsl_name), "VC[%i]", i);
entry->vuniformF_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name)); entry->vuniformF_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name));
} }
for (i = 0; i < MAX_CONST_I; ++i) {
snprintf(glsl_name, sizeof(glsl_name), "VI[%i]", i);
entry->vuniformI_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name));
}
entry->puniformF_locations = HeapAlloc(GetProcessHeap(), 0, sizeof(GLhandleARB) * GL_LIMITS(pshader_constantsF)); entry->puniformF_locations = HeapAlloc(GetProcessHeap(), 0, sizeof(GLhandleARB) * GL_LIMITS(pshader_constantsF));
for (i = 0; i < GL_LIMITS(pshader_constantsF); ++i) { for (i = 0; i < GL_LIMITS(pshader_constantsF); ++i) {
snprintf(glsl_name, sizeof(glsl_name), "PC[%i]", i); snprintf(glsl_name, sizeof(glsl_name), "PC[%i]", i);
entry->puniformF_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name)); entry->puniformF_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name));
} }
for (i = 0; i < MAX_CONST_I; ++i) {
snprintf(glsl_name, sizeof(glsl_name), "PI[%i]", i);
entry->puniformI_locations[i] = GL_EXTCALL(glGetUniformLocationARB(programId, glsl_name));
}
entry->posFixup_location = GL_EXTCALL(glGetUniformLocationARB(programId, "posFixup")); entry->posFixup_location = GL_EXTCALL(glGetUniformLocationARB(programId, "posFixup"));
entry->bumpenvmat_location = GL_EXTCALL(glGetUniformLocationARB(programId, "bumpenvmat")); entry->bumpenvmat_location = GL_EXTCALL(glGetUniformLocationARB(programId, "bumpenvmat"));
@ -3049,6 +3046,7 @@ static void set_glsl_shader_program(IWineD3DDevice *iface, BOOL use_ps, BOOL use
entry->srgb_comparison_location = GL_EXTCALL(glGetUniformLocationARB(programId, "srgb_comparison")); entry->srgb_comparison_location = GL_EXTCALL(glGetUniformLocationARB(programId, "srgb_comparison"));
entry->srgb_mul_low_location = GL_EXTCALL(glGetUniformLocationARB(programId, "srgb_mul_low")); entry->srgb_mul_low_location = GL_EXTCALL(glGetUniformLocationARB(programId, "srgb_mul_low"));
entry->ycorrection_location = GL_EXTCALL(glGetUniformLocationARB(programId, "ycorrection")); entry->ycorrection_location = GL_EXTCALL(glGetUniformLocationARB(programId, "ycorrection"));
checkGLcall("Find glsl program uniform locations");
} }
static GLhandleARB create_glsl_blt_shader(WineD3D_GL_Info *gl_info) { static GLhandleARB create_glsl_blt_shader(WineD3D_GL_Info *gl_info) {

View File

@ -1611,6 +1611,8 @@ struct glsl_shader_prog_link {
GLhandleARB programId; GLhandleARB programId;
GLhandleARB *vuniformF_locations; GLhandleARB *vuniformF_locations;
GLhandleARB *puniformF_locations; GLhandleARB *puniformF_locations;
GLhandleARB vuniformI_locations[MAX_CONST_I];
GLhandleARB puniformI_locations[MAX_CONST_I];
GLhandleARB posFixup_location; GLhandleARB posFixup_location;
GLhandleARB bumpenvmat_location; GLhandleARB bumpenvmat_location;
GLhandleARB luminancescale_location; GLhandleARB luminancescale_location;