Commit graph

14858 commits

Author SHA1 Message Date
Bill Currie
5b9e2f6766 [qfcc] simplify __VA_OPT__ handling
It turns out it didn't need to expand the arguments itself. Now my
@image tests get past the pre-processor. ie, the following works (until
spir-v segs):

    #define __image(t,...) @image(t __VA_OPT__(,) __VA_ARGS__)
    #define _image(d,...) __image(float, d __VA_OPT__(,) __VA_ARGS__)
    @generic(foo=[_image(1D,Array)]) { void bar(foo baz); }
2025-02-15 13:14:58 +09:00
Bill Currie
447af36d43 [qfcc] Make __VA_ARGS__ an actual macro parameter
It seems I hadn't understood the C spec very well when I implemented
__VA_ARGS__ as reading it again now was (after a bit of extra thought)
helpful in realizing that __VA_ARGS__ is simply a proper name for the
... "parameter". Fixes __VA_ARGS__ not expanding in the arguments to
another macro.

I think the __VA_ARGS__ magic macro is no longer needed, but I need to
test it properly before deleting it outright.
2025-02-11 19:56:13 +09:00
Bill Currie
6af42e979e [qfcc] Parse @image() in Ruamoko
I'll probably tweak the syntax a little (make placement of the type more
flexible and not generate an error if either type or other arguments are
missing), but I think I like it result:

    typedef @image(int, 2D, Array, R8) bimage;
    typedef @image(float, 3D, Rgba8) fimage;
    typedef @image(float, Cube, Rgba8) cube;
    typedef @image(float, Array, Cube) cube_array;
2025-02-11 18:08:13 +09:00
Bill Currie
28604add29 [qfcc] Add a silent spirv enum lookup function
Or mostly silent, since the core and enumeration symbols are expected to
be value, but the enumerant itself does not cause a diagnostic if not
found (needed for checking image dimension and format).
2025-02-11 17:59:03 +09:00
Bill Currie
1c20316c9a [qfcc] Make image handles independent of glsl
It has come time to get image handle type creation into Ruamoko. This
commit only gets the functions and types independent of glsl, @image (my
plan for dealing with the handles) isn't implemented yet.
2025-02-11 16:01:59 +09:00
Bill Currie
c18d1b5629 [qfcc] Handle aliases and provisional in spirv grammar
They're currently ignored, but it seems the recent spec update added
these fields.
2025-02-11 15:10:50 +09:00
Bill Currie
ad51881a60 [qfcc] Implement the image format layout qualifier
It doesn't really work yet for multiple reasons (eg, not an exact match
with the spir-v names, and the type system itself being a little
inadequate), but gotta start somewhere.
2025-02-11 14:56:32 +09:00
Bill Currie
10505451eb [qfcc] Encode handle descriptor type and extra
Needed for differentiating image types, and any other fancy handle types
in the future.
2025-02-11 14:43:52 +09:00
Bill Currie
e8e2bf7efe [qfcc] Fix some forwarded enum issues
Forwarded enums need the backing type specified (which makes sense).
2025-02-11 12:49:52 +09:00
Bill Currie
81349ced5d [vulkan] Correct another sign error in QFV_PerspectiveTanFar
It turns out it was completely tangled up when I first wrote it. The
previous correction got things mostly right, but the overall sign was
wrong (ie, it gave -1..0 instead of 1..0)
2025-02-08 11:09:58 +09:00
Bill Currie
f10abf4a18 [qfcc] Check for uniform arrays for UniformConstant
Another one bites the dust (still more fragment shader issues, though).
2025-02-05 10:57:28 +09:00
Bill Currie
6bf5c047c1 [vulkan] Use qfcc for fragment shaders
Nothing works yet, though.
2025-02-05 10:51:53 +09:00
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