Commit 532770bb by Nicolas Capens Committed by Nicolas Capens

Use aligned allocation for classes with aligned members

The legacy PixelProcessor and VertexProcessor classes for OpenGL ES contain member fields with types like float4, which require 16-byte alignment. This isn't guaranteed by the compiler until C++17. On macOS, this also requires OS support, which was added in version 10.14 (Mojave), while Chrome still has to support macOS 10.11. src/Renderer/PixelProcessor.cpp:75:18: error: aligned deallocation function of type 'void (void *, std::align_val_t) noexcept' is only available on macOS 10.14 or newer Overriding new and delete for these classes allows us to use our custom allocator which guarantees alignment. Note that the Renderer class already used the same approach. Also note that this hasn't caused issues before because these fields aren't actually accessed by instructions which demand alignment. However, it's still good for performance and to align with the intent (pun intended). Bug: b/174843857 Change-Id: Ia5de5f6fe67a4f54805cdde3fed565c30b9318a8 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/52029Reviewed-by: 's avatarAntonio Maiorano <amaiorano@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent b3e5c440
......@@ -21,6 +21,7 @@
#include "Shader/PixelShader.hpp"
#include "Shader/Constants.hpp"
#include "Common/Debug.hpp"
#include "Common/Memory.hpp"
#include <cstring>
......@@ -78,6 +79,18 @@ namespace sw
routineCache = nullptr;
}
// This object has to be mem aligned
void *PixelProcessor::operator new(size_t size)
{
ASSERT(size == sizeof(PixelProcessor)); // This operator can't be called from a derived class
return sw::allocate(sizeof(PixelProcessor), 16);
}
void PixelProcessor::operator delete(void *mem)
{
sw::deallocate(mem);
}
void PixelProcessor::setFloatConstant(unsigned int index, const float value[4])
{
if(index < FRAGMENT_UNIFORM_VECTORS)
......
......@@ -191,6 +191,9 @@ namespace sw
virtual ~PixelProcessor();
void *operator new(size_t size);
void operator delete(void *mem);
void setFloatConstant(unsigned int index, const float value[4]);
void setIntegerConstant(unsigned int index, const int value[4]);
void setBooleanConstant(unsigned int index, int boolean);
......
......@@ -20,6 +20,7 @@
#include "Shader/PixelShader.hpp"
#include "Shader/Constants.hpp"
#include "Common/Math.hpp"
#include "Common/Memory.hpp"
#include "Common/Debug.hpp"
#include <cstring>
......@@ -124,6 +125,18 @@ namespace sw
routineCache = nullptr;
}
// This object has to be mem aligned
void *VertexProcessor::operator new(size_t size)
{
ASSERT(size == sizeof(VertexProcessor)); // This operator can't be called from a derived class
return sw::allocate(sizeof(VertexProcessor), 16);
}
void VertexProcessor::operator delete(void *mem)
{
sw::deallocate(mem);
}
void VertexProcessor::setInputStream(int index, const Stream &stream)
{
context->input[index] = stream;
......
......@@ -186,6 +186,9 @@ namespace sw
virtual ~VertexProcessor();
void *operator new(size_t size);
void operator delete(void *mem);
void setInputStream(int index, const Stream &stream);
void resetInputStreams(bool preTransformed);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment