spirv-reader: use spirv.hpp11

In preparation for SPIRV-Tools change where its internals
use the C++11 headers.

This patch works with SPIRV-Tools using the old C header
and using the C++11 header.

This patch includes some complex machinery inside "three_sided_patch"
namespaces that can be removed after third_party/vulkan-deps/spirv-tools has
fully transitioned into using the C++11 headers.

Change-Id: I36f358fe3edcc5e613625708017fb8d7919c40c6
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/108780
Reviewed-by: Alan Baker <alanbaker@google.com>
Commit-Queue: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
David Neto 2022-11-08 00:17:56 +00:00 committed by Dawn LUCI CQ
parent 82f6475faf
commit eb949c87ee
8 changed files with 904 additions and 722 deletions

View File

@ -20,13 +20,13 @@ EnumConverter::EnumConverter(const FailStream& fs) : fail_stream_(fs) {}
EnumConverter::~EnumConverter() = default; EnumConverter::~EnumConverter() = default;
ast::PipelineStage EnumConverter::ToPipelineStage(SpvExecutionModel model) { ast::PipelineStage EnumConverter::ToPipelineStage(spv::ExecutionModel model) {
switch (model) { switch (model) {
case SpvExecutionModelVertex: case spv::ExecutionModel::Vertex:
return ast::PipelineStage::kVertex; return ast::PipelineStage::kVertex;
case SpvExecutionModelFragment: case spv::ExecutionModel::Fragment:
return ast::PipelineStage::kFragment; return ast::PipelineStage::kFragment;
case SpvExecutionModelGLCompute: case spv::ExecutionModel::GLCompute:
return ast::PipelineStage::kCompute; return ast::PipelineStage::kCompute;
default: default:
break; break;
@ -36,23 +36,23 @@ ast::PipelineStage EnumConverter::ToPipelineStage(SpvExecutionModel model) {
return ast::PipelineStage::kNone; return ast::PipelineStage::kNone;
} }
ast::AddressSpace EnumConverter::ToAddressSpace(const SpvStorageClass sc) { ast::AddressSpace EnumConverter::ToAddressSpace(const spv::StorageClass sc) {
switch (sc) { switch (sc) {
case SpvStorageClassInput: case spv::StorageClass::Input:
return ast::AddressSpace::kIn; return ast::AddressSpace::kIn;
case SpvStorageClassOutput: case spv::StorageClass::Output:
return ast::AddressSpace::kOut; return ast::AddressSpace::kOut;
case SpvStorageClassUniform: case spv::StorageClass::Uniform:
return ast::AddressSpace::kUniform; return ast::AddressSpace::kUniform;
case SpvStorageClassWorkgroup: case spv::StorageClass::Workgroup:
return ast::AddressSpace::kWorkgroup; return ast::AddressSpace::kWorkgroup;
case SpvStorageClassUniformConstant: case spv::StorageClass::UniformConstant:
return ast::AddressSpace::kNone; return ast::AddressSpace::kNone;
case SpvStorageClassStorageBuffer: case spv::StorageClass::StorageBuffer:
return ast::AddressSpace::kStorage; return ast::AddressSpace::kStorage;
case SpvStorageClassPrivate: case spv::StorageClass::Private:
return ast::AddressSpace::kPrivate; return ast::AddressSpace::kPrivate;
case SpvStorageClassFunction: case spv::StorageClass::Function:
return ast::AddressSpace::kFunction; return ast::AddressSpace::kFunction;
default: default:
break; break;
@ -62,31 +62,31 @@ ast::AddressSpace EnumConverter::ToAddressSpace(const SpvStorageClass sc) {
return ast::AddressSpace::kUndefined; return ast::AddressSpace::kUndefined;
} }
ast::BuiltinValue EnumConverter::ToBuiltin(SpvBuiltIn b) { ast::BuiltinValue EnumConverter::ToBuiltin(spv::BuiltIn b) {
switch (b) { switch (b) {
case SpvBuiltInPosition: case spv::BuiltIn::Position:
return ast::BuiltinValue::kPosition; return ast::BuiltinValue::kPosition;
case SpvBuiltInVertexIndex: case spv::BuiltIn::VertexIndex:
return ast::BuiltinValue::kVertexIndex; return ast::BuiltinValue::kVertexIndex;
case SpvBuiltInInstanceIndex: case spv::BuiltIn::InstanceIndex:
return ast::BuiltinValue::kInstanceIndex; return ast::BuiltinValue::kInstanceIndex;
case SpvBuiltInFrontFacing: case spv::BuiltIn::FrontFacing:
return ast::BuiltinValue::kFrontFacing; return ast::BuiltinValue::kFrontFacing;
case SpvBuiltInFragCoord: case spv::BuiltIn::FragCoord:
return ast::BuiltinValue::kPosition; return ast::BuiltinValue::kPosition;
case SpvBuiltInFragDepth: case spv::BuiltIn::FragDepth:
return ast::BuiltinValue::kFragDepth; return ast::BuiltinValue::kFragDepth;
case SpvBuiltInLocalInvocationId: case spv::BuiltIn::LocalInvocationId:
return ast::BuiltinValue::kLocalInvocationId; return ast::BuiltinValue::kLocalInvocationId;
case SpvBuiltInLocalInvocationIndex: case spv::BuiltIn::LocalInvocationIndex:
return ast::BuiltinValue::kLocalInvocationIndex; return ast::BuiltinValue::kLocalInvocationIndex;
case SpvBuiltInGlobalInvocationId: case spv::BuiltIn::GlobalInvocationId:
return ast::BuiltinValue::kGlobalInvocationId; return ast::BuiltinValue::kGlobalInvocationId;
case SpvBuiltInWorkgroupId: case spv::BuiltIn::WorkgroupId:
return ast::BuiltinValue::kWorkgroupId; return ast::BuiltinValue::kWorkgroupId;
case SpvBuiltInSampleId: case spv::BuiltIn::SampleId:
return ast::BuiltinValue::kSampleIndex; return ast::BuiltinValue::kSampleIndex;
case SpvBuiltInSampleMask: case spv::BuiltIn::SampleMask:
return ast::BuiltinValue::kSampleMask; return ast::BuiltinValue::kSampleMask;
default: default:
break; break;
@ -96,12 +96,12 @@ ast::BuiltinValue EnumConverter::ToBuiltin(SpvBuiltIn b) {
return ast::BuiltinValue::kUndefined; return ast::BuiltinValue::kUndefined;
} }
ast::TextureDimension EnumConverter::ToDim(SpvDim dim, bool arrayed) { ast::TextureDimension EnumConverter::ToDim(spv::Dim dim, bool arrayed) {
if (arrayed) { if (arrayed) {
switch (dim) { switch (dim) {
case SpvDim2D: case spv::Dim::Dim2D:
return ast::TextureDimension::k2dArray; return ast::TextureDimension::k2dArray;
case SpvDimCube: case spv::Dim::Cube:
return ast::TextureDimension::kCubeArray; return ast::TextureDimension::kCubeArray;
default: default:
break; break;
@ -111,13 +111,13 @@ ast::TextureDimension EnumConverter::ToDim(SpvDim dim, bool arrayed) {
} }
// Assume non-arrayed // Assume non-arrayed
switch (dim) { switch (dim) {
case SpvDim1D: case spv::Dim::Dim1D:
return ast::TextureDimension::k1d; return ast::TextureDimension::k1d;
case SpvDim2D: case spv::Dim::Dim2D:
return ast::TextureDimension::k2d; return ast::TextureDimension::k2d;
case SpvDim3D: case spv::Dim::Dim3D:
return ast::TextureDimension::k3d; return ast::TextureDimension::k3d;
case SpvDimCube: case spv::Dim::Cube:
return ast::TextureDimension::kCube; return ast::TextureDimension::kCube;
default: default:
break; break;
@ -126,47 +126,47 @@ ast::TextureDimension EnumConverter::ToDim(SpvDim dim, bool arrayed) {
return ast::TextureDimension::kNone; return ast::TextureDimension::kNone;
} }
ast::TexelFormat EnumConverter::ToTexelFormat(SpvImageFormat fmt) { ast::TexelFormat EnumConverter::ToTexelFormat(spv::ImageFormat fmt) {
switch (fmt) { switch (fmt) {
case SpvImageFormatUnknown: case spv::ImageFormat::Unknown:
return ast::TexelFormat::kUndefined; return ast::TexelFormat::kUndefined;
// 8 bit channels // 8 bit channels
case SpvImageFormatRgba8: case spv::ImageFormat::Rgba8:
return ast::TexelFormat::kRgba8Unorm; return ast::TexelFormat::kRgba8Unorm;
case SpvImageFormatRgba8Snorm: case spv::ImageFormat::Rgba8Snorm:
return ast::TexelFormat::kRgba8Snorm; return ast::TexelFormat::kRgba8Snorm;
case SpvImageFormatRgba8ui: case spv::ImageFormat::Rgba8ui:
return ast::TexelFormat::kRgba8Uint; return ast::TexelFormat::kRgba8Uint;
case SpvImageFormatRgba8i: case spv::ImageFormat::Rgba8i:
return ast::TexelFormat::kRgba8Sint; return ast::TexelFormat::kRgba8Sint;
// 16 bit channels // 16 bit channels
case SpvImageFormatRgba16ui: case spv::ImageFormat::Rgba16ui:
return ast::TexelFormat::kRgba16Uint; return ast::TexelFormat::kRgba16Uint;
case SpvImageFormatRgba16i: case spv::ImageFormat::Rgba16i:
return ast::TexelFormat::kRgba16Sint; return ast::TexelFormat::kRgba16Sint;
case SpvImageFormatRgba16f: case spv::ImageFormat::Rgba16f:
return ast::TexelFormat::kRgba16Float; return ast::TexelFormat::kRgba16Float;
// 32 bit channels // 32 bit channels
case SpvImageFormatR32ui: case spv::ImageFormat::R32ui:
return ast::TexelFormat::kR32Uint; return ast::TexelFormat::kR32Uint;
case SpvImageFormatR32i: case spv::ImageFormat::R32i:
return ast::TexelFormat::kR32Sint; return ast::TexelFormat::kR32Sint;
case SpvImageFormatR32f: case spv::ImageFormat::R32f:
return ast::TexelFormat::kR32Float; return ast::TexelFormat::kR32Float;
case SpvImageFormatRg32ui: case spv::ImageFormat::Rg32ui:
return ast::TexelFormat::kRg32Uint; return ast::TexelFormat::kRg32Uint;
case SpvImageFormatRg32i: case spv::ImageFormat::Rg32i:
return ast::TexelFormat::kRg32Sint; return ast::TexelFormat::kRg32Sint;
case SpvImageFormatRg32f: case spv::ImageFormat::Rg32f:
return ast::TexelFormat::kRg32Float; return ast::TexelFormat::kRg32Float;
case SpvImageFormatRgba32ui: case spv::ImageFormat::Rgba32ui:
return ast::TexelFormat::kRgba32Uint; return ast::TexelFormat::kRgba32Uint;
case SpvImageFormatRgba32i: case spv::ImageFormat::Rgba32i:
return ast::TexelFormat::kRgba32Sint; return ast::TexelFormat::kRgba32Sint;
case SpvImageFormatRgba32f: case spv::ImageFormat::Rgba32f:
return ast::TexelFormat::kRgba32Float; return ast::TexelFormat::kRgba32Float;
default: default:
break; break;

View File

@ -16,6 +16,7 @@
#define SRC_TINT_READER_SPIRV_ENUM_CONVERTER_H_ #define SRC_TINT_READER_SPIRV_ENUM_CONVERTER_H_
#include "spirv/unified1/spirv.h" #include "spirv/unified1/spirv.h"
#include "spirv/unified1/spirv.hpp11"
#include "src/tint/ast/address_space.h" #include "src/tint/ast/address_space.h"
#include "src/tint/ast/builtin_value.h" #include "src/tint/ast/builtin_value.h"
#include "src/tint/ast/pipeline_stage.h" #include "src/tint/ast/pipeline_stage.h"
@ -37,32 +38,49 @@ class EnumConverter {
/// On failure, logs an error and returns kNone /// On failure, logs an error and returns kNone
/// @param model the SPIR-V entry point execution model /// @param model the SPIR-V entry point execution model
/// @returns a Tint AST pipeline stage /// @returns a Tint AST pipeline stage
ast::PipelineStage ToPipelineStage(SpvExecutionModel model); ast::PipelineStage ToPipelineStage(spv::ExecutionModel model);
/// Converts a SPIR-V storage class to a Tint address space. /// Converts a SPIR-V storage class to a Tint address space.
/// On failure, logs an error and returns kNone /// On failure, logs an error and returns kNone
/// @param sc the SPIR-V storage class /// @param sc the SPIR-V storage class
/// @returns a Tint AST address space /// @returns a Tint AST address space
ast::AddressSpace ToAddressSpace(const SpvStorageClass sc); ast::AddressSpace ToAddressSpace(const spv::StorageClass sc);
/// Converts a SPIR-V Builtin value a Tint Builtin. /// Converts a SPIR-V Builtin value a Tint Builtin.
/// On failure, logs an error and returns kNone /// On failure, logs an error and returns kNone
/// @param b the SPIR-V builtin /// @param b the SPIR-V builtin
/// @returns a Tint AST builtin /// @returns a Tint AST builtin
ast::BuiltinValue ToBuiltin(SpvBuiltIn b); ast::BuiltinValue ToBuiltin(spv::BuiltIn b);
/// Converts a possibly arrayed SPIR-V Dim to a Tint texture dimension. /// Converts a possibly arrayed SPIR-V Dim to a Tint texture dimension.
/// On failure, logs an error and returns kNone /// On failure, logs an error and returns kNone
/// @param dim the SPIR-V Dim value /// @param dim the SPIR-V Dim value
/// @param arrayed true if the texture is arrayed /// @param arrayed true if the texture is arrayed
/// @returns a Tint AST texture dimension /// @returns a Tint AST texture dimension
ast::TextureDimension ToDim(SpvDim dim, bool arrayed); ast::TextureDimension ToDim(spv::Dim dim, bool arrayed);
/// Converts a possibly arrayed SPIR-V Dim to a Tint texture dimension.
/// On failure, logs an error and returns kNone
/// @param dim the SPIR-V Dim value
/// @param arrayed true if the texture is arrayed
/// @returns a Tint AST texture dimension
ast::TextureDimension ToDim(SpvDim dim, bool arrayed) {
return ToDim(static_cast<spv::Dim>(dim), arrayed);
}
/// Converts a SPIR-V Image Format to a TexelFormat /// Converts a SPIR-V Image Format to a TexelFormat
/// On failure, logs an error and returns kNone /// On failure, logs an error and returns kNone
/// @param fmt the SPIR-V format /// @param fmt the SPIR-V format
/// @returns a Tint AST format /// @returns a Tint AST format
ast::TexelFormat ToTexelFormat(SpvImageFormat fmt); ast::TexelFormat ToTexelFormat(spv::ImageFormat fmt);
/// Converts a SPIR-V Image Format to a TexelFormat
/// On failure, logs an error and returns kNone
/// @param fmt the SPIR-V format
/// @returns a Tint AST format
ast::TexelFormat ToTexelFormat(SpvImageFormat fmt) {
return ToTexelFormat(static_cast<spv::ImageFormat>(fmt));
}
private: private:
/// Registers a failure and returns a stream for log diagnostics. /// Registers a failure and returns a stream for log diagnostics.

View File

@ -24,12 +24,12 @@ namespace {
// Pipeline stage // Pipeline stage
struct PipelineStageCase { struct PipelineStageCase {
SpvExecutionModel model; spv::ExecutionModel model;
bool expect_success; bool expect_success;
ast::PipelineStage expected; ast::PipelineStage expected;
}; };
inline std::ostream& operator<<(std::ostream& out, PipelineStageCase psc) { inline std::ostream& operator<<(std::ostream& out, PipelineStageCase psc) {
out << "PipelineStageCase{ SpvExecutionModel:" << int(psc.model) out << "PipelineStageCase{ spv::ExecutionModel:::" << int(psc.model)
<< " expect_success?:" << int(psc.expect_success) << " expected:" << int(psc.expected) << " expect_success?:" << int(psc.expect_success) << " expected:" << int(psc.expected)
<< "}"; << "}";
return out; return out;
@ -65,29 +65,29 @@ TEST_P(SpvPipelineStageTest, Samples) {
INSTANTIATE_TEST_SUITE_P(EnumConverterGood, INSTANTIATE_TEST_SUITE_P(EnumConverterGood,
SpvPipelineStageTest, SpvPipelineStageTest,
testing::Values(PipelineStageCase{SpvExecutionModelVertex, true, testing::Values(PipelineStageCase{spv::ExecutionModel::Vertex, true,
ast::PipelineStage::kVertex}, ast::PipelineStage::kVertex},
PipelineStageCase{SpvExecutionModelFragment, true, PipelineStageCase{spv::ExecutionModel::Fragment, true,
ast::PipelineStage::kFragment}, ast::PipelineStage::kFragment},
PipelineStageCase{SpvExecutionModelGLCompute, true, PipelineStageCase{spv::ExecutionModel::GLCompute, true,
ast::PipelineStage::kCompute})); ast::PipelineStage::kCompute}));
INSTANTIATE_TEST_SUITE_P(EnumConverterBad, INSTANTIATE_TEST_SUITE_P(EnumConverterBad,
SpvPipelineStageTest, SpvPipelineStageTest,
testing::Values(PipelineStageCase{static_cast<SpvExecutionModel>(9999), testing::Values(PipelineStageCase{static_cast<spv::ExecutionModel>(9999),
false, ast::PipelineStage::kNone}, false, ast::PipelineStage::kNone},
PipelineStageCase{SpvExecutionModelTessellationControl, PipelineStageCase{spv::ExecutionModel::TessellationControl,
false, ast::PipelineStage::kNone})); false, ast::PipelineStage::kNone}));
// Storage class // Storage class
struct StorageClassCase { struct StorageClassCase {
SpvStorageClass sc; spv::StorageClass sc;
bool expect_success; bool expect_success;
ast::AddressSpace expected; ast::AddressSpace expected;
}; };
inline std::ostream& operator<<(std::ostream& out, StorageClassCase scc) { inline std::ostream& operator<<(std::ostream& out, StorageClassCase scc) {
out << "StorageClassCase{ SpvStorageClass:" << int(scc.sc) out << "StorageClassCase{ spv::StorageClass:::" << int(scc.sc)
<< " expect_success?:" << int(scc.expect_success) << " expected:" << int(scc.expected) << " expect_success?:" << int(scc.expect_success) << " expected:" << int(scc.expected)
<< "}"; << "}";
return out; return out;
@ -125,29 +125,29 @@ INSTANTIATE_TEST_SUITE_P(
EnumConverterGood, EnumConverterGood,
SpvStorageClassTest, SpvStorageClassTest,
testing::Values( testing::Values(
StorageClassCase{SpvStorageClassInput, true, ast::AddressSpace::kIn}, StorageClassCase{spv::StorageClass::Input, true, ast::AddressSpace::kIn},
StorageClassCase{SpvStorageClassOutput, true, ast::AddressSpace::kOut}, StorageClassCase{spv::StorageClass::Output, true, ast::AddressSpace::kOut},
StorageClassCase{SpvStorageClassUniform, true, ast::AddressSpace::kUniform}, StorageClassCase{spv::StorageClass::Uniform, true, ast::AddressSpace::kUniform},
StorageClassCase{SpvStorageClassWorkgroup, true, ast::AddressSpace::kWorkgroup}, StorageClassCase{spv::StorageClass::Workgroup, true, ast::AddressSpace::kWorkgroup},
StorageClassCase{SpvStorageClassUniformConstant, true, ast::AddressSpace::kNone}, StorageClassCase{spv::StorageClass::UniformConstant, true, ast::AddressSpace::kNone},
StorageClassCase{SpvStorageClassStorageBuffer, true, ast::AddressSpace::kStorage}, StorageClassCase{spv::StorageClass::StorageBuffer, true, ast::AddressSpace::kStorage},
StorageClassCase{SpvStorageClassPrivate, true, ast::AddressSpace::kPrivate}, StorageClassCase{spv::StorageClass::Private, true, ast::AddressSpace::kPrivate},
StorageClassCase{SpvStorageClassFunction, true, ast::AddressSpace::kFunction})); StorageClassCase{spv::StorageClass::Function, true, ast::AddressSpace::kFunction}));
INSTANTIATE_TEST_SUITE_P(EnumConverterBad, INSTANTIATE_TEST_SUITE_P(EnumConverterBad,
SpvStorageClassTest, SpvStorageClassTest,
testing::Values(StorageClassCase{static_cast<SpvStorageClass>(9999), false, testing::Values(StorageClassCase{static_cast<spv::StorageClass>(9999),
ast::AddressSpace::kUndefined})); false, ast::AddressSpace::kUndefined}));
// Builtin // Builtin
struct BuiltinCase { struct BuiltinCase {
SpvBuiltIn builtin; spv::BuiltIn builtin;
bool expect_success; bool expect_success;
ast::BuiltinValue expected; ast::BuiltinValue expected;
}; };
inline std::ostream& operator<<(std::ostream& out, BuiltinCase bc) { inline std::ostream& operator<<(std::ostream& out, BuiltinCase bc) {
out << "BuiltinCase{ SpvBuiltIn:" << int(bc.builtin) out << "BuiltinCase{ spv::BuiltIn::" << int(bc.builtin)
<< " expect_success?:" << int(bc.expect_success) << " expected:" << int(bc.expected) << "}"; << " expect_success?:" << int(bc.expect_success) << " expected:" << int(bc.expected) << "}";
return out; return out;
} }
@ -184,43 +184,44 @@ INSTANTIATE_TEST_SUITE_P(
EnumConverterGood_Input, EnumConverterGood_Input,
SpvBuiltinTest, SpvBuiltinTest,
testing::Values( testing::Values(
BuiltinCase{SpvBuiltInPosition, true, ast::BuiltinValue::kPosition}, BuiltinCase{spv::BuiltIn::Position, true, ast::BuiltinValue::kPosition},
BuiltinCase{SpvBuiltInInstanceIndex, true, ast::BuiltinValue::kInstanceIndex}, BuiltinCase{spv::BuiltIn::InstanceIndex, true, ast::BuiltinValue::kInstanceIndex},
BuiltinCase{SpvBuiltInFrontFacing, true, ast::BuiltinValue::kFrontFacing}, BuiltinCase{spv::BuiltIn::FrontFacing, true, ast::BuiltinValue::kFrontFacing},
BuiltinCase{SpvBuiltInFragCoord, true, ast::BuiltinValue::kPosition}, BuiltinCase{spv::BuiltIn::FragCoord, true, ast::BuiltinValue::kPosition},
BuiltinCase{SpvBuiltInLocalInvocationId, true, ast::BuiltinValue::kLocalInvocationId}, BuiltinCase{spv::BuiltIn::LocalInvocationId, true, ast::BuiltinValue::kLocalInvocationId},
BuiltinCase{SpvBuiltInLocalInvocationIndex, true, ast::BuiltinValue::kLocalInvocationIndex}, BuiltinCase{spv::BuiltIn::LocalInvocationIndex, true,
BuiltinCase{SpvBuiltInGlobalInvocationId, true, ast::BuiltinValue::kGlobalInvocationId}, ast::BuiltinValue::kLocalInvocationIndex},
BuiltinCase{SpvBuiltInWorkgroupId, true, ast::BuiltinValue::kWorkgroupId}, BuiltinCase{spv::BuiltIn::GlobalInvocationId, true, ast::BuiltinValue::kGlobalInvocationId},
BuiltinCase{SpvBuiltInSampleId, true, ast::BuiltinValue::kSampleIndex}, BuiltinCase{spv::BuiltIn::WorkgroupId, true, ast::BuiltinValue::kWorkgroupId},
BuiltinCase{SpvBuiltInSampleMask, true, ast::BuiltinValue::kSampleMask})); BuiltinCase{spv::BuiltIn::SampleId, true, ast::BuiltinValue::kSampleIndex},
BuiltinCase{spv::BuiltIn::SampleMask, true, ast::BuiltinValue::kSampleMask}));
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
EnumConverterGood_Output, EnumConverterGood_Output,
SpvBuiltinTest, SpvBuiltinTest,
testing::Values(BuiltinCase{SpvBuiltInPosition, true, ast::BuiltinValue::kPosition}, testing::Values(BuiltinCase{spv::BuiltIn::Position, true, ast::BuiltinValue::kPosition},
BuiltinCase{SpvBuiltInFragDepth, true, ast::BuiltinValue::kFragDepth}, BuiltinCase{spv::BuiltIn::FragDepth, true, ast::BuiltinValue::kFragDepth},
BuiltinCase{SpvBuiltInSampleMask, true, ast::BuiltinValue::kSampleMask})); BuiltinCase{spv::BuiltIn::SampleMask, true, ast::BuiltinValue::kSampleMask}));
INSTANTIATE_TEST_SUITE_P(EnumConverterBad, INSTANTIATE_TEST_SUITE_P(EnumConverterBad,
SpvBuiltinTest, SpvBuiltinTest,
testing::Values(BuiltinCase{static_cast<SpvBuiltIn>(9999), false, testing::Values(BuiltinCase{static_cast<spv::BuiltIn>(9999), false,
ast::BuiltinValue::kUndefined}, ast::BuiltinValue::kUndefined},
BuiltinCase{static_cast<SpvBuiltIn>(9999), false, BuiltinCase{static_cast<spv::BuiltIn>(9999), false,
ast::BuiltinValue::kUndefined}, ast::BuiltinValue::kUndefined},
BuiltinCase{SpvBuiltInNumWorkgroups, false, BuiltinCase{spv::BuiltIn::NumWorkgroups, false,
ast::BuiltinValue::kUndefined})); ast::BuiltinValue::kUndefined}));
// Dim // Dim
struct DimCase { struct DimCase {
SpvDim dim; spv::Dim dim;
bool arrayed; bool arrayed;
bool expect_success; bool expect_success;
ast::TextureDimension expected; ast::TextureDimension expected;
}; };
inline std::ostream& operator<<(std::ostream& out, DimCase dc) { inline std::ostream& operator<<(std::ostream& out, DimCase dc) {
out << "DimCase{ SpvDim:" << int(dc.dim) << " arrayed?:" << int(dc.arrayed) out << "DimCase{ spv::Dim:::" << int(dc.dim) << " arrayed?:" << int(dc.arrayed)
<< " expect_success?:" << int(dc.expect_success) << " expected:" << int(dc.expected) << "}"; << " expect_success?:" << int(dc.expect_success) << " expected:" << int(dc.expected) << "}";
return out; return out;
} }
@ -256,40 +257,41 @@ INSTANTIATE_TEST_SUITE_P(EnumConverterGood,
SpvDimTest, SpvDimTest,
testing::Values( testing::Values(
// Non-arrayed // Non-arrayed
DimCase{SpvDim1D, false, true, ast::TextureDimension::k1d}, DimCase{spv::Dim::Dim1D, false, true, ast::TextureDimension::k1d},
DimCase{SpvDim2D, false, true, ast::TextureDimension::k2d}, DimCase{spv::Dim::Dim2D, false, true, ast::TextureDimension::k2d},
DimCase{SpvDim3D, false, true, ast::TextureDimension::k3d}, DimCase{spv::Dim::Dim3D, false, true, ast::TextureDimension::k3d},
DimCase{SpvDimCube, false, true, ast::TextureDimension::kCube}, DimCase{spv::Dim::Cube, false, true, ast::TextureDimension::kCube},
// Arrayed // Arrayed
DimCase{SpvDim2D, true, true, ast::TextureDimension::k2dArray}, DimCase{spv::Dim::Dim2D, true, true, ast::TextureDimension::k2dArray},
DimCase{SpvDimCube, true, true, ast::TextureDimension::kCubeArray})); DimCase{spv::Dim::Cube, true, true,
ast::TextureDimension::kCubeArray}));
INSTANTIATE_TEST_SUITE_P(EnumConverterBad, INSTANTIATE_TEST_SUITE_P(
EnumConverterBad,
SpvDimTest, SpvDimTest,
testing::Values( testing::Values(
// Invalid SPIR-V dimensionality. // Invalid SPIR-V dimensionality.
DimCase{SpvDimMax, false, false, ast::TextureDimension::kNone}, DimCase{spv::Dim::Max, false, false, ast::TextureDimension::kNone},
DimCase{SpvDimMax, true, false, ast::TextureDimension::kNone}, DimCase{spv::Dim::Max, true, false, ast::TextureDimension::kNone},
// Vulkan non-arrayed dimensionalities not supported by WGSL. // Vulkan non-arrayed dimensionalities not supported by WGSL.
DimCase{SpvDimRect, false, false, ast::TextureDimension::kNone}, DimCase{spv::Dim::Rect, false, false, ast::TextureDimension::kNone},
DimCase{SpvDimBuffer, false, false, ast::TextureDimension::kNone}, DimCase{spv::Dim::Buffer, false, false, ast::TextureDimension::kNone},
DimCase{SpvDimSubpassData, false, false, ast::TextureDimension::kNone}, DimCase{spv::Dim::SubpassData, false, false, ast::TextureDimension::kNone},
// Arrayed dimensionalities not supported by WGSL // Arrayed dimensionalities not supported by WGSL
DimCase{SpvDim3D, true, false, ast::TextureDimension::kNone}, DimCase{spv::Dim::Dim3D, true, false, ast::TextureDimension::kNone},
DimCase{SpvDimRect, true, false, ast::TextureDimension::kNone}, DimCase{spv::Dim::Rect, true, false, ast::TextureDimension::kNone},
DimCase{SpvDimBuffer, true, false, ast::TextureDimension::kNone}, DimCase{spv::Dim::Buffer, true, false, ast::TextureDimension::kNone},
DimCase{SpvDimSubpassData, true, false, DimCase{spv::Dim::SubpassData, true, false, ast::TextureDimension::kNone}));
ast::TextureDimension::kNone}));
// TexelFormat // TexelFormat
struct TexelFormatCase { struct TexelFormatCase {
SpvImageFormat format; spv::ImageFormat format;
bool expect_success; bool expect_success;
ast::TexelFormat expected; ast::TexelFormat expected;
}; };
inline std::ostream& operator<<(std::ostream& out, TexelFormatCase ifc) { inline std::ostream& operator<<(std::ostream& out, TexelFormatCase ifc) {
out << "TexelFormatCase{ SpvImageFormat:" << int(ifc.format) out << "TexelFormatCase{ spv::ImageFormat:::" << int(ifc.format)
<< " expect_success?:" << int(ifc.expect_success) << " expected:" << int(ifc.expected) << " expect_success?:" << int(ifc.expect_success) << " expected:" << int(ifc.expected)
<< "}"; << "}";
return out; return out;
@ -328,52 +330,52 @@ INSTANTIATE_TEST_SUITE_P(
SpvImageFormatTest, SpvImageFormatTest,
testing::Values( testing::Values(
// Unknown. This is used for sampled images. // Unknown. This is used for sampled images.
TexelFormatCase{SpvImageFormatUnknown, true, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::Unknown, true, ast::TexelFormat::kUndefined},
// 8 bit channels // 8 bit channels
TexelFormatCase{SpvImageFormatRgba8, true, ast::TexelFormat::kRgba8Unorm}, TexelFormatCase{spv::ImageFormat::Rgba8, true, ast::TexelFormat::kRgba8Unorm},
TexelFormatCase{SpvImageFormatRgba8Snorm, true, ast::TexelFormat::kRgba8Snorm}, TexelFormatCase{spv::ImageFormat::Rgba8Snorm, true, ast::TexelFormat::kRgba8Snorm},
TexelFormatCase{SpvImageFormatRgba8ui, true, ast::TexelFormat::kRgba8Uint}, TexelFormatCase{spv::ImageFormat::Rgba8ui, true, ast::TexelFormat::kRgba8Uint},
TexelFormatCase{SpvImageFormatRgba8i, true, ast::TexelFormat::kRgba8Sint}, TexelFormatCase{spv::ImageFormat::Rgba8i, true, ast::TexelFormat::kRgba8Sint},
// 16 bit channels // 16 bit channels
TexelFormatCase{SpvImageFormatRgba16ui, true, ast::TexelFormat::kRgba16Uint}, TexelFormatCase{spv::ImageFormat::Rgba16ui, true, ast::TexelFormat::kRgba16Uint},
TexelFormatCase{SpvImageFormatRgba16i, true, ast::TexelFormat::kRgba16Sint}, TexelFormatCase{spv::ImageFormat::Rgba16i, true, ast::TexelFormat::kRgba16Sint},
TexelFormatCase{SpvImageFormatRgba16f, true, ast::TexelFormat::kRgba16Float}, TexelFormatCase{spv::ImageFormat::Rgba16f, true, ast::TexelFormat::kRgba16Float},
// 32 bit channels // 32 bit channels
// ... 1 channel // ... 1 channel
TexelFormatCase{SpvImageFormatR32ui, true, ast::TexelFormat::kR32Uint}, TexelFormatCase{spv::ImageFormat::R32ui, true, ast::TexelFormat::kR32Uint},
TexelFormatCase{SpvImageFormatR32i, true, ast::TexelFormat::kR32Sint}, TexelFormatCase{spv::ImageFormat::R32i, true, ast::TexelFormat::kR32Sint},
TexelFormatCase{SpvImageFormatR32f, true, ast::TexelFormat::kR32Float}, TexelFormatCase{spv::ImageFormat::R32f, true, ast::TexelFormat::kR32Float},
// ... 2 channels // ... 2 channels
TexelFormatCase{SpvImageFormatRg32ui, true, ast::TexelFormat::kRg32Uint}, TexelFormatCase{spv::ImageFormat::Rg32ui, true, ast::TexelFormat::kRg32Uint},
TexelFormatCase{SpvImageFormatRg32i, true, ast::TexelFormat::kRg32Sint}, TexelFormatCase{spv::ImageFormat::Rg32i, true, ast::TexelFormat::kRg32Sint},
TexelFormatCase{SpvImageFormatRg32f, true, ast::TexelFormat::kRg32Float}, TexelFormatCase{spv::ImageFormat::Rg32f, true, ast::TexelFormat::kRg32Float},
// ... 4 channels // ... 4 channels
TexelFormatCase{SpvImageFormatRgba32ui, true, ast::TexelFormat::kRgba32Uint}, TexelFormatCase{spv::ImageFormat::Rgba32ui, true, ast::TexelFormat::kRgba32Uint},
TexelFormatCase{SpvImageFormatRgba32i, true, ast::TexelFormat::kRgba32Sint}, TexelFormatCase{spv::ImageFormat::Rgba32i, true, ast::TexelFormat::kRgba32Sint},
TexelFormatCase{SpvImageFormatRgba32f, true, ast::TexelFormat::kRgba32Float})); TexelFormatCase{spv::ImageFormat::Rgba32f, true, ast::TexelFormat::kRgba32Float}));
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
EnumConverterBad, EnumConverterBad,
SpvImageFormatTest, SpvImageFormatTest,
testing::Values( testing::Values(
// Scanning in order from the SPIR-V spec. // Scanning in order from the SPIR-V spec.
TexelFormatCase{SpvImageFormatRg16f, false, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::Rg16f, false, ast::TexelFormat::kUndefined},
TexelFormatCase{SpvImageFormatR11fG11fB10f, false, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::R11fG11fB10f, false, ast::TexelFormat::kUndefined},
TexelFormatCase{SpvImageFormatR16f, false, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::R16f, false, ast::TexelFormat::kUndefined},
TexelFormatCase{SpvImageFormatRgb10A2, false, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::Rgb10A2, false, ast::TexelFormat::kUndefined},
TexelFormatCase{SpvImageFormatRg16, false, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::Rg16, false, ast::TexelFormat::kUndefined},
TexelFormatCase{SpvImageFormatRg8, false, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::Rg8, false, ast::TexelFormat::kUndefined},
TexelFormatCase{SpvImageFormatR16, false, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::R16, false, ast::TexelFormat::kUndefined},
TexelFormatCase{SpvImageFormatR8, false, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::R8, false, ast::TexelFormat::kUndefined},
TexelFormatCase{SpvImageFormatRgba16Snorm, false, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::Rgba16Snorm, false, ast::TexelFormat::kUndefined},
TexelFormatCase{SpvImageFormatRg16Snorm, false, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::Rg16Snorm, false, ast::TexelFormat::kUndefined},
TexelFormatCase{SpvImageFormatRg8Snorm, false, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::Rg8Snorm, false, ast::TexelFormat::kUndefined},
TexelFormatCase{SpvImageFormatRg16i, false, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::Rg16i, false, ast::TexelFormat::kUndefined},
TexelFormatCase{SpvImageFormatRg8i, false, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::Rg8i, false, ast::TexelFormat::kUndefined},
TexelFormatCase{SpvImageFormatR8i, false, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::R8i, false, ast::TexelFormat::kUndefined},
TexelFormatCase{SpvImageFormatRgb10a2ui, false, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::Rgb10a2ui, false, ast::TexelFormat::kUndefined},
TexelFormatCase{SpvImageFormatRg16ui, false, ast::TexelFormat::kUndefined}, TexelFormatCase{spv::ImageFormat::Rg16ui, false, ast::TexelFormat::kUndefined},
TexelFormatCase{SpvImageFormatRg8ui, false, ast::TexelFormat::kUndefined})); TexelFormatCase{spv::ImageFormat::Rg8ui, false, ast::TexelFormat::kUndefined}));
} // namespace } // namespace
} // namespace tint::reader::spirv } // namespace tint::reader::spirv

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -66,8 +66,8 @@ namespace tint::reader::spirv {
/// The binary representation of a SPIR-V decoration enum followed by its /// The binary representation of a SPIR-V decoration enum followed by its
/// operands, if any. /// operands, if any.
/// Example: { SpvDecorationBlock } /// Example: { spv::Decoration::Block }
/// Example: { SpvDecorationArrayStride, 16 } /// Example: { spv::Decoration::ArrayStride, 16 }
using Decoration = std::vector<uint32_t>; using Decoration = std::vector<uint32_t>;
/// DecorationList is a list of decorations /// DecorationList is a list of decorations
@ -338,13 +338,13 @@ class ParserImpl : Reader {
/// Returns true when the given instruction is an extended instruction /// Returns true when the given instruction is an extended instruction
/// for GLSL.std.450. /// for GLSL.std.450.
/// @param inst a SPIR-V instruction /// @param inst a SPIR-V instruction
/// @returns true if its an SpvOpExtInst for GLSL.std.450 /// @returns true if its an spv::Op::ExtInst for GLSL.std.450
bool IsGlslExtendedInstruction(const spvtools::opt::Instruction& inst) const; bool IsGlslExtendedInstruction(const spvtools::opt::Instruction& inst) const;
/// Returns true when the given instruction is an extended instruction /// Returns true when the given instruction is an extended instruction
/// from an ignored extended instruction set. /// from an ignored extended instruction set.
/// @param inst a SPIR-V instruction /// @param inst a SPIR-V instruction
/// @returns true if its an SpvOpExtInst for an ignored extended instruction /// @returns true if its an spv::Op::ExtInst for an ignored extended instruction
bool IsIgnoredExtendedInstruction(const spvtools::opt::Instruction& inst) const; bool IsIgnoredExtendedInstruction(const spvtools::opt::Instruction& inst) const;
/// Registers user names for SPIR-V objects, from OpName, and OpMemberName. /// Registers user names for SPIR-V objects, from OpName, and OpMemberName.
@ -585,7 +585,7 @@ class ParserImpl : Reader {
/// class class. /// class class.
uint32_t pointer_type_id = 0; uint32_t pointer_type_id = 0;
/// The SPIR-V address space. /// The SPIR-V address space.
SpvStorageClass storage_class = SpvStorageClassOutput; spv::StorageClass storage_class = spv::StorageClass::Output;
/// The ID of the type of a pointer to the Position member. /// The ID of the type of a pointer to the Position member.
uint32_t position_member_pointer_type_id = 0; uint32_t position_member_pointer_type_id = 0;
/// The ID of the gl_PerVertex variable, if it was declared. /// The ID of the gl_PerVertex variable, if it was declared.
@ -690,7 +690,7 @@ class ParserImpl : Reader {
const spvtools::opt::Instruction* GetInstructionForTest(uint32_t id) const; const spvtools::opt::Instruction* GetInstructionForTest(uint32_t id) const;
/// A map of SPIR-V identifiers to builtins /// A map of SPIR-V identifiers to builtins
using BuiltInsMap = std::unordered_map<uint32_t, SpvBuiltIn>; using BuiltInsMap = std::unordered_map<uint32_t, spv::BuiltIn>;
/// @returns a map of builtins that should be handled specially by code /// @returns a map of builtins that should be handled specially by code
/// generation. Either the builtin does not exist in WGSL, or a type /// generation. Either the builtin does not exist in WGSL, or a type
@ -699,7 +699,7 @@ class ParserImpl : Reader {
/// @param builtin the SPIR-V builtin variable kind /// @param builtin the SPIR-V builtin variable kind
/// @returns the SPIR-V ID for the variable defining the given builtin, or 0 /// @returns the SPIR-V ID for the variable defining the given builtin, or 0
uint32_t IdForSpecialBuiltIn(SpvBuiltIn builtin) const { uint32_t IdForSpecialBuiltIn(spv::BuiltIn builtin) const {
// Do a linear search. // Do a linear search.
for (const auto& entry : special_builtins_) { for (const auto& entry : special_builtins_) {
if (entry.second == builtin) { if (entry.second == builtin) {

View File

@ -31,7 +31,7 @@ TEST_F(SpvParserTest, ConvertMemberDecoration_IsEmpty) {
TEST_F(SpvParserTest, ConvertMemberDecoration_OffsetWithoutOperand) { TEST_F(SpvParserTest, ConvertMemberDecoration_OffsetWithoutOperand) {
auto p = parser(std::vector<uint32_t>{}); auto p = parser(std::vector<uint32_t>{});
auto result = p->ConvertMemberDecoration(12, 13, nullptr, {SpvDecorationOffset}); auto result = p->ConvertMemberDecoration(12, 13, nullptr, {uint32_t(spv::Decoration::Offset)});
EXPECT_TRUE(result.IsEmpty()); EXPECT_TRUE(result.IsEmpty());
EXPECT_THAT(p->error(), Eq("malformed Offset decoration: expected 1 literal " EXPECT_THAT(p->error(), Eq("malformed Offset decoration: expected 1 literal "
"operand, has 0: member 13 of SPIR-V type 12")); "operand, has 0: member 13 of SPIR-V type 12"));
@ -40,7 +40,8 @@ TEST_F(SpvParserTest, ConvertMemberDecoration_OffsetWithoutOperand) {
TEST_F(SpvParserTest, ConvertMemberDecoration_OffsetWithTooManyOperands) { TEST_F(SpvParserTest, ConvertMemberDecoration_OffsetWithTooManyOperands) {
auto p = parser(std::vector<uint32_t>{}); auto p = parser(std::vector<uint32_t>{});
auto result = p->ConvertMemberDecoration(12, 13, nullptr, {SpvDecorationOffset, 3, 4}); auto result =
p->ConvertMemberDecoration(12, 13, nullptr, {uint32_t(spv::Decoration::Offset), 3, 4});
EXPECT_TRUE(result.IsEmpty()); EXPECT_TRUE(result.IsEmpty());
EXPECT_THAT(p->error(), Eq("malformed Offset decoration: expected 1 literal " EXPECT_THAT(p->error(), Eq("malformed Offset decoration: expected 1 literal "
"operand, has 2: member 13 of SPIR-V type 12")); "operand, has 2: member 13 of SPIR-V type 12"));
@ -49,7 +50,7 @@ TEST_F(SpvParserTest, ConvertMemberDecoration_OffsetWithTooManyOperands) {
TEST_F(SpvParserTest, ConvertMemberDecoration_Offset) { TEST_F(SpvParserTest, ConvertMemberDecoration_Offset) {
auto p = parser(std::vector<uint32_t>{}); auto p = parser(std::vector<uint32_t>{});
auto result = p->ConvertMemberDecoration(1, 1, nullptr, {SpvDecorationOffset, 8}); auto result = p->ConvertMemberDecoration(1, 1, nullptr, {uint32_t(spv::Decoration::Offset), 8});
ASSERT_FALSE(result.IsEmpty()); ASSERT_FALSE(result.IsEmpty());
EXPECT_TRUE(result[0]->Is<ast::StructMemberOffsetAttribute>()); EXPECT_TRUE(result[0]->Is<ast::StructMemberOffsetAttribute>());
auto* offset_deco = result[0]->As<ast::StructMemberOffsetAttribute>(); auto* offset_deco = result[0]->As<ast::StructMemberOffsetAttribute>();
@ -64,7 +65,8 @@ TEST_F(SpvParserTest, ConvertMemberDecoration_Matrix2x2_Stride_Natural) {
spirv::F32 f32; spirv::F32 f32;
spirv::Matrix matrix(&f32, 2, 2); spirv::Matrix matrix(&f32, 2, 2);
auto result = p->ConvertMemberDecoration(1, 1, &matrix, {SpvDecorationMatrixStride, 8}); auto result =
p->ConvertMemberDecoration(1, 1, &matrix, {uint32_t(spv::Decoration::MatrixStride), 8});
EXPECT_TRUE(result.IsEmpty()); EXPECT_TRUE(result.IsEmpty());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -74,7 +76,8 @@ TEST_F(SpvParserTest, ConvertMemberDecoration_Matrix2x2_Stride_Custom) {
spirv::F32 f32; spirv::F32 f32;
spirv::Matrix matrix(&f32, 2, 2); spirv::Matrix matrix(&f32, 2, 2);
auto result = p->ConvertMemberDecoration(1, 1, &matrix, {SpvDecorationMatrixStride, 16}); auto result =
p->ConvertMemberDecoration(1, 1, &matrix, {uint32_t(spv::Decoration::MatrixStride), 16});
ASSERT_FALSE(result.IsEmpty()); ASSERT_FALSE(result.IsEmpty());
EXPECT_TRUE(result[0]->Is<ast::StrideAttribute>()); EXPECT_TRUE(result[0]->Is<ast::StrideAttribute>());
auto* stride_deco = result[0]->As<ast::StrideAttribute>(); auto* stride_deco = result[0]->As<ast::StrideAttribute>();
@ -88,7 +91,8 @@ TEST_F(SpvParserTest, ConvertMemberDecoration_Matrix2x4_Stride_Natural) {
spirv::F32 f32; spirv::F32 f32;
spirv::Matrix matrix(&f32, 2, 4); spirv::Matrix matrix(&f32, 2, 4);
auto result = p->ConvertMemberDecoration(1, 1, &matrix, {SpvDecorationMatrixStride, 16}); auto result =
p->ConvertMemberDecoration(1, 1, &matrix, {uint32_t(spv::Decoration::MatrixStride), 16});
EXPECT_TRUE(result.IsEmpty()); EXPECT_TRUE(result.IsEmpty());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -98,7 +102,8 @@ TEST_F(SpvParserTest, ConvertMemberDecoration_Matrix2x4_Stride_Custom) {
spirv::F32 f32; spirv::F32 f32;
spirv::Matrix matrix(&f32, 2, 4); spirv::Matrix matrix(&f32, 2, 4);
auto result = p->ConvertMemberDecoration(1, 1, &matrix, {SpvDecorationMatrixStride, 64}); auto result =
p->ConvertMemberDecoration(1, 1, &matrix, {uint32_t(spv::Decoration::MatrixStride), 64});
ASSERT_FALSE(result.IsEmpty()); ASSERT_FALSE(result.IsEmpty());
EXPECT_TRUE(result[0]->Is<ast::StrideAttribute>()); EXPECT_TRUE(result[0]->Is<ast::StrideAttribute>());
auto* stride_deco = result[0]->As<ast::StrideAttribute>(); auto* stride_deco = result[0]->As<ast::StrideAttribute>();
@ -112,7 +117,8 @@ TEST_F(SpvParserTest, ConvertMemberDecoration_Matrix2x3_Stride_Custom) {
spirv::F32 f32; spirv::F32 f32;
spirv::Matrix matrix(&f32, 2, 3); spirv::Matrix matrix(&f32, 2, 3);
auto result = p->ConvertMemberDecoration(1, 1, &matrix, {SpvDecorationMatrixStride, 32}); auto result =
p->ConvertMemberDecoration(1, 1, &matrix, {uint32_t(spv::Decoration::MatrixStride), 32});
ASSERT_FALSE(result.IsEmpty()); ASSERT_FALSE(result.IsEmpty());
EXPECT_TRUE(result[0]->Is<ast::StrideAttribute>()); EXPECT_TRUE(result[0]->Is<ast::StrideAttribute>());
auto* stride_deco = result[0]->As<ast::StrideAttribute>(); auto* stride_deco = result[0]->As<ast::StrideAttribute>();
@ -127,7 +133,8 @@ TEST_F(SpvParserTest, ConvertMemberDecoration_RelaxedPrecision) {
// relaxed precision f32. // relaxed precision f32.
auto p = parser(std::vector<uint32_t>{}); auto p = parser(std::vector<uint32_t>{});
auto result = p->ConvertMemberDecoration(1, 1, nullptr, {SpvDecorationRelaxedPrecision}); auto result =
p->ConvertMemberDecoration(1, 1, nullptr, {uint32_t(spv::Decoration::RelaxedPrecision)});
EXPECT_TRUE(result.IsEmpty()); EXPECT_TRUE(result.IsEmpty());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }

View File

@ -52,7 +52,7 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsFor_OneDecoration) {
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
auto decorations = p->GetDecorationsFor(10); auto decorations = p->GetDecorationsFor(10);
EXPECT_THAT(decorations, UnorderedElementsAre(Decoration{SpvDecorationBlock})); EXPECT_THAT(decorations, UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::Block)}));
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
p->SkipDumpingPending(kSkipReason); p->SkipDumpingPending(kSkipReason);
} }
@ -66,7 +66,7 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsFor_Duplicate) {
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
auto decorations = p->GetDecorationsFor(10); auto decorations = p->GetDecorationsFor(10);
EXPECT_THAT(decorations, UnorderedElementsAre(Decoration{SpvDecorationBlock})); EXPECT_THAT(decorations, UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::Block)}));
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
p->SkipDumpingPending(kSkipReason); p->SkipDumpingPending(kSkipReason);
} }
@ -80,8 +80,9 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsFor_MultiDecoration) {
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
auto decorations = p->GetDecorationsFor(5); auto decorations = p->GetDecorationsFor(5);
EXPECT_THAT(decorations, UnorderedElementsAre(Decoration{SpvDecorationRelaxedPrecision}, EXPECT_THAT(decorations,
Decoration{SpvDecorationLocation, 7})); UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::RelaxedPrecision)},
Decoration{uint32_t(spv::Decoration::Location), 7}));
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
p->SkipDumpingPending(kSkipReason); p->SkipDumpingPending(kSkipReason);
} }
@ -124,7 +125,8 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsForMember_RelaxedPrecision) {
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error();
auto decorations = p->GetDecorationsForMember(10, 0); auto decorations = p->GetDecorationsForMember(10, 0);
EXPECT_THAT(decorations, UnorderedElementsAre(Decoration{SpvDecorationRelaxedPrecision})); EXPECT_THAT(decorations,
UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::RelaxedPrecision)}));
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
p->SkipDumpingPending(kSkipReason); p->SkipDumpingPending(kSkipReason);
} }
@ -138,7 +140,8 @@ TEST_F(SpvParserGetDecorationsTest, GetDecorationsForMember_Duplicate) {
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error();
auto decorations = p->GetDecorationsForMember(10, 0); auto decorations = p->GetDecorationsForMember(10, 0);
EXPECT_THAT(decorations, UnorderedElementsAre(Decoration{SpvDecorationRelaxedPrecision})); EXPECT_THAT(decorations,
UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::RelaxedPrecision)}));
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
p->SkipDumpingPending(kSkipReason); p->SkipDumpingPending(kSkipReason);
} }
@ -154,7 +157,8 @@ TEST_F(SpvParserGetDecorationsTest, DISABLED_GetDecorationsForMember_OneDecorati
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error(); EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error();
auto decorations = p->GetDecorationsForMember(10, 1); auto decorations = p->GetDecorationsForMember(10, 1);
EXPECT_THAT(decorations, UnorderedElementsAre(Decoration{SpvDecorationArrayStride, 12})); EXPECT_THAT(decorations,
UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::ArrayStride), 12}));
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }
@ -179,11 +183,11 @@ TEST_F(SpvParserGetDecorationsTest, DISABLED_GetDecorationsForMember_MultiDecora
EXPECT_TRUE(p->GetDecorationsForMember(50, 0).empty()); EXPECT_TRUE(p->GetDecorationsForMember(50, 0).empty());
EXPECT_THAT(p->GetDecorationsForMember(50, 1), EXPECT_THAT(p->GetDecorationsForMember(50, 1),
UnorderedElementsAre(Decoration{SpvDecorationRelaxedPrecision})); UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::RelaxedPrecision)}));
EXPECT_THAT(p->GetDecorationsForMember(50, 2), EXPECT_THAT(p->GetDecorationsForMember(50, 2),
UnorderedElementsAre(Decoration{SpvDecorationColMajor}, UnorderedElementsAre(Decoration{uint32_t(spv::Decoration::ColMajor)},
Decoration{SpvDecorationMatrixStride, 8}, Decoration{uint32_t(spv::Decoration::MatrixStride), 8},
Decoration{SpvDecorationArrayStride, 16})); Decoration{uint32_t(spv::Decoration::ArrayStride), 16}));
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }