Skip to content

Commit eb3b217

Browse files
committed
RenderingDevice: Use the correct amount of layers for Cubemaps for boundary checks
1 parent 91eb688 commit eb3b217

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

servers/rendering/rendering_device.cpp

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,11 +1148,7 @@ Error RenderingDevice::_texture_update(RID p_texture, uint32_t p_layer, const Ve
11481148
ERR_FAIL_COND_V_MSG(p_validate_can_update && !(texture->usage_flags & TEXTURE_USAGE_CAN_UPDATE_BIT), ERR_INVALID_PARAMETER,
11491149
"Texture requires the `RenderingDevice.TEXTURE_USAGE_CAN_UPDATE_BIT` to be set to be updatable.");
11501150

1151-
uint32_t layer_count = texture->layers;
1152-
if (texture->type == TEXTURE_TYPE_CUBE || texture->type == TEXTURE_TYPE_CUBE_ARRAY) {
1153-
layer_count *= 6;
1154-
}
1155-
ERR_FAIL_COND_V(p_layer >= layer_count, ERR_INVALID_PARAMETER);
1151+
ERR_FAIL_COND_V(p_layer >= texture->layers, ERR_INVALID_PARAMETER);
11561152

11571153
uint32_t width, height;
11581154
uint32_t tight_mip_size = get_image_format_required_size(texture->format, texture->width, texture->height, texture->depth, texture->mipmaps, &width, &height);
@@ -1584,8 +1580,7 @@ Vector<uint8_t> RenderingDevice::texture_get_data(RID p_texture, uint32_t p_laye
15841580
ERR_FAIL_COND_V_MSG(!(tex->usage_flags & TEXTURE_USAGE_CAN_COPY_FROM_BIT), Vector<uint8_t>(),
15851581
"Texture requires the `RenderingDevice.TEXTURE_USAGE_CAN_COPY_FROM_BIT` to be set to be retrieved.");
15861582

1587-
uint32_t layer_count = tex->layers;
1588-
ERR_FAIL_COND_V(p_layer >= layer_count, Vector<uint8_t>());
1583+
ERR_FAIL_COND_V(p_layer >= tex->layers, Vector<uint8_t>());
15891584

15901585
if ((tex->usage_flags & TEXTURE_USAGE_CPU_READ_BIT)) {
15911586
// Does not need anything fancy, map and read.
@@ -1603,7 +1598,7 @@ Vector<uint8_t> RenderingDevice::texture_get_data(RID p_texture, uint32_t p_laye
16031598
driver->texture_get_copyable_layout(tex->driver_id, subres, &mip_layouts[i]);
16041599

16051600
// Assuming layers are tightly packed. If this is not true on some driver, we must modify the copy algorithm.
1606-
DEV_ASSERT(mip_layouts[i].layer_pitch == mip_layouts[i].size / layer_count);
1601+
DEV_ASSERT(mip_layouts[i].layer_pitch == mip_layouts[i].size / tex->layers);
16071602

16081603
work_buffer_size = STEPIFY(work_buffer_size, work_mip_alignment) + mip_layouts[i].size;
16091604
}
@@ -1748,18 +1743,14 @@ Error RenderingDevice::texture_copy(RID p_from_texture, RID p_to_texture, const
17481743
ERR_FAIL_COND_V_MSG(!(src_tex->usage_flags & TEXTURE_USAGE_CAN_COPY_FROM_BIT), ERR_INVALID_PARAMETER,
17491744
"Source texture requires the `RenderingDevice.TEXTURE_USAGE_CAN_COPY_FROM_BIT` to be set to be retrieved.");
17501745

1751-
uint32_t src_layer_count = src_tex->layers;
17521746
uint32_t src_width, src_height, src_depth;
17531747
get_image_format_required_size(src_tex->format, src_tex->width, src_tex->height, src_tex->depth, p_src_mipmap + 1, &src_width, &src_height, &src_depth);
1754-
if (src_tex->type == TEXTURE_TYPE_CUBE || src_tex->type == TEXTURE_TYPE_CUBE_ARRAY) {
1755-
src_layer_count *= 6;
1756-
}
17571748

17581749
ERR_FAIL_COND_V(p_from.x < 0 || p_from.x + p_size.x > src_width, ERR_INVALID_PARAMETER);
17591750
ERR_FAIL_COND_V(p_from.y < 0 || p_from.y + p_size.y > src_height, ERR_INVALID_PARAMETER);
17601751
ERR_FAIL_COND_V(p_from.z < 0 || p_from.z + p_size.z > src_depth, ERR_INVALID_PARAMETER);
17611752
ERR_FAIL_COND_V(p_src_mipmap >= src_tex->mipmaps, ERR_INVALID_PARAMETER);
1762-
ERR_FAIL_COND_V(p_src_layer >= src_layer_count, ERR_INVALID_PARAMETER);
1753+
ERR_FAIL_COND_V(p_src_layer >= src_tex->layers, ERR_INVALID_PARAMETER);
17631754

17641755
Texture *dst_tex = texture_owner.get_or_null(p_to_texture);
17651756
ERR_FAIL_NULL_V(dst_tex, ERR_INVALID_PARAMETER);
@@ -1769,18 +1760,14 @@ Error RenderingDevice::texture_copy(RID p_from_texture, RID p_to_texture, const
17691760
ERR_FAIL_COND_V_MSG(!(dst_tex->usage_flags & TEXTURE_USAGE_CAN_COPY_TO_BIT), ERR_INVALID_PARAMETER,
17701761
"Destination texture requires the `RenderingDevice.TEXTURE_USAGE_CAN_COPY_TO_BIT` to be set to be retrieved.");
17711762

1772-
uint32_t dst_layer_count = dst_tex->layers;
17731763
uint32_t dst_width, dst_height, dst_depth;
17741764
get_image_format_required_size(dst_tex->format, dst_tex->width, dst_tex->height, dst_tex->depth, p_dst_mipmap + 1, &dst_width, &dst_height, &dst_depth);
1775-
if (dst_tex->type == TEXTURE_TYPE_CUBE || dst_tex->type == TEXTURE_TYPE_CUBE_ARRAY) {
1776-
dst_layer_count *= 6;
1777-
}
17781765

17791766
ERR_FAIL_COND_V(p_to.x < 0 || p_to.x + p_size.x > dst_width, ERR_INVALID_PARAMETER);
17801767
ERR_FAIL_COND_V(p_to.y < 0 || p_to.y + p_size.y > dst_height, ERR_INVALID_PARAMETER);
17811768
ERR_FAIL_COND_V(p_to.z < 0 || p_to.z + p_size.z > dst_depth, ERR_INVALID_PARAMETER);
17821769
ERR_FAIL_COND_V(p_dst_mipmap >= dst_tex->mipmaps, ERR_INVALID_PARAMETER);
1783-
ERR_FAIL_COND_V(p_dst_layer >= dst_layer_count, ERR_INVALID_PARAMETER);
1770+
ERR_FAIL_COND_V(p_dst_layer >= dst_tex->layers, ERR_INVALID_PARAMETER);
17841771

17851772
ERR_FAIL_COND_V_MSG(src_tex->read_aspect_flags != dst_tex->read_aspect_flags, ERR_INVALID_PARAMETER,
17861773
"Source and destination texture must be of the same type (color or depth).");
@@ -1876,13 +1863,8 @@ Error RenderingDevice::texture_clear(RID p_texture, const Color &p_color, uint32
18761863
ERR_FAIL_COND_V_MSG(!(src_tex->usage_flags & TEXTURE_USAGE_CAN_COPY_TO_BIT), ERR_INVALID_PARAMETER,
18771864
"Source texture requires the `RenderingDevice.TEXTURE_USAGE_CAN_COPY_TO_BIT` to be set to be cleared.");
18781865

1879-
uint32_t src_layer_count = src_tex->layers;
1880-
if (src_tex->type == TEXTURE_TYPE_CUBE || src_tex->type == TEXTURE_TYPE_CUBE_ARRAY) {
1881-
src_layer_count *= 6;
1882-
}
1883-
18841866
ERR_FAIL_COND_V(p_base_mipmap + p_mipmaps > src_tex->mipmaps, ERR_INVALID_PARAMETER);
1885-
ERR_FAIL_COND_V(p_base_layer + p_layers > src_layer_count, ERR_INVALID_PARAMETER);
1867+
ERR_FAIL_COND_V(p_base_layer + p_layers > src_tex->layers, ERR_INVALID_PARAMETER);
18861868

18871869
RDD::TextureSubresourceRange range;
18881870
range.aspect = src_tex->read_aspect_flags;

0 commit comments

Comments
 (0)