Commit graph

1397 commits

Author SHA1 Message Date
Bill Currie
e7106cce9e [plugin] Remove Draw_Init from draw funcs
It's never called outside the renderers.
2021-01-10 15:22:39 +09:00
Bill Currie
16334158bd [util] Support struct pointer accesses in cexpr 2021-01-10 01:51:07 +09:00
Bill Currie
d4277ef130 [util] Mark PL_CheckType as const
I keep forgetting to do optimized builds :(
2021-01-07 01:10:25 +09:00
Bill Currie
3b06ca01af [vulkan] Destroy pipeline on shutdown 2021-01-05 23:54:22 +09:00
Bill Currie
b493e6ac32 [util] Expose plist type check support functions 2021-01-05 23:39:52 +09:00
Bill Currie
a45f8f98b6 [util] Make exprctx hashlinks double pointer
The way I wound up using the field meant that exprctx should not "own"
the hashlinks chain, but rather just point to it. This fixes the nasty
access errors I had.
2021-01-05 19:55:17 +09:00
Bill Currie
518befdaed [util] FIx an "only" in a comment 2021-01-05 17:40:07 +09:00
Bill Currie
e5708100bb [vulkan] Generate code for resource nodes
This makes it easy to add resource nodes defining contextually named
resources. It is already used for shaders, set layouts, and pipeline
layouts.
2021-01-05 14:15:35 +09:00
Bill Currie
9039c6975a [util] Clean up some missed vsqrt changes 2021-01-05 08:35:53 +09:00
Bill Currie
e4f75791ce [vulkan] Clean up some tangled dependencies
Dependencies on vkparse.hinc were spreading through the code which I
didn't want as that removes a lot of the automation from the automake
files. This keeps all parser code internal to vkparse.c's scope, and any
accesses required for enum and struct (not yet) definitions can be
fetched by name.
2021-01-04 17:26:39 +09:00
Bill Currie
4562e0b876 [util] Implement more of cexpr
This adds unary, vector and function expressions.
2021-01-04 00:23:48 +09:00
Bill Currie
81300f89f8 [util] Allow multiple types for pl fields
I want to be able to use name references, but that requires string
items, so anything that would normally be dictionary or array (or
binary, even) would also need to accept string. This seemed to be the
cleanest solution. Any custom parser would then need to check the type
and act appropriately, but any inappropriate types have already been
pre-filtered by the standard parsers.
2021-01-02 14:02:33 +09:00
Bill Currie
015cee7b6f [util] Add vector-quaternion shortcut functions
Care needs to be taken to ensure the right function is used with the
right arguments, but with these, the need to use qconj(d|f) for a
one-off inverse rotation is removed.
2021-01-02 10:44:45 +09:00
Bill Currie
7bf90e5f4a [util] Sort out implementation issues for simd 2021-01-02 09:55:59 +09:00
Bill Currie
73544f0790 [util] Split cmem's free cache-line over size bins
They're binned by powers of two (with in between sizes going to the
smaller bin should I make cache-line allocations NPOT (which I think
might be worthwhile). However, there seems to still be a bug somewhere
causing a nasty leak as now my hacked qfvis consumes 40G in less than a
minute.
2020-12-30 18:20:11 +09:00
Bill Currie
4039075f41 [util] Use a linked list of free cache lines
The idea is to not search through blocks for an available allocation.
While the goal was to speed up allocation of cache lines of varying
cluster sizes, it's not enough due to fragmentation.
2020-12-30 18:20:11 +09:00
Bill Currie
3125009a7c [util] Add vector and quaternion types to cexpr
Although there's no distinction between the two at the C level, I think
it's probably best to separate them in a scripting language.
2020-12-30 18:20:11 +09:00
Bill Currie
1ddd57b09e [util] Add qconj, vtrunc, vceil and vfloor functions
I had forgotten these rather critical functions. Both double and float
versions are included.
2020-12-30 18:20:11 +09:00
Bill Currie
09a10f80e1 [util] Add basic SIMD implemented vector functions
They take advantage of gcc's vector_size attribute and so only cross,
dot, qmul, qvmul and qrot (create rotation quaternion from two vectors)
are needed at this stage as basic (per-component) math is supported
natively by gcc.

The provided functions work on horizontal (array-of-structs) data, ie a
vec4d_t or vec4f_t represents a single vector, or traditional vector
layout. Vertical layout (struct-of-arrays) does not need any special
functions as the regular math can be used to operate on four vectors at
a time.

Functions are provided for loading a vec4 from a vec3 (4th element set
to 0) and storing a vec4 into a vec3 (discarding the 4th element).

With this, QF will require AVX2 support (needed for vec4d_t). Without
support for doubles, SSE is possible, but may not be worthwhile for
horizontal data.

Fused-multiply-add is NOT used because it alters the results between
unoptimized and optimized code, resulting in -mfma really meaning
-mfast-math-anyway. I really do not want to have to debug issues that
occur only in optimized code.
2020-12-30 18:20:11 +09:00
Bill Currie
fefb32bf13 [util] Add a PL dictionary to hash table parser 2020-12-24 16:06:34 +09:00
Bill Currie
cb2bdb0224 [util] Rename PL_ParseDictionary to PL_ParseStruct
Struct is far more appropriate for its function, and I need to parse a
dictionary into a hash table.
2020-12-24 13:33:37 +09:00
Bill Currie
25ade4c0f3 [vulkan] Add support for custom parsers
And provisionally parse shader stage defs.
2020-12-24 01:36:17 +09:00
Bill Currie
7fb335a215 [vulkan] Add support for building and loading shaders
Shaders can be built as spv files and installed into
$libdir/quakeforge/shaders or as spvc files and compiled into the
engine. Loading supports $builtin/name to access builtin shaders,
$shader/path to access external standard shaders and quake filesystem
access for all other paths.
2020-12-23 14:32:29 +09:00
Bill Currie
5864b553ef [util] Add accessors for binary plist objects 2020-12-23 14:07:30 +09:00
Bill Currie
91c5baa708 [util] Add size_t support to cexpr 2020-12-23 14:06:20 +09:00
Bill Currie
79f22ffebf [util] Propagate cexpr errors back to the caller
Not much point in error detection when it's ignored.
2020-12-21 20:15:43 +09:00
Bill Currie
f3682638d4 [util] Add a mini expression parser
It is capable of parsing single expressions with fairly simple
operations. It current supports ints, enums, cvars and (external) data
structs. It is also thread-safe (in theory, needs proper testing) and
the memory it uses can be mass-freed.
2020-12-21 14:22:42 +09:00
Bill Currie
591667c36d [util] Add a context parameter to the plist parsers
Not used by the dict/array parsers themselves, but is passed on to any
value parser callbacks for their own use.
2020-12-21 14:22:42 +09:00
Bill Currie
ab04a1915e [build] Fix a pile of gcc 10 issues
gcc got stricter about array accesses, complicating progs macros, and
much better at detecting buffer overflows.
2020-12-21 14:14:29 +09:00
Bill Currie
af814ff9a8 [util] Add a cache-line aligned memory allocator
This was inspired by
Hoard: A Scalable Memory Allocator
  for Multithreaded Applications

 Emery D. Berger, Kathryn S. McKinley, Robert D. Blumofe, Paul R.
 Wilson,

It's not anywhere near the same implementation, but it did take a few
basic concepts. The idea is twofold:
1) A pool of memory from which blocks can be allocated and then freed
en-mass and is fairly efficient for small (4-16 byte) blocks
2) Tread safety for use with the Vulkan renderer (and any other
multi-threaded tasks).

