Reduce duplication of type format strings.

This CL makes the AST type format name match the WGSL name so the
overloaded operator<< can be used in the WGSL writer. This removes a
bunch of duplication of WGSL type format name strings.

Bug: tint:230
Change-Id: I14aaefd21ced267ceed31f21faba3bd291275f0d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/29402
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair 2020-10-05 19:55:56 +00:00 committed by Commit Bot service account
parent 94b7c66858
commit b5e5b804c3
2 changed files with 7 additions and 108 deletions

View File

@ -46,6 +46,8 @@ std::ostream& operator<<(std::ostream& out, StorageAccess access) {
return out;
}
// Note, these names match the names in the WGSL spec. This behaviour is used
// in the WGSL writer to emit the texture format names.
std::ostream& operator<<(std::ostream& out, ImageFormat format) {
switch (format) {
case ImageFormat::kNone:
@ -106,7 +108,7 @@ std::ostream& operator<<(std::ostream& out, ImageFormat format) {
out << "rgba8unorm";
break;
case ImageFormat::kRgba8UnormSrgb:
out << "rgba8unorm-srgb";
out << "rgba8unorm_srgb";
break;
case ImageFormat::kRgba8Snorm:
out << "rgba8snorm";
@ -121,7 +123,7 @@ std::ostream& operator<<(std::ostream& out, ImageFormat format) {
out << "bgra8unorm";
break;
case ImageFormat::kBgra8UnormSrgb:
out << "rbgra8unorm-srgb";
out << "bgra8unorm_srgb";
break;
case ImageFormat::kRgb10A2Unorm:
out << "rgb10a2unorm";

View File

@ -379,114 +379,11 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) {
bool GeneratorImpl::EmitImageFormat(const ast::type::ImageFormat fmt) {
switch (fmt) {
case ast::type::ImageFormat::kBgra8Unorm:
out_ << "bgra8unorm";
break;
case ast::type::ImageFormat::kBgra8UnormSrgb:
out_ << "bgra8unorm_srgb";
break;
case ast::type::ImageFormat::kR16Float:
out_ << "r16float";
break;
case ast::type::ImageFormat::kR16Sint:
out_ << "r16sint";
break;
case ast::type::ImageFormat::kR16Uint:
out_ << "r16uint";
break;
case ast::type::ImageFormat::kR32Float:
out_ << "r32float";
break;
case ast::type::ImageFormat::kR32Sint:
out_ << "r32sint";
break;
case ast::type::ImageFormat::kR32Uint:
out_ << "r32uint";
break;
case ast::type::ImageFormat::kR8Sint:
out_ << "r8sint";
break;
case ast::type::ImageFormat::kR8Snorm:
out_ << "r8snorm";
break;
case ast::type::ImageFormat::kR8Uint:
out_ << "r8uint";
break;
case ast::type::ImageFormat::kR8Unorm:
out_ << "r8unorm";
break;
case ast::type::ImageFormat::kRg11B10Float:
out_ << "rg11b10float";
break;
case ast::type::ImageFormat::kRg16Float:
out_ << "rg16float";
break;
case ast::type::ImageFormat::kRg16Sint:
out_ << "rg16sint";
break;
case ast::type::ImageFormat::kRg16Uint:
out_ << "rg16uint";
break;
case ast::type::ImageFormat::kRg32Float:
out_ << "rg32float";
break;
case ast::type::ImageFormat::kRg32Sint:
out_ << "rg32sint";
break;
case ast::type::ImageFormat::kRg32Uint:
out_ << "rg32uint";
break;
case ast::type::ImageFormat::kRg8Sint:
out_ << "rg8sint";
break;
case ast::type::ImageFormat::kRg8Snorm:
out_ << "rg8snorm";
break;
case ast::type::ImageFormat::kRg8Uint:
out_ << "rg8uint";
break;
case ast::type::ImageFormat::kRg8Unorm:
out_ << "rg8unorm";
break;
case ast::type::ImageFormat::kRgb10A2Unorm:
out_ << "rgb10a2unorm";
break;
case ast::type::ImageFormat::kRgba16Float:
out_ << "rgba16float";
break;
case ast::type::ImageFormat::kRgba16Sint:
out_ << "rgba16sint";
break;
case ast::type::ImageFormat::kRgba16Uint:
out_ << "rgba16uint";
break;
case ast::type::ImageFormat::kRgba32Float:
out_ << "rgba32float";
break;
case ast::type::ImageFormat::kRgba32Sint:
out_ << "rgba32sint";
break;
case ast::type::ImageFormat::kRgba32Uint:
out_ << "rgba32uint";
break;
case ast::type::ImageFormat::kRgba8Sint:
out_ << "rgba8sint";
break;
case ast::type::ImageFormat::kRgba8Snorm:
out_ << "rgba8snorm";
break;
case ast::type::ImageFormat::kRgba8Uint:
out_ << "rgba8uint";
break;
case ast::type::ImageFormat::kRgba8Unorm:
out_ << "rgba8unorm";
break;
case ast::type::ImageFormat::kRgba8UnormSrgb:
out_ << "rgba8unorm_srgb";
break;
default:
case ast::type::ImageFormat::kNone:
error_ = "unknown image format";
return false;
default:
out_ << fmt;
}
return true;
}