Commit graph

14782 commits

Author SHA1 Message Date
Bill Currie
1f0d7f249c [qfcc] Move countof macro to qtypes
It makes it more accessible and easy to remove when it (or equivalent)
becomes standard in C.
2025-01-20 15:02:21 +09:00
Bill Currie
0ecd8f06bd [cexpr] Add support for long and ulong types
As int64_t and uint64_t. This gets everything building again.
2025-01-20 14:22:44 +09:00
Bill Currie
ea1c0a012b [cexpr] Correct size_t op types
I probably missed changing those unsigned types to size_t. Yay
case&paste programming :P
2025-01-20 14:18:31 +09:00
Bill Currie
1e052ad0dc [vkgen] Use correct types for 64-bit types
When I wrote vkgen's stdint.h, qfcc didn't support long or ulong, and
with the common init check, it now matters that the correct types are
used. It turns out some of my structs may not have been initialized
correctly, but with the next commits (long and ulong for cexpr), they
should be but do seem to be working at least.
2025-01-20 14:18:15 +09:00
Bill Currie
97a0763766 [qfcc] Do initializer type checking in declare_symbol
This is a nice common place (all languages and targets use it) for the
warning and any conversions, though those are still spread in various
places (and need to be cleaned up), so it doesn't do all that much yet.
2025-01-20 14:08:36 +09:00
Bill Currie
133156fdc7 [qfcc] Use OpBitcast for alias exprs in spirv
Really, just implementing it properly.
2025-01-20 14:04:19 +09:00
Bill Currie
54231b21ed [qfcc] Add an is_auto helper function
It's cleaner than type == &type_auto and will allow me to check that
`auto` hasn't been aliased or something like that.
2025-01-20 12:26:57 +09:00
Bill Currie
a922088c1c [qfcc] Correct explicit lod's 0
It needs to be a float, not an int.
2025-01-20 11:42:25 +09:00
Bill Currie
16b04512cb [qfcc] Support marking expression for the back-end
The spir-v back-end needs to emit literal values in some places and
supporting that in explicit intrinsics required marking the expression
as special. Unary = seems a little odd at first, but at the same time
seems to make sense, especially for marking expressions as "use literal
value" (eg =ImageOperands.Lod will result in a literal 2 instead of an
op id that points to the 2).
2025-01-20 11:26:20 +09:00
Bill Currie
3a521ebe16 [qfcc] Support uint and enum in expr_int
Signed or unsigned isn't that important for internal errors.
2025-01-20 11:25:22 +09:00
Bill Currie
332c991064 [qfcc] Do type promotions for conditional expressions
Where possible of course, but the two results need to have the same
type. When not possible, an error is generated.
2025-01-20 10:17:01 +09:00
Bill Currie
b1389ddb79 [qfcc] Emit all called functions for spir-v
The functions get queued up if they haven't already been assigned an id.
2025-01-20 10:15:42 +09:00
Bill Currie
d10da51a1f [qfcc] Put unary expressions into the dag
Missed optimization opportunities.
2025-01-20 09:56:44 +09:00
Bill Currie
495a1c7994 [qfcc] Dereference explicit intrinsic arg references
The dereferencing was done for implicit intrinsic args, but I had
forgotten about it for explicit intrinsics. Now the scalar `a` version
of `mix` works.
2025-01-20 09:06:38 +09:00
Bill Currie
498288b630 [build] Fix some distcheck issues
Let's do the distcheck again...
2025-01-20 08:33:57 +09:00
Bill Currie
96a6c91747 Merge branch 'wip-ruaspirv'
This is more a check-point merge to get the more general qfcc
improvements onto master, as well as several vulkan fixes.
2025-01-20 01:41:33 +09:00
Bill Currie
93991ce30d [qfcc] Use the ruamoko test_expr for spirv
The two back-ends are mostly compatible for bools (just lbool is a minor
problem) so reusing the code makes sense.
2025-01-20 01:34:27 +09:00
Bill Currie
1e88fec72c [qfcc] Promote enums so they can be used in math 2025-01-20 01:33:18 +09:00
Bill Currie
f92ab4f64b [qfcc] Make pointer-function casts two-way
This fixes the cast for the think function in game-source/fbxa.
2025-01-20 00:57:54 +09:00
Bill Currie
c88820c31e [qfcc] Split test_expr per target
While there's a bit of code duplication, it very much cleans things up
for the various targets, especially v6 progs. However, spirv is not
implemented yet, so that's broken again.
2025-01-20 00:55:01 +09:00
Bill Currie
0143a2410c [qfcc] Use const type_t * for new_horizontal_expr
It was missed in the type_t const-correctness pass.
2025-01-20 00:51:38 +09:00
Bill Currie
f511bb31c5 [qfcc] Fix a typo in a comment 2025-01-20 00:50:09 +09:00
Bill Currie
21868d4a38 [qfcc] Don't try to vectorize vector/quaternion unary results
matrix_type doesn't like it and it's wrong anyway.
2025-01-18 23:15:29 +09:00
Bill Currie
1ec97632e6 [qfcc] Handle general types in boolean expressions
Probably need language-specific checks (eg, glsl doesn't accept anything
but bool for && etc).
2025-01-18 23:13:55 +09:00
Bill Currie
d3bcd0c3a3 [qfcc] Dump message expression dots 2025-01-18 23:12:47 +09:00
Bill Currie
f713d53fb6 [qfcc] Allow local/param function variables
I thought that was needed, but wasn't sure. It is :P.
2025-01-18 20:51:47 +09:00
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
974306fa12 [gamesource] Correct columns for bitops
bitnot doesn't use operand b so its columns needs to be 0, not 1.
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