1 // Copyright 2019 The Amber Authors.
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 "src/vulkan/descriptor.h"
16
17 #include <cassert>
18 #include <cstring>
19
20 #include "src/vulkan/command_buffer.h"
21 #include "src/vulkan/device.h"
22
23 namespace amber {
24 namespace vulkan {
25
Descriptor(DescriptorType type,Device * device,uint32_t desc_set,uint32_t binding)26 Descriptor::Descriptor(DescriptorType type,
27 Device* device,
28 uint32_t desc_set,
29 uint32_t binding)
30 : device_(device),
31 type_(type),
32 descriptor_set_(desc_set),
33 binding_(binding) {}
34
35 Descriptor::~Descriptor() = default;
36
GetVkDescriptorType() const37 VkDescriptorType Descriptor::GetVkDescriptorType() const {
38 switch (type_) {
39 case DescriptorType::kStorageBuffer:
40 return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
41 case DescriptorType::kStorageBufferDynamic:
42 return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
43 case DescriptorType::kUniformBuffer:
44 return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
45 case DescriptorType::kUniformBufferDynamic:
46 return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
47 case DescriptorType::kSampler:
48 return VK_DESCRIPTOR_TYPE_SAMPLER;
49 case DescriptorType::kStorageImage:
50 return VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
51 case DescriptorType::kCombinedImageSampler:
52 return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
53 case DescriptorType::kUniformTexelBuffer:
54 return VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
55 case DescriptorType::kStorageTexelBuffer:
56 return VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
57 default:
58 assert(type_ == DescriptorType::kSampledImage);
59 return VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
60 }
61 }
62
63 } // namespace vulkan
64 } // namespace amber
65