Commit graph

1104 commits

Author SHA1 Message Date
Bill Currie
88253a847b [qfcc] Support type inference for spir-v
I guess I hadn't thought of it because GLSL doesn't have `auto`, but
since the builtin functions are implemented in Ruamoko, `auto` is
available and I use it for the atomic image functions.
2025-01-14 01:27:11 +09:00
Bill Currie
ed88152f85 [qfcc] Get type attribute working for computed types
It even handles errors :)
2025-01-14 01:02:31 +09:00
Bill Currie
041216182e [qfcc] Implement spirv instruction lookup
Yay, no more magic numbers for intrinsics :)
2025-01-13 21:38:35 +09:00
Bill Currie
027ad12c72 [qfcc] Support add/sub for matrix/vector and scalar operands
GLSL needs it, and it's not entirely unreasonable (though I'll probably
add some flags to control it since it doesn't always make sense).
2025-01-13 12:52:12 +09:00
Bill Currie
320f9e2fe7 [qfcc] Support type.attribute on any type
The goal is to make it easy to get size/coord/base types from image
types without creating a zillion type functions.

It was necessary to make it possible for any type to have an attribute
function (returns an expression so it can be more useful: types are
returned via type expressions). Algebra types were the first victim
(which was nice for testing).
2025-01-13 00:10:27 +09:00
Bill Currie
7baf93c8df [qfcc] Make short-circuit boolean logic language dependent
And disable it for GLSL. I might need to make it target-dependent
instead as I don't know if I'll be able to implement it in SPIR-V, and
when I get to the C back-end, it will be superfluous.
2025-01-12 23:29:56 +09:00
Bill Currie
6e004e9baa [qfcc] Implement generic type computation
I had already implemented the code generation side (though using type
ids instead of encodings is a nice change), but I hadn't implemented the
actual evaluation or even called it. Now return types can be computed
from generic parameters (eg, ivecN from vecN).
2025-01-10 00:56:02 +09:00
Bill Currie
a93c109988 [qfcc] Improve spir-v entry point handling
It's still not great (mostly on the language side, I think), but
different glsl shader types get the correct model and fragment shaders
even get the correct mode.
2025-01-09 17:29:27 +09:00
Bill Currie
4998968169 [qfcc] Emit spirv image type encodings
Access qualifiers aren't supported yet, and some of the image handling
is a bit messy (currently tied to glsl when it should be general), but
the basics are there. However, now I've got to sort out the execution
model (need Fragment or GLCompute for ImplicitLod).
2025-01-09 01:29:38 +09:00
Bill Currie
99b1859aac [qfcc] Parse the spirv grammar json files
I really don't like the way they're included (I'm really looking forward
to #embed, but gotta wait for gcc 15), and I'm a tad grumpy that the
documentation for them
(https://registry.khronos.org/SPIR-V/specs/unified1/MachineReadableGrammar.html)
is wrong (missing fields), but I think I like the result.

The grammars (core and glsl.std.450) are parsed into structs that should
be fairly easy to interpret: the instructions, kinds, and enumerant
values are sorted by name for search with bsearch. Having the data
parsed in means source code can refer to the items by name rather than
magic numbers, which will be very nice for intrinsics and image types
(and probably a few other things).
2025-01-07 03:26:12 +09:00
Bill Currie
400486931f [qfcc] Allow languages to hook number parsing
The idea is to allow certain contexts to interpret something like `2D`
as an identifier instead of 2.0 (double), or (not sure I'll go there,
5e12 as a bivector instead of a double or float.
2025-01-04 12:51:30 +09:00
Bill Currie
ea3198e8fe [qfcc] Update generic handling for the new type scheme
And clean up some redundant (premature!) spec processing.
2025-01-03 21:27:28 +09:00
Bill Currie
ae4c107384 [qfcc] Add type_process for type functions
I'm not quite sure it's what I need, but it does help with resolving
types with complex expressions (eg, `@vector(bool,@width(vec))`).
2025-01-03 17:55:08 +09:00
Bill Currie
bec8b290d2 [qfcc] Resurrect is_function
In the end, it does simplify things a lot, though it helped get function
pointers working at least a bit (they're not quite the same as C yet,
but I think that's mostly that functions can be struct fields).
2025-01-03 17:52:19 +09:00
Bill Currie
99632ddb03 [qfcc] Rework function/pointer/array declarations
They should now work in generic contexts, but the pressing need to work
on arrays was due to constant expressions for element counts breaking.
As a side effect, function pointers are now a thing (and seem to work
like they do in C)
2025-01-03 13:22:29 +09:00
Bill Currie
6af7ff2867 [qfcc] Ensure processed expressions are dagged
GA expressions need to be optimized so things that should cancel out do,
and this requires everything to be dagged. Doing so in expr_process gets
most of the expressions, and then a few stragglers in proc_field. There
might still be some more, but my test scene compiles again.
2025-01-03 02:34:15 +09:00
Bill Currie
625c53180f [qfcc] Propagate rua_ctx_t to more functions
It will eventually get to most places, but this set is necessary for
using expr_process in expr_type.c
2024-12-23 22:03:47 +09:00
Bill Currie
626680f22f [qfcc] Handle return in inline functions
The code is pretty lousy in that it assumes there's only one `return`
and it's the end of the function, and the generated code is even worse
(too many load/store ops in the spir-v), but it looks like it at least
works. It does pass validation.
2024-12-12 11:08:30 +09:00
Bill Currie
a0f09b13cf [qfcc] Set current function for inlined functions
It improves error reporting and is even a solution for what to do with
return statements in inline functions.
2024-12-11 16:05:50 +09:00
Bill Currie
6840a208b9 [qfcc] Implement inline function calls
They're buggy in that the defspaces for parameters and locals are
incorrect (they need to point to the calling scope's space). Also,
parameters are not yet hooked up correctly. However, errors (because I
need to allow casts from scalars to vectors) do get handled.
2024-12-11 03:16:15 +09:00
Bill Currie
36cf1f948e [qfcc] Add bypass scopes
Because the symbol tables for generic functions are ephemeral (as such),
they need to be easily removed from the scope chain, it's easiest if
definitions are never added to them (instead, they get added to the
parent symbol table). This keeps handling of function declarations or
definitions and their parameter scopes simple as the function gets put
in the global scope still, and the parameter scope simply gets
reconnected to the global scope (really, the generic scope's parent)
when the parameter scope is popped within a generic scope.
2024-12-11 03:06:50 +09:00
Bill Currie
b2049f496b [qfcc] Save caller to new_symbol* in symbol_t
I should go through and do this for all the structs (not looking forward
to expr_t) as it's sometimes quite handy to know who created something.
2024-12-11 02:41:13 +09:00
Bill Currie
306306fc5a [qfcc] Move semantic processing into build_code_function
In the end, I could have done the null context check for pascal, but I
think the xvalue support will come in handy for implementing inline
functions.
2024-12-08 20:01:06 +09:00
Bill Currie
4a8c53aa6f [qfcc] Add partial support for renamed builtins
The back-end support for renamed builtins (fte's = #0:name) was needed
for pascal functions because the internal name is now prefixed with an @
to allow the lvalue/rvalue selection of behavior for function symbols
2024-12-08 19:13:49 +09:00
Bill Currie
38c64c61b9 [qfcc] Make new_call_expr non-const
I really don't remember why I made it const. Although there are still
others, new_* exression calls are meant to be mutable.
2024-12-08 19:03:41 +09:00
Bill Currie
1e19335b44 [qfcc] Add xvalue expressions and symbols
xvalue symbols refer to two expressions: an lvalue and an rvalue. They
are meant to be used with xvalue expressions.

xvalue expressions are useful when a distinction must be made between
the behavior of something (eg, a pascal function symbol) must change
depending on whether it's an lvalue (assignment of the function's return
value) or an rvalue (a call to the function, especially when the
function takes no parameters).
2024-12-08 18:59:40 +09:00
Bill Currie
213ac2a328 [qfcc] Use a context object to hold current language
Because the glsl front-end uses Ruamoko to compile its builtins, it
needs to switch languages, and the cleanest way to do so is to use a
context object that gets passed around. This removes not only the
current_language global, but also (as a bonus) any real references to
flex's scanner object (there's still a pointer in rua_ctx_t, but it's no
longer a parameter (which caused some pain in the change)).
2024-12-07 23:55:48 +09:00
Bill Currie
bbc7fcd207 [qfcc] Remove convert_name
It's no longer necessary with the shift to deferred semantics.  The
remaining relevant functionality has been moved to proc_symbol.
2024-12-07 18:35:01 +09:00
Bill Currie
c5d77141eb [qfcc] Defer Ruamoko semantics processing
The main goal was to make it possible to give generic functions
definitions (since the code would be very dependent on the actual
parameter types), but will also allow for inline functions. It also
helped move a lot of the back-end dependent code out of semantics
processing and almost completely (if not completely) out of the parser.
Possibly more importantly, it gets the dags flushing out of the parser,
which means such is now shared by all front-ends.

There's probably a lot of dead code in expr.c now, but that can be taken
care of another time.
2024-12-07 02:38:00 +09:00
Bill Currie
ec436ee65e [qfcc] Put definition for generic functions in genfunc
It is then copied to the metafunc when finding the actual function to
call. Fixes the last definition defining all instances.
2024-12-05 16:08:39 +09:00
Bill Currie
ad45715359 [qfcc] Clean up duplicated vector list construction
I wound up with a few too many copies for my liking.
2024-12-05 11:13:08 +09:00
Bill Currie
c185d2463b [qfcc] Support matrices in spirv output
With a few more fixes, iqm.vert builds nicely.
2024-12-05 00:26:07 +09:00
Bill Currie
5e053fe270 [qfcc] Fix an overflow for matrix values
ex_value_t keeps getting bigger :P
2024-12-05 00:22:38 +09:00
Bill Currie
8e2fe83c27 [qfcc] Add a function for checking type comparisons
It returns true if the comparison is valid without a diagnostic (usually
a warning), false otherwise.
2024-12-05 00:10:15 +09:00
Bill Currie
5714433a9c [qfcc] Clean up some more bools 2024-12-05 00:10:15 +09:00
Bill Currie
d0db75779a [qfcc] Add a check for shifts and expand math ops
I found a need to check for shifts separately (not sure it's the right
approach for that problem, though), and there are a few more math ops
than just +-*/.
2024-11-28 21:16:14 +09:00
Bill Currie
43716e5d6a [qfcc] Use columns for selecting instructions
Now both width and columns must match for an instruction to be selected.
Found a few errors in my opcode specs, and some minor goofs in the type
system (really just overthinking things when I added matrices).
2024-11-26 10:45:20 +09:00
Bill Currie
a4eefa6204 [qfcc] Implement matrix construction for constants
Non-constant matrices are not implemented yet, and it turns out
vector-matrix multiplication produces incorrect vector types (for
vec4*mat3x4)
2024-11-25 12:39:14 +09:00
Bill Currie
1e5d500f8b [qfcc] Implement intrinsic functions in spir-v
Only a tiny handful of glsl functions are implemented (dot, cross,
sqrt), but the system works, both via generics and regular overloads.
2024-11-25 01:39:27 +09:00
Bill Currie
b0207f4dc9 [qfcc] Allow demotion of implicit literals
This fixes the modulo test.
2024-11-24 18:12:51 +09:00
Bill Currie
1893df34a3 [qfcc] Add an intrinsic expression type
This will be fore generating specific SPIR-V instructions via function
calls, and could be useful for Ruamoko, too.
2024-11-22 23:44:37 +09:00
Bill Currie
0dfe81bce8 [qfcc] Move ruamoko attribute parsing out of the parser
Makes for better separation of variable and function attributes.
2024-11-22 14:15:08 +09:00
Bill Currie
c16a8411bc [qfcc] Extend handles to support image types
Images are just handles, but they have additional type data like
dimensionality, array, etc that distinguishes between the image types.
2024-11-21 19:18:13 +09:00
Bill Currie
03c47f8af7 [qfcc] Support (partially) attributes on types
For now, it's just recording that type type has attributes (encoding
begins with %) and resurrecting types_same which is used only when
matching with types with attributes, so there's still a fair bit of work
to do.
2024-11-21 08:30:47 +09:00
Bill Currie
5e605aee36 [qfcc] Clean up some overzealous const correctness
I'm not sure why I made those functions take const type_t *, but they
didn't need it. There's still a relevant fixime in find_handle, but I
haven't decided how to fix that one just yet.
2024-11-21 08:30:47 +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
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
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
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