[2.2] Metal iOS issues Topic is solved

Design / architecture / roadmap discussions related to future of Ogre3D (version 2.0 and above)
Post Reply
rujialiu
Gremlin
Posts: 180
Joined: Mon May 09, 2016 8:21 am
x 12

[2.2] Metal iOS issues

Post by rujialiu » Sun Jan 13, 2019 12:14 pm

Hi!

We're recently upgrading our iOS build to Ogre 2.2 (from 2.1). Our windows build is already working, but for iOS there are some unique problems. The first one is that the are some extra files in Hlms Pbs's folder: BRDF*, BlendModes*, DetailMaps*, IrradianceVolume*, Structs*. They need to be removed, otherwise we'll get errors like

Code: Select all

Error at line 1: @piece 'PassStructDecl' already defined
Then, using per-pixel reflections will get this error:

Code: Select all

-[MTLDebugBlitCommandEncoder validateCopyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:toTexture:destinationSlice:destinationLevel:destinationOrigin:options:]:239: failed assertion `destinationSlice(4) must be < (4).'
Triggered from code OgreMetalTextureGpu.mm line 252:

Code: Select all

        __unsafe_unretained id<MTLBlitCommandEncoder> blitEncoder = device->getBlitEncoder();
        for( uint32 slice=0; slice<numSlices; ++slice )
        {
            [blitEncoder copyFromTexture:srcTextureName
                             sourceSlice:srcBox.sliceStart + this->getInternalSliceStart() + slice
                             sourceLevel:srcMipLevel
                            sourceOrigin:MTLOriginMake( srcBox.x, srcBox.y, srcBox.z )
                              sourceSize:MTLSizeMake( srcBox.width, srcBox.height, srcBox.depth )
                               toTexture:dstTextureName
                        destinationSlice:dstBox.sliceStart + dstMetal->getInternalSliceStart() + slice
                        destinationLevel:dstMipLevel
                       destinationOrigin:MTLOriginMake( dstBox.x, dstBox.y, dstBox.z )];
        }
I disabled per-pixel reflections (and used regular PCC instead) then our app starts working.

The memory consumption is considerably lower than Ogre 2.1 (for example, one of our scenes used 1.5GB -> 900MB after upgrading), but it seems that it's easier to get killed by "memory issue". Maybe it's due to more memory fragmentation?

Another frustrating issue is that it looks like destroying scene nodes/movable objects will not free memory? I'm manually calling unloadunreferencedXXXX() function for v1/v2 mesh manager, texture manager and material manager, and I can see some resources are really unloaded (and for meshes, vaoManager->destroyVertx/IndexBuffer() is called), but the memory is not back.

One of our key functionality is to replace part of the large scene with another "sub-scene", but currently unloading the old part does free memory but loading another sub-scene increases memory :(

Thanks in advance.
0 x

rujialiu
Gremlin
Posts: 180
Joined: Mon May 09, 2016 8:21 am
x 12

Re: [2.2] Metal iOS issues

Post by rujialiu » Fri Jan 18, 2019 7:05 am

The extra files is my fault. The bitbucket repo doesn't contain them. However, I'm still having trouble with per-pixel reflections in iOS. The same code works with D3D11.

Edit: the number 4 in the message "destinationSlice(4) must be < (4)" is the maxmimum number of probes I set in the code. I tried to increase it to 32 and it's still not working. I've confirmed that the real number of probes did not exceeded 32.
0 x

rujialiu
Gremlin
Posts: 180
Joined: Mon May 09, 2016 8:21 am
x 12

Re: [2.2] Metal iOS issues

Post by rujialiu » Fri Jan 25, 2019 2:04 pm

Over the past week, Ogre 2.2 got several important leak fixes and enhancements that made iOS Render System much more usable. However, I still have one major issue: After upgrading to XCode 10 + iOS 12, the memory consumption at least doubles! And we're not alone. Unity users are complaining about this for the past few months:

https://forum.unity.com/threads/ios-12- ... 550/page-3

Quoting the latest reply for Unity:
At the moment it seems that there are at least two issues:
1) iOS 12 memory reporting tools has been updated, so you will see different numbers when running same app on iOS 11 or 12 devices. You will see similar pattern when using any Metal application, regardless of the engine being used.
2) iOS 12 jetsam rules can be the cause for different maximum allowed memory pressure for your apps.

These issues are slightly connected but still distinct, and the ultimate reason for unexpected termination is 2) and not 1).
We are working closely with Apple to find a solution for this issue.
But we only have one month before Apple forcing us to upgrade to XCode 10 :(
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 3949
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 172
Contact:

Re: [2.2] Metal iOS issues

Post by dark_sylinc » Sat Jan 26, 2019 9:28 pm

rujialiu wrote:
Sun Jan 13, 2019 12:14 pm
Then, using per-pixel reflections will get this error:

Code: Select all

-[MTLDebugBlitCommandEncoder validateCopyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:toTexture:destinationSlice:destinationLevel:destinationOrigin:options:]:239: failed assertion `destinationSlice(4) must be < (4).'
Triggered from code OgreMetalTextureGpu.mm line 252:

Code: Select all

        __unsafe_unretained id<MTLBlitCommandEncoder> blitEncoder = device->getBlitEncoder();
        for( uint32 slice=0; slice<numSlices; ++slice )
        {
            [blitEncoder copyFromTexture:srcTextureName
                             sourceSlice:srcBox.sliceStart + this->getInternalSliceStart() + slice
                             sourceLevel:srcMipLevel
                            sourceOrigin:MTLOriginMake( srcBox.x, srcBox.y, srcBox.z )
                              sourceSize:MTLSizeMake( srcBox.width, srcBox.height, srcBox.depth )
                               toTexture:dstTextureName
                        destinationSlice:dstBox.sliceStart + dstMetal->getInternalSliceStart() + slice
                        destinationLevel:dstMipLevel
                       destinationOrigin:MTLOriginMake( dstBox.x, dstBox.y, dstBox.z )];
        }
I disabled per-pixel reflections (and used regular PCC instead) then our app starts working.
I tried, but I cannot repro. Everything works as expected in iOS with per pixel cubemaps.

A couple remarks:
  • If the PCC system ran out of slots (i.e. max number of active probes was surpassed), it wouldn't be handled correctly and this error could be seen. Fixed, and a warning will be issued if the value is surpassed.
    However you assured me you increased the max number of probes to 32 and the error was still there; so I guess this was not the problem? Maybe you were wrong and the max num. probes was still somehow being surpassed?
  • If you're not using 2D Arrays (i.e. you're not using cubemap arrays, but rather parabolloid mapping), then the error is weird, as the number of slices must be multiple of 6. The number 4 is definitely not a multiple of 6. If you're using 2D arrays, this then it's ok
If this error persists after the fix, could you post the callstack?
0 x

rujialiu
Gremlin
Posts: 180
Joined: Mon May 09, 2016 8:21 am
x 12

Re: [2.2] Metal iOS issues

Post by rujialiu » Tue Jan 29, 2019 6:42 am

dark_sylinc wrote:
Sat Jan 26, 2019 9:28 pm
If this error persists after the fix, could you post the callstack?
After some refactor/bugfix of our code (to better integrate with Ogre 2.2) and updated to the lastest commit (i.e. https://bitbucket.org/sinbad/ogre/commi ... 8f04c88297) the problem went away (BTW: we're not using parabolloid mapping because A11 already supports cubemap array), so now the only real problem is iOS 12/XCode 10 memory issue, which is not Ogre's fault. Thanks!
0 x

Post Reply