GLSL: fix sample_index, sample_mask and bitcasts

In GLSL, gl_SampleID and gl_SampleMask[In] require the
GL_OES_sample_variables extension, so output:

"#extension GL_OES_sample_variables : require"

in the header if those builtins is used.

Note that extensions must be inserted before the default precision
declaration, but helpers must be inserted after it, so we set a flag
and emit extensions, then the precision declaration, then helpers.

Further fixes:
- use gl_SampleMaskIn for input builtins, gl_SampleMask for output,
  necessitating the addition of a storage class to GLSLBuiltinToString()
- fix the handling of gl_SampleMaskIn: it's array<i32> in GLSL, not
  array<u32> as in SPIR-V
- centralize conversions for GLSL builtins used as input variables in
  FromGLSLBuiltin()
- implement bitcasts on assignment to GLSL builtin output variables,
  centralized in ToGLSLBuiltin()
- update the extension handling in the GLSL writer to check for both
  sample_index and sample_mask.
- call UnwrapRef() in GLSL's EmitBitcast(). In the test case, we were
  not recognizing the argument as a uint, yielding float() instead of
  uintBitsToFloat().

Bug: tint:1408, tint:1412, tint:1414

Change-Id: Ie01541eb6e7cdf4e21347341f988bff916346797
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/78920
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Stephen White
2022-02-04 16:41:33 +00:00
committed by Tint LUCI CQ
parent 009d129103
commit a924ffe70c
35 changed files with 196 additions and 800 deletions

View File

