3.7.2,创建Image.format=RGBA32F的Texture2d对象时,ios端CCMTLTexture::doInit会报错

this.forceField = new Float32Array(2000 * 4);
this.forceField.fill(0);
const forceimage = new ImageAsset();
forceimage.reset({
    _data: this.forceField,
    width: 2000,
    height: 1,
    format: Texture2D.PixelFormat.RGBA32F,
    _compressed: false
});

this.forceTex = new Texture2D();
this.forceTex.reset({
    width: 2000,
    height: 1
});
this.forceTex.setFilters(Texture2D.Filter.NONE, Texture2D.Filter.NONE);
this.forceTex.image = forceimage;

image

_validateTextureView:557: failed assertion `Texture View Validation

texture usage (0x03) doesn’t specify MTLTextureUsagePixelFormatView (0x10)

dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/usr/lib/libMTLCapture.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib

_validateTextureView:557: failed assertion `Texture View Validation

texture usage (0x03) doesn’t specify MTLTextureUsagePixelFormatView (0x10)

image

给点反馈啊谢谢:pray:

RGBA32F 压缩纹理格式的内存计算公式为:width * height * depth * 16。
通常 depth 为 1

呢么,我需要改什么东西,才能让他在ios上跑通呢?因为小游戏端,安卓端都是正常的

image
游戏需要在风扇位置施加一个风力,风力是通过32f的纹理数据传进shader的。

经过漫长的时间,我终于找到了这个问题的答案:
image
在run里关掉这个选项

@dumganhar
@minggo

感谢你的研究节省了大量时间,3.8.2 依然存在此问题,导致项目根本无法正常运行。

@531854115
代码使用的是 Texture,为啥会走到 TextureView 的初始化呢?上面的代码和截图对不上啊。

@SmallMain 你也是一样的用法重现的一样的问题?

应该是内部组件调用到的,我们看一下。

@minggo

我试过将 onLoadstart 的所有代码注释,这会使游戏只停留在首场景,首场景只有一些图片和文字。

我没有做过 new Texture2D 的操作,类似的操作只有 SpriteFrame.createWithImage(result.value!)

也是一样的错误吗?

@531854115 你的错误是因为 Texture 和 Image 的 pixel format 不一致导致的。改成一致就可以了。在 metal,如果要支持格式不一致的话,那么在创建 texture 时就得传入特殊的 usage 字段。 目前引擎没有对外暴露 Texture View 的接口,没法做。

后续引擎会在内部判断要求格式一致,让错误明显些。

17:57:09 [ERROR]: [ERROR] file /Applications/Cocos/Creator/3.8.2/CocosCreator.app/Contents/Resources/resources/3d/engine/native/cocos/renderer/gfx-metal/MTLBuffer.mm: line 64 
17:57:09 [ERROR]: CCMTLBuffer:: Illegal index buffer stride.
_validateTextureView:685: failed assertion `Texture View Validation
texture usage (0x07) doesn't specify MTLTextureUsagePixelFormatView (0x10)
'

你这是有两个问题了。一个是 buffer 的 stride 设置不对。一个才是和这个帖子想过的 pixel format 的问题。

pixel format 的问题你有可重现的代码吗?我也有修复了想关 bug 的 PR。你可以试试。

至于 buffer stride 的错误需要你给更详细的信息才好定位是哪里的问题。

pixel format 没有遇到,buffer stride 的问题现在我删除了一些项目里的代码,创建了一个复现工程,仅在首场景几乎什么也没执行就复现了该问题。

由于工程内还有部分代码不想公开,我应该如何把工程文件发给你呢?

@minggo

你可以私信给我。

你贴的这个错误就如我上面说的,image 和 texture 的 format 不一致。把,代码改成

this.forceTex.reset({
    width: 2000,
    height: 1,
    format: PixelFormat.RGBA32F
});