blob: 80b99d5e043401f6384019ab488e687cb7e6926c [file] [log] [blame]
Jon Ashburnc6f4a412014-12-24 12:38:36 -07001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Jon Ashburnc6f4a412014-12-24 12:38:36 -07003 *
4 * Copyright (C) 2014 LunarG, Inc.
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 shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 */
25
26#include "dev.h"
27#include "obj.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070028#include "view.h"
29#include "img.h"
Jon Ashburnc6f4a412014-12-24 12:38:36 -070030#include "fb.h"
31
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070032static void fb_destroy(struct intel_obj *obj)
33{
Chia-I Wu9d748fd2015-02-18 14:46:55 -070034 struct intel_fb *fb = intel_fb_from_obj(obj);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070035
36 intel_fb_destroy(fb);
37}
38
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060039VkResult intel_fb_create(struct intel_dev *dev,
Chia-I Wuc278df82015-07-07 11:50:03 +080040 const VkFramebufferCreateInfo *info,
41 struct intel_fb **fb_ret)
Jon Ashburnc6f4a412014-12-24 12:38:36 -070042{
Chia-I Wu9d748fd2015-02-18 14:46:55 -070043 struct intel_fb *fb;
Chia-I Wu4f7730d2015-02-18 15:21:38 -070044 uint32_t width, height, array_size, i;
45
Chia-I Wu545c2e12015-02-22 13:19:54 +080046 fb = (struct intel_fb *) intel_base_create(&dev->base.handle,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -060047 sizeof(*fb), dev->base.dbg, VK_OBJECT_TYPE_FRAMEBUFFER, info, 0);
Jon Ashburnc6f4a412014-12-24 12:38:36 -070048 if (!fb)
Tony Barbour8205d902015-04-16 15:59:00 -060049 return VK_ERROR_OUT_OF_HOST_MEMORY;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070050
Chia-I Wuc278df82015-07-07 11:50:03 +080051 fb->view_count = info->attachmentCount;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +080052 fb->views = intel_alloc(fb, sizeof(fb->views[0]) * fb->view_count, 0,
53 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
54 if (!fb->views) {
55 intel_fb_destroy(fb);
56 return VK_ERROR_OUT_OF_HOST_MEMORY;
57 }
58
Chia-I Wu4f7730d2015-02-18 15:21:38 -070059 width = info->width;
60 height = info->height;
61 array_size = info->layers;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070062
Chia-I Wuc278df82015-07-07 11:50:03 +080063 for (i = 0; i < info->attachmentCount; i++) {
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -060064 const VkImageView *att = &info->pAttachments[i];
65 const struct intel_img_view *view = intel_img_view(*att);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070066
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -060067 if (array_size > view->att_view.array_size)
68 array_size = view->att_view.array_size;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070069
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -060070 fb->views[i] = &view->att_view;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070071 }
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -060072
Chia-I Wu4f7730d2015-02-18 15:21:38 -070073 fb->width = width;
74 fb->height = height;
75 fb->array_size = array_size;
76
Chia-I Wu4f7730d2015-02-18 15:21:38 -070077 fb->obj.destroy = fb_destroy;
Jon Ashburnc6f4a412014-12-24 12:38:36 -070078
79 *fb_ret = fb;
80
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060081 return VK_SUCCESS;
Jon Ashburnc6f4a412014-12-24 12:38:36 -070082}
83
Chia-I Wu9d748fd2015-02-18 14:46:55 -070084void intel_fb_destroy(struct intel_fb *fb)
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070085{
Chia-I Wu3d4d4a62015-07-09 10:34:10 +080086 if (fb->views)
87 intel_free(fb, fb->views);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070088 intel_base_destroy(&fb->obj.base);
89}
90
91static void render_pass_destroy(struct intel_obj *obj)
92{
Chia-I Wu768a14b2015-02-18 14:48:21 -070093 struct intel_render_pass *rp = intel_render_pass_from_obj(obj);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070094
Courtney Goeltzenleuchter5f5a6182015-01-23 14:27:58 -070095 intel_render_pass_destroy(rp);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070096}
97
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060098VkResult intel_render_pass_create(struct intel_dev *dev,
Chia-I Wubdeed152015-07-09 12:16:29 +080099 const VkRenderPassCreateInfo *info,
100 struct intel_render_pass **rp_ret)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700101{
102 struct intel_render_pass *rp;
Chia-I Wuba627862015-02-18 15:32:06 -0700103 uint32_t i;
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700104
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -0600105 /* TODOVV: Move to validation layer */
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -0600106 assert(!(info->dependencyCount) && "Invalid dependencyCount");
Chia-I Wuc278df82015-07-07 11:50:03 +0800107
Chia-I Wu545c2e12015-02-22 13:19:54 +0800108 rp = (struct intel_render_pass *) intel_base_create(&dev->base.handle,
Courtney Goeltzenleuchter1c7c65d2015-06-10 17:39:03 -0600109 sizeof(*rp), dev->base.dbg, VK_OBJECT_TYPE_RENDER_PASS, info, 0);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700110 if (!rp)
Tony Barbour8205d902015-04-16 15:59:00 -0600111 return VK_ERROR_OUT_OF_HOST_MEMORY;
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700112
Chia-I Wuc278df82015-07-07 11:50:03 +0800113 rp->attachment_count = info->attachmentCount;
114 rp->subpass_count = info->subpassCount;
Chia-I Wubdeed152015-07-09 12:16:29 +0800115
116 rp->attachments = intel_alloc(rp,
117 sizeof(rp->attachments[0]) * rp->attachment_count +
118 sizeof(rp->subpasses[0]) * rp->subpass_count, 0,
119 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
120 if (!rp->attachments) {
121 intel_render_pass_destroy(rp);
122 return VK_ERROR_OUT_OF_HOST_MEMORY;
123 }
124
125 rp->subpasses = (struct intel_render_pass_subpass *)
126 (rp->attachments + rp->attachment_count);
127
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700128 rp->obj.destroy = render_pass_destroy;
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700129
Chia-I Wuc278df82015-07-07 11:50:03 +0800130 for (i = 0; i < info->attachmentCount; i++) {
Chia-I Wubdeed152015-07-09 12:16:29 +0800131 struct intel_render_pass_attachment *att = &rp->attachments[i];
Chris Forbesfff9bf42015-06-15 15:26:19 +1200132
Chia-I Wuc278df82015-07-07 11:50:03 +0800133 att->format = info->pAttachments[i].format;
134 att->sample_count = info->pAttachments[i].samples;
135 att->initial_layout = info->pAttachments[i].initialLayout;
136 att->final_layout = info->pAttachments[i].finalLayout;
Chia-I Wubdeed152015-07-09 12:16:29 +0800137
Chia-I Wuc278df82015-07-07 11:50:03 +0800138 att->clear_on_load = (info->pAttachments[i].loadOp ==
139 VK_ATTACHMENT_LOAD_OP_CLEAR);
140 att->disable_store = (info->pAttachments[i].storeOp ==
141 VK_ATTACHMENT_STORE_OP_DONT_CARE);
Chia-I Wubdeed152015-07-09 12:16:29 +0800142
Chia-I Wuc278df82015-07-07 11:50:03 +0800143 att->stencil_clear_on_load = (info->pAttachments[i].stencilLoadOp ==
144 VK_ATTACHMENT_LOAD_OP_CLEAR);
145 att->stencil_disable_store = (info->pAttachments[i].stencilStoreOp ==
146 VK_ATTACHMENT_STORE_OP_DONT_CARE);
Chia-I Wu1af1a782015-07-09 10:46:39 +0800147 }
148
Chia-I Wubdeed152015-07-09 12:16:29 +0800149 for (i = 0; i < rp->subpass_count; i++) {
Chia-I Wuc278df82015-07-07 11:50:03 +0800150 const VkSubpassDescription *subpass_info = &info->pSubpasses[i];
Chia-I Wubdeed152015-07-09 12:16:29 +0800151 struct intel_render_pass_subpass *subpass = &rp->subpasses[i];
152 uint32_t j;
153
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -0600154 /* missing SPIR support? */
155 /* TODOVV: What do we test here? */
156 assert(!(subpass_info->inputCount) && "Unknown render pass failure");
Chia-I Wuc278df82015-07-07 11:50:03 +0800157
158 for (j = 0; j < subpass_info->colorCount; j++) {
159 const VkAttachmentReference *color_ref =
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600160 &subpass_info->pColorAttachments[j];
Chia-I Wuc278df82015-07-07 11:50:03 +0800161 const VkAttachmentReference *resolve_ref =
Cody Northrop6de6b0b2015-08-04 11:16:41 -0600162 (subpass_info->pResolveAttachments) ?
163 &subpass_info->pResolveAttachments[j] : NULL;
Chia-I Wuc278df82015-07-07 11:50:03 +0800164
165 subpass->color_indices[j] = color_ref->attachment;
166 subpass->resolve_indices[j] = (resolve_ref) ?
167 resolve_ref->attachment : VK_ATTACHMENT_UNUSED;
168 subpass->color_layouts[j] = color_ref->layout;
Chia-I Wubdeed152015-07-09 12:16:29 +0800169 }
170
Chia-I Wuc278df82015-07-07 11:50:03 +0800171 subpass->color_count = subpass_info->colorCount;
Chia-I Wubdeed152015-07-09 12:16:29 +0800172
Chia-I Wuc278df82015-07-07 11:50:03 +0800173 subpass->ds_index = subpass_info->depthStencilAttachment.attachment;
174 subpass->ds_layout = subpass_info->depthStencilAttachment.layout;
Chia-I Wubdeed152015-07-09 12:16:29 +0800175
Chia-I Wuc278df82015-07-07 11:50:03 +0800176 switch (subpass->ds_layout) {
Chia-I Wubdeed152015-07-09 12:16:29 +0800177 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
178 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
179 subpass->ds_optimal = true;
180 break;
181 default:
182 subpass->ds_optimal = false;
183 break;
184 }
185 }
Chris Forbesfff9bf42015-06-15 15:26:19 +1200186
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700187 *rp_ret = rp;
188
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600189 return VK_SUCCESS;
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700190}
191
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700192void intel_render_pass_destroy(struct intel_render_pass *rp)
193{
Chia-I Wubdeed152015-07-09 12:16:29 +0800194 if (rp->attachments)
195 intel_free(rp, rp->attachments);
196
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700197 intel_base_destroy(&rp->obj.base);
198}
199
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600200ICD_EXPORT VkResult VKAPI vkCreateFramebuffer(
201 VkDevice device,
202 const VkFramebufferCreateInfo* pCreateInfo,
203 VkFramebuffer* pFramebuffer)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700204{
205 struct intel_dev *dev = intel_dev(device);
206
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700207 return intel_fb_create(dev, pCreateInfo,
208 (struct intel_fb **) pFramebuffer);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700209}
210
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600211ICD_EXPORT void VKAPI vkDestroyFramebuffer(
Tony Barbourde4124d2015-07-03 10:33:54 -0600212 VkDevice device,
213 VkFramebuffer framebuffer)
214
215{
216 struct intel_obj *obj = intel_obj(framebuffer.handle);
217
218 obj->destroy(obj);
Tony Barbourde4124d2015-07-03 10:33:54 -0600219}
220
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600221ICD_EXPORT VkResult VKAPI vkCreateRenderPass(
222 VkDevice device,
223 const VkRenderPassCreateInfo* pCreateInfo,
224 VkRenderPass* pRenderPass)
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700225{
226 struct intel_dev *dev = intel_dev(device);
227
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700228 return intel_render_pass_create(dev, pCreateInfo,
229 (struct intel_render_pass **) pRenderPass);
Jon Ashburnc6f4a412014-12-24 12:38:36 -0700230}
Tony Barbourde4124d2015-07-03 10:33:54 -0600231
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600232ICD_EXPORT void VKAPI vkDestroyRenderPass(
Tony Barbourde4124d2015-07-03 10:33:54 -0600233 VkDevice device,
234 VkRenderPass renderPass)
235
236{
237 struct intel_obj *obj = intel_obj(renderPass.handle);
238
239 obj->destroy(obj);
Tony Barbourde4124d2015-07-03 10:33:54 -0600240}