Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize shared texture creations #98760

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions servers/rendering/rendering_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ RID RenderingDevice::texture_create_shared(const TextureView &p_view, RID p_with

// Create view.

Texture texture = *src_texture;
Texture texture = src_texture->duplicate_as_shared_texture();
texture.shared_fallback = nullptr;
Comment on lines +906 to 907
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess duplicate_as_shared_resource should also avoid copying shared_fallback so we don't have to manually set it to nullptr right after doing the copy


RDD::TextureView tv;
Expand Down Expand Up @@ -960,8 +960,6 @@ RID RenderingDevice::texture_create_shared(const TextureView &p_view, RID p_with

ERR_FAIL_COND_V(!texture.driver_id, RID());

texture.slice_trackers.clear();

if (texture.draw_tracker != nullptr) {
texture.draw_tracker->reference_count++;
}
Expand Down Expand Up @@ -1055,7 +1053,7 @@ RID RenderingDevice::texture_create_shared_from_slice(const TextureView &p_view,
slice_layers = 6;
}

Texture texture = *src_texture;
Texture texture = src_texture->duplicate_as_shared_texture();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it a bit surprising that we don't call texture.slice_trackers.clear(); here.

CC @DarioSamo who added the call in texture_create_shared(). Do you think this was missed by mistake? Or is there a reason to maintain the slice_tracker when creating a shared texture from a slice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clear is made in _texture_make_mutable

texture.shared_fallback = nullptr;

get_image_format_required_size(texture.format, texture.width, texture.height, texture.depth, p_mipmap + 1, &texture.width, &texture.height);
Expand Down
35 changes: 35 additions & 0 deletions servers/rendering/rendering_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,41 @@ class RenderingDevice : public RenderingDeviceCommons {
int32_t transfer_worker_index = -1;
uint64_t transfer_worker_operation = 0;

Texture duplicate_as_shared_texture() const {
Texture texture;
texture.driver_id = driver_id;
texture.type = type;
texture.format = format;
texture.samples = samples;
texture.slice_type = slice_type;
texture.slice_rect = slice_rect;
texture.width = width;
texture.height = height;
texture.depth = depth;
texture.layers = layers;
texture.mipmaps = mipmaps;
texture.usage_flags = usage_flags;
texture.base_mipmap = base_mipmap;
texture.base_layer = base_layer;

texture.allowed_shared_formats = allowed_shared_formats;

texture.is_resolve_buffer = is_resolve_buffer;
texture.has_initial_data = has_initial_data;

texture.read_aspect_flags = read_aspect_flags;
texture.barrier_aspect_flags = barrier_aspect_flags;
texture.bound = bound;
texture.owner = owner;

texture.draw_tracker = draw_tracker;
// `slice_trackers` is only used by the owner and it can be expensive to copy.
texture.shared_fallback = shared_fallback;
texture.transfer_worker_index = transfer_worker_index;
texture.transfer_worker_operation = transfer_worker_operation;
return texture;
}

RDD::TextureSubresourceRange barrier_range() const {
RDD::TextureSubresourceRange r;
r.aspect = barrier_aspect_flags;
Expand Down
Loading