Resolver: Add ast -> sem type resolving

Not currently called (nothing currently attaches ast::Type nodes to the AST), but implements some of the boilerplate that'll be shortly required.

This change also removes a bunch of duplicated enumerators from the sem namespace for their counterpart in the ast namespace.

Bug: tint:724
Change-Id: I0372a9f4eca2f9357ff161e7ec1b67eae1c4c8f6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48603
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton
2021-04-21 13:47:12 +00:00
committed by Commit Bot service account
parent a922e65d72
commit fec63b7aa6
62 changed files with 1405 additions and 1591 deletions

View File

@@ -100,83 +100,83 @@ ast::Builtin EnumConverter::ToBuiltin(SpvBuiltIn b) {
return ast::Builtin::kNone;
}
sem::TextureDimension EnumConverter::ToDim(SpvDim dim, bool arrayed) {
ast::TextureDimension EnumConverter::ToDim(SpvDim dim, bool arrayed) {
if (arrayed) {
switch (dim) {
case SpvDim2D:
return sem::TextureDimension::k2dArray;
return ast::TextureDimension::k2dArray;
case SpvDimCube:
return sem::TextureDimension::kCubeArray;
return ast::TextureDimension::kCubeArray;
default:
break;
}
Fail() << "arrayed dimension must be 1D, 2D, or Cube. Got " << int(dim);
return sem::TextureDimension::kNone;
return ast::TextureDimension::kNone;
}
// Assume non-arrayed
switch (dim) {
case SpvDim1D:
return sem::TextureDimension::k1d;
return ast::TextureDimension::k1d;
case SpvDim2D:
return sem::TextureDimension::k2d;
return ast::TextureDimension::k2d;
case SpvDim3D:
return sem::TextureDimension::k3d;
return ast::TextureDimension::k3d;
case SpvDimCube:
return sem::TextureDimension::kCube;
return ast::TextureDimension::kCube;
default:
break;
}
Fail() << "invalid dimension: " << int(dim);
return sem::TextureDimension::kNone;
return ast::TextureDimension::kNone;
}
sem::ImageFormat EnumConverter::ToImageFormat(SpvImageFormat fmt) {
ast::ImageFormat EnumConverter::ToImageFormat(SpvImageFormat fmt) {
switch (fmt) {
case SpvImageFormatUnknown:
return sem::ImageFormat::kNone;
return ast::ImageFormat::kNone;
// 8 bit channels
case SpvImageFormatRgba8:
return sem::ImageFormat::kRgba8Unorm;
return ast::ImageFormat::kRgba8Unorm;
case SpvImageFormatRgba8Snorm:
return sem::ImageFormat::kRgba8Snorm;
return ast::ImageFormat::kRgba8Snorm;
case SpvImageFormatRgba8ui:
return sem::ImageFormat::kRgba8Uint;
return ast::ImageFormat::kRgba8Uint;
case SpvImageFormatRgba8i:
return sem::ImageFormat::kRgba8Sint;
return ast::ImageFormat::kRgba8Sint;
// 16 bit channels
case SpvImageFormatRgba16ui:
return sem::ImageFormat::kRgba16Uint;
return ast::ImageFormat::kRgba16Uint;
case SpvImageFormatRgba16i:
return sem::ImageFormat::kRgba16Sint;
return ast::ImageFormat::kRgba16Sint;
case SpvImageFormatRgba16f:
return sem::ImageFormat::kRgba16Float;
return ast::ImageFormat::kRgba16Float;
// 32 bit channels
case SpvImageFormatR32ui:
return sem::ImageFormat::kR32Uint;
return ast::ImageFormat::kR32Uint;
case SpvImageFormatR32i:
return sem::ImageFormat::kR32Sint;
return ast::ImageFormat::kR32Sint;
case SpvImageFormatR32f:
return sem::ImageFormat::kR32Float;
return ast::ImageFormat::kR32Float;
case SpvImageFormatRg32ui:
return sem::ImageFormat::kRg32Uint;
return ast::ImageFormat::kRg32Uint;
case SpvImageFormatRg32i:
return sem::ImageFormat::kRg32Sint;
return ast::ImageFormat::kRg32Sint;
case SpvImageFormatRg32f:
return sem::ImageFormat::kRg32Float;
return ast::ImageFormat::kRg32Float;
case SpvImageFormatRgba32ui:
return sem::ImageFormat::kRgba32Uint;
return ast::ImageFormat::kRgba32Uint;
case SpvImageFormatRgba32i:
return sem::ImageFormat::kRgba32Sint;
return ast::ImageFormat::kRgba32Sint;
case SpvImageFormatRgba32f:
return sem::ImageFormat::kRgba32Float;
return ast::ImageFormat::kRgba32Float;
default:
break;
}
Fail() << "invalid image format: " << int(fmt);
return sem::ImageFormat::kNone;
return ast::ImageFormat::kNone;
}
} // namespace spirv

View File

@@ -58,13 +58,13 @@ class EnumConverter {
/// @param dim the SPIR-V Dim value
/// @param arrayed true if the texture is arrayed
/// @returns a Tint AST texture dimension
sem::TextureDimension ToDim(SpvDim dim, bool arrayed);
ast::TextureDimension ToDim(SpvDim dim, bool arrayed);
/// Converts a SPIR-V Image Format to a Tint ImageFormat
/// On failure, logs an error and returns kNone
/// @param fmt the SPIR-V format
/// @returns a Tint AST format
sem::ImageFormat ToImageFormat(SpvImageFormat fmt);
ast::ImageFormat ToImageFormat(SpvImageFormat fmt);
private:
/// Registers a failure and returns a stream for log diagnostics.

View File

@@ -243,7 +243,7 @@ struct DimCase {
SpvDim dim;
bool arrayed;
bool expect_success;
sem::TextureDimension expected;
ast::TextureDimension expected;
};
inline std::ostream& operator<<(std::ostream& out, DimCase dc) {
out << "DimCase{ SpvDim:" << int(dc.dim) << " arrayed?:" << int(dc.arrayed)
@@ -287,37 +287,37 @@ INSTANTIATE_TEST_SUITE_P(
SpvDimTest,
testing::Values(
// Non-arrayed
DimCase{SpvDim1D, false, true, sem::TextureDimension::k1d},
DimCase{SpvDim2D, false, true, sem::TextureDimension::k2d},
DimCase{SpvDim3D, false, true, sem::TextureDimension::k3d},
DimCase{SpvDimCube, false, true, sem::TextureDimension::kCube},
DimCase{SpvDim1D, false, true, ast::TextureDimension::k1d},
DimCase{SpvDim2D, false, true, ast::TextureDimension::k2d},
DimCase{SpvDim3D, false, true, ast::TextureDimension::k3d},
DimCase{SpvDimCube, false, true, ast::TextureDimension::kCube},
// Arrayed
DimCase{SpvDim2D, true, true, sem::TextureDimension::k2dArray},
DimCase{SpvDimCube, true, true, sem::TextureDimension::kCubeArray}));
DimCase{SpvDim2D, true, true, ast::TextureDimension::k2dArray},
DimCase{SpvDimCube, true, true, ast::TextureDimension::kCubeArray}));
INSTANTIATE_TEST_SUITE_P(
EnumConverterBad,
SpvDimTest,
testing::Values(
// Invalid SPIR-V dimensionality.
DimCase{SpvDimMax, false, false, sem::TextureDimension::kNone},
DimCase{SpvDimMax, true, false, sem::TextureDimension::kNone},
DimCase{SpvDimMax, false, false, ast::TextureDimension::kNone},
DimCase{SpvDimMax, true, false, ast::TextureDimension::kNone},
// Vulkan non-arrayed dimensionalities not supported by WGSL.
DimCase{SpvDimRect, false, false, sem::TextureDimension::kNone},
DimCase{SpvDimBuffer, false, false, sem::TextureDimension::kNone},
DimCase{SpvDimSubpassData, false, false, sem::TextureDimension::kNone},
DimCase{SpvDimRect, false, false, ast::TextureDimension::kNone},
DimCase{SpvDimBuffer, false, false, ast::TextureDimension::kNone},
DimCase{SpvDimSubpassData, false, false, ast::TextureDimension::kNone},
// Arrayed dimensionalities not supported by WGSL
DimCase{SpvDim3D, true, false, sem::TextureDimension::kNone},
DimCase{SpvDimRect, true, false, sem::TextureDimension::kNone},
DimCase{SpvDimBuffer, true, false, sem::TextureDimension::kNone},
DimCase{SpvDimSubpassData, true, false, sem::TextureDimension::kNone}));
DimCase{SpvDim3D, true, false, ast::TextureDimension::kNone},
DimCase{SpvDimRect, true, false, ast::TextureDimension::kNone},
DimCase{SpvDimBuffer, true, false, ast::TextureDimension::kNone},
DimCase{SpvDimSubpassData, true, false, ast::TextureDimension::kNone}));
// ImageFormat
struct ImageFormatCase {
SpvImageFormat format;
bool expect_success;
sem::ImageFormat expected;
ast::ImageFormat expected;
};
inline std::ostream& operator<<(std::ostream& out, ImageFormatCase ifc) {
out << "ImageFormatCase{ SpvImageFormat:" << int(ifc.format)
@@ -361,68 +361,68 @@ INSTANTIATE_TEST_SUITE_P(
SpvImageFormatTest,
testing::Values(
// Unknown. This is used for sampled images.
ImageFormatCase{SpvImageFormatUnknown, true, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatUnknown, true, ast::ImageFormat::kNone},
// 8 bit channels
ImageFormatCase{SpvImageFormatRgba8, true,
sem::ImageFormat::kRgba8Unorm},
ast::ImageFormat::kRgba8Unorm},
ImageFormatCase{SpvImageFormatRgba8Snorm, true,
sem::ImageFormat::kRgba8Snorm},
ast::ImageFormat::kRgba8Snorm},
ImageFormatCase{SpvImageFormatRgba8ui, true,
sem::ImageFormat::kRgba8Uint},
ast::ImageFormat::kRgba8Uint},
ImageFormatCase{SpvImageFormatRgba8i, true,
sem::ImageFormat::kRgba8Sint},
ast::ImageFormat::kRgba8Sint},
// 16 bit channels
ImageFormatCase{SpvImageFormatRgba16ui, true,
sem::ImageFormat::kRgba16Uint},
ast::ImageFormat::kRgba16Uint},
ImageFormatCase{SpvImageFormatRgba16i, true,
sem::ImageFormat::kRgba16Sint},
ast::ImageFormat::kRgba16Sint},
ImageFormatCase{SpvImageFormatRgba16f, true,
sem::ImageFormat::kRgba16Float},
ast::ImageFormat::kRgba16Float},
// 32 bit channels
// ... 1 channel
ImageFormatCase{SpvImageFormatR32ui, true, sem::ImageFormat::kR32Uint},
ImageFormatCase{SpvImageFormatR32i, true, sem::ImageFormat::kR32Sint},
ImageFormatCase{SpvImageFormatR32f, true, sem::ImageFormat::kR32Float},
ImageFormatCase{SpvImageFormatR32ui, true, ast::ImageFormat::kR32Uint},
ImageFormatCase{SpvImageFormatR32i, true, ast::ImageFormat::kR32Sint},
ImageFormatCase{SpvImageFormatR32f, true, ast::ImageFormat::kR32Float},
// ... 2 channels
ImageFormatCase{SpvImageFormatRg32ui, true,
sem::ImageFormat::kRg32Uint},
ImageFormatCase{SpvImageFormatRg32i, true, sem::ImageFormat::kRg32Sint},
ast::ImageFormat::kRg32Uint},
ImageFormatCase{SpvImageFormatRg32i, true, ast::ImageFormat::kRg32Sint},
ImageFormatCase{SpvImageFormatRg32f, true,
sem::ImageFormat::kRg32Float},
ast::ImageFormat::kRg32Float},
// ... 4 channels
ImageFormatCase{SpvImageFormatRgba32ui, true,
sem::ImageFormat::kRgba32Uint},
ast::ImageFormat::kRgba32Uint},
ImageFormatCase{SpvImageFormatRgba32i, true,
sem::ImageFormat::kRgba32Sint},
ast::ImageFormat::kRgba32Sint},
ImageFormatCase{SpvImageFormatRgba32f, true,
sem::ImageFormat::kRgba32Float}));
ast::ImageFormat::kRgba32Float}));
INSTANTIATE_TEST_SUITE_P(
EnumConverterBad,
SpvImageFormatTest,
testing::Values(
// Scanning in order from the SPIR-V spec.
ImageFormatCase{SpvImageFormatRg16f, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg16f, false, ast::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR11fG11fB10f, false,
sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR16f, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRgb10A2, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg16, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg8, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR16, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR8, false, sem::ImageFormat::kNone},
ast::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR16f, false, ast::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRgb10A2, false, ast::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg16, false, ast::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg8, false, ast::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR16, false, ast::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR8, false, ast::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRgba16Snorm, false,
sem::ImageFormat::kNone},
ast::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg16Snorm, false,
sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg8Snorm, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg16i, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg8i, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR8i, false, sem::ImageFormat::kNone},
ast::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg8Snorm, false, ast::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg16i, false, ast::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg8i, false, ast::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatR8i, false, ast::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRgb10a2ui, false,
sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg16ui, false, sem::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg8ui, false, sem::ImageFormat::kNone}));
ast::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg16ui, false, ast::ImageFormat::kNone},
ImageFormatCase{SpvImageFormatRg8ui, false, ast::ImageFormat::kNone}));
} // namespace
} // namespace spirv

View File

@@ -4549,9 +4549,9 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
<< inst.PrettyPrint();
}
switch (texture_type->dim()) {
case sem::TextureDimension::k2d:
case sem::TextureDimension::k2dArray:
case sem::TextureDimension::k3d:
case ast::TextureDimension::k2d:
case ast::TextureDimension::k2dArray:
case ast::TextureDimension::k3d:
break;
default:
return Fail() << "ConstOffset is only permitted for 2D, 2D Arrayed, "
@@ -4674,7 +4674,7 @@ bool FunctionEmitter::EmitImageQuery(const spvtools::opt::Instruction& inst) {
}
exprs.push_back(
create<ast::CallExpression>(Source{}, dims_ident, dims_args));
if (sem::IsTextureArray(texture_type->dim())) {
if (ast::IsTextureArray(texture_type->dim())) {
auto* layers_ident = create<ast::IdentifierExpression>(
Source{}, builder_.Symbols().Register("textureNumLayers"));
exprs.push_back(create<ast::CallExpression>(
@@ -4753,10 +4753,10 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess(
if (!texture_type) {
return {};
}
sem::TextureDimension dim = texture_type->dim();
ast::TextureDimension dim = texture_type->dim();
// Number of regular coordinates.
uint32_t num_axes = sem::NumCoordinateAxes(dim);
bool is_arrayed = sem::IsTextureArray(dim);
uint32_t num_axes = ast::NumCoordinateAxes(dim);
bool is_arrayed = ast::IsTextureArray(dim);
if ((num_axes == 0) || (num_axes > 3)) {
Fail() << "unsupported image dimensionality for "
<< texture_type->type_name() << " prompted by "

View File

@@ -1898,8 +1898,8 @@ sem::Pointer* ParserImpl::GetTypeForHandleVar(
sem::Type* ast_store_type = nullptr;
if (usage.IsSampler()) {
ast_store_type = builder_.create<sem::Sampler>(
usage.IsComparisonSampler() ? sem::SamplerKind::kComparisonSampler
: sem::SamplerKind::kSampler);
usage.IsComparisonSampler() ? ast::SamplerKind::kComparisonSampler
: ast::SamplerKind::kSampler);
} else if (usage.IsTexture()) {
const spvtools::opt::analysis::Image* image_type =
type_mgr_->GetType(raw_handle_type->result_id())->AsImage();
@@ -1909,9 +1909,9 @@ sem::Pointer* ParserImpl::GetTypeForHandleVar(
return nullptr;
}
const sem::TextureDimension dim =
const ast::TextureDimension dim =
enum_converter_.ToDim(image_type->dim(), image_type->is_arrayed());
if (dim == sem::TextureDimension::kNone) {
if (dim == ast::TextureDimension::kNone) {
return nullptr;
}
@@ -1942,7 +1942,7 @@ sem::Pointer* ParserImpl::GetTypeForHandleVar(
? ast::AccessControl::kReadOnly
: ast::AccessControl::kWriteOnly;
const auto format = enum_converter_.ToImageFormat(image_type->format());
if (format == sem::ImageFormat::kNone) {
if (format == ast::ImageFormat::kNone) {
return nullptr;
}
auto* subtype = sem::StorageTexture::SubtypeFor(format, builder_.Types());
@@ -1964,47 +1964,47 @@ sem::Pointer* ParserImpl::GetTypeForHandleVar(
return result;
}
sem::Type* ParserImpl::GetComponentTypeForFormat(sem::ImageFormat format) {
sem::Type* ParserImpl::GetComponentTypeForFormat(ast::ImageFormat format) {
switch (format) {
case sem::ImageFormat::kR8Uint:
case sem::ImageFormat::kR16Uint:
case sem::ImageFormat::kRg8Uint:
case sem::ImageFormat::kR32Uint:
case sem::ImageFormat::kRg16Uint:
case sem::ImageFormat::kRgba8Uint:
case sem::ImageFormat::kRg32Uint:
case sem::ImageFormat::kRgba16Uint:
case sem::ImageFormat::kRgba32Uint:
case ast::ImageFormat::kR8Uint:
case ast::ImageFormat::kR16Uint:
case ast::ImageFormat::kRg8Uint:
case ast::ImageFormat::kR32Uint:
case ast::ImageFormat::kRg16Uint:
case ast::ImageFormat::kRgba8Uint:
case ast::ImageFormat::kRg32Uint:
case ast::ImageFormat::kRgba16Uint:
case ast::ImageFormat::kRgba32Uint:
return builder_.create<sem::U32>();
case sem::ImageFormat::kR8Sint:
case sem::ImageFormat::kR16Sint:
case sem::ImageFormat::kRg8Sint:
case sem::ImageFormat::kR32Sint:
case sem::ImageFormat::kRg16Sint:
case sem::ImageFormat::kRgba8Sint:
case sem::ImageFormat::kRg32Sint:
case sem::ImageFormat::kRgba16Sint:
case sem::ImageFormat::kRgba32Sint:
case ast::ImageFormat::kR8Sint:
case ast::ImageFormat::kR16Sint:
case ast::ImageFormat::kRg8Sint:
case ast::ImageFormat::kR32Sint:
case ast::ImageFormat::kRg16Sint:
case ast::ImageFormat::kRgba8Sint:
case ast::ImageFormat::kRg32Sint:
case ast::ImageFormat::kRgba16Sint:
case ast::ImageFormat::kRgba32Sint:
return builder_.create<sem::I32>();
case sem::ImageFormat::kR8Unorm:
case sem::ImageFormat::kRg8Unorm:
case sem::ImageFormat::kRgba8Unorm:
case sem::ImageFormat::kRgba8UnormSrgb:
case sem::ImageFormat::kBgra8Unorm:
case sem::ImageFormat::kBgra8UnormSrgb:
case sem::ImageFormat::kRgb10A2Unorm:
case sem::ImageFormat::kR8Snorm:
case sem::ImageFormat::kRg8Snorm:
case sem::ImageFormat::kRgba8Snorm:
case sem::ImageFormat::kR16Float:
case sem::ImageFormat::kR32Float:
case sem::ImageFormat::kRg16Float:
case sem::ImageFormat::kRg11B10Float:
case sem::ImageFormat::kRg32Float:
case sem::ImageFormat::kRgba16Float:
case sem::ImageFormat::kRgba32Float:
case ast::ImageFormat::kR8Unorm:
case ast::ImageFormat::kRg8Unorm:
case ast::ImageFormat::kRgba8Unorm:
case ast::ImageFormat::kRgba8UnormSrgb:
case ast::ImageFormat::kBgra8Unorm:
case ast::ImageFormat::kBgra8UnormSrgb:
case ast::ImageFormat::kRgb10A2Unorm:
case ast::ImageFormat::kR8Snorm:
case ast::ImageFormat::kRg8Snorm:
case ast::ImageFormat::kRgba8Snorm:
case ast::ImageFormat::kR16Float:
case ast::ImageFormat::kR32Float:
case ast::ImageFormat::kRg16Float:
case ast::ImageFormat::kRg11B10Float:
case ast::ImageFormat::kRg32Float:
case ast::ImageFormat::kRgba16Float:
case ast::ImageFormat::kRgba32Float:
return builder_.create<sem::F32>();
default:
break;
@@ -2013,54 +2013,54 @@ sem::Type* ParserImpl::GetComponentTypeForFormat(sem::ImageFormat format) {
return nullptr;
}
sem::Type* ParserImpl::GetTexelTypeForFormat(sem::ImageFormat format) {
sem::Type* ParserImpl::GetTexelTypeForFormat(ast::ImageFormat format) {
auto* component_type = GetComponentTypeForFormat(format);
if (!component_type) {
return nullptr;
}
switch (format) {
case sem::ImageFormat::kR16Float:
case sem::ImageFormat::kR16Sint:
case sem::ImageFormat::kR16Uint:
case sem::ImageFormat::kR32Float:
case sem::ImageFormat::kR32Sint:
case sem::ImageFormat::kR32Uint:
case sem::ImageFormat::kR8Sint:
case sem::ImageFormat::kR8Snorm:
case sem::ImageFormat::kR8Uint:
case sem::ImageFormat::kR8Unorm:
case ast::ImageFormat::kR16Float:
case ast::ImageFormat::kR16Sint:
case ast::ImageFormat::kR16Uint:
case ast::ImageFormat::kR32Float:
case ast::ImageFormat::kR32Sint:
case ast::ImageFormat::kR32Uint:
case ast::ImageFormat::kR8Sint:
case ast::ImageFormat::kR8Snorm:
case ast::ImageFormat::kR8Uint:
case ast::ImageFormat::kR8Unorm:
// One channel
return component_type;
case sem::ImageFormat::kRg11B10Float:
case sem::ImageFormat::kRg16Float:
case sem::ImageFormat::kRg16Sint:
case sem::ImageFormat::kRg16Uint:
case sem::ImageFormat::kRg32Float:
case sem::ImageFormat::kRg32Sint:
case sem::ImageFormat::kRg32Uint:
case sem::ImageFormat::kRg8Sint:
case sem::ImageFormat::kRg8Snorm:
case sem::ImageFormat::kRg8Uint:
case sem::ImageFormat::kRg8Unorm:
case ast::ImageFormat::kRg11B10Float:
case ast::ImageFormat::kRg16Float:
case ast::ImageFormat::kRg16Sint:
case ast::ImageFormat::kRg16Uint:
case ast::ImageFormat::kRg32Float:
case ast::ImageFormat::kRg32Sint:
case ast::ImageFormat::kRg32Uint:
case ast::ImageFormat::kRg8Sint:
case ast::ImageFormat::kRg8Snorm:
case ast::ImageFormat::kRg8Uint:
case ast::ImageFormat::kRg8Unorm:
// Two channels
return builder_.create<sem::Vector>(component_type, 2);
case sem::ImageFormat::kBgra8Unorm:
case sem::ImageFormat::kBgra8UnormSrgb:
case sem::ImageFormat::kRgb10A2Unorm:
case sem::ImageFormat::kRgba16Float:
case sem::ImageFormat::kRgba16Sint:
case sem::ImageFormat::kRgba16Uint:
case sem::ImageFormat::kRgba32Float:
case sem::ImageFormat::kRgba32Sint:
case sem::ImageFormat::kRgba32Uint:
case sem::ImageFormat::kRgba8Sint:
case sem::ImageFormat::kRgba8Snorm:
case sem::ImageFormat::kRgba8Uint:
case sem::ImageFormat::kRgba8Unorm:
case sem::ImageFormat::kRgba8UnormSrgb:
case ast::ImageFormat::kBgra8Unorm:
case ast::ImageFormat::kBgra8UnormSrgb:
case ast::ImageFormat::kRgb10A2Unorm:
case ast::ImageFormat::kRgba16Float:
case ast::ImageFormat::kRgba16Sint:
case ast::ImageFormat::kRgba16Uint:
case ast::ImageFormat::kRgba32Float:
case ast::ImageFormat::kRgba32Sint:
case ast::ImageFormat::kRgba32Uint:
case ast::ImageFormat::kRgba8Sint:
case ast::ImageFormat::kRgba8Snorm:
case ast::ImageFormat::kRgba8Uint:
case ast::ImageFormat::kRgba8Unorm:
case ast::ImageFormat::kRgba8UnormSrgb:
// Four channels
return builder_.create<sem::Vector>(component_type, 4);

View File

@@ -475,12 +475,12 @@ class ParserImpl : Reader {
/// format.
/// @param format image texel format
/// @returns the component type, one of f32, i32, u32
sem::Type* GetComponentTypeForFormat(sem::ImageFormat format);
sem::Type* GetComponentTypeForFormat(ast::ImageFormat format);
/// Returns texel type corresponding to the given image format.
/// @param format image texel format
/// @returns the texel format
sem::Type* GetTexelTypeForFormat(sem::ImageFormat format);
sem::Type* GetTexelTypeForFormat(ast::ImageFormat format);
/// Returns the SPIR-V instruction with the given ID, or nullptr.
/// @param id the SPIR-V result ID

View File

@@ -563,10 +563,10 @@ Maybe<sem::Type*> ParserImpl::texture_sampler_types() {
// | SAMPLER_COMPARISON
Maybe<sem::Type*> ParserImpl::sampler_type() {
if (match(Token::Type::kSampler))
return builder_.create<sem::Sampler>(sem::SamplerKind::kSampler);
return builder_.create<sem::Sampler>(ast::SamplerKind::kSampler);
if (match(Token::Type::kComparisonSampler))
return builder_.create<sem::Sampler>(sem::SamplerKind::kComparisonSampler);
return builder_.create<sem::Sampler>(ast::SamplerKind::kComparisonSampler);
return Failure::kNoMatch;
}
@@ -578,33 +578,33 @@ Maybe<sem::Type*> ParserImpl::sampler_type() {
// | TEXTURE_SAMPLED_3D
// | TEXTURE_SAMPLED_CUBE
// | TEXTURE_SAMPLED_CUBE_ARRAY
Maybe<sem::TextureDimension> ParserImpl::sampled_texture_type() {
Maybe<ast::TextureDimension> ParserImpl::sampled_texture_type() {
if (match(Token::Type::kTextureSampled1d))
return sem::TextureDimension::k1d;
return ast::TextureDimension::k1d;
if (match(Token::Type::kTextureSampled2d))
return sem::TextureDimension::k2d;
return ast::TextureDimension::k2d;
if (match(Token::Type::kTextureSampled2dArray))
return sem::TextureDimension::k2dArray;
return ast::TextureDimension::k2dArray;
if (match(Token::Type::kTextureSampled3d))
return sem::TextureDimension::k3d;
return ast::TextureDimension::k3d;
if (match(Token::Type::kTextureSampledCube))
return sem::TextureDimension::kCube;
return ast::TextureDimension::kCube;
if (match(Token::Type::kTextureSampledCubeArray))
return sem::TextureDimension::kCubeArray;
return ast::TextureDimension::kCubeArray;
return Failure::kNoMatch;
}
// multisampled_texture_type
// : TEXTURE_MULTISAMPLED_2D
Maybe<sem::TextureDimension> ParserImpl::multisampled_texture_type() {
Maybe<ast::TextureDimension> ParserImpl::multisampled_texture_type() {
if (match(Token::Type::kTextureMultisampled2d))
return sem::TextureDimension::k2d;
return ast::TextureDimension::k2d;
return Failure::kNoMatch;
}
@@ -614,15 +614,15 @@ Maybe<sem::TextureDimension> ParserImpl::multisampled_texture_type() {
// | TEXTURE_STORAGE_2D
// | TEXTURE_STORAGE_2D_ARRAY
// | TEXTURE_STORAGE_3D
Maybe<sem::TextureDimension> ParserImpl::storage_texture_type() {
Maybe<ast::TextureDimension> ParserImpl::storage_texture_type() {
if (match(Token::Type::kTextureStorage1d))
return sem::TextureDimension::k1d;
return ast::TextureDimension::k1d;
if (match(Token::Type::kTextureStorage2d))
return sem::TextureDimension::k2d;
return ast::TextureDimension::k2d;
if (match(Token::Type::kTextureStorage2dArray))
return sem::TextureDimension::k2dArray;
return ast::TextureDimension::k2dArray;
if (match(Token::Type::kTextureStorage3d))
return sem::TextureDimension::k3d;
return ast::TextureDimension::k3d;
return Failure::kNoMatch;
}
@@ -634,17 +634,17 @@ Maybe<sem::TextureDimension> ParserImpl::storage_texture_type() {
// | TEXTURE_DEPTH_CUBE_ARRAY
Maybe<sem::Type*> ParserImpl::depth_texture_type() {
if (match(Token::Type::kTextureDepth2d))
return builder_.create<sem::DepthTexture>(sem::TextureDimension::k2d);
return builder_.create<sem::DepthTexture>(ast::TextureDimension::k2d);
if (match(Token::Type::kTextureDepth2dArray))
return builder_.create<sem::DepthTexture>(sem::TextureDimension::k2dArray);
return builder_.create<sem::DepthTexture>(ast::TextureDimension::k2dArray);
if (match(Token::Type::kTextureDepthCube))
return builder_.create<sem::DepthTexture>(sem::TextureDimension::kCube);
return builder_.create<sem::DepthTexture>(ast::TextureDimension::kCube);
if (match(Token::Type::kTextureDepthCubeArray))
return builder_.create<sem::DepthTexture>(
sem::TextureDimension::kCubeArray);
ast::TextureDimension::kCubeArray);
return Failure::kNoMatch;
}
@@ -685,112 +685,112 @@ Maybe<sem::Type*> ParserImpl::depth_texture_type() {
// | RGBA32UINT
// | RGBA32SINT
// | RGBA32FLOAT
Expect<sem::ImageFormat> ParserImpl::expect_image_storage_type(
Expect<ast::ImageFormat> ParserImpl::expect_image_storage_type(
const std::string& use) {
if (match(Token::Type::kFormatR8Unorm))
return sem::ImageFormat::kR8Unorm;
return ast::ImageFormat::kR8Unorm;
if (match(Token::Type::kFormatR8Snorm))
return sem::ImageFormat::kR8Snorm;
return ast::ImageFormat::kR8Snorm;
if (match(Token::Type::kFormatR8Uint))
return sem::ImageFormat::kR8Uint;
return ast::ImageFormat::kR8Uint;
if (match(Token::Type::kFormatR8Sint))
return sem::ImageFormat::kR8Sint;
return ast::ImageFormat::kR8Sint;
if (match(Token::Type::kFormatR16Uint))
return sem::ImageFormat::kR16Uint;
return ast::ImageFormat::kR16Uint;
if (match(Token::Type::kFormatR16Sint))
return sem::ImageFormat::kR16Sint;
return ast::ImageFormat::kR16Sint;
if (match(Token::Type::kFormatR16Float))
return sem::ImageFormat::kR16Float;
return ast::ImageFormat::kR16Float;
if (match(Token::Type::kFormatRg8Unorm))
return sem::ImageFormat::kRg8Unorm;
return ast::ImageFormat::kRg8Unorm;
if (match(Token::Type::kFormatRg8Snorm))
return sem::ImageFormat::kRg8Snorm;
return ast::ImageFormat::kRg8Snorm;
if (match(Token::Type::kFormatRg8Uint))
return sem::ImageFormat::kRg8Uint;
return ast::ImageFormat::kRg8Uint;
if (match(Token::Type::kFormatRg8Sint))
return sem::ImageFormat::kRg8Sint;
return ast::ImageFormat::kRg8Sint;
if (match(Token::Type::kFormatR32Uint))
return sem::ImageFormat::kR32Uint;
return ast::ImageFormat::kR32Uint;
if (match(Token::Type::kFormatR32Sint))
return sem::ImageFormat::kR32Sint;
return ast::ImageFormat::kR32Sint;
if (match(Token::Type::kFormatR32Float))
return sem::ImageFormat::kR32Float;
return ast::ImageFormat::kR32Float;
if (match(Token::Type::kFormatRg16Uint))
return sem::ImageFormat::kRg16Uint;
return ast::ImageFormat::kRg16Uint;
if (match(Token::Type::kFormatRg16Sint))
return sem::ImageFormat::kRg16Sint;
return ast::ImageFormat::kRg16Sint;
if (match(Token::Type::kFormatRg16Float))
return sem::ImageFormat::kRg16Float;
return ast::ImageFormat::kRg16Float;
if (match(Token::Type::kFormatRgba8Unorm))
return sem::ImageFormat::kRgba8Unorm;
return ast::ImageFormat::kRgba8Unorm;
if (match(Token::Type::kFormatRgba8UnormSrgb))
return sem::ImageFormat::kRgba8UnormSrgb;
return ast::ImageFormat::kRgba8UnormSrgb;
if (match(Token::Type::kFormatRgba8Snorm))
return sem::ImageFormat::kRgba8Snorm;
return ast::ImageFormat::kRgba8Snorm;
if (match(Token::Type::kFormatRgba8Uint))
return sem::ImageFormat::kRgba8Uint;
return ast::ImageFormat::kRgba8Uint;
if (match(Token::Type::kFormatRgba8Sint))
return sem::ImageFormat::kRgba8Sint;
return ast::ImageFormat::kRgba8Sint;
if (match(Token::Type::kFormatBgra8Unorm))
return sem::ImageFormat::kBgra8Unorm;
return ast::ImageFormat::kBgra8Unorm;
if (match(Token::Type::kFormatBgra8UnormSrgb))
return sem::ImageFormat::kBgra8UnormSrgb;
return ast::ImageFormat::kBgra8UnormSrgb;
if (match(Token::Type::kFormatRgb10A2Unorm))
return sem::ImageFormat::kRgb10A2Unorm;
return ast::ImageFormat::kRgb10A2Unorm;
if (match(Token::Type::kFormatRg11B10Float))
return sem::ImageFormat::kRg11B10Float;
return ast::ImageFormat::kRg11B10Float;
if (match(Token::Type::kFormatRg32Uint))
return sem::ImageFormat::kRg32Uint;
return ast::ImageFormat::kRg32Uint;
if (match(Token::Type::kFormatRg32Sint))
return sem::ImageFormat::kRg32Sint;
return ast::ImageFormat::kRg32Sint;
if (match(Token::Type::kFormatRg32Float))
return sem::ImageFormat::kRg32Float;
return ast::ImageFormat::kRg32Float;
if (match(Token::Type::kFormatRgba16Uint))
return sem::ImageFormat::kRgba16Uint;
return ast::ImageFormat::kRgba16Uint;
if (match(Token::Type::kFormatRgba16Sint))
return sem::ImageFormat::kRgba16Sint;
return ast::ImageFormat::kRgba16Sint;
if (match(Token::Type::kFormatRgba16Float))
return sem::ImageFormat::kRgba16Float;
return ast::ImageFormat::kRgba16Float;
if (match(Token::Type::kFormatRgba32Uint))
return sem::ImageFormat::kRgba32Uint;
return ast::ImageFormat::kRgba32Uint;
if (match(Token::Type::kFormatRgba32Sint))
return sem::ImageFormat::kRgba32Sint;
return ast::ImageFormat::kRgba32Sint;
if (match(Token::Type::kFormatRgba32Float))
return sem::ImageFormat::kRgba32Float;
return ast::ImageFormat::kRgba32Float;
return add_error(peek().source(), "invalid format", use);
}

View File

@@ -403,21 +403,21 @@ class ParserImpl {
/// Parses a `multisampled_texture_type` grammar element
/// @returns returns the multisample texture dimension or kNone if none
/// matched.
Maybe<sem::TextureDimension> multisampled_texture_type();
Maybe<ast::TextureDimension> multisampled_texture_type();
/// Parses a `sampled_texture_type` grammar element
/// @returns returns the sample texture dimension or kNone if none matched.
Maybe<sem::TextureDimension> sampled_texture_type();
Maybe<ast::TextureDimension> sampled_texture_type();
/// Parses a `storage_texture_type` grammar element
/// @returns returns the storage texture dimension.
/// Returns kNone if none matched.
Maybe<sem::TextureDimension> storage_texture_type();
Maybe<ast::TextureDimension> storage_texture_type();
/// Parses a `depth_texture_type` grammar element
/// @returns the parsed Type or nullptr if none matched.
Maybe<sem::Type*> depth_texture_type();
/// Parses a `image_storage_type` grammar element
/// @param use a description of what was being parsed if an error was raised
/// @returns returns the image format or kNone if none matched.
Expect<sem::ImageFormat> expect_image_storage_type(const std::string& use);
Expect<ast::ImageFormat> expect_image_storage_type(const std::string& use);
/// Parses a `function_type_decl` grammar element
/// @returns the parsed type or nullptr otherwise
Maybe<sem::Type*> function_type_decl();

View File

@@ -36,7 +36,7 @@ TEST_F(ParserImplTest, DepthTextureType_2d) {
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::DepthTexture>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k2d);
EXPECT_EQ(t->As<sem::Texture>()->dim(), ast::TextureDimension::k2d);
EXPECT_FALSE(p->has_error());
}
@@ -48,7 +48,7 @@ TEST_F(ParserImplTest, DepthTextureType_2dArray) {
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::DepthTexture>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k2dArray);
EXPECT_EQ(t->As<sem::Texture>()->dim(), ast::TextureDimension::k2dArray);
EXPECT_FALSE(p->has_error());
}
@@ -60,7 +60,7 @@ TEST_F(ParserImplTest, DepthTextureType_Cube) {
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::DepthTexture>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::kCube);
EXPECT_EQ(t->As<sem::Texture>()->dim(), ast::TextureDimension::kCube);
EXPECT_FALSE(p->has_error());
}
@@ -72,7 +72,7 @@ TEST_F(ParserImplTest, DepthTextureType_CubeArray) {
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::DepthTexture>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::kCubeArray);
EXPECT_EQ(t->As<sem::Texture>()->dim(), ast::TextureDimension::kCubeArray);
EXPECT_FALSE(p->has_error());
}

View File

@@ -31,7 +31,7 @@ TEST_F(ParserImplTest, ImageStorageType_R8Unorm) {
auto p = parser("r8unorm");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kR8Unorm);
EXPECT_EQ(t.value, ast::ImageFormat::kR8Unorm);
EXPECT_FALSE(p->has_error());
}
@@ -39,7 +39,7 @@ TEST_F(ParserImplTest, ImageStorageType_R8Snorm) {
auto p = parser("r8snorm");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kR8Snorm);
EXPECT_EQ(t.value, ast::ImageFormat::kR8Snorm);
EXPECT_FALSE(p->has_error());
}
@@ -47,7 +47,7 @@ TEST_F(ParserImplTest, ImageStorageType_R8Uint) {
auto p = parser("r8uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kR8Uint);
EXPECT_EQ(t.value, ast::ImageFormat::kR8Uint);
EXPECT_FALSE(p->has_error());
}
@@ -55,7 +55,7 @@ TEST_F(ParserImplTest, ImageStorageType_R8Sint) {
auto p = parser("r8sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kR8Sint);
EXPECT_EQ(t.value, ast::ImageFormat::kR8Sint);
EXPECT_FALSE(p->has_error());
}
@@ -63,7 +63,7 @@ TEST_F(ParserImplTest, ImageStorageType_R16Uint) {
auto p = parser("r16uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kR16Uint);
EXPECT_EQ(t.value, ast::ImageFormat::kR16Uint);
EXPECT_FALSE(p->has_error());
}
@@ -71,7 +71,7 @@ TEST_F(ParserImplTest, ImageStorageType_R16Sint) {
auto p = parser("r16sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kR16Sint);
EXPECT_EQ(t.value, ast::ImageFormat::kR16Sint);
EXPECT_FALSE(p->has_error());
}
@@ -79,7 +79,7 @@ TEST_F(ParserImplTest, ImageStorageType_R16Float) {
auto p = parser("r16float");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kR16Float);
EXPECT_EQ(t.value, ast::ImageFormat::kR16Float);
EXPECT_FALSE(p->has_error());
}
@@ -87,7 +87,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg8Unorm) {
auto p = parser("rg8unorm");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRg8Unorm);
EXPECT_EQ(t.value, ast::ImageFormat::kRg8Unorm);
EXPECT_FALSE(p->has_error());
}
@@ -95,7 +95,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg8Snorm) {
auto p = parser("rg8snorm");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRg8Snorm);
EXPECT_EQ(t.value, ast::ImageFormat::kRg8Snorm);
EXPECT_FALSE(p->has_error());
}
@@ -103,7 +103,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg8Uint) {
auto p = parser("rg8uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRg8Uint);
EXPECT_EQ(t.value, ast::ImageFormat::kRg8Uint);
EXPECT_FALSE(p->has_error());
}
@@ -111,7 +111,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg8Sint) {
auto p = parser("rg8sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRg8Sint);
EXPECT_EQ(t.value, ast::ImageFormat::kRg8Sint);
EXPECT_FALSE(p->has_error());
}
@@ -119,7 +119,7 @@ TEST_F(ParserImplTest, ImageStorageType_R32Uint) {
auto p = parser("r32uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kR32Uint);
EXPECT_EQ(t.value, ast::ImageFormat::kR32Uint);
EXPECT_FALSE(p->has_error());
}
@@ -127,7 +127,7 @@ TEST_F(ParserImplTest, ImageStorageType_R32Sint) {
auto p = parser("r32sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kR32Sint);
EXPECT_EQ(t.value, ast::ImageFormat::kR32Sint);
EXPECT_FALSE(p->has_error());
}
@@ -135,7 +135,7 @@ TEST_F(ParserImplTest, ImageStorageType_R32Float) {
auto p = parser("r32float");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kR32Float);
EXPECT_EQ(t.value, ast::ImageFormat::kR32Float);
EXPECT_FALSE(p->has_error());
}
@@ -143,7 +143,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg16Uint) {
auto p = parser("rg16uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRg16Uint);
EXPECT_EQ(t.value, ast::ImageFormat::kRg16Uint);
EXPECT_FALSE(p->has_error());
}
@@ -151,7 +151,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg16Sint) {
auto p = parser("rg16sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRg16Sint);
EXPECT_EQ(t.value, ast::ImageFormat::kRg16Sint);
EXPECT_FALSE(p->has_error());
}
@@ -159,7 +159,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg16Float) {
auto p = parser("rg16float");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRg16Float);
EXPECT_EQ(t.value, ast::ImageFormat::kRg16Float);
EXPECT_FALSE(p->has_error());
}
@@ -167,7 +167,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba8Unorm) {
auto p = parser("rgba8unorm");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba8Unorm);
EXPECT_EQ(t.value, ast::ImageFormat::kRgba8Unorm);
EXPECT_FALSE(p->has_error());
}
@@ -175,7 +175,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba8UnormSrgb) {
auto p = parser("rgba8unorm_srgb");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba8UnormSrgb);
EXPECT_EQ(t.value, ast::ImageFormat::kRgba8UnormSrgb);
EXPECT_FALSE(p->has_error());
}
@@ -183,7 +183,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba8Snorm) {
auto p = parser("rgba8snorm");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba8Snorm);
EXPECT_EQ(t.value, ast::ImageFormat::kRgba8Snorm);
EXPECT_FALSE(p->has_error());
}
@@ -191,7 +191,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba8Uint) {
auto p = parser("rgba8uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba8Uint);
EXPECT_EQ(t.value, ast::ImageFormat::kRgba8Uint);
EXPECT_FALSE(p->has_error());
}
@@ -199,7 +199,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba8Sint) {
auto p = parser("rgba8sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba8Sint);
EXPECT_EQ(t.value, ast::ImageFormat::kRgba8Sint);
EXPECT_FALSE(p->has_error());
}
@@ -207,7 +207,7 @@ TEST_F(ParserImplTest, ImageStorageType_Bgra8Unorm) {
auto p = parser("bgra8unorm");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kBgra8Unorm);
EXPECT_EQ(t.value, ast::ImageFormat::kBgra8Unorm);
EXPECT_FALSE(p->has_error());
}
@@ -215,7 +215,7 @@ TEST_F(ParserImplTest, ImageStorageType_Bgra8UnormSrgb) {
auto p = parser("bgra8unorm_srgb");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kBgra8UnormSrgb);
EXPECT_EQ(t.value, ast::ImageFormat::kBgra8UnormSrgb);
EXPECT_FALSE(p->has_error());
}
@@ -223,7 +223,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgb10A2Unorm) {
auto p = parser("rgb10a2unorm");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRgb10A2Unorm);
EXPECT_EQ(t.value, ast::ImageFormat::kRgb10A2Unorm);
EXPECT_FALSE(p->has_error());
}
@@ -231,7 +231,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg11B10Float) {
auto p = parser("rg11b10float");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRg11B10Float);
EXPECT_EQ(t.value, ast::ImageFormat::kRg11B10Float);
EXPECT_FALSE(p->has_error());
}
@@ -239,7 +239,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg32Uint) {
auto p = parser("rg32uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRg32Uint);
EXPECT_EQ(t.value, ast::ImageFormat::kRg32Uint);
EXPECT_FALSE(p->has_error());
}
@@ -247,7 +247,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg32Sint) {
auto p = parser("rg32sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRg32Sint);
EXPECT_EQ(t.value, ast::ImageFormat::kRg32Sint);
EXPECT_FALSE(p->has_error());
}
@@ -255,7 +255,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rg32Float) {
auto p = parser("rg32float");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRg32Float);
EXPECT_EQ(t.value, ast::ImageFormat::kRg32Float);
EXPECT_FALSE(p->has_error());
}
@@ -263,7 +263,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba16Uint) {
auto p = parser("rgba16uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba16Uint);
EXPECT_EQ(t.value, ast::ImageFormat::kRgba16Uint);
EXPECT_FALSE(p->has_error());
}
@@ -271,7 +271,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba16Sint) {
auto p = parser("rgba16sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba16Sint);
EXPECT_EQ(t.value, ast::ImageFormat::kRgba16Sint);
EXPECT_FALSE(p->has_error());
}
@@ -279,7 +279,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba16Float) {
auto p = parser("rgba16float");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba16Float);
EXPECT_EQ(t.value, ast::ImageFormat::kRgba16Float);
EXPECT_FALSE(p->has_error());
}
@@ -287,7 +287,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba32Uint) {
auto p = parser("rgba32uint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba32Uint);
EXPECT_EQ(t.value, ast::ImageFormat::kRgba32Uint);
EXPECT_FALSE(p->has_error());
}
@@ -295,7 +295,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba32Sint) {
auto p = parser("rgba32sint");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba32Sint);
EXPECT_EQ(t.value, ast::ImageFormat::kRgba32Sint);
EXPECT_FALSE(p->has_error());
}
@@ -303,7 +303,7 @@ TEST_F(ParserImplTest, ImageStorageType_Rgba32Float) {
auto p = parser("rgba32float");
auto t = p->expect_image_storage_type("test");
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::ImageFormat::kRgba32Float);
EXPECT_EQ(t.value, ast::ImageFormat::kRgba32Float);
EXPECT_FALSE(p->has_error());
}

