refactor: specify number of video input buffers
Clang Lint CI / lint-no-video (push) Successful in 1m5s
Clang Build CI / run-no-video (push) Successful in 1m5s
Clang Build CI / run-video (push) Successful in 1m5s
Clang Build CI / build-release (push) Successful in 2m24s
Clang Lint CI / lint-video (push) Successful in 2m22s
Clang Lint CI / lint-no-video (push) Successful in 1m5s
Clang Build CI / run-no-video (push) Successful in 1m5s
Clang Build CI / run-video (push) Successful in 1m5s
Clang Build CI / build-release (push) Successful in 2m24s
Clang Lint CI / lint-video (push) Successful in 2m22s
This commit is contained in:
+77
-53
@@ -191,18 +191,20 @@ static void rebind_textures(const ShaderProgram *program) {
|
||||
#ifdef VIDEO_IN
|
||||
static bool link_input_to_texture(ShaderProgram *program, VideoCapture *input,
|
||||
unsigned int input_index,
|
||||
unsigned int texture_index, bool swap,
|
||||
bool reload) {
|
||||
unsigned int sub_index, bool reload) {
|
||||
unsigned int texture_index =
|
||||
program->tex_count + input_index * program->sub_video_count + sub_index;
|
||||
|
||||
if (reload) {
|
||||
glDeleteTextures(1, program->textures + texture_index);
|
||||
if (check_glerror(program, "link_input_to_texture/glDeleteTextures")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
glGenTextures(1, program->textures + texture_index);
|
||||
if (check_glerror(program, "link_input_to_texture/glGenTextures")) {
|
||||
return false;
|
||||
}
|
||||
glGenTextures(1, program->textures + texture_index);
|
||||
if (check_glerror(program, "link_input_to_texture/glGenTextures")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EGLImageKHR dma_image;
|
||||
@@ -217,7 +219,7 @@ static bool link_input_to_texture(ShaderProgram *program, VideoCapture *input,
|
||||
EGL_LINUX_DRM_FOURCC_EXT,
|
||||
input->pixelformat,
|
||||
EGL_DMA_BUF_PLANE0_FD_EXT,
|
||||
swap ? input->exp_fd_swap : input->exp_fd,
|
||||
input->exp_fd[sub_index],
|
||||
EGL_DMA_BUF_PLANE0_OFFSET_EXT,
|
||||
0,
|
||||
EGL_DMA_BUF_PLANE0_PITCH_EXT,
|
||||
@@ -230,11 +232,8 @@ static bool link_input_to_texture(ShaderProgram *program, VideoCapture *input,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (swap) {
|
||||
program->dma_images_swap[input_index] = dma_image;
|
||||
} else {
|
||||
program->dma_images[input_index] = dma_image;
|
||||
}
|
||||
program->dma_images[input_index * program->sub_video_count + sub_index] =
|
||||
dma_image;
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + texture_index);
|
||||
if (check_glerror(program, "link_input_to_texture/glActiveTexture")) {
|
||||
@@ -259,33 +258,35 @@ static bool link_input_to_texture(ShaderProgram *program, VideoCapture *input,
|
||||
return false;
|
||||
}
|
||||
|
||||
log_info("Texture %d linked to %s", texture_index, input->name);
|
||||
log_info("Texture %d linked to %s[%d]", texture_index, input->name,
|
||||
sub_index);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool init_input(ShaderProgram *program, const ConfigFile *config,
|
||||
VideoCaptureArray *inputs, unsigned int i, bool reload) {
|
||||
VideoCaptureArray *inputs, unsigned int input_index,
|
||||
bool reload) {
|
||||
unsigned int tex_i;
|
||||
unsigned int sub_index;
|
||||
char name[STR_LEN];
|
||||
|
||||
if (i < inputs->length && !inputs->values[i].error) {
|
||||
snprintf(name, STR_LEN, "IN_%d_OUT", i + 1);
|
||||
if (input_index < inputs->length && input_index < program->in_count &&
|
||||
!inputs->values[input_index].error) {
|
||||
snprintf(name, STR_LEN, "IN_%d_OUT", input_index + 1);
|
||||
tex_i = config_file_get_int(config, name, 0);
|
||||
if (!link_input_to_texture(program, &inputs->values[i], i, tex_i, false,
|
||||
reload)) {
|
||||
return false;
|
||||
}
|
||||
if (inputs->values[i].with_swap) {
|
||||
snprintf(name, STR_LEN, "IN_%d_SWAP_OUT", i + 1);
|
||||
tex_i = config_file_get_int(config, name, 0);
|
||||
if (!link_input_to_texture(program, &inputs->values[i], i, tex_i, true,
|
||||
reload)) {
|
||||
for (sub_index = 0; sub_index < inputs->values[input_index].buf_count;
|
||||
sub_index++) {
|
||||
if (!link_input_to_texture(program, &inputs->values[input_index],
|
||||
input_index, sub_index, reload)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
program->input_tex_map[input_index] = tex_i;
|
||||
program->tex_map[tex_i] =
|
||||
program->tex_count + input_index * program->sub_video_count;
|
||||
} else {
|
||||
log_warn("Cannot link input %d", i + 1);
|
||||
log_warn("Cannot link input %d", input_index + 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -535,13 +536,6 @@ static bool init_single_program(ShaderProgram *program, unsigned int i,
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
}
|
||||
|
||||
prefix = config_file_get_str(config, "UNIFORM_IN_SWAP_PREFIX", "iInputSwap");
|
||||
for (unsigned int j = 0; j < program->in_count; j++) {
|
||||
snprintf(name, STR_LEN, "%s%d", prefix, j + 1);
|
||||
program->iinswap_locations[i * program->in_count + j] =
|
||||
glGetUniformLocation(program->programs[i], name);
|
||||
}
|
||||
|
||||
prefix = config_file_get_str(config, "UNIFORM_SEED_PREFIX", "iSeed");
|
||||
for (unsigned int j = 0; j < program->frag_count; j++) {
|
||||
snprintf(name, STR_LEN, "%s%d", prefix, j + 1);
|
||||
@@ -650,8 +644,7 @@ static void update_viewport(ShaderProgram *program, const Context *context) {
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, context->tex_resolution[0],
|
||||
context->tex_resolution[1], 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
|
||||
check_glerror_ro(
|
||||
"update_viewport/glTexImage2D"); // TODO dont remap input textures
|
||||
check_glerror_ro("update_viewport/glTexImage2D");
|
||||
}
|
||||
program->last_resolution[0] = context->resolution[0];
|
||||
program->last_resolution[1] = context->resolution[1];
|
||||
@@ -736,8 +729,6 @@ static void use_program(const ShaderProgram *program, int i, bool output,
|
||||
context->input_formats[j]);
|
||||
write_uniform_1i(program->iinfps_locations[i * program->in_count + j],
|
||||
context->input_fps[j]);
|
||||
write_uniform_1i(program->iinswap_locations[i * program->in_count + j],
|
||||
context->input_swap[j] ? 1 : 0);
|
||||
}
|
||||
|
||||
#endif /* VIDEO_IN */
|
||||
@@ -781,10 +772,9 @@ static void use_program(const ShaderProgram *program, int i, bool output,
|
||||
}
|
||||
|
||||
// set GL_TEXTURE(X) to uniform sampler2D texX
|
||||
// TODO perform input swap here
|
||||
for (unsigned int j = 0; j < program->tex_count; j++) {
|
||||
write_uniform_1i(program->textures_locations[i * program->tex_count + j],
|
||||
j);
|
||||
program->tex_map[j]);
|
||||
}
|
||||
|
||||
// draw output
|
||||
@@ -793,11 +783,16 @@ static void use_program(const ShaderProgram *program, int i, bool output,
|
||||
|
||||
void shaders_init(ShaderProgram *program, const Project *project,
|
||||
const Context *context, bool rebind) {
|
||||
unsigned int i;
|
||||
if (!rebind) {
|
||||
program->error = false;
|
||||
program->last_resolution[0] = context->resolution[0];
|
||||
program->last_resolution[1] = context->resolution[1];
|
||||
program->tex_count = config_file_get_int(&project->config, "TEX_COUNT", 9);
|
||||
memset(program->tex_map, 0, sizeof(program->tex_map));
|
||||
for (i = 0; i < program->tex_count; i++) {
|
||||
program->tex_map[i] = i;
|
||||
}
|
||||
program->frag_count = project->frag_count;
|
||||
program->frag_output_index =
|
||||
config_file_get_int(&project->config, "FRAG_OUTPUT", 1) - 1;
|
||||
@@ -812,7 +807,7 @@ void shaders_init(ShaderProgram *program, const Project *project,
|
||||
|
||||
#ifdef VIDEO_IN
|
||||
memset(program->dma_images, 0, sizeof(program->dma_images));
|
||||
memset(program->dma_images_swap, 0, sizeof(program->dma_images_swap));
|
||||
memset(program->input_tex_map, 0, sizeof(program->input_tex_map));
|
||||
#endif /* VIDEO_IN */
|
||||
|
||||
if (!init_gl(program)) {
|
||||
@@ -848,31 +843,50 @@ void shaders_init(ShaderProgram *program, const Project *project,
|
||||
#ifdef VIDEO_IN
|
||||
|
||||
void shaders_relink_input(ShaderProgram *program, const Project *project,
|
||||
VideoCaptureArray *inputs, unsigned int i) {
|
||||
// shaders_free_input(program, i);
|
||||
init_input(program, &project->config, inputs, i, true);
|
||||
VideoCaptureArray *inputs, unsigned int input_index) {
|
||||
shaders_free_input(program, input_index);
|
||||
init_input(program, &project->config, inputs, input_index, true);
|
||||
}
|
||||
|
||||
void shaders_link_inputs(ShaderProgram *program, const Project *project,
|
||||
VideoCaptureArray *inputs) {
|
||||
for (unsigned int i = 0; i < program->in_count; i++) {
|
||||
VideoCaptureArray *inputs, unsigned int buffer_count) {
|
||||
unsigned int i;
|
||||
program->sub_video_count = buffer_count;
|
||||
for (i = 0; i < program->in_count; i++) {
|
||||
init_input(program, &project->config, inputs, i, false);
|
||||
}
|
||||
}
|
||||
|
||||
void shaders_free_input(ShaderProgram *program, unsigned int input_index) {
|
||||
if (program->dma_images[input_index] != EGL_NO_IMAGE_KHR) {
|
||||
eglDestroyImageKHR(program->egl_display, program->dma_images[input_index]);
|
||||
program->dma_images[input_index] = EGL_NO_IMAGE_KHR;
|
||||
}
|
||||
if (program->dma_images_swap[input_index] != EGL_NO_IMAGE_KHR) {
|
||||
eglDestroyImageKHR(program->egl_display,
|
||||
program->dma_images_swap[input_index]);
|
||||
program->dma_images_swap[input_index] = EGL_NO_IMAGE_KHR;
|
||||
unsigned int sub_index;
|
||||
for (sub_index = 0; sub_index < program->sub_video_count; sub_index++) {
|
||||
if (program->dma_images[input_index * program->sub_video_count +
|
||||
sub_index] != EGL_NO_IMAGE_KHR) {
|
||||
eglDestroyImageKHR(
|
||||
program->egl_display,
|
||||
program
|
||||
->dma_images[input_index * program->sub_video_count + sub_index]);
|
||||
program->dma_images[input_index * program->sub_video_count + sub_index] =
|
||||
EGL_NO_IMAGE_KHR;
|
||||
}
|
||||
}
|
||||
check_eglerror_ro("shaders_free_input/eglDestroyImageKHR");
|
||||
}
|
||||
|
||||
static void update_inputs_tex_map(ShaderProgram *program,
|
||||
const Context *context) {
|
||||
unsigned int i;
|
||||
unsigned int tex_i;
|
||||
for (i = 0; i < program->in_count; i++) {
|
||||
if (context->input_formats[i] != 0) {
|
||||
tex_i = program->input_tex_map[i];
|
||||
program->tex_map[tex_i] = program->tex_count +
|
||||
i * program->sub_video_count +
|
||||
context->input_index[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* VIDEO_IN */
|
||||
|
||||
void shaders_update(ShaderProgram *program, const File *fragment_shader,
|
||||
@@ -887,6 +901,10 @@ void shaders_update(ShaderProgram *program, const File *fragment_shader,
|
||||
|
||||
void shaders_compute(ShaderProgram *program, const Context *context,
|
||||
bool monitor, bool output_only) {
|
||||
#ifdef VIDEO_IN
|
||||
update_inputs_tex_map(program, context);
|
||||
#endif /* VIDEO_IN */
|
||||
|
||||
if (!output_only) {
|
||||
glBindVertexArray(program->vertex_array[0]);
|
||||
|
||||
@@ -923,6 +941,12 @@ void shaders_free(const ShaderProgram *program) {
|
||||
glDeleteTextures(program->tex_count, program->textures);
|
||||
check_glerror_ro("shaders_free/glDeleteTextures");
|
||||
|
||||
#ifdef VIDEO_IN
|
||||
glDeleteTextures(program->in_count * program->sub_video_count,
|
||||
program->textures + program->tex_count);
|
||||
check_glerror_ro("shaders_free/glDeleteTextures");
|
||||
#endif
|
||||
|
||||
glDeleteBuffers(1, &program->vertex_buffer);
|
||||
check_glerror_ro("shaders_free/glDeleteBuffers");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user