Skip to content

Commit

Permalink
layers: Use vvl unordered_map in sync helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-lunarg authored and spencer-lunarg committed Oct 3, 2024
1 parent 65f986c commit 9cf4cbd
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 153 deletions.
11 changes: 5 additions & 6 deletions layers/core_checks/cc_synchronization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -926,12 +926,11 @@ bool CoreChecks::ValidateStageMasksAgainstQueueCapabilities(const LogObjectList
return skip;
}

static const std::map<VkPipelineStageFlags2KHR, VkQueueFlags> metaFlags{
{VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT_KHR, VK_QUEUE_GRAPHICS_BIT},
{VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT_KHR, VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT},
{VK_PIPELINE_STAGE_2_PRE_RASTERIZATION_SHADERS_BIT_KHR, VK_QUEUE_GRAPHICS_BIT},
{VK_PIPELINE_STAGE_2_VERTEX_INPUT_BIT_KHR, VK_QUEUE_GRAPHICS_BIT},
};
static const std::array<std::pair<VkPipelineStageFlags2KHR, VkQueueFlags>, 4> metaFlags{
{{VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT_KHR, VK_QUEUE_GRAPHICS_BIT},
{VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT_KHR, VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT},
{VK_PIPELINE_STAGE_2_PRE_RASTERIZATION_SHADERS_BIT_KHR, VK_QUEUE_GRAPHICS_BIT},
{VK_PIPELINE_STAGE_2_VERTEX_INPUT_BIT_KHR, VK_QUEUE_GRAPHICS_BIT}}};