View File

@@ -32,7 +32,7 @@ TEST_F(ParserImplTest, SampledTextureType_1d) {
auto t = p->sampled_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::TextureDimension::k1d);
EXPECT_EQ(t.value, ast::TextureDimension::k1d);
EXPECT_FALSE(p->has_error());
}
@@ -41,7 +41,7 @@ TEST_F(ParserImplTest, SampledTextureType_2d) {
auto t = p->sampled_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::TextureDimension::k2d);
EXPECT_EQ(t.value, ast::TextureDimension::k2d);
EXPECT_FALSE(p->has_error());
}
@@ -50,7 +50,7 @@ TEST_F(ParserImplTest, SampledTextureType_2dArray) {
auto t = p->sampled_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::TextureDimension::k2dArray);
EXPECT_EQ(t.value, ast::TextureDimension::k2dArray);
EXPECT_FALSE(p->has_error());
}
@@ -59,7 +59,7 @@ TEST_F(ParserImplTest, SampledTextureType_3d) {
auto t = p->sampled_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::TextureDimension::k3d);
EXPECT_EQ(t.value, ast::TextureDimension::k3d);
EXPECT_FALSE(p->has_error());
}
@@ -68,7 +68,7 @@ TEST_F(ParserImplTest, SampledTextureType_Cube) {
auto t = p->sampled_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::TextureDimension::kCube);
EXPECT_EQ(t.value, ast::TextureDimension::kCube);
EXPECT_FALSE(p->has_error());
}
@@ -77,7 +77,7 @@ TEST_F(ParserImplTest, SampledTextureType_kCubeArray) {
auto t = p->sampled_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::TextureDimension::kCubeArray);
EXPECT_EQ(t.value, ast::TextureDimension::kCubeArray);
EXPECT_FALSE(p->has_error());
}

View File

@@ -32,7 +32,7 @@ TEST_F(ParserImplTest, StorageTextureType_1d) {
auto t = p->storage_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::TextureDimension::k1d);
EXPECT_EQ(t.value, ast::TextureDimension::k1d);
EXPECT_FALSE(p->has_error());
}
@@ -41,7 +41,7 @@ TEST_F(ParserImplTest, StorageTextureType_2d) {
auto t = p->storage_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::TextureDimension::k2d);
EXPECT_EQ(t.value, ast::TextureDimension::k2d);
EXPECT_FALSE(p->has_error());
}
@@ -50,7 +50,7 @@ TEST_F(ParserImplTest, StorageTextureType_2dArray) {
auto t = p->storage_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::TextureDimension::k2dArray);
EXPECT_EQ(t.value, ast::TextureDimension::k2dArray);
EXPECT_FALSE(p->has_error());
}
@@ -59,7 +59,7 @@ TEST_F(ParserImplTest, StorageTextureType_3d) {
auto t = p->storage_texture_type();
EXPECT_TRUE(t.matched);
EXPECT_FALSE(t.errored);
EXPECT_EQ(t.value, sem::TextureDimension::k3d);
EXPECT_EQ(t.value, ast::TextureDimension::k3d);
EXPECT_FALSE(p->has_error());
}

