Import Tint changes from Dawn
Changes:
- d03dceebf3bcddcdcbf891f6ae715a342b1007fd tint: Add bgra8unorm storage texture support by Ben Clayton <bclayton@google.com>
GitOrigin-RevId: d03dceebf3bcddcdcbf891f6ae715a342b1007fd
Change-Id: I992cfa604e8da3125fcd271c8a15982e56ed5341
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/117172
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/ast/storage_texture.cc b/src/tint/ast/storage_texture.cc
index c9d26c2..0a48a5b 100644
--- a/src/tint/ast/storage_texture.cc
+++ b/src/tint/ast/storage_texture.cc
@@ -67,6 +67,7 @@
return builder.create<I32>();
}
+ case TexelFormat::kBgra8Unorm:
case TexelFormat::kRgba8Unorm:
case TexelFormat::kRgba8Snorm:
case TexelFormat::kR32Float:
diff --git a/src/tint/ast/texel_format.cc b/src/tint/ast/texel_format.cc
index 587cf29..c14c06c 100644
--- a/src/tint/ast/texel_format.cc
+++ b/src/tint/ast/texel_format.cc
@@ -28,6 +28,9 @@
/// @param str the string to parse
/// @returns the parsed enum, or TexelFormat::kUndefined if the string could not be parsed.
TexelFormat ParseTexelFormat(std::string_view str) {
+ if (str == "bgra8unorm") {
+ return TexelFormat::kBgra8Unorm;
+ }
if (str == "r32float") {
return TexelFormat::kR32Float;
}
@@ -83,6 +86,8 @@
switch (value) {
case TexelFormat::kUndefined:
return out << "undefined";
+ case TexelFormat::kBgra8Unorm:
+ return out << "bgra8unorm";
case TexelFormat::kR32Float:
return out << "r32float";
case TexelFormat::kR32Sint:
diff --git a/src/tint/ast/texel_format.h b/src/tint/ast/texel_format.h
index fff88a3..48d05ad 100644
--- a/src/tint/ast/texel_format.h
+++ b/src/tint/ast/texel_format.h
@@ -30,6 +30,7 @@
/// Enumerator of texel formats
enum class TexelFormat {
kUndefined,
+ kBgra8Unorm,
kR32Float,
kR32Sint,
kR32Uint,
@@ -59,9 +60,9 @@
TexelFormat ParseTexelFormat(std::string_view str);
constexpr const char* kTexelFormatStrings[] = {
- "r32float", "r32sint", "r32uint", "rg32float", "rg32sint", "rg32uint",
- "rgba16float", "rgba16sint", "rgba16uint", "rgba32float", "rgba32sint", "rgba32uint",
- "rgba8sint", "rgba8snorm", "rgba8uint", "rgba8unorm",
+ "bgra8unorm", "r32float", "r32sint", "r32uint", "rg32float", "rg32sint",
+ "rg32uint", "rgba16float", "rgba16sint", "rgba16uint", "rgba32float", "rgba32sint",
+ "rgba32uint", "rgba8sint", "rgba8snorm", "rgba8uint", "rgba8unorm",
};
} // namespace tint::ast
diff --git a/src/tint/ast/texel_format_bench.cc b/src/tint/ast/texel_format_bench.cc
index c48e0f6..0b1b18e 100644
--- a/src/tint/ast/texel_format_bench.cc
+++ b/src/tint/ast/texel_format_bench.cc
@@ -31,29 +31,30 @@
void TexelFormatParser(::benchmark::State& state) {
std::array kStrings{
- "rcc2flot", "3flo3", "r32flVat", "r32float", "132float",
- "32Jlqqat", "ll3277loat", "ppqq2snHH", "r3cv", "b2siGt",
- "r32sint", "r32siivt", "8WW2sint", "rxxsint", "rXuingg",
- "3uiXt", "r32u3nt", "r32uint", "E32uint", "rPTTuint",
- "r32uidxx", "44g32float", "VVg32SSloat", "r32flo2Rt", "rg32float",
- "r93Float", "rg32foat", "rgVROOlHat", "rg3ysin", "77grr2sllnnt",
- "04g32sint", "rg32sint", "g3oont", "rg32zzt", "rgiipps1n",
- "XXg32uint", "rII39955nnnt", "aagHH2uinYSS", "rg32uint", "rkk3it",
- "gj3uRRn", "r3bunt", "rgba16fljat", "rgba6float", "rbq6float",
- "rgba16float", "rgba1NNloat", "rgbvv6flot", "rgbaQQ6foat", "rgb6srnff",
- "rgba16sijt", "NNgba16ww2t", "rgba16sint", "rgba16snt", "rgba16rrint",
- "rgba1Gsint", "rgba16uFFnt", "g16uEnt", "rgb16rrint", "rgba16uint",
- "gba16uit", "rXa1DuiJJt", "rgauint", "rga32klot", "rgb32float",
- "rgJa32flot", "rgba32float", "rgba32fcoat", "rgba32floOt", "__gttavv2fKKoat",
- "rg5a32xxnt", "__ba3sqqFt", "rgbqq2sint", "rgba32sint", "33ba32s66nt",
- "rtt6a3QQooint", "r66ba3sint", "xba32zzinO6", "ryyba32uint", "rbZ32HinZ",
- "rgba32uint", "rgba3u4WWnq", "rgba32uOOt", "oogba2Yin", "gba8si",
- "rgba8inF", "rgba8wnt", "rgba8sint", "Gb8Kinff", "KKgqa8sint",
- "rgbammsi3t", "rgba8snom", "rqba8norm", "rgbabbsnor", "rgba8snorm",
- "rba8siorm", "qgba8snoOm", "rgba8snoTTvv", "rgbaFFuint", "rgQa00uiP",
- "rgPa8uint", "rgba8uint", "rgssa77unt", "Cgbbb8uiRRt", "rgba8uinXX",
- "CqgbaOOunorm", "rgbu8usrL", "rgba8Xnorm", "rgba8unorm", "rgba8unrm",
- "ba8uqqor", "rgba8unor22",
+ "bgraunccrm", "blranr3", "bVra8unorm", "bgra8unorm", "bgra1unorm",
+ "bgrJqqnorm", "bgr7ll8unorm", "qq32lppHat", "c2fov", "r32Goat",
+ "r32float", "r3viiloat", "r3WWflo8t", "rxxfMoat", "rXsingg",
+ "3siXt", "r32s3nt", "r32sint", "E32sint", "rPTTsint",
+ "r32sidxx", "r442uint", "r3SSuiVVt", "R32R22t", "r32uint",
+ "rFui9t", "r32int", "VOORRHnt", "rgy2foat", "l77nnrr2floGt",
+ "rg42fl00at", "rg32float", "rgoofat", "rgzzflot", "g11p2fliia",
+ "XXg32sint", "rII39955nnnt", "aagHH2sinYSS", "rg32sint", "rkk3it",
+ "gj3sRRn", "r3bsnt", "rg32jint", "rg32unt", "rgqint",
+ "rg32uint", "rg32inNN", "g3vvint", "rg2uQQnt", "rga16floft",
+ "rgja16float", "rgNNww16f2oa", "rgba16float", "rgba16flot", "rgba16rrloat",
+ "rgGa16float", "rgba16sFFnt", "g16sEnt", "rgb16rrint", "rgba16sint",
+ "gba16sit", "rXa1DsiJJt", "rgasint", "rg111kin", "rgb16uint",
+ "rgJa16uit", "rgba16uint", "rgca16uint", "rgba16Oint", "KKgba__v6uintt",
+ "rgb832fxx5t", "rgbaqq__lat", "rgba32qloat", "rgba32float", "33gbO2floa66",
+ "rgboott6QQloat", "66ba32float", "xba32zzinO6", "ryyba32sint", "rbZ32HinZ",
+ "rgba32sint", "rgba3s4WWnq", "rgba32sOOt", "oogba2Yin", "ga32unt",
+ "Fga32uint", "rgb32uinw", "rgba32uint", "rgGf32uit", "rgbaqKKuint",
+ "rFba32ummnt", "rgba8snt", "rgq8sint", "rbbba8bin", "rgba8sint",
+ "rgbisint", "rgq8sinOO", "rgbaTTvvint", "rgFFa8snorm", "rg00QsnPrm",
+ "rgbaPsnorm", "rgba8snorm", "rgb77ssnorm", "rgba8snbbRRC", "rgbXX8snorm",
+ "qgCCOO8iOOt", "rsauuinL", "rgXa8uint", "rgba8uint", "rgba8int",
+ "rgbunqq", "rg22a8uint", "rybXX0nzzrm", "rgVVa8iorP", "rbaCunnnrm",
+ "rgba8unorm", "ba8unoqqHHA", "rga8unorm", "rgfa8uKKo",
};
for (auto _ : state) {
for (auto& str : kStrings) {
diff --git a/src/tint/ast/texel_format_test.cc b/src/tint/ast/texel_format_test.cc
index d257d5e..2caee4a 100644
--- a/src/tint/ast/texel_format_test.cc
+++ b/src/tint/ast/texel_format_test.cc
@@ -42,41 +42,44 @@
}
static constexpr Case kValidCases[] = {
- {"r32float", TexelFormat::kR32Float}, {"r32sint", TexelFormat::kR32Sint},
- {"r32uint", TexelFormat::kR32Uint}, {"rg32float", TexelFormat::kRg32Float},
- {"rg32sint", TexelFormat::kRg32Sint}, {"rg32uint", TexelFormat::kRg32Uint},
- {"rgba16float", TexelFormat::kRgba16Float}, {"rgba16sint", TexelFormat::kRgba16Sint},
- {"rgba16uint", TexelFormat::kRgba16Uint}, {"rgba32float", TexelFormat::kRgba32Float},
- {"rgba32sint", TexelFormat::kRgba32Sint}, {"rgba32uint", TexelFormat::kRgba32Uint},
- {"rgba8sint", TexelFormat::kRgba8Sint}, {"rgba8snorm", TexelFormat::kRgba8Snorm},
- {"rgba8uint", TexelFormat::kRgba8Uint}, {"rgba8unorm", TexelFormat::kRgba8Unorm},
+ {"bgra8unorm", TexelFormat::kBgra8Unorm}, {"r32float", TexelFormat::kR32Float},
+ {"r32sint", TexelFormat::kR32Sint}, {"r32uint", TexelFormat::kR32Uint},
+ {"rg32float", TexelFormat::kRg32Float}, {"rg32sint", TexelFormat::kRg32Sint},
+ {"rg32uint", TexelFormat::kRg32Uint}, {"rgba16float", TexelFormat::kRgba16Float},
+ {"rgba16sint", TexelFormat::kRgba16Sint}, {"rgba16uint", TexelFormat::kRgba16Uint},
+ {"rgba32float", TexelFormat::kRgba32Float}, {"rgba32sint", TexelFormat::kRgba32Sint},
+ {"rgba32uint", TexelFormat::kRgba32Uint}, {"rgba8sint", TexelFormat::kRgba8Sint},
+ {"rgba8snorm", TexelFormat::kRgba8Snorm}, {"rgba8uint", TexelFormat::kRgba8Uint},
+ {"rgba8unorm", TexelFormat::kRgba8Unorm},
};
static constexpr Case kInvalidCases[] = {
- {"rcc2flot", TexelFormat::kUndefined}, {"3flo3", TexelFormat::kUndefined},
- {"r32flVat", TexelFormat::kUndefined}, {"r32s1nt", TexelFormat::kUndefined},
- {"rq2Jint", TexelFormat::kUndefined}, {"r32sin7ll", TexelFormat::kUndefined},
- {"ppqq2unHH", TexelFormat::kUndefined}, {"r3cv", TexelFormat::kUndefined},
- {"b2uiGt", TexelFormat::kUndefined}, {"rgvi2float", TexelFormat::kUndefined},
- {"rg328WWoat", TexelFormat::kUndefined}, {"rg32lxxMt", TexelFormat::kUndefined},
- {"rgXggsnt", TexelFormat::kUndefined}, {"rgXsnu", TexelFormat::kUndefined},
- {"rg32s3nt", TexelFormat::kUndefined}, {"rg3Euint", TexelFormat::kUndefined},
- {"PP32TTint", TexelFormat::kUndefined}, {"xxg32ddnt", TexelFormat::kUndefined},
- {"rgba446float", TexelFormat::kUndefined}, {"SSVVba16float", TexelFormat::kUndefined},
- {"rgbRR6float", TexelFormat::kUndefined}, {"rga16Fint", TexelFormat::kUndefined},
- {"rgb16sint", TexelFormat::kUndefined}, {"ORVHa16sint", TexelFormat::kUndefined},
- {"ryba1uint", TexelFormat::kUndefined}, {"r77ba1nnullrrt", TexelFormat::kUndefined},
- {"rgb4006uint", TexelFormat::kUndefined}, {"rboofloat", TexelFormat::kUndefined},
- {"rgbaz2loat", TexelFormat::kUndefined}, {"ppga3ii1floa", TexelFormat::kUndefined},
- {"XXgba32sint", TexelFormat::kUndefined}, {"IIgb9932nni55t", TexelFormat::kUndefined},
- {"rYbaSSrrsiHHat", TexelFormat::kUndefined}, {"rbkk2Hit", TexelFormat::kUndefined},
- {"jgba3ugRR", TexelFormat::kUndefined}, {"rgbab2ui", TexelFormat::kUndefined},
- {"rgba8sijt", TexelFormat::kUndefined}, {"rba8sint", TexelFormat::kUndefined},
- {"rba8sqt", TexelFormat::kUndefined}, {"rgba8NNnom", TexelFormat::kUndefined},
- {"rga8vvorm", TexelFormat::kUndefined}, {"rgba8snorQ", TexelFormat::kUndefined},
- {"rgbauirf", TexelFormat::kUndefined}, {"rgbajuint", TexelFormat::kUndefined},
- {"wNNgbauin2", TexelFormat::kUndefined}, {"rgba8unrm", TexelFormat::kUndefined},
- {"rgba8urrorm", TexelFormat::kUndefined}, {"rgba8Gnorm", TexelFormat::kUndefined},
+ {"bgraunccrm", TexelFormat::kUndefined}, {"blranr3", TexelFormat::kUndefined},
+ {"bVra8unorm", TexelFormat::kUndefined}, {"132float", TexelFormat::kUndefined},
+ {"32Jlqqat", TexelFormat::kUndefined}, {"ll3277loat", TexelFormat::kUndefined},
+ {"ppqq2snHH", TexelFormat::kUndefined}, {"r3cv", TexelFormat::kUndefined},
+ {"b2siGt", TexelFormat::kUndefined}, {"r32uiivt", TexelFormat::kUndefined},
+ {"8WW2uint", TexelFormat::kUndefined}, {"rxxuint", TexelFormat::kUndefined},
+ {"rX2flggat", TexelFormat::kUndefined}, {"rg3XVut", TexelFormat::kUndefined},
+ {"3g32float", TexelFormat::kUndefined}, {"rg3Esint", TexelFormat::kUndefined},
+ {"PP32TTint", TexelFormat::kUndefined}, {"xxg32ddnt", TexelFormat::kUndefined},
+ {"44g32uint", TexelFormat::kUndefined}, {"rSS32uinVV", TexelFormat::kUndefined},
+ {"R322Rint", TexelFormat::kUndefined}, {"rgba16fF9a", TexelFormat::kUndefined},
+ {"rgba16floa", TexelFormat::kUndefined}, {"rOObVR16floH", TexelFormat::kUndefined},
+ {"ryba1sint", TexelFormat::kUndefined}, {"r77ba1nnsllrrt", TexelFormat::kUndefined},
+ {"rgb4006sint", TexelFormat::kUndefined}, {"rb1uioot", TexelFormat::kUndefined},
+ {"rga1uzznt", TexelFormat::kUndefined}, {"r11b1uppiit", TexelFormat::kUndefined},
+ {"rgba32fXXoat", TexelFormat::kUndefined}, {"rgbII99355float", TexelFormat::kUndefined},
+ {"rgbaa32fSSrHHYt", TexelFormat::kUndefined}, {"rbkk2Hit", TexelFormat::kUndefined},
+ {"jgba3sgRR", TexelFormat::kUndefined}, {"rgbab2si", TexelFormat::kUndefined},
+ {"rgba32jint", TexelFormat::kUndefined}, {"rba32uint", TexelFormat::kUndefined},
+ {"rgba2uqn", TexelFormat::kUndefined}, {"rbaNNsint", TexelFormat::kUndefined},
+ {"rga8invv", TexelFormat::kUndefined}, {"gba8sQQnt", TexelFormat::kUndefined},
+ {"rgbsnrrff", TexelFormat::kUndefined}, {"rgba8snojm", TexelFormat::kUndefined},
+ {"NNgba8sww2m", TexelFormat::kUndefined}, {"rgba8uit", TexelFormat::kUndefined},
+ {"rrgba8uint", TexelFormat::kUndefined}, {"rgba8uiGt", TexelFormat::kUndefined},
+ {"rgba8unFFrm", TexelFormat::kUndefined}, {"g8unErm", TexelFormat::kUndefined},
+ {"rgb8urrorm", TexelFormat::kUndefined},
};
using TexelFormatParseTest = testing::TestWithParam<Case>;
diff --git a/src/tint/cmd/main.cc b/src/tint/cmd/main.cc
index fd67617..a30a133 100644
--- a/src/tint/cmd/main.cc
+++ b/src/tint/cmd/main.cc
@@ -335,6 +335,8 @@
return "R32Sint";
case tint::inspector::ResourceBinding::TexelFormat::kR32Float:
return "R32Float";
+ case tint::inspector::ResourceBinding::TexelFormat::kBgra8Unorm:
+ return "Bgra8Unorm";
case tint::inspector::ResourceBinding::TexelFormat::kRgba8Unorm:
return "Rgba8Unorm";
case tint::inspector::ResourceBinding::TexelFormat::kRgba8Snorm:
diff --git a/src/tint/inspector/resource_binding.cc b/src/tint/inspector/resource_binding.cc
index 4fca85e..4dd26e0 100644
--- a/src/tint/inspector/resource_binding.cc
+++ b/src/tint/inspector/resource_binding.cc
@@ -72,6 +72,8 @@
ResourceBinding::TexelFormat TypeTexelFormatToResourceBindingTexelFormat(
const ast::TexelFormat& image_format) {
switch (image_format) {
+ case ast::TexelFormat::kBgra8Unorm:
+ return ResourceBinding::TexelFormat::kBgra8Unorm;
case ast::TexelFormat::kR32Uint:
return ResourceBinding::TexelFormat::kR32Uint;
case ast::TexelFormat::kR32Sint:
diff --git a/src/tint/inspector/resource_binding.h b/src/tint/inspector/resource_binding.h
index 76b5024..ef22578 100644
--- a/src/tint/inspector/resource_binding.h
+++ b/src/tint/inspector/resource_binding.h
@@ -51,6 +51,7 @@
enum class TexelFormat {
kNone = -1,
+ kBgra8Unorm,
kRgba8Unorm,
kRgba8Snorm,
kRgba8Uint,
diff --git a/src/tint/intrinsics.def b/src/tint/intrinsics.def
index c8ff511..08dc366 100644
--- a/src/tint/intrinsics.def
+++ b/src/tint/intrinsics.def
@@ -79,6 +79,7 @@
// https://gpuweb.github.io/gpuweb/wgsl/#texel-formats
enum texel_format {
+ bgra8unorm
rgba8unorm
rgba8snorm
rgba8uint
@@ -244,7 +245,8 @@
// https://gpuweb.github.io/gpuweb/wgsl/#texel-formats
match f32_texel_format
- : texel_format.rgba8unorm
+ : texel_format.bgra8unorm
+ | texel_format.rgba8unorm
| texel_format.rgba8snorm
| texel_format.rgba16float
| texel_format.r32float
diff --git a/src/tint/reader/wgsl/parser_impl_error_msg_test.cc b/src/tint/reader/wgsl/parser_impl_error_msg_test.cc
index 822be9b..ff077ab 100644
--- a/src/tint/reader/wgsl/parser_impl_error_msg_test.cc
+++ b/src/tint/reader/wgsl/parser_impl_error_msg_test.cc
@@ -681,7 +681,7 @@
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingSubtype) {
EXPECT("var x : texture_storage_2d<>;",
R"(test.wgsl:1:28 error: expected texel format for storage texture type
-Possible values: 'r32float', 'r32sint', 'r32uint', 'rg32float', 'rg32sint', 'rg32uint', 'rgba16float', 'rgba16sint', 'rgba16uint', 'rgba32float', 'rgba32sint', 'rgba32uint', 'rgba8sint', 'rgba8snorm', 'rgba8uint', 'rgba8unorm'
+Possible values: 'bgra8unorm', 'r32float', 'r32sint', 'r32uint', 'rg32float', 'rg32sint', 'rg32uint', 'rgba16float', 'rgba16sint', 'rgba16uint', 'rgba32float', 'rgba32sint', 'rgba32uint', 'rgba8sint', 'rgba8snorm', 'rgba8uint', 'rgba8unorm'
var x : texture_storage_2d<>;
^
)");
@@ -690,7 +690,7 @@
TEST_F(ParserImplErrorTest, GlobalDeclStorageTextureMissingInvalidSubtype) {
EXPECT("var x : texture_storage_2d<1>;",
R"(test.wgsl:1:28 error: expected texel format for storage texture type
-Possible values: 'r32float', 'r32sint', 'r32uint', 'rg32float', 'rg32sint', 'rg32uint', 'rgba16float', 'rgba16sint', 'rgba16uint', 'rgba32float', 'rgba32sint', 'rgba32uint', 'rgba8sint', 'rgba8snorm', 'rgba8uint', 'rgba8unorm'
+Possible values: 'bgra8unorm', 'r32float', 'r32sint', 'r32uint', 'rg32float', 'rg32sint', 'rg32uint', 'rgba16float', 'rgba16sint', 'rgba16uint', 'rgba32float', 'rgba32sint', 'rgba32uint', 'rgba8sint', 'rgba8snorm', 'rgba8uint', 'rgba8unorm'
var x : texture_storage_2d<1>;
^
)");
diff --git a/src/tint/reader/wgsl/parser_impl_texel_format_test.cc b/src/tint/reader/wgsl/parser_impl_texel_format_test.cc
index 1697359..8551032 100644
--- a/src/tint/reader/wgsl/parser_impl_texel_format_test.cc
+++ b/src/tint/reader/wgsl/parser_impl_texel_format_test.cc
@@ -23,7 +23,7 @@
EXPECT_TRUE(t.errored);
EXPECT_TRUE(p->has_error());
EXPECT_EQ(p->error(), R"(1:1: expected texel format for test
-Possible values: 'r32float', 'r32sint', 'r32uint', 'rg32float', 'rg32sint', 'rg32uint', 'rgba16float', 'rgba16sint', 'rgba16uint', 'rgba32float', 'rgba32sint', 'rgba32uint', 'rgba8sint', 'rgba8snorm', 'rgba8uint', 'rgba8unorm')");
+Possible values: 'bgra8unorm', 'r32float', 'r32sint', 'r32uint', 'rg32float', 'rg32sint', 'rg32uint', 'rgba16float', 'rgba16sint', 'rgba16uint', 'rgba32float', 'rgba32sint', 'rgba32uint', 'rgba8sint', 'rgba8snorm', 'rgba8uint', 'rgba8unorm')");
}
TEST_F(ParserImplTest, TexelFormat_R32Uint) {
diff --git a/src/tint/reader/wgsl/parser_impl_texture_sampler_test.cc b/src/tint/reader/wgsl/parser_impl_texture_sampler_test.cc
index 47ea247..01a4241 100644
--- a/src/tint/reader/wgsl/parser_impl_texture_sampler_test.cc
+++ b/src/tint/reader/wgsl/parser_impl_texture_sampler_test.cc
@@ -219,7 +219,7 @@
EXPECT_FALSE(t.matched);
EXPECT_TRUE(t.errored);
EXPECT_EQ(p->error(), R"(1:20: expected texel format for storage texture type
-Possible values: 'r32float', 'r32sint', 'r32uint', 'rg32float', 'rg32sint', 'rg32uint', 'rgba16float', 'rgba16sint', 'rgba16uint', 'rgba32float', 'rgba32sint', 'rgba32uint', 'rgba8sint', 'rgba8snorm', 'rgba8uint', 'rgba8unorm')");
+Possible values: 'bgra8unorm', 'r32float', 'r32sint', 'r32uint', 'rg32float', 'rg32sint', 'rg32uint', 'rgba16float', 'rgba16sint', 'rgba16uint', 'rgba32float', 'rgba32sint', 'rgba32uint', 'rgba8sint', 'rgba8snorm', 'rgba8uint', 'rgba8unorm')");
}
TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidTypeSuggest) {
@@ -230,7 +230,7 @@
EXPECT_TRUE(t.errored);
EXPECT_EQ(p->error(),
R"(1:20: expected texel format for storage texture type. Did you mean 'rg32float'?
-Possible values: 'r32float', 'r32sint', 'r32uint', 'rg32float', 'rg32sint', 'rg32uint', 'rgba16float', 'rgba16sint', 'rgba16uint', 'rgba32float', 'rgba32sint', 'rgba32uint', 'rgba8sint', 'rgba8snorm', 'rgba8uint', 'rgba8unorm')");
+Possible values: 'bgra8unorm', 'r32float', 'r32sint', 'r32uint', 'rg32float', 'rg32sint', 'rg32uint', 'rgba16float', 'rgba16sint', 'rgba16uint', 'rgba32float', 'rgba32sint', 'rgba32uint', 'rgba8sint', 'rgba8snorm', 'rgba8uint', 'rgba8unorm')");
}
TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidAccess) {
@@ -251,7 +251,7 @@
EXPECT_FALSE(t.matched);
EXPECT_TRUE(t.errored);
EXPECT_EQ(p->error(), R"(1:20: expected texel format for storage texture type
-Possible values: 'r32float', 'r32sint', 'r32uint', 'rg32float', 'rg32sint', 'rg32uint', 'rgba16float', 'rgba16sint', 'rgba16uint', 'rgba32float', 'rgba32sint', 'rgba32uint', 'rgba8sint', 'rgba8snorm', 'rgba8uint', 'rgba8unorm')");
+Possible values: 'bgra8unorm', 'r32float', 'r32sint', 'r32uint', 'rg32float', 'rg32sint', 'rg32uint', 'rgba16float', 'rgba16sint', 'rgba16uint', 'rgba32float', 'rgba32sint', 'rgba32uint', 'rgba8sint', 'rgba8snorm', 'rgba8uint', 'rgba8unorm')");
}
TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingLessThan) {
diff --git a/src/tint/resolver/intrinsic_table.inl b/src/tint/resolver/intrinsic_table.inl
index b13934a..a8351f5 100644
--- a/src/tint/resolver/intrinsic_table.inl
+++ b/src/tint/resolver/intrinsic_table.inl
@@ -2378,6 +2378,7 @@
Number F32TexelFormat::Match(MatchState&, Number number) const {
switch (static_cast<TexelFormat>(number.Value())) {
+ case TexelFormat::kBgra8Unorm:
case TexelFormat::kRgba8Unorm:
case TexelFormat::kRgba8Snorm:
case TexelFormat::kRgba16Float:
@@ -2391,7 +2392,7 @@
}
std::string F32TexelFormat::String(MatchState*) const {
- return "rgba8unorm, rgba8snorm, rgba16float, r32float, rg32float or rgba32float";
+ return "bgra8unorm, rgba8unorm, rgba8snorm, rgba16float, r32float, rg32float or rgba32float";
}
/// EnumMatcher for 'match i32_texel_format'
diff --git a/src/tint/resolver/type_validation_test.cc b/src/tint/resolver/type_validation_test.cc
index c3c9119..ebd40b0 100644
--- a/src/tint/resolver/type_validation_test.cc
+++ b/src/tint/resolver/type_validation_test.cc
@@ -1126,7 +1126,8 @@
bool is_valid;
};
-static constexpr FormatParams format_cases[] = {FormatParams{ast::TexelFormat::kR32Float, true},
+static constexpr FormatParams format_cases[] = {FormatParams{ast::TexelFormat::kBgra8Unorm, true},
+ FormatParams{ast::TexelFormat::kR32Float, true},
FormatParams{ast::TexelFormat::kR32Sint, true},
FormatParams{ast::TexelFormat::kR32Uint, true},
FormatParams{ast::TexelFormat::kRg32Float, true},
diff --git a/src/tint/resolver/validator.cc b/src/tint/resolver/validator.cc
index 6c05df2..c25129a 100644
--- a/src/tint/resolver/validator.cc
+++ b/src/tint/resolver/validator.cc
@@ -98,6 +98,7 @@
bool IsValidStorageTextureTexelFormat(ast::TexelFormat format) {
switch (format) {
+ case ast::TexelFormat::kBgra8Unorm:
case ast::TexelFormat::kR32Uint:
case ast::TexelFormat::kR32Sint:
case ast::TexelFormat::kR32Float:
diff --git a/src/tint/transform/builtin_polyfill.cc b/src/tint/transform/builtin_polyfill.cc
index 2bab400..dbd6f6e 100644
--- a/src/tint/transform/builtin_polyfill.cc
+++ b/src/tint/transform/builtin_polyfill.cc
@@ -833,160 +833,206 @@
bool made_changes = false;
for (auto* node : src->ASTNodes().Objects()) {
- auto* expr = src->Sem().Get<sem::Expression>(node);
- if (!expr || expr->Stage() == sem::EvaluationStage::kConstant ||
- expr->Stage() == sem::EvaluationStage::kNotEvaluated) {
- continue; // Don't polyfill @const expressions
- }
-
- if (auto* call = expr->As<sem::Call>()) {
- auto* builtin = call->Target()->As<sem::Builtin>();
- if (!builtin) {
- continue;
- }
- Symbol fn;
- switch (builtin->Type()) {
- case sem::BuiltinType::kAcosh:
- if (polyfill.acosh != Level::kNone) {
- fn = builtin_polyfills.GetOrCreate(
- builtin, [&] { return s.acosh(builtin->ReturnType()); });
- }
- break;
- case sem::BuiltinType::kAsinh:
- if (polyfill.asinh) {
- fn = builtin_polyfills.GetOrCreate(
- builtin, [&] { return s.asinh(builtin->ReturnType()); });
- }
- break;
- case sem::BuiltinType::kAtanh:
- if (polyfill.atanh != Level::kNone) {
- fn = builtin_polyfills.GetOrCreate(
- builtin, [&] { return s.atanh(builtin->ReturnType()); });
- }
- break;
- case sem::BuiltinType::kClamp:
- if (polyfill.clamp_int) {
- auto& sig = builtin->Signature();
- if (sig.parameters[0]->Type()->is_integer_scalar_or_vector()) {
+ Switch(
+ node,
+ [&](const ast::CallExpression* expr) {
+ auto* call = src->Sem().Get(expr)->UnwrapMaterialize()->As<sem::Call>();
+ if (!call || call->Stage() == sem::EvaluationStage::kConstant ||
+ call->Stage() == sem::EvaluationStage::kNotEvaluated) {
+ return; // Don't polyfill @const expressions
+ }
+ auto* builtin = call->Target()->As<sem::Builtin>();
+ if (!builtin) {
+ return;
+ }
+ Symbol fn;
+ switch (builtin->Type()) {
+ case sem::BuiltinType::kAcosh:
+ if (polyfill.acosh != Level::kNone) {
fn = builtin_polyfills.GetOrCreate(
- builtin, [&] { return s.clampInteger(builtin->ReturnType()); });
+ builtin, [&] { return s.acosh(builtin->ReturnType()); });
}
- }
- break;
- case sem::BuiltinType::kCountLeadingZeros:
- if (polyfill.count_leading_zeros) {
- fn = builtin_polyfills.GetOrCreate(
- builtin, [&] { return s.countLeadingZeros(builtin->ReturnType()); });
- }
- break;
- case sem::BuiltinType::kCountTrailingZeros:
- if (polyfill.count_trailing_zeros) {
- fn = builtin_polyfills.GetOrCreate(
- builtin, [&] { return s.countTrailingZeros(builtin->ReturnType()); });
- }
- break;
- case sem::BuiltinType::kExtractBits:
- if (polyfill.extract_bits != Level::kNone) {
- fn = builtin_polyfills.GetOrCreate(
- builtin, [&] { return s.extractBits(builtin->ReturnType()); });
- }
- break;
- case sem::BuiltinType::kFirstLeadingBit:
- if (polyfill.first_leading_bit) {
- fn = builtin_polyfills.GetOrCreate(
- builtin, [&] { return s.firstLeadingBit(builtin->ReturnType()); });
- }
- break;
- case sem::BuiltinType::kFirstTrailingBit:
- if (polyfill.first_trailing_bit) {
- fn = builtin_polyfills.GetOrCreate(
- builtin, [&] { return s.firstTrailingBit(builtin->ReturnType()); });
- }
- break;
- case sem::BuiltinType::kInsertBits:
- if (polyfill.insert_bits != Level::kNone) {
- fn = builtin_polyfills.GetOrCreate(
- builtin, [&] { return s.insertBits(builtin->ReturnType()); });
- }
- break;
- case sem::BuiltinType::kSaturate:
- if (polyfill.saturate) {
- fn = builtin_polyfills.GetOrCreate(
- builtin, [&] { return s.saturate(builtin->ReturnType()); });
- }
- break;
- case sem::BuiltinType::kSign:
- if (polyfill.sign_int) {
- auto* ty = builtin->ReturnType();
- if (ty->is_signed_integer_scalar_or_vector()) {
- fn = builtin_polyfills.GetOrCreate(builtin,
- [&] { return s.sign_int(ty); });
+ break;
+ case sem::BuiltinType::kAsinh:
+ if (polyfill.asinh) {
+ fn = builtin_polyfills.GetOrCreate(
+ builtin, [&] { return s.asinh(builtin->ReturnType()); });
}
- }
- break;
- case sem::BuiltinType::kTextureSampleBaseClampToEdge:
- if (polyfill.texture_sample_base_clamp_to_edge_2d_f32) {
- auto& sig = builtin->Signature();
- auto* tex = sig.Parameter(sem::ParameterUsage::kTexture);
- if (auto* stex = tex->Type()->As<type::SampledTexture>()) {
- if (stex->type()->Is<type::F32>()) {
- fn = builtin_polyfills.GetOrCreate(builtin, [&] {
- return s.textureSampleBaseClampToEdge_2d_f32();
- });
+ break;
+ case sem::BuiltinType::kAtanh:
+ if (polyfill.atanh != Level::kNone) {
+ fn = builtin_polyfills.GetOrCreate(
+ builtin, [&] { return s.atanh(builtin->ReturnType()); });
+ }
+ break;
+ case sem::BuiltinType::kClamp:
+ if (polyfill.clamp_int) {
+ auto& sig = builtin->Signature();
+ if (sig.parameters[0]->Type()->is_integer_scalar_or_vector()) {
+ fn = builtin_polyfills.GetOrCreate(
+ builtin, [&] { return s.clampInteger(builtin->ReturnType()); });
}
}
- }
- break;
- case sem::BuiltinType::kQuantizeToF16:
- if (polyfill.quantize_to_vec_f16) {
- if (auto* vec = builtin->ReturnType()->As<type::Vector>()) {
- fn = builtin_polyfills.GetOrCreate(
- builtin, [&] { return s.quantizeToF16(vec); });
+ break;
+ case sem::BuiltinType::kCountLeadingZeros:
+ if (polyfill.count_leading_zeros) {
+ fn = builtin_polyfills.GetOrCreate(builtin, [&] {
+ return s.countLeadingZeros(builtin->ReturnType());
+ });
}
- }
- break;
+ break;
+ case sem::BuiltinType::kCountTrailingZeros:
+ if (polyfill.count_trailing_zeros) {
+ fn = builtin_polyfills.GetOrCreate(builtin, [&] {
+ return s.countTrailingZeros(builtin->ReturnType());
+ });
+ }
+ break;
+ case sem::BuiltinType::kExtractBits:
+ if (polyfill.extract_bits != Level::kNone) {
+ fn = builtin_polyfills.GetOrCreate(
+ builtin, [&] { return s.extractBits(builtin->ReturnType()); });
+ }
+ break;
+ case sem::BuiltinType::kFirstLeadingBit:
+ if (polyfill.first_leading_bit) {
+ fn = builtin_polyfills.GetOrCreate(
+ builtin, [&] { return s.firstLeadingBit(builtin->ReturnType()); });
+ }
+ break;
+ case sem::BuiltinType::kFirstTrailingBit:
+ if (polyfill.first_trailing_bit) {
+ fn = builtin_polyfills.GetOrCreate(
+ builtin, [&] { return s.firstTrailingBit(builtin->ReturnType()); });
+ }
+ break;
+ case sem::BuiltinType::kInsertBits:
+ if (polyfill.insert_bits != Level::kNone) {
+ fn = builtin_polyfills.GetOrCreate(
+ builtin, [&] { return s.insertBits(builtin->ReturnType()); });
+ }
+ break;
+ case sem::BuiltinType::kSaturate:
+ if (polyfill.saturate) {
+ fn = builtin_polyfills.GetOrCreate(
+ builtin, [&] { return s.saturate(builtin->ReturnType()); });
+ }
+ break;
+ case sem::BuiltinType::kSign:
+ if (polyfill.sign_int) {
+ auto* ty = builtin->ReturnType();
+ if (ty->is_signed_integer_scalar_or_vector()) {
+ fn = builtin_polyfills.GetOrCreate(builtin,
+ [&] { return s.sign_int(ty); });
+ }
+ }
+ break;
+ case sem::BuiltinType::kTextureSampleBaseClampToEdge:
+ if (polyfill.texture_sample_base_clamp_to_edge_2d_f32) {
+ auto& sig = builtin->Signature();
+ auto* tex = sig.Parameter(sem::ParameterUsage::kTexture);
+ if (auto* stex = tex->Type()->As<type::SampledTexture>()) {
+ if (stex->type()->Is<type::F32>()) {
+ fn = builtin_polyfills.GetOrCreate(builtin, [&] {
+ return s.textureSampleBaseClampToEdge_2d_f32();
+ });
+ }
+ }
+ }
+ break;
+ case sem::BuiltinType::kTextureStore:
+ if (polyfill.bgra8unorm) {
+ auto& sig = builtin->Signature();
+ auto* tex = sig.Parameter(sem::ParameterUsage::kTexture);
+ if (auto* stex = tex->Type()->As<type::StorageTexture>()) {
+ if (stex->texel_format() == ast::TexelFormat::kBgra8Unorm) {
+ size_t value_idx = static_cast<size_t>(
+ sig.IndexOf(sem::ParameterUsage::kValue));
+ ctx.Replace(expr, [&ctx, expr, value_idx] {
+ utils::Vector<const ast::Expression*, 3> args;
+ for (auto* arg : expr->args) {
+ arg = ctx.Clone(arg);
+ if (args.Length() == value_idx) { // value
+ arg = ctx.dst->MemberAccessor(arg, "bgra");
+ }
+ args.Push(arg);
+ }
+ return ctx.dst->Call(
+ utils::ToString(sem::BuiltinType::kTextureStore),
+ std::move(args));
+ });
+ made_changes = true;
+ }
+ }
+ }
+ break;
+ case sem::BuiltinType::kQuantizeToF16:
+ if (polyfill.quantize_to_vec_f16) {
+ if (auto* vec = builtin->ReturnType()->As<type::Vector>()) {
+ fn = builtin_polyfills.GetOrCreate(
+ builtin, [&] { return s.quantizeToF16(vec); });
+ }
+ }
+ break;
- case sem::BuiltinType::kWorkgroupUniformLoad:
- if (polyfill.workgroup_uniform_load) {
- fn = builtin_polyfills.GetOrCreate(
- builtin, [&] { return s.workgroupUniformLoad(builtin->ReturnType()); });
- }
- break;
+ case sem::BuiltinType::kWorkgroupUniformLoad:
+ if (polyfill.workgroup_uniform_load) {
+ fn = builtin_polyfills.GetOrCreate(builtin, [&] {
+ return s.workgroupUniformLoad(builtin->ReturnType());
+ });
+ }
+ break;
- default:
- break;
- }
-
- if (fn.IsValid()) {
- auto* replacement = b.Call(fn, ctx.Clone(call->Declaration()->args));
- ctx.Replace(call->Declaration(), replacement);
- made_changes = true;
- }
- } else if (auto* bin_op = node->As<ast::BinaryExpression>()) {
- switch (bin_op->op) {
- case ast::BinaryOp::kShiftLeft:
- case ast::BinaryOp::kShiftRight: {
- if (polyfill.bitshift_modulo) {
- ctx.Replace(bin_op, [bin_op, &s] { return s.BitshiftModulo(bin_op); });
- made_changes = true;
- }
- break;
+ default:
+ break;
}
- case ast::BinaryOp::kDivide:
- case ast::BinaryOp::kModulo: {
- if (polyfill.int_div_mod) {
- auto* lhs_ty = src->TypeOf(bin_op->lhs)->UnwrapRef();
- if (lhs_ty->is_integer_scalar_or_vector()) {
- ctx.Replace(bin_op, [bin_op, &s] { return s.IntDivMod(bin_op); });
+
+ if (fn.IsValid()) {
+ ctx.Replace(call->Declaration(), [&ctx, fn, expr] {
+ return ctx.dst->Call(fn, ctx.Clone(expr->args));
+ });
+ made_changes = true;
+ }
+ },
+ [&](const ast::BinaryExpression* bin_op) {
+ if (auto* sem = src->Sem().Get(bin_op);
+ !sem || sem->Stage() == sem::EvaluationStage::kConstant ||
+ sem->Stage() == sem::EvaluationStage::kNotEvaluated) {
+ return; // Don't polyfill @const expressions
+ }
+ switch (bin_op->op) {
+ case ast::BinaryOp::kShiftLeft:
+ case ast::BinaryOp::kShiftRight: {
+ if (polyfill.bitshift_modulo) {
+ ctx.Replace(bin_op, [bin_op, &s] { return s.BitshiftModulo(bin_op); });
made_changes = true;
}
+ break;
}
- break;
+ case ast::BinaryOp::kDivide:
+ case ast::BinaryOp::kModulo: {
+ if (polyfill.int_div_mod) {
+ auto* lhs_ty = src->TypeOf(bin_op->lhs)->UnwrapRef();
+ if (lhs_ty->is_integer_scalar_or_vector()) {
+ ctx.Replace(bin_op, [bin_op, &s] { return s.IntDivMod(bin_op); });
+ made_changes = true;
+ }
+ }
+ break;
+ }
+ default:
+ break;
}
- default:
- break;
- }
- }
+ },
+ [&](const ast::StorageTexture* tex) {
+ if (polyfill.bgra8unorm && tex->format == ast::TexelFormat::kBgra8Unorm) {
+ ctx.Replace(tex, [&ctx, tex] {
+ return ctx.dst->ty.storage_texture(tex->dim, ast::TexelFormat::kRgba8Unorm,
+ tex->access);
+ });
+ made_changes = true;
+ }
+ });
}
if (!made_changes) {
diff --git a/src/tint/transform/builtin_polyfill.h b/src/tint/transform/builtin_polyfill.h
index a3d5b48..ae5f588 100644
--- a/src/tint/transform/builtin_polyfill.h
+++ b/src/tint/transform/builtin_polyfill.h
@@ -47,6 +47,8 @@
bool asinh = false;
/// What level should `atanh` be polyfilled?
Level atanh = Level::kNone;
+ /// Should storage textures of format 'bgra8unorm' be replaced with 'rgba8unorm'?
+ bool bgra8unorm = false;
/// Should the RHS of `<<` and `>>` be wrapped in a modulo bit-width of LHS?
bool bitshift_modulo = false;
/// Should `clamp()` be polyfilled for integer values (scalar or vector)?
diff --git a/src/tint/transform/builtin_polyfill_test.cc b/src/tint/transform/builtin_polyfill_test.cc
index aed8d97..2a7f684 100644
--- a/src/tint/transform/builtin_polyfill_test.cc
+++ b/src/tint/transform/builtin_polyfill_test.cc
@@ -381,6 +381,138 @@
}
////////////////////////////////////////////////////////////////////////////////
+// bgra8unorm
+////////////////////////////////////////////////////////////////////////////////
+DataMap polyfillBgra8unorm() {
+ BuiltinPolyfill::Builtins builtins;
+ builtins.bgra8unorm = true;
+ DataMap data;
+ data.Add<BuiltinPolyfill::Config>(builtins);
+ return data;
+}
+
+TEST_F(BuiltinPolyfillTest, ShouldRunBgra8unorm_StorageTextureVar) {
+ auto* src = R"(
+@group(0) @binding(0) var tex : texture_storage_3d<bgra8unorm, write>;
+)";
+
+ EXPECT_FALSE(ShouldRun<BuiltinPolyfill>(src));
+ EXPECT_TRUE(ShouldRun<BuiltinPolyfill>(src, polyfillBgra8unorm()));
+}
+
+TEST_F(BuiltinPolyfillTest, ShouldRunBgra8unorm_StorageTextureParam) {
+ auto* src = R"(
+fn f(tex : texture_storage_3d<bgra8unorm, write>) {
+}
+)";
+
+ EXPECT_FALSE(ShouldRun<BuiltinPolyfill>(src));
+ EXPECT_TRUE(ShouldRun<BuiltinPolyfill>(src, polyfillBgra8unorm()));
+}
+
+TEST_F(BuiltinPolyfillTest, Bgra8unorm_StorageTextureVar) {
+ auto* src = R"(
+@group(0) @binding(0) var tex : texture_storage_3d<bgra8unorm, write>;
+)";
+
+ auto* expect = R"(
+@group(0) @binding(0) var tex : texture_storage_3d<rgba8unorm, write>;
+)";
+
+ auto got = Run<BuiltinPolyfill>(src, polyfillBgra8unorm());
+
+ EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(BuiltinPolyfillTest, Bgra8unorm_StorageTextureParam) {
+ auto* src = R"(
+fn f(tex : texture_storage_3d<bgra8unorm, write>) {
+}
+)";
+
+ auto* expect = R"(
+fn f(tex : texture_storage_3d<rgba8unorm, write>) {
+}
+)";
+
+ auto got = Run<BuiltinPolyfill>(src, polyfillBgra8unorm());
+
+ EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(BuiltinPolyfillTest, Bgra8unorm_TextureStore) {
+ auto* src = R"(
+@group(0) @binding(0) var tex : texture_storage_2d<bgra8unorm, write>;
+
+fn f(coords : vec2<i32>, value : vec4<f32>) {
+ textureStore(tex, coords, value);
+}
+)";
+
+ auto* expect = R"(
+@group(0) @binding(0) var tex : texture_storage_2d<rgba8unorm, write>;
+
+fn f(coords : vec2<i32>, value : vec4<f32>) {
+ textureStore(tex, coords, value.bgra);
+}
+)";
+
+ auto got = Run<BuiltinPolyfill>(src, polyfillBgra8unorm());
+
+ EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(BuiltinPolyfillTest, Bgra8unorm_TextureStore_Param) {
+ auto* src = R"(
+fn f(tex : texture_storage_2d<bgra8unorm, write>, coords : vec2<i32>, value : vec4<f32>) {
+ textureStore(tex, coords, value);
+}
+)";
+
+ auto* expect = R"(
+fn f(tex : texture_storage_2d<rgba8unorm, write>, coords : vec2<i32>, value : vec4<f32>) {
+ textureStore(tex, coords, value.bgra);
+}
+)";
+
+ auto got = Run<BuiltinPolyfill>(src, polyfillBgra8unorm());
+
+ EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(BuiltinPolyfillTest, Bgra8unorm_TextureStore_WithAtanh) {
+ auto* src = R"(
+@group(0) @binding(0) var tex : texture_storage_2d<bgra8unorm, write>;
+
+fn f(coords : vec2<i32>, value : vec4<f32>) {
+ textureStore(tex, coords, atanh(value));
+}
+)";
+
+ auto* expect = R"(
+fn tint_atanh(x : vec4<f32>) -> vec4<f32> {
+ return (log(((1 + x) / (1 - x))) * 0.5);
+}
+
+@group(0) @binding(0) var tex : texture_storage_2d<rgba8unorm, write>;
+
+fn f(coords : vec2<i32>, value : vec4<f32>) {
+ textureStore(tex, coords, tint_atanh(value).bgra);
+}
+)";
+
+ BuiltinPolyfill::Builtins builtins;
+ builtins.atanh = BuiltinPolyfill::Level::kFull;
+ builtins.bgra8unorm = true;
+ DataMap data;
+ data.Add<BuiltinPolyfill::Config>(builtins);
+
+ auto got = Run<BuiltinPolyfill>(src, std::move(data));
+
+ EXPECT_EQ(expect, str(got));
+}
+
+////////////////////////////////////////////////////////////////////////////////
// bitshiftModulo
////////////////////////////////////////////////////////////////////////////////
DataMap polyfillBitshiftModulo() {
diff --git a/src/tint/type/storage_texture.cc b/src/tint/type/storage_texture.cc
index d893767..a47b094 100644
--- a/src/tint/type/storage_texture.cc
+++ b/src/tint/type/storage_texture.cc
@@ -63,6 +63,7 @@
return type_mgr.Get<I32>();
}
+ case ast::TexelFormat::kBgra8Unorm:
case ast::TexelFormat::kRgba8Unorm:
case ast::TexelFormat::kRgba8Snorm:
case ast::TexelFormat::kR32Float:
diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc
index b5d897d..720423c 100644
--- a/src/tint/writer/glsl/generator_impl.cc
+++ b/src/tint/writer/glsl/generator_impl.cc
@@ -110,46 +110,6 @@
return IsAnyOf<ast::BreakStatement>(stmts->Last());
}
-const char* convert_texel_format_to_glsl(const ast::TexelFormat format) {
- switch (format) {
- case ast::TexelFormat::kR32Uint:
- return "r32ui";
- case ast::TexelFormat::kR32Sint:
- return "r32i";
- case ast::TexelFormat::kR32Float:
- return "r32f";
- case ast::TexelFormat::kRgba8Unorm:
- return "rgba8";
- case ast::TexelFormat::kRgba8Snorm:
- return "rgba8_snorm";
- case ast::TexelFormat::kRgba8Uint:
- return "rgba8ui";
- case ast::TexelFormat::kRgba8Sint:
- return "rgba8i";
- case ast::TexelFormat::kRg32Uint:
- return "rg32ui";
- case ast::TexelFormat::kRg32Sint:
- return "rg32i";
- case ast::TexelFormat::kRg32Float:
- return "rg32f";
- case ast::TexelFormat::kRgba16Uint:
- return "rgba16ui";
- case ast::TexelFormat::kRgba16Sint:
- return "rgba16i";
- case ast::TexelFormat::kRgba16Float:
- return "rgba16f";
- case ast::TexelFormat::kRgba32Uint:
- return "rgba32ui";
- case ast::TexelFormat::kRgba32Sint:
- return "rgba32i";
- case ast::TexelFormat::kRgba32Float:
- return "rgba32f";
- case ast::TexelFormat::kUndefined:
- return "unknown";
- }
- return "unknown";
-}
-
void PrintF32(std::ostream& out, float value) {
if (std::isinf(value)) {
out << "0.0f " << (value >= 0 ? "/* inf */" : "/* -inf */");
@@ -191,6 +151,7 @@
transform::BuiltinPolyfill::Builtins polyfills;
polyfills.acosh = transform::BuiltinPolyfill::Level::kRangeCheck;
polyfills.atanh = transform::BuiltinPolyfill::Level::kRangeCheck;
+ polyfills.bgra8unorm = true;
polyfills.bitshift_modulo = true;
polyfills.count_leading_zeros = true;
polyfills.count_trailing_zeros = true;
@@ -2069,7 +2030,65 @@
return true;
}
if (auto* storage = type->As<type::StorageTexture>()) {
- out << "layout(" << convert_texel_format_to_glsl(storage->texel_format()) << ") ";
+ out << "layout(";
+ switch (storage->texel_format()) {
+ case ast::TexelFormat::kBgra8Unorm:
+ TINT_ICE(Writer, diagnostics_)
+ << "bgra8unorm should have been polyfilled to rgba8unorm";
+ break;
+ case ast::TexelFormat::kR32Uint:
+ out << "r32ui";
+ break;
+ case ast::TexelFormat::kR32Sint:
+ out << "r32i";
+ break;
+ case ast::TexelFormat::kR32Float:
+ out << "r32f";
+ break;
+ case ast::TexelFormat::kRgba8Unorm:
+ out << "rgba8";
+ break;
+ case ast::TexelFormat::kRgba8Snorm:
+ out << "rgba8_snorm";
+ break;
+ case ast::TexelFormat::kRgba8Uint:
+ out << "rgba8ui";
+ break;
+ case ast::TexelFormat::kRgba8Sint:
+ out << "rgba8i";
+ break;
+ case ast::TexelFormat::kRg32Uint:
+ out << "rg32ui";
+ break;
+ case ast::TexelFormat::kRg32Sint:
+ out << "rg32i";
+ break;
+ case ast::TexelFormat::kRg32Float:
+ out << "rg32f";
+ break;
+ case ast::TexelFormat::kRgba16Uint:
+ out << "rgba16ui";
+ break;
+ case ast::TexelFormat::kRgba16Sint:
+ out << "rgba16i";
+ break;
+ case ast::TexelFormat::kRgba16Float:
+ out << "rgba16f";
+ break;
+ case ast::TexelFormat::kRgba32Uint:
+ out << "rgba32ui";
+ break;
+ case ast::TexelFormat::kRgba32Sint:
+ out << "rgba32i";
+ break;
+ case ast::TexelFormat::kRgba32Float:
+ out << "rgba32f";
+ break;
+ case ast::TexelFormat::kUndefined:
+ TINT_ICE(Writer, diagnostics_) << "invalid texel format";
+ return false;
+ }
+ out << ") ";
}
if (!EmitTypeAndName(out, type, sem->AddressSpace(), sem->Access(), name)) {
return false;
diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc
index d9afe1d..3bac389 100644
--- a/src/tint/writer/hlsl/generator_impl.cc
+++ b/src/tint/writer/hlsl/generator_impl.cc
@@ -88,6 +88,7 @@
const char* image_format_to_rwtexture_type(ast::TexelFormat image_format) {
switch (image_format) {
+ case ast::TexelFormat::kBgra8Unorm:
case ast::TexelFormat::kRgba8Unorm:
case ast::TexelFormat::kRgba8Snorm:
case ast::TexelFormat::kRgba16Float:
diff --git a/src/tint/writer/spirv/builder.cc b/src/tint/writer/spirv/builder.cc
index c252f8c..df5a2e3 100644
--- a/src/tint/writer/spirv/builder.cc
+++ b/src/tint/writer/spirv/builder.cc
@@ -4079,6 +4079,10 @@
SpvImageFormat Builder::convert_texel_format_to_spv(const ast::TexelFormat format) {
switch (format) {
+ case ast::TexelFormat::kBgra8Unorm:
+ TINT_ICE(Writer, builder_.Diagnostics())
+ << "bgra8unorm should have been polyfilled to rgba8unorm";
+ return SpvImageFormatUnknown;
case ast::TexelFormat::kR32Uint:
return SpvImageFormatR32ui;
case ast::TexelFormat::kR32Sint:
diff --git a/src/tint/writer/spirv/generator_impl.cc b/src/tint/writer/spirv/generator_impl.cc
index 9133703..ef6aa2d 100644
--- a/src/tint/writer/spirv/generator_impl.cc
+++ b/src/tint/writer/spirv/generator_impl.cc
@@ -57,6 +57,7 @@
transform::BuiltinPolyfill::Builtins polyfills;
polyfills.acosh = transform::BuiltinPolyfill::Level::kRangeCheck;
polyfills.atanh = transform::BuiltinPolyfill::Level::kRangeCheck;
+ polyfills.bgra8unorm = true;
polyfills.bitshift_modulo = true;
polyfills.clamp_int = true;
polyfills.count_leading_zeros = true;