Commit Graph

592 Commits

Author SHA1 Message Date
Benjamin Otte
d33881e0ec gsksltype: Implement arrays
This is incomplete as we can only declare variables using array types
but not as arrays of static types yet.
2017-10-30 02:58:03 +01:00
Benjamin Otte
7e9aa97fd5 gsksl: Add gsk_sl_expression_parse_integral_constant()
This is for parsing constant expressions, like array indices or layout
specifiers.
2017-10-30 02:58:03 +01:00
Benjamin Otte
38bc5f3d37 gskslbinary: Implement equal and not equal operations 2017-10-30 02:58:03 +01:00
Benjamin Otte
119f7fe74a gsksl: Comparisons aren't allowed between opaque types
For that purpose, export gsk_sl_type_contains_opaque() as it's used in
multiple places. It checks if a type or any of it's members are opaque.
2017-10-30 02:58:03 +01:00
Benjamin Otte
516cd4b499 gsksltype: Add sampler types
Also add texture() and texelFetch() functions and all variants.

textureGather() and textureQuery() functions are still missing
2017-10-30 02:58:03 +01:00
Benjamin Otte
38a255d132 gskspv: Deal with ImageOperands
ImageOperands are followed by an optional list of arguments for those
arguments.
2017-10-30 02:58:03 +01:00
Benjamin Otte
15cbfc8370 gskslqualifier: Require type to determine storage class
Opaque type uniforms have a different storage class than regular
uniforms.
2017-10-30 02:58:03 +01:00
Benjamin Otte
caaf1845c3 gsksl: Allow an optional access qualifier of -1
Use this to mark optional access qualifiers as "do not write". For now
this is a good enough way to not write out access qualifiers, which is
disallowed in GLSL shaders.
2017-10-30 02:58:03 +01:00
Benjamin Otte
031a1812b8 gskslstatement: Implement for loops 2017-10-30 02:58:03 +01:00
Benjamin Otte
d59333da9e gsksl: Don't pass matcher to function argument parser
... when an error has occured. That way we avoid duplicate error
messages for nonexisting functions.
2017-10-30 02:58:03 +01:00
Benjamin Otte
fe4d17fee1 gskspvwriter: Change get_id_for_zero/one() functions
Accept a basic GskSlType instead of a scalar. That way, we can return
0/1 for vectors and matrices, which is kinda common.
2017-10-30 02:58:03 +01:00
Benjamin Otte
6a95433046 gsksltype: Add gsk_sl_type_is_basic()
That way, code doesn't have to do if (is_vector() || is_matrix() ||
is_scalar()) everywhere.
2017-10-30 02:58:03 +01:00
Benjamin Otte
b5919bf848 gskslexpression: Parse ++ and -- increment and decrement 2017-10-30 02:58:03 +01:00
Benjamin Otte
41fd67263f gsksl: Parse interpolation qualifiers 2017-10-30 02:58:03 +01:00
Benjamin Otte
5472458e6b gsksl: Check qualifier/type combinations are valid
So far, this is only implemented for in variables.
2017-10-30 02:58:03 +01:00
Benjamin Otte
8431b63b5d gsksl: Add support for stages
The stage is just passed to everywhere it's needed. The compiler does
not keep a stage property, instead it requires passing the stage as an
argument to every compilation.

As a side effect, environment treatment has changed:
Environments now allow creating "similar" (for lack of a better term)
environments with different version/profile.
We use this to pass the stage as part of the environment.
2017-10-30 02:58:03 +01:00
Benjamin Otte
d17abee4eb gsksldeclaration: Correctly parse initializers
And store them as initializers for later.
2017-10-30 02:58:03 +01:00
Benjamin Otte
8a59adedfc testsuite: Add a simple test runner for errors
The test runner does nothing more but try to parse a given source and
check that that fails.

If it succeeds or crashes, the test fails.
2017-10-30 02:58:03 +01:00
Benjamin Otte
0b7b7a31b4 gskslvariable: Add API to query if access chain usage is possible
This is necessary so access chain creation can fail early when a
reference expression is asked to create one.
2017-10-30 02:58:03 +01:00
Benjamin Otte
4f8a422410 gsksltype: Write decorations for struct and block members 2017-10-30 02:58:03 +01:00
Benjamin Otte
f440e23bba gskslnative: Implement all native functions
Well, with the exception of modf() (out arguments, booo!) and the GL 150
functions.
2017-10-30 02:58:03 +01:00
Benjamin Otte
8d5fce4c69 gskspv: Change the way we deal with labels
Instead of having a code block abstraction, just make code deal with
label ids instead. that way, code can just use gsk_spv_writer_make_id()
and pass that ID to the label func.

