RavEngine
Loading...
Searching...
No Matches
MTLCommandBuffer.hpp
1#pragma once
2#include <RGL/Types.hpp>
3#include <RGL/CommandBuffer.hpp>
4#include "MTLObjCCompatLayer.hpp"
5#include <array>
6
7namespace RGL{
8struct CommandQueueMTL;
9struct TextureMTL;
10struct IBuffer;
11struct RenderPipelineDescriptor;
12struct BufferMTL;
13
15 OBJC_ID(MTLCommandBuffer) currentCommandBuffer = nullptr;
16 OBJC_ID(MTLRenderCommandEncoder) currentCommandEncoder = nullptr;
17 OBJC_ID(MTLComputeCommandEncoder) currentComputeCommandEncoder = nullptr;
18 OBJC_ID(MTLDepthStencilState) noDepthStencil = nullptr;
19 int currentPrimitiveType = 0;
20
21 std::shared_ptr<BufferMTL> indexBuffer;
22 std::shared_ptr<BufferMTL> vertexBuffer;
23
24 const std::shared_ptr<CommandQueueMTL> owningQueue;
25 CommandBufferMTL(decltype(owningQueue));
26
27 // ICommandBuffer
28 void Reset() final;
29 void Begin() final;
30 void End() final;
31 void BindRenderPipeline(RGLRenderPipelinePtr) final;
32 void BeginCompute(RGLComputePipelinePtr) final;
33 void EndCompute() final;
34 void DispatchCompute(uint32_t threadsX, uint32_t threadsY, uint32_t threadsZ, uint32_t threadsPerThreadgroupX=1, uint32_t threadsPerThreadgroupY=1, uint32_t threadsPerThreadgroupZ=1) final;
35
36 void BeginRendering(RGLRenderPassPtr) final;
37 void EndRendering() final;
38
39 void BindBuffer(RGLBufferPtr buffer, uint32_t binding, uint32_t offsetIntoBuffer = 0) final;
40 void BindComputeBuffer(RGLBufferPtr buffer, uint32_t binding, uint32_t offsetIntoBuffer = 0) final;
41 void SetVertexBuffer(RGLBufferPtr buffer, const VertexBufferBinding& bindingInfo = {}) final;
42
43 void SetIndexBuffer(RGLBufferPtr buffer) final;
44
45 void SetVertexBytes(const untyped_span data, uint32_t offset) final;
46 void SetFragmentBytes(const untyped_span data, uint32_t offset) final;
47 void SetComputeBytes(const untyped_span data, uint32_t offset) final;
48
49 void SetVertexSampler(RGLSamplerPtr sampler, uint32_t index) final;
50 void SetFragmentSampler(RGLSamplerPtr sampler, uint32_t index) final;
51 void SetComputeSampler(RGLSamplerPtr sampler, uint32_t index) final;
52
53 void SetVertexTexture(const TextureView& texture, uint32_t index) final;
54 void SetFragmentTexture(const TextureView& texture, uint32_t index) final;
55 void SetComputeTexture(const TextureView& texture, uint32_t index) final;
56
57 void BindBindlessBufferDescriptorSet(uint32_t set_idx) final;
58
59 void Draw(uint32_t nVertices, const DrawInstancedConfig& = {}) final;
60 void DrawIndexed(uint32_t nIndices, const DrawIndexedInstancedConfig& = {}) final;
61
62 void SetViewport(const Viewport&) final;
63 void SetScissor(const Rect&) final;
64
65 void CopyTextureToBuffer(RGL::TextureView& sourceTexture, const Rect& sourceRect, size_t offset, RGLBufferPtr desetBuffer) final;
66 void CopyBufferToBuffer(BufferCopyConfig from, BufferCopyConfig to, uint32_t size) final;
67 void CopyTextureToTexture(const TextureCopyConfig& from, const TextureCopyConfig& to) final;
68 void CopyBufferToTexture(RGLBufferPtr source, uint32_t size, const TextureDestConfig& dest) final;
69
70 void UseResource(const TextureView& tx) final;
71 void UseResource(const RGLBufferPtr buffer) final;
72
73 void Commit(const CommitConfig&) final;
74
75 virtual void ExecuteIndirectIndexed(const IndirectConfig&) final;
76 virtual void ExecuteIndirect(const IndirectConfig&) final;
77 void DispatchIndirect(const DispatchIndirectConfig&) final;
78
79 virtual ~CommandBufferMTL(){}
80
81 void BeginRenderDebugMarker(const std::string& label) final;
82 void BeginComputeDebugMarker(const std::string& label) final;
83
84 void EndRenderDebugMarker() final;
85 void EndComputeDebugMarker() final;
86
87 void BlockUntilCompleted() final;
88 private:
89 bool isRender = false;
90 const RenderPipelineDescriptor* pipelineConstructionSettings = nullptr;
91 std::shared_ptr<RenderPipelineMTL> currentRenderPipeline = nullptr;
92 std::shared_ptr<ComputePipelineMTL> currentComputePipeline = nullptr;
93 };
94
95}
Definition Span.hpp:11
Definition CommandBuffer.hpp:18
Definition CommandBuffer.hpp:11
Definition MTLCommandBuffer.hpp:14
Definition CommandBuffer.hpp:46
Definition CommandBuffer.hpp:80
Definition CommandBuffer.hpp:153
Definition CommandBuffer.hpp:159
Definition CommandBuffer.hpp:146
Definition CommandBuffer.hpp:99
Definition CommandBuffer.hpp:74
Definition CommandBuffer.hpp:40
Definition Pipeline.hpp:164
Definition Texture.hpp:43
Definition CommandBuffer.hpp:86
Definition CommandBuffer.hpp:31