Commit graph

4917 commits

Author SHA1 Message Date
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
e87e01e4f2 [qfcc] Don't fold constants for algebra
While it is a pessimism, I really want to get rid of fold_constants (in
favor of something smarter), and it's currently in the way of more
important things.
2024-12-07 19:09:10 +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
9c037ce79d [qfcc] Clean up some cruft in the glsl parser 2024-12-07 02:53:56 +09:00
Bill Currie
a91595ad6b [qfcc] Make the GA tests a little easier to "use"
All errors are printed now, and the line numbers of the error message
are given, making finding the offending test much easier.
2024-12-07 02:52:10 +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
d08816cb6b [qfcc] Update offset for aliased defs
When getting an offset alias of an already aliased def, the offset needs
to be updated so it points to the correct part of the def. This is
actually a rather old bug but it got uncovered somehow with my rework of
the ruamoko semantic processing (probably an altered cast).
2024-12-07 00:22:53 +09:00
Bill Currie
4e3bacd827 [qfcc] Fix handling of a single id in ... macros
If the id isn't a parameter or other macro, then it can't be empty and
thus the va_args aren't empty.
2024-12-06 22:38:58 +09:00
Bill Currie
bc1b9893a7 [qfcc] Fix vector constructions from scalars
Yet another bit of is_vector/is_nonscalar confusion.
2024-12-05 16:11:59 +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
a5366bf7f9 [qfcc] Fix matrix indexing for ruamoko
The change to exclude matrices from is_nonscalar broke indexing of the
columns.
2024-12-05 14:24:14 +09:00
Bill Currie
639818cca5 [qfcc] Handle unsigned int correctly
I'd missed the one case, so such declarations wound up just `int`
2024-12-05 13:12:27 +09:00
Bill Currie
b4387cd881 [qfcc] Finish type decl for type_ref
I guess I'd wanted to avoid supporting automatic types in type
functions, but that broke long and unsigned int: either no type, or just
int, depending on the decl style.
2024-12-05 13:10:11 +09:00
Bill Currie
a938f1c507 [qfcc] Define the glsl mix builtins
Unfortunately, it turns out that generic functions are over-grouped so
all functions with the same name get the last definition, so `mix` with
a float (which should get GLSLstd450FMix) gets the bool version instead
(SpvOpSelect).
2024-12-05 12:19:04 +09:00
Bill Currie
9f9aecfeec [qfcc] Fix function disambiguation
I was checking for duplicate best matches too early. Local minimum (or
inflection point, really) problem.
2024-12-05 12:08:08 +09:00
Bill Currie
277c5a2318 [qfcc] Optimize matrix construction from a matrix
If the source matrix has at least as many rows as the new matrix, then
the columns are taken from the columns (possibly shortened via swizzle).
2024-12-05 11:45:01 +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
81aa77b142 [qfcc] Optimize matrix construction from vectors
When the number of supplied vectors matches the number of columns in the
matrix and all vectors have the same width as the number of rows in the
matrix, there's no need to expand the vectors into components only to be
gathered again.
2024-12-05 10:31:32 +09:00
Bill Currie
14e39627cc [qfcc] Construct matrices by vectors
SPIR-V requires that matrices are constructed from vectors rather than
individual components. While not optimal, iqm.vert's output now passes
spirv-val. Also probably still lots wrong with fine details.
2024-12-05 10:03:01 +09:00
Bill Currie
f014d3f580 [qfcc] Clean up logical not and bool expressions
Got to get rid of a FIXME :)
2024-12-05 02:02:14 +09:00
Bill Currie
4b7025fa0b [qfcc] Implement matrix ops in spirv
And they pass spirv-val.
2024-12-05 02:00:35 +09:00
Bill Currie
a9bff23a6a [qfcc] Define the glsl normalize functions
I think I need to come up with a better way of defining glsl builtins
and the strings are rather ugly (and I don't want to use qfcc system
header files).

