passing fragcoord.w in SPIR-V and Metal
Bug: skia:
Change-Id: I94447ae74a1709c789b8d70dfd7f9572bbb2c3cf
Reviewed-on: https://skia-review.googlesource.com/c/174303
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/sksl/SkSLMetalCodeGenerator.cpp b/src/sksl/SkSLMetalCodeGenerator.cpp
index e4bcb5e..f69efdd 100644
--- a/src/sksl/SkSLMetalCodeGenerator.cpp
+++ b/src/sksl/SkSLMetalCodeGenerator.cpp
@@ -324,7 +324,8 @@
}
void MetalCodeGenerator::writeFragCoord() {
- this->write("float4(_fragCoord.x, _anonInterface0.u_skRTHeight - _fragCoord.y, 0.0, 1.0)");
+ this->write("float4(_fragCoord.x, _anonInterface0.u_skRTHeight - _fragCoord.y, 0.0, "
+ "_fragCoord.w)");
}
void MetalCodeGenerator::writeVariableReference(const VariableReference& ref) {
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp
index 2878296..5d92e2b 100644
--- a/src/sksl/SkSLSPIRVCodeGenerator.cpp
+++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp
@@ -1742,7 +1742,7 @@
fRTHeightFieldIndex = 0;
}
SkASSERT(fRTHeightFieldIndex != (SpvId) -1);
- // write float4(gl_FragCoord.x, u_skRTHeight - gl_FragCoord.y, 0.0, 1.0)
+ // write float4(gl_FragCoord.x, u_skRTHeight - gl_FragCoord.y, 0.0, gl_FragCoord.w)
SpvId xId = this->nextId();
this->writeInstruction(SpvOpCompositeExtract, this->getType(*fContext.fFloat_Type), xId,
result, 0, out);
@@ -1766,7 +1766,9 @@
FloatLiteral zero(fContext, -1, 0.0);
SpvId zeroId = writeFloatLiteral(zero);
FloatLiteral one(fContext, -1, 1.0);
- SpvId oneId = writeFloatLiteral(one);
+ SpvId wId = this->nextId();
+ this->writeInstruction(SpvOpCompositeExtract, this->getType(*fContext.fFloat_Type), wId,
+ result, 3, out);
SpvId flipped = this->nextId();
this->writeOpCode(SpvOpCompositeConstruct, 7, out);
this->writeWord(this->getType(*fContext.fFloat4_Type), out);
@@ -1774,7 +1776,7 @@
this->writeWord(xId, out);
this->writeWord(flippedYId, out);
this->writeWord(zeroId, out);
- this->writeWord(oneId, out);
+ this->writeWord(wId, out);
return flipped;
}
if (ref.fVariable.fModifiers.fLayout.fBuiltin == SK_CLOCKWISE_BUILTIN &&