View File

@@ -62,7 +62,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_DepthTexture) {
ASSERT_NE(t.value, nullptr);
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::DepthTexture>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k2d);
EXPECT_EQ(t->As<sem::Texture>()->dim(), ast::TextureDimension::k2d);
}
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) {
@@ -75,7 +75,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) {
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::SampledTexture>());
ASSERT_TRUE(t->As<sem::SampledTexture>()->type()->Is<sem::F32>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k1d);
EXPECT_EQ(t->As<sem::Texture>()->dim(), ast::TextureDimension::k1d);
}
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) {
@@ -88,7 +88,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) {
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::SampledTexture>());
ASSERT_TRUE(t->As<sem::SampledTexture>()->type()->Is<sem::I32>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k2d);
EXPECT_EQ(t->As<sem::Texture>()->dim(), ast::TextureDimension::k2d);
}
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) {
@@ -101,7 +101,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) {
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::SampledTexture>());
ASSERT_TRUE(t->As<sem::SampledTexture>()->type()->Is<sem::U32>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k3d);
EXPECT_EQ(t->As<sem::Texture>()->dim(), ast::TextureDimension::k3d);
}
TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_Invalid) {
@@ -154,7 +154,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_I32) {
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::MultisampledTexture>());
ASSERT_TRUE(t->As<sem::MultisampledTexture>()->type()->Is<sem::I32>());
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k2d);
EXPECT_EQ(t->As<sem::Texture>()->dim(), ast::TextureDimension::k2d);
}
TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_Invalid) {
@@ -208,8 +208,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dR8Unorm) {
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::StorageTexture>());
EXPECT_EQ(t->As<sem::StorageTexture>()->image_format(),
sem::ImageFormat::kR8Unorm);
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k1d);
ast::ImageFormat::kR8Unorm);
EXPECT_EQ(t->As<sem::Texture>()->dim(), ast::TextureDimension::k1d);
}
TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) {
@@ -223,8 +223,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) {
ASSERT_TRUE(t->Is<sem::Texture>());
ASSERT_TRUE(t->Is<sem::StorageTexture>());
EXPECT_EQ(t->As<sem::StorageTexture>()->image_format(),
sem::ImageFormat::kR16Float);
EXPECT_EQ(t->As<sem::Texture>()->dim(), sem::TextureDimension::k2d);
ast::ImageFormat::kR16Float);
EXPECT_EQ(t->As<sem::Texture>()->dim(), ast::TextureDimension::k2d);
}
TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidType) {

View File

@@ -746,7 +746,7 @@ TEST_F(ParserImplTest, TypeDecl_Sampler) {
auto p = parser("sampler");
auto& builder = p->builder();
auto* type = builder.create<sem::Sampler>(sem::SamplerKind::kSampler);
auto* type = builder.create<sem::Sampler>(ast::SamplerKind::kSampler);
auto t = p->type_decl();
EXPECT_TRUE(t.matched);
@@ -761,7 +761,7 @@ TEST_F(ParserImplTest, TypeDecl_Texture) {
auto p = parser("texture_cube<f32>");
auto& builder = p->builder();
auto* type = builder.create<sem::SampledTexture>(sem::TextureDimension::kCube,
auto* type = builder.create<sem::SampledTexture>(ast::TextureDimension::kCube,
ty.f32());
auto t = p->type_decl();