chromium/third_party/vulkan-validation-layers/src/layers/sync/sync_common.h

/*
 * Copyright (c) 2019-2024 Valve Corporation
 * Copyright (c) 2019-2024 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.
 */
#pragma once
#include "error_message/error_location.h"
#include "containers/subresource_adapter.h"
#include "containers/range_vector.h"
#include "generated/sync_validation_types.h"

namespace vvl {
class Buffer;
class BufferView;
struct VertexBufferBinding;
struct IndexBufferBinding;
}  // namespace vvl

namespace syncval_state {
class CommandBuffer;
class ImageState;
class ImageViewState;
class Swapchain;
}  // namespace syncval_state

class HazardResult;
class SyncValidator;

ImageRangeGen;

// The resource tag index is relative to the command buffer or queue in which it's found
QueueId;
constexpr static QueueId kQueueIdInvalid =;
constexpr static QueueId kQueueAny =;

ResourceUsageTag;
constexpr static ResourceUsageTag kMaxIndex =;
constexpr static ResourceUsageTag kInvalidTag =;

ResourceUsageRange;
ResourceAddress;
ResourceAccessRange;

// Usage tag extended with resource handle information
struct ResourceUsageTagEx {};

template <typename T>
ResourceAccessRange MakeRange(const T &has_offset_and_size) {}
ResourceAccessRange MakeRange(VkDeviceSize start, VkDeviceSize size);
ResourceAccessRange MakeRange(const vvl::Buffer &buffer, VkDeviceSize offset, VkDeviceSize size);
ResourceAccessRange MakeRange(const vvl::BufferView &buf_view_state);
ResourceAccessRange MakeRange(VkDeviceSize offset, uint32_t first_index, uint32_t count, uint32_t stride);
ResourceAccessRange MakeRange(const vvl::VertexBufferBinding &binding, uint32_t first_index, const std::optional<uint32_t> &count,
                              uint32_t stride);
ResourceAccessRange MakeRange(const vvl::IndexBufferBinding &binding, uint32_t first_index, const std::optional<uint32_t> &count,
                              uint32_t index_size);

extern const ResourceAccessRange kFullRange;

constexpr VkImageAspectFlags kColorAspects =;
constexpr VkImageAspectFlags kDepthStencilAspects =;

class SyncValidationInfo {};


// Useful Utilites for manipulating StageAccess parameters, suitable as base class to save typing
struct SyncStageAccess {};

// Notes:
//  * Design goal is performance optimized set creation during specific SyncVal operations
//  * Key must be integral.
//  * We aren't interested as of this implementation in caching lookups, only inserts
//  * using a raw C-style array instead of std::array intentionally for size/performance reasons
//
// The following were shown to not improve hit rate for current usage (tag set gathering).  For general use YMMV.
//  * More complicated index construction (at >> LogSize ^ at)
//  * Multi-way LRU eviction caching (equivalent hit rate to 1-way direct replacement of same total cache slots) but with
//    higher complexity.
template <typename IntegralKey, size_t LogSize = 4U, IntegralKey kInvalidKey = IntegralKey(0)>
class CachedInsertSet : public std::set<IntegralKey> {};

// A wrapper for a single range with the same semantics as other non-trivial range generators
template <typename KeyType>
class SingleRangeGenerator {};