This simplifies code a lot as it allows special treatment of those
labels at eg the beginning of functions which can be kept local to where
it happens.
2017-10-30 02:58:03 +01:00
Benjamin Otte
fd83132d76 gskspv: Generate code for the extended instructions
This way, we can use the same approach to emit code for built-in
functions that we use for the rest of SPIRV emission.
2017-10-30 02:58:03 +01:00
Benjamin Otte
fde721eda8 gskslexpression: Function arguments are evaluated randomly
The C spec doesn't guarantee an order of evaluation for function
arguments. In fact, gcc evaluates them last to first while clang
evaluated them first to last.

We would like the left argument to be written into the SPIRV file first
(the GLSL spec wants that), so enforce this by calling the functions
before.
2017-10-30 02:58:03 +01:00
Benjamin Otte
c546e64419 gskslstatement: Add a return value to spirv writing
When writing SPIRV, statements return TRUE if they terminate the current
block (such as in a return statement). This is necessary because no code
may be written into a block after a termination opcode, so make all
other code check this return value and stop writing anything into the
current block.
2017-10-30 02:58:03 +01:00
Benjamin Otte
04dc25ed62 gskslnative: Reorganize more
Instead of creating a large const array of a custom struct holding all
the infos about native functions and iterating over that array, make the
macros generate code that register the functions directly.

So we don't need to deal with that weird struct anymore.
2017-10-30 02:58:03 +01:00
Benjamin Otte
4d49471685 gskslfunction: Move native function details to native function code
Instead of specifying the GskSlNativeFunction struct as the interface,
just have a more verbose constructor for native functins.

This will allow refactoring at will in the native function code.
2017-10-30 02:58:03 +01:00
Benjamin Otte
481cb8ffad gsk: Add GskSlEnvironment
This is the object that is meant to hold information about different GL
versions and take care of intializing native functions and variables at
the start of parsing.
2017-10-30 02:58:03 +01:00
Benjamin Otte
97a80e9169 gskslexpression: Implement a logical and expression
This mirrors what we did for || - because the right side is not always
evaluated, this isn't a normal binary operation.
2017-10-30 02:58:03 +01:00
Benjamin Otte
7445483691 gskslexpression: Fold constant expressions into SPIRV
If an expression is constant, always get the constant expression and
write it to the SPIRV file instead of doing an evaluation.

This has immense benefits when dealing with initializations, because
vec4(1, 2, 3, 4) will actually result in a constant instead of first
creating 4 integers, manually converting each of them to float before
calling the constructor. Yuck.
2017-10-30 02:58:03 +01:00
Benjamin Otte
2ee2457e82 gskslexpression: Add a logical or expression
Logical or is not a binary expression in that the right side of the
expression is only executed if the left side returns false while all
binary operations always execute both sides.
2017-10-30 02:58:03 +01:00
Benjamin Otte
9a0374f4fb gsksl: Implement relational comparisons 2017-10-30 02:58:03 +01:00
Benjamin Otte
4e61c71a5a gsksl: Implement subtraction 2017-10-30 02:58:03 +01:00
Benjamin Otte
d6c2c00a0a gskspv: Implement writing constructor functions
Calling a constructor is a simple OpConstantComposite call. Who'd have
thought.
2017-10-30 02:58:03 +01:00
Benjamin Otte
a7f11b5923 gsksl: Implement addition 2017-10-30 02:58:03 +01:00
Benjamin Otte
3124dffa37 gsksl: Emit decorations for variables
This requires some changes to the generated code from the SPIRV spec,
because the grammar does not list the optional argument for OpDecorate.

Bad spec!
2017-10-30 02:58:03 +01:00
Benjamin Otte
bde7a1f51c gskspv: Collect in and out variables
Send those variables as interaces with the entry point.
2017-10-30 02:58:03 +01:00
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