Wrapped MtlBlitCommandEncoder

Added temporary implementation of GetWrapped() and Unwrap() for the unimplemented Metal types used by MTLBlitCommandEncoder APIs (MTLFence, MTLIndirectCommandBuffer, MTLCounterSampleBuffer).
The API synchronizeResource uses ObjC inheritance for MTLResource, which uses new helper methods for MTLResource without implementing the complete type.

MTLResource helper methods: GetResID(), Unwrap(), GetWrapped().
The WrappedMTLResource* is cast to WrappedMTLObject* to get the ID and real resource.

For the unimplemented Metal types: MTLFence, MTLIndirectCommandBuffer, MTLCounterSampleBuffer have added temporary implementations of GetWrapped() and Unwrap().
These temporary implementations perform the appropriate casting. There is no actual implementation of the unimplemented wrapped types. These unimplemented wrapped types are a temporary solution to enable the ObjC bridge to be implemented.

The APIs related to retrieving GPU counters have been hooked with basic serialization. It is expected the replay and capture will need to be specific ie. capture & serialize the buffer data, then at replay upload the serialized buffer data to the GPU buffer.
This commit is contained in:
Jake Turner
2022-06-27 14:19:07 +01:00
committed by Baldur Karlsson
parent 0a4fbe8c30
commit d257b5016d
15 changed files with 2000 additions and 5 deletions
+3
View File
@@ -35,6 +35,9 @@ set(sources
metal_buffer.cpp
metal_buffer.h
metal_buffer_bridge.mm
metal_blit_command_encoder.cpp
metal_blit_command_encoder.h
metal_blit_command_encoder_bridge.mm
metal_render_command_encoder.cpp
metal_render_command_encoder.h
metal_render_command_encoder_bridge.mm
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,113 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2022 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#pragma once
#include "metal_common.h"
#include "metal_device.h"
#include "metal_resources.h"
class WrappedMTLBlitCommandEncoder : public WrappedMTLObject
{
public:
WrappedMTLBlitCommandEncoder(MTL::BlitCommandEncoder *realMTLBlitCommandEncoder, ResourceId objId,
WrappedMTLDevice *wrappedMTLDevice);
void SetCommandBuffer(WrappedMTLCommandBuffer *commandBuffer) { m_CommandBuffer = commandBuffer; }
DECLARE_FUNCTION_SERIALISED(void, setLabel, NS::String *value);
DECLARE_FUNCTION_SERIALISED(void, endEncoding);
DECLARE_FUNCTION_SERIALISED(void, insertDebugSignpost, NS::String *string);
DECLARE_FUNCTION_SERIALISED(void, pushDebugGroup, NS::String *string);
DECLARE_FUNCTION_SERIALISED(void, popDebugGroup);
DECLARE_FUNCTION_SERIALISED(void, synchronizeResource, WrappedMTLResource *resource);
DECLARE_FUNCTION_SERIALISED(void, synchronizeTexture, WrappedMTLTexture *texture,
NS::UInteger slice, NS::UInteger level);
DECLARE_FUNCTION_SERIALISED(void, copyFromBuffer, WrappedMTLBuffer *sourceBuffer,
NS::UInteger sourceOffset, WrappedMTLBuffer *destinationBuffer,
NS::UInteger destinationOffset, NS::UInteger size);
DECLARE_FUNCTION_SERIALISED(void, copyFromBuffer, WrappedMTLBuffer *sourceBuffer,
NS::UInteger sourceOffset, NS::UInteger sourceBytesPerRow,
NS::UInteger sourceBytesPerImage, MTL::Size &sourceSize,
WrappedMTLTexture *destinationTexture, NS::UInteger destinationSlice,
NS::UInteger destinationLevel, MTL::Origin &destinationOrigin,
MTL::BlitOption options);
DECLARE_FUNCTION_SERIALISED(void, copyFromTexture, WrappedMTLTexture *sourceTexture,
NS::UInteger sourceSlice, NS::UInteger sourceLevel,
MTL::Origin &sourceOrigin, MTL::Size &sourceSize,
WrappedMTLTexture *destinationTexture, NS::UInteger destinationSlice,
NS::UInteger destinationLevel, MTL::Origin &destinationOrigin);
DECLARE_FUNCTION_SERIALISED(void, copyFromTexture, WrappedMTLTexture *sourceTexture,
NS::UInteger sourceSlice, NS::UInteger sourceLevel,
MTL::Origin &sourceOrigin, MTL::Size &sourceSize,
WrappedMTLBuffer *destinationBuffer, NS::UInteger destinationOffset,
NS::UInteger destinationBytesPerRow,
NS::UInteger destinationBytesPerImage, MTL::BlitOption options);
DECLARE_FUNCTION_SERIALISED(void, copyFromTexture, WrappedMTLTexture *sourceTexture,
WrappedMTLTexture *destinationTexture);
DECLARE_FUNCTION_SERIALISED(void, copyFromTexture, WrappedMTLTexture *sourceTexture,
NS::UInteger sourceSlice, NS::UInteger sourceLevel,
WrappedMTLTexture *destinationTexture, NS::UInteger destinationSlice,
NS::UInteger destinationLevel, NS::UInteger sliceCount,
NS::UInteger levelCount);
DECLARE_FUNCTION_SERIALISED(void, generateMipmapsForTexture, WrappedMTLTexture *texture);
DECLARE_FUNCTION_SERIALISED(void, fillBuffer, WrappedMTLBuffer *buffer, NS::Range &range,
uint8_t value);
DECLARE_FUNCTION_SERIALISED(void, updateFence, WrappedMTLFence *fence);
DECLARE_FUNCTION_SERIALISED(void, waitForFence, WrappedMTLFence *fence);
DECLARE_FUNCTION_SERIALISED(void, getTextureAccessCounters, WrappedMTLTexture *texture,
MTL::Region &region, NS::UInteger mipLevel, NS::UInteger slice,
bool resetCounters, WrappedMTLBuffer *countersBuffer,
NS::UInteger countersBufferOffset);
DECLARE_FUNCTION_SERIALISED(void, resetTextureAccessCounters, WrappedMTLTexture *texture,
MTL::Region &region, NS::UInteger mipLevel, NS::UInteger slice);
DECLARE_FUNCTION_SERIALISED(void, optimizeContentsForGPUAccess, WrappedMTLTexture *texture);
DECLARE_FUNCTION_SERIALISED(void, optimizeContentsForGPUAccess, WrappedMTLTexture *texture,
NS::UInteger slice, NS::UInteger level);
DECLARE_FUNCTION_SERIALISED(void, optimizeContentsForCPUAccess, WrappedMTLTexture *texture);
DECLARE_FUNCTION_SERIALISED(void, optimizeContentsForCPUAccess, WrappedMTLTexture *texture,
NS::UInteger slice, NS::UInteger level);
DECLARE_FUNCTION_SERIALISED(void, resetCommandsInBuffer, WrappedMTLIndirectCommandBuffer *buffer,
NS::Range &range);
DECLARE_FUNCTION_SERIALISED(void, copyIndirectCommandBuffer,
WrappedMTLIndirectCommandBuffer *source, NS::Range &sourceRange,
WrappedMTLIndirectCommandBuffer *destination,
NS::UInteger destinationIndex);
DECLARE_FUNCTION_SERIALISED(void, optimizeIndirectCommandBuffer,
WrappedMTLIndirectCommandBuffer *indirectCommandBuffer,
NS::Range &range);
DECLARE_FUNCTION_SERIALISED(void, sampleCountersInBuffer,
WrappedMTLCounterSampleBuffer *sampleBuffer, NS::UInteger sampleIndex,
bool barrier);
DECLARE_FUNCTION_SERIALISED(void, resolveCounters, WrappedMTLCounterSampleBuffer *sampleBuffer,
NS::Range &range, WrappedMTLBuffer *destinationBuffer,
NS::UInteger destinationOffset);
enum
{
TypeEnum = eResBlitCommandEncoder
};
private:
WrappedMTLCommandBuffer *m_CommandBuffer;
};
@@ -0,0 +1,338 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2022 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#include "metal_blit_command_encoder.h"
#include "metal_types_bridge.h"
// Wrapper for MTLBlitCommandEncoder
@implementation ObjCBridgeMTLBlitCommandEncoder
// ObjCWrappedMTLBlitCommandEncoder specific
- (id<MTLBlitCommandEncoder>)real
{
return id<MTLBlitCommandEncoder>(Unwrap(GetWrapped(self)));
}
// Silence compiler warning
// error: method possibly missing a [super dealloc] call [-Werror,-Wobjc-missing-super-calls]
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-missing-super-calls"
- (void)dealloc
{
GetWrapped(self)->Dealloc();
}
#pragma clang diagnostic pop
// Use the real MTLBlitCommandEncoder to find methods from messages
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
id fwd = self.real;
return [fwd methodSignatureForSelector:aSelector];
}
// Forward any unknown messages to the real MTLBlitCommandEncoder
- (void)forwardInvocation:(NSInvocation *)invocation
{
SEL aSelector = [invocation selector];
if([self.real respondsToSelector:aSelector])
[invocation invokeWithTarget:self.real];
else
[super forwardInvocation:invocation];
}
// MTLCommandEncoder : based on the protocol defined in
// Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLCommandEncoder.h
- (id<MTLDevice>)device
{
return id<MTLDevice>(GetWrapped(self)->GetDevice());
}
- (nullable NSString *)label
{
return self.real.label;
}
- (void)setLabel:value
{
GetWrapped(self)->setLabel((NS::String *)value);
}
- (void)endEncoding
{
GetWrapped(self)->endEncoding();
}
- (void)insertDebugSignpost:(NSString *)string
{
GetWrapped(self)->insertDebugSignpost((NS::String *)string);
}
- (void)pushDebugGroup:(NSString *)string
{
GetWrapped(self)->pushDebugGroup((NS::String *)string);
}
- (void)popDebugGroup
{
GetWrapped(self)->popDebugGroup();
}
// MTLBlitCommandEncoder : based on the protocol defined in
// Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLBlitCommandEncoder.h
- (void)synchronizeResource:(id<MTLResource>)resource API_AVAILABLE(macos(10.11), macCatalyst(13.0))
API_UNAVAILABLE(ios)
{
GetWrapped(self)->synchronizeResource(GetWrapped(resource));
}
- (void)synchronizeTexture:(id<MTLTexture>)texture
slice:(NSUInteger)slice
level:(NSUInteger)level API_AVAILABLE(macos(10.11), macCatalyst(13.0))
API_UNAVAILABLE(ios)
{
GetWrapped(self)->synchronizeTexture(GetWrapped(texture), slice, level);
}
- (void)copyFromTexture:(id<MTLTexture>)sourceTexture
sourceSlice:(NSUInteger)sourceSlice
sourceLevel:(NSUInteger)sourceLevel
sourceOrigin:(MTLOrigin)sourceOrigin
sourceSize:(MTLSize)sourceSize
toTexture:(id<MTLTexture>)destinationTexture
destinationSlice:(NSUInteger)destinationSlice
destinationLevel:(NSUInteger)destinationLevel
destinationOrigin:(MTLOrigin)destinationOrigin
{
GetWrapped(self)->copyFromTexture(GetWrapped(sourceTexture), sourceSlice, sourceSlice,
(MTL::Origin &)sourceOrigin, (MTL::Size &)sourceSize,
GetWrapped(destinationTexture), destinationSlice,
destinationLevel, (MTL::Origin &)destinationOrigin);
}
- (void)copyFromBuffer:(id<MTLBuffer>)sourceBuffer
sourceOffset:(NSUInteger)sourceOffset
sourceBytesPerRow:(NSUInteger)sourceBytesPerRow
sourceBytesPerImage:(NSUInteger)sourceBytesPerImage
sourceSize:(MTLSize)sourceSize
toTexture:(id<MTLTexture>)destinationTexture
destinationSlice:(NSUInteger)destinationSlice
destinationLevel:(NSUInteger)destinationLevel
destinationOrigin:(MTLOrigin)destinationOrigin
{
GetWrapped(self)->copyFromBuffer(
GetWrapped(sourceBuffer), sourceOffset, sourceBytesPerRow, sourceBytesPerImage,
(MTL::Size &)sourceSize, GetWrapped(destinationTexture), destinationSlice, destinationLevel,
(MTL::Origin &)destinationOrigin, MTL::BlitOptionNone);
}
- (void)copyFromBuffer:(id<MTLBuffer>)sourceBuffer
sourceOffset:(NSUInteger)sourceOffset
sourceBytesPerRow:(NSUInteger)sourceBytesPerRow
sourceBytesPerImage:(NSUInteger)sourceBytesPerImage
sourceSize:(MTLSize)sourceSize
toTexture:(id<MTLTexture>)destinationTexture
destinationSlice:(NSUInteger)destinationSlice
destinationLevel:(NSUInteger)destinationLevel
destinationOrigin:(MTLOrigin)destinationOrigin
options:(MTLBlitOption)options API_AVAILABLE(macos(10.11), ios(9.0))
{
GetWrapped(self)->copyFromBuffer(
GetWrapped(sourceBuffer), sourceOffset, sourceBytesPerRow, sourceBytesPerImage,
(MTL::Size &)sourceSize, GetWrapped(destinationTexture), destinationSlice, destinationLevel,
(MTL::Origin &)destinationOrigin, (MTL::BlitOption)options);
}
- (void)copyFromTexture:(id<MTLTexture>)sourceTexture
sourceSlice:(NSUInteger)sourceSlice
sourceLevel:(NSUInteger)sourceLevel
sourceOrigin:(MTLOrigin)sourceOrigin
sourceSize:(MTLSize)sourceSize
toBuffer:(id<MTLBuffer>)destinationBuffer
destinationOffset:(NSUInteger)destinationOffset
destinationBytesPerRow:(NSUInteger)destinationBytesPerRow
destinationBytesPerImage:(NSUInteger)destinationBytesPerImage
{
GetWrapped(self)->copyFromTexture(
GetWrapped(sourceTexture), sourceSlice, sourceLevel, (MTL::Origin &)sourceOrigin,
(MTL::Size &)sourceSize, GetWrapped(destinationBuffer), destinationOffset,
destinationBytesPerRow, destinationBytesPerImage, MTL::BlitOptionNone);
}
- (void)copyFromTexture:(id<MTLTexture>)sourceTexture
sourceSlice:(NSUInteger)sourceSlice
sourceLevel:(NSUInteger)sourceLevel
sourceOrigin:(MTLOrigin)sourceOrigin
sourceSize:(MTLSize)sourceSize
toBuffer:(id<MTLBuffer>)destinationBuffer
destinationOffset:(NSUInteger)destinationOffset
destinationBytesPerRow:(NSUInteger)destinationBytesPerRow
destinationBytesPerImage:(NSUInteger)destinationBytesPerImage
options:(MTLBlitOption)options API_AVAILABLE(macos(10.11), ios(9.0))
{
GetWrapped(self)->copyFromTexture(
GetWrapped(sourceTexture), sourceSlice, sourceLevel, (MTL::Origin &)sourceOrigin,
(MTL::Size &)sourceSize, GetWrapped(destinationBuffer), destinationOffset,
destinationBytesPerRow, destinationBytesPerImage, (MTL::BlitOption)options);
}
- (void)generateMipmapsForTexture:(id<MTLTexture>)texture
{
GetWrapped(self)->generateMipmapsForTexture(GetWrapped(texture));
}
- (void)fillBuffer:(id<MTLBuffer>)buffer range:(NSRange)range value:(uint8_t)value
{
GetWrapped(self)->fillBuffer(GetWrapped(buffer), (NS::Range &)range, value);
}
- (void)copyFromTexture:(id<MTLTexture>)sourceTexture
sourceSlice:(NSUInteger)sourceSlice
sourceLevel:(NSUInteger)sourceLevel
toTexture:(id<MTLTexture>)destinationTexture
destinationSlice:(NSUInteger)destinationSlice
destinationLevel:(NSUInteger)destinationLevel
sliceCount:(NSUInteger)sliceCount
levelCount:(NSUInteger)levelCount API_AVAILABLE(macos(10.15), ios(13.0))
{
GetWrapped(self)->copyFromTexture(GetWrapped(sourceTexture), sourceSlice, sourceLevel,
GetWrapped(destinationTexture), destinationSlice,
destinationLevel, sliceCount, levelCount);
}
- (void)copyFromTexture:(id<MTLTexture>)sourceTexture
toTexture:(id<MTLTexture>)destinationTexture API_AVAILABLE(macos(10.15), ios(13.0))
{
GetWrapped(self)->copyFromTexture(GetWrapped(sourceTexture), GetWrapped(destinationTexture));
}
- (void)copyFromBuffer:(id<MTLBuffer>)sourceBuffer
sourceOffset:(NSUInteger)sourceOffset
toBuffer:(id<MTLBuffer>)destinationBuffer
destinationOffset:(NSUInteger)destinationOffset
size:(NSUInteger)size
{
GetWrapped(self)->copyFromBuffer(GetWrapped(sourceBuffer), sourceOffset,
GetWrapped(destinationBuffer), destinationOffset, size);
}
- (void)updateFence:(id<MTLFence>)fence API_AVAILABLE(macos(10.13), ios(10.0))
{
GetWrapped(self)->updateFence(GetWrapped(fence));
}
- (void)waitForFence:(id<MTLFence>)fence API_AVAILABLE(macos(10.13), ios(10.0))
{
GetWrapped(self)->waitForFence(GetWrapped(fence));
}
- (void)getTextureAccessCounters:(id<MTLTexture>)texture
region:(MTLRegion)region
mipLevel:(NSUInteger)mipLevel
slice:(NSUInteger)slice
resetCounters:(BOOL)resetCounters
countersBuffer:(id<MTLBuffer>)countersBuffer
countersBufferOffset:(NSUInteger)countersBufferOffset
API_AVAILABLE(macos(11.0), macCatalyst(14.0), ios(13.0))
{
GetWrapped(self)->getTextureAccessCounters(GetWrapped(texture), (MTL::Region &)region, mipLevel,
slice, resetCounters, GetWrapped(countersBuffer),
countersBufferOffset);
}
- (void)resetTextureAccessCounters:(id<MTLTexture>)texture
region:(MTLRegion)region
mipLevel:(NSUInteger)mipLevel
slice:(NSUInteger)slice
API_AVAILABLE(macos(11.0), macCatalyst(14.0), ios(13.0))
{
GetWrapped(self)->resetTextureAccessCounters(GetWrapped(texture), (MTL::Region &)region, mipLevel,
slice);
}
- (void)optimizeContentsForGPUAccess:(id<MTLTexture>)texture API_AVAILABLE(macos(10.14), ios(12.0))
{
GetWrapped(self)->optimizeContentsForGPUAccess(GetWrapped(texture));
}
- (void)optimizeContentsForGPUAccess:(id<MTLTexture>)texture
slice:(NSUInteger)slice
level:(NSUInteger)level API_AVAILABLE(macos(10.14), ios(12.0))
{
GetWrapped(self)->optimizeContentsForGPUAccess(GetWrapped(texture), slice, level);
}
- (void)optimizeContentsForCPUAccess:(id<MTLTexture>)texture API_AVAILABLE(macos(10.14), ios(12.0))
{
GetWrapped(self)->optimizeContentsForCPUAccess(GetWrapped(texture));
}
- (void)optimizeContentsForCPUAccess:(id<MTLTexture>)texture
slice:(NSUInteger)slice
level:(NSUInteger)level API_AVAILABLE(macos(10.14), ios(12.0))
{
GetWrapped(self)->optimizeContentsForCPUAccess(GetWrapped(texture), slice, level);
}
- (void)resetCommandsInBuffer:(id<MTLIndirectCommandBuffer>)buffer
withRange:(NSRange)range API_AVAILABLE(macos(10.14), ios(12.0))
{
GetWrapped(self)->resetCommandsInBuffer(GetWrapped(buffer), (NS::Range &)range);
}
- (void)copyIndirectCommandBuffer:(id<MTLIndirectCommandBuffer>)source
sourceRange:(NSRange)sourceRange
destination:(id<MTLIndirectCommandBuffer>)destination
destinationIndex:(NSUInteger)destinationIndex API_AVAILABLE(macos(10.14), ios(12.0))
{
GetWrapped(self)->copyIndirectCommandBuffer(GetWrapped(source), (NS::Range &)sourceRange,
GetWrapped(destination), destinationIndex);
}
- (void)optimizeIndirectCommandBuffer:(id<MTLIndirectCommandBuffer>)indirectCommandBuffer
withRange:(NSRange)range API_AVAILABLE(macos(10.14), ios(12.0))
{
GetWrapped(self)->optimizeIndirectCommandBuffer(GetWrapped(indirectCommandBuffer),
(NS::Range &)range);
}
- (void)sampleCountersInBuffer:(id<MTLCounterSampleBuffer>)sampleBuffer
atSampleIndex:(NSUInteger)sampleIndex
withBarrier:(BOOL)barrier API_AVAILABLE(macos(10.15), ios(14.0))
{
GetWrapped(self)->sampleCountersInBuffer(GetWrapped(sampleBuffer), sampleIndex, barrier);
}
- (void)resolveCounters:(id<MTLCounterSampleBuffer>)sampleBuffer
inRange:(NSRange)range
destinationBuffer:(id<MTLBuffer>)destinationBuffer
destinationOffset:(NSUInteger)destinationOffset API_AVAILABLE(macos(10.15), ios(14.0))
{
GetWrapped(self)->resolveCounters(GetWrapped(sampleBuffer), (NS::Range &)range,
GetWrapped(destinationBuffer), destinationOffset);
}
@end
@@ -23,6 +23,7 @@
******************************************************************************/
#include "metal_command_buffer.h"
#include "metal_blit_command_encoder.h"
#include "metal_device.h"
#include "metal_render_command_encoder.h"
#include "metal_resources.h"
@@ -35,6 +36,54 @@ WrappedMTLCommandBuffer::WrappedMTLCommandBuffer(MTL::CommandBuffer *realMTLComm
AllocateObjCBridge(this);
}
template <typename SerialiserType>
bool WrappedMTLCommandBuffer::Serialise_blitCommandEncoder(SerialiserType &ser,
WrappedMTLBlitCommandEncoder *encoder)
{
SERIALISE_ELEMENT_LOCAL(CommandBuffer, this);
SERIALISE_ELEMENT_LOCAL(BlitCommandEncoder, GetResID(encoder))
.TypedAs("MTLBlitCommandEncoder"_lit);
SERIALISE_CHECK_READ_ERRORS();
if(IsReplayingAndReading())
{
// TODO: implement RD MTL replay
}
return true;
}
WrappedMTLBlitCommandEncoder *WrappedMTLCommandBuffer::blitCommandEncoder()
{
MTL::BlitCommandEncoder *realMTLBlitCommandEncoder;
SERIALISE_TIME_CALL(realMTLBlitCommandEncoder = Unwrap(this)->blitCommandEncoder());
WrappedMTLBlitCommandEncoder *wrappedMTLBlitCommandEncoder;
ResourceId id =
GetResourceManager()->WrapResource(realMTLBlitCommandEncoder, wrappedMTLBlitCommandEncoder);
wrappedMTLBlitCommandEncoder->SetCommandBuffer(this);
if(IsCaptureMode(m_State))
{
Chunk *chunk = NULL;
{
CACHE_THREAD_SERIALISER();
SCOPED_SERIALISE_CHUNK(MetalChunk::MTLCommandBuffer_blitCommandEncoder);
Serialise_blitCommandEncoder(ser, wrappedMTLBlitCommandEncoder);
chunk = scope.Get();
}
MetalResourceRecord *bufferRecord = GetRecord(this);
bufferRecord->AddChunk(chunk);
MetalResourceRecord *encoderRecord =
GetResourceManager()->AddResourceRecord(wrappedMTLBlitCommandEncoder);
}
else
{
// TODO: implement RD MTL replay
// GetResourceManager()->AddLiveResource(id, *wrappedMTLLibrary);
}
return wrappedMTLBlitCommandEncoder;
}
template <typename SerialiserType>
bool WrappedMTLCommandBuffer::Serialise_renderCommandEncoderWithDescriptor(
SerialiserType &ser, WrappedMTLRenderCommandEncoder *encoder,
@@ -180,6 +229,9 @@ void WrappedMTLCommandBuffer::commit()
}
}
INSTANTIATE_FUNCTION_WITH_RETURN_SERIALISED(WrappedMTLCommandBuffer,
WrappedMTLBlitCommandEncoder *encoder,
blitCommandEncoder);
INSTANTIATE_FUNCTION_WITH_RETURN_SERIALISED(WrappedMTLCommandBuffer,
WrappedMTLRenderCommandEncoder *encoder,
renderCommandEncoderWithDescriptor,
@@ -37,6 +37,7 @@ public:
void SetCommandQueue(WrappedMTLCommandQueue *commandQueue) { m_CommandQueue = commandQueue; }
MTL::CommandQueue *GetCommandQueue() { return (MTL::CommandQueue *)m_CommandQueue; }
DECLARE_FUNCTION_WITH_RETURN_SERIALISED(WrappedMTLBlitCommandEncoder *, blitCommandEncoder);
DECLARE_FUNCTION_WITH_RETURN_SERIALISED(WrappedMTLRenderCommandEncoder *,
renderCommandEncoderWithDescriptor,
RDMTL::RenderPassDescriptor &descriptor);
@@ -186,8 +186,7 @@
- (nullable id<MTLBlitCommandEncoder>)blitCommandEncoder
{
METAL_NOT_HOOKED();
return [self.real blitCommandEncoder];
return id<MTLBlitCommandEncoder>(GetWrapped(self)->blitCommandEncoder());
}
- (nullable id<MTLRenderCommandEncoder>)renderCommandEncoderWithDescriptor:
+36
View File
@@ -233,6 +233,36 @@ enum class MetalChunk : uint32_t
MTLBuffer_remoteStorageBuffer,
MTLBuffer_newRemoteBufferViewForDevice,
MTLBuffer_InternalModifyCPUContents,
MTLBlitCommandEncoder_setLabel,
MTLBlitCommandEncoder_endEncoding,
MTLBlitCommandEncoder_insertDebugSignpost,
MTLBlitCommandEncoder_pushDebugGroup,
MTLBlitCommandEncoder_popDebugGroup,
MTLBlitCommandEncoder_synchronizeResource,
MTLBlitCommandEncoder_synchronizeTexture,
MTLBlitCommandEncoder_copyFromBuffer_toBuffer,
MTLBlitCommandEncoder_copyFromBuffer_toTexture,
MTLBlitCommandEncoder_copyFromBuffer_toTexture_options,
MTLBlitCommandEncoder_copyFromTexture_toBuffer,
MTLBlitCommandEncoder_copyFromTexture_toBuffer_options,
MTLBlitCommandEncoder_copyFromTexture_toTexture,
MTLBlitCommandEncoder_copyFromTexture_toTexture_slice_level_origin,
MTLBlitCommandEncoder_copyFromTexture_toTexture_slice_level_count,
MTLBlitCommandEncoder_generateMipmapsForTexture,
MTLBlitCommandEncoder_fillBuffer,
MTLBlitCommandEncoder_updateFence,
MTLBlitCommandEncoder_waitForFence,
MTLBlitCommandEncoder_getTextureAccessCounters,
MTLBlitCommandEncoder_resetTextureAccessCounters,
MTLBlitCommandEncoder_optimizeContentsForGPUAccess,
MTLBlitCommandEncoder_optimizeContentsForGPUAccess_slice_level,
MTLBlitCommandEncoder_optimizeContentsForCPUAccess,
MTLBlitCommandEncoder_optimizeContentsForCPUAccess_slice_level,
MTLBlitCommandEncoder_resetCommandsInBuffer,
MTLBlitCommandEncoder_copyIndirectCommandBuffer,
MTLBlitCommandEncoder_optimizeIndirectCommandBuffer,
MTLBlitCommandEncoder_sampleCountersInBuffer,
MTLBlitCommandEncoder_resolveCounters,
Max
};
@@ -282,6 +312,12 @@ DECLARE_REFLECTION_ENUM(MetalChunk);
} while((void)0, 0)
#endif
#define METAL_CAPTURE_NOT_IMPLEMENTED() \
do \
{ \
RDCERR("Metal '%s' capture not implemented", __PRETTY_FUNCTION__); \
} while((void)0, 0)
// similar to RDCUNIMPLEMENTED but without the debugbreak
#define METAL_NOT_IMPLEMENTED(...) \
do \
@@ -23,6 +23,7 @@
******************************************************************************/
#include "metal_resources.h"
#include "metal_blit_command_encoder.h"
#include "metal_buffer.h"
#include "metal_command_buffer.h"
#include "metal_command_queue.h"
+11
View File
@@ -44,6 +44,7 @@ enum MetalResourceType
eResRenderPipelineState,
eResTexture,
eResRenderCommandEncoder,
eResBlitCommandEncoder,
eResMax
};
@@ -78,6 +79,11 @@ struct WrappedMTLObject
ResourceId GetResID(WrappedMTLObject *obj);
inline ResourceId GetResID(WrappedMTLResource *obj)
{
return GetResID((WrappedMTLObject *)obj);
}
template <typename WrappedType>
MetalResourceRecord *GetRecord(WrappedType *obj)
{
@@ -113,6 +119,11 @@ struct UnwrapHelper
METALCPP_WRAPPED_PROTOCOLS(WRAPPED_TYPE_HELPERS)
#undef WRAPPED_TYPE_HELPERS
inline MTL::Resource *Unwrap(WrappedMTLResource *obj)
{
return Unwrap<MTL::Resource *>((WrappedMTLObject *)obj);
}
struct MetalCmdBufferRecordingInfo
{
MetalCmdBufferRecordingInfo(WrappedMTLCommandQueue *parentQueue)
@@ -22,6 +22,7 @@
* THE SOFTWARE.
******************************************************************************/
#include "metal_blit_command_encoder.h"
#include "metal_buffer.h"
#include "metal_command_buffer.h"
#include "metal_command_queue.h"
@@ -77,6 +78,7 @@ void DoSerialiseViaResourceId(SerialiserType &ser, type &el)
INSTANTIATE_SERIALISE_TYPE(WrappedMTL##CPPTYPE *);
METALCPP_WRAPPED_PROTOCOLS(IMPLEMENT_WRAPPED_TYPE_SERIALISE);
IMPLEMENT_WRAPPED_TYPE_SERIALISE(Resource);
#undef IMPLEMENT_WRAPPED_TYPE_SERIALISE
template <typename SerialiserType>
+62 -2
View File
@@ -31,7 +31,7 @@
template <>
rdcstr DoStringise(const MetalChunk &el)
{
RDCCOMPILE_ASSERT((uint32_t)MetalChunk::Max == 1199, "Chunks changed without updating names");
RDCCOMPILE_ASSERT((uint32_t)MetalChunk::Max == 1229, "Chunks changed without updating names");
BEGIN_ENUM_STRINGISE(MetalChunk)
{
@@ -400,6 +400,65 @@ rdcstr DoStringise(const MetalChunk &el)
"MTLBuffer::newRemoteBufferViewForDevice");
STRINGISE_ENUM_CLASS_NAMED(MTLBuffer_InternalModifyCPUContents,
"Internal_MTLBufferModifyCPUContents");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_setLabel, "MTLBlitCommandEncoder::setLabel");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_endEncoding,
"MTLBlitCommandEncoder::endEncoding");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_insertDebugSignpost,
"MTLBlitCommandEncoder::insertDebugSignpost");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_pushDebugGroup,
"MTLBlitCommandEncoder::pushDebugGroup");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_popDebugGroup,
"MTLBlitCommandEncoder::popDebugGroup");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_synchronizeResource,
"MTLBlitCommandEncoder::synchronizeResource");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_synchronizeTexture,
"MTLBlitCommandEncoder::synchronizeTexture");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_copyFromBuffer_toBuffer,
"MTLBlitCommandEncoder::copyFromBuffer");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_copyFromBuffer_toTexture,
"MTLBlitCommandEncoder::copyFromBuffer");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_copyFromBuffer_toTexture_options,
"MTLBlitCommandEncoder::copyFromBuffer");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_copyFromTexture_toBuffer,
"MTLBlitCommandEncoder::copyFromTexture_toBuffer");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_copyFromTexture_toBuffer_options,
"MTLBlitCommandEncoder::copyFromTexture");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_copyFromTexture_toTexture,
"MTLBlitCommandEncoder::copyFromTexture_toTexture");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_copyFromTexture_toTexture_slice_level_origin,
"MTLBlitCommandEncoder::copyFromTexture");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_copyFromTexture_toTexture_slice_level_count,
"MTLBlitCommandEncoder::copyFromTexture");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_generateMipmapsForTexture,
"MTLBlitCommandEncoder::generateMipmapsForTexture");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_fillBuffer,
"MTLBlitCommandEncoder::fillBuffer");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_updateFence,
"MTLBlitCommandEncoder::updateFence");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_waitForFence,
"MTLBlitCommandEncoder::waitForFence");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_getTextureAccessCounters,
"MTLBlitCommandEncoder::getTextureAccessCounters");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_resetTextureAccessCounters,
"MTLBlitCommandEncoder::resetTextureAccessCounters");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_optimizeContentsForGPUAccess,
"MTLBlitCommandEncoder::optimizeContentsForGPUAccess");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_optimizeContentsForGPUAccess_slice_level,
"MTLBlitCommandEncoder::optimizeContentsForGPUAccess");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_optimizeContentsForCPUAccess,
"MTLBlitCommandEncoder::optimizeContentsForCPUAccess");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_optimizeContentsForCPUAccess_slice_level,
"MTLBlitCommandEncoder::optimizeContentsForCPUAccess");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_resetCommandsInBuffer,
"MTLBlitCommandEncoder::resetCommandsInBuffer");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_copyIndirectCommandBuffer,
"MTLBlitCommandEncoder::copyIndirectCommandBuffer");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_optimizeIndirectCommandBuffer,
"MTLBlitCommandEncoder::optimizeIndirectCommandBuffer");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_sampleCountersInBuffer,
"MTLBlitCommandEncoder::sampleCountersInBuffer");
STRINGISE_ENUM_CLASS_NAMED(MTLBlitCommandEncoder_resolveCounters,
"MTLBlitCommandEncoder::resolveCounters");
STRINGISE_ENUM_CLASS_NAMED(Max, "Max Chunk");
}
END_ENUM_STRINGISE()
@@ -1069,7 +1128,7 @@ rdcstr DoStringise(const MTL::CullMode &el)
template <>
rdcstr DoStringise(const MetalResourceType &el)
{
RDCCOMPILE_ASSERT((uint32_t)MetalResourceType::eResMax == 10, "MetalResourceType changed");
RDCCOMPILE_ASSERT((uint32_t)MetalResourceType::eResMax == 11, "MetalResourceType changed");
BEGIN_ENUM_STRINGISE(MetalResourceType);
{
STRINGISE_ENUM(eResUnknown);
@@ -1082,6 +1141,7 @@ rdcstr DoStringise(const MetalResourceType &el)
STRINGISE_ENUM(eResRenderPipelineState);
STRINGISE_ENUM(eResTexture);
STRINGISE_ENUM(eResRenderCommandEncoder);
STRINGISE_ENUM(eResBlitCommandEncoder);
}
END_ENUM_STRINGISE();
}
+1
View File
@@ -23,6 +23,7 @@
******************************************************************************/
#include "metal_types.h"
#include "metal_blit_command_encoder.h"
#include "metal_buffer.h"
#include "metal_command_buffer.h"
#include "metal_command_queue.h"
+15 -1
View File
@@ -48,7 +48,8 @@ const uint32_t MAX_RENDER_PASS_SAMPLE_BUFFER_ATTACHMENTS = 4;
FUNC(Library); \
FUNC(RenderPipelineState); \
FUNC(Texture); \
FUNC(RenderCommandEncoder);
FUNC(RenderCommandEncoder); \
FUNC(BlitCommandEncoder);
// These serialise overloads will fetch the ID during capture, serialise the ID
// directly as-if it were the original type, then on replay load up the resource if available.
@@ -63,6 +64,7 @@ const uint32_t MAX_RENDER_PASS_SAMPLE_BUFFER_ATTACHMENTS = 4;
void DoSerialise(SerialiserType &ser, WrappedMTL##CPPTYPE *&el);
METALCPP_WRAPPED_PROTOCOLS(DECLARE_WRAPPED_TYPE_SERIALISE);
DECLARE_WRAPPED_TYPE_SERIALISE(Resource)
#undef DECLARE_WRAPPED_TYPE_SERIALISE
#define DECLARE_OBJC_HELPERS(CPPTYPE) \
@@ -76,6 +78,18 @@ METALCPP_WRAPPED_PROTOCOLS(DECLARE_WRAPPED_TYPE_SERIALISE);
METALCPP_WRAPPED_PROTOCOLS(DECLARE_OBJC_HELPERS)
#undef DECLARE_OBJC_HELPERS
// TODO: Wrapped types that need implementing
#define METALCPP_UNIMPLEMENTED_WRAPPED_PROTOCOLS(FUNC) \
FUNC(Fence); \
FUNC(IndirectCommandBuffer); \
FUNC(CounterSampleBuffer);
#define DECLARE_UNIMPLEMENTED_WRAPPED_CPP_HELPERS(CPPTYPE) \
class WrappedMTL##CPPTYPE; \
inline MTL::CPPTYPE *Unwrap(WrappedMTL##CPPTYPE *obj) { return (MTL::CPPTYPE *)obj; }
METALCPP_UNIMPLEMENTED_WRAPPED_PROTOCOLS(DECLARE_UNIMPLEMENTED_WRAPPED_CPP_HELPERS)
#undef DECLARE_UNIMPLEMENTED_WRAPPED_CPP_HELPERS
#define MTL_DECLARE_REFLECTION_TYPE(TYPE) \
template <> \
inline rdcliteral TypeName<MTL::TYPE>() \
@@ -41,6 +41,20 @@
METALCPP_WRAPPED_PROTOCOLS(DECLARE_OBJC_WRAPPED_INTERFACES)
#undef DECLARE_OBJC_WRAPPED_INTERFACES
#define DECLARE_UNIMPLEMENTED_WRAPPED_OBJC_HELPERS(CPPTYPE) \
inline WrappedMTL##CPPTYPE *GetWrapped(id<MTL##CPPTYPE> objC) \
{ \
return (WrappedMTL##CPPTYPE *)objC; \
}
METALCPP_UNIMPLEMENTED_WRAPPED_PROTOCOLS(DECLARE_UNIMPLEMENTED_WRAPPED_OBJC_HELPERS)
#undef DECLARE_UNIMPLEMENTED_WRAPPED_OBJC_HELPERS
inline WrappedMTLResource *GetWrapped(id<MTLResource> objC)
{
return (WrappedMTLResource *)objC;
}
// Define Mac SDK versions when compiling with earlier SDKs
#ifndef __MAC_12_0
#define __MAC_12_0 120000