Array length fix

When available, the decorations for the array member of the structure
used in EmitArrayLength should be used to find the array stride and
use it in the length computation.

This cl should fix these tests with SwANGLE:
dEQP-GLES31.functional.compute.basic.write_multiple_unsized_arr_*

Bug: b/148459131
Change-Id: I5722ebc761b81faf75bb9bab7c60f240afa50446
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/41271
Presubmit-Ready: Alexis Hétu <sugoi@google.com>
Reviewed-by: Chris Forbes <chrisforbes@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index 0fe5b09..5026373 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -2327,20 +2327,22 @@
 
 	auto &structPtrTy = getType(getObject(structPtrId).type);
 	auto &structTy = getType(structPtrTy.element);
-	auto &arrayTy = getType(structTy.definition.word(2 + arrayFieldIdx));
-	ASSERT(arrayTy.definition.opcode() == spv::OpTypeRuntimeArray);
-	auto &arrayElTy = getType(arrayTy.element);
+	auto arrayId = Type::ID(structTy.definition.word(2 + arrayFieldIdx));
 
 	auto &result = state->createIntermediate(resultId, 1);
 	auto structBase = GetPointerToData(structPtrId, 0, state);
 
-	Decorations d = {};
-	ApplyDecorationsForIdMember(&d, structPtrTy.element, arrayFieldIdx);
-	ASSERT(d.HasOffset);
+	Decorations structDecorations = {};
+	ApplyDecorationsForIdMember(&structDecorations, structPtrTy.element, arrayFieldIdx);
+	ASSERT(structDecorations.HasOffset);
 
-	auto arrayBase = structBase + d.Offset;
+	auto arrayBase = structBase + structDecorations.Offset;
 	auto arraySizeInBytes = SIMD::Int(arrayBase.limit()) - arrayBase.offsets();
-	auto arrayLength = arraySizeInBytes / SIMD::Int(arrayElTy.sizeInComponents * sizeof(float));
+
+	Decorations arrayDecorations = {};
+	ApplyDecorationsForId(&arrayDecorations, arrayId);
+	ASSERT(arrayDecorations.HasArrayStride);
+	auto arrayLength = arraySizeInBytes / SIMD::Int(arrayDecorations.ArrayStride);
 
 	result.move(0, SIMD::Int(arrayLength));