Commit Graph

2226 Commits

Author SHA1 Message Date
Bill Currie 437e447b6b [renderer] Add a buffer print function
It handles basic cursor motion respecting \r \n \f and \t (might be a
problem for id chars), wraps at the right edge, and automatically
scrolls when the cursor tries to pass the bottom of the screen.

Clearing the buffer resets its cursor to the upper left.
2022-09-16 00:58:25 +09:00
Bill Currie c5099d30b1 [renderer] Fix access to freed memory loading fonts
QFS_LoadFile closes its file argument (this is a design error resulting
from changing QFS_LoadFile to take a file instead of a path and not
completing the update), resulting in the call to Qfilesize accessing
freed memory.
2022-09-15 14:32:16 +09:00
Bill Currie 25a14eb232 [renderer] Add a cell-based character buffer
This is intended for the built-in 8x8 bitmap characters and quake's
"conchars", but could potentially be used for any simple (non-composed
characters) mono-spaced font. Currently, the buffers can be created,
destroyed, cleared, scrolled vertically in either direction, and
rendered to the screen in a single blast.

One of the reasons for creating the buffer is to make it so scaling can
be supported in the sw renderer.
2022-09-15 14:24:33 +09:00
Bill Currie c771bfa58c [renderer] Correct freetype and harfbuzz lib linking
renderer_libs was in both LIBADD and DEPENDENCIES, so make was trying to
build the freetype and harfbuzz libs when building for windows.
2022-09-13 17:38:58 +09:00
Bill Currie 99196550d1 [renderer] Move r_font.c to correct library
Fixes the linker error in the standard build.
2022-09-12 08:43:28 +09:00
Bill Currie 71efbba628 [vulkan] Switch draw_pic to take subpic_t instead of qpic_t
While this does pull the grovelling for the subpic out to the callers,
the real problem is the excessive use of qpic_t in the internal code:
qpic_t is really just the image format in wad files, and shouldn't be
used as a generic image handle.

Cleans up more of the icky code in the font drawing functions.
2022-09-09 20:05:31 +09:00
Bill Currie 936f6d91e4 [vulkan] Use vertex queue objects for Draw
This makes working with quads, implied alpha quads, and lines much
cleaner (and gets rid of the bulk of the "eww" fixme), and will probably
make it easier to support multiple scraps and fonts, and potentially
more flexible ordering between pipelines.
2022-09-09 17:06:33 +09:00
Bill Currie 935e883d8d [renderer] Switch to using HarfBuzz for glyph positioning
This means that QF should support more exotic fonts without any issue
(once the rest of the text handling system is up to snuff) as HarfBuzz
does all the hard work of handling OpenType, Graphite, etc text shaping,
including kerning (when enabled).

