Remove idle Blitter fallbacks
For Vulkan we must support all blittable formats natively, so there's
no fallback to C++ code. Also, if by error an unsupported format is
used we don't have to immediately abort routine generation but can
continue with something that's benign.
This change simplifies the code, makes it more readable/maintainable,
and marks other formats as unsupported instead of unimplemented.
Bug: b/138944025
Bug: b/131243109
Change-Id: I4d246cdd280c5a352f18341996c92111a5144d96
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/34588
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Device/Blitter.cpp b/src/Device/Blitter.cpp
index f6b483e..198f108 100644
--- a/src/Device/Blitter.cpp
+++ b/src/Device/Blitter.cpp
@@ -257,9 +257,9 @@
return true;
}
- bool Blitter::read(Float4 &c, Pointer<Byte> element, const State &state)
+ Float4 Blitter::readFloat4(Pointer<Byte> element, const State &state)
{
- c = Float4(0.0f, 0.0f, 0.0f, 1.0f);
+ Float4 c(0.0f, 0.0f, 0.0f, 1.0f);
switch(state.sourceFormat)
{
@@ -448,13 +448,13 @@
c.x = Float(Int(*Pointer<Byte>(element)));
break;
default:
- return false;
+ UNSUPPORTED("Blitter source format %d", (int)state.sourceFormat);
}
- return true;
+ return c;
}
- bool Blitter::write(Float4 &c, Pointer<Byte> element, const State &state)
+ void Blitter::write(Float4 &c, Pointer<Byte> element, const State &state)
{
bool writeR = state.writeRed;
bool writeG = state.writeGreen;
@@ -983,14 +983,14 @@
*Pointer<Byte>(element) = Byte(RoundInt(Float(c.x)));
break;
default:
- return false;
+ UNSUPPORTED("Blitter destination format %d", (int)state.destFormat);
+ break;
}
- return true;
}
- bool Blitter::read(Int4 &c, Pointer<Byte> element, const State &state)
+ Int4 Blitter::readInt4(Pointer<Byte> element, const State &state)
{
- c = Int4(0, 0, 0, 1);
+ Int4 c(0, 0, 0, 1);
switch(state.sourceFormat)
{
@@ -1046,13 +1046,13 @@
c = Insert(c, *Pointer<Int>(element), 0);
break;
default:
- return false;
+ UNSUPPORTED("Blitter source format %d", (int)state.sourceFormat);
}
- return true;
+ return c;
}
- bool Blitter::write(Int4 &c, Pointer<Byte> element, const State &state)
+ void Blitter::write(Int4 &c, Pointer<Byte> element, const State &state)
{
bool writeR = state.writeRed;
bool writeG = state.writeGreen;
@@ -1273,15 +1273,14 @@
if(writeR) { *Pointer<UInt>(element) = As<UInt>(Extract(c, 0)); }
break;
default:
- return false;
+ UNSUPPORTED("Blitter destination format %d", (int)state.destFormat);
}
-
- return true;
}
- bool Blitter::ApplyScaleAndClamp(Float4 &value, const State &state, bool preScaled)
+ void Blitter::ApplyScaleAndClamp(Float4 &value, const State &state, bool preScaled)
{
float4 scale, unscale;
+
if(state.clearOperation &&
state.sourceFormat.isNonNormalizedInteger() &&
!state.destFormat.isNonNormalizedInteger())
@@ -1297,18 +1296,15 @@
unscale = replicate(static_cast<float>(0xFFFFFFFF));
break;
default:
- return false;
+ UNSUPPORTED("Blitter source format %d", (int)state.sourceFormat);
}
}
- else if(!state.sourceFormat.getScale(unscale))
+ else
{
- return false;
+ unscale = state.sourceFormat.getScale();
}
- if(!state.destFormat.getScale(scale))
- {
- return false;
- }
+ scale = state.destFormat.getScale();
bool srcSRGB = state.sourceFormat.isSRGBformat();
bool dstSRGB = state.destFormat.isSRGBformat();
@@ -1334,8 +1330,6 @@
state.destFormat.isUnsignedComponent(2) ? 0.0f : -scale.z,
state.destFormat.isUnsignedComponent(3) ? 0.0f : -scale.w));
}
-
- return true;
}
Int Blitter::ComputeOffset(Int &x, Int &y, Int &pitchB, int bytes, bool quadLayout)
@@ -1416,24 +1410,15 @@
{
if(intBoth) // Integer types
{
- if(!read(constantColorI, source, state))
- {
- return nullptr;
- }
+ constantColorI = readInt4(source, state);
hasConstantColorI = true;
}
else
{
- if(!read(constantColorF, source, state))
- {
- return nullptr;
- }
+ constantColorF = readFloat4(source, state);
hasConstantColorF = true;
- if(!ApplyScaleAndClamp(constantColorF, state))
- {
- return nullptr;
- }
+ ApplyScaleAndClamp(constantColorF, state);
}
}
@@ -1449,26 +1434,19 @@
if(hasConstantColorI)
{
- if(!write(constantColorI, d, state))
- {
- return nullptr;
- }
+ write(constantColorI, d, state);
}
else if(hasConstantColorF)
{
for(int s = 0; s < state.destSamples; s++)
{
- if(!write(constantColorF, d, state))
- {
- return nullptr;
- }
+ write(constantColorF, d, state);
d += *Pointer<Int>(blit + OFFSET(BlitData, dSliceB));
}
}
else if(intBoth) // Integer types do not support filtering
{
- Int4 color; // When both formats are true integer types, we don't go to float to avoid losing precision
Int X = Int(x);
Int Y = Int(y);
@@ -1480,15 +1458,9 @@
Pointer<Byte> s = source + ComputeOffset(X, Y, sPitchB, srcBytes, srcQuadLayout);
- if(!read(color, s, state))
- {
- return nullptr;
- }
-
- if(!write(color, d, state))
- {
- return nullptr;
- }
+ // When both formats are true integer types, we don't go to float to avoid losing precision
+ Int4 color = readInt4(s, state);
+ write(color, d, state);
}
else
{
@@ -1508,29 +1480,24 @@
Pointer<Byte> s = source + ComputeOffset(X, Y, sPitchB, srcBytes, srcQuadLayout);
- if(!read(color, s, state))
- {
- return nullptr;
- }
+ color = readFloat4(s, state);
if(state.srcSamples > 1) // Resolve multisampled source
{
if(state.convertSRGB && state.sourceFormat.isSRGBformat()) // sRGB -> RGB
{
- if(!ApplyScaleAndClamp(color, state)) return nullptr;
+ ApplyScaleAndClamp(color, state);
preScaled = true;
}
Float4 accum = color;
for(int sample = 1; sample < state.srcSamples; sample++)
{
s += *Pointer<Int>(blit + OFFSET(BlitData, sSliceB));
- if(!read(color, s, state))
- {
- return nullptr;
- }
+ color = readFloat4(s, state);
+
if(state.convertSRGB && state.sourceFormat.isSRGBformat()) // sRGB -> RGB
{
- if(!ApplyScaleAndClamp(color, state)) return nullptr;
+ ApplyScaleAndClamp(color, state);
preScaled = true;
}
accum += color;
@@ -1565,17 +1532,17 @@
Pointer<Byte> s10 = source + ComputeOffset(X0, Y1, sPitchB, srcBytes, srcQuadLayout);
Pointer<Byte> s11 = source + ComputeOffset(X1, Y1, sPitchB, srcBytes, srcQuadLayout);
- Float4 c00; if(!read(c00, s00, state)) return nullptr;
- Float4 c01; if(!read(c01, s01, state)) return nullptr;
- Float4 c10; if(!read(c10, s10, state)) return nullptr;
- Float4 c11; if(!read(c11, s11, state)) return nullptr;
+ Float4 c00 = readFloat4(s00, state);
+ Float4 c01 = readFloat4(s01, state);
+ Float4 c10 = readFloat4(s10, state);
+ Float4 c11 = readFloat4(s11, state);
if(state.convertSRGB && state.sourceFormat.isSRGBformat()) // sRGB -> RGB
{
- if(!ApplyScaleAndClamp(c00, state)) return nullptr;
- if(!ApplyScaleAndClamp(c01, state)) return nullptr;
- if(!ApplyScaleAndClamp(c10, state)) return nullptr;
- if(!ApplyScaleAndClamp(c11, state)) return nullptr;
+ ApplyScaleAndClamp(c00, state);
+ ApplyScaleAndClamp(c01, state);
+ ApplyScaleAndClamp(c10, state);
+ ApplyScaleAndClamp(c11, state);
preScaled = true;
}
@@ -1588,17 +1555,11 @@
(c10 * ix + c11 * fx) * fy;
}
- if(!ApplyScaleAndClamp(color, state, preScaled))
- {
- return nullptr;
- }
+ ApplyScaleAndClamp(color, state, preScaled);
for(int s = 0; s < state.destSamples; s++)
{
- if(!write(color, d, state))
- {
- return nullptr;
- }
+ write(color, d, state);
d += *Pointer<Int>(blit + OFFSET(BlitData,dSliceB));
}
@@ -1618,13 +1579,6 @@
if(!blitRoutine)
{
blitRoutine = generate(state);
-
- if(!blitRoutine)
- {
- UNIMPLEMENTED("blitRoutine");
- return nullptr;
- }
-
blitCache.add(state, blitRoutine);
}
@@ -1639,13 +1593,6 @@
if(!cornerUpdateRoutine)
{
cornerUpdateRoutine = generateCornerUpdate(state);
-
- if(!cornerUpdateRoutine)
- {
- UNIMPLEMENTED("cornerUpdateRoutine");
- return nullptr;
- }
-
cornerUpdateCache.add(state, cornerUpdateRoutine);
}
@@ -1918,15 +1865,13 @@
int bytes = state.sourceFormat.bytes();
bool quadLayout = state.sourceFormat.hasQuadLayout();
- Float4 c0;
- read(c0, layer + ComputeOffset(x0, y1, pitchB, bytes, quadLayout), state);
- Float4 c1;
- read(c1, layer + ComputeOffset(x1, y0, pitchB, bytes, quadLayout), state);
- c0 += c1;
- read(c1, layer + ComputeOffset(x1, y1, pitchB, bytes, quadLayout), state);
- c0 += c1;
- c0 *= Float4(1.0f / 3.0f);
- write(c0, layer + ComputeOffset(x0, y0, pitchB, bytes, quadLayout), state);
+ Float4 c = readFloat4(layer + ComputeOffset(x0, y1, pitchB, bytes, quadLayout), state) +
+ readFloat4(layer + ComputeOffset(x1, y0, pitchB, bytes, quadLayout), state) +
+ readFloat4(layer + ComputeOffset(x1, y1, pitchB, bytes, quadLayout), state);
+
+ c *= Float4(1.0f / 3.0f);
+
+ write(c, layer + ComputeOffset(x0, y0, pitchB, bytes, quadLayout), state);
}
std::shared_ptr<Routine> Blitter::generateCornerUpdate(const State& state)
@@ -2082,7 +2027,7 @@
int h = extent.height;
if(w != h)
{
- UNIMPLEMENTED("Cube doesn't have square faces : (%d, %d)", w, h);
+ UNSUPPORTED("Cube doesn't have square faces : (%d, %d)", w, h);
}
// Src is expressed in the regular [0, width-1], [0, height-1] space