From 3fe1aab63922eec99d8bf6fd4fd60bec10df173c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 11 Nov 2021 00:59:22 +0200 Subject: [PATCH] Refactor a common part in LocationAllocator into a function --- source/glsl/finalize.cpp | 38 +++++++++++++++----------------------- source/glsl/finalize.h | 1 + 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/source/glsl/finalize.cpp b/source/glsl/finalize.cpp index e89aa494..864a128b 100644 --- a/source/glsl/finalize.cpp +++ b/source/glsl/finalize.cpp @@ -169,6 +169,17 @@ void LocationAllocator::add_layout_value(RefPtr &layout, const string &n layout->qualifiers.push_back(Layout::Qualifier(name, value)); } +bool LocationAllocator::visit_uniform(const string &name, RefPtr &layout) +{ + int bind_point = (layout ? get_layout_value(*layout, "binding") : -1); + if(bind_point>=0) + { + used_bindings[0].insert(bind_point); + uniforms[name].bind_point = bind_point; + } + return bind_point>=0; +} + void LocationAllocator::visit(VariableDeclaration &var) { if(!var.name.compare(0, 3, "gl_")) @@ -202,17 +213,8 @@ void LocationAllocator::visit(VariableDeclaration &var) const TypeDeclaration *type = var.type_declaration; while(const BasicTypeDeclaration *basic = dynamic_cast(type)) type = basic->base_type; - if(dynamic_cast(type)) - { - int bind_point = (var.layout ? get_layout_value(*var.layout, "binding") : -1); - if(bind_point>=0) - { - used_bindings[0].insert(bind_point); - uniforms[var.name].bind_point = bind_point; - } - else - unbound_textures.push_back(&var); - } + if(dynamic_cast(type) && !visit_uniform(var.name, var.layout)) + unbound_textures.push_back(&var); } } @@ -230,18 +232,8 @@ void LocationAllocator::visit(InterfaceBlock &iface) push_constant = (i!=iface.layout->qualifiers.end()); } - if(!push_constant) - { - int bind_point = (iface.layout ? get_layout_value(*iface.layout, "binding") : -1); - - if(bind_point>=0) - { - used_bindings[0].insert(bind_point); - uniforms[iface.block_name].bind_point = bind_point; - } - else - unbound_blocks.push_back(&iface); - } + if(!push_constant && !visit_uniform(iface.block_name, iface.layout)) + unbound_blocks.push_back(&iface); } } diff --git a/source/glsl/finalize.h b/source/glsl/finalize.h index 263be454..17430748 100644 --- a/source/glsl/finalize.h +++ b/source/glsl/finalize.h @@ -52,6 +52,7 @@ private: void bind_uniform(RefPtr &, const std::string &, unsigned); void add_layout_value(RefPtr &, const std::string &, unsigned); + bool visit_uniform(const std::string &, RefPtr &); virtual void visit(VariableDeclaration &); virtual void visit(InterfaceBlock &); virtual void visit(FunctionDeclaration &) { } -- 2.45.2