Commit graph

13701 commits

Author SHA1 Message Date
Bill Currie
5aea74de7e [qfcc] Show algebra signature for bad basis blades
Clear error messages are always more helpful than opaque ones.
2023-08-27 15:17:22 +09:00
Bill Currie
c7d6e80d69 [qfcc] Use GPU-style alignment for algebra types
Meaning vec3 is aligned to 4 components instead of 1. 2-component ops
use vec2 in the VM thus requiring alignment to boundaries of 2, but 4
seems better as it conforms with OpenGL and Vulkan (and, I imagine,
DirectX, but I doubt QF will ever use DirectX).
2023-08-27 15:13:49 +09:00
Bill Currie
727b490a0c [gamecode] Improve hops instruction readability 2023-08-27 12:28:16 +09:00
Bill Currie
74b7e0a35b [qfcc] Get some of 2d PGA mostly working
Better yet, some tests :)
2023-08-27 00:24:23 +09:00
Bill Currie
0939979d84 [qfcc] Allow #pragma to control warning options
I probably need to make a decision about vararg integer constants, but
the ability to control warnings is never a bad thing.
2023-08-26 23:47:00 +09:00
Bill Currie
a5304461dd [qfcc] Fix adjusted swizzles for the same def
The singleton alias resulted in the adjusted swizzles being corrupted
when for the same def. Other than adding properly sized swizzles
(planned), the simplest solution is to (separately) allow alias that
stick out from from the def.
2023-08-26 23:08:55 +09:00
Bill Currie
29a57b7128 [qfcc] Correct handling of 64-bit comparisons
While the progs engine itself implements the instructions correctly, the
opcode specs (and thus qfcc) treated the results as 32-bit (which was,
really, a hidden fixme, it seems).
2023-08-26 23:04:34 +09:00
Bill Currie
8a0246c910 [ruamoko] Add type info for algebra types
And get vector type views working in the debugger.
2023-08-26 23:01:01 +09:00
Bill Currie
a88d17459f [gamecode] Decode hops and extend opcodes 2023-08-26 22:43:15 +09:00
Bill Currie
91edc5d177 [qfcc] Unalias expressions when checking for math values
Fixes some ICEs when trying to fold constants in geometric algebra.
2023-08-26 11:48:23 +09:00
Bill Currie
81b57903fc [gamecode] Support the l flag for %v and %q
This makes it much easier to print double vector types (for 3 and 4
components, at least).
2023-08-26 11:47:04 +09:00
Bill Currie
77c1b584ea [qfcc] Clean up the blade scaling
I didn't particularly like that solution due to the implied extra
bandwidth (probably should profile such sometime), but I think the
extend operations could be merged into simple assignments by the
optimizer at some stage (or further cleaned up when this stuff gets
moved to actual code gen where it should be).
2023-08-25 22:34:41 +09:00
Bill Currie
60ce4ba8fb [qfcc] Give direct access to algebra subtypes
Currently via only the group mask (which is really horrible to work
with: requires too much knowledge of implementation details, but does
the job for testing), but it got some basics working.
2023-08-25 22:13:54 +09:00
Bill Currie
d2e134cc22 [qfcc] Support multiple parameters for attributes
I have no idea why I threw away all but the *last* parameter (especially
considering nothing used parameters until now).
2023-08-25 22:13:54 +09:00
Bill Currie
b2301c8bad [qfcc] Implement 3d PGA geometric algebra
No clue whether anything is actually correct. Time to start creating
real tests.
2023-08-25 22:13:54 +09:00
Bill Currie
e888f71f8a [qfcc] Fetch sum operand type early
Because component_sum works in-place, using a[i]'s type after setting
c[i] resulting in a null type and thus a segfault.
2023-08-25 22:13:54 +09:00
Bill Currie
a46f9a63d2 [qfcc] Clean up GA sum and scale expressions
Scale was inconsistent and sum was error prone due to using
new_binary_expression raw.
2023-08-25 17:24:47 +09:00
Bill Currie
53d9fee586 [qfcc] Support the extended extend instruction
That... feels odd :)
2023-08-25 17:20:28 +09:00
Bill Currie
7338f86c77 [gamecode] Extend extend to support reversal
Using swizzle for some of the geometric product operations was a bit
clunky and has problems with alignment. While I will still need it in
the future, it turns out that the extend instruction almost did what I
needed. However, I'm unsure that reversing components within an extended
vector is the way to go.
2023-08-25 10:30:14 +09:00
Bill Currie
55bdcbe4c5 [qfcc] Implement 2d PGA geometric product
This is definitely showing the need for better vector instructions
(mostly a 2d wedge and width dependent swizzles).
2023-08-24 22:07:04 +09:00
Bill Currie
e66ae0aad6 [qfcc] Correct swizzle expressions
It turned out they were always using floats for the source type (meaning
doubles were broken), and not shifting the component in the final sizzle
code meaning all swizzles were ?xxx (neglecting minus or 0). I'd make
tests, but I plan on modifying the instruction set a little bit.
2023-08-24 21:43:09 +09:00
Bill Currie
fb6d3f2f86 [gamecode] Decode the swizzle operand
-yx00 is much easier to interpret than some "random" number.
2023-08-24 20:17:17 +09:00
Bill Currie
5f22fd07d9 [qfcc] Implement 3d PGA dot products
Also, correct the handling of scalars in dot and wedge products: it
turns out s.v and s^v both scale. However, it seems the CSE code loses
things sometimes.
2023-08-24 15:49:52 +09:00
Bill Currie
6d75d91de2 [qfcc] Implement 2d PGA dot (inner) product
This has shown the need for more instructions, such as a 2d wedge
product and narrower swizzles. Also, making dot product produce a vector
instead of a scalar was a big mistake (works nicely in C, but not so
well in Ruamoko).
2023-08-24 00:19:58 +09:00
Bill Currie
469fdea0a1 [qfcc] Implement 2d PGA outer products
The specialization is really just in the layout.
2023-08-23 21:52:33 +09:00
Bill Currie
da1b797cb7 [qfcc] Get scalar promotion working again
The cleanup of the scalar expressions lost the type promotion so using
ints in expressions didn't always work.
2023-08-23 21:51:01 +09:00
Bill Currie
d7bab4e222 [qfcc] Avoid constant folding for vector types
The current code is pretty broken when it comes to vector types (losing
the vector and bogus errors among other issues). The whole thing needs a
rework or even just to be tossed in favor of better DAG processing.
2023-08-23 21:48:25 +09:00
Bill Currie
c550ab6b86 [qfcc] Switch 2d PGA groups to be easily implemented
I guess Hamish's suggestion made sense at the time, but I found that
with the current instructions, the reversed bivector wasn't so nice to
implement it would need a swizzle as well as the cross-product.
2023-08-23 21:43:14 +09:00
Bill Currie
8ff2c5a747 [util] Support utf-8 strings in Sys_Printf
By default. Conversion of quake strings needs to be requested (which is
done by nq and qw clients and servers, as well as qfprogs via an
option). I got tired of seeing mangled source code in the disassembly.
2023-08-23 21:40:50 +09:00
Bill Currie
30f2abb0ad [gamecode] Correct 64-bit debug views
I had forgotten that value needs to be incremented by 2 for 64-bit
values because it's only 32-bit.
2023-08-23 21:39:06 +09:00
Bill Currie
24c085c1bd [qfcc] Implement 3d-PGA wedge products
Not all possibilities have been tested yet, but the initial code looks
good even if it has a couple of excessive temporary variables.
2023-08-23 15:38:32 +09:00
Bill Currie
c92dd9d86c [type] Use vec4 and vec3 in Ruamoko progs
I'm not sure if that was a thinko, typo, or something else, but judging
by the relevant commit message, the use of quaternion and vector was
intended only for advanced progs (v6p).
2023-08-23 15:38:32 +09:00
Bill Currie
0d639510e3 [qfcc] Add a function to create typed zero expressions
Sometimes, nil's untyped 0 isn't really suitable.
2023-08-23 15:38:32 +09:00
Bill Currie
deb03ca27a [qfcc] Set correct statement type for memset
Explicit memset expressions were becoming move instructions when
optimizing, which would generally not result in correct values.
2023-08-23 15:38:32 +09:00
Bill Currie
0d491ce68c [qfcc] Build multi-vector expressions correctly
Losing the other components and getting the offset wrong doesn't make
for a correct multi-vector expression when pulling apart a multi-vector
def.
2023-08-23 15:38:32 +09:00
Bill Currie
d75bf346f3 [qfcc] Support multivec expressions for dot
They don't normally survive to the block-dot stage, but being able to
see the graphs when debugging.
2023-08-23 15:38:32 +09:00
Bill Currie
cfcacfbf28 [qfcc] Use scatter-gather for multivec expressions
This makes working with them much easier, and the type system reflects
what's in the multi-vector. Unfortunately, that does mean that large
algebras will wind up having a LOT of types, but it allows for efficient
storage of sparse multi-vectors:

    auto v = 4*(e1 + e032 + e123);

