Skip to content

Commit e29b44b

Browse files
committed
CompileOptions mozangle
1 parent 038fed5 commit e29b44b

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

src/shaders/mod.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,29 @@ impl BuiltInResources {
124124
}
125125
}
126126

127+
pub type CompileOptions = ShCompileOptions;
128+
129+
impl CompileOptions {
130+
fn mozangle() -> Self {
131+
let mut options = unsafe { CompileOptions::new() };
132+
options.set_validateLoopIndexing(1); // SH_VALIDATE
133+
options.set_objectCode(1);
134+
options.set_variables(1); // For uniform_name_map()
135+
options.set_emulateAbsIntFunction(1); // To workaround drivers
136+
options.set_emulateIsnanFloatFunction(1); // To workaround drivers
137+
options.set_emulateAtan2FloatFunction(1); // To workaround drivers
138+
options.set_clampIndirectArrayBounds(1);
139+
options.set_initGLPosition(1);
140+
options.set_enforcePackingRestrictions(1);
141+
options.set_limitExpressionComplexity(1);
142+
options.set_limitCallStackDepth(1);
143+
// Todo(Mortimer): Add SH_TIMING_RESTRICTIONS to options when the implementations gets better
144+
// Right now SH_TIMING_RESTRICTIONS is experimental
145+
// and doesn't support user callable functions in shaders
146+
options
147+
}
148+
}
149+
127150
pub struct ShaderValidator {
128151
handle: ShHandle,
129152
}
@@ -213,26 +236,7 @@ impl ShaderValidator {
213236
}
214237

215238
pub fn compile_and_translate(&self, strings: &[&str]) -> Result<String, &'static str> {
216-
// TODO: make this selection smarter
217-
let options = unsafe {
218-
let mut options = ShCompileOptions::new();
219-
options.set_validateLoopIndexing(1); // SH_VALIDATE
220-
options.set_objectCode(1);
221-
options.set_variables(1); // For uniform_name_map()
222-
options.set_emulateAbsIntFunction(1); // To workaround drivers
223-
options.set_emulateIsnanFloatFunction(1); // To workaround drivers
224-
options.set_emulateAtan2FloatFunction(1); // To workaround drivers
225-
options.set_clampIndirectArrayBounds(1);
226-
options.set_initGLPosition(1);
227-
options.set_enforcePackingRestrictions(1);
228-
options.set_limitExpressionComplexity(1);
229-
options.set_limitCallStackDepth(1);
230-
options
231-
};
232-
// Todo(Mortimer): Add SH_TIMING_RESTRICTIONS to options when the implementations gets better
233-
// Right now SH_TIMING_RESTRICTIONS is experimental
234-
// and doesn't support user callable functions in shaders
235-
239+
let options = CompileOptions::mozangle();
236240
self.compile(strings, options)?;
237241
Ok(self.object_code())
238242
}

0 commit comments

Comments
 (0)