spirv-reader: Declare multiuse constant composites

When an OpConstantComposite result is used by multiple instructions,
declare it as a module-scope `const` instead of inlining the constant
at each use site. This fixes an issue whereby the spirv-reader was
massively inflating the size of the WGSL it produces, which was caught
via an OOM fuzzer bug.

Bug: oss-fuzz:57795
Change-Id: Iac8c6a2147a7e2ebfddbaacae9fcb1dbe0b59e9d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/128881
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: David Neto <dneto@google.com>
This commit is contained in:
James Price
2023-04-25 19:16:25 +00:00
committed by Dawn LUCI CQ
parent a41693babb
commit ae39e6d628
17 changed files with 400 additions and 109 deletions

View File

@@ -1,7 +1,9 @@
const x_10 = vec3<f32>(1.0f, 2.0f, 3.0f);
fn main_1() {
let x_11 : f32 = vec3<f32>(1.0f, 2.0f, 3.0f).y;
let x_13 : vec2<f32> = vec2<f32>(vec3<f32>(1.0f, 2.0f, 3.0f).x, vec3<f32>(1.0f, 2.0f, 3.0f).z);
let x_14 : vec3<f32> = vec3<f32>(vec3<f32>(1.0f, 2.0f, 3.0f).x, vec3<f32>(1.0f, 2.0f, 3.0f).z, vec3<f32>(1.0f, 2.0f, 3.0f).y);
let x_11 : f32 = x_10.y;
let x_13 : vec2<f32> = vec2<f32>(x_10.x, x_10.z);
let x_14 : vec3<f32> = vec3<f32>(x_10.x, x_10.z, x_10.y);
return;
}

Binary file not shown.

View File

@@ -0,0 +1,18 @@
struct S_6 {
float3 field0[13][18];
};
static float4x4 x_75[58] = (float4x4[58])0;
static S_6 x_82[46] = (S_6[46])0;
static float3 x_85[37] = (float3[37])0;
void main_1() {
const uint x_88 = 58u;
return;
}
void main() {
main_1();
return;
}

View File

@@ -0,0 +1,18 @@
struct S_6 {
float3 field0[13][18];
};
static float4x4 x_75[58] = (float4x4[58])0;
static S_6 x_82[46] = (S_6[46])0;
static float3 x_85[37] = (float3[37])0;
void main_1() {
const uint x_88 = 58u;
return;
}
void main() {
main_1();
return;
}

View File

@@ -0,0 +1,48 @@
#version 310 es
precision highp float;
struct S {
mat3 field0;
};
struct S_1 {
S field0[47][21][83];
};
struct S_2 {
vec3 field0[95][37];
};
struct S_3 {
S_2 field0;
};
struct S_4 {
ivec2 field0[56];
};
struct S_5 {
S_4 field0;
};
struct S_6 {
vec3 field0[13][18];
};
struct S_7 {
ivec2 field0[88];
};
void main_1() {
uint x_88 = 58u;
return;
}
void tint_symbol() {
main_1();
}
void main() {
tint_symbol();
return;
}

View File

@@ -0,0 +1,64 @@
#include <metal_stdlib>
using namespace metal;
template<typename T, size_t N>
struct tint_array {
const constant T& operator[](size_t i) const constant { return elements[i]; }
device T& operator[](size_t i) device { return elements[i]; }
const device T& operator[](size_t i) const device { return elements[i]; }
thread T& operator[](size_t i) thread { return elements[i]; }
const thread T& operator[](size_t i) const thread { return elements[i]; }
threadgroup T& operator[](size_t i) threadgroup { return elements[i]; }
const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; }
T elements[N];
};
struct S_6 {
tint_array<tint_array<float3, 18>, 13> field0;
};
struct tint_private_vars_struct {
tint_array<float4x4, 58> x_75;
tint_array<S_6, 46> x_82;
tint_array<float3, 37> x_85;
};
struct S {
float3x3 field0;
};
struct S_1 {
tint_array<tint_array<tint_array<S, 83>, 21>, 47> field0;
};
struct S_2 {
tint_array<tint_array<float3, 37>, 95> field0;
};
struct S_3 {
S_2 field0;
};
struct S_4 {
tint_array<int2, 56> field0;
};
struct S_5 {
S_4 field0;
};
struct S_7 {
tint_array<int2, 88> field0;
};
void main_1() {
uint const x_88 = 58u;
return;
}
fragment void tint_symbol() {
main_1();
return;
}

View File

@@ -0,0 +1,58 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 33
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main"
OpExecutionMode %main OriginUpperLeft
OpName %x_75 "x_75"
OpName %S_6 "S_6"
OpMemberName %S_6 0 "field0"
OpName %x_82 "x_82"
OpName %x_85 "x_85"
OpName %main_1 "main_1"
OpName %main "main"
OpDecorate %_arr_mat4v4float_uint_58 ArrayStride 64
OpMemberDecorate %S_6 0 Offset 0
OpDecorate %_arr_v3float_uint_18 ArrayStride 16
OpDecorate %_arr__arr_v3float_uint_18_uint_13 ArrayStride 288
OpDecorate %_arr_S_6_uint_46 ArrayStride 3744
OpDecorate %_arr_v3float_uint_37 ArrayStride 16
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%mat4v4float = OpTypeMatrix %v4float 4
%uint = OpTypeInt 32 0
%uint_58 = OpConstant %uint 58
%_arr_mat4v4float_uint_58 = OpTypeArray %mat4v4float %uint_58
%7 = OpConstantNull %_arr_mat4v4float_uint_58
%_ptr_Private__arr_mat4v4float_uint_58 = OpTypePointer Private %_arr_mat4v4float_uint_58
%x_75 = OpVariable %_ptr_Private__arr_mat4v4float_uint_58 Private %7
%v3float = OpTypeVector %float 3
%uint_18 = OpConstant %uint 18
%_arr_v3float_uint_18 = OpTypeArray %v3float %uint_18
%uint_13 = OpConstant %uint 13
%_arr__arr_v3float_uint_18_uint_13 = OpTypeArray %_arr_v3float_uint_18 %uint_13
%S_6 = OpTypeStruct %_arr__arr_v3float_uint_18_uint_13
%uint_46 = OpConstant %uint 46
%_arr_S_6_uint_46 = OpTypeArray %S_6 %uint_46
%18 = OpConstantNull %_arr_S_6_uint_46
%_ptr_Private__arr_S_6_uint_46 = OpTypePointer Private %_arr_S_6_uint_46
%x_82 = OpVariable %_ptr_Private__arr_S_6_uint_46 Private %18
%uint_37 = OpConstant %uint 37
%_arr_v3float_uint_37 = OpTypeArray %v3float %uint_37
%23 = OpConstantNull %_arr_v3float_uint_37
%_ptr_Private__arr_v3float_uint_37 = OpTypePointer Private %_arr_v3float_uint_37
%x_85 = OpVariable %_ptr_Private__arr_v3float_uint_37 Private %23
%void = OpTypeVoid
%26 = OpTypeFunction %void
%main_1 = OpFunction %void None %26
%29 = OpLabel
OpReturn
OpFunctionEnd
%main = OpFunction %void None %26
%31 = OpLabel
%32 = OpFunctionCall %void %main_1
OpReturn
OpFunctionEnd

View File

@@ -0,0 +1,57 @@
struct S {
field0 : mat3x3<f32>,
}
struct S_1 {
field0 : array<array<array<S, 83u>, 21u>, 47u>,
}
struct S_2 {
field0 : array<array<vec3<f32>, 37u>, 95u>,
}
struct S_3 {
field0 : S_2,
}
struct S_4 {
field0 : array<vec2<i32>, 56u>,
}
struct S_5 {
field0 : S_4,
}
struct S_6 {
field0 : array<array<vec3<f32>, 18u>, 13u>,
}
struct S_7 {
field0 : array<vec2<i32>, 88u>,
}
const x_72 = vec4<f32>(0.0f, 0.0f, 0.0f, 0.0f);
const x_73 = mat4x4<f32>(x_72, x_72, x_72, x_72);
var<private> x_75 : array<mat4x4<f32>, 58u> = array<mat4x4<f32>, 58u>(x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73, x_73);
const x_77 = vec3<f32>(0.0f, 0.0f, 0.0f);
const x_78 = array<vec3<f32>, 18u>(x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77);
const x_80 = S_6(array<array<vec3<f32>, 18u>, 13u>(x_78, x_78, x_78, x_78, x_78, x_78, x_78, x_78, x_78, x_78, x_78, x_78, x_78));
var<private> x_82 : array<S_6, 46u> = array<S_6, 46u>(x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80, x_80);
var<private> x_85 : array<vec3<f32>, 37u> = array<vec3<f32>, 37u>(x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77, x_77);
fn main_1() {
let x_88 : u32 = 58u;
return;
}
@fragment
fn main() {
main_1();
}

