TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
tachyon::metal::MetalGraphicsContext::Impl Struct Reference

#include <gui_core/graphics/metal/metal_device.h>

Classes

struct  Garbage
struct  ImageUpload
 A whole image's pixels, or with partial a band of rows from firstRow written into an image already up (UpdateImageRows): its other rows are kept. More...
struct  Scene
 What RenderScene keeps for a key: its color texture (in the image set) and depth, both in liveImages. More...
struct  SceneRequest

Public Member Functions

uint64_t Commit (id< MTLCommandBuffer > commandBuffer)
 Commits commandBuffer and counts it; its value.
void Wait (uint64_t value)
 Waits on the CPU until the commit counted value (and every one before) is done.
void WaitIdle ()
 Waits until everything committed so far is done.
uint64_t Completed ()
 The highest value all commits up to are done.
Buffer CreateBuffer (size_t size)
 A shared buffer the shaders can read, with a handle. Empty on failure.
void ReleaseBuffer (Buffer &buffer)
 Its handle given back: draws recorded with it keep the buffer (Metal holds it).
std::pair< id< MTLBuffer >, NSUInteger > Resolve (DeviceAddress address) const
 The buffer and offset an address names; nil for 0 or a buffer let go of.
void DestroyAfterGpu (std::unique_ptr< MetalImage > image, uint64_t afterValue)
 What's let go is freed once the GPU is past afterValue: the next commit (submitted + 1) for anything a window frame being recorded may use.
void DestroyAfterGpu (id< MTLResource > resource, uint64_t afterValue)
void FlushDeletions ()
 Frees what the GPU is done with.
void RecordPendingUploads (id< MTLCommandBuffer > commandBuffer)
 Records the queued image copies into commandBuffer, ahead of its draws.
RHI::ResidentBufferId CreateResidentBuffer (std::span< const RHI::UploadRequest > requests, std::span< DeviceAddress > addresses)
RHI::ResidentState ResidentState (RHI::ResidentBufferId id) const
void ReleaseResident (RHI::ResidentBufferId id)
bool EnsureQuadIndices (uint32_t quads)
 Grows the quads' index buffer to hold quads; false when it can't.
void RecordScenes (id< MTLCommandBuffer > commandBuffer, ID window)
 Records the scenes asked for in window this frame, before its UI.
MetalImage * CreateTargetImage (uint2 size, MTLPixelFormat format, MTLTextureUsage usage, Sampler sampler)
 A texture the GPU draws into (a scene's), in liveImages so DestroyImageAtEnd frees it; null on failure.

Public Attributes

ExternalDevice external
 the host's device and queue, when it gave them
std::string gpuPreference
std::string deviceName
uint32_t imageSlots = 4096
 asked for with SetImageSlotCount
id< MTLDevice > device = nil
id< MTLCommandQueue > queue = nil
std::atomic< uint64_t > submitted = 0
 Every commit counts the next value: submitted is the last one.
std::mutex inFlightMutex
 The command buffers committed and not seen complete, oldest first.
std::deque< std::pair< uint64_t, id< MTLCommandBuffer > > > inFlight
uint64_t completed = 0
std::atomic< bool > removed = false
 A command buffer failed in a way that loses the device: told once, and the GUI is told through DeviceLost.
std::unordered_map< uint32_t, id< MTLBuffer > > buffers
 Every buffer the shaders read, by its handle (Buffer::handle); handles are never handed out twice.
uint32_t nextBufferHandle = 1
std::mutex garbageMutex
 images are let go on any thread
std::vector< Garbage > garbage
std::mutex uploadMutex
 images are made on any thread
std::vector< ImageUpload > imageUploads
std::vector< ImageUpload > uploadScratch
std::unordered_map< RHI::ResidentBufferId, Buffer > residents
 Shared memory: written at once and never again, so ready for the draws recorded from now on.
RHI::ResidentBufferId nextResident = 1
std::unordered_set< MetalImage * > liveImages
 Every image made and not let go for a frame (DeviceScope::Frame): those handed over for the application's lifetime too.
MetalImageSet imageSet
RHI::ResidentBufferId boxStyles = 0
 The box styles (a resident buffer), made again when they change; 0: none.
RHI::ResidentBufferId colorStyles = 0
 The color styles, with their gradient pages' slots, likewise.
std::vector< ImageIndex > gradientPages
 each gradient page's index in the image set
StyleManager * lastStyles = nullptr
 PrepareFrame's, for a live resize's redraw.
GradientManager * lastGradients = nullptr
float lastTime = 0.0f
std::vector< id< MTLRenderPipelineState > > pipelineStates
 By PrimitiveKind; GpuPipeline::pipeline is the id<MTLRenderPipelineState>, unretained.
std::array< RHI::GpuPipeline, kPrimitiveKindCount > pipelines {}
id< MTLDepthStencilState > depthTest = nil
 GREATER_EQUAL, no writes.
id< MTLDepthStencilState > depthWrite = nil
 GREATER_EQUAL, writes (occluders).
std::array< id< MTLSamplerState >, 3 > samplers {}
 SamplerSlot's order.
id< MTLBuffer > quadIndices = nil
 p * 4 + { 0, 1, 3, 0, 3, 2 } for each quad p.
uint32_t quadCapacity = 0
id< MTLBuffer > emptyBuffer = nil
 Bound where a draw's buffer address is 0, so every buffer the shaders declare is bound.
GPUDrawPushConstants pushConstants {}
 the styles' addresses and the time, from PrepareFrame
std::unordered_map< ID, Scene > scenes
std::vector< SceneRequest > sceneRequests
uint64_t sceneFrame = 0
std::unordered_map< uint32_t, std::unique_ptr< MetalImage > > externalImages
 By image index: what the image set points at for a host's texture.

Static Public Attributes

static constexpr MTLPixelFormat kSceneColorFormat = MTLPixelFormatRGBA8Unorm
static constexpr uint64_t kSceneKeepFrames = 4
 a scene not asked for this long goes

Member Function Documentation

◆ Commit()

uint64_t tachyon::metal::MetalGraphicsContext::Impl::Commit ( id< MTLCommandBuffer > commandBuffer)

Commits commandBuffer and counts it; its value.

◆ Wait()

void tachyon::metal::MetalGraphicsContext::Impl::Wait ( uint64_t value)

Waits on the CPU until the commit counted value (and every one before) is done.

◆ WaitIdle()

void tachyon::metal::MetalGraphicsContext::Impl::WaitIdle ( )

Waits until everything committed so far is done.

◆ Completed()

uint64_t tachyon::metal::MetalGraphicsContext::Impl::Completed ( )

The highest value all commits up to are done.

◆ CreateBuffer()

Buffer tachyon::metal::MetalGraphicsContext::Impl::CreateBuffer ( size_t size)

A shared buffer the shaders can read, with a handle. Empty on failure.

◆ ReleaseBuffer()

void tachyon::metal::MetalGraphicsContext::Impl::ReleaseBuffer ( Buffer & buffer)

Its handle given back: draws recorded with it keep the buffer (Metal holds it).

◆ Resolve()

std::pair< id< MTLBuffer >, NSUInteger > tachyon::metal::MetalGraphicsContext::Impl::Resolve ( DeviceAddress address) const

The buffer and offset an address names; nil for 0 or a buffer let go of.

◆ DestroyAfterGpu() [1/2]

void tachyon::metal::MetalGraphicsContext::Impl::DestroyAfterGpu ( std::unique_ptr< MetalImage > image,
uint64_t afterValue )

What's let go is freed once the GPU is past afterValue: the next commit (submitted + 1) for anything a window frame being recorded may use.

◆ DestroyAfterGpu() [2/2]

void tachyon::metal::MetalGraphicsContext::Impl::DestroyAfterGpu ( id< MTLResource > resource,
uint64_t afterValue )

◆ FlushDeletions()

void tachyon::metal::MetalGraphicsContext::Impl::FlushDeletions ( )

Frees what the GPU is done with.

◆ RecordPendingUploads()

void tachyon::metal::MetalGraphicsContext::Impl::RecordPendingUploads ( id< MTLCommandBuffer > commandBuffer)

Records the queued image copies into commandBuffer, ahead of its draws.

◆ CreateResidentBuffer()

RHI::ResidentBufferId tachyon::metal::MetalGraphicsContext::Impl::CreateResidentBuffer ( std::span< const RHI::UploadRequest > requests,
std::span< DeviceAddress > addresses )

◆ ResidentState()

RHI::ResidentState tachyon::metal::MetalGraphicsContext::Impl::ResidentState ( RHI::ResidentBufferId id) const

◆ ReleaseResident()

void tachyon::metal::MetalGraphicsContext::Impl::ReleaseResident ( RHI::ResidentBufferId id)

◆ EnsureQuadIndices()

bool tachyon::metal::MetalGraphicsContext::Impl::EnsureQuadIndices ( uint32_t quads)

Grows the quads' index buffer to hold quads; false when it can't.

◆ RecordScenes()

void tachyon::metal::MetalGraphicsContext::Impl::RecordScenes ( id< MTLCommandBuffer > commandBuffer,
ID window )

Records the scenes asked for in window this frame, before its UI.

◆ CreateTargetImage()

MetalImage * tachyon::metal::MetalGraphicsContext::Impl::CreateTargetImage ( uint2 size,
MTLPixelFormat format,
MTLTextureUsage usage,
Sampler sampler )

A texture the GPU draws into (a scene's), in liveImages so DestroyImageAtEnd frees it; null on failure.

Member Data Documentation

◆ external

ExternalDevice tachyon::metal::MetalGraphicsContext::Impl::external

the host's device and queue, when it gave them

◆ gpuPreference

std::string tachyon::metal::MetalGraphicsContext::Impl::gpuPreference

◆ deviceName

std::string tachyon::metal::MetalGraphicsContext::Impl::deviceName

◆ imageSlots

uint32_t tachyon::metal::MetalGraphicsContext::Impl::imageSlots = 4096

asked for with SetImageSlotCount

◆ device

id<MTLDevice> tachyon::metal::MetalGraphicsContext::Impl::device = nil

◆ queue

id<MTLCommandQueue> tachyon::metal::MetalGraphicsContext::Impl::queue = nil

◆ submitted

std::atomic<uint64_t> tachyon::metal::MetalGraphicsContext::Impl::submitted = 0

Every commit counts the next value: submitted is the last one.

Atomic: DestroyImageAtEnd, on any thread, reads it.

◆ inFlightMutex

std::mutex tachyon::metal::MetalGraphicsContext::Impl::inFlightMutex

The command buffers committed and not seen complete, oldest first.

◆ inFlight

std::deque<std::pair<uint64_t, id<MTLCommandBuffer> > > tachyon::metal::MetalGraphicsContext::Impl::inFlight

◆ completed

uint64_t tachyon::metal::MetalGraphicsContext::Impl::completed = 0

◆ removed

std::atomic<bool> tachyon::metal::MetalGraphicsContext::Impl::removed = false

A command buffer failed in a way that loses the device: told once, and the GUI is told through DeviceLost.

◆ buffers

std::unordered_map<uint32_t, id<MTLBuffer> > tachyon::metal::MetalGraphicsContext::Impl::buffers

Every buffer the shaders read, by its handle (Buffer::handle); handles are never handed out twice.

◆ nextBufferHandle

uint32_t tachyon::metal::MetalGraphicsContext::Impl::nextBufferHandle = 1

◆ garbageMutex

std::mutex tachyon::metal::MetalGraphicsContext::Impl::garbageMutex

images are let go on any thread

◆ garbage

std::vector<Garbage> tachyon::metal::MetalGraphicsContext::Impl::garbage

◆ uploadMutex

std::mutex tachyon::metal::MetalGraphicsContext::Impl::uploadMutex

images are made on any thread

◆ imageUploads

std::vector<ImageUpload> tachyon::metal::MetalGraphicsContext::Impl::imageUploads

◆ uploadScratch

std::vector<ImageUpload> tachyon::metal::MetalGraphicsContext::Impl::uploadScratch

◆ residents

std::unordered_map<RHI::ResidentBufferId, Buffer> tachyon::metal::MetalGraphicsContext::Impl::residents

Shared memory: written at once and never again, so ready for the draws recorded from now on.

◆ nextResident

RHI::ResidentBufferId tachyon::metal::MetalGraphicsContext::Impl::nextResident = 1

◆ liveImages

std::unordered_set<MetalImage*> tachyon::metal::MetalGraphicsContext::Impl::liveImages

Every image made and not let go for a frame (DeviceScope::Frame): those handed over for the application's lifetime too.

Cleanup frees what's left.

◆ imageSet

MetalImageSet tachyon::metal::MetalGraphicsContext::Impl::imageSet

◆ boxStyles

RHI::ResidentBufferId tachyon::metal::MetalGraphicsContext::Impl::boxStyles = 0

The box styles (a resident buffer), made again when they change; 0: none.

◆ colorStyles

RHI::ResidentBufferId tachyon::metal::MetalGraphicsContext::Impl::colorStyles = 0

The color styles, with their gradient pages' slots, likewise.

◆ gradientPages

std::vector<ImageIndex> tachyon::metal::MetalGraphicsContext::Impl::gradientPages

each gradient page's index in the image set

◆ lastStyles

StyleManager* tachyon::metal::MetalGraphicsContext::Impl::lastStyles = nullptr

PrepareFrame's, for a live resize's redraw.

◆ lastGradients

GradientManager* tachyon::metal::MetalGraphicsContext::Impl::lastGradients = nullptr

◆ lastTime

float tachyon::metal::MetalGraphicsContext::Impl::lastTime = 0.0f

◆ pipelineStates

std::vector<id<MTLRenderPipelineState> > tachyon::metal::MetalGraphicsContext::Impl::pipelineStates

By PrimitiveKind; GpuPipeline::pipeline is the id<MTLRenderPipelineState>, unretained.

◆ pipelines

std::array<RHI::GpuPipeline, kPrimitiveKindCount> tachyon::metal::MetalGraphicsContext::Impl::pipelines {}

◆ depthTest

id<MTLDepthStencilState> tachyon::metal::MetalGraphicsContext::Impl::depthTest = nil

GREATER_EQUAL, no writes.

◆ depthWrite

id<MTLDepthStencilState> tachyon::metal::MetalGraphicsContext::Impl::depthWrite = nil

GREATER_EQUAL, writes (occluders).

◆ samplers

std::array<id<MTLSamplerState>, 3> tachyon::metal::MetalGraphicsContext::Impl::samplers {}

SamplerSlot's order.

◆ quadIndices

id<MTLBuffer> tachyon::metal::MetalGraphicsContext::Impl::quadIndices = nil

p * 4 + { 0, 1, 3, 0, 3, 2 } for each quad p.

◆ quadCapacity

uint32_t tachyon::metal::MetalGraphicsContext::Impl::quadCapacity = 0

◆ emptyBuffer

id<MTLBuffer> tachyon::metal::MetalGraphicsContext::Impl::emptyBuffer = nil

Bound where a draw's buffer address is 0, so every buffer the shaders declare is bound.

◆ pushConstants

GPUDrawPushConstants tachyon::metal::MetalGraphicsContext::Impl::pushConstants {}

the styles' addresses and the time, from PrepareFrame

◆ kSceneColorFormat

MTLPixelFormat tachyon::metal::MetalGraphicsContext::Impl::kSceneColorFormat = MTLPixelFormatRGBA8Unorm
staticconstexpr

◆ kSceneKeepFrames

uint64_t tachyon::metal::MetalGraphicsContext::Impl::kSceneKeepFrames = 4
staticconstexpr

a scene not asked for this long goes

◆ scenes

std::unordered_map<ID, Scene> tachyon::metal::MetalGraphicsContext::Impl::scenes

◆ sceneRequests

std::vector<SceneRequest> tachyon::metal::MetalGraphicsContext::Impl::sceneRequests

◆ sceneFrame

uint64_t tachyon::metal::MetalGraphicsContext::Impl::sceneFrame = 0

◆ externalImages

std::unordered_map<uint32_t, std::unique_ptr<MetalImage> > tachyon::metal::MetalGraphicsContext::Impl::externalImages

By image index: what the image set points at for a host's texture.


The documentation for this struct was generated from the following file: