Commit df0a92e6 by Shahbaz Youssefi Committed by Commit Bot

Assert valid when using SPIR-V ids

Useful for debugging when an uninitialized id is used in the SPIR-V transformer. Bug: angleproject:4888 Change-Id: If446187a8a27a06f5958d5df5bc00d02e98d20e3 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2713268 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 1330aa2c
...@@ -50,6 +50,14 @@ struct LiteralIntegerHelper ...@@ -50,6 +50,14 @@ struct LiteralIntegerHelper
}; };
using IdRef = BoxedUint32<IdRefHelper>; using IdRef = BoxedUint32<IdRefHelper>;
template <>
inline BoxedUint32<IdRefHelper>::operator uint32_t() const
{
ASSERT(valid());
return mValue.value;
}
// IdResult, IdResultType, IdMemorySemantics and IdScope are all translated as IdRef. This makes // IdResult, IdResultType, IdMemorySemantics and IdScope are all translated as IdRef. This makes
// the type verification weaker, but stops the API from becoming tediously verbose. // the type verification weaker, but stops the API from becoming tediously verbose.
using IdResult = IdRef; using IdResult = IdRef;
...@@ -96,6 +104,9 @@ using PairLiteralIntegerIdRefList = FastVectorHelper<PairLiteralIntegerIdRef>; ...@@ -96,6 +104,9 @@ using PairLiteralIntegerIdRefList = FastVectorHelper<PairLiteralIntegerIdRef>;
using PairIdRefLiteralIntegerList = FastVectorHelper<PairIdRefLiteralInteger>; using PairIdRefLiteralIntegerList = FastVectorHelper<PairIdRefLiteralInteger>;
using PairIdRefIdRefList = FastVectorHelper<PairIdRefIdRef>; using PairIdRefIdRefList = FastVectorHelper<PairIdRefIdRef>;
// Id 0 is invalid in SPIR-V.
constexpr uint32_t kMinValidId = 1;
} // namespace spirv } // namespace spirv
} // namespace angle } // namespace angle
......
...@@ -1954,7 +1954,7 @@ void SpirvVaryingPrecisionFixer::writeInputPreamble( ...@@ -1954,7 +1954,7 @@ void SpirvVaryingPrecisionFixer::writeInputPreamble(
} }
// Copy from corrected varyings to temp global variables with original precision. // Copy from corrected varyings to temp global variables with original precision.
for (uint32_t idIndex = 0; idIndex < variableInfoById.size(); idIndex++) for (uint32_t idIndex = spirv::kMinValidId; idIndex < variableInfoById.size(); idIndex++)
{ {
const spirv::IdRef id(idIndex); const spirv::IdRef id(idIndex);
const ShaderInterfaceVariableInfo *info = variableInfoById[id]; const ShaderInterfaceVariableInfo *info = variableInfoById[id];
...@@ -2004,7 +2004,7 @@ void SpirvVaryingPrecisionFixer::writeOutputPrologue( ...@@ -2004,7 +2004,7 @@ void SpirvVaryingPrecisionFixer::writeOutputPrologue(
} }
// Copy from temp global variables with original precision to corrected varyings. // Copy from temp global variables with original precision to corrected varyings.
for (uint32_t idIndex = 0; idIndex < variableInfoById.size(); idIndex++) for (uint32_t idIndex = spirv::kMinValidId; idIndex < variableInfoById.size(); idIndex++)
{ {
const spirv::IdRef id(idIndex); const spirv::IdRef id(idIndex);
const ShaderInterfaceVariableInfo *info = variableInfoById[id]; const ShaderInterfaceVariableInfo *info = variableInfoById[id];
...@@ -3381,7 +3381,7 @@ void SpirvVertexAttributeAliasingTransformer::preprocessAliasingAttributes() ...@@ -3381,7 +3381,7 @@ void SpirvVertexAttributeAliasingTransformer::preprocessAliasingAttributes()
mExpandedMatrixFirstVectorIdById.resize(indexBound); mExpandedMatrixFirstVectorIdById.resize(indexBound);
// Go through attributes and find out which alias which. // Go through attributes and find out which alias which.
for (size_t idIndex = 0; idIndex < indexBound; ++idIndex) for (size_t idIndex = spirv::kMinValidId; idIndex < indexBound; ++idIndex)
{ {
const spirv::IdRef id(idIndex); const spirv::IdRef id(idIndex);
...@@ -4042,16 +4042,18 @@ TransformationState SpirvVertexAttributeAliasingTransformer::transformLoad( ...@@ -4042,16 +4042,18 @@ TransformationState SpirvVertexAttributeAliasingTransformer::transformLoad(
void SpirvVertexAttributeAliasingTransformer::declareExpandedMatrixVectors() void SpirvVertexAttributeAliasingTransformer::declareExpandedMatrixVectors()
{ {
// Go through matrix attributes and expand them. // Go through matrix attributes and expand them.
for (uint32_t matrixIdIndex = 0; matrixIdIndex < mExpandedMatrixFirstVectorIdById.size(); for (uint32_t matrixIdIndex = spirv::kMinValidId;
++matrixIdIndex) matrixIdIndex < mExpandedMatrixFirstVectorIdById.size(); ++matrixIdIndex)
{ {
const spirv::IdRef matrixId(matrixIdIndex); const spirv::IdRef matrixId(matrixIdIndex);
const spirv::IdRef vec0Id(mExpandedMatrixFirstVectorIdById[matrixId]);
if (!vec0Id.valid()) if (!mExpandedMatrixFirstVectorIdById[matrixId].valid())
{ {
continue; continue;
} }
const spirv::IdRef vec0Id(mExpandedMatrixFirstVectorIdById[matrixId]);
const ShaderInterfaceVariableInfo *info = mVariableInfoById[matrixId]; const ShaderInterfaceVariableInfo *info = mVariableInfoById[matrixId];
ValidateShaderInterfaceVariableIsAttribute(info); ValidateShaderInterfaceVariableIsAttribute(info);
...@@ -4111,7 +4113,7 @@ void SpirvVertexAttributeAliasingTransformer::declareExpandedMatrixVectors() ...@@ -4111,7 +4113,7 @@ void SpirvVertexAttributeAliasingTransformer::declareExpandedMatrixVectors()
// Op*AccessChain instructions, if any). // Op*AccessChain instructions, if any).
for (size_t n = 1; n < mFloatTypes.size(); ++n) for (size_t n = 1; n < mFloatTypes.size(); ++n)
{ {
if (mFloatTypes[n].valid() && mPrivateFloatTypePointers[n] == 0) if (mFloatTypes[n].valid() && !mPrivateFloatTypePointers[n].valid())
{ {
const spirv::IdRef privateType(getNewId()); const spirv::IdRef privateType(getNewId());
mPrivateFloatTypePointers[n] = privateType; mPrivateFloatTypePointers[n] = privateType;
...@@ -4125,16 +4127,18 @@ void SpirvVertexAttributeAliasingTransformer::writeExpandedMatrixInitialization( ...@@ -4125,16 +4127,18 @@ void SpirvVertexAttributeAliasingTransformer::writeExpandedMatrixInitialization(
{ {
// Go through matrix attributes and initialize them. Note that their declaration is replaced // Go through matrix attributes and initialize them. Note that their declaration is replaced
// with a Private storage class, but otherwise has the same id. // with a Private storage class, but otherwise has the same id.
for (uint32_t matrixIdIndex = 0; matrixIdIndex < mExpandedMatrixFirstVectorIdById.size(); for (uint32_t matrixIdIndex = spirv::kMinValidId;
++matrixIdIndex) matrixIdIndex < mExpandedMatrixFirstVectorIdById.size(); ++matrixIdIndex)
{ {
const spirv::IdRef matrixId(matrixIdIndex); const spirv::IdRef matrixId(matrixIdIndex);
const spirv::IdRef vec0Id(mExpandedMatrixFirstVectorIdById[matrixId]);
if (!vec0Id.valid()) if (!mExpandedMatrixFirstVectorIdById[matrixId].valid())
{ {
continue; continue;
} }
const spirv::IdRef vec0Id(mExpandedMatrixFirstVectorIdById[matrixId]);
// For every matrix, need to generate the following: // For every matrix, need to generate the following:
// //
// %vec0Id = OpLoad %vecType %vec0Pointer // %vec0Id = OpLoad %vecType %vec0Pointer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment