File: vk_struct_compare.cpp

package info (click to toggle)
vulkan-validationlayers 1.4.321.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,412 kB
  • sloc: cpp: 594,175; python: 11,321; sh: 24; makefile: 20; xml: 14
file content (205 lines) | stat: -rw-r--r-- 12,508 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/* Copyright (c) 2024-2025 The Khronos Group Inc.
 * Copyright (c) 2024-2025 Valve Corporation
 * Copyright (c) 2024-2025 LunarG, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "utils/vk_struct_compare.h"
#include "utils/image_utils.h"
#include <vulkan/utility/vk_struct_helper.hpp>

static inline bool ComparePipelineSampleLocationsStateCreateInfo(const VkPipelineSampleLocationsStateCreateInfoEXT &a,
                                                                 const VkPipelineSampleLocationsStateCreateInfoEXT &b) {
    // Having VkSampleLocationEXT not confirmed to matter for the VU this is being used for, so just check the Count is good enough
    return (a.sampleLocationsEnable == b.sampleLocationsEnable) &&
           (a.sampleLocationsInfo.sampleLocationsPerPixel == b.sampleLocationsInfo.sampleLocationsPerPixel) &&
           (a.sampleLocationsInfo.sampleLocationGridSize.height == b.sampleLocationsInfo.sampleLocationGridSize.height) &&
           (a.sampleLocationsInfo.sampleLocationGridSize.width == b.sampleLocationsInfo.sampleLocationGridSize.width) &&
           (a.sampleLocationsInfo.sampleLocationsCount == b.sampleLocationsInfo.sampleLocationsCount);
}

bool ComparePipelineMultisampleStateCreateInfo(const VkPipelineMultisampleStateCreateInfo &a,
                                               const VkPipelineMultisampleStateCreateInfo &b) {
    bool valid_mask = true;
    if (a.pSampleMask && b.pSampleMask && (a.rasterizationSamples == b.rasterizationSamples)) {
        uint32_t length = (SampleCountSize(a.rasterizationSamples) + 31) / 32;
        for (uint32_t i = 0; i < length; i++) {
            if (a.pSampleMask[i] != b.pSampleMask[i]) {
                valid_mask = false;
                break;
            }
        }
    } else if (a.pSampleMask || b.pSampleMask) {
        valid_mask = false;  // one is not null
    }

    bool valid_pNext = true;
    if (a.pNext && b.pNext) {
        auto *a_sample_location = vku::FindStructInPNextChain<VkPipelineSampleLocationsStateCreateInfoEXT>(a.pNext);
        auto *b_sample_location = vku::FindStructInPNextChain<VkPipelineSampleLocationsStateCreateInfoEXT>(b.pNext);
        if (a_sample_location && b_sample_location) {
            if (!ComparePipelineSampleLocationsStateCreateInfo(*a_sample_location, *b_sample_location)) {
                valid_pNext = false;
            }
        } else if (a_sample_location != b_sample_location) {
            valid_pNext = false;  // both are not null
        }
    } else if (a.pNext != b.pNext) {
        valid_pNext = false;  // both are not null
    }

    return (a.sType == b.sType) && (valid_pNext) && (a.flags == b.flags) && (a.rasterizationSamples == b.rasterizationSamples) &&
           (a.sampleShadingEnable == b.sampleShadingEnable) && (a.minSampleShading == b.minSampleShading) && (valid_mask) &&
           (a.alphaToCoverageEnable == b.alphaToCoverageEnable) && (a.alphaToOneEnable == b.alphaToOneEnable);
}

bool CompareDescriptorSetLayoutBinding(const VkDescriptorSetLayoutBinding &a, const VkDescriptorSetLayoutBinding &b) {
    return (a.binding == b.binding) && (a.descriptorType == b.descriptorType) && (a.descriptorCount == b.descriptorCount) &&
           (a.stageFlags == b.stageFlags) && (a.pImmutableSamplers == b.pImmutableSamplers);
}

bool ComparePipelineColorBlendAttachmentState(const VkPipelineColorBlendAttachmentState &a,
                                              const VkPipelineColorBlendAttachmentState &b) {
    return (a.blendEnable == b.blendEnable) && (a.srcColorBlendFactor == b.srcColorBlendFactor) &&
           (a.dstColorBlendFactor == b.dstColorBlendFactor) && (a.colorBlendOp == b.colorBlendOp) &&
           (a.srcAlphaBlendFactor == b.srcAlphaBlendFactor) && (a.dstAlphaBlendFactor == b.dstAlphaBlendFactor) &&
           (a.alphaBlendOp == b.alphaBlendOp) && (a.colorWriteMask == b.colorWriteMask);
}

bool ComparePipelineFragmentShadingRateStateCreateInfo(const VkPipelineFragmentShadingRateStateCreateInfoKHR &a,
                                                       const VkPipelineFragmentShadingRateStateCreateInfoKHR &b) {
    // Since this is chained in a pnext, we don't want to check the pNext/sType
    return (a.fragmentSize.width == b.fragmentSize.width) && (a.fragmentSize.height == b.fragmentSize.height) &&
           (a.combinerOps[0] == b.combinerOps[0]) && (a.combinerOps[1] == b.combinerOps[1]);
}

static inline bool CompareSamplerYcbcrConversionInfo(const VkSamplerYcbcrConversionInfo &a, const VkSamplerYcbcrConversionInfo &b) {
    return a.conversion == b.conversion;
}
static inline bool CompareSamplerReductionModeCreateInfo(const VkSamplerReductionModeCreateInfo &a,
                                                         const VkSamplerReductionModeCreateInfo &b) {
    return a.reductionMode == b.reductionMode;
}

static inline bool CompareSamplerBorderColorComponentMappingCreateInfo(const VkSamplerBorderColorComponentMappingCreateInfoEXT &a,
                                                                       const VkSamplerBorderColorComponentMappingCreateInfoEXT &b) {
    return (a.components.r == b.components.r) && (a.components.g == b.components.g) && (a.components.b == b.components.b) &&
           (a.components.a == b.components.a) && (a.srgb == b.srgb);
}

static inline bool CompareSamplerCustomBorderColorCreateInfo(const VkSamplerCustomBorderColorCreateInfoEXT &a,
                                                             const VkSamplerCustomBorderColorCreateInfoEXT &b) {
    return (a.format == b.format);
}

bool CompareSamplerCreateInfo(const VkSamplerCreateInfo &a, const VkSamplerCreateInfo &b) {
    if (a.pNext && b.pNext) {
        auto *a_ycbcr_conversion = vku::FindStructInPNextChain<VkSamplerYcbcrConversionInfo>(a.pNext);
        auto *b_ycbcr_conversion = vku::FindStructInPNextChain<VkSamplerYcbcrConversionInfo>(b.pNext);
        if (a_ycbcr_conversion && b_ycbcr_conversion) {
            if (!CompareSamplerYcbcrConversionInfo(*a_ycbcr_conversion, *b_ycbcr_conversion)) {
                return false;
            }
        } else if (a_ycbcr_conversion != b_ycbcr_conversion) {
            return false;  // both are not null
        }

        auto *a_reduction_mode = vku::FindStructInPNextChain<VkSamplerReductionModeCreateInfo>(a.pNext);
        auto *b_reduction_mode = vku::FindStructInPNextChain<VkSamplerReductionModeCreateInfo>(b.pNext);
        if (a_reduction_mode && b_reduction_mode) {
            if (!CompareSamplerReductionModeCreateInfo(*a_reduction_mode, *b_reduction_mode)) {
                return false;
            }
        } else if (a_reduction_mode != b_reduction_mode) {
            return false;  // both are not null
        }

        auto *a_component_mapping = vku::FindStructInPNextChain<VkSamplerBorderColorComponentMappingCreateInfoEXT>(a.pNext);
        auto *b_component_mapping = vku::FindStructInPNextChain<VkSamplerBorderColorComponentMappingCreateInfoEXT>(b.pNext);
        if (a_component_mapping && b_component_mapping) {
            if (!CompareSamplerBorderColorComponentMappingCreateInfo(*a_component_mapping, *b_component_mapping)) {
                return false;
            }
        } else if (a_component_mapping != b_component_mapping) {
            return false;  // both are not null
        }

        auto *a_border_color = vku::FindStructInPNextChain<VkSamplerCustomBorderColorCreateInfoEXT>(a.pNext);
        auto *b_border_color = vku::FindStructInPNextChain<VkSamplerCustomBorderColorCreateInfoEXT>(b.pNext);
        if (a_border_color && b_border_color) {
            if (!CompareSamplerCustomBorderColorCreateInfo(*a_border_color, *b_border_color)) {
                return false;
            }
        } else if (a_border_color != b_border_color) {
            return false;  // both are not null
        }
    } else if (a.pNext != b.pNext) {
        return false;  // both are not null
    }

    return (a.flags == b.flags) && (a.magFilter == b.magFilter) && (a.minFilter == b.minFilter) && (a.mipmapMode == b.mipmapMode) &&
           (a.addressModeU == b.addressModeU) && (a.addressModeV == b.addressModeV) && (a.addressModeW == b.addressModeW) &&
           (a.mipLodBias == b.mipLodBias) && (a.anisotropyEnable == b.anisotropyEnable) && (a.maxAnisotropy == b.maxAnisotropy) &&
           (a.compareEnable == b.compareEnable) && (a.compareOp == b.compareOp) && (a.minLod == b.minLod) &&
           (a.maxLod == b.maxLod) && (a.borderColor == b.borderColor) && (a.unnormalizedCoordinates == b.unnormalizedCoordinates);
}

bool CompareDependencyInfo(const VkDependencyInfo &a, const VkDependencyInfo &b) {
    if (a.dependencyFlags != b.dependencyFlags || a.memoryBarrierCount != b.memoryBarrierCount ||
        a.bufferMemoryBarrierCount != b.bufferMemoryBarrierCount || a.imageMemoryBarrierCount != b.imageMemoryBarrierCount) {
        return false;
    }
    for (uint32_t i = 0; i < b.memoryBarrierCount; ++i) {
        if (b.pMemoryBarriers[i].srcStageMask != a.pMemoryBarriers[i].srcStageMask ||
            b.pMemoryBarriers[i].srcAccessMask != a.pMemoryBarriers[i].srcAccessMask ||
            b.pMemoryBarriers[i].dstStageMask != a.pMemoryBarriers[i].dstStageMask ||
            b.pMemoryBarriers[i].dstAccessMask != a.pMemoryBarriers[i].dstAccessMask) {
            return false;
        }
    }
    for (uint32_t i = 0; i < b.bufferMemoryBarrierCount; ++i) {
        if (b.pBufferMemoryBarriers[i].srcStageMask != a.pBufferMemoryBarriers[i].srcStageMask ||
            b.pBufferMemoryBarriers[i].srcAccessMask != a.pBufferMemoryBarriers[i].srcAccessMask ||
            b.pBufferMemoryBarriers[i].dstStageMask != a.pBufferMemoryBarriers[i].dstStageMask ||
            b.pBufferMemoryBarriers[i].dstAccessMask != a.pBufferMemoryBarriers[i].dstAccessMask ||
            b.pBufferMemoryBarriers[i].srcQueueFamilyIndex != a.pBufferMemoryBarriers[i].srcQueueFamilyIndex ||
            b.pBufferMemoryBarriers[i].dstQueueFamilyIndex != a.pBufferMemoryBarriers[i].dstQueueFamilyIndex ||
            b.pBufferMemoryBarriers[i].buffer != a.pBufferMemoryBarriers[i].buffer ||
            b.pBufferMemoryBarriers[i].offset != a.pBufferMemoryBarriers[i].offset ||
            b.pBufferMemoryBarriers[i].size != a.pBufferMemoryBarriers[i].size) {
            return false;
        }
    }

    for (uint32_t i = 0; i < b.imageMemoryBarrierCount; ++i) {
        if (b.pImageMemoryBarriers[i].srcStageMask != a.pImageMemoryBarriers[i].srcStageMask ||
            b.pImageMemoryBarriers[i].srcAccessMask != a.pImageMemoryBarriers[i].srcAccessMask ||
            b.pImageMemoryBarriers[i].dstStageMask != a.pImageMemoryBarriers[i].dstStageMask ||
            b.pImageMemoryBarriers[i].dstAccessMask != a.pImageMemoryBarriers[i].dstAccessMask ||
            b.pImageMemoryBarriers[i].oldLayout != a.pImageMemoryBarriers[i].oldLayout ||
            b.pImageMemoryBarriers[i].newLayout != a.pImageMemoryBarriers[i].newLayout ||
            b.pImageMemoryBarriers[i].srcQueueFamilyIndex != a.pImageMemoryBarriers[i].srcQueueFamilyIndex ||
            b.pImageMemoryBarriers[i].dstQueueFamilyIndex != a.pImageMemoryBarriers[i].dstQueueFamilyIndex ||
            b.pImageMemoryBarriers[i].image != a.pImageMemoryBarriers[i].image ||
            b.pImageMemoryBarriers[i].subresourceRange.aspectMask != a.pImageMemoryBarriers[i].subresourceRange.aspectMask ||
            b.pImageMemoryBarriers[i].subresourceRange.baseMipLevel != a.pImageMemoryBarriers[i].subresourceRange.baseMipLevel ||
            b.pImageMemoryBarriers[i].subresourceRange.levelCount != a.pImageMemoryBarriers[i].subresourceRange.levelCount ||
            b.pImageMemoryBarriers[i].subresourceRange.baseArrayLayer !=
                a.pImageMemoryBarriers[i].subresourceRange.baseArrayLayer ||
            b.pImageMemoryBarriers[i].subresourceRange.layerCount != a.pImageMemoryBarriers[i].subresourceRange.layerCount) {
            return false;
        }
    }
    return true;
}