iqm.vert now compiles, but doesn't pass validation yet (matrix bugs).
2024-12-05 00:30:17 +09:00
Bill Currie
2a5c9ae45b [qfcc] Emit spirv array types correctly
Array count is an id, not a literal. Oops.
2024-12-05 00:27:27 +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
7bbbbe1f0e [qfcc] Improve glsl source line tracking
It's never nice getting an error on the wrong line.
2024-12-05 00:21:19 +09:00
Bill Currie
8cc71395cc [qfcc] Fix some more unsupported expressions in dot 2024-12-05 00:19:48 +09:00
Bill Currie
674fbae225 [qfcc] Rework binary_expr to be support matrices
And, nicely, simplify it quite a bit. I'm not sure why I didn't thinkg
of this approach before. While the ruamoko back-end doesn't support
matrices yet, the expressions are handled.

As a side effect, type checking on comparisons is "stricter" in that
more potentially bogus comparisons (eg, int-float) are caught, resulting
in a few warnings in ruamoko code and even finding a couple of bugs.
2024-12-05 00:18:47 +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
8d69ca9a99 [qfcc] Simplify type_promotes and type_demotes
Using bit masks for valid source types for each destination type makes
the logic a lot easier to read. Still had to have some explicit checks
for enums and bools.
2024-12-05 00:10:15 +09:00
Bill Currie
f4a8a5e179 [qfcc] Fix some inconsistent tokens
I need to find a good way to share token defs between bison files.
2024-12-05 00:10:15 +09:00
Bill Currie
7a30ac9527 [qfcc] Clear current function for constexpr evaluation
The code gen return statements checks for out/inout parameters in the
current function and thus could result in some undesired behavior when
constants are evaluated within such a function.
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
b03132825e [qfcc] Fix a typo in a variable name 2024-12-04 23:48:43 +09:00
Bill Currie
4800fef4fd [qfcc] Give short and ushort width of 1
I'm not sure why I thought a width of 0 was a good idea, but it proved
to be problematic when implementing matrices.
2024-12-04 23:47:58 +09:00
Bill Currie
58b78cfdec [qfcc] Separate matrices from non-scalars
While matrices are non-scalars in math, is_nonscalar is meant for any
vector type because is_vector is specifically for the quakec vector
type.
2024-12-03 14:56:38 +09:00
Bill Currie
7c56c10d25 [qfcc] Support matrices in binary expressions
Partially. There are problems with scaling and code-gen.
2024-11-28 23:30:39 +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
8323868b2c [qfcc] Add an opcode for outer products
I'm not sure what it's useful for, but GLSL has a function for it thus I
decided to add the instruction to the VM, so this is part of the
compiler side.
2024-11-28 21:16:14 +09:00
Bill Currie
c4f48353b9 [qfcc] Correct a typo in a comment 2024-11-28 21:05:34 +09:00
Bill Currie
0652a103d0 [qfcc] Correct edge labels for field expressions
I had f and o reversed and decided to use m (member) instead of f.
2024-11-28 20:09:51 +09:00
Bill Currie
2b70c54b15 [qfcc] Fix an uninitialized variable
I'd forgotten to do an optimized compile check :/
2024-11-26 16:26:45 +09:00
Bill Currie
2bd9d26cc1 [qfcc] Implement mod for v6 progs
The tricky bit was figuring out how to get `floor()` out of the
available instructions. It's handy that the comparison ops always
returned floats and didn't force the use of branches.
2024-11-26 14:38:55 +09:00
Bill Currie
7b4aa1efd8 [qfcc] Clean up v6 rem implementation
I couldn't do it this way before I got dag expressions working, but this
is much cleaner.
2024-11-26 14:21:10 +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
b9ed0dcc64 [qfcc] Allow obj pointer to id conversions for free
Overloaded functions taking id need to allow any obj pointer.
2024-11-24 18:38:45 +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
98d122f122 [qfcc] Use same cost function for generic and overloaded
The modulo test breaks due to implicitly typed literals, but otherwise
seems to do a better job of resolving function calls.
2024-11-24 15:56:46 +09:00
Bill Currie
70bb5c3434 [qfcc] Check for errors in conditional expressions 2024-11-24 15:52:17 +09:00
Bill Currie
53c4c205ca [qfcc] Override function declaration with definition
This fixes the problem of the function declaration parameter names
overriding the definition's parameter names.
2024-11-24 13:03:34 +09:00
Bill Currie
ffcee99835 [qfcc] Partially handle implementing generic functions
Implemented via specific overloads of the function.

It's not quite working correctly in that parameter names are taken from
the declaration instead of definition. However, this seems to be an old
bug that went unnoticed due to me almost always using the same parameter
names in declaration and definition.

Also, the code in get_function() is a horrible mess.

However, the basic idea turned out to be simpler than I though (though
details of the implementation are indeed a little trickier): generic
functions are essentially prototype generators when implemented using
non-generic specialized overloads.
2024-11-24 11:34:59 +09:00
Bill Currie
980dd913b5 [qfcc] Split up find_generic_function
I want to reuse its generic function search for defining
implementations.
2024-11-22 23:50:07 +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
11f8992710 [qfcc] Handle dynamic array indices for spir-v
Now bsp_turb.frag (with hacks for builtin functions) compiles and even
passes validation, but is badly broken.
2024-11-21 19:18:13 +09:00
Bill Currie
fbcdf227c5 [qfcc] Assign indices to glsl block members
spirv-val didn't particularly like all my block members getting index 0
(really, it was tangled types, but 0 was the cause).
2024-11-21 19:18:13 +09:00
Bill Currie
cfc5e0b5fd [qfcc] Handle convert symbols when processing
I'm pretty sure I don't want this getting into the target code, so
handling it early (like in the immediate processing path) seems good.
2024-11-21 19:18:13 +09:00
Bill Currie
c3bbd85857 [qfcc] Skip void param for spir-v
Functions declared with `(void)` don't actually have any parameters, so
ensure no parameters are emitted for such functions.
2024-11-21 19:18:13 +09:00
Bill Currie
744c3ff1d6 [qfcc] Handle reference params/args for overloaded functions
Reference vs value parameters do not resolve overloaded functions.
2024-11-21 19:18:13 +09:00
Bill Currie
663aeb16fd [qfcc] Enable color/texture vector component names
Yet another step closer to glsl support.

