Space Sim
Loading...
Searching...
No Matches
com22.comp
Go to the documentation of this file.
1
2#version 440
8#define WORKGROUP_SIZE 128
9#define RADIX_SORT_BINS 128
10#define SUBGROUP_SIZE 32
11#define BODY_COUNT 15000
12#define MAX_NODES 45000
13layout (local_size_x = WORKGROUP_SIZE) in;
14struct Particle
15{
16 vec4 p_m;
17 vec4 mat;
18 vec4 vel;
19 vec4 acc;
20};
21layout(std430, binding=1) buffer ParticleData {
22
23 Particle p_spawn[BODY_COUNT];
24 vec4 p_colors[BODY_COUNT];
25 uint p_dead[BODY_COUNT];
26 uint claimed[BODY_COUNT];
27 int nodes_visited[BODY_COUNT];
28 uint star_particles[BODY_COUNT];
29 Particle p[];
30};
31struct MortonEntry
32{
33 uint pid;
34 uint morton;
35};
36layout(std430, binding=2) buffer MortonData {
37
38 MortonEntry entry[];
39};
40layout(std430, binding=3) buffer MortonPingData {
41
42 MortonEntry exit[];
43};
44struct Node {
46 // min and size
48 // max and next
50 int next;
51 // left child, right child, parent, depth
53 // ivec4 next;
54};
55#define MAX_DEPTH 64
56layout(std430, binding=4) buffer NodeData {
57 uint ready_queue[MAX_NODES];
58 uint children_remaining[MAX_NODES];
59 uint depth_offsets[MAX_DEPTH+1];
60 uint pad0;
61 uint pad1;
62 uint pad2;
63 vec4 com_m[MAX_NODES];
64 vec4 lrsn[MAX_NODES];
65 // min and parent
66 vec4 nmin[MAX_NODES];
67 // max and depth
68 vec4 nmax[MAX_NODES];
69};
70layout(std430, binding=6) buffer NodeCounter {
71 uint queue_out;
72 int p_dead_cnt;
73 int p_spawn_cnt;
74 uint star_pcnt;
75};
76uniform int depth;
77
78void main()
79{
80 if (depth == 0)
81 {
82 uint i = gl_GlobalInvocationID.x;
83 if (i >= BODY_COUNT) return;
84
85 int p = floatBitsToInt(nmin[i].w);
86 if (p >= 0) {
87 uint remaining = atomicAdd(children_remaining[p], -1);
88 if (remaining == 1) {
89 uint amt = atomicAdd(depth_offsets[depth+1], 1);
90 ready_queue[amt] = uint(p);
91 }
92 }
93 return;
94 }
95 uint id = gl_GlobalInvocationID.x;
96 if (id >= depth_offsets[depth]) return;
97 uint i = ready_queue[id];
98 ready_queue[id] = 0;
99 vec4 lr = lrsn[i];
100 int lc = floatBitsToInt(lr.x);
101 int rc = floatBitsToInt(lr.y);
102
103 vec4 lcom = com_m[lc];
104 vec4 lmin = nmin[lc];
105 vec4 lmax = nmax[lc];
106 vec4 rcom = com_m[rc];
107 vec4 rmin = nmin[rc];
108 vec4 rmax = nmax[rc];
109
110
111 float total_mass = lcom.w + rcom.w;
112 vec3 w = lcom.xyz * lcom.w + rcom.xyz * rcom.w;
113
114 vec4 com = vec4(w, total_mass);
115 if (total_mass > 0.0) {
116 com.xyz = w / total_mass;
117 }
118 vec3 mmin = min(lmin.xyz, rmin.xyz);
119 vec3 mmax = max(lmax.xyz, rmax.xyz);
120 nmax[i].xyz = mmax;
121 nmax[i].w = intBitsToFloat(max(floatBitsToInt(lmax.w), floatBitsToInt(rmax.w)) + 1);
122
123 vec3 d = mmax - mmin;
124
125 float r = max(max(d.x, d.y), d.z);
126
127
128 com_m[i] = com;
129 nmin[i].xyz = mmin;
130 lrsn[i].z = r*r;
131
132 int p = floatBitsToInt(nmin[i].w);
133 if (p >= 0) {
134 uint remaining = atomicAdd(children_remaining[p], -1);
135 if (remaining == 1) {
136 uint amt = atomicAdd(depth_offsets[depth+1], 1);
137 ready_queue[amt] = uint(p);
138 }
139 }
140
141
142}
layout(local_size_x=16, local_size_y=16, local_size_z=1) in
uniform int depth
Definition com22.comp:76
int main(int argc, char *argv[])
Definition main.c:1726
vec4 mat
Definition main.c:261
uint morton
Definition bounds.comp:32
vec3 max
Definition com22.comp:49
vec4 com_m
Definition com22.comp:45
int next
Definition com22.comp:50
ivec4 lrpd
Definition com22.comp:52
vec4 min
Definition com22.comp:47
Definition bounds.comp:30
Definition types.h:109
vec4 acc
Definition types.h:97
vec4 p_m
Definition types.h:94
vec3 vel
Definition main.h:10
Definition main.h:8
float w
Definition types.h:47
float x
Definition types.h:47
#define WORKGROUP_SIZE
Definition types.h:171
float x
Definition main.h:5
#define MAX_DEPTH
Definition types.h:154
#define BODY_COUNT
Definition types.h:39
float y
Definition types.h:47
float y
Definition main.h:5
float z
Definition main.h:5
#define MAX_NODES
Definition types.h:40
Definition types.h:49
Definition main.h:5
Definition types.h:47