Commit graph

3773 commits

Author SHA1 Message Date
Bill Currie
d05fcecae4 [qfcc] Handle storage blocks for parameters
Klik is the only code base that uses them, so the param storage class
check got confused by them.
2025-01-18 20:48:40 +09:00
Bill Currie
df04a37a8c [qfcc] Count terms correctly
Parentheses confused the term counting because they weren't taken into
account for the "neither expression can be split" check, resulting in a
later segfault due to walking off the end of the array.
2025-01-18 20:47:06 +09:00
Bill Currie
7dc1ab0ea8 [qfcc] Split up shift ops by target
v6 can't do shifts at all, and rua/spir-v can do only integral shifts.
2025-01-18 20:44:55 +09:00
Bill Currie
77158130ca [qfcc] Flush dags aggressively for if statements
I'm sure there are more places that need flushing, but this gets
game-code/quakeworld building.
2025-01-18 20:36:23 +09:00
Bill Currie
fd52c055e0 [qfcc] Default math.vector_mult correctly
The check was bogus in that it had `!val == 0` for non-traditional, and
was checking the wrong spot for traditional.
2025-01-18 20:36:23 +09:00
Bill Currie
2c204d40b2 [qfcc] Check const_initializers option for constexpr
This is probably not right for spir-v, but it fixes initialized defs in
switch case labels (qc legacy with the defs).
2025-01-18 20:36:23 +09:00
Bill Currie
2cf14e13ec [qfcc] Process state frame and step expressions
Just a victim of the deferred processing. `think` can't be processed
because it can act as a forward declaration (qc legacy).
2025-01-18 15:24:46 +09:00
Bill Currie
3881147210 [qfcc] Check return value for null in has_function_call
Avoids a segfault when dagging. I'm not sure how a switch statement got
into the dags, but still don't want a segfault there.
2025-01-18 15:23:37 +09:00
Bill Currie
8d69dd85eb [qfcc] Allow some mixing of vector/quaternion types
That is, vector ops with 3-component general vectors and quaternion ops
with 3 and 4 component general vectors "promote" the general vectors to
vector or quaternion as appropriate. Needed for operations with
vector and quaternion literals.
2025-01-18 15:20:59 +09:00
Bill Currie
1950c03195 [qfcc] Promote types for bitops
Bitops are allowed for float operands in quakec and ruamoko (not glsl,
but meh for now). Fixes another ice in game-source/quake.
2025-01-18 14:13:40 +09:00
Bill Currie
92727019b5 [qfcc] Split up vector/quaternion compare by target
The v6 and v6p targets don't have horizontal operations, instead they
have direct vector/quaternion equality to float/int scalar result. Fixes
an ice when building game-source/quake.
2025-01-18 14:06:27 +09:00
Bill Currie
a5272d2e05 [qfcc] Hook spir-v operand kinds into intrinsic scopes
The operand kinds form namespaces for their enumerants (only BitEnum and
ValueEnum operand kinds are supported for this). Now `Lod` and `Bias`
use `ImageOperands.Lod` and `ImageOperands.Bias`, which is probably a
big improvement in the long run.

