Commit graph

14846 commits

Author SHA1 Message Date
Bill Currie
8ca018f062 [qfcc] Ensure geometry shader invocations is set
It must always be at least 1, but specifying it in glsl is optional.

And now geometry shaders work :)
2025-02-05 10:26:21 +09:00
Bill Currie
e1969a9ded [qfcc] Set tess/geom in/out array sizes
Tessellation via `vertices` and geometry via the topology. Includes user
`in` vertex attribute arrays.
2025-02-05 10:23:27 +09:00
Bill Currie
34d5f724d0 [vulkan] Use qfcc for geometry shaders
Unsurprisingly, they have issues, but one step at a time :)
2025-02-05 10:21:45 +09:00
Bill Currie
c99f8a8df4 [qfcc] Check for unused operands in evaluate_constexpr
Fixes a segfault when evaluating unary expressions on constants.
2025-02-04 07:39:30 +09:00
Bill Currie
3d488354b7 [qfcc] Use symbol expression for constexpr symbols
Prevents specialization constants from getting folded (and thus fixes
the NaN normals for iqm models).
2025-02-04 07:38:09 +09:00
Bill Currie
059936d18f [qfcc] Fix spir-v buffer struct copying
I had forgotten the parameters needed to be in reverse order (since
constructor_expr was written as the implementation of a function call),
and I had also forgotten I need to do the assignment. No more broken
lights :)
2025-02-04 01:55:35 +09:00
Bill Currie
c6e98107ba [qfcc] Mark non-out and non-push_constant blocks NonWritable
This is a hack until I rethink the entire glsl implementation, but it
gets my vertex shaders such that Vulkan no longer rejects them. However,
there are a couple struct related bugs (next).
2025-02-04 01:53:40 +09:00
Bill Currie
2c7a6c8a87 [vulkan] Switch to qfcc for the vertex shaders
Things aren't quite working yet (currently due to buffer blocks not
getting marked NonWritable (or maybe they should be BufferBlock)), but
this gets shader compilation via qfcc working at all, including
automatic dependencies.
2025-02-03 20:47:10 +09:00
Bill Currie
e2631db4eb [qfcc] Make push_constant blocks push_constant
And now all my vertex shaders seem to pass validation. Time for some
real testing.
2025-02-03 19:31:55 +09:00
Bill Currie
de2d108e41 [qfcc] Process attributes for blocks
And now they get their `set` and `binding` decorations so slice.vert
actually works in nq-x11 :D
2025-02-03 16:51:08 +09:00
Bill Currie
d952bec679 [qfcc] Auto-cast compatible structs in assignment
This allows struct block members to be copied out of a block for spir-v.
The code may not be optimal (the full struct is copied rather than only
used members), but it gets my vertex shaders compiling again and thus
passing that part of validation.
2025-02-03 14:06:27 +09:00
Bill Currie
52c5ec3119 [qfcc] Do some more 0 -> nullptr changes 2025-02-02 13:23:29 +09:00
Bill Currie
be576babf9 [qfcc] Branch struct and array types for blocks
SPIR-V buffer block members need to be fully decorated with offsets
(recursively), which means that any members with struct or array types
need their own types in order to support having different offset and
stride (arrays) decorations. This breaks struct assignment at the
language level, but that is intentional as I want to deal with the
member copying needed to implement struct assignment before emitting
code. It also removes the need for some of the complication in
target_spirv.c, but I'll deal with that later.

