|
254 | 254 | { |
255 | 255 | ASSERT(mColorTexture); |
256 | 256 |
|
257 | | - if (mContentInitialized) |
258 | | - { |
259 | | - return angle::Result::Continue; |
260 | | - } |
261 | | - |
262 | 257 | ContextMtl *contextMtl = mtl::GetImpl(context); |
263 | 258 |
|
264 | 259 | // Use loadAction=clear |
|
269 | 264 | { |
270 | 265 | case GL_BACK: |
271 | 266 | { |
| 267 | + if (mColorTextureInitialized) |
| 268 | + { |
| 269 | + return angle::Result::Continue; |
| 270 | + } |
272 | 271 | rpDesc.numColorAttachments = 1; |
273 | 272 | mColorRenderTarget.toRenderPassAttachmentDesc(&rpDesc.colorAttachments[0]); |
274 | 273 | rpDesc.colorAttachments[0].loadAction = MTLLoadActionClear; |
275 | 274 | MTLClearColor black = {}; |
276 | 275 | rpDesc.colorAttachments[0].clearColor = |
277 | 276 | mtl::EmulatedAlphaClearColor(black, mColorTexture->getColorWritableMask()); |
| 277 | + mColorTextureInitialized = true; |
278 | 278 | break; |
279 | 279 | } |
280 | 280 | case GL_DEPTH: |
281 | 281 | case GL_STENCIL: |
282 | 282 | { |
| 283 | + if (mDepthStencilTexturesInitialized) |
| 284 | + { |
| 285 | + return angle::Result::Continue; |
| 286 | + } |
283 | 287 | if (mDepthTexture) |
284 | 288 | { |
285 | 289 | mDepthRenderTarget.toRenderPassAttachmentDesc(&rpDesc.depthAttachment); |
|
290 | 294 | mStencilRenderTarget.toRenderPassAttachmentDesc(&rpDesc.stencilAttachment); |
291 | 295 | rpDesc.stencilAttachment.loadAction = MTLLoadActionClear; |
292 | 296 | } |
| 297 | + mDepthStencilTexturesInitialized = true; |
293 | 298 | break; |
294 | 299 | } |
295 | 300 | default: |
|
298 | 303 | } |
299 | 304 | mtl::RenderCommandEncoder *encoder = contextMtl->getRenderPassCommandEncoder(rpDesc); |
300 | 305 | encoder->setStoreAction(MTLStoreActionStore); |
301 | | - mContentInitialized = true; |
302 | 306 |
|
303 | 307 | return angle::Result::Continue; |
304 | 308 | } |
|
374 | 378 | /** renderTargetOnly */ false, &mDepthTexture)); |
375 | 379 |
|
376 | 380 | mDepthRenderTarget.set(mDepthTexture, mtl::kZeroNativeMipLevel, 0, mDepthFormat); |
| 381 | + // Robust resource init: should initialize depth to 1.0. |
| 382 | + mDepthStencilTexturesInitialized = false; |
377 | 383 | } |
378 | 384 |
|
379 | 385 | if (mStencilFormat.valid() && (!mStencilTexture || mStencilTexture->sizeAt0() != size)) |
|
390 | 396 | } |
391 | 397 |
|
392 | 398 | mStencilRenderTarget.set(mStencilTexture, mtl::kZeroNativeMipLevel, 0, mStencilFormat); |
| 399 | + // Robust resource init: should initialize stencil to zero. |
| 400 | + mDepthStencilTexturesInitialized = false; |
393 | 401 | } |
394 | 402 |
|
395 | 403 | return angle::Result::Continue; |
|
671 | 679 | mMetalLayer.get().allowsNextDrawableTimeout = NO; |
672 | 680 | mCurrentDrawable.retainAssign([mMetalLayer nextDrawable]); |
673 | 681 | mMetalLayer.get().allowsNextDrawableTimeout = YES; |
674 | | - mContentInitialized = false; |
675 | 682 | } |
676 | 683 |
|
677 | 684 | if (!mColorTexture) |
|
685 | 692 | { |
686 | 693 | mColorTexture->set(mCurrentDrawable.get().texture); |
687 | 694 | } |
| 695 | + mColorTextureInitialized = false; |
688 | 696 |
|
689 | 697 | ANGLE_MTL_LOG("Current metal drawable size=%d,%d", mColorTexture->width(), |
690 | 698 | mColorTexture->height()); |
|
718 | 726 | mColorTexture->set(nil); |
719 | 727 | mCurrentDrawable = nil; |
720 | 728 | } |
721 | | - |
| 729 | + // Robust resource init: should initialize stencil zero and depth to 1.0 after swap. |
| 730 | + if (mDepthTexture || mStencilTexture) |
| 731 | + { |
| 732 | + mDepthStencilTexturesInitialized = false; |
| 733 | + } |
722 | 734 | return angle::Result::Continue; |
723 | 735 | } |
724 | 736 |
|
|
0 commit comments