Commit graph

14686 commits

Author SHA1 Message Date
Bill Currie
bc1b9893a7 [qfcc] Fix vector constructions from scalars
Yet another bit of is_vector/is_nonscalar confusion.
2024-12-05 16:11:59 +09:00
Bill Currie
ec436ee65e [qfcc] Put definition for generic functions in genfunc
It is then copied to the metafunc when finding the actual function to
call. Fixes the last definition defining all instances.
2024-12-05 16:08:39 +09:00
Bill Currie
a5366bf7f9 [qfcc] Fix matrix indexing for ruamoko
The change to exclude matrices from is_nonscalar broke indexing of the
columns.
2024-12-05 14:24:14 +09:00
Bill Currie
639818cca5 [qfcc] Handle unsigned int correctly
I'd missed the one case, so such declarations wound up just `int`
2024-12-05 13:12:27 +09:00
Bill Currie
b4387cd881 [qfcc] Finish type decl for type_ref
I guess I'd wanted to avoid supporting automatic types in type
functions, but that broke long and unsigned int: either no type, or just
int, depending on the decl style.
2024-12-05 13:10:11 +09:00
Bill Currie
a938f1c507 [qfcc] Define the glsl mix builtins
Unfortunately, it turns out that generic functions are over-grouped so
all functions with the same name get the last definition, so `mix` with
a float (which should get GLSLstd450FMix) gets the bool version instead
(SpvOpSelect).
2024-12-05 12:19:04 +09:00
Bill Currie
9f9aecfeec [qfcc] Fix function disambiguation
I was checking for duplicate best matches too early. Local minimum (or
inflection point, really) problem.
2024-12-05 12:08:08 +09:00
Bill Currie
277c5a2318 [qfcc] Optimize matrix construction from a matrix
If the source matrix has at least as many rows as the new matrix, then
the columns are taken from the columns (possibly shortened via swizzle).
2024-12-05 11:45:01 +09:00
Bill Currie
ad45715359 [qfcc] Clean up duplicated vector list construction
I wound up with a few too many copies for my liking.
2024-12-05 11:13:08 +09:00
Bill Currie
81aa77b142 [qfcc] Optimize matrix construction from vectors
When the number of supplied vectors matches the number of columns in the
matrix and all vectors have the same width as the number of rows in the
matrix, there's no need to expand the vectors into components only to be
gathered again.
2024-12-05 10:31:32 +09:00
Bill Currie
14e39627cc [qfcc] Construct matrices by vectors
SPIR-V requires that matrices are constructed from vectors rather than
individual components. While not optimal, iqm.vert's output now passes
spirv-val. Also probably still lots wrong with fine details.
2024-12-05 10:03:01 +09:00
Bill Currie
f014d3f580 [qfcc] Clean up logical not and bool expressions
Got to get rid of a FIXME :)
2024-12-05 02:02:14 +09:00
Bill Currie
4b7025fa0b [qfcc] Implement matrix ops in spirv
And they pass spirv-val.
2024-12-05 02:00:35 +09:00
Bill Currie
a9bff23a6a [qfcc] Define the glsl normalize functions
I think I need to come up with a better way of defining glsl builtins
and the strings are rather ugly (and I don't want to use qfcc system
header files).

iqm.vert now compiles, but doesn't pass validation yet (matrix bugs).
2024-12-05 00:30:17 +09:00
Bill Currie
2a5c9ae45b [qfcc] Emit spirv array types correctly
Array count is an id, not a literal. Oops.
2024-12-05 00:27:27 +09:00
Bill Currie
c185d2463b [qfcc] Support matrices in spirv output
With a few more fixes, iqm.vert builds nicely.
2024-12-05 00:26:07 +09:00
Bill Currie
5e053fe270 [qfcc] Fix an overflow for matrix values
ex_value_t keeps getting bigger :P
2024-12-05 00:22:38 +09:00
Bill Currie
7bbbbe1f0e [qfcc] Improve glsl source line tracking
It's never nice getting an error on the wrong line.
2024-12-05 00:21:19 +09:00
Bill Currie
8cc71395cc [qfcc] Fix some more unsupported expressions in dot 2024-12-05 00:19:48 +09:00
Bill Currie
674fbae225 [qfcc] Rework binary_expr to be support matrices
And, nicely, simplify it quite a bit. I'm not sure why I didn't thinkg
of this approach before. While the ruamoko back-end doesn't support
matrices yet, the expressions are handled.

