mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-06 01:50:38 +00:00
Added wrapped MTLRenderCommandEncoder
Implemented capture serialisation for APIs: MTLCommandBuffer::renderCommandEncoderWithDescriptor MTLRenderCommandEncoder::setRenderPipelineState MTLRenderCommandEncoder::setFragmentTexture MTLRenderCommandEncoder::setViewport MTLRenderCommandEncoder::drawPrimitives MTLRenderCommandEncoder::endEncoding Serialisation for helper types: MTL::PrimitiveType MTL::LoadAction MTL::StoreAction MTL::StoreActionOptions MTL::ClearColor MTL::Viewport MTL::MultisampleDepthResolveFilter MTL::MultisampleStencilResolveFilter MTL::SamplePosition MTL::RenderPassDescriptor MTL::RenderPassAttachmentDescriptor MTL::RenderPassColorAttachmentDescriptor MTL::RenderPassDepthAttachmentDescriptor MTL::RenderPassStencilAttachmentDescriptor MTL::RenderPassSampleBufferAttachmentDescriptor
This commit is contained in:
committed by
Baldur Karlsson
parent
c4b4c528a3
commit
958e568c9d
@@ -31,6 +31,9 @@ set(sources
|
||||
metal_texture.cpp
|
||||
metal_texture.h
|
||||
metal_texture_bridge.mm
|
||||
metal_render_command_encoder.cpp
|
||||
metal_render_command_encoder.h
|
||||
metal_render_command_encoder_bridge.mm
|
||||
metal_core.cpp
|
||||
metal_core.h
|
||||
metal_manager.cpp
|
||||
|
||||
@@ -23,9 +23,10 @@
|
||||
******************************************************************************/
|
||||
|
||||
#include "metal_command_buffer.h"
|
||||
#include "core/settings.h"
|
||||
#include "metal_device.h"
|
||||
#include "metal_render_command_encoder.h"
|
||||
#include "metal_resources.h"
|
||||
#include "metal_texture.h"
|
||||
|
||||
WrappedMTLCommandBuffer::WrappedMTLCommandBuffer(MTL::CommandBuffer *realMTLCommandBuffer,
|
||||
ResourceId objId, WrappedMTLDevice *wrappedMTLDevice)
|
||||
@@ -34,6 +35,69 @@ WrappedMTLCommandBuffer::WrappedMTLCommandBuffer(MTL::CommandBuffer *realMTLComm
|
||||
AllocateObjCBridge(this);
|
||||
}
|
||||
|
||||
template <typename SerialiserType>
|
||||
bool WrappedMTLCommandBuffer::Serialise_renderCommandEncoderWithDescriptor(
|
||||
SerialiserType &ser, WrappedMTLRenderCommandEncoder *encoder,
|
||||
RDMTL::RenderPassDescriptor &descriptor)
|
||||
{
|
||||
SERIALISE_ELEMENT_LOCAL(CommandBuffer, this);
|
||||
SERIALISE_ELEMENT_LOCAL(RenderCommandEncoder, GetResID(encoder))
|
||||
.TypedAs("MTLRenderCommandEncoder"_lit);
|
||||
SERIALISE_ELEMENT(descriptor).Important();
|
||||
|
||||
SERIALISE_CHECK_READ_ERRORS();
|
||||
|
||||
if(IsReplayingAndReading())
|
||||
{
|
||||
// TODO: implement RD MTL replay
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
WrappedMTLRenderCommandEncoder *WrappedMTLCommandBuffer::renderCommandEncoderWithDescriptor(
|
||||
RDMTL::RenderPassDescriptor &descriptor)
|
||||
{
|
||||
MTL::RenderCommandEncoder *realMTLRenderCommandEncoder;
|
||||
MTL::RenderPassDescriptor *mtlDescriptor(descriptor);
|
||||
SERIALISE_TIME_CALL(realMTLRenderCommandEncoder =
|
||||
Unwrap(this)->renderCommandEncoder(mtlDescriptor));
|
||||
mtlDescriptor->release();
|
||||
WrappedMTLRenderCommandEncoder *wrappedMTLRenderCommandEncoder;
|
||||
ResourceId id = GetResourceManager()->WrapResource(realMTLRenderCommandEncoder,
|
||||
wrappedMTLRenderCommandEncoder);
|
||||
wrappedMTLRenderCommandEncoder->SetCommandBuffer(this);
|
||||
if(IsCaptureMode(m_State))
|
||||
{
|
||||
Chunk *chunk = NULL;
|
||||
{
|
||||
CACHE_THREAD_SERIALISER();
|
||||
SCOPED_SERIALISE_CHUNK(MetalChunk::MTLCommandBuffer_renderCommandEncoderWithDescriptor);
|
||||
Serialise_renderCommandEncoderWithDescriptor(ser, wrappedMTLRenderCommandEncoder, descriptor);
|
||||
chunk = scope.Get();
|
||||
}
|
||||
MetalResourceRecord *bufferRecord = GetRecord(this);
|
||||
bufferRecord->AddChunk(chunk);
|
||||
|
||||
MetalResourceRecord *encoderRecord =
|
||||
GetResourceManager()->AddResourceRecord(wrappedMTLRenderCommandEncoder);
|
||||
|
||||
for(int i = 0; i < descriptor.colorAttachments.count(); ++i)
|
||||
{
|
||||
WrappedMTLTexture *texture = descriptor.colorAttachments[i].texture;
|
||||
if(texture != NULL)
|
||||
{
|
||||
bufferRecord->MarkResourceFrameReferenced(GetResID(texture), eFrameRef_Read);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: implement RD MTL replay
|
||||
// GetResourceManager()->AddLiveResource(id, *wrappedMTLLibrary);
|
||||
}
|
||||
return wrappedMTLRenderCommandEncoder;
|
||||
}
|
||||
|
||||
template <typename SerialiserType>
|
||||
bool WrappedMTLCommandBuffer::Serialise_presentDrawable(SerialiserType &ser, MTL::Drawable *drawable)
|
||||
{
|
||||
@@ -116,6 +180,10 @@ void WrappedMTLCommandBuffer::commit()
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_FUNCTION_WITH_RETURN_SERIALISED(WrappedMTLCommandBuffer,
|
||||
WrappedMTLRenderCommandEncoder *encoder,
|
||||
renderCommandEncoderWithDescriptor,
|
||||
RDMTL::RenderPassDescriptor &descriptor);
|
||||
INSTANTIATE_FUNCTION_SERIALISED(WrappedMTLCommandBuffer, void, presentDrawable,
|
||||
MTL::Drawable *drawable);
|
||||
INSTANTIATE_FUNCTION_SERIALISED(WrappedMTLCommandBuffer, void, commit);
|
||||
|
||||
@@ -37,6 +37,9 @@ public:
|
||||
|
||||
void SetCommandQueue(WrappedMTLCommandQueue *commandQueue) { m_CommandQueue = commandQueue; }
|
||||
MTL::CommandQueue *GetCommandQueue() { return (MTL::CommandQueue *)m_CommandQueue; }
|
||||
DECLARE_FUNCTION_WITH_RETURN_SERIALISED(WrappedMTLRenderCommandEncoder *,
|
||||
renderCommandEncoderWithDescriptor,
|
||||
RDMTL::RenderPassDescriptor &descriptor);
|
||||
DECLARE_FUNCTION_SERIALISED(void, presentDrawable, MTL::Drawable *drawable);
|
||||
DECLARE_FUNCTION_SERIALISED(void, commit);
|
||||
|
||||
|
||||
@@ -193,8 +193,9 @@
|
||||
- (nullable id<MTLRenderCommandEncoder>)renderCommandEncoderWithDescriptor:
|
||||
(MTLRenderPassDescriptor *)renderPassDescriptor
|
||||
{
|
||||
METAL_NOT_HOOKED();
|
||||
return [self.real renderCommandEncoderWithDescriptor:renderPassDescriptor];
|
||||
RDMTL::RenderPassDescriptor rdDescriptor((MTL::RenderPassDescriptor *)renderPassDescriptor);
|
||||
return id<MTLRenderCommandEncoder>(
|
||||
GetWrapped(self)->renderCommandEncoderWithDescriptor(rdDescriptor));
|
||||
}
|
||||
|
||||
- (nullable id<MTLComputeCommandEncoder>)computeCommandEncoderWithDescriptor:
|
||||
|
||||
@@ -120,6 +120,109 @@ enum class MetalChunk : uint32_t
|
||||
MTLRenderPipelineState_newVisibleFunctionTableWithDescriptor,
|
||||
MTLRenderPipelineState_newIntersectionFunctionTableWithDescriptor,
|
||||
MTLRenderPipelineState_newRenderPipelineStateWithAdditionalBinaryFunctions,
|
||||
MTLRenderCommandEncoder_endEncoding,
|
||||
MTLRenderCommandEncoder_insertDebugSignpost,
|
||||
MTLRenderCommandEncoder_pushDebugGroup,
|
||||
MTLRenderCommandEncoder_popDebugGroup,
|
||||
MTLRenderCommandEncoder_setRenderPipelineState,
|
||||
MTLRenderCommandEncoder_setVertexBytes,
|
||||
MTLRenderCommandEncoder_setVertexBuffer,
|
||||
MTLRenderCommandEncoder_setVertexBufferOffset,
|
||||
MTLRenderCommandEncoder_setVertexBuffers,
|
||||
MTLRenderCommandEncoder_setVertexTexture,
|
||||
MTLRenderCommandEncoder_setVertexTextures,
|
||||
MTLRenderCommandEncoder_setVertexSamplerState,
|
||||
MTLRenderCommandEncoder_setVertexSamplerState_lodclamp,
|
||||
MTLRenderCommandEncoder_setVertexSamplerStates,
|
||||
MTLRenderCommandEncoder_setVertexSamplerStates_lodclamp,
|
||||
MTLRenderCommandEncoder_setVertexVisibleFunctionTable,
|
||||
MTLRenderCommandEncoder_setVertexVisibleFunctionTables,
|
||||
MTLRenderCommandEncoder_setVertexIntersectionFunctionTable,
|
||||
MTLRenderCommandEncoder_setVertexIntersectionFunctionTables,
|
||||
MTLRenderCommandEncoder_setVertexAccelerationStructure,
|
||||
MTLRenderCommandEncoder_setViewport,
|
||||
MTLRenderCommandEncoder_setViewports,
|
||||
MTLRenderCommandEncoder_setFrontFacingWinding,
|
||||
MTLRenderCommandEncoder_setVertexAmplificationCount,
|
||||
MTLRenderCommandEncoder_setCullMode,
|
||||
MTLRenderCommandEncoder_setDepthClipMode,
|
||||
MTLRenderCommandEncoder_setDepthBias,
|
||||
MTLRenderCommandEncoder_setScissorRect,
|
||||
MTLRenderCommandEncoder_setScissorRects,
|
||||
MTLRenderCommandEncoder_setTriangleFillMode,
|
||||
MTLRenderCommandEncoder_setFragmentBytes,
|
||||
MTLRenderCommandEncoder_setFragmentBuffer,
|
||||
MTLRenderCommandEncoder_setFragmentBufferOffset,
|
||||
MTLRenderCommandEncoder_setFragmentBuffers,
|
||||
MTLRenderCommandEncoder_setFragmentTexture,
|
||||
MTLRenderCommandEncoder_setFragmentTextures,
|
||||
MTLRenderCommandEncoder_setFragmentSamplerState,
|
||||
MTLRenderCommandEncoder_setFragmentSamplerState_lodclamp,
|
||||
MTLRenderCommandEncoder_setFragmentSamplerStates,
|
||||
MTLRenderCommandEncoder_setFragmentSamplerStates_lodclamp,
|
||||
MTLRenderCommandEncoder_setFragmentVisibleFunctionTable,
|
||||
MTLRenderCommandEncoder_setFragmentVisibleFunctionTables,
|
||||
MTLRenderCommandEncoder_setFragmentIntersectionFunctionTable,
|
||||
MTLRenderCommandEncoder_setFragmentIntersectionFunctionTables,
|
||||
MTLRenderCommandEncoder_setFragmentAccelerationStructure,
|
||||
MTLRenderCommandEncoder_setBlendColor,
|
||||
MTLRenderCommandEncoder_setDepthStencilState,
|
||||
MTLRenderCommandEncoder_setStencilReferenceValue,
|
||||
MTLRenderCommandEncoder_setStencilFrontReferenceValue,
|
||||
MTLRenderCommandEncoder_setVisibilityResultMode,
|
||||
MTLRenderCommandEncoder_setColorStoreAction,
|
||||
MTLRenderCommandEncoder_setDepthStoreAction,
|
||||
MTLRenderCommandEncoder_setStencilStoreAction,
|
||||
MTLRenderCommandEncoder_setColorStoreActionOptions,
|
||||
MTLRenderCommandEncoder_setDepthStoreActionOptions,
|
||||
MTLRenderCommandEncoder_setStencilStoreActionOptions,
|
||||
MTLRenderCommandEncoder_drawPrimitives,
|
||||
MTLRenderCommandEncoder_drawPrimitives_instanced,
|
||||
MTLRenderCommandEncoder_drawPrimitives_instanced_base,
|
||||
MTLRenderCommandEncoder_drawPrimitives_indirect,
|
||||
MTLRenderCommandEncoder_drawIndexedPrimitives,
|
||||
MTLRenderCommandEncoder_drawIndexedPrimitives_instanced,
|
||||
MTLRenderCommandEncoder_drawIndexedPrimitives_instanced_base,
|
||||
MTLRenderCommandEncoder_drawIndexedPrimitives_indirect,
|
||||
MTLRenderCommandEncoder_textureBarrier,
|
||||
MTLRenderCommandEncoder_updateFence,
|
||||
MTLRenderCommandEncoder_waitForFence,
|
||||
MTLRenderCommandEncoder_setTessellationFactorBuffer,
|
||||
MTLRenderCommandEncoder_setTessellationFactorScale,
|
||||
MTLRenderCommandEncoder_drawPatches,
|
||||
MTLRenderCommandEncoder_drawPatches_indirect,
|
||||
MTLRenderCommandEncoder_drawIndexedPatches,
|
||||
MTLRenderCommandEncoder_drawIndexedPatches_indirect,
|
||||
MTLRenderCommandEncoder_setTileBytes,
|
||||
MTLRenderCommandEncoder_setTileBuffer,
|
||||
MTLRenderCommandEncoder_setTileBufferOffset,
|
||||
MTLRenderCommandEncoder_setTileBuffers,
|
||||
MTLRenderCommandEncoder_setTileTexture,
|
||||
MTLRenderCommandEncoder_setTileTextures,
|
||||
MTLRenderCommandEncoder_setTileSamplerState,
|
||||
MTLRenderCommandEncoder_setTileSamplerState_lodclamp,
|
||||
MTLRenderCommandEncoder_setTileSamplerStates,
|
||||
MTLRenderCommandEncoder_setTileSamplerStates_lodclamp,
|
||||
MTLRenderCommandEncoder_setTileVisibleFunctionTable,
|
||||
MTLRenderCommandEncoder_setTileVisibleFunctionTables,
|
||||
MTLRenderCommandEncoder_setTileIntersectionFunctionTable,
|
||||
MTLRenderCommandEncoder_setTileIntersectionFunctionTables,
|
||||
MTLRenderCommandEncoder_setTileAccelerationStructure,
|
||||
MTLRenderCommandEncoder_dispatchThreadsPerTile,
|
||||
MTLRenderCommandEncoder_setThreadgroupMemoryLength,
|
||||
MTLRenderCommandEncoder_useResource,
|
||||
MTLRenderCommandEncoder_useResource_stages,
|
||||
MTLRenderCommandEncoder_useResources,
|
||||
MTLRenderCommandEncoder_useResources_stages,
|
||||
MTLRenderCommandEncoder_useHeap,
|
||||
MTLRenderCommandEncoder_useHeap_stages,
|
||||
MTLRenderCommandEncoder_useHeaps,
|
||||
MTLRenderCommandEncoder_useHeaps_stages,
|
||||
MTLRenderCommandEncoder_executeCommandsInBuffer,
|
||||
MTLRenderCommandEncoder_executeCommandsInBuffer_indirect,
|
||||
MTLRenderCommandEncoder_memoryBarrierWithScope,
|
||||
MTLRenderCommandEncoder_memoryBarrierWithResources,
|
||||
MTLRenderCommandEncoder_sampleCountersInBuffer,
|
||||
Max
|
||||
};
|
||||
|
||||
|
||||
@@ -128,6 +128,7 @@ WrappedMTLCommandQueue *WrappedMTLDevice::newCommandQueue()
|
||||
Serialise_newCommandQueue(ser, wrappedMTLCommandQueue);
|
||||
chunk = scope.Get();
|
||||
}
|
||||
|
||||
MetalResourceRecord *record = GetResourceManager()->AddResourceRecord(wrappedMTLCommandQueue);
|
||||
record->AddChunk(chunk);
|
||||
}
|
||||
@@ -177,9 +178,9 @@ WrappedMTLLibrary *WrappedMTLDevice::newDefaultLibrary()
|
||||
Serialise_newDefaultLibrary(ser, wrappedMTLLibrary);
|
||||
chunk = scope.Get();
|
||||
}
|
||||
|
||||
MetalResourceRecord *record = GetResourceManager()->AddResourceRecord(wrappedMTLLibrary);
|
||||
record->AddChunk(chunk);
|
||||
GetResourceManager()->MarkResourceFrameReferenced(id, eFrameRef_Read);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -225,9 +226,9 @@ WrappedMTLLibrary *WrappedMTLDevice::newLibraryWithSource(NS::String *source,
|
||||
Serialise_newLibraryWithSource(ser, wrappedMTLLibrary, source, options, error);
|
||||
chunk = scope.Get();
|
||||
}
|
||||
|
||||
MetalResourceRecord *record = GetResourceManager()->AddResourceRecord(wrappedMTLLibrary);
|
||||
record->AddChunk(chunk);
|
||||
GetResourceManager()->MarkResourceFrameReferenced(id, eFrameRef_Read);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -70,7 +70,6 @@ WrappedMTLFunction *WrappedMTLLibrary::newFunctionWithName(NS::String *functionN
|
||||
}
|
||||
MetalResourceRecord *record = GetResourceManager()->AddResourceRecord(wrappedMTLFunction);
|
||||
record->AddChunk(chunk);
|
||||
GetResourceManager()->MarkResourceFrameReferenced(id, eFrameRef_Read);
|
||||
record->AddParent(GetRecord(this));
|
||||
}
|
||||
else
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
/******************************************************************************
|
||||
* 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_render_command_encoder.h"
|
||||
#include "metal_command_buffer.h"
|
||||
#include "metal_manager.h"
|
||||
#include "metal_render_pipeline_state.h"
|
||||
#include "metal_texture.h"
|
||||
|
||||
WrappedMTLRenderCommandEncoder::WrappedMTLRenderCommandEncoder(
|
||||
MTL::RenderCommandEncoder *realMTLRenderCommandEncoder, ResourceId objId,
|
||||
WrappedMTLDevice *wrappedMTLDevice)
|
||||
: WrappedMTLObject(realMTLRenderCommandEncoder, objId, wrappedMTLDevice,
|
||||
wrappedMTLDevice->GetStateRef())
|
||||
{
|
||||
AllocateObjCBridge(this);
|
||||
}
|
||||
|
||||
template <typename SerialiserType>
|
||||
bool WrappedMTLRenderCommandEncoder::Serialise_setRenderPipelineState(
|
||||
SerialiserType &ser, WrappedMTLRenderPipelineState *pipelineState)
|
||||
{
|
||||
SERIALISE_ELEMENT_LOCAL(RenderCommandEncoder, this);
|
||||
SERIALISE_ELEMENT(pipelineState).Important();
|
||||
|
||||
SERIALISE_CHECK_READ_ERRORS();
|
||||
|
||||
// TODO: implement RD MTL replay
|
||||
if(IsReplayingAndReading())
|
||||
{
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WrappedMTLRenderCommandEncoder::setRenderPipelineState(WrappedMTLRenderPipelineState *pipelineState)
|
||||
{
|
||||
SERIALISE_TIME_CALL(Unwrap(this)->setRenderPipelineState(Unwrap(pipelineState)));
|
||||
|
||||
if(IsCaptureMode(m_State))
|
||||
{
|
||||
Chunk *chunk = NULL;
|
||||
{
|
||||
CACHE_THREAD_SERIALISER();
|
||||
SCOPED_SERIALISE_CHUNK(MetalChunk::MTLRenderCommandEncoder_setRenderPipelineState);
|
||||
Serialise_setRenderPipelineState(ser, pipelineState);
|
||||
chunk = scope.Get();
|
||||
}
|
||||
MetalResourceRecord *bufferRecord = GetRecord(m_CommandBuffer);
|
||||
bufferRecord->AddChunk(chunk);
|
||||
bufferRecord->MarkResourceFrameReferenced(GetResID(pipelineState), eFrameRef_Read);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: implement RD MTL replay
|
||||
}
|
||||
}
|
||||
|
||||
template <typename SerialiserType>
|
||||
bool WrappedMTLRenderCommandEncoder::Serialise_setFragmentTexture(SerialiserType &ser,
|
||||
WrappedMTLTexture *texture,
|
||||
NS::UInteger index)
|
||||
{
|
||||
SERIALISE_ELEMENT_LOCAL(RenderCommandEncoder, this);
|
||||
SERIALISE_ELEMENT(texture).Important();
|
||||
SERIALISE_ELEMENT(index).Important();
|
||||
|
||||
SERIALISE_CHECK_READ_ERRORS();
|
||||
|
||||
// TODO: implement RD MTL replay
|
||||
if(IsReplayingAndReading())
|
||||
{
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WrappedMTLRenderCommandEncoder::setFragmentTexture(WrappedMTLTexture *texture, NS::UInteger index)
|
||||
{
|
||||
SERIALISE_TIME_CALL(Unwrap(this)->setFragmentTexture(Unwrap(texture), index));
|
||||
|
||||
if(IsCaptureMode(m_State))
|
||||
{
|
||||
Chunk *chunk = NULL;
|
||||
{
|
||||
CACHE_THREAD_SERIALISER();
|
||||
SCOPED_SERIALISE_CHUNK(MetalChunk::MTLRenderCommandEncoder_setFragmentTexture);
|
||||
Serialise_setFragmentTexture(ser, texture, index);
|
||||
chunk = scope.Get();
|
||||
}
|
||||
MetalResourceRecord *bufferRecord = GetRecord(m_CommandBuffer);
|
||||
bufferRecord->AddChunk(chunk);
|
||||
bufferRecord->MarkResourceFrameReferenced(GetResID(texture), eFrameRef_Read);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: implement RD MTL replay
|
||||
}
|
||||
}
|
||||
|
||||
template <typename SerialiserType>
|
||||
bool WrappedMTLRenderCommandEncoder::Serialise_setViewport(SerialiserType &ser,
|
||||
MTL::Viewport &viewport)
|
||||
{
|
||||
SERIALISE_ELEMENT_LOCAL(RenderCommandEncoder, this);
|
||||
SERIALISE_ELEMENT(viewport).Important();
|
||||
|
||||
SERIALISE_CHECK_READ_ERRORS();
|
||||
|
||||
// TODO: implement RD MTL replay
|
||||
if(IsReplayingAndReading())
|
||||
{
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WrappedMTLRenderCommandEncoder::setViewport(MTL::Viewport &viewport)
|
||||
{
|
||||
SERIALISE_TIME_CALL(Unwrap(this)->setViewport(viewport));
|
||||
|
||||
if(IsCaptureMode(m_State))
|
||||
{
|
||||
Chunk *chunk = NULL;
|
||||
{
|
||||
CACHE_THREAD_SERIALISER();
|
||||
SCOPED_SERIALISE_CHUNK(MetalChunk::MTLRenderCommandEncoder_setViewport);
|
||||
Serialise_setViewport(ser, viewport);
|
||||
chunk = scope.Get();
|
||||
}
|
||||
MetalResourceRecord *bufferRecord = GetRecord(m_CommandBuffer);
|
||||
bufferRecord->AddChunk(chunk);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: implement RD MTL replay
|
||||
}
|
||||
}
|
||||
|
||||
template <typename SerialiserType>
|
||||
bool WrappedMTLRenderCommandEncoder::Serialise_drawPrimitives(
|
||||
SerialiserType &ser, MTL::PrimitiveType primitiveType, NS::UInteger vertexStart,
|
||||
NS::UInteger vertexCount, NS::UInteger instanceCount, NS::UInteger baseInstance)
|
||||
{
|
||||
SERIALISE_ELEMENT_LOCAL(RenderCommandEncoder, this);
|
||||
SERIALISE_ELEMENT(primitiveType);
|
||||
SERIALISE_ELEMENT(vertexStart);
|
||||
SERIALISE_ELEMENT(vertexCount).Important();
|
||||
SERIALISE_ELEMENT(instanceCount);
|
||||
SERIALISE_ELEMENT(baseInstance);
|
||||
|
||||
SERIALISE_CHECK_READ_ERRORS();
|
||||
|
||||
// TODO: implement RD MTL replay
|
||||
if(IsReplayingAndReading())
|
||||
{
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WrappedMTLRenderCommandEncoder::drawPrimitives(MTL::PrimitiveType primitiveType,
|
||||
NS::UInteger vertexStart,
|
||||
NS::UInteger vertexCount,
|
||||
NS::UInteger instanceCount,
|
||||
NS::UInteger baseInstance)
|
||||
{
|
||||
SERIALISE_TIME_CALL(Unwrap(this)->drawPrimitives(primitiveType, vertexStart, vertexCount,
|
||||
instanceCount, baseInstance));
|
||||
|
||||
if(IsCaptureMode(m_State))
|
||||
{
|
||||
Chunk *chunk = NULL;
|
||||
{
|
||||
CACHE_THREAD_SERIALISER();
|
||||
SCOPED_SERIALISE_CHUNK(MetalChunk::MTLRenderCommandEncoder_drawPrimitives_instanced);
|
||||
Serialise_drawPrimitives(ser, primitiveType, vertexStart, vertexCount, instanceCount,
|
||||
baseInstance);
|
||||
chunk = scope.Get();
|
||||
}
|
||||
MetalResourceRecord *bufferRecord = GetRecord(m_CommandBuffer);
|
||||
bufferRecord->AddChunk(chunk);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: implement RD MTL replay
|
||||
}
|
||||
}
|
||||
|
||||
void WrappedMTLRenderCommandEncoder::drawPrimitives(MTL::PrimitiveType primitiveType,
|
||||
NS::UInteger vertexStart,
|
||||
NS::UInteger vertexCount)
|
||||
{
|
||||
drawPrimitives(primitiveType, vertexStart, vertexCount, 1, 0);
|
||||
}
|
||||
|
||||
void WrappedMTLRenderCommandEncoder::drawPrimitives(MTL::PrimitiveType primitiveType,
|
||||
NS::UInteger vertexStart,
|
||||
NS::UInteger vertexCount,
|
||||
NS::UInteger instanceCount)
|
||||
{
|
||||
drawPrimitives(primitiveType, vertexStart, vertexCount, instanceCount, 0);
|
||||
}
|
||||
|
||||
template <typename SerialiserType>
|
||||
bool WrappedMTLRenderCommandEncoder::Serialise_endEncoding(SerialiserType &ser)
|
||||
{
|
||||
SERIALISE_ELEMENT_LOCAL(RenderCommandEncoder, this);
|
||||
|
||||
SERIALISE_CHECK_READ_ERRORS();
|
||||
|
||||
// TODO: implement RD MTL replay
|
||||
if(IsReplayingAndReading())
|
||||
{
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WrappedMTLRenderCommandEncoder::endEncoding()
|
||||
{
|
||||
SERIALISE_TIME_CALL(Unwrap(this)->endEncoding());
|
||||
|
||||
if(IsCaptureMode(m_State))
|
||||
{
|
||||
Chunk *chunk = NULL;
|
||||
{
|
||||
CACHE_THREAD_SERIALISER();
|
||||
SCOPED_SERIALISE_CHUNK(MetalChunk::MTLRenderCommandEncoder_endEncoding);
|
||||
Serialise_endEncoding(ser);
|
||||
chunk = scope.Get();
|
||||
}
|
||||
MetalResourceRecord *bufferRecord = GetRecord(m_CommandBuffer);
|
||||
bufferRecord->AddChunk(chunk);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: implement RD MTL replay
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_FUNCTION_SERIALISED(WrappedMTLRenderCommandEncoder, void, endEncoding);
|
||||
INSTANTIATE_FUNCTION_SERIALISED(WrappedMTLRenderCommandEncoder, void, setRenderPipelineState,
|
||||
WrappedMTLRenderPipelineState *pipelineState);
|
||||
INSTANTIATE_FUNCTION_SERIALISED(WrappedMTLRenderCommandEncoder, void, setFragmentTexture,
|
||||
WrappedMTLTexture *texture, NS::UInteger index);
|
||||
INSTANTIATE_FUNCTION_SERIALISED(WrappedMTLRenderCommandEncoder, void, setViewport,
|
||||
MTL::Viewport &viewport);
|
||||
INSTANTIATE_FUNCTION_SERIALISED(WrappedMTLRenderCommandEncoder, void, drawPrimitives,
|
||||
MTL::PrimitiveType primitiveType, NS::UInteger vertexStart,
|
||||
NS::UInteger vertexCount, NS::UInteger instanceCount,
|
||||
NS::UInteger baseInstance);
|
||||
@@ -0,0 +1,59 @@
|
||||
/******************************************************************************
|
||||
* 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 WrappedMTLRenderCommandEncoder : public WrappedMTLObject
|
||||
{
|
||||
public:
|
||||
WrappedMTLRenderCommandEncoder(MTL::RenderCommandEncoder *realMTLRenderCommandEncoder,
|
||||
ResourceId objId, WrappedMTLDevice *wrappedMTLDevice);
|
||||
|
||||
void SetCommandBuffer(WrappedMTLCommandBuffer *commandBuffer) { m_CommandBuffer = commandBuffer; }
|
||||
DECLARE_FUNCTION_SERIALISED(void, setRenderPipelineState,
|
||||
WrappedMTLRenderPipelineState *pipelineState);
|
||||
DECLARE_FUNCTION_SERIALISED(void, setFragmentTexture, WrappedMTLTexture *texture,
|
||||
NS::UInteger index);
|
||||
DECLARE_FUNCTION_SERIALISED(void, setViewport, MTL::Viewport &viewport);
|
||||
DECLARE_FUNCTION_SERIALISED(void, drawPrimitives, MTL::PrimitiveType primitiveType,
|
||||
NS::UInteger vertexStart, NS::UInteger vertexCount,
|
||||
NS::UInteger instanceCount, NS::UInteger baseInstance);
|
||||
void drawPrimitives(MTL::PrimitiveType primitiveType, NS::UInteger vertexStart,
|
||||
NS::UInteger vertexCount);
|
||||
void drawPrimitives(MTL::PrimitiveType primitiveType, NS::UInteger vertexStart,
|
||||
NS::UInteger vertexCount, NS::UInteger instanceCount);
|
||||
DECLARE_FUNCTION_SERIALISED(void, endEncoding);
|
||||
|
||||
enum
|
||||
{
|
||||
TypeEnum = eResRenderCommandEncoder
|
||||
};
|
||||
|
||||
private:
|
||||
WrappedMTLCommandBuffer *m_CommandBuffer;
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -28,6 +28,7 @@
|
||||
#include "metal_device.h"
|
||||
#include "metal_function.h"
|
||||
#include "metal_library.h"
|
||||
#include "metal_render_command_encoder.h"
|
||||
#include "metal_render_pipeline_state.h"
|
||||
#include "metal_texture.h"
|
||||
|
||||
|
||||
@@ -41,7 +41,8 @@ enum MetalResourceType
|
||||
eResLibrary,
|
||||
eResFunction,
|
||||
eResRenderPipelineState,
|
||||
eResTexture
|
||||
eResTexture,
|
||||
eResRenderCommandEncoder,
|
||||
};
|
||||
|
||||
DECLARE_REFLECTION_ENUM(MetalResourceType);
|
||||
@@ -113,7 +114,7 @@ METALCPP_WRAPPED_PROTOCOLS(WRAPPED_TYPE_HELPERS)
|
||||
struct MetalCmdBufferRecordingInfo
|
||||
{
|
||||
MetalCmdBufferRecordingInfo(WrappedMTLCommandQueue *parentQueue)
|
||||
: queue(parentQueue), present(false), isEncoding(false), drawable(NULL)
|
||||
: queue(parentQueue), present(false), drawable(NULL)
|
||||
{
|
||||
}
|
||||
MetalCmdBufferRecordingInfo() = delete;
|
||||
@@ -127,8 +128,6 @@ struct MetalCmdBufferRecordingInfo
|
||||
MTL::Drawable *drawable;
|
||||
// AdvanceFrame/Present should be called after this buffer is committed.
|
||||
bool present;
|
||||
// an encoder is active : waiting for endEncoding to be called
|
||||
bool isEncoding;
|
||||
};
|
||||
|
||||
struct MetalResourceRecord : public ResourceRecord
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "metal_function.h"
|
||||
#include "metal_library.h"
|
||||
#include "metal_manager.h"
|
||||
#include "metal_render_command_encoder.h"
|
||||
#include "metal_render_pipeline_state.h"
|
||||
#include "metal_resources.h"
|
||||
#include "metal_texture.h"
|
||||
@@ -102,6 +103,33 @@ void DoSerialise(SerialiserType &ser, MTL::TextureSwizzleChannels &el)
|
||||
SERIALISE_MEMBER(alpha);
|
||||
}
|
||||
|
||||
template <typename SerialiserType>
|
||||
void DoSerialise(SerialiserType &ser, MTL::ClearColor &el)
|
||||
{
|
||||
SERIALISE_MEMBER(red);
|
||||
SERIALISE_MEMBER(green);
|
||||
SERIALISE_MEMBER(blue);
|
||||
SERIALISE_MEMBER(alpha);
|
||||
}
|
||||
|
||||
template <typename SerialiserType>
|
||||
void DoSerialise(SerialiserType &ser, MTL::Viewport &el)
|
||||
{
|
||||
SERIALISE_MEMBER(originX);
|
||||
SERIALISE_MEMBER(originY);
|
||||
SERIALISE_MEMBER(width);
|
||||
SERIALISE_MEMBER(height);
|
||||
SERIALISE_MEMBER(znear);
|
||||
SERIALISE_MEMBER(zfar);
|
||||
}
|
||||
|
||||
template <typename SerialiserType>
|
||||
void DoSerialise(SerialiserType &ser, MTL::SamplePosition &el)
|
||||
{
|
||||
SERIALISE_MEMBER(x);
|
||||
SERIALISE_MEMBER(y);
|
||||
}
|
||||
|
||||
template <typename SerialiserType>
|
||||
void DoSerialise(SerialiserType &ser, RDMTL::TextureDescriptor &el)
|
||||
{
|
||||
@@ -221,8 +249,83 @@ void DoSerialise(SerialiserType &ser, RDMTL::RenderPipelineDescriptor &el)
|
||||
SERIALISE_MEMBER(maxFragmentCallStackDepth);
|
||||
}
|
||||
|
||||
template <typename SerialiserType>
|
||||
void DoSerialise(SerialiserType &ser, RDMTL::RenderPassAttachmentDescriptor &el)
|
||||
{
|
||||
SERIALISE_MEMBER(texture);
|
||||
SERIALISE_MEMBER(level);
|
||||
SERIALISE_MEMBER(slice);
|
||||
SERIALISE_MEMBER(depthPlane);
|
||||
SERIALISE_MEMBER(resolveTexture);
|
||||
SERIALISE_MEMBER(resolveLevel);
|
||||
SERIALISE_MEMBER(resolveSlice);
|
||||
SERIALISE_MEMBER(resolveDepthPlane);
|
||||
SERIALISE_MEMBER(loadAction);
|
||||
SERIALISE_MEMBER(storeAction);
|
||||
SERIALISE_MEMBER(storeActionOptions);
|
||||
};
|
||||
|
||||
template <typename SerialiserType>
|
||||
void DoSerialise(SerialiserType &ser, RDMTL::RenderPassColorAttachmentDescriptor &el)
|
||||
{
|
||||
DoSerialise(ser, (RDMTL::RenderPassAttachmentDescriptor &)el);
|
||||
SERIALISE_MEMBER(clearColor);
|
||||
};
|
||||
|
||||
template <typename SerialiserType>
|
||||
void DoSerialise(SerialiserType &ser, RDMTL::RenderPassDepthAttachmentDescriptor &el)
|
||||
{
|
||||
DoSerialise(ser, (RDMTL::RenderPassAttachmentDescriptor &)el);
|
||||
SERIALISE_MEMBER(clearDepth);
|
||||
SERIALISE_MEMBER(depthResolveFilter);
|
||||
};
|
||||
|
||||
template <typename SerialiserType>
|
||||
void DoSerialise(SerialiserType &ser, RDMTL::RenderPassStencilAttachmentDescriptor &el)
|
||||
{
|
||||
DoSerialise(ser, (RDMTL::RenderPassAttachmentDescriptor &)el);
|
||||
SERIALISE_MEMBER(clearStencil);
|
||||
SERIALISE_MEMBER(stencilResolveFilter);
|
||||
};
|
||||
|
||||
template <typename SerialiserType>
|
||||
void DoSerialise(SerialiserType &ser, RDMTL::RenderPassSampleBufferAttachmentDescriptor &el)
|
||||
{
|
||||
// TODO: when WrappedMTLCounterSampleBuffer exists
|
||||
// SERIALISE_MEMBER(sampleBuffer);
|
||||
SERIALISE_MEMBER(startOfVertexSampleIndex);
|
||||
SERIALISE_MEMBER(endOfVertexSampleIndex);
|
||||
SERIALISE_MEMBER(startOfFragmentSampleIndex);
|
||||
SERIALISE_MEMBER(endOfFragmentSampleIndex);
|
||||
};
|
||||
|
||||
template <typename SerialiserType>
|
||||
void DoSerialise(SerialiserType &ser, RDMTL::RenderPassDescriptor &el)
|
||||
{
|
||||
SERIALISE_MEMBER(colorAttachments);
|
||||
SERIALISE_MEMBER(depthAttachment);
|
||||
SERIALISE_MEMBER(stencilAttachment);
|
||||
// TODO: when WrappedMTLBuffer exists
|
||||
// WrappedMTLBuffer *visibilityResultBuffer;
|
||||
SERIALISE_MEMBER(renderTargetArrayLength);
|
||||
SERIALISE_MEMBER(imageblockSampleLength);
|
||||
SERIALISE_MEMBER(threadgroupMemoryLength);
|
||||
SERIALISE_MEMBER(tileWidth);
|
||||
SERIALISE_MEMBER(tileHeight);
|
||||
SERIALISE_MEMBER(defaultRasterSampleCount);
|
||||
SERIALISE_MEMBER(renderTargetWidth);
|
||||
SERIALISE_MEMBER(renderTargetHeight);
|
||||
SERIALISE_MEMBER(samplePositions);
|
||||
// TODO: when WrappedRasterizationRateMap exists
|
||||
// SERIALISE_MEMBER(rasterizationRateMap);
|
||||
SERIALISE_MEMBER(sampleBufferAttachments);
|
||||
};
|
||||
|
||||
INSTANTIATE_SERIALISE_TYPE(NS::String *);
|
||||
INSTANTIATE_SERIALISE_TYPE(MTL::TextureSwizzleChannels);
|
||||
INSTANTIATE_SERIALISE_TYPE(MTL::ClearColor);
|
||||
INSTANTIATE_SERIALISE_TYPE(MTL::SamplePosition);
|
||||
INSTANTIATE_SERIALISE_TYPE(MTL::Viewport);
|
||||
INSTANTIATE_SERIALISE_TYPE(RDMTL::TextureDescriptor);
|
||||
INSTANTIATE_SERIALISE_TYPE(RDMTL::RenderPipelineColorAttachmentDescriptor);
|
||||
INSTANTIATE_SERIALISE_TYPE(RDMTL::PipelineBufferDescriptor);
|
||||
@@ -232,3 +335,8 @@ INSTANTIATE_SERIALISE_TYPE(RDMTL::VertexDescriptor);
|
||||
INSTANTIATE_SERIALISE_TYPE(RDMTL::FunctionGroup);
|
||||
INSTANTIATE_SERIALISE_TYPE(RDMTL::LinkedFunctions);
|
||||
INSTANTIATE_SERIALISE_TYPE(RDMTL::RenderPipelineDescriptor);
|
||||
INSTANTIATE_SERIALISE_TYPE(RDMTL::RenderPassAttachmentDescriptor);
|
||||
INSTANTIATE_SERIALISE_TYPE(RDMTL::RenderPassColorAttachmentDescriptor);
|
||||
INSTANTIATE_SERIALISE_TYPE(RDMTL::RenderPassDepthAttachmentDescriptor);
|
||||
INSTANTIATE_SERIALISE_TYPE(RDMTL::RenderPassStencilAttachmentDescriptor);
|
||||
INSTANTIATE_SERIALISE_TYPE(RDMTL::RenderPassDescriptor);
|
||||
|
||||
@@ -486,6 +486,58 @@ rdcstr DoStringise(const MTL::TextureSwizzle &el)
|
||||
END_ENUM_STRINGISE()
|
||||
}
|
||||
|
||||
template <>
|
||||
rdcstr DoStringise(const MTL::PrimitiveType &el)
|
||||
{
|
||||
BEGIN_ENUM_STRINGISE(MTL::PrimitiveType)
|
||||
{
|
||||
MTL_STRINGISE_ENUM(PrimitiveTypePoint);
|
||||
MTL_STRINGISE_ENUM(PrimitiveTypeLine);
|
||||
MTL_STRINGISE_ENUM(PrimitiveTypeLineStrip);
|
||||
MTL_STRINGISE_ENUM(PrimitiveTypeTriangle);
|
||||
MTL_STRINGISE_ENUM(PrimitiveTypeTriangleStrip);
|
||||
}
|
||||
END_ENUM_STRINGISE()
|
||||
}
|
||||
|
||||
template <>
|
||||
rdcstr DoStringise(const MTL::LoadAction &el)
|
||||
{
|
||||
BEGIN_ENUM_STRINGISE(MTL::LoadAction)
|
||||
{
|
||||
MTL_STRINGISE_ENUM(LoadActionDontCare);
|
||||
MTL_STRINGISE_ENUM(LoadActionLoad);
|
||||
MTL_STRINGISE_ENUM(LoadActionClear);
|
||||
}
|
||||
END_ENUM_STRINGISE()
|
||||
}
|
||||
|
||||
template <>
|
||||
rdcstr DoStringise(const MTL::StoreAction &el)
|
||||
{
|
||||
BEGIN_ENUM_STRINGISE(MTL::StoreAction)
|
||||
{
|
||||
MTL_STRINGISE_ENUM(StoreActionDontCare);
|
||||
MTL_STRINGISE_ENUM(StoreActionStore);
|
||||
MTL_STRINGISE_ENUM(StoreActionMultisampleResolve);
|
||||
MTL_STRINGISE_ENUM(StoreActionStoreAndMultisampleResolve);
|
||||
MTL_STRINGISE_ENUM(StoreActionUnknown);
|
||||
MTL_STRINGISE_ENUM(StoreActionCustomSampleDepthStore);
|
||||
}
|
||||
END_ENUM_STRINGISE()
|
||||
}
|
||||
|
||||
template <>
|
||||
rdcstr DoStringise(const MTL::StoreActionOptions &el)
|
||||
{
|
||||
BEGIN_BITFIELD_STRINGISE(MTL::StoreActionOptions)
|
||||
{
|
||||
MTL_STRINGISE_BITFIELD_VALUE(StoreActionOptionNone);
|
||||
MTL_STRINGISE_BITFIELD_BIT(StoreActionOptionCustomSamplePositions);
|
||||
}
|
||||
END_BITFIELD_STRINGISE()
|
||||
}
|
||||
|
||||
template <>
|
||||
rdcstr DoStringise(const MTL::BlendFactor &el)
|
||||
{
|
||||
@@ -542,3 +594,26 @@ rdcstr DoStringise(const MTL::ColorWriteMask &el)
|
||||
}
|
||||
END_BITFIELD_STRINGISE()
|
||||
}
|
||||
|
||||
template <>
|
||||
rdcstr DoStringise(const MTL::MultisampleDepthResolveFilter &el)
|
||||
{
|
||||
BEGIN_ENUM_STRINGISE(MTL::MultisampleDepthResolveFilter)
|
||||
{
|
||||
MTL_STRINGISE_ENUM(MultisampleDepthResolveFilterSample0);
|
||||
MTL_STRINGISE_ENUM(MultisampleDepthResolveFilterMin);
|
||||
MTL_STRINGISE_ENUM(MultisampleDepthResolveFilterMax);
|
||||
}
|
||||
END_ENUM_STRINGISE()
|
||||
}
|
||||
|
||||
template <>
|
||||
rdcstr DoStringise(const MTL::MultisampleStencilResolveFilter &el)
|
||||
{
|
||||
BEGIN_ENUM_STRINGISE(MTL::MultisampleStencilResolveFilter)
|
||||
{
|
||||
MTL_STRINGISE_ENUM(MultisampleStencilResolveFilterSample0);
|
||||
MTL_STRINGISE_ENUM(MultisampleStencilResolveFilterDepthResolvedSample);
|
||||
}
|
||||
END_ENUM_STRINGISE()
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "metal_function.h"
|
||||
#include "metal_library.h"
|
||||
#include "metal_manager.h"
|
||||
#include "metal_render_command_encoder.h"
|
||||
#include "metal_render_pipeline_state.h"
|
||||
#include "metal_resources.h"
|
||||
#include "metal_texture.h"
|
||||
@@ -93,6 +94,21 @@ static bool ValidData(MTL::RenderPipelineColorAttachmentDescriptor *descriptor)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ValidData(MTL::RenderPassColorAttachmentDescriptor *descriptor)
|
||||
{
|
||||
MTL::RenderPassAttachmentDescriptor *base = (MTL::RenderPassAttachmentDescriptor *)descriptor;
|
||||
if(!base->texture() && !base->resolveTexture())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ValidData(MTL::RenderPassSampleBufferAttachmentDescriptor *descriptor)
|
||||
{
|
||||
if(!descriptor->sampleBuffer())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename MTL_TYPE>
|
||||
static void GetWrappedNSArray(rdcarray<typename UnwrapHelper<MTL_TYPE>::Outer *> &to, NS::Array *from)
|
||||
{
|
||||
@@ -406,4 +422,150 @@ RenderPipelineDescriptor::operator MTL::RenderPipelineDescriptor *()
|
||||
return objc;
|
||||
}
|
||||
|
||||
RenderPassAttachmentDescriptor::RenderPassAttachmentDescriptor(MTL::RenderPassAttachmentDescriptor *objc)
|
||||
: texture(GetWrapped(objc->texture())),
|
||||
level(objc->level()),
|
||||
slice(objc->slice()),
|
||||
depthPlane(objc->depthPlane()),
|
||||
resolveTexture(GetWrapped(objc->resolveTexture())),
|
||||
resolveLevel(objc->resolveLevel()),
|
||||
resolveSlice(objc->resolveSlice()),
|
||||
resolveDepthPlane(objc->resolveDepthPlane()),
|
||||
loadAction(objc->loadAction()),
|
||||
storeAction(objc->storeAction()),
|
||||
storeActionOptions(objc->storeActionOptions())
|
||||
{
|
||||
}
|
||||
|
||||
void RenderPassAttachmentDescriptor::CopyTo(MTL::RenderPassAttachmentDescriptor *objc)
|
||||
{
|
||||
objc->setTexture(Unwrap(texture));
|
||||
objc->setLevel(level);
|
||||
objc->setSlice(slice);
|
||||
objc->setDepthPlane(depthPlane);
|
||||
objc->setResolveTexture(Unwrap(resolveTexture));
|
||||
objc->setResolveLevel(resolveLevel);
|
||||
objc->setResolveSlice(resolveSlice);
|
||||
objc->setResolveDepthPlane(resolveDepthPlane);
|
||||
objc->setLoadAction(loadAction);
|
||||
objc->setStoreAction(storeAction);
|
||||
objc->setStoreActionOptions(storeActionOptions);
|
||||
}
|
||||
|
||||
RenderPassColorAttachmentDescriptor::RenderPassColorAttachmentDescriptor(
|
||||
MTL::RenderPassColorAttachmentDescriptor *objc)
|
||||
: RenderPassAttachmentDescriptor((MTL::RenderPassAttachmentDescriptor *)objc),
|
||||
clearColor(objc->clearColor())
|
||||
{
|
||||
}
|
||||
|
||||
void RenderPassColorAttachmentDescriptor::CopyTo(MTL::RenderPassColorAttachmentDescriptor *objc)
|
||||
{
|
||||
((RenderPassAttachmentDescriptor *)this)->CopyTo((MTL::RenderPassAttachmentDescriptor *)objc);
|
||||
objc->setClearColor(clearColor);
|
||||
}
|
||||
|
||||
RenderPassDepthAttachmentDescriptor::RenderPassDepthAttachmentDescriptor(
|
||||
MTL::RenderPassDepthAttachmentDescriptor *objc)
|
||||
: RenderPassAttachmentDescriptor((MTL::RenderPassAttachmentDescriptor *)objc),
|
||||
clearDepth(objc->clearDepth()),
|
||||
depthResolveFilter(objc->depthResolveFilter())
|
||||
{
|
||||
}
|
||||
|
||||
void RenderPassDepthAttachmentDescriptor::CopyTo(MTL::RenderPassDepthAttachmentDescriptor *objc)
|
||||
{
|
||||
((RenderPassAttachmentDescriptor *)this)->CopyTo((MTL::RenderPassAttachmentDescriptor *)objc);
|
||||
objc->setClearDepth(clearDepth);
|
||||
objc->setDepthResolveFilter(depthResolveFilter);
|
||||
}
|
||||
|
||||
RenderPassStencilAttachmentDescriptor::RenderPassStencilAttachmentDescriptor(
|
||||
MTL::RenderPassStencilAttachmentDescriptor *objc)
|
||||
: RenderPassAttachmentDescriptor((MTL::RenderPassAttachmentDescriptor *)objc),
|
||||
clearStencil(objc->clearStencil()),
|
||||
stencilResolveFilter(objc->stencilResolveFilter())
|
||||
{
|
||||
}
|
||||
|
||||
void RenderPassStencilAttachmentDescriptor::CopyTo(MTL::RenderPassStencilAttachmentDescriptor *objc)
|
||||
{
|
||||
((RenderPassAttachmentDescriptor *)this)->CopyTo((MTL::RenderPassAttachmentDescriptor *)objc);
|
||||
objc->setClearStencil(clearStencil);
|
||||
objc->setStencilResolveFilter(stencilResolveFilter);
|
||||
}
|
||||
|
||||
RenderPassSampleBufferAttachmentDescriptor::RenderPassSampleBufferAttachmentDescriptor(
|
||||
MTL::RenderPassSampleBufferAttachmentDescriptor *objc)
|
||||
: // TODO: when WrappedMTLCounterSampleBuffer exists
|
||||
// sampleBuffer(GetWrapped(objc->sampleBuffer())),
|
||||
startOfVertexSampleIndex(objc->startOfVertexSampleIndex()),
|
||||
endOfVertexSampleIndex(objc->endOfVertexSampleIndex()),
|
||||
startOfFragmentSampleIndex(objc->startOfFragmentSampleIndex()),
|
||||
endOfFragmentSampleIndex(objc->endOfFragmentSampleIndex())
|
||||
{
|
||||
}
|
||||
|
||||
void RenderPassSampleBufferAttachmentDescriptor::CopyTo(
|
||||
MTL::RenderPassSampleBufferAttachmentDescriptor *objc)
|
||||
{
|
||||
// TODO: when WrappedMTLCounterSampleBuffer exists
|
||||
// objc->setSampleBuffer(Unwrap(sampleBuffer));
|
||||
objc->setStartOfVertexSampleIndex(startOfVertexSampleIndex);
|
||||
objc->setEndOfVertexSampleIndex(endOfVertexSampleIndex);
|
||||
objc->setStartOfFragmentSampleIndex(startOfFragmentSampleIndex);
|
||||
objc->setEndOfFragmentSampleIndex(endOfFragmentSampleIndex);
|
||||
}
|
||||
|
||||
RenderPassDescriptor::RenderPassDescriptor(MTL::RenderPassDescriptor *objc)
|
||||
: depthAttachment(objc->depthAttachment()),
|
||||
stencilAttachment(objc->stencilAttachment()),
|
||||
// TODO: when WrappedMTLBuffer exists
|
||||
// visibilityResultBuffer(GetWrapped(objc->visibilityResultBuffer())),
|
||||
renderTargetArrayLength(objc->renderTargetArrayLength()),
|
||||
imageblockSampleLength(objc->imageblockSampleLength()),
|
||||
threadgroupMemoryLength(objc->threadgroupMemoryLength()),
|
||||
tileWidth(objc->tileWidth()),
|
||||
tileHeight(objc->tileHeight()),
|
||||
defaultRasterSampleCount(objc->defaultRasterSampleCount()),
|
||||
renderTargetWidth(objc->renderTargetWidth()),
|
||||
renderTargetHeight(objc->renderTargetHeight())
|
||||
// TODO: when WrappedRasterizationRateMap exists
|
||||
// rasterizationRateMap(objc->rasterizationRateMap())
|
||||
{
|
||||
GETOBJCARRAY(RenderPassColorAttachmentDescriptor, MAX_RENDER_PASS_COLOR_ATTACHMENTS,
|
||||
colorAttachments, ValidData);
|
||||
uint32_t count = objc->getSamplePositions(NULL, 0);
|
||||
if(count)
|
||||
{
|
||||
samplePositions.resize(count);
|
||||
objc->getSamplePositions(samplePositions.data(), count);
|
||||
}
|
||||
GETOBJCARRAY(RenderPassSampleBufferAttachmentDescriptor,
|
||||
MAX_RENDER_PASS_SAMPLE_BUFFER_ATTACHMENTS, sampleBufferAttachments, ValidData);
|
||||
}
|
||||
|
||||
RenderPassDescriptor::operator MTL::RenderPassDescriptor *()
|
||||
{
|
||||
MTL::RenderPassDescriptor *objc = MTL::RenderPassDescriptor::alloc()->init();
|
||||
COPYTOOBJCARRAY(RenderPassColorAttachmentDescriptor, colorAttachments);
|
||||
depthAttachment.CopyTo(objc->depthAttachment());
|
||||
stencilAttachment.CopyTo(objc->stencilAttachment());
|
||||
// TODO: when WrappedMTLBuffer exists
|
||||
// objc->setVisibilityResultBuffer(Unwrap(visibilityResultBuffer));
|
||||
objc->setRenderTargetArrayLength(renderTargetArrayLength);
|
||||
objc->setImageblockSampleLength(imageblockSampleLength);
|
||||
objc->setThreadgroupMemoryLength(threadgroupMemoryLength);
|
||||
objc->setTileWidth(tileWidth);
|
||||
objc->setTileHeight(tileHeight);
|
||||
objc->setDefaultRasterSampleCount(defaultRasterSampleCount);
|
||||
objc->setRenderTargetWidth(renderTargetWidth);
|
||||
objc->setRenderTargetHeight(renderTargetHeight);
|
||||
objc->setSamplePositions(samplePositions.data(), samplePositions.count());
|
||||
// TODO: when WrappedRasterizationRateMap exists
|
||||
// objc->setRasterizationRateMap(Unwrap(rasterizationRateMap));
|
||||
COPYTOOBJCARRAY(RenderPassSampleBufferAttachmentDescriptor, sampleBufferAttachments);
|
||||
return objc;
|
||||
}
|
||||
|
||||
} // namespace RDMTL
|
||||
|
||||
@@ -32,6 +32,12 @@
|
||||
const uint32_t MAX_RENDER_PASS_COLOR_ATTACHMENTS = 8;
|
||||
const uint32_t MAX_RENDER_PASS_BUFFER_ATTACHMENTS = 31;
|
||||
const uint32_t MAX_VERTEX_SHADER_ATTRIBUTES = 31;
|
||||
const uint32_t MAX_RENDER_PASS_SAMPLE_BUFFER_ATTACHMENTS = 4;
|
||||
|
||||
// Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLCounters.h
|
||||
#ifndef MTLCounterDontSample
|
||||
#define MTLCounterDontSample ((NS::UInteger)-1)
|
||||
#endif // #ifndef MTLCounterDontSample
|
||||
|
||||
#define METALCPP_WRAPPED_PROTOCOLS(FUNC) \
|
||||
FUNC(CommandBuffer); \
|
||||
@@ -40,7 +46,8 @@ const uint32_t MAX_VERTEX_SHADER_ATTRIBUTES = 31;
|
||||
FUNC(Function); \
|
||||
FUNC(Library); \
|
||||
FUNC(RenderPipelineState); \
|
||||
FUNC(Texture);
|
||||
FUNC(Texture); \
|
||||
FUNC(RenderCommandEncoder);
|
||||
|
||||
// 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.
|
||||
@@ -98,6 +105,15 @@ MTL_DECLARE_REFLECTION_TYPE(TessellationFactorFormat);
|
||||
MTL_DECLARE_REFLECTION_TYPE(TessellationControlPointIndexType);
|
||||
MTL_DECLARE_REFLECTION_TYPE(TessellationFactorStepFunction);
|
||||
MTL_DECLARE_REFLECTION_TYPE(Winding);
|
||||
MTL_DECLARE_REFLECTION_TYPE(PrimitiveType);
|
||||
MTL_DECLARE_REFLECTION_TYPE(StoreActionOptions);
|
||||
MTL_DECLARE_REFLECTION_TYPE(LoadAction);
|
||||
MTL_DECLARE_REFLECTION_TYPE(StoreAction);
|
||||
MTL_DECLARE_REFLECTION_TYPE(ClearColor);
|
||||
MTL_DECLARE_REFLECTION_TYPE(Viewport);
|
||||
MTL_DECLARE_REFLECTION_TYPE(MultisampleDepthResolveFilter);
|
||||
MTL_DECLARE_REFLECTION_TYPE(MultisampleStencilResolveFilter);
|
||||
MTL_DECLARE_REFLECTION_TYPE(SamplePosition);
|
||||
|
||||
namespace RDMTL
|
||||
{
|
||||
@@ -254,6 +270,110 @@ struct RenderPipelineDescriptor
|
||||
NS::UInteger maxFragmentCallStackDepth = 1;
|
||||
};
|
||||
|
||||
// MTLRenderPassAttachmentDescriptor : based on the interface defined in
|
||||
// Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLRenderPass.h
|
||||
struct RenderPassAttachmentDescriptor
|
||||
{
|
||||
RenderPassAttachmentDescriptor(MTL::LoadAction load, MTL::StoreAction store)
|
||||
: loadAction(load), storeAction(store)
|
||||
{
|
||||
}
|
||||
RenderPassAttachmentDescriptor(MTL::RenderPassAttachmentDescriptor *objc);
|
||||
void CopyTo(MTL::RenderPassAttachmentDescriptor *objc);
|
||||
WrappedMTLTexture *texture = NULL;
|
||||
NS::UInteger level = 0;
|
||||
NS::UInteger slice = 0;
|
||||
NS::UInteger depthPlane = 0;
|
||||
WrappedMTLTexture *resolveTexture = NULL;
|
||||
NS::UInteger resolveLevel = 0;
|
||||
NS::UInteger resolveSlice = 0;
|
||||
NS::UInteger resolveDepthPlane = 0;
|
||||
MTL::LoadAction loadAction;
|
||||
MTL::StoreAction storeAction;
|
||||
MTL::StoreActionOptions storeActionOptions = MTL::StoreActionOptionNone;
|
||||
};
|
||||
|
||||
// MTLRenderPassColorAttachmentDescriptor : based on the interface defined in
|
||||
// Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLRenderPass.h
|
||||
struct RenderPassColorAttachmentDescriptor : RenderPassAttachmentDescriptor
|
||||
{
|
||||
RenderPassColorAttachmentDescriptor()
|
||||
: RenderPassAttachmentDescriptor(MTL::LoadActionDontCare, MTL::StoreActionStore)
|
||||
{
|
||||
}
|
||||
RenderPassColorAttachmentDescriptor(MTL::RenderPassColorAttachmentDescriptor *objc);
|
||||
void CopyTo(MTL::RenderPassColorAttachmentDescriptor *objc);
|
||||
MTL::ClearColor clearColor = MTL::ClearColor::Make(0.0, 0.0, 0.0, 1.0);
|
||||
};
|
||||
|
||||
// MTLRenderPassDepthAttachmentDescriptor : based on the interface defined in
|
||||
// Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLRenderPass.h
|
||||
struct RenderPassDepthAttachmentDescriptor : RenderPassAttachmentDescriptor
|
||||
{
|
||||
RenderPassDepthAttachmentDescriptor()
|
||||
: RenderPassAttachmentDescriptor(MTL::LoadActionClear, MTL::StoreActionDontCare)
|
||||
{
|
||||
}
|
||||
RenderPassDepthAttachmentDescriptor(MTL::RenderPassDepthAttachmentDescriptor *objc);
|
||||
void CopyTo(MTL::RenderPassDepthAttachmentDescriptor *objc);
|
||||
double clearDepth = 1.0;
|
||||
MTL::MultisampleDepthResolveFilter depthResolveFilter = MTL::MultisampleDepthResolveFilterSample0;
|
||||
};
|
||||
|
||||
// MTLRenderPassStencilAttachmentDescriptor : based on the interface defined in
|
||||
// Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLRenderPass.h
|
||||
struct RenderPassStencilAttachmentDescriptor : RenderPassAttachmentDescriptor
|
||||
{
|
||||
RenderPassStencilAttachmentDescriptor()
|
||||
: RenderPassAttachmentDescriptor(MTL::LoadActionClear, MTL::StoreActionDontCare)
|
||||
{
|
||||
}
|
||||
RenderPassStencilAttachmentDescriptor(MTL::RenderPassStencilAttachmentDescriptor *objc);
|
||||
void CopyTo(MTL::RenderPassStencilAttachmentDescriptor *objc);
|
||||
uint32_t clearStencil = 0;
|
||||
MTL::MultisampleStencilResolveFilter stencilResolveFilter =
|
||||
MTL::MultisampleStencilResolveFilterSample0;
|
||||
};
|
||||
|
||||
// MTLRenderPassSampleBufferAttachmentDescriptor : based on the interface defined in
|
||||
// Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Metal.framework/Headers/MTLRenderPass.h
|
||||
struct RenderPassSampleBufferAttachmentDescriptor
|
||||
{
|
||||
RenderPassSampleBufferAttachmentDescriptor() = default;
|
||||
RenderPassSampleBufferAttachmentDescriptor(MTL::RenderPassSampleBufferAttachmentDescriptor *objc);
|
||||
void CopyTo(MTL::RenderPassSampleBufferAttachmentDescriptor *objc);
|
||||
// TODO: when WrappedMTLCounterSampleBuffer exists
|
||||
// WrappedMTLCounterSampleBuffer *sampleBuffer = NULL;
|
||||
NS::UInteger startOfVertexSampleIndex = MTLCounterDontSample;
|
||||
NS::UInteger endOfVertexSampleIndex = MTLCounterDontSample;
|
||||
NS::UInteger startOfFragmentSampleIndex = MTLCounterDontSample;
|
||||
NS::UInteger endOfFragmentSampleIndex = MTLCounterDontSample;
|
||||
};
|
||||
|
||||
struct RenderPassDescriptor
|
||||
{
|
||||
RenderPassDescriptor() = default;
|
||||
RenderPassDescriptor(MTL::RenderPassDescriptor *objc);
|
||||
explicit operator MTL::RenderPassDescriptor *();
|
||||
rdcarray<RenderPassColorAttachmentDescriptor> colorAttachments;
|
||||
RenderPassDepthAttachmentDescriptor depthAttachment;
|
||||
RenderPassStencilAttachmentDescriptor stencilAttachment;
|
||||
// TODO: when WrappedMTLBuffer exists
|
||||
// WrappedMTLBuffer *visibilityResultBuffer;
|
||||
NS::UInteger renderTargetArrayLength = 0;
|
||||
NS::UInteger imageblockSampleLength = 0;
|
||||
NS::UInteger threadgroupMemoryLength = 0;
|
||||
NS::UInteger tileWidth = 0;
|
||||
NS::UInteger tileHeight = 0;
|
||||
NS::UInteger defaultRasterSampleCount = 0;
|
||||
NS::UInteger renderTargetWidth = 0;
|
||||
NS::UInteger renderTargetHeight = 0;
|
||||
rdcarray<MTL::SamplePosition> samplePositions;
|
||||
// TODO: when WrappedRasterizationRateMap exists
|
||||
// WrappedRasterizationRateMap *rasterizationRateMap = NULL;
|
||||
rdcarray<RenderPassSampleBufferAttachmentDescriptor> sampleBufferAttachments;
|
||||
};
|
||||
|
||||
} // namespace RDMTL
|
||||
|
||||
template <>
|
||||
@@ -282,3 +402,9 @@ RDMTL_DECLARE_REFLECTION_STRUCT(VertexDescriptor);
|
||||
RDMTL_DECLARE_REFLECTION_STRUCT(FunctionGroup);
|
||||
RDMTL_DECLARE_REFLECTION_STRUCT(LinkedFunctions);
|
||||
RDMTL_DECLARE_REFLECTION_STRUCT(RenderPipelineDescriptor);
|
||||
RDMTL_DECLARE_REFLECTION_STRUCT(RenderPassAttachmentDescriptor);
|
||||
RDMTL_DECLARE_REFLECTION_STRUCT(RenderPassColorAttachmentDescriptor);
|
||||
RDMTL_DECLARE_REFLECTION_STRUCT(RenderPassDepthAttachmentDescriptor);
|
||||
RDMTL_DECLARE_REFLECTION_STRUCT(RenderPassStencilAttachmentDescriptor);
|
||||
RDMTL_DECLARE_REFLECTION_STRUCT(RenderPassSampleBufferAttachmentDescriptor);
|
||||
RDMTL_DECLARE_REFLECTION_STRUCT(RenderPassDescriptor);
|
||||
|
||||
Reference in New Issue
Block a user