16 const std::shared_ptr<Core::VulkanBackend>& backend,
21 "ShaderFoundry already initialized (static flag)");
27 "Cannot initialize ShaderFoundry with null backend");
33 "ShaderFoundry already initialized");
54 "ShaderFoundry initialized");
65 "Stopping ShaderFoundry - freeing command buffers...");
74 "ShaderFoundry stopped - command buffers freed");
88 "Shutting down ShaderFoundry...");
92 "{} command buffers still exist during shutdown - freeing now",
107 "ShaderFoundry shutdown complete");
115 const std::string& filepath,
116 std::optional<ShaderStage> stage,
117 const std::string& entry_point)
121 "ShaderFoundry not initialized");
128 "Using cached shader: {}", filepath);
132 std::optional<vk::ShaderStageFlagBits> vk_stage;
133 if (stage.has_value()) {
139 if (filepath.ends_with(
".spv")) {
140 if (!shader->create_from_spirv_file(
142 vk_stage.value_or(vk::ShaderStageFlagBits::eCompute),
145 "Failed to compile SPIR-V shader: {}", filepath);
149 if (!shader->create_from_glsl_file(
150 get_device(), filepath, vk_stage, entry_point,
154 "Failed to compile GLSL shader: {}", filepath);
161 "Compiled shader: {} ({})", filepath, vk::to_string(shader->get_stage()));
166 const std::string& source,
168 const std::string& entry_point)
172 "ShaderFoundry not initialized");
179 if (!shader->create_from_glsl(
184 "Failed to compile GLSL source");
189 "Compiled shader from source ({})", vk::to_string(vk_stage));
194 const std::string& source,
196 const std::string& cache_key,
197 const std::string& entry_point)
202 "Using cached shader: {}", cache_key);
216 const std::string& spirv_path,
218 const std::string& entry_point)
222 "ShaderFoundry not initialized");
229 "Using cached SPIR-V shader: {}", spirv_path);
236 if (!shader->create_from_spirv_file(
237 get_device(), spirv_path, vk_stage, entry_point,
240 "Failed to load SPIR-V shader: {}", spirv_path);
246 "Loaded SPIR-V shader: {}", spirv_path);
251 const std::string& spirv_asm,
253 const std::string& entry_point)
256 if (!shader->create_from_spirv_asm(
260 "Failed to assemble generated SPIR-V");
268 switch (shader_source.
type) {
283 "Unknown shader source type");
289 const std::string& content,
290 std::optional<ShaderStage> stage,
291 const std::string& entry_point)
295 "ShaderFoundry not initialized");
301 std::string cache_key;
311 "Using cached shader ID for: {}", cache_key);
312 return id_it->second;
315 if (!stage.has_value()) {
318 std::filesystem::path p(content);
319 std::string stem = p.stem().string();
326 if (!stage.has_value()) {
328 "Cannot auto-detect shader stage from '{}' - must specify explicitly",
334 std::shared_ptr<Core::VKShaderModule> shader_module;
336 switch (source_type) {
348 "Cannot determine shader source type");
352 if (!shader_module) {
359 state.module = shader_module;
361 state.
stage = *stage;
367 "Shader loaded: {} (ID: {}, stage: {})",
368 cache_key,
id,
static_cast<int>(*stage));
375 return load_shader(source.content, source.stage, source.entry_point);
382 "ShaderFoundry not initialized");
386 if (spec.
kernel.has_value()) {
389 auto module = compile_from_source_cached(glsl, ShaderStage::COMPUTE, key);
392 "Failed to compile kernel shader");
397 state.module =
module;
398 state.filepath = key;
400 state.entry_point =
"main";
403 "Compiled kernel shader (ID: {}, key: {})",
id, key);
413 "Using cached generated shader: {}", key);
414 return id_it->second;
417 auto module = compile_from_spirv_asm(asm_text, ShaderStage::COMPUTE);
420 "Failed to compile generated shader (key: {})", key);
426 state.module =
module;
427 state.filepath = key;
429 state.entry_point =
"main";
434 "Compiled generated shader (ID: {}, key: {})",
id, key);
441 namespace fs = std::filesystem;
443 fs::path path(filepath);
445 if (path.is_absolute() || fs::exists(filepath)) {
449 std::vector<std::string> search_paths = {
450 Core::SHADER_BUILD_OUTPUT_DIR,
451 Core::SHADER_INSTALL_DIR,
452 Core::SHADER_SOURCE_DIR,
460 if (std::string_view(Core::SHADER_EXAMPLE_DIR).length() > 0) {
461 search_paths.emplace_back(Core::SHADER_EXAMPLE_DIR);
464#ifdef MAYAFLUX_PROJECT_SHADER_DIR
465 search_paths.emplace_back(MAYAFLUX_PROJECT_SHADER_DIR);
468 for (
const auto& search_path : search_paths) {
469 fs::path full_path = fs::path(search_path) / filepath;
470 if (fs::exists(full_path)) {
482 if (resolved_path.has_value()) {
483 std::string ext = resolved_path->extension().string();
484 std::ranges::transform(ext, ext.begin(), ::tolower);
493 if (content.size() > 1024 || content.find(
'\n') != std::string::npos) {
502 std::hash<std::string> hasher;
503 size_t hash = hasher(source + std::to_string(
static_cast<int>(stage)));
504 return "source_" + std::to_string(hash);
524 if (!it->second.filepath.empty()) {
528 if (it->second.module) {
546 const auto& reflection = it->second.module->get_reflection();
549 info.
stage = it->second.stage;
553 for (
const auto& binding : reflection.bindings) {
555 .binding = binding.binding,
556 .type = binding.type,
557 .name = binding.name });
560 for (
const auto& pc : reflection.push_constants) {
562 pc_info.
offset = pc.offset;
563 pc_info.size = pc.size;
574 return it->second.
stage;
583 return it->second.entry_point;
595 std::vector<std::string> keys;
609 shader_module->cleanup(device);
618 "Cleaned up shader modules");
631 "Invalidated shader cache: {}", cache_key);
639 "Cleared shader cache");
656 "Updated shader compiler configuration");
686 vk::DescriptorType type,
696 vk::DescriptorBufferInfo buffer_info;
697 buffer_info.buffer = buffer;
698 buffer_info.offset =
offset;
699 buffer_info.range = size;
701 vk::WriteDescriptorSet write;
702 write.dstSet = it->second.descriptor_set;
703 write.dstBinding = binding;
704 write.dstArrayElement = 0;
705 write.descriptorCount = 1;
706 write.descriptorType = type;
707 write.pBufferInfo = &buffer_info;
709 get_device().updateDescriptorSets(1, &write, 0,
nullptr);
715 vk::ImageView image_view,
717 vk::ImageLayout layout,
718 uint32_t array_element)
725 vk::DescriptorImageInfo image_info;
726 image_info.imageView = image_view;
727 image_info.sampler = sampler;
728 image_info.imageLayout = layout;
730 vk::WriteDescriptorSet write;
731 write.dstSet = it->second.descriptor_set;
732 write.dstBinding = binding;
733 write.dstArrayElement = array_element;
734 write.descriptorCount = 1;
735 write.descriptorType = vk::DescriptorType::eCombinedImageSampler;
736 write.pImageInfo = &image_info;
738 get_device().updateDescriptorSets(1, &write, 0,
nullptr);
744 vk::ImageView image_view,
745 vk::ImageLayout layout)
752 vk::DescriptorImageInfo image_info;
753 image_info.imageView = image_view;
754 image_info.imageLayout = layout;
756 vk::WriteDescriptorSet write;
757 write.dstSet = it->second.descriptor_set;
758 write.dstBinding = binding;
759 write.dstArrayElement = 0;
760 write.descriptorCount = 1;
761 write.descriptorType = vk::DescriptorType::eStorageImage;
762 write.pImageInfo = &image_info;
764 get_device().updateDescriptorSets(1, &write, 0,
nullptr);
771 error<std::invalid_argument>(
774 std::source_location::current(),
775 "Invalid DescriptorSetID: {}", descriptor_set_id);
777 return it->second.descriptor_set;
792 "Cleaned up descriptor resources");
801 auto& cmd_manager =
m_backend->get_command_manager();
808 ? cmd_manager.begin_single_time_commands_compute()
809 : cmd_manager.begin_single_time_commands();
818 vk::Format color_format,
819 vk::Format depth_format)
821 auto& cmd_manager =
m_backend->get_command_manager();
825 vk::CommandBuffer
cmd = cmd_manager.allocate_command_buffer(vk::CommandBufferLevel::eSecondary);
827 vk::CommandBufferInheritanceRenderingInfo inheritance_rendering;
828 inheritance_rendering.colorAttachmentCount = 1;
829 inheritance_rendering.pColorAttachmentFormats = &color_format;
830 inheritance_rendering.depthAttachmentFormat = depth_format;
831 inheritance_rendering.rasterizationSamples = vk::SampleCountFlagBits::e1;
833 vk::CommandBufferInheritanceInfo inheritance_info;
834 inheritance_info.pNext = &inheritance_rendering;
836 vk::CommandBufferBeginInfo begin_info;
837 begin_info.flags = vk::CommandBufferUsageFlagBits::eRenderPassContinue | vk::CommandBufferUsageFlagBits::eOneTimeSubmit;
838 begin_info.pInheritanceInfo = &inheritance_info;
840 cmd.begin(begin_info);
855 return it->second.cmd;
867 it->second.cmd.end();
868 it->second.is_active =
false;
878 auto& cmd_manager =
m_backend->get_command_manager();
883 if (state.is_active) {
884 cmd_manager.free_command_buffer(state.cmd);
886 if (state.timestamp_pool) {
887 device.destroyQueryPool(state.timestamp_pool);
893 "Freed all command buffers");
907 auto& cmd_manager =
m_backend->get_command_manager();
909 it->second.cmd.end();
911 vk::SubmitInfo submit_info;
912 submit_info.commandBufferCount = 1;
913 submit_info.pCommandBuffers = &it->second.cmd;
916 switch (it->second.type) {
928 if (queue.submit(1, &submit_info,
nullptr) != vk::Result::eSuccess) {
930 "Failed to submit command buffer");
935 cmd_manager.free_command_buffer(it->second.cmd);
937 it->second.is_active =
false;
948 cmd_it->second.cmd.end();
952 vk::FenceCreateInfo fence_info;
956 fence_state.
cmd_id = cmd_id;
958 vk::SubmitInfo submit_info;
959 submit_info.commandBufferCount = 1;
960 submit_info.pCommandBuffers = &cmd_it->second.cmd;
963 switch (cmd_it->second.type) {
975 if (queue.submit(1, &submit_info, fence_state.
fence) != vk::Result::eSuccess) {
977 "Failed to submit command buffer");
981 cmd_it->second.is_active =
false;
993 cmd_it->second.cmd.end();
997 vk::SemaphoreCreateInfo semaphore_info;
1001 vk::SubmitInfo submit_info;
1002 submit_info.commandBufferCount = 1;
1003 submit_info.pCommandBuffers = &cmd_it->second.cmd;
1004 submit_info.signalSemaphoreCount = 1;
1005 submit_info.pSignalSemaphores = &semaphore_state.
semaphore;
1008 switch (cmd_it->second.type) {
1020 if (queue.submit(1, &submit_info,
nullptr) != vk::Result::eSuccess) {
1022 "Failed to submit command buffer");
1026 cmd_it->second.is_active =
false;
1028 return semaphore_id;
1038 if (
get_device().waitForFences(1, &it->second.fence, VK_TRUE, UINT64_MAX) != vk::Result::eSuccess) {
1040 "Failed to wait for fence: {}", fence_id);
1043 it->second.signaled =
true;
1048 std::vector<vk::Fence> fences;
1049 for (
auto fence_id : fence_ids) {
1052 fences.push_back(it->second.fence);
1056 if (!fences.empty()) {
1057 if (
get_device().waitForFences(
static_cast<uint32_t
>(fences.size()), fences.data(), VK_TRUE, UINT64_MAX) != vk::Result::eSuccess) {
1059 "Failed to wait for fences");
1064 for (
auto fence_id : fence_ids) {
1067 it->second.signaled =
true;
1081 if (it->second.fence) {
1083 it->second.fence =
nullptr;
1092 m_backend->get_command_manager().free_command_buffer(cmd_it->second.cmd);
1105 if (it->second.signaled) {
1109 auto result =
get_device().getFenceStatus(it->second.fence);
1110 it->second.signaled = (result == vk::Result::eSuccess);
1111 return it->second.signaled;
1117 vk::PipelineStageFlags )
1131 return it->second.semaphore;
1140 for (
auto& [
id, state] :
m_fences) {
1142 device.destroyFence(state.fence);
1148 if (state.semaphore) {
1149 device.destroySemaphore(state.semaphore);
1155 "Cleaned up sync objects");
1165 vk::AccessFlags src_access,
1166 vk::AccessFlags dst_access,
1167 vk::PipelineStageFlags src_stage,
1168 vk::PipelineStageFlags dst_stage)
1175 vk::BufferMemoryBarrier barrier;
1176 barrier.srcAccessMask = src_access;
1177 barrier.dstAccessMask = dst_access;
1178 barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
1179 barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
1180 barrier.buffer = buffer;
1182 barrier.size = VK_WHOLE_SIZE;
1184 it->second.cmd.pipelineBarrier(
1187 vk::DependencyFlags {},
1196 vk::ImageLayout old_layout,
1197 vk::ImageLayout new_layout,
1198 vk::AccessFlags src_access,
1199 vk::AccessFlags dst_access,
1200 vk::PipelineStageFlags src_stage,
1201 vk::PipelineStageFlags dst_stage)
1208 vk::ImageMemoryBarrier barrier;
1209 barrier.srcAccessMask = src_access;
1210 barrier.dstAccessMask = dst_access;
1211 barrier.oldLayout = old_layout;
1212 barrier.newLayout = new_layout;
1213 barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
1214 barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
1215 barrier.image =
image;
1216 barrier.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor;
1217 barrier.subresourceRange.baseMipLevel = 0;
1218 barrier.subresourceRange.levelCount = 1;
1219 barrier.subresourceRange.baseArrayLayer = 0;
1220 barrier.subresourceRange.layerCount = 1;
1222 it->second.cmd.pipelineBarrier(
1225 vk::DependencyFlags {},
1250 if (!it->second.timestamp_pool) {
1251 vk::QueryPoolCreateInfo pool_info;
1252 pool_info.queryType = vk::QueryType::eTimestamp;
1253 pool_info.queryCount = 128;
1254 it->second.timestamp_pool =
get_device().createQueryPool(pool_info);
1257 auto query_index =
static_cast<uint32_t
>(it->second.timestamp_queries.size() * 2);
1258 it->second.timestamp_queries[label] = query_index;
1260 it->second.cmd.resetQueryPool(it->second.timestamp_pool, query_index, 2);
1261 it->second.cmd.writeTimestamp(vk::PipelineStageFlagBits::eTopOfPipe, it->second.timestamp_pool, query_index);
1271 auto query_it = it->second.timestamp_queries.find(label);
1272 if (query_it == it->second.timestamp_queries.end()) {
1276 uint32_t query_index = query_it->second;
1277 it->second.cmd.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, it->second.timestamp_pool, query_index + 1);
1284 return { .
label = label, .duration_ns = 0, .valid =
false };
1287 auto query_it = it->second.timestamp_queries.find(label);
1288 if (query_it == it->second.timestamp_queries.end()) {
1289 return { .label = label, .duration_ns = 0, .valid =
false };
1292 if (!it->second.timestamp_pool) {
1293 return { .label = label, .duration_ns = 0, .valid =
false };
1296 uint32_t query_index = query_it->second;
1297 uint64_t timestamps[2];
1299 auto result =
get_device().getQueryPoolResults(
1300 it->second.timestamp_pool,
1306 vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait);
1308 if (result != vk::Result::eSuccess) {
1309 return { .label = label, .duration_ns = 0, .valid =
false };
1312 auto props =
m_backend->get_context().get_physical_device().getProperties();
1313 float timestamp_period = props.limits.timestampPeriod;
1315 auto duration_ns =
static_cast<uint64_t
>((timestamps[1] - timestamps[0]) * timestamp_period);
1317 return { .label = label, .duration_ns = duration_ns, .valid =
true };
1327 auto it = foundry.m_shaders.find(shader_id);
1328 if (it != foundry.m_shaders.end()) {
1329 return it->second.module;
1342 return vk::ShaderStageFlagBits::eCompute;
1344 return vk::ShaderStageFlagBits::eVertex;
1346 return vk::ShaderStageFlagBits::eFragment;
1348 return vk::ShaderStageFlagBits::eGeometry;
1350 return vk::ShaderStageFlagBits::eTessellationControl;
1352 return vk::ShaderStageFlagBits::eTessellationEvaluation;
1354 return vk::ShaderStageFlagBits::eMeshEXT;
1356 return vk::ShaderStageFlagBits::eTaskEXT;
1358 return vk::ShaderStageFlagBits::eCompute;
1365 if (!vk_stage.has_value()) {
1366 return std::nullopt;
1369 switch (*vk_stage) {
1370 case vk::ShaderStageFlagBits::eCompute:
1372 case vk::ShaderStageFlagBits::eVertex:
1374 case vk::ShaderStageFlagBits::eFragment:
1376 case vk::ShaderStageFlagBits::eGeometry:
1378 case vk::ShaderStageFlagBits::eTessellationControl:
1380 case vk::ShaderStageFlagBits::eTessellationEvaluation:
1382 case vk::ShaderStageFlagBits::eMeshEXT:
1384 case vk::ShaderStageFlagBits::eTaskEXT:
1387 return std::nullopt;
1397 return std::make_shared<Core::VKShaderModule>();
1402 return m_backend->get_context().get_device();
1407 return m_backend->get_context().get_physical_device();
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
static std::optional< vk::ShaderStageFlagBits > detect_stage_from_extension(const std::string &filepath)
Auto-detect shader stage from file extension.
vk::DescriptorSet get_descriptor_set(DescriptorSetID descriptor_set_id)
Get Vulkan descriptor set handle from DescriptorSetID.
vk::Queue get_graphics_queue() const
Get Vulkan graphics queue.
void wait_for_fences(const std::vector< FenceID > &fence_ids)
Wait for multiple fences to be signaled.
CommandBufferID begin_secondary_commands(vk::Format color_format, vk::Format depth_format=vk::Format::eUndefined)
Begin recording a secondary command buffer for dynamic rendering.
static std::optional< ShaderStage > detect_stage_from_extension(const std::string &filepath)
Auto-detect shader stage from file extension.
vk::Device get_device() const
Get logical device handle.
static bool s_initialized
void shutdown()
Shutdown and cleanup all ShaderFoundry resources.
std::atomic< uint64_t > m_next_fence_id
void wait_for_fence(FenceID fence_id)
Wait for fence to be signaled.
bool is_cached(const std::string &cache_key) const
Check if shader is cached.
std::shared_ptr< Core::VKShaderModule > compile(const ShaderSource &shader_source)
Compile shader from ShaderSource descriptor.
ShaderID reload_shader(const std::string &filepath)
Hot-reload shader (returns new ID)
void cleanup_sync_objects()
std::shared_ptr< Core::VKShaderModule > hot_reload(const std::string &filepath)
Hot-reload a shader from file.
std::atomic< uint64_t > m_next_shader_id
void set_config(const ShaderCompilerConfig &config)
Update compiler configuration.
void update_descriptor_storage_image(DescriptorSetID descriptor_set_id, uint32_t binding, vk::ImageView image_view, vk::ImageLayout layout=vk::ImageLayout::eGeneral)
Update descriptor set with storage image binding.
CommandBufferID begin_commands(CommandBufferType type)
Begin recording command buffer.
vk::Semaphore get_semaphore_handle(SemaphoreID semaphore_id)
Get Vulkan fence handle from FenceID.
std::shared_ptr< Core::VKShaderModule > get_vk_shader_module(ShaderID shader_id)
DetectedSourceType
Internal enum for source type detection.
vk::Queue m_transfer_queue
bool initialize(const std::shared_ptr< Core::VulkanBackend > &backend, const ShaderCompilerConfig &config={})
Initialize shader compiler.
std::unordered_map< std::string, ShaderID > m_shader_filepath_cache
void release_fence(FenceID fence_id)
Destroy the fence and free its associated command buffer.
DetectedSourceType detect_source_type(const std::string &content) const
std::unordered_map< FenceID, FenceState > m_fences
std::shared_ptr< Core::VKShaderModule > create_shader_module()
void cleanup_shader_modules()
void free_all_command_buffers()
Free all allocated command buffers.
void invalidate_cache(const std::string &cache_key)
Invalidate cache for specific shader.
std::atomic< uint64_t > m_next_command_id
TimestampResult get_timestamp_result(CommandBufferID cmd_id, const std::string &label)
void update_descriptor_image(DescriptorSetID descriptor_set_id, uint32_t binding, vk::ImageView image_view, vk::Sampler sampler, vk::ImageLayout layout=vk::ImageLayout::eShaderReadOnlyOptimal, uint32_t array_element=0)
Update descriptor set with image binding.
void add_define(const std::string &name, const std::string &value="")
Add preprocessor define for shader compilation.
std::unordered_map< std::string, std::shared_ptr< Core::VKShaderModule > > m_shader_cache
static vk::ShaderStageFlagBits to_vulkan_stage(ShaderStage stage)
Convert Portal ShaderStage to Vulkan ShaderStageFlagBits.
void update_descriptor_buffer(DescriptorSetID descriptor_set_id, uint32_t binding, vk::DescriptorType type, vk::Buffer buffer, size_t offset, size_t size)
Update descriptor set with buffer binding.
vk::Queue m_graphics_queue
CommandBufferID begin_commands_with_wait(CommandBufferType type, SemaphoreID wait_semaphore, vk::PipelineStageFlags wait_stage)
Begin command buffer that waits on a semaphore.
std::optional< std::filesystem::path > resolve_shader_path(const std::string &filepath) const
void stop()
Stop active command recording and free command buffers.
std::unordered_map< DescriptorSetID, DescriptorSetState > m_descriptor_sets
std::unordered_map< CommandBufferID, CommandBufferState > m_command_buffers
ShaderCompilerConfig m_config
SemaphoreID submit_with_signal(CommandBufferID cmd_id)
Submit command buffer asynchronously, returning a semaphore.
void cleanup_descriptor_resources()
std::shared_ptr< Core::VKDescriptorManager > m_global_descriptor_manager
vk::Queue get_compute_queue() const
Get Vulkan compute queue.
FenceID submit_async(CommandBufferID cmd_id)
Submit command buffer asynchronously, returning a fence.
std::string get_shader_entry_point(ShaderID shader_id)
Get entry point name for compiled shader.
std::shared_ptr< Core::VKShaderModule > compile_from_source_cached(const std::string &source, ShaderStage stage, const std::string &cache_key, const std::string &entry_point="main")
bool end_commands(CommandBufferID cmd_id)
End recording command buffer.
bool is_initialized() const
Check if compiler is initialized.
void destroy_shader(ShaderID shader_id)
Destroy shader (cleanup internal state)
void begin_timestamp(CommandBufferID cmd_id, const std::string &label="")
void image_barrier(CommandBufferID cmd_id, vk::Image image, vk::ImageLayout old_layout, vk::ImageLayout new_layout, vk::AccessFlags src_access, vk::AccessFlags dst_access, vk::PipelineStageFlags src_stage, vk::PipelineStageFlags dst_stage)
Insert image memory barrier.
static ShaderFoundry & instance()
void submit_and_wait(CommandBufferID cmd_id)
Submit command buffer and wait for completion.
vk::CommandBuffer get_command_buffer(CommandBufferID cmd_id)
Get Vulkan command buffer handle from CommandBufferID.
vk::Queue get_transfer_queue() const
Get Vulkan transfer queue.
void add_include_directory(const std::string &directory)
Add include directory for shader compilation.
std::vector< std::string > get_cached_keys() const
Get all cached shader keys.
vk::Queue m_compute_queue
void clear_cache()
Invalidate entire shader cache.
ShaderReflectionInfo get_shader_reflection(ShaderID shader_id)
Get reflection info for compiled shader.
vk::PhysicalDevice get_physical_device() const
Get physical device handle.
std::shared_ptr< Core::VKShaderModule > compile_from_source(const std::string &source, ShaderStage stage, const std::string &entry_point="main")
void buffer_barrier(CommandBufferID cmd_id, vk::Buffer buffer, vk::AccessFlags src_access, vk::AccessFlags dst_access, vk::PipelineStageFlags src_stage, vk::PipelineStageFlags dst_stage)
Insert buffer memory barrier.
std::atomic< uint64_t > m_next_descriptor_set_id
std::shared_ptr< Core::VKShaderModule > compile_from_spirv_asm(const std::string &spirv_asm, ShaderStage stage, const std::string &entry_point="main")
std::shared_ptr< Core::VKShaderModule > compile_from_file(const std::string &filepath, std::optional< ShaderStage > stage=std::nullopt, const std::string &entry_point="main")
void end_timestamp(CommandBufferID cmd_id, const std::string &label="")
std::shared_ptr< Core::VKShaderModule > compile_from_spirv(const std::string &spirv_path, ShaderStage stage, const std::string &entry_point="main")
ShaderID load_shader(const std::string &content, std::optional< ShaderStage > stage=std::nullopt, const std::string &entry_point="main")
Universal shader loader - auto-detects source type.
std::string generate_source_cache_key(const std::string &source, ShaderStage stage) const
std::shared_ptr< Core::VulkanBackend > m_backend
bool is_fence_signaled(FenceID fence_id)
Check if fence is signaled.
std::unordered_map< SemaphoreID, SemaphoreState > m_semaphores
ShaderStage get_shader_stage(ShaderID shader_id)
Get shader stage for compiled shader.
std::unordered_map< ShaderID, ShaderState > m_shaders
DescriptorSetID allocate_descriptor_set(vk::DescriptorSetLayout layout)
Allocate descriptor set for a pipeline.
std::atomic< uint64_t > m_next_semaphore_id
@ ShaderCompilation
Shader compilation tasks (Portal::Graphics::ShaderCompiler)
@ Portal
High-level user-facing API layer.
std::string emit_glsl_kernel(const ShaderSpec &spec)
Emit a complete GLSL compute shader from spec metadata and a KernelSource body.
std::string emit_spirv_asm(const ShaderSpec &spec)
Emit complete SPIR-V assembly text for a generated compute kernel.
constexpr ShaderID INVALID_SHADER
ShaderStage
User-friendly shader stage enum.
constexpr FenceID INVALID_FENCE
constexpr SemaphoreID INVALID_SEMAPHORE
constexpr CommandBufferID INVALID_COMMAND_BUFFER
Extracted push constant range from shader reflection.
bool enable_reflection
Extract descriptor bindings and metadata.
std::vector< std::string > include_directories
Paths for #include resolution.
std::unordered_map< std::string, std::string > defines
Preprocessor macros.
Configuration for shader compilation.
vk::DescriptorSet descriptor_set
std::shared_ptr< Core::VKShaderModule > std::string filepath
std::optional< std::array< uint32_t, 3 > > workgroup_size
std::vector< PushConstantRangeInfo > push_constant_ranges
std::vector< DescriptorBindingInfo > descriptor_bindings
Extracted reflection information from compiled shader.
std::string content
Shader source code, SPIR-V path, or SPIR-V assembly text.
enum MayaFlux::Portal::Graphics::ShaderSource::SourceType type
@ GLSL_FILE
Path to .comp/.vert/.frag/etc.
@ GLSL_STRING
In-memory GLSL source.
@ SPIRV_ASM
In-memory SPIR-V assembly text (assembled via SPIRV-Tools, no shaderc)
@ SPIRV_FILE
Path to .spv file.
Shader source descriptor for compilation.
std::optional< KernelSource > kernel
When set, KernelOp is ignored.
Complete declarative description of a generated compute shader.