Skip to content

Commit

Permalink
Add function to count number of unpacked varying vectors
Browse files Browse the repository at this point in the history
This counts the number of vectors used by each active varying in a
shader. This can be used to ensure that a shader will succesfully
compile without using more than GL_MAX_VARYING_VECTORS on devices that
do not perform spec-compliant packing of varyings. This is in contrast
to sh::CheckVariablesWithinPackingLimits(), which checks whether there
are enough vectors *with* spec-compliant packing.
  • Loading branch information
jamienicol committed Mar 10, 2021
1 parent 898bde1 commit 5317496
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mozangle"
version = "0.3.2"
version = "0.3.3"
authors = ["The ANGLE Project Authors", "The Servo Project Developers"]
license = " BSD-3-Clause"
description = "Mozilla’s fork of Google ANGLE, repackaged as a Rust crate "
Expand Down
22 changes: 22 additions & 0 deletions src/shaders/glslang-c.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "GLSLANG/ShaderLang.h"
#include "common/utilities.h"

extern "C"
int GLSLangInitialize() {
Expand Down Expand Up @@ -91,3 +92,24 @@ void GLSLangIterUniformNameMapping(const ShHandle handle, StrPairFunction each,
);
}
}

// Returns the number of vectors that the shader's active varyings fit
// in to without additional packing. Can be used to test whether a
// shader will compile on drivers that do not perform spec-compliant
// packing. This contrasts with sh::CheckVariablesWithinPackingLimits
// which does pack the varyings in accordance with the spec.
extern "C"
int GLSLangGetNumUnpackedVaryingVectors(const ShHandle handle) {
int total_rows = 0;
const std::vector<sh::Varying>* varyings = sh::GetVaryings(handle);

if (varyings) {
for (const auto& varying : *varyings) {
if (varying.active) {
total_rows += gl::VariableRowCount(varying.type) * varying.getArraySizeProduct();
}
}
}

return total_rows;
}
7 changes: 7 additions & 0 deletions src/shaders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub mod ffi {
each: unsafe extern fn(*mut c_void, *const c_char, usize, *const c_char, usize),
closure_each: *mut c_void
);
pub fn GLSLangGetNumUnpackedVaryingVectors(handle: ShHandle) -> c_int;
}
}

Expand Down Expand Up @@ -292,6 +293,12 @@ impl ShaderValidator {
}
closure.map
}

pub fn get_num_unpacked_varying_vectors(&self) -> i32 {
unsafe {
GLSLangGetNumUnpackedVaryingVectors(self.handle)
}
}
}

impl Drop for ShaderValidator {
Expand Down

0 comments on commit 5317496

Please sign in to comment.