Commit Graph

52334 Commits

Author SHA1 Message Date
Benjamin Otte
6fa6e9964c gskslexpression: Parse (sub)expressions in parenthesis
Well, that was easy.
2017-10-30 02:58:02 +01:00
Benjamin Otte
c22b36d2b5 gskslfunction: Parse arguments 2017-10-30 02:58:02 +01:00
Benjamin Otte
fad4112d78 gsksl: Introduce gsk_sl_preprocessor_sync()
Instead of just returning after an error an continuing to parse
wherever, use gsk_sl_preprocessor_sync() to find the next point in the
token stream that looks like a useful way to continue parsing.
2017-10-30 02:58:02 +01:00
Benjamin Otte
c30089a1cb gskslfunction: Properly type-check calls to struct constructors 2017-10-30 02:58:02 +01:00
Benjamin Otte
4450d83cb9 gsksltype: Generate better type names
If multiple consecutive struct names share their types, use comma
notation to goup them.
2017-10-30 02:58:02 +01:00
Benjamin Otte
500e6bc2bc gsksl: Add support for parsing members of struct variables
This includes adding the concept of members to GskSlType.
2017-10-30 02:58:02 +01:00
Benjamin Otte
8d6a332482 gsksl: Add support for structs 2017-10-30 02:58:02 +01:00
Benjamin Otte
4d5cf80003 gskslexpression: Implment function calls 2017-10-30 02:58:02 +01:00
Benjamin Otte
458a9e3e44 gskslscope: Track function calls 2017-10-30 02:58:02 +01:00
Benjamin Otte
1d87210572 gskslnode: Always return a statement
Same thing as with expresssions: On parsing errors, return something,
anything really.
2017-10-30 02:58:02 +01:00
Benjamin Otte
2a7f343714 gsksl: Make expression parsing never fail
Code will always return a valid expression - for an invlaid token
stream, that might be a very random expression, but still, it's an
expression.
2017-10-30 02:58:02 +01:00
Benjamin Otte
a2aaf2b90e gskslpreprocessor: Return fatalness of parsing
Instead of relying on parsing functions to return FALSE on error, we
record that parsing failed inside the preprocessor object and continue
parsing (potentially using dummy objects as the result).

That way, we keep parsing and can emit potentially useful error messages
for the rest of the document.

Now we just need to implement that mentality.
2017-10-30 02:58:02 +01:00
Benjamin Otte
2bceaedd37 gsksl: Add an error enum
And specify the correct error value whenever an error is emitted.
2017-10-30 02:58:02 +01:00
Benjamin Otte
46c9a3aaaa gskslpreprocessor: Redo error emission
Instead of an error function, we now have a macro that calls
gsk_sl_preprocessor_emit_error().
2017-10-30 02:58:02 +01:00
Benjamin Otte
13dd620828 gskslexpression: Parse swizzles 2017-10-30 02:58:02 +01:00
Benjamin Otte
c8f234971b gsksltype: Add gsk_sl_type_get_index_stride()
This allows operations on GskSlValues that are arrays, because one can
just do code like:
  data = gsk_sl_value_get_data (value);
  stride = gsk_sl_value_get_index_stride (type);
  for (i = 0; i < gsk_sl_value_get_length (type); i++)
    {
      do_stuff_with_data (data + i * stride);
    }
2017-10-30 02:58:02 +01:00
Benjamin Otte
0e284138e3 gskslexpression: References to const variables are const
So we return a const value if that happens.
2017-10-30 02:58:02 +01:00
Benjamin Otte
7e4d163f11 gskslprogram: Allow variables to have constant initializers
Technically, all intiializers should be allowed, but for now we're happy
we can do const ones.

Also store them properly in the SPIR-V output.
2017-10-30 02:58:02 +01:00
Benjamin Otte
850c6d1116 gskslvariable: Allow storing an initializer value with a variable
This code requires the addition of gsk_sl_value_new_convert() so
constants can be converted to the right type.
2017-10-30 02:58:02 +01:00
Benjamin Otte
ea45570850 gsksldeclaration: Throw an error if a variable initializer doesn't match
... the type of the declared variable and cannot be converted to it.
2017-10-30 02:58:02 +01:00
Benjamin Otte
3fc253c57d gskslvariable: Store constness of variables 2017-10-30 02:58:02 +01:00
Benjamin Otte
545ce13981 gskslexpression: Change is_constant() to get_constant()
Actually use this to evaluate layout () expressions.

Unfortunately get_constant() is not implemented in many places, so it
doesn't do much more than the int constant parsing.
2017-10-30 02:58:02 +01:00
Benjamin Otte
c2672540d9 gsksl: Parse common layout() specifiers
In particular: binding, set, location and component.
2017-10-30 02:58:02 +01:00
Benjamin Otte
a7fce5603a gsksl: Redo declaration "decorator" parsing
Instead of parsing into a list of flags, have an array of values that
can be set to certain values. This way, we can reuse it for layout()
contents.
2017-10-30 02:58:02 +01:00
Benjamin Otte
cf40318d9b gsksl: Introduce GskSlValue
This is - analog to a GValue - a type plus the memory of a value in that
type.