As a side effect, type checking on comparisons is "stricter" in that
more potentially bogus comparisons (eg, int-float) are caught, resulting
in a few warnings in ruamoko code and even finding a couple of bugs.
2024-12-05 00:18:47 +09:00
Bill Currie
8e2fe83c27 [qfcc] Add a function for checking type comparisons
It returns true if the comparison is valid without a diagnostic (usually
a warning), false otherwise.
2024-12-05 00:10:15 +09:00
Bill Currie
8d69ca9a99 [qfcc] Simplify type_promotes and type_demotes
Using bit masks for valid source types for each destination type makes
the logic a lot easier to read. Still had to have some explicit checks
for enums and bools.
2024-12-05 00:10:15 +09:00
Bill Currie
f4a8a5e179 [qfcc] Fix some inconsistent tokens
I need to find a good way to share token defs between bison files.
2024-12-05 00:10:15 +09:00
Bill Currie
7a30ac9527 [qfcc] Clear current function for constexpr evaluation
The code gen return statements checks for out/inout parameters in the
current function and thus could result in some undesired behavior when
constants are evaluated within such a function.
2024-12-05 00:10:15 +09:00
Bill Currie
5714433a9c [qfcc] Clean up some more bools 2024-12-05 00:10:15 +09:00
Bill Currie
b03132825e [qfcc] Fix a typo in a variable name 2024-12-04 23:48:43 +09:00
Bill Currie
4800fef4fd [qfcc] Give short and ushort width of 1
I'm not sure why I thought a width of 0 was a good idea, but it proved
to be problematic when implementing matrices.
2024-12-04 23:47:58 +09:00
Bill Currie
58b78cfdec [qfcc] Separate matrices from non-scalars
While matrices are non-scalars in math, is_nonscalar is meant for any
vector type because is_vector is specifically for the quakec vector
type.
2024-12-03 14:56:38 +09:00
Bill Currie
5c822f6579 [gamecode] Tidy up shiftops a little
The various indices were a little inconsistent making modifications
tricky. I discovered that signed left-shifts are considered UB if the
value overflows the non-sign bits (but unsigned left shifts are fine),
and signed right shifts are implementation dependent. Whee. However,
it's likely that signed right shifts can be relied upon, at least well
enough for unit tests. I imagine signed left, too, but I plan on
converting them to unsigned. Also, negative shift values are UB, but
that's less of a worry, but also needs "fixing" (ie, make unsigned).
However, later.
2024-11-28 23:41:07 +09:00
Bill Currie
7c56c10d25 [qfcc] Support matrices in binary expressions
Partially. There are problems with scaling and code-gen.
2024-11-28 23:30:39 +09:00
Bill Currie
d0db75779a [qfcc] Add a check for shifts and expand math ops
I found a need to check for shifts separately (not sure it's the right
approach for that problem, though), and there are a few more math ops
than just +-*/.
2024-11-28 21:16:14 +09:00
Bill Currie
8323868b2c [qfcc] Add an opcode for outer products
I'm not sure what it's useful for, but GLSL has a function for it thus I
decided to add the instruction to the VM, so this is part of the
compiler side.
2024-11-28 21:16:14 +09:00
Bill Currie
d418c4b8c4 [gamecode] Tweak matrix product instruction names
The name for VMMUL was outright wrong (outer), but both MVMUL and VMMUL
can be mul because of the type and width/columns specifiers. I think
OUTER can too, but I'll leave that for now.
2024-11-28 21:07:30 +09:00
Bill Currie
c4f48353b9 [qfcc] Correct a typo in a comment 2024-11-28 21:05:34 +09:00
Bill Currie
0652a103d0 [qfcc] Correct edge labels for field expressions
I had f and o reversed and decided to use m (member) instead of f.
2024-11-28 20:09:51 +09:00
Bill Currie
b2a1a3c791 [vulkan] Add source barrier to packet scatter and image copy
I got a sync validation error on a scatter command (I think) thus the
setting was probably wrong. Most of the parameters are still what they
were, but I'll be able to tweak the barriers as necessary.
Unfortunately, it didn't help with the hang on fetching the light cull
query data when starting in fisheye mode (no hang when enabling fisheye
after startup). I'm not sure what's going on there other than the
queries aren't getting updated: the counts seem to be fine so maybe the
commands aren't running. I've probably got a tangled mess of
pseudo-parallel command buffers: I need to go through my system and
clean everything up.
2024-11-27 20:15:51 +09:00
Bill Currie
23ec8d5de4 [build] Document --disable-Werror for git builds
It came up in a discord discussion. I thought it was documented, but it
wasn't. It is now.
2024-11-26 17:52:46 +09:00
Bill Currie
2c313a87c6 [gamecode] Fix some tangled rows and columns
I'd suspected I had some mistakes in there, but I didn't expect gcc to
find them for me.
2024-11-26 16:28:15 +09:00
Bill Currie
2b70c54b15 [qfcc] Fix an uninitialized variable
I'd forgotten to do an optimized compile check :/
2024-11-26 16:26:45 +09:00
Bill Currie
2bd9d26cc1 [qfcc] Implement mod for v6 progs
The tricky bit was figuring out how to get `floor()` out of the
available instructions. It's handy that the comparison ops always
returned floats and didn't force the use of branches.
2024-11-26 14:38:55 +09:00
Bill Currie
7b4aa1efd8 [qfcc] Clean up v6 rem implementation
I couldn't do it this way before I got dag expressions working, but this
is much cleaner.
2024-11-26 14:21:10 +09:00
Bill Currie
43716e5d6a [qfcc] Use columns for selecting instructions
Now both width and columns must match for an instruction to be selected.
Found a few errors in my opcode specs, and some minor goofs in the type
system (really just overthinking things when I added matrices).
2024-11-26 10:45:20 +09:00
Bill Currie
9c394c02f8 [gamecode] Correct some instruction column specs
Getting qfcc to use columns when selecting instructions proved to be not
too difficult. I think I'm more surprised at how few errors there were.
2024-11-26 10:40:10 +09:00
Bill Currie
efc1fdbd29 [gamecode] Add matrix instructions
Only matrix-vector, vector-matrix and vector-vector outer products (no
more room), but that's enough to get decent performance out of
matrix-matrix and matrix-scalar (both of which can be done as a set of
matrix-vector or vertex-scalar products).