results in:

    0005 0213 1:0008<00000008>4:void     0:0000<00000000>?:invalid
              0:0044<00000044>4:void          assign (<void>), v
    0006 0213 1:000c<0000000c>4:void     0:0000<00000000>?:invalid
              0:0048<00000048>4:void          assign (<void>), {v + 4}

Where the two source vectors are:

    44:1 0 .imm float:18e [4, 0, 0, 0]
    48:1 0 .imm float:1aa [4, 0, 0, 4]

They just happen to be adjacent, but don't need to be.
2023-08-23 15:38:32 +09:00
Bill Currie
dfb719c92b [qfcc] Correct scaling and multivec sums
Scaling now works for multi-vector expressions, and always subtracting
even when addition is wanted doesn't work too well. However, now there's
the problem of multi-vectors very quickly becoming full algebra vectors,
which means certain things need a rethink.
2023-08-21 20:10:13 +09:00
Bill Currie
2e91b29580 [qfcc] Start work on implementing geometric algebra
This gets only some very basics working:
 * Algebra (multi-vector) types: eg @algebra(float(3,0,1)).
 * Algebra scopes (using either the above or @algebra(TYPE_NAME) where
   the above was used in a typedef.
 * Basis blades (eg, e12) done via procedural symbols that evaluate to
   suitable constants based on the basis group for the blade.
 * Addition and subtraction of multi-vectors (only partially tested).
 * Assignment of sub-algebra multi-vectors to full-algebra multi-vectors
   (missing elements zeroed).

There's still much work to be done, but I thought it time to get
something into git.
2023-08-21 17:58:20 +09:00
Bill Currie
cb9a82e74c [qfcc] Allow symbol tables to have procedural symbols
If a symbol is not found in the table and a callback is provided, the
callback will be used to check for a valid procedural symbol before
moving on to the next table in the chain. This allows for both tight
scoping of the procedural symbols and caching.
2023-08-21 17:47:55 +09:00
Bill Currie
dfb7862419 [qfcc] Use the progs VM to help with constant folding
Due to joys of pointers and the like, it's a bit of a bolt-on for now,
but it works nicely for basic math ops which is what I wanted, and the
code is generated from the expression.
2023-08-21 17:47:55 +09:00
Bill Currie
27ccad40c9 [qfcc] Split out the conversion evaluation code
This takes care of the FIXME regarding breaking it out for more general
use (the time has come to redo constant folding).
2023-08-21 17:47:55 +09:00
Bill Currie
b4afaab03c [gamecode] Support wide types in type views
Now the new vector types print properly :)

    0003 scale.F{4,1,4} ([1, 0, 0, 0]), (3), p1
