Nathaniel Cesario | 9ee6c57 | 2022-04-06 10:56:19 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2015-2022 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2022 Valve Corporation |
| 3 | * Copyright (c) 2015-2022 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2022 Google Inc. |
| 5 | * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved. |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | * |
| 19 | * Author: Courtney Goeltzenleuchter <courtneygo@google.com> |
| 20 | * Author: Tobin Ehlis <tobine@google.com> |
| 21 | * Author: Chris Forbes <chrisf@ijw.co.nz> |
| 22 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 23 | * Author: Dave Houlton <daveh@lunarg.com> |
| 24 | * Author: John Zulauf <jzulauf@lunarg.com> |
| 25 | * Author: Tobias Hector <tobias.hector@amd.com> |
| 26 | * Author: Jeremy Gebben <jeremyg@lunarg.com> |
| 27 | * Author: Nathaniel Cesario <nathaniel@lunarg.com> |
| 28 | */ |
| 29 | |
Nathaniel Cesario | 4be91bc | 2022-02-15 14:35:43 -0700 | [diff] [blame] | 30 | #pragma once |
| 31 | |
| 32 | #include <vector> |
| 33 | #include <memory> |
| 34 | #include "base_node.h" |
Nathaniel Cesario | 2e8dc80 | 2022-02-15 14:54:04 -0700 | [diff] [blame] | 35 | #include "hash_util.h" |
| 36 | #include "hash_vk_types.h" |
Nathaniel Cesario | 5239844 | 2022-02-15 16:33:46 -0700 | [diff] [blame] | 37 | #include "state_tracker.h" |
Nathaniel Cesario | 4be91bc | 2022-02-15 14:35:43 -0700 | [diff] [blame] | 38 | |
| 39 | // Fwd declarations -- including descriptor_set.h creates an ugly include loop |
| 40 | namespace cvdescriptorset { |
| 41 | class DescriptorSetLayout; |
| 42 | class DescriptorSetLayoutDef; |
| 43 | } // namespace cvdescriptorset |
| 44 | |
| 45 | class ValidationStateTracker; |
| 46 | |
| 47 | // Canonical dictionary for the pipeline layout's layout of descriptorsetlayouts |
| 48 | using DescriptorSetLayoutDef = cvdescriptorset::DescriptorSetLayoutDef; |
| 49 | using DescriptorSetLayoutId = std::shared_ptr<const DescriptorSetLayoutDef>; |
| 50 | using PipelineLayoutSetLayoutsDef = std::vector<DescriptorSetLayoutId>; |
| 51 | using PipelineLayoutSetLayoutsDict = |
| 52 | hash_util::Dictionary<PipelineLayoutSetLayoutsDef, hash_util::IsOrderedContainer<PipelineLayoutSetLayoutsDef>>; |
| 53 | using PipelineLayoutSetLayoutsId = PipelineLayoutSetLayoutsDict::Id; |
| 54 | |
| 55 | // Canonical dictionary for PushConstantRanges |
| 56 | using PushConstantRangesDict = hash_util::Dictionary<PushConstantRanges>; |
| 57 | using PushConstantRangesId = PushConstantRangesDict::Id; |
| 58 | |
| 59 | // Defines/stores a compatibility defintion for set N |
| 60 | // The "layout layout" must store at least set+1 entries, but only the first set+1 are considered for hash and equality testing |
| 61 | // Note: the "cannonical" data are referenced by Id, not including handle or device specific state |
| 62 | // Note: hash and equality only consider layout_id entries [0, set] for determining uniqueness |
| 63 | struct PipelineLayoutCompatDef { |
| 64 | uint32_t set; |
| 65 | PushConstantRangesId push_constant_ranges; |
| 66 | PipelineLayoutSetLayoutsId set_layouts_id; |
| 67 | PipelineLayoutCompatDef(const uint32_t set_index, const PushConstantRangesId pcr_id, const PipelineLayoutSetLayoutsId sl_id) |
| 68 | : set(set_index), push_constant_ranges(pcr_id), set_layouts_id(sl_id) {} |
| 69 | size_t hash() const; |
| 70 | bool operator==(const PipelineLayoutCompatDef &other) const; |
| 71 | }; |
| 72 | |
| 73 | // Canonical dictionary for PipelineLayoutCompat records |
| 74 | using PipelineLayoutCompatDict = hash_util::Dictionary<PipelineLayoutCompatDef, hash_util::HasHashMember<PipelineLayoutCompatDef>>; |
| 75 | using PipelineLayoutCompatId = PipelineLayoutCompatDict::Id; |
| 76 | |
| 77 | // Store layouts and pushconstants for PipelineLayout |
| 78 | class PIPELINE_LAYOUT_STATE : public BASE_NODE { |
| 79 | public: |
| 80 | using SetLayoutVector = std::vector<std::shared_ptr<cvdescriptorset::DescriptorSetLayout const>>; |
| 81 | const SetLayoutVector set_layouts; |
| 82 | // canonical form IDs for the "compatible for set" contents |
| 83 | const PushConstantRangesId push_constant_ranges; |
| 84 | // table of "compatible for set N" cannonical forms for trivial accept validation |
| 85 | const std::vector<PipelineLayoutCompatId> compat_for_set; |
Nathaniel Cesario | 08ae4bf | 2022-03-17 11:42:44 -0600 | [diff] [blame] | 86 | VkPipelineLayoutCreateFlags create_flags; |
Nathaniel Cesario | 4be91bc | 2022-02-15 14:35:43 -0700 | [diff] [blame] | 87 | |
| 88 | PIPELINE_LAYOUT_STATE(ValidationStateTracker *dev_data, VkPipelineLayout l, const VkPipelineLayoutCreateInfo *pCreateInfo); |
Nathaniel Cesario | 81257cb | 2022-02-16 17:15:58 -0700 | [diff] [blame] | 89 | // Merge 2 or more non-overlapping layouts |
| 90 | PIPELINE_LAYOUT_STATE(const layer_data::span<const PIPELINE_LAYOUT_STATE *const> &layouts); |
| 91 | template <typename Container> |
| 92 | PIPELINE_LAYOUT_STATE(const Container &layouts) |
| 93 | : PIPELINE_LAYOUT_STATE(layer_data::span<const PIPELINE_LAYOUT_STATE *const>{layouts}) {} |
Nathaniel Cesario | 4be91bc | 2022-02-15 14:35:43 -0700 | [diff] [blame] | 94 | |
| 95 | VkPipelineLayout layout() const { return handle_.Cast<VkPipelineLayout>(); } |
| 96 | |
| 97 | std::shared_ptr<cvdescriptorset::DescriptorSetLayout const> GetDsl(uint32_t set) const { |
| 98 | std::shared_ptr<cvdescriptorset::DescriptorSetLayout const> dsl = nullptr; |
| 99 | if (set < set_layouts.size()) { |
| 100 | dsl = set_layouts[set]; |
| 101 | } |
| 102 | return dsl; |
| 103 | } |
Nathaniel Cesario | 08ae4bf | 2022-03-17 11:42:44 -0600 | [diff] [blame] | 104 | |
| 105 | VkPipelineLayoutCreateFlags CreateFlags() const { return create_flags; } |
Nathaniel Cesario | 4be91bc | 2022-02-15 14:35:43 -0700 | [diff] [blame] | 106 | }; |