Renderer: Fix Metal handling of cube textures; assert equal dimensions
This commit is contained in:
parent
fdbf6ecc9f
commit
e2066298d9
@ -405,6 +405,15 @@ RDD::TextureID RenderingDeviceDriverMetal::texture_create_from_extension(uint64_
|
|||||||
RDD::TextureID RenderingDeviceDriverMetal::texture_create_shared(TextureID p_original_texture, const TextureView &p_view) {
|
RDD::TextureID RenderingDeviceDriverMetal::texture_create_shared(TextureID p_original_texture, const TextureView &p_view) {
|
||||||
id<MTLTexture> src_texture = rid::get(p_original_texture);
|
id<MTLTexture> src_texture = rid::get(p_original_texture);
|
||||||
|
|
||||||
|
NSUInteger slices = src_texture.arrayLength;
|
||||||
|
if (src_texture.textureType == MTLTextureTypeCube) {
|
||||||
|
// Metal expects Cube textures to have a slice count of 6.
|
||||||
|
slices = 6;
|
||||||
|
} else if (src_texture.textureType == MTLTextureTypeCubeArray) {
|
||||||
|
// Metal expects Cube Array textures to have 6 slices per layer.
|
||||||
|
slices *= 6;
|
||||||
|
}
|
||||||
|
|
||||||
#if DEV_ENABLED
|
#if DEV_ENABLED
|
||||||
if (src_texture.sampleCount > 1) {
|
if (src_texture.sampleCount > 1) {
|
||||||
// TODO(sgc): is it ok to create a shared texture from a multi-sample texture?
|
// TODO(sgc): is it ok to create a shared texture from a multi-sample texture?
|
||||||
@ -434,7 +443,7 @@ RDD::TextureID RenderingDeviceDriverMetal::texture_create_shared(TextureID p_ori
|
|||||||
id<MTLTexture> obj = [src_texture newTextureViewWithPixelFormat:format
|
id<MTLTexture> obj = [src_texture newTextureViewWithPixelFormat:format
|
||||||
textureType:src_texture.textureType
|
textureType:src_texture.textureType
|
||||||
levels:NSMakeRange(0, src_texture.mipmapLevelCount)
|
levels:NSMakeRange(0, src_texture.mipmapLevelCount)
|
||||||
slices:NSMakeRange(0, src_texture.arrayLength)
|
slices:NSMakeRange(0, slices)
|
||||||
swizzle:swizzle];
|
swizzle:swizzle];
|
||||||
ERR_FAIL_NULL_V_MSG(obj, TextureID(), "Unable to create shared texture");
|
ERR_FAIL_NULL_V_MSG(obj, TextureID(), "Unable to create shared texture");
|
||||||
return rid::make(obj);
|
return rid::make(obj);
|
||||||
@ -566,7 +575,14 @@ void RenderingDeviceDriverMetal::texture_get_copyable_layout(TextureID p_texture
|
|||||||
r_layout->size = get_image_format_required_size(format, sz.width, sz.height, sz.depth, 1, &sbw, &sbh);
|
r_layout->size = get_image_format_required_size(format, sz.width, sz.height, sz.depth, 1, &sbw, &sbh);
|
||||||
r_layout->row_pitch = r_layout->size / ((sbh / bh) * sz.depth);
|
r_layout->row_pitch = r_layout->size / ((sbh / bh) * sz.depth);
|
||||||
r_layout->depth_pitch = r_layout->size / sz.depth;
|
r_layout->depth_pitch = r_layout->size / sz.depth;
|
||||||
r_layout->layer_pitch = r_layout->size / obj.arrayLength;
|
|
||||||
|
uint32_t array_length = obj.arrayLength;
|
||||||
|
if (obj.textureType == MTLTextureTypeCube) {
|
||||||
|
array_length = 6;
|
||||||
|
} else if (obj.textureType == MTLTextureTypeCubeArray) {
|
||||||
|
array_length *= 6;
|
||||||
|
}
|
||||||
|
r_layout->layer_pitch = r_layout->size / array_length;
|
||||||
} else {
|
} else {
|
||||||
CRASH_NOW_MSG("need to calculate layout for shared texture");
|
CRASH_NOW_MSG("need to calculate layout for shared texture");
|
||||||
}
|
}
|
||||||
|
@ -912,6 +912,8 @@ RID RenderingDevice::texture_create(const TextureFormat &p_format, const Texture
|
|||||||
"Number of layers must be equal or greater than 1 for arrays and cubemaps.");
|
"Number of layers must be equal or greater than 1 for arrays and cubemaps.");
|
||||||
ERR_FAIL_COND_V_MSG((format.texture_type == TEXTURE_TYPE_CUBE_ARRAY || format.texture_type == TEXTURE_TYPE_CUBE) && (format.array_layers % 6) != 0, RID(),
|
ERR_FAIL_COND_V_MSG((format.texture_type == TEXTURE_TYPE_CUBE_ARRAY || format.texture_type == TEXTURE_TYPE_CUBE) && (format.array_layers % 6) != 0, RID(),
|
||||||
"Cubemap and cubemap array textures must provide a layer number that is multiple of 6");
|
"Cubemap and cubemap array textures must provide a layer number that is multiple of 6");
|
||||||
|
ERR_FAIL_COND_V_MSG(((format.texture_type == TEXTURE_TYPE_CUBE_ARRAY || format.texture_type == TEXTURE_TYPE_CUBE)) && (format.width != format.height), RID(),
|
||||||
|
"Cubemap and cubemap array textures must have equal width and height.");
|
||||||
ERR_FAIL_COND_V_MSG(format.array_layers > driver->limit_get(LIMIT_MAX_TEXTURE_ARRAY_LAYERS), RID(), "Number of layers exceeds device maximum.");
|
ERR_FAIL_COND_V_MSG(format.array_layers > driver->limit_get(LIMIT_MAX_TEXTURE_ARRAY_LAYERS), RID(), "Number of layers exceeds device maximum.");
|
||||||
} else {
|
} else {
|
||||||
format.array_layers = 1;
|
format.array_layers = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user