Commit graph

14586 commits

Author SHA1 Message Date
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
addf877416 [vulkan] Correct a sign error in QFV_PerspectiveTanFar
Unfortunately, the function isn't used yet, so it's easy to miss. I just
happened to notice things didn't look right when looking at my
projection matrices.
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
bff709e71d [plist] Fix a purity issue in the json test
I guess I forgot to do a `make check` with optimized builds.
2024-10-26 23:34:55 +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
164c949796 [plist] Add a test mode to get parse timings
It turns out parsing runs at about 40-55MB/s, but that may be down to
allocations.
2024-10-19 02:19:01 +09:00
Bill Currie
d780146be3 [plist] Fix json parsing and test
It turns out my test was backwards: it fed the json text into a string
object then pulled it out, which of course round-tripped correctly. Now
things do round-trip correctly, but I had to ignore white-space
differences and edit the numbers as text->double->text doesn't
necessarily round-trip well (though double->text->double does with 17
digits).
2024-10-19 02:15:27 +09:00
Bill Currie
cb0eeb9366 [vulkan] Remove duplicate descriptor set layout
Don't need two identical descriptor set layouts for particles.
2024-10-19 00:28:27 +09:00
Bill Currie
427d239008 [simd] Fix uninitialized warning hidden by lto
It turns out lto was hiding an uninitialized warning that showed up with
gcc-14.
2024-10-17 11:03:03 +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
a0e4aa487f [ui] Pass text verticality and font to configure_textview
They're not actually used yet because all the calculations are giving me
a headache, but the improved handling of text direction in
Text_PassageView, along with passing the information, is important
enough, I think.
2024-10-10 14:09: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