don't write unused uniforms

This commit is contained in:
2025-09-28 23:32:27 +02:00
parent 529f92ab4d
commit 8511e50b6d
6 changed files with 61 additions and 33 deletions
+8 -2
View File
@@ -67,6 +67,11 @@ static void init_context(Parameters params, unsigned int in_count,
state_randomize(context, state_config, frag_count);
}
memset(context->active, 0, sizeof(context->active));
context->page = 0;
context->selected = 0;
memset(context->seeds, 0, sizeof(context->seeds));
for (i = 0; i < frag_count; i++) {
@@ -285,7 +290,8 @@ void forge_run(Parameters params) {
program = shaders_init(
fragment_shaders, config, context, inputs, params.video_in_count,
state_config.select_page_count * state_config.select_item_count, NULL);
state_config.select_page_count * state_config.select_item_count,
state_config.src_count, NULL);
} else {
window_output = NULL;
}
@@ -300,7 +306,7 @@ void forge_run(Parameters params) {
program = shaders_init(
fragment_shaders, config, context, inputs, params.video_in_count,
state_config.select_page_count * state_config.select_item_count,
window_output != NULL ? &program : NULL);
state_config.src_count, window_output != NULL ? &program : NULL);
} else {
window_monitor = NULL;
}
+25 -4
View File
@@ -260,6 +260,12 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
program->idemo_locations[i] = glGetUniformLocation(
program->programs[i],
config_file_get_str(config, "UNIFORM_DEMO", "iDemo"));
program->ipage_locations[i] = glGetUniformLocation(
program->programs[i],
config_file_get_str(config, "UNIFORM_PAGE", "iPage"));
program->iselected_locations[i] = glGetUniformLocation(
program->programs[i],
config_file_get_str(config, "UNIFORM_SELECTED", "iSelected"));
prefix = config_file_get_str(config, "UNIFORM_IN_RESOLUTION_PREFIX",
"iInputResolution");
@@ -310,6 +316,13 @@ static void init_single_program(ShaderProgram *program, unsigned int i,
}
}
prefix = config_file_get_str(config, "UNIFORM_ACTIVE_PREFIX", "active");
for (j = 0; j < program->active_count; j++) {
sprintf(name, "%s%d", prefix, j + 1);
program->iactive_locations[i * program->active_count + j] =
glGetUniformLocation(program->programs[i], name);
}
// create texX uniforms pointer
prefix = config_file_get_str(config, "UNIFORM_TEX_PREFIX", "tex");
for (j = 0; j < program->tex_count; j++) {
@@ -337,7 +350,7 @@ ShaderProgram shaders_init(File *fragment_shaders, ConfigFile config,
SharedContext *context, VideoCapture *inputs,
unsigned int input_count,
unsigned int sub_variant_count,
ShaderProgram *previous) {
unsigned int active_count, ShaderProgram *previous) {
ShaderProgram program;
if (previous == NULL) {
@@ -351,8 +364,9 @@ ShaderProgram shaders_init(File *fragment_shaders, ConfigFile config,
program.frag_monitor_index =
config_file_get_int(config, "FRAG_MONITOR", 1) - 1;
program.sub_type_count = config_file_get_int(config, "SUB_TYPE_COUNT", 0);
program.sub_variant_count = sub_variant_count;
program.in_count = config_file_get_int(config, "IN_COUNT", 0);
program.sub_variant_count = sub_variant_count;
program.active_count = active_count;
if (program.frag_count > MAX_FRAG) {
log_error("FRAG_COUNT over %d", MAX_FRAG);
@@ -378,8 +392,8 @@ ShaderProgram shaders_init(File *fragment_shaders, ConfigFile config,
init_vertices(&program);
log_debug("Error after init: %04x",
glGetError()); // TODO check error at each step
// log_debug("Error after init: %04x",
// glGetError()); // TODO check error at each step
} else {
program = *previous;
}
@@ -476,9 +490,16 @@ static void use_program(ShaderProgram program, int i, bool output,
write_uniform_1f(program.itempo_locations[i], context->tempo);
write_uniform_1i(program.ifps_locations[i], context->fps);
write_uniform_1i(program.idemo_locations[i], context->demo ? 1 : 0);
write_uniform_1i(program.ipage_locations[i], context->page);
write_uniform_1i(program.iselected_locations[i], context->page);
write_uniform_2f(program.ires_locations[i], &resolution);
write_uniform_2f(program.itexres_locations[i], &tex_resolution);
for (j = 0; j < program.active_count; j++) {
write_uniform_1i(program.iactive_locations[i * program.active_count + j],
context->active[i] + 1);
}
for (j = 0; j < program.in_count; j++) {
in_resolution[0] = context->input_widths[j];
in_resolution[1] = context->input_heights[j];
+1 -1
View File
@@ -7,7 +7,7 @@ ShaderProgram shaders_init(File *fragment_shaders, ConfigFile config,
SharedContext *context, VideoCapture *inputs,
unsigned int input_count,
unsigned int sub_variant_count,
ShaderProgram *previous);
unsigned int active_count, ShaderProgram *previous);
void shaders_update(ShaderProgram program, File *fragment_shaders,
unsigned int i);
+8 -10
View File
@@ -14,16 +14,6 @@
#ifndef TYPES_H
#define TYPES_H
typedef struct SharedUint {
int fd;
unsigned int value;
} SharedUint;
typedef struct SharedBool {
int fd;
bool value;
} SharedBool;
typedef struct Parameters {
bool hot_reload;
bool output;
@@ -86,6 +76,9 @@ typedef struct ShaderProgram {
GLuint idemo_locations[ARRAY_SIZE];
GLuint iseed_locations[ARRAY_SIZE];
GLuint istate_locations[ARRAY_SIZE];
GLuint ipage_locations[ARRAY_SIZE];
GLuint iselected_locations[ARRAY_SIZE];
GLuint iactive_locations[ARRAY_SIZE];
GLuint vpos_locations[ARRAY_SIZE];
@@ -95,6 +88,8 @@ typedef struct ShaderProgram {
unsigned int sub_variant_count;
GLuint sub_locations[ARRAY_SIZE];
unsigned int active_count;
unsigned int in_count;
EGLDisplay egl_display;
} ShaderProgram;
@@ -126,6 +121,9 @@ typedef struct SharedContext {
unsigned int fps;
float tempo;
unsigned int state[MAX_FRAG];
unsigned int page;
unsigned int selected;
unsigned int active[ARRAY_SIZE];
bool demo;
unsigned int seeds[MAX_FRAG];
bool monitor;