Hi guys,I use MTLFence for synchronizing the resources,but I didn't get what I wanted. I want the oneTriangleTex having one triangle and the twoTriangleTex having two triangles,but they have the same two triangle, I don't know if the usage is correct. If not, what should I do? code snippets:
texDescriptor.hazardTrackingMode=MTLHazardTrackingModeUntracked;
texDescriptor.storageMode=MTLStorageModePrivate;
id<MTLTexture> oneTriangleTex = [_device newTextureWithDescriptor:texDescriptor];
id<MTLTexture> twoTriangleTex = [_device newTextureWithDescriptor:texDescriptor];
id<MTLFence> endPrimFence = [_device newFence];
id<MTLFence> endCopyFboFence = [_device newFence];
id <MTLCommandBuffer> cmdBuffer = [_commandQueue commandBuffer];
//render,using MTLLoadActionClear for color attachment
id <MTLRenderCommandEncoder> renderEncoder = [cmdBuffer renderCommandEncoderWithDescriptor:_descriptor];
//draw triangle a
[renderEncoder drawPrimitives:...];
[renderEncoder updateFence:endPrimFence afterStages:MTLRenderStageFragment];
[renderEncoder waitForFence:endCopyFboFence beforeStages:MTLRenderStageFragment];
//draw triangle b
[renderEncoder drawPrimitives:...];
[renderEncoder updateFence:endPrimFence afterStages:MTLRenderStageFragment];
[renderEncoder endEncoding];
// blit
id<MTLBlitCommandEncoder> biltEncoder = [cmdBuffer blitCommandEncoder];
[biltEncoder waitForFence:endPrimFence];
//copy fbo color to oneTriangleStoreTex
[biltEncoder copyFromTexture:attachmentTex
sourceSlice:0
sourceLevel:0
sourceOrigin:srcOrig
sourceSize:cpSize
toTexture:oneTriangleTex
destinationSlice:0
destinationLevel:0
destinationOrigin:dstOrig];
[biltEncoder updateFence:endCopyFboFence];
[biltEncoder waitForFence:endPrimFence];
//copy fbo color to twoTriangleStoreTex
[biltEncoder copyFromTexture:attachmentTex
sourceSlice:0
sourceLevel:0
sourceOrigin:srcOrig
sourceSize:cpSize
toTexture:twoTriangleTex
destinationSlice:0
destinationLevel:0
destinationOrigin:dstOrig];
[biltEncoder endEncoding];
[cmdBuffer commit];