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