mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-09-25 15:16:22 +00:00
Added wrapped MTLBuffer
This commit is contained in:
committed by
Baldur Karlsson
parent
85af87c231
commit
22b2272812
@@ -0,0 +1,116 @@
|
||||
/******************************************************************************
|
||||
* 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_buffer.h"
|
||||
#include "core/core.h"
|
||||
#include "metal_resources.h"
|
||||
|
||||
WrappedMTLBuffer::WrappedMTLBuffer(MTL::Buffer *realMTLBuffer, ResourceId objId,
|
||||
WrappedMTLDevice *wrappedMTLDevice)
|
||||
: WrappedMTLObject(realMTLBuffer, objId, wrappedMTLDevice, wrappedMTLDevice->GetStateRef())
|
||||
{
|
||||
AllocateObjCBridge(this);
|
||||
}
|
||||
|
||||
void *WrappedMTLBuffer::contents()
|
||||
{
|
||||
void *data = Unwrap(this)->contents();
|
||||
|
||||
if(IsCaptureMode(m_State))
|
||||
{
|
||||
// Snapshot potentially CPU modified buffer if the returned pointer is not NULL
|
||||
if(data)
|
||||
{
|
||||
GetResourceManager()->MarkDirtyResource(m_ID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: implement RD MTL replay
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
template <typename SerialiserType>
|
||||
bool WrappedMTLBuffer::Serialise_didModifyRange(SerialiserType &ser, NS::Range &range)
|
||||
{
|
||||
SERIALISE_ELEMENT_LOCAL(Buffer, this);
|
||||
SERIALISE_ELEMENT(range).Important();
|
||||
byte *pData = NULL;
|
||||
uint64_t memSize = range.length;
|
||||
if(ser.IsWriting())
|
||||
{
|
||||
pData = (byte *)Unwrap(this)->contents() + range.location;
|
||||
}
|
||||
if(IsReplayingAndReading())
|
||||
{
|
||||
pData = (byte *)Unwrap(Buffer)->contents() + range.location;
|
||||
}
|
||||
|
||||
// serialise directly using buffer memory
|
||||
ser.Serialise("data"_lit, pData, memSize, SerialiserFlags::NoFlags).Important();
|
||||
|
||||
SERIALISE_CHECK_READ_ERRORS();
|
||||
|
||||
// TODO: implement RD MTL replay
|
||||
if(IsReplayingAndReading())
|
||||
{
|
||||
Unwrap(Buffer)->didModifyRange(range);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WrappedMTLBuffer::didModifyRange(NS::Range &range)
|
||||
{
|
||||
SERIALISE_TIME_CALL(Unwrap(this)->didModifyRange(range));
|
||||
if(IsCaptureMode(m_State))
|
||||
{
|
||||
bool backframe = IsBackgroundCapturing(m_State);
|
||||
if(backframe)
|
||||
{
|
||||
// Snapshot potentially CPU modified buffer
|
||||
GetResourceManager()->MarkDirtyResource(m_ID);
|
||||
}
|
||||
|
||||
bool capframe = IsActiveCapturing(m_State);
|
||||
if(capframe)
|
||||
{
|
||||
Chunk *chunk = NULL;
|
||||
{
|
||||
CACHE_THREAD_SERIALISER();
|
||||
SCOPED_SERIALISE_CHUNK(MetalChunk::MTLBuffer_didModifyRange);
|
||||
Serialise_didModifyRange(ser, range);
|
||||
chunk = scope.Get();
|
||||
}
|
||||
// TODO: add to the frame capture record chunk
|
||||
// m_Device->AddFrameCaptureRecordChunk(chunk);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: implement RD MTL replay
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_FUNCTION_SERIALISED(WrappedMTLBuffer, void, didModifyRange, NS::Range &);
|
||||
Reference in New Issue
Block a user