However, based on the Hoard paper, small allocations are cache-line
aligned. On top of that, larger allocations are page aligned.

I suspect it would help qfvis somewhat if I ever get around to tweaking
qfvis to use cmem.
2020-12-21 14:14:29 +09:00
Bill Currie
62f3e1f428 [util] Calculate quaternion to rotate between two vectors
The calculation fails (produces NaN) if the vectors are anti-parallel,
but works for all other combinations. I came up with this implementation
when I discovered Unity's Quaternion.FromToRotation could did not work
with very small angles. This implementation will produce a usable
quaternion below 0.00255 degrees (though it will be slightly larger than
unit). Unity's failed such that I could see KSP's skybox snap while it
rotated around my test vessel.
2020-12-21 14:14:10 +09:00
Bill Currie
2b23e01d9a [util] Make PL_Type and PL_Line const-correct 2020-07-17 00:22:47 +09:00
Bill Currie
26cd93f788 [util] Expose PL_Message
It's far to useful elsewhere.
2020-07-16 22:14:19 +09:00
Bill Currie
ef33adac56 [util] Make PL_String const correct 2020-07-16 22:14:19 +09:00
Bill Currie
c6a8829a52 [util] Add code to parse a plist array to an array 2020-07-14 12:05:34 +09:00
Bill Currie
8bd5f4f201 [util] Add code to parse a dictionary to a struct
PL_ParseDictionary itself does only one level, but it takes care of the
key-field mappings and property list item type checking leaving the
actual parsing to a helper specified by the field. That helper is free
to call PL_ParseDictionary recursively.
2020-07-05 16:53:35 +09:00
Bill Currie
f6ea9e4d87 [util] Store source line in plist items
The first line of the parsed item is stored and can be retrieved using
PL_Line. Line numbers not stored for dictionary keys yet. Will be 0 for
any items generated by code rather than parsed from a file or string.
2020-07-01 21:47:09 +09:00
Bill Currie
19c75f5e49 [vulkan] Clean up QFV_CreateFramebuffer's prototype
It now takes qfv_imageviewset_t instead of separate count and
VkImageView array.
2020-06-28 13:53:11 +09:00
Bill Currie
8f2bc18a4f [build] Fix a merge error
Messed up the vulkan headers.
2020-06-25 19:51:40 +09:00
Bill Currie
86b5b30b45 Merge branch 'master' into vulkan 2020-06-25 14:03:52 +09:00
Bill Currie
6d5ffa9f8e [build] Move to non-recursive make
There's still some cleanup to do, but everything seems to be working
nicely: `make -j` works, `make distcheck` passes. There is probably
plenty of bitrot in the package directories (RPM, debian), though.

