Skip to content

Commit

Permalink
Merge pull request #90911 from clayjohn/RD-tex-copy
Browse files Browse the repository at this point in the history
Ensure minimum block size is respected when doing GPU to CPU copies of compressed textures
  • Loading branch information
akien-mga committed Apr 23, 2024
2 parents ff9d78c + c52e217 commit 258be6d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions servers/rendering/rendering_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,9 @@ Vector<uint8_t> RenderingDevice::texture_get_data(RID p_texture, uint32_t p_laye
thread_local LocalVector<RDD::BufferTextureCopyRegion> command_buffer_texture_copy_regions_vector;
command_buffer_texture_copy_regions_vector.clear();

uint32_t block_w = 0, block_h = 0;
get_compressed_image_format_block_dimensions(tex->format, block_w, block_h);

uint32_t w = tex->width;
uint32_t h = tex->height;
uint32_t d = tex->depth;
Expand All @@ -1365,8 +1368,8 @@ Vector<uint8_t> RenderingDevice::texture_get_data(RID p_texture, uint32_t p_laye
copy_region.texture_region_size.z = d;
command_buffer_texture_copy_regions_vector.push_back(copy_region);

w = MAX(1u, w >> 1);
h = MAX(1u, h >> 1);
w = MAX(block_w, w >> 1);
h = MAX(block_h, h >> 1);
d = MAX(1u, d >> 1);
}

Expand Down Expand Up @@ -1395,8 +1398,6 @@ Vector<uint8_t> RenderingDevice::texture_get_data(RID p_texture, uint32_t p_laye
for (uint32_t i = 0; i < tex->mipmaps; i++) {
uint32_t width = 0, height = 0, depth = 0;
uint32_t tight_mip_size = get_image_format_required_size(tex->format, w, h, d, 1, &width, &height, &depth);
uint32_t block_w = 0, block_h = 0;
get_compressed_image_format_block_dimensions(tex->format, block_w, block_h);
uint32_t tight_row_pitch = tight_mip_size / ((height / block_h) * depth);

// Copy row-by-row to erase padding due to alignments.
Expand All @@ -1408,8 +1409,8 @@ Vector<uint8_t> RenderingDevice::texture_get_data(RID p_texture, uint32_t p_laye
wp += tight_row_pitch;
}

w = MAX(1u, w >> 1);
h = MAX(1u, h >> 1);
w = MAX(block_w, w >> 1);
h = MAX(block_h, h >> 1);
d = MAX(1u, d >> 1);
read_ptr += mip_layouts[i].size;
write_ptr += tight_mip_size;
Expand Down

0 comments on commit 258be6d

Please sign in to comment.