20 size_t cell_stride_bytes,
24 static_cast<size_t>(
width) *
height * sizeof(Kakshya::Vertex),
26 Kakshya::DataModality::VERTEX_POSITIONS_3D)
29 , m_cell_stride_bytes(cell_stride_bytes)
30 , m_rule_source(
std::move(rule_source))
31 , m_emit_source(
std::move(emit_source))
36 if (!buffer_service) {
37 error<std::runtime_error>(
40 std::source_location::current(),
41 "RelaxationGridBuffer requires a valid BufferService");
45 const auto usage_flags =
static_cast<uint32_t
>(
46 VkBufferUsageFlags(vk::BufferUsageFlagBits::eStorageBuffer));
47 const auto memory_flags =
static_cast<uint32_t
>(
48 VkMemoryPropertyFlags(vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent));
51 resources.back_buffers.resize(2);
53 for (uint32_t i = 0; i < 2; ++i) {
54 void* out_buffer =
nullptr;
55 void* out_memory =
nullptr;
56 void* out_mapped =
nullptr;
58 buffer_service->allocate_raw_buffer(
59 state_bytes, usage_flags, memory_flags,
true,
60 out_buffer, out_memory, out_mapped);
62 resources.back_buffers[i].buffer =
static_cast<vk::Buffer
>(
static_cast<VkBuffer
>(out_buffer));
63 resources.back_buffers[i].memory =
static_cast<vk::DeviceMemory
>(
static_cast<VkDeviceMemory
>(out_memory));
64 resources.back_buffers[i].mapped_ptr = out_mapped;
68 "RelaxationGridBuffer: {}x{} grid, {} bytes/cell, {} bytes/generation",
79 [](
const auto& src) {
return std::make_shared<RelaxationStepProcessor>(src); },
87 chain = std::make_shared<BufferProcessingChain>();
90 chain->set_preferred_token(token);
93 [](
const auto& src) {
return std::make_shared<RelaxationEmitProcessor>(src); },
99 "RelaxationGridBuffer setup_processors: step + emit attached");
118 "RelaxationGridBuffer: rendering configured");
125 "seed_state size {} does not match expected {}", size,
get_state_bytes());
130 auto& front = resources.back_buffers[
front_index()];
132 if (!front.mapped_ptr) {
134 "seed_state: front generation buffer has no mapped pointer");
138 std::memcpy(front.mapped_ptr, data, size);
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
void setup_rendering(const RenderConfig &config)
Attach a RenderProcessor drawing the emitted vertex output as ordinary untextured point geometry.
std::shared_ptr< RelaxationEmitProcessor > m_emit_processor
Emit stage, retained for parameter access.
ShaderSource m_emit_source
Either a path to a hand-written emit shader or a generated ShaderSpec.
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.
void setup_processors(ProcessingToken token) override
Create and attach RelaxationStepProcessor (default processor) and RelaxationEmitProcessor (flat proce...
void seed_state(const void *data, size_t size)
Write initial state directly into the current front generation.
uint32_t get_cell_count() const
Total cell count, width * height.
std::shared_ptr< RelaxationStepProcessor > m_step_processor
Rule stage, retained for parameter access.
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.
uint32_t m_width
Grid width in cells.
ShaderSource m_rule_source
Either a path to a hand-written rule shader or a generated ShaderSpec.
std::variant< std::string, Portal::Graphics::ShaderSpec > ShaderSource
Either a shader file path or a generated ShaderSpec, resolved at construction time by setup_processor...
uint32_t front_index() const
Index into m_resources.back_buffers currently holding the most recently completed generation's state.
uint32_t m_height
Grid height in cells.
void set_vertex_layout(const Kakshya::VertexLayout &layout)
Set vertex layout for this buffer.
std::shared_ptr< Buffers::BufferProcessingChain > get_processing_chain() override
Access the buffer's processing chain.
void set_default_processor(const std::shared_ptr< BufferProcessor > &processor) override
Set the buffer's default processor.
void set_processing_chain(const std::shared_ptr< BufferProcessingChain > &chain, bool force=false) override
Replace the buffer's processing chain.
void apply_render_config(const RenderConfig &config, const ShaderConfig &shader_config)
Configure the internal m_render_processor from a RenderConfig.
std::shared_ptr< RenderProcessor > m_render_processor
const VKBufferResources & get_buffer_resources() const
Get all buffer resources at once (read-only)
Vulkan-backed buffer wrapper used in processing chains.
Interface * get_service()
Query for a backend service.
static BackendRegistry & instance()
Get the global registry instance.
ProcessingToken
Bitfield enum defining processing characteristics and backend requirements for buffer operations.
@ BufferManagement
Buffer Management (Buffers::BufferManager, creating buffers)
@ Init
Engine/subsystem initialization.
@ Buffers
Buffers, Managers, processors and processing chains.
BufferUsageHint
Semantic usage hint for buffer allocation and memory properties.
static VertexLayout for_raw(uint32_t stride=60)
Factory: layout for raw vertex data with common attributes.
Type-neutral vertex carrying the universal 60-byte attribute layout.
PrimitiveTopology topology
std::string vertex_shader
std::string fragment_shader
Unified rendering configuration for graphics buffers.
Backend buffer management service interface.