Commit Graph

5574 Commits

Author SHA1 Message Date
Bill Currie 551c6b82cb [vulkan] Tweak spotlight cone edges a little 2022-05-06 08:32:19 +09:00
Bill Currie ed82b5f299 [ruamoko] Clean up lighting data blocks
Don't want to leak memory.
2022-05-06 08:26:55 +09:00
Bill Currie 4abcaff980 [vulkan] Normalize the normal vectors on alias models
I was wondering why scaled-down quake-guy was dimmer than full-size
quake-guy. And the per-fragment normalization gives the illusion of
smoothness if you don't look at his legs (and even then...).
2022-05-05 23:49:31 +09:00
Bill Currie 72cb7d3fdd [scene] Make the empty world work with lights
Needed visibility and a sky surf flag, otherwise no lights were visible
(why does this seem familiar?).
2022-05-05 23:49:31 +09:00
Bill Currie d14b17567e [ruamoko] Add builtins for adding lights to scenes
Pretty much just raw wrappers around the C versions. I'm not sure about
Light_EnableSun (even in C), but it does build the sky surf pvs.
2022-05-05 23:49:31 +09:00
Bill Currie 95264b3a54 [ruamoko] Move emtpy_world into scene
And use it as the default worldmodel for new scenes. Since it's
statically allocated, it shouldn't cause any harm so long as no one
tries to free it.
2022-05-05 23:49:31 +09:00
Bill Currie d850285e3f [ruamoko] Allow scenes to be fetched by C code
Need to clean up that part of the API, though.
2022-05-05 23:49:31 +09:00
Bill Currie 7b275ebab6 [vulkan] Don't update lights that don't exist
However, the lighting pass still needs to be run in order to generate
the solid color image.
2022-05-05 23:49:31 +09:00
Bill Currie 2818fc12a5 [model] Initialize r_notexture_mip in the right places
That being in the renderer. This is why qwaq needed that call to
Mod_ProcessTexture (but no longer does :)
2022-05-05 23:49:31 +09:00
Bill Currie 41a12f066b [client] Clean up light loading
By adding Light_AddLight to scene light management
2022-05-05 23:49:31 +09:00
Bill Currie b2928b5ed7 [client] Reverse the direction of sunlight
Maps specify sunlight as shining in a specific direction, but the
lighting system wants the direction to the sun as it's used directly in
shading calculations. Direction correctness confirmed by disabling other
lights and checking marcher's outside scene (ensuring the flat ground
was lit). As a bonus, I've finally confirmed I actually have the skybox
in the correct orientation (sunlight vector more or less matched the
position of the sun in marcher's sky).
2022-05-05 23:49:31 +09:00
Bill Currie d60602421b [vulkan] Ensure dynamic lights are positional
I'm not sure what's up with the weird lighting that results from dynamic
lights being directional (sunlight works nicely in marcher, but it has a
unit vector for position).
2022-05-05 23:49:31 +09:00
Bill Currie df5b471342 [scene] Support ambient lighting in worldspawn
Abyss of Pandemonium uses global ambient light a lot, but doesn't
specify it in every map (nothing extracting entities and adding a
reasonable value can't fix). I imagine some further tweaking will be
needed.
2022-05-05 23:49:30 +09:00
Bill Currie a31ff3153c [gamecode] Fail gracefully on invalid entity strings
Returning null (and printing some error messages) is far friendlier than
aborting.
2022-05-05 23:49:30 +09:00
Bill Currie 4a4e16399a [client] Clean up world entity parsing a bit
Now the entities are parsed only once and the resulting data reused.
2022-05-05 23:49:30 +09:00
Bill Currie 9ee0eada1f [vulkan] Move non-specific lighting code out of Vulkan
The parsing of light data from maps is now in the client library, and
basic light management is in scene. Putting the light loading code into
the Vulkan renderer was a mistake I've wanted to correct for a while.
The client code still needs a bit of cleanup, but the basics are working
nicely.
2022-05-05 23:49:30 +09:00
Bill Currie e9ad7b748b [renderer] Use scene_t to set the model data
This replaces *_NewMap with *_NewScene and adds SCR_NewScene to handle
loading a new map (for quake) in the renderer, and will eventually be
how any new scene is loaded.
2022-05-05 14:46:02 +09:00
Bill Currie e323fbbbed [vulkan] Rework lighting model to be more algebraic
This leaves only the one conditional in the shader code, that being the
distance check. It doesn't seem to make any noticeable difference to
performance, but other than explosion sprites being blue, lighting
quality seems to have improved. However, I really need to get shadows
working: marcher is just silly-bright without them, and light levels
changing as I move around is a bit disconcerting (but reasonable as
those lights' leaf nodes go in and out of visibility).
2022-05-05 08:40:02 +09:00
Bill Currie fe63d93e8e [build] Remove some csqc dependencies
vkgen and the programs in ruamoko/qwaq just don't need it.
2022-05-04 18:01:50 +09:00
Bill Currie eaaa0f597f [scene] Set the color for new entities
Black doesn't show up too well on black. Really, this isn't the best
fix, but it will do until I can rework entities to use a component
system.
2022-05-04 18:00:35 +09:00
Bill Currie 2493ca71c7 [ruamoko] Allow entity model to be set
And add header and function definitions for scene to libcsqc.
2022-05-04 17:38:38 +09:00
Bill Currie 8e658eac78 [vulkan] Correct a pile of copyright attributions
Id Software had pretty much nothing to do with the vulkan renderer (they
still get credit for code that's heavily based on the original quake
code, of course).
2022-05-04 14:44:54 +09:00
Bill Currie e95d498b97 [vulkan] Resurrect the forward render pass spec
It's not used yet, and thus may have some incorrect settings, but I
decided that I will probably want it at some stage for qwaq. It's
essentially was was in the original spec, but updated for some of the
niceties added to parsing since I removed it back then. It's also in its
own file.
2022-05-04 14:44:54 +09:00
Bill Currie c10e529dfd [vulkan] Clean up alias pipeline layout spec
It didn't really need the extra layer of indirection: now it's much
clearer that the alias pipeline uses matrices and textures.
2022-05-04 14:44:54 +09:00
Bill Currie 0983cc5d8c [scene] Fix a spelling error in a comment 2022-05-04 14:44:54 +09:00
Bill Currie 3de10f32c7 [ruamoko] Add builtins for handling models
Just "loading" and "unloading" (both really just hints due to the
caching system), and an internal function for converting a handle to a
model pointer, but it let me test IQM loading and unloading in Vulkan.
2022-05-04 14:44:54 +09:00
Bill Currie ecf33fe8e3 [model] Add a function to "unload" models
The model system is rather clunky as it is focused around caching, so
unloading is more of a suggestion than anything, but it was good enough
for testing loading and unloading of IQM models in Vulkan.
2022-05-04 14:13:18 +09:00
Bill Currie bbca22c722 [vulkan] Add support for IQM models
Despite the base IQM specification not supporting blend-shapes, I think
IQM will become the basis for QF's generic model representation (at
least for the more advanced renderers). After my experience with .mu
models (KSP) and unity mesh objects (both normal and skinned), and
reviewing the IQM spec, it looks like with the addition of support for
blend-shapes, IQM is actually pretty good.

This is just the preliminary work to get standard IQM models loading in
vulkan (seems to work, along with unloading), and they very basics into
the renderer (most likely not working: not tested yet). The rest of the
renderer seems to be unaffected, though, which is good.
2022-05-04 14:07:27 +09:00
Bill Currie a4f500da3c [vulkan] Add a mini resource subsystem
The resource subsystem creates buffers, images, buffer views and image
views in a single batch operation, using a single memory object to back
all the buffers and images. I had been doing this by hand for a while,
but got tired of jumping through all those vulkan hoops. While it's
still a little tedious to set up the arrays for QFV_CreateResource (and
they need to be kept around for QFV_DestroyResource), it really eases
calculation of memory object size and sub-resource offsets. And
destroying all the objects is just one call to QFV_DestroyResource.
2022-05-04 13:59:38 +09:00
Bill Currie 9d7cad420d [vulkan] Add a function to translate QFFormat to VkFormat
It's not great, but it does produce reasonable results for the formats
supported by QF's image system.
2022-05-04 13:57:02 +09:00
Bill Currie 419d91edc5 [image] Set texture type for no-load tga images
I might need to do similar for other formats, but i ran into the problem
of the texture type being tex_palette instead of the expected tex_rgba
when pre-(no-)loading a tga image resulting in Vulkan not liking my
attempt at generating mipmaps.
2022-05-04 13:50:55 +09:00
Bill Currie fe891dd70b Merge branch 'master' into wip-rua_scene 2022-05-01 14:46:47 +09:00
Bill Currie b87a768c43 [gamecode] Sort debug local defs by address
This allows the fuzzy bsearch used to find a def by address to work
properly (ie, find the actual def instead of giving some other def +
offset). Makes for a much more readable instruction stream.
2022-05-01 14:35:24 +09:00
Bill Currie 4ed9fc6820 [ruamoko] Switch to 64-bit handles for scene objects
The scene id is in the lower 32-bits for all objects (upper 32-bits are
0 for actual scene objects) and entity/transform ids are in the upper
32-bits. Saves having to pass around a second parameter in progs code.
2022-04-29 21:02:08 +09:00
Bill Currie 875c9bde7c [gamecode] Print operand widths when not 1
The widths for all three operands are printed if any is greater than 1.
Makes figuring out which instruction is executing a little easier.
2022-04-29 16:59:15 +09:00
Bill Currie af2dfde37a [gamecode] Support printing 64-bit integer types
The 'l' modifier always means 64-bit, regardless of the underlying
platform. As well, the 32-bit integer types are handled portably too.
2022-04-29 16:59:15 +09:00
Bill Currie 6d62e91ce7 [gamecode] Clean up progs data access
pr_type_t now contains only the one "value" field, and all the access
macros now use their PACKED variant for base access, making access to
larger types more consistent with the smaller types.
2022-04-29 16:59:15 +09:00
Bill Currie c4d56afd33 [vulkan] Cope with an empty world model
Vulkan doesn't appreciate the empty buffers that result from the model
not having any textures or surfaces that can be rendered (rightfully so,
for such a bare-metal api).
2022-04-26 07:26:32 +09:00
Bill Currie 5703df00fd [renderer] Don't try to draw a nonexistent view model
Doing so doesn't end well (segfault). This is a bit of a hack until I
come up with a design for configurable scene rendering.
2022-04-26 07:22:45 +09:00
Bill Currie 98cbacfe9d [renderer] Remove redundant calls to visit_leaf
I doubt the calls were ever actually made in a normal map due to the
node actually being a node when breaking out of the loop, but when I
experimented with an empty world model (no nodes, one infinite empty
leaf) I found that visit_leaf was getting called twice instead of once.
2022-04-26 07:14:03 +09:00
Bill Currie fddff1c24d Merge branch 'master' into wip-rua_scene 2022-04-25 08:13:35 +09:00
Bill Currie 7ef9aab7f3 [vulkan] Use cached memory for the bsp index buffer
Since it is updated every frame, it needs to be as fast as possible for
the cpu code. This seems to make a difference of about 10us (~130 ->
~120) when testing in marcher. Not a huge change, but the timing
calculation was wrapped around the entire base world pass, so there was
a fair bit of overhead from bsp traversal etc.
2022-04-25 07:49:30 +09:00
Bill Currie 0b912795d0 [vulkan] Use host-cached memory for staging buffers
It makes a significant difference to level load times (approximately
halves them for demo1 and demo2). Nicely, it turns out I had implemented
the rest of the staging buffer code (in particular, flushing) correctly
in that it seems there's no corruption any of the data.
2022-04-25 07:49:30 +09:00
Bill Currie f6baa16084 [cvar] Remove the cvar lists
They're really redundant, and removing the next pointer makes for a
slightly smaller cvar struct. Cvar_Select was added to allow finding
lists of matching cvars.

The tab-completion and config saving code was reworked to use the hash
table DO functions. Comments removed since the code was completely
rewritten, but still many thanks to EvilTypeGuy and Fett.
2022-04-25 00:26:45 +09:00
Bill Currie 8bd626a3e4 [hash] Add a couple of data-oriented functions
Hash_Select returns a list of elements that match a given criterion
(select callback returning non-0).

Hash_ForEach simply calls a function for every element.
2022-04-25 00:18:22 +09:00
Bill Currie bafe54b010 [view] Add a cexpr enum for grav_t
And use it for hud_scoreboard_gravity. Putting the enum def in view made
the most sense as view does own the base type and the enum is likely to
be by useful for other settings.
2022-04-24 21:09:58 +09:00
Bill Currie bdb1192c13 [console] Fix missed changes to console line exec control
I think I'd gotten distracted while making the changes to the server,
then simply copied the partial changes to the client. It didn't blow up
thanks to the backing store bing char * and the type sized for int, so
safe on any platform, but useless as it wasn't connected properly.

It's actually pretty neat being able to directly, but safely, control a
function pointer via a cvar :)
2022-04-24 20:46:06 +09:00
Bill Currie bff0847761 [cvar] Clean up most misinterpreted cvar types
The misinterpretations were due to either the cvar not being accessed
directly by the engine, but via only the callback, or the cvars were
accesssed only by progs (in which case, they should be float). The
remainder are a potential enum (hud gravity) and a "too hard basket"
(rcon password: need to figure out how I want to handle secret strings).
2022-04-24 20:04:06 +09:00
Bill Currie 90447a5d3b [quakefs] Ensure fs_sharepath and fs_userpath are never empty
Other parts of quakefs treat an empty path as an error, so fs_sharepath
and fs_userpath must never be empty or they will effectively be
rejected. While the user explicitly setting them to empty strings is one
way for them to become empty, another is QFS_CompressPath compressing
'.' to an empty path, which makes it rather difficult to set up the
traditional quake directory tree (ie, operate from the current
directory).
2022-04-24 19:15:22 +09:00
Bill Currie 9f876390f0 [input] Fix up some mistranslated cvars
My script didn't know what type to make the cvars since they're not used
directly by the code, so they got treated as strings instead of ints or
floats.
2022-04-24 19:15:22 +09:00
Bill Currie 12c84046f3 [cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.

As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.

The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).

While not used yet (partly due to working out the design), cvars can
have a validation function.

Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.

nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-24 19:15:22 +09:00
Bill Currie 87b3c64801 [vulkan] Parse VkPresentModeKHR
And strip the KHR for short names.
2022-04-24 19:15:22 +09:00
Bill Currie a52704e8ca [cexpr] Allow assignment of double to float
I didn't really want this, but it's needed for cvar support.
2022-04-24 19:15:22 +09:00
Bill Currie aad4546c01 [cexpr] Expose cexpr assignment
This makes it much easier for other systems (in particular, cvar) to
copy values safely.
2022-04-24 19:15:22 +09:00
Bill Currie 021ec4962b [cexpr] Add optional error message prefix string
The prefix gives more context to the error messages, making the system a
lot easier to use (it was especially helpful when getting my cvar revamp
into shape).
2022-04-24 19:15:22 +09:00
Bill Currie d68db74049 [cexpr] Add a flags type
Based on the flags type used in vkparse (difference is the lack of
support for plists). Having this will make supporting named flags in
cvars much easier (though setting up the enum type is a bit of a chore).
2022-04-24 19:15:22 +09:00
Bill Currie 392e032ce2 [cexpr] Add a get_string function to exprtype_t
This allows for easy (and safe) printing of cexpr values where the type
supports it. Types that don't support printing would be due to being too
complex or possibly write-only (eg, password strings, when strings are
supported directly).
2022-04-24 19:13:54 +09:00
Bill Currie db5b77c838 [cexpr] Require designated initializers for exprtype_t
This will make expanding it much safer in the future.
2022-04-24 17:31:17 +09:00
Bill Currie 8a411dc120 [joy] Clean up some redundant cvar flags
No need to or CVAR_NONE with other flags.
2022-04-24 17:23:46 +09:00
Bill Currie 001b3eb908 Fix some inconsistent cvar uses
Surprisingly, only two, but they were caught by the different value
fields being used, thus the cvar was checked in multiple places. I
imagine that's not really all that common, so there may be some
inconsistencies between default value and use.
2022-04-24 17:23:46 +09:00
Bill Currie 55f7886607 Remove some long dead cvars
The declarations were still around, but the creation and code using them
was removed long ago.
2022-04-24 17:23:46 +09:00
Bill Currie ef574e67d0 [net] Remove client references from net_main
This is progress towards #23. There are still some references to
host_time and host_client (via nq's server.h), and a lot of references
to sv and svs, but this is definitely a step in the right direction.
2022-04-24 17:21:58 +09:00
Bill Currie b2d4fa0ccf [vulkan] Break render pass parsing away from swapchain
This allows a single render pass description to be used for both
on-screen and off-screen targets. While Vulkan does allow a VkRenderPass
to be used with any compatible frame buffer, and vkparse caches a
VkRenderPass created from the same description, this allows the same
description to be used for a compatible off-screen target without any
dependence on the swapchain. However, there is a problem in the caching
when it comes to targeting outputs with different formats.
2022-04-24 17:04:10 +09:00
Bill Currie bc1fe6aa01 [renderer] Remove some redundant comments
No need for comments when the code says it all.
2022-04-23 10:56:56 +09:00
Bill Currie f15abcea53 [vulkan] Add a FIXME for the flashing Q icon
As I had suspected, it's due to a synchronization problem between the
scrap and drawing. There's actually a double problem in that data
uploaded to the scrap isn't flushed until the first frame is rendered
causing a quick init-shutdown sequence to take at least five seconds due
to the staging buffer waiting (and timing out) on a stuck fence.
Rendering just one frame "fixes" the problem (draw was one of the
earliest subsystems to get going in vulkan).
2022-04-23 10:46:55 +09:00
Bill Currie b649638400 [joy] Clean up some redundant cvar flags
No need to or CVAR_NONE with other flags.
2022-04-13 14:17:58 +09:00
Bill Currie 063c0797d6 Fix some inconsistent cvar uses
Surprisingly, only two, but they were caught by the different value
fields being used, thus the cvar was checked in multiple places. I
imagine that's not really all that common, so there may be some
inconsistencies between default value and use.
2022-04-13 14:17:58 +09:00
Bill Currie e97b96b536 Remove some long dead cvars
The declarations were still around, but the creation and code using them
was removed long ago.
2022-04-13 14:17:58 +09:00
Bill Currie 4d443d3114 [vid] Fix non-utf8 circle-c in fbset
Python didn't like reading the files.
2022-04-13 10:35:40 +09:00
Bill Currie 6b81a4b882 [renderer] Don't try to animate lightstyles that aren't there
Prevents a segfault when running the renderer via qwaq-x11.
2022-04-07 22:30:19 +09:00
Bill Currie f6541dbe3f [net] Remove client references from net_main
This is progress towards #23. There are still some references to
host_time and host_client (via nq's server.h), and a lot of references
to sv and svs, but this is definitely a step in the right direction.
2022-04-06 19:32:55 +09:00
Bill Currie 8f56f28ad7 [net] Use designated initializers for drivers
Not that I expect anything to change any time soon, but nice to have
the initializers explicitly named.
2022-04-06 18:46:28 +09:00
Bill Currie 3f575ab025 [win] Update for moved vulkan viewport
I forgot to do a windows test build.
2022-04-06 18:36:07 +09:00
Bill Currie 2798b5fd58 [vulkan] Use cached memory for the bsp index buffer
Since it is updated every frame, it needs to be as fast as possible for
the cpu code. This seems to make a difference of about 10us (~130 ->
~120) when testing in marcher. Not a huge change, but the timing
calculation was wrapped around the entire base world pass, so there was
a fair bit of overhead from bsp traversal etc.
2022-04-06 14:40:40 +09:00
Bill Currie b011f91018 [model] Clean up alias skin loading a little
The improved allocation overheads have been implemented for gl and sw,
and glsl no longer uses malloc. Using array textures will have to wait
as the current texture loading code doesn't support them.
2022-04-04 17:47:21 +09:00
Bill Currie e40f3f4f93 [model] Make alias skin loading a batch operation
Really, this won't make all that much difference because alias models
with more than one skin are quite rare, and those with animated skin
groups are even rarer. However, for those models that do have more than
one skin, it will allow for reduced allocation overheads, and when
supported (glsl, vulkan, maybe gl), loading all the skins into an array
texture (since all skins are the same size, though external skins may
vary), but that's not implemented yet, this just wraps the old one skin
at a time code.
2022-04-04 15:38:27 +09:00
Bill Currie f66df59c43 [vulkan] Use a template for the attachment desciptions 2022-04-03 13:15:30 +09:00
Bill Currie c8e299ca58 [vulkan] Use a template for the deferred attachment images
It's certainly much easier to read and see what's different between the
attachment.
2022-04-03 12:25:04 +09:00
Bill Currie d3d081ea0a [vulkan] Switch deferred opaque attachment to f16 rgb
While looking at the deferred attachment images with using a template in
mind, I noticed that the opaque attachment was using 8-bit color. The
problem is, it's meant to be HDRI with the compose pass crunching it
down to LDRI. Switching to 16-bit float does seem to have made a subtle
difference (hey, it's still quake data, not much HDRI in there).
2022-04-03 12:02:13 +09:00
Bill Currie 39e7c4a9b2 [vulkan] Use a template for the deferred image views
That certainly makes it nicer to work with large sets, and shows one way
to be careful with allocated resources: don't allocate them in the
inherited data and use a template that needs a few things filled in to
be valid. Also, it seems that overriding values in sub-structures "just
works" :)
2022-04-03 11:47:53 +09:00
Bill Currie eb4d566801 [vkparse] Add support for inheriting objects
It simply parses the referenced plist dictionary (via @inherit =
plist.path;) into the current data block, then allows the data to be
overwritten by the current plist dictionary. This may be a bit iffy for
any allocated resources, so some care must be taken, but it seems to
work nicely.
2022-04-03 11:11:28 +09:00
Bill Currie bbbdc41af3 [vulkan] Break render pass parsing away from swapchain
This allows a single render pass description to be used for both
on-screen and off-screen targets. While Vulkan does allow a VkRenderPass
to be used with any compatible frame buffer, and vkparse caches a
VkRenderPass created from the same description, this allows the same
description to be used for a compatible off-screen target without any
dependence on the swapchain. However, there is a problem in the caching
when it comes to targeting outputs with different formats.
2022-04-02 11:42:36 +09:00
Bill Currie 9892e571ce [vulkan] Move viewport and scissor into qfv_renderpass_t
This makes much more sense as they are intimately tied to the frame
buffer on which a render pass is working. Now, just the window width
and height are stored in vulkan_ctx_t. As a side benefit,
QFV_CreateSwapchain no long references viddef (now just palette and
conview in vulkan_draw.c to go).
2022-04-01 20:34:41 +09:00
Bill Currie 11e30583cf [vulkan] Switch to full screen triangle instead of quad
While I have trouble imagining it making that much performance
difference going from 4 verts to 3 for a whopping 2 polygons, or even
from 2 triangles to 1 for each poly, using only indices for the vertices
does remove a lot of code, and better yet, some memory and buffer
allocations... always a good thing.

That said, I guess freeing up a GPU thread for something else could make
a difference.
2022-04-01 19:50:41 +09:00
Bill Currie 88343d73ea [vulkan] Safely ignore fisheye and water warp
I didn't like the abort (especially having pushed it to master). This
takes care of things until I can get them implemented properly
(hopefully soon).
2022-04-01 16:51:25 +09:00
Bill Currie 03c403610d [vulkan] Safely ignore fisheye and water warp
I didn't like the abort (especially having pushed it to master). This
takes care of things until I can get them implemented properly
(hopefully soon).
2022-04-01 16:49:39 +09:00
Bill Currie 6bbbe4997b [vulkan] Invalidate mapped capture image memory
I think I had gotten lucky with captures not being corrupt due to them
being much bigger than all but the L3 cache (and then they're over 1/2
the size), so the memory was being automatically invalidated by other
activity. Don't want to trust such luck, though.
2022-04-01 16:19:10 +09:00
Bill Currie 42a03758c5 [vulkan] Remove redundant entity queue creation
I'd missed this when cleaning up entity queue creation for the other
renderers.
2022-04-01 15:26:51 +09:00
Bill Currie 6d0abd42bb [vulkan] Use host-cached memory for staging buffers
It makes a significant difference to level load times (approximately
halves them for demo1 and demo2). Nicely, it turns out I had implemented
the rest of the staging buffer code (in particular, flushing) correctly
in that it seems there's no corruption any of the data.
2022-04-01 15:14:56 +09:00
Bill Currie 78119aeb7a [gamecode] Clean up generated swizzle code 2022-04-01 02:14:05 +09:00
Bill Currie ddfacf61ee [qw] Get remote screen shots working again
Probably better than they ever have, really, since I think they were
broken for one renderer or another.
2022-04-01 02:04:24 +09:00
Bill Currie 86e95fc1d0 [vulkan] Use host-cached memory for captures
This takes simply reading the transfer buffer from about 400ms down to
about 3ms (for 1920x1080 rgba). PNG compression is now the bottleneck.
2022-04-01 01:01:53 +09:00
Bill Currie 790f62a209 [image] Make WritePNG take settings from tex_t
This means that a tex_t object is passed in instead of just raw bytes
and width and height, but it means the texture can specify whether it's
flipped or uses BGR instead of RGB. This fixes the upside down
screenshots for vulkan.
2022-04-01 01:01:53 +09:00
Bill Currie acffacc59b [renderer] Make screen capture support asynchronous operation
This fixes (*ahem*) the vulkan renderer segfaulting when attempting to
take a screenshot. However, the image is upside down. Also, remote
snapshots and demo capture are broken for the moment.
2022-04-01 01:01:53 +09:00
Bill Currie a29836cc2c [quakefs] Return QFile pointer from QFS_NextFile(name)
QFS_NextFilename was renamed to QFS_NextFile to reflect the fact it now
returns a QFile pointer for the newly created file (as well as the
name). This necessitated updating WritePNG to take a file pointer
instead of a file name, with the advantage that WritePNGqfs is no longer
necessary and callers have much more control over the creation of the
file.

This makes QFS_NextFile much more secure against file system race
conditions and attacks (at least in theory). If nothing else, it will
make it more robust in a multi-threaded environment.
2022-03-31 17:27:04 +09:00
Bill Currie 8cdabc8905 [quakefs] Reimplement QFS_NextFilename to be more secure
It's not there yet as it promptly closes the file and returns only the
filename (and then only the portion within the user's directory tree).
However, this worked nicely as a test for Sys_UniqueFile.
2022-03-31 16:44:19 +09:00
Bill Currie a35bfef24c [sys] Add a function to safely create a unique file
QF currently uses unique file names for screenshots and server-side
demos (and remote snapshots), but they're generally useful.
QFS_NextFilename has been filling this role, but it is highly insecure
in its current implementation. This is the first step to taking care of
that.
2022-03-31 16:44:19 +09:00
Bill Currie 14ad364e17 [gamecode] Document the tests that fail under clang
The tests fail due to differences in how clang and gcc treat floating
point to unsigned integral type conversions when the values overflow. It
wouldn't be so bad if clang was consistent with conversions to 32-bit
unsigned integers, like it seems to be with conversion to 64-bit
unsigned integers.

With this, the "get QF building with clang" mini-project is done and I
won't have to panic when someone comes to me and asks if it will work.
At worst, there'll be a little bit-rot.
2022-03-31 14:50:49 +09:00
Bill Currie d3afb0da50 [vulkan] Remove a dead function
I guess gcc missed it because it's inline.
2022-03-31 02:59:37 +09:00
Bill Currie dad17162bb [console] Rewrite the download progress indicator
It was a nasty mess of suspicious strncats and the like.
2022-03-31 02:57:38 +09:00
Bill Currie 8f6ee4f5ac [gl] Work aground clang not liking variable structs with followers
Really, it's an ugly hack made uglier, but I don't feel like dealing
with it right now.
2022-03-31 02:56:14 +09:00
Bill Currie d109571994 [gamecode] Use 64 byte alignment for most of progs memory
Only edicts themselves get a smaller alignment (4, 8 or 32 bytes,
depending on hardware and progs version). I didn't want to waste too
much memory on edict alignment for progs that don't need any better than
void *, but the zone really wants 64 bytes, and the stack might as well
have 64 bytes as well. Fixes a segfault when running v6 progs in a clang
build (clang got really agressive with simd in zone.c).
2022-03-31 02:51:05 +09:00
Bill Currie f601606ad7 [gamecode] Fix an enum cast warning
Harmless, but it doesn't hurt to make it explicit.
2022-03-31 02:50:03 +09:00
Bill Currie cdcf1a71ea [gamecode] use correct void for global_string
It seems gcc is a little fast and loose with 0 as a null vector.
2022-03-31 02:48:01 +09:00
Bill Currie 2f9df0f05b Work around some clang parsing issues
clang has no problem with labels crossing declarations, but it can't
cope with a declaration (or end of block) just after a label.
2022-03-31 02:44:58 +09:00
Bill Currie 5b3cd93fa3 [gamecode] Implement with more portably
clang doesn't support taking the address of a vector component. I was
just being lazy when I used a pointer when setting the base register.
2022-03-31 02:38:26 +09:00
Bill Currie 7a6ca0ebcb [simd] Use portable swizzles
gcc and clang have rather different swizzle builtins, but both do a nice
job of optimizing the intuitive initializer swizzle (I think gcc 8(?)
didn't do such a good job thus my use of __builtin_shuffle).
2022-03-31 02:25:33 +09:00
Bill Currie 7305406f46 [vulkan] Update labeled struct inits
I had used some legacy gcc extensions rather than standard C (clang
wasn't too happy about that).
2022-03-31 01:26:57 +09:00
Bill Currie b02e29ea89 [x11] Clear up some signed/unsigned ambiguity
I don't remember what gcc does with unsigned-int, but obviously clang
produces another unsigned, which is most definitely not wanted.
2022-03-31 00:34:40 +09:00
Bill Currie 68b133417b [net] Fix some logic precedence errors 2022-03-31 00:31:15 +09:00
Bill Currie 78089a0e99 [mode] Fix a sizeof error
I'm surprised that got past gcc, but it's nice clang caught it.
2022-03-31 00:30:00 +09:00
Bill Currie 38319d01b2 Fix some null pointer shenanigans
clang doesn't like anything but a bare 0 as null (and in some of the
cases, it was quite right: '\0' should not be treated as a null
pointer). And the crashers were just for paranoia and probably aren't
needed any more (kept for now, though).
2022-03-31 00:25:22 +09:00
Bill Currie 63e5655f68 Clean up some enum sanity checks
It seems clang defaults to unsigned for enums. Interestingly, gcc was ok
with the checks being either way. I guess gcc treats enums that *can* be
unsigned as DWIM.
2022-03-31 00:18:53 +09:00
Bill Currie db01650dac Update vec3_t/vec4f_t hacks to work with clang
Still work with gcc, of course, and I still need to fix them properly,
but now they're actually slightly easier to find as they all have vec_t
and FIXME on the same line.
2022-03-31 00:08:26 +09:00
Bill Currie a6df8ab995 [renderer] Move a couple functions to using vec4f_t
Makes for a few less FIXMEs and better consistency with vectors.
2022-03-30 23:53:30 +09:00
Bill Currie da42aaf423 [sound] Use vec4f_t for api functions
Fixes a few vec3_t/vec4f_t FIXMEs.
2022-03-30 23:42:38 +09:00
Bill Currie d35154ecf1 [vulkan] Clean up a lot of unnecessary includes
Too much copying of base files.
2022-03-30 15:54:07 +09:00
Bill Currie 495dd759f0 [renderer] Clean up FOV and viewport handling
Viewport and FOV updates are now separate so updating one doesn't cause
recalculations of the other. Also, perspective setup is now done
directly from the tangents of the half angles for fov_x and fov_y making
the renderers independent of fov/aspect mode. I imagine things are a bit
of a mess with view size changes, and especially screen size changes
(not supported yet anyway), and vulkan winds up updating its projection
matrices every frame, but everything that's expected to work does
(vulkan errors out for fisheye or warp due to frame buffer creation not
being supported yet).
2022-03-30 14:55:32 +09:00
Bill Currie 9fbd16be05 [renderer] Avoid infinite loop
If the entity didn't have a known model type, R_StoreEfrags would get
stuck in an infinite loop (fortunately, never actually happened. The
result of making it not call Sys_Error for unknown models)).
2022-03-30 11:06:46 +09:00
Bill Currie 3c86764eb2 [scene] Move entity_t etc into scene headers
I meant to do this a while ago but forgot about it. Things are a bit of
a mess in that the renderer knows too much about entities, but
eventually the renderer will know about only things to render (meshes,
particles, etc).
2022-03-29 14:43:38 +09:00
Bill Currie 75d7f4cecb [renderer] Clean up particles a little
The quake-specific enums are now in the client header, and the particle
system now has a gravity field rather than getting it from
vid_render_data (which I hope to eventually get rid of entirely).
2022-03-29 14:43:38 +09:00
Bill Currie ca9e18b9d6 [renderer] Use initializer labels for vid_render_data
Got tired of figuring out which initializers to remove when editing
vid_render_data_t.
2022-03-29 14:43:38 +09:00
Bill Currie d53b0b0064 [sw] Clean up use of vid.colormap8
The main goal was to not update the colormap pointers when only the
viewport or fov changed.
2022-03-29 14:43:38 +09:00
Bill Currie 3103f400fd [sw] Clean up r_refdef and R_ViewChanged
r_refdef is really meant for holding the various screen "constants" for
the software renderer rather than the more generic scene stuff. All the
fields referenced by the low level rendering code (especially assembly)
have been moved to the beginning of the struct (and nicely fit within 64
bytes). The other fields should be moved elsewhere, but not this commit.

On top of that, R_ViewChanged is much easier to read, and there are
fewer static globals.
2022-03-27 15:32:00 +09:00
Bill Currie aafd5c3d81 [gl] Make perspective matrix setup consistent
Now GL perspective matrix setup matches that of GLSL and Vulkan, and
GL's z_up matrix matches GLSL's (as it should, since they're really
going through the same API). GL also needs the depth adjustmet matrix
now. Other than having to google the docs for glFrustum, there's nothing
wrong with the function itself, but it's nice to have direct control
over the matrices.

In the process, I discovered how horribly confused I've been at times
with respect to the handedness of GL and Quake: GL is right-handed
(y-up, z-out, x-right), as is Quake itself (but z-up, y-left, x-in), but
as the perspective matrix used in the three renderers expects z-in,
having x-right and y-up makes the matrix effectively left-handed (not
for Vulkan though, because there it's y-down, x-right, z-up, so
right-handed again).
2022-03-27 13:23:44 +09:00
Bill Currie 12776e487a [gl] Implement screen warping for liquids
It's not the most efficient code (uses sin() directly), but at least it
works (and with about 75% cpu headroom at 72fps on my machine).
2022-03-26 18:13:37 +09:00
Bill Currie a0adca011f [gl] Get fisheye working with frame buffers
Of course, it's not as correct as glsl or sw due to using polygons and
uvs rather than a fragment shader (not that such is out of the question
since GL 3.0 is requested, but I don't feel like getting shaders going
just for a couple of post-processing effects in an obsolete renderer).
2022-03-26 12:51:31 +09:00
Bill Currie aa41259008 [gl] Clean out the last of the mirror code
Stragglers...
2022-03-26 10:27:16 +09:00
Bill Currie 303756b41b [gl] Remove the envmap command
It has never worked, but it should be easy enough to implement for all
renderers since fisheye does the same thing.
2022-03-26 10:27:16 +09:00
Bill Currie 77a797d04b [renderer] Clean up viewport setting
Software is still a mess, and vulkan never supported viewsize, but
otherwise everything seems fine.
2022-03-26 10:27:16 +09:00
Bill Currie f2bc5b560f [renderer] Clean up post processing
While it's not where I want it to be, it at least now no longer messes
with frame buffer binding or the view ports. This involved switching
around buffers in D_WarpScreen so that the main buffer could be bound
before post-processing.
2022-03-26 00:42:43 +09:00
Bill Currie 25e6865fa5 [glsl] Update particle arrays when maximum changes
The cvar setup for particles is a bit wonky in that the arrays get
initialized using the default max particle count but never updated.
Though things could be improved some more, this solution works (and has
been more or less copied to gl, but I couldn't reproduce the crash
there, or even the valgrind error).
2022-03-25 14:48:01 +09:00
Bill Currie 286344c7b6 [glsl] Implement fisheye rendering
The code dealing with state is a bit of a mess, but everything is
working nicely. Get around 400fps when all 6 faces need to be rendered
(no surprise: it should be about 1/6 of that for normal rendering). The
messy state handling code did not come as a surprise as I suspected
there were various mistakes in my scene rendering "recipe", and fisheye
highlighted them nicely (I'm sure getting this stuff working in Vulkan
will highlight even more issues).
2022-03-25 12:22:16 +09:00
Bill Currie 18aae8205e [glsl] Implement screen warp when in liquids
Finally, after a decade :P Looks pretty good, too, and is (almost)
properly scaled to the resolution (almost because the effect is a little
squashed, but I think the sw renderer does the same).
2022-03-25 09:01:27 +09:00
Bill Currie e263521330 [glsl] Put #line after any #version lines in the chunks
The GLSL compiler requires any #version lines to be the first (real)
line of the program, even #line causes an error, so if the first line of
the chunk starts with #version, insert the #line directive as the second
line.
2022-03-25 09:01:27 +09:00
Bill Currie 00362e9f4e [gl] Explicitly request compatibility profile
And core profile for glsl
2022-03-25 09:01:11 +09:00
Bill Currie 7ca3b56620 [glsl] Fix a silly typo in a comment 2022-03-24 15:54:23 +09:00
Bill Currie 20a2e7e06f [renderer] Get sw fisheye working again
Again, gl/vulkan not working yet (on the assumption that sw would be
trickier).

Fisheye overrides water warp because updating the projection map every
frame is far too expensive.

I've added a post-process pass to the interface in order to hide the
implementation details, but I'm not sure I'm happy about how the
multi-pass rendering for cube maps is handled (or having the frame
buffers as exposed as they are), but mainly because Vulkan will make
implementation interesting.
2022-03-24 15:50:41 +09:00
Bill Currie 0c437492b4 [renderer] Move to using dynamic frame buffers
For now, OpenGL and Vulkan renderers are broken as I focused on getting
the software renderer working (which was quite tricky to get right).

This fixes a couple of issues: the segfault when warping the screen (due
to the scene rendering move invalidating the warp buffer), and warp
always having 320x200 resolution. There's still the problem of the
effect being too subtle at high resolution, but that's just a matter of
updating the tables and tweaking the code in D_WarpScreen.

Another issue is the Draw functions should probably write directly to
the main frame buffer or even one passed in as a parameter. This would
remove the need for binding the main buffer at the beginning and end of
the frame.
2022-03-24 12:56:29 +09:00
Bill Currie 4a917449b7 [sw] Clean up a bunch of unnecessary casts
They won't affect performance, but they cluttered the code making it
harder to read.
2022-03-21 23:15:14 +09:00
Bill Currie 8ee776e8fb [sw] Rename d_pzbuffer to d_zbuffer 2022-03-21 23:12:22 +09:00
Bill Currie 376a173e66 [sw] Set FP precision in R_DrawEntitiesOnList
This used to be handled by R_RenderView (encompassing all of the
rendering) before the scene rendering was moved out to r_screen. This
fixes the stuck time in 32-bit nq-win.
2022-03-21 21:59:07 +09:00
Bill Currie 2e1ddfed0d [sw] Fix some missed symbol renames
Missed due to assembly language :P
2022-03-21 19:24:43 +09:00
Bill Currie 939a73fb52 [sys] Override strdup for 32-bit windows
This fixes some nasty segfaults when calling free due to different
allocators being used.
2022-03-21 19:23:49 +09:00
Bill Currie 296c04c8eb [console] Ensure console lines doesn't exceed view
This fixes a segfault in 32-bit nq-win caused by negative frame times
(due to something going weird with Sys_DoubleTime).
2022-03-21 19:21:54 +09:00
Bill Currie 4c90c3c4bb [sw] Remove pixbytes from sw_ctx_t
It's no longer needed as the sw renderer is 8-bit only.
2022-03-21 14:37:28 +09:00
Bill Currie b82a353a20 [vid] Remove VID_InitBuffers
Its guts have been moved to D_Init temporarily while I work on the
frame buffer design. This is actually a big part of that work as it
moves most of the frame buffer creation into the one place, making it
easier to ensure I get all the sub-buffers and caches created.
2022-03-21 14:35:11 +09:00
Bill Currie 3b4608a0cd [vid] Update glx handling to ensure GL 3.0
With what I have planned for frame buffers etc, GL 3.0 will be needed
even for the fixed-function GL renderer, and then I might even take the
GLSL renderer to 4.6 (dunno yet). This means that wgl will need to be
updated too, and I've found the info I need for that, but it's a bit
much to take on just yet.
2022-03-20 12:52:20 +09:00
Bill Currie 0f30f0a133 [mathlib] Remove suspicious IS_NAN
The implementation looks wrong (more like infinity). Where it was used
is currently disabled, but the usages were replaced with C99's isnan.
2022-03-19 12:50:08 +09:00
Bill Currie 65af7fb4a4 [mathlib] Remove frustum global
It should never have been there and is now in the refdef (not its final
home: it should probably be part of the camera).
2022-03-19 12:33:12 +09:00
Bill Currie b912c2a667 [renderer] Clean up R_SetFrustum
The only global it touches now is frustum, and that needs fixing in
mathlib (good grief, we (probably I) did some weird things when merging
the code).
2022-03-19 10:06:38 +09:00
Bill Currie c3f38e1c79 [renderer] Remove player_entity field
This was a hold-over from the gl mirror code.
2022-03-19 09:46:53 +09:00
Bill Currie ee51d06aa3 [renderer] Clean up a lot of recalc_refdef use
I think the widespread use of recalc_refdef (and force_fullscreen) was
the result of a rushed merge of the renderer and video code (I do seem
to remember sprinkling them around). This cleans the two out of the
client code.
2022-03-19 00:56:30 +09:00
Bill Currie a4479f4840 [cvar] Ensure floats can round-trip when setting
The way Cvar_SetValue is used, floats need to be able to round-trip
reliably and thus need up to 9 digits of precision.
2022-03-18 11:42:14 +09:00
Bill Currie c8c742b240 [renderer] Use a better calculation for fov_y
This avoids the possibility of a singularity (and thus the temptation to
use Sys_Error). While the rendering is rubbish, 0 degrees is allowed
because values less than 1 should be allowed, but where does one stop?
170 is the maximum in order to avoid any issues with (near) parallel or
inverted frustum planes (or other fun things) in the low level code.
2022-03-18 11:14:24 +09:00
Bill Currie 2b72506868 [renderer] Handle transparent surfaces
Other than the view model (undecided on the approach) this has
R_RenderView pretty much pulled out of the low level renderers. With
this, I'll be able to focus on scene handling for a bit then getting
shadows and fisheye working (again for fisheye).
2022-03-18 01:08:19 +09:00
Bill Currie c05476f94b [renderer] Move most of the scene rendering into r_screen
r_screen isn't really the right place, but it gets the scene rendering
out of the low-level renderers and will make it easier to sort out
later, and hopefully easier to figure out a good design for vulkan.
2022-03-17 17:57:50 +09:00
Bill Currie 961e6d9e6c [gl] Remove unnecessary light map update code
gl_overbright_f shouldn't need to run through any entity queues to
update the light maps as only the world model has light maps, and
hitting the world model should hit all its sub-models.
2022-03-17 17:46:25 +09:00
Bill Currie 833fb2f4f8 [sw] Make alight_t lightvec an actual vector
The change to using separate per-model-type entity queues resulted in
the lighting vector used for alias and iqm models being in an ephemeral
location (in the shared setup_lighting function's stack frame). This
resulted in the model rendering code getting a garbage vector due to it
being overwritten by another stack frame. What I don't get is why the
garbage varied from run to run for the same demo (demo2, the first scrag
behind the start door showed the bad lighting nicely), which made
tracking down the offending commit (and thus the code) rather
troublesome, though once I found it, it was a bit of a face-palm moment.
2022-03-17 15:38:22 +09:00
Bill Currie 6c29904b1d [sw] Clean up R_SetSkyFrame a little
Move the constant data into R_InitSky so it doesn't get calculated every
frame (doesn't make much difference of course, but...)
2022-03-17 13:37:21 +09:00
Bill Currie d8a4c8dbe9 [renderer] Clean up r_bsp a little
Move r_pcurrentvertbase into the sw renderer, cleaning up gl's use of
(not really needed there). Not ready to move r_bsp into the main bin yet
as there are linking issues since only the low-level code references any
of its symbols.
2022-03-17 13:09:20 +09:00
Bill Currie 7ee9159638 [renderer] Move common R_SetupFrame code to r_screen
The code is really part of scene (not a typo wrt r_screen: that is
misnamed as such, or at least SCR_UpdateScreen needs to be split into
screen (2d overlay, really) and scene updates).

This breaks fisheye rendering as the fisheye code calls the actual scene
render code multiple times, but the fisheye code is called by said scene
render code via a diversion. The fisheye needs to be moved out to the
high level scene render, but that will takes some extra work for frame
buffer setup.
2022-03-17 12:00:43 +09:00
Bill Currie 335d387ba8 [renderer] Clean up some stray vup etc
Now vup, vfwd, vright names are restricted to only the software renderer
(the only one that has such global variables).
2022-03-17 11:55:58 +09:00
Bill Currie 0e58f96d37 [renderer] Fix more plugin linking errors 2022-03-17 11:21:38 +09:00
Bill Currie 1458f61a48 [renderer] Fix non-static linking of graph code
Obviously forgot to test the changes I made to graph rendering in
non-static builds. Oops :P
2022-03-17 10:51:29 +09:00
Bill Currie d3bfc54a68 [sw] Disable water warp when doing fisheye
The two aren't compatible (but warping might be doable in the fisheye
code). The whole frame setup code needs a rework, and really, even the
buffer handling.
2022-03-17 09:42:09 +09:00
Bill Currie 9241efaf1e [sw] Use a smaller size for the fish eye cube map
This speeds up sw rendering of the fish eye effect.
2022-03-16 13:55:44 +09:00
Bill Currie ab78e9d2ff [sw] Make worldent local static
It being on the stack was a bad idea as R_RenderWorld returns before the
scans are rendered and thus the entity pointer winds up pointing to
abandoned stack space.
2022-03-15 16:54:59 +09:00
Bill Currie 91d7a80dff [renderer] Get timegraph and zgraph working
Only for sw and gl right now, but this sorts out the issues that
prevented the graphs working at all.
2022-03-15 15:42:43 +09:00
Bill Currie 5a57280aa9 [gl] Use glGenTextures to allocate texture numbers
While the scheme of using our own allocated did work just fine, fisheye
rendering uses glGenTextures which caused a texture id clash and thus
invalid operations (the cube map texture happened to be the same as the
console background texture). Sure, I could have just "fixed" the fisheye
init code, but this brings gl closer in line with glsl (which makes
extensive use of glGenTextures and glDeleteTextures). This doesn't fix
any texture leaks gl has (plenty, I imagine), but it's a step in the
right direction.
2022-03-15 13:29:05 +09:00
Bill Currie fb4fd979ec [gl] Move error check support into a better place
This makes it a little easier to spam checks everywhere and thus narrow
down the location of the error.
2022-03-15 12:33:25 +09:00
Bill Currie 1d93bcfc34 [gl] Clean out some missed mirror code 2022-03-15 00:09:37 +09:00
Bill Currie fd805886f7 [renderer] Get fisheye working again
Only for gl and sw at the moment (want to merge things further before I
do anything for glsl or vulkan). However, with with I've learned getting
gl and sw to work, glsl and vulkan will be trivial.
2022-03-14 23:51:30 +09:00
Bill Currie 7402fcfd0c [renderer] move r_worldentity and r_viewleaf into refdef
More cleanup of globals that seem to be quake specific.
2022-03-14 15:27:43 +09:00
Bill Currie 2641fe3241 [gl] Remove some dead code
R_RecursiveLightUpdate has been obsolete for a very long time, and
R_Mirror is just wrong (needs envmaps etc, wonder if it can be done in
the fixed function code using skyclip?)
2022-03-14 15:12:33 +09:00
Bill Currie 56c39c34ba [renderer] Remove namehack.h
Finally. I never liked it (felt bad adding it in the first place), and
it has caused confusion with function and global variable names, but it
did let me get the render plugins working.
2022-03-14 14:31:23 +09:00
Bill Currie 04ba724382 [sw] Clean up alias and iqm matrix setup
This removes some FIXMEs and might even speed things up ever so
slightly.
2022-03-14 11:56:10 +09:00
Bill Currie 16440bce2d [mathlib] Clean up AngleVectors comments a little
They're still slightly confusing, but the situation itself is confusing,
but the comments should be a little more helpful now as they are more
explicit about the orientation of the matrices and just which axis
points where.
2022-03-14 11:51:50 +09:00
Bill Currie bce7d5b832 [renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.

Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 09:45:27 +09:00
Bill Currie f3768e3dfb [renderer] Remove currententity
One more global in the trash :)
2022-03-11 16:39:08 +09:00
Bill Currie 64666cfa5b [renderer] Clean up most uses of currententity
Just some brush model related code in the software renderer remaining.
2022-03-11 15:07:38 +09:00
Bill Currie 3bdec49587 [sw] Remove r_origin entirely
And clean up a lot of modelorg (a little trickier than it was for gl due
to messy usage).
2022-03-11 13:10:20 +09:00
Bill Currie 2606564955 [sw] Remove some dead code 2022-03-10 11:37:19 +09:00
Bill Currie 0cfff27cd0 [sw] Move surf and edge stats printing to begin_frame
Part of cleaning up SetupFrame
2022-03-09 22:53:15 +09:00
Bill Currie 3414eb12a3 [renderer] Move r_ambient and r_drawflat to client code
It makes more sense for these cvars to be under client control via
r_refdef. Completely disabled in qw, and currently ignored in nq.
2022-03-09 22:51:21 +09:00
Bill Currie 5477352e93 [renderer] Abandon sw32 altogether
I'd been considering it for a while, but in the end, all the issues it
presented made me decide it wasn't worth merging and was never really
worth keeping: it was a neat proof of concept but of little actual use,
especially now everyone either has an OK GPU or would want to stick to
8-bit rendering anyway (sorry L-Havoc).

However, both it and my merge work are preserved in git history :)
2022-03-09 21:36:15 +09:00
Bill Currie 19348f678f [win] Get the software renderer hobbling
16 and 32 bit rendering are disabled at the moment because there's a
weird segfault I need to fix, but the 8-bit dynamic lights are doing
weird things (for x11, too) when updating the light maps.
2022-03-09 20:00:59 +09:00
Bill Currie dce1a4d292 [util] Force 32-bit windows malloc to be 16-byte aligned
By replacing it :P (and its friends). This gets the non-sw renderers
working with recent scene changes.
2022-03-09 20:00:51 +09:00
Bill Currie 747494c03a [sw] Fix 16 and 32 bit alias model rendering
Intel asm needs testing still, but C is working nicely.
2022-03-09 16:56:36 +09:00
Bill Currie 6377734e32 [renderer] Merge the two software renderers
I got tired of having to maintain two separate software renderers, but
didn't want to just nuke sw32, so its core changes are merged into sw.

Alias model rendering is broken, but I know exactly what's wrong and how
to fix it, just need to take care due to asm.
2022-03-09 15:56:19 +09:00
Bill Currie 5c8f3ec3ac [renderer] Fix some non-static linking issues
Well, hopefully I'll get the root cause sorted eventually. I really hate
globals.
2022-03-09 06:55:31 +09:00
Bill Currie 1fef0e50e0 [particles] Use read data instead of written data
I'm not sure this makes any difference (at 2500fps, the noise is crazy),
but fewer instructions can't hurt.
2022-03-09 06:47:43 +09:00
Bill Currie a9cc51b22c [particles] Use correct index for source ramp
This fixes both the weird colors and a segfault in the 32-bit software
renderer.
2022-03-08 20:16:18 +09:00
Bill Currie 20536d83eb [vulkan] Clean up r_origin and modelorg
Same deal as for GL and GLSL.
2022-03-08 18:41:09 +09:00
Bill Currie 075a0fe326 [renderer] Clean up r_origin and modelorg
So far, in gl and glsl, but viewposition is much clearer than r_origin
(despite being the same thing), and modelorg is just confusing (I think
it's the view position relative to the current model).
2022-03-08 03:47:36 +09:00
Bill Currie 48c225da89 [renderer] Merge the fog support code
GL still has its own functions for enabling and disabling fog while
rendering, but GLSL doesn't need such (thanks to the shaders), nor will
vulkan (and the software renderers don't support fog).
2022-03-08 02:28:19 +09:00
Bill Currie af0c66dff9 [renderer] Move frame rendering out a layer.
This is a step towards high-level unification of the renderers, as far
as possible keeping only actual low-level implementation details in the
individual renderers (some higher level stuff, eg shadows, is expected
to be per-renderer as some things are just not feasible to implement in
all renderers). However, the idea is to move the high-level
functionality into scene rendering.
2022-03-08 01:04:40 +09:00
Bill Currie e1d38a9373 [renderer] Force-link r_efrag.o for static qwaq
As qwaq doesn't yet do any 3d rendering, it doesn't use efrags and thus
wasn't pulling in the object file, but the various renderers were trying
to access it. And I thought plugin builds were more difficult (I had
forgotten).
2022-03-07 16:59:01 +09:00
Bill Currie ea223f6312 [sw] Clean up use of r_rectdesc
I have no idea why the struct even had a local vrect that was used for
temporary storage.
2022-03-07 16:57:22 +09:00
Bill Currie ea2fd32228 [renderer] Merge screenshot code as much as possible
Only CaptureBGR is per-renderer as the rest of the screenshot code uses
it to do the actual capture (which is target dependent). Vulkan is
currently broken due to capture being an asynchronous process and the
rest of the code expecting capture to be synchronous (also, bgr vs rgb).

The best thing is all renderers now write the same format (currently
png).
2022-03-07 15:04:54 +09:00
Bill Currie 2eae2e5d74 [renderer] Move some functions from plugins to main lib
One step in cleaning up vid_render_funcs.
2022-03-07 13:40:04 +09:00
Bill Currie 2a87983bf4 [sw] Remove some unnecessary casting
I'm not sure what the author of that code was thinking (maybe trying to
do 4 pixels at a time?), but the resulting code still did only one.
Better to remove all the casts, use the right pointer type, and keep the
code clear.
2022-03-07 08:47:54 +09:00
Bill Currie 5eb397dd31 [renderer] Remove more dead code
The back-buffer and video buffer locking code was pretty much never more
than stubs (except maybe in dos quake).
2022-03-07 08:44:53 +09:00
Bill Currie 04fd9baff5 [glsl] Reorder some code for consistency 2022-03-07 08:43:23 +09:00
Bill Currie 9514ad1ae4 [gl] Draw sky chains before brush entities
Drawing sky chains first ensures that sky surfaces correctly block parts
of the map that should not be visible (by writing the correct depth to
the depth buffer when doing box or dome skies). Writing brush models
first means that the models (ammo boxes etc) could be visible when they
should not be.
2022-03-07 08:40:39 +09:00
Bill Currie 71c1b4e0c4 [gl] Clean up some triple buffer and multi-texture cvar mess
Excess declarations for gl_multitexture_f, and move gl_triplebuffer into
a callback.
2022-03-07 08:38:38 +09:00
Bill Currie 1ea3a3807e [renderer] Clean up a pile of dead screen declarations
The declarations were either unused, or the functions empty stubs for
all renderers.
2022-03-06 13:47:41 +09:00
Bill Currie 45c3c6d7be [screen] Clean up some dead declarations 2022-03-05 14:35:56 +09:00
Bill Currie 73444c3b7a [ruamoko] Give the scene resource block a rua prefix
No effect on the code itself, but it makes debugging much easier when
there aren't two very different structs with the same name.
2022-03-05 02:05:59 +09:00
Bill Currie d69355f521 [renderer] Support multiple entity queues
While there's currently only the one still, this will allow the entities
to be multiply queued for multi-pass rendering (eg, shadows). As the
avoidance of putting an entity in the same queue more than once relies
on the entity id, all entities now come from the scene (which is stored
in cl_world in the client code for nq and qw), thus the extensive
changes in the clients.
2022-03-05 02:05:39 +09:00
Bill Currie 6ec8e29429 [scene] Track hierarchies instead of root transforms
The root transform of each hierarchy can be extracted from the first
transform of the list in the hierarchy, so no information is lost. The
main reason for the change is I discovered (obvious in hindsight) that
deleting root transforms was O(n) due to keeping them in an array, thus
the use of a linked list (I don't expect a hierarchy to be in more than
one such list), and I didn't want the transforms to be in a linked list.
2022-03-04 06:43:30 +09:00
Bill Currie 7906db5a37 [client] Set camera rotation for chase mode 1
With the change in cl_view separating chase cam updates from
first-person updates, the auto-rotation of the camera was lost.
2022-03-02 19:13:58 +09:00
Bill Currie f296cb897e [renderer] Make draw order a little more consistent
GL and GLSL were drawing the view model after particles instead of
before. For GL, this is likely due to avoiding fog affecting the view
model (which I think is not the right thing to do), and GLSL due to
copying GL (because I had no idea at the time). This makes the two
renderers consistent with the software renderers, and might even speed
things up a little as that's one less set of blends to do when the
particles are covered by the view model (I don't expect much
difference).
2022-03-02 16:29:40 +09:00
Bill Currie ae6970a005 [renderer] Split entity queue into per-model-type
While I doubt the difference is all that significant, this should speed
up entity rendering because it cuts out a lot of branching, and
eliminates scanning the same list multiple times only to not do anything
for large chunks of the list.
2022-03-02 15:00:32 +09:00
Bill Currie ab91d73635 [scene] Use scene resources for the main hierarchy block
This will reduce the memory churn when creating hierarchies as
transforms switch between being root and child.
2022-03-02 10:49:41 +09:00
Bill Currie b210f01837 [scene] Manage scene roots in transform
Since transforms now know the scene to which they belong, and they know
when they are root and when not, getting the transform code to manage
the scene roots is the best way to keep the list of root transforms
consistent.
2022-03-02 10:43:52 +09:00
Bill Currie 54c3b4cc53 [client] Get the chase camera working with input
It turns out cam_controls is for pointing the player model in the
direction of movement rather than controlling the camera (I should add
proper camera controls).
2022-03-01 16:07:04 +09:00
Bill Currie ee3c9fa59f [client] Sort out the chase mode input FIXME
It's messing with player motion (so not working properly), but at least
now it compiles, I can get it working.
2022-03-01 15:31:00 +09:00
Bill Currie 8407e3acd1 [client] Make input axes accessible and add camera axes
And clean up the names (viewdelta_position_forward -> in_move_forward).
2022-03-01 15:15:33 +09:00
Bill Currie 7c07118541 [mathlib] Clean up AngleVectors comment
I finally spent the time to work out what it was trying to say. Still
not sure it's clear, but what is clear is that there was probably some
disagreement at Id about the orientation of the world.
2022-03-01 14:52:45 +09:00
Bill Currie 1859ff233d [client] Fix the chase cameras
They no longer spin like crazy. I don't know how, but I must have broken
something over the years as I'm sure Seth had the code working (and I
seem to remember seeing it working). In the process, clean up a lot of
the angle mess.
2022-03-01 14:44:53 +09:00
Bill Currie 5b08ee768c [client] Clean up chase camera code
It's a lot easier to read (and see the difference between modes 2 and 3)
with all the ifs removed, and the state is properly is chasestate_t now
(though not handled properly on level reset etc).
2022-03-01 13:49:14 +09:00
Bill Currie 43a329dcb5 [client] Get the basic chase camera working
The more advanced modes are rather broken (continuous spinning), but
they may have been for a while. The bulk of the various changes were due
to renaming viewstate's origin and angles to make their meaning more
explicit.
2022-03-01 11:43:23 +09:00
Bill Currie fb83d87a0e Fix some distcheck issues
Just keeping up with myself.
2022-03-01 10:12:50 +09:00
Bill Currie 457c73967b [sound] Correct "default" listener origin
Position vectors need to be homogeneous, I forgot that when doing the
change.
2022-03-01 01:02:11 +09:00
Bill Currie 57dd4494cc [renderer] Pass in a camera transform
More r_data cleanup. Things could be better still, but this is a start.
2022-02-28 16:59:38 +09:00
Bill Currie ca9e8a3b68 [client] Pass time into locs_draw
This avoids unnecessary access to r_data.
2022-02-28 16:57:43 +09:00
Bill Currie 2477a44d15 [client] Move cshift info from viddef to viewstate
It makes much more sense for cshift state to be in viewstate because it
is very much an effect rather than anything specific to a renderer.
2022-02-28 16:55:12 +09:00
Bill Currie 7d059a0b56 [client] Merge nq and qw cl_view
They've been near-identical for years, now they're only one. It proved
necessary to start merging the HUD code which for now is just a few cvar
declarations (not even init), but that should be a separate set of
commits.
2022-02-28 12:12:51 +09:00
Bill Currie aac9069d9f [nq,qw] Clean up cl_view's use of the client struct
This is a huge step towards merging cl_view.
2022-02-25 16:54:45 +09:00
Bill Currie e920abe142 [glsl] Adjust view/projection matrices for consistency
The actual view and projection matrices are now consistent with vulkan,
with the vulkan-gl disparity moved into adjustment matrices. The goal is
to allow the same camera data and code to be used in all renderers. The
extra matrix multiplication shouldn't be too expensive as it occurs only
when the field of view (not often, under user control) or near and far
clip distances (very rarely) change.
2022-02-25 10:50:53 +09:00
Bill Currie 5ad7c0fbd6 [scene] Add a camera object
It holds the data for a basic 3d camera (transform, fov, near and far
clip). Not used yet as there is much work to be done in cleaning up the
client code.
2022-02-25 10:41:50 +09:00
Bill Currie deff95f490 [client] Merge chase camera and much of input
Handling of view angles is a little hacky at the moment, but this gets
the chase camera code and most of the common input code into one place,
which will make cleaning up the camera code much easier.
2022-02-22 15:51:28 +09:00
Bill Currie 2615953e17 [scene] Move transform getters into inline functions 2022-02-21 08:33:41 +09:00
Bill Currie e67ec84db9 [vulkan] Use simpler projection and z_up matrices
While both matrices had positive determinants in the first place, I find
the projection matrix easier to understand without all the negatives,
and having quake-x/vulkan-z positively parallel in the z-up matrix makes
that a lot easier to think about.
2022-02-18 14:25:50 +09:00
Bill Currie cd26073b6a [vulkan] Update the sky matrix
Regardless of whether the sky is spinning or not, the matrix needs to be
updated with the current origin in order to get the direction vector
right in the shader. Also, it's in the update that the required x-y
plane rotation gets in so the skies move in the correct direction.
2022-02-18 13:29:41 +09:00
Bill Currie 981fcca76d [sw,sw32] Fix broken software skies
All for an unfortunate unsigned promotion. I guess I just wasn't testing
the software renderers enough.
2022-02-18 12:54:54 +09:00
Bill Currie d75726dd22 [vulkan] Bind the correct texture for sky boxes
That took way too long to find: just couldn't see it for looking.
2022-02-18 01:17:25 +09:00
Bill Currie 2d2f14cd31 [vulkan] Fix incorrect bsp sky constant ids
I guess I got things a little tangled when cleaning up my bindless
attempt.
Fixes black default skies.
2022-02-18 01:15:38 +09:00
Bill Currie 54f0af854b [ruamoko] Wrap the transform fuctions
Except for get/set name as I'm still pondering strings.
2022-02-15 00:06:39 +09:00
Bill Currie ba3879c6e0 [scene] Make transforms owned by the scene
This actually has at least two benefits: the transform id is managed by
the scene and thus does not need separate management by the Ruamoko
wrapper functions, and better memory handling of the transform objects.
Another benefit that isn't realized yet is that this is a step towards
breaking the renderers free of quake and quakeworld: although the
clients don't actually use the scene yet, it will be a good place to
store the rendering information (functions to run, etc).
2022-02-14 20:01:36 +09:00
Bill Currie f0c35e541a [ruamoko] Pass some more purity tests
Separate because I want to cherry-pick the other commit.
2022-02-14 19:56:56 +09:00
Bill Currie e58d53d4b6 [gamecode] Pass gcc's purity test again
I guess maybe that change might make a bigger difference than I thought,
gcc wasn't happy with it.
2022-02-14 19:30:50 +09:00
Bill Currie 59044d3827 Fix a bunch of distcheck issues 2022-02-14 19:28:19 +09:00
Bill Currie afbca54faf [ruamoko] Add wrappers for the existing scene functions
I've run into a bit of an issue with transform management (really, just
need to make them owned by the scene, but that means creating a scene
for quake and quakeworld).
2022-02-14 16:43:10 +09:00
Bill Currie f6ac614e09 [scene] Add functions for scene and entity create/delete
Scene creation was already there, but now can be deleted, as can
entities.
2022-02-14 16:41:38 +09:00
Bill Currie 4d491a444d [gamecode] Fix handling of undefined builtins
The setup of the function descriptor for undefined builtins was
incomplete and led to the progs running code at address 0. It didn't end
well.
2022-02-14 14:28:19 +09:00
Bill Currie db8cf68ef3 [gamecode] Pass registered data pointer to builtins
This is the bulk of the work for recording the resource pointer with
with builtin data. I don't know how much of a difference it makes for
most things, but it's probably pretty big for qwaq-curses due to the
very high number of calls to the curses builtins.

Closes #26
2022-02-14 12:28:38 +09:00
Bill Currie 944a9253e9 [gamecode] Support %u format in PR_Sprintf
Not sure why it was missed as it would have been useful even before
unsigned was properly supported by qfcc.
2022-02-12 01:58:38 +09:00
Bill Currie fc8cc0b703 [zone] Be more informative when catching memory errors
The registered error handler is given a chance to report the error, and
the corrupted id is printed.
2022-02-12 01:57:03 +09:00
Bill Currie 1d26c727a3 [ruamoko] Allocate selectors in large blocks
The zone memory block header is 64 bytes, so allocating a single 8 byte
selector is rather wasteful. Instead, allocate selectors in large chunks
(currently 64) and divvy them out as needed. Significantly reduces
memory pressure in large Ruamoko progs.
2022-02-12 01:52:35 +09:00
Bill Currie eba614336d [gamecode] Add single-component float bitop instructions
These add legacy support for basic float bitops (& | ^ ~). Avoiding the
instructions would require tot only the source to be converted, but also
the servers (as they do access those fields), and this seemed to be too
much.
2022-02-06 21:20:00 +09:00
Bill Currie 7c6ef06dfb [gamecode] Make PF_VarString v6p-only
It's not enforced a this stage, and it would be easy enough to handle,
but it turns out all the standard quake and quakeworld progs never used
... for the print functions: the behavior of PF_VarString was
undocumented and so... tough :P.
2022-02-06 21:20:00 +09:00
Bill Currie 95c4cdd1b0 [vulkan] Set frame buffer before calling draw functions
This lets them set up their subpass inherit info correctly. QF now
renders correctly, albeit painfully slowly, on my VersaPro.
2022-02-06 13:12:16 +09:00
Bill Currie e1ecda9221 [gamecode] Add unsigned divide and remainder instructions
I had forgotten that unsigned division was different from signed
division (rather silly of me). However, with some testing and analysis,
unsigned true modulo is not needed as it's not possible to have
negative inputs and thus it's the same as remainder.
2022-02-06 12:20:17 +09:00
Bill Currie c10b09d41b [ruamoko] Make RUA_Sprintf more generally useful
It now takes the function name to print in error message (passed on to
PR_Sprintf) and the argument number of the format string. The variable
arguments (in ...) are assumed to be immediately after the format
argument.
2022-02-05 20:24:17 +09:00
Bill Currie 078f36a871 [gamecode] Add "return pointer" mode to with instruction
This loads the current return pointer into the specified register. No
offset is used (should make that an error, but for now any offset is
simply ignored). This is part of the fix for getting obj_msg_sendv to
work with return values.
2022-02-05 18:42:54 +09:00
Bill Currie 208cba85eb [gamecode] Move return buffer to end of progs memory map
With the return buffer in progs_t, it could not be addressed by the
progs on 64-bit machines (this was intentional, actually), but in order
to get obj_msg_sendv working properly, I needed a way to "bounce" the
return address of a calling function to the called function. The
cleanest solution I could think of was to add a mode to the with
instruction allowing the return pointer to be loaded into a register and
then calling the function with a 0 offset for the return value but using
the relevant register (next few commits). Testing promptly segfaulted
due to the 64-bit offset not fitting into a 32-bit value.
2022-02-05 18:37:23 +09:00
Bill Currie b0810958e7 [ruamoko] Use encoded selector param count when forwarding
This gets message forwarding apparently working, though something isn't
quite right as qwaq-app doesn't update properly when I try to step
through the program, but that could be an error elsewhere.
2022-02-05 14:24:12 +09:00
Bill Currie 9cf2740cb4 [gamecode] Create a globally accessible hash of type encodings
The plan is to use the types to extract the number of parameters for a
selector when it is necessary to know the count. However, it'll probably
become useful for something else alter (these things seem to always do
so).
2022-02-05 14:07:45 +09:00
Bill Currie 2c0969f988 [ruamoko] Rework method call hand-off to preserve the stack
This takes care of the problems with PR_RESET_PARAMS (which has recently
become just a wrapper for PR_SetupParams) changing the stack and causing
PR_CallFunction to save the wrong stack pointer. Message forwarding is
currently broken for Ruamoko ISA progs, but that is due to not having a
valid pr_argc. However, I do have a plan involving extracting the
parameter count from the selector, but that's something for a later
commit. Everything else seems to be ok (my little game is working
nicely).
2022-02-05 13:01:44 +09:00
Bill Currie 01345ba675 [gamecode] Wrap most uses of PR_RESET_PARAMS with push/pop frame
rua_obj was skipped because that looks to be a bit more work and should
be a separate commit.

This is to avoid the stack getting mangled when calling progs functions
with parameters.
2022-02-05 10:26:47 +09:00
Bill Currie 2fc35b39b0 [ruamoko] Use a shared implementation for set functions
I suppose having one builtin call another was a neat idea at the time,
and really could have been fixed by simply wrapping the calls with
push/pop frame, but this is probably faster.
2022-02-04 22:19:05 +09:00
Bill Currie 5f684b2f81 [ruamoko] Rework PF_VarString to work with Ruamoko progs
It's a rather core function used by the game code, though it is rather
horrid.
2022-02-04 22:15:24 +09:00
Bill Currie cdc3c9822d [ruamoko] Preserve the stack in obj_msg_sendv
obj_msg_sendv needs to push the parameters onto the stack for Ruamoko
progs, but this causes problems because PR_CallFunction winds up
recording the wrong stack pointer for progs functions, and nothing
restores the stack for builtins. The handling is basically the same as
for the return pointer.
2022-02-04 22:09:38 +09:00
Bill Currie 2a8fca80a0 [nq,qw] Give the menu and server progs stacks
They're going to need them :P
2022-02-04 21:53:37 +09:00
Bill Currie 7731c469e2 [gamecode] Count calls to builtins in profile
It's a bit disconcerting seeing a builtin in the top 10 when builtins
are counted by call while progs functions are counted by instruction.

Also, show the total profile after the function top-10 list.
2022-02-04 21:49:59 +09:00
Bill Currie b425f449b6 [ruamoko] Separate the two str_mid builtins
pr_argc cannot be used in Ruamoko progs because nothing sets it. This
fixes the parse errors and resulting segfault when trying to parse the
Vulkan pipeline config.
2022-02-04 11:38:36 +09:00
Bill Currie 0211b6ec5b [gamecode] Add 64-bit load/store instructions
Only widths 3 and 4 have been added because widths 1 and 2 can be
implemented by widths 2 and 4 of the 32-bit load/store instructions.
2022-02-02 14:47:36 +09:00
Bill Currie 6514e09e7c [gamecode] Use an explicit size for the null page
It's currently only 4 (or even 3 for v6) words, but this fixes false
positives when checking for null pointers in Ruamoko progs due to
pr_return pointing to the return buffer and thus outside the progs
memory map resulting in an impossible to exceed value.
2022-02-01 16:43:29 +09:00
Bill Currie 2fcec6e5cb [zone] Move heap check to Z_TagMalloc
Since Z_Malloc uses Z_TagMalloc to do the work, this ensures the check
is always run.

Also, add the check to Z_Realloc when it needs to adjust an existing
block.
2022-02-01 14:56:47 +09:00
Bill Currie b8c2b7f856 [ruamoko] Make a common sprintf wrapper function
This takes care of converting from progs varargs to what PR_Sprintf
expects. I got tired of modifying the wrappers when I found a third one.
2022-02-01 09:27:03 +09:00
Bill Currie 5d41e90cc7 [gamecode] Remove pushregs and popregs specs
They have been redundant since the operations were moved into with.
2022-01-31 23:47:47 +09:00
Bill Currie e7ac637687 [ruamoko] Wrap hash table callbacks with push/pop frame
Builtins that call progs with parameters now must always wrap the call
to PR_ExecuteProgram so that the data stack is properly preserved across
the call.

I need to do an audit of all the calls to PR_ExecuteProgram.
2022-01-31 23:47:02 +09:00
Bill Currie 712d800491 [gamecode] Save return ptr for chained calls
It turns out the return pointer still needs to be saved even when a
builtin sets up a chain call to progs, but rather than the pointer being
simply restored, it needs to be saved in the call stack exactly as if
the function was called directly by progs. This fixes the invalid self
issue quite thoroughly: parameter state seems to be correct across all
calls now.

I should set up an automated test now that I know and understand the
situation.
2022-01-31 23:35:56 +09:00
Bill Currie 92711e778c [ruamoko] Set params in obj_msgSend_super only for v6p progs
In Ruamoko ISA progs, the param pointers point to the stack and
generally must most be manipulated by builtins, and there is no need
anyway as Ruamoko doesn't have RCALL. Fixes the mangling of .super.
2022-01-31 19:04:18 +09:00
Bill Currie cabb53e693 [gamecode] Skip return ptr restore if depth changed
When calling a builtin, normally the return pointer needs to be
restored, but if the builtin changes the call depth (usually by
effecting "return foo()" as in support for objects, but possibly
setjmp/longjmp when they are implemented), then the return pointer must
not be restored. This gets vkgen past object allocation, but it dies
when trying to send messages to super. This appears to be a compiler
bug.
2022-01-31 16:51:46 +09:00
Bill Currie c5ae1ae13c [ruamoko] Check self is within progs memory
Changes a segfault to a runtime error, which beats the risk of self
pointing somewhere that doesn't segrault.
2022-01-31 14:03:36 +09:00
Bill Currie 8dc4a0ea80 [qfcc] Change v6p's jumpb opname to jump
More ease of searching, since the operand types help greatly.
2022-01-30 22:39:21 +09:00
Bill Currie 7971bcd91c [gamecode] Sort out shr's opname for easier searching
Since the operand types sort out the difference between asr and shr, no
need to give them different opnames. Means qfcc doesn't need to worry
about which one it's searching for.
2022-01-30 22:37:03 +09:00
Bill Currie 766bf758ab [gamecode] Redesign jump's B addressing
Yet another redundant addressing mode (since ptr + 0 can be used), so
replace it with a variable-indexed array (same as in v6p). Was forced
into noticing the problem when trying to compile Machine.r.
2022-01-30 22:34:40 +09:00
Bill Currie 4871717fae [gamecode] Rename v6 vector-scalar multiply to scale
Makes it easier to get Ruamoko scaling implemented if they both use the
same opname.
2022-01-30 14:47:26 +09:00
Bill Currie 46ce37160b [gamecode] Correct vecops widths
I had forgotten to update the widths when I moved cross product's
position.
2022-01-30 14:11:41 +09:00
Bill Currie 728c42e921 [gamecode] Use pr_type_names for debug views
I abandoned the reason for doing it (adding a pile of vector types), but
I liked the cleanup. All the implementations are hand-written still, but
at least the boilerplate stuff is automated.
2022-01-30 10:49:33 +09:00
Bill Currie 49395b3ba1 [gamecode] Correct state's types for double time
It takes int for the frame rather than float.
2022-01-29 18:48:05 +09:00
Bill Currie 7e9cf76cfe [qfcc] Change ne to cmp for v6 string inequality check
Since it's really strcmp in disguise (makes the instruction consistent
across all targets).
2022-01-29 18:18:33 +09:00
Bill Currie 10843fe340 [gamecode] Correct memset opname and types 2022-01-29 17:05:10 +09:00
Bill Currie 5c22253095 [gamecode] Use the stack frame to find local defs
Of course, only in Ruamoko progs, but it works quite nicely.
global_string is now passed the absolute address of the referenced
operand. With a little groveling through the progs stack, it should be
possible to resolve pointers to locals in functions further up the
stack.
2022-01-27 14:20:09 +09:00
Bill Currie de974fdd3f [gamecode] Add format for addressing modes and use in return
This fixes Ruamoko's return format string. It looks like it's producing
the correct address (but doesn't show all the information it should),
but the rest of the debug code needs work locals.
2022-01-27 13:29:38 +09:00
Bill Currie 42db8514ae [gamecode] Use version instead of locals count
It turned out I need locals count and params_start for debugging, so use
the progs version instead to bail early from PR_EnterFunction and
PR_LeaveFunction (which I had forgotten anyway, oops).
2022-01-27 11:24:00 +09:00
Bill Currie a0d9cf8d8e [gamecode] Improve verbose statement prints for Ruamoko
They now include base register index and effective address of the
operands (though it may be wrong for instructions that don't use a base
register for that operand).
2022-01-27 10:57:31 +09:00
Bill Currie 59ee723201 [gamecode] Rename parm to param
That misspelling bothered me from the very beginning, I'd always have
trouble getting the name right when trying to access one of those fields.
2022-01-27 10:55:06 +09:00
Bill Currie e9dff4ff9c [gamecode] Correct types and widths for bitnot
bitnot is the only unary operator in the bitops group and thus needs
special handling.
2022-01-27 10:21:48 +09:00
Bill Currie faa98d8198 [gamecode] Use a struct for offset/count pairs
This cleans up dprograms_t, making it easier to read and see what chunks
are in it (I was surprised to see only 6, the explicit pairs made it
seem to have more).
2022-01-26 19:30:25 +09:00
Bill Currie a2f4522e76 [gamecode] Align Ruamoko progs to 32 bytes.
Intel hardware requires 32-byte alignment for lvec4 and dvec4.
Unfortunately, it turns out that my attempts to align progs data in qfcc
went awry do to the order block sizes are calculated when writing the
progs.
2022-01-26 16:55:14 +09:00
Bill Currie ee4eecc741 [gamecode] Correct types and opname for memset and move 2022-01-26 12:26:12 +09:00
Bill Currie 6bc6db471d [gamecode] Make return use same addressing as other ops
This makes return consistent with load, store, etc, though its
addressing mode is encoded in bits 5 and 6 of c rather than the opcode.
It turns out I had no tests for any of return's addressing modes other
than basic def references, so no tests needed changing.
2022-01-26 09:51:11 +09:00
Bill Currie 37f08f9d4f [qfcc] Build the Ruamoko function parameters
The parameter defs are allocated from the parameter space using a
minimum alignment of 4, and varargs functions get a va_list struct in
place of the ...

An "args" expression is unconditionally injected into the call arguments
list at the place where ... is in the list, with arguments passed
through ... coming after the ...

Arguments get through to functions now, but there's problems with taking
the address of local variables: currently done using constant pointer
defs, which can't work for the base register addressing used in Ruamoko
progs.

With the update to test-bi's printf (and a hack to qfcc for lea),
triangle.r actually works, printing the expected results (but -1 instead
of 1 for equality, though that too is actually expected). qfcc will take
a bit longer because it seems there are some design issues in address
expressions (ambiguity, and a few other things) that have pretty much
always been there.
2022-01-24 23:44:48 +09:00
Bill Currie b663fecd4e [gamecode] Use PR_SetupParameters for rua called builtins
It's a bit heavy-handed as it sets all the param pointers, but simple
(no varargs) functions are working nicely in Ruamoko.
2022-01-24 16:46:49 +09:00
Bill Currie 00b7bced7f [gamecode] Rework PR_RESET_PARAMS to use PR_SetupParams
PR_SetupParams is new and sets up the parameter pointers so older code
that expects only up to 8 parameter will work with both v6p and Ruamoko
progs without having to check what progs are running. PR_SetupParams is
useful even when Ruamoko progs are expected as it reserves the required
space (respecting alignment) on the stack and returns a pointer to the
top (bottom? confusing) of the stack. PR_PushFrame and PR_PopFrame
need to be used around PR_SetupParams, regardless of using temp strings,
to avoid a stack leak (need to do an audit).
2022-01-24 12:50:15 +09:00
Bill Currie 9c51c3d2e1 [gamecode] Add a data pointer passed to builtin functions
This is part of the work for #26 (Record resource pointer with builtin
function data). Currently, the data pointer gets as far as the
per-instance VM function table (I don't feel like tackling the job of
converting all the builtin functions tonight). All the builtin modules
that register a resources data block pass that block on to
PR_RegisterBuiltins.
2022-01-24 00:20:05 +09:00
Bill Currie a818fa4b8e [gamecode] Rearrange bfunction_t in preparation for param offsets
The builtin and progs function data is overlaid so the extra data
doesn't cause too much memory to be used (it's actually 8 bytes smaller
now).  The plan is to pre-compute the offsets based on the parameter
size and alignment data.
2022-01-24 00:19:13 +09:00
Bill Currie a6b932025c [gamecode] Provide builtins with information about their parameters
This will make it possible for the engine to set up their parameter
pointers when running Ruamoko progs. At this stage, it doesn't matter
*too* much, except for varargs functions, because no builtin yet takes
anything larger than a float quaternion, but it will be critical when
double or long vec3 and vec4 values are passed.
2022-01-23 22:27:27 +09:00
Bill Currie e746e39738 [gamecode] Create macros for progs sizeof and alignof
I wound up needing the idioms in too many places.
2022-01-23 14:29:33 +09:00
Bill Currie 3c86660d4a [gamecode] Rename MAX_PARMS to PR_MAXPARAMS 2022-01-23 14:17:25 +09:00
Bill Currie cfaf158ebc [math] Add some bit-op functions
Just 32-bit rounding to next higher power of two, and base 2 logarithm.
Most importantly, they are suitable for use in initializers as they are
constant in, constant out.
2022-01-23 13:47:14 +09:00
Bill Currie 861e98725c [gamecode] Return early if the entered function has no locals
As even the simplest v6p functions that take parameters but have no
local or temporary variables still have locals for the local copy of the
parameters, this is a both a good check for for the Ruamoko ISA as its
functions never have locals (everything's on the progs data stack), and
an optimization for v6p functions that have no params or locals (simple
getters (very rare?), most .ctor, etc).
2022-01-22 21:41:35 +09:00
Bill Currie 06b1ea6837 [gamecode] Tweak some docs and macro names
And fix an incorrect definition for RETURN_QUAT.

Prefixed MAX_STACK_DEPTH and LOCALSTACK_SIZE (and LOCALSTACK_SIZE got an
extra _).

The rest is just edits to documentation comments.
2022-01-22 11:38:14 +09:00
Bill Currie 7a5ee6a55a [gamecode] Initialize .stack if it's available
And implement bounds checks for adjstk.
2022-01-21 20:33:15 +09:00
Bill Currie 9199a0ee54 [gamecode] Don't check v6p progs for Ruamoko progs
It doesn't end well. For now, the Ruamoko check is just a stub, but I do
plan on doing similar checks.
2022-01-21 20:31:49 +09:00
Bill Currie 3df46d197f [gamecode] Add instructions for stack adjust, nop, and ldconst
ldconst isn't implemented yet but the plan is to load various constants
(eg, 0, 1, 2, pi, e, ...).

Stack adjust is useful for adding an offset to the stack pointer without
having to worry about finding it (and it checks for alignment).

nop is just that :)
2022-01-21 20:00:38 +09:00
Bill Currie c53127707b [qfcc] Set the return of Ruamoko calls
Of course, I had the width of opc wrong :P. But with this, it seems that
unoptimized calls should work once I get the stack frame working.
2022-01-21 13:50:21 +09:00
Bill Currie 16a203c643 [gamecode] Partially implement conversion code debug
The code is simply printed in octal for now, but it's better than
breaking the rest of the format string.
2022-01-21 10:12:50 +09:00
Bill Currie 578314c5a3 [gamecode] Use a buffer for discarded return values
Due to how OP_RETURN works, a destination is required for any function
returning data, but the caller may not have allocated any space for the
value. Thus the VM maintains a buffer into which the data can be put and
ignored. It also makes a good place for return values when the engine
calls Ruamoko code as trusting progs code with return sizes seems like a
recipe for disaster, especially if the return location is on the C
stack.
2022-01-21 10:09:02 +09:00
Bill Currie 4b87d24737 [gamecode] Correct call's operator types 2022-01-21 10:07:35 +09:00
Bill Currie 5f66bfe887 [gamecode] Update printed opcode width
Opcodes now need 3 hex digits (hexits?) to print.
2022-01-20 18:37:28 +09:00
Bill Currie c39558efaa [gamecode] Audit the widths of rest of the instructions
I can't test them properly until I get qfcc up and running with basic
ruamoko code, but they are at least more correct than they were.
2022-01-20 17:27:56 +09:00
Bill Currie 854e45485a [gamecode] Correct the widths for load, store and lea
The different addressing modes complicate the width calculations, and
lea is particularly fun in that it doesn't care what the width of value
is.
2022-01-20 16:33:04 +09:00
Bill Currie e20aed5c5a [gamecode] Change address mode B to entity.field
It turned out that address mode B was redundant as C with 0 offset
(immediate) was the same (except for the underlying C code of course,
but adding st->b is very cheap). This allowed B to be used for
entity.field for all transfer operations. Thus instructions 0-3 are now
free as load E became load B, and other than the specifics of format
codes for statement printing, transfers+lea are unified.
2022-01-20 14:55:29 +09:00
Bill Currie 6ae9daf4b7 [gamecode] Clean out dead any/all/none data
The instructions are gone as hor/hand/hnor take care of them.
2022-01-20 14:52:59 +09:00
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