From 7f2ee55aacaf1aae80d276ef9b7a0b12cc1c71f1 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Sun, 27 Nov 2016 10:31:01 +1100 Subject: mesa: fix active subroutine uniforms properly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 07fe2d565b introduced a big hack in order to return NumSubroutineUniforms when querying ACTIVE_RESOURCES for _SUBROUTINE_UNIFORM interfaces. However this is the wrong fix we are meant to be returning the number of active resources i.e. the count of subroutine uniforms in the resource list which is what the code was previously doing, anything else will cause trouble when trying to retrieve the resource properties based on the ACTIVE_RESOURCES count. The real problem is that NumSubroutineUniforms was counting array elements as separate uniforms but the innermost array is always considered a single uniform so we fix that count instead which was counted incorrectly in 7fa0250f9. Idealy we could probably completely remove NumSubroutineUniforms and just compute its value when needed from the resource list but this works for now. Reviewed-by: Alejandro Piñeiro Reviewed-by: Tapani Pälli Cc: 13.0 (cherry picked from commit 0303201dfb73c16751d5519cca7480fa678d429a) [Emil Velikov: LinkStatus is in gl_shader_program] Signed-off-by: Emil Velikov Conflicts: src/mesa/main/program_resource.c --- src/compiler/glsl/link_uniforms.cpp | 2 ++ src/compiler/glsl/linker.cpp | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src/compiler') diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp index b3c3c5a..8529b74 100644 --- a/src/compiler/glsl/link_uniforms.cpp +++ b/src/compiler/glsl/link_uniforms.cpp @@ -633,6 +633,8 @@ private: uniform->opaque[shader_type].index = this->next_subroutine; uniform->opaque[shader_type].active = true; + prog->_LinkedShaders[shader_type]->NumSubroutineUniforms++; + /* Increment the subroutine index by 1 for non-arrays and by the * number of array elements for arrays. */ diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp index f62a848..b71c51e 100644 --- a/src/compiler/glsl/linker.cpp +++ b/src/compiler/glsl/linker.cpp @@ -3118,7 +3118,6 @@ link_calculate_subroutine_compat(struct gl_shader_program *prog) if (!uni) continue; - sh->NumSubroutineUniforms++; count = 0; if (sh->NumSubroutineFunctions == 0) { linker_error(prog, "subroutine uniform %s defined but no valid functions found\n", uni->type->name); -- cgit v1.1 From 41c688a6c31ac5b985a3318e082f78103f061977 Mon Sep 17 00:00:00 2001 From: Haixia Shi Date: Thu, 8 Dec 2016 17:41:02 -0800 Subject: compiler/glsl: fix precision problem of tanh Clamp input scalar value to range [-10, +10] to avoid precision problems when the absolute value of input is too large. Fixes dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.* test failures. v2: added more explanation in the comment. v3: fixed a typo in the comment. Signed-off-by: Haixia Shi Reviewed-by: Jason Ekstrand Reviewed-by: Kenneth Graunke Cc: "13.0" (cherry picked from commit d4983390a869c3051929858a8b783be53d46b722) --- src/compiler/glsl/builtin_functions.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp index 3e4bcbb..3dead1a 100644 --- a/src/compiler/glsl/builtin_functions.cpp +++ b/src/compiler/glsl/builtin_functions.cpp @@ -3563,9 +3563,17 @@ builtin_builder::_tanh(const glsl_type *type) ir_variable *x = in_var(type, "x"); MAKE_SIG(type, v130, 1, x); + /* Clamp x to [-10, +10] to avoid precision problems. + * When x > 10, e^(-x) is so small relative to e^x that it gets flushed to + * zero in the computation e^x + e^(-x). The same happens in the other + * direction when x < -10. + */ + ir_variable *t = body.make_temp(type, "tmp"); + body.emit(assign(t, min2(max2(x, imm(-10.0f)), imm(10.0f)))); + /* (e^x - e^(-x)) / (e^x + e^(-x)) */ - body.emit(ret(div(sub(exp(x), exp(neg(x))), - add(exp(x), exp(neg(x)))))); + body.emit(ret(div(sub(exp(t), exp(neg(t))), + add(exp(t), exp(neg(t)))))); return sig; } -- cgit v1.1 From fb9f0a1197e10f9b1c727b5b2956f36827308ad1 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Fri, 9 Dec 2016 09:34:50 -0800 Subject: spirv: Use a simpler and more correct implementaiton of tanh() The new implementation is more correct because it clamps the incoming value to 10 to avoid floating-point overflow. It also uses a much reduced version of the formula which only requires 1 exp() rather than 2. This fixes all of the dEQP-VK.glsl.builtin.precision.tanh.* tests. Reviewed-by: Kenneth Graunke Cc: "13.0" (cherry picked from commit da1c49171d0df185545cfbbd600e287f7c6160fa) --- src/compiler/spirv/vtn_glsl450.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/spirv/vtn_glsl450.c b/src/compiler/spirv/vtn_glsl450.c index cb0570d..fbc7ce6 100644 --- a/src/compiler/spirv/vtn_glsl450.c +++ b/src/compiler/spirv/vtn_glsl450.c @@ -565,16 +565,21 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint, build_exp(nb, nir_fneg(nb, src[0])))); return; - case GLSLstd450Tanh: - /* (0.5 * (e^x - e^(-x))) / (0.5 * (e^x + e^(-x))) */ - val->ssa->def = - nir_fdiv(nb, nir_fmul(nb, nir_imm_float(nb, 0.5f), - nir_fsub(nb, build_exp(nb, src[0]), - build_exp(nb, nir_fneg(nb, src[0])))), - nir_fmul(nb, nir_imm_float(nb, 0.5f), - nir_fadd(nb, build_exp(nb, src[0]), - build_exp(nb, nir_fneg(nb, src[0]))))); + case GLSLstd450Tanh: { + /* tanh(x) := (0.5 * (e^x - e^(-x))) / (0.5 * (e^x + e^(-x))) + * + * With a little algebra this reduces to (e^2x - 1) / (e^2x + 1) + * + * We clamp x to (-inf, +10] to avoid precision problems. When x > 10, + * e^2x is so much larger than 1.0 that 1.0 gets flushed to zero in the + * computation e^2x +/- 1 so it can be ignored. + */ + nir_ssa_def *x = nir_fmin(nb, src[0], nir_imm_float(nb, 10)); + nir_ssa_def *exp2x = build_exp(nb, nir_fmul(nb, x, nir_imm_float(nb, 2))); + val->ssa->def = nir_fdiv(nb, nir_fsub(nb, exp2x, nir_imm_float(nb, 1)), + nir_fadd(nb, exp2x, nir_imm_float(nb, 1))); return; + } case GLSLstd450Asinh: val->ssa->def = nir_fmul(nb, nir_fsign(nb, src[0]), -- cgit v1.1 From c682fdb77c1499fa424b943be1d242a499677144 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Thu, 15 Dec 2016 16:51:13 +1100 Subject: Revert "nir: Turn imov/fmov of undef into undef." This reverts commit 6aa730000fea84a14b49828a4bb30761d43903bf. This was changing the size of the undef to always be 1 (the number of inputs to imov and fmov) which is wrong, we could be moving a vec4 for example. Acked-by: Kenneth Graunke Cc: "13.0" (cherry picked from commit a5502a721fd30fde4f5dc71421494329052f805b) --- src/compiler/nir/nir_opt_undef.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/nir/nir_opt_undef.c b/src/compiler/nir/nir_opt_undef.c index 0f8ba31..c4777a8 100644 --- a/src/compiler/nir/nir_opt_undef.c +++ b/src/compiler/nir/nir_opt_undef.c @@ -79,9 +79,7 @@ opt_undef_vecN(nir_builder *b, nir_alu_instr *alu) { if (alu->op != nir_op_vec2 && alu->op != nir_op_vec3 && - alu->op != nir_op_vec4 && - alu->op != nir_op_fmov && - alu->op != nir_op_imov) + alu->op != nir_op_vec4) return false; assert(alu->dest.dest.is_ssa); -- cgit v1.1 From 241dc4634f47113243ddc6d02d4d73fc6f4e98e9 Mon Sep 17 00:00:00 2001 From: Rhys Kidd Date: Wed, 26 Oct 2016 00:13:24 -0400 Subject: glsl: Add pthread libs to cache_test Fixes the following compile error, present when the SHA1 library is libgcrypt: CCLD glsl/tests/cache-test glsl/.libs/libglsl.a(libmesautil_la-mesa-sha1.o): In function `call_once': /mesa/src/util/../../include/c11/threads_posix.h:96: undefined reference to `pthread_once' Signed-off-by: Rhys Kidd Reviewed-by: Timothy Arceri (cherry picked from commit 5c73ecaac487eba36e15f22be2e9396c4a0ffe46) --- src/compiler/Makefile.glsl.am | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/compiler') diff --git a/src/compiler/Makefile.glsl.am b/src/compiler/Makefile.glsl.am index 80dfb73..15bea6b 100644 --- a/src/compiler/Makefile.glsl.am +++ b/src/compiler/Makefile.glsl.am @@ -62,8 +62,11 @@ glsl_tests_blob_test_LDADD = \ glsl_tests_cache_test_SOURCES = \ glsl/tests/cache_test.c +glsl_tests_cache_test_CFLAGS = \ + $(PTHREAD_CFLAGS) glsl_tests_cache_test_LDADD = \ - glsl/libglsl.la + glsl/libglsl.la \ + $(PTHREAD_LIBS) glsl_tests_general_ir_test_SOURCES = \ glsl/tests/builtin_variable_test.cpp \ -- cgit v1.1