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/+/52029
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Renderer/PixelProcessor.cpp b/src/Renderer/PixelProcessor.cpp
index c927d5d..0802580 100644
--- a/src/Renderer/PixelProcessor.cpp
+++ b/src/Renderer/PixelProcessor.cpp
@@ -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 @@
 		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)
diff --git a/src/Renderer/PixelProcessor.hpp b/src/Renderer/PixelProcessor.hpp
index b901ffe..2fc292a 100644
--- a/src/Renderer/PixelProcessor.hpp
+++ b/src/Renderer/PixelProcessor.hpp
@@ -191,6 +191,9 @@
 
 		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);
diff --git a/src/Renderer/VertexProcessor.cpp b/src/Renderer/VertexProcessor.cpp
index 246e278..0020d74 100644
--- a/src/Renderer/VertexProcessor.cpp
+++ b/src/Renderer/VertexProcessor.cpp
@@ -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 @@
 		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;
diff --git a/src/Renderer/VertexProcessor.hpp b/src/Renderer/VertexProcessor.hpp
index 8fdd65f..7321e69 100644
--- a/src/Renderer/VertexProcessor.hpp
+++ b/src/Renderer/VertexProcessor.hpp
@@ -186,6 +186,9 @@
 
 		virtual ~VertexProcessor();
 
+		void *operator new(size_t size);
+		void operator delete(void *mem);
+
 		void setInputStream(int index, const Stream &stream);
 		void resetInputStreams(bool preTransformed);