Commit Graph

1578 Commits

Author SHA1 Message Date
bjorn 215e042e05 Add lovrUnreachable branch; 2024-01-31 12:52:29 -08:00
Josip Miskovic 1ad8f23fb8 Jolt physics engine integration 2024-01-30 18:22:27 +01:00
bjorn 06bfbbaa6b Validate that intra-buffer copy has non-overlapping ranges; 2024-01-29 21:33:51 -08:00
bjorn 5bd48f16f5 lovr.system.get/setClipboardText; 2024-01-29 12:52:41 -08:00
bjorn 287769f1f2 Fix 32 bit sync flag truncation; Fix sync validation; 2024-01-29 02:10:40 -08:00
bjorn 6516cca39d Switch to VK_KHR_synchronization2; 2024-01-29 00:58:11 -08:00
bjorn 3712bc3fba Fix error when loading a Model without any vertices; 2024-01-29 00:33:34 -08:00
bjorn 35f97f08f3 glTF: support glb models without BIN chunk; 2024-01-29 00:29:23 -08:00
bjorn 2b351fa145 Clean up NodeTransform struct a bit; 2024-01-26 10:47:54 -08:00
bjorn 1ede3ef012 gpu_wait_idle also updates tick;
So you don't have to call `gpu_wait_tick` right after.
2024-01-25 00:13:25 -08:00
bjorn f8158744f9 Details; 2024-01-20 21:58:03 -08:00
xiejiangzhi 45a6333afb Slow movement for sim, fix bug of tag, add max number of tag to 32
Holding ctrl to slowly movement for Sim
Check null for findTag
Increment max number of tags to 32
Fix newWorld error if tags > MAX_TAGS
2024-01-21 13:50:59 +08:00
bjorn 40d85c6a16 Model uses sn10x3 normals and tangents;
This shaves 20 bytes off of each model vertex, or around 40% savings.
The vertex size is also a power of two which results in extreme amounts
of style points.
2024-01-20 17:39:36 -08:00
bjorn 5434dd6add Add sn10x3 data type;
The unpacking code might not be working properly...
2024-01-20 17:39:36 -08:00
bjorn a4c57193d5 Details; 2024-01-20 03:42:51 -08:00
bjorn fd771f6420 Fix newBuffer crash when created with initial contents on some GPUs; 2024-01-17 15:52:56 -08:00
bjorn dfa231ebc0 Fix memory leak in pass lookup; 2024-01-17 15:48:34 -08:00
bjorn 65f1370314 Update flushTransfers comment;
No longer applies to buffers.
2024-01-17 15:41:27 -08:00
bjorn 5c60f068db Blend mode usess a lookup table; 2024-01-17 15:40:42 -08:00
bjorn 435d2676cd Fix issue with buffer destruction; 2024-01-14 02:28:10 -08:00
bjorn 33fa6ed623 Fix skeletal animation; 2024-01-13 18:01:04 -08:00
bjorn e1abf0b332 Refactor render passes for thread safety;
Currently pipeline compilation accesses the render pass cache, which
presents thread safety challenges.  The framebuffer and render pass
caches are also slow and gross.

This adds a `gpu_pass` object which is basically just a VkRenderPass
object.  The graphics module creates and caches these in
`lovrPassSetCanvas`.  They are used when compiling pipelines and
beginning render passes.

Framebuffers are no longer cached but are just created and immediately
condemned dynamically when beginning a render pass.  This is fine,
because framebuffers are super cheap.

There's still technically a thread safety issue with the `gpu_pass`
object caching, but it's much easier to solve that with a lock in
`lovrPassSetCanvas` compared to trying to make core/gpu's render pass
cache thread safe.

This is all still a temporary measure until we can use a more
"ergonomic" render pass API like dynamic rendering.

