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

@ -30,6 +30,11 @@ std::string Preamble() {
OpEntryPoint Fragment %100 "main"
OpExecutionMode %100 OriginUpperLeft
OpName %v2float_50_60 "v2float_50_60"
OpName %v2float_60_50 "v2float_60_50"
OpName %v3float_50_60_70 "v3float_50_60_70"
OpName %v3float_60_70_50 "v3float_60_70_50"
%void = OpTypeVoid
%voidfn = OpTypeFunction %void
@ -94,10 +99,10 @@ std::string AstFor(std::string assembly) {
return "bitcast<vec2<u32>>(vec2<i32>(40i, 30i))";
}
if (assembly == "v2float_50_60") {
return "vec2<f32>(50.0f, 60.0f)";
return "v2float_50_60";
}
if (assembly == "v2float_60_50") {
return "vec2<f32>(60.0f, 50.0f)";
return "v2float_60_50";
}
return "bad case";
}
@ -271,7 +276,7 @@ TEST_F(SpvUnaryArithTest, FNegate_Vector) {
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto ast_body = fe.ast_body();
EXPECT_THAT(test::ToString(p->program(), ast_body),
HasSubstr("let x_1 : vec2<f32> = -(vec2<f32>(50.0f, 60.0f));"));
HasSubstr("let x_1 : vec2<f32> = -(v2float_50_60);"));
}
struct BinaryData {
@ -704,10 +709,9 @@ TEST_F(SpvBinaryArithTestBasic, FMod_Vector) {
auto fe = p->function_emitter(100);
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto ast_body = fe.ast_body();
EXPECT_THAT(
test::ToString(p->program(), ast_body),
HasSubstr(
R"(let x_1 : vec2<f32> = (vec2<f32>(50.0f, 60.0f) - (vec2<f32>(60.0f, 50.0f) * floor((vec2<f32>(50.0f, 60.0f) / vec2<f32>(60.0f, 50.0f)))));)"));
EXPECT_THAT(test::ToString(p->program(), ast_body),
HasSubstr("let x_1 : vec2<f32> = (v2float_50_60 - (v2float_60_50 * "
"floor((v2float_50_60 / v2float_60_50))));"));
}
TEST_F(SpvBinaryArithTestBasic, VectorTimesScalar) {

View File

@ -877,8 +877,7 @@ TEST_F(SpvUnaryBitTest, InsertBits_IntVector) {
auto body = test::ToString(p->program(), ast_body);
EXPECT_THAT(
body,
HasSubstr(
R"(let x_1 : vec2<i32> = insertBits(vec2<i32>(30i, 40i), vec2<i32>(40i, 30i), 10u, 20u);)"))
HasSubstr(R"(let x_1 : vec2<i32> = insertBits(x_28, vec2<i32>(40i, 30i), 10u, 20u);)"))
<< body;
}
@ -897,7 +896,7 @@ TEST_F(SpvUnaryBitTest, InsertBits_IntVector_SignedOffsetAndCount) {
EXPECT_THAT(
body,
HasSubstr(
R"(let x_1 : vec2<i32> = insertBits(vec2<i32>(30i, 40i), vec2<i32>(40i, 30i), u32(10i), u32(20i));)"))
R"(let x_1 : vec2<i32> = insertBits(x_28, vec2<i32>(40i, 30i), u32(10i), u32(20i));)"))
<< body;
}
@ -946,8 +945,7 @@ TEST_F(SpvUnaryBitTest, InsertBits_UintVector) {
auto body = test::ToString(p->program(), ast_body);
EXPECT_THAT(
body,
HasSubstr(
R"(let x_1 : vec2<u32> = insertBits(vec2<u32>(10u, 20u), vec2<u32>(20u, 10u), 10u, 20u);)"))
HasSubstr(R"(let x_1 : vec2<u32> = insertBits(x_26, vec2<u32>(20u, 10u), 10u, 20u);)"))
<< body;
}
@ -966,7 +964,7 @@ TEST_F(SpvUnaryBitTest, InsertBits_UintVector_SignedOffsetAndCount) {
EXPECT_THAT(
body,
HasSubstr(
R"(let x_1 : vec2<u32> = insertBits(vec2<u32>(10u, 20u), vec2<u32>(20u, 10u), u32(10i), u32(20i));)"))
R"(let x_1 : vec2<u32> = insertBits(x_26, vec2<u32>(20u, 10u), u32(10i), u32(20i));)"))
<< body;
}
@ -1012,9 +1010,7 @@ TEST_F(SpvUnaryBitTest, ExtractBits_IntVector) {
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto ast_body = fe.ast_body();
auto body = test::ToString(p->program(), ast_body);
EXPECT_THAT(body,
HasSubstr("let x_1 : vec2<i32> = extractBits(vec2<i32>(30i, 40i), 10u, 20u);"))
<< body;
EXPECT_THAT(body, HasSubstr("let x_1 : vec2<i32> = extractBits(x_28, 10u, 20u);")) << body;
}
TEST_F(SpvUnaryBitTest, ExtractBits_IntVector_SignedOffsetAndCount) {
@ -1029,9 +1025,7 @@ TEST_F(SpvUnaryBitTest, ExtractBits_IntVector_SignedOffsetAndCount) {
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto ast_body = fe.ast_body();
auto body = test::ToString(p->program(), ast_body);
EXPECT_THAT(
body,
HasSubstr("let x_1 : vec2<i32> = extractBits(vec2<i32>(30i, 40i), u32(10i), u32(20i));"))
EXPECT_THAT(body, HasSubstr("let x_1 : vec2<i32> = extractBits(x_28, u32(10i), u32(20i));"))
<< body;
}
@ -1077,9 +1071,7 @@ TEST_F(SpvUnaryBitTest, ExtractBits_UintVector) {
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto ast_body = fe.ast_body();
auto body = test::ToString(p->program(), ast_body);
EXPECT_THAT(body,
HasSubstr("let x_1 : vec2<u32> = extractBits(vec2<u32>(10u, 20u), 10u, 20u);"))
<< body;
EXPECT_THAT(body, HasSubstr("let x_1 : vec2<u32> = extractBits(x_26, 10u, 20u);")) << body;
}
TEST_F(SpvUnaryBitTest, ExtractBits_UintVector_SignedOffsetAndCount) {
@ -1094,9 +1086,7 @@ TEST_F(SpvUnaryBitTest, ExtractBits_UintVector_SignedOffsetAndCount) {
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto ast_body = fe.ast_body();
auto body = test::ToString(p->program(), ast_body);
EXPECT_THAT(
body,
HasSubstr("let x_1 : vec2<u32> = extractBits(vec2<u32>(10u, 20u), u32(10i), u32(20i));"))
EXPECT_THAT(body, HasSubstr("let x_1 : vec2<u32> = extractBits(x_26, u32(10i), u32(20i));"))
<< body;
}

View File

@ -1916,6 +1916,13 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
case spv::Op::OpConstantComposite: {
// Handle vector, matrix, array, and struct
auto itr = declared_constant_composites_.find(id);
if (itr != declared_constant_composites_.end()) {
// We've already declared this constant value as a module-scope const, so just
// reference that identifier.
return {original_ast_type, builder_.Expr(itr->second)};
}
// Generate a composite from explicit components.
ExpressionList ast_components;
if (!inst->WhileEachInId([&](const uint32_t* id_ref) -> bool {
@ -1930,8 +1937,20 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
// We've already emitted a diagnostic.
return {};
}
return {original_ast_type, builder_.Call(source, original_ast_type->Build(builder_),
std::move(ast_components))};
auto* expr = builder_.Call(source, original_ast_type->Build(builder_),
std::move(ast_components));
if (def_use_mgr_->NumUses(id) == 1) {
// The constant is only used once, so just inline its use.
return {original_ast_type, expr};
}
// Create a module-scope const declaration for the constant.
auto name = namer_.Name(id);
auto* decl = builder_.GlobalConst(name, expr);
declared_constant_composites_.insert({id, decl->name->symbol});
return {original_ast_type, builder_.Expr(name)};
}
default:
break;

View File

@ -880,6 +880,9 @@ class ParserImpl : Reader {
// The ast::Struct type names with only read-only members.
std::unordered_set<Symbol> read_only_struct_types_;
// Maps from OpConstantComposite IDs to identifiers of module-scope const declarations.
std::unordered_map<uint32_t, Symbol> declared_constant_composites_;
// The IDs of scalar spec constants
std::unordered_set<uint32_t> scalar_spec_constants_;

View File

@ -1504,7 +1504,7 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d<f32>;)",
"textureGather(1i, x_20, x_10, coords12, vec2<i32>(3i, 4i))"},
"textureGather(1i, x_20, x_10, coords12, offsets2d)"},
// OpImageGather 2D ConstOffset unsigned
ImageAccessCase{"%float 2D 0 0 0 1 Unknown",
"%result = OpImageGather "
@ -1514,7 +1514,7 @@ INSTANTIATE_TEST_SUITE_P(
@group(2) @binding(1) var x_20 : texture_2d<f32>;)",
"textureGather(1i, x_20, x_10, coords12, "
"vec2<i32>(vec2<u32>(3u, 4u)))"},
"vec2<i32>(u_offsets2d))"},
// OpImageGather 2D Array
ImageAccessCase{"%float 2D 0 1 0 1 Unknown",
"%result = OpImageGather "
@ -1532,7 +1532,7 @@ INSTANTIATE_TEST_SUITE_P(
@group(2) @binding(1) var x_20 : texture_2d_array<f32>;)",
"textureGather(1i, x_20, x_10, coords123.xy, "
"i32(round(coords123.z)), vec2<i32>(3i, 4i))"},
"i32(round(coords123.z)), offsets2d)"},
// OpImageGather 2D Array ConstOffset unsigned
ImageAccessCase{"%float 2D 0 1 0 1 Unknown",
"%result = OpImageGather "
@ -1543,7 +1543,7 @@ INSTANTIATE_TEST_SUITE_P(
@group(2) @binding(1) var x_20 : texture_2d_array<f32>;)",
"textureGather(1i, x_20, x_10, coords123.xy, "
"i32(round(coords123.z)), "
"vec2<i32>(vec2<u32>(3u, 4u)))"},
"vec2<i32>(u_offsets2d))"},
// OpImageGather Cube
ImageAccessCase{"%float Cube 0 0 0 1 Unknown",
"%result = OpImageGather "
@ -1576,7 +1576,7 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_depth_2d;)",
"textureGather(x_20, x_10, coords12, vec2<i32>(3i, 4i))"},
"textureGather(x_20, x_10, coords12, offsets2d)"},
// OpImageGather 2DDepth ConstOffset unsigned
ImageAccessCase{"%float 2D 1 0 0 1 Unknown",
"%result = OpImageGather "
@ -1586,7 +1586,7 @@ INSTANTIATE_TEST_SUITE_P(
@group(2) @binding(1) var x_20 : texture_depth_2d;)",
"textureGather(x_20, x_10, coords12, "
"vec2<i32>(vec2<u32>(3u, 4u)))"},
"vec2<i32>(u_offsets2d))"},
// OpImageGather 2DDepth Array
ImageAccessCase{"%float 2D 1 1 0 1 Unknown",
"%result = OpImageGather "
@ -1604,7 +1604,7 @@ INSTANTIATE_TEST_SUITE_P(
@group(2) @binding(1) var x_20 : texture_depth_2d_array;)",
"textureGather(x_20, x_10, coords123.xy, "
"i32(round(coords123.z)), vec2<i32>(3i, 4i))"},
"i32(round(coords123.z)), offsets2d)"},
// OpImageGather 2DDepth Array ConstOffset unsigned
ImageAccessCase{"%float 2D 1 1 0 1 Unknown",
"%result = OpImageGather "
@ -1615,7 +1615,7 @@ INSTANTIATE_TEST_SUITE_P(
@group(2) @binding(1) var x_20 : texture_depth_2d_array;)",
"textureGather(x_20, x_10, coords123.xy, "
"i32(round(coords123.z)), "
"vec2<i32>(vec2<u32>(3u, 4u)))"},
"vec2<i32>(u_offsets2d))"},
// OpImageGather DepthCube
ImageAccessCase{"%float Cube 1 0 0 1 Unknown",
"%result = OpImageGather "
@ -1654,7 +1654,7 @@ INSTANTIATE_TEST_SUITE_P(
@group(2) @binding(1) var x_20 : texture_depth_2d;)",
"textureGatherCompare(x_20, x_10, coords12, 0.20000000298023223877f, "
"vec2<i32>(3i, 4i))"},
"offsets2d)"},
// OpImageDrefGather 2DDepth ConstOffset unsigned
ImageAccessCase{"%float 2D 1 0 0 1 Unknown",
"%result = OpImageDrefGather "
@ -1664,7 +1664,7 @@ INSTANTIATE_TEST_SUITE_P(
@group(2) @binding(1) var x_20 : texture_depth_2d;)",
"textureGatherCompare(x_20, x_10, coords12, 0.20000000298023223877f, "
"vec2<i32>(vec2<u32>(3u, 4u)))"},
"vec2<i32>(u_offsets2d))"},
// OpImageDrefGather 2DDepth Array
ImageAccessCase{"%float 2D 1 1 0 1 Unknown",
"%result = OpImageDrefGather "
@ -1682,7 +1682,7 @@ INSTANTIATE_TEST_SUITE_P(
@group(2) @binding(1) var x_20 : texture_depth_2d_array;)",
"textureGatherCompare(x_20, x_10, coords123.xy, "
"i32(round(coords123.z)), 0.20000000298023223877f, vec2<i32>(3i, 4i))"},
"i32(round(coords123.z)), 0.20000000298023223877f, offsets2d)"},
// OpImageDrefGather 2DDepth Array ConstOffset unsigned
ImageAccessCase{"%float 2D 1 1 0 1 Unknown",
"%result = OpImageDrefGather "
@ -1693,7 +1693,7 @@ INSTANTIATE_TEST_SUITE_P(
@group(2) @binding(1) var x_20 : texture_depth_2d_array;)",
"textureGatherCompare(x_20, x_10, coords123.xy, "
"i32(round(coords123.z)), 0.20000000298023223877f, "
"vec2<i32>(vec2<u32>(3u, 4u)))"},
"vec2<i32>(u_offsets2d))"},
// OpImageDrefGather DepthCube
ImageAccessCase{"%float Cube 1 0 0 1 Unknown",
"%result = OpImageDrefGather "
@ -1742,7 +1742,7 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d<f32>;)",
"textureSample(x_20, x_10, coords12, vec2<i32>(3i, 4i))"},
"textureSample(x_20, x_10, coords12, offsets2d)"},
// OpImageSampleImplicitLod arrayed with ConstOffset
ImageAccessCase{
@ -1752,7 +1752,7 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d_array<f32>;)",
R"(textureSample(x_20, x_10, coords123.xy, i32(round(coords123.z)), vec2<i32>(3i, 4i)))"},
R"(textureSample(x_20, x_10, coords123.xy, i32(round(coords123.z)), offsets2d))"},
// OpImageSampleImplicitLod with Bias
ImageAccessCase{"%float 2D 0 0 0 1 Unknown",
@ -1781,19 +1781,18 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d<f32>;)",
R"(textureSampleBias(x_20, x_10, coords12, 7.0f, vec2<i32>(3i, 4i))"},
R"(textureSampleBias(x_20, x_10, coords12, 7.0f, offsets2d)"},
// OpImageSampleImplicitLod with Bias and unsigned ConstOffset
// Convert ConstOffset to signed
ImageAccessCase{
"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleImplicitLod "
"%v4float %sampled_image %coords12 Bias|ConstOffset "
"%float_7 %u_offsets2d",
R"(@group(0) @binding(0) var x_10 : sampler;
ImageAccessCase{"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleImplicitLod "
"%v4float %sampled_image %coords12 Bias|ConstOffset "
"%float_7 %u_offsets2d",
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d<f32>;)",
R"(textureSampleBias(x_20, x_10, coords12, 7.0f, vec2<i32>(vec2<u32>(3u, 4u)))"},
R"(textureSampleBias(x_20, x_10, coords12, 7.0f, vec2<i32>(u_offsets2d))"},
// OpImageSampleImplicitLod arrayed with Bias
ImageAccessCase{
"%float 2D 0 1 0 1 Unknown",
@ -1803,7 +1802,7 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d_array<f32>;)",
R"(textureSampleBias(x_20, x_10, coords123.xy, i32(round(coords123.z)), 7.0f, vec2<i32>(3i, 4i))"}));
R"(textureSampleBias(x_20, x_10, coords123.xy, i32(round(coords123.z)), 7.0f, offsets2d)"}));
INSTANTIATE_TEST_SUITE_P(
// This test shows the use of a sampled image used with both regular
@ -1863,7 +1862,7 @@ INSTANTIATE_TEST_SUITE_P(
@group(2) @binding(1) var x_20 : texture_depth_2d;
)",
R"(textureSampleCompare(x_20, x_10, coords12, 0.20000000298023223877f, vec2<i32>(3i, 4i)))"},
R"(textureSampleCompare(x_20, x_10, coords12, 0.20000000298023223877f, offsets2d))"},
// ImageSampleDrefImplicitLod arrayed with ConstOffset
ImageAccessCase{
"%float 2D 0 1 0 1 Unknown",
@ -1872,7 +1871,7 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler_comparison;
@group(2) @binding(1) var x_20 : texture_depth_2d_array;)",
R"(textureSampleCompare(x_20, x_10, coords123.xy, i32(round(coords123.z)), 0.20000000298023223877f, vec2<i32>(3i, 4i)))"}));
R"(textureSampleCompare(x_20, x_10, coords123.xy, i32(round(coords123.z)), 0.20000000298023223877f, offsets2d))"}));
INSTANTIATE_TEST_SUITE_P(
ImageSampleDrefExplicitLod,
@ -1909,7 +1908,7 @@ INSTANTIATE_TEST_SUITE_P(
@group(2) @binding(1) var x_20 : texture_depth_2d;
)",
R"(textureSampleCompareLevel(x_20, x_10, coords12, 0.20000000298023223877f, vec2<i32>(3i, 4i)))"},
R"(textureSampleCompareLevel(x_20, x_10, coords12, 0.20000000298023223877f, offsets2d))"},
// 2D array, ConstOffset
ImageAccessCase{
"%float 2D 1 1 0 1 Unknown",
@ -1919,7 +1918,7 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler_comparison;
@group(2) @binding(1) var x_20 : texture_depth_2d_array;)",
R"(textureSampleCompareLevel(x_20, x_10, coords123.xy, i32(round(coords123.z)), 0.20000000298023223877f, vec2<i32>(3i, 4i)))"},
R"(textureSampleCompareLevel(x_20, x_10, coords123.xy, i32(round(coords123.z)), 0.20000000298023223877f, offsets2d))"},
// Cube
ImageAccessCase{
"%float Cube 1 0 0 1 Unknown",
@ -1971,19 +1970,18 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d<f32>;)",
R"(textureSampleLevel(x_20, x_10, coords12, 0.0f, vec2<i32>(3i, 4i)))"},
R"(textureSampleLevel(x_20, x_10, coords12, 0.0f, offsets2d))"},
// OpImageSampleExplicitLod - using Lod and unsigned ConstOffset
// Convert the ConstOffset operand to signed
ImageAccessCase{
"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleExplicitLod "
"%v4float %sampled_image %coords12 Lod|ConstOffset "
"%float_null %u_offsets2d",
R"(@group(0) @binding(0) var x_10 : sampler;
ImageAccessCase{"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleExplicitLod "
"%v4float %sampled_image %coords12 Lod|ConstOffset "
"%float_null %u_offsets2d",
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d<f32>;)",
R"(textureSampleLevel(x_20, x_10, coords12, 0.0f, vec2<i32>(vec2<u32>(3u, 4u)))"},
R"(textureSampleLevel(x_20, x_10, coords12, 0.0f, vec2<i32>(u_offsets2d))"},
// OpImageSampleExplicitLod arrayed - using Lod and ConstOffset
ImageAccessCase{
@ -1994,7 +1992,7 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d_array<f32>;)",
R"(textureSampleLevel(x_20, x_10, coords123.xy, i32(round(coords123.z)), 0.0f, vec2<i32>(3i, 4i)))"}));
R"(textureSampleLevel(x_20, x_10, coords123.xy, i32(round(coords123.z)), 0.0f, offsets2d))"}));
INSTANTIATE_TEST_SUITE_P(
ImageSampleExplicitLod_UsingGrad,
@ -2021,15 +2019,14 @@ INSTANTIATE_TEST_SUITE_P(
R"(textureSampleGrad(x_20, x_10, coords123.xy, i32(round(coords123.z)), vf12, vf21))"},
// OpImageSampleExplicitLod - using Grad and ConstOffset
ImageAccessCase{
"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleExplicitLod "
"%v4float %sampled_image %coords12 Grad|ConstOffset "
"%vf12 %vf21 %offsets2d",
R"(@group(0) @binding(0) var x_10 : sampler;
ImageAccessCase{"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleExplicitLod "
"%v4float %sampled_image %coords12 Grad|ConstOffset "
"%vf12 %vf21 %offsets2d",
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d<f32>;)",
R"(textureSampleGrad(x_20, x_10, coords12, vf12, vf21, vec2<i32>(3i, 4i)))"},
R"(textureSampleGrad(x_20, x_10, coords12, vf12, vf21, offsets2d))"},
// OpImageSampleExplicitLod - using Grad and unsigned ConstOffset
ImageAccessCase{
@ -2040,7 +2037,7 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d<f32>;)",
R"(textureSampleGrad(x_20, x_10, coords12, vf12, vf21, vec2<i32>(vec2<u32>(3u, 4u)))"},
R"(textureSampleGrad(x_20, x_10, coords12, vf12, vf21, vec2<i32>(u_offsets2d))"},
// OpImageSampleExplicitLod arrayed - using Grad and ConstOffset
ImageAccessCase{
@ -2051,7 +2048,7 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d_array<f32>;)",
R"(textureSampleGrad(x_20, x_10, coords123.xy, i32(round(coords123.z)), vf12, vf21, vec2<i32>(3i, 4i)))"},
R"(textureSampleGrad(x_20, x_10, coords123.xy, i32(round(coords123.z)), vf12, vf21, offsets2d))"},
// OpImageSampleExplicitLod arrayed - using Grad and unsigned
// ConstOffset
@ -2063,7 +2060,7 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d_array<f32>;)",
R"(textureSampleGrad(x_20, x_10, coords123.xy, i32(round(coords123.z)), vf12, vf21, vec2<i32>(vec2<u32>(3u, 4u))))"}));
R"(textureSampleGrad(x_20, x_10, coords123.xy, i32(round(coords123.z)), vf12, vf21, vec2<i32>(u_offsets2d)))"}));
// Test crbug.com/378:
// In WGSL, sampling from depth texture with explicit level of detail
@ -2153,14 +2150,13 @@ INSTANTIATE_TEST_SUITE_P(
// OpImageSampleProjImplicitLod 2D with ConstOffset
// (Don't need to test with 1D or 3D, as the hard part was the splatted
// division.) This case tests handling of the ConstOffset
ImageAccessCase{
"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleProjImplicitLod "
"%v4float %sampled_image %coords123 ConstOffset %offsets2d",
R"(@group(0) @binding(0) var x_10 : sampler;
ImageAccessCase{"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleProjImplicitLod "
"%v4float %sampled_image %coords123 ConstOffset %offsets2d",
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d<f32>;)",
R"(textureSample(x_20, x_10, (coords123.xy / coords123.z), vec2<i32>(3i, 4i)))"}));
R"(textureSample(x_20, x_10, (coords123.xy / coords123.z), offsets2d))"}));
INSTANTIATE_TEST_SUITE_P(
ImageSampleProjImplicitLod_Bias,
@ -2186,7 +2182,7 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d<f32>;)",
R"(textureSampleBias(x_20, x_10, (coords123.xy / coords123.z), 7.0f, vec2<i32>(3i, 4i)))"},
R"(textureSampleBias(x_20, x_10, (coords123.xy / coords123.z), 7.0f, offsets2d))"},
// OpImageSampleProjImplicitLod with Bias and unsigned ConstOffset
// Convert ConstOffset to signed
@ -2198,7 +2194,7 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d<f32>;)",
R"(textureSampleBias(x_20, x_10, (coords123.xy / coords123.z), 7.0f, vec2<i32>(vec2<u32>(3u, 4u))))"}));
R"(textureSampleBias(x_20, x_10, (coords123.xy / coords123.z), 7.0f, vec2<i32>(u_offsets2d)))"}));
INSTANTIATE_TEST_SUITE_P(
ImageSampleProjExplicitLod_Lod,
@ -2221,7 +2217,7 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d<f32>;)",
R"(textureSampleLevel(x_20, x_10, (coords123.xy / coords123.z), f1, vec2<i32>(3i, 4i)))"}));
R"(textureSampleLevel(x_20, x_10, (coords123.xy / coords123.z), f1, offsets2d))"}));
INSTANTIATE_TEST_SUITE_P(
ImageSampleProjExplicitLod_Grad,
@ -2246,7 +2242,7 @@ INSTANTIATE_TEST_SUITE_P(
R"(@group(0) @binding(0) var x_10 : sampler;
@group(2) @binding(1) var x_20 : texture_2d<f32>;)",
R"(textureSampleGrad(x_20, x_10, (coords123.xy / coords123.z), vf12, vf21, vec2<i32>(3i, 4i)))"}));
R"(textureSampleGrad(x_20, x_10, (coords123.xy / coords123.z), vf12, vf21, offsets2d))"}));
INSTANTIATE_TEST_SUITE_P(
// Ordinary (non-comparison) sampling on a depth texture.
@ -2291,7 +2287,7 @@ INSTANTIATE_TEST_SUITE_P(
@group(2) @binding(1) var x_20 : texture_depth_2d;
)",
R"(textureSampleCompare(x_20, x_10, (coords123.xy / coords123.z), f1, vec2<i32>(3i, 4i)))"}));
R"(textureSampleCompare(x_20, x_10, (coords123.xy / coords123.z), f1, offsets2d))"}));
INSTANTIATE_TEST_SUITE_P(
DISABLED_ImageSampleProjDrefExplicitLod_Lod,

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;
}