@@ -1,6 +1,5 @@
SKIP: FAILED
#version 310 es
#extension GL_OES_sample_variables : require
precision mediump float;
layout(location = 0) in float a_1;
@@ -20,16 +19,9 @@ FragIn tint_symbol(FragIn tint_symbol_1, float b) {
}
void main() {
FragIn tint_symbol_3 = FragIn(a_1, uint(gl_SampleMask[0]));
FragIn tint_symbol_3 = FragIn(a_1, uint(gl_SampleMaskIn[0]));
FragIn inner_result = tint_symbol(tint_symbol_3, b_1);
a_2 = inner_result.a;
gl_SampleMask_1[0] = inner_result.mask;
gl_SampleMask[0] = int(inner_result.mask);
return;
}
Error parsing GLSL shader:
ERROR: 0:21: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:21: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,6 +1,5 @@
SKIP: FAILED
#version 310 es
#extension GL_OES_sample_variables : require
precision mediump float;
void tint_symbol(vec4 position, bool front_facing, uint sample_index, uint sample_mask) {
@@ -11,13 +10,6 @@ void tint_symbol(vec4 position, bool front_facing, uint sample_index, uint sampl
}
void main() {
tint_symbol(gl_FragCoord, gl_FrontFacing, uint(gl_SampleID), uint(gl_SampleMask[0]));
tint_symbol(gl_FragCoord, gl_FrontFacing, uint(gl_SampleID), uint(gl_SampleMaskIn[0]));
return;
}
Error parsing GLSL shader:
ERROR: 0:12: 'gl_SampleID' : required extension not requested: GL_OES_sample_variables
ERROR: 0:12: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,6 +1,5 @@
SKIP: FAILED
#version 310 es
#extension GL_OES_sample_variables : require
precision mediump float;
struct FragmentInputs {
@@ -18,14 +17,7 @@ void tint_symbol(FragmentInputs inputs) {
}
void main() {
FragmentInputs tint_symbol_1 = FragmentInputs(gl_FragCoord, gl_FrontFacing, uint(gl_SampleID), uint(gl_SampleMask[0]));
FragmentInputs tint_symbol_1 = FragmentInputs(gl_FragCoord, gl_FrontFacing, uint(gl_SampleID), uint(gl_SampleMaskIn[0]));
tint_symbol(tint_symbol_1);
return;
}
Error parsing GLSL shader:
ERROR: 0:19: 'gl_SampleID' : required extension not requested: GL_OES_sample_variables
ERROR: 0:19: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,6 +1,5 @@
SKIP: FAILED
#version 310 es
#extension GL_OES_sample_variables : require
precision mediump float;
layout(location = 0) flat in int loc0_1;
@@ -30,14 +29,7 @@ void tint_symbol(FragmentInputs0 inputs0, bool front_facing, uint loc1, uint sam
void main() {
FragmentInputs0 tint_symbol_1 = FragmentInputs0(gl_FragCoord, loc0_1);
FragmentInputs1 tint_symbol_2 = FragmentInputs1(loc3_1, uint(gl_SampleMask[0]));
FragmentInputs1 tint_symbol_2 = FragmentInputs1(loc3_1, uint(gl_SampleMaskIn[0]));
tint_symbol(tint_symbol_1, gl_FrontFacing, loc1_1, uint(gl_SampleID), tint_symbol_2, loc2_1);
return;
}
Error parsing GLSL shader:
ERROR: 0:31: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:31: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,5 +1,3 @@
SKIP: FAILED
#version 310 es
precision mediump float;
@@ -13,6 +11,7 @@ void main() {
return;
}
#version 310 es
#extension GL_OES_sample_variables : require
precision mediump float;
uint main2() {
@@ -21,13 +20,6 @@ uint main2() {
void main() {
uint inner_result = main2();
gl_SampleMask[0] = inner_result;
gl_SampleMask[0] = int(inner_result);
return;
}
Error parsing GLSL shader:
ERROR: 0:10: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:10: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,6 +1,5 @@
SKIP: FAILED
#version 310 es
#extension GL_OES_sample_variables : require
precision mediump float;
struct FragmentOutputs {
@@ -16,13 +15,6 @@ FragmentOutputs tint_symbol() {
void main() {
FragmentOutputs inner_result = tint_symbol();
gl_FragDepth = inner_result.frag_depth;
gl_SampleMask[0] = inner_result.sample_mask;
gl_SampleMask[0] = int(inner_result.sample_mask);
return;
}
Error parsing GLSL shader:
ERROR: 0:17: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:17: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,6 +1,5 @@
SKIP: FAILED
#version 310 es
#extension GL_OES_sample_variables : require
precision mediump float;
layout(location = 0) out int loc0_1;
@@ -27,14 +26,7 @@ void main() {
gl_FragDepth = inner_result.frag_depth;
loc1_1 = inner_result.loc1;
loc2_1 = inner_result.loc2;
gl_SampleMask[0] = inner_result.sample_mask;
gl_SampleMask[0] = int(inner_result.sample_mask);
loc3_1 = inner_result.loc3;
return;
}
Error parsing GLSL shader:
ERROR: 0:28: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:28: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,26 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
int x_1[1] = int[1](0);
void main_1() {
return;
}
void tint_symbol(uint x_1_param) {
x_1[0] = int(x_1_param);
main_1();
}
void main() {
tint_symbol(uint(gl_SampleMask[0]));
return;
}
Error parsing GLSL shader:
ERROR: 0:15: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:15: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,26 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
uint x_1[1] = uint[1](0u);
void main_1() {
return;
}
void tint_symbol(uint x_1_param) {
x_1[0] = x_1_param;
main_1();
}
void main() {
tint_symbol(uint(gl_SampleMask[0]));
return;
}
Error parsing GLSL shader:
ERROR: 0:15: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:15: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,32 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
int x_1[1] = int[1](0);
void main_1() {
return;
}
struct main_out {
uint x_1_1;
};
main_out tint_symbol() {
main_1();
main_out tint_symbol_1 = main_out(uint(x_1[0]));
return tint_symbol_1;
}
void main() {
main_out inner_result = tint_symbol();
gl_SampleMask[0] = inner_result.x_1_1;
return;
}
Error parsing GLSL shader:
ERROR: 0:21: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:21: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,32 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
uint x_1[1] = uint[1](0u);
void main_1() {
return;
}
struct main_out {
uint x_1_1;
};
main_out tint_symbol() {
main_1();
main_out tint_symbol_1 = main_out(x_1[0]);
return tint_symbol_1;
}
void main() {
main_out inner_result = tint_symbol();
gl_SampleMask[0] = inner_result.x_1_1;
return;
}
Error parsing GLSL shader:
ERROR: 0:21: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:21: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,27 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
int x_1 = 0;
void main_1() {
int x_2 = x_1;
return;
}
void tint_symbol(uint x_1_param) {
x_1 = int(x_1_param);
main_1();
}
void main() {
tint_symbol(uint(gl_SampleID));
return;
}
Error parsing GLSL shader:
ERROR: 0:16: 'gl_SampleID' : required extension not requested: GL_OES_sample_variables
ERROR: 0:16: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,27 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
int x_1 = 0;
void main_1() {
int x_2 = x_1;
return;
}
void tint_symbol(uint x_1_param) {
x_1 = int(x_1_param);
main_1();
}
void main() {
tint_symbol(uint(gl_SampleID));
return;
}
Error parsing GLSL shader:
ERROR: 0:16: 'gl_SampleID' : required extension not requested: GL_OES_sample_variables
ERROR: 0:16: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,27 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
int x_1 = 0;
void main_1() {
int x_2 = x_1;
return;
}
void tint_symbol(uint x_1_param) {
x_1 = int(x_1_param);
main_1();
}
void main() {
tint_symbol(uint(gl_SampleID));
return;
}
Error parsing GLSL shader:
ERROR: 0:16: 'gl_SampleID' : required extension not requested: GL_OES_sample_variables
ERROR: 0:16: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,27 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
uint x_1 = 0u;
void main_1() {
uint x_2 = x_1;
return;
}
void tint_symbol(uint x_1_param) {
x_1 = x_1_param;
main_1();
}
void main() {
tint_symbol(uint(gl_SampleID));
return;
}
Error parsing GLSL shader:
ERROR: 0:16: 'gl_SampleID' : required extension not requested: GL_OES_sample_variables
ERROR: 0:16: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,27 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
uint x_1 = 0u;
void main_1() {
uint x_2 = x_1;
return;
}
void tint_symbol(uint x_1_param) {
x_1 = x_1_param;
main_1();
}
void main() {
tint_symbol(uint(gl_SampleID));
return;
}
Error parsing GLSL shader:
ERROR: 0:16: 'gl_SampleID' : required extension not requested: GL_OES_sample_variables
ERROR: 0:16: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,27 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
uint x_1 = 0u;
void main_1() {
uint x_2 = x_1;
return;
}
void tint_symbol(uint x_1_param) {
x_1 = x_1_param;
main_1();
}
void main() {
tint_symbol(uint(gl_SampleID));
return;
}
Error parsing GLSL shader:
ERROR: 0:16: 'gl_SampleID' : required extension not requested: GL_OES_sample_variables
ERROR: 0:16: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,27 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
int x_1[1] = int[1](0);
void main_1() {
int x_4 = x_1[0];
return;
}
void tint_symbol(uint x_1_param) {
x_1[0] = int(x_1_param);
main_1();
}
void main() {
tint_symbol(uint(gl_SampleMask[0]));
return;
}
Error parsing GLSL shader:
ERROR: 0:16: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:16: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,27 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
int x_1[1] = int[1](0);
void main_1() {
int x_4 = x_1[0];
return;
}
void tint_symbol(uint x_1_param) {
x_1[0] = int(x_1_param);
main_1();
}
void main() {
tint_symbol(uint(gl_SampleMask[0]));
return;
}
Error parsing GLSL shader:
ERROR: 0:16: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:16: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,27 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
int x_1[1] = int[1](0);
void main_1() {
int x_3 = x_1[0];
return;
}
void tint_symbol(uint x_1_param) {
x_1[0] = int(x_1_param);
main_1();
}
void main() {
tint_symbol(uint(gl_SampleMask[0]));
return;
}
Error parsing GLSL shader:
ERROR: 0:16: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:16: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,27 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
uint x_1[1] = uint[1](0u);
void main_1() {
uint x_4 = x_1[0];
return;
}
void tint_symbol(uint x_1_param) {
x_1[0] = x_1_param;
main_1();
}
void main() {
tint_symbol(uint(gl_SampleMask[0]));
return;
}
Error parsing GLSL shader:
ERROR: 0:16: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:16: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,27 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
uint x_1[1] = uint[1](0u);
void main_1() {
uint x_4 = x_1[0];
return;
}
void tint_symbol(uint x_1_param) {
x_1[0] = x_1_param;
main_1();
}
void main() {
tint_symbol(uint(gl_SampleMask[0]));
return;
}
Error parsing GLSL shader:
ERROR: 0:16: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:16: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,27 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
uint x_1[1] = uint[1](0u);
void main_1() {
uint x_3 = x_1[0];
return;
}
void tint_symbol(uint x_1_param) {
x_1[0] = x_1_param;
main_1();
}
void main() {
tint_symbol(uint(gl_SampleMask[0]));
return;
}
Error parsing GLSL shader:
ERROR: 0:16: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:16: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,27 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
uint x_1[1] = uint[1](0u);
void main_1() {
uint x_3 = x_1[0];
return;
}
void tint_symbol(uint x_1_param) {
x_1[0] = x_1_param;
main_1();
}
void main() {
tint_symbol(uint(gl_SampleMask[0]));
return;
}
Error parsing GLSL shader:
ERROR: 0:16: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:16: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,33 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
int x_1[1] = int[1](0);
void main_1() {
x_1[0] = 12;
return;
}
struct main_out {
uint x_1_1;
};
main_out tint_symbol() {
main_1();
main_out tint_symbol_1 = main_out(uint(x_1[0]));
return tint_symbol_1;
}
void main() {
main_out inner_result = tint_symbol();
gl_SampleMask[0] = inner_result.x_1_1;
return;
}
Error parsing GLSL shader:
ERROR: 0:22: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:22: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,33 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
int x_1[1] = int[1](0);
void main_1() {
x_1[0] = 12;
return;
}
struct main_out {
uint x_1_1;
};
main_out tint_symbol() {
main_1();
main_out tint_symbol_1 = main_out(uint(x_1[0]));
return tint_symbol_1;
}
void main() {
main_out inner_result = tint_symbol();
gl_SampleMask[0] = inner_result.x_1_1;
return;
}
Error parsing GLSL shader:
ERROR: 0:22: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:22: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,33 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
int x_1[1] = int[1](0);
void main_1() {
x_1[0] = 12;
return;
}
struct main_out {
uint x_1_1;
};
main_out tint_symbol() {
main_1();
main_out tint_symbol_1 = main_out(uint(x_1[0]));
return tint_symbol_1;
}
void main() {
main_out inner_result = tint_symbol();
gl_SampleMask[0] = inner_result.x_1_1;
return;
}
Error parsing GLSL shader:
ERROR: 0:22: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:22: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,33 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
uint x_1[1] = uint[1](0u);
void main_1() {
x_1[0] = 0u;
return;
}
struct main_out {
uint x_1_1;
};
main_out tint_symbol() {
main_1();
main_out tint_symbol_1 = main_out(x_1[0]);
return tint_symbol_1;
}
void main() {
main_out inner_result = tint_symbol();
gl_SampleMask[0] = inner_result.x_1_1;
return;
}
Error parsing GLSL shader:
ERROR: 0:22: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:22: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,33 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
uint x_1[1] = uint[1](0u);
void main_1() {
x_1[0] = 0u;
return;
}
struct main_out {
uint x_1_1;
};
main_out tint_symbol() {
main_1();
main_out tint_symbol_1 = main_out(x_1[0]);
return tint_symbol_1;
}
void main() {
main_out inner_result = tint_symbol();
gl_SampleMask[0] = inner_result.x_1_1;
return;
}
Error parsing GLSL shader:
ERROR: 0:22: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:22: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,33 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
uint x_1[1] = uint[1](0u);
void main_1() {
x_1[0] = 0u;
return;
}
struct main_out {
uint x_1_1;
};
main_out tint_symbol() {
main_1();
main_out tint_symbol_1 = main_out(x_1[0]);
return tint_symbol_1;
}
void main() {
main_out inner_result = tint_symbol();
gl_SampleMask[0] = inner_result.x_1_1;
return;
}
Error parsing GLSL shader:
ERROR: 0:22: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:22: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.

View File

@@ -1,33 +0,0 @@
SKIP: FAILED
#version 310 es
precision mediump float;
uint x_1[1] = uint[1](0u);
void main_1() {
x_1[0] = 0u;
return;
}
struct main_out {
uint x_1_1;
};
main_out tint_symbol() {
main_1();
main_out tint_symbol_1 = main_out(x_1[0]);
return tint_symbol_1;
}
void main() {
main_out inner_result = tint_symbol();
gl_SampleMask[0] = inner_result.x_1_1;
return;
}
Error parsing GLSL shader:
ERROR: 0:22: 'gl_SampleMask' : required extension not requested: GL_OES_sample_variables
ERROR: 0:22: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.