SPIR-V and GCC

2015-03-04 Thread BogDan
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] https://www.khronos.org/registry/spir-v/


Re: SPIR-V and GCC

2015-03-04 Thread BogDan
On Wednesday, March 4, 2015 5:22 PM, David Malcolm  wrote:
On Wed, 2015-03-04 at 14:36 +, 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] https://www.khronos.org/registry/spir-v/

I work on gcc, but in a former life I was a game developer [1], so this
piqued my interest :)



WOW you've work on AVP!



A few questions:

(A) Does SPIR-V have an assembler? The URL you posted talks about it
being a binary format, but the example in there shows a "disassembled"
textual form. The reason I ask is that the internals of gcc's backend
expect to be writing out "assembler", which then goes through an
assembler program to produce a binary. In theory I guess one could have
the "assembler" format generated by the backend be binary, but it's
likely to be *much* easier to hack on if there's an intermediate textual
form.



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 http://www.g-truc.net/post-0714.html great article explans better
what SPIR-V is.



(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!



(C) (probably most important) Is a SPIR-V backend something you'd be
up for working on? Any other volunteers out there?
(Maybe a GSoC thing?)



Personally, I never touched gcc source code before, and I don't have 
any idea about (any) compilers internals (thought I have experience 
working for free software projects [0]). Anyway I think it will be a 
great experience to (at least try to :) ) help in my spare time.
A GSOC project is a great idea as well!



Thanks,
BogDan


P.S. Sorry for the inline reply, I had to use yahoo mail and ...

[0] 
http://blog.qt.io/blog/2012/11/08/necessitas-android-port-contributed-to-the-qt-project


Re: SPIR-V and GCC

2015-03-06 Thread BogDan
[...]
> This http://www.g-truc.net/post-0714.html great article explans better
> what SPIR-V is.


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:
https://gcc.gnu.org/onlinedocs/jit/intro/tutorial05.html

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.

That use-case is probably doable today using gcc 5 (and could be written
in C, C++, Python, or D, with the bindings we already have).
Potentially such a library could also generate other kinds of code,
including e.g. optimized SPIR-V... but that requires both (i) a gcc
backend for the desired target code and (ii) libgccjit to support
cross-compilation (which as I mentioned would probably be a gcc 6
thing).
[...]


Yep, that's another use-case, which might be used by free drives (Intel, AMD, 
Lima, etc.).


[...]
I'm probably not the best person to help, as I've not written a gcc
backend (the jit counts as a frontend, albeit a very unusual one).  FWIW
there seems to be a good tutorial on writing backends here:
http://www.cse.iitb.ac.in/grc/intdocs/gcc-writing-md.html
[...]

Thanks a lot for the link, it helped me a lot (I found this [0] one quite good).

I checked them a little bit and I'm afraid it might be a a few problems to 
create a SPIR-V backend:

1. SPIR-V a binary Intermediate Language format but it's still not machine 
code. It seems gcc backends produces a text machine code, so I think will not 
be possible to produce SPIR-V a binary format directly from GCC backend.

2. Because SPIR-V is not a machine format, it doesn't have any registers. 
Instead it's using IDs for everything [1]. I didn't find a way to create IDs 
instead of registers in GCC.

3. SPIR-V supports some "non-standard" types[2], will it be a problems to 
support these types in GCC frontend/backend?

Cheers,
BogDan.

[0] https://gcc.gnu.org/onlinedocs/gccint/Back-End.html#Back-End
[1] https://www.khronos.org/registry/spir-v/specs/1.0/SPIRV.html#_instructions
[2] https://www.khronos.org/registry/spir-v/specs/1.0/SPIRV.html#_types


CPP documentation minor typo

2018-02-20 Thread Bogdan Harjoc
__VA_OPT__ was documented after 7.3.0 and the eprintf example for it
ends with two backslashes instead of one:

https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html

Regards,
Bogdan