Commit graph

5154 commits

Author SHA1 Message Date
Bill Currie
875d4dc7cf [gamecode] Correct some ruamoko instruction meta data
There were some errors in instruction names and operand types resulting
in unsearchable instructions.
2022-01-20 13:08:05 +09:00
Bill Currie
a4ebd6aa58 [gamecode] Fix a few missed opcode renames
if and ifnot became ifnz and ifz, and return_v lost its tail (it was
always redundant, except in dags, and that's fixed with a pointer check).
2022-01-20 13:07:57 +09:00
Bill Currie
143030fec4 [gamecode] Use text for all v6p opcode names
This makes the v6p instruction table consistent with the ruamoko
instruction table, and clears up some of the ugliness with the load,
store, and assign instructions (. .= and = are now spelled out). I think
I'd still prefer an enum code (faster) but at least this is more
readable.
2022-01-20 09:26:01 +09:00
Bill Currie
df890432b7 [qfcc] Add support for unsigned, long, etc
long is ignored for double, and v6p progs are stuck with 32 bits for
longs (don't feel like extending v6p any further), but the basics are
there for Ruamoko.

short is ignored for ints because the minimum size is 32, and signed is
just noise for ints anyway (and no chars, so...).

unsigned, however, is finally implemented properly (or at least seems to
be working correctly: tests pass after getting things compiling again,
and lt.u is used where it should be :)
2022-01-19 18:08:58 +09:00
Bill Currie
8d20997b2b [gamecode] Move pr_void_t to pr_comp.h
I think I had decided to put it there but forgot before committing the
size change, but I wound up needing it for qfcc.
2022-01-18 22:58:26 +09:00
Bill Currie
068c04ece6 [gamecode] Add ev_ushort and partial support
Really, only just enough to get everything compiling (which does include
vkgen running correctly).
2022-01-18 22:08:37 +09:00
Bill Currie
ed501b7734 [gamecode] Specify the alignment for progs types
And provide a table for such for qfcc and the like. With this, using
pr_double_t (for example) in C will cause the double value to always be
8-byte aligned and thus structures shared between gcc and qfcc will be
consistent (with a little fuss to take care of the warts).
2022-01-18 18:41:39 +09:00
Bill Currie
25f8d3a23d [gamecode] Use pr_type_names.h for type sizes
The goal of the previous mess of commits. Ruamoko needs to wait until
qfcc has the new types.
2022-01-18 17:05:12 +09:00
Bill Currie
2c52e26d1a [gamecode] Be more consistent with access types
Eg, pointers via ptr, entities via entity, etc.
2022-01-18 17:05:12 +09:00
Bill Currie
cd30408675 [gamecode] Rename ev_quat to ev_quaternion
I much prefer the full name, though the short version is easier to type.
2022-01-18 17:05:12 +09:00
Bill Currie
e9e54d08c0 [gamecode] Rename func_t to pr_func_t
Even more consistency.
2022-01-18 15:36:58 +09:00
Bill Currie
afd1eb775b [gamecode] Rename ev_pointer to ev_ptr
Rather short (no worse than ev_int, though) but more consistency is
usually a good thing.
2022-01-18 14:36:06 +09:00
Bill Currie
cfe7c44df0 [gamecode] Rename ev_integer to ev_int
And other related fields so integer is now int (and uinteger is uint). I
really don't know why I went with integer in the first place, but this
will make using macros easier for dealing with types.
2022-01-18 13:27:19 +09:00
Bill Currie
978d6fd3e8 [gamecode] Macro-ize the progs type names
Now they'll never get out of sync again :)
2022-01-18 13:27:19 +09:00
Bill Currie
2df64384c1 [gamecode] Clean up string_t and pointer_t
They are both gone, and pr_pointer_t is now pr_ptr_t (pointer may be a
little clearer than ptr, but ptr is consistent with things like intptr,
and keeps the type name short).
2022-01-18 12:11:14 +09:00
Bill Currie
9348f7b89c [gamecode] Preserve the return pointer across calls
This required delaying the setting of the return pointer by call until
after the current pointer had been saved, and thus passing the desired
pointer into PR_CallFunction (which does have some advantages for C
functions calling progs functions, but some dangers too (should ensure a
128 byte (32 word) buffer when calling untrusted code (which is any,
really)).
2022-01-17 19:12:28 +09:00
Bill Currie
e9af549195 [gamecode] Fix some goofs in the callchain test
They made it difficult to tell when I got things working :P
2022-01-17 18:51:50 +09:00
Bill Currie
306fcbfbd0 [gamecode] Improve callchain test
Add another function call to further mess up the return value address
and verify just where it is pointing.
2022-01-17 16:55:39 +09:00
Bill Currie
89e120ba34 [gamecode] Make return support 32 words
This took interpreting the lower 5 bits of operand c as size - 1, and
0xffff as void (0 words).
2022-01-17 16:54:27 +09:00
Bill Currie
94ef9931a5 [gamecode] Add two more call/return tests
The two tests check that 32 words can be returned (fails) and that
function calls can be nested and their values returned properly (also
fails).
2022-01-17 16:30:13 +09:00
Bill Currie
736387bc88 [gamecode] Preserve base registers across calls
With this, functions can call other functions without having to worry
about whether the base registers they set up are still valid.
2022-01-17 15:08:58 +09:00
Bill Currie
8da1163a82 [gamecode] Add bases check to callret test
The base registers must be preserved across a function call and they
currently are not, thus the updated test fails again.
2022-01-17 14:59:17 +09:00
Bill Currie
213434b705 [gamecode] Save and restore data stack in call stack
This fixes the issue of the data stack not being restored properly
because the returning function needs to return a value from its local
variables (stored on the stack) and accessing stack data below the stack
pointer is a bad idea (sure, no interrupts yet, but who knows...).
2022-01-17 14:45:14 +09:00
Bill Currie
8e5c2c6534 [gamecode] Correct type of return address in stack
This is another one of those "why signed?" things: can't have negative
return addresses.
2022-01-17 14:43:43 +09:00
Bill Currie
cf3106ce28 [gamecode] Correct call's mode selection
Call's operand c is used to specify where the return value of the
function is to be stored. This gets both the correct function being
called, and the value being returned correctly. Test still fails due to
the stack restoration issue.
2022-01-17 14:29:14 +09:00
Bill Currie
b3909dbe4c [gamecode] Add a test for call and return
It currently fails for two reasons:
 - call's mode selection is incorrect (never updated from when there was
   only the one call instruction and the mode was encoded in operand c)
 - return should automatically restore the stack pointer to the value it
   had on entry to the function, thus allowing local values stored on
   the stack to be safely returned.
2022-01-17 14:26:12 +09:00
Bill Currie
56d8bdee82 [gamecode] Add a fixme about using gcc's vec convert
It might produce better code than the way I'm currently doing it.
2022-01-17 10:32:19 +09:00
Bill Currie
1beadbf871 [gamecode] Add tests for the branch instructions 2022-01-17 09:57:54 +09:00
Bill Currie
1baf17b780 [gamecode] Add tests for the jump instructions 2022-01-17 09:34:16 +09:00
Bill Currie
1397c94ef5 [gamecode] Add tests for the state instructions 2022-01-16 22:17:17 +09:00
Bill Currie
0bd05c71ac [gamecode] Use unsigned for entity values
I don't know why they were ever signed (oversight at id and just
propagated?). Anyway, this resulted in "unsigned" spreading a bit, but
all to reasonable places.
2022-01-16 22:15:18 +09:00
Bill Currie
2b82533526 [gamecode] Add double time state instructions
This has been a long-held wishlist item, really, and I thought I might
as well take the opportunity to add the instructions. The double
versions of STATE require both the nextthink field and time global to be
double (but they're not resolved properly yet: marked with
"FIXME double time" comments).

Also, the frame number for double time state is integer rather than
float.
2022-01-16 21:27:49 +09:00
Bill Currie
d57712975e [gamecode] Add tests for the hops instructions
And, of course, fix a bug in the inverted hops (yay for tests).
2022-01-16 18:46:29 +09:00
Bill Currie
7ea12b3ff9 [gamecode] Implement the HOPS sub-instructions
In the end, I decided any/all/none should be separate from the other
horizontal ops, if I even do them (can be implemented by first
converting to bool, then using the appropriate horizontal operation (& |
etc).
2022-01-16 16:28:48 +09:00
Bill Currie
8050c7bd77 [gamecode] Rearrange several instructions
ANY/ALL/NONE have been temporarily removed until I implement the HOPS
(horizontal operations) sub-instructions, which will all both 32-bit and
64-bit operands and several other operations (eg, horizontal add).

All the fancy addressing modes for the conditional branch instructions
have been permanently removed: I decided the gain was too little for the
cost (24 instructions vs 6). JUMP and CALL retain their addressing
modes, though.

Other instructions have been shuffled around a little to fill most of
the holes in the upper block of 256 instructions: just a single small
7-instruction hole.

Rearrangements in the actual engine are mostly just to keep the code
organized. The only real changes were the various IF statements and
dealing with the resulting changes in their addressing.
2022-01-16 14:22:04 +09:00
Bill Currie
dc4df49fff [gamecode] Add tests for the swizzle instructions
While not always generated (yet?) the tests are at least in. Just not
sure about auto-generated tests that can't be hand-edited.
2022-01-15 22:44:58 +09:00
Bill Currie
49dcd5ef40 [gamecode] Add tests for the with instruction(s)
While mode 4 was tested a lot, none of the rest were. Also added a full
reset instruction.
2022-01-15 18:44:11 +09:00
Bill Currie
38ab0f0243 [gamecode] Move pushregs and popregs into with
This frees up another two instructions.
2022-01-15 16:51:59 +09:00
Bill Currie
a14b9f8252 [gamecode] Move the lea block
It just feels better with it being close the load/store etc
2022-01-15 16:39:52 +09:00
Bill Currie
e133de8c89 [gamecode] Drop B addressing for lea
When creating the tests for lea, I noticed that B was yet another simple
assign, so I decided it was best to drop it and move E into its place
(freeing up another instruction).
2022-01-15 16:27:46 +09:00
Bill Currie
11e89c8c97 [gamecode] Add tests for lea 2022-01-15 16:07:11 +09:00
Bill Currie
fae432f46e [gamecode] Make no-op conversions simple copies
Most useful for 64-bit values as only one instruction is needed to move
the data around rather than two, but could be slightly faster for 32-bit
as the addressing is simpler (needs profiling).
2022-01-15 15:44:53 +09:00
Bill Currie
bffcbfc9fc [gamecode] Add tests for bitops 2022-01-15 13:59:03 +09:00
Bill Currie
7cd398d4a7 [gamecodee] Add tests for move and memset 2022-01-15 13:20:33 +09:00
Bill Currie
6f1f56aea7 [gamecode] Make commented braces match
They annoyed me
2022-01-14 22:51:18 +09:00
Bill Currie
1aa4844bf6 [gamecode] Make string ops mostly conform with bools
The compare/ne operator returns "random" -ve, 0, +ve values (really,
just the numerical difference between the chars of the strings), but all
the rest return -1 for true and 0 for false, as with the rest of the
comparison operators.
2022-01-14 22:44:08 +09:00
Bill Currie
c8362c28fe [gamecode] Add tests for string ops
Does not include string concatenation because I don't feel like messing
with zone init, but all the other operators are tested (currently
failing due to bool convention)
2022-01-14 22:42:56 +09:00
Bill Currie
f4eeed36b7 [gamecode] Add tests for the scale instructions 2022-01-14 19:46:35 +09:00
Bill Currie
1a2ac24d8d [gamecode] Make num_globals() calculate actual globals
It calculating only the size of the array (which was often 4 or 8
globals per element) proved to be a pain when I forgot to alter the size
for the new scale tests. Fixing the size calculation even found a bug in
the shiftop tests.
2022-01-14 19:45:51 +09:00
Bill Currie
a81067603c [gamecode] Mention possibly undefined behavior
It seems casting from float/double to [unsigned] int/long when the value
doesn't fit is undefined (which would explain the inconsistent results).
Mentioning the possibility seems like a good idea should the results for
such casts change and cause the tests to fail.
2022-01-14 16:52:44 +09:00
Bill Currie
a1c1c9fcf0 [gamecode] Add test for conversions to double
And fix an incorrect base index in the bool64 tests.
2022-01-14 15:51:49 +09:00
Bill Currie
1f73b26d24 [gamecode] Correct incorrect bool32-bool64 conversion
And add tests for long, ulong and bool64 conversions.
2022-01-14 14:54:35 +09:00
Bill Currie
4bf934e6b9 [gamecode] Correct incorrect bool64-bool32 conversion
And add tests for float, uint and bool32 conversions.
2022-01-14 13:54:03 +09:00
Bill Currie
e26fb49df7 [gamecode] Get conversion to int working for all types
Bools turned out to be a problem to due to me wanting any non-zero value
to be treated as true thus had to expand them out as well as the
floating point <-> integral conversions.
2022-01-14 12:11:23 +09:00
Bill Currie
cd68455e46 [gamecode] Add tests for converting to int
They currently fail because for vector values, gcc casts the view, not
the value, so vec4 cast to ivec4 simply views the bits as int rather
than doing the actual conversion.
2022-01-14 12:11:22 +09:00
Bill Currie
e8e0a69628 [gamecode] Add conversions to/from bool
For now, from bool results in 0/1, but conversion to bool guarantees
0/-1 and correct interpretations for floating point types.
2022-01-13 17:37:44 +09:00
Bill Currie
ba1d73200f [gamecode] Clean up a pile of duplicate code
All those duplicated formats were getting unwieldy, especially as I want
to add more conversion modes.
2022-01-13 16:10:06 +09:00
Bill Currie
3eb2194343 [gamecode] Invert the meaning of the skip matrix
Rather than specifying that the conversion should be skipped, it now
specifies the mode of the conversions (with 0 being no conversion). This
is in preparation for boolean conversion.
2022-01-13 15:58:12 +09:00
Bill Currie
6f6f47e27e [gamecode] Drop bool ops in favor of long bit ops
I realized that being able to do bit-wise operations with 64-bit values
(and 256-bit vectors) is far more important than some convenient boolean
logic operators. The logic ops can be handled via the bit-wise ops so
long as the values are all properly boolean, and I plan on adding some
boolean conversion ope, so no real loss.
2022-01-13 14:24:11 +09:00
Bill Currie
424bdcbf96 [gamecode] Implement the scale instructions
Both float 2,3,4 vectors and double 2,3,4 vectors (1 would be just a
copy of the mul instructions).

This completes the currently planned instructions. Now for testing.
2022-01-13 13:53:07 +09:00
Bill Currie
3587b13a40 [gamecode] Implement the conversion instructions
Not all possibilities are supported because converting between int and
uint, and long and ulong is essentially a no-op. However, thanks to
Deek's suggestion, not only are all reasonable conversions available,
conversions for all widths are available, so vector conversions are
supported.

The code for the conversions is generated.
2022-01-13 13:51:24 +09:00
Bill Currie
f7181a09b4 [gamecode] Add tests for shiftops
They're in test-unsigned because 2/3 of them are unsigned.
2022-01-12 10:24:59 +09:00
Bill Currie
6229ae8ecc [gamecode] Add tests for unsigned comparisons
And fix the implementation: I had used the wrong macro.
2022-01-11 13:00:54 +09:00
Bill Currie
e7d7ec1989 [gamecode] Add tests for signed comparison ops
Fortunately, they all pass without issues.
2022-01-11 09:37:38 +09:00
Bill Currie
0fb6619585 [gamecode] Compact the convert instructions into one
Thanks to Deek for the suggestion: the mode (ie, src and dst types) are
encoded in st->b. Actual code not written yet, but this frees up 13
instructions: now have 74 available for really interesting stuff :)
2022-01-10 11:53:57 +09:00
Bill Currie
b9e32ee2f5 [gamecode] Rework call and return instructions
The call1-8 instructions have been removed as they are really not needed
(they were put in when I had plans of simple translation of v6p progs to
ruamoko, but they joined the dinosaurs).

The call instruction lost mode A (that is now return) and its mode B is
just the regular function access. The important thing is op_c (with
support for with-bases) specifies the location of the return def.

The return instruction packs both its addressing mode and return value
size into st->c as a 3.5 value: 3 bits for the mode (it supports all
five addressing modes with entity.field being mode 4) and 5 for the
size, limiting return sizes to 32 words, which is enough for one 4x4
double matrix.

This, especially with the following convert patch, frees up a lot of
instructions.
2022-01-10 11:53:14 +09:00
Bill Currie
ba29be3f82 [gamecode] Rename ifnot and if to be less confusing
I think :) anyway, now they're ifz and ifnz, making them consistent with
the rest of the if instructions.
2022-01-10 11:27:57 +09:00
Bill Currie
db7a67e5b7 [gamecode] Rearrange vector instructions
This allows the dot products to be consistent with their sizes: cdot is
really dot_2, vdot dot_3, and qdot dot_4.
2022-01-10 11:16:55 +09:00
Bill Currie
494a6908bb [gamecode] Improve with's comment 2022-01-10 11:04:43 +09:00
Bill Currie
86e81ba250 [gamecode] Rearrange the branch instructions
Now they're in a much more consistent arrangement, in particular with
the comparison opcodes if the conditional branch instructions are
considered to be fast comparisons with zero (ifnot -> ifeq, if -> ifne,
etc). Unconditional jump and call fill in the gaps. The goal was to get
them all in an arrangement that would work as a small enum for qfcc: it
can use the enum directly for the ruamoko IS, and a small map array for
v6p (except for call).
2022-01-09 01:07:23 +09:00
Bill Currie
7d5c692313 [gamecode] Generate the new opcodes enum too
It turns out I'll be tweaking it more than I expected.
2022-01-09 01:04:51 +09:00
Bill Currie
4111d44dcc [gamecode] Move progs auxiliary headers into a subdirectory
Just another step along the road of tidying up the QF include directory
(and desirable for generated data).
2022-01-09 00:26:52 +09:00
Bill Currie
ed6b84fbde [gamecode] Add missed long and ulong info
Both pr_type_size and pr_type_name. I want to macroize the enum, but
need to sort out the clutter of headers first, just need to decide on
naming. This at least sorts out the missed values for now.
2022-01-08 03:07:17 +09:00
Bill Currie
e186d5064d [gamecode] Correct return's opname
Not meant to have the size in it.
2022-01-07 21:48:19 +09:00
Bill Currie
8559a4fe2d whitespace 2022-01-07 21:48:02 +09:00
Bill Currie
14d95f81d1 [gamecode] Remove PR_Opcode_Init
It was idempotent, then it became impotent. Now it's just not needed.
2022-01-07 19:25:34 +09:00
Bill Currie
aee31a8be5 [sys] Use tailless INT64_C macro
I guess I missed the non-internal version when searching for it before.
2022-01-06 22:27:42 +09:00
Bill Currie
1cb35b1fe3 [gamecode] Fix some more operand formats
With and relative branches.
2022-01-06 22:27:09 +09:00
Bill Currie
0d9294d541 [gamesource] Work around a windows gcc bug
The bug (alignment issues with AVX on windows) seems to have in gcc from
the 4.x days, and is still present in 11.2: it does not ensure stack
parameters that need 32 byte alignment are aligned. Telling gcc to use
the sysv abi (safe on a static function) lets gcc do what it does for
linux (usually pass the parameters in registers, which it seems to have
done).
2022-01-06 22:21:24 +09:00
Bill Currie
c3317f8e5e [gamecode] use INT64_C instead of l-suffix
Once again, I had forgotten that long is not always 64-bits.
2022-01-06 22:20:16 +09:00
Bill Currie
80c5e2c3f6 [simd] Remove requirements for AVX2 for vec4d
It seems gcc-11 does a pretty good job of emulating the instructions (it
no longer requires avx2 for 256-bit wide vectors).
2022-01-06 18:06:56 +09:00
Bill Currie
c0277c0b03 [gamecode] Fix incorrect entity load format
Had a typo in load and forgot to edit lea, but now they share the
formats (like they should have in the first place).
2022-01-06 11:51:38 +09:00
Bill Currie
d9d37fda47 [gamecode] Implement ruamoko opcode lookup
And get the debugger working with the new instruction set.
2022-01-06 11:47:05 +09:00
Bill Currie
c74cfb9bf6 [gamecode] Generate instruction widths and types
Not everything is correct, but this is enough to get started on
supporting disassembly in the various tools and code generation in qfcc.
2022-01-05 22:33:59 +09:00
Bill Currie
c9b2a740a0 [gamecode] Add etypes for long and ulong
And partial implementations in qfcc (most places will generate an
internal error (not implemented) or segfault, but some low-hanging fruit
has already been implemented).
2022-01-05 22:32:07 +09:00
Bill Currie
0b92cd3a88 [gamecode] Generate the new opcode table
As I expect to be tweaking things for a while, it's part of the build
process. This will make it a lot easier to adjust mnemonics and argument
formats (tweaking the old table was a pain when conventions changed).