Also, font loading now loads all the glyphs into the atlas (preload is
gone).
2022-09-04 20:56:38 +09:00
Bill Currie db69f5fd23 [renderer] Use VRect_SubRect for scrap allocation
While the results are a little surprising (tends to alternate between
left side and top for allocations), there is much less wasted space in
the partially allocated regions, and the main free region seems to
always be quite big.
2022-09-02 19:08:58 +09:00
Bill Currie cd66dbfc97 [vulkan] Implement font rendering
It is currently an ugly hack for dealing with the separate quad queue,
and the pipeline handling code needs a lot of cleanup, but it works
quite well, though I do plan on moving to HarfBuzz for text shaping. One
nice development is I got updating of descriptor sets working (just need
to ensure the set is no longer in use by the command queue, which the
multiple frames in flight makes easy).
2022-09-02 14:23:19 +09:00
Bill Currie 73635d84bf [renderer] Add stubs for Draw_FontString
Draw_FontString is for font-based text rendering. Nothing is implemented
at this stage.
2022-09-02 11:38:09 +09:00
Bill Currie 599c09e77e [renderer] Add Draw_AddFont for registering a font
It's implemented only in the Vulkan renderer, partly because there's a
lot of experimenting going on with it, but the glyphs do get transferred
to the GPU (checked in render doc). No rendering is done yet: still
thinking about whether to do a quick-and-dirty test, or to add HarfBuzz
immediately, and the design surrounding that.
2022-08-31 19:23:30 +09:00
Bill Currie 096ecc7710 [vulkan] Fix incorrect image view format
R8G8B8A8 was hard-coded by accident when creating Vulkan_LoadTexArray
(or probably even the original Vulkan_LoadTex). This wasn't a problem
while everything was loaded in that format, but attempting to load an R8
texture didn't go so well. The same format as the image itself is used
now (correctly so).
2022-08-31 18:14:24 +09:00
Bill Currie 8c270a0a9e [vulkan] Switch to pre-multiplied alpha for 2d
I have recently learned that pre-multiplied alpha is the correct way to
do compositing, which is pretty much what the 2d pass does (actually,
all passes, but...). This required ensuring the color factor passed to
the fragment shader is pre-multiplied (a little silly for cshifts as
they used to be pre-multiplied but were un-pre-multiplied early in QF's
history and I don't feel like fixing that right now as it affects all
renderers), and also pre-multiplying alpha when converting from 8-bit
palette to rgba as the palette entry for transparent has that funky pink
(which is used in full-brights).
2022-08-30 14:29:22 +09:00
Bill Currie 4d5b38f0c9 [renderer] Star work on adding FreeType support
Right now, this just initializes the library and loads a font into
memory, preloading a given set of characters (specified by unicode
values).
2022-08-27 17:53:03 +09:00
Bill Currie d39f02ecfc [renderer] Don't round up scrap allocations
I will need to do more work to improve the 2d allocation, but rounding
up the requested sizes to the next power of two proved to be excessively
wasteful: I was able to allocate spots for only half of the sub-pics I
needed (though I did still need to double the number of pixels in the
end).
2022-08-27 17:46:14 +09:00
Bill Currie 630dde6df7 [render] Add basic 2d line drawing
The software renderer uses Bresenham's line slice algorithm as presented
by Michael Abrash in his Graphics Programming Black Book Special Edition
with the serial numbers filed off (as such, more just so *I* can read
the code easily), along with the Chen-Sutherland line clipping
algorithm. The other renderers were more or less trivial in comparison.
2022-08-27 17:29:15 +09:00
Bill Currie 732ea3a5fd Fix a bunch of issues for clang
One *actual* error (wrong enum type), and some memory alignment issues.
The rest just clang being lame.
2022-07-31 17:15:40 +09:00
Bill Currie 2c8bec27c7 Fix a pile of warnings for gcc 12
Most were pretty easy and fairly logical, but gib's regex was a bit of a
pain until I figured out the real problem was the conditional
assignments.

However, libs/gamecode/test/test-conv4 fails when optimizing due to gcc
using vcvttps2dq (which is nice, actually) for vector forms, but not the
single equivalent other times. I haven't decided what to do with the
test (I might abandon it as it does seem to be UD).
2022-07-31 17:13:26 +09:00
Bill Currie 94db9c8ab1 [quakefs] Add a data parameter to gamedir callbacks
While this didn't fix the problem for which I needed the data pointer,
having data pointers in callbacks is far too useful to throw out the
change.
2022-06-04 16:06:04 +09:00
Bill Currie e1a0bde5ee [sound] Remove a pile of unwanted sound.h includes
This does mean that the gl and sw renderers can no longer call
S_ExtraUpdate, but really, they shouldn't be anyway. And I seem to
remember it not really helping (been way too long since quake ran that
slowly for me).
2022-06-03 15:43:53 +09:00
Bill Currie 61178978be [vulkan] Get bsp texture animations working again
The texture animation data is compacted into a small struct for each
texture, resulting in much less data access when animating the texture.
More importantly, no looping over the list of frames. I plan on
migrating this to at least the other hardware renderers.
2022-05-26 22:31:31 +09:00
Bill Currie 4786594f3c [vulkan] Create a "missing" texture for bsps
I found a test map with no texture data. Even after fixing the bsp
loader, vulkan didn't like it. Now vulkan is happy. The "Missing" text
is full-bright magenta on a dim grey background so it should be visible
in any lighting conditions.
2022-05-26 19:14:44 +09:00
Bill Currie 4dc1988af1 [vulkan] Add a function to load texture arrays
I needed to create an array texture and didn't feel like doing all that
boilerplate again :P.
2022-05-26 18:43:15 +09:00
Bill Currie 70ece6d5bb [vulkan] Work around buggy maps with broken brushes
Conflagrant Rodent has a sub-model with 0 faces (double bit error?)
causing simply counting faces to get out of sync with actual model
starts thus breaking *all* brush models that come after it (including
other maps). Thus be a little less lazy in figuring out model start
faces.
2022-05-25 20:08:36 +09:00
Bill Currie 524c1e27c4 [vulkan] Use instanced rendering for brush models
The models are broken up into N sub-(sub-)models, one for each texture,
but all faces using the same texture are drawn as an instance, making
for both reduced draw calls and reduced index buffer use (and thus,
hopefully, reduced bandwidth). While texture animations are broken, this
does mark a significant milestone towards implementing shadows as it
should now be possible to use multiple threads (with multiple index and
entid buffers) to render the depth buffers for all the lights.
2022-05-25 13:29:11 +09:00
Bill Currie a08261c620 [vulkan] Use a buffer for entity transform and color data
This allows the use of an entity id to index into the entity data and
fetch the transform and colormod data in the vertex shader, thus making
instanced rendering possible. Non-world brush entities are still not
rendered, but the world entity is using both the entity data buffer and
entid buffer.
2022-05-25 00:17:57 +09:00
Bill Currie 3a2560e4c1 [vulkan] Implement thread-safe rendering for the world model
Sub-models and instance models need an instance data buffer, but this
gets the basics working (and the proof of concept). Using arrays like
this actually simplified a lot of the code, and will make it easy to get
transparency without turbulence (just another queue).
2022-05-23 01:28:43 +09:00
Bill Currie c6f520b743 [model] Clean out some useless surface flags
The gl water warp ones have been useless since very early on due to not
doing water warp in gl (vertex warping just didn't work well), and the
recent water warp implementation doesn't need those hacks. The rest of
the removed flags just aren't needed for anything. SURF_DRAWNOALPHA
might get renamed, but should be useful for translucent bsp surfaces
(eg, vines in ad_tears).
2022-05-22 23:38:18 +09:00
Bill Currie c8472755d1 [model] Move visframe out of msurface_t
One more step towards BSP thread-safety. This one brought with it a very
noticeable speed boost (ie, not lost in the noise) thanks to the face
visframes being in tightly packed groups instead of 128 bytes apart,
though the sw render's boost is lost in the noise (but it's very
fill-rate limited).
2022-05-22 16:38:50 +09:00
Bill Currie d40769c21d [model] Move visframe out of mleaf_t
This is next critical step to making BSP rendering thread-safe.