Finally, all of QF's shaders *compile*, though the spir-v is generally
incorrect (capabilities etc), and the code gen may still be full of
bugs.
2025-01-18 13:15:05 +09:00
Bill Currie
a4acfc30d7 [qfcc] Implement shadow coord/comp extraction
This took sorting out a few issues with type property evaluation, but it
seems to work nicely now. Just one known error to sort out and then it's
time to get the spir-v correct.
2025-01-18 11:59:05 +09:00
Bill Currie
42f1f39329 [qfcc] Support subpassInput for image_coord
Easiest to special case it since tex_coord uses the same dim_widths
array.
2025-01-17 22:18:49 +09:00
Bill Currie
1a019ad818 [qfcc] Use the param scope for explicit intrinsics
Explicit intrinsics are very similar to inline functions, so the
function data for generic explicit intrinsics functions also need a full
scope. Fixes the undefined symbols for generic type names.
2025-01-17 22:12:38 +09:00
Bill Currie
c48fe5e7f5 [qfcc] Handle explicit arguments to intrinsics
There are problems with symbol lookup (eg, generic type names, image
operand names) but the system seems to be working: texelFetch ->
OpImageFetch (which uses explicit arguments even though it doesn't need
to) seems to set the arguments to OpImageFetch correctly.
2025-01-17 18:14:21 +09:00
Bill Currie
393ef8f455 [qfcc] Define the geometry functions
Now all my glsl shaders build, though most likely none of them
correctly. However, I'm finally out of that tunnel... only to find
myself in a moonlit forest fill with the sounds of wolves (at least, I
hope they're wolves).
2025-01-17 11:56:54 +09:00
Bill Currie
7bbe0d991b [qfcc] Declare block instance arrays correctly
I think this was broken by the deferred type processing, but now my
geometry shaders try to emit code (fail due to missing function
definitions).
2025-01-17 11:52:45 +09:00
Bill Currie
3e32ce4caf [qfcc] Improve error checking for arrays
The checks had been lost with the move to deferred semantics. Fixes an
internal error when trying to index a non-array-compatible object.
2025-01-17 11:29:06 +09:00
Bill Currie
8e5fd85c0f [qfcc] Default fp constants to float for glsl
And support `lf` for double constants (always: I don't see the harm
other than minor confusion with C, but Ruamoko isn't C).
2025-01-16 18:02:44 +09:00
Bill Currie
e0e168620f [qfcc] Rename type attributes to properties
I had a feeling that attribute was wrong at the time, then I got
reminded of properties.
2025-01-16 17:31:04 +09:00
Bill Currie
6ff1704246 [qfcc] Implement min and the pack/unpack functions
Well... at least as far as marking the intrinsics. Still need to
implement parameterized intrinsics.
2025-01-16 17:18:17 +09:00
Bill Currie
1a1bbfd03a [qfcc] Detect interface blocks
This gets the `offset` layout working for block members.
2025-01-16 17:17:13 +09:00
Bill Currie
456594a4fe [qfcc] Implement many glsl functions
All was fine... until the texture handling. Ugh, what a mess: 16
variants of "texture", times all the sampler variants. And I haven't
done even half of them.
2025-01-15 18:48:25 +09:00
Bill Currie
2aadb23a35 [qfcc] Move image attribute stuff out of glsl-parse
I won't say it belongs in glsl-builtins, though the glsl-specific stuff
probably does (glsl texture handling is a mess). Also adds sampler
attribute handling (which falls back to image when necessary).
2025-01-15 18:48:25 +09:00
Bill Currie
2c29dcd7d9 [qfcc] Allow more control of intrinsic functions
If `@intrinsic()` is followed by `[expr_list]` then those expresses will
be used to create the intrinsic rather than the function's parameters,
allowing for reordering, adding extra parameters or even complex
expressions.

However, only the parsing is implemented.
2025-01-15 18:47:56 +09:00
Bill Currie
92b476bf04 [qfcc] Make type attribute functions usable in expressions
Unfortunately, this require using different syntax for the two cases:
type.attr works in cases where types are expected, but not in
expressions (lots of shift/reduce and reduce/reduce conflicts). However,
treating type like an Objective-C class works nicely, though
`[type attrib(params)]` looks a little odd. However, this allows using
generic types to provide function calls (eg, converting texture
coordinates).
2025-01-15 18:31:37 +09:00
Bill Currie
351136a636 [qfcc] Fix a few segfaults compiling glsl 2025-01-15 18:23:25 +09:00
Bill Currie
376f8f2c09 [qfcc] Check rows/columns for type promotion
There's no automatic type promotion between scalars, vectors or matrices
of different component counts.
2025-01-14 13:20:12 +09:00
Bill Currie
2f3097aed7 [qfcc] Fix the subpassLoad functions
I had forgotten that subpassInput can't be used but the normal imageLoad
functions since they don't (and mustn't, by the spec) have subpassInput
as a possible type. While creating a specialized version works, I think
I need to come up with a better way of specifying intrinsics.
2025-01-14 01:27:11 +09:00
Bill Currie
341504261a [qfcc] Get the abs functions working
Well... probably (again, build issues).
2025-01-14 01:27:11 +09:00
Bill Currie
64bbdbda44 [qfcc] Fix up the atomic functions
It seems the base atomic functions should use const for the data
parameters and just a reference for the mem parameter (not entirely sure
yet as I need to check with spirv-val, but there are still build
issues). Using __imageTexel correctly took a little thinking since it
returns a pointer but the atomic functions take a reference.
2025-01-14 01:27:11 +09:00
Bill Currie
88253a847b [qfcc] Support type inference for spir-v
I guess I hadn't thought of it because GLSL doesn't have `auto`, but
since the builtin functions are implemented in Ruamoko, `auto` is
available and I use it for the atomic image functions.
2025-01-14 01:27:11 +09:00
Bill Currie
9ba335f91e [qfcc] Use maximum cost for non-matching param counts
I had missed this so such cases wound up with a cost of 0 resulting in
bogusly ambiguous function calls (or possibly worse).
2025-01-14 01:11:19 +09:00
Bill Currie
17ae2b592c [qfcc] Support attributes on image types
And rename base_type to sample_type: I decided it was a better name as
it's "sampled type" in the spir-v spec.
2025-01-14 01:07:00 +09:00
Bill Currie
ed88152f85 [qfcc] Get type attribute working for computed types
It even handles errors :)
2025-01-14 01:02:31 +09:00
Bill Currie
041216182e [qfcc] Implement spirv instruction lookup
Yay, no more magic numbers for intrinsics :)
2025-01-13 21:38:35 +09:00
Bill Currie
9dca83d40a [qfcc] Fix some errors in subpassLoad
Used the wrong generic type name for gvec4*, and missed @construct. Now
gridplane.frag tries to generate spir-v again (fails due to the
instruction names).
2025-01-13 19:55:27 +09:00
Bill Currie
cb20153da5 [qfcc] Handle field expressions in compute_type
I'm not entirely sure how that got in there (I didn't check the
backtrace, but probably in @construct (before I realized I needed to add
@construct)).
2025-01-13 19:50:23 +09:00
Bill Currie
9dca372643 [qfcc] Compare parameter type compute programs
This allows generic parameters to be computed as well as the return
type (without segfaulting :P).
2025-01-13 19:48:22 +09:00
Bill Currie
c830bb55c3 [qfcc] Use default_type on generic spec
Needed for implied int return types (unsigned etc).
2025-01-13 19:46:35 +09:00
Bill Currie
388a1c6c28 [qfcc] Use names for spir-v intrinsic opcodes
Everything is smashed because the names aren't looked up yet, but
removing magic numbers is almost always a good thing.
2025-01-13 17:54:44 +09:00
Bill Currie
e0e3998efc [qfcc] Semi-implement some glsl layout attributes
They're still just stubs, but the error noise is down.
2025-01-13 17:52:15 +09:00
Bill Currie
b28cd673ae [qfcc] Prefer fixed types over generic
This allows the various vector,vector and vector,scalar to disambiguate.
2025-01-13 17:47:52 +09:00
Bill Currie
027ad12c72 [qfcc] Support add/sub for matrix/vector and scalar operands
GLSL needs it, and it's not entirely unreasonable (though I'll probably
add some flags to control it since it doesn't always make sense).
2025-01-13 12:52:12 +09:00
Bill Currie
320f9e2fe7 [qfcc] Support type.attribute on any type
The goal is to make it easy to get size/coord/base types from image
types without creating a zillion type functions.

It was necessary to make it possible for any type to have an attribute
function (returns an expression so it can be more useful: types are
returned via type expressions). Algebra types were the first victim
(which was nice for testing).
2025-01-13 00:10:27 +09:00
Bill Currie
e9eae1c75f [qfcc] Implement incop for SPIR-V
I think I got it right, but it's hard to tell because my shaders use ++
only for the iterator of loops so the result is thrown away.
2025-01-12 23:29:57 +09:00
Bill Currie
270c57e46e [qfcc] Support assignment into array elements in SPIR-V
Just a missed detection of needing to use access chains.
2025-01-12 23:29:57 +09:00
Bill Currie
42fc1323e1 [qfcc] Clean up glsl for loops
The changes for deferred semantics in Ruamoko broke for loops for GLSL,
but matching GLSL's structure to Ruamoko's cleaned things up nicely.
2025-01-12 23:29:57 +09:00
Bill Currie
7baf93c8df [qfcc] Make short-circuit boolean logic language dependent
And disable it for GLSL. I might need to make it target-dependent
instead as I don't know if I'll be able to implement it in SPIR-V, and
when I get to the C back-end, it will be superfluous.
2025-01-12 23:29:56 +09:00