When we use Swiftshader which is part of the Android image (compiled for ARM64) to render graphics, Android12 boot sometimes crashes in JIT code.
The crash occurs in access to Texture’s data.
As we analized the crash, we found the following:
A texture with an external format FORMAT_A16B16G16R16F was created from an
Android native buffer (HAL_PIXEL_FORMAT_RGBA_FP16 -> GL_RGBA16F).
All textures with half float (2 bytes) external formats are constructed with the corresponding single float precision (4 bytes) internal format (FORMAT_A32B32G32R32F).
When applyTexture is called, it calls Sampler::setTextureLevel that calls
surface->lockInternal(…). This virtual function is overridden in AndroidNativeImage class
(swiftshader/src/OpenGL/common/Image.hpp), and it returns the pointer to a native buffer that has “half float” data.
When a shader code containing access to texture data is generated, it calculates offset in the buffer using four-float-per-texel (FORMAT_A32B32G32R32F, 16 bytes ). This often causes crashes because the calculated offset is incorrect.
From tombstone:
pid: 379, tid: 435, name: RenderEngine >>> /system/bin/surfaceflinger <<<
uid: 1000
signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x774823f010
x0 000000000003c010 x1 0000000000003c80 x2 0000000000003c81 x3 000000
000003c000
x4 0000000000000008 x5 0000000000000004 x6 2e7265646168732e x7 6e6962
2e72656461
x8 0000000000019ee0 x9 00000000000018b0 x10 00000000000018b2 x11 000000
74b166e638
x12 0000000000000002 x13 0000000000000004 x14 0000000000000008 x15 000000
00000184b0
x16 0000000000019f20 x17 00000000000098c0 x18 0000007748203000 x19 000000
7553e473d0
x20 00000074b166f370 x21 0000000000000004 x22 0000007653979108 x23 000000
74b1672000
x24 0000000000000001 x25 0000000000000004 x26 00000075e397e060 x27 000000
60b48ce000
x28 00000075e397e010 x29 00000074b166e7c0
lr 00000074ab6dd490 sp 00000074b166e430 pc 00000077485573b4 pst 000000
0000001000
backtrace:
#00 pc 00000000000003b4 [anon:swiftshader_jit]
#01 pc 000000000097f48c /vendor/lib64/egl/libGLESv2_swiftshader.so (sw::Renderer::executeTask(int)+1248) (BuildId: a5771f173a7615706148282b349cf3a6)
#02 pc 000000000097e95c /vendor/lib64/egl/libGLESv2_swiftshader.so (sw::Renderer::taskLoop(int)+88) (BuildId: a5771f173a7615706148282b349cf3a6)
#03 pc 000000000097d53c /vendor/lib64/egl/libGLESv2_swiftshader.so (sw::Renderer::draw(sw::DrawType, unsigned int, unsigned int, bool)+8972) (BuildId: a5771f173a7615706148282b349cf3a6)
#04 pc 000000000088dcd4 /vendor/lib64/egl/libGLESv2_swiftshader.so (es2::Device::drawPrimitive(sw::DrawType, unsigned int)+88) (BuildId: a5771f173a7615706148282b349cf3a6)
……
……
Do you have any advice/suggestions on how to fix this crash?