Specification doesn't define behaviour for rotation of 0-vector. In https://github.com/KhronosGroup/OpenGL-API/issues/41 said that behaviour is undefined and agreed that it would be fine for implementation to do something useful for this. Windows and Nvidia drivers have a workaround for that. For compatibility proposed optimized version of computations. Specification defines a formula of rotation (see "OpenGL 4.6 (Compatibility Profile) - May 14, 2018", paragraph "12.1.1 Matrices").
Optimized formula will look so: R = cos(angle) * I That is equavalent to logic that magnitude of (0,0,0)-vector is 1.0. -v2: logic moved to _math_matrix_rotate -v3: general optimization of computations -v4: added compatible_0vector_rotation option CC: Tapani Pälli <tapani.pa...@intel.com> CC: Timothy Arceri <tarc...@itsqueeze.com> CC: Brian Paul <bri...@vmware.com> Signed-off-by: Sergii Romantsov <sergii.romant...@globallogic.com> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100960 Spec: https://github.com/KhronosGroup/OpenGL-API/issues/41 --- src/mesa/drivers/dri/i915/intel_screen.c | 1 + src/mesa/drivers/dri/i965/brw_context.c | 3 +++ src/mesa/drivers/dri/i965/intel_screen.c | 1 + src/mesa/main/matrix.c | 3 ++- src/mesa/main/mtypes.h | 5 +++++ src/mesa/math/m_matrix.c | 14 +++++++++++++- src/mesa/math/m_matrix.h | 2 +- src/util/xmlpool/t_options.h | 5 +++++ 8 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/mesa/drivers/dri/i915/intel_screen.c b/src/mesa/drivers/dri/i915/intel_screen.c index 50934c1..49a1c5f 100644 --- a/src/mesa/drivers/dri/i915/intel_screen.c +++ b/src/mesa/drivers/dri/i915/intel_screen.c @@ -71,6 +71,7 @@ DRI_CONF_BEGIN DRI_CONF_FORCE_GLSL_EXTENSIONS_WARN("false") DRI_CONF_DISABLE_GLSL_LINE_CONTINUATIONS("false") DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED("false") + DRI_CONF_COMPATIBLE_0VECTOR_ROTATION("false") DRI_CONF_OPT_BEGIN_B(stub_occlusion_query, "false") DRI_CONF_DESC(en, "Enable stub ARB_occlusion_query support on 915/945.") diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c index 6ba64e4..ca50364 100644 --- a/src/mesa/drivers/dri/i965/brw_context.c +++ b/src/mesa/drivers/dri/i965/brw_context.c @@ -890,6 +890,9 @@ brw_process_driconf_options(struct brw_context *brw) ctx->Const.AllowGLSLCrossStageInterpolationMismatch = driQueryOptionb(options, "allow_glsl_cross_stage_interpolation_mismatch"); + ctx->Const.Compatible0VectorRotation = + driQueryOptionb(options, "compatible_0vector_rotation"); + ctx->Const.dri_config_options_sha1 = ralloc_array(brw, unsigned char, 20); driComputeOptionsSha1(&brw->screen->optionCache, ctx->Const.dri_config_options_sha1); diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c index c57fb54..67938b6 100644 --- a/src/mesa/drivers/dri/i965/intel_screen.c +++ b/src/mesa/drivers/dri/i965/intel_screen.c @@ -87,6 +87,7 @@ DRI_CONF_BEGIN DRI_CONF_ALLOW_GLSL_CROSS_STAGE_INTERPOLATION_MISMATCH("false") DRI_CONF_ALLOW_HIGHER_COMPAT_VERSION("false") DRI_CONF_FORCE_GLSL_ABS_SQRT("false") + DRI_CONF_COMPATIBLE_0VECTOR_ROTATION("false") DRI_CONF_OPT_BEGIN_B(shader_precompile, "true") DRI_CONF_DESC(en, "Perform code generation at shader link time.") diff --git a/src/mesa/main/matrix.c b/src/mesa/main/matrix.c index 8065a83..28537a5 100644 --- a/src/mesa/main/matrix.c +++ b/src/mesa/main/matrix.c @@ -415,7 +415,8 @@ _mesa_Rotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ) FLUSH_VERTICES(ctx, 0); if (angle != 0.0F) { - _math_matrix_rotate( ctx->CurrentStack->Top, angle, x, y, z); + _math_matrix_rotate( ctx->CurrentStack->Top, angle, x, y, z, + ctx->Const.Compatible0VectorRotation ); ctx->NewState |= ctx->CurrentStack->DirtyFlag; } } diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 9ed49b7..e9cbcf1 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -3789,6 +3789,11 @@ struct gl_constants GLboolean AllowLayoutQualifiersOnFunctionParameters; /** + * Allow compatible to Windows and Nvidia logic of 0-vector rotation. + */ + GLboolean Compatible0VectorRotation; + + /** * Force computing the absolute value for sqrt() and inversesqrt() to follow * D3D9 when apps rely on this behaviour. */ diff --git a/src/mesa/math/m_matrix.c b/src/mesa/math/m_matrix.c index 57a4953..8ff7b11 100644 --- a/src/mesa/math/m_matrix.c +++ b/src/mesa/math/m_matrix.c @@ -794,7 +794,7 @@ static GLboolean matrix_invert( GLmatrix *mat ) */ void _math_matrix_rotate( GLmatrix *mat, - GLfloat angle, GLfloat x, GLfloat y, GLfloat z ) + GLfloat angle, GLfloat x, GLfloat y, GLfloat z, GLboolean process_zeros ) { GLfloat xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c, s, c; GLfloat m[16]; @@ -824,6 +824,18 @@ _math_matrix_rotate( GLmatrix *mat, M(1,0) = s; } } + else if (process_zeros) { + /* https://bugs.freedesktop.org/show_bug.cgi?id=100960 + * https://github.com/KhronosGroup/OpenGL-API/issues/41 + * Here we will treat magnitude as 1.0 if it really 0.0. + * So that is kind of workaround for empty-vectors to have + * compatibility with Windows and Nvidia drivers. + */ + optimized = GL_TRUE; + M(0,0) = c; + M(1,1) = c; + M(2,2) = c; + } } else if (z == 0.0F) { optimized = GL_TRUE; diff --git a/src/mesa/math/m_matrix.h b/src/mesa/math/m_matrix.h index c34d9e3..44459a6 100644 --- a/src/mesa/math/m_matrix.h +++ b/src/mesa/math/m_matrix.h @@ -104,7 +104,7 @@ _math_matrix_translate( GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z ); extern void _math_matrix_rotate( GLmatrix *m, GLfloat angle, - GLfloat x, GLfloat y, GLfloat z ); + GLfloat x, GLfloat y, GLfloat z, GLboolean process_zeros ); extern void _math_matrix_scale( GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z ); diff --git a/src/util/xmlpool/t_options.h b/src/util/xmlpool/t_options.h index e0a30f5..3bc5495 100644 --- a/src/util/xmlpool/t_options.h +++ b/src/util/xmlpool/t_options.h @@ -145,6 +145,11 @@ DRI_CONF_OPT_BEGIN_B(force_compat_profile, def) \ DRI_CONF_DESC(en,gettext("Force an OpenGL compatibility context")) \ DRI_CONF_OPT_END +#define DRI_CONF_COMPATIBLE_0VECTOR_ROTATION(def) \ +DRI_CONF_OPT_BEGIN_B(compatible_0vector_rotation, def) \ + DRI_CONF_DESC(en,gettext("Allow compatible to Windows and Nvidia logic of 0-vector rotation")) \ +DRI_CONF_OPT_END + /** * \brief Image quality-related options */ -- 2.7.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev