blob: 5c4941b3113c0b4a871b08f1d6b2309f2e056675 [file] [log] [blame]
Nathaniel Cesario9ee6c572022-04-06 10:56:19 -06001/* 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 Cesario4be91bc2022-02-15 14:35:43 -070030#pragma once
31
32#include <vector>
33#include <memory>
34#include "base_node.h"
Nathaniel Cesario2e8dc802022-02-15 14:54:04 -070035#include "hash_util.h"
36#include "hash_vk_types.h"
Nathaniel Cesario52398442022-02-15 16:33:46 -070037#include "state_tracker.h"
Nathaniel Cesario4be91bc2022-02-15 14:35:43 -070038
39// Fwd declarations -- including descriptor_set.h creates an ugly include loop
40namespace cvdescriptorset {
41class DescriptorSetLayout;
42class DescriptorSetLayoutDef;
43} // namespace cvdescriptorset
44
45class ValidationStateTracker;
46
47// Canonical dictionary for the pipeline layout's layout of descriptorsetlayouts
48using DescriptorSetLayoutDef = cvdescriptorset::DescriptorSetLayoutDef;
49using DescriptorSetLayoutId = std::shared_ptr<const DescriptorSetLayoutDef>;
50using PipelineLayoutSetLayoutsDef = std::vector<DescriptorSetLayoutId>;
51using PipelineLayoutSetLayoutsDict =
52 hash_util::Dictionary<PipelineLayoutSetLayoutsDef, hash_util::IsOrderedContainer<PipelineLayoutSetLayoutsDef>>;
53using PipelineLayoutSetLayoutsId = PipelineLayoutSetLayoutsDict::Id;
54
55// Canonical dictionary for PushConstantRanges
56using PushConstantRangesDict = hash_util::Dictionary<PushConstantRanges>;
57using 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
63struct 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
74using PipelineLayoutCompatDict = hash_util::Dictionary<PipelineLayoutCompatDef, hash_util::HasHashMember<PipelineLayoutCompatDef>>;
75using PipelineLayoutCompatId = PipelineLayoutCompatDict::Id;
76
77// Store layouts and pushconstants for PipelineLayout
78class 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 Cesario08ae4bf2022-03-17 11:42:44 -060086 VkPipelineLayoutCreateFlags create_flags;
Nathaniel Cesario4be91bc2022-02-15 14:35:43 -070087
88 PIPELINE_LAYOUT_STATE(ValidationStateTracker *dev_data, VkPipelineLayout l, const VkPipelineLayoutCreateInfo *pCreateInfo);
Nathaniel Cesario81257cb2022-02-16 17:15:58 -070089 // 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 Cesario4be91bc2022-02-15 14:35:43 -070094
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 Cesario08ae4bf2022-03-17 11:42:44 -0600104
105 VkPipelineLayoutCreateFlags CreateFlags() const { return create_flags; }
Nathaniel Cesario4be91bc2022-02-15 14:35:43 -0700106};