tint/writer/glsl: Fix vector `select`
mix of ivec is not core until later GLSL versions.
Just polyfill in the writer with ternary ops.
Change-Id: Ia0c35bf95842e03ef8447019f3264d01c11fd384
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/123240
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Stephen White <senorblanco@chromium.org>
Kokoro: Ben Clayton <bclayton@google.com>
diff --git a/test/tint/builtins/gen/literal/textureLoad/1bfdfb.wgsl.expected.glsl b/test/tint/builtins/gen/literal/textureLoad/1bfdfb.wgsl.expected.glsl
index 50390aa..273445c 100644
--- a/test/tint/builtins/gen/literal/textureLoad/1bfdfb.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/textureLoad/1bfdfb.wgsl.expected.glsl
@@ -1,5 +1,10 @@
#version 310 es
+vec3 tint_select(vec3 param_0, vec3 param_1, bvec3 param_2) {
+ return vec3(param_2[0] ? param_1[0] : param_0[0], param_2[1] ? param_1[1] : param_0[1], param_2[2] ? param_1[2] : param_0[2]);
+}
+
+
struct GammaTransferParams {
float G;
float A;
@@ -49,7 +54,7 @@
bvec3 cond = lessThan(abs(v), vec3(params.D));
vec3 t = (sign(v) * ((params.C * abs(v)) + params.F));
vec3 f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3(params.G)) + params.E));
- return mix(f, t, cond);
+ return tint_select(f, t, cond);
}
vec4 textureLoadExternal(highp sampler2D plane0_1, highp sampler2D plane1_1, uvec2 coord, ExternalTextureParams params) {
@@ -99,6 +104,11 @@
#version 310 es
precision mediump float;
+vec3 tint_select(vec3 param_0, vec3 param_1, bvec3 param_2) {
+ return vec3(param_2[0] ? param_1[0] : param_0[0], param_2[1] ? param_1[1] : param_0[1], param_2[2] ? param_1[2] : param_0[2]);
+}
+
+
struct GammaTransferParams {
float G;
float A;
@@ -148,7 +158,7 @@
bvec3 cond = lessThan(abs(v), vec3(params.D));
vec3 t = (sign(v) * ((params.C * abs(v)) + params.F));
vec3 f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3(params.G)) + params.E));
- return mix(f, t, cond);
+ return tint_select(f, t, cond);
}
vec4 textureLoadExternal(highp sampler2D plane0_1, highp sampler2D plane1_1, uvec2 coord, ExternalTextureParams params) {
@@ -192,6 +202,11 @@
}
#version 310 es
+vec3 tint_select(vec3 param_0, vec3 param_1, bvec3 param_2) {
+ return vec3(param_2[0] ? param_1[0] : param_0[0], param_2[1] ? param_1[1] : param_0[1], param_2[2] ? param_1[2] : param_0[2]);
+}
+
+
struct GammaTransferParams {
float G;
float A;
@@ -241,7 +256,7 @@
bvec3 cond = lessThan(abs(v), vec3(params.D));
vec3 t = (sign(v) * ((params.C * abs(v)) + params.F));
vec3 f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3(params.G)) + params.E));
- return mix(f, t, cond);
+ return tint_select(f, t, cond);
}
vec4 textureLoadExternal(highp sampler2D plane0_1, highp sampler2D plane1_1, uvec2 coord, ExternalTextureParams params) {
diff --git a/test/tint/builtins/gen/literal/textureLoad/8acf41.wgsl.expected.glsl b/test/tint/builtins/gen/literal/textureLoad/8acf41.wgsl.expected.glsl
index ef39bd8..5760501 100644
--- a/test/tint/builtins/gen/literal/textureLoad/8acf41.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/textureLoad/8acf41.wgsl.expected.glsl
@@ -1,5 +1,10 @@
#version 310 es
+vec3 tint_select(vec3 param_0, vec3 param_1, bvec3 param_2) {
+ return vec3(param_2[0] ? param_1[0] : param_0[0], param_2[1] ? param_1[1] : param_0[1], param_2[2] ? param_1[2] : param_0[2]);
+}
+
+
struct GammaTransferParams {
float G;
float A;
@@ -49,7 +54,7 @@
bvec3 cond = lessThan(abs(v), vec3(params.D));
vec3 t = (sign(v) * ((params.C * abs(v)) + params.F));
vec3 f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3(params.G)) + params.E));
- return mix(f, t, cond);
+ return tint_select(f, t, cond);
}
vec4 textureLoadExternal(highp sampler2D plane0_1, highp sampler2D plane1_1, ivec2 coord, ExternalTextureParams params) {
@@ -99,6 +104,11 @@
#version 310 es
precision mediump float;
+vec3 tint_select(vec3 param_0, vec3 param_1, bvec3 param_2) {
+ return vec3(param_2[0] ? param_1[0] : param_0[0], param_2[1] ? param_1[1] : param_0[1], param_2[2] ? param_1[2] : param_0[2]);
+}
+
+
struct GammaTransferParams {
float G;
float A;
@@ -148,7 +158,7 @@
bvec3 cond = lessThan(abs(v), vec3(params.D));
vec3 t = (sign(v) * ((params.C * abs(v)) + params.F));
vec3 f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3(params.G)) + params.E));
- return mix(f, t, cond);
+ return tint_select(f, t, cond);
}
vec4 textureLoadExternal(highp sampler2D plane0_1, highp sampler2D plane1_1, ivec2 coord, ExternalTextureParams params) {
@@ -192,6 +202,11 @@
}
#version 310 es
+vec3 tint_select(vec3 param_0, vec3 param_1, bvec3 param_2) {
+ return vec3(param_2[0] ? param_1[0] : param_0[0], param_2[1] ? param_1[1] : param_0[1], param_2[2] ? param_1[2] : param_0[2]);
+}
+
+
struct GammaTransferParams {
float G;
float A;
@@ -241,7 +256,7 @@
bvec3 cond = lessThan(abs(v), vec3(params.D));
vec3 t = (sign(v) * ((params.C * abs(v)) + params.F));
vec3 f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3(params.G)) + params.E));
- return mix(f, t, cond);
+ return tint_select(f, t, cond);
}
vec4 textureLoadExternal(highp sampler2D plane0_1, highp sampler2D plane1_1, ivec2 coord, ExternalTextureParams params) {
diff --git a/test/tint/builtins/gen/literal/textureSampleBaseClampToEdge/7c04e6.wgsl.expected.glsl b/test/tint/builtins/gen/literal/textureSampleBaseClampToEdge/7c04e6.wgsl.expected.glsl
index df288db..b348446 100644
--- a/test/tint/builtins/gen/literal/textureSampleBaseClampToEdge/7c04e6.wgsl.expected.glsl
+++ b/test/tint/builtins/gen/literal/textureSampleBaseClampToEdge/7c04e6.wgsl.expected.glsl
@@ -1,5 +1,10 @@
#version 310 es
+vec3 tint_select(vec3 param_0, vec3 param_1, bvec3 param_2) {
+ return vec3(param_2[0] ? param_1[0] : param_0[0], param_2[1] ? param_1[1] : param_0[1], param_2[2] ? param_1[2] : param_0[2]);
+}
+
+
struct GammaTransferParams {
float G;
float A;
@@ -49,7 +54,7 @@
bvec3 cond = lessThan(abs(v), vec3(params.D));
vec3 t = (sign(v) * ((params.C * abs(v)) + params.F));
vec3 f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3(params.G)) + params.E));
- return mix(f, t, cond);
+ return tint_select(f, t, cond);
}
@@ -108,6 +113,11 @@
#version 310 es
precision mediump float;
+vec3 tint_select(vec3 param_0, vec3 param_1, bvec3 param_2) {
+ return vec3(param_2[0] ? param_1[0] : param_0[0], param_2[1] ? param_1[1] : param_0[1], param_2[2] ? param_1[2] : param_0[2]);
+}
+
+
struct GammaTransferParams {
float G;
float A;
@@ -157,7 +167,7 @@
bvec3 cond = lessThan(abs(v), vec3(params.D));
vec3 t = (sign(v) * ((params.C * abs(v)) + params.F));
vec3 f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3(params.G)) + params.E));
- return mix(f, t, cond);
+ return tint_select(f, t, cond);
}
@@ -210,6 +220,11 @@
}
#version 310 es
+vec3 tint_select(vec3 param_0, vec3 param_1, bvec3 param_2) {
+ return vec3(param_2[0] ? param_1[0] : param_0[0], param_2[1] ? param_1[1] : param_0[1], param_2[2] ? param_1[2] : param_0[2]);
+}
+
+
struct GammaTransferParams {
float G;
float A;
@@ -259,7 +274,7 @@
bvec3 cond = lessThan(abs(v), vec3(params.D));
vec3 t = (sign(v) * ((params.C * abs(v)) + params.F));
vec3 f = (sign(v) * (pow(((params.A * abs(v)) + params.B), vec3(params.G)) + params.E));
- return mix(f, t, cond);
+ return tint_select(f, t, cond);
}