Commit Graph

546 Commits

Author SHA1 Message Date
bjorn abd2eddf0d Fix some strict prototype warnings; 2024-03-23 13:12:26 -07:00
bjorn d097d9819d Add wrappers for malloc functions; 2024-03-11 14:38:00 -07:00
bjorn 2d7b636a90 Change more asserts to checks; 2024-03-11 00:58:21 -07:00
bjorn aa79822edb Fix VertexIndex;
Adding an offset to VertexIndex/BaseVertex breaks those builtins for
shader code.  Instead, go back to binding the vertex buffer at an
appropriate offset.

This means we rebind the vertex buffer and makes it harder to batch
draws.  In the future we'd like to go back to binding all vertex buffers
at zero and incorporating per-draw vertex offsets, but we'll need to
adjust the VertexIndex macro to subtract that offset.
2024-03-10 10:36:13 -07:00
bjorn f93fb0c0c7 Set buffer tick properly when destroying pass;
This was causing one of the pass's buffers to be unrecyclable.
2024-03-08 11:56:23 -08:00
bjorn 4719dbdd10 Fix crash with timestamp readback; 2024-03-07 10:26:35 -08:00
bjorn 1ec0a41bb8 Also avoid allocating empty uniform buffer for indirect/compute; 2024-03-01 17:14:08 -08:00
bjorn c3d81debe8 Clean up GPU submission; 2024-03-01 17:13:06 -08:00
bjorn 79e28eb7e3 Fix issue with shader uniforms;
Shader == NULL wasn't clearing the dirty uniform flag, so if the
uniforms were dirty when you set a default shader we would try to
allocate and bind a zero-size uniform buffer.

Instead, let's avoid making a new uniform buffer if the shader doesn't
have any uniforms!
2024-03-01 12:46:08 -08:00
Bjorn 73eae189ae
Merge pull request #749 from bjornbytes/shader-rework
Shader Rework
2024-02-26 15:35:39 -08:00
bjorn 792fd75204 Texture view improvements;
- You can nest texture views (make a view of a view).
- You can do transfers on views (copies, clears, blits, etc.).
- You can give labels to views.
- API changes
  - Rename Texture:newView to lovr.graphics.newTextureView.
  - Constructor takes a table of options (order was too confusing).
  - Remove Texture:isView/getParent, since views can be used for everything now.
  - Better matches what LÖVE ended up doing.
- Fix bug where :getType on a view returned parent type.
2024-02-26 15:24:09 -08:00
bjorn ec380e0cfd rm pass uniformSize;
It's no longer necessary.
2024-02-25 14:58:11 -08:00
bjorn fa8ea6732b rm pass binding mask;
It's no longer necessary.
2024-02-25 14:57:27 -08:00
bjorn 2fe5ba8f3b Ensure all binding fields are fully initialized; 2024-02-24 15:45:10 -08:00
bjorn ae19b7aad3 Fix resource binding numbers; 2024-02-24 15:33:09 -08:00
bjorn 652a074677 Update resource invalidation when switching shaders;
Previously, when switching shaders, resource bindings would be preserved
for resources with matching slots/types.  This doesn't make sense in a
world where binding numbers are internal.  Instead, match up resources
by name/type.

Additionally, rewire all the uniforms by name/size so uniforms with the
same name get preserved (name/type would be too hard for e.g. structs).
This seems like it would be horribly slow and may need to be optimized,
optional, or removed.

I didn't test any of this lol, but I will I promise.
2024-02-24 14:34:29 -08:00
bjorn bd83ad6eb4 Cleanup; 2024-02-24 11:49:11 -08:00
bjorn 114109ab54 rm multisample texture objects; 2024-02-22 14:40:32 -08:00
bjorn b63ec6e137 Graphics shader requires fragment stage for now;
The vertex-only shader requires too much juggling of shader stage flags
and pipeline layout compatibility when e.g. binding push constants and
descriptor sets.
2024-02-21 10:37:59 -08:00
bjorn 728b166d69 Fix binding numbers; 2024-02-21 10:21:42 -08:00
bjorn 64e253a8ef mv logo shader to nogame bundle; 2024-02-21 10:21:42 -08:00
bjorn 81ef58d032 Use push constant instead of BaseInstance for DrawID;
This is a little slower, but means indirect draws can use Transform and Color.

There are other solutions for this.  For example LÖVR could reserve
BaseInstance and use a compute shader to rewrite indirect buffers.

For now we choose to be correct and a little slower.
2024-02-21 10:21:42 -08:00
bjorn 875a7f8237 Shader rework;
- Undeprecate ShaderType (it's good actually, kinda like a pipeline bind
  point and more specific than having lovr trying to make sense of a
  random set of stages).
- Use a default uniform block instead of push constants.  The Constants
  macro now maps to a uniform block declaration.
- It is no longer possible to create a shader by giving a single
  DefaultShader string (you can still give a per-stage DefaultShader
  though).
- lovr.graphics.compileShader now takes all stages instead of a single
  stage.  In general we need all stages when compiling GLSL because
  default uniforms require linking across stages.
2024-02-21 10:21:41 -08:00
bjorn 45eba2fe85 rm ability to send resources by slot number; 2024-02-20 10:16:41 -08:00
bjorn 93348499e9 Binding numbers are assigned explicitly and merged across stages; 2024-02-20 10:16:41 -08:00
bjorn 035d359133 Add relaxed Vulkan flag; 2024-02-20 10:16:41 -08:00
bjorn f7c1d4cccb core/spv: return pointer to set/binding decorations instead of value; 2024-02-20 10:16:41 -08:00
bjorn 555d97afbe core/spv: parse texture properties;
Can detect if texture is cubemap, array, 2d, multisample, etc.
2024-02-18 20:36:33 -08:00
bjorn bf97a55fcb Fix issues with Pass buffer recycling;
- When destroyed, Pass should only recycle its buffer if it actually has one.
- When resetting, chain all of the buffers at once instead of one-by-one (N^2)
2024-02-08 11:32:01 -08:00
bjorn df3544e5f3 Fix issue with buffer recycling;
Must set next pointer to NULL!
2024-02-08 11:22:34 -08:00
Bjorn d23164235b
Merge pull request #732 from bjornbytes/model-vertex-compression
Model Vertex Compression
2024-01-31 13:35:58 -08:00
bjorn 06bfbbaa6b Validate that intra-buffer copy has non-overlapping ranges; 2024-01-29 21:33:51 -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 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 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