Hash :
acdf8722
Author :
Date :
2023-06-07T11:26:37
Vulkan: Remove reliance on names for gl_PerVertex-trimmer Instead of passing in gl_Position etc built-in names and then find their index by looking at OpMemberName instructions, this change has the front-end create a bitset of active gl_PerVertex members. The SPIR-V transformer then directly uses this information to trim gl_PerVertex. Bug: angleproject:7220 Change-Id: I5c3d56784801abb310d09d98d9c82c9e6e019de8 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4600608 Reviewed-by: Yuxin Hu <yuxinhu@google.com> Reviewed-by: Roman Lavrov <romanl@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 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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
//
// 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 names to their Vulkan mapping.
#ifndef LIBANGLE_RENDERER_VULKAN_SHADERINTERFACEVARIABLEINFOMAP_H_
#define LIBANGLE_RENDERER_VULKAN_SHADERINTERFACEVARIABLEINFOMAP_H_
#include "common/FastVector.h"
#include "libANGLE/renderer/ProgramImpl.h"
#include "libANGLE/renderer/renderer_utils.h"
#include "libANGLE/renderer/vulkan/spv_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(gl::ShaderMap<VariableTypeToInfoMap> &&data,
gl::ShaderMap<NameToTypeAndIndexMap> &&nameToTypeAndIndexMap,
gl::ShaderMap<VariableTypeToIndexMap> &&indexedResourceIndexMap,
gl::ShaderMap<gl::PerVertexMemberBitSet> &&inputPerVertexActiveMembers,
gl::ShaderMap<gl::PerVertexMemberBitSet> &&outputPerVertexActiveMembers);
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);
void setInputPerVertexActiveMembers(gl::ShaderType shaderType,
gl::PerVertexMemberBitSet activeMembers);
void setOutputPerVertexActiveMembers(gl::ShaderType shaderType,
gl::PerVertexMemberBitSet activeMembers);
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 { return mData; }
const gl::ShaderMap<NameToTypeAndIndexMap> &getNameToTypeAndIndexMap() const
{
return mNameToTypeAndIndexMap;
}
const gl::ShaderMap<VariableTypeToIndexMap> &getIndexedResourceMap() const
{
return mIndexedResourceIndexMap;
}
const gl::ShaderMap<gl::PerVertexMemberBitSet> &getInputPerVertexActiveMembers() const
{
return mInputPerVertexActiveMembers;
}
const gl::ShaderMap<gl::PerVertexMemberBitSet> &getOutputPerVertexActiveMembers() const
{
return mOutputPerVertexActiveMembers;
}
private:
gl::ShaderMap<VariableTypeToInfoMap> mData;
gl::ShaderMap<NameToTypeAndIndexMap> mNameToTypeAndIndexMap;
gl::ShaderMap<VariableTypeToIndexMap> mIndexedResourceIndexMap;
// Active members of `in gl_PerVertex` and `out gl_PerVertex`
gl::ShaderMap<gl::PerVertexMemberBitSet> mInputPerVertexActiveMembers;
gl::ShaderMap<gl::PerVertexMemberBitSet> mOutputPerVertexActiveMembers;
};
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_VULKAN_SHADERINTERFACEVARIABLEINFOMAP_H_