mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 10:25:28 +00:00
tint/transform: Implement div / mod polyfill
Prevents UB for divide-by-zero and integer overflow when dividing Fixed: tint:1349 Change-Id: Ieef66d27d7aec3011628ced076b2bccc7770a8af Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/108925 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
9418152d08
commit
46ee63933c
@@ -1,13 +1,16 @@
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
; Bound: 31
|
||||
; Bound: 47
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
|
||||
OpExecutionMode %unused_entry_point LocalSize 1 1 1
|
||||
OpName %unused_entry_point "unused_entry_point"
|
||||
OpName %tint_div "tint_div"
|
||||
OpName %lhs "lhs"
|
||||
OpName %rhs "rhs"
|
||||
OpName %foo "foo"
|
||||
OpName %a "a"
|
||||
OpName %b "b"
|
||||
@@ -15,37 +18,55 @@
|
||||
%void = OpTypeVoid
|
||||
%1 = OpTypeFunction %void
|
||||
%int = OpTypeInt 32 1
|
||||
%5 = OpTypeFunction %int %int %int
|
||||
%12 = OpConstantNull %int
|
||||
%bool = OpTypeBool
|
||||
%int_n2147483648 = OpConstant %int -2147483648
|
||||
%int_n1 = OpConstant %int -1
|
||||
%int_1 = OpConstant %int 1
|
||||
%_ptr_Function_int = OpTypePointer Function %int
|
||||
%10 = OpConstantNull %int
|
||||
%float = OpTypeFloat 32
|
||||
%v4float = OpTypeVector %float 4
|
||||
%_ptr_Function_v4float = OpTypePointer Function %v4float
|
||||
%15 = OpConstantNull %v4float
|
||||
%31 = OpConstantNull %v4float
|
||||
%v2float = OpTypeVector %float 2
|
||||
%mat2v2float = OpTypeMatrix %v2float 2
|
||||
%_ptr_Function_mat2v2float = OpTypePointer Function %mat2v2float
|
||||
%20 = OpConstantNull %mat2v2float
|
||||
%36 = OpConstantNull %mat2v2float
|
||||
%int_2 = OpConstant %int 2
|
||||
%mat4v4float = OpTypeMatrix %v4float 4
|
||||
%26 = OpConstantNull %mat4v4float
|
||||
%42 = OpConstantNull %mat4v4float
|
||||
%float_2 = OpConstant %float 2
|
||||
%unused_entry_point = OpFunction %void None %1
|
||||
%4 = OpLabel
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
%tint_div = OpFunction %int None %5
|
||||
%lhs = OpFunctionParameter %int
|
||||
%rhs = OpFunctionParameter %int
|
||||
%10 = OpLabel
|
||||
%13 = OpIEqual %bool %rhs %12
|
||||
%16 = OpIEqual %bool %lhs %int_n2147483648
|
||||
%18 = OpIEqual %bool %rhs %int_n1
|
||||
%19 = OpLogicalAnd %bool %16 %18
|
||||
%20 = OpLogicalOr %bool %13 %19
|
||||
%11 = OpSelect %int %20 %int_1 %rhs
|
||||
%22 = OpSDiv %int %lhs %11
|
||||
OpReturnValue %22
|
||||
OpFunctionEnd
|
||||
%foo = OpFunction %void None %1
|
||||
%6 = OpLabel
|
||||
%a = OpVariable %_ptr_Function_int Function %10
|
||||
%b = OpVariable %_ptr_Function_v4float Function %15
|
||||
%c = OpVariable %_ptr_Function_mat2v2float Function %20
|
||||
%21 = OpLoad %int %a
|
||||
%23 = OpSDiv %int %21 %int_2
|
||||
OpStore %a %23
|
||||
%24 = OpLoad %v4float %b
|
||||
%27 = OpVectorTimesMatrix %v4float %24 %26
|
||||
OpStore %b %27
|
||||
%28 = OpLoad %mat2v2float %c
|
||||
%30 = OpMatrixTimesScalar %mat2v2float %28 %float_2
|
||||
OpStore %c %30
|
||||
%24 = OpLabel
|
||||
%a = OpVariable %_ptr_Function_int Function %12
|
||||
%b = OpVariable %_ptr_Function_v4float Function %31
|
||||
%c = OpVariable %_ptr_Function_mat2v2float Function %36
|
||||
%38 = OpLoad %int %a
|
||||
%37 = OpFunctionCall %int %tint_div %38 %int_2
|
||||
OpStore %a %37
|
||||
%40 = OpLoad %v4float %b
|
||||
%43 = OpVectorTimesMatrix %v4float %40 %42
|
||||
OpStore %b %43
|
||||
%44 = OpLoad %mat2v2float %c
|
||||
%46 = OpMatrixTimesScalar %mat2v2float %44 %float_2
|
||||
OpStore %c %46
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
|
||||
Reference in New Issue
Block a user