RavEngine
Loading...
Searching...
No Matches
MTLDevice.hpp
1#pragma once
2
3#if RGL_MTL_AVAILABLE
4#include <RGL/Types.hpp>
5#include <RGL/Device.hpp>
6#include "MTLObjCCompatLayer.hpp"
7#include "FreeList.hpp"
8#include <memory>
9
10namespace RGL{
11
12 struct DeviceMTL : public IDevice, public std::enable_shared_from_this<DeviceMTL>{
13 OBJC_ID(MTLDevice) device = nullptr;
14 OBJC_ID(MTLLibrary) defaultLibrary = nullptr;
15 OBJC_ID(MTLCommandQueue) uploadQueue = nullptr;
16 OBJC_ID(MTLArgumentEncoder) globalTextureEncoder = nullptr;
17 OBJC_ID(MTLArgumentEncoder) globalBufferEncoder = nullptr;
18 OBJC_ID(MTLBuffer) globalTextureBuffer = nullptr;
19 OBJC_ID(MTLBuffer) globalBufferBuffer = nullptr;
20
21 DeviceMTL(decltype(device) device);
22 std::string GetBrandString() final;
23
24 RGLSwapchainPtr CreateSwapchain(RGLSurfacePtr, RGLCommandQueuePtr presentQueue, int, int) final;
25
26 RGLPipelineLayoutPtr CreatePipelineLayout(const PipelineLayoutDescriptor&) final;
27 RGLRenderPipelinePtr CreateRenderPipeline(const RenderPipelineDescriptor&) final;
28 RGLComputePipelinePtr CreateComputePipeline(const struct ComputePipelineDescriptor&) final;
29
30 RGLShaderLibraryPtr CreateShaderLibraryFromName(const std::string_view& name) final;
31 RGLShaderLibraryPtr CreateDefaultShaderLibrary() final;
32 RGLShaderLibraryPtr CreateShaderLibraryFromBytes(const std::span<const uint8_t>) final;
33 RGLShaderLibraryPtr CreateShaderLibrarySourceCode(const std::string_view, const FromSourceConfig& config) final;
34 RGLShaderLibraryPtr CreateShaderLibraryFromPath(const std::filesystem::path&) final;
35
36 RGLBufferPtr CreateBuffer(const BufferConfig&) final;
37 RGLTexturePtr CreateTextureWithData(const TextureConfig&, const TextureUploadData&) final;
38 RGLTexturePtr CreateTexture(const TextureConfig&) final;
39 RGLSamplerPtr CreateSampler(const SamplerConfig&) final;
40
41 RGLCommandQueuePtr CreateCommandQueue(QueueType type) final;
42
43 TextureView GetGlobalBindlessTextureHeap() const final;
44
45 DeviceData GetDeviceData() final;
46
47 RGLFencePtr CreateFence(bool preSignaled) final;
48 void BlockUntilIdle() final;
49
50 size_t GetTotalVRAM() const final;
51 size_t GetCurrentVRAMInUse() const final;
52
53 FreeList<uint32_t, 2048> textureFreelist;
54 FreeList<uint32_t, 65536> bufferFreelist;
55
56 virtual ~DeviceMTL(){}
57 };
58
59 RGLDevicePtr CreateDefaultDeviceMTL();
60}
61
62#endif