Commit graph

4653 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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