From 35efc9e3149028e6c65dceb46f60490448dcbd9f Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 2 Jul 2017 11:30:39 +0200 Subject: [PATCH] Optimize away some glGetUniformLocation calls. --- chroma_subsampler.cpp | 37 ++++++++++++++++++++++++------------- chroma_subsampler.h | 3 +++ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/chroma_subsampler.cpp b/chroma_subsampler.cpp index cf46883..0b21413 100644 --- a/chroma_subsampler.cpp +++ b/chroma_subsampler.cpp @@ -102,6 +102,10 @@ ChromaSubsampler::ChromaSubsampler(ResourcePool *resource_pool) "} \n"; cbcr_program_num = resource_pool->compile_glsl_program(cbcr_vert_shader, cbcr_frag_shader, frag_shader_outputs); check_error(); + cbcr_chroma_offset_0_location = get_uniform_location(cbcr_program_num, "foo", "chroma_offset_0"); + check_error(); + cbcr_chroma_offset_1_location = get_uniform_location(cbcr_program_num, "foo", "chroma_offset_1"); + check_error(); cbcr_texture_sampler_uniform = glGetUniformLocation(cbcr_program_num, "cbcr_tex"); check_error(); @@ -153,6 +157,14 @@ ChromaSubsampler::ChromaSubsampler(ResourcePool *resource_pool) uyvy_program_num = resource_pool->compile_glsl_program(uyvy_vert_shader, uyvy_frag_shader, frag_shader_outputs); check_error(); + uyvy_luma_offset_0_location = get_uniform_location(uyvy_program_num, "foo", "luma_offset_0"); + check_error(); + uyvy_luma_offset_1_location = get_uniform_location(uyvy_program_num, "foo", "luma_offset_1"); + check_error(); + uyvy_chroma_offset_0_location = get_uniform_location(uyvy_program_num, "foo", "chroma_offset_0"); + check_error(); + uyvy_chroma_offset_1_location = get_uniform_location(uyvy_program_num, "foo", "chroma_offset_1"); + check_error(); uyvy_y_texture_sampler_uniform = glGetUniformLocation(uyvy_program_num, "y_tex"); check_error(); @@ -293,11 +305,10 @@ void ChromaSubsampler::subsample_chroma(GLuint cbcr_tex, unsigned width, unsigne glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); check_error(); - float chroma_offset_0[] = { -1.0f / width, 0.0f }; - float chroma_offset_1[] = { -0.0f / width, 0.0f }; - set_uniform_vec2(cbcr_program_num, "foo", "chroma_offset_0", chroma_offset_0); - set_uniform_vec2(cbcr_program_num, "foo", "chroma_offset_1", chroma_offset_1); - + glUniform2f(cbcr_chroma_offset_0_location, -1.0f / width, 0.0f); + check_error(); + glUniform2f(cbcr_chroma_offset_1_location, -0.0f / width, 0.0f); + check_error(); glUniform1i(cbcr_texture_sampler_uniform, 0); glBindBuffer(GL_ARRAY_BUFFER, vbo); @@ -372,14 +383,14 @@ void ChromaSubsampler::create_uyvy(GLuint y_tex, GLuint cbcr_tex, unsigned width glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); check_error(); - float y_offset_0[] = { -0.5f / width, 0.0f }; - float y_offset_1[] = { 0.5f / width, 0.0f }; - float cbcr_offset0[] = { -1.0f / width, 0.0f }; - float cbcr_offset1[] = { -0.0f / width, 0.0f }; - set_uniform_vec2(uyvy_program_num, "foo", "luma_offset_0", y_offset_0); - set_uniform_vec2(uyvy_program_num, "foo", "luma_offset_1", y_offset_1); - set_uniform_vec2(uyvy_program_num, "foo", "chroma_offset_0", cbcr_offset0); - set_uniform_vec2(uyvy_program_num, "foo", "chroma_offset_1", cbcr_offset1); + glUniform2f(uyvy_luma_offset_0_location, -0.5f / width, 0.0f); + check_error(); + glUniform2f(uyvy_luma_offset_1_location, 0.5f / width, 0.0f); + check_error(); + glUniform2f(uyvy_chroma_offset_0_location, -1.0f / width, 0.0f); + check_error(); + glUniform2f(uyvy_chroma_offset_1_location, -0.0f / width, 0.0f); + check_error(); glBindBuffer(GL_ARRAY_BUFFER, vbo); check_error(); diff --git a/chroma_subsampler.h b/chroma_subsampler.h index d4c1c1e..6466285 100644 --- a/chroma_subsampler.h +++ b/chroma_subsampler.h @@ -43,10 +43,13 @@ private: GLuint cbcr_program_num; // Owned by . GLuint cbcr_texture_sampler_uniform; GLuint cbcr_position_attribute_index, cbcr_texcoord_attribute_index; + GLuint cbcr_chroma_offset_0_location, cbcr_chroma_offset_1_location; GLuint uyvy_program_num; // Owned by . GLuint uyvy_y_texture_sampler_uniform, uyvy_cbcr_texture_sampler_uniform; GLuint uyvy_position_attribute_index, uyvy_texcoord_attribute_index; + GLuint uyvy_luma_offset_0_location, uyvy_luma_offset_1_location; + GLuint uyvy_chroma_offset_0_location, uyvy_chroma_offset_1_location; GLuint v210_program_num; // Compute shader, so owned by ourselves. Can be 0. GLuint v210_in_y_pos, v210_in_cbcr_pos, v210_outbuf_pos; -- 2.39.2