Commit graph

14496 commits

Author SHA1 Message Date
Bill Currie
8db547afec [ruamoko] Remove hack-in matrix type
No need for it now, either.
2024-09-04 10:36:32 +09:00
Bill Currie
fe16fed01a [vulkan] Update vkgen for the newly added bool type
I had forgotten about this, and ironically it's just one field in all of
vkparse, but adding support for bool to vkgen was easier than expected.
2024-09-04 10:33:10 +09:00
Bill Currie
83b92dd067 [qfcc] Handle fixed return types in generic functions
More segfaults, wee.
2024-09-04 09:58:14 +09:00
Bill Currie
8f9785c3da [qfcc] Handle type function parameters in type functions
The code assumed an actual type reference, not a type function,
resulting in a segfault for `@vector(bool,@width(vec))`.
2024-09-04 09:54:29 +09:00
Bill Currie
cd7abf5320 [qfcc] Add bool and matrix types to ruamoko
They're not properly implemented, but they do at least parse, so they
can be used in declarations (just not expressions yet).
2024-09-04 09:50:00 +09:00
Bill Currie
64334759f4 [qfcc] Support multiple type specs in type_ref
This is needed for `unsigned int` or `unsigned long` in type
expressions. However, there is a problem where @vector etc complain
about just `unsigned` (which should default to int, of course).
2024-09-04 09:41:57 +09:00
Bill Currie
65fc6054bb [qfcc] Actually parse ruamoko from strings
The previous related commit was just the basics and only glsl used it,
now ruamoko itself does (really need to look into namings: qc is a bit
off).
2024-09-04 09:35:25 +09:00
Bill Currie
ebb558bef1 [qfcc] Abandon v6 and v6p inout tests
Getting them to work properly with automake proved to be a lot of
trouble, though the bug the v6 inout test was for actually had nothing
to do with inout.
2024-09-03 21:38:16 +09:00
Bill Currie
87f62d1d7c [qfcc] Split sblock after v6 and v6p function calls
I seem to remember being here before (but now I've got a comment in the
code). It seems .params and the dag code don't like each other. Fixes
the failing inout test for v6 progs. I suspect the only reason inout
worked for v6p was the use of rcall.
2024-09-03 20:52:00 +09:00
Bill Currie
0c24f436ae [qfcc] Add a failing test for v6 inout params
Getting the vector literal compiling proved to be interesting.
2024-09-03 20:50:31 +09:00
Bill Currie
291f920e2a [qfcc] Parse vector literals correctly
It turned out that for v6 progs (due to lack of double or long) weren't
getting correctly parsed vector literals: incorrect "implicit" flag and
then a lot of brittleness around constant value conversions.
2024-09-03 20:50:31 +09:00
Bill Currie
b58e7791fd [qfcc] Implement parameter qualifiers in Ruamoko
Now parameters can be declared `const`, `@in`, `@out`, `@inout`. `@in`
is redundant as it's the default, but I guess it's nice for
self-documenting code. `const` marks the parameter as read-only in the
function, `@out` and `@inout` allow the parameter to pass the value back
out (by copy), but `@out` does not initialize the parameter before
calling and returning without setting an `@out` parameter is an error
(but unfortunately, currently detected only when optimizing).

