Commit Graph

238 Commits

Author SHA1 Message Date
bjorn e08217e6ca Fix lovr.graphics.newTexture when passing a single image; 2024-04-11 09:27:54 -07:00
bjorn 243b6ae21a Use lovrDefer more; 2024-04-01 15:32:06 -07:00
bjorn cdecc1bae7 Add defer system; Rework exceptions; util cleanup;
Defer can be used to clean up resources when an error occurs.
2024-03-29 18:10:22 -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 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 466a052ded Cleanup; 2024-02-24 15:45:30 -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 cbc9312716 Fix memory leak; 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 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 5434dd6add Add sn10x3 data type;
The unpacking code might not be working properly...
2024-01-20 17:39:36 -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 da763c8786 rm ability to create shaders from tables of spirv opcodes;
I don't think anyone was using this, and it adds ambiguity to
the newShader argument logic.
2023-12-30 19:52:41 -08: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 e5733bc667 Only generate mipmaps for blittable texture formats;
- If you load an image with a non-blittable format, mipmap count will
  default to 1.
- If you explicitly request mipmaps on a non-blank texture with a
  non-blittable format, that's an error (rather than leaving mipmap
  chain undefined or sliently falling back to 1 mipmap).
2023-11-17 20:48:44 -08:00
bjorn ce4e07db1b Revert removal of lovr.graphics.initialize;
I forgot that graphics also needs to be initialized after headset,
otherwise the XR_KHR_vulkan_enable2 callbacks won't exist yet. Boo
2023-11-09 13:31:56 -08:00
bjorn 9e82dc9148 Layer count is implicitly 6 when creating cubemap;
LÖVR understands me
2023-11-06 15:53:01 -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 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 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 6e12370ee8 Fix out of bounds access in newShader; 2023-10-05 11:26:43 -07:00
bjorn 9dd2782af9 Fix win32 warnings; 2023-10-03 11:51:08 -07:00
bjorn d7c6461916 Render targets with mipmaps get transfer usage;
Also I think no mipmaps is more sane default for render targets.
2023-09-29 05:22:03 -07:00
bjorn a2f539de56 Update glslang; Shader #include uses virtual filesystem;
This update seemed to increased glslang's binary size even more...
2023-09-28 22:04:05 -07:00
bjorn fbdecda440 Render textures have mipmaps by default again;
They defaulted to 1 to avoid confusion when mipmaps weren't generated
during a render pass (withou the { mipmaps = true } flag), but now the
mipmaps flag is obsolete and render passes automatically generate
mipmaps for all levels in their texture views.  This means that render
passes can have mipmaps by default again, which leads to better
appearance when sampling them later.
2023-09-25 00:07:26 -07:00
bjorn ed0756bfa2 rm variant of newMesh that takes indices;
Too many variants!  Also it had bugs.
2023-09-24 23:39:51 -07:00
bjorn f2343a2056 Fix crash when uvShift/uvScale are tables; 2023-09-12 01:11:49 -07:00
bjorn 9542d46f33 Buffer format cleanup; 2023-09-11 03:01:11 -07:00
bjorn 4892d228b3 WIP; 2023-07-24 15:34:44 -07:00
bjorn dabbd449a8 Format support considers both linear/srgb encodings; 2023-07-10 19:21:11 -07:00
bjorn ad5d00fb2f Bugfixes; 2023-06-23 22:56:33 -07:00
bjorn 68878f9197 Rename/refactor more Buffer stuff;
BufferField -> DataField
fields -> format
decontaminate buffer constructor
2023-06-23 21:14:19 -07:00
bjorn 0ff633fa56 mv FieldType DataType; 2023-06-23 19:11:30 -07:00
bjorn 0a255af337 Add materials flag to newModel; 2023-06-09 18:32:54 -07:00
bjorn 98e648871e lovr.graphics.is/setTimingEnabled;
Enables automatic CPU/GPU timing for all passes.  Defaults to true
when graphics debugging is active, but can be enabled/disabled manually.

