Commit 98e6b968 by Chris Forbes

Adjust matrix addressing to account for RowMajor/ColMajor

Bug: b/128690261 Test: dEQP-VK.glsl.* Test: dEQP-VK.ubo.* Test: dEQP-VK.ssbo.* Change-Id: Ibafc5f64263cd627a3a2cd961af226cb5b110ea0 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28968Tested-by: 's avatarChris Forbes <chrisforbes@google.com> Presubmit-Ready: Chris Forbes <chrisforbes@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 1ba5ba74
...@@ -997,18 +997,25 @@ namespace sw ...@@ -997,18 +997,25 @@ namespace sw
f(index++, offset); f(index++, offset);
break; break;
case spv::OpTypeVector: case spv::OpTypeVector:
{
auto elemStride = (d.InsideMatrix && d.HasRowMajor && d.RowMajor) ? d.MatrixStride / sizeof(float) : 1;
for (auto i = 0u; i < type.definition.word(3); i++) for (auto i = 0u; i < type.definition.word(3); i++)
{ {
VisitMemoryObjectInner(type.definition.word(2), d, index, offset + i, f); VisitMemoryObjectInner(type.definition.word(2), d, index, offset + elemStride * i, f);
} }
break; break;
}
case spv::OpTypeMatrix: case spv::OpTypeMatrix:
{
auto columnStride = (d.HasRowMajor && d.RowMajor) ? 1 : d.MatrixStride / sizeof(float);
d.InsideMatrix = true;
for (auto i = 0u; i < type.definition.word(3); i++) for (auto i = 0u; i < type.definition.word(3); i++)
{ {
ASSERT(d.HasMatrixStride); ASSERT(d.HasMatrixStride);
VisitMemoryObjectInner(type.definition.word(2), d, index, offset + i * d.MatrixStride / sizeof(float), f); VisitMemoryObjectInner(type.definition.word(2), d, index, offset + columnStride * i, f);
} }
break; break;
}
case spv::OpTypeStruct: case spv::OpTypeStruct:
for (auto i = 0u; i < type.definition.wordCount() - 2; i++) for (auto i = 0u; i < type.definition.wordCount() - 2; i++)
{ {
...@@ -1118,10 +1125,13 @@ namespace sw ...@@ -1118,10 +1125,13 @@ namespace sw
} }
case spv::OpTypeArray: case spv::OpTypeArray:
case spv::OpTypeRuntimeArray: case spv::OpTypeRuntimeArray:
case spv::OpTypeMatrix:
case spv::OpTypeVector: case spv::OpTypeVector:
typeId = type.element; typeId = type.element;
break; break;
case spv::OpTypeMatrix:
typeId = type.element;
d->InsideMatrix = true;
break;
default: default:
UNIMPLEMENTED("Unexpected type '%s' in ApplyDecorationsForAccessChain", UNIMPLEMENTED("Unexpected type '%s' in ApplyDecorationsForAccessChain",
OpcodeName(type.definition.opcode()).c_str()); OpcodeName(type.definition.opcode()).c_str());
...@@ -1190,21 +1200,24 @@ namespace sw ...@@ -1190,21 +1200,24 @@ namespace sw
{ {
// TODO: b/127950082: Check bounds. // TODO: b/127950082: Check bounds.
ASSERT(d.HasMatrixStride); ASSERT(d.HasMatrixStride);
d.InsideMatrix = true;
auto columnStride = (d.HasRowMajor && d.RowMajor) ? 1 : d.MatrixStride/sizeof(float);
auto & obj = getObject(indexIds[i]); auto & obj = getObject(indexIds[i]);
if (obj.kind == Object::Kind::Constant) if (obj.kind == Object::Kind::Constant)
constantOffset += d.MatrixStride/sizeof(float) * GetConstantInt(indexIds[i]); constantOffset += columnStride * GetConstantInt(indexIds[i]);
else else
ptr.offset += SIMD::Int(d.MatrixStride / sizeof(float)) * routine->getIntermediate(indexIds[i]).Int(0); ptr.offset += SIMD::Int(columnStride) * routine->getIntermediate(indexIds[i]).Int(0);
typeId = type.element; typeId = type.element;
break; break;
} }
case spv::OpTypeVector: case spv::OpTypeVector:
{ {
auto elemStride = (d.InsideMatrix && d.HasRowMajor && d.RowMajor) ? d.MatrixStride / sizeof(float) : 1;
auto & obj = getObject(indexIds[i]); auto & obj = getObject(indexIds[i]);
if (obj.kind == Object::Kind::Constant) if (obj.kind == Object::Kind::Constant)
constantOffset += GetConstantInt(indexIds[i]); constantOffset += elemStride * GetConstantInt(indexIds[i]);
else else
ptr.offset += routine->getIntermediate(indexIds[i]).Int(0); ptr.offset += SIMD::Int(elemStride) * routine->getIntermediate(indexIds[i]).Int(0);
typeId = type.element; typeId = type.element;
break; break;
} }
...@@ -1428,6 +1441,7 @@ namespace sw ...@@ -1428,6 +1441,7 @@ namespace sw
Block |= src.Block; Block |= src.Block;
BufferBlock |= src.BufferBlock; BufferBlock |= src.BufferBlock;
RelaxedPrecision |= src.RelaxedPrecision; RelaxedPrecision |= src.RelaxedPrecision;
InsideMatrix |= src.InsideMatrix;
} }
void SpirvShader::DescriptorDecorations::Apply(const sw::SpirvShader::DescriptorDecorations &src) void SpirvShader::DescriptorDecorations::Apply(const sw::SpirvShader::DescriptorDecorations &src)
......
...@@ -425,6 +425,7 @@ namespace sw ...@@ -425,6 +425,7 @@ namespace sw
bool BufferBlock : 1; bool BufferBlock : 1;
bool RelaxedPrecision : 1; bool RelaxedPrecision : 1;
bool RowMajor : 1; // RowMajor if true; ColMajor if false bool RowMajor : 1; // RowMajor if true; ColMajor if false
bool InsideMatrix : 1; // pseudo-decoration for whether we're inside a matrix.
Decorations() Decorations()
: Location{-1}, Component{0}, : Location{-1}, Component{0},
...@@ -436,7 +437,8 @@ namespace sw ...@@ -436,7 +437,8 @@ namespace sw
HasRowMajor{false}, HasRowMajor{false},
Flat{false}, Centroid{false}, NoPerspective{false}, Flat{false}, Centroid{false}, NoPerspective{false},
Block{false}, BufferBlock{false}, Block{false}, BufferBlock{false},
RelaxedPrecision{false}, RowMajor{false} RelaxedPrecision{false}, RowMajor{false},
InsideMatrix{false}
{ {
} }
......
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