Skip to content

Commit

Permalink
feat: progress command buffer logic
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Pollind <[email protected]>
  • Loading branch information
pollend committed Dec 26, 2024
1 parent 0eaa1a5 commit a9a3121
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 112 deletions.
2 changes: 1 addition & 1 deletion Source/Metal/CommandAllocatorMTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct CommandAllocatorMTL {

private:
DeviceMTL& m_Device;
struct CommandQueueMTL* m_CommandQueue;
const struct CommandQueueMTL* m_CommandQueue;
};

}
Expand Down
4 changes: 3 additions & 1 deletion Source/Metal/CommandAllocatorMTL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
}

Result CommandAllocatorMTL::Create(const CommandQueue& commandQueue) {
m_CommandQueue = &(CommandQueueMTL&)commandQueue;
const CommandQueueMTL& commandQueueImpl = (CommandQueueMTL&)commandQueue;
m_CommandQueue = &commandQueueImpl;
return Result::SUCCESS;
}

Expand All @@ -22,6 +23,7 @@
Result CommandAllocatorMTL::CreateCommandBuffer(CommandBuffer*& commandBuffer) {

CommandBufferMTL* commandBufferImpl = Allocate<CommandBufferMTL>(m_Device.GetStdAllocator(), m_Device);
commandBufferImpl->Create(m_CommandQueue);
commandBuffer = (CommandBuffer*)commandBufferImpl;
return Result::SUCCESS;
}
Expand Down
29 changes: 24 additions & 5 deletions Source/Metal/CommandBufferMTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ struct PipelineLayoutMTL;
struct TextureMTL;
struct DescriptorMTL;

NriBits(BarrierBits, uint8_t,
NONE = 0,
BARRIER_FLAG_BUFFERS = NriBit(0),
BARRIER_FLAG_TEXTURES = NriBit(1),
BARRIER_FLAG_RENDERTARGETS = NriBit(2),
BARRIER_FLAG_FENCE = NriBit(3));


NriBits(CommandBufferDirtyBits, uint8_t,
NONE = 0,
Expand All @@ -29,12 +36,11 @@ struct CommandBufferMTL {
inline DeviceMTL& GetDevice() const {
return m_Device;
}
inline operator id<MTLCommandBuffer>() const {

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


void SetDebugName(const char* name);
Result Begin(const DescriptorPool* descriptorPool);
Result End();
Expand Down Expand Up @@ -87,26 +93,39 @@ struct CommandBufferMTL {

~CommandBufferMTL();

void Create(id<MTLCommandBuffer> cmd);
void Create(const struct CommandQueueMTL* queue);

struct CmdIndexBuffer {
size_t m_Offset;
MTLIndexType m_Type;
struct BufferMTL* m_Buffer;
};

struct CmdVertexBuffer {
size_t m_Offset;
struct BufferMTL* m_Buffer;
};

private:

void Restore();
void updateCommandBufferState();
void EndCurrentEncoders();

DeviceMTL& m_Device;
struct PipelineMTL* m_CurrentPipeline = nullptr;
struct CmdIndexBuffer m_CurrentIndexCmd;
PipelineLayoutMTL* m_CurrentPipelineLayout = nullptr;
id<MTLCommandBuffer> m_Handle;
id<MTLRenderCommandEncoder> m_RendererEncoder = nil;
id<MTLComputeCommandEncoder> m_ComputeEncoder = nil;
id<MTLBlitCommandEncoder> m_BlitEncoder = nil;
const struct CommandQueueMTL* m_CommandQueue = nullptr;

struct CmdIndexBuffer m_CurrentIndexCmd;
uint32_t m_dirtyVertexBufferBits = 0;
struct CmdVertexBuffer m_CurrentVertexCmd[32];
id<MTLRenderPipelineState> m_GraphicsPipelineState;


CommandBufferDirtyBits m_DirtyBits = CommandBufferDirtyBits::NONE;
};
Expand Down
Loading

0 comments on commit a9a3121

Please sign in to comment.