From f02b9bf0834d2a9422cfd812159352b428b46bb6 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 6 Jan 2017 15:18:42 +0200 Subject: [PATCH] Properly handle the legacy replacement of fragment shader output Assignment targets to the output variable need to be cleared, lest the unused variable locator tries to access deleted nodes. --- source/programcompiler.cpp | 17 +++++++++++++---- source/programcompiler.h | 3 ++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/source/programcompiler.cpp b/source/programcompiler.cpp index f9a14f2f..fd27839d 100644 --- a/source/programcompiler.cpp +++ b/source/programcompiler.cpp @@ -1494,11 +1494,13 @@ void ProgramCompiler::NodeRemover::visit(VariableDeclaration &var) ProgramCompiler::LegacyConverter::LegacyConverter(): - target_version(get_glsl_version()) + target_version(get_glsl_version()), + frag_out(0) { } ProgramCompiler::LegacyConverter::LegacyConverter(const Version &v): - target_version(v) + target_version(v), + frag_out(0) { } bool ProgramCompiler::LegacyConverter::check_version(const Version &feature_version) @@ -1513,7 +1515,7 @@ bool ProgramCompiler::LegacyConverter::check_version(const Version &feature_vers void ProgramCompiler::LegacyConverter::visit(VariableReference &var) { - if(var.name==frag_out_name && !check_version(Version(1, 30))) + if(var.declaration==frag_out && !check_version(Version(1, 30))) { var.name = "gl_FragColor"; var.declaration = 0; @@ -1525,6 +1527,13 @@ void ProgramCompiler::LegacyConverter::visit(VariableReference &var) type = string(); } +void ProgramCompiler::LegacyConverter::visit(Assignment &assign) +{ + TraversingVisitor::visit(assign); + if(assign.target_declaration==frag_out && !check_version(Version(1, 30))) + assign.target_declaration = 0; +} + void ProgramCompiler::LegacyConverter::visit(FunctionCall &call) { if(call.name=="texture" && !call.declaration && !check_version(Version(1, 30))) @@ -1581,7 +1590,7 @@ void ProgramCompiler::LegacyConverter::visit(VariableDeclaration &var) { if(stage->type==FRAGMENT && var.interface=="out") { - frag_out_name = var.name; + frag_out = &var; remove_node = true; } } diff --git a/source/programcompiler.h b/source/programcompiler.h index 5bb71474..e159078a 100644 --- a/source/programcompiler.h +++ b/source/programcompiler.h @@ -330,7 +330,7 @@ private: { Version target_version; std::string type; - std::string frag_out_name; + ProgramSyntax::VariableDeclaration *frag_out; LegacyConverter(); LegacyConverter(const Version &); @@ -338,6 +338,7 @@ private: bool check_version(const Version &); using Visitor::visit; virtual void visit(ProgramSyntax::VariableReference &); + virtual void visit(ProgramSyntax::Assignment &); virtual void visit(ProgramSyntax::FunctionCall &); virtual void visit(ProgramSyntax::VariableDeclaration &); virtual void visit(ProgramSyntax::InterfaceBlock &); -- 2.45.2