visframe was replaced with cluster (not used yet) in anticipation of BSP
cluster reconstruction (which will be necessary for dealing with large
maps like ad_tears).
2022-05-22 14:43:07 +09:00
Bill Currie 7240d2dc80 [model] Move plane info into mnode_t, and visframe out
The main goal was to get visframe out of mnode_t to make it thread-safe
(each thread can have its own visframe array), but moving the plane info
into mnode_t made for better data access patters when traversing the bsp
tree as the plane is right there with the child indices. Nicely, the
size of mnode_t is the same as before (64 bytes due to alignment), with
4 bytes wasted.

Performance-wise, there seems to be very little difference. Maybe
slightly slower.

The unfortunate thing about the change is the plane distance is negated,
possibly leading to some confusion, particularly since the box and
sphere culling functions were affected. However, this is so point-plane
distance calculations can be done with a single 4d dot product.
2022-05-22 12:41:23 +09:00
Bill Currie 8633ffe9d2 Fix some MXE build issues
Just some unused variables when vulkan debug is disabled and some scanf
formats for qfcc vectors (and the safety net).
2022-05-22 11:59:53 +09:00
Bill Currie 0d609efbc6 [vulkan] Implement water alpha
I'm not sure it's working properly, but that compose pass is suspect,
especially with respect to lighting.
2022-05-22 11:59:53 +09:00
Bill Currie 3bb54bc20a [renderer] Up some limits so I can test with ad_tears
The map uses 41% of a 4k light map scrap, and 512 texture descriptors
wasn't enough for vulkan. Ouch. I do need to get cvars on these things,
but this will do for now (decades later...)
2022-05-22 11:59:53 +09:00
Bill Currie 765b61d133 [vulkan] Remove elements_t type
This was one of the biggest reasons I had trouble understanding the bsp
display list code, but it turns out it was for dealing with GLES's
16-bit limit on vertex indices. Since vulkan uses 32-bit indices,
there's no need for the extra layer of indirection. I'm pretty sure it
was that lack of understanding that prevented me from removing it when I
first converted the glsl bsp code to vulkan (ie, that 16-bit indices
were the only reason for elements_t).