It's not quite done as it still needs arg widths and types.
2022-01-05 19:09:07 +09:00
Bill Currie
0b674f5ed4 [gamecode] Clean up some opcode names
While working on the new opcode table, I decided a lot of the names were
not to my liking.  Part of the problem was the earlier clash with the
v6p opcode names, but that has been resolved via the v6p tag.
2022-01-05 19:04:43 +09:00
Bill Currie
6d9c63999c [gamecode] Rename pr_opcode.c
Just to make way for new tables :)
2022-01-04 20:45:45 +09:00
Bill Currie
35387b5450 [gamecode] Fix a pile of incorrect base register refs
The problem with copying code is it's all to easy to forget to make all
necessary edits.
2022-01-04 19:01:05 +09:00
Bill Currie
59292393e6 [gamecode] Fix up MOD (%%) for integral types
Use the new "1" versions of loadvec3 to get a 1 in w to avoid
divide-by-zero errors, and use the correct type for longs (forgot to
change i to l on the vector types).
2022-01-04 18:36:13 +09:00
Bill Currie
2f09ece65b [gamecode] Add more modes to WITH
It turned out I had no way of using a pointer or field as the value to
load, so all 4 modes are duplicated with loads from where operand b
points, but the loaded value interpreted the same way. Also, fixed an
error in the calculation of op-b offsets.
2022-01-04 17:55:20 +09:00
Bill Currie
f2b258ba76 [gamecode] Add statement bounds checking
Statements can be bounds checked in the one place (jump calculation),
but memory accesses cannot as they can be used in lea instructions which
should never cause an exception (unless one of lea's operands is OOB).
2022-01-04 17:53:10 +09:00
Bill Currie
9d74fcc181 [gamecode] Add tests for the basic math ops
* / % %% + -

As a bonus, includes partial tests for a few extra operators. Several
things are broken at this stage, but uncommitted code is already
working.
2022-01-04 17:50:49 +09:00
Bill Currie
5de4c21557 [gamecode] Fix relative offset jumps
Yet another missed sign extension.
2022-01-04 14:30:20 +09:00
Bill Currie
4777f44ba1 [gamecode] Rename test-math to test-vector
I decided to stick with the minimal tests per test program rather than
try to cram all the math operator tests into the one program.
2022-01-03 23:50:38 +09:00
Bill Currie
a6badaa05d [gamecode] Complete the vector instruction tests
Finish up the float tests and add double tests.
2022-01-03 23:27:01 +09:00
Bill Currie
6de1ba6901 [gamecode] Clean up the conversion instructions
Float bit-ops as well.

Also, add q*v4 and v4*q instructions. There are currently 48 free
opcodes, and I might remove the scale instructions, but they could be
useful as expanding a single float to a vector would take 3 instructions
(copy to temp, swizzle-expand temp, multiply, vs just scale).
2022-01-03 23:27:01 +09:00
Bill Currie
b6f9b68434 [gamecode] Implement 64-bit swizzles
See commit for 32-bit swizzles.
2022-01-03 23:27:01 +09:00
Bill Currie
bebc811f11 [gamecode] Implement 4-component 32-bit swizzle
The swizzle instruction is very powerful in that in can do any of the
256 permutations of xyzw, optionally negate any combination of the
resulting components, and zero any combination of the result components
(even all). This means the one instruction can take care of any actual
swizzles, conjugation for complex and quaternion values, zeroing vectors
(not that it's the only way), and probably other weird things.

The python file was used to generate the jump table and actual swizzle
code.
2022-01-03 23:27:01 +09:00
Bill Currie
b8d04874c3 [gamecode] Add some math tests
Hit a show stopper when it came to swizzle (not implemented yet). I
guess I know what I need to do next :P.
2022-01-03 23:27:01 +09:00
Bill Currie
fd298f3601 [gamecode] Create a mask for extracting the opcode
Got tired of copying the full thing around.
2022-01-03 23:27:01 +09:00
Bill Currie
ffbb6122b9 [gamecode] Add tests for push and pop 2022-01-03 23:27:01 +09:00
Bill Currie
c86f1f671b [gamecode] Add tests for load instructions
This needed the test struct declaration to be moved out to a head file
so it can be shared with other tests.
2022-01-03 23:27:01 +09:00
Bill Currie
28df32eb0d [gamecode] Use pr_memset instead of memset
This keeps things inline and matches the quakec exec loop. Also removes
the need to calculate the size.
2022-01-03 23:27:01 +09:00
Bill Currie
bf604b99b3 [gamecode] Add automated tests for store ops
They even found a bug in the addressing mode functions :) (I'd forgotten
that I wanted signed offsets from the pointer and thus forgot to cast
st->b to short in order to get the sign extension)
2022-01-03 23:27:01 +09:00
Bill Currie
920c5fd99b [gamecode] Add debug event name strings
Makes it easier to print nice debug event messages.
2022-01-03 23:26:50 +09:00
Bill Currie
8a2788c267 [gamecode] Add PROG_V6P_VERSION and bump PROG_VERSION
This allows the VM to select the right execution loop and qfcc currently
still produces only the old IS (it doesn't know how to deal with the new
IS yet)
2022-01-03 13:56:43 +09:00
Bill Currie
925797b1d4 [gamecode] Add a new Ruamoko instruction set
When it's finalized (most of the conversion operations will go, probably
the float bit ops, maybe (very undecided) the 3-component vector ops,
and likely the CALLN ops), this will be the actual instruction set for
Ruamoko.

