Commit Graph

107 Commits

Author SHA1 Message Date
bjorn b24350fb31 gpu: macOS also tries linking to MoltenVK; 2023-01-21 15:27:14 -08:00
bjorn 58c5f0624e Fix for vk portability extension;
- Always enable when supported.
- It's not required to be enabled, even if portability_enumeration is present.
2023-01-01 05:03:05 -08:00
bjorn ae4a75eecd Shift around Vulkan initialization;
Start to make it easier to declare extensions, mark them as required,
and detect whether they're supported at runtime.
2022-12-31 17:42:51 -08:00
bjorn 98b5fcfd20 Improve Vulkan error messages;
Instead of printing the raw Vulkan error printed, a friendly error
message gets printed out with the Vulkan error in parentheses.
2022-12-04 01:58:53 -08:00
bjorn efc81e4cec Fix some gcc warnings; 2022-12-03 01:20:02 -08:00
bjorn e2c73edabb Clear GPU memory pointer later; 2022-11-27 20:51:11 -08:00
bjorn 72ecd9cb04 Fix issue recycling GPU memory blocks;
When a memory block is used for host-visible memory, its mapped pointer
is tracked with the block.  If that memory is freed and later re-used
for some non-mappable memory, the pointer never gets cleared, and so
code thinks the memory is mappable and tries to use the pointer.
2022-11-27 19:55:27 -08:00
bjorn 0c966ba216 gpu: destroy readback scratchpads properly; 2022-11-21 19:42:13 -08:00
bjorn be3faf8822 Fixes for Vulkan initialization; 2022-11-17 20:32:24 -08:00
bjorn 3879ce926d Improve Vulkan initialization;
- Check for layers before enabling
- Check for instance/device extensions before enabling

Fixes unfriendly errors when running on a system without validation layers
installed.

Uses same table approach as OpenXR code.
2022-11-16 20:21:03 -08:00
bjorn 9783140725 Fix window resize; 2022-11-09 19:05:01 -08:00
bjorn 3775ed1be6 gpu: use distinct allocator/memory for staging buffers;
Fixes easily-encounterable GPU OOM on discrete cards.

Currently when mapping CPU-accessible GPU memory, there are only two
types of memory: write and read.

The "write" allocations try to use the special 256MB pinned memory
region, with the thought that since this memory is usually for vertices,
uniforms, etc. it should be fast.

However, this memory is also used for staging buffers for buffers and
textures, which can easily exceed the 256MB (or 246MB on NV) limit upon
creating a handful of large textures.

To fix this, we're going to separate WRITE mappings into STREAM and
STAGING.  STREAM will act like the old CPU_WRITE mapping type and use
the same memory type.  STAGING will use plain host-visible memory and
avoid hogging the precious 256MB memory region.

STAGING also uses a different allocation strategy.  Instead of creating
a big buffer with a zone for each tick, it's a more traditional linear
allocator that allocates in 4MB chunks and condemns the chunk if it ever
fills up.  This is a better fit for staging buffer lifetimes since there's
usually a bunch of them at startup and then a small/sporadic amount
afterwards.  The buffer doesn't need to double in size, and it doesn't
need to be kept around after the transfers are issued.  The memory
really is single-use and won't roll over from frame to frame like the
other scratchpads.
2022-11-09 19:05:01 -08:00
bjorn b047daa712 gpu: only set portability enumeration flag if extension is enabled;
There's a "portability enumeration" extension and flag you have to set
to get Vulkan to work on macOS.  If you don't set it, Vulkan hides the
MoltenVK runtime since it's not 100% conformant.  The flag was added
unconditionally, but it needs to only be added when the extension is
active.
2022-11-09 17:22:42 -08:00
bjorn c021fc40ef gpu: fix memory type selection;
When a fallback memory type is found, don't skip the check for a perfect
match.
2022-11-06 11:19:33 -08:00
bjorn 64591c02ed gpu: Also try to load libvulkan.so.1;
Some systems don't have libvulkan.so
2022-10-24 22:12:54 -07:00
bjorn 1a12904800 Fix gpu_release; rm morgue flush; increase morgue size;
- When a memory block was freed, any allocators that were using it need
  to null out their memory blocks.  Otherwise it would just keep using
  the freed block.
- The emergency morgue expunge doesn't work.  It would be nice if it
  did, but if the emergency expunge deletes an object that exists in a
  command buffer that's still being recorded, it causes all kinds of
  problems and corrupts the command buffer.  You'd either need to submit
  these command buffers early before deleting the object (this is super
  tricky) or just prevent this entirely, maybe by growing the morgue
  infinitely or throwing an error if it fills up.  Either way, creating
  and releasing textures in a loop without submitting work will
  eventually throw an 'out of memory' error.  None of this is
  satisfactory and I'm not sure how to solve this well yet.
- To compromise, increase the size of the morgue a bit so emergency
  flushes happen slightly less often.
