Cogs.Core
IsoSurfaces_internal.h
1#pragma once
2#include "IsoSurfaces.h"
3
4#include "Foundation/Memory/MemoryBuffer.h"
5
6#include <mutex>
7#include <atomic>
8#include <list>
9#include <glm/glm.hpp>
10
11namespace Cogs::Core::IsoSurfaces
12{
13 // Global state that the various analyze-pass tasks use.
15 Context* context;
16 const void* field;
17 const void* thresholds;
18
19 std::atomic<int32_t>* cellOffsets; // We might have contention on these.
20
21 int32_t* cellMap;
22 uint8_t* activeCellCases;
23 int32_t* activeCellIndices;
24 std::atomic<uint64_t>* elapsed_us;
25 std::mutex scratchLock;
26 std::list<Cogs::Memory::MemoryBuffer*> scratchBuffers;
27
28 glm::ivec3 tileSize;
29 glm::ivec3 tiles;
30 glm::ivec3 gridA;
31 glm::ivec3 fieldDim;
32 glm::ivec3 M;
33 unsigned Nt; // Number of thresholds
34 bool exteriorIsLess;
35 bool tryToUseAVX2;
36
37 Cogs::Memory::MemoryBuffer* scratchAcquire(uint32_t byteCount); // byte count is assumed to be consistent between invocations.
38
39 void scratchRelease(Cogs::Memory::MemoryBuffer* scratch);
40
41 };
42
43 void analyzeTile_f32(AnalyzeGlobalState* g, const glm::ivec3 id);
44 void analyzeTile_u16(AnalyzeGlobalState* g, const glm::ivec3 id);
45
46#ifndef EMSCRIPTEN
47 void analyzeTile_f32_SSE(AnalyzeGlobalState* stash, const glm::ivec3 id);
48 void analyzeTile_u16_SSE(AnalyzeGlobalState* g, const glm::ivec3 id);
49 void analyzeTile_f32_AVX2(AnalyzeGlobalState* g, const glm::ivec3 id);
50 void analyzeTile_u16_AVX2(AnalyzeGlobalState* g, const glm::ivec3 id);
51#endif
52
53
54 inline int32_t linearize(const glm::ivec3& i,
55 const glm::ivec3& M,
56 const glm::ivec3& gridA)
57 {
58 return ((i.z - gridA.z)*M.y + (i.y - gridA.y))*M.x + (i.x - gridA.x);
59 }
60
61 inline glm::ivec3 delinarize(const glm::int32_t ix,
62 const glm::ivec3& M,
63 const glm::ivec3& gridA)
64 {
65 glm::ivec3 i;
66 i.x = (ix % M.x) + gridA.x;
67 i.y = ((ix / M.x) % M.y) + gridA.y;
68 i.z = (ix / (M.x*M.y)) + gridA.z;
69 return i;
70 }
71
72
74 {
75 TaskId antecedent;
76 Context* context = nullptr;
77 int32_t* actCellVtxOff = nullptr;
78 int32_t* actCellIdxOff = nullptr;
79 size_t Nc;
80 std::atomic<uint64_t>* elapsed_us = nullptr;
81
82 void operator()();
83 };
84
86 {
87 struct Global
88 {
89 Context* context = nullptr;
90 const uint8_t* axesTable = nullptr;
91 const uint8_t* indexCountTable = nullptr;
92 const uint8_t* actCellCasesIn = nullptr;
93 const int32_t* actCellIndicesIn = nullptr;
94 glm::ivec3 M;
95 glm::ivec3 gridA;
96 glm::ivec3 gridB;
97 uint8_t* actCellCasesOut = nullptr;
98 int32_t* actCellIndicesOut = nullptr;
99 Scratch::ijk_t* actCellIJKOut = nullptr;
100 int32_t* actCellVtxCntOut = nullptr;
101 int32_t* actCellIdxCntOut = nullptr;
102 std::atomic<uint64_t>* elapsed_us = nullptr;
103 };
104 Global* g = nullptr;
105 size_t ca = 0;
106 size_t cb = 0;
107
108 void operator()();
109 };
110
111}
112
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
Task id struct used to identify unique Task instances.
Definition: TaskManager.h:20