Unfortunately, it seems to have broken (only!) v6 progs when optimizing
as the second parameter gets optimized out.
2024-09-03 18:07:42 +09:00
Bill Currie
4dd461d1e6 [qfcc] Clean up make_qc_param
The code for it and make_param were nearly identical, but it turned out
that just setting up the symbol correctly was all that was needed before
passing the spec to make_param. This will make implementing parameter
qualifiers easier (less repetition).
2024-09-02 15:59:06 +09:00
Bill Currie
6f0c7eaba6 [qfcc] Fix segfault for mixed generic and static params 2024-09-01 21:25:42 +09:00
Bill Currie
0385345d63 [qfcc] Create defs for instanced interface blocks
And allow unsized arrays (for in, uniform and buffer) to have deferred
sizes.
2024-09-01 17:10:10 +09:00
Bill Currie
f0eccc398e [qfcc] Fix some glsl parsing issues
Segfault when debug printing expr values, missing spec_merge for
type_qualifier and superfluous ; after for loop init expression.
2024-09-01 17:02:42 +09:00
Bill Currie
f335540e99 [qfcc] Handle glsl version and extension directives
The version directive really does only some error checking, and
only GL_EXT_multiview and GL_GOOGLE_include_directive are supported for
extensions, but enable/disable work (but not yet warn for multiview).
2024-09-01 17:01:05 +09:00
Bill Currie
cba28e9421 [qfcc] Use correct flags for in and uniform
They're not actually constant (in the usual sense), just read-only.
Fixes an internal error when accessing an unsigned array.
2024-09-01 16:40:47 +09:00
Bill Currie
a24d1d799f [qfcc] Use a stack for cpp_quote_start
Using set_line_file sort of worked with its stack, but line directives
embedded in the source (which glsl's initialization code uses) messed up
the start path for quoted include searches.
2024-08-31 13:01:26 +09:00
Bill Currie
9b2b841a55 [qfcc] Redo interface blocks as namespaces
There's no direct support for namespaces in Ruamoko yet, nor even in
qfcc, but glsl's blocks bring in a bit of foundation for them, even the
concept of "using" (for blocks with no instance name).

The members don't get locations allocated to them yet, but
fstrianglest.vert compiles and links correctly otherwise.

Also, there's no error checking yet.
2024-08-31 10:32:00 +09:00
Bill Currie
291898b46f [qfcc] Properly dup symbol for declaration
The unification of qc and c function symbol handling made it important
that the new symbol was a proper duplicate (minus being in a table) of
the old symbol. This fixes redeclared prototypes (especially for
qc-style functions, not encountered for c-style). Complete with unit
test :)
2024-08-30 21:45:37 +09:00
Bill Currie
ee6e38e2f9 [qfcc] Implement glsl's contructors for math types
I don't think this includes bools yet, and matrices aren't supported
yet, but float vectors work quite nicely.
2024-08-30 13:54:33 +09:00
Bill Currie
d0064c6c46 [qfcc] Implement a lot of glsl semantics
Other than contructors (and problems with the `out` block) qfcc can
compile fstrianglest.vert to what looks like working ruamoko code.
There's still a lot of work to do, though.
2024-08-30 13:51:31 +09:00
Bill Currie
4b369be8c1 [qfcc] Report correct type in enum/struct redefinitions
Enums are neither unions or structs.
2024-08-30 13:47:36 +09:00
Bill Currie
6d9e2bd926 [qfcc] Allow a single void typed parameter
It makes dealing with `foo(void)` a little easier in glsl's parser.
2024-08-30 13:32:32 +09:00
Bill Currie
1510d21cde [qfcc] Implement is_matrix correctly
There was a FIXME from before I'd figured out how I wanted to deal with
them. Now is_matrix returns true only if there's at least 2 columns.
2024-08-30 13:17:43 +09:00
Bill Currie
bca4d0e794 [qfcc] Implement location printing for the parsers
It's pretty bare-bones, but it's at least consistent across all the
parsers, and it's currently used only by the parser debug support.
2024-08-30 13:13:13 +09:00
Bill Currie
daaaeb9aed [qfcc] Abort qfo loading if file is too small
Or really, if Qfilesize thinks it's too small. Trying to allocate -1
bytes (due to trying to open / as a qfo) didn't end well.
2024-08-29 01:04:52 +09:00
Bill Currie
b302ce1095 [qfcc] Hook up glsl builtin variables
They get parsed, but nothing gets defined yet, but this proved to be a
good test for rua_parse_string().
2024-08-28 13:53:30 +09:00
Bill Currie
de6a3c5702 [qfcc] Support parsing Ruamoko from strings
Handy for parsing builtin symbols for things like glsl.
2024-08-28 13:50:36 +09:00
Bill Currie
4be1384701 [qfcc] Improve language selection
Using a struct with function pointers instead of switching on an enum
makes it much easier to add languages and, more importantly,
sub-languages like glsl's shader stage variants.
2024-08-28 10:18:21 +09:00
Bill Currie
bbb90ce27a [qfcc] Clone metafunc for generated generic symbols
Simply referencing the original metafunc resulted in only the first
variant getting a def. Now my little test generates defs for all called
variants of a generic function.

However, I'm still not sure this is quite the direction I want to go
with making calls to generic functions, but I still need to figure out
defining them. I think making progress with the glsl front-end will
help.
2024-08-28 09:03:56 +09:00
Bill Currie
4f5fcbd819 [qfcc] Check all generic function variants for dups
Checking only the last function to be added results in false negatives
and thus duplicates when defining a generic function. eg:

    genFType radians (genFType degrees);
    genDType radians (genDType degrees);
    genFType radians (genFType degrees) = #0;
    genDType radians (genDType degrees) = #0;
