mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-29 04:37:30 +01:00
Draw instances from the GPU culling with indirect draws, occlusion culling and a depth prepass
This commit is contained in:
@@ -21,8 +21,11 @@ void gl::glsl_common_setup()
|
||||
"#define INSTANCE_LOD_SSBO_BINDING " + std::to_string(INSTANCE_LOD_SSBO_BINDING) + "\n" +
|
||||
"#define INSTANCE_COUNTER_SSBO_BINDING " + std::to_string(INSTANCE_COUNTER_SSBO_BINDING) + "\n" +
|
||||
"#define INSTANCE_OUTPUT_SSBO_BINDING " + std::to_string(INSTANCE_OUTPUT_SSBO_BINDING) + "\n" +
|
||||
"#define INSTANCE_COMMAND_SSBO_BINDING " + std::to_string(INSTANCE_COMMAND_SSBO_BINDING) + "\n" +
|
||||
"#define INSTANCE_CULL_GROUP_SIZE " + std::to_string(INSTANCE_CULL_GROUP_SIZE) + "\n" +
|
||||
"#define INSTANCE_OFFSETS_GROUP_SIZE " + std::to_string(INSTANCE_OFFSETS_GROUP_SIZE) + "\n" +
|
||||
"#define INSTANCE_COMMAND_GROUP_SIZE " + std::to_string(INSTANCE_COMMAND_GROUP_SIZE) + "\n" +
|
||||
"#define HIZ_GROUP_SIZE " + std::to_string(HIZ_GROUP_SIZE) + "\n" +
|
||||
"#define INSTANCE_COUNTER_HEADER " + std::to_string(INSTANCE_COUNTER_HEADER) + "\n" +
|
||||
"#define LIGHT_SSBO_BINDING " + std::to_string(LIGHT_SSBO_BINDING) + "\n" +
|
||||
"#define CLUSTER_GRID_X " + std::to_string(CLUSTER_GRID_X) + "\n" +
|
||||
|
||||
25
gl/ubo.h
25
gl/ubo.h
@@ -391,11 +391,16 @@ namespace gl
|
||||
const GLuint INSTANCE_LOD_SSBO_BINDING = 12; // sorted lod bounds (squared distances) of the groups
|
||||
const GLuint INSTANCE_COUNTER_SSBO_BINDING = 13; // header, then count[entries] and cursor[entries]
|
||||
const GLuint INSTANCE_OUTPUT_SSBO_BINDING = 14; // modelview matrices of the instances which passed, by entry
|
||||
const GLuint INSTANCE_COMMAND_SSBO_BINDING = 15; // indirect draw commands of the entries (instance_cull_commands.comp)
|
||||
const GLuint INSTANCE_CULL_GROUP_SIZE = 64;
|
||||
const GLuint INSTANCE_OFFSETS_GROUP_SIZE = 1024;
|
||||
// uints of the header of the counter buffer: frame number, survivors in total, entries, unused.
|
||||
const GLuint INSTANCE_COMMAND_GROUP_SIZE = 64;
|
||||
// uints of the header of the counter buffer: frame number, survivors in total, entries, instances left out as hidden
|
||||
// behind the depth already drawn (occlusion test).
|
||||
// an entry is a lod band of a group: survivors of group g in band b are counted at entry entryfirst(g) + b
|
||||
const GLuint INSTANCE_COUNTER_HEADER = 4;
|
||||
// work group of the passes which make the depth pyramid of the occlusion test (hiz_build.comp), 8x8
|
||||
const GLuint HIZ_GROUP_SIZE = 8;
|
||||
|
||||
// layout std430: a bucket of a scene cell queued in the pass (GLSL: instance_cull_job)
|
||||
struct instance_cull_job
|
||||
@@ -422,5 +427,23 @@ namespace gl
|
||||
|
||||
static_assert(sizeof(instance_cull_group) == 16, "bad size of instance_cull_group");
|
||||
|
||||
// layout std430: an indirect draw of the submodel of a group in one of its lod bands. the first five fields are the
|
||||
// command of glDrawElementsIndirect (count, instance count, first index, base vertex, base instance), or with indexed 0
|
||||
// the one of glDrawArraysIndirect (count, instance count, first vertex, base instance). the cpu fills in what it knows
|
||||
// of the geometry, instance_cull_commands.comp the instances, from the counts of the entry
|
||||
struct instance_draw_command
|
||||
{
|
||||
uint32_t count;
|
||||
uint32_t instancecount;
|
||||
uint32_t first;
|
||||
uint32_t basevertex; // the base instance of an array draw
|
||||
uint32_t baseinstance;
|
||||
uint32_t entry;
|
||||
uint32_t indexed;
|
||||
uint32_t pad;
|
||||
};
|
||||
|
||||
static_assert(sizeof(instance_draw_command) == 32, "bad size of instance_draw_command");
|
||||
|
||||
#pragma pack(pop)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user