Commit graph

5048 commits

Author SHA1 Message Date
Bill Currie
02bf7dbc03 [qfcc] Correct an error message
Why is it I always find these things when posting them in discord?
2025-02-18 12:53:16 +09:00
Bill Currie
6af960cef2 [qfcc] Implement discard
I had no idea how to do it back when I started working on the glsl
parser, but intrinsics made it very easy. It's just OpKill for now (and
might stay that way for glsl).
2025-02-17 20:58:45 +09:00
Bill Currie
6b0b1b24b8 [qfcc] Fix some gcc purity issues
*sigh*. Still, nice to have them correct.
2025-02-17 19:43:15 +09:00
Bill Currie
46094e536e [qfcc] Get block member offsets working again
And now vulkan accepts all my shaders (though it does moan a little
about my alias_shadow vertex shader not using all inputs).
2025-02-17 19:06:32 +09:00
Bill Currie
4ec6df385b [qfcc] Fix the calluse tests broken by attributes
Unfortunately, the preproc-1 test is broken (by __VA_OPT__ fixes)
2025-02-17 18:58:08 +09:00
Bill Currie
ab239d2d6a [qfcc] (rua) Copy spec attributes correctly
If the destination spec didn't already have attributes, nothing was
copied due to me-logic (once again) :P
2025-02-17 18:55:42 +09:00
Bill Currie
b5259bf8f8 [qfcc] Don't copy params for aliased function types
Doing so tramples on the alias data, and the params have already been
copied in the unalized type anyway.
2025-02-17 18:53:55 +09:00
Bill Currie
6664503aaf [qfcc] Set function attributes correctly
The flags were being set, then promptly lost because the attribute flag
(%) wasn't in the encoding. Of course, this breaks a few things :/
2025-02-17 18:50:54 +09:00
Bill Currie
7c0f7c7bec [qfcc] Ensure in and out blocks are distinct
This fixes the tangled gl_PerVertex in geometry shaders. Other block
types aren't a concern as they're all user-specified and required to
have unique names (though I do suspect I did in and out incorrectly, but
that's for another day).
2025-02-17 16:03:15 +09:00
Bill Currie
c0d0c71a7c [qfcc] Support expr dot output for spirv 2025-02-17 15:14:10 +09:00
Bill Currie
5acca56d8d [qfcc] Fix some source location tracking 2025-02-17 15:13:37 +09:00
Bill Currie
71e6ff78c7 [qfcc] Limit final check to non-math types
All math types (of the same width) are assignable, though warnings might
be issued, thus the type_assignable check used for block structs was too
broad resulting in incorrect specialization of generics.
2025-02-17 14:19:59 +09:00
Bill Currie
3190daaf70 [qfcc] Copy block struct member attributes
Gets attributes from layout specifiers working for blocks (eg,
gl_PerVertex).
2025-02-17 14:18:02 +09:00
Bill Currie
054fe6e3c6 [qfcc] Correct the logic surrounding type attributes
I'd messed up the attribute check when encoding the type (such a
frequent occurrence, that) and forgotten to check for null pointer on
the list from the hash table. Fixes block member arrays not getting
their stride decoration.
2025-02-17 13:42:48 +09:00
Bill Currie
151efa5ad7 [qfcc] Rework interface block handling
The types are built with the correct attributes before any expressions
see them, so any necessary duplication is done early and guaranteed to
be only once. Now my compute shaders pass spirv-val.

However, other shaders are broken. But I think I know where to look.
2025-02-17 12:55:57 +09:00
Bill Currie
c75272efe6 [qfcc] Fix some more incorrect opcodes.
Eventually...
2025-02-16 18:54:55 +09:00
Bill Currie
175e1e00e2 [qfcc] Correct the signed clamp opcode
It's SClamp, not IClamp :/
2025-02-16 18:52:14 +09:00
Bill Currie
66b69e33da [qfcc] Catch errors during spirv code-gen
Seeing errors built successful builds was a bit disconcerting.
2025-02-16 18:51:28 +09:00
Bill Currie
3337d45aa0 [qfcc] Improve handling of branched types
This makes using structs in interface blocks possible by auto-casting
whenever possible. Now my compute shaders compile, but there's another
duplicate type sneaking in somehow.
2025-02-16 18:51:13 +09:00
Bill Currie
5690fd028d [qfcc] Fix type_count for type aliases
It was returning type_size by mistake (c&p programming ftw).
2025-02-16 18:11:26 +09:00
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
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
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
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