When active, Pass:getStats will return submitTime and gpuTime table
keys, respectively indicating CPU time the Pass took to record and the
time the Pass took to run on the GPU.  These have a delay of a few
frames.

This doesn't include a way to get "global" timing info for a submit.
This information would be useful because it doesn't require lovrrs to
sum all the timing info for all the passes and it would include other
work like transfers, synchronization, and CPU waits.  However, this is
more challenging to implement under the current architecture and will be
deferred to later.  Even if this were added, these per-pass timings will
remain useful.
2023-05-06 23:36:33 -07:00
bjorn 452ee5c7c6 Pass rework;
Pass stores draw commands rather than sending them to Vulkan
immediately.

The main motivation is to allow more flexibility in the Lua API.  Passes
are now regular objects, aren't invalidated whenever submit is called,
and can cache their draws across multiple frames.  Draws can also be
internally culled, sorted, and batched.

Some API methods (tallies) are missing, and there are still some bugs to
fix, notably with background color.
2023-05-02 00:06:01 -07:00
bjorn 6976a61464 Rename fill2d back to fill;
This rename was a mistake -- at the time I was thinking the fill shaders
were internal, but they definitely aren't.
2023-05-01 18:54:56 -07:00
bjorn f98306e786 rm transfer passes; rm Tally for now;
- Add Buffer:newReadback
- Add Buffer:getData
- Buffer:getPointer works with permanent buffers
- Buffer:setData works with permanent buffers
- Buffer:clear works with permanent buffers
- Add Texture:newReadback
- Add Texture:getPixels
- Add Texture:setPixels
- Add Texture:clear
- Add Texture:generateMipmaps
- Buffer readbacks can now return tables in addition to Blobs using Readback:getData

Tally is coming back soon with an improved API, it's temporarily removed
since it made the transfer rework a bit easier.

Note that synchronous readbacks (Buffer:getData, Texture:getPixels)
internally call lovr.graphics.submit, so they invalidate existing Pass
objects.  This will be improved soon.
2023-04-29 18:31:03 -07:00
bjorn 775b6e4ff7 Rename some buffer helper functions; 2023-04-29 18:31:03 -07:00
bjorn 8f654ed408 Simplify fill shaders;
Now there's 2 instead of 3!  Behavior is the same, fill goes
layer-by-layer onto each view until either the texture or canvas run out
of layers.
2023-04-26 22:18:06 -07:00
bjorn f3448d3167 Improve error when buffer fields are missing; 2023-04-02 13:00:32 -07:00
bjorn 4f1e3a17e1 Improve error message for invalid first buffer arg; 2023-04-02 12:58:39 -07:00
bjorn 36e8ded0d8 Add helper function for getBuffer/newBuffer; 2023-04-02 12:54:19 -07:00
bjorn 8b30dc73d3 Fix backwards compatibility behavior;
Fixes (data, format) order when fields are given using integer keys
instead of string keys.
2023-03-20 13:54:38 -07:00
bjorn 92e9efd882 More flexible Buffer formats; Deprecate temp buffers;
- Pass:mesh accepts tables for vertices/indices
- Add Pass:setVertexFormat to set format used for table-based meshes
- Pass:send accepts tables for buffers
- Pass:send supports arbitrarily nested structs/arrays for push constants
- Buffer formats support arbitrarily nested structs/arrays
  - Zero-length buffers are valid and represent structs
  - Fields can have names using 'name'
  - Field types can be tables of other fields (structs)
  - Fields can have 'length' key
- newBuffer syntax has been changed to put format first (old version
  still works)
- Buffers can be created from shader variables, avoiding need to declare
  matching format.
- Pass:clear/Pass:read use byte offsets instead of indices
- Pass:copy uses byte offsets when copying a Buffer to a Buffer
- Deprecate lovr.graphics.getBuffer (tables can be used instead)
2023-03-20 13:54:37 -07:00
bjorn b76d9bbfe5 Ensure mipmap count is consistently 1 for render targets;
Currently if you create a texture from dimensions (assumed to be a
render target), its mipmap count differs depending on whether you
provide an options table.  Now it will consistently be 1.
2023-02-05 16:02:58 -08:00