Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[glsl-out] use fma polyfill for versions below gles 320 #2197

Merged
merged 1 commit into from
Jan 7, 2023
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
19 changes: 4 additions & 15 deletions src/back/glsl/features.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{BackendResult, Error, Version, Writer};
use crate::{
AddressSpace, Binding, Bytes, Expression, Handle, ImageClass, ImageDimension, Interpolation,
MathFunction, Sampling, ScalarKind, ShaderStage, StorageFormat, Type, TypeInner,
Sampling, ScalarKind, ShaderStage, StorageFormat, Type, TypeInner,
};
use std::fmt::Write;

Expand Down Expand Up @@ -34,14 +34,12 @@ bitflags::bitflags! {
/// Arrays with a dynamic length.
const DYNAMIC_ARRAY_SIZE = 1 << 16;
const MULTI_VIEW = 1 << 17;
/// Fused multiply-add.
const FMA = 1 << 18;
/// Texture samples query
const TEXTURE_SAMPLES = 1 << 19;
const TEXTURE_SAMPLES = 1 << 18;
/// Texture levels query
const TEXTURE_LEVELS = 1 << 20;
const TEXTURE_LEVELS = 1 << 19;
/// Image size query
const IMAGE_SIZE = 1 << 21;
const IMAGE_SIZE = 1 << 20;
}
}

Expand Down Expand Up @@ -224,11 +222,6 @@ impl FeaturesManager {
}
}

if self.0.contains(Features::FMA) && version >= Version::new_gles(310) {
// https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_gpu_shader5.txt
writeln!(out, "#extension GL_EXT_gpu_shader5 : require")?;
}

if self.0.contains(Features::TEXTURE_SAMPLES) {
// https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_shader_texture_image_samples.txt
writeln!(
Expand Down Expand Up @@ -425,10 +418,6 @@ impl<'a, W> Writer<'a, W> {
{
for (_, expr) in expressions.iter() {
match *expr {
// Check for fused multiply add use
Expression::Math { fun, .. } if fun == MathFunction::Fma => {
features.request(Features::FMA)
}
// Check for queries that neeed aditonal features
Expression::ImageQuery {
image,
Expand Down
2 changes: 1 addition & 1 deletion src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl Version {
}

fn supports_fma_function(&self) -> bool {
*self >= Version::Desktop(400) || *self >= Version::new_gles(310)
*self >= Version::Desktop(400) || *self >= Version::new_gles(320)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/in/functions-webgl.param.ron
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(
glsl: (
version: Embedded(
version: 300,
version: 320,
is_webgl: false
),
writer_flags: (bits: 0),
Expand Down
4 changes: 2 additions & 2 deletions tests/out/glsl/functions-webgl.main.Vertex.glsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 300 es
#version 320 es

precision highp float;
precision highp int;
Expand All @@ -8,7 +8,7 @@ vec2 test_fma() {
vec2 a = vec2(2.0, 2.0);
vec2 b = vec2(0.5, 0.5);
vec2 c = vec2(0.5, 0.5);
return (a * b + c);
return fma(a, b, c);
}

void main() {
Expand Down
3 changes: 1 addition & 2 deletions tests/out/glsl/functions.main.Compute.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#version 310 es
#extension GL_EXT_gpu_shader5 : require

precision highp float;
precision highp int;
Expand All @@ -11,7 +10,7 @@ vec2 test_fma() {
vec2 a = vec2(2.0, 2.0);
vec2 b = vec2(0.5, 0.5);
vec2 c = vec2(0.5, 0.5);
return fma(a, b, c);
return (a * b + c);
}

int test_integer_dot_product() {
Expand Down