Re: [igt-dev] [PATCH i-g-t 1/2] shaders: Add assembler instructions and update README for shaders

Petri Latvala
2018-10-03T11:02:59Z

On Wed, Oct 03, 2018 at 07:47:22AM +0200, Katarzyna Dec wrote:
> We're not planning to work on assembler in igt anymore, since we can
> reuse an existing project (IGA) that will do this work for us. The
> only extra thing we need to do is convert the result binary to C-array,
> simple python script.
>
> v2: Moved converter to single file. Fixed README for shaders.
> v3: Fixed typos.
>
> Signed-off-by: Katarzyna Dec <katarzyna.dec@intel.com>
> Cc: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
> Cc: Petri Latvala <petri.latvala@intel.com>
> Cc: Kalamarz Lukasz <lukasz.kalamarz@intel.com>
> Cc: Antonio Argenziano <antonio.argenziano@intel.com>
> ---
> shaders/README | 19 +++++++++++++++++++
> shaders/converter.py | 24 ++++++++++++++++++++++++
> shaders/gpgpu/README | 10 ++++++++++
> shaders/gpgpu/gpgpu_fill_gen8.asm | 10 ++++++++++
> shaders/gpgpu/gpgpu_fill_gen9.asm | 10 ++++++++++
> shaders/media/README | 8 ++++++++
> shaders/media/media_fill_gen8.asm | 11 +++++++++++
> shaders/ps/README | 8 ++++++++
> shaders/ps/blit_gen8.asm | 7 +++++++
> shaders/ps/neg1_gen8.asm | 9 +++++++++
> 10 files changed, 116 insertions(+)
> create mode 100644 shaders/README
> create mode 100644 shaders/converter.py
> create mode 100644 shaders/gpgpu/gpgpu_fill_gen8.asm
> create mode 100644 shaders/gpgpu/gpgpu_fill_gen9.asm
> create mode 100644 shaders/media/media_fill_gen8.asm
> create mode 100644 shaders/ps/blit_gen8.asm
> create mode 100644 shaders/ps/neg1_gen8.asm
>
> diff --git a/shaders/README b/shaders/README
> new file mode 100644
> index 00000000..7ac125b5
> --- /dev/null
> +++ b/shaders/README
> @@ -0,0 +1,19 @@
> +This directory is for shaders used in media_fill, gpgpu_fill, rendercopy
> +and media_spin libraries.
> +
> +Till Gen8 shaders were generated using intel-gen4asm script (implementation in
> +assembler/ directory). From Gen8 it is possible to use Intel Graphics Assembler
> +to generate binary from asm instructions.
> +https://github.com/intel/intel-graphics-compiler
> + 1. Clone IGC project
> + 2. Go to igc/visa/iga
> + 3. Build iga
> + cmake . && make
> +
> +For maintaining compatibility with our tests there is a bin to hex converter
> +written in python:
> + $>converter.py input_file > output_file
> +e.g.$>python converter.py gen9_iga_output > gen9_hex_array
> +
> +Instructions how to build media, gpgpu or ps shaders are included in their
> +subdirectories.
> diff --git a/shaders/converter.py b/shaders/converter.py
> new file mode 100644
> index 00000000..d00e6193
> --- /dev/null
> +++ b/shaders/converter.py
> @@ -0,0 +1,24 @@
> +#!/usr/bin/env python2

Python 2 in 2018? Why?

--
Petri Latvala

