1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright 2021 Google LLC
3bf215546Sopenharmony_ci * SPDX-License-Identifier: MIT
4bf215546Sopenharmony_ci */
5bf215546Sopenharmony_ci
6bf215546Sopenharmony_ci#ifndef VN_RENDERER_UTIL_H
7bf215546Sopenharmony_ci#define VN_RENDERER_UTIL_H
8bf215546Sopenharmony_ci
9bf215546Sopenharmony_ci#include "vn_renderer.h"
10bf215546Sopenharmony_ci
11bf215546Sopenharmony_ci/* for suballocations of short-lived shmems, not thread-safe */
12bf215546Sopenharmony_cistruct vn_renderer_shmem_pool {
13bf215546Sopenharmony_ci   size_t min_alloc_size;
14bf215546Sopenharmony_ci
15bf215546Sopenharmony_ci   struct vn_renderer_shmem *shmem;
16bf215546Sopenharmony_ci   size_t size;
17bf215546Sopenharmony_ci   size_t used;
18bf215546Sopenharmony_ci};
19bf215546Sopenharmony_ci
20bf215546Sopenharmony_cistatic inline VkResult
21bf215546Sopenharmony_civn_renderer_submit_simple(struct vn_renderer *renderer,
22bf215546Sopenharmony_ci                          const void *cs_data,
23bf215546Sopenharmony_ci                          size_t cs_size)
24bf215546Sopenharmony_ci{
25bf215546Sopenharmony_ci   const struct vn_renderer_submit submit = {
26bf215546Sopenharmony_ci      .batches =
27bf215546Sopenharmony_ci         &(const struct vn_renderer_submit_batch){
28bf215546Sopenharmony_ci            .cs_data = cs_data,
29bf215546Sopenharmony_ci            .cs_size = cs_size,
30bf215546Sopenharmony_ci         },
31bf215546Sopenharmony_ci      .batch_count = 1,
32bf215546Sopenharmony_ci   };
33bf215546Sopenharmony_ci   return vn_renderer_submit(renderer, &submit);
34bf215546Sopenharmony_ci}
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ciVkResult
37bf215546Sopenharmony_civn_renderer_submit_simple_sync(struct vn_renderer *renderer,
38bf215546Sopenharmony_ci                               const void *cs_data,
39bf215546Sopenharmony_ci                               size_t cs_size);
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_civoid
42bf215546Sopenharmony_civn_renderer_shmem_pool_init(struct vn_renderer *renderer,
43bf215546Sopenharmony_ci                            struct vn_renderer_shmem_pool *pool,
44bf215546Sopenharmony_ci                            size_t min_alloc_size);
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_civoid
47bf215546Sopenharmony_civn_renderer_shmem_pool_fini(struct vn_renderer *renderer,
48bf215546Sopenharmony_ci                            struct vn_renderer_shmem_pool *pool);
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_cistruct vn_renderer_shmem *
51bf215546Sopenharmony_civn_renderer_shmem_pool_alloc(struct vn_renderer *renderer,
52bf215546Sopenharmony_ci                             struct vn_renderer_shmem_pool *pool,
53bf215546Sopenharmony_ci                             size_t size,
54bf215546Sopenharmony_ci                             size_t *out_offset);
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_ci#endif /* VN_RENDERER_UTIL_H */
57