Commit Graph

130 Commits

Author SHA1 Message Date
bjorn a784321d84 Rework Buffer formats;
Summary:

- Buffer length can be zero (indicates single value instead of array)
- Internally, arrays aren't coerced to array-of-single-struct
- Removes support for "flat table" data (array-of-structs w/o wrapping
  each struct in a nested table)
- Use consistent syntax for reading table data into buffers:
  - Numbers are numbers
  - Vectors are numbers, tables, or vectors
  - Structs are tables with any combination of integer/string keys
    - Fields are assigned from integer keys in order, then any remaining
      fields use the string keys
  - Arrays are tables of elements, formatted as above
- Try to improve error messages for Buffer:setData errors
2024-04-17 17:54:23 -07:00
bjorn 243b6ae21a Use lovrDefer more; 2024-04-01 15:32:06 -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 45eba2fe85 rm ability to send resources by slot number; 2024-02-20 10:16:41 -08:00
bjorn a4c57193d5 Details; 2024-01-20 03:42:51 -08:00
Josip Miskovic 3db04db05a Bound check the number of sphere segments 2024-01-19 23:18:58 +01:00
bjorn 62810a195c rm Pass:append;
This was an experiment that was never documented/announced.
2023-11-09 16:08:14 -08:00
bjorn a28d66e3a1 Mesh:setMaterial takes texture too; 2023-10-31 16:08:00 -07:00
bjorn 35628e332c rm deprecated pass stuff; 2023-10-15 14:10:39 -07:00
bjorn 2a3b517334 Fix incorrect depth buffer default in Pass:setCanvas;
If you did newPass(texture) instead of using a table, the pass would not
have a depth buffer instead of using d32f.
2023-10-05 07:20:01 -07:00
bjorn e307487041 Pass:send supports single booleans for push constants;
vectors/arrays/structs with booleans still aren't supported.
2023-10-05 06:36:21 -07:00
bjorn 3041a9a484 Pass:setTallyBuffer(nil) works; 2023-10-02 10:49:54 -07:00
bjorn 9a276e5f9a Tally fixups;
- rm :getTallyData, it's totally lame, just do a readback
  - rm gpu_tally_get_data too, webgpu doesn't support it anyway
- Clamp tally copy count so it doesn't overflow buffer
- Tally buffer offset's gotta be a multiple of 4
- Return nil instead of 2 values when tally buffer isn't set
- Copy correct number of tallies (multiply by view count instead of max
  view count)
- Skip occlusion queries entirely if no tally buffer was set
2023-10-02 10:20:52 -07:00
bjorn 9734ef005c Fix Pass:setClear w/ table of numbers; 2023-10-02 08:47:04 -07:00
bjorn d901481cdc Clear canvas info properly when setting canvas to nil; 2023-09-30 13:19:31 -07:00
bjorn fd2b2e7e4a Render pass samples can't be a boolean that's weird; 2023-09-30 12:31:10 -07:00
bjorn c3c5284f11 Improve viewport/scissor accessors;
- Better validation
- Can set to nil to "disable"
- Getter returns nil when "disabled"
- Negative viewport height works again
2023-09-27 00:24:01 -07:00
bjorn f6216415e6 Rename pass memory stats to indicate they're CPU; 2023-09-11 20:19:36 -07:00
bjorn 9542d46f33 Buffer format cleanup; 2023-09-11 03:01:11 -07:00
bjorn 2d94841db6 Pass:skybox takes nil; 2023-08-21 14:37:05 -07:00
bjorn 4892d228b3 WIP; 2023-07-24 15:34:44 -07:00
bjorn be795c0ebd Change vec3 back to 3 floats; Clean up maf/vectors;
The "vec3 is 4 floats" thing was consistently confusing to people.  It's
reverted everywhere except for Curve.

maf now has full sets of methods for vec2/vec3/vec4, for consistency.

Vector bindings now use luax_readvec* helper functions for the
number/vector variants, and use maf for most functionality, which cleans
things up a lot.
2023-07-10 17:51:24 -07:00
bjorn 10c2c75482 Frustum culling;
- Adds Pass:setViewCull to enable/disable frustum culling.
- Renames Pass:setCullMode to Pass:setFaceCull (with backcompat).