> +import struct
> +import sys
> +import argparse
> +
> +parser = argparse.ArgumentParser(description='Script for converting shaders in binary to hex.')
> +args = parser.parse_args()
> +
> +print "static const uint32_t kernel[][4] = {"
> +
> +with open(sys.argv[1], 'r') as f:
> + fmt = '<LLLL'
> + step = struct.calcsize(fmt)
> + while True:
> + buf = f.read(step)
> + if not buf:
> + break
> + elif len(buf) < step:
> + buf += '\x00' * (step - len(buf))
> +
> + val = struct.unpack('<LLLL', buf)
> + print "\t{{ 0x{:08x}, 0x{:08x}, 0x{:08x}, 0x{:08x} }},".format(*val)
> +
> +print "};"
> diff --git a/shaders/gpgpu/README b/shaders/gpgpu/README
> index 3bf328ad..9d254e2a 100644
> --- a/shaders/gpgpu/README
> +++ b/shaders/gpgpu/README
> @@ -1,4 +1,14 @@
> +These files are here for reference only.
>
> Commands used to generate the shader on gen7
> $> m4 gpgpu_fill.gxa > gpgpu_fill.gxm
> $> intel-gen4asm -g 7 -o gpgpu_fill.gxm
> +
> +From gen8 we can use Intel Graphics Assember to generate binary from asm
> +instructions
> +https://github.com/intel/intel-graphics-compiler/tree/master/visa/iga
> +
> +How to get binary from .asm (e.g. when ISA instructions has changed):
> + $> iga64 gpgpu_fill.asm -p=8 -a -o gpgpu_fill_gen8.bin
> + $> Use converter from shaders/README to have hex array used in libs
> + $> Copy output to proper lib
> diff --git a/shaders/gpgpu/gpgpu_fill_gen8.asm b/shaders/gpgpu/gpgpu_fill_gen8.asm
> new file mode 100644
> index 00000000..448e0256
> --- /dev/null
> +++ b/shaders/gpgpu/gpgpu_fill_gen8.asm
> @@ -0,0 +1,10 @@
> + mov (4|M0) r1.0<1>:ub r1.0<0;1,0>:ub
> + mul (1|M0) r2.0<1>:ud r0.1<0;1,0>:ud 0x10:ud
> + mov (1|M0) r2.1<1>:ud r0.6<0;1,0>:ud
> + mov (8|M0) r4.0<1>:ud r0.0<8;8,1>:ud
> + mov (2|M0) r4.0<1>:ud r2.0<2;2,1>:ud
> + mov (1|M0) r4.2<1>:ud 0xF:ud
> + mov (16|M0) (eq)f0.0 r5.0<1>:ud r1.0<0;1,0>:ud
> + send (16|M0) acc0.0:uw r4:d 0xC 0x060A8000 // DP_DC1 wr:3h, rd:0, fc: 0x28000
> + mov (8|M0) r112.0<1>:ud r0.0<8;8,1>:ud
> + send (16|M0) null:uw r112:d 0x27 0x02000010 {EOT} // SPAWNER wr:1, rd:0, fc: 0x10
> diff --git a/shaders/gpgpu/gpgpu_fill_gen9.asm b/shaders/gpgpu/gpgpu_fill_gen9.asm
> new file mode 100644
> index 00000000..6f948935
> --- /dev/null
> +++ b/shaders/gpgpu/gpgpu_fill_gen9.asm
> @@ -0,0 +1,10 @@
> + mov (4|M0) r1.0<1>:ub r1.0<0;1,0>:ub
> + mul (1|M0) r2.0<1>:ud r0.1<0;1,0>:ud 0x10:ud
> + mov (1|M0) r2.1<1>:ud r0.6<0;1,0>:ud
> + mov (8|M0) r4.0<1>:ud r0.0<8;8,1>:ud
> + mov (2|M0) r4.0<1>:ud r2.0<2;2,1>:ud
> + mov (1|M0) r4.2<1>:ud 0xF:ud
> + mov (16|M0) r5.0<1>:ud r1.0<0;1,0>:ud
> + send (16|M0) acc0.0:uw r4:d 0xC 0x060A8000 // DP_DC1 wr:3h, rd:0, fc: 0x28000
> + mov (8|M0) r112.0<1>:ud r0.0<8;8,1>:ud
> + send (16|M0) null:uw r112:d 0x27 0x02000010 {EOT} // SPAWNER wr:1, rd:0, fc: 0x10
> diff --git a/shaders/media/README b/shaders/media/README
> index 9f296010..44c08dce 100644
> --- a/shaders/media/README
> +++ b/shaders/media/README
> @@ -3,3 +3,11 @@ These files are here for reference only.
> Commands used to generate the shader on gen8
> $> m4 media_fill.gxa > media_fill.gxm
> $> intel-gen4asm -g 8 -o media_fill.gxm
> +
> +From gen8 we can use Intel Graphics Assember to generate binary from asm
> +instructions https://github.com/intel/intel-graphics-compiler/tree/master/visa/iga
> +
> +How to get binary from .asm (e.g. when ISA instructions has changed):
> + $> iga64 media_fill_gen8.asm -p=8 -a -o media_fill_gen8.bin
> + $> Use converter from shaders/README to have hex array used in libs
> + $> Copy output to proper lib
> diff --git a/shaders/media/media_fill_gen8.asm b/shaders/media/media_fill_gen8.asm
> new file mode 100644
> index 00000000..4b6eb84b
> --- /dev/null
> +++ b/shaders/media/media_fill_gen8.asm
> @@ -0,0 +1,11 @@
> + mov (4|M0) r1.0<1>:ub r1.0<0;1,0>:ub
> + mov (8|M0) r4.0<1>:ud r0.0<8;8,1>:ud
> + mov (2|M0) r4.0<1>:ud r2.0<2;2,1>:ud
> + mov (1|M0) r4.2<1>:ud 0xF000F:ud
> + mov (16|M0) r5.0<1>:ud r1.0<0;1,0>:ud
> + mov (16|M0) r7.0<1>:ud r1.0<0;1,0>:ud
> + mov (16|M0) r9.0<1>:ud r1.0<0;1,0>:ud
> + mov (16|M0) r11.0<1>:ud r1.0<0;1,0>:ud
> + send (16|M0) acc0.0:uw r4:d 0x1000000C 0x120A8000 // DP_DC1 wr:9h, rd:0, fc: 0x28000
> + mov (8|M0) r112.0<1>:ud r0.0<8;8,1>:ud
> + send (16|M0) null:uw r112:d 0x10000027 0x02000010 {EOT} // SPAWNER wr:1, rd:0, fc: 0x10
> diff --git a/shaders/ps/README b/shaders/ps/README
> index b196d025..21ff571a 100644
> --- a/shaders/ps/README
> +++ b/shaders/ps/README
> @@ -1 +1,9 @@
> These files are here for reference only.
> +
> +From gen8 we can use Intel Graphics Assember to generate binary from asm
> +instructions https://github.com/intel/intel-graphics-compiler/tree/master/visa/iga
> +
> +How to get binary from .asm?
> + $> iga64 blit_gen8.asm -p=8 -a -o blit_gen8.bin
> + $> Use converter from shaders/README to have hex array used in libs
> + $> Copy output to proper lib
> diff --git a/shaders/ps/blit_gen8.asm b/shaders/ps/blit_gen8.asm
> new file mode 100644
> index 00000000..c35b70a1
> --- /dev/null
> +++ b/shaders/ps/blit_gen8.asm
> @@ -0,0 +1,7 @@
> + pln (8|M0) r10.0<1>:f r6.0<0;1,0>:f r2.0<8;8,1>:f
> + pln (8|M0) r11.0<1>:f r6.0<0;1,0>:f r4.0<8;8,1>:f
> + pln (8|M0) r12.0<1>:f r6.4<0;1,0>:f r2.0<8;8,1>:f
> + pln (8|M0) 13.0<1>:f r6.4<0;1,0>:f r4.0<8;8,1>:f
> + send (16|M0) r112:f r10:ub 0x10000002 0x08840001 // SAMPLER wr:4, rd:8, fc: 0x40001
> + send (16|M0) null:f r112:ub 0x10000025 0x10031000 {EOT} // DP_RC wr:8, rd:0, Render Target Write msc:16, to #0
> +
> diff --git a/shaders/ps/neg1_gen8.asm b/shaders/ps/neg1_gen8.asm
> new file mode 100644
> index 00000000..582375b5
> --- /dev/null
> +++ b/shaders/ps/neg1_gen8.asm
> @@ -0,0 +1,9 @@
> +mov(8) r112:ud 0x3f800000:ud
> +mov(8) r113:ud 0x3f800000:ud
> +mov(8) r114:ud 0x3f800000:ud
> +mov(8) r115:ud 0x3f800000:ud
> +mov(8) r116:ud 0x3f800000:ud
> +mov(8) r117:ud 0x3f800000:ud
> +mov(8) r118:ud 0x3f800000:ud
> +mov(8) r119:ud 0x3f800000:ud
> +send(16) null r112 0x25 0x10031000 { EOT }
> --
> 2.17.1
>