The vc project files have been removed since those versions are way out
of date and quakeforge is pretty much dependent on gcc now anyway.

Most of the old Makefile.am files  are now Makemodule.am.  This should
allow for new Makefile.am files that allow local building (to be added
on an as-needed bases).  The current remaining Makefile.am files are for
standalone sub-projects.a

The installable bins are currently built in the top-level build
directory. This may change if the clutter gets to be too much.

While this does make a noticeable difference in build times, the main
reason for the switch was to take care of the growing dependency issues:
now it's possible to build tools for code generation (eg, using qfcc and
ruamoko programs for code-gen).
2020-06-25 11:35:37 +09:00
Bill Currie
2bec2527b4 [gamecode] Re-expose PR_LoadStrings
It's required for qfprogs now that PR_LoadDebug reads strings early.
2020-04-04 14:33:49 +09:00
Bill Currie
cf7c4780eb [gamecode] Load extended debug data
And add function to get a source file's base directory if available.
2020-04-04 12:50:25 +09:00
Bill Currie
59f48e5e32 [gamecode] Add function to test if string exists
As it returns the string id, it is useful for getting an string id
without risking creating a new one.
2020-04-04 12:32:12 +09:00
Bill Currie
7c5c462587 [qfcc] Write debug data space to sym file
This should keep things nicely extensible, since additional data can be
done in the data space and found using defs. This gets the compilation
units into the sym file.
2020-04-03 21:25:47 +09:00
Bill Currie
049b8f392c [qfcc] create a compilation unit for debug data
The compilation unit stores the directory from which qfcc was run and
any source files mentioned. This is similar to dwarf's compilation unit.
Right now, this is the only data in the new debug space, but more might
come in the future so it seems best to treat the debug space separately
in the object files.
2020-04-03 15:07:13 +09:00
Bill Currie
63caa5794d [qwaq] Implement step-over tracing
I decided that stopping in between function calls that are on the same
line is a good thing as it gives a chance to skip over the first but
step into the second.
2020-04-02 17:44:53 +09:00
Bill Currie
c09f57c39e [gamecode] Delay .ctor calls if debugging
This allows a debugger to do any symbol lookups and other preparations
between loading progs and the first code execution. .ctors are called as
per normal if debug_handler is not set.
2020-04-02 17:39:11 +09:00
Bill Currie
f90613bc3a [gamecode] Rename fields in pr_stack_t
s and f are a little too succinct.
2020-04-02 15:00:01 +09:00
Bill Currie
c920c746f3 [gamecode] Move debug even enum to pr_debug.h 2020-04-02 10:39:12 +09:00
Bill Currie
e2d1a0f7d2 [ruamoko] Tag object memory with the class name
This makes it a lot easier to see what's leaking.
2020-03-31 16:43:10 +09:00
Bill Currie
c23c68cf7f [ruamoko] Allow builtins to inc/dec retain count
Needed for classes that are implemented entirely in C.
2020-03-30 16:58:36 +09:00
Bill Currie
ddec80edc1 [qfcc] Make type encoding union anonymous
I'd do more, but things get messy with direct access to unions that I
want to be anonymous.
2020-03-30 11:10:05 +09:00
Bill Currie
869efa7239 [gamecode] Use etype_t in more places
But forget about bitfields. If enum isn't int and int isn't 32-bits,
we've probably got other problems (and there may be a better way).
2020-03-28 21:19:55 +09:00
Bill Currie
1eef2a8b5e [qfcc] Implement type aliasing again
When a type is aliased, the alias has two type chains: the simple type
chain with all other aliases stripped, and the full type chain. There
are still plenty of bugs in it, but having the clean type chain takes
care of the major issue that was in the previous attempt as only the
head of the type-chain needs to be skipped for type comparison.

Most of the bugs are in finding the locations where the head needs to be
skipped.
2020-03-28 12:10:23 +09:00
Bill Currie
8b1e4eea58 [qfcc] Bring back the core of type aliasing
No aliasing is done yet, but most of the infrastructure is there again.
2020-03-27 12:27:46 +09:00
Bill Currie
75394cc4f8 [gamecode,qfcc] Use enums for type encoding types
The enums are forced to 32 bits via bitfield spec, so can't use sizeof
on them, but this makes switch enum checks work in gcc.
2020-03-27 12:24:14 +09:00
Bill Currie
1586df4dfc [gamecode] Make it possible to check string mutability 2020-03-26 16:38:09 +09:00
Bill Currie
ec82d6b027 [gamecode] Add support for holding ephemeral strings
PR_HoldString converts ephemeral (temp and return) strings to dynamic
strings. This makes dealing with strings in progs a little easier.
2020-03-26 16:36:29 +09:00
Bill Currie
2d5df34234 [gamecode] Add VM enter/exit events
And rename prd_exit to prd_terminate (the idea is the host will
terminate the VM). This makes it possible for the debugger to pause the
VM before any code, even a builtin function, is executed. Breaks the
debugger source window, but only because it's not updating on file
change (I think).
2020-03-26 12:30:32 +09:00
Bill Currie
1bd8e2ee85 [gamecode] Add a param pointer to debug_handler
I decided I want events for VM enter/exit but enter needs to somehow
pass the function which will be executed (even if a builtin). A generic
void * param seemed the best idea, which meant the error string could be
passed via the param instead of a "global" string in the progs struct.
2020-03-26 11:44:02 +09:00
Bill Currie
52dcb0a6e2 [gamecode] Add G_PACKED macro
Not sure when I'll use it, but as it avoids the null pointer check, it
should make for faster access to structs when reading or writing
multiple fields.
2020-03-25 22:36:04 +09:00
Bill Currie
48f737ecb6 [gamecode] Tweak types in dfunction_t
Mostly minor corrections to make more sense when reading them.
2020-03-25 21:05:25 +09:00
Bill Currie
6f7ddf52ac [gamecode] Add an exit debug event type
The VM never sends it because it cannot know if its exit is program exit
or just sub-program exit, but it's available for host systems to send.
2020-03-25 18:28:28 +09:00
Bill Currie
4cef9792f4 [util] Make hash-tables semi-thread-safe
They take a pointer to a free-list used for hashlinks so the hashlink
pools can be per-thread. However, hash tables that are not updated are
always thread-safe, so this affects only updates. progs_t has been set
up such that it is easy for multiple progs within one thread can share
hashlinks.
2020-03-25 15:43:16 +09:00
Bill Currie
713150b41a [gamecode] Add debug hooks to the VM engine
While there was a breakpoint hook, it was for only breakpoints and more
was needed. Now there's a generic hook that is called for tracing,
breakpoints, watch points, runtime errors and VM errors, with the
"event" type passed as the first parameter and a data pointer in the
second.
2020-03-24 19:45:10 +09:00
Bill Currie
4dbf280012 [util] Add a means to open a gap in a text buffer
for loading files into the buffer.
2020-03-22 20:19:25 +09:00
Bill Currie
28f50d2719 Add function key defs up to F48
This allows for the four combinations of shift and control. Not
bothering with alt because alt-f4 closes my xterm (bbkeys from the looks
of it: it grabs a bunch of Mod1-* keys).
2020-03-22 13:46:27 +09:00
Bill Currie
84cff64f99 Remove many key number hard-codings
I left the ones below 256 alone (some were necessary anyway), but above
256 they were almost entirely sequential, which rather defeats the
purpose of using an enum, especially since it makes it difficult to
expand sections.
2020-03-22 11:18:44 +09:00
Bill Currie
88b4046632 [util] Pass a data pointer to shutdown functions
And clean up the mess.
2020-03-22 00:57:54 +09:00
Bill Currie
4e739f6b36 Use dynamic array element type instead of __auto_type
This allows using 0 for pointer arrays.
2020-03-21 12:58:07 +09:00
Bill Currie
9678eba59b Initialize array pointer in dynamic array
Oops. I guess I was using calloc in the vulkan branch.
2020-03-21 12:58:07 +09:00
Bill Currie
1a7add3f6d Merge branch 'master' into vulkan 2020-03-20 13:04:41 +09:00
Bill Currie
38fc7459e4 Add DARRAY_INIT from the vulkan branch
Couldn't cherry-pick this one as it was a bigger commit.
2020-03-20 12:59:25 +09:00
Bill Currie
2966b035bf Add a fixed-array allocator
Turned out to be very convenient.
2020-03-20 12:59:25 +09:00
Bill Currie
0764df1276 Fix incorrect include protection 2020-03-20 12:59:25 +09:00
Bill Currie
966bd267c5 Add a set of macros for dynamic arrays
Includes docs and test cases.
2020-03-20 12:59:25 +09:00
Bill Currie
ec12941fcb Move the ring buffer macros to their own header
They seem to have proven themselves to be robust.
2020-03-19 23:53:54 +09:00
Bill Currie
99f89840f9 [gamecode] Show containing def and relative offset
No more guessing when accessing structure field members. Next is ivars,
I guess.
2020-03-15 02:51:29 +09:00
Bill Currie
3d62a7f253 [gamecode] Use fuzzy bsearch to find defs by address
The idea is to find th def that contains the address. Had to write my
own bsearch (well... lifted from wikipedia) because libc's is exact. The
defs are assumed to be sorted (which qfcc now ensures when it writes
progs and sym files).
2020-03-15 02:48:13 +09:00
Bill Currie
fea6381574 [gamecode] Rework debug type handling a little
Type encodings are used whenever they are available. For now, if they
are not, then everything is treated as void (which prints <void>, not
very useful). Most return statements and references to .return are now
very readable (excluding structs), and only params going through "..."
are a messy union.
2020-03-14 20:44:43 +09:00
Bill Currie
a0d85e33c2 [gamecode] Rework implementation of memset*
The memset instructions now match the move* instructions other than the
first operand (always int). Probably breaks much, but fixed in next few
commits.
2020-03-13 17:50:57 +09:00
Bill Currie
6ca85d770d [gamecode] Add memset instructions 2020-03-11 22:48:55 +09:00
Bill Currie
f290b115a5 [gamecode] Add function PR_PushTempString
This "pushes" a temp string onto the callee's stack frame after removing
it from the caller's stack frame. This is so builtins can pass
auto-freed memory to called progs code. No checking is done, but mayhem
is likely to ensue if a string is pushed that was allocated in an
earlier frame.
2020-03-09 23:36:09 +09:00
Bill Currie
7d43bd5c66 [gamecode] Add function PR_AllocTempBlock()
PR_AllocTempBlock() works the same way as PR_SetTempString(), except
that it takes a size parameter and always allocates (never tries to
merge). This is, in a way, abusing the string system, but I needed a way
to allocate a block of progs memory that would be automatically freed
when the current frame ended. The biggest abuse is the need to cast away
the const of PR_GetString()'s return value.
2020-03-09 22:16:19 +09:00
Bill Currie
e2f4c189f9 [ruamoko] Install and use dispatch tables
This should speed up ruamoko code somewhat as hash table lookups have
been replaced with direct array indexing. As a bonus, support for
message forwarding has been added (though not tested).
2020-03-09 18:11:36 +09:00
Bill Currie
98756df9f7 [gamecode] Set final resource map free list pointer
The sub-tables were being properly linked together, but the very final
table was not properly terminated.
2020-03-09 18:03:25 +09:00
Bill Currie
3b959c3ed0 [gamecode] Add a macros for arbitrary param/return types
Of course, the type has to be small enough to fit or bad things may
happen, but it beats having to type the crazy casting every time.
2020-03-06 00:23:44 +09:00
Bill Currie
de01cff70e [build] Install QF/keys.h into qfcc's include directory
As well as $prefix/include, of course. This fixes the problem with
external ruamoko builds failing due to keys.h and qfcc's "lockdown" on
system headers.
2020-03-03 22:22:53 +09:00
Bill Currie
4e4b553cc3 [gamecode] Take care of missed type alias stuff 2020-03-01 16:20:23 +09:00
Bill Currie
caa297b756 [qfcc] Remove type alias encoding
It proved to be too fragile in its current implementation. It broke
pointers to incomplete structs and switch enum checking, and getting it
to work for other things was overly invasive. I still want the encoding,
but need to come up with something more robust.a
2020-03-01 16:13:18 +09:00
Bill Currie
75f4cebf0e Clean up after removal of uint32.h
I guess I forgot to check for its usage in header files, and the fact that
it didn't get cleaned out from being installed hid the error.
2020-02-29 16:11:07 +09:00
Bill Currie
ddd007e2d5 [dstring] Return the string instead of printed size
Other than consistency with printf(), I'm not sure why we went with the
printed size as the return value; returning the resultant strings makes
much more sense as dsprintf() (etc) can then be used as a safe va()
2020-02-26 19:00:19 +09:00
Bill Currie
aa02069dd1 Add a breakpoint flag to opcodes
The progs execution code will call a breakpoint handler just before
executing an instruction with the flag set. This means there's no need
for the breakpoint handler to mess with execution state or even the
instruction in order to continue past the breakpoint.

