Commit graph

14818 commits

Author SHA1 Message Date
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
Bill Currie
db8c9b6a03 [qfcc] Handle non-generic inlined functions
They too need a new function descriptor every time.
2025-01-21 14:46:32 +09:00
Bill Currie
60faf7c4b2 [qfcc] Solve the mysterious missing not
I'd goofed and made the identifier `NOT`. Oops.
2025-01-21 13:35:47 +09:00
Bill Currie
9e3e826338 [qfcc] "Implement" a pile more GLSL functions
`not` isn't working for some reason.
2025-01-21 13:26:15 +09:00
Bill Currie
bfed441045 [qfcc] Handle list expressions in spirv codegen
It seems they get there in declarations in inline functions. I decided
it's not worth worrying about for now.
2025-01-21 13:25:02 +09:00
Bill Currie
b25e64591f [qfcc] Print auto for auto type declarations
Better than an ICE :P
2025-01-21 13:24:32 +09:00
Bill Currie
f4cbe3f220 [qfcc] Ensure compute shaders set all local_size elements
The default value is 1, and the assumption in target_spirv is that if
the first one is set, all are set, but the source code doesn't need to
set any explicitly.
2025-01-21 12:14:06 +09:00
Bill Currie
622be33e4b [qfcc] Fix a complete brainfart with strcmp
Doing <= when I wanted != caused some very strange behavior with
valgrind and bsearch. Also, going with negative logic rather than
positive logic is probably the cause of the brainfart.
2025-01-21 11:50:49 +09:00
Bill Currie
809cffa3a8 [qfcc] Quieten ubsan
0-length arrays certainly would be UB if I tried using them, but I guess
ubsan isn't smart enough for that.
2025-01-21 11:09:00 +09:00
Bill Currie
74f973cddc [qfcc] Mark is_auto as const
All it checks is the addres, so yeah. (I guess it's lto vs no lto)
2025-01-21 11:08:35 +09:00
Bill Currie
fb7025dbd3 [qfcc] Handle execution modes for spir-v/glsl
This means that `layout(triangles)` etc now work, though there are
issues with frag shaders missing functions (since getting function calls
working) and compute shaders silently failing.
2025-01-21 10:42:56 +09:00
Bill Currie
105edc5126 [qfcc] Don't allow overloading of main for glsl
It's supposed to always be void(void), so...
2025-01-20 22:10:27 +09:00
Bill Currie
21cf636875 [qtypes] Remove field_offset macro
And use offsetof instead: it has been standard (enough) in C for a
while.
2025-01-20 20:57:54 +09:00
Bill Currie
9beb0093e6 [qfcc] Skip res type/id for void intrinsics
But only for non-extension. I'm not sure it's quite right (as I don't
know if all void intrinsics should not have res type/id (all extension
instructions *do*)).
2025-01-20 15:44:47 +09:00
Bill Currie
5248e5a4ed [qfcc] Emit base vulkan capabilities
I probably missed some, and I should make the emission more selective,
but my vertex shaders all pass spirv-val (probably don't work, though).
2025-01-20 15:03:27 +09:00
Bill Currie
1f0d7f249c [qfcc] Move countof macro to qtypes
It makes it more accessible and easy to remove when it (or equivalent)
becomes standard in C.
2025-01-20 15:02:21 +09:00
Bill Currie
0ecd8f06bd [cexpr] Add support for long and ulong types
As int64_t and uint64_t. This gets everything building again.
2025-01-20 14:22:44 +09:00
Bill Currie
ea1c0a012b [cexpr] Correct size_t op types
I probably missed changing those unsigned types to size_t. Yay
case&paste programming :P
2025-01-20 14:18:31 +09:00
Bill Currie
1e052ad0dc [vkgen] Use correct types for 64-bit types
When I wrote vkgen's stdint.h, qfcc didn't support long or ulong, and
with the common init check, it now matters that the correct types are
used. It turns out some of my structs may not have been initialized
correctly, but with the next commits (long and ulong for cexpr), they
should be but do seem to be working at least.
2025-01-20 14:18:15 +09:00
Bill Currie
97a0763766 [qfcc] Do initializer type checking in declare_symbol
This is a nice common place (all languages and targets use it) for the
warning and any conversions, though those are still spread in various
places (and need to be cleaned up), so it doesn't do all that much yet.
2025-01-20 14:08:36 +09:00
Bill Currie
133156fdc7 [qfcc] Use OpBitcast for alias exprs in spirv
Really, just implementing it properly.
2025-01-20 14:04:19 +09:00
Bill Currie
54231b21ed [qfcc] Add an is_auto helper function
It's cleaner than type == &type_auto and will allow me to check that
`auto` hasn't been aliased or something like that.
2025-01-20 12:26:57 +09:00
Bill Currie
a922088c1c [qfcc] Correct explicit lod's 0
It needs to be a float, not an int.
2025-01-20 11:42:25 +09:00
Bill Currie
16b04512cb [qfcc] Support marking expression for the back-end
The spir-v back-end needs to emit literal values in some places and
supporting that in explicit intrinsics required marking the expression
as special. Unary = seems a little odd at first, but at the same time
seems to make sense, especially for marking expressions as "use literal
value" (eg =ImageOperands.Lod will result in a literal 2 instead of an
op id that points to the 2).
2025-01-20 11:26:20 +09:00
Bill Currie
3a521ebe16 [qfcc] Support uint and enum in expr_int
Signed or unsigned isn't that important for internal errors.
2025-01-20 11:25:22 +09:00
Bill Currie
332c991064 [qfcc] Do type promotions for conditional expressions
Where possible of course, but the two results need to have the same
type. When not possible, an error is generated.
2025-01-20 10:17:01 +09:00
Bill Currie
b1389ddb79 [qfcc] Emit all called functions for spir-v
The functions get queued up if they haven't already been assigned an id.
2025-01-20 10:15:42 +09:00
Bill Currie
d10da51a1f [qfcc] Put unary expressions into the dag
Missed optimization opportunities.
2025-01-20 09:56:44 +09:00
Bill Currie
495a1c7994 [qfcc] Dereference explicit intrinsic arg references
The dereferencing was done for implicit intrinsic args, but I had
forgotten about it for explicit intrinsics. Now the scalar `a` version
of `mix` works.
2025-01-20 09:06:38 +09:00