Commit graph

14877 commits

Author SHA1 Message Date
Bill Currie
1e58a1b12e [qfcc] Set branched struct size too
Yet another fix for block types :/
2025-02-16 18:11:26 +09:00
Bill Currie
de0b8bf476 [qfcc] Add a comment about why obj_type_assignable
It's not exactly intuitive.
2025-02-16 18:11:26 +09:00
Bill Currie
f8099c9977 [qfcc] Rename obj_types_assignable
This makes it consistent with the other type_assignable functions.
2025-02-16 18:11:26 +09:00
Bill Currie
feca36bf59 [qfcc] Record type id for block types
I had initially thought I'd need to duplicate types for block members,
but that was before I did the higher-level type branching, and then I
forgot to record the type for block members. Fixes the duplicate types
on structs in blocks, and thus a type mismatch validation error in
partphysics.comp.
2025-02-16 16:27:24 +09:00
Bill Currie
70bfa64333 [qfcc] Use CopyLogical for structs and arrays
I had vaguely remembered there was something, but forgotten what it was,
then found it while debugging my compute shaders. This greatly
simplifies copying structs to/from blocks.
2025-02-16 14:26:24 +09:00
Bill Currie
e5ff5a223b [qfcc] Fix copying of structs for block types
I forgot to set the symbol type of the members and the number of symbols
in the struct. Fixes the excessive initializers when writing to a block
struct.

Also ensure the type name has "tag "  in it.
2025-02-16 14:20:00 +09:00
Bill Currie
192b42737a [qfcc] Dump compound init expressions
I finally really needed to see what was in one.
2025-02-16 12:16:39 +09:00
Bill Currie
b67eb518e5 [vulkan] Comment out some unreachable code
When targeting spir-v, qfcc does do dead code removal yet, so the return
followed the previous return (with no intervening label) so caused the
shader to not pass validation.

Now the fragment shaders work (mostly: there's a problem with discard in
the sprite shader).
2025-02-16 11:25:44 +09:00
Bill Currie
a3f4649b27 [qfcc] Use array count, not the const id for array size
Double emission of a constant... that one had me puzzled for a bit: 374?
That's not even a multiple of 32!
2025-02-16 11:23:56 +09:00
Bill Currie
a8446cb87e [qfcc] Implement input_attachment_index
Slowly getting there with getting Vulkan to accept my shaders.
2025-02-16 11:01:54 +09:00
Bill Currie
651a1611b1 [qfcc] Apply general qualifiers
They're not fully implemented, and many checks are bogus, but at least
highp and flat do the right thing.
2025-02-16 10:48:45 +09:00
Bill Currie
03285c43ca [qfcc] Handle image type promotions etc
I have no idea what should be promotion and what should be demotion, but
I think a specified format should at least be assignable to unspecified
format. It certainly helps get things compiling again.
2025-02-15 23:42:36 +09:00
Bill Currie
6c5bf8cb80 [qfcc] Use correct memory semantics for atomic ops
It seems it's supposed to be Relaxed, and there is no None anyway (and
checks aren't done until the intrinsic is instantiated).
2025-02-15 21:22:17 +09:00
Bill Currie
06573a6a8c [qfcc] Translate glsl format to spir-v format
Due to some underscores in the glsl names, there was no way just case
insensitivity would help, and I didn't want to edit the strings.
2025-02-15 21:20:49 +09:00
Bill Currie
ce287201d3 [qfcc] Get sampled image types working
I'd forgotten to set the sampled field and messed up is_sampled_image().
2025-02-15 20:52:57 +09:00
Bill Currie
bc00bd0a0c [qfcc] Clean up image type creation
While images are handles, they're not user-handles thus don't exist in
that name-space. slice.vert now compiles, but it looks like I have some
problems with sampled images/textures (sampler2D etc).
2025-02-15 19:41:02 +09:00
Bill Currie
5ac80b1859 [qfcc] Add support for sampled images
It's currently `@sampler(...)`, but I'm not sure about the name (should
it be `@sampled_image`, `@sampled` or similar?). However,
glsl-builtins.c uses `@image` and `@sampler` now, so one step closer to
my shaders compiling again.
2025-02-15 17:15:55 +09:00
Bill Currie
ac05a72253 [qfcc] Avoid some unnecessary internal errors
An empty valid type list is a valid error since one can come from input
source code, but I still wanted an internal error for compiler-generated
generic functions when I get around to doing such.
2025-02-15 15:41:15 +09:00
Bill Currie
91b269a0b8 [qfcc] Hook up @image parsing
Seems to work nicely, but I have some work to do with getting generic
functions to match (eg, when the format is specified)
2025-02-15 13:39:40 +09:00
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