This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: SPIR-V and GCC

On Wed, 2015-03-04 at 16:20 +0000, BogDan wrote:
> On Wednesday, March 4, 2015 5:22 PM, David Malcolm <> wrote:
> On Wed, 2015-03-04 at 14:36 +0000, BogDan wrote:
> > Hello folks,
> >
> >
> > Probably is a little bit too early, but I'd like to ask if there is
> > any chance to use gcc to produce SPIR-V [1].
> > It will be just great if we'll be able to write our shaders in e.g.
> > C/C++/(any language supported by gcc) and use GCC to compile them as
> > SPIR-V!
> > It will be fantastic to use only one compiler collection for CPU and
> > for GPU compute&graphics!
> >
> > Cheers,
> >
> > BogDan.
> > [1]
> I work on gcc, but in a former life I was a game developer [1], so this
> piqued my interest :)

> SPIR-V it's an Intermediate Language binary format. First versions were
> based on LLVM. SPIR-V has nothing to do with the old SPIR implementations,
> but for some reason khronos decide to keep the name :)
> This  great article explans better
> what SPIR-V is.

(nods); thanks.

> (B) Are you thinking about this for primarly ahead-of-time
> compilation, or are you interested in just-in-time compilation to
> SPIR-V? I ask since I maintain the new "libgccjit" feature in GCC 5.
> One of the current assumptions in libgccjit is that host==target, but I
> hope to relax that for gcc 6 so that libgccjit could e.g. generate code
> for a GPU. Another gcc 6 possibility could be multi-target support for
> libgccjit, so that you can populate a gcc_jit_context with code, then
> have it generate machine code for both the CPU and for the GPU (mostly
> just thinking aloud here).

> Even though most of the people will use it for ahead-of-time compilation,
> but IMHO it can be both!

Another use-case that occurred to me when I was looking at the link you
posted above: using gcc for optimizing SPIR-V and compiling it e.g. to
CPU code.

As of gcc 5, libgccjit can be hooked up to a pre-existing language
frontend, with the gcc backend emitting machine code for the CPU,
assuming that the frontend is license-compatible with libgccjit's
GPLv3-or-later.  See this example, which uses libgccjit to build a
compiler for brainf**k:

So if there's a SPIR-V loader library that's license-compatible, you
could write code to inject SPIR-V into libgccjit, and call
gcc_jit_context_compile_to_file on it to optimize it and turn it into
machine code.

Johann Sorel has written a SPIR-v binary reader and writer with a compatible license (public domain).

To quote Johann Sorel: "it's public domain, copy what you need ;)"

These SPIR-v classes is to my knowledge the first public SPIR-v reader and writer with a free software compatible license.
You can use the GCC GCJ project and Johann Sorel's Java classes that gives you all SPIR-v spec constants in machine readable form
and a SPIR-v binary parser and writer as a foundation to create your SPIR-v compiler & assembler.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]