So far it is only used to represent constant expressions.
2017-10-30 02:58:02 +01:00
Benjamin Otte
4395675c58 gskslprogram: Parse global variables
We don't parse initializations yet, but whatever.
2017-10-30 02:58:02 +01:00
Benjamin Otte
b522801c5a gskslfunction: Change name printing to name getting
Since gsk_sl_type_get_name() exists now, we can have a name getter also
for builtin constructors.
2017-10-30 02:58:02 +01:00
Benjamin Otte
eb12740151 gsksl: Turn functions into functions
Don't use a GskSlNode subclass to handle declared functions but make
them a GskSlFunction subclass.
2017-10-30 02:58:02 +01:00
Benjamin Otte
7e8604372d gsksl: Split Expression from Node 2017-10-30 02:58:02 +01:00
Benjamin Otte
4deaddeb70 gsksl: Add GskSlVariable
A variable is the abstraction used for declarations of variables.

I chose the name Variable over Declaration because it's the result of
the SPIRV instruction OpVariable.
2017-10-30 02:58:02 +01:00
Benjamin Otte
935402e0aa gskslpreprocessor: Implement #define and #undef 2017-10-30 02:58:02 +01:00
Benjamin Otte
67b60b54ac gskslcompiler: Add support for adding defines
gtk-glsl implements this via the usual -D and -U options.

Preprocessor directives aren't implemented yet, but defines are replaced
in the source code already.
2017-10-30 02:58:02 +01:00
Benjamin Otte
f8299719b4 gsksl: Introduce GskSlCompiler
This is the object that is used to create programs from. It also holds
(or will hold) all the settings necessary to parse GLSL - like defines
or include directories.
2017-10-30 02:58:02 +01:00
Benjamin Otte
eee9142397 gsksl: Split out GskSlProgram
And turn it into public API.
2017-10-30 02:58:02 +01:00
Benjamin Otte
d3511003cf gsksltokenizer: Always return idents
Turning idents into keywords is the job of the preprocessor and has to
be done after processing #defines.
2017-10-30 02:58:02 +01:00
Benjamin Otte
9417507829 gsksl: Implement skeleton SPIRV output 2017-10-30 02:58:02 +01:00
Benjamin Otte
45ad50a61c gsk: Add GskSlPointerType
This describes a type with qualifiers like const, volatile and so on.
2017-10-30 02:58:02 +01:00
Benjamin Otte
447f52502a gtk: Add gtk-glsl binary
That's supposed to become the command-line compiler.

So far all it does is parse and then dump as text again the provided
input file(s).
2017-10-30 02:58:02 +01:00
Benjamin Otte
c7590f310f gskslnode: Parse return statements 2017-10-30 02:58:02 +01:00
Benjamin Otte
f607087201 gskslnode: Add builtin constructors
Do this by implementing function call nodes and adding GskSlFunction,
which is meant to be used for anything that is callable.
2017-10-30 02:58:02 +01:00
Benjamin Otte
36a61f0ad0 gskslnode: Add comparison and shift operators 2017-10-30 02:58:02 +01:00
Benjamin Otte
b6adb44dfd gsksltype: Add matrix type 2017-10-30 02:58:02 +01:00
Benjamin Otte
0e56c28725 gsksltype: Add support for vector types 2017-10-30 02:58:02 +01:00
Benjamin Otte
0362778524 gskslnode: Add GskSlNodeOperation
This is for operations in expressions, like and, or, shift, addition or
multiplication.

These operations need to do sophisticated type checks that can't be done
yet, so only the logical operations are implemented so far.
2017-10-30 02:58:02 +01:00
Benjamin Otte
ad4b45639b gskslnode: Add variables
This requires keeping a scope object that we can use to store and load
variables.
2017-10-30 02:58:02 +01:00
Benjamin Otte
dc519ad2a2 gskslnode: Add gsk_sl_node_is_constant()
And use it to emit a compile error when trying to assign to a constant
value.
2017-10-30 02:58:02 +01:00
Benjamin Otte
7a215a6b39 gskslnode: Add gsk_sl_node_get_return_type()
It's unused for now.

But the idea is that (most) nodes return a value and we can know the
type of value they return at compile-time. And then we can check type
compatibility while parsing using this function.
2017-10-30 02:58:02 +01:00
Benjamin Otte
da5417def4 gsksl: Add gsksltypesprivate.h
All those types are recursively needing each other in their functions,
so add a generic header for all those types and only include that
header.
2017-10-30 02:58:02 +01:00
Benjamin Otte
4e0def2806 gsksl: Parse assignments 2017-10-30 02:58:02 +01:00
Benjamin Otte
bc5c3e1b56 gsksl: Start parsing statements by parsing constants 2017-10-30 02:58:02 +01:00