• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2021 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #include "vk_framebuffer.h"
25 
26 #include "vk_common_entrypoints.h"
27 #include "vk_device.h"
28 
29 VKAPI_ATTR VkResult VKAPI_CALL
vk_common_CreateFramebuffer(VkDevice _device,const VkFramebufferCreateInfo * pCreateInfo,const VkAllocationCallbacks * pAllocator,VkFramebuffer * pFramebuffer)30 vk_common_CreateFramebuffer(VkDevice _device,
31                             const VkFramebufferCreateInfo *pCreateInfo,
32                             const VkAllocationCallbacks *pAllocator,
33                             VkFramebuffer *pFramebuffer)
34 {
35    VK_FROM_HANDLE(vk_device, device, _device);
36    struct vk_framebuffer *framebuffer;
37 
38    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO);
39 
40    size_t size = sizeof(*framebuffer);
41 
42    /* VK_KHR_imageless_framebuffer extension says:
43     *
44     *    If flags includes VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT,
45     *    parameter pAttachments is ignored.
46     */
47    if (!(pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT))
48       size += sizeof(VkImageView) * pCreateInfo->attachmentCount;
49 
50    framebuffer = vk_object_alloc(device, pAllocator, size,
51                                  VK_OBJECT_TYPE_FRAMEBUFFER);
52    if (framebuffer == NULL)
53       return VK_ERROR_OUT_OF_HOST_MEMORY;
54 
55    framebuffer->flags = pCreateInfo->flags;
56    framebuffer->width = pCreateInfo->width;
57    framebuffer->height = pCreateInfo->height;
58    framebuffer->layers = pCreateInfo->layers;
59 
60    if (!(pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT)) {
61       for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++)
62          framebuffer->attachments[i] = pCreateInfo->pAttachments[i];
63       framebuffer->attachment_count = pCreateInfo->attachmentCount;
64    }
65 
66    *pFramebuffer = vk_framebuffer_to_handle(framebuffer);
67 
68    return VK_SUCCESS;
69 }
70 
71 VKAPI_ATTR void VKAPI_CALL
vk_common_DestroyFramebuffer(VkDevice _device,VkFramebuffer _framebuffer,const VkAllocationCallbacks * pAllocator)72 vk_common_DestroyFramebuffer(VkDevice _device,
73                              VkFramebuffer _framebuffer,
74                              const VkAllocationCallbacks *pAllocator)
75 {
76    VK_FROM_HANDLE(vk_device, device, _device);
77    VK_FROM_HANDLE(vk_framebuffer, framebuffer, _framebuffer);
78 
79    if (!framebuffer)
80       return;
81 
82    vk_object_free(device, pAllocator, framebuffer);
83 }
84