From 8ae8dd59b1de0bd7fffa371ed99aad8a07c067fb Mon Sep 17 00:00:00 2001 From: Pixelflinger Date: Wed, 15 Apr 2020 18:23:34 -0700 Subject: [PATCH] fix a strange static initialization problem on macOS It looks like using `half` during static initialization causes issues, where sometimes these values are not initialized correctly. The problem goes away when some other random static initializer executes, which suggests a race, except there is only a single thread at that point. I think for some reason `half4` are not put in the data section where float4 are. note: we don't understand the exact issue yet --- filament/src/Engine.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/filament/src/Engine.cpp b/filament/src/Engine.cpp index a7aa8941a8..6fbc1ea716 100644 --- a/filament/src/Engine.cpp +++ b/filament/src/Engine.cpp @@ -109,10 +109,10 @@ FEngine* FEngine::create(Backend backend, Platform* platform, void* sharedGLCont // these must be static because only a pointer is copied to the render stream // Note that these coordinates are specified in OpenGL clip space. Other backends can transform // these in the vertex shader as needed. -static const half4 sFullScreenTriangleVertices[3] = { - { -1.0_h, -1.0_h, 1.0_h, 1.0_h }, - { 3.0_h, -1.0_h, 1.0_h, 1.0_h }, - { -1.0_h, 3.0_h, 1.0_h, 1.0_h } +static constexpr float4 sFullScreenTriangleVertices[3] = { + { -1.0f, -1.0f, 1.0f, 1.0f }, + { 3.0f, -1.0f, 1.0f, 1.0f }, + { -1.0f, 3.0f, 1.0f, 1.0f } }; // these must be static because only a pointer is copied to the render stream @@ -155,7 +155,7 @@ void FEngine::init() { mFullScreenTriangleVb = upcast(VertexBuffer::Builder() .vertexCount(3) .bufferCount(1) - .attribute(VertexAttribute::POSITION, 0, VertexBuffer::AttributeType::HALF4, 0) + .attribute(VertexAttribute::POSITION, 0, VertexBuffer::AttributeType::FLOAT4, 0) .build(*this)); mFullScreenTriangleVb->setBufferAt(*this, 0,