View File

@@ -19,6 +19,12 @@ var<private> sk_Clockwise : bool;
var<private> vcolor_S0 : vec4<f32>;
const x_35 = vec4<i32>(0i, 0i, 0i, 0i);
const x_46 = vec4<i32>(1i, 1i, 1i, 1i);
const x_57 = vec4<i32>(2i, 2i, 2i, 2i);
fn test_int_S1_c0_b() -> bool {
var unknown : i32;
var ok : bool;
@@ -35,19 +41,19 @@ fn test_int_S1_c0_b() -> bool {
ok = true;
x_41 = false;
if (true) {
x_40 = all(((vec4<i32>(0i, 0i, 0i, 0i) / vec4<i32>(x_27, x_27, x_27, x_27)) == vec4<i32>(0i, 0i, 0i, 0i)));
x_40 = all(((x_35 / vec4<i32>(x_27, x_27, x_27, x_27)) == x_35));
x_41 = x_40;
}
ok = x_41;
let x_44 : vec4<i32> = vec4<i32>(x_27, x_27, x_27, x_27);
val = x_44;
let x_47 : vec4<i32> = (x_44 + vec4<i32>(1i, 1i, 1i, 1i));
let x_47 : vec4<i32> = (x_44 + x_46);
val = x_47;
let x_48 : vec4<i32> = (x_47 - vec4<i32>(1i, 1i, 1i, 1i));
let x_48 : vec4<i32> = (x_47 - x_46);
val = x_48;
let x_49 : vec4<i32> = (x_48 + vec4<i32>(1i, 1i, 1i, 1i));
let x_49 : vec4<i32> = (x_48 + x_46);
val = x_49;
let x_50 : vec4<i32> = (x_49 - vec4<i32>(1i, 1i, 1i, 1i));
let x_50 : vec4<i32> = (x_49 - x_46);
val = x_50;
x_55 = false;
if (x_41) {
@@ -55,13 +61,13 @@ fn test_int_S1_c0_b() -> bool {
x_55 = x_54;
}
ok = x_55;
let x_58 : vec4<i32> = (x_50 * vec4<i32>(2i, 2i, 2i, 2i));
let x_58 : vec4<i32> = (x_50 * x_57);
val = x_58;
let x_59 : vec4<i32> = (x_58 / vec4<i32>(2i, 2i, 2i, 2i));
let x_59 : vec4<i32> = (x_58 / x_57);
val = x_59;
let x_60 : vec4<i32> = (x_59 * vec4<i32>(2i, 2i, 2i, 2i));
let x_60 : vec4<i32> = (x_59 * x_57);
val = x_60;
let x_61 : vec4<i32> = (x_60 / vec4<i32>(2i, 2i, 2i, 2i));
let x_61 : vec4<i32> = (x_60 / x_57);
val = x_61;
x_66 = false;
if (x_55) {
@@ -72,6 +78,12 @@ fn test_int_S1_c0_b() -> bool {
return x_66;
}
const x_82 = vec4<f32>(0.0f, 0.0f, 0.0f, 0.0f);
const x_91 = vec4<f32>(1.0f, 1.0f, 1.0f, 1.0f);
const x_102 = vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f);
fn main_1() {
var outputColor_S0 : vec4<f32>;
var output_S1 : vec4<f32>;
@@ -94,19 +106,19 @@ fn main_1() {
x_9_ok = true;
x_87 = false;
if (true) {
x_86 = all(((vec4<f32>(0.0f, 0.0f, 0.0f, 0.0f) / vec4<f32>(x_77, x_77, x_77, x_77)) == vec4<f32>(0.0f, 0.0f, 0.0f, 0.0f)));
x_86 = all(((x_82 / vec4<f32>(x_77, x_77, x_77, x_77)) == x_82));
x_87 = x_86;
}
x_9_ok = x_87;
let x_89 : vec4<f32> = vec4<f32>(x_77, x_77, x_77, x_77);
x_10_val = x_89;
let x_92 : vec4<f32> = (x_89 + vec4<f32>(1.0f, 1.0f, 1.0f, 1.0f));
let x_92 : vec4<f32> = (x_89 + x_91);
x_10_val = x_92;
let x_93 : vec4<f32> = (x_92 - vec4<f32>(1.0f, 1.0f, 1.0f, 1.0f));
let x_93 : vec4<f32> = (x_92 - x_91);
x_10_val = x_93;
let x_94 : vec4<f32> = (x_93 + vec4<f32>(1.0f, 1.0f, 1.0f, 1.0f));
let x_94 : vec4<f32> = (x_93 + x_91);
x_10_val = x_94;
let x_95 : vec4<f32> = (x_94 - vec4<f32>(1.0f, 1.0f, 1.0f, 1.0f));
let x_95 : vec4<f32> = (x_94 - x_91);
x_10_val = x_95;
x_100 = false;
if (x_87) {
@@ -114,13 +126,13 @@ fn main_1() {
x_100 = x_99;
}
x_9_ok = x_100;
let x_103 : vec4<f32> = (x_95 * vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f));
let x_103 : vec4<f32> = (x_95 * x_102);
x_10_val = x_103;
let x_104 : vec4<f32> = (x_103 / vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f));
let x_104 : vec4<f32> = (x_103 / x_102);
x_10_val = x_104;
let x_105 : vec4<f32> = (x_104 * vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f));
let x_105 : vec4<f32> = (x_104 * x_102);
x_10_val = x_105;
let x_106 : vec4<f32> = (x_105 / vec4<f32>(2.0f, 2.0f, 2.0f, 2.0f));
let x_106 : vec4<f32> = (x_105 / x_102);
x_10_val = x_106;
x_111 = false;
if (x_100) {

View File

@@ -3,7 +3,7 @@ RWTexture2D<uint4> Dst : register(u1);
void main_1() {
uint4 srcValue = uint4(0u, 0u, 0u, 0u);
const uint4 x_18 = Src.Load(int3(0, 0, 0));
const uint4 x_18 = Src.Load(int3((0).xx, 0));
srcValue = x_18;
const uint x_22 = srcValue.x;
srcValue.x = (x_22 + 1u);

View File

@@ -3,7 +3,7 @@ RWTexture2D<uint4> Dst : register(u1);
void main_1() {
uint4 srcValue = uint4(0u, 0u, 0u, 0u);
const uint4 x_18 = Src.Load(int3(0, 0, 0));
const uint4 x_18 = Src.Load(int3((0).xx, 0));
srcValue = x_18;
const uint x_22 = srcValue.x;
srcValue.x = (x_22 + 1u);

View File

@@ -2,14 +2,16 @@
@group(0) @binding(1) var Dst : texture_storage_2d<r32uint, write>;
const x_17 = vec2<i32>(0i, 0i);
fn main_1() {
var srcValue : vec4<u32>;
let x_18 : vec4<u32> = textureLoad(Src, vec2<i32>(0i, 0i), 0i);
let x_18 : vec4<u32> = textureLoad(Src, x_17, 0i);
srcValue = x_18;
let x_22 : u32 = srcValue.x;
srcValue.x = (x_22 + bitcast<u32>(1i));
let x_27 : vec4<u32> = srcValue;
textureStore(Dst, vec2<i32>(0i, 0i), x_27);
textureStore(Dst, x_17, x_27);
return;
}