MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ RelaxationGridBuffer() [1/2]

MayaFlux::Buffers::RelaxationGridBuffer::RelaxationGridBuffer ( uint32_t  width,
uint32_t  height,
size_t  cell_stride_bytes,
ShaderSource  rule_source,
ShaderSource  emit_source 
)

Construct an unregistered double-buffered grid buffer.

Parameters
widthGrid width in cells.
heightGrid height in cells.
cell_stride_bytesSize in bytes of one cell's state.
rule_sourceEither a path to a hand-written rule shader (for rules needing branchy multi-state logic, e.g. Conway, Wireworld) or a generated ShaderSpec (e.g. RelaxationSpecs::jacobi_diffusion()).
emit_sourceEither a path to a hand-written emit shader, or a generated ShaderSpec that meets the packed vertex contract.

rule_source and emit_source are independent: any pairing meeting their respective contracts is supported. Processors are constructed from whichever alternative each holds in setup_processors().

Definition at line 132 of file RelaxationGridBuffer.cpp.

138 : VKBuffer(
139 static_cast<size_t>(width) * height * sizeof(Kakshya::Vertex),
140 Usage::VERTEX,
142 , m_width(width)
144 , m_cell_stride_bytes(cell_stride_bytes)
145 , m_rule_source(std::move(rule_source))
146 , m_emit_source(std::move(emit_source))
147{
148 auto buffer_service = Registry::BackendRegistry::instance()
149 .get_service<Registry::Service::BufferService>();
150
151 if (!buffer_service) {
152 error<std::runtime_error>(
155 std::source_location::current(),
156 "RelaxationGridBuffer requires a valid BufferService");
157 }
158
159 const size_t state_bytes = get_state_bytes();
160 const auto usage_flags = static_cast<uint32_t>(
161 VkBufferUsageFlags(vk::BufferUsageFlagBits::eStorageBuffer));
162 const auto memory_flags = static_cast<uint32_t>(
163 VkMemoryPropertyFlags(vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent));
164
165 auto& resources = get_buffer_resources();
166 resources.back_buffers.resize(2);
167
168 for (uint32_t i = 0; i < 2; ++i) {
169 void* out_buffer = nullptr;
170 void* out_memory = nullptr;
171 void* out_mapped = nullptr;
172
173 buffer_service->allocate_raw_buffer(
174 state_bytes, usage_flags, memory_flags, true,
175 out_buffer, out_memory, out_mapped);
176
177 resources.back_buffers[i].buffer = static_cast<vk::Buffer>(static_cast<VkBuffer>(out_buffer));
178 resources.back_buffers[i].memory = static_cast<vk::DeviceMemory>(static_cast<VkDeviceMemory>(out_memory));
179 resources.back_buffers[i].mapped_ptr = out_mapped;
180 }
181
183 "RelaxationGridBuffer: {}x{} grid, {} bytes/cell, {} bytes/generation",
184 m_width, m_height, m_cell_stride_bytes, state_bytes);
185}
#define MF_INFO(comp, ctx,...)
uint32_t width
uint32_t height
const ShaderSource & rule_source() const
The rule source this buffer was constructed with: either a hand-written shader path or a generated Sh...
ShaderSource m_emit_source
Either a path to a hand-written emit shader or a generated ShaderSpec.
size_t get_state_bytes() const
Total byte size of one generation's state buffer.
size_t m_cell_stride_bytes
Size in bytes of one cell's state, fixed at construction.
ShaderSource m_rule_source
Either a path to a hand-written rule shader or a generated ShaderSpec.
const ShaderSource & emit_source() const
The emit source this buffer was constructed with.
const VKBufferResources & get_buffer_resources() const
Get all buffer resources at once (read-only)
Definition VKBuffer.hpp:343
Interface * get_service()
Query for a backend service.
static BackendRegistry & instance()
Get the global registry instance.
@ BufferManagement
Buffer Management (Buffers::BufferManager, creating buffers)
@ Init
Engine/subsystem initialization.
@ Buffers
Buffers, Managers, processors and processing chains.

References MayaFlux::Journal::BufferManagement, MayaFlux::Journal::Buffers, MayaFlux::Buffers::VKBuffer::get_buffer_resources(), MayaFlux::Registry::BackendRegistry::get_service(), get_state_bytes(), MayaFlux::Journal::Init, MayaFlux::Registry::BackendRegistry::instance(), m_cell_stride_bytes, m_height, m_width, and MF_INFO.

+ Here is the call graph for this function: