Skip to content

Commit ebe2b44

Browse files
committed
Merge pull request #108940 from DarioSamo/transfer-alignment-lcm
Compute texture alignment for transfers using the LCM instead.
2 parents 73d3d2f + 4af0734 commit ebe2b44

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

servers/rendering/rendering_device.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,13 +1391,33 @@ uint32_t RenderingDevice::_texture_layer_count(Texture *p_texture) const {
13911391
}
13921392
}
13931393

1394+
uint32_t greatest_common_denominator(uint32_t a, uint32_t b) {
1395+
// Euclidean algorithm.
1396+
uint32_t t;
1397+
while (b != 0) {
1398+
t = b;
1399+
b = a % b;
1400+
a = t;
1401+
}
1402+
1403+
return a;
1404+
}
1405+
1406+
uint32_t least_common_multiple(uint32_t a, uint32_t b) {
1407+
if (a == 0 || b == 0) {
1408+
return 0;
1409+
}
1410+
1411+
return (a / greatest_common_denominator(a, b)) * b;
1412+
}
1413+
13941414
uint32_t RenderingDevice::_texture_alignment(Texture *p_texture) const {
13951415
uint32_t alignment = get_compressed_image_format_block_byte_size(p_texture->format);
13961416
if (alignment == 1) {
13971417
alignment = get_image_format_pixel_size(p_texture->format);
13981418
}
13991419

1400-
return STEPIFY(alignment, driver->api_trait_get(RDD::API_TRAIT_TEXTURE_TRANSFER_ALIGNMENT));
1420+
return least_common_multiple(alignment, driver->api_trait_get(RDD::API_TRAIT_TEXTURE_TRANSFER_ALIGNMENT));
14011421
}
14021422

14031423
Error RenderingDevice::_texture_initialize(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, bool p_immediate_flush) {

0 commit comments

Comments
 (0)