refactor because of DX11
This commit is contained in:
parent
c1a69995e4
commit
9b8e87ce00
4 changed files with 38 additions and 52 deletions
|
@ -41,22 +41,22 @@ struct Cluster {
|
|||
int probes_count;
|
||||
};
|
||||
|
||||
layout(std430, binding = 0) buffer lights
|
||||
layout(std430, binding = 6) buffer lights
|
||||
{
|
||||
Light b_lights[];
|
||||
};
|
||||
|
||||
layout(std430, binding = 1) buffer clusters
|
||||
layout(std430, binding = 7) buffer clusters
|
||||
{
|
||||
Cluster b_clusters[];
|
||||
};
|
||||
|
||||
layout(std430, binding = 2) buffer cluster_maps
|
||||
layout(std430, binding = 8) buffer cluster_maps
|
||||
{
|
||||
int b_cluster_map[];
|
||||
};
|
||||
|
||||
layout(std430, binding = 3) buffer probes
|
||||
layout(std430, binding = 9) buffer probes
|
||||
{
|
||||
Probe b_probes[];
|
||||
};
|
||||
|
|
|
@ -883,12 +883,12 @@ void bindTextures(const TextureHandle* handles, u32 offset, u32 count)
|
|||
CHECK_GL(glBindTextures(offset, count, gl_handles));
|
||||
}
|
||||
|
||||
void bindShaderBuffer(BufferHandle buffer, u32 binding_idx, u32 offset, u32 size)
|
||||
void bindShaderBuffer(BufferHandle handle, u32 binding_idx)
|
||||
{
|
||||
checkThread();
|
||||
if(buffer.isValid()) {
|
||||
const GLuint gl_handle = g_gpu.buffers[buffer.value].handle;
|
||||
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, binding_idx, gl_handle, offset, size);
|
||||
if(handle.isValid()) {
|
||||
const Buffer& buffer = g_gpu.buffers[handle.value];
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, binding_idx, buffer.handle);
|
||||
}
|
||||
else {
|
||||
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, binding_idx, 0, 0, 0);
|
||||
|
|
|
@ -238,7 +238,7 @@ QueryHandle createQuery();
|
|||
|
||||
void bindVertexBuffer(u32 binding_idx, BufferHandle buffer, u32 buffer_offset, u32 stride_offset);
|
||||
void bindTextures(const TextureHandle* handles, u32 offset, u32 count);
|
||||
void bindShaderBuffer(BufferHandle buffer, u32 binding_point, u32 offset, u32 size);
|
||||
void bindShaderBuffer(BufferHandle buffer, u32 binding_point);
|
||||
void update(BufferHandle buffer, const void* data, size_t size);
|
||||
void update(BufferGroupHandle group, const void* data, size_t element_index);
|
||||
void* map(BufferHandle buffer, size_t size);
|
||||
|
|
|
@ -2387,49 +2387,27 @@ struct PipelineImpl final : Pipeline
|
|||
|
||||
void execute() override {
|
||||
PROFILE_FUNCTION();
|
||||
const u32 map_size = ((m_map.byte_size() + 15) & ~15);
|
||||
const u32 clusters_size = ((m_clusters.byte_size() + 15) & ~15);
|
||||
const u32 lights_size = ((m_point_lights.byte_size() + 15) & ~15);
|
||||
const u32 probes_size = ((m_probes.byte_size() + 15) & ~15);
|
||||
const u32 total_size = map_size + lights_size + clusters_size + probes_size;
|
||||
|
||||
if (m_pipeline->m_clusters_buffer_size < total_size) {
|
||||
if (m_pipeline->m_clusters_buffer.isValid()) gpu::destroy(m_pipeline->m_clusters_buffer);
|
||||
m_pipeline->m_clusters_buffer = gpu::allocBufferHandle();
|
||||
gpu::createBuffer(m_pipeline->m_clusters_buffer, 0, total_size, nullptr);
|
||||
m_pipeline->m_clusters_buffer_size = total_size;
|
||||
}
|
||||
auto bind = [](auto& buffer, const auto& data, i32 idx){
|
||||
const u32 capacity = (data.byte_size() + 15) & ~15;
|
||||
if (buffer.capacity < capacity) {
|
||||
if (buffer.buffer.isValid()) gpu::destroy(buffer.buffer);
|
||||
buffer.buffer = gpu::allocBufferHandle();
|
||||
gpu::createBuffer(buffer.buffer, (u32)gpu::BufferFlags::SHADER_BUFFER, capacity, nullptr);
|
||||
buffer.capacity = capacity;
|
||||
}
|
||||
if (!data.empty()) {
|
||||
u8* mem = (u8*)gpu::map(buffer.buffer, capacity);
|
||||
memcpy(mem, data.begin(), data.byte_size());
|
||||
gpu::unmap(buffer.buffer);
|
||||
gpu::bindShaderBuffer(buffer.buffer, idx);
|
||||
}
|
||||
};
|
||||
|
||||
u8* mem = (u8*)gpu::map(m_pipeline->m_clusters_buffer, total_size);
|
||||
if (!m_clusters.empty()) {
|
||||
memcpy(mem, m_clusters.begin(), m_clusters.byte_size());
|
||||
mem += clusters_size;
|
||||
}
|
||||
if (!m_map.empty()) {
|
||||
memcpy(mem, m_map.begin(), m_map.byte_size());
|
||||
mem += map_size;
|
||||
}
|
||||
if (!m_point_lights.empty()) {
|
||||
memcpy(mem, m_point_lights.begin(), m_point_lights.byte_size());
|
||||
mem += lights_size;
|
||||
}
|
||||
if (!m_probes.empty()) {
|
||||
memcpy(mem, m_probes.begin(), m_probes.byte_size());
|
||||
}
|
||||
gpu::unmap(m_pipeline->m_clusters_buffer);
|
||||
|
||||
if (lights_size > 0) {
|
||||
gpu::bindShaderBuffer(m_pipeline->m_clusters_buffer, 0, clusters_size + map_size, lights_size);
|
||||
}
|
||||
if (clusters_size > 0) {
|
||||
gpu::bindShaderBuffer(m_pipeline->m_clusters_buffer, 1, 0, clusters_size);
|
||||
}
|
||||
if (map_size > 0) {
|
||||
gpu::bindShaderBuffer(m_pipeline->m_clusters_buffer, 2, clusters_size, map_size);
|
||||
}
|
||||
if (probes_size > 0) {
|
||||
gpu::bindShaderBuffer(m_pipeline->m_clusters_buffer, 3, clusters_size + map_size + lights_size, probes_size);
|
||||
}
|
||||
bind(m_pipeline->m_cluster_buffers.lights, m_point_lights, 6);
|
||||
bind(m_pipeline->m_cluster_buffers.clusters, m_clusters, 7);
|
||||
bind(m_pipeline->m_cluster_buffers.maps, m_map, 8);
|
||||
bind(m_pipeline->m_cluster_buffers.probes, m_probes, 9);
|
||||
}
|
||||
|
||||
|
||||
|
@ -3887,8 +3865,16 @@ struct PipelineImpl final : Pipeline
|
|||
gpu::BufferHandle m_cube_vb;
|
||||
gpu::BufferHandle m_cube_ib;
|
||||
gpu::BufferHandle m_drawcall_ub = gpu::INVALID_BUFFER;
|
||||
gpu::BufferHandle m_clusters_buffer = gpu::INVALID_BUFFER;
|
||||
u32 m_clusters_buffer_size = 0;
|
||||
struct {
|
||||
struct Buffer {
|
||||
gpu::BufferHandle buffer = gpu::INVALID_BUFFER;
|
||||
u32 capacity = 0;
|
||||
};
|
||||
Buffer lights;
|
||||
Buffer clusters;
|
||||
Buffer maps;
|
||||
Buffer probes;
|
||||
} m_cluster_buffers;
|
||||
CameraParams m_shadow_camera_params[4];
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue