Commit Graph

36 Commits

Author SHA1 Message Date
bjorn 48c0b4c167 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 21:35:54 -07:00
bjorn 5434dd6add Add sn10x3 data type;
The unpacking code might not be working properly...
2024-01-20 17:39:36 -08:00
bjorn ab3922345f rm deprecated buffer stuff; 2023-10-15 14:08:50 -07:00
bjorn 327b1954ea Readbacks with nesting always use key-value format; 2023-10-04 09:00:36 -07:00
bjorn 805b83601f Buffer readbacks use a more consistent format;
- Always wrapped in table
- Length is always item count
- Scalars are tables of numbers { 1, 2, 3 }
- Vectors are wrapped in tables { { 1, 2 }, { 3, 4 } }
- Compound formats are wrapped in tables, like Mesh vertices
- Structs/nested types are tables
2023-10-04 08:52:05 -07:00
bjorn 842df4b305 Fix buffer readback issues; 2023-10-04 08:52:05 -07:00
bjorn c976b36682 Buffer:getData takes optional index/count arguments;
Also, the Buffer needs to have a format.
2023-10-04 08:52:05 -07:00
bjorn 86db0e3ab5 Buffer:getPointer is renamed to mapData;
It also takes range parameters.

:getPointer is deprecated.
2023-10-04 08:52:05 -07:00
bjorn f318c68796 Buffers can be cleared to values other than zero; 2023-09-18 23:05:27 -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 237a4c19e2 Ignore empty tables when writing arrays; 2023-07-07 14:03:16 -07:00
bjorn e9af3d9167 Fix bug when writing tables of numbers to nested arrays; 2023-07-07 14:02:58 -07:00
bjorn 1ab791d89d Automatically unwrap single-field buffer structs; 2023-07-07 14:02:36 -07:00
bjorn 9d24d0173d Fix issue with lightuserdata in Buffer:setData; 2023-07-05 20:16:16 -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 ce34bf702a Put back absindex in luax_checkstruct;
I thought it was for error messages, it's for correctness.
2023-05-26 16:47:58 -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 01ba9927c1 Fix flipped condition when writing buffer data; 2023-04-02 10:09:06 -07:00
bjorn 8fa46fe236 Reading arrays of vectors works with temp vectors; 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
mcc e4e8c5476b Warning fixes (fix style) 2023-03-03 15:48:41 -05: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 e9776f98c6 Fix compatibility with Lua 5.2, 5.3, 5.4;
Part of this involved putting the Lua header back in api.h, since we
need to know the Lua version to define some macros properly.
2022-11-24 14:33:55 -08:00
bjorn a796c92556 Buffer:clear and Pass:clear(Buffer) use the same units; 2022-09-03 10:49:25 -07:00
bjorn f45706f875 Change Buffer format 'name' to 'location' string;
Name is confusing because it seems like it supports key/value setting.
2022-08-23 19:17:54 -07:00
bjorn 79cd7c10a1 Improve temporary buffers;
- They no longer live in temporary memory, but in a dedicated pool.
- There are error checks for using a temporary buffer after it's invalid
  - However, these are imperfect, and could be improved.  One idea is to
    avoid recycling a temporary buffer until its refcount decays (i.e.
    Lua finally decides to garbage collect it).  This would explode
    memory usage sometimes, so it could only be enabled when
    t.graphics.debug is true.
2022-08-22 20:30:09 -07:00
bjorn f7d7281e70 Add index16/index32 FieldTypes;
Similar to u16/u32 but are 1-indexed when written using tables.
2022-07-10 12:18:31 -07:00
bjorn a8b35074e0 Pass:send supports push constants; 2022-06-05 18:54:26 -07:00
bjorn dbc4f08fa5 You can write quats to buffers now; 2022-04-30 15:58:09 -07:00
bjorn c285d0cdf9 Buffer:getFormat uses string keys; 2022-04-28 20:19:11 -07:00
bjorn e8c809a870 Temporary buffers; 2022-04-27 00:28:39 -07:00
bjorn a3438274b5 Add non-scratchpad Buffers;
This includes the memory allocator and the morgue.

You can't actually write any data to the buffer yet, since we don't have
commands or temp buffers.  Temp buffers (scratchpads) are coming soon.
2022-04-26 15:32:54 -07:00