Some stuff currently missing:

- Text is not culled, but should be.
- VR view frusta are not merged yet.
2023-07-07 14:51:22 -07:00
bjorn 38be62c103 Use mat4_fromPose more; 2023-07-03 13:16:35 -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 3804d15184 rm Pass:setVertexFormat and table variant of Pass:mesh;
The complexity/convenience tradeoff isn't satisfactory.
2023-06-23 19:05:42 -07:00
bjorn 313fc953cc Pass:append;
Copies draws from one pass onto another one.  Experimental.
2023-06-09 21:34:39 -07:00
bjorn efb7edeb08 Pass:draw(Texture); 2023-06-09 20:15:22 -07:00
bjorn 6ef16afee3 Tally fixup;
- rm Pass:getTallyCount.  It's unclear if this reports the current tally
  count, or the number of tallies in the last submit.  lovr was even
  getting this confused internally (fixed).
- rm tally index argument from Pass:beginTally and Pass:finishTally.
  The tally index is now an autoincremented value managed internally,
  and both :beginTally/:finishTally return it.  If someone wants to use
  their own indices, a lookup table can be used to do the mapping.
2023-05-31 18:56:09 -07:00
bjorn f9866f6771 Merge branch 'master' into dev 2023-05-17 20:29:10 -07:00
bjorn 4e4184cfc2 Pass:skybox requires a texture; 2023-05-17 20:26:38 -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 f90cd237ca Add new occlusion query API; 2023-05-03 23:08:45 -07:00
bjorn e2ac329475 Add backwards compat variant for Pass:setCanvas; 2023-05-03 19:30:40 -07:00
bjorn 6fe9e0151f Add Pass:barrier function;
Previously, if you wanted to run compute operations that depend on the
results of prior compute operations, you had to put these in 2 different
passes, because logically all of the compute calls in a pass run "at the
same time" (or we're at least giving the GPU the freedom to do that).

Having to set up an entirely new pass just to synchronize 2 :compute
calls is pretty cumbersome, and incurs extra overhead.  It would be
possible to change things so *every* :compute call waits for previous
computes to finish, but this would destroy GPU parallelism.

The Pass:barrier method lets compute calls within a pass synchronize
with each other, without requiring multiple passes.  Adding a barrier
basically means "hey, wait for all the :compute calls before the barrier
to finish before running future :computes".

This lets things remain highly parallel but allows them to be easily
synchronized when needed.
2023-05-03 16:45:01 -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 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 2d8db03faa
Merge pull request #642 from bjornbytes/buffer-improvements
Buffer Format Improvements
2023-03-21 23:07:20 -07:00
bjorn f32800c044 Clean up Model lookeruppers; Model:getMaterial takes string; 2023-03-21 21:30:11 -07:00
bjorn 4d5e3f03b9 Change the way a single stencil action is used;
When a single stencil action is provided in Pass:setStencilWrite, it now
maps to just passOp instead of all the ops.  This matches expectations
and previous versions.
2023-03-21 21:13:38 -07:00
bjorn fa0576e42c Fix some magic numbers; 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 d8e856e6e0
Merge pull request #645 from mcclure/size-t-narrow
Address various MSVC warnings (casts, comparisons, function pointers)
2023-03-03 17:25:48 -08:00
Bjorn 5fa53b3812
Update error message; 2023-03-03 17:17:49 -08:00
mcc e4e8c5476b Warning fixes (fix style) 2023-03-03 15:48:41 -05:00
bjorn ccffd3c1b2 Merge branch 'master' into dev 2023-03-02 18:31:20 -08:00
mcc a5216347a0 Address size_t narrowing warnings in MSVC by adding casts. Add some asserts to make sure the casts are safe. 2023-03-01 18:15:04 -05:00
bjorn 4afb0ae2bf Fix Pass:clear(buffer); 2023-02-25 00:01:31 -08:00