[Mesa-dev] [PATCH 14/22] nir: add legal bit_sizes to intrinsics

Jason Ekstrand jason at jlekstrand.net
Wed Nov 21 21:58:40 UTC 2018


On Tue, Nov 13, 2018 at 9:49 AM Karol Herbst <kherbst at redhat.com> wrote:

> With OpenCL some system values match the address bits, but in GLSL we also
> have some system values being 64 bit.
>
> With this it is possible to adjust the builder functions so that depending
> on the bit_sizes the correct bit_size is used or an additional argument is
> added in case of multiple possible values.
>
> Also this allows for further validation
>
> Signed-off-by: Karol Herbst <kherbst at redhat.com>
> ---
>  src/compiler/nir/nir.h               |  3 +++
>  src/compiler/nir/nir_intrinsics.py   | 15 ++++++++++-----
>  src/compiler/nir/nir_intrinsics_c.py |  6 +++++-
>  src/nouveau/meson.build              | 25 +++++++++++++++++++++++++
>  4 files changed, 43 insertions(+), 6 deletions(-)
>  create mode 100644 src/nouveau/meson.build
>
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index be4f64464f9..3855eb0b582 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -1283,6 +1283,9 @@ typedef struct {
>
>     /** semantic flags for calls to this intrinsic */
>     nir_intrinsic_semantic_flag flags;
> +
> +   /** bitfield of legal bit sizes */
> +   unsigned bit_sizes : 7;
>  } nir_intrinsic_info;
>
>  extern const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics];
> diff --git a/src/compiler/nir/nir_intrinsics.py
> b/src/compiler/nir/nir_intrinsics.py
> index ec3049ca06d..9ada44aad8a 100644
> --- a/src/compiler/nir/nir_intrinsics.py
> +++ b/src/compiler/nir/nir_intrinsics.py
> @@ -32,7 +32,7 @@ class Intrinsic(object):
>     NOTE: this must be kept in sync with nir_intrinsic_info.
>     """
>     def __init__(self, name, src_components, dest_components,
> -                indices, flags, sysval):
> +                indices, flags, sysval, bit_sizes):
>         """Parameters:
>
>         - name: the intrinsic name
> @@ -45,6 +45,7 @@ class Intrinsic(object):
>         - indices: list of constant indicies
>         - flags: list of semantic flags
>         - sysval: is this a system-value intrinsic
> +       - bit_sizes: allowed dest bit_sizes
>         """
>         assert isinstance(name, str)
>         assert isinstance(src_components, list)
> @@ -58,6 +59,8 @@ class Intrinsic(object):
>         if flags:
>             assert isinstance(flags[0], str)
>         assert isinstance(sysval, bool)
> +       if bit_sizes:
> +           assert isinstance(bit_sizes[0], int)
>
>         self.name = name
>         self.num_srcs = len(src_components)
> @@ -68,6 +71,7 @@ class Intrinsic(object):
>         self.indices = indices
>         self.flags = flags
>         self.sysval = sysval
> +       self.bit_sizes = bit_sizes
>
>  #
>  # Possible indices:
> @@ -120,10 +124,10 @@ CAN_REORDER   = "NIR_INTRINSIC_CAN_REORDER"
>  INTR_OPCODES = {}
>
>  def intrinsic(name, src_comp=[], dest_comp=-1, indices=[],
> -              flags=[], sysval=False):
> +              flags=[], sysval=False, bit_sizes=[]):
>      assert name not in INTR_OPCODES
>      INTR_OPCODES[name] = Intrinsic(name, src_comp, dest_comp,
> -                                   indices, flags, sysval)
> +                                   indices, flags, sysval, bit_sizes)
>
>  intrinsic("nop", flags=[CAN_ELIMINATE])
>
> @@ -446,9 +450,10 @@ intrinsic("shared_atomic_fmin",  src_comp=[1, 1],
> dest_comp=1, indices=[BASE])
>  intrinsic("shared_atomic_fmax",  src_comp=[1, 1], dest_comp=1,
> indices=[BASE])
>  intrinsic("shared_atomic_fcomp_swap", src_comp=[1, 1, 1], dest_comp=1,
> indices=[BASE])
>
> -def system_value(name, dest_comp, indices=[]):
> +def system_value(name, dest_comp, indices=[], bit_sizes=[32]):
>      intrinsic("load_" + name, [], dest_comp, indices,
> -              flags=[CAN_ELIMINATE, CAN_REORDER], sysval=True)
> +              flags=[CAN_ELIMINATE, CAN_REORDER], sysval=True,
> +              bit_sizes=bit_sizes)
>
>  system_value("frag_coord", 4)
>  system_value("front_face", 1)
> diff --git a/src/compiler/nir/nir_intrinsics_c.py
> b/src/compiler/nir/nir_intrinsics_c.py
> index ac45b94d496..d0f1c29fa39 100644
> --- a/src/compiler/nir/nir_intrinsics_c.py
> +++ b/src/compiler/nir/nir_intrinsics_c.py
> @@ -1,3 +1,5 @@
> +from functools import reduce
> +import operator
>
>  template = """\
>  /* Copyright (C) 2018 Red Hat
> @@ -45,6 +47,7 @@ const nir_intrinsic_info
> nir_intrinsic_infos[nir_num_intrinsics] = {
>      },
>  % endif
>     .flags = ${"0" if len(opcode.flags) == 0 else " |
> ".join(opcode.flags)},
> +   .bit_sizes = ${reduce(operator.or_, opcode.bit_sizes, 0)},
>

If we're going to go to all the effort to add these bit sizes to
nir_intrinsic_infos, we should make nir_validate validate them.

Also, I'm not sure this line does what you want if bit_sizes = [].  We
could choose the 0 means anything goes convention or, since it's a
bitfield, we could do 0x78 when it's allowed to be anything.  Or we could
just change the default in python to [8, 16, 32, 64].  In any case, we
should do something sensible.

--Jason


>  },
>  % endfor
>  };
> @@ -54,6 +57,7 @@ from nir_intrinsics import INTR_OPCODES
>  from mako.template import Template
>  import argparse
>  import os
> +import functools
>
>  def main():
>      parser = argparse.ArgumentParser()
> @@ -64,7 +68,7 @@ def main():
>
>      path = os.path.join(args.outdir, 'nir_intrinsics.c')
>      with open(path, 'wb') as f:
> -        f.write(Template(template,
> output_encoding='utf-8').render(INTR_OPCODES=INTR_OPCODES))
> +        f.write(Template(template,
> output_encoding='utf-8').render(INTR_OPCODES=INTR_OPCODES, reduce=reduce,
> operator=operator))
>
>  if __name__ == '__main__':
>      main()
> diff --git a/src/nouveau/meson.build b/src/nouveau/meson.build
> new file mode 100644
> index 00000000000..5c265f207ab
> --- /dev/null
> +++ b/src/nouveau/meson.build
> @@ -0,0 +1,25 @@
> +# Copyright © 2018 Red Hat Corp.
> +
> +# Permission is hereby granted, free of charge, to any person obtaining a
> copy
> +# of this software and associated documentation files (the "Software"),
> to deal
> +# in the Software without restriction, including without limitation the
> rights
> +# to use, copy, modify, merge, publish, distribute, sublicense, and/or
> sell
> +# copies of the Software, and to permit persons to whom the Software is
> +# furnished to do so, subject to the following conditions:
> +
> +# The above copyright notice and this permission notice shall be included
> in
> +# all copies or substantial portions of the Software.
> +
> +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
> OR
> +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> THE
> +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> FROM,
> +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> IN THE
> +# SOFTWARE.
> +
> +inc_nouveau = include_directories('.')
> +
> +if with_nouveau_vk
> +  subdir('vulkan')
> +endif
>

This hunk seems to be misplaced. :-)


> --
> 2.19.1
>
> _______________________________________________
> 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/20181121/e9dddd63/attachment-0001.html>


More information about the mesa-dev mailing list