From ba27f3c22e79b91a2573b7efd00c5a3bbdb96dbc Mon Sep 17 00:00:00 2001 From: Chuyan Zhang Date: Thu, 10 Oct 2024 16:29:06 -0700 Subject: Update shader changes --- src/render_graph.h | 41 +++++++++++++++++++++++++++++++++++++++++ src/shader.cpp | 16 +++++++++++++++- src/shader.h | 8 +++++++- 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 src/render_graph.h diff --git a/src/render_graph.h b/src/render_graph.h new file mode 100644 index 0000000..f09d6cb --- /dev/null +++ b/src/render_graph.h @@ -0,0 +1,41 @@ +#pragma once + +#include "render_pass.h" +#include +#include + +namespace iris { + +struct CreatedRenderResource { + enum struct Type { + Buffer, + Image, + ImageWithSampler, + AccelerationStructure, + } type; + + +}; + +struct ImportedRenderResource { + +}; + +struct RenderResource { + enum struct Type { + Created, + Imported, + } type; + + union { + CreatedRenderResource created; + ImportedRenderResource imported; + } inner; +}; + +struct RenderGraph { + std::vector passes; + std::vector resources; +}; + +} // namespace iris \ No newline at end of file diff --git a/src/shader.cpp b/src/shader.cpp index 95a7904..1bef97f 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -6,7 +6,11 @@ namespace iris { -ShaderDesc::ShaderDesc(const std::string_view path) { +ShaderDesc::ShaderDesc( + const std::string_view path, + std::vector defines, + std::vector> valued_defines) +{ // Load the shader from file std::ifstream file("example.txt"); if (!file.is_open()) { @@ -16,6 +20,7 @@ ShaderDesc::ShaderDesc(const std::string_view path) { std::ostringstream file_stream; file_stream << file.rdbuf(); this->source = file_stream.str(); + this->entry_point = "main"; file.close(); // Determine the shader type @@ -35,6 +40,13 @@ ShaderDesc::ShaderDesc(const std::string_view path) { shaderc::Compiler compiler; shaderc::CompileOptions options; options.SetTargetEnvironment(shaderc_target_env_vulkan, shaderc_env_version_vulkan_1_3); + options.SetOptimizationLevel(shaderc_optimization_level_performance); + for (const auto &define : defines) { + options.AddMacroDefinition(define); + } + for (const auto &[key, value] : valued_defines) { + options.AddMacroDefinition(key, value); + } shaderc::SpvCompilationResult result = compiler.CompileGlslToSpv( this->source, shaderc_glsl_compute_shader, path.data(), options); @@ -56,6 +68,8 @@ ShaderDesc::Type ShaderDesc::shader_type_from_string(std::string_view type) { return ShaderDesc::Type::eAnyHit; } else if (type == "rint") { return ShaderDesc::Type::eIntersection; + } else if (type == "rcall") { + return ShaderDesc::Type::eCallable; } else if (type == "comp") { return ShaderDesc::Type::eCompute; } else { diff --git a/src/shader.h b/src/shader.h index b1be8a8..b34fd92 100644 --- a/src/shader.h +++ b/src/shader.h @@ -12,6 +12,8 @@ struct ShaderDesc { std::string name; // Source code of the shader std::string source; + // Entry name of the shader + std::string entry_point; // Shader type enum struct Type { @@ -20,6 +22,7 @@ struct ShaderDesc { eClosestHit, eAnyHit, eIntersection, + eCallable, eCompute, } type; @@ -27,7 +30,10 @@ struct ShaderDesc { std::vector compiled_binary; static Type shader_type_from_string(std::string_view type); - ShaderDesc(const std::string_view path); + ShaderDesc( + const std::string_view path, + std::vector defines, + std::vector> valued_defines); }; } // namespace iris \ No newline at end of file -- cgit v1.2.3-70-g09d2