It's hard to tell whether the change makes much difference to
performance, though it seems it might (noisy stats even over 50 timedemo
loops) and the better data localization indicate it should at least be
just as good if not better. However, the reason for the change is
simplifying the data structures so I can make bsp rendering thread-safe
in preparation for rendering shadow maps.
2022-05-19 13:26:45 +09:00
Bill Currie beb05f28ff [glsl,vulkan] More comments in the bsp code
And maybe a nano-optimization. Switching from (~side + 1) to (-side)
seems to give glsl a very tiny speed boost, but certainly doesn't hurt.
Looking at some assembly output for the three cases, the two hacks seem
to generate the same code as each other, but 3 instructions vs 6 for ?:.
While ?: is more generically robust, the hacks are tuned for the
knowledge side is either 0 or 1. The later xor might alter things, but
at least I now know that the hack (either version) is worthwhile.
2022-05-19 13:26:45 +09:00
Bill Currie 3639ee3d2d [vulkan] Just simply exit for validation errors
With experience, I have found that trying to continue after a validation
error tends to result in a segfault or some other nastiness, and
Sys_Shutdown (and the full shutdown sequence) is triggered for any error
signal (segfault, abort, etc) so just exit(1).
2022-05-19 13:26:45 +09:00
Bill Currie be635804d1 [vulkan] Clean up display list building and add some comments
Some very much needed comments :P Still, nicely, I now have a much
better understanding of how the display lists are created (10 years
is a long time to remember how intricate code works (I do remember
fighting to get it working back then))
2022-05-19 13:26:45 +09:00
Bill Currie 249feb1ae8 [glsl] Clean up build_surf_displist
This makes it much easier to see just what is being done to build a
polygon to be passed to the GPU, and it served as a test for the
lightmap st changes since Vulkan currently never used them.
2022-05-19 13:26:45 +09:00
Bill Currie 45431a0bcc [vulkan] Use absolute light intensity/radius for size
Many modders use negative lights for interesting effects, but vulkan
doesn't like the result of a negative int treated as unsigned when it
comes to texture sizes.
2022-05-19 13:26:45 +09:00
Bill Currie 27de599ac4 [vulkan] Resurrect the shadow map resource creation
However, this time it doesn't modify the light array when it sorts the
lights by size since the lights are now located before the renderer gets
to see them, and having the fix up the light leafs array would be too
painful (and probably the completely wrong thing to do anyway: the light
array should be treated as constant by the renderer). 1.6GB of memory
for gmsp3v2's lights (a little better than marcher: more smaller lights?).

For reference:
gmsp3v2: shadow maps: 8330 layers in 29 images: 1647706112
marcher: shadow maps: 2440 layers in 11 images: 2358575104
2022-05-19 13:26:45 +09:00
Bill Currie e1e4bf5659 [vulkan] Up the light limit to 768
For now, at least (I have some ideas to possibly reduce the numbers and
also to avoid the need for actual limits). I've seen gmsp3v2 use over
500 lights at once (it has over 1300), and I spent too long figuring out
that weird light behavior was due to  the limit being hit and lights
getting dropped (and even longer figuring out that more weird behavior
was due to the lack of shadows and the world being too bright in the
first place).
2022-05-19 13:26:45 +09:00
Bill Currie 9237d83b56 [vulkan] Fix some comments and developer output 2022-05-19 13:26:45 +09:00
Bill Currie ceaac00453 [vulkan] Free the staging buffer's command buffers
Since the staging buffer allocates the command buffers it uses, it
needs to free them when it is freed. I think I was confused by the
validation layers not complaining about unfreed buffers when shutting
down, but that's because destroying the pool (during program shutdown,
when the validation layers would complain) frees all the buffers. Thus,
due to staging buffers being created and destroyed during the level load
process, (rather large) command buffers were piling up like imps in a
Doom level.

In the process, it was necessary to rearrange some of the shutdown code
because vulkan_vid_render_shutdown destroys the shared command pool, but
the pool is required for freeing the command buffers, but there was a
minor mess of long-lived staging buffers being freed afterwards. That
didn't end particularly well.
2022-05-13 10:19:08 +09:00
Bill Currie 3823ea1858 [vulkan] Plug some memory leaks
I still can't find the run-time leak. I suspect something that
accumulates but gets freed on exit.
2022-05-13 00:55:37 +09:00
Bill Currie aabf3e14f8 [model] Support freeing of skin data
I doubt it's enough, but it does seem to cover what's needed for glsl
(maybe not the actual textures, unsure there, but I think they're
recycled).
2022-05-12 22:46:31 +09:00
Bill Currie bc674657cb [plugin] Ensure plugins get unloaded during shutdown
This included pre-registered (static) plugins.

Surprisingly, PI_Shutdown was never called.
2022-05-12 20:58:39 +09:00
Bill Currie 973ae0ad54 [gamecode] Add PR_Shutdown for tearing down a VM
This is meant for a "permanent" tear-down before freeing the memory
holding the VM state or at program shutdown. As a consequence, builtin
sub-systems registering resources are now required to pass a "destroy"
function pointer that will be called just before the memory holding
those resources is freed by the VM resource manager (ie, the manager
owns the resource memory block, but each subsystem is responsible for
cleaning up any resources held within that block).

This even enhances thread-safety in rua_obj (there are some problems
with cmd, cvar, and gib).
2022-05-12 19:58:18 +09:00
Bill Currie 978d0306c0 [hash] Rename the publicly visible hashlink_t to hashctx_t
I think my biggest problem with the hashlink freelist parameter was how
much implementation it exposed in just the name.
2022-05-12 18:02:01 +09:00