Merge pull request #50265 from reduz/fix-texture-thread-update

Fix threaded update for textures
This commit is contained in:
Juan Linietsky 2021-07-07 18:26:35 -03:00 committed by GitHub
commit b0822459d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 7 deletions

View file

@ -2032,7 +2032,7 @@ RID RenderingDeviceVulkan::texture_create(const TextureFormat &p_format, const T
if (p_data.size()) { if (p_data.size()) {
for (uint32_t i = 0; i < image_create_info.arrayLayers; i++) { for (uint32_t i = 0; i < image_create_info.arrayLayers; i++) {
texture_update(id, i, p_data[i]); _texture_update(id, i, p_data[i], RD::BARRIER_MASK_ALL, true);
} }
} }
return id; return id;
@ -2279,10 +2279,14 @@ RID RenderingDeviceVulkan::texture_create_shared_from_slice(const TextureView &p
} }
Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, uint32_t p_post_barrier) { Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, uint32_t p_post_barrier) {
return _texture_update(p_texture, p_layer, p_data, p_post_barrier, false);
}
Error RenderingDeviceVulkan::_texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, uint32_t p_post_barrier, bool p_use_setup_queue) {
_THREAD_SAFE_METHOD_ _THREAD_SAFE_METHOD_
ERR_FAIL_COND_V_MSG(draw_list || compute_list, ERR_INVALID_PARAMETER, ERR_FAIL_COND_V_MSG((draw_list || compute_list) && !p_use_setup_queue, ERR_INVALID_PARAMETER,
"Updating textures in is forbidden during creation of a draw or compute list"); "Updating textures is forbidden during creation of a draw or compute list");
Texture *texture = texture_owner.getornull(p_texture); Texture *texture = texture_owner.getornull(p_texture);
ERR_FAIL_COND_V(!texture, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(!texture, ERR_INVALID_PARAMETER);
@ -2323,7 +2327,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con
const uint8_t *r = p_data.ptr(); const uint8_t *r = p_data.ptr();
VkCommandBuffer command_buffer = p_post_barrier ? frames[frame].draw_command_buffer : frames[frame].setup_command_buffer; VkCommandBuffer command_buffer = p_use_setup_queue ? frames[frame].setup_command_buffer : frames[frame].draw_command_buffer;
//barrier to transfer //barrier to transfer
{ {
@ -2376,7 +2380,7 @@ Error RenderingDeviceVulkan::texture_update(RID p_texture, uint32_t p_layer, con
to_allocate >>= get_compressed_image_format_pixel_rshift(texture->format); to_allocate >>= get_compressed_image_format_pixel_rshift(texture->format);
uint32_t alloc_offset, alloc_size; uint32_t alloc_offset, alloc_size;
Error err = _staging_buffer_allocate(to_allocate, required_align, alloc_offset, alloc_size, false, p_post_barrier); Error err = _staging_buffer_allocate(to_allocate, required_align, alloc_offset, alloc_size, false, !p_use_setup_queue);
ERR_FAIL_COND_V(err, ERR_CANT_CREATE); ERR_FAIL_COND_V(err, ERR_CANT_CREATE);
uint8_t *write_ptr; uint8_t *write_ptr;

View file

@ -156,6 +156,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
uint32_t texture_upload_region_size_px = 0; uint32_t texture_upload_region_size_px = 0;
Vector<uint8_t> _texture_get_data_from_image(Texture *tex, VkImage p_image, VmaAllocation p_allocation, uint32_t p_layer, bool p_2d = false); Vector<uint8_t> _texture_get_data_from_image(Texture *tex, VkImage p_image, VmaAllocation p_allocation, uint32_t p_layer, bool p_2d = false);
Error _texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, uint32_t p_post_barrier, bool p_use_setup_queue);
/*****************/ /*****************/
/**** SAMPLER ****/ /**** SAMPLER ****/

View file

@ -1602,8 +1602,6 @@ void RendererStorageRD::material_set_param(RID p_material, const StringName &p_p
} else { } else {
_material_queue_update(material, true, true); _material_queue_update(material, true, true);
} }
print_line("set parameter: " + String(p_param));
} }
Variant RendererStorageRD::material_get_param(RID p_material, const StringName &p_param) const { Variant RendererStorageRD::material_get_param(RID p_material, const StringName &p_param) const {