mirror of
https://github.com/godotengine/godot.git
synced 2025-04-25 01:48:08 +08:00
Fix invalid buffer updates in SDFGI
This commit is contained in:
parent
ff48a6a3bc
commit
dd0b097e44
@ -3488,6 +3488,10 @@ RID RenderingDeviceVulkan::vertex_buffer_create(uint32_t p_size_bytes, const Vec
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
ERR_FAIL_COND_V(p_data.size() && (uint32_t)p_data.size() != p_size_bytes, RID());
|
||||
ERR_FAIL_COND_V_MSG(draw_list != nullptr && p_data.size(), RID(),
|
||||
"Creating buffers with data is forbidden during creation of a draw list");
|
||||
ERR_FAIL_COND_V_MSG(compute_list != nullptr && p_data.size(), RID(),
|
||||
"Creating buffers with data is forbidden during creation of a draw list");
|
||||
|
||||
Buffer buffer;
|
||||
_buffer_allocate(&buffer, p_size_bytes, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VMA_MEMORY_USAGE_GPU_ONLY);
|
||||
@ -3611,6 +3615,10 @@ RID RenderingDeviceVulkan::vertex_array_create(uint32_t p_vertex_count, VertexFo
|
||||
|
||||
RID RenderingDeviceVulkan::index_buffer_create(uint32_t p_index_count, IndexBufferFormat p_format, const Vector<uint8_t> &p_data, bool p_use_restart_indices) {
|
||||
_THREAD_SAFE_METHOD_
|
||||
ERR_FAIL_COND_V_MSG(draw_list != nullptr && p_data.size(), RID(),
|
||||
"Creating buffers with data is forbidden during creation of a draw list");
|
||||
ERR_FAIL_COND_V_MSG(compute_list != nullptr && p_data.size(), RID(),
|
||||
"Creating buffers with data is forbidden during creation of a draw list");
|
||||
|
||||
ERR_FAIL_COND_V(p_index_count == 0, RID());
|
||||
|
||||
@ -4357,6 +4365,10 @@ RID RenderingDeviceVulkan::uniform_buffer_create(uint32_t p_size_bytes, const Ve
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
ERR_FAIL_COND_V(p_data.size() && (uint32_t)p_data.size() != p_size_bytes, RID());
|
||||
ERR_FAIL_COND_V_MSG(draw_list != nullptr && p_data.size(), RID(),
|
||||
"Creating buffers with data is forbidden during creation of a draw list");
|
||||
ERR_FAIL_COND_V_MSG(compute_list != nullptr && p_data.size(), RID(),
|
||||
"Creating buffers with data is forbidden during creation of a draw list");
|
||||
|
||||
Buffer buffer;
|
||||
Error err = _buffer_allocate(&buffer, p_size_bytes, VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_GPU_ONLY);
|
||||
@ -4372,6 +4384,10 @@ RID RenderingDeviceVulkan::uniform_buffer_create(uint32_t p_size_bytes, const Ve
|
||||
|
||||
RID RenderingDeviceVulkan::storage_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data, uint32_t p_usage) {
|
||||
_THREAD_SAFE_METHOD_
|
||||
ERR_FAIL_COND_V_MSG(draw_list != nullptr && p_data.size(), RID(),
|
||||
"Creating buffers with data is forbidden during creation of a draw list");
|
||||
ERR_FAIL_COND_V_MSG(compute_list != nullptr && p_data.size(), RID(),
|
||||
"Creating buffers with data is forbidden during creation of a draw list");
|
||||
|
||||
ERR_FAIL_COND_V(p_data.size() && (uint32_t)p_data.size() != p_size_bytes, RID());
|
||||
|
||||
@ -4395,6 +4411,10 @@ RID RenderingDeviceVulkan::storage_buffer_create(uint32_t p_size_bytes, const Ve
|
||||
|
||||
RID RenderingDeviceVulkan::texture_buffer_create(uint32_t p_size_elements, DataFormat p_format, const Vector<uint8_t> &p_data) {
|
||||
_THREAD_SAFE_METHOD_
|
||||
ERR_FAIL_COND_V_MSG(draw_list != nullptr && p_data.size(), RID(),
|
||||
"Creating buffers with data is forbidden during creation of a draw list");
|
||||
ERR_FAIL_COND_V_MSG(compute_list != nullptr && p_data.size(), RID(),
|
||||
"Creating buffers with data is forbidden during creation of a draw list");
|
||||
|
||||
uint32_t element_size = get_format_vertex_size(p_format);
|
||||
ERR_FAIL_COND_V_MSG(element_size == 0, RID(), "Format requested is not supported for texture buffers");
|
||||
@ -4984,6 +5004,8 @@ Error RenderingDeviceVulkan::buffer_update(RID p_buffer, uint32_t p_offset, uint
|
||||
|
||||
ERR_FAIL_COND_V_MSG(draw_list && p_sync_with_draw, ERR_INVALID_PARAMETER,
|
||||
"Updating buffers in 'sync to draw' mode is forbidden during creation of a draw list");
|
||||
ERR_FAIL_COND_V_MSG(compute_list && p_sync_with_draw, ERR_INVALID_PARAMETER,
|
||||
"Updating buffers in 'sync to draw' mode is forbidden during creation of a compute list");
|
||||
|
||||
// Protect subsequent updates...
|
||||
VkPipelineStageFlags dst_stage_mask = VK_PIPELINE_STAGE_TRANSFER_BIT;
|
||||
|
@ -1173,27 +1173,11 @@ void RasterizerSceneRD::sdfgi_update_probes(RID p_render_buffers, RID p_environm
|
||||
/* Update dynamic lights */
|
||||
|
||||
{
|
||||
RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
|
||||
RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, sdfgi_shader.direct_light_pipeline[SDGIShader::DIRECT_LIGHT_MODE_DYNAMIC]);
|
||||
|
||||
SDGIShader::DirectLightPushConstant push_constant;
|
||||
|
||||
push_constant.grid_size[0] = rb->sdfgi->cascade_size;
|
||||
push_constant.grid_size[1] = rb->sdfgi->cascade_size;
|
||||
push_constant.grid_size[2] = rb->sdfgi->cascade_size;
|
||||
push_constant.max_cascades = rb->sdfgi->cascades.size();
|
||||
push_constant.probe_axis_size = rb->sdfgi->probe_axis_count;
|
||||
push_constant.multibounce = rb->sdfgi->uses_multibounce;
|
||||
push_constant.y_mult = rb->sdfgi->y_mult;
|
||||
|
||||
push_constant.process_offset = 0;
|
||||
push_constant.process_increment = 1;
|
||||
int32_t cascade_light_count[SDFGI::MAX_CASCADES];
|
||||
|
||||
for (uint32_t i = 0; i < rb->sdfgi->cascades.size(); i++) {
|
||||
SDFGI::Cascade &cascade = rb->sdfgi->cascades[i];
|
||||
|
||||
{ //fill light buffer
|
||||
|
||||
SDGIShader::Light lights[SDFGI::MAX_DYNAMIC_LIGHTS];
|
||||
uint32_t idx = 0;
|
||||
for (uint32_t j = 0; j < p_directional_light_count; j++) {
|
||||
@ -1273,9 +1257,29 @@ void RasterizerSceneRD::sdfgi_update_probes(RID p_render_buffers, RID p_environm
|
||||
if (idx > 0) {
|
||||
RD::get_singleton()->buffer_update(cascade.lights_buffer, 0, idx * sizeof(SDGIShader::Light), lights, true);
|
||||
}
|
||||
push_constant.light_count = idx;
|
||||
|
||||
cascade_light_count[i] = idx;
|
||||
}
|
||||
|
||||
RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
|
||||
RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, sdfgi_shader.direct_light_pipeline[SDGIShader::DIRECT_LIGHT_MODE_DYNAMIC]);
|
||||
|
||||
SDGIShader::DirectLightPushConstant push_constant;
|
||||
|
||||
push_constant.grid_size[0] = rb->sdfgi->cascade_size;
|
||||
push_constant.grid_size[1] = rb->sdfgi->cascade_size;
|
||||
push_constant.grid_size[2] = rb->sdfgi->cascade_size;
|
||||
push_constant.max_cascades = rb->sdfgi->cascades.size();
|
||||
push_constant.probe_axis_size = rb->sdfgi->probe_axis_count;
|
||||
push_constant.multibounce = rb->sdfgi->uses_multibounce;
|
||||
push_constant.y_mult = rb->sdfgi->y_mult;
|
||||
|
||||
push_constant.process_offset = 0;
|
||||
push_constant.process_increment = 1;
|
||||
|
||||
for (uint32_t i = 0; i < rb->sdfgi->cascades.size(); i++) {
|
||||
SDFGI::Cascade &cascade = rb->sdfgi->cascades[i];
|
||||
push_constant.light_count = cascade_light_count[i];
|
||||
push_constant.cascade = i;
|
||||
|
||||
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, cascade.sdf_direct_light_uniform_set, 0);
|
||||
@ -7236,8 +7240,9 @@ void RasterizerSceneRD::render_sdfgi(RID p_render_buffers, int p_region, Instanc
|
||||
push_constant.grid_size = rb->sdfgi->cascade_size;
|
||||
push_constant.cascade = cascade;
|
||||
|
||||
RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
|
||||
if (rb->sdfgi->cascades[cascade].dirty_regions != SDFGI::Cascade::DIRTY_ALL) {
|
||||
RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
|
||||
|
||||
//must pre scroll existing data because not all is dirty
|
||||
RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, sdfgi_shader.preprocess_pipeline[SDGIShader::PRE_PROCESS_SCROLL]);
|
||||
RD::get_singleton()->compute_list_bind_uniform_set(compute_list, rb->sdfgi->cascades[cascade].scroll_uniform_set, 0);
|
||||
@ -7311,13 +7316,15 @@ void RasterizerSceneRD::render_sdfgi(RID p_render_buffers, int p_region, Instanc
|
||||
}
|
||||
|
||||
//ok finally barrier
|
||||
RD::get_singleton()->compute_list_add_barrier(compute_list);
|
||||
RD::get_singleton()->compute_list_end();
|
||||
}
|
||||
|
||||
//clear dispatch indirect data
|
||||
uint32_t dispatch_indirct_data[4] = { 0, 0, 0, 0 };
|
||||
RD::get_singleton()->buffer_update(rb->sdfgi->cascades[cascade].solid_cell_dispatch_buffer, 0, sizeof(uint32_t) * 4, dispatch_indirct_data, true);
|
||||
|
||||
RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
|
||||
|
||||
bool half_size = true; //much faster, very little difference
|
||||
static const int optimized_jf_group_size = 8;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user