diff --git a/gfx/drivers_shader/shader_gl_cg.c b/gfx/drivers_shader/shader_gl_cg.c index 5456a38e15..15b6c9bb7f 100644 --- a/gfx/drivers_shader/shader_gl_cg.c +++ b/gfx/drivers_shader/shader_gl_cg.c @@ -105,42 +105,61 @@ typedef struct cg_shader_data CGcontext cgCtx; } cg_shader_data_t; -static void cg_uniform_set_parameter(void *data, void *_shader_data, void *uniform_data) +struct uniform_cg_data { - struct uniform_info *param = (struct uniform_info*)data; - CGparameter *cg_param = (CGparameter*)uniform_data; - struct shader_program_cg_data *shader_data = (struct shader_program_cg_data*)_shader_data; + CGparameter loc; +}; + +static void cg_uniform_set_parameter( + void *data, + void *uniform_info_data, + void *_shader_info_data, + void *uniform_data) +{ + CGparameter location; + cg_shader_data_t *cg_data = (cg_shader_data_t*)data; + struct uniform_info *param = (struct uniform_info*)uniform_info_data; + struct shader_program_cg_data *shader_data = (struct shader_program_cg_data*)_shader_info_data; if (!param || !param->enabled) return; + if (param->lookup.enable) + location = cgGetNamedParameter( + cg_data->prg[param->lookup.idx].fprg, cg_data->shader->lut[param->lookup.idx].id); + else + { + struct uniform_cg_data *cg_param = (struct uniform_cg_data*)uniform_data; + location = cg_param->loc; + } + switch (param->type) { case UNIFORM_1F: - cgGLSetParameter1f((CGparameter)*cg_param, param->result.f.v0); + cgGLSetParameter1f(location, param->result.f.v0); break; case UNIFORM_2F: - cgGLSetParameter2f((CGparameter)*cg_param, param->result.f.v0, param->result.f.v1); + cgGLSetParameter2f(location, param->result.f.v0, param->result.f.v1); break; case UNIFORM_3F: - cgGLSetParameter3f((CGparameter)*cg_param, param->result.f.v0, param->result.f.v1, + cgGLSetParameter3f(location, param->result.f.v0, param->result.f.v1, param->result.f.v2); break; case UNIFORM_4F: - cgGLSetParameter4f((CGparameter)*cg_param, param->result.f.v0, param->result.f.v1, + cgGLSetParameter4f(location, param->result.f.v0, param->result.f.v1, param->result.f.v2, param->result.f.v3); break; case UNIFORM_1FV: - cgGLSetParameter1fv((CGparameter)*cg_param, param->result.floatv); + cgGLSetParameter1fv(location, param->result.floatv); break; case UNIFORM_2FV: - cgGLSetParameter2fv((CGparameter)*cg_param, param->result.floatv); + cgGLSetParameter2fv(location, param->result.floatv); break; case UNIFORM_3FV: - cgGLSetParameter3fv((CGparameter)*cg_param, param->result.floatv); + cgGLSetParameter3fv(location, param->result.floatv); break; case UNIFORM_4FV: - cgGLSetParameter3fv((CGparameter)*cg_param, param->result.floatv); + cgGLSetParameter3fv(location, param->result.floatv); break; case UNIFORM_1I: /* Unimplemented - Cg limitation */ @@ -268,8 +287,8 @@ static void gl_cg_set_texture_info( const struct gfx_tex_info *info) { unsigned i; - CGparameter uniform_data[4]; - struct uniform_info uniform_params[4]; + struct uniform_cg_data uniform_data[4]; + struct uniform_info uniform_params[4] = {0}; CGparameter param = params->tex; if (param) @@ -283,31 +302,31 @@ static void gl_cg_set_texture_info( uniform_params[0].type = UNIFORM_2F; uniform_params[0].result.f.v0 = info->input_size[0]; uniform_params[0].result.f.v1 = info->input_size[1]; - uniform_data[0] = params->vid_size_v; + uniform_data[0].loc = params->vid_size_v; uniform_params[1].location = 1; uniform_params[1].enabled = true; uniform_params[1].type = UNIFORM_2F; uniform_params[1].result.f.v0 = info->input_size[0]; uniform_params[1].result.f.v1 = info->input_size[1]; - uniform_data[1] = params->vid_size_f; + uniform_data[1].loc = params->vid_size_f; uniform_params[2].location = 2; uniform_params[2].enabled = true; uniform_params[2].type = UNIFORM_2F; uniform_params[2].result.f.v0 = info->tex_size[0]; uniform_params[2].result.f.v1 = info->tex_size[1]; - uniform_data[2] = params->tex_size_v; + uniform_data[2].loc = params->tex_size_v; uniform_params[3].location = 3; uniform_params[3].enabled = true; uniform_params[3].type = UNIFORM_2F; uniform_params[3].result.f.v0 = info->tex_size[0]; uniform_params[3].result.f.v1 = info->tex_size[1]; - uniform_data[3] = params->tex_size_f; + uniform_data[3].loc = params->tex_size_f; for (i = 0; i < 4; i++) - cg_uniform_set_parameter(&uniform_params[i], NULL, &uniform_data[i]); + cg_uniform_set_parameter(cg_data, &uniform_params[i], NULL, &uniform_data[i]); if (params->coord) { @@ -330,8 +349,8 @@ static void gl_cg_set_params(void *data, void *shader_data, unsigned fbo_info_cnt) { unsigned i; - struct uniform_info uniform_params[10]; - CGparameter uniform_data[10]; + struct uniform_cg_data uniform_data[10]; + struct uniform_info uniform_params[10] = {0}; unsigned uniform_count = 0; const struct gfx_tex_info *info = (const struct gfx_tex_info*)_info; const struct gfx_tex_info *prev_info = (const struct gfx_tex_info*)_prev_info; @@ -350,54 +369,54 @@ static void gl_cg_set_params(void *data, void *shader_data, uniform_params[0].type = UNIFORM_2F; uniform_params[0].result.f.v0 = width; uniform_params[0].result.f.v1 = height; - uniform_data[0] = cg_data->prg[cg_data->active_idx].vid_size_f; + uniform_data[0].loc = cg_data->prg[cg_data->active_idx].vid_size_f; uniform_params[1].location = 1; uniform_params[1].enabled = true; uniform_params[1].type = UNIFORM_2F; uniform_params[1].result.f.v0 = tex_width; uniform_params[1].result.f.v1 = tex_height; - uniform_data[1] = cg_data->prg[cg_data->active_idx].tex_size_f; + uniform_data[1].loc = cg_data->prg[cg_data->active_idx].tex_size_f; uniform_params[2].location = 2; uniform_params[2].enabled = true; uniform_params[2].type = UNIFORM_2F; uniform_params[2].result.f.v0 = out_width; uniform_params[2].result.f.v1 = out_height; - uniform_data[2] = cg_data->prg[cg_data->active_idx].out_size_f; + uniform_data[2].loc = cg_data->prg[cg_data->active_idx].out_size_f; uniform_params[3].location = 3; uniform_params[3].enabled = true; uniform_params[3].type = UNIFORM_1F; uniform_params[3].result.f.v0 = state_manager_frame_is_reversed() ? -1.0 : 1.0; - uniform_data[3] = cg_data->prg[cg_data->active_idx].frame_dir_f; + uniform_data[3].loc = cg_data->prg[cg_data->active_idx].frame_dir_f; uniform_params[4].location = 4; uniform_params[4].enabled = true; uniform_params[4].type = UNIFORM_2F; uniform_params[4].result.f.v0 = width; uniform_params[4].result.f.v1 = height; - uniform_data[4] = cg_data->prg[cg_data->active_idx].vid_size_v; + uniform_data[4].loc = cg_data->prg[cg_data->active_idx].vid_size_v; uniform_params[5].location = 5; uniform_params[5].enabled = true; uniform_params[5].type = UNIFORM_2F; uniform_params[5].result.f.v0 = tex_width; uniform_params[5].result.f.v1 = tex_height; - uniform_data[5] = cg_data->prg[cg_data->active_idx].tex_size_v; + uniform_data[5].loc = cg_data->prg[cg_data->active_idx].tex_size_v; uniform_params[6].location = 6; uniform_params[6].enabled = true; uniform_params[6].type = UNIFORM_2F; uniform_params[6].result.f.v0 = out_width; uniform_params[6].result.f.v1 = out_height; - uniform_data[6] = cg_data->prg[cg_data->active_idx].out_size_v; + uniform_data[6].loc = cg_data->prg[cg_data->active_idx].out_size_v; uniform_params[7].location = 7; uniform_params[7].enabled = true; uniform_params[7].type = UNIFORM_1F; uniform_params[7].result.f.v0 = state_manager_frame_is_reversed() ? -1.0 : 1.0; - uniform_data[7] = cg_data->prg[cg_data->active_idx].frame_dir_v; + uniform_data[7].loc = cg_data->prg[cg_data->active_idx].frame_dir_v; uniform_count += 8; @@ -411,19 +430,19 @@ static void gl_cg_set_params(void *data, void *shader_data, uniform_params[8].enabled = true; uniform_params[8].type = UNIFORM_1F; uniform_params[8].result.f.v0 = (float)frame_count; - uniform_data[8] = cg_data->prg[cg_data->active_idx].frame_cnt_f; + uniform_data[8].loc = cg_data->prg[cg_data->active_idx].frame_cnt_f; uniform_params[9].location = 9; uniform_params[9].enabled = true; uniform_params[9].type = UNIFORM_1F; uniform_params[9].result.f.v0 = (float)frame_count; - uniform_data[9] = cg_data->prg[cg_data->active_idx].frame_cnt_v; + uniform_data[9].loc = cg_data->prg[cg_data->active_idx].frame_cnt_v; uniform_count += 2; } for (i = 0; i < uniform_count; i++) - cg_uniform_set_parameter(&uniform_params[i], &cg_data->prg[i], &uniform_data[i]); + cg_uniform_set_parameter(cg_data, &uniform_params[i], &cg_data->prg[i], &uniform_data[i]); /* Set orig texture. */ gl_cg_set_texture_info(cg_data, &cg_data->prg[cg_data->active_idx].orig, info); @@ -469,11 +488,11 @@ static void gl_cg_set_params(void *data, void *shader_data, for (i = 0; i < cg_data->shader->num_parameters; i++) { unsigned j; - CGparameter pragma_cg_params[2]; + struct uniform_cg_data pragma_cg_params[2]; - pragma_cg_params[0] = cgGetNamedParameter( + pragma_cg_params[0].loc = cgGetNamedParameter( cg_data->prg[cg_data->active_idx].vprg, cg_data->shader->parameters[i].id); - pragma_cg_params[1] = cgGetNamedParameter( + pragma_cg_params[1].loc = cgGetNamedParameter( cg_data->prg[cg_data->active_idx].fprg, cg_data->shader->parameters[i].id); uniform_params[0].location = 0; @@ -487,7 +506,7 @@ static void gl_cg_set_params(void *data, void *shader_data, uniform_params[1].result.f.v0 = cg_data->shader->parameters[i].current; for (j = 0; j < 2; j++) - cg_uniform_set_parameter(&uniform_params[j], &cg_data->prg[j], &pragma_cg_params[j]); + cg_uniform_set_parameter(cg_data, &uniform_params[j], &cg_data->prg[j], &pragma_cg_params[j]); } /* Set state parameters. */ @@ -504,11 +523,11 @@ static void gl_cg_set_params(void *data, void *shader_data, for (i = 0; i < cnt; i++) { unsigned j; - CGparameter pragma_cg_params[2]; + struct uniform_cg_data pragma_cg_params[2]; - pragma_cg_params[0] = cgGetNamedParameter( + pragma_cg_params[0].loc = cgGetNamedParameter( cg_data->prg[cg_data->active_idx].vprg, tracker_info[i].id); - pragma_cg_params[1] = cgGetNamedParameter( + pragma_cg_params[1].loc = cgGetNamedParameter( cg_data->prg[cg_data->active_idx].fprg, tracker_info[i].id); uniform_params[0].location = 0; @@ -522,7 +541,7 @@ static void gl_cg_set_params(void *data, void *shader_data, uniform_params[1].result.f.v0 = tracker_info[i].value; for (j = 0; j < 2; j++) - cg_uniform_set_parameter(&uniform_params[j], &cg_data->prg[j], &pragma_cg_params[j]); + cg_uniform_set_parameter(cg_data, &uniform_params[j], &cg_data->prg[j], &pragma_cg_params[j]); } } } diff --git a/gfx/drivers_shader/shader_glsl.c b/gfx/drivers_shader/shader_glsl.c index 0c38ca9f59..738e20c844 100644 --- a/gfx/drivers_shader/shader_glsl.c +++ b/gfx/drivers_shader/shader_glsl.c @@ -1049,46 +1049,57 @@ error: return NULL; } -static void glsl_uniform_set_parameter(void *data, void *_shader_data, void *uniform_data) +static void glsl_uniform_set_parameter( + void *data, + void *uniform_info_data, + void *shader_info_data, + void *uniform_data) { - struct uniform_info *param = (struct uniform_info*)data; - struct shader_program_glsl_data *shader_data = (struct shader_program_glsl_data*)_shader_data; + GLint location = 0; + glsl_shader_data_t *glsl = (glsl_shader_data_t*)data; + struct uniform_info *param = (struct uniform_info*)uniform_info_data; + struct shader_program_glsl_data *shader_data = (struct shader_program_glsl_data*)shader_info_data; if (!param) return; + if (param->lookup.enable) + location = glGetUniformLocation(glsl->prg[param->lookup.idx].id, param->lookup.ident); + else + location = param->location; + switch (param->type) { case UNIFORM_1F: - glUniform1f(param->location, param->result.f.v0); + glUniform1f(location, param->result.f.v0); break; case UNIFORM_2F: - glUniform2f(param->location, param->result.f.v0, + glUniform2f(location, param->result.f.v0, param->result.f.v1); break; case UNIFORM_3F: - glUniform3f(param->location, param->result.f.v0, + glUniform3f(location, param->result.f.v0, param->result.f.v1, param->result.f.v2); break; case UNIFORM_4F: - glUniform4f(param->location, param->result.f.v0, + glUniform4f(location, param->result.f.v0, param->result.f.v1, param->result.f.v2, param->result.f.v3); break; case UNIFORM_1FV: - glUniform1fv(param->location, 1, param->result.floatv); + glUniform1fv(location, 1, param->result.floatv); break; case UNIFORM_2FV: - glUniform2fv(param->location, 1, param->result.floatv); + glUniform2fv(location, 1, param->result.floatv); break; case UNIFORM_3FV: - glUniform3fv(param->location, 1, param->result.floatv); + glUniform3fv(location, 1, param->result.floatv); break; case UNIFORM_4FV: - glUniform4fv(param->location, 1, param->result.floatv); + glUniform4fv(location, 1, param->result.floatv); break; case UNIFORM_1I: - glUniform1i(param->location, param->result.integer.v0); + glUniform1i(location, param->result.integer.v0); break; } } @@ -1104,7 +1115,7 @@ static void gl_glsl_set_params(void *data, void *shader_data, const void *_fbo_info, unsigned fbo_info_cnt) { unsigned i; - struct uniform_info uniform_params[10]; + struct uniform_info uniform_params[10] = {0}; GLfloat buffer[512]; struct glsl_attrib attribs[32]; float input_size[2], output_size[2], texture_size[2]; @@ -1183,12 +1194,12 @@ static void gl_glsl_set_params(void *data, void *shader_data, uniform_count++; for (i = 0; i < uniform_count; i++) - glsl_uniform_set_parameter(&uniform_params[i], NULL, NULL); + glsl_uniform_set_parameter(glsl, &uniform_params[i], NULL, NULL); /* Set lookup textures. */ for (i = 0; i < glsl->shader->luts; i++) { - struct uniform_info lut_uniform; + struct uniform_info lut_uniform = {0}; if (uni->lut_texture[i] < 0) continue; @@ -1201,7 +1212,7 @@ static void gl_glsl_set_params(void *data, void *shader_data, lut_uniform.type = UNIFORM_1I; lut_uniform.result.integer.v0 = texunit; - glsl_uniform_set_parameter(&lut_uniform, NULL, NULL); + glsl_uniform_set_parameter(glsl, &lut_uniform, NULL, NULL); texunit++; } @@ -1214,7 +1225,7 @@ static void gl_glsl_set_params(void *data, void *shader_data, /* Set original texture. */ if (uni->orig.texture >= 0) { - struct uniform_info orig_tex_uniform; + struct uniform_info orig_tex_uniform = {0}; /* Bind original texture. */ glActiveTexture(GL_TEXTURE0 + texunit); @@ -1223,7 +1234,7 @@ static void gl_glsl_set_params(void *data, void *shader_data, orig_tex_uniform.type = UNIFORM_1I; orig_tex_uniform.result.integer.v0 = texunit; - glsl_uniform_set_parameter(&orig_tex_uniform, NULL, NULL); + glsl_uniform_set_parameter(glsl, &orig_tex_uniform, NULL, NULL); glBindTexture(GL_TEXTURE_2D, info->tex); texunit++; @@ -1246,7 +1257,7 @@ static void gl_glsl_set_params(void *data, void *shader_data, orig_uniforms[1].enabled = true; for (j = 0; j < 2; j++) - glsl_uniform_set_parameter(&orig_uniforms[i], NULL, NULL); + glsl_uniform_set_parameter(glsl, &orig_uniforms[i], NULL, NULL); /* Pass texture coordinates. */ if (uni->orig.tex_coord >= 0) @@ -1264,7 +1275,7 @@ static void gl_glsl_set_params(void *data, void *shader_data, /* Set feedback texture. */ if (uni->feedback.texture >= 0) { - struct uniform_info feedback_texture_param; + struct uniform_info feedback_texture_param = {0}; /* Bind original texture. */ glActiveTexture(GL_TEXTURE0 + texunit); @@ -1274,7 +1285,7 @@ static void gl_glsl_set_params(void *data, void *shader_data, feedback_texture_param.type = UNIFORM_1I; feedback_texture_param.result.integer.v0 = texunit; - glsl_uniform_set_parameter(&feedback_texture_param, NULL, NULL); + glsl_uniform_set_parameter(glsl, &feedback_texture_param, NULL, NULL); glBindTexture(GL_TEXTURE_2D, feedback_info->tex); texunit++; @@ -1297,7 +1308,7 @@ static void gl_glsl_set_params(void *data, void *shader_data, feedback_uniforms[1].enabled = true; for (j = 0; j < 2; j++) - glsl_uniform_set_parameter(&feedback_uniforms[i], NULL, NULL); + glsl_uniform_set_parameter(glsl, &feedback_uniforms[i], NULL, NULL); /* Pass texture coordinates. */ if (uni->feedback.tex_coord >= 0) @@ -1316,7 +1327,7 @@ static void gl_glsl_set_params(void *data, void *shader_data, for (i = 0; i < fbo_info_cnt; i++) { unsigned j; - struct uniform_info fbo_tex_params[3]; + struct uniform_info fbo_tex_params[3] = {0}; if (uni->pass[i].texture) { @@ -1348,7 +1359,7 @@ static void gl_glsl_set_params(void *data, void *shader_data, fbo_tex_params[2].enabled = true; for (j = 0; j < 3; j++) - glsl_uniform_set_parameter(&fbo_tex_params[i], NULL, NULL); + glsl_uniform_set_parameter(glsl, &fbo_tex_params[i], NULL, NULL); if (uni->pass[i].tex_coord >= 0) { @@ -1368,7 +1379,7 @@ static void gl_glsl_set_params(void *data, void *shader_data, for (i = 0; i < PREV_TEXTURES; i++) { unsigned j; - struct uniform_info prev_tex_params[3]; + struct uniform_info prev_tex_params[3] = {0}; if (uni->prev[i].texture >= 0) { @@ -1400,7 +1411,7 @@ static void gl_glsl_set_params(void *data, void *shader_data, prev_tex_params[2].enabled = true; for (j = 0; j < 3; j++) - glsl_uniform_set_parameter(&prev_tex_params[i], NULL, NULL); + glsl_uniform_set_parameter(glsl, &prev_tex_params[i], NULL, NULL); /* Pass texture coordinates. */ if (uni->prev[i].tex_coord >= 0) @@ -1427,7 +1438,7 @@ static void gl_glsl_set_params(void *data, void *shader_data, /* #pragma parameters. */ for (i = 0; i < glsl->shader->num_parameters; i++) { - struct uniform_info pragma_param; + struct uniform_info pragma_param = {0}; int location = glGetUniformLocation( glsl->prg[glsl->glsl_active_index].id, glsl->shader->parameters[i].id); @@ -1437,7 +1448,7 @@ static void gl_glsl_set_params(void *data, void *shader_data, pragma_param.type = UNIFORM_1F; pragma_param.result.f.v0 = glsl->shader->parameters[i].current; - glsl_uniform_set_parameter(&pragma_param, NULL, NULL); + glsl_uniform_set_parameter(glsl, &pragma_param, NULL, NULL); } /* Set state parameters. */ @@ -1452,7 +1463,7 @@ static void gl_glsl_set_params(void *data, void *shader_data, for (i = 0; i < cnt; i++) { - struct uniform_info state_param; + struct uniform_info state_param = {0}; int location = glGetUniformLocation( glsl->prg[glsl->glsl_active_index].id, state_info[i].id); @@ -1462,7 +1473,7 @@ static void gl_glsl_set_params(void *data, void *shader_data, state_param.type = UNIFORM_1F; state_param.result.f.v0 = state_info[i].value; - glsl_uniform_set_parameter(&state_param, NULL, NULL); + glsl_uniform_set_parameter(glsl, &state_param, NULL, NULL); } } } diff --git a/gfx/drivers_shader/shader_hlsl.c b/gfx/drivers_shader/shader_hlsl.c index 1252e9513f..7f98301995 100644 --- a/gfx/drivers_shader/shader_hlsl.c +++ b/gfx/drivers_shader/shader_hlsl.c @@ -103,10 +103,17 @@ void hlsl_set_proj_matrix(void *data, XMMATRIX rotation_value) hlsl_data->prg[hlsl_data->active_idx].mvp_val = rotation_value; } -static void hlsl_uniform_set_parameter(void *data, void *_shader_data, void *uniform_data) +static void hlsl_uniform_set_parameter( + void *data, + void *uniform_info_data, + void *_shader_info_data, + void *uniform_data) { - struct uniform_info *param = (struct uniform_info*)data; - struct shader_program_hlsl_data *shader_data = (struct shader_program_hlsl_data*)_shader_data; + hlsl_shader_data_t *hlsl = (hlsl_shader_data_t*)data; + struct uniform_info *param = (struct uniform_info*)uniform_info_data; + struct shader_program_hlsl_data *shader_data = (struct shader_program_hlsl_data*)_shader_info_data; + + (void)hlsl; if (!param || !param->enabled) return; @@ -114,28 +121,28 @@ static void hlsl_uniform_set_parameter(void *data, void *_shader_data, void *uni switch (param->type) { case UNIFORM_1F: - /* Unimplemented - Cg limitation */ + /* Unimplemented */ break; case UNIFORM_2F: - /* Unimplemented - Cg limitation */ + /* Unimplemented */ break; case UNIFORM_3F: - /* Unimplemented - Cg limitation */ + /* Unimplemented */ break; case UNIFORM_4F: - /* Unimplemented - Cg limitation */ + /* Unimplemented */ break; case UNIFORM_1FV: - /* Unimplemented - Cg limitation */ + /* Unimplemented */ break; case UNIFORM_2FV: - /* Unimplemented - Cg limitation */ + /* Unimplemented */ break; case UNIFORM_3FV: - /* Unimplemented - Cg limitation */ + /* Unimplemented */ break; case UNIFORM_4FV: - /* Unimplemented - Cg limitation */ + /* Unimplemented */ break; case UNIFORM_1I: /* Unimplemented - Cg limitation */ diff --git a/gfx/video_shader_driver.h b/gfx/video_shader_driver.h index e83c9b7d03..896713a3f2 100644 --- a/gfx/video_shader_driver.h +++ b/gfx/video_shader_driver.h @@ -109,6 +109,13 @@ struct uniform_info int32_t location; int32_t count; + struct + { + const char *ident; + uint32_t idx; + bool enable; + } lookup; + struct { struct