Hash :
21ad9b3c
Author :
Date :
2022-04-07T09:57:26
Vulkan: Add generic descriptors for DS cache. With the new design, the descriptor set cache keys include all identifying information needed to reconstruct the update descriptor sets calls except the specific resource handles. The places for the resource handles are held by serials intead. When we miss the cache, we no longer need a second step to then construct the update calls, and can build the update calls directly from the key structures in combination with a list of resource handles. Bug: angleproject:6776 Change-Id: If1660a557585a75e9aa2560d6a38c56b62f555c8 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3484981 Reviewed-by: Yuxin Hu <yuxinhu@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> 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 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
//
// 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;
uint32_t getDefaultUniformBinding(gl::ShaderType shaderType) const;
uint32_t getXfbBufferBinding(uint32_t xfbBufferIndex) const;
uint32_t getAtomicCounterBufferBinding(gl::ShaderType shaderType,
uint32_t atomicCounterBufferIndex) 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];
}
ANGLE_INLINE uint32_t
ShaderInterfaceVariableInfoMap::getDefaultUniformBinding(gl::ShaderType shaderType) const
{
return getDefaultUniformInfo(shaderType).binding;
}
ANGLE_INLINE uint32_t
ShaderInterfaceVariableInfoMap::getXfbBufferBinding(uint32_t xfbBufferIndex) const
{
// Note: we only use this method for transform feedback emulation. And emulation only supports
// XFB in the vertex shader.
return getTransformFeedbackInfo(gl::ShaderType::Vertex, xfbBufferIndex).binding;
}
ANGLE_INLINE uint32_t ShaderInterfaceVariableInfoMap::getAtomicCounterBufferBinding(
gl::ShaderType shaderType,
uint32_t atomicCounterBufferIndex) const
{
ASSERT(hasAtomicCounterInfo(shaderType));
return getAtomicCounterInfo(shaderType).binding + atomicCounterBufferIndex;
}
} // namespace rx
#endif // LIBANGLE_RENDERER_SHADERINTERFACEVARIABLEINFOMAP_H_