TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
metal_rhi.h
Go to the documentation of this file.
1#pragma once
2
3// Inside the Metal backend: the GUI's pipelines, and a window frame's recording surface for the
4// PrimitiveRenderer (RHI::RenderCommandList).
5
8
9namespace tachyon::metal
10{
14
18 {
20 size_t offset = 0;
22 std::vector<Buffer> retired;
23
26 {
27 for (Buffer& old : retired)
28 device.ReleaseBuffer(old);
29 retired.clear();
30 offset = 0;
31 }
32 };
33
35 {
36 public:
37 MetalCommandList(MetalGraphicsContext::Impl& device, id<MTLRenderCommandEncoder> encoder, FrameArena& arena)
38 : m_device(device), m_encoder(encoder), m_arena(arena) {}
39
41 DeviceAddress Push(const void* data, size_t bytes, size_t alignment);
44 void Bind(NSUInteger index, DeviceAddress address);
45
46 void DrawPrimitives(const RHI::GpuPipeline& pipeline, const GPUDrawPushConstants& pushConstants,
47 uint32_t primitiveCount, uint32_t firstPrimitive, PrimitiveShape shape,
48 std::span<const std::byte> primitives) override;
49 void UploadTransientBuffers(std::span<const RHI::UploadRequest> requests, std::span<DeviceAddress> addresses) override;
50 RHI::ResidentBufferId UploadResidentBuffers(std::span<const RHI::UploadRequest> requests,
51 std::span<DeviceAddress> addresses) override;
54
55 private:
57 id<MTLRenderCommandEncoder> m_encoder;
58 FrameArena& m_arena;
60 std::array<DeviceAddress, 10> m_bound {};
61 std::array<bool, 10> m_boundValid {};
62 uint64_t m_pipeline = 0;
63 };
64}
One frame's recording surface for one window.
Definition gui_rhi.h:62
void UploadTransientBuffers(std::span< const RHI::UploadRequest > requests, std::span< DeviceAddress > addresses) override
DeviceAddress Push(const void *data, size_t bytes, size_t alignment)
Writes bytes into the arena, alignment apart; the address of the copy, or 0.
void DrawPrimitives(const RHI::GpuPipeline &pipeline, const GPUDrawPushConstants &pushConstants, uint32_t primitiveCount, uint32_t firstPrimitive, PrimitiveShape shape, std::span< const std::byte > primitives) override
Binds the pipeline and the GUI image set, pushes the constants and draws primitiveCount primitives st...
RHI::ResidentState ResidentBufferState(RHI::ResidentBufferId id) const override
void Bind(NSUInteger index, DeviceAddress address)
Binds a buffer the shaders read at index in both stages, as the address names it; the empty buffer fo...
MetalCommandList(MetalGraphicsContext::Impl &device, id< MTLRenderCommandEncoder > encoder, FrameArena &arena)
Definition metal_rhi.h:37
void ReleaseResidentBuffer(RHI::ResidentBufferId id) override
Frees the buffer once no frame in flight reads it; an unknown id does nothing.
RHI::ResidentBufferId UploadResidentBuffers(std::span< const RHI::UploadRequest > requests, std::span< DeviceAddress > addresses) override
uint64_t ResidentBufferId
GPU storage kept across frames (UploadResidentBuffers); 0 is none.
Definition gui_rhi.h:36
uint64_t DeviceAddress
Shader-visible buffer address.
Definition gui_render_primitives.h:206
ResidentState
Where a resident buffer is.
Definition gui_rhi.h:40
PrimitiveShape
The vertices a primitive's vertex shader is run for; gl_VertexIndex divided by their count is the pri...
Definition gui_render_primitives.h:225
Definition metal_device.h:40
bool CreatePipelines(MetalGraphicsContext::Impl &device)
A pipeline per primitive kind from the built-in shaders (Metal Shading Language source,...
Definition gui_render_primitives.h:257
Definition gui_rhi.h:22
A buffer the CPU writes and the GPU reads (shared storage), and its handle for addresses.
Definition metal_device.h:74
A frame slot's transient data: one buffer, written from the start each time the slot comes round,...
Definition metal_rhi.h:18
Buffer buffer
Definition metal_rhi.h:19
std::vector< Buffer > retired
Buffers outgrown this frame: their addresses stay valid until the slot comes round.
Definition metal_rhi.h:22
size_t offset
Definition metal_rhi.h:20
void Reset(MetalGraphicsContext::Impl &device)
The slot again, its last frame done: writes start over, the outgrown buffers go.
Definition metal_rhi.h:25
Definition metal_device.h:134
void ReleaseBuffer(Buffer &buffer)
Its handle given back: draws recorded with it keep the buffer (Metal holds it).