Hash :
55c21842
Author :
Date :
2022-04-14T05:04:15
Vulkan: Use flat array lookups for shader variables. The array lookups we use after link now are simple array lookups and no longer use string hashing queries. This will make the descriptor cache indexing much faster after the cache key redesign. Bug: angleproject:4524 Change-Id: If19e3a4aa57c415f33c69172dd76c10a207e3264 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3580979 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Yuxin Hu <yuxinhu@google.com> Commit-Queue: Jamie Madill <jmadill@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 156 157 158 159 160 161 162 163 164 165
//
// 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.
//
// Header for the shared ShaderInterfaceVariableInfoMap class, used by both the
// Direct-to-Metal and Metal-SPIRV backends
#ifndef LIBANGLE_RENDERER_SHADERINTERFACEVARIABLEINFOMAP_H_
#define LIBANGLE_RENDERER_SHADERINTERFACEVARIABLEINFOMAP_H_
#include "common/FastVector.h"
#include "libANGLE/renderer/ProgramImpl.h"
#include "libANGLE/renderer/glslang_wrapper_utils.h"
#include "libANGLE/renderer/renderer_utils.h"
#include <functional>
#include <stdio.h>
namespace rx
{
enum class ShaderVariableType
{
AtomicCounter,
Attribute,
DefaultUniform,
DriverUniform,
FramebufferFetch,
Image,
Output,
SecondaryOutput,
ShaderStorageBuffer,
Texture,
TransformFeedback,
UniformBuffer,
Varying,
EnumCount,
};
struct TypeAndIndex
{
ShaderVariableType variableType;
uint32_t index;
};
class ShaderInterfaceVariableInfoMap final : angle::NonCopyable
{
public:
using VariableInfoArray = std::vector<ShaderInterfaceVariableInfo>;
using VariableTypeToInfoMap = angle::PackedEnumMap<ShaderVariableType, VariableInfoArray>;
using NameToTypeAndIndexMap = angle::HashMap<std::string, TypeAndIndex>;
static constexpr size_t kResourceFastMapMax = 32;
using ResourceIndexMap = angle::FastMap<uint32_t, kResourceFastMapMax>;
using VariableTypeToIndexMap = angle::PackedEnumMap<ShaderVariableType, ResourceIndexMap>;
ShaderInterfaceVariableInfoMap();
~ShaderInterfaceVariableInfoMap();
void clear();
void load(const gl::ShaderMap<VariableTypeToInfoMap> &data,
const gl::ShaderMap<NameToTypeAndIndexMap> &nameToTypeAndIndexMap,
const gl::ShaderMap<VariableTypeToIndexMap> &indexedResourceIndexMap);
ShaderInterfaceVariableInfo &add(gl::ShaderType shaderType,
ShaderVariableType variableType,
const std::string &variableName);
void markAsDuplicate(gl::ShaderType shaderType,
ShaderVariableType variableType,
const std::string &variableName);
ShaderInterfaceVariableInfo &addOrGet(gl::ShaderType shaderType,
ShaderVariableType variableType,
const std::string &variableName);
void setActiveStages(gl::ShaderType shaderType,
ShaderVariableType variableType,
const std::string &variableName,
gl::ShaderBitSet activeStages);
ShaderInterfaceVariableInfo &getMutable(gl::ShaderType shaderType,
ShaderVariableType variableType,
const std::string &variableName);
const ShaderInterfaceVariableInfo &getDefaultUniformInfo(gl::ShaderType shaderType) const;
const ShaderInterfaceVariableInfo &getIndexedVariableInfo(gl::ShaderType shaderType,
ShaderVariableType variableType,
uint32_t variableIndex) const;
bool hasAtomicCounterInfo(gl::ShaderType shaderType) const;
const ShaderInterfaceVariableInfo &getAtomicCounterInfo(gl::ShaderType shaderType) const;
const ShaderInterfaceVariableInfo &getFramebufferFetchInfo(gl::ShaderType shaderType) const;
bool hasTransformFeedbackInfo(gl::ShaderType shaderType, uint32_t bufferIndex) const;
const ShaderInterfaceVariableInfo &getTransformFeedbackInfo(gl::ShaderType shaderType,
uint32_t bufferIndex) const;
bool hasVariable(gl::ShaderType shaderType, const std::string &variableName) const;
const ShaderInterfaceVariableInfo &getVariableByName(gl::ShaderType shaderType,
const std::string &variableName) const;
void mapIndexedResourceByName(gl::ShaderType shaderType,
ShaderVariableType variableType,
uint32_t resourceIndex,
const std::string &variableName);
void mapIndexedResource(gl::ShaderType shaderType,
ShaderVariableType variableType,
uint32_t resourceIndex,
uint32_t variableIndex);
const VariableInfoArray &getAttributes() const;
const gl::ShaderMap<VariableTypeToInfoMap> &getData() const;
const gl::ShaderMap<NameToTypeAndIndexMap> &getNameToTypeAndIndexMap() const;
const gl::ShaderMap<VariableTypeToIndexMap> &getIndexedResourceMap() const;
private:
gl::ShaderMap<VariableTypeToInfoMap> mData;
gl::ShaderMap<NameToTypeAndIndexMap> mNameToTypeAndIndexMap;
gl::ShaderMap<VariableTypeToIndexMap> mIndexedResourceIndexMap;
};
ANGLE_INLINE const ShaderInterfaceVariableInfo &
ShaderInterfaceVariableInfoMap::getDefaultUniformInfo(gl::ShaderType shaderType) const
{
ASSERT(mData[shaderType][ShaderVariableType::DefaultUniform].size() == 1);
return mData[shaderType][ShaderVariableType::DefaultUniform][0];
}
ANGLE_INLINE const ShaderInterfaceVariableInfo &
ShaderInterfaceVariableInfoMap::getIndexedVariableInfo(gl::ShaderType shaderType,
ShaderVariableType variableType,
uint32_t resourceIndex) const
{
ASSERT(resourceIndex < mIndexedResourceIndexMap[shaderType][variableType].size());
uint32_t variableIndex = mIndexedResourceIndexMap[shaderType][variableType][resourceIndex];
ASSERT(variableIndex < mData[shaderType][variableType].size());
return mData[shaderType][variableType][variableIndex];
}
ANGLE_INLINE bool ShaderInterfaceVariableInfoMap::hasAtomicCounterInfo(
gl::ShaderType shaderType) const
{
return !mData[shaderType][ShaderVariableType::AtomicCounter].empty();
}
ANGLE_INLINE const ShaderInterfaceVariableInfo &
ShaderInterfaceVariableInfoMap::getAtomicCounterInfo(gl::ShaderType shaderType) const
{
ASSERT(mData[shaderType][ShaderVariableType::AtomicCounter].size() == 1);
return mData[shaderType][ShaderVariableType::AtomicCounter][0];
}
ANGLE_INLINE const ShaderInterfaceVariableInfo &
ShaderInterfaceVariableInfoMap::getFramebufferFetchInfo(gl::ShaderType shaderType) const
{
ASSERT(!mData[shaderType][ShaderVariableType::FramebufferFetch].empty());
return mData[shaderType][ShaderVariableType::FramebufferFetch][0];
}
ANGLE_INLINE const ShaderInterfaceVariableInfo &
ShaderInterfaceVariableInfoMap::getTransformFeedbackInfo(gl::ShaderType shaderType,
uint32_t bufferIndex) const
{
ASSERT(bufferIndex < mData[shaderType][ShaderVariableType::TransformFeedback].size());
return mData[shaderType][ShaderVariableType::TransformFeedback][bufferIndex];
}
} // namespace rx
#endif // LIBANGLE_RENDERER_SHADERINTERFACEVARIABLEINFOMAP_H_