for (const auto &entry : metaFlags) {
if (((entry.first & stage_mask) != 0) && ((entry.second & queue_flags) == 0)) {
Expand Down
5 changes: 5 additions & 0 deletions layers/error_message/error_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ bool operator<(const Key& lhs, const Key& rhs) {
return false;
}

bool operator==(const Key& lhs, const Key& rhs) {
return lhs.function == rhs.function && lhs.structure == rhs.structure && lhs.field == rhs.field &&
lhs.recurse_field == rhs.recurse_field;
}

bool operator==(const Key& key, const Location& loc) {
assert(key.function != Func::Empty || key.structure != Struct::Empty);
assert(loc.function != Func::Empty);
Expand Down
12 changes: 12 additions & 0 deletions layers/error_message/error_location.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "logging.h"
#include "containers/custom_containers.h"
#include "chassis/chassis_handle_data.h"
#include "utils/hash_util.h"

// Holds the 'Location' of where the code is inside a function/struct/etc
// see docs/error_object.md for more details
Expand Down Expand Up @@ -143,9 +144,20 @@ struct Key {
: function(fn), structure(Struct::Empty), field(f), recurse_field(recurse) {}
Key(Func fn, Struct r, Field f = Field::Empty, bool recurse = false)
: function(fn), structure(r), field(f), recurse_field(recurse) {}

struct hash {
public:
std::size_t operator()(const Key& key) const {
hash_util::HashCombiner hc;
hc << static_cast<uint32_t>(key.function) << static_cast<uint32_t>(key.structure) << static_cast<uint32_t>(key.field)
<< key.recurse_field;
return hc.Value();
}
};
};

bool operator<(const Key& lhs, const Key& rhs);
bool operator==(const Key& lhs, const Key& rhs);
bool operator==(const Key& key, const Location& loc);

// Entry in a VUID lookup table
Expand Down
6 changes: 3 additions & 3 deletions layers/sync/sync_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ VkAccessFlags2KHR CompatibleAccessMask(VkPipelineStageFlags2KHR stage_mask) {
return result;
}

VkPipelineStageFlags2KHR RelatedPipelineStages(VkPipelineStageFlags2KHR stage_mask,
const std::map<VkPipelineStageFlags2KHR, VkPipelineStageFlags2KHR> &map) {
static VkPipelineStageFlags2KHR RelatedPipelineStages(
VkPipelineStageFlags2 stage_mask, const vvl::unordered_map<VkPipelineStageFlags2KHR, VkPipelineStageFlags2KHR> &map) {
VkPipelineStageFlags2KHR unscanned = stage_mask;
VkPipelineStageFlags2KHR related = 0;
for (const auto &entry : map) {
Expand Down Expand Up @@ -203,7 +203,7 @@ std::string StringAccessFlags(VkAccessFlags2KHR mask) {
}

ShaderStageAccesses GetShaderStageAccesses(VkShaderStageFlagBits shader_stage) {
static const std::map<VkShaderStageFlagBits, ShaderStageAccesses> map = {
static const vvl::unordered_map<VkShaderStageFlagBits, ShaderStageAccesses> map = {
// clang-format off
{VK_SHADER_STAGE_VERTEX_BIT, {
SYNC_VERTEX_SHADER_SHADER_SAMPLED_READ,
Expand Down
228 changes: 114 additions & 114 deletions layers/sync/sync_vuid_maps.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions layers/sync/sync_vuid_maps.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct DeviceExtensions;

namespace sync_vuid_maps {

const std::map<VkPipelineStageFlags2KHR, std::string> &GetFeatureNameMap();
const vvl::unordered_map<VkPipelineStageFlags2KHR, std::string> &GetFeatureNameMap();

const std::string &GetBadFeatureVUID(const Location &loc, VkPipelineStageFlags2 bit, const DeviceExtensions &device_extensions);

Expand All @@ -48,7 +48,7 @@ enum class QueueError {
kHostStage,
};

const std::map<QueueError, std::string> &GetQueueErrorSummaryMap();
const vvl::unordered_map<QueueError, std::string> &GetQueueErrorSummaryMap();

const std::string &GetBarrierQueueVUID(const Location &loc, QueueError error);

Expand Down
16 changes: 8 additions & 8 deletions layers/vulkan/generated/sync_validation_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,8 +1423,8 @@ const std::map<VkAccessFlags2, SyncStageAccessFlags>& syncStageAccessMaskByAcces
return variable;
}

const std::map<VkPipelineStageFlags2, VkAccessFlags2>& syncDirectStageToAccessMask() {
static const std::map<VkPipelineStageFlags2, VkAccessFlags2> variable = {
const vvl::unordered_map<VkPipelineStageFlags2, VkAccessFlags2>& syncDirectStageToAccessMask() {
static const vvl::unordered_map<VkPipelineStageFlags2, VkAccessFlags2> variable = {
{ VK_PIPELINE_STAGE_2_DRAW_INDIRECT_BIT, (
VK_ACCESS_2_INDIRECT_COMMAND_READ_BIT |
VK_ACCESS_2_TRANSFORM_FEEDBACK_COUNTER_READ_BIT_EXT
Expand Down Expand Up @@ -1633,8 +1633,8 @@ const std::map<VkPipelineStageFlags2, VkAccessFlags2>& syncDirectStageToAccessMa
return variable;
}

const std::map<VkQueueFlagBits, VkPipelineStageFlags2>& syncAllCommandStagesByQueueFlags() {
static const std::map<VkQueueFlagBits, VkPipelineStageFlags2> variable = {
const vvl::unordered_map<VkQueueFlagBits, VkPipelineStageFlags2>& syncAllCommandStagesByQueueFlags() {
static const vvl::unordered_map<VkQueueFlagBits, VkPipelineStageFlags2> variable = {
{ VK_QUEUE_TRANSFER_BIT, (
VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT |
VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT |
Expand Down Expand Up @@ -1725,8 +1725,8 @@ const std::map<VkQueueFlagBits, VkPipelineStageFlags2>& syncAllCommandStagesByQu
return variable;
}

const std::map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyEarlierStages() {
static const std::map<VkPipelineStageFlags2, VkPipelineStageFlags2> variable = {
const vvl::unordered_map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyEarlierStages() {
static const vvl::unordered_map<VkPipelineStageFlags2, VkPipelineStageFlags2> variable = {
{ VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT, (
VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT
)},
Expand Down Expand Up @@ -1956,8 +1956,8 @@ const std::map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyEarli
return variable;
}

const std::map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyLaterStages() {
static const std::map<VkPipelineStageFlags2, VkPipelineStageFlags2> variable = {
const vvl::unordered_map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyLaterStages() {
static const vvl::unordered_map<VkPipelineStageFlags2, VkPipelineStageFlags2> variable = {
{ VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT, (
VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT |
VK_PIPELINE_STAGE_2_DRAW_INDIRECT_BIT |
Expand Down
12 changes: 6 additions & 6 deletions layers/vulkan/generated/sync_validation_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,23 +471,23 @@ static const SyncStageAccessFlags syncStageAccessWriteMask = ( // Mask of all w
SYNC_QUEUE_FAMILY_OWNERSHIP_TRANSFER_BIT
);

// Bit order mask of stage_access bit for each stage
// Bit order mask of stage_access bit for each stage. Order matters, don't try to use vvl::unordered_map
const std::map<VkPipelineStageFlags2, SyncStageAccessFlags>& syncStageAccessMaskByStageBit();

// Bit order mask of stage_access bit for each access
// Bit order mask of stage_access bit for each access. Order matters, don't try to use vvl::unordered_map
const std::map<VkAccessFlags2, SyncStageAccessFlags>& syncStageAccessMaskByAccessBit();

// Direct VkPipelineStageFlags to valid VkAccessFlags lookup table
const std::map<VkPipelineStageFlags2, VkAccessFlags2>& syncDirectStageToAccessMask();
const vvl::unordered_map<VkPipelineStageFlags2, VkAccessFlags2>& syncDirectStageToAccessMask();

// Pipeline stages corresponding to VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT for each VkQueueFlagBits
const std::map<VkQueueFlagBits, VkPipelineStageFlags2>& syncAllCommandStagesByQueueFlags();
const vvl::unordered_map<VkQueueFlagBits, VkPipelineStageFlags2>& syncAllCommandStagesByQueueFlags();

// Masks of logically earlier stage flags for a given stage flag
const std::map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyEarlierStages();
const vvl::unordered_map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyEarlierStages();

// Masks of logically later stage flags for a given stage flag
const std::map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyLaterStages();
const vvl::unordered_map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyLaterStages();
// clang-format on

// NOLINTEND
28 changes: 14 additions & 14 deletions scripts/generators/sync_validation_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,23 @@ def generateHeader(self):
out.append('\n);\n')

out.append('''
// Bit order mask of stage_access bit for each stage
// Bit order mask of stage_access bit for each stage. Order matters, don't try to use vvl::unordered_map
const std::map<VkPipelineStageFlags2, SyncStageAccessFlags>& syncStageAccessMaskByStageBit();
// Bit order mask of stage_access bit for each access
// Bit order mask of stage_access bit for each access. Order matters, don't try to use vvl::unordered_map
const std::map<VkAccessFlags2, SyncStageAccessFlags>& syncStageAccessMaskByAccessBit();
// Direct VkPipelineStageFlags to valid VkAccessFlags lookup table
const std::map<VkPipelineStageFlags2, VkAccessFlags2>& syncDirectStageToAccessMask();
const vvl::unordered_map<VkPipelineStageFlags2, VkAccessFlags2>& syncDirectStageToAccessMask();
// Pipeline stages corresponding to VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT for each VkQueueFlagBits
const std::map<VkQueueFlagBits, VkPipelineStageFlags2>& syncAllCommandStagesByQueueFlags();
const vvl::unordered_map<VkQueueFlagBits, VkPipelineStageFlags2>& syncAllCommandStagesByQueueFlags();
// Masks of logically earlier stage flags for a given stage flag
const std::map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyEarlierStages();
const vvl::unordered_map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyEarlierStages();
// Masks of logically later stage flags for a given stage flag
const std::map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyLaterStages();
const vvl::unordered_map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyLaterStages();
''')

out.append('// clang-format on\n')
Expand Down Expand Up @@ -300,8 +300,8 @@ def generateSource(self):
out.append('}\n\n')

# syncDirectStageToAccessMask
out.append('const std::map<VkPipelineStageFlags2, VkAccessFlags2>& syncDirectStageToAccessMask() {\n')
out.append(' static const std::map<VkPipelineStageFlags2, VkAccessFlags2> variable = {\n')
out.append('const vvl::unordered_map<VkPipelineStageFlags2, VkAccessFlags2>& syncDirectStageToAccessMask() {\n')
out.append(' static const vvl::unordered_map<VkPipelineStageFlags2, VkAccessFlags2> variable = {\n')
stage_to_access = {}
for stageAccess_info in self.stageAccessCombo:
stage = stageAccess_info['stage']
Expand All @@ -316,8 +316,8 @@ def generateSource(self):
out.append('}\n\n')

# syncAllCommandStagesByQueueFlags
out.append('const std::map<VkQueueFlagBits, VkPipelineStageFlags2>& syncAllCommandStagesByQueueFlags() {\n')
out.append(' static const std::map<VkQueueFlagBits, VkPipelineStageFlags2> variable = {\n')
out.append('const vvl::unordered_map<VkQueueFlagBits, VkPipelineStageFlags2>& syncAllCommandStagesByQueueFlags() {\n')
out.append(' static const vvl::unordered_map<VkQueueFlagBits, VkPipelineStageFlags2> variable = {\n')
ignoreQueueFlag = [
'VK_PIPELINE_STAGE_2_NONE',
'VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT',
Expand All @@ -333,8 +333,8 @@ def generateSource(self):
out.append('}\n\n')

# syncLogicallyEarlierStages
out.append('const std::map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyEarlierStages() {\n')
out.append(' static const std::map<VkPipelineStageFlags2, VkPipelineStageFlags2> variable = {\n')
out.append('const vvl::unordered_map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyEarlierStages() {\n')
out.append(' static const vvl::unordered_map<VkPipelineStageFlags2, VkPipelineStageFlags2> variable = {\n')
earlier_stages = {}
earlier_stages['VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT'] = set(['VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT'])
earlier_stages['VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT'] = set(['VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT', 'VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT'])
Expand All @@ -361,8 +361,8 @@ def generateSource(self):
out.append('}\n\n')

# syncLogicallyLaterStages
out.append('const std::map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyLaterStages() {\n')
out.append(' static const std::map<VkPipelineStageFlags2, VkPipelineStageFlags2> variable = {\n')
out.append('const vvl::unordered_map<VkPipelineStageFlags2, VkPipelineStageFlags2>& syncLogicallyLaterStages() {\n')
out.append(' static const vvl::unordered_map<VkPipelineStageFlags2, VkPipelineStageFlags2> variable = {\n')
later_stages = {}
later_stages['VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT'] = set(['VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT'])
later_stages['VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT'] = set(['VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT', 'VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT'])
Expand Down

0 comments on commit 9cf4cbd

Please sign in to comment.