Commit Graph

52399 Commits

Author SHA1 Message Date
Benjamin Otte
fabb55524e gsksldeclaration: Type declarations aren't variables 2017-10-30 02:58:03 +01:00
Benjamin Otte
97118140be gskslprogram: Split out GskSlDeclaration
That's the object that will keep the toplevel declarations that make up
a program.
2017-10-30 02:58:03 +01:00
Benjamin Otte
1d5ac3b892 gskspv: Pass inout parameters by reference
We can't just pass the value, SPIRV expects to be able to write to the
parameter if it's not const.

This does not yet do the right thing for for out variables. They are not
copied back to the caller.
2017-10-30 02:58:03 +01:00
Benjamin Otte
9aa73600f1 gskslexpression: Add spv writing optimization
For assignable expressions, we can always use an access chain to query
the value. Access chains are not just faster, they also contain lots of
optimizations for merging swizzles and whatnot.
2017-10-30 02:58:03 +01:00
Benjamin Otte
c4299a10c0 gskspvwriter: Add optimization for access chain
A single swizzle can be reduced to an access chain lookup. This is
especially useful during assignments, because it means we don't need to
load the whole vector and OpVectorShuffle it.
2017-10-30 02:58:03 +01:00
Benjamin Otte
a0233d96e1 gskslvariable: Fold constant variables away in SPV output
This mirrors glslang behavior.
2017-10-30 02:58:03 +01:00
Benjamin Otte
6f551adf10 gskslvariable: Add a class for parameters
This simplifies the SPV writing.
2017-10-30 02:58:03 +01:00
Benjamin Otte
53bc1a1d35 gskslvariable: Make it classed
This is still in preparation for supporting multiple types of variables.
2017-10-30 02:58:03 +01:00
Benjamin Otte
1a5615ed73 gskslvariable: Add load()/store() functions
This allows transitioning variables to different types. Which in the end
makes it possible to write different load/store code for parameters,
global variables or potentially GL builtins.
2017-10-30 02:58:03 +01:00
Benjamin Otte
b63463f1a2 gsksl: Introduce GskSlFunctionType
Represents a function, its argument types and whether they are
in/out/const arguments.

For now, this is just used to not duplicate function types in SPV files.
2017-10-30 02:58:03 +01:00
Benjamin Otte
940c13c25c gskspv: Ensure function labels come before variables 2017-10-30 02:58:03 +01:00
Benjamin Otte
31db111ae5 gskspv: Add GskSpvAccessChain
And use it to implement assignments.

And because I rock, this is all assignments, including member variables
swizzles and *= assignments. So this works:
  foo.member.rgba.rgb *= vec3(0);
2017-10-30 02:58:03 +01:00
Benjamin Otte
88413ad585 gsksl: Get rid of pointer types
Store quantifier and real type in GskSlVariable instead.
Make gsk_spv_writer_get_id_for_pointer_type() take type and storage
class.
And generate writer opcodes using 2 arguments: Type and storage class.
2017-10-30 02:58:03 +01:00
Benjamin Otte
bda72e2c23 gskslexpression: Add gsk_sl_expression_is_assignable()
And use it to fail when parsing assignments.
2017-10-30 02:58:03 +01:00
Benjamin Otte
115182d6e6 gskslexpression: Convert assignment expression to GskSlBinary
This also tightens the checks we do. So the code will now properly error
out if you try to assign an int to a matrix or try to &= with a float.
2017-10-30 02:58:03 +01:00
Benjamin Otte
41a0ce4621 gskslexpression: Move GskSlExpressionOperation to binaries
All those operations are now unimplemented binary types.
2017-10-30 02:58:03 +01:00
Benjamin Otte
093e9194b9 gskslexpression: Move division to the new binary vfuncs 2017-10-30 02:58:03 +01:00
Benjamin Otte
cb975b4faa gsksl: Split binary expressions into their own header
Ad a first step, do this for multiplication.
2017-10-30 02:58:02 +01:00
Benjamin Otte
3482a7de13 gskspv: Variables can go different places
Global variables are declared in the type definition section while local
variables are part of the function body.
2017-10-30 02:58:02 +01:00
Benjamin Otte
c803f5e5e4 gskspv: Claim to support the same source extensions as glslc
Makes it easier to compare disassembler output and hurts nobody.
2017-10-30 02:58:02 +01:00
Benjamin Otte
6d9a5feb43 gskspv: Reorganize code more
Now we create IDs in the same way glslang does and we write out code in
the same order - at least for "void main() { }"
2017-10-30 02:58:02 +01:00
Benjamin Otte
17661af6da gskspvwriter: Allow writing a function with initializer
That way, we can initialize global variables.

