17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-02 01:09:13 +01:00

perf(sleepers): the instances of the sleepers and timbers of a track sent to the gpu once, as it's laid, and kept there in a buffer of their own; in each pass the runs of them in sight turned by the modelviews of their cells into the instance buffer of the frame by a compute pass, one dispatch and one barrier a pass, and drawn in one instanced draw for each model, part and level of detail, in place of the cpu turning every instance every frame

This commit is contained in:
maj00r
2026-10-24 01:40:34 +02:00
parent f155956669
commit 85b76acca5
12 changed files with 444 additions and 92 deletions

View File

@@ -29,6 +29,11 @@ void gl::glsl_common_setup()
"#define HIZ_GROUP_SIZE " + std::to_string(HIZ_GROUP_SIZE) + "\n" +
"#define SHADOW_FIT_GROUP_SIZE " + std::to_string(SHADOW_FIT_GROUP_SIZE) + "\n" +
"#define SHADOW_FIT_SSBO_BINDING " + std::to_string(SHADOW_FIT_SSBO_BINDING) + "\n" +
"#define TIMBER_GROUP_SIZE " + std::to_string(TIMBER_GROUP_SIZE) + "\n" +
"#define TIMBER_LOCAL_SSBO_BINDING " + std::to_string(TIMBER_LOCAL_SSBO_BINDING) + "\n" +
"#define TIMBER_RANGE_SSBO_BINDING " + std::to_string(TIMBER_RANGE_SSBO_BINDING) + "\n" +
"#define TIMBER_OUTPUT_SSBO_BINDING " + std::to_string(TIMBER_OUTPUT_SSBO_BINDING) + "\n" +
"#define TIMBER_ORIGIN_SSBO_BINDING " + std::to_string(TIMBER_ORIGIN_SSBO_BINDING) + "\n" +
"#define PARTICLE_GROUP_SIZE " + std::to_string(PARTICLE_GROUP_SIZE) + "\n" +
"#define PARTICLE_SSBO_BINDING " + std::to_string(PARTICLE_SSBO_BINDING) + "\n" +
"#define PARTICLE_SOURCE_SSBO_BINDING " + std::to_string(PARTICLE_SOURCE_SSBO_BINDING) + "\n" +

View File

@@ -141,6 +141,17 @@ void gl::frame_stream::next_frame()
}
GLintptr gl::frame_stream::push(void const *Data, GLsizeiptr Size)
{
auto const offset{reserve(Size)};
auto const &current{m_slots[m_slot]};
if (current.data != nullptr)
std::memcpy(current.data + offset, Data, static_cast<std::size_t>(Size));
else
glNamedBufferSubData(current.buffer, offset, Size, Data);
return offset;
}
GLintptr gl::frame_stream::reserve(GLsizeiptr Size)
{
auto *current{&m_slots[m_slot]};
auto offset{align_up(m_fill, m_alignment)};
@@ -167,13 +178,8 @@ GLintptr gl::frame_stream::push(void const *Data, GLsizeiptr Size)
glFinish();
++m_waits;
}
current = &m_slots[m_slot];
offset = m_start;
}
if (current->data != nullptr)
std::memcpy(current->data + offset, Data, static_cast<std::size_t>(Size));
else
glNamedBufferSubData(current->buffer, offset, Size, Data);
m_fill = offset + Size;
return offset;
}

View File

@@ -34,6 +34,8 @@ namespace gl
// bigger one (generation() changes, buffer() tells which to bind); the old one stays until the frame is done with, so
// what was written to it can still be bound and drawn from later in the frame
GLintptr push(void const *Data, GLsizeiptr Size);
// the room for Size bytes in the buffer of the frame, as push() makes it, left for the gpu to write (a compute pass)
GLintptr reserve(GLsizeiptr Size);
GLuint buffer() const
{

View File

@@ -506,6 +506,24 @@ namespace gl
const GLuint PARTICLE_OUTPUT_SSBO_BINDING = 12; // what the draw reads, a particle_draw per particle drawn
const GLuint PARTICLE_COMMAND_SSBO_BINDING = 13; // the indirect draw command, whose instances the passes count
// the instances of the timbers of the tracks (opengl46_timbers, timber_instances.comp): work group of the pass and the binding
// points of its buffers, ones of the instance culling, which binds its buffers before every use; the pass binds its own
const GLuint TIMBER_GROUP_SIZE = 64;
const GLuint TIMBER_LOCAL_SSBO_BINDING = 9; // the transforms of the instances of the tracks, relative to the origins of the tracks
const GLuint TIMBER_RANGE_SSBO_BINDING = 11; // the runs of them drawn, a timber_range each
const GLuint TIMBER_OUTPUT_SSBO_BINDING = 12; // the instance buffer of the frame, their modelviews written there
const GLuint TIMBER_ORIGIN_SSBO_BINDING = 13; // the modelviews of the origins of the cells of the runs
// layout std430: GLSL timber_range. a run of instances: count of them from source in the transforms, to target in the output,
// turned by the modelview of origin
struct timber_range
{
uint32_t source;
uint32_t count;
uint32_t target;
uint32_t origin;
};
// layout std430: GLSL smoke_particle_s
struct particle_smoke
{