Commit graph

14558 commits

Author SHA1 Message Date
Bill Currie
55a5782a95 [qfcc] Save the type evaluation code
I don't yet know whether the generated code is correct, but the little
functions that compute a generic type gets stored in the function's
params/return type.
2024-09-07 02:36:54 +09:00
Bill Currie
b59a8fb66a [qfcc] Add a code generator for type expressions
Allows the parsing of the return type in the following:

    @generic(vec=[vec2,vec3,vec4]) {
    @vector(bool,@width(vec)) lessThan(vec x, vec y);
    }

Unfortunately, can't use math in int value parameters just yet, the
processing of expressions needs to be delayed (it's currently done
immediately so type-checking happens to early).

It's not connected up yet, but does produce what looks like the correct
code.
2024-09-06 01:04:38 +09:00
Bill Currie
55d7d1f069 [qfcc] Expose convert_op and ensafen free_operand
Needed for type evaluation codegen, and free_operand needs to be
null-safe.
2024-09-06 01:04:38 +09:00
Bill Currie
9c902501d7 [qfcc] Move D_* macros to def.h
Finally, after way too long.
2024-09-06 00:56:56 +09:00
Bill Currie
1f3b21a626 [qfcc] Use a temp for size-changing swizzles
The Ruamoko instruction set has only same-size swizzles, so a staging
temp is needed either before (grow) or after (srink) the swizzle.
Unfortunately, it looks like there might be missed optimization issues,
but at least things seem to be correct.
2024-09-05 14:26:29 +09:00
Bill Currie
24a48ad703 [qfcc] Improve support for matrix types
Their size is now calculated correctly, they can be assigned,
initialized using block initializers (vectors too!), and columns can be
indexed as vector lvalues.
2024-09-05 14:06:30 +09:00
Bill Currie
e9d5bac369 [gamecode] Support debug print of matrices 2024-09-05 13:16:22 +09:00
Bill Currie
698d27c996 [gamecode] Save all param pointers with PR_SaveParams
Builtins calling other functions that call back into progs can get their
parameter pointers messed up resulting in all sorts of errors. Thus wrap
all callbacks to progs in PR_SaveParams/PR_RestoreParams.

Also, ditch PR_RESET_PARAMS in favor of using PR_SetupParams and move
setting pr_argc into PR_SetupParams.
2024-09-05 00:00:44 +09:00
Bill Currie
e35bff066f [vulkan] Fix more sync issues
Thanks to validation layers showing command buffer debug regions, it was
pretty easy to find the offending buffers. Did need to modify
QFV_PacketCopyBuffer to take a source barrier as well as the destination
barrier, but this is probably for the best.
2024-09-04 17:47:04 +09:00
Bill Currie
bc22cd3255 [vulkan] Mark more command buffer regions
Now all pipelines and any tasks that have a command buffer attached get
a region using their names (tasks use the function name). I don't know
when it happened, or if I failed to notice last time, but (sync)
validation layers now include the debug region for command buffers: very
nice.
2024-09-04 17:34:01 +09:00
Bill Currie
f6d2cf43e8 [qfcc] Parse about 2/5 of the glsl functions
They're stuck on computed return types causing segfaults, but the rest
helped with ironing out other issues in the compiler.
2024-09-04 10:43:11 +09:00
Bill Currie
3aab301d45 [qfcc] Check receiver type a second type
The old "expr changed type to error" trick hasn't worked for a while, so
sending a message to an undefined class didn't end well.
2024-09-04 10:37:26 +09:00
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