Use writeComposite to vectorize scalars.

`writeComposite` can write and deduplicate constants, so it's preferable
to manually emitting an OpCompositeConstruct opcode.

Change-Id: Ie5c23af76822da762eadac8ff0ab0c6cc0febd31
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/528637
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2022-04-07 22:25:04 -04:00 committed by SkCQ
parent 699dd5ae4a
commit 89bdf0f872
6 changed files with 557 additions and 591 deletions

View File

@ -2409,16 +2409,9 @@ SpvId SPIRVCodeGenerator::writeBinaryExpression(const Type& leftType, SpvId lhs,
break;
}
}
// promote number to vector
const Type& vecType = leftType;
SpvId vec = this->nextId(&vecType);
this->writeOpCode(SpvOpCompositeConstruct, 3 + vecType.columns(), out);
this->writeWord(this->getType(vecType), out);
this->writeWord(vec, out);
for (int i = 0; i < vecType.columns(); i++) {
this->writeWord(rhs, out);
}
rhs = vec;
// Vectorize the right-hand side.
std::vector<SpvId> arguments(/*count*/ leftType.columns(), /*value*/ rhs);
rhs = this->writeComposite(arguments, leftType, out);
operandType = &leftType;
} else if (rightType.isVector() && leftType.isNumber()) {
if (resultType.componentType().isFloat()) {
@ -2429,16 +2422,9 @@ SpvId SPIRVCodeGenerator::writeBinaryExpression(const Type& leftType, SpvId lhs,
return result;
}
}
// promote number to vector
const Type& vecType = rightType;
SpvId vec = this->nextId(&vecType);
this->writeOpCode(SpvOpCompositeConstruct, 3 + vecType.columns(), out);
this->writeWord(this->getType(vecType), out);
this->writeWord(vec, out);
for (int i = 0; i < vecType.columns(); i++) {
this->writeWord(lhs, out);
}
lhs = vec;
// Vectorize the left-hand side.
std::vector<SpvId> arguments(/*count*/ rightType.columns(), /*value*/ lhs);
lhs = this->writeComposite(arguments, rightType, out);
operandType = &rightType;
} else if (leftType.isMatrix()) {
if (op.kind() == Operator::Kind::STAR) {

View File

@ -43,6 +43,7 @@ OpDecorate %30 RelaxedPrecision
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%float_1 = OpConstant %float 1
%24 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
%int_1 = OpConstant %int 1
%main = OpFunction %void None %14
%15 = OpLabel
@ -50,7 +51,6 @@ OpDecorate %30 RelaxedPrecision
%20 = OpLoad %v4float %16
%22 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0
%23 = OpLoad %v4float %22
%24 = OpCompositeConstruct %v4float %float_1 %float_1 %float_1 %float_1
%25 = OpFSub %v4float %24 %23
%26 = OpAccessChain %_ptr_Uniform_v4float %10 %int_1
%28 = OpLoad %v4float %26

View File

@ -65,6 +65,7 @@ OpDecorate %221 RelaxedPrecision
%int_0 = OpConstant %int 0
%float_100 = OpConstant %float 100
%float_200 = OpConstant %float 200
%38 = OpConstantComposite %v4float %float_200 %float_200 %float_200 %float_200
%uint_100 = OpConstant %uint 100
%uint_200 = OpConstant %uint 200
%uint_275 = OpConstant %uint 275
@ -120,7 +121,6 @@ OpFunctionEnd
%30 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0
%34 = OpLoad %v4float %30
%36 = OpVectorTimesScalar %v4float %34 %float_100
%38 = OpCompositeConstruct %v4float %float_200 %float_200 %float_200 %float_200
%39 = OpFAdd %v4float %36 %38
%40 = OpCompositeExtract %float %39 0
%41 = OpConvertFToU %uint %40

View File

@ -73,7 +73,9 @@ OpDecorate %110 RelaxedPrecision
%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%34 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
%float_1 = OpConstant %float 1
%40 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
%false = OpConstantFalse %bool
%v2bool = OpTypeVector %bool 2
%v3float = OpTypeVector %float 3
@ -98,12 +100,10 @@ OpFunctionEnd
%28 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0
%32 = OpLoad %v4float %28
%33 = OpVectorShuffle %v4float %32 %32 1 1 1 1
%34 = OpCompositeConstruct %v4float %float_0 %float_0 %float_0 %float_0
%35 = OpFDiv %v4float %34 %33
OpStore %valueIsNaN %35
%38 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0
%39 = OpLoad %v4float %38
%40 = OpCompositeConstruct %v4float %float_1 %float_1 %float_1 %float_1
%41 = OpFDiv %v4float %40 %39
OpStore %valueIsNumber %41
%44 = OpLoad %v4float %valueIsNaN

View File

@ -49,6 +49,7 @@ OpDecorate %54 RelaxedPrecision
%float_0_5 = OpConstant %float 0.5
%int_1 = OpConstant %int 1
%float_0_25 = OpConstant %float 0.25
%51 = OpConstantComposite %v4float %float_0_25 %float_0_25 %float_0_25 %float_0_25
%int_2 = OpConstant %int 2
%int_100 = OpConstant %int 100
%main = OpFunction %void None %14
@ -92,7 +93,6 @@ OpLoopMerge %48 %47 None
OpBranch %45
%45 = OpLabel
%49 = OpLoad %v4float %sk_FragColor
%51 = OpCompositeConstruct %v4float %float_0_25 %float_0_25 %float_0_25 %float_0_25
%52 = OpFAdd %v4float %49 %51
OpStore %sk_FragColor %52
OpBranch %46

File diff suppressed because it is too large Load Diff