Oh also we stopped using automatic layout transitions because they seem
to be pessimistic in drivers and require tying render pass objects to
texture usage which is annoying.  So now we do attachment layout
transitions manually before/after beginning/ending a render pass, which
isn't so bad.
2024-01-13 17:35:43 -08:00
bjorn 49752f851a More fixes for Shader clones; 2024-01-07 17:06:26 -08:00
bjorn d5d75d58e5 Shader clones set stage mask properly; 2024-01-07 13:43:22 -08:00
bjorn 3cf76c81e7 Refactor shader stages; rm ShaderType;
Goal is to support more combinations of shader stages, both for
vertex-only shaders and mesh/raytracing shaders in the future.  In
general most of the logic that conflated "stage count" with "shader
type" has been changed to look at individual shader stages.
2024-01-05 14:59:19 -08:00
bjorn 8ea2b11939 Buffer suballocation;
Now all regular Buffer objects are suballocated from big 4MB buffers,
like the temporary buffers.

Each of the big buffers is refcounted.

Wherever a `gpu_buffer` is used, the offset of the "view" into the big
buffer needs to be taken into account as well.

A practical advantage of this is that vertex/index buffers usually do
not need to be rebound between draws when drawing a different model/mesh.
2023-12-30 14:28:45 -08:00
bjorn e8e7c2afc1 Refactor buffer allocation;
Pretty much the same, but fixes an obscure lifetime issue with pass
buffer allocation.

If a pass's buffer fills up, it can't be recycled immediately because
that might cause the buffer to get reused too soon if the pass is
submitted multiple times (with draws added in between that exceed 4MB of
temp buffer allocations).

Instead, the strategy is to have the pass keep track of "full" buffers
in a pass-local freelist.

Whenever the pass is submitted, the tick of each full buffer is set to
the current tick, so we know the tick when it's safe to reuse them.

When a pass is reset (or destroyed), all of its full buffers are
returned to the global freelist of stream buffers.  The current one can
remain in use.

Pooling the buffers of all the passes globally like this increases reuse
opportunities but also increases contention.

These changes also serve as preparation to suballocate Buffer objects in
the graphics module, which makes it easier to batch more stuff.
2023-12-30 14:28:45 -08:00
bjorn a36e17b632 Error when shaders have arrays of buffers/textures;
It's not currently supported and results in undefined behavior.
2023-12-08 20:13:42 -08:00
bjorn cbc671f48d Fix query pool memory leak; 2023-12-03 06:35:38 -08:00
bjorn 3a2d453ce8 Fix thread module destruction; 2023-12-03 06:34:22 -08:00
bjorn 375866d3d4 lovr.system.openConsole; 2023-12-02 18:17:36 -08:00
bjorn 761a454291 Fix previous commit after more testing;
lastTransferRead/Write isn't always a reliable indicator of whether a
resource has pending transfers.
2023-12-02 17:27:31 -08:00
bjorn fbae4d1961 Fix possible crash with Font:getLines and Pass:text;
- Font:getLines/Pass:text use temp memory for strings/vertices.
- Due to the recent morgue fix, resizing the atlas will now do a GPU
  submit to flush the transfers before destroying the atlas.
- This GPU submit also rewinds the temp allocator, invalidating the
  temp memory used for the lines/vertices, causing a use-after-free.

There are 2 changes here:

- Only flush transfers if the destroyed resource actually has pending
  work (we're already tracking this w/ lastTransferRead/Write).
- Restore the allocator cursor after doing the submit.

Having to restore the allocator offset is kinda tricky/complicated,
which sucks.  Other solutions might be:

- Avoid using temp memory in those Font methods.  More generally, adopt
  a rule where you can't use temp memory if it's possible that there
  will be a submit while you're using the temp memory.
- Find some way to stop destroying the old font atlas during a resize?
- Don't rewind the temp allocator on every GPU submit.  Instead only
  rewind it at the end of a frame, or only when Lua does the submit.
2023-12-02 17:11:22 -08:00
Bjorn 4da1f26153
Merge pull request #719 from bjornbytes/boot-rework
Boot rework
2023-12-01 00:29:44 -08:00
bjorn edecbc50b1 Fix texture view synchronization/refcounting;
We were conflating "parent struct of Sync pointer" and "object to be
refcounted", which isn't the case for texture views.

To fix it, add both pointers to the Access struct.  This sucks because
it increases the size from 16 bytes to 24 bytes.

There might be other solutions like a "texture view mask" or having
buffers/textures store a pointer to their sync or something.  But these
have some drawbacks as well.  May revisit in future.
2023-11-30 19:30:02 -08:00
bjorn 5f53b21469 Merge branch 'stable' into dev 2023-11-30 09:04:19 -08:00
bjorn 49328b88a6 Shader #include errors on missing file; 2023-11-30 09:03:33 -08:00
bjorn 858bc7ffa0 Fix morgue overflow;
The morgue is a fixed-size queue for GPU resources that are waiting to
be destroyed.  There's been an annoying issue with it for a while where
destroying too many objects at once will trigger a "Morgue overflow!"
error.  Even innocuous projects that create more than 1024 textures will
see this during a normal quit.

One way to solve this problem is to make the queue unbounded instead of
bounded.  However, this can hide problems and lead to more catastrophic
failure modes.

A better solution is to add "backpressure", where we avoid putting
things in the queue if it's full, or find some way to deal with them.
In this case it means finding a way to destroy stuff in the morgue when
it's full, to make space for more victims.

We weren't able to add backpressure reliably before, because command
buffers could have commands that reference the condemned resources.
This was mostly a problem for texture transfers -- if you create
thousands of textures in a loop, we'd have a giant command buffer with
commands to transfer pixels to the textures.  If these textures were
destroyed before submitting anything, the morgue would fill up, and we
wouldn't have any way to clear space because there was still a pending
command buffer that needs to act on the textures!

A simple change is to flush all pending transfers whenever a buffer or
texture is destroyed.  This lets us add backpressure to the morgue
because we can guarantee that there are no pending command buffers that
refer to an object in the morgue.

For backpressure, we try to destroy the oldest object in the morgue if
the GPU is done using it.  If that doesn't work, we'll wait on the fence
for its tick and destroy it.  This *should* always work, although in an
extreme case you could vkDeviceWaitIdle and clear out the entire morgue.

It should also be noted that in general command buffers need to be
flushed when destroying objects that they refer to.  However, for our
particular usage patterns, we only need to flush state.stream when a
buffer or texture is destroyed.  Pass objects already refcount their
buffers and textures and their commands are software command buffers, so
they don't require any special handling.  Other objects like shaders,
pipelines, descriptor set layouts, etc. all survive until shutdown, so
those don't impact anything either.
2023-11-30 05:45:13 -08:00
bjorn 6ed2e4b8fb s/PassTime/TimingInfo; 2023-11-30 01:16:31 -08:00
bjorn 49ffda57cb Pipelines use virtual memory; 2023-11-30 00:14:06 -08:00
bjorn d375e96c13 sRGB storage image views take 2;
There were numerous problems with the previous effort to add support for
linear views of sRGB storage textures.  Here's another attempt:

- Images are always created with the linear version of their format.
- The default texture view uses the sRGB format if the parent is sRGB.
- Use ImageViewUsageCreateInfo to specify the usage for render/storage views.
- sRGB image views always have their storage bit forcibly cleared.

The storage view now behaves more like the existing renderView -- if we
detect that you couldn't use the default texture view for storage, we'll
create one that is guaranteed to be usable for storage bindings (by
clearing the sRGB flag on it).
2023-11-28 22:47:17 -08:00
bjorn 6da3f8efbe Support aliased shader resources within a shader stage;
Previously this would include multiple descriptors with the same
binding, which isn't allowed.  Instead, just reuse the inter-stage
tracking/merging for intra-stage resources as well.
2023-11-28 11:12:29 -08:00
bjorn 9d55a5b222 boot.lua sets source instead of filesystem module; 2023-11-27 18:42:49 -08:00
bjorn 64950bc152 lovr.filesystem.setSource; 2023-11-27 18:42:49 -08:00
bjorn 4926362cc7 lovr.filesystem.getBundlePath; 2023-11-27 18:42:49 -08:00
bjorn 1cac651392 Inline LOVR_PATH_SEP; 2023-11-27 18:42:49 -08:00
bjorn 2e543a96de More zip fixes; 2023-11-27 18:39:27 -08:00
bjorn 399a283536 zip fixes; 2023-11-26 21:49:41 -08:00
bjorn 9da89b7834 Fix Windows build; 2023-11-26 18:15:53 -08:00
Josip Miskovic a1d7bf5fbc Use virtual memory in vector pools 2023-11-26 16:54:29 +01:00
bjorn 08d6b2ad28 Refcounted modules;
This allows them to be initialized/destroyed from multiple threads in
any order.  Previously, the first thread to require a module had to be
the last thread to use the module, otherwise it would be destroyed too
early.

There are still a few issues.  If the main thread doesn't require a
module, it won't pick up the conf.lua settings.  Also graphics isn't
handling the shader cache writing properly.  And I think this breaks the
headset-graphics refcounting.  But these will be fixed in future
commits.
2023-11-23 17:07:44 -08:00
bjorn 7ca331a5f5 Adjust fs_read/fs_write signatures; Fix seeking; 2023-11-22 16:37:31 -08:00
bjorn d949b90eea Details; 2023-11-22 16:19:40 -08:00
bjorn f04a0e6bc4 Fix zip EOF emulation;
To match regular files, the file offset should be allowed to go past the
end of the file, but reads will return 0 bytes.
2023-11-22 15:49:10 -08:00
bjorn 79abe3b1d6 Windows fixes; 2023-11-21 20:19:49 -08:00
bjorn 19ac219b0c Add File object; 2023-11-21 18:49:32 -08:00
bjorn f50e9f6fe1 Use miniz to decompress files; 2023-11-21 18:49:32 -08:00
bjorn d0f1462e51 Make Archive a refcounted object;
- Archive is now an object that has a refcount
- Archives are stored in linked list instead of array
- Not exposed to Lua yet, but could be in the future
- core/zip was merged into the filesystem module
- Mountpoints are handled centrally instead of per-archive
- Zip doesn't pre-hash with the mountpoint anymore
- mtime is truly only computed on request for zips

Mountpoints don't work properly yet.
2023-11-21 18:49:32 -08:00
bjorn 209ea1e4b5 Simplify Pass draw list;
It's a normal stretchy buffer instead of a weird page table thing.

This was definitely overdesigned.

Now it uses less memory too.
2023-11-18 02:02:05 -08:00
Bjorn 895c702388
Merge pull request #720 from xiejiangzhi/auto_wakeup
Auto wake up collider when calling API to apply force or change force.
2023-11-17 17:50:10 -08:00
xiejiangzhi 1e120d3401 Auto wake up collider when calling API to apply force or change force. 2023-11-18 09:43:52 +08:00
bjorn e0e1bc68f9 Add support for cubemap arrays;
- Cubemaps can have any layer count that is a multiple of 6.
- A cubemap with more than 6 layers will be a cubemap array image view.
  - This isn't perfect because it conflates regular cubemaps with
    6-layer cubemap arrays.
- Enable the vk feature, handle the spv feature, add getPixel helper.
2023-11-10 11:15:16 -08:00
bjorn 67b1929af6 Merge branch 'stable' into dev 2023-11-09 16:51:28 -08:00
bjorn eefc89909e Fix bitangent sign;
Really gotta compress ModelVertex at some point.
2023-11-09 16:50:52 -08:00
bjorn 62810a195c rm Pass:append;
This was an experiment that was never documented/announced.
2023-11-09 16:08:14 -08:00
bjorn 534947bc20 Merge branch 'stable' into dev 2023-11-09 14:57:42 -08:00
bjorn 4522d1050f Fix OpenXR layout transitions; 2023-11-09 14:57:29 -08:00
bjorn 02860ff8e9 Merge branch 'stable' into dev 2023-11-09 12:48:10 -08:00
bjorn 648118d308 Fix excessive gamma-to-linear conversion; 2023-11-09 12:47:39 -08:00
bjorn c4cda0a7bb core/gpu: rm TRANSIENT texture usage;
It's implied when the usage is just RENDER
2023-11-08 14:54:10 -08:00
bjorn e8945763c2 core/gpu: allocation callbacks; 2023-11-08 14:45:04 -08:00
bjorn 8ed5572b0e rm lovr.graphics.initialize/isInitialized;
This only existed because the graphics module had to know about the
window during initialization, but this is no longer the case.
2023-11-03 15:53:33 -07:00
bjorn c98db5b670 lovr.system.wasMousePressed/Released; 2023-11-02 18:55:02 -07:00
bjorn 038db88cb7 Consolidate texture format features;
- 'sample' now implies both sample and linear filtering (practically always
  true for all formats lovr supports)
- 'render' now includes 'blend' for color formats (also practically
  always true except for r32f on some old mobile GPUs)
- 'blit' now includes 'blitsrc'/'blitdst' because lovr doesn't support
  blitting between textures with different formats
- 'atomic' is removed because lovr doesn't really support atomic images yet
2023-11-02 15:33:29 -07:00
bjorn c2d9aa5657 Destroy linear texture views; 2023-11-02 13:40:16 -07:00
bjorn 90a14478a3 lovrImageCreateRaw takes sRGB flag; Fix readback encoding;
Roundtripping pixels through a readback preserves sRGB encoding.
2023-11-02 13:38:21 -07:00
bjorn b2083e9a4a Ignore linear=false flag for linear-only formats;
Also fix bug with r8 srgb canvases...
2023-11-02 13:26:49 -07:00
bjorn 0468a2f090 Default texture is linear; 2023-11-02 13:16:00 -07:00
bjorn e9743a2fb8 Secretly create and bind linear views of sRGB storage textures; 2023-10-31 17:14:09 -07:00
bjorn a28d66e3a1 Mesh:setMaterial takes texture too; 2023-10-31 16:08:00 -07:00
bjorn 9ff8ad61e1 Prefix KEY enums with OS_KEY; 2023-10-31 13:16:20 -07:00
bjorn df9f50ca5c Fixes for layer depth test and depth submission; 2023-10-26 16:29:35 -07:00
bjorn bdbdd467e0 Layer improvements; 2023-10-25 15:24:14 -07:00
bjorn 6bccbd66ec Layer fixes; 2023-10-25 15:24:14 -07:00
bjorn c8eb6606c6 OpenXR layer implementation; 2023-10-25 15:24:13 -07:00
bjorn 4c2e206e30 Bindings; 2023-10-25 15:23:41 -07:00
bjorn 72aac1c58a Start Layers; 2023-10-25 15:23:41 -07:00
bjorn 2f8d9aa6dc Disable depth submission when depthResolve is not supported;
Prefer MSAA over depth submission on GPUs that can't resolve depth
buffers (Quest 1).
2023-10-25 15:22:16 -07:00
bjorn 42cfb273f9 Fix bug where depth wasn't being submitted to VR runtime; 2023-10-25 15:15:16 -07:00
bjorn 0dfa95626e Model:resetBlendShapes;
Resets blend shapes to default values, like :resetNodeTransforms.
2023-10-18 15:51:52 -07:00
bjorn 35628e332c rm deprecated pass stuff; 2023-10-15 14:10:39 -07:00
bjorn ab3922345f rm deprecated buffer stuff; 2023-10-15 14:08:50 -07:00
bjorn 99f8c3a25c Fix frustum culling;
The technique used only works for AABBs.  Trying to apply the model
matrix to the extent like that isn't valid.  For now, switch back to
the naive approach.  This is quite a bit slower, but at least it's
correct.
2023-10-11 18:21:11 -07:00
bjorn 68aad50a2d Use better UBO size when pass has more than 256 draws; 2023-10-11 13:55:25 -07:00
bjorn 5d6f538524 Pass:barrier also barriers against indirect stage;
Fixes a validation error that probably no one was running into.
2023-10-11 08:26:06 -07:00
bjorn b319aeeb40 Fix Pass:send when using a table with an array UBO; 2023-10-07 16:22:56 -07:00
bjorn 539b19c84c Fix minor undefined behavior; 2023-10-05 12:21:27 -07:00
bjorn 6cfbfd050d Fix issue with synchronization;
If there is only a single pass in the submit, barrierCount is zero
since there will be no inter-pass synchronization.  This is almost
correct, but not quite, because if a Pass has compute and render work,
the render pass may need to synchronize with the compute pass.  So a
barrier is still necessary.  For simplicity, always allocate the full
number of barriers, even though the final render barrier will always be
empty.

Additionally, avoids passing NULL to memset when the barrier count is
zero and the barrier arrays are NULL.
2023-10-05 12:09:55 -07:00
bjorn fc9bb8a5e4 Fix crash when trying to load hand models on non-Quest; 2023-10-04 17:04:03 -07:00
bjorn 6682fe1930 Fix Mesh:computeBoundingBox; 2023-10-04 14:36:39 -07:00