Main features:
 - Significant reduction in redundant instructions: no more multiple
   opcodes to move the one operand size.
 - load, store, push, and pop share unified addressing mode encoding
   (with the exception of mode 0 for load as that is redundant with mode
   0 for store, thus load mode 0 gives quick access to entity.field).
 - Full support for both 32 and 64 bit signed integer, unsigned integer,
   and floating point values.
 - SIMD for 1, 2, (currently) 3, and 4 components. Transfers support up
   to 128-bit wide operations (need two operations to transfer a full
   4-component double/long vector), but all math operations support both
   128-bit (32-bit components) and 256-bit (64-bit components) vectors.
 - "Interpreted" operations for the various vector sizes: complex dot
   and multiplication, 3d vector dot and cross product, quaternion dot
   and multiplication, along with qv and vq shortcuts.
 - 4-component swizzles for both sizes (not yet implemented, but the
   instructions are allocated), with the option to zero or negate (thus
   conjugates for complex and quaternion values) individual components.
 - "Based offsets": all relevant instructions include base register
   indices for all three operands allowing for direct access to any of
   four areas (eg, current entity, current stack frame, Objective-QC
   self, ...) instructions to set a register and push/pop the four
   registers to/from the stack.

Remaining work:
 - Implement swizzle operations and a few other stragglers.
 = Make a decision about conversion operations (if any instructions
   remain, they'll be just single-component (at 14 meaningful pairs,
   that's a lot of instructions to waste on SIMD versions).
 - Decide whether to keep CALL1-CALL8: probably little point in
   supporting two different calling conventions, and it would free up
   another eight instructions.
 - Unit tests for the instructions.
 - Teach qfcc to generate code for the new instruction set (hah, biggest
   job, I'm sure, though hopefully not as crazy as the rewrite eleven
   years ago).
2022-01-03 00:49:49 +09:00
Bill Currie
0c17c6dc24 [gamecode] Rename the old opcodes
To reflect their basis on v6 progs instructions, they sport the v6p tag
where the p is for "plus" due to the QuakeForge extensions.
2022-01-02 21:30:02 +09:00
Bill Currie
bc0a09f452 [gamecode] Switch to using type parameter op macros
I wish I'd done it this way years ago (but maybe gcc 2.95 couldn't hack
the casts, I do know there were aliasing problems in the past). Anyway,
this makes operand access much more consistent for variable sized
operands (eg float vs double vs vec4), and is a big part of the new
instruction set implementation.
2022-01-02 20:46:32 +09:00
Bill Currie
7b0eceda32 [gamecode] Split out the old quake c execution loop
There is no reasonable way (due to hardware-enforced alignment issues)
to simply convert old bytecode to new (probably best done with an
off-line tool, preferably just recompiling when I get qfcc up to the
job), so both loops will need to be present. This just moves the
original loop into its own function in order to make it easy to bring in
the new (and iron out integration issues).
2022-01-02 20:16:45 +09:00
Bill Currie
ba5f6d97c6 [gamecode] Remove the right_associative field
It has been useless pretty much since I switched to using bison for the
parser.
2022-01-02 19:09:58 +09:00
Bill Currie
0e1964bf74 [simd] Split out the ivec implementations
And add any/all/none functions.
2022-01-02 16:02:57 +09:00
Bill Currie
5fb28d7c38 [math] Clean up vector component operations
And add a unary op macro. Having VectorCompOp makes it easy to write
macros that work for multiple data widths, which is why it and its users
now use (dst, ...) instead of (..., dst) as in the past. I'll sort out
the other macros later now that I know the compiler handily gives
messages about the switched order (uninitialized vars etc).
2022-01-02 01:15:17 +09:00
Bill Currie
937f36384b [cexpr] Use correct functions for double trunc/floor
Found while sorting out the changes for the new 2d vectors.
2022-01-02 01:13:17 +09:00
Bill Currie
97034d9dde [simd] Add 2d vector types
For int, long, float and double. I've been meaning to add them for a
while, and they're part of the new Ruamoko instructions set (which is
progressing nicely).
2022-01-02 00:57:55 +09:00
Bill Currie
365762b8a6 [gamecode] Switch to using indexed initializers
The opcode table is a nightmare to maintain, but this does clean it up
and speed up opcode lookups since they can now be indexed. Of course, it
turns out I had missed adding several instructions, so had to fix that,
and qfcc needed a bit of a re-jigger to get the opcode out of the table.
2021-12-31 19:16:02 +09:00
Bill Currie
be474d9937 [gamecode] Remove the wart from def and function names
I never liked the leading s_ (though I guess it means one is supposed to
interpret the int as a string pointer, but meh).
2021-12-31 15:02:31 +09:00
Bill Currie
70aaafda10 [ruamoko] Clear dtable list on reset
The list of all allocated dispatch tables is used to free all the tables
when the progs are reloaded. Not clearing the list meant that the next
instance (second map change) corrupted the list.
2021-12-30 00:21:29 +09:00
Bill Currie
3c17efe91b [console] Unhook hooked functions on shutdown
Forgetting to unhook the functions (Sys_Printf and the client console's
input event handler) was not a problem for static builds because the
functions were always present, but in builds with dynamic plugins, the
client console's code got ripped away and thus Sys_Printf and the event
hander were being sent into invalid memory. Too much work, not enough
play (with a fully installed client).
2021-12-29 21:50:38 +09:00
Bill Currie
5f4a330b02 [console] Tweak the server status bar colors
Now the yellow stands out nicely.
2021-12-28 00:06:12 +09:00
Bill Currie
1be220559a [zone] Add function to retrieve memory usage 2021-12-27 20:12:03 +09:00
Bill Currie
65f78b43ac [gamecode] Try to set field def size
This fixes the edicts command not printing anything useful.
2021-12-27 19:02:39 +09:00
Bill Currie
94871671d2 [qw] Use a callback for netchan logging
This gets outgoing packet logging working again. Yay, fill my hard-drive
faster ;)
2021-12-27 17:54:58 +09:00
Bill Currie
cafc6a541f [gamecode] Get PR_Profile working
The switch from using pr_functions (dfunction_t) to function_table
(bfunction_t) for keeping track of the current function (and thus
profiling data) broke PR_Profile as it never saw anything but 0.
2021-12-27 13:50:49 +09:00
Bill Currie
6368791d2b [gamecode] Check entity_var is valid before display
Even NUM_FOR_BAD_EDICT will have a bad day if the edict pointer is
invalid, so make sure that the entity pointer is valid (within the edict
area AND a multiple of edict size).
2021-12-27 13:47:55 +09:00
Bill Currie
f373192a02 [gamecode] Set pr_string_resources in PR_Strings_Init
Like for debug, this is the most sensible place as the pointer will
never change.
2021-12-26 22:46:07 +09:00
Bill Currie
5588d0de60 [gamecode] Separate debug byte-swap and pointer init
PR_LoadDebug now does only the initial version and crc checks, and the
byte-swapping of the loaded symbols file. PR_DebugSetSym sets up all the
pointers.
2021-12-26 22:39:37 +09:00
Bill Currie
c9f372fa38 [gamecode] Set pr_debug_resources in PR_Debug_Init
And use the cached value in PR_LoadDebug.
2021-12-26 20:35:09 +09:00
Bill Currie
c163b311d0 [gamecode] Create hash tables in PR_Init
This makes much more sense than in PR_LoadProgsFile (and simplifies the
latter, too).
2021-12-26 20:33:37 +09:00
Bill Currie
c11a930436 [simd] Set the homogeneous coord in the csvf test
The homogeneous coord was not being initialized and thus was picking up
rubbish from the stack. This is why the test would succeed in some
circumstances but fail in others.
2021-12-26 12:25:06 +09:00
Bill Currie
8385046486 [qfcc] Warn when super dealloc invocation is missing
Forgetting to invoke [super dealloc] in a derived class's -dealloc
method has caused me to waste far too much time chasing down the
resulting memory leaks and crashes. This is actually the main focus of
issue #24, but I want to take care of multiple paths before I consider
the issue to be done.