While it wasn't correct anyway (neither vectors nor quaternions are
colors), the additional names broke q.s in the quaternion.r test, likely
due to there being two s fields.
2024-11-21 19:18:13 +09:00
Bill Currie
08bdc0794a [qfcc] Improve expression line tracking
Missed a few places in expr_process.
2024-11-21 19:18:13 +09:00
Bill Currie
fb497cd0b2 [qfcc] Clean up the errors for some layout qualifiers
Nothing's actually implemented, but once I fix a couple more errors I'll
be able to work on that.
2024-11-21 19:18:13 +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
28a85b1624 [qfcc] Fix some crashes when parsing bsp_turb.frag
Incorrect type accesses and unnamed interfaces.
2024-11-19 17:15:42 +09:00
Bill Currie
34b94aec96 [qfcc] Set binding and set attributes
Not sure if this will work, but it does fix some error and notice noise.
2024-11-19 17:13:38 +09:00
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
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
Bill Currie
a0845e65fb [qfcc] Use temp expressions as spir-v id carriers
spir-v uses SSA, so temps cannot be assigned to directly, so instead use
the temp expression as a reference for the result id of the rhs of the
assignment. This would get function calls working if the they actually
emitted any code (right now, just a place-holder id so spirv-dis doesn't
fall over).
2024-11-04 16:42:44 +09:00
Bill Currie
95cedd879a [qfcc] Remove a stale macro
I don't remember what it was for even, other than somehow dereferencing
a pointer def.
2024-11-04 16:38:51 +09:00
Bill Currie
6358143795 [qfcc] Clean up the local_expr global
I never liked it and it made things a little difficult for spir-v.
2024-11-04 16:38:07 +09:00
Bill Currie
5bf9d3c57c [qfcc] Implement spir-v assignment to vars
Since actual variables are always references, they need to written via
OpStore.
2024-11-04 12:53:21 +09:00
Bill Currie
6e5b13c6f6 [qfcc] Clean up spir-v function generation
Now spirv-val has something to chew on.
2024-11-04 12:33:59 +09:00
Bill Currie
9da3ac3fdc [qfcc] Clean up some int/bool/nullptr cruft 2024-11-04 12:29:30 +09:00
Bill Currie
9d7680228c [qfcc] Attempt to generate code for functions
It sorta kinda works, but there's a lot of bugs, and a lot more stuff to
implement, and the result doesn't pass validation yet.
2024-11-03 23:45:54 +09:00
Bill Currie
04560f61a6 [qfcc] Separate out backend variable declaration
This time, rua/v6p/v6 share the code properly, since it's only spirv
that needs something specific at this stage.
2024-11-03 18:06:25 +09:00
Bill Currie
88c67b3575 [doc] Update doxygen config via doxygen
Also, fix some missing docs. Unfortunately, there are still some
problems (incorrect resolution for multiple files/functions with the
same name, and a bug with doxygen's verbatim/code blocks).
2024-11-03 16:58:10 +09:00
Bill Currie
c8fbb93424 [qfcc] Separate out backend function building
It turns out that emit_function should have been (something like)
build_code and had the stack/locals related code taken along with it.
2024-11-03 16:58:10 +09:00
Bill Currie
a22d2a9526 [qfcc] Move guts of emit_function to per-target code
Ruamoko and v6(p) have their own copies despite being (currently) the
same, and spir-v's is currently empty, but now targeting spir-v doesn't
try to emit ruamoko code.
2024-10-26 23:30:37 +09:00
Bill Currie
95eaa4c65e [qfcc] Implement 64-bit bool
I'm not certain it's what I want, but this fixes the double.r test which
began failing with the non-scalar unary ops change.
2024-10-26 22:16:02 +09:00
Bill Currie
8ac4716f67 [qfcc] Return correct type for non-scalar unary ops
At least, for non-constants. Constants are still broken (badly,
actually).
2024-10-26 13:44:49 +09:00
Bill Currie
295cc0e0b2 [qfcc] Make non-const params references for spir-v
The whole reason for the reference work.
2024-10-26 13:33:39 +09:00
Bill Currie
af42b8e221 [qfcc] Support references in expressions
While a reference var can't be initialized yet, using them seems to work
in that they get dereferenced when the value needs to be read or written
(though I haven't seen any generated code for them yet).
2024-10-26 13:33:18 +09:00
Bill Currie
6db1942bb1 [qfcc] Make max_params a code option
Rather than relying on progsversion (I think this also fixes a bug with
max params when targeting ruamoko).
2024-10-11 10:01:45 +09:00
Bill Currie
f3181d64d0 [qfcc] Remove strange split in function arg handling
I don't know why the last argument was handled differently. I suspect it
was a hold-over from before I added list handling. Removing it seems to
have made no significant difference (all tests pass still).
2024-10-10 19:17:24 +09:00
Bill Currie
d72113f5cb [qfcc] Select correct generic function for references
When the parameter is a reference, implicit casting is not allowed, but
when the parameter is by value and the argument is a reference, the
argument is dereferenced and promotion is allowed.

However, this covers only the selection of generic functions. It doesn't
deal with otherwise overloaded functions, nor does it do the actual
dereferencing or address taking.
2024-10-09 13:33:38 +09:00
Bill Currie
421796b9ea [qfcc] Unalias type before checking for pointer/reference
Before adding references, looking at just type.type was ok whether or
not the type was an alias, but checking the deref flag needs the type to
be basic and not alias.
2024-10-09 11:31:00 +09:00
Bill Currie
a61e20ab20 [qfcc] Add parameters to spir-v function scopes
Simple functions now get to the code-gen phase (where they fail since
it's the wrong for other reasons). Parameter types aren't right for
spir-v yet as non-const params need to be references.
2024-10-08 11:58:24 +09:00
Bill Currie
9cd480640d [qfcc] Defer return expressions 2024-10-08 11:46:52 +09:00
Bill Currie
c3f11ba754 [qfcc] Add basic (type) support for references
I realized that spir-v pointers are essentially references (the way
they're used) since OpVariable requires a pointer type rather than the
base type. Thus, under the hood, references are just pointers with
automatic dereferencing. However, nothing uses references yet, and I
expect to run into issues with is_pointer vs is_reference vs is_ptr
(high-level pointer, reference, low-level pointer, respectively).
2024-10-08 11:45:51 +09:00
Bill Currie
dc878dbb4c [qfcc] Skip scope creation for function bodies
Since begin_function creates the parameter and locals scopes, there's no
need for another scope for the function body. This fixes the detection
of shadowed parameters for Ruamoko and QuakeC.
2024-10-07 09:55:21 +09:00
Bill Currie
3c7bd275f3 [qfcc] Detect shadowed parameters in glsl
Unfortunately, it breaks detection in Ruamoko and QuakeC.
2024-10-07 09:51:03 +09:00
Bill Currie
dae442c91e [qfcc] Move function scope building into target
This nicely separates Ruamoko and V6p function scope creation, and then
makes spir-v's a no-op (for now).
2024-10-07 09:48:44 +09:00
Bill Currie
0bc58246b1 [qfcc] Add a passing test for shadowed params
It's currently passing for Ruamoko, but glsl doesn't catch shadowed
params. There's a bit of a conflict and I want to make sure I don't lose
the checking.
2024-10-07 09:29:14 +09:00
Bill Currie
0cf8e7cb41 [qfcc] Start properly separating target code
I'd gotten tired of all the convoluted progs version checks, and with
the addition of spirv, they're not even always relevant, and adding C
(when I get to it) will make things even worse. However, for now the
first victim is just the parameter/return value size check.
2024-10-06 14:29:02 +09:00
Bill Currie
d46620fcf4 [qfcc] Add declaration expressions
Now declarations can be deferred too, thus things like generic/template
and inline functions should be possible. However, the most important
thing is this is a step towards a cleaner middle layer for compilation,
separating front-end language from back-end code-gen.
2024-10-04 11:51:34 +09:00
Bill Currie
8b9333e108 [qfcc] Remove union hack for block expressions
I don't remember why I thought it was a good idea at the time, but I
decided that having the union was a bit iffy and making the list
"official" would be a good idea. In the end, it removed a nice chunk of
code (redundant list manipulations).
2024-10-03 19:11:49 +09:00
Bill Currie
dcd2505bb9 [qfcc] Align cast operands
I'm surprised alignment didn't bite me earlier. Fixes a surprise
segfault in vecconst.r.
2024-10-03 19:11:49 +09:00
Bill Currie
8853d56af3 [qfcc] Ensure only one type def for functions
Only aggregate types are allowed to have duplicate type definitions. It
seems I forgot to do the id check for function types.
2024-10-02 02:12:07 +09:00
Bill Currie
56f8e19f63 [qfcc] Implement specialization constants
And they even pass validation (though it turns out there's a bug in
glslangValidator regarding specialization constants with expressions (or
possibly spirv-val, but it seems to be the former as my bug report shows
signs of activity in that direction)).

https://github.com/KhronosGroup/glslang/issues/3748
2024-10-02 02:11:53 +09:00