Cogs.Core
TransformVertices_ref.cpp
1#include <iostream>
2#include "Utilities/TransformVertices.h"
3#include "Context.h"
4#include "Services/Features.h"
5
6//#ifdef COGS_ARCH_X86
7//#include "TransformVerticesSSE.h"
8//#ifdef COGS_EXTENSIONS_AVX
9//#include "../../Extensions/UtilitiesAVX/TransformVerticesAVX.h"
10//#endif
11//#endif
12
13#ifndef EMSCRIPTEN
14namespace Cogs::Core
15{
16
17 void transformVertex3ToVertex4AVX(uint8_t* dst,
18 const size_t dst_stride,
19 const size_t dst_bytes,
20 const glm::mat4& matrix,
21 const uint8_t* src,
22 const size_t src_stride,
23 const size_t src_bytes,
24 const size_t src_count);
25
26 void transformVertex3ToVertex4FastPathAVX(uint8_t* dst,
27 const size_t dst_stride,
28 const size_t dst_bytes,
29 const glm::mat4& matrix,
30 const uint8_t* src,
31 const size_t src_stride,
32 const size_t src_bytes,
33 const size_t src_count);
34
35 void transformVertex3ToVertex4SSE1(uint8_t* dst, const size_t dst_stride, const size_t dst_bytes,
36 const glm::mat4& matrix,
37 const uint8_t* src,
38 const size_t src_stride,
39 const size_t src_bytes,
40 const size_t src_count);
41
42
43 void transformVertex3ToVertex4FastPathSSE1(uint8_t* dst, const size_t dst_stride, const size_t dst_bytes,
44 const glm::mat4& matrix,
45 const uint8_t* src,
46 const size_t src_stride,
47 const size_t src_bytes,
48 const size_t src_count);
49
50}
51#endif
52
53
54void Cogs::Core::transformVertex3ToVertex4(Context* context,
55 uint8_t* dst,
56 const size_t dst_stride,
57 const size_t dst_bytes,
58 const glm::mat4& matrix,
59 const uint8_t* src,
60 const size_t src_stride,
61 const size_t src_bytes,
62 const size_t src_count)
63{
64 size_t i = 0;
65
66#if !defined(EMSCRIPTEN) && !defined(__APPLE__)
67
68 if (context->features->supported(CPUFeature::AVX)) {
69 if ((((size_t)dst & 0x1f) == 0) && (dst_stride == 16) && (((size_t)src & 0xf) == 0) && ((src_stride & 0xf) == 0)) {
70 transformVertex3ToVertex4FastPathAVX(dst, dst_stride, dst_bytes, matrix, src, src_stride, src_bytes, src_count);
71 }
72 else {
73 transformVertex3ToVertex4AVX(dst, dst_stride, dst_bytes, matrix, src, src_stride, src_bytes, src_count);
74 }
75 return;
76 }
77
78 if (context->features->supported(CPUFeature::SSE)) {
79 if ((((size_t)dst & 0xf) == 0) && ((dst_stride & 0xf) == 0) && (((size_t)src & 0xf) == 0) && ((src_stride & 0xf) == 0)) {
80 transformVertex3ToVertex4FastPathSSE1(dst, dst_stride, dst_bytes, matrix, src, src_stride, src_bytes, src_count);
81 }
82 else {
83 transformVertex3ToVertex4SSE1(dst, dst_stride, dst_bytes, matrix, src, src_stride, src_bytes, src_count);
84 }
85 return; // No remainder
86 }
87#else
88 (void)context;
89 (void)src_bytes;
90 (void)dst_bytes;
91#endif
92
93 for (; i < src_count; i++) {
94 glm::vec4& d = *reinterpret_cast<glm::vec4*>(dst + dst_stride*i);
95 const glm::vec3& s = *reinterpret_cast<const glm::vec3*>(src + src_stride*i);
96 d = matrix * glm::vec4(s[0], s[1], s[2], 1.f);
97 }
98}
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....