Commit graph

14616 commits

Author SHA1 Message Date
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
Bill Currie
f4d8af400e [qfcc] Apply suspenders and a belt to the dimension check
Maybe there's a different trick to making gcc see that the dimension was
already check, but this works nicely size if the two calculations
differ, there are bigger problems.
2024-09-24 11:17:01 +09:00
Bill Currie
5a928581ab [vkgen] Fix parsing of actual bool types
Switching to native ruamoko bool for vkgen resulted in bool getting
incorrectly parsed as a string (which mean getting the string's address
written to the value). Fixes the randomly enabled debug pipelines (and
probably a few randomly disabled normal pipelines, though less likely as
they're usually implicitly initialized). The one bit of actual legit UB
(ie, that which wasn't immediately mitigated one way or another) found
by ubsan, and it was a data error.
2024-09-24 11:09:10 +09:00
Bill Currie
23e2fff44a [cexpr] Correct bool's backing value type
Using int instead of bool probably won't work well if QF ever finds
itself on a big-endian system again.
2024-09-24 11:07:32 +09:00
Bill Currie
c0f4a2143f [net] Always allocate memory for ifaces
Pointing ifaces at myAddr doesn't end well when nq exits (free doesn't
like it).
2024-09-24 11:04:27 +09:00
Bill Currie
6f03b4a65f [console] Use aligned malloc for menu progs
Fixes ubsan's (random!) complaints about memblock not being aligned. I
should probably look into making the progs loader code ensure the memory
is aligned itself.
2024-09-24 10:58:47 +09:00
Bill Currie
399c0ec17f [zone] Use a static_assert for retain's offset
I'd written the old version long before static_assert was available in
C.
2024-09-24 10:57:01 +09:00
Bill Currie
867e49980f Fix some dodgy shifts
While I guess ubsan is right that shifting a 1 bit into the sign of an
int can cause problems, but that's assuming the int is numeric. And it
doesn't help that unsigned char promotes to int instead of unsigned int.
2024-09-24 10:54:17 +09:00
Bill Currie
e3d403cada [vulkan] Mark read-only buffers as such
Recent vulkan validation layers started complaining about vertex
processing stages having read-write buffers without atomics enabled
(fair enough), but I decided to get all the buffers that don't need to
be written.
2024-09-24 10:44:59 +09:00
Bill Currie
594ba86aae [qfcc] Start emitting spir-v expression instructions
They're currently wrong since they're meant to be for specialization
constants (and that whole system is currently broken anyway) but are
instead raw code expressions, but progress is progress.
2024-09-23 18:56:18 +09:00
Bill Currie
5c9ba80d3a [qfcc] Rewrite unary_expr to be more maintainable
Result type and constant handling is now table-driven, resulting in the
removal of seven switch statements (and thus a lot less hassle when
extending types or expressions). Also, (u)long and (u)short are fully
implemented.

In addition, other than result type handing for boolean results, any
back-end specific implementation is now in the back-end.
2024-09-22 16:21:21 +09:00
Bill Currie
f5d3507819 [qfcc] Split out unary_expr to its own file
The plan is to clean up unary_expr like binary_expr.
2024-09-22 12:44:12 +09:00
Bill Currie
8099c4cf8e [qfcc] Support the idea of constexpr
It's nowhere near complete, but unary and binary expressions that are
marked as constant will not be subject to constant folding. This is
necessary for proper support of specialization constants.
2024-09-22 12:28:37 +09:00
Bill Currie
e7710bb7ac [qfcc] Give symtabs a name field
It's currently just to help with debugging now that I've got more
less-random symtabs floating around.
2024-09-21 23:09:38 +09:00
Bill Currie
6e4812f914 [qfcc] Mark symbols as being lvalue or not
This simplifies things a lot and fstrianglest.vert compiles again
(albeit incorrectly).
2024-09-21 22:08:51 +09:00
Bill Currie
753e21f56a [qfcc] Add inout expr dot output 2024-09-21 17:18:38 +09:00
Bill Currie
2c445380b1 [qfcc] Emit extensions and extinst imports
The imports need their result id recorded somewhere (and the hard-coding
in qc-parse.y removed), but that's a little bit of progress getting
spir-v working.
2024-09-20 14:03:03 +09:00
Bill Currie
e09f97685f [qfcc] Avoid ubsan related warning with lto
I'm not sure what's up (I doubt it's actually ub, it's just that it took
enabling ubsan *and* link-time-optimizations to see the warning), and
the warning is technically correct, though going from -1 (int) to
0xfffffff400000000 has me stumped, but ensuring width is 2-4 does take
care of it. All because I got a weird test failure that I wound up being
unable to reproduce after rebuilding qfcc (thus the ubsan pass, but no
other sniffles).
2024-09-20 13:30:28 +09:00
Bill Currie
186a781121 [qfcc] Allow single-constant attribute values
I don't remember why I though requiring a parameter list was a good
idea, but it makes working with attributes harder than it needs to be.
2024-09-20 12:28:02 +09:00
Bill Currie
1117d31b30 [qfcc] Make some sideways progress with layouts
I'm not sure it's the right directly, and qfcc's internals are starting
to show their age.
2024-09-20 12:24:51 +09:00
Bill Currie
34fc2108ea [qfcc] Use separate symbol types for def and offset
I don't know why I thought it was a good idea to make sy_var context
dependent. Renaming sy_var to sy_def makes it a little easier to know to
use the def field, too.
2024-09-20 11:39:16 +09:00
Bill Currie
6ca06a577a [qfcc] Make capabilities and memory model configurable
While I'm not happy with the module "creation" (at least it's limited to
two places), setting it up with spir-v capabilities and memory model
seems quite nice and should play nicely with being set up from within
source code, though using uint constant expressions might be overkill.
2024-09-20 01:39:44 +09:00
Bill Currie
2768606f1d [set] Allow a set pool to be cleaned up
In the end, I couldn't use it (due to needing to hold onto the sets),
but it balances the init.
2024-09-19 12:22:46 +09:00
Bill Currie
e477148a9b [qfcc] Improve spir-v type emission
A few more types and function parameters are set up more or less
correctly (however, the pointer storage class is hard-coded for now:
need to add attributes to everything).
2024-09-18 15:12:57 +09:00
Bill Currie
7931eb8c03 [qfcc] Disable varargs for spirv
I'm not certain supporting varargs in spirv is impossible, but being
able to disable it might be worthwhile anyway.
2024-09-18 14:33:02 +09:00
Bill Currie
ee3a9bd200 [qfcc] Start work on emitting SPIR-V
It's rather non-functional but does so far pass validation via
spirv-val. However, it's showing that qfcc's internals need a lot of
work.
2024-09-17 16:47:19 +09:00
Bill Currie
9b49ede47d [build] Update pkg.m4
Our copy was rather ancient and a little buggy.
2024-09-17 16:29:05 +09:00
Bill Currie
d4c78a69f4 [qfcc] Fix uninitialized zero in component_compare
It was a bit of a surprise seeing a test case fail and then succeed
after making a minor edit to help find the bug, but valgrind to the
rescue. I'm surprised nothing showed up earlier.
2024-09-15 15:02:36 +09:00
Bill Currie
9cd8bc0d45 [qfcc] Move type encoding defs into an array
This allows the defs to be updated without having to modify the type
struct itself, and also allows for alternative encodings (eg, spir-v).
2024-09-15 12:05:57 +09:00
Bill Currie
c7e35994b5 [qfcc] Give type_t objects unique id indices
This allows indexing into arrays or sets of all types, good for various
mutable information.
2024-09-15 10:29:36 +09:00
Bill Currie
7b9dc3c878 [plist] Add support for parsing and writing JSON
It seemed like a good idea since vulkan and gltf resources use JSON.
However, plist and json parsing and writing are separate: there's no
auto-detection for parsing, and the appropriate function must be used
for writing (though reading one then writing the other will work, but
may result in some information loss, or even invalid json (binary)).

Escape characters aren't handled quite to spec yet (eg, no \uxxxx).

The tests are pretty lame, but they're taken from rfc7159 and round-trip
correctly (which is a surprise for the fp numbers).
2024-09-14 18:59:48 +09:00
Bill Currie
edc03c22f9 [dstring] Ignore embedded nulls for appendstr
I don't remember why I thought it was a good idea to respect embedded
nul characters, but doing so makes appendstr O(N) instead of O(1) (or
O(N^2) instead of O(N) for multiple appends of n chars (N = sum(n)).
Also, this makes appendstr consistent with dasprintf.
2024-09-14 17:12:01 +09:00
Bill Currie
4329537b1b [dstring] Implement reserve
In the end, I'm not sure when I'll use it, but at least the expected
semantics are there.
2024-09-14 16:20:14 +09:00
Bill Currie
ebaa557d2a [dstring] Rename reserve to open
I've decided that I want reserve to mean only allocate backing memory,
not modify the size of the string, but I didn't want to rework much code
in the process. I might eventually get right of the open functions, but
I wouldn't be surprised if that's another decade or two in the future.
2024-09-14 15:51:41 +09:00
Bill Currie
e933eb8fae [qfcc] Clean up expr parenthesis setting
Thare are still many const casts, but this does get rid of one set. I
had tried to replace the paren flag with a () unary expression, but that
brought out a whole pile of places that had problems (especially
anything to do with boolean expressions).
2024-09-14 08:31:26 +09:00
Bill Currie
4c603c3989 [qfcc] Remove rvalue flag from expr_t
It seems it was needed for dealing with the result expression for block
expressions, but it turns out (possibly thanks to dags), that it's easy
to check for the result value and using the appropriate call to emit the
code thus avoiding the non-executable code warning.
2024-09-13 21:41:40 +09:00
Bill Currie
3f66dc1164 [gamecode] Use only scalar types for basic encodings
I'm surprised other types weren't affected, but vec4's ecoding was being
picked up for float. Thankfully, all that was needed was checking width
and columns.
2024-09-13 21:25:57 +09:00
Bill Currie
cd051e8f9f [qfcc] Check handle types correctly
They can have a variety (min int and long) of backing types, so
requiring ev_invalid (which is used for struct and union).

Also, ensure is_int etc fail for handle types.
2024-09-12 14:10:44 +09:00
Bill Currie
355ee12c3f [qfcc] Give qfo spaces support for names
Fortunately, there was a reserved spot that could be used for the name
thus no need for a version update. The name isn't used yet but will be
for glsl support.
2024-09-12 13:50:33 +09:00
Bill Currie
99be6f6e41 [qfcc] Build namespaces for non-instanced blocks
Each interface type (in, out, uniform etc) gets its own namespace, and
non-instanced blocks get a namespace (their block name) within the
interface namespace.

The defs for the block members are currently "allocated" to be at offset
-1, but the idea is to allow layout qualifiers to know if the member has
already been located.
2024-09-12 13:33:42 +09:00
Bill Currie
1dc31f83af [qfcc] Implement namespace lookups
I don't know if they work correctly yet (because other areas are
incomplete), but they seem to do the job (at least no segfault).
2024-09-12 12:38:39 +09:00
Bill Currie
db39fdbe37 [qfcc] Create glsl block before parsing members
This allows attributes to be put on the block before members are
declared thus giving member attributes to override block attributes when
appropriate.
2024-09-12 12:14:10 +09:00
Bill Currie
f7f2790937 [qfcc] Use macro magic for the symbol type enum
I found that I'd missed an update or two of the names array.
2024-09-12 12:14:02 +09:00
Bill Currie
b1f4fc3131 [qfcc] Allow ~ on all int types.
I really need to revamp the unary operator code.
2024-09-11 17:33:13 +09:00
Bill Currie
224d1fd5f5 [qfcc] Fix misspelled compute shader name
And a gcc purity check.
2024-09-11 17:32:13 +09:00
Bill Currie
c038670114 [gatest] Add a commutesWith method to blades
It came about from a discussion in the bivector discord about
programmatic testing for blade commutativity and why no texts talked
about it. I came up with an idea that turned out not to work (I guess
I'd overthought how count_flips works). In the end, I decided to keep
it, and simplified metric's sign check.
2024-09-11 17:25:38 +09:00
Bill Currie
f0e770b972 [qfcc] Allow aligned despace allocs to be overridden
GLSL (and in the end, spir-v) needs more control over allocation than
does the Ruamoko VM.
2024-09-10 20:44:51 +09:00