1 // Copyright 2018 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "VkImageView.hpp"
16 #include "VkImage.hpp"
17
18 namespace vk
19 {
20
ImageView(const VkImageViewCreateInfo * pCreateInfo,void * mem)21 ImageView::ImageView(const VkImageViewCreateInfo* pCreateInfo, void* mem) :
22 image(Cast(pCreateInfo->image)), viewType(pCreateInfo->viewType), format(pCreateInfo->format),
23 components(pCreateInfo->components), subresourceRange(pCreateInfo->subresourceRange)
24 {
25 }
26
ComputeRequiredAllocationSize(const VkImageViewCreateInfo * pCreateInfo)27 size_t ImageView::ComputeRequiredAllocationSize(const VkImageViewCreateInfo* pCreateInfo)
28 {
29 return 0;
30 }
31
destroy(const VkAllocationCallbacks * pAllocator)32 void ImageView::destroy(const VkAllocationCallbacks* pAllocator)
33 {
34 }
35
imageTypesMatch(VkImageType imageType) const36 bool ImageView::imageTypesMatch(VkImageType imageType) const
37 {
38 bool isCube = image->isCube();
39
40 switch(imageType)
41 {
42 case VK_IMAGE_TYPE_1D:
43 switch(viewType)
44 {
45 case VK_IMAGE_VIEW_TYPE_1D:
46 case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
47 return true;
48 }
49 break;
50 case VK_IMAGE_TYPE_2D:
51 switch(viewType)
52 {
53 case VK_IMAGE_VIEW_TYPE_2D:
54 case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
55 return !isCube;
56 case VK_IMAGE_VIEW_TYPE_CUBE:
57 case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
58 return isCube;
59 }
60 break;
61 case VK_IMAGE_TYPE_3D:
62 switch(viewType)
63 {
64 case VK_IMAGE_VIEW_TYPE_3D:
65 return true;
66 }
67 break;
68 default:
69 break;
70 }
71
72 return false;
73 }
74
clear(const VkClearValue & clearValue,const VkImageAspectFlags aspectMask,const VkRect2D & renderArea)75 void ImageView::clear(const VkClearValue& clearValue, const VkImageAspectFlags aspectMask, const VkRect2D& renderArea)
76 {
77 // Note: clearing ignores swizzling, so components is ignored.
78
79 if(!imageTypesMatch(image->getImageType()))
80 {
81 UNIMPLEMENTED();
82 }
83
84 if(image->getFormat() != format)
85 {
86 UNIMPLEMENTED();
87 }
88
89 VkImageSubresourceRange sr = subresourceRange;
90 sr.aspectMask = aspectMask;
91 image->clear(clearValue, renderArea, subresourceRange);
92 }
93
clear(const VkClearValue & clearValue,const VkImageAspectFlags aspectMask,const VkClearRect & renderArea)94 void ImageView::clear(const VkClearValue& clearValue, const VkImageAspectFlags aspectMask, const VkClearRect& renderArea)
95 {
96 // Note: clearing ignores swizzling, so components is ignored.
97
98 if(!imageTypesMatch(image->getImageType()))
99 {
100 UNIMPLEMENTED();
101 }
102
103 if(image->getFormat() != format)
104 {
105 UNIMPLEMENTED();
106 }
107
108 VkImageSubresourceRange sr;
109 sr.aspectMask = aspectMask;
110 sr.baseMipLevel = subresourceRange.baseMipLevel;
111 sr.levelCount = subresourceRange.levelCount;
112 sr.baseArrayLayer = renderArea.baseArrayLayer + subresourceRange.baseArrayLayer;
113 sr.layerCount = renderArea.layerCount;
114
115 image->clear(clearValue, renderArea.rect, sr);
116 }
117
118 }