[qfcc] Allow aligned despace allocs to be overridden

GLSL (and in the end, spir-v) needs more control over allocation than
does the Ruamoko VM.
This commit is contained in:
Bill Currie 2024-09-10 20:44:51 +09:00
parent 7742450e03
commit f0e770b972
2 changed files with 16 additions and 0 deletions

View file

@ -60,6 +60,19 @@ typedef struct defspace_s {
int size; ///< current high-water mark for alloced data int size; ///< current high-water mark for alloced data
int max_size; ///< size of backing memory, or highwater mark int max_size; ///< size of backing memory, or highwater mark
///< for ds_virtual ///< for ds_virtual
/** Optional callback for aligned allocation of space
Overrides defspace_alloc_aligned_loc.
\param space This defspace.
\param size Size of space to allocate. Must be > 0.
\param alignment Requested alignment for the space. Must be > 0.
\return The offset of the allocated space. If allocation fails
(because the backing memory cannot be grown), it is
treated as an internal error.
*/
int (*alloc_aligned) (struct defspace_s *space, int size,
int alignment);
/** Grow the backing memory of the defspace. /** Grow the backing memory of the defspace.
This function is called when more memory is needed for the space. This function is called when more memory is needed for the space.

View file

@ -159,6 +159,9 @@ defspace_alloc_loc (defspace_t *space, int size)
int int
defspace_alloc_aligned_loc (defspace_t *space, int size, int alignment) defspace_alloc_aligned_loc (defspace_t *space, int size, int alignment)
{ {
if (space->alloc_aligned) {
return space->alloc_aligned (space, size, alignment);
}
int ofs, pad; int ofs, pad;
locref_t *loc; locref_t *loc;
locref_t **l = &space->free_locs; locref_t **l = &space->free_locs;