Commit Graph

52361 Commits

Author SHA1 Message Date
Benjamin Otte
a50d932150 gskslvalue: Add gsk_sl_value_to_string ()
Very useful to have in gdb.
2017-10-30 02:58:02 +01:00
Benjamin Otte
6af46a0659 gsksltype: Add concept of components
A type has components, if it is essentially an array of tighly packed
scalar values. In this case, a GskSlValue's data is essentially
  ScalarType data[n_components];
2017-10-30 02:58:02 +01:00
Benjamin Otte
c624bae54c gskslpreprocessor: Support parsing #version
This required a lot of reorganization because we have to track if we're
at the start of the document.

On the plus side, we now parse the #version tag and if it's correctly
used, we emit a warning that we don't support it.

Aren't we awesome?
2017-10-30 02:58:02 +01:00
Benjamin Otte
c5a1eaf1a1 gskslpreprocessor: Implement #include 2017-10-30 02:58:02 +01:00
Benjamin Otte
35476639c4 gskslcompiler: Provide a way to compile files
And use it from gtk-glsl.

A neat side effect is that we now get the actual file printed in error
messages.
2017-10-30 02:58:02 +01:00
Benjamin Otte
e48be683c7 gsk: Add GskCodeSource
This is basically the source format we use to represent source code.

It can be created either from a file or from a GBytes, so we can use it
to hold all data that can be provided by user input (#defines) or by
actual files.
2017-10-30 02:58:02 +01:00
Benjamin Otte
a07924c0d6 gsksltokenizer: Parse strings
And when we encounter any strings in the preprocessor, we promptly emit
an error and skip them. But we do that after the preprocessor runs, so
we can access strings inside the preprocessor.
2017-10-30 02:58:02 +01:00
Benjamin Otte
4927e229b3 gskslqualifier: Implement layout(push_constant) 2017-10-30 02:58:02 +01:00
Benjamin Otte
deb3d26ff6 gsksl: Add support for parsing blocks 2017-10-30 02:58:02 +01:00
Benjamin Otte
60add60236 gskslqualifier: Handle uniform variables 2017-10-30 02:58:02 +01:00
Benjamin Otte
19ae9c0f8e gsksl: Redo qualifier handling
This is the 3rd time at least that I've rewritten it. This time, I've
added a GskSlQualifier struct that contains all the information relevant
to qualifiers. It replaces the previous GskSlDecorationList.
2017-10-30 02:58:02 +01:00
Benjamin Otte
a3dec06d3f gskslstatement: Add gsk_sl_Stement_get_jump()
This queries where a statement jumps to after it is done. The enum is
sorted by importance, larger values jump further.

We use this to do 3 things:
1. Error out if the function body statement does not return a value from
   a non-void function.
2. Make sure to emit a Return as last instruction in a function body
3. Print a warning about dead code when statements follow a jump.
2017-10-30 02:58:02 +01:00
Benjamin Otte
196ee554b4 gsksltype: Turn void into a custom type class
Previously, void was a scalar type. It's not anymore.

On the plus side, we now got a gsk_sl_type_is_void() function that's
kinda useful in places.
2017-10-30 02:58:02 +01:00
Benjamin Otte
7b416c9dc5 gskslpreprocessor: Implement #ifdef, #else and #endif 2017-10-30 02:58:02 +01:00
Benjamin Otte
a05961d57a gskslstatement: Handle if statements 2017-10-30 02:58:02 +01:00
Benjamin Otte
7e55c4760a gskslfunction: the body of a function is a single statement
Now that we have compound statements, we can use them as the function
body.
2017-10-30 02:58:02 +01:00
Benjamin Otte
e2d6d07c2a gsksl: Don't return a value from gsk_sl_statement_write_spv()
Statements emit code, they don't return any values. That's what
expressions are for.
2017-10-30 02:58:02 +01:00
Benjamin Otte
607b4b40a0 gskslstatement: Parse compound statements 2017-10-30 02:58:02 +01:00
Benjamin Otte
622dccd438 gskslstatement: Print semicolon in the statement print function
This is necessary for compound statements which don't have a semicolon.
2017-10-30 02:58:02 +01:00
Benjamin Otte
6247fae076 gsksl: Rename GskSlNode to GskSlStatement
The generic node class from the beginning was only used by statements,
so better name it appropriately.
2017-10-30 02:58:02 +01:00
Benjamin Otte
3279b11a99 gsksl: Add native functions
This basically just adds the prototypes, actually evaluating the
functions doesn't work.
2017-10-30 02:58:02 +01:00
Benjamin Otte
6f80039428 gsksl: Add GskSlPrinter
This is a subclass for pretty-printing. It's not yet very useful, but
will become so once we nest blocks or have way too long statements to
fit on a single line.
2017-10-30 02:58:02 +01:00
Benjamin Otte
11ab6f823b gsksl: Add support for overloaded functions
This changes GskSlScope to allow multiple functions of the same name.

It also introduces GskSlFunctionMatcher, which does overload matching in
a way that can be used while parsing function calls.
2017-10-30 02:58:02 +01:00
Benjamin Otte
d3b452e303 gskslfunction: Reorganize gsk_sl_function_matches()
This is the first step towards implementing function overloading.

Instead of having the matches() vfunc the code now can query argument
type and count and uses this to implement a generic matches().

Constructors are checked seperately and manually. They also report 0
arguments.
2017-10-30 02:58:02 +01:00
Benjamin Otte
88eac26f5a gskslfunction: Split regular and builtin constructors
Their behavior is just too different.
2017-10-30 02:58:02 +01:00
Benjamin Otte
21fe62ec66 gskslexpression: Implement negation
This includes adding gsk_sl_value_componentwise() which is not something
I particularly like, but it does its job - and will be useful for the
other operations.
2017-10-30 02:58:02 +01:00
Benjamin Otte
69b4834764 gskslexpression: Change function call error handling
Allow calling the function call parsing code with a NULL function. In
that case, we will parse the arguments and then return without emitting
an error. This ensures that the parser is in a sane state and reports
useful errors even if there's a typo in a function call.
2017-10-30 02:58:02 +01:00
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