1 /*
2  * GStreamer
3  * Copyright (C) 2015 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., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 #ifndef _VK_MACROS_H_
21 #define _VK_MACROS_H_
22 
23 #include <gst/gst.h>
24 #include <vk.h>
25 
26 G_BEGIN_DECLS
27 
28 #define GST_VK_STRUCT_1(a) \
29   { a }
30 #define GST_VK_STRUCT_2(a, b) \
31   { a, b }
32 #define GST_VK_STRUCT_3(a, b, c) \
33   { a, b, c }
34 #define GST_VK_STRUCT_4(a, b, c, d) \
35   { a, b, c, d }
36 #define GST_VK_STRUCT_5(a, b, c, d, e) \
37   { a, b, c, d, e }
38 #define GST_VK_STRUCT_6(a, b, c, d, e, f) \
39   { a, b, c, d, e, f }
40 #define GST_VK_STRUCT_7(a, b, c, d, e, f, g) \
41   { a, b, c, d, e, f, g }
42 #define GST_VK_STRUCT_8(a, b, c, d, e, f, g, h) \
43   { a, b, c, d, e, f, g, h }
44 
45 #define GST_VK_BUFFER_IMAGE_COPY_INIT GST_VK_STRUCT_6
46 #define GST_VK_BUFFER_IMAGE_COPY(info,bufferOffset_,bufferRowLength_,bufferImageHeight_,imageSubresourceLayers_,imageOffset_,imageExtent_) \
47   G_STMT_START { \
48     VkImageSubresourceLayers sub = imageSubresourceLayers_; \
49     VkOffset3D offset = imageOffset_; \
50     VkExtent3D extent = imageExtent_; \
51     VkBufferImageCopy tmp = GST_VK_BUFFER_IMAGE_COPY_INIT(bufferOffset_,bufferRowLength_,bufferImageHeight_,sub,offset,extent); \
52     (region) = tmp; \
53   } G_STMT_END
54 
55 #define GST_VK_COMPONENT_MAPPING_INIT GST_VK_STRUCT_4
56 #define GST_VK_COMPONENT_MAPPING(component, r_, g_, b_, a_) \
57   G_STMT_START { \
58     VkComponentMapping tmp = GST_VK_COMPONENT_MAPPING_INIT(r_, g_, b_, a_); \
59     (component) = tmp; \
60   } G_STMT_END
61 
62 #define GST_VK_EXTENT3D_INIT GST_VK_STRUCT_3
63 #define GST_VK_EXTENT3D(extent,w,h,d) \
64   G_STMT_START { \
65     VkExtent3D tmp = GST_VK_EXTENT3D_INIT(w,h,d); \
66     (extent) = tmp; \
67   } G_STMT_END
68 
69 #define GST_VK_IMAGE_COPY_INIT GST_VK_STRUCT_5
70 #define GST_VK_IMAGE_COPY(copy,srcSubresource_,srcOffset_,dstSubresource_,dstOffset_,extent_) \
71   G_STMT_START { \
72     VkImageSubresourceLayers src_res = srcSubresource_; \
73     VkOffset3D src_offset = srcOffset_; \
74     VkImageSubresourceLayers dst_res = dstSubresource_; \
75     VkOffset3D dst_offset = dstOffset_; \
76     VkExtent3D ext = extent_; \
77     VkImageCopy tmp = GST_VK_IMAGE_COPY_INIT(src_res,src_offset,dst_res,dst_offset,ext); \
78     (copy) = tmp; \
79   } G_STMT_END
80 
81 #define GST_VK_IMAGE_BLIT_INIT GST_VK_STRUCT_6
82 #define GST_VK_IMAGE_BLIT(blit,srcSubresource_,srcOffset_,srcExtent_,dstSubresource_,dstOffset_,dstExtent_) \
83   G_STMT_START { \
84     VkImageSubresourceLayers src_res = srcSubresource_; \
85     VkOffset3D src_offset = srcOffset; \
86     VkExtent3D src_ext = srcExtent_; \
87     VkImageSubresourceLayers dst_res = dstSubresource_; \
88     VkOffset3D dst_offset = dstSubresource_; \
89     VkExtent3D dst_ext = dstExtent_; \
90     VkImageBlit tmp = GST_VK_IMAGE_BLIT_INIT(src_res, src_offset, src_ext, dst_res, dst_offset, dst_ext); \
91     (blit) = tmp; \
92   } G_STMT_END
93 
94 #define GST_VK_IMAGE_SUBRESOURCE_INIT GST_VK_STRUCT_3
95 #define GST_VK_IMAGE_SUBRESOURCE(subresource,aspectMast,mipLevel,arrayLayer) \
96   G_STMT_START { \
97     VkImageSubresource tmp = GST_VK_IMAGE_SUBRESOURCE_INIT(aspectMast,mipLevel,arrayLayer); \
98     (subresource) = tmp; \
99   } G_STMT_END
100 
101 #define GST_VK_IMAGE_SUBRESOURCE_LAYERS_INIT GST_VK_STRUCT_4
102 #define GST_VK_IMAGE_SUBRESOURCE_LAYERS(res,aspect_,mip,base_layer,layer_count) \
103   G_STMT_START { \
104     VkImageSubresourceLayers tmp = GST_VK_IMAGE_SUBRESOURCE_LAYERS_INIT(aspect_,mip,base_layer,layer_count); \
105     (res) = tmp; \
106   } G_STMT_END
107 
108 #define GST_VK_IMAGE_SUBRESOURCE_RANGE_INIT GST_VK_STRUCT_5
109 #define GST_VK_IMAGE_SUBRESOURCE_RANGE(range, aspect, mip_lvl, mip_lvl_count, array, layer_count) \
110   G_STMT_START { \
111     VkImageSubresourceRange tmp = GST_VK_IMAGE_SUBRESOURCE_RANGE_INIT(aspect,mip_lvl,mip_lvl_count,array,layer_count); \
112     (range) = tmp; \
113   } G_STMT_END
114 
115 #define GST_VK_OFFSET3D_INIT GST_VK_STRUCT_3
116 #define GST_VK_OFFSET3D(offset,x_,y_,z_) \
117   G_STMT_START { \
118     VkOffset3D tmp = GST_VK_OFFSET3D_INIT (x_,y_,z_); \
119     (offset) = tmp; \
120   } G_STMT_END
121 
122 G_END_DECLS
123 
124 #endif /*_VK_MACROS_H_ */
125