wsi: Use const qualifier for semaphores in vk_wait_for_semaphores()
[platform/core/uifw/vulkan-wsi-tizen.git] / src / null-driver / null-driver.c
1 /*
2  * Copyright (C) 2015 Valve Corporation
3  * Copyright © 2016 S-Core Corporation
4  * Copyright © 2016-2017 Samsung Electronics co., Ltd. All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23  * DEALINGS IN THE SOFTWARE.
24  *
25  * Author: Cody Northrop <cody@lunarg.com>
26  * Author: David Pinedo <david@lunarg.com>
27  * Author: Ian Elliott <ian@LunarG.com>
28  * Author: Tony Barbour <tony@LunarG.com>
29  */
30
31 #include "null-driver.h"
32 #include <stdbool.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <vulkan/vk_icd.h>
36 #include <utils.h>
37 #include <vulkan-wsi-tizen.h>
38
39 #if 0
40 #include <stdio.h>
41 #define NULLDRV_LOG_FUNC \
42         do { \
43                 fflush(stdout); \
44                 fflush(stderr); \
45                 printf("null driver: %s\n", __FUNCTION__); \
46                 fflush(stdout); \
47         } while (0)
48 #else
49 #define NULLDRV_LOG_FUNC do { } while (0)
50 #endif
51
52 struct nulldrv_base {
53     void *loader_data;
54     uint32_t magic;
55     VkResult (*get_memory_requirements)(struct nulldrv_base *base,
56                                                                                 VkMemoryRequirements *mem_requirements);
57 };
58
59 struct nulldrv_obj {
60     struct nulldrv_base base;
61 };
62
63 enum nulldrv_ext_type {
64    NULLDRV_EXT_KHR_SWAPCHAIN,
65    NULLDRV_EXT_COUNT,
66    NULLDRV_EXT_INVALID = NULLDRV_EXT_COUNT,
67 };
68
69 struct nulldrv_instance {
70     struct nulldrv_obj obj;
71 };
72
73 struct nulldrv_gpu {
74     void *loader_data;
75 };
76
77 struct nulldrv_dev {
78      struct nulldrv_base base;
79      bool exts[NULLDRV_EXT_COUNT];
80      struct nulldrv_desc_ooxx *desc_ooxx;
81      struct nulldrv_queue *queues[1];
82 };
83
84 struct nulldrv_desc_ooxx {
85     uint32_t surface_desc_size;
86     uint32_t sampler_desc_size;
87 };
88
89 struct nulldrv_queue {
90     struct nulldrv_base base;
91     struct nulldrv_dev *dev;
92 };
93
94 struct nulldrv_rt_view {
95     struct nulldrv_obj obj;
96 };
97
98 struct nulldrv_fence {
99     struct nulldrv_obj obj;
100 };
101
102 struct nulldrv_img {
103     struct nulldrv_obj obj;
104     VkImageType type;
105     int32_t depth;
106     uint32_t mip_levels;
107     uint32_t array_size;
108     VkFlags usage;
109     VkSampleCountFlagBits samples;
110     size_t total_size;
111         tbm_surface_h tbm_surface;
112 };
113
114 struct nulldrv_mem {
115     struct nulldrv_base base;
116     struct nulldrv_bo *bo;
117     VkDeviceSize size;
118 };
119
120 struct nulldrv_sampler {
121     struct nulldrv_obj obj;
122 };
123
124 struct nulldrv_shader_module {
125     struct nulldrv_obj obj;
126 };
127
128 struct nulldrv_pipeline_cache {
129     struct nulldrv_obj obj;
130 };
131
132 struct nulldrv_img_view {
133     struct nulldrv_obj obj;
134     struct nulldrv_img *img;
135     float min_lod;
136     uint32_t cmd_len;
137 };
138
139 struct nulldrv_buf {
140     struct nulldrv_obj obj;
141     VkDeviceSize size;
142     VkFlags usage;
143 };
144
145 struct nulldrv_desc_layout {
146     struct nulldrv_obj obj;
147 };
148
149 struct nulldrv_pipeline_layout {
150     struct nulldrv_obj obj;
151 };
152
153 struct nulldrv_shader {
154     struct nulldrv_obj obj;
155
156 };
157
158 struct nulldrv_pipeline {
159     struct nulldrv_obj obj;
160     struct nulldrv_dev *dev;
161 };
162
163 struct nulldrv_dynamic_vp {
164     struct nulldrv_obj obj;
165 };
166
167 struct nulldrv_dynamic_line_width {
168     struct nulldrv_obj obj;
169 };
170
171 struct nulldrv_dynamic_depth_bias {
172     struct nulldrv_obj obj;
173 };
174
175 struct nulldrv_dynamic_blend {
176     struct nulldrv_obj obj;
177 };
178
179 struct nulldrv_dynamic_depth_bounds {
180     struct nulldrv_obj obj;
181 };
182
183 struct nulldrv_dynamic_stencil {
184     struct nulldrv_obj obj;
185 };
186
187 struct nulldrv_cmd {
188     struct nulldrv_obj obj;
189 };
190
191 struct nulldrv_desc_pool {
192     struct nulldrv_obj obj;
193     struct nulldrv_dev *dev;
194 };
195
196 struct nulldrv_desc_set {
197     struct nulldrv_obj obj;
198     struct nulldrv_desc_ooxx *ooxx;
199     const struct nulldrv_desc_layout *layout;
200 };
201
202 struct nulldrv_framebuffer {
203     struct nulldrv_obj obj;
204 };
205
206 struct nulldrv_render_pass {
207     struct nulldrv_obj obj;
208 };
209
210 struct nulldrv_buf_view {
211     struct nulldrv_obj obj;
212
213     struct nulldrv_buf *buf;
214
215     /* SURFACE_STATE */
216     uint32_t cmd[8];
217     uint32_t fs_cmd[8];
218     uint32_t cmd_len;
219 };
220
221 struct nulldrv_display {
222     struct nulldrv_base base;
223     struct nulldrv_dev *dev;
224 };
225
226 struct nulldrv_swap_chain {
227     struct nulldrv_base base;
228     struct nulldrv_dev *dev;
229 };
230
231 static const VkExtensionProperties instance_extensions[NULLDRV_EXT_COUNT] =
232 {
233         {
234                 .extensionName = VK_KHR_SURFACE_EXTENSION_NAME,
235                 .specVersion = VK_KHR_SURFACE_SPEC_VERSION,
236         }
237 };
238
239 const VkExtensionProperties device_extensions[1] =
240 {
241         {
242                 .extensionName = VK_KHR_SWAPCHAIN_EXTENSION_NAME,
243                 .specVersion = VK_KHR_SWAPCHAIN_SPEC_VERSION,
244         }
245 };
246
247 static struct nulldrv_base *
248 nulldrv_base(void* base)
249 {
250         return (struct nulldrv_base *) base;
251 }
252
253 static struct nulldrv_base *
254 nulldrv_base_create(struct nulldrv_dev *dev,
255                                         size_t obj_size,
256                                         VkDebugReportObjectTypeEXT type)
257 {
258         struct nulldrv_base *base;
259
260         if (!obj_size)
261                 obj_size = sizeof(*base);
262
263         VK_ASSERT(obj_size >= sizeof(*base));
264
265         base = (struct nulldrv_base*)malloc(obj_size);
266         if (!base)
267                 return NULL;
268
269         memset(base, 0, obj_size);
270
271         /* Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC */
272         set_loader_magic_value(base);
273
274         if (dev == NULL) {
275                 /*
276                  * dev is NULL when we are creating the base device object
277                  * Set dev now so that debug setup happens correctly
278                  */
279                 dev = (struct nulldrv_dev *) base;
280         }
281
282
283         base->get_memory_requirements = NULL;
284
285         return base;
286 }
287
288 static VkResult
289 nulldrv_gpu_add(int devid, const char *primary_node,
290                                 const char *render_node, struct nulldrv_gpu **gpu_ret)
291 {
292         struct nulldrv_gpu *gpu;
293
294         gpu = malloc(sizeof(*gpu));
295         if (!gpu)
296                 return VK_ERROR_OUT_OF_HOST_MEMORY;
297
298         memset(gpu, 0, sizeof(*gpu));
299
300         /* Initialize pointer to loader's dispatch table with ICD_LOADER_MAGIC */
301         set_loader_magic_value(gpu);
302
303         *gpu_ret = gpu;
304
305         return VK_SUCCESS;
306 }
307
308 static VkResult
309 nulldrv_queue_create(struct nulldrv_dev *dev,
310                                          uint32_t node_index,
311                                          struct nulldrv_queue **queue_ret)
312 {
313         struct nulldrv_queue *queue;
314
315         queue = (struct nulldrv_queue *)
316                 nulldrv_base_create(dev, sizeof(*queue),
317                                                         VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT);
318         if (!queue)
319                 return VK_ERROR_OUT_OF_HOST_MEMORY;
320
321         queue->dev = dev;
322
323         *queue_ret = queue;
324
325         return VK_SUCCESS;
326 }
327
328 static VkResult
329 dev_create_queues(struct nulldrv_dev *dev,
330                                   const VkDeviceQueueCreateInfo *queues,
331                                   uint32_t count)
332 {
333         uint32_t i;
334
335         for (i = 0; i < count; i++) {
336                 const VkDeviceQueueCreateInfo *q = &queues[i];
337                 VkResult ret = VK_SUCCESS;
338
339                 if (q->queueCount == 1 && !dev->queues[q->queueFamilyIndex]) {
340                         ret = nulldrv_queue_create(dev, q->queueFamilyIndex,
341                                                                            &dev->queues[q->queueFamilyIndex]);
342                 }
343
344                 if (ret != VK_SUCCESS)
345                         return ret;
346         }
347
348         return VK_SUCCESS;
349 }
350
351 static enum nulldrv_ext_type
352 nulldrv_gpu_lookup_extension(const struct nulldrv_gpu *gpu,
353                                                          const char* name)
354 {
355         enum nulldrv_ext_type type;
356
357         for (type = 0; type < ARRAY_LENGTH(device_extensions); type++) {
358                 if (strcmp(device_extensions[type].extensionName, name) == 0)
359                         break;
360         }
361
362         VK_ASSERT(type < NULLDRV_EXT_COUNT || type == NULLDRV_EXT_INVALID);
363
364         return type;
365 }
366
367 static VkResult
368 nulldrv_desc_ooxx_create(struct nulldrv_dev *dev,
369                                                  struct nulldrv_desc_ooxx **ooxx_ret)
370 {
371         struct nulldrv_desc_ooxx *ooxx;
372
373         ooxx = malloc(sizeof(*ooxx));
374         if (!ooxx)
375                 return VK_ERROR_OUT_OF_HOST_MEMORY;
376
377         memset(ooxx, 0, sizeof(*ooxx));
378
379         ooxx->surface_desc_size = 0;
380         ooxx->sampler_desc_size = 0;
381
382         *ooxx_ret = ooxx;
383
384         return VK_SUCCESS;
385 }
386
387 static VkResult
388 nulldrv_dev_create(struct nulldrv_gpu *gpu,
389                                    const VkDeviceCreateInfo *info,
390                                    struct nulldrv_dev **dev_ret)
391 {
392         struct nulldrv_dev *dev;
393         uint32_t i;
394         VkResult ret;
395
396         dev = (struct nulldrv_dev *)
397                 nulldrv_base_create(NULL, sizeof(*dev),
398                                                         VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT);
399         if (!dev)
400                 return VK_ERROR_OUT_OF_HOST_MEMORY;
401
402         for (i = 0; i < info->enabledExtensionCount; i++) {
403                 enum nulldrv_ext_type ext =
404                         nulldrv_gpu_lookup_extension(gpu,
405                                                                                  info->ppEnabledExtensionNames[i]);
406
407                 if (ext == NULLDRV_EXT_INVALID)
408                         return VK_ERROR_EXTENSION_NOT_PRESENT;
409
410                 dev->exts[ext] = true;
411         }
412
413         ret = nulldrv_desc_ooxx_create(dev, &dev->desc_ooxx);
414         if (ret != VK_SUCCESS)
415                 return ret;
416
417         ret = dev_create_queues(dev, info->pQueueCreateInfos,
418                                                         info->queueCreateInfoCount);
419         if (ret != VK_SUCCESS)
420                 return ret;
421
422         *dev_ret = dev;
423
424         return VK_SUCCESS;
425 }
426
427 static struct nulldrv_gpu *nulldrv_gpu(VkPhysicalDevice gpu)
428 {
429         return (struct nulldrv_gpu *) gpu;
430 }
431
432 static VkResult nulldrv_fence_create(struct nulldrv_dev *dev,
433                                                                          const VkFenceCreateInfo *info,
434                                                                          struct nulldrv_fence **fence_ret)
435 {
436         struct nulldrv_fence *fence;
437
438         fence = (struct nulldrv_fence *)
439                 nulldrv_base_create(dev, sizeof(*fence),
440                                                         VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT);
441         if (!fence)
442                 return VK_ERROR_OUT_OF_HOST_MEMORY;
443
444         *fence_ret = fence;
445
446         return VK_SUCCESS;
447 }
448
449 static struct nulldrv_dev *
450 nulldrv_dev(VkDevice dev)
451 {
452         return (struct nulldrv_dev *) dev;
453 }
454
455 static struct nulldrv_img *
456 nulldrv_img_from_base(struct nulldrv_base *base)
457 {
458         return (struct nulldrv_img *) base;
459 }
460
461
462 static VkResult
463 img_get_memory_requirements(struct nulldrv_base *base,
464                                                         VkMemoryRequirements *requirements)
465 {
466         struct nulldrv_img *img = nulldrv_img_from_base(base);
467         VkResult ret = VK_SUCCESS;
468
469         requirements->size = img->total_size;
470         requirements->alignment = 4096;
471         requirements->memoryTypeBits = ~0u;        /* can use any memory type */
472
473         return ret;
474 }
475
476 static VkResult
477 nulldrv_img_create(struct nulldrv_dev *dev,
478                                    tbm_surface_h tbm_surface,
479                                    const VkImageCreateInfo *info,
480                                    bool scanout,
481                                    struct nulldrv_img **img_ret)
482 {
483         struct nulldrv_img *img;
484
485         img = (struct nulldrv_img *)
486                 nulldrv_base_create(dev, sizeof(*img),
487                                                         VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT);
488         if (!img)
489                 return VK_ERROR_OUT_OF_HOST_MEMORY;
490
491         img->tbm_surface = tbm_surface;
492         img->type = info->imageType;
493         img->depth = info->extent.depth;
494         img->mip_levels = info->mipLevels;
495         img->array_size = info->arrayLayers;
496         img->usage = info->usage;
497         img->samples = info->samples;
498
499         img->obj.base.get_memory_requirements = img_get_memory_requirements;
500
501         *img_ret = img;
502
503         return VK_SUCCESS;
504 }
505
506 static struct nulldrv_img *
507 nulldrv_img(VkImage image)
508 {
509         return *(struct nulldrv_img **) &image;
510 }
511
512 static VkResult
513 nulldrv_mem_alloc(struct nulldrv_dev *dev,
514                                   const VkMemoryAllocateInfo *info,
515                                   struct nulldrv_mem **mem_ret)
516 {
517         struct nulldrv_mem *mem;
518
519         mem = (struct nulldrv_mem *)
520                 nulldrv_base_create(dev, sizeof(*mem),
521                                                         VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT);
522         if (!mem)
523                 return VK_ERROR_OUT_OF_HOST_MEMORY;
524
525         mem->bo = malloc(info->allocationSize);
526         if (!mem->bo)
527                 return VK_ERROR_OUT_OF_HOST_MEMORY;
528
529         mem->size = info->allocationSize;
530
531         *mem_ret = mem;
532
533         return VK_SUCCESS;
534 }
535
536 static VkResult
537 nulldrv_sampler_create(struct nulldrv_dev *dev,
538                                            const VkSamplerCreateInfo *info,
539                                            struct nulldrv_sampler **sampler_ret)
540 {
541         struct nulldrv_sampler *sampler;
542
543         sampler = (struct nulldrv_sampler *)
544                 nulldrv_base_create(dev, sizeof(*sampler),
545                                                         VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT);
546         if (!sampler)
547                 return VK_ERROR_OUT_OF_HOST_MEMORY;
548
549         *sampler_ret = sampler;
550
551         return VK_SUCCESS;
552 }
553
554 static VkResult
555 nulldrv_img_view_create(struct nulldrv_dev *dev,
556                                                 const VkImageViewCreateInfo *info,
557                                                 struct nulldrv_img_view **view_ret)
558 {
559         struct nulldrv_img *img = nulldrv_img(info->image);
560         struct nulldrv_img_view *view;
561
562         view = (struct nulldrv_img_view *)
563                 nulldrv_base_create(dev, sizeof(*view),
564                                                         VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT);
565         if (!view)
566                 return VK_ERROR_OUT_OF_HOST_MEMORY;
567
568         view->img = img;
569
570         view->cmd_len = 8;
571
572         *view_ret = view;
573
574         return VK_SUCCESS;
575 }
576
577 static void *
578 nulldrv_mem_map(struct nulldrv_mem *mem, VkFlags flags)
579 {
580         return mem->bo;
581 }
582
583 static struct nulldrv_mem *
584 nulldrv_mem(VkDeviceMemory mem)
585 {
586         return *(struct nulldrv_mem **) &mem;
587 }
588
589 static struct nulldrv_buf *
590 nulldrv_buf_from_base(struct nulldrv_base *base)
591 {
592         return (struct nulldrv_buf *) base;
593 }
594
595 static VkResult
596 buf_get_memory_requirements(struct nulldrv_base *base,
597                                                         VkMemoryRequirements* requirements)
598 {
599         struct nulldrv_buf *buf = nulldrv_buf_from_base(base);
600
601         if (requirements == NULL)
602                 return VK_SUCCESS;
603
604         requirements->size = buf->size;
605         requirements->alignment = 4096;
606         requirements->memoryTypeBits = 1; /* nulldrv only has one memory type */
607
608         return VK_SUCCESS;
609 }
610
611 static VkResult
612 nulldrv_buf_create(struct nulldrv_dev *dev,
613                                    const VkBufferCreateInfo *info,
614                                    struct nulldrv_buf **buf_ret)
615 {
616         struct nulldrv_buf *buf;
617
618         buf = (struct nulldrv_buf *)
619                 nulldrv_base_create(dev, sizeof(*buf),
620                                                         VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT);
621         if (!buf)
622                 return VK_ERROR_OUT_OF_HOST_MEMORY;
623
624         buf->size = info->size;
625         buf->usage = info->usage;
626
627         buf->obj.base.get_memory_requirements = buf_get_memory_requirements;
628
629         *buf_ret = buf;
630
631         return VK_SUCCESS;
632 }
633
634 static VkResult
635 nulldrv_desc_layout_create(struct nulldrv_dev *dev,
636                                                    const VkDescriptorSetLayoutCreateInfo *info,
637                                                    struct nulldrv_desc_layout **layout_ret)
638 {
639         struct nulldrv_desc_layout *layout;
640
641         layout = (struct nulldrv_desc_layout *)
642                 nulldrv_base_create(dev, sizeof(*layout),
643                                                         VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT);
644         if (!layout)
645                 return VK_ERROR_OUT_OF_HOST_MEMORY;
646
647         *layout_ret = layout;
648
649         return VK_SUCCESS;
650 }
651
652 static VkResult
653 nulldrv_pipeline_layout_create(struct nulldrv_dev *dev,
654                                                            const VkPipelineLayoutCreateInfo* info,
655                                                            struct nulldrv_pipeline_layout **ret)
656 {
657         struct nulldrv_pipeline_layout *pipeline_layout;
658
659         pipeline_layout = (struct nulldrv_pipeline_layout *)
660                 nulldrv_base_create(dev, sizeof(*pipeline_layout),
661                                                         VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT);
662         if (!pipeline_layout)
663                 return VK_ERROR_OUT_OF_HOST_MEMORY;
664
665         *ret = pipeline_layout;
666
667         return VK_SUCCESS;
668 }
669
670 static struct nulldrv_desc_layout *
671 nulldrv_desc_layout(const VkDescriptorSetLayout layout)
672 {
673         return *(struct nulldrv_desc_layout **) &layout;
674 }
675
676 static VkResult
677 graphics_pipeline_create(struct nulldrv_dev *dev,
678                                                  const VkGraphicsPipelineCreateInfo *info,
679                                                  struct nulldrv_pipeline **pipeline_ret)
680 {
681         struct nulldrv_pipeline *pipeline;
682
683         pipeline = (struct nulldrv_pipeline *)
684                 nulldrv_base_create(dev, sizeof(*pipeline),
685                                                         VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT);
686         if (!pipeline)
687                 return VK_ERROR_OUT_OF_HOST_MEMORY;
688
689         *pipeline_ret = pipeline;
690
691         return VK_SUCCESS;
692 }
693
694 static VkResult
695 nulldrv_cmd_create(struct nulldrv_dev *dev,
696                                    const VkCommandBufferAllocateInfo *info,
697                                    struct nulldrv_cmd **cmd_ret)
698 {
699         struct nulldrv_cmd *cmd;
700         uint32_t num_allocated = 0;
701         uint32_t i, j;
702
703         for (i = 0; i < info->commandBufferCount; i++) {
704                 cmd = (struct nulldrv_cmd *)
705                         nulldrv_base_create(dev, sizeof(*cmd),
706                                                                 VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT);
707                 if (!cmd) {
708                         for (j = 0; j < num_allocated; j++)
709                                 free(cmd_ret[j]);
710
711                         return VK_ERROR_OUT_OF_HOST_MEMORY;
712                 }
713
714                 num_allocated++;
715                 cmd_ret[i] = cmd;
716         }
717
718         return VK_SUCCESS;
719 }
720
721 static VkResult
722 nulldrv_desc_pool_create(struct nulldrv_dev *dev,
723                                                  const VkDescriptorPoolCreateInfo *info,
724                                                  struct nulldrv_desc_pool **pool_ret)
725 {
726         struct nulldrv_desc_pool *pool;
727
728         pool = (struct nulldrv_desc_pool *)
729                 nulldrv_base_create(dev, sizeof(*pool),
730                                                         VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT);
731         if (!pool)
732                 return VK_ERROR_OUT_OF_HOST_MEMORY;
733
734         pool->dev = dev;
735
736         *pool_ret = pool;
737
738         return VK_SUCCESS;
739 }
740
741 static VkResult
742 nulldrv_desc_set_create(struct nulldrv_dev *dev,
743                                                 struct nulldrv_desc_pool *pool,
744                                                 const struct nulldrv_desc_layout *layout,
745                                                 struct nulldrv_desc_set **set_ret)
746 {
747         struct nulldrv_desc_set *set;
748
749         set = (struct nulldrv_desc_set *)
750                 nulldrv_base_create(dev, sizeof(*set),
751                                                         VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT);
752         if (!set)
753                 return VK_ERROR_OUT_OF_HOST_MEMORY;
754
755         set->ooxx = dev->desc_ooxx;
756         set->layout = layout;
757         *set_ret = set;
758
759         return VK_SUCCESS;
760 }
761
762 static struct nulldrv_desc_pool *
763 nulldrv_desc_pool(VkDescriptorPool pool)
764 {
765         return *(struct nulldrv_desc_pool **) &pool;
766 }
767
768 static VkResult
769 nulldrv_fb_create(struct nulldrv_dev *dev,
770                                   const VkFramebufferCreateInfo *info,
771                                   struct nulldrv_framebuffer **fb_ret)
772 {
773
774         struct nulldrv_framebuffer *fb;
775
776         fb = (struct nulldrv_framebuffer *)
777                 nulldrv_base_create(dev, sizeof(*fb),
778                                                         VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT);
779         if (!fb)
780                 return VK_ERROR_OUT_OF_HOST_MEMORY;
781
782         *fb_ret = fb;
783
784         return VK_SUCCESS;
785
786 }
787
788 static VkResult
789 nulldrv_render_pass_create(struct nulldrv_dev *dev,
790                                                    const VkRenderPassCreateInfo *info,
791                                                    struct nulldrv_render_pass **rp_ret)
792 {
793         struct nulldrv_render_pass *rp;
794
795         rp = (struct nulldrv_render_pass *)
796                 nulldrv_base_create(dev, sizeof(*rp),
797                                                         VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT);
798         if (!rp)
799                 return VK_ERROR_OUT_OF_HOST_MEMORY;
800
801         *rp_ret = rp;
802
803         return VK_SUCCESS;
804 }
805
806 static struct nulldrv_buf *
807 nulldrv_buf(VkBuffer buf)
808 {
809         return *(struct nulldrv_buf **) &buf;
810 }
811
812 static VkResult
813 nulldrv_buf_view_create(struct nulldrv_dev *dev,
814                                                 const VkBufferViewCreateInfo *info,
815                                                 struct nulldrv_buf_view **view_ret)
816 {
817         struct nulldrv_buf *buf = nulldrv_buf(info->buffer);
818         struct nulldrv_buf_view *view;
819
820         view = (struct nulldrv_buf_view *)
821                 nulldrv_base_create(dev, sizeof(*view),
822                                                         VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT);
823         if (!view)
824                 return VK_ERROR_OUT_OF_HOST_MEMORY;
825
826         view->buf = buf;
827
828         *view_ret = view;
829
830         return VK_SUCCESS;
831 }
832
833 static VKAPI_ATTR VkResult VKAPI_CALL
834 create_buffer(VkDevice device,
835                           const VkBufferCreateInfo *info,
836                           const VkAllocationCallbacks *allocator,
837                           VkBuffer *buffer)
838 {
839         NULLDRV_LOG_FUNC;
840         struct nulldrv_dev *dev = nulldrv_dev(device);
841
842         return nulldrv_buf_create(dev, info,
843                                                           (struct nulldrv_buf **) buffer);
844 }
845
846 static VKAPI_ATTR void VKAPI_CALL
847 destroy_buffer(VkDevice device,
848                            VkBuffer buffer,
849                            const VkAllocationCallbacks *allocator)
850 {
851         NULLDRV_LOG_FUNC;
852 }
853
854 static VKAPI_ATTR VkResult VKAPI_CALL
855 create_command_pool(VkDevice device,
856                                         const VkCommandPoolCreateInfo *info,
857                                         const VkAllocationCallbacks *allocator,
858                                         VkCommandPool *pool)
859 {
860         NULLDRV_LOG_FUNC;
861         *pool = (VkCommandPool)1;
862         return VK_SUCCESS;
863 }
864
865 static VKAPI_ATTR void VKAPI_CALL
866 destroy_command_pool(VkDevice device,
867                                          VkCommandPool pool,
868                                          const VkAllocationCallbacks *allocator)
869 {
870         NULLDRV_LOG_FUNC;
871 }
872
873 static VKAPI_ATTR VkResult VKAPI_CALL
874 reset_command_pool(VkDevice device,
875                                    VkCommandPool pool,
876                                    VkCommandPoolResetFlags flags)
877 {
878         NULLDRV_LOG_FUNC;
879         return VK_SUCCESS;
880 }
881
882 static VKAPI_ATTR VkResult VKAPI_CALL
883 allocate_command_buffers(VkDevice device,
884                                                  const VkCommandBufferAllocateInfo *info,
885                                                  VkCommandBuffer *command_buffers)
886 {
887         NULLDRV_LOG_FUNC;
888         struct nulldrv_dev *dev = nulldrv_dev(device);
889
890         return nulldrv_cmd_create(dev, info, (struct nulldrv_cmd **)command_buffers);
891 }
892
893 static VKAPI_ATTR void VKAPI_CALL
894 free_command_buffers(VkDevice device,
895                                          VkCommandPool pool,
896                                          uint32_t count,
897                                          const VkCommandBuffer *command_buffers)
898 {
899         NULLDRV_LOG_FUNC;
900         uint32_t i;
901
902         for (i = 0; i < count; i++)
903                 free(command_buffers[i]);
904 }
905
906 static VKAPI_ATTR VkResult VKAPI_CALL
907 begin_command_buffer(VkCommandBuffer command_buffer,
908                                          const VkCommandBufferBeginInfo *info)
909 {
910         NULLDRV_LOG_FUNC;
911         return VK_SUCCESS;
912 }
913
914 static VKAPI_ATTR VkResult VKAPI_CALL
915 end_command_buffer(VkCommandBuffer command_buffer)
916 {
917         NULLDRV_LOG_FUNC;
918         return VK_SUCCESS;
919 }
920
921 static VKAPI_ATTR VkResult VKAPI_CALL
922 reset_command_buffer(VkCommandBuffer command_buffer,
923                                          VkCommandBufferResetFlags flags)
924 {
925         NULLDRV_LOG_FUNC;
926         return VK_SUCCESS;
927 }
928
929 static VKAPI_ATTR void VKAPI_CALL
930 cmd_copy_buffer(VkCommandBuffer command_buffer,
931                                 VkBuffer src,
932                                 VkBuffer dst,
933                                 uint32_t region_count,
934                                 const VkBufferCopy *regions)
935 {
936         NULLDRV_LOG_FUNC;
937 }
938
939 static VKAPI_ATTR void VKAPI_CALL
940 cmd_copy_image(VkCommandBuffer command_buffer,
941                            VkImage src,
942                            VkImageLayout src_layout,
943                            VkImage dst,
944                            VkImageLayout dst_layout,
945                            uint32_t region_count,
946                            const VkImageCopy *regions)
947 {
948         NULLDRV_LOG_FUNC;
949 }
950
951 static VKAPI_ATTR void VKAPI_CALL
952 cmd_blit_image(VkCommandBuffer command_buffer,
953                            VkImage src,
954                            VkImageLayout src_layout,
955                            VkImage dst,
956                            VkImageLayout dst_layout,
957                            uint32_t region_count,
958                            const VkImageBlit *regions,
959                            VkFilter filter)
960 {
961         NULLDRV_LOG_FUNC;
962 }
963
964 static VKAPI_ATTR void VKAPI_CALL
965 cmd_copy_buffer_to_image(VkCommandBuffer command_buffer,
966                                                  VkBuffer src,
967                                                  VkImage dst,
968                                                  VkImageLayout dst_layout,
969                                                  uint32_t region_count,
970                                                  const VkBufferImageCopy *regions)
971 {
972         NULLDRV_LOG_FUNC;
973 }
974
975 static VKAPI_ATTR void VKAPI_CALL
976 cmd_copy_image_to_buffer(VkCommandBuffer command_buffer,
977                                                  VkImage src,
978                                                  VkImageLayout src_layout,
979                                                  VkBuffer dst,
980                                                  uint32_t region_count,
981                                                  const VkBufferImageCopy *regions)
982 {
983         NULLDRV_LOG_FUNC;
984 }
985
986 static VKAPI_ATTR void VKAPI_CALL
987 cmd_update_buffer(VkCommandBuffer command_buffer,
988                                   VkBuffer buffer,
989                                   VkDeviceSize offset,
990                                   VkDeviceSize size,
991                                   const uint32_t *data)
992 {
993         NULLDRV_LOG_FUNC;
994 }
995
996 static VKAPI_ATTR void VKAPI_CALL
997 cmd_fill_buffer(VkCommandBuffer command_buffer,
998                                 VkBuffer buffer,
999                                 VkDeviceSize offset,
1000                                 VkDeviceSize size,
1001                                 uint32_t data)
1002 {
1003         NULLDRV_LOG_FUNC;
1004 }
1005
1006 static VKAPI_ATTR void VKAPI_CALL
1007 cmd_clear_depth_stencil_image(VkCommandBuffer command_buffer,
1008                                                           VkImage image,
1009                                                           VkImageLayout layout,
1010                                                           const VkClearDepthStencilValue *value,
1011                                                           uint32_t range_count,
1012                                                           const VkImageSubresourceRange *ranges)
1013 {
1014         NULLDRV_LOG_FUNC;
1015 }
1016
1017 static VKAPI_ATTR void VKAPI_CALL
1018 cmd_clear_attachments(VkCommandBuffer command_buffer,
1019                                           uint32_t attachment_count,
1020                                           const VkClearAttachment *attachments,
1021                                           uint32_t rect_count,
1022                                           const VkClearRect *rects)
1023 {
1024         NULLDRV_LOG_FUNC;
1025 }
1026
1027 static VKAPI_ATTR void VKAPI_CALL
1028 cmd_clear_color_image(VkCommandBuffer command_buffer,
1029                                           VkImage image,
1030                                           VkImageLayout image_layout,
1031                                           const VkClearColorValue *color,
1032                                           uint32_t range_count,
1033                                           const VkImageSubresourceRange *ranges)
1034 {
1035         NULLDRV_LOG_FUNC;
1036 }
1037
1038 static VKAPI_ATTR void VKAPI_CALL
1039 cmd_resolve_image(VkCommandBuffer command_buffer,
1040                                   VkImage src,
1041                                   VkImageLayout src_layout,
1042                                   VkImage dst,
1043                                   VkImageLayout dst_layout,
1044                                   uint32_t region_count,
1045                                   const VkImageResolve *regions)
1046 {
1047         NULLDRV_LOG_FUNC;
1048 }
1049
1050 static VKAPI_ATTR void VKAPI_CALL
1051 cmd_begin_query(VkCommandBuffer command_buffer,
1052                                 VkQueryPool pool,
1053                                 uint32_t slot,
1054                                 VkFlags flags)
1055 {
1056         NULLDRV_LOG_FUNC;
1057 }
1058
1059 static VKAPI_ATTR void VKAPI_CALL
1060 cmd_end_query(VkCommandBuffer command_buffer,
1061                           VkQueryPool pool,
1062                           uint32_t slot)
1063 {
1064         NULLDRV_LOG_FUNC;
1065 }
1066
1067 static VKAPI_ATTR void VKAPI_CALL
1068 cmd_reset_query_pool(VkCommandBuffer command_buffer,
1069                                          VkQueryPool pool,
1070                                          uint32_t first_query,
1071                                          uint32_t query_count)
1072 {
1073         NULLDRV_LOG_FUNC;
1074 }
1075
1076 static VKAPI_ATTR void VKAPI_CALL
1077 cmd_set_event(VkCommandBuffer command_buffer,
1078                           VkEvent event,
1079                           VkPipelineStageFlags stage_mask)
1080 {
1081         NULLDRV_LOG_FUNC;
1082 }
1083
1084 static VKAPI_ATTR void VKAPI_CALL
1085 cmd_reset_event(VkCommandBuffer command_buffer,
1086                                 VkEvent event,
1087                                 VkPipelineStageFlags stage_mask)
1088 {
1089         NULLDRV_LOG_FUNC;
1090 }
1091
1092 static VKAPI_ATTR void VKAPI_CALL
1093 cmd_copy_query_pool_results(VkCommandBuffer command_buffer,
1094                                                         VkQueryPool pool,
1095                                                         uint32_t first_query,
1096                                                         uint32_t query_count,
1097                                                         VkBuffer buffer,
1098                                                         VkDeviceSize offset,
1099                                                         VkDeviceSize stride,
1100                                                         VkFlags flags)
1101 {
1102         NULLDRV_LOG_FUNC;
1103 }
1104
1105 static VKAPI_ATTR void VKAPI_CALL
1106 cmd_write_timestamp(VkCommandBuffer command_buffer,
1107                                         VkPipelineStageFlagBits pipeline_stage,
1108                                         VkQueryPool pool,
1109                                         uint32_t slot)
1110 {
1111         NULLDRV_LOG_FUNC;
1112 }
1113
1114 static VKAPI_ATTR void VKAPI_CALL
1115 cmd_bind_pipeline(VkCommandBuffer command_buffer,
1116                                   VkPipelineBindPoint pipeline_bind_point,
1117                                   VkPipeline pipeline)
1118 {
1119         NULLDRV_LOG_FUNC;
1120 }
1121
1122 static VKAPI_ATTR void VKAPI_CALL
1123 cmd_set_viewport(VkCommandBuffer command_buffer,
1124                                  uint32_t first,
1125                                  uint32_t count,
1126                                  const VkViewport *viewports)
1127 {
1128         NULLDRV_LOG_FUNC;
1129 }
1130
1131 static VKAPI_ATTR void VKAPI_CALL
1132 cmd_set_scissor(VkCommandBuffer command_buffer,
1133                                 uint32_t first,
1134                                 uint32_t count,
1135                                 const VkRect2D *scissors)
1136 {
1137         NULLDRV_LOG_FUNC;
1138 }
1139
1140 static VKAPI_ATTR void VKAPI_CALL
1141 cmd_set_line_width(VkCommandBuffer command_buffer, float line_width)
1142 {
1143         NULLDRV_LOG_FUNC;
1144 }
1145
1146 static VKAPI_ATTR void VKAPI_CALL
1147 cmd_set_depth_bias(VkCommandBuffer command_buffer,
1148                                    float constant,
1149                                    float clamp,
1150                                    float slope)
1151 {
1152         NULLDRV_LOG_FUNC;
1153 }
1154
1155 static VKAPI_ATTR void VKAPI_CALL
1156 cmd_set_blend_constants(VkCommandBuffer command_buffer,
1157                                                 const float blend_constants[4])
1158 {
1159         NULLDRV_LOG_FUNC;
1160 }
1161
1162 static VKAPI_ATTR void VKAPI_CALL
1163 cmd_set_depth_bounds(VkCommandBuffer command_buffer,
1164                                          float min,
1165                                          float max)
1166 {
1167         NULLDRV_LOG_FUNC;
1168 }
1169
1170 static VKAPI_ATTR void VKAPI_CALL
1171 cmd_set_stencil_compare_mask(VkCommandBuffer command_buffer,
1172                                                          VkStencilFaceFlags face_mask,
1173                                                          uint32_t compare_mask)
1174 {
1175         NULLDRV_LOG_FUNC;
1176 }
1177
1178 static VKAPI_ATTR void VKAPI_CALL
1179 cmd_set_stencil_write_mask(VkCommandBuffer command_buffer,
1180                                                    VkStencilFaceFlags face_mask,
1181                                                    uint32_t write_mask)
1182 {
1183         NULLDRV_LOG_FUNC;
1184 }
1185
1186 static VKAPI_ATTR void VKAPI_CALL
1187 cmd_set_stencil_reference(VkCommandBuffer command_buffer,
1188                                                   VkStencilFaceFlags face_mask,
1189                                                   uint32_t reference)
1190 {
1191         NULLDRV_LOG_FUNC;
1192 }
1193
1194 static VKAPI_ATTR void VKAPI_CALL
1195 cmd_bind_descriptor_sets(VkCommandBuffer command_buffer,
1196                                                  VkPipelineBindPoint pipeline_bind_point,
1197                                                  VkPipelineLayout layout,
1198                                                  uint32_t first,
1199                                                  uint32_t count,
1200                                                  const VkDescriptorSet *sets,
1201                                                  uint32_t offset_count,
1202                                                  const uint32_t *offsets)
1203 {
1204         NULLDRV_LOG_FUNC;
1205 }
1206
1207 static VKAPI_ATTR void VKAPI_CALL
1208 cmd_bind_vertex_buffers(VkCommandBuffer command_buffer,
1209                                                 uint32_t first,
1210                                                 uint32_t count,
1211                                                 const VkBuffer *buffers,
1212                                                 const VkDeviceSize *offsets)
1213 {
1214         NULLDRV_LOG_FUNC;
1215 }
1216
1217 static VKAPI_ATTR void VKAPI_CALL
1218 cmd_bind_index_buffer(VkCommandBuffer command_buffer,
1219                                           VkBuffer buffer,
1220                                           VkDeviceSize offset,
1221                                           VkIndexType index_type)
1222 {
1223         NULLDRV_LOG_FUNC;
1224 }
1225
1226 static VKAPI_ATTR void VKAPI_CALL
1227 cmd_draw(VkCommandBuffer command_buffer,
1228                  uint32_t vertex_count,
1229                  uint32_t instance_count,
1230                  uint32_t first_vertex,
1231                  uint32_t first_instance)
1232 {
1233         NULLDRV_LOG_FUNC;
1234 }
1235
1236 static VKAPI_ATTR void VKAPI_CALL
1237 cmd_draw_indexed(VkCommandBuffer command_buffer,
1238                                  uint32_t index_count,
1239                                  uint32_t instance_count,
1240                                  uint32_t first_index,
1241                                  int32_t vertex_offset,
1242                                  uint32_t first_instance)
1243 {
1244         NULLDRV_LOG_FUNC;
1245 }
1246
1247 static VKAPI_ATTR void VKAPI_CALL
1248 cmd_draw_indirect(VkCommandBuffer command_buffer,
1249                                   VkBuffer buffer,
1250                                   VkDeviceSize offset,
1251                                   uint32_t draw_count,
1252                                   uint32_t stride)
1253 {
1254         NULLDRV_LOG_FUNC;
1255 }
1256
1257 static VKAPI_ATTR void VKAPI_CALL
1258 cmd_draw_indexed_indirect(VkCommandBuffer command_buffer,
1259                                                   VkBuffer buffer,
1260                                                   VkDeviceSize offset,
1261                                                   uint32_t draw_count,
1262                                                   uint32_t stride)
1263 {
1264         NULLDRV_LOG_FUNC;
1265 }
1266
1267 static VKAPI_ATTR void VKAPI_CALL
1268 cmd_dispatch(VkCommandBuffer command_buffer,
1269                          uint32_t x,
1270                          uint32_t y,
1271                          uint32_t z)
1272 {
1273         NULLDRV_LOG_FUNC;
1274 }
1275
1276 static VKAPI_ATTR void VKAPI_CALL
1277 cmd_dispatch_indirect(VkCommandBuffer command_buffer,
1278                                           VkBuffer buffer,
1279                                           VkDeviceSize offset)
1280 {
1281         NULLDRV_LOG_FUNC;
1282 }
1283
1284 static VKAPI_ATTR void VKAPI_CALL
1285 cmd_wait_events(VkCommandBuffer command_buffer,
1286                                 uint32_t event_count,
1287                                 const VkEvent *events,
1288                                 VkPipelineStageFlags source_stage_mask,
1289                                 VkPipelineStageFlags dst_stage_mask,
1290                                 uint32_t memory_barrier_count,
1291                                 const VkMemoryBarrier *memory_barriers,
1292                                 uint32_t buffer_memory_barrierCount,
1293                                 const VkBufferMemoryBarrier *buffer_memory_barriers,
1294                                 uint32_t image_memory_barrierCount,
1295                                 const VkImageMemoryBarrier *image_memory_barriers)
1296 {
1297         NULLDRV_LOG_FUNC;
1298 }
1299
1300 static VKAPI_ATTR void VKAPI_CALL
1301 cmd_pipeline_barrier(VkCommandBuffer command_buffer,
1302                                          VkPipelineStageFlags src_stage_mask,
1303                                          VkPipelineStageFlags dst_stage_mask,
1304                                          VkDependencyFlags dependency_flags,
1305                                          uint32_t memory_barrier_count,
1306                                          const VkMemoryBarrier *memory_barriers,
1307                                          uint32_t buffer_memory_barrierCount,
1308                                          const VkBufferMemoryBarrier *buffer_memory_barriers,
1309                                          uint32_t image_memory_barrierCount,
1310                                          const VkImageMemoryBarrier *image_memory_barriers)
1311 {
1312         NULLDRV_LOG_FUNC;
1313 }
1314
1315 static VKAPI_ATTR VkResult VKAPI_CALL
1316 create_device(VkPhysicalDevice dev,
1317                           const VkDeviceCreateInfo *info,
1318                           const VkAllocationCallbacks *allocator,
1319                           VkDevice *device)
1320 {
1321         NULLDRV_LOG_FUNC;
1322         struct nulldrv_gpu *gpu = nulldrv_gpu(dev);
1323         return nulldrv_dev_create(gpu, info, (struct nulldrv_dev**)device);
1324 }
1325
1326 static VKAPI_ATTR void VKAPI_CALL
1327 destroy_device(VkDevice device,
1328                            const VkAllocationCallbacks *allocator)
1329 {
1330         NULLDRV_LOG_FUNC;
1331 }
1332
1333 static VKAPI_ATTR void VKAPI_CALL
1334 get_device_queue(VkDevice device,
1335                                  uint32_t queue_node_index,
1336                                  uint32_t queue_index,
1337                                  VkQueue *queue)
1338 {
1339         NULLDRV_LOG_FUNC;
1340         struct nulldrv_dev *dev = nulldrv_dev(device);
1341         *queue = (VkQueue) dev->queues[0];
1342 }
1343
1344 static VKAPI_ATTR VkResult VKAPI_CALL
1345 device_wait_idle(VkDevice device)
1346 {
1347         NULLDRV_LOG_FUNC;
1348         return VK_SUCCESS;
1349 }
1350
1351 static VKAPI_ATTR VkResult VKAPI_CALL
1352 create_event(VkDevice device,
1353                          const VkEventCreateInfo *info,
1354                          const VkAllocationCallbacks *allocator,
1355                          VkEvent *event)
1356 {
1357         NULLDRV_LOG_FUNC;
1358         return VK_SUCCESS;
1359 }
1360
1361 static VKAPI_ATTR void VKAPI_CALL
1362 destroy_event(VkDevice device,
1363                           VkEvent event,
1364                           const VkAllocationCallbacks *allocator)
1365 {
1366         NULLDRV_LOG_FUNC;
1367 }
1368
1369 static VKAPI_ATTR VkResult VKAPI_CALL
1370 get_event_status(VkDevice device,
1371                                  VkEvent event)
1372 {
1373         NULLDRV_LOG_FUNC;
1374         return VK_SUCCESS;
1375 }
1376
1377 static VKAPI_ATTR VkResult VKAPI_CALL
1378 set_event(VkDevice device,
1379                   VkEvent event)
1380 {
1381         NULLDRV_LOG_FUNC;
1382         return VK_SUCCESS;
1383 }
1384
1385 static VKAPI_ATTR VkResult VKAPI_CALL
1386 reset_event(VkDevice device,
1387                         VkEvent event)
1388 {
1389         NULLDRV_LOG_FUNC;
1390         return VK_SUCCESS;
1391 }
1392
1393 static VKAPI_ATTR VkResult VKAPI_CALL
1394 create_fence(VkDevice device,
1395                          const VkFenceCreateInfo *info,
1396                          const VkAllocationCallbacks *allocator,
1397                          VkFence *fence)
1398 {
1399         NULLDRV_LOG_FUNC;
1400         struct nulldrv_dev *dev = nulldrv_dev(device);
1401
1402         return nulldrv_fence_create(dev, info,
1403                                                                 (struct nulldrv_fence **) fence);
1404 }
1405
1406 static VKAPI_ATTR void VKAPI_CALL
1407 destroy_fence(VkDevice device,
1408                           VkFence fence,
1409                           const VkAllocationCallbacks *allocator)
1410 {
1411         NULLDRV_LOG_FUNC;
1412 }
1413
1414 static VKAPI_ATTR VkResult VKAPI_CALL
1415 get_fence_status(VkDevice device,
1416                                  VkFence fence)
1417 {
1418         NULLDRV_LOG_FUNC;
1419         return VK_SUCCESS;
1420 }
1421
1422 static VKAPI_ATTR VkResult VKAPI_CALL
1423 reset_fences(VkDevice device,
1424                          uint32_t fence_count,
1425                          const VkFence *fences)
1426 {
1427         NULLDRV_LOG_FUNC;
1428         return VK_SUCCESS;
1429 }
1430
1431 static VKAPI_ATTR VkResult VKAPI_CALL
1432 wait_for_fences(VkDevice device,
1433                                 uint32_t fence_count,
1434                                 const VkFence *fences,
1435                                 VkBool32 wait_all,
1436                                 uint64_t timeout)
1437 {
1438         NULLDRV_LOG_FUNC;
1439         return VK_SUCCESS;
1440 }
1441
1442 static VKAPI_ATTR void VKAPI_CALL
1443 get_physical_device_properties(VkPhysicalDevice pdev,
1444                                                            VkPhysicalDeviceProperties *props)
1445 {
1446         NULLDRV_LOG_FUNC;
1447
1448         props->apiVersion = VK_API_VERSION_1_0;
1449         props->driverVersion = 0;
1450         props->vendorID = 0;
1451         props->deviceID = 0;
1452         props->deviceType = VK_PHYSICAL_DEVICE_TYPE_OTHER;
1453         strncpy(props->deviceName, "nulldrv", strlen("nulldrv"));
1454
1455         /* TODO: fill out limits */
1456         memset(&props->limits, 0, sizeof(VkPhysicalDeviceLimits));
1457         memset(&props->sparseProperties, 0,
1458                    sizeof(VkPhysicalDeviceSparseProperties));
1459 }
1460
1461 static VKAPI_ATTR void VKAPI_CALL
1462 get_physical_device_features(VkPhysicalDevice dev,
1463                                                          VkPhysicalDeviceFeatures *features)
1464 {
1465         NULLDRV_LOG_FUNC;
1466
1467         memset(features, 0xff, sizeof(*features));
1468 }
1469
1470 static VKAPI_ATTR void VKAPI_CALL
1471 get_physical_device_format_properties(VkPhysicalDevice pdev,
1472                                                                           VkFormat format,
1473                                                                           VkFormatProperties *format_info)
1474 {
1475         NULLDRV_LOG_FUNC;
1476
1477         format_info->linearTilingFeatures = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
1478                 VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
1479         format_info->optimalTilingFeatures = format_info->linearTilingFeatures;
1480         format_info->bufferFeatures = 0;
1481 }
1482
1483 static VKAPI_ATTR void VKAPI_CALL
1484 get_physical_device_queue_family_properties(VkPhysicalDevice pdev,
1485                                                                                         uint32_t *queue_family_prop_count,
1486                                                                                         VkQueueFamilyProperties *props)
1487 {
1488         if (props == NULL) {
1489                 *queue_family_prop_count = 1;
1490                 return;
1491         }
1492         props->queueFlags = VK_QUEUE_GRAPHICS_BIT |
1493                 VK_QUEUE_SPARSE_BINDING_BIT;
1494         props->queueCount = 1;
1495         props->timestampValidBits = 0;
1496 }
1497
1498 static VKAPI_ATTR void VKAPI_CALL
1499 get_physical_device_memory_properties(VkPhysicalDevice pdev,
1500                                                                           VkPhysicalDeviceMemoryProperties *props)
1501 {
1502         /* null driver pretends to have a single memory type (and single heap) */
1503         props->memoryTypeCount = 1;
1504         props->memoryHeapCount = 1;
1505         props->memoryTypes[0].heapIndex = 0;
1506         props->memoryTypes[0].propertyFlags =
1507                 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
1508                 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
1509                 VK_MEMORY_PROPERTY_HOST_CACHED_BIT |
1510                 VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT;
1511         props->memoryHeaps[0].flags = 0; /* not physical_deviceice local */
1512         props->memoryHeaps[0].size = 0;  /* it's just malloc-backed memory */
1513 }
1514
1515 static VKAPI_ATTR VkResult VKAPI_CALL
1516 enumerate_device_layer_properties(VkPhysicalDevice pdev,
1517                                                                   uint32_t *prop_count,
1518                                                                   VkLayerProperties *props)
1519 {
1520         /* TODO: Fill in with real data */
1521         return VK_SUCCESS;
1522 }
1523
1524 static VKAPI_ATTR VkResult VKAPI_CALL
1525 enumerate_instance_extension_properties(const char *layer_name,
1526                                                                                 uint32_t *prop_count,
1527                                                                                 VkExtensionProperties *props)
1528 {
1529         uint32_t copy_size;
1530
1531         if (props == NULL) {
1532                 *prop_count = NULLDRV_EXT_COUNT;
1533                 return VK_SUCCESS;
1534         }
1535
1536         copy_size = *prop_count < NULLDRV_EXT_COUNT ?
1537                 *prop_count : NULLDRV_EXT_COUNT;
1538
1539         memcpy(props, instance_extensions,
1540                    copy_size * sizeof(VkExtensionProperties));
1541
1542         *prop_count = copy_size;
1543
1544         if (copy_size < NULLDRV_EXT_COUNT)
1545                 return VK_INCOMPLETE;
1546
1547         return VK_SUCCESS;
1548 }
1549
1550 static VKAPI_ATTR VkResult VKAPI_CALL
1551 enumerate_instance_layer_properties(uint32_t *prop_count,
1552                                                                         VkLayerProperties *props)
1553 {
1554         /* TODO: Fill in with real data */
1555         return VK_SUCCESS;
1556 }
1557
1558 static VKAPI_ATTR VkResult VKAPI_CALL
1559 enumerate_device_extension_properties(VkPhysicalDevice pdev,
1560                                                                           const char *layer_name,
1561                                                                           uint32_t *prop_count,
1562                                                                           VkExtensionProperties *props)
1563 {
1564         uint32_t copy_size;
1565         uint32_t extension_count = ARRAY_LENGTH(device_extensions);
1566
1567         if (props == NULL) {
1568                 *prop_count = extension_count;
1569                 return VK_SUCCESS;
1570         }
1571
1572         copy_size = *prop_count < extension_count ?
1573                 *prop_count : extension_count;
1574
1575         memcpy(props, device_extensions,
1576                    copy_size * sizeof(VkExtensionProperties));
1577
1578         *prop_count = copy_size;
1579
1580         if (copy_size < extension_count)
1581                 return VK_INCOMPLETE;
1582
1583         return VK_SUCCESS;
1584 }
1585
1586 static VKAPI_ATTR VkResult VKAPI_CALL
1587 create_image(VkDevice device,
1588                          const VkImageCreateInfo *info,
1589                          const VkAllocationCallbacks *allocator,
1590                          VkImage *image)
1591 {
1592         NULLDRV_LOG_FUNC;
1593         struct nulldrv_dev *dev = nulldrv_dev(device);
1594
1595         return nulldrv_img_create(dev, NULL, info, false,
1596                                                           (struct nulldrv_img **) image);
1597 }
1598
1599 static VKAPI_ATTR void VKAPI_CALL
1600 destroy_image(VkDevice device,
1601                           VkImage image,
1602                           const VkAllocationCallbacks *allocator)
1603 {
1604         NULLDRV_LOG_FUNC;
1605 }
1606
1607 static VKAPI_ATTR void VKAPI_CALL
1608 get_image_subresource_layout(VkDevice device,
1609                                                          VkImage image,
1610                                                          const VkImageSubresource *subresource,
1611                                                          VkSubresourceLayout *layout)
1612 {
1613         NULLDRV_LOG_FUNC;
1614
1615         layout->offset = 0;
1616         layout->size = 1;
1617         layout->rowPitch = 4;
1618         layout->depthPitch = 4;
1619         layout->arrayPitch = 4;
1620 }
1621
1622 static VKAPI_ATTR VkResult VKAPI_CALL
1623 allocate_memory(VkDevice device,
1624                                 const VkMemoryAllocateInfo *info,
1625                                 const VkAllocationCallbacks *allocator,
1626                                 VkDeviceMemory *memory)
1627 {
1628         NULLDRV_LOG_FUNC;
1629         struct nulldrv_dev *dev = nulldrv_dev(device);
1630
1631         return nulldrv_mem_alloc(dev, info,
1632                                                          (struct nulldrv_mem **) memory);
1633 }
1634
1635 static VKAPI_ATTR void VKAPI_CALL
1636 free_memory(VkDevice device,
1637                         VkDeviceMemory memory,
1638                         const VkAllocationCallbacks *allocator)
1639 {
1640         NULLDRV_LOG_FUNC;
1641 }
1642
1643 static VKAPI_ATTR VkResult VKAPI_CALL
1644 map_memory(VkDevice device,
1645                    VkDeviceMemory memory,
1646                    VkDeviceSize offset,
1647                    VkDeviceSize size,
1648                    VkFlags flags,
1649                    void** pdata)
1650 {
1651         NULLDRV_LOG_FUNC;
1652         struct nulldrv_mem *mem = nulldrv_mem(memory);
1653         void *ptr = nulldrv_mem_map(mem, flags);
1654
1655         *pdata = ptr;
1656
1657         return (ptr) ? VK_SUCCESS : VK_ERROR_MEMORY_MAP_FAILED;
1658 }
1659
1660 static VKAPI_ATTR void VKAPI_CALL
1661 unmap_memory(VkDevice device,
1662                          VkDeviceMemory memory)
1663 {
1664         NULLDRV_LOG_FUNC;
1665 }
1666
1667 static VKAPI_ATTR VkResult VKAPI_CALL
1668 flush_mapped_memory_ranges(VkDevice device,
1669                                                    uint32_t memory_range_count,
1670                                                    const VkMappedMemoryRange *memory_ranges)
1671 {
1672         NULLDRV_LOG_FUNC;
1673         return VK_SUCCESS;
1674 }
1675
1676 static VKAPI_ATTR VkResult VKAPI_CALL
1677 invalidate_mapped_memory_ranges(VkDevice device,
1678                                                                 uint32_t memory_range_count,
1679                                                                 const VkMappedMemoryRange *memory_ranges)
1680 {
1681         NULLDRV_LOG_FUNC;
1682         return VK_SUCCESS;
1683 }
1684
1685 static VKAPI_ATTR void VKAPI_CALL
1686 get_device_memory_commitment(VkDevice device,
1687                                                          VkDeviceMemory memory,
1688                                                          VkDeviceSize *committed_memory_bytes)
1689 {
1690 }
1691
1692 static VKAPI_ATTR VkResult VKAPI_CALL
1693 create_instance(const VkInstanceCreateInfo *info,
1694                                 const VkAllocationCallbacks *allocator,
1695                                 VkInstance *instance)
1696 {
1697         NULLDRV_LOG_FUNC;
1698         struct nulldrv_instance *inst;
1699
1700         inst = (struct nulldrv_instance *)
1701                 nulldrv_base_create(NULL, sizeof(*inst),
1702                                                         VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT);
1703         if (!inst)
1704                 return VK_ERROR_OUT_OF_HOST_MEMORY;
1705
1706         inst->obj.base.get_memory_requirements = NULL;
1707
1708         *instance = (VkInstance) inst;
1709
1710         return VK_SUCCESS;
1711 }
1712
1713 static VKAPI_ATTR void VKAPI_CALL
1714 destroy_instance(VkInstance instance,
1715                                  const VkAllocationCallbacks *allocator)
1716 {
1717         NULLDRV_LOG_FUNC;
1718 }
1719
1720 static VKAPI_ATTR VkResult VKAPI_CALL
1721 enumerate_physical_devices(VkInstance instance,
1722                                                    uint32_t *gpu_count,
1723                                                    VkPhysicalDevice *gpus)
1724 {
1725         NULLDRV_LOG_FUNC;
1726         VkResult ret;
1727         struct nulldrv_gpu *gpu;
1728
1729         *gpu_count = 1;
1730         ret = nulldrv_gpu_add(0, 0, 0, &gpu);
1731
1732         if (ret == VK_SUCCESS && gpus)
1733                 gpus[0] = (VkPhysicalDevice) gpu;
1734
1735         return ret;
1736 }
1737
1738 static VKAPI_ATTR void VKAPI_CALL
1739 get_buffer_memory_requirements(VkDevice device,
1740                                                            VkBuffer buffer,
1741                                                            VkMemoryRequirements *memory_requirements)
1742 {
1743         NULLDRV_LOG_FUNC;
1744         struct nulldrv_base *base = nulldrv_base((void*)(uintptr_t)buffer);
1745
1746         base->get_memory_requirements(base, memory_requirements);
1747 }
1748
1749 static VKAPI_ATTR void VKAPI_CALL
1750 get_image_memory_requirements(VkDevice device,
1751                                                           VkImage image,
1752                                                           VkMemoryRequirements *memory_requirements)
1753 {
1754         NULLDRV_LOG_FUNC;
1755         struct nulldrv_base *base = nulldrv_base((void*)(uintptr_t)image);
1756
1757         base->get_memory_requirements(base, memory_requirements);
1758 }
1759
1760 static VKAPI_ATTR VkResult VKAPI_CALL
1761 bind_buffer_memory(VkDevice device,
1762                                    VkBuffer buffer,
1763                                    VkDeviceMemory memory,
1764                                    VkDeviceSize memory_offset)
1765 {
1766         NULLDRV_LOG_FUNC;
1767         return VK_SUCCESS;
1768 }
1769
1770 static VKAPI_ATTR VkResult VKAPI_CALL
1771 bind_image_memory(VkDevice device,
1772                                   VkImage image,
1773                                   VkDeviceMemory memory,
1774                                   VkDeviceSize memory_offset)
1775 {
1776         NULLDRV_LOG_FUNC;
1777         return VK_SUCCESS;
1778 }
1779
1780 static VKAPI_ATTR void VKAPI_CALL
1781 get_image_sparse_memory_requirements(VkDevice device,
1782                                                                          VkImage image,
1783                                                                          uint32_t *count,
1784                                                                          VkSparseImageMemoryRequirements *reqs)
1785 {
1786         NULLDRV_LOG_FUNC;
1787 }
1788
1789 static VKAPI_ATTR void VKAPI_CALL
1790 get_physical_device_sparse_image_format_properties(VkPhysicalDevice dev,
1791                                                                                                    VkFormat format,
1792                                                                                                    VkImageType type,
1793                                                                                                    VkSampleCountFlagBits samples,
1794                                                                                                    VkImageUsageFlags usage,
1795                                                                                                    VkImageTiling tiling,
1796                                                                                                    uint32_t *prop_count,
1797                                                                                                    VkSparseImageFormatProperties *props)
1798 {
1799         NULLDRV_LOG_FUNC;
1800 }
1801
1802 static VKAPI_ATTR VkResult VKAPI_CALL
1803 queue_bind_sparse(VkQueue queue,
1804                                   uint32_t bind_info_count,
1805                                   const VkBindSparseInfo *bind_info,
1806                                   VkFence fence)
1807 {
1808         NULLDRV_LOG_FUNC;
1809         return VK_SUCCESS;
1810 }
1811
1812 static VKAPI_ATTR VkResult VKAPI_CALL
1813 create_pipeline_cache(VkDevice device,
1814                                           const VkPipelineCacheCreateInfo *info,
1815                                           const VkAllocationCallbacks *allocator,
1816                                           VkPipelineCache *cache)
1817 {
1818
1819         NULLDRV_LOG_FUNC;
1820
1821         struct nulldrv_dev *dev = nulldrv_dev(device);
1822         struct nulldrv_pipeline_cache *pipeline_cache;
1823
1824         pipeline_cache = (struct nulldrv_pipeline_cache *)
1825                 nulldrv_base_create(dev, sizeof(*pipeline_cache),
1826                                                         VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT);
1827         if (!pipeline_cache)
1828                 return VK_ERROR_OUT_OF_HOST_MEMORY;
1829
1830         *cache = (VkPipelineCache)(uintptr_t)pipeline_cache;
1831
1832         return VK_SUCCESS;
1833 }
1834
1835 static VKAPI_ATTR void VKAPI_CALL
1836 destroy_pipeline(VkDevice device,
1837                                  VkPipeline pipeline,
1838                                  const VkAllocationCallbacks *allocator)
1839 {
1840         NULLDRV_LOG_FUNC;
1841 }
1842
1843 static VKAPI_ATTR void VKAPI_CALL
1844 destroy_pipeline_cache(VkDevice device,
1845                                            VkPipelineCache pipeline_cache,
1846                                            const VkAllocationCallbacks *allocator)
1847 {
1848         NULLDRV_LOG_FUNC;
1849 }
1850
1851 static VKAPI_ATTR VkResult VKAPI_CALL
1852 get_pipeline_cache_data(VkDevice device,
1853                                                 VkPipelineCache pipeline_cache,
1854                                                 size_t *data_size,
1855                                                 void *data)
1856 {
1857         NULLDRV_LOG_FUNC;
1858         return VK_ERROR_INITIALIZATION_FAILED;
1859 }
1860
1861 static VKAPI_ATTR VkResult VKAPI_CALL
1862 merge_pipeline_caches(VkDevice device,
1863                                           VkPipelineCache dst_cache,
1864                                           uint32_t src_cache_count,
1865                                           const VkPipelineCache *src_caches)
1866 {
1867         NULLDRV_LOG_FUNC;
1868         return VK_ERROR_INITIALIZATION_FAILED;
1869 }
1870
1871 static VKAPI_ATTR VkResult VKAPI_CALL
1872 create_graphics_pipelines(VkDevice device,
1873                                                   VkPipelineCache pipeline_cache,
1874                                                   uint32_t create_info_count,
1875                                                   const VkGraphicsPipelineCreateInfo *info,
1876                                                   const VkAllocationCallbacks *allocator,
1877                                                   VkPipeline *pipeline)
1878 {
1879         NULLDRV_LOG_FUNC;
1880         struct nulldrv_dev *dev = nulldrv_dev(device);
1881
1882         return graphics_pipeline_create(dev, info,
1883                                                                         (struct nulldrv_pipeline **) pipeline);
1884 }
1885
1886 static VKAPI_ATTR VkResult VKAPI_CALL
1887 create_compute_pipelines(VkDevice device,
1888                                                  VkPipelineCache pipeline_cache,
1889                                                  uint32_t create_info_count,
1890                                                  const VkComputePipelineCreateInfo *info,
1891                                                  const VkAllocationCallbacks *allocator,
1892                                                  VkPipeline *pipeline)
1893 {
1894         NULLDRV_LOG_FUNC;
1895         return VK_SUCCESS;
1896 }
1897
1898 static VKAPI_ATTR VkResult VKAPI_CALL
1899 create_query_pool(VkDevice device,
1900                                   const VkQueryPoolCreateInfo *info,
1901                                   const VkAllocationCallbacks *allocator,
1902                                   VkQueryPool *pool)
1903 {
1904         NULLDRV_LOG_FUNC;
1905         return VK_SUCCESS;
1906 }
1907
1908 static VKAPI_ATTR void VKAPI_CALL
1909 destroy_query_pool(VkDevice device,
1910                                    VkQueryPool query_poool,
1911                                    const VkAllocationCallbacks *allocator)
1912 {
1913         NULLDRV_LOG_FUNC;
1914 }
1915
1916 static VKAPI_ATTR VkResult VKAPI_CALL
1917 get_query_pool_results(VkDevice device,
1918                                            VkQueryPool query_pool,
1919                                            uint32_t first_query,
1920                                            uint32_t query_count,
1921                                            size_t data_size,
1922                                            void *data,
1923                                            size_t stride,
1924                                            VkQueryResultFlags flags)
1925 {
1926         NULLDRV_LOG_FUNC;
1927         return VK_SUCCESS;
1928 }
1929
1930 static VKAPI_ATTR VkResult VKAPI_CALL
1931 queue_wait_idle(VkQueue queue)
1932 {
1933         NULLDRV_LOG_FUNC;
1934         return VK_SUCCESS;
1935 }
1936
1937 static VKAPI_ATTR VkResult VKAPI_CALL
1938 queue_submit(VkQueue queue,
1939                          uint32_t submit_count,
1940                          const VkSubmitInfo *submits,
1941                          VkFence fence)
1942 {
1943         NULLDRV_LOG_FUNC;
1944         return VK_SUCCESS;
1945 }
1946
1947 static VKAPI_ATTR VkResult VKAPI_CALL
1948 create_semaphore(VkDevice device,
1949                                  const VkSemaphoreCreateInfo *info,
1950                                  const VkAllocationCallbacks *allocator,
1951                                  VkSemaphore *semaphore)
1952 {
1953         NULLDRV_LOG_FUNC;
1954         return VK_SUCCESS;
1955 }
1956
1957 static VKAPI_ATTR void VKAPI_CALL
1958 destroy_semaphore(VkDevice device,
1959                                   VkSemaphore semaphore,
1960                                   const VkAllocationCallbacks *allocator)
1961 {
1962         NULLDRV_LOG_FUNC;
1963 }
1964
1965 static VKAPI_ATTR VkResult VKAPI_CALL
1966 create_sampler(VkDevice device,
1967                            const VkSamplerCreateInfo *info,
1968                            const VkAllocationCallbacks *allocator,
1969                            VkSampler *sampler)
1970 {
1971         NULLDRV_LOG_FUNC;
1972         struct nulldrv_dev *dev = nulldrv_dev(device);
1973
1974         return nulldrv_sampler_create(dev, info,
1975                                                                   (struct nulldrv_sampler **) sampler);
1976 }
1977
1978 static VKAPI_ATTR void VKAPI_CALL
1979 destroy_sampler(VkDevice device,
1980                                 VkSampler sampler,
1981                                 const VkAllocationCallbacks *allocator)
1982 {
1983         NULLDRV_LOG_FUNC;
1984 }
1985
1986 static VKAPI_ATTR VkResult VKAPI_CALL
1987 create_shader_module(VkDevice device,
1988                                          const VkShaderModuleCreateInfo *info,
1989                                          const VkAllocationCallbacks *allocator,
1990                                          VkShaderModule *module)
1991 {
1992         NULLDRV_LOG_FUNC;
1993
1994         struct nulldrv_dev *dev = nulldrv_dev(device);
1995         struct nulldrv_shader_module *shader_module;
1996
1997         shader_module = (struct nulldrv_shader_module *)
1998                 nulldrv_base_create(dev, sizeof(*shader_module),
1999                                                         VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT);
2000         if (!shader_module)
2001                 return VK_ERROR_OUT_OF_HOST_MEMORY;
2002
2003         *module = (VkShaderModule)(uintptr_t)shader_module;
2004
2005         return VK_SUCCESS;
2006 }
2007
2008 static VKAPI_ATTR void VKAPI_CALL
2009 destroy_shader_module(VkDevice device,
2010                                           VkShaderModule shader_module,
2011                                           const VkAllocationCallbacks *allocator)
2012 {
2013         /* TODO: Fill in with real data */
2014         NULLDRV_LOG_FUNC;
2015 }
2016
2017 static VKAPI_ATTR VkResult VKAPI_CALL
2018 create_buffer_view(VkDevice device,
2019                                    const VkBufferViewCreateInfo *info,
2020                                    const VkAllocationCallbacks *allocator,
2021                                    VkBufferView *view)
2022 {
2023         NULLDRV_LOG_FUNC;
2024         struct nulldrv_dev *dev = nulldrv_dev(device);
2025
2026         return nulldrv_buf_view_create(dev, info,
2027                                                                    (struct nulldrv_buf_view **) view);
2028 }
2029
2030 static VKAPI_ATTR void VKAPI_CALL
2031 destroy_buffer_view(VkDevice device,
2032                                         VkBufferView buffer_view,
2033                                         const VkAllocationCallbacks *allocator)
2034 {
2035         NULLDRV_LOG_FUNC;
2036 }
2037
2038 static VKAPI_ATTR VkResult VKAPI_CALL
2039 create_image_view(VkDevice device,
2040                                   const VkImageViewCreateInfo *info,
2041                                   const VkAllocationCallbacks *allocator,
2042                                   VkImageView *view)
2043 {
2044         NULLDRV_LOG_FUNC;
2045         struct nulldrv_dev *dev = nulldrv_dev(device);
2046
2047         return nulldrv_img_view_create(dev, info,
2048                                                                    (struct nulldrv_img_view **) view);
2049 }
2050
2051 static VKAPI_ATTR void VKAPI_CALL
2052 destroy_image_view(VkDevice device,
2053                                    VkImageView image_view,
2054                                    const VkAllocationCallbacks *allocator)
2055 {
2056         NULLDRV_LOG_FUNC;
2057 }
2058
2059 static VKAPI_ATTR VkResult VKAPI_CALL
2060 create_descriptor_set_layout(VkDevice device,
2061                                                          const VkDescriptorSetLayoutCreateInfo *info,
2062                                                          const VkAllocationCallbacks *allocator,
2063                                                          VkDescriptorSetLayout *layout)
2064 {
2065         NULLDRV_LOG_FUNC;
2066         struct nulldrv_dev *dev = nulldrv_dev(device);
2067
2068         return nulldrv_desc_layout_create(dev, info,
2069                                                                           (struct nulldrv_desc_layout **)layout);
2070 }
2071
2072 static VKAPI_ATTR void VKAPI_CALL
2073 destroy_descriptor_set_layout(VkDevice device,
2074                                                           VkDescriptorSetLayout layout,
2075                                                           const VkAllocationCallbacks *allocator)
2076 {
2077         NULLDRV_LOG_FUNC;
2078 }
2079
2080 static VKAPI_ATTR VkResult VKAPI_CALL
2081 create_pipeline_layout(VkDevice device,
2082                                            const VkPipelineLayoutCreateInfo *info,
2083                                            const VkAllocationCallbacks *allocator,
2084                                            VkPipelineLayout *layout)
2085 {
2086         NULLDRV_LOG_FUNC;
2087         struct nulldrv_dev *dev = nulldrv_dev(device);
2088
2089         return nulldrv_pipeline_layout_create(dev, info,
2090                                                                                   (struct nulldrv_pipeline_layout **)
2091                                                                                   layout);
2092 }
2093
2094 static VKAPI_ATTR void VKAPI_CALL
2095 destroy_pipeline_layout(VkDevice device,
2096                                                 VkPipelineLayout layout,
2097                                                 const VkAllocationCallbacks *allocator)
2098 {
2099         NULLDRV_LOG_FUNC;
2100 }
2101
2102 static VKAPI_ATTR VkResult VKAPI_CALL
2103 create_descriptor_pool(VkDevice device,
2104                                            const VkDescriptorPoolCreateInfo *info,
2105                                            const VkAllocationCallbacks *allocator,
2106                                            VkDescriptorPool *pool)
2107 {
2108         NULLDRV_LOG_FUNC;
2109         struct nulldrv_dev *dev = nulldrv_dev(device);
2110
2111         return nulldrv_desc_pool_create(dev, info,
2112                                                                         (struct nulldrv_desc_pool **)pool);
2113 }
2114
2115 static VKAPI_ATTR void VKAPI_CALL
2116 destroy_descriptor_pool(VkDevice device,
2117                                                 VkDescriptorPool descriptor_pool,
2118                                                 const VkAllocationCallbacks *allocator)
2119 {
2120         NULLDRV_LOG_FUNC;
2121 }
2122
2123 static VKAPI_ATTR VkResult VKAPI_CALL
2124 reset_descriptor_pool(VkDevice device,
2125                                           VkDescriptorPool descriptor_pool,
2126                                           VkDescriptorPoolResetFlags flags)
2127 {
2128         NULLDRV_LOG_FUNC;
2129         return VK_SUCCESS;
2130 }
2131
2132 static VKAPI_ATTR VkResult VKAPI_CALL
2133 allocate_descriptor_sets(VkDevice device,
2134                                                  const VkDescriptorSetAllocateInfo *info,
2135                                                  VkDescriptorSet *sets)
2136 {
2137         NULLDRV_LOG_FUNC;
2138         struct nulldrv_desc_pool *pool =
2139                 nulldrv_desc_pool(info->descriptorPool);
2140         struct nulldrv_dev *dev = pool->dev;
2141         VkResult ret = VK_SUCCESS;
2142         uint32_t i;
2143
2144         for (i = 0; i < info->descriptorSetCount; i++) {
2145                 const struct nulldrv_desc_layout *layout =
2146                         nulldrv_desc_layout(info->pSetLayouts[i]);
2147
2148                 ret = nulldrv_desc_set_create(dev, pool, layout,
2149                                                                           (struct nulldrv_desc_set **)&sets[i]);
2150                 if (ret != VK_SUCCESS)
2151                         break;
2152         }
2153
2154         return ret;
2155 }
2156
2157 static VKAPI_ATTR VkResult VKAPI_CALL
2158 free_descriptor_sets(VkDevice device,
2159                                          VkDescriptorPool descriptor_pool,
2160                                          uint32_t descriptor_set_count,
2161                                          const VkDescriptorSet *sets)
2162 {
2163         NULLDRV_LOG_FUNC;
2164         return VK_SUCCESS;
2165 }
2166
2167 static VKAPI_ATTR void VKAPI_CALL
2168 update_descriptor_sets(VkDevice device,
2169                                            uint32_t write_count,
2170                                            const VkWriteDescriptorSet *writes,
2171                                            uint32_t copy_count,
2172                                            const VkCopyDescriptorSet *copies)
2173 {
2174         NULLDRV_LOG_FUNC;
2175 }
2176
2177 static VKAPI_ATTR VkResult VKAPI_CALL
2178 create_framebuffer(VkDevice device,
2179                                    const VkFramebufferCreateInfo *info,
2180                                    const VkAllocationCallbacks *allocator,
2181                                    VkFramebuffer* fb)
2182 {
2183         NULLDRV_LOG_FUNC;
2184         struct nulldrv_dev *dev = nulldrv_dev(device);
2185
2186         return nulldrv_fb_create(dev, info, (struct nulldrv_framebuffer **)fb);
2187 }
2188
2189 static VKAPI_ATTR void VKAPI_CALL
2190 destroy_framebuffer(VkDevice device,
2191                                         VkFramebuffer framebuffer,
2192                                         const VkAllocationCallbacks *allocator)
2193 {
2194         NULLDRV_LOG_FUNC;
2195 }
2196
2197 static VKAPI_ATTR VkResult VKAPI_CALL
2198 create_render_pass(VkDevice device,
2199                                    const VkRenderPassCreateInfo *info,
2200                                    const VkAllocationCallbacks *allocator,
2201                                    VkRenderPass *rp)
2202 {
2203         NULLDRV_LOG_FUNC;
2204         struct nulldrv_dev *dev = nulldrv_dev(device);
2205
2206         return nulldrv_render_pass_create(dev, info,
2207                                                                           (struct nulldrv_render_pass **)rp);
2208 }
2209
2210 static VKAPI_ATTR void VKAPI_CALL
2211 destroy_render_pass(VkDevice device,
2212                                         VkRenderPass render_pass,
2213                                         const VkAllocationCallbacks *allocator)
2214 {
2215         NULLDRV_LOG_FUNC;
2216 }
2217
2218 static VKAPI_ATTR void VKAPI_CALL
2219 cmd_push_constants(VkCommandBuffer command_buffer,
2220                                    VkPipelineLayout layout,
2221                                    VkShaderStageFlags stage_flags,
2222                                    uint32_t offset,
2223                                    uint32_t size,
2224                                    const void *values)
2225 {
2226         /* TODO: Implement */
2227 }
2228
2229 static VKAPI_ATTR void VKAPI_CALL
2230 get_render_area_granularity(VkDevice device,
2231                                                         VkRenderPass render_pass,
2232                                                         VkExtent2D *granularity)
2233 {
2234         granularity->height = 1;
2235         granularity->width = 1;
2236 }
2237
2238 static VKAPI_ATTR void VKAPI_CALL
2239 cmd_begin_render_pass(VkCommandBuffer command_buffer,
2240                                           const VkRenderPassBeginInfo *render_pass_begin,
2241                                           VkSubpassContents contents)
2242 {
2243         NULLDRV_LOG_FUNC;
2244 }
2245
2246 static VKAPI_ATTR void VKAPI_CALL
2247 cmd_next_subpass(VkCommandBuffer command_buffer,
2248                                  VkSubpassContents contents)
2249 {
2250         NULLDRV_LOG_FUNC;
2251 }
2252
2253 static VKAPI_ATTR void VKAPI_CALL
2254 cmd_end_render_pass(VkCommandBuffer command_buffer)
2255 {
2256         NULLDRV_LOG_FUNC;
2257 }
2258
2259 static VKAPI_ATTR void VKAPI_CALL
2260 cmd_execute_commands(VkCommandBuffer command_buffer,
2261                                          uint32_t count,
2262                                          const VkCommandBuffer *buffers)
2263 {
2264         NULLDRV_LOG_FUNC;
2265 }
2266
2267 static VKAPI_ATTR VkResult VKAPI_CALL
2268 get_physical_device_image_format_properties(VkPhysicalDevice dev,
2269                                                                                         VkFormat format,
2270                                                                                         VkImageType type,
2271                                                                                         VkImageTiling tiling,
2272                                                                                         VkImageUsageFlags usage,
2273                                                                                         VkImageCreateFlags flags,
2274                                                                                         VkImageFormatProperties *props)
2275 {
2276         props->maxExtent.width = 1024;
2277         props->maxExtent.height = 1024;
2278         props->maxExtent.depth = 1024;
2279         props->maxMipLevels = 10;
2280         props->maxArrayLayers = 1024;
2281         props->sampleCounts = VK_SAMPLE_COUNT_1_BIT;
2282         props->maxResourceSize = 1024*1024*1024;
2283
2284         return VK_SUCCESS;
2285 }
2286
2287 struct nulldrv_entry
2288 {
2289         const char      *name;
2290         void            *func;
2291 };
2292
2293 static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
2294 get_device_proc_addr(VkDevice device, const char *name);
2295
2296 static const struct nulldrv_entry device_funcs[] =
2297 {
2298         { "vkGetDeviceProcAddr", get_device_proc_addr },
2299         { "vkEnumerateDeviceExtensionProperties", enumerate_device_extension_properties },
2300         { "vkEnumerateDeviceLayerProperties", enumerate_device_layer_properties },
2301
2302         { "vkDestroyDevice", destroy_device },
2303         { "vkGetDeviceQueue", get_device_queue },
2304         { "vkQueueSubmit", queue_submit },
2305         { "vkQueueWaitIdle", queue_wait_idle },
2306         { "vkDeviceWaitIdle", device_wait_idle },
2307         { "vkAllocateMemory", allocate_memory },
2308         { "vkFreeMemory", free_memory },
2309         { "vkMapMemory", map_memory },
2310         { "vkUnmapMemory", unmap_memory },
2311         { "vkFlushMappedMemoryRanges", flush_mapped_memory_ranges },
2312         { "vkInvalidateMappedMemoryRanges", invalidate_mapped_memory_ranges },
2313         { "vkGetDeviceMemoryCommitment", get_device_memory_commitment },
2314         { "vkBindBufferMemory", bind_buffer_memory },
2315         { "vkBindImageMemory", bind_image_memory },
2316         { "vkGetBufferMemoryRequirements", get_buffer_memory_requirements },
2317         { "vkGetImageMemoryRequirements", get_image_memory_requirements },
2318         { "vkGetImageSparseMemoryRequirements", get_image_sparse_memory_requirements },
2319         { "vkQueueBindSparse", queue_bind_sparse },
2320         { "vkCreateFence", create_fence },
2321         { "vkDestroyFence", destroy_fence },
2322         { "vkResetFences", reset_fences },
2323         { "vkGetFenceStatus", get_fence_status },
2324         { "vkWaitForFences", wait_for_fences },
2325         { "vkCreateSemaphore", create_semaphore },
2326         { "vkDestroySemaphore", destroy_semaphore },
2327         { "vkCreateEvent", create_event },
2328         { "vkDestroyEvent", destroy_event },
2329         { "vkGetEventStatus", get_event_status },
2330         { "vkSetEvent", set_event },
2331         { "vkResetEvent", reset_event },
2332         { "vkCreateQueryPool", create_query_pool },
2333         { "vkDestroyQueryPool", destroy_query_pool },
2334         { "vkGetQueryPoolResults", get_query_pool_results },
2335         { "vkCreateBuffer", create_buffer },
2336         { "vkDestroyBuffer", destroy_buffer },
2337         { "vkCreateBufferView", create_buffer_view },
2338         { "vkDestroyBufferView", destroy_buffer_view },
2339         { "vkCreateImage", create_image },
2340         { "vkDestroyImage", destroy_image },
2341         { "vkGetImageSubresourceLayout", get_image_subresource_layout },
2342         { "vkCreateImageView", create_image_view },
2343         { "vkDestroyImageView", destroy_image_view },
2344         { "vkCreateShaderModule", create_shader_module },
2345         { "vkDestroyShaderModule", destroy_shader_module },
2346         { "vkCreatePipelineCache", create_pipeline_cache },
2347         { "vkDestroyPipelineCache", destroy_pipeline_cache },
2348         { "vkGetPipelineCacheData", get_pipeline_cache_data },
2349         { "vkMergePipelineCaches", merge_pipeline_caches },
2350         { "vkCreateGraphicsPipelines", create_graphics_pipelines },
2351         { "vkCreateComputePipelines", create_compute_pipelines },
2352         { "vkDestroyPipeline", destroy_pipeline },
2353         { "vkCreatePipelineLayout", create_pipeline_layout },
2354         { "vkDestroyPipelineLayout", destroy_pipeline_layout },
2355         { "vkCreateSampler", create_sampler },
2356         { "vkDestroySampler", destroy_sampler },
2357         { "vkCreateDescriptorSetLayout", create_descriptor_set_layout },
2358         { "vkDestroyDescriptorSetLayout", destroy_descriptor_set_layout },
2359         { "vkCreateDescriptorPool", create_descriptor_pool },
2360         { "vkDestroyDescriptorPool", destroy_descriptor_pool },
2361         { "vkResetDescriptorPool", reset_descriptor_pool },
2362         { "vkAllocateDescriptorSets", allocate_descriptor_sets },
2363         { "vkFreeDescriptorSets", free_descriptor_sets },
2364         { "vkUpdateDescriptorSets", update_descriptor_sets },
2365         { "vkCreateFramebuffer", create_framebuffer },
2366         { "vkDestroyFramebuffer", destroy_framebuffer },
2367         { "vkCreateRenderPass", create_render_pass },
2368         { "vkDestroyRenderPass", destroy_render_pass },
2369         { "vkGetRenderAreaGranularity", get_render_area_granularity },
2370         { "vkCreateCommandPool", create_command_pool },
2371         { "vkDestroyCommandPool", destroy_command_pool },
2372         { "vkResetCommandPool", reset_command_pool },
2373         { "vkAllocateCommandBuffers", allocate_command_buffers },
2374         { "vkFreeCommandBuffers", free_command_buffers },
2375         { "vkBeginCommandBuffer", begin_command_buffer },
2376         { "vkEndCommandBuffer", end_command_buffer },
2377         { "vkResetCommandBuffer", reset_command_buffer },
2378         { "vkCmdBindPipeline", cmd_bind_pipeline },
2379         { "vkCmdSetViewport", cmd_set_viewport },
2380         { "vkCmdSetScissor", cmd_set_scissor },
2381         { "vkCmdSetLineWidth", cmd_set_line_width },
2382         { "vkCmdSetDepthBias", cmd_set_depth_bias },
2383         { "vkCmdSetBlendConstants", cmd_set_blend_constants },
2384         { "vkCmdSetDepthBounds", cmd_set_depth_bounds },
2385         { "vkCmdSetStencilCompareMask", cmd_set_stencil_compare_mask },
2386         { "vkCmdSetStencilWriteMask", cmd_set_stencil_write_mask },
2387         { "vkCmdSetStencilReference", cmd_set_stencil_reference },
2388         { "vkCmdBindDescriptorSets", cmd_bind_descriptor_sets },
2389         { "vkCmdBindIndexBuffer", cmd_bind_index_buffer },
2390         { "vkCmdBindVertexBuffers", cmd_bind_vertex_buffers },
2391         { "vkCmdDraw", cmd_draw },
2392         { "vkCmdDrawIndexed", cmd_draw_indexed },
2393         { "vkCmdDrawIndirect", cmd_draw_indirect },
2394         { "vkCmdDrawIndexedIndirect", cmd_draw_indexed_indirect },
2395         { "vkCmdDispatch", cmd_dispatch },
2396         { "vkCmdDispatchIndirect", cmd_dispatch_indirect },
2397         { "vkCmdCopyBuffer", cmd_copy_buffer },
2398         { "vkCmdCopyImage", cmd_copy_image },
2399         { "vkCmdBlitImage", cmd_blit_image },
2400         { "vkCmdCopyBufferToImage", cmd_copy_buffer_to_image },
2401         { "vkCmdCopyImageToBuffer", cmd_copy_image_to_buffer },
2402         { "vkCmdUpdateBuffer", cmd_update_buffer },
2403         { "vkCmdFillBuffer", cmd_fill_buffer },
2404         { "vkCmdClearColorImage", cmd_clear_color_image },
2405         { "vkCmdClearDepthStencilImage", cmd_clear_depth_stencil_image },
2406         { "vkCmdClearAttachments", cmd_clear_attachments },
2407         { "vkCmdResolveImage", cmd_resolve_image },
2408         { "vkCmdSetEvent", cmd_set_event },
2409         { "vkCmdResetEvent", cmd_reset_event },
2410         { "vkCmdWaitEvents", cmd_wait_events },
2411         { "vkCmdPipelineBarrier", cmd_pipeline_barrier },
2412         { "vkCmdBeginQuery", cmd_begin_query },
2413         { "vkCmdEndQuery", cmd_end_query },
2414         { "vkCmdResetQueryPool", cmd_reset_query_pool },
2415         { "vkCmdWriteTimestamp", cmd_write_timestamp },
2416         { "vkCmdCopyQueryPoolResults", cmd_copy_query_pool_results },
2417         { "vkCmdPushConstants", cmd_push_constants },
2418         { "vkCmdBeginRenderPass", cmd_begin_render_pass },
2419         { "vkCmdNextSubpass", cmd_next_subpass },
2420         { "vkCmdEndRenderPass", cmd_end_render_pass },
2421         { "vkCmdExecuteCommands", cmd_execute_commands },
2422 };
2423
2424 static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
2425 get_device_proc_addr(VkDevice device, const char *name)
2426 {
2427         unsigned int i;
2428
2429         for (i = 0; i < ARRAY_LENGTH(device_funcs); ++i) {
2430                 if (strcmp(name, device_funcs[i].name) == 0)
2431                         return device_funcs[i].func;
2432         }
2433
2434         return NULL;
2435 }
2436
2437 static const struct nulldrv_entry global_funcs[] =
2438 {
2439         { "vkEnumerateInstanceLayerProperties", enumerate_instance_layer_properties },
2440         { "vkEnumerateInstanceExtensionProperties", enumerate_instance_extension_properties },
2441         { "vkCreateInstance", create_instance },
2442 };
2443
2444 static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
2445 get_instance_proc_addr(VkInstance instance, const char *name);
2446
2447 static const struct nulldrv_entry instance_funcs[] =
2448 {
2449         { "vkGetInstanceProcAddr", get_instance_proc_addr },
2450         { "vkDestroyInstance", destroy_instance },
2451         { "vkEnumeratePhysicalDevices", enumerate_physical_devices },
2452
2453         { "vkGetPhysicalDeviceFeatures", get_physical_device_features },
2454         { "vkGetPhysicalDeviceFormatProperties", get_physical_device_format_properties },
2455         { "vkGetPhysicalDeviceImageFormatProperties", get_physical_device_image_format_properties },
2456         { "vkGetPhysicalDeviceProperties", get_physical_device_properties },
2457         { "vkGetPhysicalDeviceQueueFamilyProperties", get_physical_device_queue_family_properties },
2458         { "vkGetPhysicalDeviceMemoryProperties", get_physical_device_memory_properties },
2459         { "vkGetPhysicalDeviceSparseImageFormatProperties",
2460                 get_physical_device_sparse_image_format_properties },
2461         { "vkCreateDevice", create_device },
2462 };
2463
2464 static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
2465 get_instance_proc_addr(VkInstance instance, const char *name)
2466 {
2467         unsigned int i;
2468
2469         if (instance == NULL)
2470         {
2471                 for (i = 0; i < ARRAY_LENGTH(global_funcs); ++i) {
2472                         if (strcmp(name, global_funcs[i].name) == 0)
2473                                 return global_funcs[i].func;
2474                 }
2475         }
2476         else
2477         {
2478                 for (i = 0; i < ARRAY_LENGTH(instance_funcs); ++i) {
2479                         if (strcmp(name, instance_funcs[i].name) == 0)
2480                                 return instance_funcs[i].func;
2481                 }
2482
2483                 for (i = 0; i < ARRAY_LENGTH(device_funcs); ++i) {
2484                         if (strcmp(name, device_funcs[i].name) == 0)
2485                                 return device_funcs[i].func;
2486                 }
2487         }
2488
2489         return NULL;
2490 }
2491
2492 VK_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
2493 vk_icdGetInstanceProcAddr(VkInstance instance, const char *name)
2494 {
2495         unsigned int i;
2496
2497         for (i = 0; i < ARRAY_LENGTH(global_funcs); ++i) {
2498                 if (strcmp(name, global_funcs[i].name) == 0)
2499                         return global_funcs[i].func;
2500         }
2501
2502         for (i = 0; i < ARRAY_LENGTH(instance_funcs); ++i) {
2503                 if (strcmp(name, instance_funcs[i].name) == 0)
2504                         return instance_funcs[i].func;
2505         }
2506
2507         for (i = 0; i < ARRAY_LENGTH(device_funcs); ++i) {
2508                 if (strcmp(name, device_funcs[i].name) == 0)
2509                         return device_funcs[i].func;
2510         }
2511
2512         return NULL;
2513 }
2514
2515 VK_EXPORT VkImage
2516 vk_create_presentable_image(VkDevice device, const VkImageCreateInfo *info, tbm_surface_h surface)
2517 {
2518         NULLDRV_LOG_FUNC;
2519         struct nulldrv_dev *dev = nulldrv_dev(device);
2520         struct nulldrv_img *img;
2521
2522         if (nulldrv_img_create(dev, surface, info, false, &img) == VK_SUCCESS)
2523                 return (VkImage)(uintptr_t)img;
2524
2525         return (VkImage)(uintptr_t)NULL;
2526 }
2527
2528 VkBool32
2529 vk_signal_semaphore(VkSemaphore semaphore)
2530 {
2531         return VK_TRUE;
2532 }
2533
2534 VkBool32
2535 vk_wait_for_semaphores(uint32_t count, const VkSemaphore *semaphores)
2536 {
2537         return VK_TRUE;
2538 }
2539
2540 VkBool32
2541 vk_signal_fence(VkFence fence)
2542 {
2543         return VK_TRUE;
2544 }