Commit graph

3632 commits

Author SHA1 Message Date
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
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
Bill Currie
53c4c205ca [qfcc] Override function declaration with definition
This fixes the problem of the function declaration parameter names
overriding the definition's parameter names.
2024-11-24 13:03:34 +09:00
Bill Currie
ffcee99835 [qfcc] Partially handle implementing generic functions
Implemented via specific overloads of the function.

It's not quite working correctly in that parameter names are taken from
the declaration instead of definition. However, this seems to be an old
bug that went unnoticed due to me almost always using the same parameter
names in declaration and definition.

Also, the code in get_function() is a horrible mess.

However, the basic idea turned out to be simpler than I though (though
details of the implementation are indeed a little trickier): generic
functions are essentially prototype generators when implemented using
non-generic specialized overloads.
2024-11-24 11:34:59 +09:00
Bill Currie
980dd913b5 [qfcc] Split up find_generic_function
I want to reuse its generic function search for defining
implementations.
2024-11-22 23:50:07 +09:00
Bill Currie
1893df34a3 [qfcc] Add an intrinsic expression type
This will be fore generating specific SPIR-V instructions via function
calls, and could be useful for Ruamoko, too.
2024-11-22 23:44:37 +09:00
Bill Currie
0dfe81bce8 [qfcc] Move ruamoko attribute parsing out of the parser
Makes for better separation of variable and function attributes.
2024-11-22 14:15:08 +09:00
Bill Currie
11f8992710 [qfcc] Handle dynamic array indices for spir-v
Now bsp_turb.frag (with hacks for builtin functions) compiles and even
passes validation, but is badly broken.
2024-11-21 19:18:13 +09:00
Bill Currie
fbcdf227c5 [qfcc] Assign indices to glsl block members
spirv-val didn't particularly like all my block members getting index 0
(really, it was tangled types, but 0 was the cause).
2024-11-21 19:18:13 +09:00
Bill Currie
cfc5e0b5fd [qfcc] Handle convert symbols when processing
I'm pretty sure I don't want this getting into the target code, so
handling it early (like in the immediate processing path) seems good.
2024-11-21 19:18:13 +09:00
Bill Currie
c3bbd85857 [qfcc] Skip void param for spir-v
Functions declared with `(void)` don't actually have any parameters, so
ensure no parameters are emitted for such functions.
2024-11-21 19:18:13 +09:00
Bill Currie
744c3ff1d6 [qfcc] Handle reference params/args for overloaded functions
Reference vs value parameters do not resolve overloaded functions.
2024-11-21 19:18:13 +09:00
Bill Currie
663aeb16fd [qfcc] Enable color/texture vector component names
Yet another step closer to glsl support.