We're also a lot closer to emitting code in the way glslc does.
2017-10-30 02:58:02 +01:00
Benjamin Otte
1455ef2c21 gskspv: emit Debug information 2017-10-30 02:58:02 +01:00
Benjamin Otte
cccca8c2f0 gskspvwriter: Put the declaration section into the block
Declarations are per-function, so treat them like that.
2017-10-30 02:58:02 +01:00
Benjamin Otte
a29a486442 gskspv: Allow writing function calls
The code is all very wonky still in the way it orders instructions
and needs some reorganization to consistently do the right thing.
2017-10-30 02:58:02 +01:00
Benjamin Otte
807b63fded gskspv: Add GskSpvCodeBlock
This represents a block of code. For now it's only used for if
statements (which are now enabled again), but in future commits
writing of function blocks will use it, too.
2017-10-30 02:58:02 +01:00
Benjamin Otte
918ff3d58e gskpsv: Completely redo SPV writing
Autogenerate the headers for SPIR-V from the JSON file provided by the
spec (and now included here).
This provides a way more readable and on top of that type-safe way to
emit bytecodes when generating code.

As a result of this, the whole bytecode emission was rewritten, so there
are probably lots of different bugs in it now.

Note: If statement SPV generation was disabled. Code generation needs
some more support for control flow before I can reenable if statements.
2017-10-30 02:58:02 +01:00
Benjamin Otte
bfdc7ad4ab gskslexpression: Implement Division
Split out arithmetic expressions and implement constant evaluation SPV
writing for division.
2017-10-30 02:58:02 +01:00
Benjamin Otte
c45e88f36a gskslfunction: Actually write arguments to SPV
This includes code in the variable path to write parameter variables out
as parameters instead of regular global/local variables.
2017-10-30 02:58:02 +01:00
Benjamin Otte
bc83778cd5 gskslstatement: Add SPV code for return statement 2017-10-30 02:58:02 +01:00
Benjamin Otte
737bb72ccc gsksltype: Add gsk_sl_type_get_matching()
Returns the matching basic type for a different scalar type, ie returns
bvec3 for boolean vec3 or dmat3x4 for double mat3x4.

If the function is called when no matching type exists, it will explode
in your face.
2017-10-30 02:58:02 +01:00
Benjamin Otte
9825d95857 gsksl: Add gsk_spv_writer_get_id_for_zero()
and gsk_spv_writer_get_id_for_one(). Those are functions that return the
id for the value 0 or 1 in the given scalar. Note that they can be used
for FALSE/TRUE.
2017-10-30 02:58:02 +01:00
Benjamin Otte
6bdf46fbcf gskslprinter: Deal with non-normal floating points
Instead of NaN, print "(0.0 / 0.0)" and instead of INF, print "(1.0 /
0.0)".

Both of that is not spec-conformant, but the best we can do if we
encounter constant expressions that evaluate to these numbers.
2017-10-30 02:58:02 +01:00
Benjamin Otte
420fb00e1e gskslexpression: Split multiplication from other binary operations
Also implement get_constant() and write_spv() vfuncs.
2017-10-30 02:58:02 +01:00
Benjamin Otte
764f6708f6 gsksl: Implement constructor writing to SPIR-V
This includes the new function gsk_spv_writer_add_conversion() which
does the daunting task of doing a conversion for all types that can
convert, so it's the equivalent to gsk_sl_value_new_convert().
2017-10-30 02:58:02 +01:00
Benjamin Otte
6e7c348654 gsksltype: Add gsk_sl_type_value_equal()
Use this in gsk_sl_value_equal().
2017-10-30 02:58:02 +01:00
Benjamin Otte
0a9f758c36 gskslfunction: Add gsk_sl_function_get_constant()
Also, call it from the function call expression.

It's completely unimplemented so far, so it's not that useful.
2017-10-30 02:58:02 +01:00
Benjamin Otte
0c567d6c28 gsksl: Builtin constructors are no longer functions
They don't obey the laws that govern constructors (argument promotion,
constant amount of predefined types of arguments and so on).
So we turn constructor calls into their own expression type.

This also dimplifies function call validation because we don't have to
do two-in-one with constructors in there.

And while doing that, also fix up the rules that govern constructor
arguments: Matrixes aren't allowed as arguments for matrixes unless
they're the first and only argument.
And if scalars are the first and only argument, they behave differently
than they would otherwise.
2017-10-30 02:58:02 +01:00
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