Commit graph

14568 commits

Author SHA1 Message Date
Bill Currie
59c8e8e907 [qfcc] Don't check for redefs of unnamed symbols
Both glsl and spir-v need this for non-instanced interface blocks.
2024-11-19 17:12:03 +09:00
Bill Currie
128682624e [qfcc] Process array sub-expressions 2024-11-19 17:10:37 +09:00
Bill Currie
943cf9659b [qfcc] Make requiring @overload a language feature
Ruamoko still needs @overload (for now), but now glsl does not.
2024-11-18 22:46:14 +09:00
Bill Currie
393f669864 [qfcc] Ensure function types are complete
All types need non-zero alignment, width and columns.
2024-11-18 22:45:08 +09:00
Bill Currie
9add468462 [qfcc] Improve interface block declaration
I'm sure there are still some warts, but interface declaration now works
for spir-v and a real vertex shader can be compiled (albeit one that
doesn't use matrices).
2024-11-18 21:41:33 +09:00
Bill Currie
3dc22d8cd6 [qfcc] Support spir-v vector expressions even better
It turned out I did need direct vector expression support: the previous
commit handled only assignments, not sub-expressions.
2024-11-18 15:47:22 +09:00
Bill Currie
0771d6b3be [qfcc] Support assignment to field members in spirv
And now something like `a.y += 1` works.
2024-11-18 15:29:58 +09:00
Bill Currie
9b2240aaf8 [qfcc] Implement vector expressions for spir-v
And fix a little goof with VectorShuffle (c&p coding bites again).
2024-11-18 14:55:32 +09:00
Bill Currie
39514e4f3d [qfcc] Implement swizzle and arrays for spir-v
Arrays done via the field code since they use the same opcode and logic.
For now swizzles are just swizzles and don't support zeroing or negating
(but doing one or the other (not both) should be easy).
2024-11-18 12:29:25 +09:00
Bill Currie
34277b2050 [build] Install QF/input/event* header files for qfcc
I guess I'd copied them by hand once and forgot about it. Need to clean
out QF's install more often.
2024-11-18 12:07:55 +09:00
Bill Currie
73a8404684 [qfcc] Alias pointer etc to int for !
This fixes the calluse2 test.
2024-11-18 11:51:10 +09:00
Bill Currie
13f25af881 [qfcc] Use the called function for ruamoko progs
This was a nasty one to find as it was the unary expression rewrite that
triggered the bug (by causing tighter if tests to be generated, which
surprised me: I wasn't even trying for better if tests). I'm actually
not sure why things worked at all, but this fixes the crashes and other
weird behavior resulting from calls to performSelector.

Two tests are included because I found a separate bug (not fixed yet,
tested by calluse2) while getting the calluse test working.
2024-11-18 03:42:26 +09:00
Bill Currie
28e8697ae6 [qfcc] Implement compound initializers for spir-v
They don't yet support designators, and vectors aren't treated the way I
want, but my little test works correctly.
2024-11-17 22:45:18 +09:00
Bill Currie
91a93d7803 [qfcc] Add type_count() function
It returns the number of elements in a type (so something like `countof`
(hopefully that's what the up-coming C feature will be called) can be
implemented), but it applies to structs, vectors, etc (eg, 9 for mat3).
2024-11-17 16:12:27 +09:00
Bill Currie
d082d39e17 [qfcc] Use count for number of array elements
I got tired of seeing size when count is the real intent (mistake copied
from C++).
2024-11-17 15:27:10 +09:00
Bill Currie
2115e962fe [qfcc] Support typed compound initializers
Explicitly typed compound initializers are what C uses and allows them
to initialized `auto` vars and even pass through `...`. Not tested yet
other than ensuring existing tests didn't break.
2024-11-17 13:17:36 +09:00
Bill Currie
a7f9d96a02 [qfcc] Implement select (if) constructs
And break/continue too, since my test for them required select.
2024-11-16 23:13:46 +09:00
Bill Currie
93d116cf16 [qfcc] Rename body_first to do_while
Since loops are always while or do-while (for loops are just while loops
with an init block), it made more sense in the end.
2024-11-16 23:10:54 +09:00
Bill Currie
2ef72f745d [qfcc] Improve glsl scope handling
While storing the scope in a block was the right idea, the
implementation wasn't quite right as it resulted in the current scope
getting set at the wrong times resulting in incorrect symbol access when
shadowing was in effect.
2024-11-16 20:14:51 +09:00
Bill Currie
3797b1083b [qfcc] Implement loops for spir-v
Mostly, at least: continue and break aren't functional yet, and for
loops haven't been tested, but while and do-while seem to work.
2024-11-16 19:29:41 +09:00
Bill Currie
89dac4a1b8 [qfcc] Create scopes for while and for loops in glsl
I guess that was a mental FIXME for later, but later came sooner. The
declaration doesn't seem to be working properly, but I'll worry about
that later when I can get some automated tests going.
2024-11-16 19:29:41 +09:00
Bill Currie
01d3c60fe0 [qfcc] Encode param qualifiers in function type
I'm not sure whether I'll stick with the current encoding, but it turns
out it's necessary to separate function types on parameter qualifiers (I
was half expecting that, though).
2024-11-16 19:29:41 +09:00
Bill Currie
22794caf11 [qfcc] Support vector value expressions for spir-v
It seems constant initializers are different from constants in an
expression.
2024-11-16 18:54:31 +09:00
Bill Currie
27afd608f1 [qfcc] Emit bool types
Because spir-v's bools are abstract and have no specific size, bool and
lbool need to both have the same spir-v id, as do the vector
counterparts, so when one gets emitted, the id is copied to the mirror
type.
2024-11-15 13:09:26 +09:00
Bill Currie
ebb3ec592a [qfcc] Implement bool and lbool types
Since spir-v needs actual bools for its conditional instructions, the
time to do bool properly finally came. As expected, the changes caused
quite a mess, but Ruamoko now does bool/true/false.
2024-11-15 12:36:08 +09:00
Bill Currie
ad36d2cd50 [qfcc] Clean up some 0/nullptr in type.c 2024-11-15 10:50:03 +09:00
Bill Currie
7ad6aff928 [qfcc] Implement cast and ?: expressions for spir-v
Unfortunately, there are some bugs with the result of comparisons
(getting int instead of bool in the spir-v).
2024-11-15 10:49:07 +09:00
Bill Currie
81cc736683 [qfcc] Add is_signed and is_unsigned type check functions
Makes implementing casts for spir-v much easier.
2024-11-15 10:49:07 +09:00
Bill Currie
d6d44b62d9 [qfcc] Use bool for type is_* functions
More clarity often helps.
2024-11-15 10:49:07 +09:00
Bill Currie
dc85a4df4b [qfcc] Specify entry-point interface variables
Yet another step closer to having a working glsl compiler.
2024-11-14 20:58:21 +09:00
Bill Currie
c5613ba1e4 [qfcc] Use tagged references for spir-v storage
The tags might have other uses thus the generic term, but this allows
spir-v variables to be declared with the correct pointer storage
classes. Now spirv-val is complaining about my interfaces, so progress :)
2024-11-14 18:37:38 +09:00
Bill Currie
fa42478af6 [qfcc] Ensure final block is terminated
Which for a function means return or unreachable (though I suppose
branches might work).
2024-11-14 09:04:48 +09:00
Bill Currie
5033dc9a12 [qfcc] Use staging vars for non-const params
Non-const params use references and so need somewhere to store the
arguments. Local variables could be passed directly (parameters normally
require function storage class, which local variables are), but that's a
potential optimization for later.
2024-11-14 09:04:48 +09:00
Bill Currie
698430630d [qfcc] Emit spir-v global variables
This required adding a `var` symbol type. For now, it holds just the
storage class, but it might be good for the initializer, too.

Also, clean up some pointer/reference inconsistencies.
2024-11-14 09:04:48 +09:00
Bill Currie
ae4d87b969 [qfcc] Dereference cast expression 2024-11-13 19:03:20 +09:00
Bill Currie
52d38ce8a6 [qfcc] Set struct member ids
The id matches the member's order in the struct's fields (needed for
spir-v access chains).
2024-11-13 14:25:25 +09:00
Bill Currie
14f428a81d [qfcc] Don't dereference pointer for field access
As I suspected, the dereference was premature, although it can act as an
optimization when multiple fields of an object are accessed, though it
won't work for writes to lvalues (which means my fixes for spir-v
code-gen currently don't work for lvalue writes). Still, progress. Need
to get field member ids set.
2024-11-13 14:05:46 +09:00
Bill Currie
fb58c1aace [qfcc] Implement field access for spir-v
It turns out my field access processing works well enough for vectors.
I'm not sure about pointer access as I may have done the pointer
dereference prematurely.
2024-11-13 13:36:57 +09:00
Bill Currie
549203d05d [qfcc] Correct a comment 2024-11-13 13:36:46 +09:00
Bill Currie
410317fdf7 [qfcc] Mark spirv variable declarations as lvalues
I'm not sure this is always correct, but it does respect `const`.
2024-11-13 12:16:43 +09:00
Bill Currie
b43fe9ddc5 [qfcc] Process field expressions
I'm not sure they work yet as the spirv output doesn't support them yet,
but after an lvalue fix (next), this gets field accesses to code-gen.
2024-11-13 12:15:24 +09:00
Bill Currie
7b80ec2a14 [qfcc] Support field expressions in dot output
Some other types were added with null functions to make things a little
easier when I get around to implementing them.
2024-11-13 12:14:05 +09:00
Bill Currie
e4e04b183a [qfcc] Switch is_lvalue to use bool instead of int
Self documentation for the win.
2024-11-13 12:13:05 +09:00
Bill Currie
6649d8238e [qfcc] Process glsl parameters correctly
This gets parameter qualifiers to the parameters and thus `const`
parameters work as expected (even passes validation). However,
in/out/inout do not work yet due to incorrect setup of the function
call: spir-v wants them to be passed by reference (pointers) rather than
by value.
2024-11-12 23:49:47 +09:00
Bill Currie
32bf9e9435 [qfcc] Generate spir-v function calls
The function parameter and argument types are a mess with respect to
references (and thus calls don't pass validation) but the generated code
seems to be otherwise correct.
2024-11-12 18:24:40 +09:00
Bill Currie
f9345caeb3 [qfcc] Clean up spirv instruction generation
This should make it easier to declare local variables on the fly (needed
for function arguments).
2024-11-12 01:26:20 +09:00
Bill Currie
8a3a39be68 [qfcc] Fix a missed local var use
I'd intended on using arg_space instead of current_func->arguments, but
missed one spot.
2024-11-12 01:24:31 +09:00
Bill Currie
a68aaad307 [qfcc] Clean up some arg/param confusion
Only in expr_call.c, but that's probably where it's at its worst.
2024-11-10 23:34:07 +09:00
Bill Currie
819d0fc3be [qfcc] Split up build_function_call
It wasn't quite as nasty as I thought, but splitting it up helps add a
little self documentation and, possibly more importantly, simplify
navigation through the type checks and argument setup.
2024-11-10 16:48:01 +09:00
Bill Currie
bcfd1b7660 [qfcc] Split out the call related expression code
I've long felt build_function_call was getting a bit big, and expr.c
especially so. This should make it easier to rewrite build_function_call
for dealing with target-specific code. As a bonus, the int through ...
warning is already cleaned up.
2024-11-04 20:28:30 +09:00