Skip to content

Commit

Permalink
feat: add command buffer impl progress
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Pollind <[email protected]>
  • Loading branch information
pollend committed Nov 21, 2024
1 parent b0ecb16 commit d8e29d3
Show file tree
Hide file tree
Showing 8 changed files with 449 additions and 20 deletions.
5 changes: 4 additions & 1 deletion Source/Metal/BufferMTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ struct BufferMTL {
return pBuffer;
}


inline DeviceMTL& GetDevice() const {
return m_Device;
}
Expand All @@ -27,6 +26,10 @@ struct BufferMTL {
return m_Desc;
}

void* Map(uint64_t offset, uint64_t size);
void Unmap();
void SetDebugName(const char* name);

~BufferMTL();

Result Create(const BufferDesc& bufferDesc);
Expand Down
19 changes: 19 additions & 0 deletions Source/Metal/BufferMTL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@
return Result::SUCCESS;
}


void* BufferMTL::Map(uint64_t offset, uint64_t size) {
return (uint8_t*)[pBuffer contents] + offset;
}

void BufferMTL::Unmap() {

}


Result BufferMTL::Create(const AllocateBufferDesc& bufferDesc) {
return Result::SUCCESS;
}

void BufferMTL::SetDebugName(const char* name) {

NSString* str = [NSString stringWithUTF8String:name];


//[pBuffer addDebugMarker:name range:]

}
5 changes: 5 additions & 0 deletions Source/Metal/CommandBufferMTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ struct CommandBufferMTL {
return m_Device;
}

inline operator id<MTLCommandBuffer>() const {
return m_Handle;
}


void SetDebugName(const char* name);
Result Begin(const DescriptorPool* descriptorPool);
Result End();
Expand Down
12 changes: 9 additions & 3 deletions Source/Metal/CommandBufferMTL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,21 @@
m_RendererEncoder = [m_Handle renderCommandEncoderWithDescriptor: renderPassDescriptor];
}
void CommandBufferMTL::EndRendering() {
NSCAssert(m_RendererEncoder, @"Renderer Encoderer Not Set");
[m_RendererEncoder endEncoding];
m_RendererEncoder = nil;
m_ComputeEncoder = nil;
}
void CommandBufferMTL::SetViewports(const Viewport* viewports, uint32_t viewportNum) {
//MTLViewport* mtlViewports = StackAlloc(MTLViewport, viewportNum);

Scratch<MTLViewport> mtlViewports = AllocateScratch(m_Device, MTLViewport, viewportNum);

for(size_t i = 0; i < viewportNum; i++) {
mtlViewports[i].originX = viewports[i].x;
mtlViewports[i].originY = viewports[i].y;
mtlViewports[i].width = viewports[i].width;
mtlViewports[i].height = viewports[i].height;
mtlViewports[i].znear = viewports[i].depthMin;
mtlViewports[i].zfar = viewports[i].depthMax;
}

[m_RendererEncoder setViewports:mtlViewports count:viewportNum];
}
Expand Down
4 changes: 3 additions & 1 deletion Source/Metal/CommandQueueMTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ struct CommandQueueMTL {
return m_Lock;
}

Result WaitForIdle();

void SetDebugName(const char* name);
void Submit(const QueueSubmitDesc& queueSubmitDesc, const SwapChain* swapChain);
Result WaitForIdle();

Result Create(CommandQueueType type);
QueueBarrierBits m_BarrierBits = QueueBarrierBits::NONE;

Expand Down
16 changes: 15 additions & 1 deletion Source/Metal/CommandQueueMTL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "SharedMTL.h"

#include "CommandQueueMTL.h"
#include "CommandBufferMTL.h"

using namespace nri;

Expand All @@ -24,7 +25,20 @@
return Result::SUCCESS;
}

inline void CommandQueueMTL::SetDebugName(const char* name) {

void CommandQueueMTL::Submit(const QueueSubmitDesc& queueSubmitDesc, const SwapChain* swapChain) {

for(uint32_t i = 0; i < queueSubmitDesc.commandBufferNum; i++) {
id<MTLCommandBuffer> cmd = *(struct CommandBufferMTL*)queueSubmitDesc.commandBuffers[i];
[cmd commit];

}


}


void CommandQueueMTL::SetDebugName(const char* name) {
[m_Handle setLabel:[NSString stringWithUTF8String:name]];
}

Expand Down
28 changes: 14 additions & 14 deletions Source/Metal/DeviceMTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ struct DeviceMTL final : public DeviceBase {
inline operator id<MTLDevice>() const {
return m_Device;
}

inline const DeviceDesc& GetDesc() const {
return m_Desc;
}

void Destruct() override;

template <typename Implementation, typename Interface, typename... Args>
inline Result CreateImplementation(Interface*& entity, const Args&... args) {
Implementation* impl = Allocate<Implementation>(GetStdAllocator(), *this);
Expand All @@ -41,14 +35,20 @@ struct DeviceMTL final : public DeviceBase {
void GetMemoryDesc(const TextureDesc& textureDesc, MemoryLocation memoryLocation, MemoryDesc& memoryDesc);
void GetMemoryDesc(const AccelerationStructureDesc& accelerationStructureDesc, MemoryLocation memoryLocation, MemoryDesc& memoryDesc);

Result FillFunctionTable(CoreInterface& table) const;
Result FillFunctionTable(HelperInterface& table) const;
Result FillFunctionTable(LowLatencyInterface& table) const;
Result FillFnctionTable(MeshShaderInterface& table) const;
Result FillFunctionTable(RayTracingInterface& table) const;
Result FillFunctionTable(StreamerInterface& table) const;
Result FillFunctionTable(SwapChainInterface& table) const;
Result FillFunctionTable(ResourceAllocatorInterface& table) const;

const DeviceDesc& GetDesc() const override {
return m_Desc;
}
void Destruct() override;

Result FillFunctionTable(CoreInterface& table) const override;
Result FillFunctionTable(HelperInterface& table) const override;
Result FillFunctionTable(LowLatencyInterface& table) const override;
Result FillFunctionTable(MeshShaderInterface& table) const override;
Result FillFunctionTable(RayTracingInterface& table) const override;
Result FillFunctionTable(StreamerInterface& table) const override;
Result FillFunctionTable(SwapChainInterface& table) const override;
Result FillFunctionTable(ResourceAllocatorInterface& table) const override;

Result Create(const DeviceCreationDesc& deviceCreationDesc, const DeviceCreationMTLDesc& deviceCreationVKDesc, bool isWrapper);
private:
Expand Down
Loading

0 comments on commit d8e29d3

Please sign in to comment.