While it wasn't correct anyway (neither vectors nor quaternions are
colors), the additional names broke q.s in the quaternion.r test, likely
due to there being two s fields.
2024-11-21 19:18:13 +09:00
Bill Currie
08bdc0794a [qfcc] Improve expression line tracking
Missed a few places in expr_process.
2024-11-21 19:18:13 +09:00
Bill Currie
fb497cd0b2 [qfcc] Clean up the errors for some layout qualifiers
Nothing's actually implemented, but once I fix a couple more errors I'll
be able to work on that.
2024-11-21 19:18:13 +09:00
Bill Currie
c16a8411bc [qfcc] Extend handles to support image types
Images are just handles, but they have additional type data like
dimensionality, array, etc that distinguishes between the image types.
2024-11-21 19:18:13 +09:00
Bill Currie
03c47f8af7 [qfcc] Support (partially) attributes on types
For now, it's just recording that type type has attributes (encoding
begins with %) and resurrecting types_same which is used only when
matching with types with attributes, so there's still a fair bit of work
to do.
2024-11-21 08:30:47 +09:00
Bill Currie
5e605aee36 [qfcc] Clean up some overzealous const correctness
I'm not sure why I made those functions take const type_t *, but they
didn't need it. There's still a relevant fixime in find_handle, but I
haven't decided how to fix that one just yet.
2024-11-21 08:30:47 +09:00
Bill Currie
28a85b1624 [qfcc] Fix some crashes when parsing bsp_turb.frag
Incorrect type accesses and unnamed interfaces.
2024-11-19 17:15:42 +09:00
Bill Currie
34b94aec96 [qfcc] Set binding and set attributes
Not sure if this will work, but it does fix some error and notice noise.
2024-11-19 17:13:38 +09:00
Bill Currie
59c8e8e907 [qfcc] Don't check for redefs of unnamed symbols
Both glsl and spir-v need this for non-instanced interface blocks.
2024-11-19 17:12:03 +09:00
Bill Currie
128682624e [qfcc] Process array sub-expressions 2024-11-19 17:10:37 +09:00
Bill Currie
943cf9659b [qfcc] Make requiring @overload a language feature
Ruamoko still needs @overload (for now), but now glsl does not.
2024-11-18 22:46:14 +09:00
Bill Currie
393f669864 [qfcc] Ensure function types are complete
All types need non-zero alignment, width and columns.
2024-11-18 22:45:08 +09:00
Bill Currie
9add468462 [qfcc] Improve interface block declaration
I'm sure there are still some warts, but interface declaration now works
for spir-v and a real vertex shader can be compiled (albeit one that
doesn't use matrices).
2024-11-18 21:41:33 +09:00
Bill Currie
3dc22d8cd6 [qfcc] Support spir-v vector expressions even better
It turned out I did need direct vector expression support: the previous
commit handled only assignments, not sub-expressions.
2024-11-18 15:47:22 +09:00
Bill Currie
0771d6b3be [qfcc] Support assignment to field members in spirv
And now something like `a.y += 1` works.
2024-11-18 15:29:58 +09:00
Bill Currie
9b2240aaf8 [qfcc] Implement vector expressions for spir-v
And fix a little goof with VectorShuffle (c&p coding bites again).
2024-11-18 14:55:32 +09:00
Bill Currie
39514e4f3d [qfcc] Implement swizzle and arrays for spir-v
Arrays done via the field code since they use the same opcode and logic.
For now swizzles are just swizzles and don't support zeroing or negating
(but doing one or the other (not both) should be easy).
2024-11-18 12:29:25 +09:00
Bill Currie
73a8404684 [qfcc] Alias pointer etc to int for !
This fixes the calluse2 test.
2024-11-18 11:51:10 +09:00
Bill Currie
13f25af881 [qfcc] Use the called function for ruamoko progs
This was a nasty one to find as it was the unary expression rewrite that
triggered the bug (by causing tighter if tests to be generated, which
surprised me: I wasn't even trying for better if tests). I'm actually
not sure why things worked at all, but this fixes the crashes and other
weird behavior resulting from calls to performSelector.

Two tests are included because I found a separate bug (not fixed yet,
tested by calluse2) while getting the calluse test working.
2024-11-18 03:42:26 +09:00
Bill Currie
28e8697ae6 [qfcc] Implement compound initializers for spir-v
They don't yet support designators, and vectors aren't treated the way I
want, but my little test works correctly.
2024-11-17 22:45:18 +09:00
Bill Currie
91a93d7803 [qfcc] Add type_count() function
It returns the number of elements in a type (so something like `countof`
(hopefully that's what the up-coming C feature will be called) can be
implemented), but it applies to structs, vectors, etc (eg, 9 for mat3).
2024-11-17 16:12:27 +09:00
Bill Currie
d082d39e17 [qfcc] Use count for number of array elements
I got tired of seeing size when count is the real intent (mistake copied
from C++).
2024-11-17 15:27:10 +09:00
Bill Currie
2115e962fe [qfcc] Support typed compound initializers
Explicitly typed compound initializers are what C uses and allows them
to initialized `auto` vars and even pass through `...`. Not tested yet
other than ensuring existing tests didn't break.
2024-11-17 13:17:36 +09:00
Bill Currie
a7f9d96a02 [qfcc] Implement select (if) constructs
And break/continue too, since my test for them required select.
2024-11-16 23:13:46 +09:00
Bill Currie
93d116cf16 [qfcc] Rename body_first to do_while
Since loops are always while or do-while (for loops are just while loops
with an init block), it made more sense in the end.
2024-11-16 23:10:54 +09:00
Bill Currie
2ef72f745d [qfcc] Improve glsl scope handling
While storing the scope in a block was the right idea, the
implementation wasn't quite right as it resulted in the current scope
getting set at the wrong times resulting in incorrect symbol access when
shadowing was in effect.
2024-11-16 20:14:51 +09:00
Bill Currie
3797b1083b [qfcc] Implement loops for spir-v
Mostly, at least: continue and break aren't functional yet, and for
loops haven't been tested, but while and do-while seem to work.
2024-11-16 19:29:41 +09:00
Bill Currie
89dac4a1b8 [qfcc] Create scopes for while and for loops in glsl
I guess that was a mental FIXME for later, but later came sooner. The
declaration doesn't seem to be working properly, but I'll worry about
that later when I can get some automated tests going.
2024-11-16 19:29:41 +09:00
Bill Currie
01d3c60fe0 [qfcc] Encode param qualifiers in function type
I'm not sure whether I'll stick with the current encoding, but it turns
out it's necessary to separate function types on parameter qualifiers (I
was half expecting that, though).
2024-11-16 19:29:41 +09:00
Bill Currie
22794caf11 [qfcc] Support vector value expressions for spir-v
It seems constant initializers are different from constants in an
expression.
2024-11-16 18:54:31 +09:00