@@ -2075,12 +2075,10 @@ class SpirvVertexAttributeAliasingTransformer final : public SpirvTransformerBas
20752075 const std::vector<uint32_t > &spirvBlobIn,
20762076 const ShaderInterfaceVariableInfoMap &variableInfoMap,
20772077 std::vector<const ShaderInterfaceVariableInfo *> &&variableInfoById,
2078- gl::AttribArray<AliasingAttributeMap> &&aliasingAttributeMap,
20792078 SpirvBlob *spirvBlobOut)
20802079 : SpirvTransformerBase(spirvBlobIn, variableInfoMap, gl::ShaderType::Vertex, spirvBlobOut)
20812080 {
2082- mVariableInfoById = std::move (variableInfoById);
2083- mAliasingAttributeMap = std::move (aliasingAttributeMap);
2081+ mVariableInfoById = std::move (variableInfoById);
20842082 }
20852083
20862084 bool transform ();
@@ -2154,13 +2152,59 @@ void SpirvVertexAttributeAliasingTransformer::preprocessAliasingAttributes()
21542152 const size_t indexBound = mSpirvBlobIn [kHeaderIndexIndexBound ];
21552153 mIsAliasingAttributeById .resize (indexBound + 1 , false );
21562154
2157- for (const AliasingAttributeMap &aliasingMap : mAliasingAttributeMap )
2155+ // Go through attributes and find out which alias which.
2156+ for (size_t id = 0 ; id < mVariableInfoById .size (); ++id)
21582157 {
2159- for (uint32_t aliasingId : aliasingMap.aliasingAttributes )
2158+ const ShaderInterfaceVariableInfo *info = mVariableInfoById [id];
2159+
2160+ // Ignore non attribute or inactive ids.
2161+ if (info == nullptr || info->attributeComponentCount == 0 ||
2162+ !info->activeStages [gl::ShaderType::Vertex])
2163+ {
2164+ continue ;
2165+ }
2166+
2167+ // Ignore matrix attributes for now.
2168+ // TODO: aliasing matrix attributes. http://anglebug.com/4249
2169+ if (info->isMatrixAttribute )
2170+ {
2171+ continue ;
2172+ }
2173+
2174+ ASSERT (info->location != ShaderInterfaceVariableInfo::kInvalid );
2175+ ASSERT (info->location < mAliasingAttributeMap .size ());
2176+
2177+ AliasingAttributeMap *aliasingMap = &mAliasingAttributeMap [info->location ];
2178+
2179+ // If this is the first attribute in this location, remember it.
2180+ if (aliasingMap->attribute == 0 )
2181+ {
2182+ aliasingMap->attribute = id;
2183+ continue ;
2184+ }
2185+
2186+ // Otherwise, either add it to the list of aliasing attributes, or replace the main
2187+ // attribute (and add that to the list of aliasing attributes). The one with the largest
2188+ // number of component is used as the main attribute.
2189+ const ShaderInterfaceVariableInfo *curMainAttribute =
2190+ mVariableInfoById [aliasingMap->attribute ];
2191+ ASSERT (curMainAttribute != nullptr && curMainAttribute->attributeComponentCount > 0 &&
2192+ !curMainAttribute->isMatrixAttribute );
2193+
2194+ uint32_t aliasingId;
2195+ if (info->attributeComponentCount > curMainAttribute->attributeComponentCount )
21602196 {
2161- ASSERT ( mIsAliasingAttributeById [ aliasingId] == false ) ;
2162- mIsAliasingAttributeById [aliasingId] = true ;
2197+ aliasingId = aliasingMap-> attribute ;
2198+ aliasingMap-> attribute = id ;
21632199 }
2200+ else
2201+ {
2202+ aliasingId = id;
2203+ }
2204+
2205+ aliasingMap->aliasingAttributes .push_back (aliasingId);
2206+ ASSERT (mIsAliasingAttributeById [aliasingId] == false );
2207+ mIsAliasingAttributeById [aliasingId] = true ;
21642208 }
21652209}
21662210
@@ -2588,64 +2632,39 @@ void SpirvVertexAttributeAliasingTransformer::writeVectorShuffle(
25882632 copyInstruction (vectorShuffle.data (), kVectorShuffleInstructionBaseLength + fields.size ());
25892633}
25902634
2591- bool CalculateAliasingAttributes (
2592- const std::vector<const ShaderInterfaceVariableInfo *> &variableInfoById,
2593- gl::AttribArray<AliasingAttributeMap> *aliasingAttributeMapOut)
2635+ bool HasAliasingAttributes (const ShaderInterfaceVariableInfoMap &variableInfoMap)
25942636{
2595- bool anyAliasing = false ;
2637+ gl::AttributesMask isLocationAssigned ;
25962638
2597- for (size_t id = 0 ; id < variableInfoById. size (); ++id )
2639+ for (const auto &infoIter : variableInfoMap )
25982640 {
2599- const ShaderInterfaceVariableInfo * info = variableInfoById[id] ;
2641+ const ShaderInterfaceVariableInfo & info = infoIter. second ;
26002642
26012643 // Ignore non attribute or inactive ids.
2602- if (info == nullptr || info->attributeComponentCount == 0 ||
2603- !info->activeStages [gl::ShaderType::Vertex])
2644+ if (info.attributeComponentCount == 0 || !info.activeStages [gl::ShaderType::Vertex])
26042645 {
26052646 continue ;
26062647 }
26072648
26082649 // Ignore matrix attributes for now.
26092650 // TODO: aliasing matrix attributes. http://anglebug.com/4249
2610- if (info-> isMatrixAttribute )
2651+ if (info. isMatrixAttribute )
26112652 {
26122653 continue ;
26132654 }
26142655
2615- ASSERT (info->location != ShaderInterfaceVariableInfo::kInvalid );
2616- ASSERT (info->location < aliasingAttributeMapOut->size ());
2656+ ASSERT (info.location != ShaderInterfaceVariableInfo::kInvalid );
26172657
2618- AliasingAttributeMap *aliasingMap = &(*aliasingAttributeMapOut)[info->location ];
2619-
2620- // If this is the first attribute in this location, remember it.
2621- if (aliasingMap->attribute == 0 )
2658+ // If there's aliasing, return immediately.
2659+ if (isLocationAssigned.test (info.location ))
26222660 {
2623- aliasingMap->attribute = id;
2624- continue ;
2661+ return true ;
26252662 }
26262663
2627- anyAliasing = true ;
2628-
2629- // Otherwise, either add it to the list of aliasing attributes, or replace the main
2630- // attribute (and add that to the list of aliasing attributes). The one with the largest
2631- // number of component is used as the main attribute.
2632- const ShaderInterfaceVariableInfo *curMainAttribute =
2633- variableInfoById[aliasingMap->attribute ];
2634- ASSERT (curMainAttribute != nullptr && curMainAttribute->attributeComponentCount > 0 &&
2635- !curMainAttribute->isMatrixAttribute );
2636-
2637- if (info->attributeComponentCount > curMainAttribute->attributeComponentCount )
2638- {
2639- aliasingMap->aliasingAttributes .push_back (aliasingMap->attribute );
2640- aliasingMap->attribute = id;
2641- }
2642- else
2643- {
2644- aliasingMap->aliasingAttributes .push_back (id);
2645- }
2664+ isLocationAssigned.set (info.location );
26462665 }
26472666
2648- return anyAliasing ;
2667+ return false ;
26492668}
26502669} // anonymous namespace
26512670
@@ -2867,22 +2886,14 @@ angle::Result GlslangTransformSpirvCode(const GlslangErrorCallback &callback,
28672886 removeDebugInfo, variableInfoMap, shaderType, spirvBlobOut);
28682887 ANGLE_GLSLANG_CHECK (callback, transformer.transform (), GlslangError::InvalidSpirv);
28692888
2870- if (shaderType == gl::ShaderType::Vertex)
2889+ // If there are aliasing vertex attributes, transform the SPIR-V again to remove them.
2890+ if (shaderType == gl::ShaderType::Vertex && HasAliasingAttributes (variableInfoMap))
28712891 {
2872- gl::AttribArray<AliasingAttributeMap> aliasingAttributeMap;
2873- std::vector<const ShaderInterfaceVariableInfo *> &variableInfoById =
2874- transformer.getVariableInfoByIdMap ();
2875-
2876- // If there are aliasing vertex attributes, transform the SPIR-V again to remove them.
2877- if (CalculateAliasingAttributes (variableInfoById, &aliasingAttributeMap))
2878- {
2879- SpirvBlob preTransformBlob = std::move (*spirvBlobOut);
2880- SpirvVertexAttributeAliasingTransformer aliasingTransformer (
2881- preTransformBlob, variableInfoMap, std::move (variableInfoById),
2882- std::move (aliasingAttributeMap), spirvBlobOut);
2883- ANGLE_GLSLANG_CHECK (callback, aliasingTransformer.transform (),
2884- GlslangError::InvalidSpirv);
2885- }
2892+ SpirvBlob preTransformBlob = std::move (*spirvBlobOut);
2893+ SpirvVertexAttributeAliasingTransformer aliasingTransformer (
2894+ preTransformBlob, variableInfoMap, std::move (transformer.getVariableInfoByIdMap ()),
2895+ spirvBlobOut);
2896+ ANGLE_GLSLANG_CHECK (callback, aliasingTransformer.transform (), GlslangError::InvalidSpirv);
28862897 }
28872898
28882899 ASSERT (ValidateSpirv (*spirvBlobOut));
0 commit comments