|
728 | 728 | // Framebuffer creation |
729 | 729 | FramebufferImpl *ContextMtl::createFramebuffer(const gl::FramebufferState &state) |
730 | 730 | { |
731 | | - return new FramebufferMtl(state, false); |
| 731 | + return new FramebufferMtl(state, false, nullptr); |
732 | 732 | } |
733 | 733 |
|
734 | 734 | // Texture creation |
|
1003 | 1003 | ensureCommandBufferValid(); |
1004 | 1004 |
|
1005 | 1005 | // Always discard default FBO's depth stencil buffers at the end of the frame: |
1006 | | - if (mDrawFramebufferIsDefault && hasStartedRenderPass(mDrawFramebuffer)) |
| 1006 | + if (mDrawFramebufferIsDefault && mDrawFramebuffer->renderPassHasStarted(this)) |
1007 | 1007 | { |
1008 | 1008 | constexpr GLenum dsAttachments[] = {GL_DEPTH, GL_STENCIL}; |
1009 | 1009 | (void)mDrawFramebuffer->invalidate(context, 2, dsAttachments); |
|
1037 | 1037 | mRenderEncoder.renderPassDesc().equalIgnoreLoadStoreOptions(desc); |
1038 | 1038 | } |
1039 | 1039 |
|
1040 | | -bool ContextMtl::hasStartedRenderPass(FramebufferMtl *framebuffer) |
1041 | | -{ |
1042 | | - return framebuffer && hasStartedRenderPass(framebuffer->getRenderPassDesc(this)); |
1043 | | -} |
1044 | | - |
1045 | 1040 | // Get current render encoder |
1046 | 1041 | mtl::RenderCommandEncoder *ContextMtl::getRenderCommandEncoder() |
1047 | 1042 | { |
|
1053 | 1048 | return &mRenderEncoder; |
1054 | 1049 | } |
1055 | 1050 |
|
1056 | | -mtl::RenderCommandEncoder *ContextMtl::getCurrentFramebufferRenderCommandEncoder() |
1057 | | -{ |
1058 | | - if (!mDrawFramebuffer) |
1059 | | - { |
1060 | | - return nullptr; |
1061 | | - } |
1062 | | - |
1063 | | - return getRenderCommandEncoder(mDrawFramebuffer->getRenderPassDesc(this)); |
1064 | | -} |
1065 | | - |
1066 | 1051 | mtl::RenderCommandEncoder *ContextMtl::getRenderCommandEncoder(const mtl::RenderPassDesc &desc) |
1067 | 1052 | { |
1068 | 1053 | if (hasStartedRenderPass(desc)) |
|
1080 | 1065 | return &mRenderEncoder.restart(desc); |
1081 | 1066 | } |
1082 | 1067 |
|
1083 | | -// Utilities to quickly create render command enconder to a specific texture: |
| 1068 | +// Utilities to quickly create render command encoder to a specific texture: |
1084 | 1069 | // The previous content of texture will be loaded if clearColor is not provided |
1085 | 1070 | mtl::RenderCommandEncoder *ContextMtl::getRenderCommandEncoder( |
1086 | | - const mtl::TextureRef &textureTarget, |
1087 | | - const gl::ImageIndex &index, |
| 1071 | + const RenderTargetMtl &renderTarget, |
1088 | 1072 | const Optional<MTLClearColor> &clearColor) |
1089 | 1073 | { |
1090 | | - ASSERT(textureTarget && textureTarget->valid()); |
| 1074 | + ASSERT(renderTarget.getTexture()); |
1091 | 1075 |
|
1092 | 1076 | mtl::RenderPassDesc rpDesc; |
1093 | | - |
1094 | | - rpDesc.colorAttachments[0].texture = textureTarget; |
1095 | | - rpDesc.colorAttachments[0].level = index.getLevelIndex(); |
1096 | | - rpDesc.colorAttachments[0].slice = index.hasLayer() ? index.getLayerIndex() : 0; |
1097 | | - rpDesc.numColorAttachments = 1; |
| 1077 | + renderTarget.toRenderPassAttachmentDesc(&rpDesc.colorAttachments[0]); |
| 1078 | + rpDesc.numColorAttachments = 1; |
1098 | 1079 |
|
1099 | 1080 | if (clearColor.valid()) |
1100 | 1081 | { |
1101 | 1082 | rpDesc.colorAttachments[0].loadAction = MTLLoadActionClear; |
1102 | | - rpDesc.colorAttachments[0].clearColor = |
1103 | | - mtl::EmulatedAlphaClearColor(clearColor.value(), textureTarget->getColorWritableMask()); |
| 1083 | + rpDesc.colorAttachments[0].clearColor = mtl::EmulatedAlphaClearColor( |
| 1084 | + clearColor.value(), renderTarget.getTexture()->getColorWritableMask()); |
1104 | 1085 | } |
1105 | 1086 |
|
1106 | 1087 | return getRenderCommandEncoder(rpDesc); |
1107 | 1088 | } |
1108 | 1089 | // The previous content of texture will be loaded |
1109 | | -mtl::RenderCommandEncoder *ContextMtl::getRenderCommandEncoder(const mtl::TextureRef &textureTarget, |
1110 | | - const gl::ImageIndex &index) |
| 1090 | +mtl::RenderCommandEncoder *ContextMtl::getRenderCommandEncoder(const RenderTargetMtl &renderTarget) |
1111 | 1091 | { |
1112 | | - return getRenderCommandEncoder(textureTarget, index, Optional<MTLClearColor>()); |
| 1092 | + return getRenderCommandEncoder(renderTarget, Optional<MTLClearColor>()); |
1113 | 1093 | } |
1114 | 1094 |
|
1115 | 1095 | mtl::BlitCommandEncoder *ContextMtl::getBlitCommandEncoder() |
|
1354 | 1334 | if (mDirtyBits.test(DIRTY_BIT_DRAW_FRAMEBUFFER)) |
1355 | 1335 | { |
1356 | 1336 | // Start new render command encoder |
1357 | | - const mtl::RenderPassDesc &rpDesc = mDrawFramebuffer->getRenderPassDesc(this); |
1358 | | - ANGLE_MTL_TRY(this, getRenderCommandEncoder(rpDesc)); |
| 1337 | + ANGLE_MTL_TRY(this, mDrawFramebuffer->ensureRenderPassStarted(context)); |
1359 | 1338 |
|
1360 | 1339 | // re-apply everything |
1361 | 1340 | invalidateState(context); |
|
1552 | 1531 |
|
1553 | 1532 | // Need to handle the case when render pass doesn't have depth/stencil attachment. |
1554 | 1533 | mtl::DepthStencilDesc dsDesc = mDepthStencilDesc; |
1555 | | - const mtl::RenderPassDesc &renderPassDesc = mDrawFramebuffer->getRenderPassDesc(this); |
| 1534 | + const mtl::RenderPassDesc &renderPassDesc = mRenderEncoder.renderPassDesc(); |
1556 | 1535 |
|
1557 | | - if (!renderPassDesc.depthAttachment.texture) |
| 1536 | + if (!renderPassDesc.depthAttachment.texture()) |
1558 | 1537 | { |
1559 | 1538 | dsDesc.depthWriteEnabled = false; |
1560 | 1539 | dsDesc.depthCompareFunction = MTLCompareFunctionAlways; |
1561 | 1540 | } |
1562 | 1541 |
|
1563 | | - if (!renderPassDesc.stencilAttachment.texture) |
| 1542 | + if (!renderPassDesc.stencilAttachment.texture()) |
1564 | 1543 | { |
1565 | 1544 | dsDesc.frontFaceStencil.reset(); |
1566 | 1545 | dsDesc.backFaceStencil.reset(); |
|
1606 | 1585 |
|
1607 | 1586 | if (rppChange) |
1608 | 1587 | { |
1609 | | - const mtl::RenderPassDesc &renderPassDesc = mDrawFramebuffer->getRenderPassDesc(this); |
| 1588 | + const mtl::RenderPassDesc &renderPassDesc = mRenderEncoder.renderPassDesc(); |
1610 | 1589 | // Obtain RenderPipelineDesc's output descriptor. |
1611 | 1590 | renderPassDesc.populateRenderPipelineOutputDesc(mBlendDesc, |
1612 | 1591 | &mRenderPipelineDesc.outputDescriptor); |
|
0 commit comments