-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WGSL] Add validation to integer division during code generation
https://bugs.webkit.org/show_bug.cgi?id=264106 rdar://117865769 Reviewed by Mike Wyrzykowski. According to the spec, the runtime behavior for integer division needs to handle the following two corner cases: - x / 0 = x - INT_MIN / -1 = INT_MIN The latter matches the default Metal behavior, but considering it's technically undefined behavior, it seems safer to handle it explicitly. * Source/WebGPU/WGSL/GlobalVariableRewriter.cpp: (WGSL::RewriteGlobalVariables::getPacking): * Source/WebGPU/WGSL/Metal/MetalCodeGenerator.cpp: (WGSL::Metal::metalCodePrologue): * Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp: (WGSL::Metal::FunctionDefinitionWriter::emitNecessaryHelpers): (WGSL::Metal::FunctionDefinitionWriter::visit): * Source/WebGPU/WGSL/TypeCheck.cpp: (WGSL::TypeChecker::visit): * Source/WebGPU/WGSL/WGSLShaderModule.h: (WGSL::ShaderModule::usesDivision const): (WGSL::ShaderModule::setUsesDivision): (WGSL::ShaderModule::clearUsesDivision): * Source/WebGPU/WGSL/tests/lit.cfg: * Source/WebGPU/WGSL/tests/valid/division.wgsl: Added. Canonical link: https://commits.webkit.org/270174@main
- Loading branch information
1 parent
b01c2d6
commit 3bb0644
Showing
8 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// RUN: %metal-compile main | ||
|
||
fn testI32() | ||
{ | ||
var x: vec2<i32>; | ||
var y: vec2<i32>; | ||
|
||
let a = x / y; | ||
let b = x / y[0]; | ||
let c = x[0] / y; | ||
let d = x[0] / y[0]; | ||
} | ||
|
||
fn testU32() | ||
{ | ||
var x: vec2<u32>; | ||
var y: vec2<u32>; | ||
|
||
let a = x / y; | ||
let b = x / y[0]; | ||
let c = x[0] / y; | ||
let d = x[0] / y[0]; | ||
} | ||
|
||
fn testF32() | ||
{ | ||
var x: vec2<f32>; | ||
var y: vec2<f32>; | ||
|
||
let a = x / y; | ||
let b = x / y[0]; | ||
let c = x[0] / y; | ||
let d = x[0] / y[0]; | ||
} | ||
|
||
fn testI32Compound() | ||
{ | ||
var x: vec2<i32>; | ||
var y: vec2<i32>; | ||
|
||
x /= y; | ||
x /= y[0]; | ||
x[0] /= y[0]; | ||
} | ||
|
||
fn testU32Compound() | ||
{ | ||
var x: vec2<u32>; | ||
var y: vec2<u32>; | ||
|
||
x /= y; | ||
x /= y[0]; | ||
x[0] /= y[0]; | ||
} | ||
|
||
fn testF32Compound() | ||
{ | ||
var x: vec2<f32>; | ||
var y: vec2<f32>; | ||
|
||
x /= y; | ||
x /= y[0]; | ||
x[0] /= y[0]; | ||
} | ||
|
||
@compute @workgroup_size(1) | ||
fn main() { | ||
testI32(); | ||
testU32(); | ||
testF32(); | ||
|
||
testI32Compound(); | ||
testU32Compound(); | ||
testF32Compound(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters