Work around Subzero constant folding limitation. The Subzero JIT only supports constants in the second operand of arithmetic operations, not the first. It assumes constant folding already took place (true for NaCl which takes LLVM IR as input). Reactor has constant folding as part of the static C++ compilation, but the Optimizer may substitute the first operand for a constant (i.e. constant propagation). Addressing it in the Optimizer by not performing the substitution is not trivial because we'd have to check each use. And it would cost run-time performance. Ideally we'd have a pass for legalization/optimization which performs constant folding. For now, avoid hitting 'unreachable' code in Subzero by multiplying constants at the Reactor level. Fixes regression caused by https://swiftshader-review.googlesource.com/22910 Bug chromium:904265 Bug swiftshader:14 Change-Id: Ifdc72ac997ad5d71c1f7006259f54f3d715cb613 Reviewed-on: https://swiftshader-review.googlesource.com/c/22930 Tested-by: Nicolas Capens <nicolascapens@google.com> Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Pipeline/PixelProgram.cpp b/src/Pipeline/PixelProgram.cpp index 5b5df45..4ebe3e0 100644 --- a/src/Pipeline/PixelProgram.cpp +++ b/src/Pipeline/PixelProgram.cpp
@@ -1255,8 +1255,8 @@ void PixelProgram::TEXSIZE(Vector4f &dst, Float4 &lod, const Src &src1) { bool uniformSampler = (src1.type == Shader::PARAMETER_SAMPLER && src1.rel.type == Shader::PARAMETER_VOID); - Int index = uniformSampler ? src1.index : As<Int>(Float(fetchRegister(src1).x.x)); - Pointer<Byte> texture = data + OFFSET(DrawData, mipmap) + index * sizeof(Texture); + Int offset = uniformSampler ? src1.index * sizeof(Texture) : As<Int>(Float(fetchRegister(src1).x.x)) * sizeof(Texture); + Pointer<Byte> texture = data + OFFSET(DrawData, mipmap) + offset; dst = SamplerCore::textureSize(texture, lod); }
diff --git a/src/Pipeline/VertexProgram.cpp b/src/Pipeline/VertexProgram.cpp index 3ad2156..e5241f3 100644 --- a/src/Pipeline/VertexProgram.cpp +++ b/src/Pipeline/VertexProgram.cpp
@@ -1525,8 +1525,8 @@ void VertexProgram::TEXSIZE(Vector4f &dst, Float4 &lod, const Src &src1) { bool uniformSampler = (src1.type == Shader::PARAMETER_SAMPLER && src1.rel.type == Shader::PARAMETER_VOID); - Int index = uniformSampler ? src1.index : As<Int>(Float(fetchRegister(src1).x.x)); - Pointer<Byte> texture = data + OFFSET(DrawData, mipmap[TEXTURE_IMAGE_UNITS]) + index * sizeof(Texture); + Int offset = uniformSampler ? src1.index * sizeof(Texture) : As<Int>(Float(fetchRegister(src1).x.x)) * sizeof(Texture); + Pointer<Byte> texture = data + OFFSET(DrawData, mipmap[TEXTURE_IMAGE_UNITS]) + offset; dst = SamplerCore::textureSize(texture, lod); }
diff --git a/src/Shader/PixelProgram.cpp b/src/Shader/PixelProgram.cpp index 06ece40..671b0ef 100644 --- a/src/Shader/PixelProgram.cpp +++ b/src/Shader/PixelProgram.cpp
@@ -1280,8 +1280,8 @@ void PixelProgram::TEXSIZE(Vector4f &dst, Float4 &lod, const Src &src1) { bool uniformSampler = (src1.type == Shader::PARAMETER_SAMPLER && src1.rel.type == Shader::PARAMETER_VOID); - Int index = uniformSampler ? src1.index : As<Int>(Float(fetchRegister(src1).x.x)); - Pointer<Byte> texture = data + OFFSET(DrawData, mipmap) + index * sizeof(Texture); + Int offset = uniformSampler ? src1.index * sizeof(Texture) : As<Int>(Float(fetchRegister(src1).x.x)) * sizeof(Texture); + Pointer<Byte> texture = data + OFFSET(DrawData, mipmap) + offset; dst = SamplerCore::textureSize(texture, lod); }
diff --git a/src/Shader/VertexProgram.cpp b/src/Shader/VertexProgram.cpp index a74a37f..bde7531 100644 --- a/src/Shader/VertexProgram.cpp +++ b/src/Shader/VertexProgram.cpp
@@ -1609,8 +1609,8 @@ void VertexProgram::TEXSIZE(Vector4f &dst, Float4 &lod, const Src &src1) { bool uniformSampler = (src1.type == Shader::PARAMETER_SAMPLER && src1.rel.type == Shader::PARAMETER_VOID); - Int index = uniformSampler ? src1.index : As<Int>(Float(fetchRegister(src1).x.x)); - Pointer<Byte> texture = data + OFFSET(DrawData, mipmap[TEXTURE_IMAGE_UNITS]) + index * sizeof(Texture); + Int offset = uniformSampler ? src1.index * sizeof(Texture) : As<Int>(Float(fetchRegister(src1).x.x)) * sizeof(Texture); + Pointer<Byte> texture = data + OFFSET(DrawData, mipmap[TEXTURE_IMAGE_UNITS]) + offset; dst = SamplerCore::textureSize(texture, lod); }