However, as a bonus, four cases were found :)
2021-12-24 22:45:43 +09:00
Bill Currie
5bfe0e5d34 [sw] Update for changed particle field names
Fixes 32-bit x86 target builds.
2021-12-24 19:33:06 +09:00
Bill Currie
2b25748cc4 [ruamoko] Correct SetIterator memory handling
This makes SetIterator more compatible with autorelease.
2021-12-24 06:45:13 +09:00
Bill Currie
7571231100 [input] Get single axis info for unbound devices
This doesn't fix the problem of keyhelp not working for axes belonging
to unbound devices, but may be a step in the right direction.
2021-12-24 06:45:13 +09:00
Bill Currie
2e3e9ea7c0 [ruamoko] Actually save the cooke
This fixes the listener leak.
2021-12-24 06:45:13 +09:00
Bill Currie
f77da210ff [ruamoko] Merge listener cookie code
I know that duplication would turn around and bite me :P
2021-12-24 06:45:13 +09:00
Bill Currie
b726c24b05 [ruamoko] Reset parameters before setting in listener
It's right there in the docs, even (though only on the macro, which I'd
forgotten about). Fixes some nasty corruption.
2021-12-24 06:45:13 +09:00
Bill Currie
dad19aa2ad [input] Correct balanced range calculation
Fixes axis inputs being half what they should be. Can't quite get +1,
though (need to figure something out for the positive axis range being
slightly smaller than the negative range).
2021-12-24 06:45:13 +09:00
Bill Currie
f3918471d5 [ruamoko] Add bindings for the main IMT functions
IMT_SetContextCbuf is not bound as that requires cbuf to be bound.
However, imt contexts can be created, fetched and set.
2021-12-24 06:45:13 +09:00
Bill Currie
0c41c11f1d [gamecode] Use a new developer flag for builtin debug
rua_resolve works for now
2021-12-24 06:45:13 +09:00
Bill Currie
6d64b2c47c [vulkan] Build particle buffers 2021-12-24 06:45:13 +09:00
Bill Currie
a4c4155a51 [vulkan] Clean up packet submission
In the end, there's no need for the two paths and I want to be able to
submit empty packets with semaphores.
2021-12-24 06:45:13 +09:00
Bill Currie
dcd1fa28ba [ruamoko] Get the input bindings working
With some hacks that are not included (plan on handling events and
contexts properly), button inputs, including using listeners, are
working nicely: my little game is working again. While the trampoline
code was a bit repetitive (and I do want to clean that up), connecting
button listeners directly to Ruamoko instance methods proved to be quite
nice.
2021-12-24 06:45:13 +09:00
Bill Currie
23e3b4c2e5 [ruamoko] Retrieve a plitem_t from PropertyList
And also internally for cross-builtin use.
2021-12-24 06:45:13 +09:00
Bill Currie
f1d097c0c4 [ruamoko] Add bindings for Mercenne Twister 2021-12-24 06:45:13 +09:00
Bill Currie
91a686d1f5 [util] Add mtwist float random number functions
mtwist_rand_0_1 produces numbers in the range [0, 1) and
mtwist_rand_m1_1 produces numbers in the range (-1, 1). The numbers will
not be denormal, so the distribution should be fairly uniform (as much
as Mersenne Twister itself is), but this needs proper testing.

0 is included for the mtwist_rand_0_1 as it seems useful, but -1 is not
included in mtwist_rand_m1_1 in order to keep the extremes of the
distribution balanced around 0.
2021-12-24 06:45:13 +09:00
Bill Currie
6411518603 [ruamoko] Make some progress on the input bindings 2021-12-24 06:45:13 +09:00
Bill Currie
3cb93d4cbe [input] Add functions to get single axis/button info
Handy for retrieving the current state (raw) of a single axis or button.
2021-12-24 06:45:13 +09:00
Bill Currie
803c9defae [input] Clean out more keys.h refs 2021-12-24 06:45:13 +09:00
Bill Currie
33e48025dd [ruamoko] Replace rua_key with rua_input
And create rua_game to coordinate other game builtins.

Menus are broken for key handling, but have been since the input rewrite
anyway. rua_input adds the ability to create buttons and axes (but not
destroy them). More work needs to be done to flesh things out, though.
2021-12-24 06:45:13 +09:00
Bill Currie
2cb987fdb5 [build] Clean up a pile of distcheck issues 2021-12-24 06:45:13 +09:00
Bill Currie
2d109e615b [client] Clean up a stray reference to the renderer
Reaching into the renderer internals for r_worldmodel doesn't work when
the plugins are not static.
2021-12-24 06:45:13 +09:00
Bill Currie
194f958666 [console] Add a comment about skipping the first char
I had to dig through logs of deleted files to find out what was going
on. Forget six months later, twenty years...
2021-12-24 06:45:13 +09:00
Bill Currie
e0863ff067 [net_chan] Clean out unnecessary include
net_chan was still including client.h from qw when it no longer needed
it (I guess I forgot to clean that out when I resolved any last
dependencies).
2021-12-24 06:45:13 +09:00
Bill Currie
d70d72e6e4 [particles] Create a psystem object
This takes care of the global variables to a point (there is still the
global struct shared between the non-vulkan renderers), but it also
takes care of glsl's points-only rendering.
2021-12-24 06:45:13 +09:00
Bill Currie
372c89b479 [particles] Merge physics code
The particle physics is called by the renderer.
2021-12-24 06:45:13 +09:00
Bill Currie
8d2791752e [particles] Merge particle spawning into client
After yesterday's crazy marathon editing all the particles files, and
starting to do another big change to them today, I realized that I
really do need to merge them down. All the actual spawning is now in the
client library (though particle insertion will need to be moved). GLSL
particle rendering is semi-broken in that it now does only points (until
I come up with a way to select between points and quads (probably a
context object, which I need anyway for Vulkan)).
2021-12-24 06:45:13 +09:00
Bill Currie
81a5e076ac [vulkan] Move render pass array init
Having it in Vulkan_Init_Common means the array can be used in more
places than just Vulkan_CreateRenderPass (which probably needs a
rename).
2021-12-24 06:45:13 +09:00
Bill Currie
2be19046b6 [vulkan] Allow render passes to not have a render pass
This may seem a little contradictory, but it's due to the difference
between a high level (engine) render pass and a Vulkan render pass
object (and quite likely a poor choice in names for the high level
object). This is necessary for supporting compute shader dispatches as
they cannot be submitted inside a Vulkan render pass.
2021-12-24 06:45:13 +09:00
Bill Currie
43cdca330b [client] Add bindings for load and quickload in demos 2021-12-24 06:45:13 +09:00
Bill Currie
aacd2575d2 [sw,sw32] Ensure the particle system is initialized
This fixes the missing particles (because mtwist_rand was returning 0).
2021-12-24 06:45:13 +09:00
Bill Currie
ce4bb1d56c [renderer] Move particles over to simd
This has the advantage of getting entity_t out of the particle system,
and much easier to read math. Also, it served as a nice test for my
particle physics shaders (implemented the ideas in C). There's a lot of
code that needs merging down: all but the actual drawing can be merged.

