Import Tint changes from Dawn
Changes:
- 477744b7b52c0402e970b203431a5fbc305b4da4 Tint/GLSL: fix null ptr deref in Texture1D -> 2D. by senorblanco@chromium.org <Stephen White>
- f7beb85fd10ae1a9493cd83df27fad07203012ba Count the line pos, offset and size of compilation messag... by Jiawei Shao <jiawei.shao@intel.com>
- 2dfd177009b14650d67697b25f291dceb18d96d1 spirv-reader: Apply image coord vector check on unwrapped... by Arman Uguray <armansito@google.com>
GitOrigin-RevId: 477744b7b52c0402e970b203431a5fbc305b4da4
Change-Id: I3da91528ea74f26d1ea0518eee1eec390f86851c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/116559
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/include/tint/tint.h b/include/tint/tint.h
index 02ac423..cdda85c 100644
--- a/include/tint/tint.h
+++ b/include/tint/tint.h
@@ -25,6 +25,7 @@
#include "src/tint/diagnostic/printer.h"
#include "src/tint/inspector/inspector.h"
#include "src/tint/reader/reader.h"
+#include "src/tint/text/unicode.h"
#include "src/tint/transform/binding_remapper.h"
#include "src/tint/transform/clamp_frag_depth.h"
#include "src/tint/transform/first_index_offset.h"
diff --git a/src/tint/reader/spirv/function.cc b/src/tint/reader/spirv/function.cc
index 33f2bdb..a0b257b 100644
--- a/src/tint/reader/spirv/function.cc
+++ b/src/tint/reader/spirv/function.cc
@@ -5979,7 +5979,7 @@
auto* component_type = raw_coords.type->UnwrapRef();
if (component_type->IsFloatScalar() || component_type->IsIntegerScalar()) {
num_coords_supplied = 1;
- } else if (auto* vec_type = As<Vector>(raw_coords.type)) {
+ } else if (auto* vec_type = As<Vector>(component_type)) {
component_type = vec_type->type;
num_coords_supplied = vec_type->size;
}
diff --git a/src/tint/reader/spirv/parser_impl_handle_test.cc b/src/tint/reader/spirv/parser_impl_handle_test.cc
index 4e02d9b..1270d31 100644
--- a/src/tint/reader/spirv/parser_impl_handle_test.cc
+++ b/src/tint/reader/spirv/parser_impl_handle_test.cc
@@ -3914,6 +3914,93 @@
ASSERT_EQ(expect, got);
}
+TEST_F(SpvParserHandleTest, ImageCoordinateCanBeHoistedVector) {
+ // Demonstrates fix for crbug.com/tint/1712
+ // The problem is the coordinate for an image operation
+ // can be a combinatorial value that has been hoisted out
+ // to a 'var' declaration.
+ //
+ // In this test (and the original case form the bug), the
+ // definition for the value is in an outer construct, and
+ // the image operation using it is in a doubly nested
+ // construct.
+ //
+ // The coordinate handling has to unwrap the ref type it
+ // made for the 'var' declaration.
+ const auto assembly = Preamble() + R"(
+
+OpEntryPoint Fragment %100 "main"
+OpExecutionMode %100 OriginUpperLeft
+OpDecorate %10 DescriptorSet 0
+OpDecorate %10 Binding 0
+OpDecorate %20 DescriptorSet 2
+OpDecorate %20 Binding 1
+
+%void = OpTypeVoid
+%voidfn = OpTypeFunction %void
+
+%bool = OpTypeBool
+%true = OpConstantTrue %bool
+%float = OpTypeFloat 32
+
+%v2float = OpTypeVector %float 2
+%v4float = OpTypeVector %float 4
+
+%v2float_null = OpConstantNull %v2float
+
+%sampler = OpTypeSampler
+%ptr_sampler = OpTypePointer UniformConstant %sampler
+%im_ty = OpTypeImage %float 1D 0 0 0 1 Unknown
+%ptr_im_ty = OpTypePointer UniformConstant %im_ty
+%si_ty = OpTypeSampledImage %im_ty
+
+%10 = OpVariable %ptr_sampler UniformConstant
+%20 = OpVariable %ptr_im_ty UniformConstant
+
+%100 = OpFunction %void None %voidfn
+%entry = OpLabel
+%900 = OpCopyObject %v2float %v2float_null ; definition here
+OpSelectionMerge %99 None
+OpBranchConditional %true %40 %99
+
+ %40 = OpLabel
+ OpSelectionMerge %80 None
+ OpBranchConditional %true %50 %80
+
+ %50 = OpLabel
+ %sam = OpLoad %sampler %10
+ %im = OpLoad %im_ty %20
+ %sampled_image = OpSampledImage %si_ty %im %sam
+ %result = OpImageSampleImplicitLod %v4float %sampled_image %900 ; usage here
+ OpBranch %80
+
+ %80 = OpLabel
+ OpBranch %99
+
+%99 = OpLabel
+OpReturn
+OpFunctionEnd
+
+ )";
+ auto p = parser(test::Assemble(assembly));
+ EXPECT_TRUE(p->BuildAndParseInternalModule()) << assembly;
+ auto fe = p->function_emitter(100);
+ EXPECT_TRUE(fe.EmitBody()) << p->error();
+ EXPECT_TRUE(p->error().empty()) << p->error();
+ auto ast_body = fe.ast_body();
+ const auto got = test::ToString(p->program(), ast_body);
+ auto* expect = R"(var x_900 : vec2<f32>;
+x_900 = vec2<f32>();
+if (true) {
+ if (true) {
+ let x_19 : vec4<f32> = textureSample(x_20, x_10, x_900.x);
+ }
+}
+return;
+)";
+ ASSERT_EQ(expect, got);
+}
+
TEST_F(SpvParserHandleTest, TexelTypeWhenLoop) {
// Demonstrates fix for crbug.com/tint/1642
// The problem is the texel value for an image write
diff --git a/src/tint/text/unicode.cc b/src/tint/text/unicode.cc
index e23f3dd..cc9a9d1 100644
--- a/src/tint/text/unicode.cc
+++ b/src/tint/text/unicode.cc
@@ -427,6 +427,10 @@
return {c, n};
}
+std::pair<CodePoint, size_t> Decode(std::string_view utf8_string) {
+ return Decode(reinterpret_cast<const uint8_t*>(utf8_string.data()), utf8_string.size());
+}
+
bool IsASCII(std::string_view str) {
for (auto c : str) {
if (c & 0x80) {
diff --git a/src/tint/text/unicode.h b/src/tint/text/unicode.h
index f0aa272..0594d31 100644
--- a/src/tint/text/unicode.h
+++ b/src/tint/text/unicode.h
@@ -69,6 +69,12 @@
/// If the next code point cannot be decoded then returns [0,0].
std::pair<CodePoint, size_t> Decode(const uint8_t* ptr, size_t len);
+/// Decodes the first code point in the utf8 string.
+/// @param utf8_string the string view that contains the utf8 sequence
+/// @returns a pair of CodePoint and width in code units (bytes).
+/// If the next code point cannot be decoded then returns [0,0].
+std::pair<CodePoint, size_t> Decode(std::string_view utf8_string);
+
/// @returns true if all the utf-8 code points in the string are ASCII
/// (code-points 0x00..0x7f).
bool IsASCII(std::string_view);
diff --git a/src/tint/transform/texture_1d_to_2d.cc b/src/tint/transform/texture_1d_to_2d.cc
index 0e19d02..85cd512 100644
--- a/src/tint/transform/texture_1d_to_2d.cc
+++ b/src/tint/transform/texture_1d_to_2d.cc
@@ -126,7 +126,10 @@
return nullptr;
}
const auto& signature = builtin->Signature();
- auto texture = signature.Parameter(sem::ParameterUsage::kTexture);
+ auto* texture = signature.Parameter(sem::ParameterUsage::kTexture);
+ if (!texture) {
+ return nullptr;
+ }
auto* tex = texture->Type()->As<type::Texture>();
if (tex->dim() != ast::TextureDimension::k1d) {
return nullptr;
diff --git a/src/tint/transform/texture_1d_to_2d_test.cc b/src/tint/transform/texture_1d_to_2d_test.cc
index 83a12bd..687988c 100644
--- a/src/tint/transform/texture_1d_to_2d_test.cc
+++ b/src/tint/transform/texture_1d_to_2d_test.cc
@@ -275,5 +275,30 @@
EXPECT_EQ(expect, str(got));
}
+TEST_F(Texture1DTo2DTest, TextureAndNonTextureBuiltin) {
+ auto* src = R"(
+@group(0) @binding(0) var tex : texture_1d<i32>;
+
+fn d() {
+ textureLoad(tex, 1, 0);
+ let l = sin(3.0);
+}
+)";
+
+ auto* expect = R"(
+@group(0) @binding(0) var tex : texture_2d<i32>;
+
+fn d() {
+ textureLoad(tex, vec2<i32>(1, 0), 0);
+ let l = sin(3.0);
+}
+)";
+
+ DataMap data;
+ auto got = Run<Texture1DTo2D>(src, data);
+
+ EXPECT_EQ(expect, str(got));
+}
+
} // namespace
} // namespace tint::transform