22 #include "common/matrix.h"
23 #include "common/glutil.h"
24 #include "common/shader.h"
25 #include "common/common.h"
28 #define MAX_SCAN_LEVELS 4
46 string res =
"/data/data/com.arm.malideveloper.openglessdk.computeparticles/files/";
112 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buf_input);
113 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1,
buf_scan[0]);
114 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2,
buf_sums[0]);
115 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3,
buf_flags);
117 uniform(
"bitOffset", bit_offset);
121 dispatch_sizes[0] = blocks;
122 glDispatchCompute(blocks, 1, 1);
123 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
132 dispatch_sizes[i] = blocks;
134 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0,
buf_sums[i - 1]);
139 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1,
buf_sums[i - 1]);
143 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1,
buf_scan[i]);
145 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2,
buf_sums[i]);
147 glDispatchCompute(blocks, 1, 1);
148 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
154 for (
unsigned i = scan_levels - 1; i; i--)
156 if (dispatch_sizes[i] <= 1)
161 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0,
buf_scan[i]);
162 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1,
buf_sums[i]);
163 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2,
buf_sums[i - 1]);
164 glDispatchCompute(dispatch_sizes[i], 1, 1);
165 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
170 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buf_input);
171 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1,
buf_scan[0]);
172 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2,
buf_sums[0]);
173 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3,
buf_sorted);
174 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4,
buf_flags);
176 glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
183 for (uint32_t i = 0; i < 8; i++)
185 sort_bits(buf_input, i * 2, axis, z_min, z_max);
194 glMemoryBarrier(GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT);
void sort_bits(GLuint buf_input, int bit_offset, vec3 axis, float z_min, float z_max)
bool load_compute_from_file(string cs_path)
void radix_sort(GLuint buf_input, vec3 axis, float z_min, float z_max)
GLuint buf_scan[MAX_SCAN_LEVELS]
void del_buffer(GLuint buffer)
const uint32_t NUM_BLOCKS
const uint32_t BLOCK_SIZE
GLuint buf_sums[MAX_SCAN_LEVELS]
GLuint gen_buffer(GLenum target, GLenum usage, GLsizei size, const void *data)
void uniform(string name, const mat4 &v)
void use_shader(Shader shader)
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count