The flag being set in a progs file is invalid.
2020-02-26 13:40:26 +09:00
Bill Currie
42713cad8b Make script much friendlier to use
It now simply sets an error message pointer and returns false if there's
an error.
2020-02-26 09:39:03 +09:00
Bill Currie
35c9d6ee38 Make pr_obcode.c mostly thread safe
Its public data is all read-only, and once set up, its private data is
too (just don't call init in multiple threads).
2020-02-26 01:20:28 +09:00
Bill Currie
3577d27a45 Move the ObjQC data into a resource block
This makes it nice and private (though with the cached pointer, ObjQC is
still a first-class component).
2020-02-25 23:14:18 +09:00
Bill Currie
66dd3ef070 Make a bunch of count things positive-only
This fixes a pile of FIXMEs, because some things should never be
negative.
2020-02-25 21:23:13 +09:00
Bill Currie
4bc36836a1 Correct the type of an aux function's return type
It was made to be the address of the type encoding long ago.
2020-02-25 20:17:20 +09:00
Bill Currie
89e83d7d73 Move the debug info out of progs_t
The debug subsystem now uses the resources system to ensure it cleans
up, and its data is now semi-private. Unfortunately, PR_LoadDebug had to
remain public for qfprogs because using PR_RunLoadFuncs would cause
builtin resolution to complain.
2020-02-25 20:07:29 +09:00