mirror of
				https://github.com/encounter/dawn-cmake.git
				synced 2025-10-25 19:20:30 +00:00 
			
		
		
		
	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>
		
			
				
	
	
		
			166 lines
		
	
	
		
			6.8 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			166 lines
		
	
	
		
			6.8 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| ; SPIR-V
 | |
| ; Version: 1.3
 | |
| ; Generator: Google Tint Compiler; 0
 | |
| ; Bound: 105
 | |
| ; Schema: 0
 | |
|                OpCapability Shader
 | |
|                OpMemoryModel Logical GLSL450
 | |
|                OpEntryPoint GLCompute %compute_main "compute_main" %local_invocation_index_1_param_1
 | |
|                OpExecutionMode %compute_main LocalSize 1 1 1
 | |
|                OpName %local_invocation_index_1_param_1 "local_invocation_index_1_param_1"
 | |
|                OpName %local_invocation_index_1 "local_invocation_index_1"
 | |
|                OpName %wg "wg"
 | |
|                OpName %tint_div "tint_div"
 | |
|                OpName %lhs "lhs"
 | |
|                OpName %rhs "rhs"
 | |
|                OpName %tint_mod "tint_mod"
 | |
|                OpName %lhs_0 "lhs"
 | |
|                OpName %rhs_0 "rhs"
 | |
|                OpName %compute_main_inner "compute_main_inner"
 | |
|                OpName %local_invocation_index "local_invocation_index"
 | |
|                OpName %idx "idx"
 | |
|                OpName %compute_main_1 "compute_main_1"
 | |
|                OpName %compute_main_inner_1 "compute_main_inner_1"
 | |
|                OpName %local_invocation_index_1_param "local_invocation_index_1_param"
 | |
|                OpName %idx_1 "idx_1"
 | |
|                OpName %compute_main "compute_main"
 | |
|                OpDecorate %local_invocation_index_1_param_1 BuiltIn LocalInvocationIndex
 | |
|                OpDecorate %_arr_uint_uint_1 ArrayStride 4
 | |
|                OpDecorate %_arr__arr_uint_uint_1_uint_2 ArrayStride 4
 | |
|                OpDecorate %_arr__arr__arr_uint_uint_1_uint_2_uint_3 ArrayStride 8
 | |
|        %uint = OpTypeInt 32 0
 | |
| %_ptr_Input_uint = OpTypePointer Input %uint
 | |
| %local_invocation_index_1_param_1 = OpVariable %_ptr_Input_uint Input
 | |
| %_ptr_Private_uint = OpTypePointer Private %uint
 | |
|           %6 = OpConstantNull %uint
 | |
| %local_invocation_index_1 = OpVariable %_ptr_Private_uint Private %6
 | |
|      %uint_1 = OpConstant %uint 1
 | |
| %_arr_uint_uint_1 = OpTypeArray %uint %uint_1
 | |
|      %uint_2 = OpConstant %uint 2
 | |
| %_arr__arr_uint_uint_1_uint_2 = OpTypeArray %_arr_uint_uint_1 %uint_2
 | |
|      %uint_3 = OpConstant %uint 3
 | |
| %_arr__arr__arr_uint_uint_1_uint_2_uint_3 = OpTypeArray %_arr__arr_uint_uint_1_uint_2 %uint_3
 | |
| %_ptr_Workgroup__arr__arr__arr_uint_uint_1_uint_2_uint_3 = OpTypePointer Workgroup %_arr__arr__arr_uint_uint_1_uint_2_uint_3
 | |
|          %wg = OpVariable %_ptr_Workgroup__arr__arr__arr_uint_uint_1_uint_2_uint_3 Workgroup
 | |
|          %15 = OpTypeFunction %uint %uint %uint
 | |
|        %bool = OpTypeBool
 | |
|        %void = OpTypeVoid
 | |
|          %31 = OpTypeFunction %void %uint
 | |
| %_ptr_Function_uint = OpTypePointer Function %uint
 | |
|      %uint_6 = OpConstant %uint 6
 | |
|      %uint_0 = OpConstant %uint 0
 | |
| %_ptr_Workgroup_uint = OpTypePointer Workgroup %uint
 | |
|    %uint_264 = OpConstant %uint 264
 | |
|         %int = OpTypeInt 32 1
 | |
|       %int_2 = OpConstant %int 2
 | |
|       %int_1 = OpConstant %int 1
 | |
|          %68 = OpConstantNull %int
 | |
|          %70 = OpTypeFunction %void
 | |
|    %tint_div = OpFunction %uint None %15
 | |
|         %lhs = OpFunctionParameter %uint
 | |
|         %rhs = OpFunctionParameter %uint
 | |
|          %19 = OpLabel
 | |
|          %21 = OpIEqual %bool %rhs %6
 | |
|          %20 = OpSelect %uint %21 %uint_1 %rhs
 | |
|          %23 = OpUDiv %uint %lhs %20
 | |
|                OpReturnValue %23
 | |
|                OpFunctionEnd
 | |
|    %tint_mod = OpFunction %uint None %15
 | |
|       %lhs_0 = OpFunctionParameter %uint
 | |
|       %rhs_0 = OpFunctionParameter %uint
 | |
|          %27 = OpLabel
 | |
|          %29 = OpIEqual %bool %rhs_0 %6
 | |