There's some weirdness with color ramps, but I'll look into that later.
2021-12-24 06:45:13 +09:00
Bill Currie
4d1e8b2375 [vulkan] Update the number of drawn quads correctly
They should increment by one for each pic, not 4 (I think some fluff
remaining from copying glsl's draw code).

I noticed the problem when I saw large gaps of 0s in the vertex data in
renderdoc.
2021-12-24 06:45:13 +09:00
Bill Currie
be7216e660 [vulkan] Implement crosshair rendering
That makes quite the difference to playability.
2021-12-24 06:45:13 +09:00
Bill Currie
6b84ae5554 [renderer] Update crosshair color on palette changes
This gets the crosshair working in Vulkan (next commit) and fixes issues
with changing the palette (though I've never seen a different palette
for quate, there's still the change from "all black" to an actual
palette).
2021-12-24 06:45:13 +09:00
Bill Currie
83ec2be2a6 [vid] Add a listener set for palette changes
This was needed to get crosshaircolor working correctly, but is likely
another step towards resizable windows (the listener set types are
generic for any viddef event, not just palette changes).
2021-12-24 06:45:13 +09:00
Bill Currie
cd641e2b1c [vulkan] Clean up alias push-constants 2021-12-24 06:45:13 +09:00
Bill Currie
8b1eec08cf [scene] Provide direct access to the world matrix
Holding onto the pointer is not a good idea, and it is read-only as
direct manipulation of the world matrix is not supported. However, this
is useful for passing the matrix to the GPU.
2021-12-24 06:45:13 +09:00
Bill Currie
869cc4050c [vulkan] Flush bsp vertex indices after all drawing 2021-12-24 06:45:13 +09:00
Bill Currie
36e98f013e [vulkan] Clean up bsp push-constants. 2021-12-24 06:45:13 +09:00
Bill Currie
081c46da7a Clean up some white space 2021-12-24 06:45:13 +09:00
Bill Currie
b9bc3fa132 [vulkan] Split out the push constants helper
It proved to work well in the sprite pipeline, and should be useful for
cleaning up the magic numbers in bsp and alias.
2021-12-24 06:45:13 +09:00
Bill Currie
0b99ff104d [vulkan] Clear the color attachments
This means color, emission, and translucent. Fixes the HOM issues on my
VersaPro (but halves the frame-rate... definitely need to bring back the
forward renderer as an option).
2021-12-24 06:45:13 +09:00
Bill Currie
db6c76d583 [vulkan] Abandon bindless rendering
At least for now, it is more trouble than it is worth as it (or my
implementation of it) breaks lavapipe and renderdoc.
2021-12-24 06:45:13 +09:00
Bill Currie
8228146ac0 [vulkan] Use the particle system buffer for indirect draws
I realized I'd need to get the particle counts out to the draw commands
somehow, and this seemed to be the most natural way.
2021-12-24 06:45:13 +09:00
Bill Currie
6aaf5c3722 [vulkan] Start work on particles for Vulkan
This gets the pipelines loaded (and unloaded on shutdown). Probably the
easy part :P. Still need to sort out the command buffers,
synchronization, and particle generation (and probably a bunch else
that's not coming to mind).
2021-12-24 06:45:13 +09:00
Bill Currie
9dcaa98205 [vulkan] Clean up a pile of C&P fluff 2021-12-24 06:45:13 +09:00
Bill Currie
e0af6541e6 [vulkan] And a bunch of buffer barrier transitions
These seem to be the most likely ones for compute shaders (some based on
my ideas for particles).
2021-12-24 06:45:13 +09:00
Bill Currie
7901f87960 [vulkan] Add support for compute shaders
This needed changing Vulkan_CreatePipeline to
Vulkan_CreateGraphicsPipeline for consistency (and parsing the
difference from a plist seemed... not worth thinking about).
2021-12-24 06:45:13 +09:00
Bill Currie
0d4ece875d [vulkan] Use indexed initializers for barriers
This will make maintaining the arrays much easier: no worries about
getting things out of sync.
2021-12-24 06:45:13 +09:00
Bill Currie
6a7f78485a [zone] Use memccpy instead of strncpy
Probably the best way to tell gcc I know what I'm doing.
2021-12-24 06:45:13 +09:00
Bill Currie
f7c14a9b39 [sw32] Use the shared R_GetSpriteFrame
One less copy of near-identical code.
2021-12-24 06:45:13 +09:00
Bill Currie
5223752f9e [vulkan] Fix lighting size calculation
It turns out the required memory size is not guaranteed to be aligned.
2021-12-24 06:45:13 +09:00
Bill Currie
c366b1b7bb [vulkan] Implement the sprite render passes
It turned out the bindless approach wouldn't work too well for my design
of the sprite objects, but I don't think that's a big issue at this
stage (and it seems bindless is causing problems for brush/alias
rendering via renderdoc and on my versa pro). However, I have figured
out how to make effective use of descriptor sets (finally :P).

The actual normal still needs checking, but the sprites are currently
unlit so not an issue at this stage.
2021-12-24 06:45:13 +09:00
Bill Currie
dafe591446 [renderer] Start merging sprite frame calculation
This covers gl and sw. sw32 should be trivial (just haven't done it),
but glsl will take a little. Vulkan will use it.
2021-12-24 06:45:13 +09:00
Bill Currie
743a732bd7 [vulkan] Correct the semantics of QFV_NextOffset
I'm not at all sure what I was thinking when I designed it, but I
certainly designed it wrong (to the point of being fairly useless). It
turns out memory requirements are already aligned in size (so just
multiplying is fine), and what I really wanted was to get the next
offset aligned to the given requirements.
2021-12-24 06:45:13 +09:00
Bill Currie
36e0d857a2 [vulkan] Create the non-C side of the sprite pipeline
This adds the shaders and the pipeline specs. I'm not sure that the
deferred rendering side of the render pass is appropriate, but I thought
I'd give it a go, since quake sprites are really cutoff rather than
translucent.
2021-12-24 06:45:13 +09:00
Bill Currie
2db8d11dd0 [vulkan] Clean up some excessive descriptor sets
With the switch to multi-layer textures for brush models, the bsp and
alias texture descriptor sets became identical and thus the definitions
shareable. However, due to complications I don't want to address yet,
they're still separately identified, but I should be able to use the
texture set for most, if not all, pipelines.
2021-12-24 06:45:13 +09:00
Bill Currie
0eb556b8f9 [vulkan] Load sprite model data
The vertices and frame images are loaded into the one memory object,
with the vertices first followed by the images.

The vertices are 2D xy+uv sets meant to be applied to the model
transform frame, and are pre-computed for the sprite size (this part
does support sprites with varying frame image sizes).

The frame images are loaded into one image with each frame on its own
layer. This will cause some problems if any sprites with varying frame
image sizes are found, but the three sprites in quake are all uniform
size.
2021-12-24 06:45:13 +09:00
Bill Currie
c5cfcc7bfd [sprite] Separate model and texture loading
As much as it can be since the texture data is interleaved with the
model data in the files (I guess not that bad a design for 25 years ago
with the tight memory constraints), but this paves the way for
supporting sprites in Vulkan.
2021-12-24 06:45:13 +09:00
Bill Currie
e7e6dd87e8 [glsl] Fix some const-correct issues for textures 2021-12-24 06:45:13 +09:00
Bill Currie
2b332cfe4a [zone] Clean up some magic numbers 2021-12-24 06:45:13 +09:00
Bill Currie
854c92d10e [simd] Indicate when the circumsphere is degenerate
CircumSphere_vf sets the sphere radius to -1 when the points are
degenerate (co-linear for three points, co-planar for four points).
2021-12-24 06:45:13 +09:00
Bill Currie
eee25d21ba [zone] Clean out unnecessary memsets
As the cache blocks are always filled in with a memcpy, there's no need
to zero out the whole allocation, and the header is initialized anyway.
2021-12-24 06:45:13 +09:00
Bill Currie
ff40563fc0 [zone] Squeeze cache_system_t to fit into 64 bytes
The cache system pointers are now indices into an array of
cache_system_t blocks, allowing them to be 32 bits instead of 64, thus
allowing cache_system_t to fit into a single CPU cache line. This still
gives and effective 38 bits (256GB) of addressing for cache/hunk. This
does mean that the cache functions cannot work with more than 256GB, but
should that become a problem, cache and working hunking hunk can be
separate, and it should be possible to have multiple cache systems.
2021-12-24 06:45:13 +09:00
Bill Currie
d857bdea77 [vulkan] Fix a typo and gcc purity warning 2021-12-24 06:45:13 +09:00
Bill Currie
fde47d6983 [quakefs] Clean out some excess memsets
There's no point in zeroing out memory that is only going to be
overwritten by the loaded file (excess bytes beyond the end of a
massaged text file shouldn't be accessed anyway, and the terminating
null is still written).
2021-12-24 06:45:13 +09:00
Bill Currie
2086125e0b [quakefs] Take in the pointer to the global hunk
This is needed for cleaning up excess memsets when loading files because
Hunk_RawAllocName has nonnull on its hunk pointer (as the rest of the
hunk functions really should, but not just yet).
2021-12-24 06:45:13 +09:00
Bill Currie
39c020908c [zone] Return the pointer to the global hunk
In trying to reduce unnecessary memsets when loading files, I found that
Hunk_RawAllocName already had nonnull on it, so quakefs needed to know
the hunk it was to use. It seemed much better to to go this way (first
step in what is likely to be a lengthy process) than backtracking a
little and removing the nonnull attribute.
2021-12-24 06:45:13 +09:00
Bill Currie
0a5981878b [sprite] Clean up field names and casting
No wonder I hated the sprite code: I couldn't see the code for all the
casts (and hungarian warts).
2021-12-24 06:45:13 +09:00
Bill Currie
1df3c2eea0 [renderer] Make R_BillboarFrame's comments true
While they weren't entirely false, they were overly verbose and thus
clouded the point.
2021-12-24 06:45:13 +09:00
Bill Currie
3a17e062da [renderer] Merge sprite billboarding code
As the sw renderer's implementation was the closest to id's, it was used
as the model (thus a fair bit of cleanup is still needed). This fixes
some incorrect implementations in glsl and gl.
2021-12-24 06:45:13 +09:00
Bill Currie
8c5c39cbe4 [vulkan] Mix turb full-brights into main color
I'd forgotten (when doing the original brush texture loader) that
turbulent surfaces were unlit and thus always full-bright, then never
wrote the turb shader to take care of it. The best solution seems to be
to just mix the two colors in the shader as it will allow turb surfaces
to be lit in the future (probably with severely limited light counts due
to being a forward renderer).
2021-12-24 06:45:13 +09:00
Bill Currie
d5b824a47c [vulkan] Switch alias pipeline to multi-texture
This gets the alias pipeline in line with the bsp pipeline, and thus
everything is about as functional as it was before the rework (minus
dealing with large texture sets).
2021-12-24 06:45:13 +09:00
Bill Currie
11492d77ce [vulkan] Switch bsp renderer to multi-texture
I guess it's not quite bindless as the texture index is a push constant,
but it seems to work well (and I may have fixed some full-bright issues
by accident, though I suspect that's just my imagination, but they do
look good).
2021-12-24 06:45:13 +09:00
Bill Currie
6fbce335bb [vulkan] Add an array view for default_magenta
The validation layers get very picky about image view types (rightfully
so, I imagine).
2021-12-24 06:45:13 +09:00
Bill Currie
2740f6093b [vulkan] Update shaders and layouts for new scheme
Still need to work on the code, though.
2021-12-24 06:45:13 +09:00
Bill Currie
8422732505 [vulkan] Move matrices into per-frame buffers
This should fix the horrid frame rate dependent behavior of the view
model.

They are also in their own descriptor set so they can be easily shared
between pipelines. This has been verified to work for Draw.
2021-12-24 06:45:13 +09:00
Bill Currie
e8961342d5 [vulkan] Fix some mostly harmless typos 2021-12-24 06:45:13 +09:00
Bill Currie
d7f588ecfe [vulkan] Rework bsp texture loader
BSP textures are now two-layered with the albedo and emission in the two
layers rather than two separate images. While this does increase memory
usage for the textures themselves (most do not have fullbright pixels),
it cuts down on image and image view handles (and shader resources).
2021-12-24 06:45:13 +09:00
Bill Currie
ea4ac894d8 [model] Swap fullbright/top/bottom color func params
This makes them semantically compatible with memcpy.
2021-12-24 06:45:13 +09:00
Bill Currie
ff6d6f6dd6 [vulkan] Rework shaders and pipelines for bindless textures
Smashing everything in the process :P (need to work on the C side).
However, while bindless is supposedly good for performance, the biggest
gain this will bring is portability: the texture counts are
automatically limited to what the hardware can handle, and the reliance
on push descriptors is removed (though they were nice and did help get
things up and running).
2021-12-24 06:45:13 +09:00
Bill Currie
3a742f59f7 [vulkan] Copy array() parameters correctly
I had forgotten that the parameters are in reverse order, and even if I
had remembered, I forgot to reset offset before the second loop.
Pre-decrementing offset takes care of both issues at once.
2021-12-24 06:45:13 +09:00
Bill Currie
a0c935e8bc [vulkan] Make lighting samplers configurable
My VersaPro doesn't support more than 32 per-stage samplers (lavapipe).
This is a small part of getting Vulkan to run on lavapipe and even in
itself is rather incomplete.
2021-12-24 06:45:13 +09:00
Bill Currie
062f616548 [cexpr] Add support for casting plitems
This allows using references in expressions, eg:

    $frames.size * size_t($properties.limits.maxSamplers)

As references remain property list items until actually evaluated.
2021-12-24 06:45:13 +09:00
Bill Currie
e7b067d6a9 [cexpr] Add some functions for size_t and uint
Casting for size_t and uint, and min/max/bound for size_t.
2021-12-24 06:45:13 +09:00
Bill Currie
ee1c3e7db5 [cexpr] Clean up the macros a little 2021-12-24 06:45:13 +09:00
Bill Currie
f6cc138f48 [vulkan] Provide access to VkPhysicalDeviceLimits
Fixes the warning about parse_fixed_array not being used (oops, the
problem with partial commits), but more importantly, gives access to
things like maxDescriptorSetSamplers.
2021-12-24 06:45:13 +09:00
Bill Currie
cff23ac93c [vulkan] Connect up the cexpr library
This will make property list expressions easier to work with. The
library is rather limited right now (trig, dot, min/max/bound) but even
just min adds a lot of functionality.
2021-12-24 06:45:12 +09:00
Bill Currie
d2eb928210 [cexpr] Add a small library with some useful functions
For now, just dot product, trig, and min/max/bound, but it works well as
a proof of concept. The main goal was actually min. Only the list of
symbols is provided, it is the user's responsibility to set up the
symbol table and context.
2021-12-24 06:45:12 +09:00
Bill Currie
44102f2639 [cexpr] Support chained contexts for scoping
cexpr's symbol tables currently aren't readily extended, and dynamic
scoping is usually a good thing anyway. The chain of contexts is walked
when a symbol is not found in the current context's symtab, but minor
efforts are made to avoid checking the same symtab twice (usually cased
by cloning a context but not updating the symtab).
2021-12-24 06:45:12 +09:00
Bill Currie
049968b38e white space 2021-12-24 06:45:12 +09:00
Bill Currie
4e8718980f [cexpr] Remove some disabled code
It looks like a munged commit, but I think I had decided that it was
best to make cvar access explicit.
2021-12-24 06:45:12 +09:00
Bill Currie
8271860fb3 [vkgen] Add support for fixed arrays
I want to support reading VkPhysicalDeviceLimits but it has some arrays.
While I don't need to parse them (VkPhysicalDeviceLimits should be
treated as read-only), I do need to be able to access them in property
list expressions, and vkgen generates the cexpr type descriptors too.

However, I will probably want to parse arrays some time in the future.
2021-12-24 06:45:12 +09:00
Bill Currie
c8846f8007 [cexpr] Support array indexing
The index is currently limited to ints, and is bounds checked (the array
type has a size field indicating the number of elements).
2021-12-24 06:45:12 +09:00
Bill Currie
c73e4efcb7 [vkgen] Don't queue types for fields with custom parsers
This ensures that unused parser blocks do not get emitted. In the
testing of the upcoming support for fixed arrays, the blend color
constants were being double emitted (both as custom and normal parser)
due to being an array. gcc did not like that (what with all those
warning flags).
2021-12-24 06:45:12 +09:00
Bill Currie
a522464fc1 [vkgen] Clean up an unnecessary function redirect
I think it was mostly a holdover from early development, but it
certainly makes sense to tuck the functionality away in Struct.
2021-12-24 06:45:12 +09:00
Bill Currie
c402275112 [vulkan] Add some more debug stack contexts 2021-12-24 06:45:12 +09:00
Bill Currie
75d06c4f98 [vulkan] Clean out some expired FIXME comments 2021-12-24 06:45:12 +09:00
Bill Currie
928408bad9 [vulkan] Support multiple render passes
Multiple render passes are needed for supporting shadow mapping, and
this is a huge step towards breaking the Vulkan render free of Quake,
and hopefully will lead the way for breaking the GL renderers free as
well.
2021-12-24 06:45:12 +09:00
Bill Currie
84a24dbb34 [renderer] Make R_RenderView private
This is actually a better solution to the renderer directly accessing
client code than provided by 7e078c7f9c.

Essentially, V_RenderView should not have been calling R_RenderView, and
CL_UpdateScreen should have been calling V_RenderView directly. The
issue was that the renderers expected the world entity model to be valid
at all times. Now, R_RenderView checks the world entity model's validity
and immediately bails if it is not, and R_ClearState (which is called
whenever the client disconnects and thus no longer has a world to
render) clears the world entity model. Thus R_RenderView can (and is)
now called unconditionally from within the renderer, simplifying
renderer-specific variants.
2021-12-24 06:45:12 +09:00
Bill Currie
eb828007e9 [vulkan] Add a comment about next pass timing 2021-12-24 06:45:12 +09:00
Bill Currie
b1ba87e5aa [vulkan] Use the short name for the image types
Yay for coming up with a solution for enums short names that start with
a number, makes things more readable.
2021-12-24 06:45:12 +09:00
Bill Currie
614c744693 [cexpr] Use ` to allow identifiers to start with a number
The generated short names for a lot of Vulkan enums start with a number
(eg VK_IMAGE_TYPE_2D -> 2d). Having to prefix the short name with ` is a
tiny cost for the convenience.
2021-12-24 06:45:12 +09:00
Bill Currie
a6703c95cf [plist] Allow ` to be used without quotes
It has no special meaning when parsing property lists, so there's no
reason to require quotes around it.
2021-12-24 06:45:12 +09:00
Bill Currie
9e755f270e [vulkan] Set staging fence timeout to 5 seconds
0.5s seemes to be unreliable on my VersaPro, particularly after a large
build.
2021-12-24 06:45:12 +09:00
Bill Currie
02ba3da0ba [vulkan] Ease writing of specialization data
While using binary data objects for specialization data works for bools
(as they can be 0 or -1), they don't work so well for numeric values due
to having to get the byte order correct and thus are not portable, and
difficult to get right.

Binary data is still supported, but the data can be written as a string
with an array(...) "constructor" expression taking any number of
parameters, with each parameter itself being an expression (though
values are limited at this stage).

Due to the plist format, quotes are required around the expression
("array(...)")
2021-12-24 06:45:12 +09:00
Bill Currie
bd31f40c9b [cexpr] Support varargs functions
While there may be better solutions, I needed a varargs function for
building Vulkan specialization data. Like progs functions, negative
parameter counts indicate ellipsis with the number of fixed parameters
being equal to -param_count - 1.
2021-12-24 06:45:12 +09:00
Bill Currie
422ad2a6c9 [vulkan] Recreate lighting pvs sets when loading lights
Sets never shrink, so assigning a dynamically created set to a
statically created set after the working size has reduced (going from
demo2 to demo3) causes the set code to attempt to resize the statically
created set, which leads to libc having a bad time.
2021-12-24 06:45:12 +09:00
Bill Currie
0c0fce2f03 [vulkan] Drop lights with size 0
They can't contribute any light, so no point in keeping them. Fixes the
erroneous size-0 shadow maps in the second nq demo.
2021-12-24 06:45:12 +09:00
Bill Currie
08721f7a21 [vulkan] Destroy the right framebuffers
Why nvidia's drivers accepted double-destroyed framebuffers is beyond
me, but this fixes the Intel drivers complaining about such (and the
subsequent segfault).
2021-12-24 06:45:12 +09:00
Bill Currie
5b1052087a [vulkan] Calculate matrix offset correctly
When I changed the matrices from an array of floats to an array of
vec4f_t, I forgot to update the flush offsets. Yay for having a
Vulkan-capable Intel device with its different alignment requirements.
2021-12-24 06:45:12 +09:00
Bill Currie
25559243ae [vulkan] Add function to compute next offset
When allocating memory for multiple objects that have alignment
requirements, it gets tedious keeping track of the offset and the
alignment. This is a simple function for walking the offset respecting
size and alignment requirements, and doubles as a size calculator.
2021-12-24 06:45:12 +09:00
Bill Currie
8d58dee4b1 [input] Ensure button id is never 0
IN_ButtonAction treats id 0 as not pressed in its internal processing,
and the previous input implementation treated 0 as "no key", so this is
both the simplest and most correct fix.

Fixes mouse left button not working every second time the game is run
(due to keyboard and mouse bindings swapping places in the config file
(separate issue, if it really is one)).
2021-12-18 14:17:40 +09:00
Bill Currie
68de8615d6 [input] Set cbuf of correct imt context
This fixes key_demo bindings not working. Quite the face-palm.
2021-12-17 08:33:13 +09:00
Bill Currie
cbf84d815f [client] Add default bindings for key_demo
Just F10 (quite) and ` (toggleconsole) so the two can be used during
demos, but just this is a major improvement.
2021-12-17 08:33:02 +09:00
Bill Currie
9d4017885f [cvar] Preserve cvars loaded from config files
This restores the equivalent functionality that seta in config.cfg
provided (no more losing my volume setting after using -nosound).
2021-12-17 08:32:36 +09:00
Bill Currie
032f9971ed [plist] Remove incorrect const from PL_RemoveObjectForKey
I'm not sure what I was thinking when I made PL_RemoveObjectForKey take
a const plitem. One of those times where C could do with being a little
more strict.
2021-12-17 08:30:00 +09:00
Bill Currie
d76cf9202d [x11] Create barriers only when grabbing
While using barriers is a zillion times better than actually grabbing
the mouse and keyboard, they're still a pain when debugging as qf is not
able to respond to the barrier-hit events. All the other logic is still
there so even when "grabbing", the mouse will not be blocked if the
window doesn't have focus.
2021-12-06 07:27:08 +09:00
Bill Currie
8b85e422d7 [vulkan] Add a debug stack to the vulkan instance
The stack is arbitrary strings that the validation layer debug callback
prints in reverse order after each message. This makes it easy to work
out what nodes in a pipeline/render pass plist are causing validation
errors. Still have to narrow down the actual line, but the messages seem
to help with that.
Putting qfvPushDebug/qfvPopDebug around other calls to vulkan should
help out a lot, tool.
As a bonus, the stack is printed before debug_breakpoint is called, so
it's immediately visible in gdb.
2021-11-30 18:10:48 +09:00
Bill Currie
2334798432 [vulkan] Make vulkan_use_validation easier more useful
Rather than just 0/1, it now acts as flags to control what messages are
printed. In addition to the Vulkan enum names (long and short), none and
all are supported (as well as raw numbers, but they're not checked for
validity). This makes vulkan_use_validation a bit easier to use and less
verbose by default.

Now, if only it was easier to remember the name :P
2021-11-30 18:10:48 +09:00
Bill Currie
901619235b [vulkan] Split out cvar enum parsing code
Need to reuse it :)
2021-11-30 18:10:48 +09:00
Bill Currie
52f86adb84 [vulkan] Fail gracefully if vulkan driver init fails
Well, a little more gracefully than a segfault, at least.
2021-11-30 18:10:48 +09:00
Bill Currie
c9508f7261 [vkgen] Name-shorten extension enum flag bits
The prefix was being stripped, but not the _BIT_EXT suffix. This makes
extension flags a little easier to use.
2021-11-30 18:10:48 +09:00
Bill Currie
1efeac6d60 [vkgen] Support specifying enum "searches" directly
Being able to parse enums that aren't part of a specified struct is
handy for cvars.
2021-11-30 18:10:18 +09:00
Bill Currie
f36fa23666 [client] Block binding of the escape key
Id's binding of escape to togglemenu interfered with the hard-coding
(want escape to togglemenu (or console as a fallback) no matter what).
This idea was part of mercury's original design, too.
2021-11-28 23:22:11 +09:00
Bill Currie
b0447c1cf1 [console] Get message modes and menus working again
I'm not at all happy with con_message and con_menu, but fixing them
properly will take a rework of the menus (planned, though). Also, the
Menu_ console command implementations are a bit iffy and could also do
with a rewrite (probably part of the rest of the menu rework) or just
nuking (they were part of Johnny on Flame's work, so I suspect had
something to do with joystick bindings).
2021-11-28 23:21:55 +09:00
Bill Currie
376e838d1c [console] Remove togglechat implementation
It has always been just a clone of toggleconsole, so the command has
been linked to toggleconsole's implementation instead.
2021-11-28 21:17:06 +09:00
Bill Currie
652546a4fb [input] Clean out a lot of obsolete stuff from keys
The new binding system makes much of keys.[ch] obsolete leaving only the
key name translations.
2021-11-27 12:31:24 +09:00
Bill Currie
70c2fdce9e [client] Move default input config to its own file
This makes it much easier to maintain the config.
2021-11-25 20:23:18 +09:00
Bill Currie
b01c38903d [x11] Clamp barriers to the screen
It seems X11 does not like creating barriers entirely off the screen,
though the error seems to be a little unreliable (however, off the left
edge was definitely bad).
2021-11-25 20:23:18 +09:00
Bill Currie
d1153be594 [build] Move plist rules to root Makefile
They are globally useful rather than specific to the vulkan renderer.
2021-11-25 20:23:18 +09:00
Bill Currie
62f592b92c [input] Create an automatic imt switcher
An imt switcher automatically changes the context's active imt based on
a user specified list of binary inputs. The inputs may be either buttons
(indicated as +button) or cvars (bare name). For buttons, the
pressed/not pressed state is used, and cvars are interpreted as ints
being 0 or not 0. The order of the inputs determines the bit number of
the input, with the first input being bit 0, second bit 1, third bit 2
etc. A default imt is given so large switchers do not need to be fully
configured (the default imt is written to all states).

A context can have any number of switchers attached. The switchers can
wind up fighting over the active imt, but this seems to be something for
the "user" (eg, configuration system) to sort out rather than the
switcher code enforcing anything.

As a result of the inputs being treated as bits, a switcher with N
inputs will have 2**N states, thus there's a maximum of 16 inputs for
now as 65536 states is a lot of configuration.

Using a switcher, setting up a standard strafe/mouse look configuration
is fairly easy.

    imt_create key_game imt_mod
    imt_create key_game imt_mod_strafe imt_mod
    imt_create key_game imt_mod_freelook
    imt_create key_game imt_mod_lookstrafe imt_mod_freelook
    imt_switcher_create mouse key_game imt_mod_strafe +strafe lookstrafe +mlook freelook
    imt_switcher 0 imt_mod 2 imt_mod 4 imt_mod_freelook 8 imt_mod_freelook 12 imt_mod_freelook
    imt_switcher 6 imt_mod_lookstrafe 10 imt_mod_lookstrafe 14 imt_mod_lookstrafe
    in_bind imt_mod mouse axis 0 move.yaw
    in_bind imt_mod mouse axis 1 move.forward
    in_bind imt_mod_strafe mouse axis 0 move.side
    in_bind imt_mod_lookstrafe mouse axis 0 move.side
    in_bind imt_mod_freelook mouse axis 1 move.pitch

This takes advantage of imt chaining and the default imt for the
switcher (there are 8 states that use imt_mod_strafe).

The switcher name must be unique across all contexts, and every imt used
in a switcher must be in the switcher's context.
2021-11-25 20:23:18 +09:00
Bill Currie
1a79915d22 [input] Add axis listeners
The listener is invoked when the axis value changes due to IN_UpdateAxis
or IN_ClampAxis updating the axis. This does mean the listener
invocation make be somewhat delayed. I am a tad uncertain about this
design thus it being a separate commit.
2021-11-25 20:04:08 +09:00
Bill Currie
8e8a573876 [input] Add listeners to buttons
The listener is invoked when the button state changes.
2021-11-25 20:04:08 +09:00
Bill Currie
c4118a4bf1 [util] Add listeners to cvars
Listeners are separate to the main callback as listeners have only
read-only access to the objects, but the main callback is free to modify
the cvar and thus can act as a parser and validator. The listeners are
invoked after the main callback if the cvar is modified. There does not
need to be a main callback for the listeners to be invoked.
2021-11-25 17:46:16 +09:00
Bill Currie
3f299155a3 [client] Reimplement legacy bind and unbind commands
This allows id1/qw config files, and to a certain extent scripts, to
work with the new binding system. It does highlight just how limited the
original system was (many keys could not bound).

Mouse axis input does not work yet as that needs a little more work to
support +strafe and +mlook.
2021-11-25 13:36:02 +09:00
Bill Currie
6a395e3416 [input] Remove some cruft
The disabled commands were implemented elsewhere or are no longer
relevant.
2021-11-25 13:36:02 +09:00
Bill Currie
fba1a1ac6b [input] Rebuild the button binding string
I had forgotten that Cmd_Args() preserves quotes, which resulted in
button bindings having excess quotes when used to bind complex commands
(eg, the default quicksave and quickload bindings).
2021-11-25 13:36:02 +09:00
Bill Currie
3bd922e473 [input] Correct a typo in in_bind's help text 2021-11-25 13:36:02 +09:00
Bill Currie
c069e7754f [util] Add a listener object
I decided cvars and input buttons/axes need listeners so any changes to
them can be propagated. This will make using cvars in bindings feasible
and I have an idea for automatic imt switching that would benefit from
listeners attached to buttons and cvars.
2021-11-25 13:36:02 +09:00
Bill Currie
67735182d7 [x11] Protect XInput2 and XFixes code
This will allow QF to be built in the unlikely event XInput2 or XFixes
are not available. nq-x11 seemed to work nicely with both disabled.
2021-11-24 02:17:08 +09:00
Bill Currie
b45acf7974 [x11] Add a comment about grabbing design 2021-11-24 01:51:52 +09:00
Bill Currie
719525a4a1 [x11] Set backed mouse button state for raw presses
Fixes button press events being treated as button releases in the event
handlers.
2021-11-23 23:21:43 +09:00
Bill Currie
28b80d8bf8 [x11] Handle raw motion events (more) correctly
For now, only the first two axis (mouse X and Y) are supported (XInput
treats the scroll wheel events as axes too, so mice have up to 4!), but
most importantly, this prevents the scroll wheel from being seen as the
X axis. Oops.
2021-11-23 23:15:08 +09:00
Bill Currie
1ef99a9130 [input] Separate absolute and relative axis inputs
Combining absolute and relative inputs at the binding does not work well
because absolute inputs generally update only when the physical input
updates, so clearing the axis input each frame results in a brief pulse
from the physical input, but relative inputs must be cleared each frame
(where frame here is each time the axis is read) but must accumulate the
relative updates between frames.

Other than the axis mode being incorrect, this seems to work quite
nicely.
2021-11-23 22:04:17 +09:00
Bill Currie
78b4e8217e [x11] Fix a optimization compiler warning
With the old headers removed, X11_SetGamma became a stub and gcc
complained about it wanting the const attribute. On investigation, it
turned out the X_XF86VidModeSetGamma was a holdover from the initial
implementation of hardware gamma support.
2021-11-23 12:44:21 +09:00
Bill Currie
af5d92708d [x11] Implement raw keyboard input via XInput2
UI key presses are still handled by regular X events, but in-game
"button" presses arrive via raw keyboard events. This gives transparent
handling of keyboard repeat (UI keys see repeat, game keys do not),
without messing with the server's settings (yay, that was most annoying
when it came to debugging), and the keyboard is never grabbed, so this
is a fairly user-friendly setup.

