• 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 static GstVulkanQueue *queue;
32 
33 static void
setup(void)34 setup (void)
35 {
36   instance = gst_vulkan_instance_new ();
37   fail_unless (gst_vulkan_instance_open (instance, NULL));
38   device = gst_vulkan_device_new_with_index (instance, 0);
39   fail_unless (gst_vulkan_device_open (device, NULL));
40   /* family and id may be wrong! */
41   queue = gst_vulkan_device_get_queue (device, 0, 0);
42   fail_unless (GST_IS_VULKAN_QUEUE (queue));
43 }
44 
45 static void
teardown(void)46 teardown (void)
47 {
48   gst_object_unref (instance);
49   gst_object_unref (device);
50   gst_object_unref (queue);
51 }
52 
GST_START_TEST(test_new)53 GST_START_TEST (test_new)
54 {
55   GstVulkanCommandPool *pool =
56       gst_vulkan_queue_create_command_pool (queue, NULL);
57   fail_unless (GST_IS_VULKAN_COMMAND_POOL (pool));
58   gst_object_unref (pool);
59 }
60 
61 GST_END_TEST;
62 
63 static void
buffer_destroy_notify(gpointer ptr)64 buffer_destroy_notify (gpointer ptr)
65 {
66   gint *counter = ptr;
67 
68   GST_DEBUG ("buffer destroyed");
69 
70   *counter += 1;
71 }
72 
73 /* Track when a buffer is destroyed. The counter will be increased if the
74  * buffer is finalized (but not if it was re-surrected in dispose and put
75  * back into the buffer pool. */
76 static void
buffer_track_destroy(GstVulkanCommandBuffer * buf,gint * counter)77 buffer_track_destroy (GstVulkanCommandBuffer * buf, gint * counter)
78 {
79   gst_mini_object_set_qdata (GST_MINI_OBJECT (buf),
80       g_quark_from_static_string ("TestTracker"),
81       counter, buffer_destroy_notify);
82 }
83 
GST_START_TEST(test_recycle)84 GST_START_TEST (test_recycle)
85 {
86   GstVulkanCommandPool *pool =
87       gst_vulkan_queue_create_command_pool (queue, NULL);
88   GstVulkanCommandBuffer *cmd;
89   gint dcount = 0;
90 
91   fail_unless (GST_IS_VULKAN_COMMAND_POOL (pool));
92   cmd = gst_vulkan_command_pool_create (pool, NULL);
93   fail_unless (cmd != NULL);
94   buffer_track_destroy (cmd, &dcount);
95 
96   gst_vulkan_command_buffer_unref (cmd);
97   /* buffer should have been recycled */
98   fail_unless (dcount == 0);
99 
100   gst_object_unref (pool);
101 }
102 
103 GST_END_TEST;
104 
105 static Suite *
vkcommandpool_suite(void)106 vkcommandpool_suite (void)
107 {
108   Suite *s = suite_create ("vkcommandpool");
109   TCase *tc_basic = tcase_create ("general");
110   gboolean have_instance;
111 
112   suite_add_tcase (s, tc_basic);
113   tcase_add_checked_fixture (tc_basic, setup, teardown);
114 
115   /* FIXME: CI doesn't have a software vulkan renderer (and none exists currently) */
116   instance = gst_vulkan_instance_new ();
117   have_instance = gst_vulkan_instance_open (instance, NULL);
118   gst_object_unref (instance);
119   if (have_instance) {
120     tcase_add_test (tc_basic, test_new);
121     tcase_add_test (tc_basic, test_recycle);
122   }
123 
124   return s;
125 }
126 
127 GST_CHECK_MAIN (vkcommandpool);
128