@@ -721,7 +721,6 @@ Error RenderingDevice::buffer_get_data_async(RID p_buffer, const Callable &p_cal
721721 _check_transfer_worker_buffer (buffer);
722722
723723 BufferGetDataRequest get_data_request;
724- uint32_t flushed_copies = 0 ;
725724 get_data_request.callback = p_callback;
726725 get_data_request.frame_local_index = frames[frame].download_buffer_copy_regions .size ();
727726 get_data_request.size = p_size;
@@ -738,22 +737,26 @@ Error RenderingDevice::buffer_get_data_async(RID p_buffer, const Callable &p_cal
738737 return err;
739738 }
740739
741- if ((get_data_request.frame_local_count > 0 ) && required_action == STAGING_REQUIRED_ACTION_FLUSH_AND_STALL_ALL) {
740+ const bool flush_frames = (get_data_request.frame_local_count > 0 ) && required_action == STAGING_REQUIRED_ACTION_FLUSH_AND_STALL_ALL;
741+ if (flush_frames) {
742742 if (_buffer_make_mutable (buffer, p_buffer)) {
743743 // The buffer must be mutable to be used as a copy source.
744744 draw_graph.add_synchronization ();
745745 }
746746
747- for (uint32_t i = flushed_copies ; i < get_data_request.frame_local_count ; i++) {
747+ for (uint32_t i = 0 ; i < get_data_request.frame_local_count ; i++) {
748748 uint32_t local_index = get_data_request.frame_local_index + i;
749749 draw_graph.add_buffer_get_data (buffer->driver_id , buffer->draw_tracker , frames[frame].download_buffer_staging_buffers [local_index], frames[frame].download_buffer_copy_regions [local_index]);
750750 }
751-
752- flushed_copies = get_data_request.frame_local_count ;
753751 }
754752
755753 _staging_buffer_execute_required_action (download_staging_buffers, required_action);
756754
755+ if (flush_frames) {
756+ get_data_request.frame_local_count = 0 ;
757+ get_data_request.frame_local_index = frames[frame].download_buffer_copy_regions .size ();
758+ }
759+
757760 RDD::BufferCopyRegion region;
758761 region.src_offset = submit_from + p_offset;
759762 region.dst_offset = block_write_offset;
@@ -775,7 +778,7 @@ Error RenderingDevice::buffer_get_data_async(RID p_buffer, const Callable &p_cal
775778 draw_graph.add_synchronization ();
776779 }
777780
778- for (uint32_t i = flushed_copies ; i < get_data_request.frame_local_count ; i++) {
781+ for (uint32_t i = 0 ; i < get_data_request.frame_local_count ; i++) {
779782 uint32_t local_index = get_data_request.frame_local_index + i;
780783 draw_graph.add_buffer_get_data (buffer->driver_id , buffer->draw_tracker , frames[frame].download_buffer_staging_buffers [local_index], frames[frame].download_buffer_copy_regions [local_index]);
781784 }
@@ -2098,7 +2101,6 @@ Error RenderingDevice::texture_get_data_async(RID p_texture, uint32_t p_layer, c
20982101 uint32_t block_write_offset;
20992102 uint32_t block_write_amount;
21002103 StagingRequiredAction required_action;
2101- uint32_t flushed_copies = 0 ;
21022104 for (uint32_t i = 0 ; i < tex->mipmaps ; i++) {
21032105 uint32_t image_total = get_image_format_required_size (tex->format , tex->width , tex->height , tex->depth , i + 1 , &w, &h, &d);
21042106 uint32_t tight_mip_size = image_total - mipmap_offset;
@@ -2119,17 +2121,21 @@ Error RenderingDevice::texture_get_data_async(RID p_texture, uint32_t p_layer, c
21192121 Error err = _staging_buffer_allocate (download_staging_buffers, to_allocate, required_align, block_write_offset, block_write_amount, required_action, false );
21202122 ERR_FAIL_COND_V (err, ERR_CANT_CREATE);
21212123
2122- if ((get_data_request.frame_local_count > 0 ) && required_action == STAGING_REQUIRED_ACTION_FLUSH_AND_STALL_ALL) {
2123- for (uint32_t j = flushed_copies; j < get_data_request.frame_local_count ; j++) {
2124+ const bool flush_frames = (get_data_request.frame_local_count > 0 ) && required_action == STAGING_REQUIRED_ACTION_FLUSH_AND_STALL_ALL;
2125+ if (flush_frames) {
2126+ for (uint32_t j = 0 ; j < get_data_request.frame_local_count ; j++) {
21242127 uint32_t local_index = get_data_request.frame_local_index + j;
21252128 draw_graph.add_texture_get_data (tex->driver_id , tex->draw_tracker , frames[frame].download_texture_staging_buffers [local_index], frames[frame].download_buffer_texture_copy_regions [local_index]);
21262129 }
2127-
2128- flushed_copies = get_data_request.frame_local_count ;
21292130 }
21302131
21312132 _staging_buffer_execute_required_action (download_staging_buffers, required_action);
21322133
2134+ if (flush_frames) {
2135+ get_data_request.frame_local_count = 0 ;
2136+ get_data_request.frame_local_index = frames[frame].download_buffer_texture_copy_regions .size ();
2137+ }
2138+
21332139 RDD::BufferTextureCopyRegion copy_region;
21342140 copy_region.buffer_offset = block_write_offset;
21352141 copy_region.texture_subresources .aspect = tex->read_aspect_flags ;
@@ -2154,12 +2160,11 @@ Error RenderingDevice::texture_get_data_async(RID p_texture, uint32_t p_layer, c
21542160 }
21552161
21562162 if (get_data_request.frame_local_count > 0 ) {
2157- for (uint32_t i = flushed_copies ; i < get_data_request.frame_local_count ; i++) {
2163+ for (uint32_t i = 0 ; i < get_data_request.frame_local_count ; i++) {
21582164 uint32_t local_index = get_data_request.frame_local_index + i;
21592165 draw_graph.add_texture_get_data (tex->driver_id , tex->draw_tracker , frames[frame].download_texture_staging_buffers [local_index], frames[frame].download_buffer_texture_copy_regions [local_index]);
21602166 }
21612167
2162- flushed_copies = get_data_request.frame_local_count ;
21632168 frames[frame].download_texture_get_data_requests .push_back (get_data_request);
21642169 }
21652170
0 commit comments