Skip to content

Commit

Permalink
Add test to rename combined image samplers
Browse files Browse the repository at this point in the history
  • Loading branch information
grovesNL committed Mar 19, 2019
1 parent 1dab068 commit a5a299a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
45 changes: 45 additions & 0 deletions spirv_cross/tests/glsl_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,48 @@ void main()
"
);
}


#[test]
fn ast_can_rename_combined_image_samplers() {
let mut ast = spirv::Ast::<glsl::Target>::parse(&spirv::Module::from_words(words_from_bytes(
include_bytes!("shaders/sampler.frag.spv"),
)))
.unwrap();
ast.set_compiler_options(&glsl::CompilerOptions {
version: glsl::Version::V4_10,
vertex: glsl::CompilerVertexOptions::default(),
})
.unwrap();
for cis in ast.get_combined_image_samplers().unwrap() {
let new_name = "combined_sampler".to_string()
+ "_"
+ &cis.sampler_id.to_string()
+ "_"
+ &cis.image_id.to_string()
+ "_"
+ &cis.combined_id.to_string();
ast.set_name(cis.combined_id, &new_name).unwrap();
}

assert_eq!(
ast.compile().unwrap(),
"\
#version 410
#ifdef GL_ARB_shading_language_420pack
#extension GL_ARB_shading_language_420pack : require
#endif
uniform sampler2D combined_sampler_16_12_26;
layout(location = 0) out vec4 target0;
layout(location = 0) in vec2 v_uv;
void main()
{
target0 = texture(combined_sampler_16_12_26, v_uv);
}
"
);
}
12 changes: 12 additions & 0 deletions spirv_cross/tests/shaders/sampler.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 450
#extension GL_ARB_separate_shader_objects : enable

layout(location = 0) in vec2 v_uv;
layout(location = 0) out vec4 target0;

layout(set = 0, binding = 0) uniform texture2D u_texture;
layout(set = 0, binding = 1) uniform sampler u_sampler;

void main() {
target0 = texture(sampler2D(u_texture, u_sampler), v_uv);
}
Binary file added spirv_cross/tests/shaders/sampler.frag.spv
Binary file not shown.

0 comments on commit a5a299a

Please sign in to comment.