From 3e97906b32e328e6e0d1db3cb44dba5e3bb9b6c9 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Mon, 8 Jan 2018 17:30:33 +0100 Subject: [PATCH] gs-vertex: Always align to 16-byte --- source/gs-vertex.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++ source/gs-vertex.h | 18 +++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/source/gs-vertex.cpp b/source/gs-vertex.cpp index 69a59c79..4b94ea0a 100644 --- a/source/gs-vertex.cpp +++ b/source/gs-vertex.cpp @@ -18,3 +18,48 @@ */ #include "gs-vertexbuffer.h" +#include "util-memory.h" + +GS::Vertex& GS::Vertex::operator=(const Vertex& r) { + vec3_copy(&this->position, &r.position); + vec3_copy(&this->normal, &r.normal); + vec3_copy(&this->tangent, &r.tangent); + for (size_t n = 0; n < MAXIMUM_UVW_LAYERS; n++) { + vec4_copy(&this->uv[n], &r.uv[n]); + } + return *this; +} + +GS::Vertex* GS::Vertex::operator=(const Vertex* r) { + vec3_copy(&this->position, &r->position); + vec3_copy(&this->normal, &r->normal); + vec3_copy(&this->tangent, &r->tangent); + for (size_t n = 0; n < MAXIMUM_UVW_LAYERS; n++) { + vec4_copy(&this->uv[n], &r->uv[n]); + } + return this; +} + +void* GS::Vertex::operator new(size_t count) { + return util::malloc_aligned(16, count); +} + +void* GS::Vertex::operator new(size_t count, void* d){ + return d; +} + +void* GS::Vertex::operator new[](size_t count) { + return util::malloc_aligned(16, count); +} + +void* GS::Vertex::operator new[](size_t count, void* d) { + return d; +} + +void GS::Vertex::operator delete(void* p) { + return util::free_aligned(p); +} + +void GS::Vertex::operator delete[](void* p) { + return util::free_aligned(p); +} diff --git a/source/gs-vertex.h b/source/gs-vertex.h index 06c2d193..979f19e7 100644 --- a/source/gs-vertex.h +++ b/source/gs-vertex.h @@ -29,11 +29,27 @@ extern "C" { namespace GS { const uint32_t MAXIMUM_UVW_LAYERS = 8u; // ToDo: Optimize for use with GS::VertexBuffer so that it doesn't require in-memory copy. - struct Vertex { + __declspec(align(16)) struct Vertex { vec3 position; vec3 normal; vec3 tangent; vec4 uv[MAXIMUM_UVW_LAYERS]; uint32_t color; + + // Operators + static void* Vertex::operator new(size_t count); + static void* Vertex::operator new[](size_t count); + static void* Vertex::operator new(size_t count, void* d); + static void* Vertex::operator new[](size_t count, void* d); + static void Vertex::operator delete(void* p); + static void Vertex::operator delete[](void* p); + + //Vertex& Vertex::operator =(Vertex r); + Vertex& Vertex::operator =(const Vertex& r); + Vertex* Vertex::operator =(const Vertex* r); + + private: + uint32_t padding[3]; }; + }