panfrost: Include sample count in payload estimates
[mesa.git] / src / panfrost / encoder / pan_bo.h
1 /*
2 * © Copyright 2019 Alyssa Rosenzweig
3 * © Copyright 2019 Collabora, Ltd.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 */
25
26 #ifndef __PAN_BO_H__
27 #define __PAN_BO_H__
28
29 #include <panfrost-misc.h>
30 #include "util/list.h"
31 #include "pan_device.h"
32 #include <time.h>
33
34 /* Flags for allocated memory */
35
36 /* This memory region is executable */
37 #define PAN_BO_EXECUTE (1 << 0)
38
39 /* This memory region should be lazily allocated and grow-on-page-fault. Must
40 * be used in conjunction with INVISIBLE */
41 #define PAN_BO_GROWABLE (1 << 1)
42
43 /* This memory region should not be mapped to the CPU */
44 #define PAN_BO_INVISIBLE (1 << 2)
45
46 /* This region may not be used immediately and will not mmap on allocate
47 * (semantically distinct from INVISIBLE, which cannot never be mmaped) */
48 #define PAN_BO_DELAY_MMAP (1 << 3)
49
50 /* BO is shared across processes (imported or exported) and therefore cannot be
51 * cached locally */
52 #define PAN_BO_SHARED (1 << 4)
53
54 /* GPU access flags */
55
56 /* BO is either shared (can be accessed by more than one GPU batch) or private
57 * (reserved by a specific GPU job). */
58 #define PAN_BO_ACCESS_PRIVATE (0 << 0)
59 #define PAN_BO_ACCESS_SHARED (1 << 0)
60
61 /* BO is being read/written by the GPU */
62 #define PAN_BO_ACCESS_READ (1 << 1)
63 #define PAN_BO_ACCESS_WRITE (1 << 2)
64 #define PAN_BO_ACCESS_RW (PAN_BO_ACCESS_READ | PAN_BO_ACCESS_WRITE)
65
66 /* BO is accessed by the vertex/tiler job. */
67 #define PAN_BO_ACCESS_VERTEX_TILER (1 << 3)
68
69 /* BO is accessed by the fragment job. */
70 #define PAN_BO_ACCESS_FRAGMENT (1 << 4)
71
72 struct panfrost_bo {
73 /* Must be first for casting */
74 struct list_head bucket_link;
75
76 /* Used to link the BO to the BO cache LRU list. */
77 struct list_head lru_link;
78
79 /* Store the time this BO was use last, so the BO cache logic can evict
80 * stale BOs.
81 */
82 time_t last_used;
83
84 /* Atomic reference count */
85 int32_t refcnt;
86
87 struct panfrost_device *dev;
88
89 /* Mapping for the entire object (all levels) */
90 uint8_t *cpu;
91
92 /* GPU address for the object */
93 mali_ptr gpu;
94
95 /* Size of all entire trees */
96 size_t size;
97
98 int gem_handle;
99
100 uint32_t flags;
101
102 /* Combination of PAN_BO_ACCESS_{READ,WRITE} flags encoding pending
103 * GPU accesses to this BO. Useful to avoid calling the WAIT_BO ioctl
104 * when the BO is idle.
105 */
106 uint32_t gpu_access;
107 };
108
109 bool
110 panfrost_bo_wait(struct panfrost_bo *bo, int64_t timeout_ns,
111 uint32_t access_type);
112 void
113 panfrost_bo_reference(struct panfrost_bo *bo);
114 void
115 panfrost_bo_unreference(struct panfrost_bo *bo);
116 struct panfrost_bo *
117 panfrost_bo_create(struct panfrost_device *dev, size_t size,
118 uint32_t flags);
119 void
120 panfrost_bo_mmap(struct panfrost_bo *bo);
121 struct panfrost_bo *
122 panfrost_bo_import(struct panfrost_device *dev, int fd);
123 int
124 panfrost_bo_export(struct panfrost_bo *bo);
125 void
126 panfrost_bo_cache_evict_all(struct panfrost_device *dev);
127
128 #endif /* __PAN_BO_H__ */