• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  *
3  * Copyright (C) 2019 Matthew Waters <matthew@centricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include <gst/gst.h>
26 #include <gst/check/gstcheck.h>
27 #include <gst/vulkan/vulkan.h>
28 
29 static GstVulkanInstance *instance;
30 static GstVulkanDevice *device;
31 
32 static void
setup(void)33 setup (void)
34 {
35   instance = gst_vulkan_instance_new ();
36   fail_unless (gst_vulkan_instance_open (instance, NULL));
37   device = gst_vulkan_device_new_with_index (instance, 0);
38   fail_unless (gst_vulkan_device_open (device, NULL));
39 }
40 
41 static void
teardown(void)42 teardown (void)
43 {
44   gst_object_unref (instance);
45   gst_object_unref (device);
46 }
47 
48 static void
check_size(GstMemory * mem,gsize at_least)49 check_size (GstMemory * mem, gsize at_least)
50 {
51   gsize size, maxsize, offset;
52 
53   size = gst_memory_get_sizes (mem, &offset, &maxsize);
54   fail_unless (size <= maxsize);
55   fail_unless (size >= at_least);
56 }
57 
GST_START_TEST(test_buffer_mem_allocate)58 GST_START_TEST (test_buffer_mem_allocate)
59 {
60   VkBufferUsageFlags usage;
61   GstVulkanBufferMemory *vk_mem;
62   gsize orig_size = 1024, size, offset;
63   GstMemory *mem;
64 
65   usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
66   mem =
67       gst_vulkan_buffer_memory_alloc (device, orig_size,
68       usage, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
69   fail_unless (gst_is_vulkan_buffer_memory (mem));
70   vk_mem = (GstVulkanBufferMemory *) mem;
71 
72   fail_unless (vk_mem->device == device);
73   fail_unless (vk_mem->usage == usage);
74   fail_unless (vk_mem->vk_mem != NULL);
75 
76   size = gst_memory_get_sizes (mem, &offset, NULL);
77   fail_unless (offset == 0);
78   check_size (mem, orig_size);
79   fail_unless (vk_mem->requirements.size >= size);
80 
81   size = gst_memory_get_sizes ((GstMemory *) vk_mem->vk_mem, &offset, NULL);
82   fail_unless (offset == 0);
83   check_size ((GstMemory *) vk_mem->vk_mem, orig_size);
84 
85   gst_memory_unref (mem);
86 }
87 
88 GST_END_TEST;
89 
90 static Suite *
vkmemory_suite(void)91 vkmemory_suite (void)
92 {
93   Suite *s = suite_create ("vkmemory");
94   TCase *tc_basic = tcase_create ("general");
95   gboolean have_instance;
96 
97   suite_add_tcase (s, tc_basic);
98   tcase_add_checked_fixture (tc_basic, setup, teardown);
99 
100   /* FIXME: CI doesn't have a software vulkan renderer (and none exists currently) */
101   instance = gst_vulkan_instance_new ();
102   have_instance = gst_vulkan_instance_open (instance, NULL);
103   gst_object_unref (instance);
104   if (have_instance) {
105     tcase_add_test (tc_basic, test_buffer_mem_allocate);
106   }
107 
108   return s;
109 }
110 
111 
112 GST_CHECK_MAIN (vkmemory);
113