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,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.