From 6d1132352008627d286b7f3df358448b34792547 Mon Sep 17 00:00:00 2001 From: chyyran Date: Thu, 24 Nov 2022 02:08:58 -0500 Subject: [PATCH] gl: use real texture names when fixing bindings --- librashader-reflect/src/back/cross.rs | 2 +- librashader-reflect/src/reflect/cross.rs | 8 ++++---- librashader-runtime-gl/src/filter_chain.rs | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/librashader-reflect/src/back/cross.rs b/librashader-reflect/src/back/cross.rs index 1a49bef..1f52cc5 100644 --- a/librashader-reflect/src/back/cross.rs +++ b/librashader-reflect/src/back/cross.rs @@ -7,7 +7,7 @@ use crate::reflect::ReflectShader; pub type GlVersion = spirv_cross::glsl::Version; pub struct GlslangGlslContext { - pub sampler_bindings: Vec, + pub sampler_bindings: Vec<(String, u32)>, pub compiler: CompiledAst, } diff --git a/librashader-reflect/src/reflect/cross.rs b/librashader-reflect/src/reflect/cross.rs index b1a282e..d4b6d1a 100644 --- a/librashader-reflect/src/reflect/cross.rs +++ b/librashader-reflect/src/reflect/cross.rs @@ -792,15 +792,15 @@ impl CompileShader for CrossReflect { } let mut texture_fixups = Vec::new(); - for res in &fragment_resources.sampled_images { + for res in fragment_resources.sampled_images { let binding = self.fragment.get_decoration(res.id, Decoration::Binding)?; - self.fragment - .set_name(res.id, &format!("LIBRA_TEXTURE_{binding}"))?; self.fragment .unset_decoration(res.id, Decoration::DescriptorSet)?; self.fragment .unset_decoration(res.id, Decoration::Binding)?; - texture_fixups.push(binding); + let mut name = res.name; + name.push('\0'); + texture_fixups.push((name, binding)); } Ok(ShaderCompilerOutput { diff --git a/librashader-runtime-gl/src/filter_chain.rs b/librashader-runtime-gl/src/filter_chain.rs index d1dde29..ef4d73b 100644 --- a/librashader-runtime-gl/src/filter_chain.rs +++ b/librashader-runtime-gl/src/filter_chain.rs @@ -402,10 +402,9 @@ impl FilterChain { gl::UseProgram(program); - for binding in &glsl.context.sampler_bindings { - let loc_name = format!("LIBRA_TEXTURE_{}\0", *binding); + for (name, binding) in &glsl.context.sampler_bindings { let location = - gl::GetUniformLocation(program, loc_name.as_str().as_ptr().cast()); + gl::GetUniformLocation(program, name.as_str().as_ptr().cast()); if location >= 0 { // eprintln!("setting sampler {location} to sample from {binding}"); gl::Uniform1i(location, *binding as GLint);