Commit graph

14607 commits

Author SHA1 Message Date
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
Bill Currie
7742450e03 [qfcc] Do basic error checking on layout qualifiers
I'm not sure I got all the checks right, but bsp_gbuf.geom passes the
validity (but failes due to not having implemented the application of
the qualifiers).
2024-09-10 19:03:13 +09:00
Bill Currie
5d7a8127c2 [qfcc] Add is_handle type check function 2024-09-10 19:00:09 +09:00
Bill Currie
c58748d640 [qfcc] Implement many glsl qualifiers as attributes
Attributes seem appropriate as GLSL's qualifiers affect variables rather
than types (since there's no typedef).

Not much is done with the attributes yet other than some basic error
checking (duplicates of non-layout attributes) and debug output, but
most (if not all) declarations get to the declaration code with
attributes intact.
2024-09-09 20:01:06 +09:00
Bill Currie
ad3ae1abec [qfcc] Get true and false working in glsl 2024-09-09 11:47:01 +09:00
Bill Currie
2fc3a43e31 [glsl] Fix multiplication after addition
I'd goofed when transcribing the glsl grammar.
2024-09-09 11:42:30 +09:00
Bill Currie
7a2027276b [qfcc] Use a separate enum for glsl interfaces
While technically storage classes, they shouldn't pollute other
languages. It's a bit hacky mixing enums in one value, but having some
macros helps.
2024-09-09 11:40:57 +09:00
Bill Currie
c4c4b9f5b4 [qfcc] Make not a soft keyword
Its grammatical usage is such that it's unambiguous with identifiers,
and is needed for parsing the glsl functions (the not() function for
boolean vectors).
2024-09-07 02:42:32 +09:00
Bill Currie
13d38622f7 [qfcc] Copy parameter qualifiers when copying type
Fixes a segfault for some functions (generics?) cause by the new
parameter qualifiers.
2024-09-07 02:39:13 +09:00
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