[Mesa-dev] [PATCH] spirv: Handle doubles when multiplying a mat by a scalar

Jason Ekstrand jason at jlekstrand.net
Tue Mar 13 18:13:41 UTC 2018


Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>

On Tue, Mar 13, 2018 at 9:16 AM, Neil Roberts <nroberts at igalia.com> wrote:

> The code to handle mat multipication by a scalar tries to pick either
> imul or fmul depending on whether the matrix is float or integer.
> However it was doing this by checking whether the base type is float.
> This was making it choose the int path for doubles (and presumably
> float16s).
>
> ---
>
> This was discovered from running the arb_gpu_shader_fp64 tests through
> the GL_ARB_gl_spirv branch. For example:
> arb_gpu_shader_fp64 at execution@built-in-functions at vs-op-div-dmat4-double.
> Note however these tests are hidden behind a glslang bug:
>
> https://github.com/KhronosGroup/glslang/issues/1278
>
> The fix in that issue along with this patch makes them all pass.
>
> There’s also a little test case for this with VkRunner here:
>
> https://github.com/Igalia/vkrunner/blob/tests/examples/
> dmat-mul-scalar.shader_test
>
>  src/compiler/spirv/vtn_alu.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/compiler/spirv/vtn_alu.c b/src/compiler/spirv/vtn_alu.c
> index d0c9e316935..110fcec2a60 100644
> --- a/src/compiler/spirv/vtn_alu.c
> +++ b/src/compiler/spirv/vtn_alu.c
> @@ -142,10 +142,10 @@ mat_times_scalar(struct vtn_builder *b,
>  {
>     struct vtn_ssa_value *dest = vtn_create_ssa_value(b, mat->type);
>     for (unsigned i = 0; i < glsl_get_matrix_columns(mat->type); i++) {
> -      if (glsl_get_base_type(mat->type) == GLSL_TYPE_FLOAT)
> -         dest->elems[i]->def = nir_fmul(&b->nb, mat->elems[i]->def,
> scalar);
> -      else
> +      if (glsl_base_type_is_integer(glsl_get_base_type(mat->type)))
>           dest->elems[i]->def = nir_imul(&b->nb, mat->elems[i]->def,
> scalar);
> +      else
> +         dest->elems[i]->def = nir_fmul(&b->nb, mat->elems[i]->def,
> scalar);
>     }
>
>     return dest;
> --
> 2.14.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180313/bbf68a81/attachment-0001.html>


More information about the mesa-dev mailing list