Commit graph

14712 commits

Author SHA1 Message Date
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
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
e7401c5ff4 [vulkan] Regenerate mips for transparent textures
BSP textures have pre-generated mips, including the transparent
textures, but mips don't play nicely with the transparency color (255):
it gets blended to other colors (at least in ad tears). Regenerating the
mips from the rgba texture (using transparent black) produces nice
results.

Also, needed to discard on 0 alpha to avoid weird interactions with fog
(I didn't know ad tears had fog: I guess I had last loaded it before
implementing fog).
2024-10-04 22:10:08 +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
Bill Currie
a7639a685e [qfcc] Add field and array expression types
And implement enough AST processing to compile fstrianglest.vert

Plenty of code-gen issues, though.
2024-10-02 02:01:33 +09:00
Bill Currie
feca9bd5cb [qfcc] Rename new_field_expr to new_deffield_expr
I want to use new_field_expr for specialized field expressions instead.
However, I don't particularly like new_deffield_expr as a name, but I
can't think of anything better just yet.
2024-10-02 01:52:34 +09:00
Bill Currie
5a9ef35199 [qfcc] Add constexpr initializers to the ctor list
So far, this affects only glsl (because only glsl marks expressions as
constexpr), but it does get specialization constant initializers for
global variables working.
2024-10-01 17:10:00 +09:00
Bill Currie
f73e1bf353 [qfcc] Move ctor creation out of class_finish_module
Now, ctor expressions are collected and emitted after all other code,
and the ctor function being created outside of class_finish_module means
it's no longer limited to just class related initialization.
2024-10-01 16:51:49 +09:00
Bill Currie
3af078628e [qfcc] Preserve symbol expressions when constexpr
This prevents them from getting folded out of existence and thus
impossible to specialize.
2024-10-01 14:42:30 +09:00
Bill Currie
491b612888 [qfcc] Avoid (null) labels for dot graphs
I got tired of seeing it when looking at debug dumps of expressions.
2024-10-01 14:30:09 +09:00
Bill Currie
fc4e8cb350 [qfcc] Switch to deferred expressions for glsl
I plan to do this eventually for Ruamoko, but I need it to keep working
for now; it's rather nice having multiple languages. I expect this will
open up a lot of options for inlining, generic/template function
instantiation, etc. Right now, it's helping with specialization
constants in glsl.
2024-10-01 14:30:09 +09:00
Bill Currie
a97fc8154a [qfcc] Set all the commutativity flags
Including anti-commutativity. I hadn't set them before because I was
uncertain and got conflicting answers, but when I took a look again, it
seems IEEE 754 does guarantee commutativity for multiplication and
addition, so long as NaN isn't involved (and then it seems to be because
`a==a` is always false when a is a NaN).
2024-09-30 19:23:37 +09:00
Bill Currie
eade7e9a85 [qfcc] Add anti-commutative flags for cross and fp sub
They're still not set, but the commutativity can be adjusted
individually.
2024-09-30 19:23:37 +09:00
Bill Currie
275201afdf [qfcc] Optimize negating anti-commutative operations
Both for geometric algebra and in general (since it's just in
unary_expr). However, it doesn't quite work for float stuff (eg,
`vector × vector`, but that's only because the anti-commutative flag
isn't set.
2024-09-30 19:23:37 +09:00
Bill Currie
9797dcb5de [qfcc] Optimize (a+a)/2 in geometric algebra expressions
Really, I need to look into getting the optimizations more general, but
`a × ⋆a` is now just a single cross product instead off cross, add and
divide.
2024-09-30 19:23:37 +09:00
Bill Currie
b00d4d3b5b [qfcc] Respect parentheses when scattering sums
It may not be ideal at all times, but it does conform better with
general requirements for floating-point math.
2024-09-30 13:51:52 +09:00
Bill Currie
91febd50c6 [win] Fix some bitrot for building
Needed an option to disable LTO, and a couple of errors that crept in
with preprocessor and vulkan improvements.
2024-09-24 19:49:41 +09:00
Bill Currie
46a0be837e [vulkan] Check qfv_matrix_buffer_t size
Instead of forcing it via unnecessary alignment. I didn't feel like
using aligned malloc to silence ubsan when really the alignment was just
to force the size to be aligned.
2024-09-24 11:35:22 +09:00
Bill Currie
83c65e6abd [vulkan] Deal with some ubsan complaints
One is potentially legit (depends on what really happens when allocating
0-length arrays on the stack), but the offset null pointer ones are
dubious as `a` should never be null when `size` is non-zero, and when
`size` is zero, everything gets corrected.
2024-09-24 11:31:36 +09:00
Bill Currie
9713e7764c [input] Plug some potential UB
More "null pointer but zero size", but with library code, who knows?
2024-09-24 11:28:59 +09:00