Hash :
ec1f18db
Author :
Date :
2023-06-21T10:16:51
Vulkan: Remove ShaderVariableType and flatten info map With the conversion of the interface variable info map keys to SPIR-V ids, there is no longer a benefit to bucket resources by their type. This change removes this bucketing and flattens the map. Bug: angleproject:7220 Change-Id: If83cb02ca9e91f72dddb2deb7313fee40f9f06c3 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4632577 Reviewed-by: Yuxin Hu <yuxinhu@google.com> Reviewed-by: Charlie Lao <cclao@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
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
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ShaderInterfaceVariableInfoMap: Maps shader interface variable SPIR-V ids to their Vulkan
// mapping.
//
#include "libANGLE/renderer/vulkan/ShaderInterfaceVariableInfoMap.h"
namespace rx
{
namespace
{
uint32_t HashSPIRVId(uint32_t id)
{
ASSERT(id >= sh::vk::spirv::kIdShaderVariablesBegin);
return id - sh::vk::spirv::kIdShaderVariablesBegin;
}
} // anonymous namespace
ShaderInterfaceVariableInfo::ShaderInterfaceVariableInfo() {}
// ShaderInterfaceVariableInfoMap implementation.
ShaderInterfaceVariableInfoMap::ShaderInterfaceVariableInfoMap() = default;
ShaderInterfaceVariableInfoMap::~ShaderInterfaceVariableInfoMap() = default;
void ShaderInterfaceVariableInfoMap::clear()
{
mData.clear();
for (gl::ShaderType shaderType : gl::AllShaderTypes())
{
mIdToIndexMap[shaderType].clear();
}
std::fill(mInputPerVertexActiveMembers.begin(), mInputPerVertexActiveMembers.end(),
gl::PerVertexMemberBitSet{});
std::fill(mOutputPerVertexActiveMembers.begin(), mOutputPerVertexActiveMembers.end(),
gl::PerVertexMemberBitSet{});
}
void ShaderInterfaceVariableInfoMap::load(
VariableInfoArray &&data,
gl::ShaderMap<IdToIndexMap> &&idToIndexMap,
gl::ShaderMap<gl::PerVertexMemberBitSet> &&inputPerVertexActiveMembers,
gl::ShaderMap<gl::PerVertexMemberBitSet> &&outputPerVertexActiveMembers)
{
mData.swap(data);
mIdToIndexMap.swap(idToIndexMap);
mInputPerVertexActiveMembers.swap(inputPerVertexActiveMembers);
mOutputPerVertexActiveMembers.swap(outputPerVertexActiveMembers);
}
void ShaderInterfaceVariableInfoMap::setInputPerVertexActiveMembers(
gl::ShaderType shaderType,
gl::PerVertexMemberBitSet activeMembers)
{
// Input gl_PerVertex is only meaningful for tessellation and geometry stages
ASSERT(shaderType == gl::ShaderType::TessControl ||
shaderType == gl::ShaderType::TessEvaluation || shaderType == gl::ShaderType::Geometry ||
activeMembers.none());
mInputPerVertexActiveMembers[shaderType] = activeMembers;
}
void ShaderInterfaceVariableInfoMap::setOutputPerVertexActiveMembers(
gl::ShaderType shaderType,
gl::PerVertexMemberBitSet activeMembers)
{
// Output gl_PerVertex is only meaningful for vertex, tessellation and geometry stages
ASSERT(shaderType == gl::ShaderType::Vertex || shaderType == gl::ShaderType::TessControl ||
shaderType == gl::ShaderType::TessEvaluation || shaderType == gl::ShaderType::Geometry ||
activeMembers.none());
mOutputPerVertexActiveMembers[shaderType] = activeMembers;
}
void ShaderInterfaceVariableInfoMap::setVariableIndex(gl::ShaderType shaderType,
uint32_t id,
VariableIndex index)
{
mIdToIndexMap[shaderType][HashSPIRVId(id)] = index;
}
const VariableIndex &ShaderInterfaceVariableInfoMap::getVariableIndex(gl::ShaderType shaderType,
uint32_t id) const
{
return mIdToIndexMap[shaderType].at(HashSPIRVId(id));
}
ShaderInterfaceVariableInfo &ShaderInterfaceVariableInfoMap::getMutable(gl::ShaderType shaderType,
uint32_t id)
{
ASSERT(hasVariable(shaderType, id));
uint32_t index = getVariableIndex(shaderType, id).index;
return mData[index];
}
ShaderInterfaceVariableInfo &ShaderInterfaceVariableInfoMap::add(gl::ShaderType shaderType,
uint32_t id)
{
ASSERT(!hasVariable(shaderType, id));
uint32_t index = static_cast<uint32_t>(mData.size());
setVariableIndex(shaderType, id, {index});
mData.resize(index + 1);
return mData[index];
}
void ShaderInterfaceVariableInfoMap::addResource(gl::ShaderBitSet shaderTypes,
const gl::ShaderMap<uint32_t> &idInShaderTypes,
uint32_t descriptorSet,
uint32_t binding)
{
uint32_t index = static_cast<uint32_t>(mData.size());
mData.resize(index + 1);
ShaderInterfaceVariableInfo *info = &mData[index];
info->descriptorSet = descriptorSet;
info->binding = binding;
info->activeStages = shaderTypes;
for (const gl::ShaderType shaderType : shaderTypes)
{
const uint32_t id = idInShaderTypes[shaderType];
ASSERT(!hasVariable(shaderType, id));
setVariableIndex(shaderType, id, {index});
}
}
ShaderInterfaceVariableInfo &ShaderInterfaceVariableInfoMap::addOrGet(gl::ShaderType shaderType,
uint32_t id)
{
if (!hasVariable(shaderType, id))
{
return add(shaderType, id);
}
else
{
uint32_t index = getVariableIndex(shaderType, id).index;
return mData[index];
}
}
bool ShaderInterfaceVariableInfoMap::hasVariable(gl::ShaderType shaderType, uint32_t id) const
{
const uint32_t hashedId = HashSPIRVId(id);
return hashedId < mIdToIndexMap[shaderType].size() &&
mIdToIndexMap[shaderType].at(hashedId).index != VariableIndex::kInvalid;
}
bool ShaderInterfaceVariableInfoMap::hasTransformFeedbackInfo(gl::ShaderType shaderType,
uint32_t bufferIndex) const
{
return hasVariable(shaderType, SpvGetXfbBufferBlockId(bufferIndex));
}
} // namespace rx