From 28a1ee435463c898314a0db0d42a1eacd40e95fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Fri, 21 May 2021 22:46:17 +0100 Subject: [PATCH] [glsl-in] Don't read builtin if it isn't available --- src/front/glsl/functions.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/front/glsl/functions.rs b/src/front/glsl/functions.rs index 6da0028a21..8838562380 100644 --- a/src/front/glsl/functions.rs +++ b/src/front/glsl/functions.rs @@ -439,6 +439,7 @@ impl Program<'_> { for (binding, input, handle) in self.entry_args.iter().cloned() { match binding { Binding::Location { .. } if !input => continue, + Binding::BuiltIn(builtin) if !should_read(builtin, stage) => continue, _ => {} } @@ -524,6 +525,32 @@ impl Program<'_> { } } +// FIXME: Both of the functions below should be removed they are a temporary solution +// +// The fix should analyze the entry point and children function calls +// (recursively) and store something like `GlobalUse` and then later only read +// or store the globals that need to be read or written in that stage + +fn should_read(built_in: BuiltIn, stage: ShaderStage) -> bool { + match (built_in, stage) { + (BuiltIn::Position, ShaderStage::Fragment) + | (BuiltIn::BaseInstance, ShaderStage::Vertex) + | (BuiltIn::BaseVertex, ShaderStage::Vertex) + | (BuiltIn::ClipDistance, ShaderStage::Fragment) + | (BuiltIn::InstanceIndex, ShaderStage::Vertex) + | (BuiltIn::VertexIndex, ShaderStage::Vertex) + | (BuiltIn::FrontFacing, ShaderStage::Fragment) + | (BuiltIn::SampleIndex, ShaderStage::Fragment) + | (BuiltIn::SampleMask, ShaderStage::Fragment) + | (BuiltIn::GlobalInvocationId, ShaderStage::Compute) + | (BuiltIn::LocalInvocationId, ShaderStage::Compute) + | (BuiltIn::LocalInvocationIndex, ShaderStage::Compute) + | (BuiltIn::WorkGroupId, ShaderStage::Compute) + | (BuiltIn::WorkGroupSize, ShaderStage::Compute) => true, + _ => false, + } +} + fn should_write(built_in: BuiltIn, stage: ShaderStage) -> bool { match (built_in, stage) { (BuiltIn::Position, ShaderStage::Vertex)