aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChia-I Wu <olvaffe@gmail.com>2021-08-24 16:30:17 -0700
committerChia-I Wu <olvaffe@gmail.com>2021-09-03 09:28:44 -0700
commit81e081c6e3e5ac4b04cbfca0079a515200428047 (patch)
tree4a9e9b7238174b2f8e015148df2663bb43299c7d
parentbeffc976c99e926ba0589c0530393695ef59224d (diff)
downloadvirglrenderer-81e081c6e3e5ac4b04cbfca0079a515200428047.tar.gz
vkr: add vkr_region
I need to work with ring regions in more places, and need helper functions. vkr_region uses {begin, end}, which seems easier to work with than {offset, size}. Signed-off-by: Chia-I Wu <olvaffe@gmail.com> Reviewed-by: Ryan Neph <ryanneph@google.com> Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
-rw-r--r--src/venus/vkr_common.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/venus/vkr_common.h b/src/venus/vkr_common.h
index eb43bbd4..2abc8d57 100644
--- a/src/venus/vkr_common.h
+++ b/src/venus/vkr_common.h
@@ -59,6 +59,12 @@
return obj; \
}
+/* vkr_region_is_valid should be used to check for overflows */
+#define VKR_REGION_INIT(offset, size) \
+ { \
+ .begin = (offset), .end = (offset) + (size) \
+ }
+
struct vkr_context;
struct vkr_instance;
struct vkr_physical_device;
@@ -146,6 +152,11 @@ struct object_array {
bool objects_stolen;
};
+struct vkr_region {
+ size_t begin;
+ size_t end;
+};
+
extern uint32_t vkr_renderer_flags;
extern uint32_t vkr_debug_flags;
@@ -232,4 +243,46 @@ vkr_object_alloc(size_t size, VkObjectType type, vkr_object_id id)
return obj;
}
+static inline bool
+vkr_region_is_valid(const struct vkr_region *region)
+{
+ return region->begin <= region->end;
+}
+
+static inline size_t
+vkr_region_size(const struct vkr_region *region)
+{
+ return region->end - region->begin;
+}
+
+static inline bool
+vkr_region_is_aligned(const struct vkr_region *region, size_t align)
+{
+ assert(align && util_is_power_of_two(align));
+ return !((region->begin | region->end) & (align - 1));
+}
+
+static inline bool
+vkr_region_is_disjoint(const struct vkr_region *region, const struct vkr_region *other)
+{
+ return region->begin >= other->end || region->end <= other->begin;
+}
+
+static inline bool
+vkr_region_is_within(const struct vkr_region *region, const struct vkr_region *other)
+{
+ /* note that when region regresses to a point at other->end, both this
+ * function and vkr_region_is_disjoint return true
+ */
+ return region->begin >= other->begin && region->end <= other->end;
+}
+
+static inline struct vkr_region
+vkr_region_make_relative(const struct vkr_region *region)
+{
+ return (struct vkr_region){
+ .end = region->end - region->begin,
+ };
+}
+
#endif /* VKR_COMMON_H */