Fix FXC compile errors on modulo by zero

Just like for divide, FXC fails with the exact same error when
performing a modulo on a value that FXC determines to be zero. We
address it in the same way as we do for divide.

This also fixes a couple of the vk-gl-cts tests for which I manually
generated expectation files for.

Bug: tint:1083
Change-Id: Ia388bf002112afded542adb791d37e88e35a77ff
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/74220
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano
2021-12-22 15:02:09 +00:00
committed by Tint LUCI CQ
parent cc4d97b6e3
commit 9943de6813
159 changed files with 1965 additions and 69 deletions

View File

@@ -0,0 +1,6 @@
[[stage(compute), workgroup_size(1)]]
fn f() {
var a = 1.;
var b = 0.;
let r : f32 = a % (b + b);
}

View File

@@ -0,0 +1,7 @@
[numthreads(1, 1, 1)]
void f() {
float a = 1.0f;
float b = 0.0f;
const float r = (a % (b + b));
return;
}

View File

@@ -0,0 +1,10 @@
#include <metal_stdlib>
using namespace metal;
kernel void f() {
float a = 1.0f;
float b = 0.0f;
float const r = fmod(a, (b + b));
return;
}

View File

@@ -0,0 +1,32 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 17
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %f "f"
OpExecutionMode %f LocalSize 1 1 1
OpName %f "f"
OpName %a "a"
OpName %b "b"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%float = OpTypeFloat 32
%float_1 = OpConstant %float 1
%_ptr_Function_float = OpTypePointer Function %float
%9 = OpConstantNull %float
%float_0 = OpConstant %float 0
%f = OpFunction %void None %1
%4 = OpLabel
%a = OpVariable %_ptr_Function_float Function %9
%b = OpVariable %_ptr_Function_float Function %9
OpStore %a %float_1
OpStore %b %float_0
%12 = OpLoad %float %a
%13 = OpLoad %float %b
%14 = OpLoad %float %b
%15 = OpFAdd %float %13 %14
%16 = OpFRem %float %12 %15
OpReturn
OpFunctionEnd

View File

@@ -0,0 +1,6 @@
[[stage(compute), workgroup_size(1)]]
fn f() {
var a = 1.0;
var b = 0.0;
let r : f32 = (a % (b + b));
}

View File

@@ -0,0 +1,6 @@
[[stage(compute), workgroup_size(1)]]
fn f() {
var a = 1;
var b = 0;
let r : i32 = a % (b + b);
}

View File

@@ -0,0 +1,11 @@
int value_or_one_if_zero_int(int value) {
return value == 0 ? 1 : value;
}
[numthreads(1, 1, 1)]
void f() {
int a = 1;
int b = 0;
const int r = (a % value_or_one_if_zero_int((b + b)));
return;
}

View File

@@ -0,0 +1,10 @@
#include <metal_stdlib>
using namespace metal;
kernel void f() {
int a = 1;
int b = 0;
int const r = (a % as_type<int>((as_type<uint>(b) + as_type<uint>(b))));
return;
}

View File

@@ -0,0 +1,32 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 17
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %f "f"
OpExecutionMode %f LocalSize 1 1 1
OpName %f "f"
OpName %a "a"
OpName %b "b"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%int = OpTypeInt 32 1
%int_1 = OpConstant %int 1
%_ptr_Function_int = OpTypePointer Function %int
%9 = OpConstantNull %int
%int_0 = OpConstant %int 0
%f = OpFunction %void None %1
%4 = OpLabel
%a = OpVariable %_ptr_Function_int Function %9
%b = OpVariable %_ptr_Function_int Function %9
OpStore %a %int_1
OpStore %b %int_0
%12 = OpLoad %int %a
%13 = OpLoad %int %b
%14 = OpLoad %int %b
%15 = OpIAdd %int %13 %14
%16 = OpSMod %int %12 %15
OpReturn
OpFunctionEnd

View File

@@ -0,0 +1,6 @@
[[stage(compute), workgroup_size(1)]]
fn f() {
var a = 1;
var b = 0;
let r : i32 = (a % (b + b));
}

View File

@@ -0,0 +1,6 @@
[[stage(compute), workgroup_size(1)]]
fn f() {
var a = 1u;
var b = 0u;
let r : u32 = a % (b + b);
}

View File

@@ -0,0 +1,11 @@
uint value_or_one_if_zero_uint(uint value) {
return value == 0u ? 1u : value;
}
[numthreads(1, 1, 1)]
void f() {
uint a = 1u;
uint b = 0u;
const uint r = (a % value_or_one_if_zero_uint((b + b)));
return;
}

View File

@@ -0,0 +1,10 @@
#include <metal_stdlib>
using namespace metal;
kernel void f() {
uint a = 1u;
uint b = 0u;
uint const r = (a % (b + b));
return;
}

View File

@@ -0,0 +1,32 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 17
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %f "f"
OpExecutionMode %f LocalSize 1 1 1
OpName %f "f"
OpName %a "a"
OpName %b "b"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_ptr_Function_uint = OpTypePointer Function %uint
%9 = OpConstantNull %uint
%uint_0 = OpConstant %uint 0
%f = OpFunction %void None %1
%4 = OpLabel
%a = OpVariable %_ptr_Function_uint Function %9
%b = OpVariable %_ptr_Function_uint Function %9
OpStore %a %uint_1
OpStore %b %uint_0
%12 = OpLoad %uint %a
%13 = OpLoad %uint %b
%14 = OpLoad %uint %b
%15 = OpIAdd %uint %13 %14
%16 = OpUMod %uint %12 %15
OpReturn
OpFunctionEnd

View File

@@ -0,0 +1,6 @@
[[stage(compute), workgroup_size(1)]]
fn f() {
var a = 1u;
var b = 0u;
let r : u32 = (a % (b + b));
}