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
+3
View File
@@ -13,6 +13,9 @@ UNIFORM_SEED_PREFIX=seed
UNIFORM_STATE_PREFIX=state
UNIFORM_TEX_PREFIX=tex
UNIFORM_SRC_PREFIX=midi
UNIFORM_PAGE=iPage
UNIFORM_SELECTED=iSelected
UNIFORM_ACTIVE_PREFIX=active
SUB_TYPE_COUNT=2
SUB_1_PREFIX=src_
+16 -16
View File
@@ -14,6 +14,8 @@ uniform vec2 iTexResolution;
uniform vec2 iInputResolution1;
uniform vec2 iInputResolution2;
uniform int iDemo;
uniform int iPage;
uniform int iSelected;
uniform int seed1;
uniform int seed2;
@@ -28,9 +30,11 @@ uniform int state3;
uniform int state4;
uniform int state5;
uniform int state6;
uniform int state7;
uniform int state8;
uniform int active1;
uniform int active2;
// 2. textures
// ---------------
@@ -1239,10 +1243,6 @@ subroutine(src_stage_sub) vec4 src_16(vec2 vUV, int seed)
// inputs
int selected = 0; // TODO debug selected
int page = 0; // TODO debug page
int selected_src = 0; // TODO debug selected
int selected_fx = 0; // TODO debug selected
int selected_srca = state3;
int selected_srcb = state4;
int selected_fxa = state5;
@@ -1298,18 +1298,18 @@ subroutine(src_stage_sub) vec4 src_16(vec2 vUV, int seed)
f += char_at(uv2, vec2(-2.4, -2.55), hex_chars[selected_mfx]);
// show current selected
f += selected == 0 ? h_rect(uv2, vec2(-5, 2), vec2(1.2), 0.1) : 0;
f += selected == 1 ? h_rect(uv2, vec2(-5, -2), vec2(1.2), 0.1) : 0;
f += selected == 2 ? h_rect(uv2, vec2(-2, 2), vec2(1.2), 0.1) : 0;
f += selected == 3 ? h_rect(uv2, vec2(5, 0), vec2(1.2), 0.1) : 0;
f += selected == 4 ? h_rect(uv2, vec2(-2, -2), vec2(1.2), 0.1) : 0;
f += iSelected == 3 ? h_rect(uv2, vec2(-5, 2), vec2(1.2), 0.1) : 0;
f += iSelected == 4 ? h_rect(uv2, vec2(-5, -2), vec2(1.2), 0.1) : 0;
f += iSelected == 5 ? h_rect(uv2, vec2(-2, 2), vec2(1.2), 0.1) : 0;
f += iSelected == 6 ? h_rect(uv2, vec2(5, 0), vec2(1.2), 0.1) : 0;
f += iSelected == 8 ? h_rect(uv2, vec2(-2, -2), vec2(1.2), 0.1) : 0;
// show selected src/fx
f += selected_src == 0 ? h_rect(uv2, vec2(-5, 0.8), vec2(1, 0), 0.1) : 0;
f += selected_src == 1 ? h_rect(uv2, vec2(-5, -3.2), vec2(1, 0), 0.1) : 0;
f += selected_fx == 2 ? h_rect(uv2, vec2(-2, 0.8), vec2(1.2, 0), 0.1) : 0;
f += selected_fx == 3 ? h_rect(uv2, vec2(5, -1.2), vec2(1, 0), 0.1) : 0;
f += selected_fx == 4 ? h_rect(uv2, vec2(-2, -3.2), vec2(1, 0), 0.1) : 0;
f += active1 == 1 ? h_rect(uv2, vec2(-5, 0.8), vec2(1, 0), 0.1) : 0;
f += active1 == 2 ? h_rect(uv2, vec2(-5, -3.2), vec2(1, 0), 0.1) : 0;
f += active2 == 1 ? h_rect(uv2, vec2(-2, 0.8), vec2(1.2, 0), 0.1) : 0;
f += active2 == 2 ? h_rect(uv2, vec2(5, -1.2), vec2(1, 0), 0.1) : 0;
f += active2 == 3 ? h_rect(uv2, vec2(-2, -3.2), vec2(1, 0), 0.1) : 0;
// show inputs / feedback
float line_a_a = rect(uv2, vec2(-8, 2), vec2(2, 0.1));
@@ -1334,7 +1334,7 @@ subroutine(src_stage_sub) vec4 src_16(vec2 vUV, int seed)
}
// show page
f += char_at(uv2, vec2(-9.2, -4.3), hex_chars[page]);
f += char_at(uv2, vec2(-9.2, -4.3), hex_chars[iPage]);
// show fx values
f = mix(f, 1 - f, rect(uv2, vec2(-2, 1.1 + 0.9 * fxa_value), vec2(0.9, 0.9 * fxa_value)));
+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;