The recursively built tag for nested structs might be a bit too
aggressive, but that too can wait until I have a better idea of what's
needed.
2025-02-02 13:06:43 +09:00
Bill Currie
d1a13318a3 [qfcc] Tidy up type.h a little
Forward declare type_t and some int -> bool
2025-02-02 11:34:23 +09:00
Bill Currie
375a068024 [qfcc] Emit required decorations for buffer blocks
Any matrix, array or struct member in a uniform/buffer block requires
offset and stride annotations. These seem to be calculated correctly
(tricky due to qfcc's internal size system, which I should probably
adjust based on target (I think type_size() and type_align() should help
here). Now I've got fun with incompatible structs that are the same type
in the source (thus pass type checks), but different in the target (due
to concrete vs abstract addressing).
2025-01-27 14:21:21 +09:00
Bill Currie
2ad496ebc2 [qfcc] Add more type convenience functions
Due to aliases, even after checking the type of the type, it's not safe
to directly access the type's data without first unaliasing the type.
2025-01-26 19:29:38 +09:00
Bill Currie
f85b966f95 [qfcc] Rename type_id to spirv_Type
Seeing just type_id made me think it did something else (and I wrote
it).
2025-01-25 22:05:12 +09:00
Bill Currie
dcd2c565c1 [qfcc] Emit struct member decorations
They're not enough yet as offsets and strides need to be emitted.
2025-01-25 19:32:12 +09:00
Bill Currie
96375e870a [ruamoko] Update function names for IMP button/axis listeners
The function pointer changes made it necessary.
2025-01-25 18:44:56 +09:00
Bill Currie
0f3f275ab2 [qfcc] Decorate uniform/storage blocks as such
Yet another step closer to getting a shader working in Vulkan.
2025-01-24 22:05:16 +09:00
Bill Currie
6cac4de0ea [qfcc] Use UniformConstant for opaque uniforms
I missed this when reading the glsl spec (I really don't like that
thing).
2025-01-24 22:03:14 +09:00
Bill Currie
7ef4ab474d [qfcc] Set most glsl builtin arrays to 1
Vulkan doesn't like them being zero length and I don't feel like dealing
with it at this stage (and I don't use clip/cull distances).
2025-01-24 22:01:32 +09:00
Bill Currie
95f3efd237 [qfcc] Strip the path for array name
I had meant to do this earlier...
2025-01-24 20:50:09 +09:00
Bill Currie
0071c138bd [qfcc] Support generating a C array of the output
I'd far rather use #embed, but gotta wait for gcc-15.
2025-01-24 19:14:56 +09:00
Bill Currie
a3a4ca90b5 [qfcc] Create generic params only in generic blocks
Since adding type properties, spec.type_expr wasn't enough for detecting
generic parameters. Fixes the missing `points` parameter in simplex.r.
2025-01-24 16:30:58 +09:00
Bill Currie
2c96acc4f0 [qfcc] Clear spec.type_expr after resolving
Fixes an ICE when compiling simplex.r (thus its addition to qfcc's
tests). It still fails due to having lost the points parameter, but yet
another automated test :)
2025-01-24 15:49:49 +09:00
Bill Currie
e179b10455 [qfcc] Get ?: working for references
And spir-v (missed test_expr, and test_expr wasn't dereferencing the
test).
2025-01-24 14:50:28 +09:00
Bill Currie
1e58ca394b [qfcc] Emit the MultiView capability when enabled
Yet another validation error bites the dust.
2025-01-24 14:49:51 +09:00
Bill Currie
0f34e69aeb [qfcc] Use a builtin layout for glsl builtin vars
It both seems to be a bit of a hack (since it probably doesn't conform
with the GLSL spec, but I've given up on worrying too much about that),
and the most sensible thing to do.
2025-01-24 14:48:51 +09:00
Bill Currie
6c4fd34229 [qfcc] Decorate spir-v variable declarations
This takes care of most global variable (not yet member or other
variable) attributes.
2025-01-24 14:01:01 +09:00
Bill Currie
f946a515e6 [qfcc] Make spirv kinds easier to use
Having a specific function for each kind gets out of hand fast.
2025-01-24 13:47:57 +09:00
Bill Currie
d062fef8aa [qfcc] Use field access for single components
Shadow swizzling can return a single component but OpVectorShuffle
doesn't support returning a scalar. This is essentially duplicating the
vector logic in proc_field.
2025-01-23 00:16:39 +09:00
Bill Currie
8cc00cd91b [qfcc] Cast args to inline/intrinsic functions
The whole point of prototypes is to ensure arguments are of the correct
type. Fixes some ints getting into places where floats were expected
(eg, mix, smoothstep, etc).
2025-01-23 00:14:52 +09:00
Bill Currie
354a161722 [qfcc] Fix some gcc purity checks 2025-01-22 20:31:22 +09:00
Bill Currie
2f941ff9dd [qfcc] Clear the function queue immediately
The function queue needs to be cleared before figuring out the interface
symbols otherwise the variables referenced only by called functions will
not get into the list of interface symbols.
2025-01-22 20:26:11 +09:00
Bill Currie
75f59b01c2 [qfcc] Fix some incorrectly specced glsl functions
Some clamps got max by mistake, and boolean mixes were backwards.
2025-01-22 19:43:12 +09:00
Bill Currie
e7d3259829 [qfcc] Force symbol lookup when processing expressions
This fixes the constant type reference ICE for subpassLoad. The problem
was stale symbols recorded in the expressions thus gsubpassInput
referred to the allowed types for the generic function rather than the
type specific to the call.
2025-01-22 18:43:19 +09:00
Bill Currie
5b9d241177 [qfcc] Add reference_expr() to create references
`address_expr()` wasn't enough because it returns pointers instead of
references (quite correct) which messes with checks for references
elsewhere (also quite correct). It seems I've finally got reference
parameters working.
2025-01-22 14:59:03 +09:00
Bill Currie
9c3dc555a3 [qfcc] More work towards proper reference handling
Generic function parameters can now use references (currently via
`@reference()`) for generic types. And seem to work. There's still a
problem with chains: `atomicExchange(__imageTexel(...))` is
dereferencing __imageTexel's return value.
2025-01-22 11:11:38 +09:00
Bill Currie
e2f3a00a78 [qfcc] Fix a wrong var gaff
Bloody symbol->type (pointer) vs sy_type (enum) and C's "any 0 is a
pointer".
2025-01-22 11:02:34 +09:00
Bill Currie
ce8d1467ef [qfcc] Correct basic glsl atomic functions
The `mem` param is now a reference (though it manages to skip checks
based on the tag, but that's convenient for now).
2025-01-21 22:45:24 +09:00
Bill Currie
53afbc3a9b [qfcc] Handle address of field expressions
In particular, spir-v needs special handling to avoid unwanted loads.
2025-01-21 22:43:51 +09:00
Bill Currie
198821f0d3 [qfcc] Improve reference param and arg handling
In particular, type matching for overloads/generics and correct handling
for inline/intrinsic functions.
2025-01-21 22:41:42 +09:00
Bill Currie
da6c5129eb [qfcc] Support @reference() in the same vein as @pointer
This allows computed reference types, especially tagged references.
2025-01-21 22:38:23 +09:00
Bill Currie
866e1dc06a [qfcc] Remove the ptr temp
By default, spir-v doesn't allow pointer variables, so the result of
__imageTexel needs to be used directly.
2025-01-21 20:08:34 +09:00
Bill Currie
f08faee2ed [qfcc] Use a tagged pointer for __imageTexel()
It seems it should return an Image storage class pointer. Validation
still fails because of the ptr local var (not allowed by default) and so
needs to be an SSA temp, but I'm having a little trouble with *that*.
2025-01-21 20:05:01 +09:00
Bill Currie
cdfc6bc704 [qfcc] Process and check for errors in compute_type
It turned out error checking on type functions was broken by generic
functions because type_function wasn't being called. The rest of the
changes were for error recovery.
2025-01-21 19:47:23 +09:00
Bill Currie
b9c3f427b7 [qfcc] Emit debug line info for spir-v
Other than a bug in spirv_str_insn, that was a lot easier than I
expected.
2025-01-21 17:26:34 +09:00
Bill Currie
2d5f59777d [qfcc] Use string offset/id slots in strpool
This makes it a little easier to deal with unique strings, particularly
for spir-v.
2025-01-21 17:25:32 +09:00
Bill Currie
27c33abf58 [qfcc] Correct the atomic functions
They needed Scope and MemorySemantics.
2025-01-21 14:54:25 +09:00