Home | History | Annotate | Download | only in vk
      1 /*
      2 * Copyright 2016 Google Inc.
      3 *
      4 * Use of this source code is governed by a BSD-style license that can be
      5 * found in the LICENSE file.
      6 */
      7 
      8 #include "GrVkImageView.h"
      9 #include "GrVkGpu.h"
     10 #include "GrVkUtil.h"
     11 
     12 const GrVkImageView* GrVkImageView::Create(GrVkGpu* gpu, VkImage image, VkFormat format,
     13                                            Type viewType) {
     14     VkImageView imageView;
     15 
     16     // Create the VkImageView
     17     VkImageViewCreateInfo viewInfo = {
     18         VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,               // sType
     19         NULL,                                                   // pNext
     20         0,                                                      // flags
     21         image,                                                  // image
     22         VK_IMAGE_VIEW_TYPE_2D,                                  // viewType
     23         format,                                                 // format
     24         { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G,
     25           VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },     // components
     26         { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },              // subresourceRange
     27     };
     28     if (kStencil_Type == viewType) {
     29         viewInfo.components.r = VK_COMPONENT_SWIZZLE_ZERO;
     30         viewInfo.components.g = VK_COMPONENT_SWIZZLE_ZERO;
     31         viewInfo.components.b = VK_COMPONENT_SWIZZLE_ZERO;
     32         viewInfo.components.a = VK_COMPONENT_SWIZZLE_ZERO;
     33         viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
     34     }
     35 
     36     VkResult err = GR_VK_CALL(gpu->vkInterface(), CreateImageView(gpu->device(), &viewInfo,
     37                                                                   nullptr, &imageView));
     38     if (err) {
     39         return nullptr;
     40     }
     41 
     42     return new GrVkImageView(imageView);
     43 }
     44 
     45 void GrVkImageView::freeGPUData(const GrVkGpu* gpu) const {
     46     GR_VK_CALL(gpu->vkInterface(), DestroyImageView(gpu->device(), fImageView, nullptr));
     47 }
     48 
     49 
     50