Commit graph

3757 commits

Author SHA1 Message Date
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
Bill Currie
03bbfde5f1 [qfcc] Get some more texture functions implemented
GLSL's texture functions are a bit of a nightmare. The return types are
wrong, but I need to decide how I want to pull the sample type from a
texture or sampler.
2025-01-10 01:00:00 +09:00
Bill Currie
09bd49814e [qfcc] Correct spirv right shift types
Spir-v is pretty slack with the exact types of the operants to the
right-shift instructions so no need to care about the type for shift so
long as it has the correct number of components.
2025-01-10 00:58:26 +09:00
Bill Currie
6e004e9baa [qfcc] Implement generic type computation
I had already implemented the code generation side (though using type
ids instead of encodings is a nice change), but I hadn't implemented the
actual evaluation or even called it. Now return types can be computed
from generic parameters (eg, ivecN from vecN).
2025-01-10 00:56:02 +09:00
Bill Currie
76fcc2f1a9 [qfcc] Support nil expressions in spir-v 2025-01-09 17:49:20 +09:00
Bill Currie
1d0135be52 [qfcc] Support nil in matrix construction
While not used by glsl, ruamoko will and qfcc does internally.
2025-01-09 17:48:39 +09:00
Bill Currie
d1364e460c [qfcc] Update some TODO entries
Mostly marking stuff as done, and adding a note to the optional params
item.
2025-01-09 17:32:07 +09:00
Bill Currie
a93c109988 [qfcc] Improve spir-v entry point handling
It's still not great (mostly on the language side, I think), but
different glsl shader types get the correct model and fragment shaders
even get the correct mode.
2025-01-09 17:29:27 +09:00
Bill Currie
4998968169 [qfcc] Emit spirv image type encodings
Access qualifiers aren't supported yet, and some of the image handling
is a bit messy (currently tied to glsl when it should be general), but
the basics are there. However, now I've got to sort out the execution
model (need Fragment or GLCompute for ImplicitLod).
2025-01-09 01:29:38 +09:00
Bill Currie
99b1859aac [qfcc] Parse the spirv grammar json files
I really don't like the way they're included (I'm really looking forward
to #embed, but gotta wait for gcc 15), and I'm a tad grumpy that the
documentation for them
(https://registry.khronos.org/SPIR-V/specs/unified1/MachineReadableGrammar.html)
is wrong (missing fields), but I think I like the result.

The grammars (core and glsl.std.450) are parsed into structs that should
be fairly easy to interpret: the instructions, kinds, and enumerant
values are sorted by name for search with bsearch. Having the data
parsed in means source code can refer to the items by name rather than
magic numbers, which will be very nice for intrinsics and image types
(and probably a few other things).
2025-01-07 03:26:12 +09:00
Bill Currie
400486931f [qfcc] Allow languages to hook number parsing
The idea is to allow certain contexts to interpret something like `2D`
as an identifier instead of 2.0 (double), or (not sure I'll go there,
5e12 as a bivector instead of a double or float.
2025-01-04 12:51:30 +09:00
Bill Currie
9aea4d4b61 [qfcc] Update glsl function declaration handling
Finally back to where I was before discovering that arrays with computed
counts didn't work.
2025-01-03 21:58:33 +09:00
Bill Currie
ea3198e8fe [qfcc] Update generic handling for the new type scheme
And clean up some redundant (premature!) spec processing.
2025-01-03 21:27:28 +09:00
Bill Currie
ae4c107384 [qfcc] Add type_process for type functions
I'm not quite sure it's what I need, but it does help with resolving
types with complex expressions (eg, `@vector(bool,@width(vec))`).
2025-01-03 17:55:08 +09:00
Bill Currie
bec8b290d2 [qfcc] Resurrect is_function
In the end, it does simplify things a lot, though it helped get function
pointers working at least a bit (they're not quite the same as C yet,
but I think that's mostly that functions can be struct fields).
2025-01-03 17:52:19 +09:00
Bill Currie
99632ddb03 [qfcc] Rework function/pointer/array declarations
They should now work in generic contexts, but the pressing need to work
on arrays was due to constant expressions for element counts breaking.
As a side effect, function pointers are now a thing (and seem to work
like they do in C)
2025-01-03 13:22:29 +09:00
Bill Currie
fd836e74e1 [qfcc] Check implicit is the same for dagged values
Not doing so results in subtle bugs such as implicit constants becoming
explicit behind the programmer's back.
2025-01-03 13:22:29 +09:00