Skip Early Depth Test When Unsupported in GLSL

This commit is contained in:
Zicklag
2021-07-21 16:43:00 -05:00
committed by Dzmitry Malyshau
parent 82b2fe4410
commit bdcab53231
2 changed files with 23 additions and 11 deletions

View File

@@ -206,7 +206,10 @@ impl<'a, W> Writer<'a, W> {
/// [`Error::MissingFeatures`](super::Error::MissingFeatures) will be returned
pub(super) fn collect_required_features(&mut self) -> BackendResult {
if let Some(depth_test) = self.entry_point.early_depth_test {
self.features.request(Features::IMAGE_LOAD_STORE);
// If IMAGE_LOAD_STORE is supported for this version of GLSL
if self.options.version.supports_early_depth_test() {
self.features.request(Features::IMAGE_LOAD_STORE);
}
if depth_test.conservative.is_some() {
self.features.request(Features::CONSERVATIVE_DEPTH);

View File

@@ -110,6 +110,10 @@ impl Version {
fn supports_explicit_locations(&self) -> bool {
*self >= Version::Embedded(310) || *self >= Version::Desktop(410)
}
fn supports_early_depth_test(&self) -> bool {
*self >= Version::Desktop(130) || *self >= Version::Embedded(310)
}
}
impl PartialOrd for Version {
@@ -430,22 +434,27 @@ impl<'a, W: Write> Writer<'a, W> {
// Enable early depth tests if needed
if let Some(depth_test) = self.entry_point.early_depth_test {
writeln!(self.out, "layout(early_fragment_tests) in;")?;
// If early depth test is supported for this version of GLSL
if self.options.version.supports_early_depth_test() {
writeln!(self.out, "layout(early_fragment_tests) in;")?;
if let Some(conservative) = depth_test.conservative {
use crate::ConservativeDepth as Cd;
if let Some(conservative) = depth_test.conservative {
use crate::ConservativeDepth as Cd;
writeln!(
self.out,
"layout (depth_{}) out float gl_FragDepth;",
match conservative {
let depth = match conservative {
Cd::GreaterEqual => "greater",
Cd::LessEqual => "less",
Cd::Unchanged => "unchanged",
}
)?;
};
writeln!(self.out, "layout (depth_{}) out float gl_FragDepth;", depth)?;
}
writeln!(self.out)?;
} else {
log::warn!(
"Early depth testing is not supported for this version of GLSL: {}",
self.options.version
);
}
writeln!(self.out)?;
}
// Write all structs