1 // Copyright 2019 The Amber Authors.
2 // Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 #include "src/vulkan/descriptor.h"
17
18 #include <cassert>
19 #include <cstring>
20
21 #include "src/vulkan/command_buffer.h"
22 #include "src/vulkan/device.h"
23
24 namespace amber {
25 namespace vulkan {
26
Descriptor(DescriptorType type,Device * device,uint32_t desc_set,uint32_t binding)27 Descriptor::Descriptor(DescriptorType type,
28 Device* device,
29 uint32_t desc_set,
30 uint32_t binding)
31 : device_(device),
32 type_(type),
33 descriptor_set_(desc_set),
34 binding_(binding) {}
35
36 Descriptor::~Descriptor() = default;
37
GetVkDescriptorType() const38 VkDescriptorType Descriptor::GetVkDescriptorType() const {
39 switch (type_) {
40 case DescriptorType::kStorageBuffer:
41 return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
42 case DescriptorType::kStorageBufferDynamic:
43 return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC;
44 case DescriptorType::kUniformBuffer:
45 return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
46 case DescriptorType::kUniformBufferDynamic:
47 return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
48 case DescriptorType::kSampler:
49 return VK_DESCRIPTOR_TYPE_SAMPLER;
50 case DescriptorType::kStorageImage:
51 return VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
52 case DescriptorType::kCombinedImageSampler:
53 return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
54 case DescriptorType::kUniformTexelBuffer:
55 return VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
56 case DescriptorType::kStorageTexelBuffer:
57 return VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
58 case DescriptorType::kTLAS:
59 return VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR;
60 default:
61 assert(type_ == DescriptorType::kSampledImage);
62 return VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
63 }
64 }
65
66 } // namespace vulkan
67 } // namespace amber
68