1#include "Services/TaskManager.h"
2#include "Services/Features.h"
3#include "Platform/Instrumentation.h"
6#include "BoundingBox.h"
8#include "Foundation/Memory/MemoryBuffer.h"
12void Cogs::Core::EchoSounder::includeInBBox(
Context* context,
13 Geometry::BoundingBox& bbox,
14 const float* vertices,
16 const size_t numVertices,
17 const size_t taskSize)
20 auto N = (numVertices + taskSize - 1) / taskSize;
23 if (context->
features->supported(CPUFeature::SSE2)) {
26 auto group = tm->createGroup();
27 for (
size_t i = 0; i < N; i++) {
28 auto * minmax = minmaxes.data() + 8 * i;
30 auto ib = std::min(numVertices, ia + taskSize);
31 tm->enqueueChild(group, [vertices, vertexStride, minmax, ia, ib]
33 CpuInstrumentationScope(SCOPE_GEOMETRY,
"BBoxFindSSE2");
34 __m128 min = _mm_set1_ps(std::numeric_limits<float>::max());
35 __m128 max = _mm_sub_ps(_mm_setzero_ps(), min);
36 for (
size_t i = ia; i < ib; i++) {
37 __m128 p = _mm_loadu_ps(vertices + i*vertexStride);
38 min = _mm_min_ps(min, p);
39 max = _mm_max_ps(max, p);
41 _mm_storeu_ps(minmax + 0, min);
42 _mm_storeu_ps(minmax + 4, max);
49 CpuInstrumentationScope(SCOPE_GEOMETRY,
"BBoxMergeSSE2");
51 __m128 min = _mm_set1_ps(std::numeric_limits<float>::max());
52 __m128 max = _mm_sub_ps(_mm_setzero_ps(), min);
53 for (
size_t i = 0; i < N; i++) {
54 min = _mm_min_ps(min, _mm_loadu_ps(minmaxes.data() + 8 * i + 0));
55 max = _mm_max_ps(max, _mm_loadu_ps(minmaxes.data() + 8 * i + 4));
57 for (uint32_t k = 0; k < 3; k++) {
58 bbox.min[k] = std::min(bbox.min[k], min.m128_f32[k]);
59 bbox.max[k] = std::max(bbox.max[k], max.m128_f32[k]);
69 std::vector<Cogs::Geometry::BoundingBox> bboxes(N);
71 auto group = tm->createGroup();
72 for (
int i = 0; i < N; i++) {
73 auto * sub_bbox = bboxes.data() + i;
75 auto ib = std::min(numVertices, ia + taskSize);
76 tm->enqueueChild(group, [vertices, vertexStride, sub_bbox, ia, ib]
78 CpuInstrumentationScope(SCOPE_GEOMETRY,
"BBoxFind");
79 (*sub_bbox) = Cogs::Geometry::makeEmptyBoundingBox<Cogs::Geometry::BoundingBox>();
80 for (
size_t i = ia; i < ib; i++) {
81 (*sub_bbox) += *
reinterpret_cast<const glm::vec3*
>(vertices + i*vertexStride);
89 CpuInstrumentationScope(SCOPE_GEOMETRY,
"BBoxMerge");
90 for (
int i = 0; i < N; i++) {
A Context instance contains all the services, systems and runtime components needed to use Cogs.
std::unique_ptr< class Features > features
Features service instance.
std::unique_ptr< class TaskManager > taskManager
TaskManager service instance.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....