From 9328859840052a49ca3ba868e35fcf64d417c623 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 4 Mar 2021 23:26:19 +0200 Subject: [PATCH] Use a different method of adding builtins to stages This gets them in the correct order with the module's shared stage, and also allows builtins to have shared declarations. --- source/glsl/builtin.cpp | 2 ++ source/glsl/compiler.cpp | 12 +++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/glsl/builtin.cpp b/source/glsl/builtin.cpp index 04974065..955266fe 100644 --- a/source/glsl/builtin.cpp +++ b/source/glsl/builtin.cpp @@ -49,6 +49,8 @@ Stage *get_builtins(Stage::Type type) if(!module) return 0; + if(type==Stage::SHARED) + return &module->shared; for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) if(i->type==type) return &*i; diff --git a/source/glsl/compiler.cpp b/source/glsl/compiler.cpp index d5ee6691..c2a0656d 100644 --- a/source/glsl/compiler.cpp +++ b/source/glsl/compiler.cpp @@ -206,13 +206,6 @@ void Compiler::append_stage(Stage &stage) target = &*i; } - if(target->content.body.empty()) - { - Stage *builtins = get_builtins(stage.type); - if(builtins && builtins!=&stage) - append_stage(*builtins); - } - if(stage.required_features.glsl_version>target->required_features.glsl_version) target->required_features.glsl_version = stage.required_features.glsl_version; for(NodeList::iterator i=stage.content.body.begin(); i!=stage.content.body.end(); ++i) @@ -239,7 +232,12 @@ void Compiler::generate(Stage &stage, Mode mode) stage.required_features.gl_api = features.gl_api; if(module->shared.required_features.glsl_version>stage.required_features.glsl_version) stage.required_features.glsl_version = module->shared.required_features.glsl_version; + inject_block(stage.content, module->shared.content); + if(Stage *builtins = get_builtins(stage.type)) + inject_block(stage.content, builtins->content); + if(Stage *builtins = get_builtins(Stage::SHARED)) + inject_block(stage.content, builtins->content); // Initial resolving pass BlockHierarchyResolver().apply(stage); -- 2.45.2