From 173494bd81e34cdfa7141f244aab216958cfac68 Mon Sep 17 00:00:00 2001 From: Amy Date: Sun, 5 Nov 2023 00:17:14 +0100 Subject: [PATCH] fix bug in reading shader files --- engine/vk/VkShaderModule.h | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/engine/vk/VkShaderModule.h b/engine/vk/VkShaderModule.h index 6536a82..5f97e21 100644 --- a/engine/vk/VkShaderModule.h +++ b/engine/vk/VkShaderModule.h @@ -7,7 +7,7 @@ #endif #include -#include +#include #include #include #include @@ -184,6 +184,8 @@ namespace Vixen::Vk { throw std::runtime_error("Unsupported stage for shader module"); } + spdlog::trace("Passed in shader source\n{}", source.data()); + glslang::InitializeProcess(); glslang::TShader shader{s}; glslang::TProgram program; @@ -199,32 +201,33 @@ namespace Vixen::Vk { shader.setSourceEntryPoint(entrypoint.c_str()); auto messages = (EShMessages) (EShMsgSpvRules | EShMsgVulkanRules); + // TODO: Add actual includer glslang::TShader::ForbidIncluder includer; - const auto &limits = TBuiltInResource(); - if (!shader.parse(&limits, VIXEN_VK_SPIRV_VERSION, false, messages)) + // TODO: Resource limit should probably be gotten from the GPU + if (!shader.parse(GetDefaultResources(), VIXEN_VK_SPIRV_VERSION, false, messages)) error("Failed to parse shader; {}", shader.getInfoLog()); program.addShader(&shader); if (!program.link(messages)) error("Failed to link shader program; {}", shader.getInfoLog()); - glslang::SpvOptions options; - + glslang::SpvOptions options{ #ifdef DEBUG - options.generateDebugInfo = true; - options.stripDebugInfo = false; - options.disableOptimizer = true; - options.optimizeSize = false; - options.disassemble = true; + .generateDebugInfo = true, + .stripDebugInfo = false, + .disableOptimizer = true, + .optimizeSize = false, + .disassemble = true, #else - options.generateDebugInfo = false; - options.stripDebugInfo = true; - options.disableOptimizer = false; - options.optimizeSize = true; - options.disassemble = false; + .generateDebugInfo = false, + .stripDebugInfo = true, + .disableOptimizer = false, + .optimizeSize = true, + .disassemble = false, #endif - options.validate = true; + .validate = true, + }; spv::SpvBuildLogger logger; glslang::GlslangToSpv(*program.getIntermediate(s), binary, &logger, &options); @@ -273,7 +276,7 @@ namespace Vixen::Vk { std::streamsize size = file.tellg(); std::vector buffer(size); - file.seekg(0); + file.seekg(0, std::ios_base::beg); file.read(buffer.data(), size); file.close();