Progs version bumped because I found that I'd put the swizzle and 2d
wedge ops in the wrong spot (compared to both intention and docs) and
rather than adjust the docs, I took advantage of the opportunity to get
a nicer layout for the wedge products (nestled into the spare slots left
by the 2x2 matrix ops, which seems fitting as the 2d wedge is the
determinant of a 2x2 matrix).
2024-11-26 00:22:56 +09:00
Bill Currie
a4eefa6204 [qfcc] Implement matrix construction for constants
Non-constant matrices are not implemented yet, and it turns out
vector-matrix multiplication produces incorrect vector types (for
vec4*mat3x4)
2024-11-25 12:39:14 +09:00
Bill Currie
1e5d500f8b [qfcc] Implement intrinsic functions in spir-v
Only a tiny handful of glsl functions are implemented (dot, cross,
sqrt), but the system works, both via generics and regular overloads.
2024-11-25 01:39:27 +09:00
Bill Currie
b9ed0dcc64 [qfcc] Allow obj pointer to id conversions for free
Overloaded functions taking id need to allow any obj pointer.
2024-11-24 18:38:45 +09:00
Bill Currie
b0207f4dc9 [qfcc] Allow demotion of implicit literals
This fixes the modulo test.
2024-11-24 18:12:51 +09:00
Bill Currie
98d122f122 [qfcc] Use same cost function for generic and overloaded
The modulo test breaks due to implicitly typed literals, but otherwise
seems to do a better job of resolving function calls.
2024-11-24 15:56:46 +09:00
Bill Currie
70bb5c3434 [qfcc] Check for errors in conditional expressions 2024-11-24 15:52:17 +09:00