2023-08-21 17:47:55 +09:00
Bill Currie
a64895b98f [qfcc] Include C function in diagnostic messages
It's kind of redundant with the line number, but it's helpful for seeing
the context at a glance.
2023-08-21 17:47:55 +09:00
Bill Currie
b9fd7a46af [qfcc] Implement auto as per c23
That was surprisingly easy, which makes me worried I missed something.
2023-08-21 17:47:55 +09:00
Bill Currie
cb4b073e47 [qfcc] Support some unicode ops and GA ops
Only · (dot product) and × (cross product for vector, commutator product
for geometric algebra) have been tested so far, but that involved
fighting with cpp to get it to not convert the · to \U000000b7, which
was rather annoying.
2023-08-21 17:47:55 +09:00
Bill Currie
a0ddc2b2bd [qfcc] Support explicit dot product in v6p code
The dot product in v6p code returns a float rather than a vector.
2023-08-21 17:47:55 +09:00
Bill Currie
74405ee31b [gamecode] Switch dstatement ops to signed
I realized recently that I had made a huge mistake making Ruamoko's
based addressing use unsigned offsets as it makes stack-relative
addressing more awkward when it comes to runtime-determined stack frames
(eg, using alloca). This does put a bit of an extra limit on directly
addressable globals, but that's what the based addressing is meant to
help with anyway.
2023-08-21 17:47:55 +09:00
Bill Currie
a238eac75b [vulkan] Ensure the barriers array is initialized
I'm not sure what's up, but arm gcc thinks the array isn't properly
initialized even though x86_64 gcc does. Maybe something with padding.
At least c23 makes it easy to 0-initialize VLAs.
2023-08-17 12:54:28 +09:00
Bill Currie
ab5f28f743 [vulkan] Allocate map spaces for dynamic lights
I'm actually surprised anything worked, though I guess it was just the
one entry getting corrupted (and not 32, but I figured allocate slots
for all of the dynamic lights just in case). Or none, really, since
larger scenes (ie, those with multiple lights that fit in the same image
size) would result in not all the maps getting used and thus one spare
for dynamic lights.
2023-08-16 10:54:42 +09:00