At first, I wasn't too keen on capturing them from the root window
(thinking about the user's security), but after a lot of investigation,
I found a post by Peter Hutterer
(http://who-t.blogspot.com/2011/09/whats-new-in-xi-21-raw-events.html)
commenting that root window events were added to XInput2 specifically
for games. Since application focus is tracked and unfocused key events
are dropped very early on, there's no way for code further down the
food-chain to know there even was an event, abusing the access would
require modifying the x11 input code, in which case all bets are off
anyway and any attempt at security anywhere in the code will fail,
meaning that nefarious progs code and the like shouldn't be a problem.
2021-11-23 11:39:48 +09:00
Bill Currie
0c1927d631 [x11] Remove -nomouse handling
After a lot of thought, it really doesn't make sense to have an option
to block mouse input in x11 (not grabbing or similar does make sense, of
course). Not initializing mouse input made perfect sense in DOS and even
console Linux (SVGA) what with the low level access.
2021-11-22 23:54:31 +09:00
Bill Currie
c3ce12de4c [x11] Use root window for barriers
It turns out that if the barriers are set on the app window, and the app
grabs the pointer (even passively), barrier events will no longer be
sent to the app. However, creating the barriers on the root window and
the events are selected on the root window, the barrier events are sent
regardless of the grab state.
2021-11-22 15:42:22 +09:00
Bill Currie
d930a49de6 [console] Close console when escape key is pressed
I should have fixed this back when I got console working with the new
input system.
2021-11-22 14:59:32 +09:00
Bill Currie
bc0451634a [input] Drop unfocused evdev axis/button events
The kernel knows nothing about X11 application focus, so we need to take
care of it ourselves.

Device add/remove events are unaffected: the are always passed on.
2021-11-22 14:59:32 +09:00
Bill Currie
ce8eac5ca0 [x11] Send app focus loss/gain events
Other subsystems, especially low-level input drivers, need to know when
the app has input focus. eg, as the evdev driver uses the raw stream
from the kernel, which has no idea about X application focus (in fact,
it seems the events are shared across multiple apps without any issue),
the evdev driver sees all the events thus needs to know when to drop
them.
2021-11-22 14:59:32 +09:00
Bill Currie
67483eea37 [input] Make event names easy to print
Handy for debugging and testing.
2021-11-22 14:59:32 +09:00
Bill Currie
e8a7e8218e [x11] Check hit barrier is valid before releasing pointer
It turns out to be possible to get a barrier event at the same time as a
configure notify event (which rebuilds the barriers), and trying to
release the pointer at such a time results in a bad barrier error and
program crash. Thus check the event barrier against the currently
existing barriers before attempting to release the pointer.

This does mean that a better mechanism for sequencing window
repositioning and barrier creation may be required.
2021-11-22 14:59:32 +09:00
Bill Currie
3ac6d2aa22 [x11] Use barriers to trap the pointer in the window
This should be a much friendlier way of "grabbing" input, though I
suspect that using raw keyboard events will result in a keyboard grab,
which is part of the reason for wanting a friendly grab.

There does seem to be a problem with the mouse sneaking out of the
top-right and bottom-left corners. I currently suspect a bug in the X
server, but further investigation is needed.
2021-11-22 14:59:27 +09:00
Bill Currie
3af078b77a [x11] Send app_window event when window moves
This is needed for getting window position info into in_x11 without
exposing more globals, and is likely to be useful for other things,
especially as it doubles as a resize event when that's eventually
supported.
2021-11-22 13:20:13 +09:00
Bill Currie
4391b87d04 [x11] Grab focus when the pointer enters the window
This is necessary in focus-follows-mouse environments (at least for
openbox, but it wouldn't surprise me if most other WMs behave the same
way) because the WMs don't set focus when the pointer is grabbed (which
XInput does before the WM sees the enter event). This is especially
important when the window is fullscreen on a multi-monitor setup as
there is no border to *maybe* catch the mouse before it enters the
window.
2021-11-21 23:42:33 +09:00
Bill Currie
a32f83d50f whitespace 2021-11-21 23:42:33 +09:00
Bill Currie
e45d19835c [x11] Add initial support for XInput2
Right now, only raw pointer motion and button events are handled, and
the mouse escapes the window, and there are some issues with focus in
focus-follows-mouse environments. However, this should be a much nicer
setup than DGA.
2021-11-21 23:42:33 +09:00
Bill Currie
4944c40f86 [x11] Remove the magic number for mouse buttons
The current limit is still 32. Dealing with it properly will take some
rather advanced messing with XInput, and will be necessary assuming
non-XInput support is continued.
2021-11-21 22:16:08 +09:00
Bill Currie
26a1f66b4e [x11] Split up in_x11_init into three stages
There's now IN_X11_Preinit, IN_X11_Postinit (both for want of better
names), and in_x11_init. The first two are for taking care of
initialization that needs to be done before window creation and between
window creation and mapping (ie, are very specific to X11 stuff) while
in_x11_init takes care of the setup for the input system. This proved
necessary in my XInput experimentation: a passive enter grab takes
effect only when the pointer enters the window, thus setting up the grab
with the pointer already in the window has no effect until the pointer
leaves the window and returns.
2021-11-21 21:22:11 +09:00
Bill Currie
95becc5c05 [x11] Add some braces around an if block 2021-11-21 21:16:55 +09:00
Bill Currie
fe2dd013be [x11] Clean out some unnecessary includes 2021-11-21 21:16:55 +09:00
Bill Currie
8988008ad6 [x11] Don't mess with the mouse when going fullscreen
This was always a horrible hack just to get the screen centered on the
window back when we were doing fullscreen badly. With my experiments
with XInput, it has proven to be a liability (I'd forgotten it was even
there until it started imposing a 2s delay to QF's startup).
2021-11-21 20:59:49 +09:00
Bill Currie
925a55f6cc [input] Allow drivers to initialize cvars early
Input driver can now have an optional init_cvars function. This allows
them to create all their cvars before the actual init pass thus avoiding
some initialization order interdependency issues (in this case, fixing a
segfault when starting x11 clients fullscreen due to the in_dga cvar not
existing yet).
2021-11-21 11:33:58 +09:00
Bill Currie
88b3965794 [vulkan] Pick up vulkan.h from correct location
Well... it could be done better, but this works for now assuming it's in
/usr/include (and it's correct for mxe builts). Does need proper
autoconfiscation, though.
2021-11-19 22:36:19 +09:00
Bill Currie
e080bb333c [win] Update windows input for new binding system
Seems to work nicely for keyboard (though key bindings are not
cross-platform). Mouse not tested yet, and I expect there are problems
with it for absolute inputs (yay mouse warp :P).
2021-11-19 13:52:40 +09:00
Bill Currie
b1d388563e [input] Don't specify ld flags for evdev lib
libtool gets confused if the convenience library has normal library
linker flags and fails to properly relink the main library when
installing.
2021-11-19 12:08:58 +09:00