2022-10-20 20:21:55 -07:00
bjorn 0b6fe9c81a Fix off-by-one error in gpu allocator;
Refcount wasn't being initialized to 1.
2022-10-18 22:28:14 -07:00
bjorn 93b465bd1f gpu: Use portability extensions when needed;
This makes newer versions of macOS load Vulkan properly.
2022-10-15 00:45:46 -07:00
bjorn 82dc3cc920 Fix multiview limit;
When multiview is not supported (although technically lovr requires it),
the renderSize limit for array layers was zero, which meant no render
passes would work.  Instead, make sure it's at least 1, which is more
correct.
2022-10-12 10:37:58 -07:00
bjorn 272893fe66 Use correct array length for depth range; 2022-09-28 19:16:55 -07:00
bjorn 68f3610d5e Fix stencil test; 2022-09-12 17:58:29 -07:00
bjorn 0191d29a45 Handle missing Vulkan error; 2022-09-10 13:06:32 -07:00
bjorn ede1036694 Temporary Passes;
Sigh, back to getPass.  I don't even know at this point.  Basically now
that we came up with a half-solution for temp buffers, it makes sense to
apply this to passes as well, since we aren't going with the workstream
idea and temp passes are more convenient than retained passes.
2022-08-25 21:57:15 -07:00
bjorn 18413114ad Fix depthClamp; 2022-08-24 03:09:09 -07:00
bjorn 1c48578e95 Fix automipmap synchronization; 2022-08-23 18:49:11 -07:00
bjorn f310a7ad04 gpu_bind_bundles;
Now you can bind multiple bundles at once.
2022-08-08 20:36:22 -07:00
bjorn 2ebb4bb415 Improve OpenXR layout transitions a bit; 2022-08-06 23:25:49 -07:00
bjorn 8aa1cf91b2 Submit depth buffer to OpenXR; 2022-08-06 22:52:18 -07:00
bjorn 642388709b Shader helper improvements; 2022-08-06 13:06:42 -07:00
bjorn ed59eeb11c gpu: don't use VkPipelineCacheHeaderVersionOne;
Doesn't exist in NDK...
2022-08-05 23:41:25 -07:00
bjorn a23f0351cc WIP OpenXR layout transitions; 2022-08-05 18:36:51 -07:00
bjorn acd87a5e5c lovr.graphics.present;
It's nice to have an explicit action for presentation.
2022-08-04 00:06:54 -07:00
bjorn 89312c1c4b Add on-disk shader cache;
Set t.graphics.shadercache to true (the default) and lovr will
read/write a shader cache file from/to disk.
2022-08-02 22:06:44 -07:00
bjorn 4ee092e81b Make Pass a regular object;
It uses newPass instead of getPass.  Temporary objects had lifetime
issues that were nearly impossible to solve.  And normal objects are
easier to understand because they behave like all other LÖVR objects.

However, Pass commands are not retained from frame to frame.  Pass
objects must be re-recorded before every submit, and must be reset
before being recorded again.

Pass objects now provide a natural place for render-pass-related info
like clears and texture handles.  They also allow more information to be
precomputed which should reduce overhead a bit.

It is now possible to request a stencil buffer and antialiasing on the
window and headset textures, via conf.lua.

lovr.graphics.setBackground should instead set the clear color on the
window pass.  Though we're still going to try to do spherical harmonics
in some capacity.

There are still major issues with OpenXR that are going to be ironed
out, and the desktop driver hasn't been converted over to the new
headset Pass system yet.  So lovr.headset integration is a bit WIP.
2022-08-02 22:06:44 -07:00
bjorn 92201b87a1 Rename timer tally type to time; 2022-07-17 13:17:33 -07:00
bjorn c2dd7281cc mv stage tally -> shader tally; 2022-07-17 11:38:55 -07:00
bjorn 5d3e1f93cd Add d32fs8; 2022-07-17 11:03:00 -07:00
bjorn 32346796ef Tally/Readback cleanup; 2022-07-17 09:50:15 -07:00
bjorn e2bfff1b0a Tally/Readback fixes; 2022-07-14 19:23:02 -07:00
bjorn 3bfd9ca0e1 gpu: improve wait functions;
- gpu_finished -> gpu_is_complete
- add gpu_wait_tick -> can wait for specific tick to finish (fence)
- gpu_wait -> gpu_wait_idle
2022-07-14 00:04:38 -07:00
bjorn c54a587590 gpu: fix read scratchpad destruction; 2022-07-14 00:04:21 -07:00
bjorn ae87abc7bb gpu: fix allocator; 2022-07-11 19:53:53 -07:00
bjorn cfa5613db4 gpu: render pass cache uses correct resolve layout; 2022-07-10 17:06:43 -07:00
bjorn f23ae4009f gpu: Fix render pass cache eviction; 2022-07-10 17:06:20 -07:00
bjorn a44ab9bcfa Fix presentation sequence issue;
Fixes crash on error inside lovr.draw.
2022-07-05 21:58:54 -07:00
bjorn d06e0c8b09 gpu: tally waits for query results; 2022-06-30 17:34:30 -07:00
bjorn 0417e9095d gpu: add timestampPeriod limit; 2022-06-30 17:34:30 -07:00
bjorn c327eb103f Tally; 2022-06-30 17:34:29 -07:00
bjorn 24fd9e0c04 gpu: properly cast device to uintptr_t; 2022-06-26 00:46:11 -07:00
bjorn 7def390f9c OpenXR/CMake fixes; 2022-06-20 15:51:24 -07:00