Skip to content

Commit b261771

Browse files
authored
Auto merge of #50 - jamienicol:num-varying-vecs, r=jrmuizel
Add function to count number of unpacked varying vectors 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.
2 parents 898bde1 + 5317496 commit b261771

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mozangle"
3-
version = "0.3.2"
3+
version = "0.3.3"
44
authors = ["The ANGLE Project Authors", "The Servo Project Developers"]
55
license = " BSD-3-Clause"
66
description = "Mozilla’s fork of Google ANGLE, repackaged as a Rust crate "

src/shaders/glslang-c.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "GLSLANG/ShaderLang.h"
2+
#include "common/utilities.h"
23

34
extern "C"
45
int GLSLangInitialize() {
@@ -91,3 +92,24 @@ void GLSLangIterUniformNameMapping(const ShHandle handle, StrPairFunction each,
9192
);
9293
}
9394
}
95+
96+
// Returns the number of vectors that the shader's active varyings fit
97+
// in to without additional packing. Can be used to test whether a
98+
// shader will compile on drivers that do not perform spec-compliant
99+
// packing. This contrasts with sh::CheckVariablesWithinPackingLimits
100+
// which does pack the varyings in accordance with the spec.
101+
extern "C"
102+
int GLSLangGetNumUnpackedVaryingVectors(const ShHandle handle) {
103+
int total_rows = 0;
104+
const std::vector<sh::Varying>* varyings = sh::GetVaryings(handle);
105+
106+
if (varyings) {
107+
for (const auto& varying : *varyings) {
108+
if (varying.active) {
109+
total_rows += gl::VariableRowCount(varying.type) * varying.getArraySizeProduct();
110+
}
111+
}
112+
}
113+
114+
return total_rows;
115+
}

src/shaders/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub mod ffi {
2424
each: unsafe extern fn(*mut c_void, *const c_char, usize, *const c_char, usize),
2525
closure_each: *mut c_void
2626
);
27+
pub fn GLSLangGetNumUnpackedVaryingVectors(handle: ShHandle) -> c_int;
2728
}
2829
}
2930

@@ -292,6 +293,12 @@ impl ShaderValidator {
292293
}
293294
closure.map
294295
}
296+
297+
pub fn get_num_unpacked_varying_vectors(&self) -> i32 {
298+
unsafe {
299+
GLSLangGetNumUnpackedVaryingVectors(self.handle)
300+
}
301+
}
295302
}
296303

297304
impl Drop for ShaderValidator {

0 commit comments

Comments
 (0)