2024-08-27 14:41:38 +09:00
Bill Currie
c236129bbe [qfcc] Parse generic functions early
Detecting generic functions needs to be done before finalizing the
function type for non-generic functions, otherwise the resulting
function type winds up being incorrect due to bogus resolution of the
return type (and probably a few other factors).
This takes care of handling the return type in function definitions as
well as declarations as
2024-08-27 14:37:18 +09:00
Bill Currie
27286389d1 [qfcc] Isolate functions from symbols
Symbols now use metafunc_t to reference functions, which should make
working with generic and overloaded functions easier.
2024-08-26 15:50:27 +09:00
Bill Currie
8eae02209e [qfcc] Unify qc and c function symbol handling
This gets all the function symbol type handling into the one place,
which will make dealing with generic functions much easier.
2024-08-26 12:58:39 +09:00
Bill Currie
80df79a62f [qfcc] Be more clear about the builtin id parameter
While `expr` is better than `$n`, `bi_val` seems even better at
conveying meaning.
2024-08-26 10:31:57 +09:00
Bill Currie
3abf69cb36 [qfcc] Report errors accessing source files
This got lost in the switch to internal preprocessing as cpp used to do
the job for us.
2024-08-21 16:12:52 +09:00
Bill Currie
6a70ecda9d [qfcc] Make default_type take const symbol_t
It doesn't need to modify sym, and being const makes it more clear that
it doesn't (despite some of the other type functions breaking that rule,
ugh).
2024-08-21 08:30:15 +09:00
Bill Currie
43f83fc0eb [qfcc] Clean up some redundancy in methodproto
I don't know why I didn't apply the same ideas as in methoddef, maybe I
just forgot. I'm pretty sure I did methodproto first, or maybe cleaned
up methoddef much later then didn't think of methodproto. Still, the
grammar is much nicer to read now.
2024-08-21 08:26:31 +09:00
Bill Currie
a00b17bf71 [qfcc] Check declarator type chains
Arrays of functions or functions that return arrays or functions aren't
valid. While working on how to get generics in properly, I finally
understood what's going on with function types in the specifier, and I
think I'll be able to sort out function pointers vs prototypes, too.
2024-08-21 08:23:12 +09:00
Bill Currie
856761c4a9 [qfcc] Add to a FIXME comment 2024-08-20 20:20:05 +09:00
Bill Currie
5e6832294e [qfcc] Handle parsing generic builtin functions
Generic qc-style prototypes don't work but both c and qc style
definitions get as far as trying to build the builtin function. It
starting to look like I need to rework function handling, which isn't
all that surprising as it hasn't changed much over 22 years.
2024-08-20 15:19:31 +09:00
Bill Currie
219f2f26da [qfcc] Add is_double_val check
I wound up not using it, but I'll probably want it eventually..
2024-08-20 15:16:25 +09:00
Bill Currie
b8fe10f8a5 [qfcc] Limit builtin numbers to ints
Or whole-number floats for v6 progs.
2024-08-20 15:13:57 +09:00
Bill Currie
7f021b074c [qfcc] Treat fp constants as float for v6 progs
v6 progs don't support doubles, so demote double suffices to float, and
treat implicit fp constants as float.
2024-08-20 14:49:24 +09:00
Bill Currie
d9e2108b91 [qfcc] Return a metafunc for generic functions
One step closer to getting this idea to work.
2024-08-20 12:43:17 +09:00
Bill Currie
67c380e98d [qfcc] Clean up function.h a little
And even remove a dead function.
2024-08-20 09:26:24 +09:00
Bill Currie
0aab95eefe [qfcc] Rename overloaded_function_t to metafunc_t
I never did like overloaded_function_t as a name, and with the
introduction of generic functions (or templates, I guess?) meta-function
makes more sense to me.
2024-08-19 18:29:44 +09:00
Bill Currie
34b79ce783 [qfcc] Clean up some unnecessary type const casts
Most of them were noise from the type const correctness pass, but the
qc field function handling was always dubious (though in practice safe
due to how the type was built, but...). The remaining casts outside of
type.c need some thought.
2024-08-19 13:04:19 +09:00