|          %28 = OpSelect %uint %29 %uint_1 %rhs_0
 | |
|          %30 = OpUMod %uint %lhs_0 %28
 | |
|                OpReturnValue %30
 | |
|                OpFunctionEnd
 | |
| %compute_main_inner = OpFunction %void None %31
 | |
| %local_invocation_index = OpFunctionParameter %uint
 | |
|          %35 = OpLabel
 | |
|         %idx = OpVariable %_ptr_Function_uint Function %6
 | |
|                OpStore %idx %6
 | |
|                OpStore %idx %local_invocation_index
 | |
|                OpBranch %38
 | |
|          %38 = OpLabel
 | |
|                OpLoopMerge %39 %40 None
 | |
|                OpBranch %41
 | |
|          %41 = OpLabel
 | |
|          %42 = OpLoad %uint %idx
 | |
|          %45 = OpULessThan %bool %42 %uint_6
 | |
|          %43 = OpLogicalNot %bool %45
 | |
|                OpSelectionMerge %46 None
 | |
|                OpBranchConditional %43 %47 %46
 | |
|          %47 = OpLabel
 | |
|                OpBranch %39
 | |
|          %46 = OpLabel
 | |
|          %48 = OpLoad %uint %idx
 | |
|          %49 = OpLoad %uint %idx
 | |
|          %50 = OpLoad %uint %idx
 | |
|          %51 = OpFunctionCall %uint %tint_div %48 %uint_2
 | |
|          %52 = OpFunctionCall %uint %tint_mod %49 %uint_2
 | |
|          %53 = OpFunctionCall %uint %tint_mod %50 %uint_1
 | |
|          %58 = OpAccessChain %_ptr_Workgroup_uint %wg %51 %52 %53
 | |
|                OpAtomicStore %58 %uint_2 %uint_0 %6
 | |
|                OpBranch %40
 | |
|          %40 = OpLabel
 | |
|          %59 = OpLoad %uint %idx
 | |
|          %60 = OpIAdd %uint %59 %uint_1
 | |
|                OpStore %idx %60
 | |
|                OpBranch %38
 | |
|          %39 = OpLabel
 | |
|                OpControlBarrier %uint_2 %uint_2 %uint_264
 | |
|          %69 = OpAccessChain %_ptr_Workgroup_uint %wg %int_2 %int_1 %68
 | |
|                OpAtomicStore %69 %uint_2 %uint_0 %uint_1
 | |
|                OpReturn
 | |
|                OpFunctionEnd
 | |
| %compute_main_1 = OpFunction %void None %70
 | |
|          %72 = OpLabel
 | |
|          %73 = OpLoad %uint %local_invocation_index_1
 | |
|          %74 = OpFunctionCall %void %compute_main_inner %73
 | |
|                OpReturn
 | |
|                OpFunctionEnd
 | |
| %compute_main_inner_1 = OpFunction %void None %31
 | |
| %local_invocation_index_1_param = OpFunctionParameter %uint
 | |
|          %77 = OpLabel
 | |
|       %idx_1 = OpVariable %_ptr_Function_uint Function %6
 | |
|                OpStore %idx_1 %local_invocation_index_1_param
 | |
|                OpBranch %79
 | |
|          %79 = OpLabel
 | |
|                OpLoopMerge %80 %81 None
 | |
|                OpBranch %82
 | |
|          %82 = OpLabel
 | |
|          %84 = OpLoad %uint %idx_1
 | |
|          %85 = OpULessThan %bool %84 %uint_6
 | |
|          %83 = OpLogicalNot %bool %85
 | |
|                OpSelectionMerge %86 None
 | |
|                OpBranchConditional %83 %87 %86
 | |
|          %87 = OpLabel
 | |
|                OpBranch %80
 | |
|          %86 = OpLabel
 | |
|          %88 = OpLoad %uint %idx_1
 | |
|          %89 = OpUDiv %uint %88 %uint_2
 | |
|          %90 = OpLoad %uint %idx_1
 | |
|          %91 = OpUMod %uint %90 %uint_2
 | |
|          %92 = OpLoad %uint %idx_1
 | |
|          %93 = OpUMod %uint %92 %uint_1
 | |
|          %96 = OpAccessChain %_ptr_Workgroup_uint %wg %89 %91 %93
 | |
|                OpAtomicStore %96 %uint_2 %uint_0 %6
 | |
|                OpBranch %81
 | |
|          %81 = OpLabel
 | |
|          %97 = OpLoad %uint %idx_1
 | |
|          %98 = OpIAdd %uint %97 %uint_1
 | |
|                OpStore %idx_1 %98
 | |
|                OpBranch %79
 | |
|          %80 = OpLabel
 | |
|                OpControlBarrier %uint_2 %uint_2 %uint_264
 | |
|                OpStore %local_invocation_index_1 %local_invocation_index_1_param
 | |
|         %100 = OpFunctionCall %void %compute_main_1
 | |
|                OpReturn
 | |
|                OpFunctionEnd
 | |
| %compute_main = OpFunction %void None %70
 | |
|         %102 = OpLabel
 | |
|         %104 = OpLoad %uint %local_invocation_index_1_param_1
 | |
|         %103 = OpFunctionCall %void %compute_main_inner_1 %104
 | |
|                OpReturn
 | |
|                OpFunctionEnd
 |