Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

glsl-in: inject sampler2DMSArray builtins on use #1737

Merged
merged 2 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/front/glsl/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ bitflags::bitflags! {
const DOUBLE = 1 << 1;
/// Request overloads that use samplerCubeArray(Shadow)
const CUBE_TEXTURES_ARRAY = 1 << 2;
/// Request overloads that use sampler2DMSArray
const D2_MULTI_TEXTURES_ARRAY = 1 << 3;
}
}

Expand Down
20 changes: 19 additions & 1 deletion src/front/glsl/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ pub fn inject_builtin(
name: &str,
mut variations: BuiltinVariations,
) {
log::trace!(
"{} variations: {:?} {:?}",
name,
variations,
declaration.variations
);
// Don't regeneate variations
variations.remove(declaration.variations);
declaration.variations |= variations;
Expand Down Expand Up @@ -2202,6 +2208,8 @@ bitflags::bitflags! {
const STANDARD = 1 << 2;
/// Generates cube arrayed images
const CUBE_ARRAY = 1 << 3;
/// Generates cube arrayed images
const D2_MULTI_ARRAY = 1 << 4;
}
}

Expand All @@ -2214,6 +2222,9 @@ impl From<BuiltinVariations> for TextureArgsOptions {
if variations.contains(BuiltinVariations::CUBE_TEXTURES_ARRAY) {
options |= TextureArgsOptions::CUBE_ARRAY
}
if variations.contains(BuiltinVariations::D2_MULTI_TEXTURES_ARRAY) {
options |= TextureArgsOptions::D2_MULTI_ARRAY
}
options
}
}
Expand All @@ -2238,6 +2249,13 @@ fn texture_args_generator(
if !options.contains(TextureArgsOptions::CUBE_ARRAY) {
continue;
}
} else if Dim::D2 == dim
&& options.contains(TextureArgsOptions::MULTI)
&& arrayed
&& options.contains(TextureArgsOptions::D2_MULTI_ARRAY)
{
// multisampling for sampler2DMSArray
f(kind, dim, arrayed, true, false);
} else if !options.contains(TextureArgsOptions::STANDARD) {
continue;
}
Expand All @@ -2251,7 +2269,7 @@ fn texture_args_generator(
break;
}

if Dim::D2 == dim && options.contains(TextureArgsOptions::MULTI) {
if Dim::D2 == dim && options.contains(TextureArgsOptions::MULTI) && !arrayed {
// multisampling
f(kind, dim, arrayed, true, false);
}
Expand Down
10 changes: 9 additions & 1 deletion src/front/glsl/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1498,10 +1498,18 @@ fn builtin_required_variations<'a>(args: impl Iterator<Item = &'a TypeInner>) ->
variations |= BuiltinVariations::DOUBLE
}
}
TypeInner::Image { dim, arrayed, .. } => {
TypeInner::Image {
dim,
arrayed,
class,
} => {
if dim == crate::ImageDimension::Cube && arrayed {
variations |= BuiltinVariations::CUBE_TEXTURES_ARRAY
}

if dim == crate::ImageDimension::D2 && arrayed && class.is_multisampled() {
variations |= BuiltinVariations::D2_MULTI_TEXTURES_ARRAY
}
}
_ => {}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/in/variations.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#version 460 core

layout(set = 0, binding = 0) uniform textureCube texCube;
layout(set = 0, binding = 1) uniform sampler samp;

void main() {
ivec2 sizeCube = textureSize(samplerCube(texCube, samp), 0);
float a = ceil(1.0);
}
21 changes: 21 additions & 0 deletions tests/out/glsl/variations-glsl.main.Fragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#version 310 es

precision highp float;
precision highp int;

uniform highp samplerCube _group_0_binding_0_fs;


void main_1() {
ivec2 sizeCube = ivec2(0);
float a = 0.0;
sizeCube = textureSize(_group_0_binding_0_fs, 0).xy;
a = ceil(1.0);
return;
}

void main() {
main_1();
return;
}

19 changes: 19 additions & 0 deletions tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,25 @@ fn convert_spv_all() {
convert_spv("degrees", false, Targets::empty());
}

#[cfg(feature = "glsl-in")]
#[test]
fn convert_glsl_variations_check() {
let root = env!("CARGO_MANIFEST_DIR");
let file = fs::read_to_string(format!("{}/{}/variations.glsl", root, BASE_DIR_IN))
.expect("Couldn't find glsl file");
let mut parser = naga::front::glsl::Parser::default();
let module = parser
.parse(
&naga::front::glsl::Options {
stage: naga::ShaderStage::Fragment,
defines: Default::default(),
},
&file,
)
.unwrap();
check_targets(&module, "variations-glsl", Targets::GLSL);
}

#[cfg(feature = "glsl-in")]
#[allow(unused_variables)]
#[test]
Expand Down