Commit graph

14439 commits

Author SHA1 Message Date
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
Bill Currie
b59a8fb66a [qfcc] Add a code generator for type expressions
Allows the parsing of the return type in the following:

    @generic(vec=[vec2,vec3,vec4]) {
    @vector(bool,@width(vec)) lessThan(vec x, vec y);
    }

Unfortunately, can't use math in int value parameters just yet, the
processing of expressions needs to be delayed (it's currently done
immediately so type-checking happens to early).

It's not connected up yet, but does produce what looks like the correct
code.
2024-09-06 01:04:38 +09:00
Bill Currie
55d7d1f069 [qfcc] Expose convert_op and ensafen free_operand
Needed for type evaluation codegen, and free_operand needs to be
null-safe.
2024-09-06 01:04:38 +09:00
Bill Currie
9c902501d7 [qfcc] Move D_* macros to def.h
Finally, after way too long.
2024-09-06 00:56:56 +09:00
Bill Currie
1f3b21a626 [qfcc] Use a temp for size-changing swizzles
The Ruamoko instruction set has only same-size swizzles, so a staging
temp is needed either before (grow) or after (srink) the swizzle.
Unfortunately, it looks like there might be missed optimization issues,
but at least things seem to be correct.
2024-09-05 14:26:29 +09:00
Bill Currie
24a48ad703 [qfcc] Improve support for matrix types
Their size is now calculated correctly, they can be assigned,
initialized using block initializers (vectors too!), and columns can be
indexed as vector lvalues.
2024-09-05 14:06:30 +09:00
Bill Currie
e9d5bac369 [gamecode] Support debug print of matrices 2024-09-05 13:16:22 +09:00
Bill Currie
698d27c996 [gamecode] Save all param pointers with PR_SaveParams
Builtins calling other functions that call back into progs can get their
parameter pointers messed up resulting in all sorts of errors. Thus wrap
all callbacks to progs in PR_SaveParams/PR_RestoreParams.

Also, ditch PR_RESET_PARAMS in favor of using PR_SetupParams and move
setting pr_argc into PR_SetupParams.
2024-09-05 00:00:44 +09:00
Bill Currie
e35bff066f [vulkan] Fix more sync issues
Thanks to validation layers showing command buffer debug regions, it was
pretty easy to find the offending buffers. Did need to modify
QFV_PacketCopyBuffer to take a source barrier as well as the destination
barrier, but this is probably for the best.
2024-09-04 17:47:04 +09:00
Bill Currie
bc22cd3255 [vulkan] Mark more command buffer regions
Now all pipelines and any tasks that have a command buffer attached get
a region using their names (tasks use the function name). I don't know
when it happened, or if I failed to notice last time, but (sync)
validation layers now include the debug region for command buffers: very
nice.
2024-09-04 17:34:01 +09:00
Bill Currie
f6d2cf43e8 [qfcc] Parse about 2/5 of the glsl functions
They're stuck on computed return types causing segfaults, but the rest
helped with ironing out other issues in the compiler.
2024-09-04 10:43:11 +09:00
Bill Currie
3aab301d45 [qfcc] Check receiver type a second type
The old "expr changed type to error" trick hasn't worked for a while, so
sending a message to an undefined class didn't end well.
2024-09-04 10:37:26 +09:00
Bill Currie
8db547afec [ruamoko] Remove hack-in matrix type
No need for it now, either.
2024-09-04 10:36:32 +09:00
Bill Currie
fe16fed01a [vulkan] Update vkgen for the newly added bool type
I had forgotten about this, and ironically it's just one field in all of
vkparse, but adding support for bool to vkgen was easier than expected.
2024-09-04 10:33:10 +09:00
Bill Currie
83b92dd067 [qfcc] Handle fixed return types in generic functions
More segfaults, wee.
2024-09-04 09:58:14 +09:00
Bill Currie
8f9785c3da [qfcc] Handle type function parameters in type functions
The code assumed an actual type reference, not a type function,
resulting in a segfault for `@vector(bool,@width(vec))`.
2024-09-04 09:54:29 +09:00
Bill Currie
cd7abf5320 [qfcc] Add bool and matrix types to ruamoko
They're not properly implemented, but they do at least parse, so they
can be used in declarations (just not expressions yet).
2024-09-04 09:50:00 +09:00
Bill Currie
64334759f4 [qfcc] Support multiple type specs in type_ref
This is needed for `unsigned int` or `unsigned long` in type
expressions. However, there is a problem where @vector etc complain
about just `unsigned` (which should default to int, of course).
2024-09-04 09:41:57 +09:00
Bill Currie
65fc6054bb [qfcc] Actually parse ruamoko from strings
The previous related commit was just the basics and only glsl used it,
now ruamoko itself does (really need to look into namings: qc is a bit
off).
2024-09-04 09:35:25 +09:00