MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
BufferService.hpp
Go to the documentation of this file.
1#pragma once
2
4
5/**
6 * @brief Backend buffer management service interface
7 *
8 * Defines GPU/backend buffer operations that any graphics backend must provide.
9 * Implementations are backend-specific (Vulkan, OpenGL, Metal, DirectX, etc.).
10 * All handles are opaque to maintain backend independence while providing type safety.
11 */
12struct MAYAFLUX_API BufferService {
13 /**
14 * @brief Initialize a buffer object
15 * @param buffer Buffer handle to initialize
16 */
17 std::function<void(const std::shared_ptr<void>&)> initialize_buffer;
18
19 /**
20 * @brief Destroy a buffer and free its associated memory
21 * @param buffer Buffer handle to destroy
22 *
23 * Automatically handles cleanup of both buffer and memory resources.
24 * Safe to call with invalid/null handles (no-op).
25 */
26 std::function<void(const std::shared_ptr<void>&)> destroy_buffer;
27
28 /**
29 * @brief Map buffer memory to host-visible pointer
30 * @param memory Memory handle to map
31 * @param offset Offset in bytes from memory start
32 * @param size Size in bytes to map (or 0 for entire range)
33 * @return Host-visible pointer to mapped memory
34 *
35 * Only valid for host-visible memory. Pointer remains valid until
36 * unmap_buffer() is called. Multiple maps of the same memory are
37 * backend-specific behavior.
38 */
39 std::function<void*(void*, size_t, size_t)> map_buffer;
40
41 /**
42 * @brief Unmap previously mapped buffer memory
43 * @param memory Memory handle to unmap
44 *
45 * Invalidates the pointer returned by map_buffer(). Host writes may
46 * not be visible to device until flush_range() is called.
47 */
48 std::function<void(void*)> unmap_buffer;
49
50 /**
51 * @brief Flush mapped memory range (make host writes visible to device)
52 * @param memory Memory handle
53 * @param offset Offset in bytes
54 * @param size Size in bytes to flush (or 0 for entire mapped range)
55 *
56 * Required for non-coherent host-visible memory after CPU writes.
57 * For coherent memory, this is typically a no-op but may still
58 * provide ordering guarantees.
59 */
60 std::function<void(void*, size_t, size_t)> flush_range;
61
62 /**
63 * @brief Invalidate mapped memory range (make device writes visible to host)
64 * @param memory Memory handle
65 * @param offset Offset in bytes
66 * @param size Size in bytes to invalidate (or 0 for entire mapped range)
67 *
68 * Required for non-coherent host-visible memory before CPU reads.
69 * Ensures device writes are visible to the host.
70 */
71 std::function<void(void*, size_t, size_t)> invalidate_range;
72
73 /**
74 * @brief Execute commands immediately with synchronization
75 * @param recorder Lambda that records commands into command buffer
76 *
77 * The backend handles:
78 * - Command buffer allocation
79 * - Begin/end recording
80 * - Queue submission
81 * - Fence wait for completion
82 *
83 * Blocks until GPU operations complete. Thread-safe.
84 *
85 * Example:
86 * service->execute_immediate([&](CommandBuffer cmd) {
87 * // Record copy, clear, or other operations
88 * });
89 */
90 std::function<void(std::function<void(void*)>)> execute_immediate;
91
92 /**
93 * @brief Record commands for deferred execution
94 * @param recorder Lambda that records commands into command buffer
95 *
96 * Commands are batched and submitted later by backend for optimal
97 * performance. Does not block. Thread-safe.
98 *
99 * Use for operations where immediate completion is not required.
100 * Backend determines when to flush batched commands.
101 */
102 std::function<void(std::function<void(void*)>)> record_deferred;
103};
104
105} // namespace MayaFlux::Registry::Services
std::function< void(const std::shared_ptr< void > &)> initialize_buffer
Initialize a buffer object.
std::function< void(void *)> unmap_buffer
Unmap previously mapped buffer memory.
std::function< void(const std::shared_ptr< void > &)> destroy_buffer
Destroy a buffer and free its associated memory.
std::function< void(void *, size_t, size_t)> invalidate_range
Invalidate mapped memory range (make device writes visible to host)
std::function< void(void *, size_t, size_t)> flush_range
Flush mapped memory range (make host writes visible to device)
std::function< void(std::function< void(void *)>)> record_deferred
Record commands for deferred execution.
std::function< void(std::function< void(void *)>)> execute_immediate
Execute commands immediately with synchronization.
Backend buffer management service interface.