1 /*
2 * Vulkan Samples
3 *
4 * Copyright (C) 2015-2016 Valve Corporation
5 * Copyright (C) 2015-2016 LunarG, Inc.
6 * Copyright (C) 2015-2018 Google, Inc.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21 /*
22 VULKAN_SAMPLE_DESCRIPTION
23 samples utility functions
24 */
25
26 #ifndef VULKAN_COMMAND_BUFFER_UTILS_H
27 #define VULKAN_COMMAND_BUFFER_UTILS_H
28
29 #include <iostream>
30 #include <sstream>
31 #include <string>
32 #include <vector>
33
34 #include "common/debug.h"
35
36 // glslang has issues with some specific warnings.
37 ANGLE_DISABLE_EXTRA_SEMI_WARNING
38
39 // Pull in upstream glslang header (http://anglebug.com/42266837)
40 #include "glslang/Public/ShaderLang.h"
41
42 ANGLE_REENABLE_EXTRA_SEMI_WARNING
43
44 #ifdef _WIN32
45 # pragma comment(linker, "/subsystem:console")
46 # ifndef WIN32_LEAN_AND_MEAN
47 # define WIN32_LEAN_AND_MEAN
48 # endif
49 # ifndef NOMINMAX
50 # define NOMINMAX /* Don't let Windows define min() or max() */
51 # endif
52 # define APP_NAME_STR_LEN 80
53 #elif defined(__ANDROID__)
54 // Include files for Android
55 # include <android/log.h>
56 # include <unistd.h>
57 # include "util/OSWindow.h"
58 # include "util/android/third_party/android_native_app_glue.h"
59 #else
60 # include <unistd.h>
61 # include "vulkan/vk_sdk_platform.h"
62 #endif
63
64 #include "common/vulkan/vk_headers.h"
65
66 /* Number of descriptor sets needs to be the same at alloc, */
67 /* pipeline layout creation, and descriptor set layout creation */
68 #define NUM_DESCRIPTOR_SETS 1
69
70 /* Number of samples needs to be the same at image creation, */
71 /* renderpass creation and pipeline creation. */
72 #define NUM_SAMPLES VK_SAMPLE_COUNT_1_BIT
73
74 /* Number of viewports and number of scissors have to be the same */
75 /* at pipeline creation and in any call to set them dynamically */
76 /* They also have to be the same as each other */
77 #define NUM_VIEWPORTS 1
78 #define NUM_SCISSORS NUM_VIEWPORTS
79
80 /* Amount of time, in nanoseconds, to wait for a command buffer to complete */
81 #define FENCE_TIMEOUT 100000000
82
83 #ifdef __ANDROID__
84 # define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "VK-SAMPLE", __VA_ARGS__))
85 # define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "VK-SAMPLE", __VA_ARGS__))
86 # define GET_INSTANCE_PROC_ADDR(inst, entrypoint) \
87 { \
88 info.fp##entrypoint = \
89 (PFN_vk##entrypoint)vkGetInstanceProcAddr(inst, "vk" #entrypoint); \
90 if (info.fp##entrypoint == NULL) \
91 { \
92 std::cout << "vkGetDeviceProcAddr failed to find vk" #entrypoint; \
93 exit(-1); \
94 } \
95 }
96
97 #endif
98
99 /*
100 * Keep each of our swap chain buffers' image, command buffer and view in one
101 * spot
102 */
103 typedef struct _swap_chain_buffers
104 {
105 VkImage image;
106 VkImageView view;
107 VkDeviceMemory mem;
108 } swap_chain_buffer;
109
110 /*
111 * A layer can expose extensions, keep track of those
112 * extensions here.
113 */
114 typedef struct
115 {
116 VkLayerProperties properties;
117 std::vector<VkExtensionProperties> instance_extensions;
118 std::vector<VkExtensionProperties> device_extensions;
119 } layer_properties;
120
121 /*
122 * Structure for tracking information used / created / modified
123 * by utility functions.
124 */
125 struct sample_info
126 {
127 #ifdef _WIN32
128 # define APP_NAME_STR_LEN 80
129 HINSTANCE connection; // hInstance - Windows Instance
130 char name[APP_NAME_STR_LEN]; // Name to put on the window/icon
131 HWND window; // hWnd - window handle
132 #elif defined(__ANDROID__)
133 OSWindow *mOSWindow;
134 PFN_vkCreateAndroidSurfaceKHR fpCreateAndroidSurfaceKHR;
135 #elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
136 wl_display *display;
137 wl_registry *registry;
138 wl_compositor *compositor;
139 wl_surface *window;
140 wl_shell *shell;
141 wl_shell_surface *shell_surface;
142 #else
143 xcb_connection_t *connection;
144 xcb_screen_t *screen;
145 xcb_window_t window;
146 xcb_intern_atom_reply_t *atom_wm_delete_window;
147 #endif // _WIN32
148 VkSurfaceKHR surface;
149 bool prepared;
150 bool use_staging_buffer;
151 bool save_images;
152
153 std::vector<const char *> instance_layer_names;
154 std::vector<const char *> instance_extension_names;
155 std::vector<layer_properties> instance_layer_properties;
156 std::vector<VkExtensionProperties> instance_extension_properties;
157 VkInstance inst;
158
159 std::vector<const char *> device_extension_names;
160 std::vector<VkExtensionProperties> device_extension_properties;
161 std::vector<VkPhysicalDevice> gpus;
162 VkDevice device;
163 VkQueue graphics_queue;
164 VkQueue present_queue;
165 uint32_t graphics_queue_family_index;
166 uint32_t present_queue_family_index;
167 VkPhysicalDeviceProperties gpu_props;
168 std::vector<VkQueueFamilyProperties> queue_props;
169 VkPhysicalDeviceMemoryProperties memory_properties;
170
171 VkFramebuffer *framebuffers;
172 int width, height;
173 VkFormat format;
174
175 uint32_t swapchainImageCount;
176 VkSwapchainKHR swap_chain;
177 std::vector<swap_chain_buffer> buffers;
178 VkSemaphore imageAcquiredSemaphore;
179
180 VkCommandPool cmd_pool;
181
182 struct
183 {
184 VkFormat format;
185
186 VkImage image;
187 VkDeviceMemory mem;
188 VkImageView view;
189 } depth;
190
191 struct
192 {
193 VkBuffer buf;
194 VkDeviceMemory mem;
195 VkDescriptorBufferInfo buffer_info;
196 } uniform_data;
197
198 struct
199 {
200 VkBuffer buf;
201 VkDeviceMemory mem;
202 VkDescriptorBufferInfo buffer_info;
203 } vertex_buffer;
204 VkVertexInputBindingDescription vi_binding;
205 VkVertexInputAttributeDescription vi_attribs[2];
206
207 std::vector<float> MVP;
208
209 VkCommandBuffer cmd; // Buffer for initialization commands
210 std::vector<VkCommandBuffer> cmds; // Place to hold a lot of buffers
211 std::vector<VkCommandBuffer> cmd2s; // Place to hold a lot of 2nd buffers
212 VkPipelineLayout pipeline_layout;
213 std::vector<VkDescriptorSetLayout> desc_layout;
214 VkPipelineCache pipelineCache;
215 VkRenderPass render_pass;
216 VkPipeline pipeline;
217
218 VkPipelineShaderStageCreateInfo shaderStages[2];
219
220 VkDescriptorPool desc_pool;
221 std::vector<VkDescriptorSet> desc_set;
222
223 PFN_vkCreateDebugReportCallbackEXT dbgCreateDebugReportCallback;
224 PFN_vkDestroyDebugReportCallbackEXT dbgDestroyDebugReportCallback;
225 PFN_vkDebugReportMessageEXT dbgBreakCallback;
226 std::vector<VkDebugReportCallbackEXT> debug_report_callbacks;
227
228 uint32_t current_buffer;
229 uint32_t queue_family_count;
230
231 VkViewport viewport;
232 VkRect2D scissor;
233 };
234
235 struct Vertex
236 {
237 float posX, posY, posZ, posW; // Position data
238 float r, g, b, a; // Color
239 };
240
241 struct VertexUV
242 {
243 float posX, posY, posZ, posW; // Position data
244 float u, v; // texture u,v
245 };
246
247 #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
248 #define UV(_u_, _v_) (_u_), (_v_)
249
250 static const Vertex g_vbData[] = {
251 {XYZ1(-1, -1, -1), XYZ1(0.f, 0.f, 0.f)}, {XYZ1(1, -1, -1), XYZ1(1.f, 0.f, 0.f)},
252 {XYZ1(-1, 1, -1), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(-1, 1, -1), XYZ1(0.f, 1.f, 0.f)},
253 {XYZ1(1, -1, -1), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, 1, -1), XYZ1(1.f, 1.f, 0.f)},
254
255 {XYZ1(-1, -1, 1), XYZ1(0.f, 0.f, 1.f)}, {XYZ1(-1, 1, 1), XYZ1(0.f, 1.f, 1.f)},
256 {XYZ1(1, -1, 1), XYZ1(1.f, 0.f, 1.f)}, {XYZ1(1, -1, 1), XYZ1(1.f, 0.f, 1.f)},
257 {XYZ1(-1, 1, 1), XYZ1(0.f, 1.f, 1.f)}, {XYZ1(1, 1, 1), XYZ1(1.f, 1.f, 1.f)},
258
259 {XYZ1(1, 1, 1), XYZ1(1.f, 1.f, 1.f)}, {XYZ1(1, 1, -1), XYZ1(1.f, 1.f, 0.f)},
260 {XYZ1(1, -1, 1), XYZ1(1.f, 0.f, 1.f)}, {XYZ1(1, -1, 1), XYZ1(1.f, 0.f, 1.f)},
261 {XYZ1(1, 1, -1), XYZ1(1.f, 1.f, 0.f)}, {XYZ1(1, -1, -1), XYZ1(1.f, 0.f, 0.f)},
262
263 {XYZ1(-1, 1, 1), XYZ1(0.f, 1.f, 1.f)}, {XYZ1(-1, -1, 1), XYZ1(0.f, 0.f, 1.f)},
264 {XYZ1(-1, 1, -1), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(-1, 1, -1), XYZ1(0.f, 1.f, 0.f)},
265 {XYZ1(-1, -1, 1), XYZ1(0.f, 0.f, 1.f)}, {XYZ1(-1, -1, -1), XYZ1(0.f, 0.f, 0.f)},
266
267 {XYZ1(1, 1, 1), XYZ1(1.f, 1.f, 1.f)}, {XYZ1(-1, 1, 1), XYZ1(0.f, 1.f, 1.f)},
268 {XYZ1(1, 1, -1), XYZ1(1.f, 1.f, 0.f)}, {XYZ1(1, 1, -1), XYZ1(1.f, 1.f, 0.f)},
269 {XYZ1(-1, 1, 1), XYZ1(0.f, 1.f, 1.f)}, {XYZ1(-1, 1, -1), XYZ1(0.f, 1.f, 0.f)},
270
271 {XYZ1(1, -1, 1), XYZ1(1.f, 0.f, 1.f)}, {XYZ1(1, -1, -1), XYZ1(1.f, 0.f, 0.f)},
272 {XYZ1(-1, -1, 1), XYZ1(0.f, 0.f, 1.f)}, {XYZ1(-1, -1, 1), XYZ1(0.f, 0.f, 1.f)},
273 {XYZ1(1, -1, -1), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(-1, -1, -1), XYZ1(0.f, 0.f, 0.f)},
274 };
275
276 static const Vertex g_vb_solid_face_colors_Data[] = {
277 // red face
278 {XYZ1(-1, -1, 1), XYZ1(1.f, 0.f, 0.f)},
279 {XYZ1(-1, 1, 1), XYZ1(1.f, 0.f, 0.f)},
280 {XYZ1(1, -1, 1), XYZ1(1.f, 0.f, 0.f)},
281 {XYZ1(1, -1, 1), XYZ1(1.f, 0.f, 0.f)},
282 {XYZ1(-1, 1, 1), XYZ1(1.f, 0.f, 0.f)},
283 {XYZ1(1, 1, 1), XYZ1(1.f, 0.f, 0.f)},
284 // green face
285 {XYZ1(-1, -1, -1), XYZ1(0.f, 1.f, 0.f)},
286 {XYZ1(1, -1, -1), XYZ1(0.f, 1.f, 0.f)},
287 {XYZ1(-1, 1, -1), XYZ1(0.f, 1.f, 0.f)},
288 {XYZ1(-1, 1, -1), XYZ1(0.f, 1.f, 0.f)},
289 {XYZ1(1, -1, -1), XYZ1(0.f, 1.f, 0.f)},
290 {XYZ1(1, 1, -1), XYZ1(0.f, 1.f, 0.f)},
291 // blue face
292 {XYZ1(-1, 1, 1), XYZ1(0.f, 0.f, 1.f)},
293 {XYZ1(-1, -1, 1), XYZ1(0.f, 0.f, 1.f)},
294 {XYZ1(-1, 1, -1), XYZ1(0.f, 0.f, 1.f)},
295 {XYZ1(-1, 1, -1), XYZ1(0.f, 0.f, 1.f)},
296 {XYZ1(-1, -1, 1), XYZ1(0.f, 0.f, 1.f)},
297 {XYZ1(-1, -1, -1), XYZ1(0.f, 0.f, 1.f)},
298 // yellow face
299 {XYZ1(1, 1, 1), XYZ1(1.f, 1.f, 0.f)},
300 {XYZ1(1, 1, -1), XYZ1(1.f, 1.f, 0.f)},
301 {XYZ1(1, -1, 1), XYZ1(1.f, 1.f, 0.f)},
302 {XYZ1(1, -1, 1), XYZ1(1.f, 1.f, 0.f)},
303 {XYZ1(1, 1, -1), XYZ1(1.f, 1.f, 0.f)},
304 {XYZ1(1, -1, -1), XYZ1(1.f, 1.f, 0.f)},
305 // magenta face
306 {XYZ1(1, 1, 1), XYZ1(1.f, 0.f, 1.f)},
307 {XYZ1(-1, 1, 1), XYZ1(1.f, 0.f, 1.f)},
308 {XYZ1(1, 1, -1), XYZ1(1.f, 0.f, 1.f)},
309 {XYZ1(1, 1, -1), XYZ1(1.f, 0.f, 1.f)},
310 {XYZ1(-1, 1, 1), XYZ1(1.f, 0.f, 1.f)},
311 {XYZ1(-1, 1, -1), XYZ1(1.f, 0.f, 1.f)},
312 // cyan face
313 {XYZ1(1, -1, 1), XYZ1(0.f, 1.f, 1.f)},
314 {XYZ1(1, -1, -1), XYZ1(0.f, 1.f, 1.f)},
315 {XYZ1(-1, -1, 1), XYZ1(0.f, 1.f, 1.f)},
316 {XYZ1(-1, -1, 1), XYZ1(0.f, 1.f, 1.f)},
317 {XYZ1(1, -1, -1), XYZ1(0.f, 1.f, 1.f)},
318 {XYZ1(-1, -1, -1), XYZ1(0.f, 1.f, 1.f)},
319 };
320
321 static const VertexUV g_vb_texture_Data[] = {
322 // left face
323 {XYZ1(-1, -1, -1), UV(1.f, 0.f)}, // lft-top-front
324 {XYZ1(-1, 1, 1), UV(0.f, 1.f)}, // lft-btm-back
325 {XYZ1(-1, -1, 1), UV(0.f, 0.f)}, // lft-top-back
326 {XYZ1(-1, 1, 1), UV(0.f, 1.f)}, // lft-btm-back
327 {XYZ1(-1, -1, -1), UV(1.f, 0.f)}, // lft-top-front
328 {XYZ1(-1, 1, -1), UV(1.f, 1.f)}, // lft-btm-front
329 // front face
330 {XYZ1(-1, -1, -1), UV(0.f, 0.f)}, // lft-top-front
331 {XYZ1(1, -1, -1), UV(1.f, 0.f)}, // rgt-top-front
332 {XYZ1(1, 1, -1), UV(1.f, 1.f)}, // rgt-btm-front
333 {XYZ1(-1, -1, -1), UV(0.f, 0.f)}, // lft-top-front
334 {XYZ1(1, 1, -1), UV(1.f, 1.f)}, // rgt-btm-front
335 {XYZ1(-1, 1, -1), UV(0.f, 1.f)}, // lft-btm-front
336 // top face
337 {XYZ1(-1, -1, -1), UV(0.f, 1.f)}, // lft-top-front
338 {XYZ1(1, -1, 1), UV(1.f, 0.f)}, // rgt-top-back
339 {XYZ1(1, -1, -1), UV(1.f, 1.f)}, // rgt-top-front
340 {XYZ1(-1, -1, -1), UV(0.f, 1.f)}, // lft-top-front
341 {XYZ1(-1, -1, 1), UV(0.f, 0.f)}, // lft-top-back
342 {XYZ1(1, -1, 1), UV(1.f, 0.f)}, // rgt-top-back
343 // bottom face
344 {XYZ1(-1, 1, -1), UV(0.f, 0.f)}, // lft-btm-front
345 {XYZ1(1, 1, 1), UV(1.f, 1.f)}, // rgt-btm-back
346 {XYZ1(-1, 1, 1), UV(0.f, 1.f)}, // lft-btm-back
347 {XYZ1(-1, 1, -1), UV(0.f, 0.f)}, // lft-btm-front
348 {XYZ1(1, 1, -1), UV(1.f, 0.f)}, // rgt-btm-front
349 {XYZ1(1, 1, 1), UV(1.f, 1.f)}, // rgt-btm-back
350 // right face
351 {XYZ1(1, 1, -1), UV(0.f, 1.f)}, // rgt-btm-front
352 {XYZ1(1, -1, 1), UV(1.f, 0.f)}, // rgt-top-back
353 {XYZ1(1, 1, 1), UV(1.f, 1.f)}, // rgt-btm-back
354 {XYZ1(1, -1, 1), UV(1.f, 0.f)}, // rgt-top-back
355 {XYZ1(1, 1, -1), UV(0.f, 1.f)}, // rgt-btm-front
356 {XYZ1(1, -1, -1), UV(0.f, 0.f)}, // rgt-top-front
357 // back face
358 {XYZ1(-1, 1, 1), UV(1.f, 1.f)}, // lft-btm-back
359 {XYZ1(1, 1, 1), UV(0.f, 1.f)}, // rgt-btm-back
360 {XYZ1(-1, -1, 1), UV(1.f, 0.f)}, // lft-top-back
361 {XYZ1(-1, -1, 1), UV(1.f, 0.f)}, // lft-top-back
362 {XYZ1(1, 1, 1), UV(0.f, 1.f)}, // rgt-btm-back
363 {XYZ1(1, -1, 1), UV(0.f, 0.f)}, // rgt-top-back
364 };
365
init_resources(TBuiltInResource & Resources)366 inline void init_resources(TBuiltInResource &Resources)
367 {
368 Resources.maxLights = 32;
369 Resources.maxClipPlanes = 6;
370 Resources.maxTextureUnits = 32;
371 Resources.maxTextureCoords = 32;
372 Resources.maxVertexAttribs = 64;
373 Resources.maxVertexUniformComponents = 4096;
374 Resources.maxVaryingFloats = 64;
375 Resources.maxVertexTextureImageUnits = 32;
376 Resources.maxCombinedTextureImageUnits = 80;
377 Resources.maxTextureImageUnits = 32;
378 Resources.maxFragmentUniformComponents = 4096;
379 Resources.maxDrawBuffers = 32;
380 Resources.maxVertexUniformVectors = 128;
381 Resources.maxVaryingVectors = 8;
382 Resources.maxFragmentUniformVectors = 16;
383 Resources.maxVertexOutputVectors = 16;
384 Resources.maxFragmentInputVectors = 15;
385 Resources.minProgramTexelOffset = -8;
386 Resources.maxProgramTexelOffset = 7;
387 Resources.maxClipDistances = 8;
388 Resources.maxComputeWorkGroupCountX = 65535;
389 Resources.maxComputeWorkGroupCountY = 65535;
390 Resources.maxComputeWorkGroupCountZ = 65535;
391 Resources.maxComputeWorkGroupSizeX = 1024;
392 Resources.maxComputeWorkGroupSizeY = 1024;
393 Resources.maxComputeWorkGroupSizeZ = 64;
394 Resources.maxComputeUniformComponents = 1024;
395 Resources.maxComputeTextureImageUnits = 16;
396 Resources.maxComputeImageUniforms = 8;
397 Resources.maxComputeAtomicCounters = 8;
398 Resources.maxComputeAtomicCounterBuffers = 1;
399 Resources.maxVaryingComponents = 60;
400 Resources.maxVertexOutputComponents = 64;
401 Resources.maxGeometryInputComponents = 64;
402 Resources.maxGeometryOutputComponents = 128;
403 Resources.maxFragmentInputComponents = 128;
404 Resources.maxImageUnits = 8;
405 Resources.maxCombinedImageUnitsAndFragmentOutputs = 8;
406 Resources.maxCombinedShaderOutputResources = 8;
407 Resources.maxImageSamples = 0;
408 Resources.maxVertexImageUniforms = 0;
409 Resources.maxTessControlImageUniforms = 0;
410 Resources.maxTessEvaluationImageUniforms = 0;
411 Resources.maxGeometryImageUniforms = 0;
412 Resources.maxFragmentImageUniforms = 8;
413 Resources.maxCombinedImageUniforms = 8;
414 Resources.maxGeometryTextureImageUnits = 16;
415 Resources.maxGeometryOutputVertices = 256;
416 Resources.maxGeometryTotalOutputComponents = 1024;
417 Resources.maxGeometryUniformComponents = 1024;
418 Resources.maxGeometryVaryingComponents = 64;
419 Resources.maxTessControlInputComponents = 128;
420 Resources.maxTessControlOutputComponents = 128;
421 Resources.maxTessControlTextureImageUnits = 16;
422 Resources.maxTessControlUniformComponents = 1024;
423 Resources.maxTessControlTotalOutputComponents = 4096;
424 Resources.maxTessEvaluationInputComponents = 128;
425 Resources.maxTessEvaluationOutputComponents = 128;
426 Resources.maxTessEvaluationTextureImageUnits = 16;
427 Resources.maxTessEvaluationUniformComponents = 1024;
428 Resources.maxTessPatchComponents = 120;
429 Resources.maxPatchVertices = 32;
430 Resources.maxTessGenLevel = 64;
431 Resources.maxViewports = 16;
432 Resources.maxVertexAtomicCounters = 0;
433 Resources.maxTessControlAtomicCounters = 0;
434 Resources.maxTessEvaluationAtomicCounters = 0;
435 Resources.maxGeometryAtomicCounters = 0;
436 Resources.maxFragmentAtomicCounters = 8;
437 Resources.maxCombinedAtomicCounters = 8;
438 Resources.maxAtomicCounterBindings = 1;
439 Resources.maxVertexAtomicCounterBuffers = 0;
440 Resources.maxTessControlAtomicCounterBuffers = 0;
441 Resources.maxTessEvaluationAtomicCounterBuffers = 0;
442 Resources.maxGeometryAtomicCounterBuffers = 0;
443 Resources.maxFragmentAtomicCounterBuffers = 1;
444 Resources.maxCombinedAtomicCounterBuffers = 1;
445 Resources.maxAtomicCounterBufferSize = 16384;
446 Resources.maxTransformFeedbackBuffers = 4;
447 Resources.maxTransformFeedbackInterleavedComponents = 64;
448 Resources.maxCullDistances = 8;
449 Resources.maxCombinedClipAndCullDistances = 8;
450 Resources.maxSamples = 4;
451 Resources.limits.nonInductiveForLoops = 1;
452 Resources.limits.whileLoops = 1;
453 Resources.limits.doWhileLoops = 1;
454 Resources.limits.generalUniformIndexing = 1;
455 Resources.limits.generalAttributeMatrixVectorIndexing = 1;
456 Resources.limits.generalVaryingIndexing = 1;
457 Resources.limits.generalSamplerIndexing = 1;
458 Resources.limits.generalVariableIndexing = 1;
459 Resources.limits.generalConstantMatrixVectorIndexing = 1;
460 }
461
FindLanguage(const VkShaderStageFlagBits shader_type)462 inline EShLanguage FindLanguage(const VkShaderStageFlagBits shader_type)
463 {
464 switch (shader_type)
465 {
466 case VK_SHADER_STAGE_VERTEX_BIT:
467 return EShLangVertex;
468
469 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
470 return EShLangTessControl;
471
472 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
473 return EShLangTessEvaluation;
474
475 case VK_SHADER_STAGE_GEOMETRY_BIT:
476 return EShLangGeometry;
477
478 case VK_SHADER_STAGE_FRAGMENT_BIT:
479 return EShLangFragment;
480
481 case VK_SHADER_STAGE_COMPUTE_BIT:
482 return EShLangCompute;
483
484 default:
485 return EShLangVertex;
486 }
487 }
488
489 VkResult init_global_extension_properties(layer_properties &layer_props);
490
491 VkResult init_global_layer_properties(sample_info &info);
492
493 VkResult init_device_extension_properties(struct sample_info &info, layer_properties &layer_props);
494
495 void init_instance_extension_names(struct sample_info &info);
496 VkResult init_instance(struct sample_info &info, char const *const app_short_name);
497 void init_device_extension_names(struct sample_info &info);
498 VkResult init_device(struct sample_info &info);
499 VkResult init_enumerate_device(struct sample_info &info, uint32_t gpu_count = 1);
500 VkBool32 demo_check_layers(const std::vector<layer_properties> &layer_props,
501 const std::vector<const char *> &layer_names);
502 void init_connection(struct sample_info &info);
503 void init_window(struct sample_info &info);
504 void init_swapchain_extension(struct sample_info &info);
505 void init_command_pool(struct sample_info &info, VkCommandPoolCreateFlags cmd_pool_create_flags);
506 void init_command_buffer(struct sample_info &info);
507 void init_command_buffer_array(struct sample_info &info, int numBuffers);
508 void init_command_buffer2_array(struct sample_info &info, int numBuffers);
509 void execute_begin_command_buffer(struct sample_info &info);
510 void init_device_queue(struct sample_info &info);
511 void init_swap_chain(struct sample_info &info,
512 VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
513 VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
514 void init_depth_buffer(struct sample_info &info);
515 void init_uniform_buffer(struct sample_info &info);
516 void init_descriptor_and_pipeline_layouts(
517 struct sample_info &info,
518 bool use_texture,
519 VkDescriptorSetLayoutCreateFlags descSetLayoutCreateFlags = 0);
520 void init_renderpass(struct sample_info &info,
521 bool include_depth,
522 bool clear = true,
523 VkImageLayout finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
524 void init_vertex_buffer(struct sample_info &info,
525 const void *vertexData,
526 uint32_t dataSize,
527 uint32_t dataStride,
528 bool use_texture);
529 void init_framebuffers(struct sample_info &info, bool include_depth);
530 void init_descriptor_pool(struct sample_info &info, bool use_texture);
531 void init_descriptor_set(struct sample_info &info);
532 void init_shaders(struct sample_info &info, const char *vertShaderText, const char *fragShaderText);
533 void init_pipeline_cache(struct sample_info &info);
534 void init_pipeline(struct sample_info &info, VkBool32 include_depth, VkBool32 include_vi = true);
535 void init_sampler(struct sample_info &info, VkSampler &sampler);
536 void init_viewports(struct sample_info &info);
537 void init_viewports_array(struct sample_info &info, int index);
538 void init_viewports2_array(struct sample_info &info, int index);
539 void init_scissors(struct sample_info &info);
540 void init_scissors_array(struct sample_info &info, int index);
541 void init_scissors2_array(struct sample_info &info, int index);
542 void init_window_size(struct sample_info &info, int32_t default_width, int32_t default_height);
543 void destroy_pipeline(struct sample_info &info);
544 void destroy_pipeline_cache(struct sample_info &info);
545 void destroy_descriptor_pool(struct sample_info &info);
546 void destroy_vertex_buffer(struct sample_info &info);
547 void destroy_framebuffers(struct sample_info &info);
548 void destroy_shaders(struct sample_info &info);
549 void destroy_renderpass(struct sample_info &info);
550 void destroy_descriptor_and_pipeline_layouts(struct sample_info &info);
551 void destroy_uniform_buffer(struct sample_info &info);
552 void destroy_depth_buffer(struct sample_info &info);
553 void destroy_swap_chain(struct sample_info &info);
554 void destroy_command_buffer(struct sample_info &info);
555 void destroy_command_buffer_array(struct sample_info &info, int numBuffers);
556 void destroy_command_buffer2_array(struct sample_info &info, int numBuffers);
557 void reset_command_buffer2_array(struct sample_info &info,
558 VkCommandBufferResetFlags cmd_buffer_reset_flags);
559 void reset_command_pool(struct sample_info &info, VkCommandPoolResetFlags cmd_pool_reset_flags);
560 void destroy_command_pool(struct sample_info &info);
561 void destroy_device(struct sample_info &info);
562 void destroy_instance(struct sample_info &info);
563 void destroy_window(struct sample_info &info);
564
565 #endif
566