Use a smarter way to parse enumerations

This commit is contained in:
Pierre Krieger 2016-01-31 14:45:17 +01:00
parent be43ab8218
commit b2e63f2e3a
3 changed files with 548 additions and 368 deletions

537
shader-parser/src/enums.rs Normal file
View File

@ -0,0 +1,537 @@
use parse::ParseError;
macro_rules! enumeration {
($(typedef enum $unused:ident { $($elem:ident = $value:expr,)+ } $name:ident;)+) => (
$(
#[derive(Debug, Clone)]
pub enum $name {
$($elem),+
}
impl $name {
pub fn from_num(num: u32) -> Result<$name, ParseError> {
match num {
$(
$value => Ok($name::$elem),
)+
_ => Err(ParseError::UnknownConstant(stringify!($name), num)),
}
}
}
)+
)
}
// The code below is a copy-paste from `spirv-2.h`, with the `Spv` prefixes removed.
enumeration! {
typedef enum SourceLanguage_ {
SourceLanguageUnknown = 0,
SourceLanguageESSL = 1,
SourceLanguageGLSL = 2,
SourceLanguageOpenCL_C = 3,
SourceLanguageOpenCL_CPP = 4,
} SourceLanguage;
typedef enum ExecutionModel_ {
ExecutionModelVertex = 0,
ExecutionModelTessellationControl = 1,
ExecutionModelTessellationEvaluation = 2,
ExecutionModelGeometry = 3,
ExecutionModelFragment = 4,
ExecutionModelGLCompute = 5,
ExecutionModelKernel = 6,
} ExecutionModel;
typedef enum AddressingModel_ {
AddressingModelLogical = 0,
AddressingModelPhysical32 = 1,
AddressingModelPhysical64 = 2,
} AddressingModel;
typedef enum MemoryModel_ {
MemoryModelSimple = 0,
MemoryModelGLSL450 = 1,
MemoryModelOpenCL = 2,
} MemoryModel;
typedef enum ExecutionMode_ {
ExecutionModeInvocations = 0,
ExecutionModeSpacingEqual = 1,
ExecutionModeSpacingFractionalEven = 2,
ExecutionModeSpacingFractionalOdd = 3,
ExecutionModeVertexOrderCw = 4,
ExecutionModeVertexOrderCcw = 5,
ExecutionModePixelCenterInteger = 6,
ExecutionModeOriginUpperLeft = 7,
ExecutionModeOriginLowerLeft = 8,
ExecutionModeEarlyFragmentTests = 9,
ExecutionModePointMode = 10,
ExecutionModeXfb = 11,
ExecutionModeDepthReplacing = 12,
ExecutionModeDepthGreater = 14,
ExecutionModeDepthLess = 15,
ExecutionModeDepthUnchanged = 16,
ExecutionModeLocalSize = 17,
ExecutionModeLocalSizeHint = 18,
ExecutionModeInputPoints = 19,
ExecutionModeInputLines = 20,
ExecutionModeInputLinesAdjacency = 21,
ExecutionModeTriangles = 22,
ExecutionModeInputTrianglesAdjacency = 23,
ExecutionModeQuads = 24,
ExecutionModeIsolines = 25,
ExecutionModeOutputVertices = 26,
ExecutionModeOutputPoints = 27,
ExecutionModeOutputLineStrip = 28,
ExecutionModeOutputTriangleStrip = 29,
ExecutionModeVecTypeHint = 30,
ExecutionModeContractionOff = 31,
} ExecutionMode;
typedef enum StorageClass_ {
StorageClassUniformConstant = 0,
StorageClassInput = 1,
StorageClassUniform = 2,
StorageClassOutput = 3,
StorageClassWorkgroup = 4,
StorageClassCrossWorkgroup = 5,
StorageClassPrivate = 6,
StorageClassFunction = 7,
StorageClassGeneric = 8,
StorageClassPushConstant = 9,
StorageClassAtomicCounter = 10,
StorageClassImage = 11,
} StorageClass;
typedef enum Dim_ {
Dim1D = 0,
Dim2D = 1,
Dim3D = 2,
DimCube = 3,
DimRect = 4,
DimBuffer = 5,
DimSubpassData = 6,
} Dim;
typedef enum SamplerAddressingMode_ {
SamplerAddressingModeNone = 0,
SamplerAddressingModeClampToEdge = 1,
SamplerAddressingModeClamp = 2,
SamplerAddressingModeRepeat = 3,
SamplerAddressingModeRepeatMirrored = 4,
} SamplerAddressingMode;
typedef enum SamplerFilterMode_ {
SamplerFilterModeNearest = 0,
SamplerFilterModeLinear = 1,
} SamplerFilterMode;
typedef enum ImageFormat_ {
ImageFormatUnknown = 0,
ImageFormatRgba32f = 1,
ImageFormatRgba16f = 2,
ImageFormatR32f = 3,
ImageFormatRgba8 = 4,
ImageFormatRgba8Snorm = 5,
ImageFormatRg32f = 6,
ImageFormatRg16f = 7,
ImageFormatR11fG11fB10f = 8,
ImageFormatR16f = 9,
ImageFormatRgba16 = 10,
ImageFormatRgb10A2 = 11,
ImageFormatRg16 = 12,
ImageFormatRg8 = 13,
ImageFormatR16 = 14,
ImageFormatR8 = 15,
ImageFormatRgba16Snorm = 16,
ImageFormatRg16Snorm = 17,
ImageFormatRg8Snorm = 18,
ImageFormatR16Snorm = 19,
ImageFormatR8Snorm = 20,
ImageFormatRgba32i = 21,
ImageFormatRgba16i = 22,
ImageFormatRgba8i = 23,
ImageFormatR32i = 24,
ImageFormatRg32i = 25,
ImageFormatRg16i = 26,
ImageFormatRg8i = 27,
ImageFormatR16i = 28,
ImageFormatR8i = 29,
ImageFormatRgba32ui = 30,
ImageFormatRgba16ui = 31,
ImageFormatRgba8ui = 32,
ImageFormatR32ui = 33,
ImageFormatRgb10a2ui = 34,
ImageFormatRg32ui = 35,
ImageFormatRg16ui = 36,
ImageFormatRg8ui = 37,
ImageFormatR16ui = 38,
ImageFormatR8ui = 39,
} ImageFormat;
typedef enum ImageChannelOrder_ {
ImageChannelOrderR = 0,
ImageChannelOrderA = 1,
ImageChannelOrderRG = 2,
ImageChannelOrderRA = 3,
ImageChannelOrderRGB = 4,
ImageChannelOrderRGBA = 5,
ImageChannelOrderBGRA = 6,
ImageChannelOrderARGB = 7,
ImageChannelOrderIntensity = 8,
ImageChannelOrderLuminance = 9,
ImageChannelOrderRx = 10,
ImageChannelOrderRGx = 11,
ImageChannelOrderRGBx = 12,
ImageChannelOrderDepth = 13,
ImageChannelOrderDepthStencil = 14,
ImageChannelOrdersRGB = 15,
ImageChannelOrdersRGBx = 16,
ImageChannelOrdersRGBA = 17,
ImageChannelOrdersBGRA = 18,
} ImageChannelOrder;
typedef enum ImageChannelDataType_ {
ImageChannelDataTypeSnormInt8 = 0,
ImageChannelDataTypeSnormInt16 = 1,
ImageChannelDataTypeUnormInt8 = 2,
ImageChannelDataTypeUnormInt16 = 3,
ImageChannelDataTypeUnormShort565 = 4,
ImageChannelDataTypeUnormShort555 = 5,
ImageChannelDataTypeUnormInt101010 = 6,
ImageChannelDataTypeSignedInt8 = 7,
ImageChannelDataTypeSignedInt16 = 8,
ImageChannelDataTypeSignedInt32 = 9,
ImageChannelDataTypeUnsignedInt8 = 10,
ImageChannelDataTypeUnsignedInt16 = 11,
ImageChannelDataTypeUnsignedInt32 = 12,
ImageChannelDataTypeHalfFloat = 13,
ImageChannelDataTypeFloat = 14,
ImageChannelDataTypeUnormInt24 = 15,
ImageChannelDataTypeUnormInt101010_2 = 16,
} ImageChannelDataType;
typedef enum ImageOperandsShift_ {
ImageOperandsBiasShift = 0,
ImageOperandsLodShift = 1,
ImageOperandsGradShift = 2,
ImageOperandsConstOffsetShift = 3,
ImageOperandsOffsetShift = 4,
ImageOperandsConstOffsetsShift = 5,
ImageOperandsSampleShift = 6,
ImageOperandsMinLodShift = 7,
} ImageOperandsShift;
typedef enum ImageOperandsMask_ {
ImageOperandsMaskNone = 0,
ImageOperandsBiasMask = 0x00000001,
ImageOperandsLodMask = 0x00000002,
ImageOperandsGradMask = 0x00000004,
ImageOperandsConstOffsetMask = 0x00000008,
ImageOperandsOffsetMask = 0x00000010,
ImageOperandsConstOffsetsMask = 0x00000020,
ImageOperandsSampleMask = 0x00000040,
ImageOperandsMinLodMask = 0x00000080,
} ImageOperandsMask;
typedef enum FPFastMathModeShift_ {
FPFastMathModeNotNaNShift = 0,
FPFastMathModeNotInfShift = 1,
FPFastMathModeNSZShift = 2,
FPFastMathModeAllowRecipShift = 3,
FPFastMathModeFastShift = 4,
} FPFastMathModeShift;
typedef enum FPFastMathModeMask_ {
FPFastMathModeMaskNone = 0,
FPFastMathModeNotNaNMask = 0x00000001,
FPFastMathModeNotInfMask = 0x00000002,
FPFastMathModeNSZMask = 0x00000004,
FPFastMathModeAllowRecipMask = 0x00000008,
FPFastMathModeFastMask = 0x00000010,
} FPFastMathModeMask;
typedef enum FPRoundingMode_ {
FPRoundingModeRTE = 0,
FPRoundingModeRTZ = 1,
FPRoundingModeRTP = 2,
FPRoundingModeRTN = 3,
} FPRoundingMode;
typedef enum LinkageType_ {
LinkageTypeExport = 0,
LinkageTypeImport = 1,
} LinkageType;
typedef enum AccessQualifier_ {
AccessQualifierReadOnly = 0,
AccessQualifierWriteOnly = 1,
AccessQualifierReadWrite = 2,
} AccessQualifier;
typedef enum FunctionParameterAttribute_ {
FunctionParameterAttributeZext = 0,
FunctionParameterAttributeSext = 1,
FunctionParameterAttributeByVal = 2,
FunctionParameterAttributeSret = 3,
FunctionParameterAttributeNoAlias = 4,
FunctionParameterAttributeNoCapture = 5,
FunctionParameterAttributeNoWrite = 6,
FunctionParameterAttributeNoReadWrite = 7,
} FunctionParameterAttribute;
typedef enum Decoration_ {
DecorationRelaxedPrecision = 0,
DecorationSpecId = 1,
DecorationBlock = 2,
DecorationBufferBlock = 3,
DecorationRowMajor = 4,
DecorationColMajor = 5,
DecorationArrayStride = 6,
DecorationMatrixStride = 7,
DecorationGLSLShared = 8,
DecorationGLSLPacked = 9,
DecorationCPacked = 10,
DecorationBuiltIn = 11,
DecorationNoPerspective = 13,
DecorationFlat = 14,
DecorationPatch = 15,
DecorationCentroid = 16,
DecorationSample = 17,
DecorationInvariant = 18,
DecorationRestrict = 19,
DecorationAliased = 20,
DecorationVolatile = 21,
DecorationConstant = 22,
DecorationCoherent = 23,
DecorationNonWritable = 24,
DecorationNonReadable = 25,
DecorationUniform = 26,
DecorationSaturatedConversion = 28,
DecorationStream = 29,
DecorationLocation = 30,
DecorationComponent = 31,
DecorationIndex = 32,
DecorationBinding = 33,
DecorationDescriptorSet = 34,
DecorationOffset = 35,
DecorationXfbBuffer = 36,
DecorationXfbStride = 37,
DecorationFuncParamAttr = 38,
DecorationFPRoundingMode = 39,
DecorationFPFastMathMode = 40,
DecorationLinkageAttributes = 41,
DecorationNoContraction = 42,
DecorationInputAttachmentIndex = 43,
DecorationAlignment = 44,
} Decoration;
typedef enum BuiltIn_ {
BuiltInPosition = 0,
BuiltInPointSize = 1,
BuiltInClipDistance = 3,
BuiltInCullDistance = 4,
BuiltInVertexId = 5,
BuiltInInstanceId = 6,
BuiltInPrimitiveId = 7,
BuiltInInvocationId = 8,
BuiltInLayer = 9,
BuiltInViewportIndex = 10,
BuiltInTessLevelOuter = 11,
BuiltInTessLevelInner = 12,
BuiltInTessCoord = 13,
BuiltInPatchVertices = 14,
BuiltInFragCoord = 15,
BuiltInPointCoord = 16,
BuiltInFrontFacing = 17,
BuiltInSampleId = 18,
BuiltInSamplePosition = 19,
BuiltInSampleMask = 20,
BuiltInFragDepth = 22,
BuiltInHelperInvocation = 23,
BuiltInNumWorkgroups = 24,
BuiltInWorkgroupSize = 25,
BuiltInWorkgroupId = 26,
BuiltInLocalInvocationId = 27,
BuiltInGlobalInvocationId = 28,
BuiltInLocalInvocationIndex = 29,
BuiltInWorkDim = 30,
BuiltInGlobalSize = 31,
BuiltInEnqueuedWorkgroupSize = 32,
BuiltInGlobalOffset = 33,
BuiltInGlobalLinearId = 34,
BuiltInSubgroupSize = 36,
BuiltInSubgroupMaxSize = 37,
BuiltInNumSubgroups = 38,
BuiltInNumEnqueuedSubgroups = 39,
BuiltInSubgroupId = 40,
BuiltInSubgroupLocalInvocationId = 41,
BuiltInVertexIndex = 42,
BuiltInInstanceIndex = 43,
} BuiltIn;
typedef enum SelectionControlShift_ {
SelectionControlFlattenShift = 0,
SelectionControlDontFlattenShift = 1,
} SelectionControlShift;
typedef enum SelectionControlMask_ {
SelectionControlMaskNone = 0,
SelectionControlFlattenMask = 0x00000001,
SelectionControlDontFlattenMask = 0x00000002,
} SelectionControlMask;
typedef enum LoopControlShift_ {
LoopControlUnrollShift = 0,
LoopControlDontUnrollShift = 1,
} LoopControlShift;
typedef enum LoopControlMask_ {
LoopControlMaskNone = 0,
LoopControlUnrollMask = 0x00000001,
LoopControlDontUnrollMask = 0x00000002,
} LoopControlMask;
typedef enum FunctionControlShift_ {
FunctionControlInlineShift = 0,
FunctionControlDontInlineShift = 1,
FunctionControlPureShift = 2,
FunctionControlConstShift = 3,
} FunctionControlShift;
typedef enum FunctionControlMask_ {
FunctionControlMaskNone = 0,
FunctionControlInlineMask = 0x00000001,
FunctionControlDontInlineMask = 0x00000002,
FunctionControlPureMask = 0x00000004,
FunctionControlConstMask = 0x00000008,
} FunctionControlMask;
typedef enum MemorySemanticsShift_ {
MemorySemanticsAcquireShift = 1,
MemorySemanticsReleaseShift = 2,
MemorySemanticsAcquireReleaseShift = 3,
MemorySemanticsSequentiallyConsistentShift = 4,
MemorySemanticsUniformMemoryShift = 6,
MemorySemanticsSubgroupMemoryShift = 7,
MemorySemanticsWorkgroupMemoryShift = 8,
MemorySemanticsCrossWorkgroupMemoryShift = 9,
MemorySemanticsAtomicCounterMemoryShift = 10,
MemorySemanticsImageMemoryShift = 11,
} MemorySemanticsShift;
typedef enum MemorySemanticsMask_ {
MemorySemanticsMaskNone = 0,
MemorySemanticsAcquireMask = 0x00000002,
MemorySemanticsReleaseMask = 0x00000004,
MemorySemanticsAcquireReleaseMask = 0x00000008,
MemorySemanticsSequentiallyConsistentMask = 0x00000010,
MemorySemanticsUniformMemoryMask = 0x00000040,
MemorySemanticsSubgroupMemoryMask = 0x00000080,
MemorySemanticsWorkgroupMemoryMask = 0x00000100,
MemorySemanticsCrossWorkgroupMemoryMask = 0x00000200,
MemorySemanticsAtomicCounterMemoryMask = 0x00000400,
MemorySemanticsImageMemoryMask = 0x00000800,
} MemorySemanticsMask;
typedef enum MemoryAccessShift_ {
MemoryAccessVolatileShift = 0,
MemoryAccessAlignedShift = 1,
MemoryAccessNontemporalShift = 2,
} MemoryAccessShift;
typedef enum MemoryAccessMask_ {
MemoryAccessMaskNone = 0,
MemoryAccessVolatileMask = 0x00000001,
MemoryAccessAlignedMask = 0x00000002,
MemoryAccessNontemporalMask = 0x00000004,
} MemoryAccessMask;
typedef enum Scope_ {
ScopeCrossDevice = 0,
ScopeDevice = 1,
ScopeWorkgroup = 2,
ScopeSubgroup = 3,
ScopeInvocation = 4,
} Scope;
typedef enum GroupOperation_ {
GroupOperationReduce = 0,
GroupOperationInclusiveScan = 1,
GroupOperationExclusiveScan = 2,
} GroupOperation;
typedef enum KernelEnqueueFlags_ {
KernelEnqueueFlagsNoWait = 0,
KernelEnqueueFlagsWaitKernel = 1,
KernelEnqueueFlagsWaitWorkGroup = 2,
} KernelEnqueueFlags;
typedef enum KernelProfilingInfoShift_ {
KernelProfilingInfoCmdExecTimeShift = 0,
} KernelProfilingInfoShift;
typedef enum KernelProfilingInfoMask_ {
KernelProfilingInfoMaskNone = 0,
KernelProfilingInfoCmdExecTimeMask = 0x00000001,
} KernelProfilingInfoMask;
typedef enum Capability_ {
CapabilityMatrix = 0,
CapabilityShader = 1,
CapabilityGeometry = 2,
CapabilityTessellation = 3,
CapabilityAddresses = 4,
CapabilityLinkage = 5,
CapabilityKernel = 6,
CapabilityVector16 = 7,
CapabilityFloat16Buffer = 8,
CapabilityFloat16 = 9,
CapabilityFloat64 = 10,
CapabilityInt64 = 11,
CapabilityInt64Atomics = 12,
CapabilityImageBasic = 13,
CapabilityImageReadWrite = 14,
CapabilityImageMipmap = 15,
CapabilityPipes = 17,
CapabilityGroups = 18,
CapabilityDeviceEnqueue = 19,
CapabilityLiteralSampler = 20,
CapabilityAtomicStorage = 21,
CapabilityInt16 = 22,
CapabilityTessellationPointSize = 23,
CapabilityGeometryPointSize = 24,
CapabilityImageGatherExtended = 25,
CapabilityStorageImageMultisample = 27,
CapabilityUniformBufferArrayDynamicIndexing = 28,
CapabilitySampledImageArrayDynamicIndexing = 29,
CapabilityStorageBufferArrayDynamicIndexing = 30,
CapabilityStorageImageArrayDynamicIndexing = 31,
CapabilityClipDistance = 32,
CapabilityCullDistance = 33,
CapabilityImageCubeArray = 34,
CapabilitySampleRateShading = 35,
CapabilityImageRect = 36,
CapabilitySampledRect = 37,
CapabilityGenericPointer = 38,
CapabilityInt8 = 39,
CapabilityInputAttachment = 40,
CapabilitySparseResidency = 41,
CapabilityMinLod = 42,
CapabilitySampled1D = 43,
CapabilityImage1D = 44,
CapabilitySampledCubeArray = 45,
CapabilitySampledBuffer = 46,
CapabilityImageBuffer = 47,
CapabilityImageMSArray = 48,
CapabilityStorageImageExtendedFormats = 49,
CapabilityImageQuery = 50,
CapabilityDerivativeControl = 51,
CapabilityInterpolationFunction = 52,
CapabilityTransformFeedback = 53,
CapabilityGeometryStreams = 54,
CapabilityStorageImageReadWithoutFormat = 55,
CapabilityStorageImageWriteWithoutFormat = 56,
} Capability;
}

View File

@ -3,6 +3,7 @@ use std::io::Read;
pub use parse::ParseError;
mod enums;
mod parse;
pub fn reflect<R>(mut spirv: R) -> Result<String, Error>
@ -35,15 +36,15 @@ impl Shader {{
"#, spirv_data = spirv_data));
}
println!("{:?}", doc);
println!("{:#?}", doc);
for instruction in doc.instructions.iter() {
match instruction {
&parse::Instruction::Variable { result_type_id, result_id, ref storage_class, .. } => {
match *storage_class {
parse::StorageClass::UniformConstant => (),
parse::StorageClass::Uniform => (),
parse::StorageClass::PushConstant => (),
enums::StorageClass::StorageClassUniformConstant => (),
enums::StorageClass::StorageClassUniform => (),
enums::StorageClass::StorageClassPushConstant => (),
_ => continue
};

View File

@ -1,3 +1,4 @@
use enums::*;
/// Parses a SPIR-V document.
pub fn parse_spirv(data: &[u8]) -> Result<Spirv, ParseError> {
@ -64,14 +65,7 @@ pub enum ParseError {
MissingHeader,
WrongHeader,
IncompleteInstruction,
UnknownCapability(u32),
UnknownExecutionModel(u32),
UnknownStorageClass(u32),
UnknownAddressingModel(u32),
UnknownMemoryModel(u32),
UnknownDim(u32),
UnknownImageFormat(u32),
UnknownAccessQualifier(u32),
UnknownConstant(&'static str, u32),
}
#[derive(Debug, Clone)]
@ -105,6 +99,8 @@ pub enum Instruction {
TypePointer { result_id: u32, storage_class: StorageClass, type_id: u32 },
FunctionEnd,
Variable { result_type_id: u32, result_id: u32, storage_class: StorageClass, initializer: Option<u32> },
Label { result_id: u32 },
Branch { result_id: u32 },
Kill,
Return,
}
@ -172,6 +168,8 @@ fn decode_instruction(opcode: u16, operands: &[u32]) -> Result<Instruction, Pars
storage_class: try!(StorageClass::from_num(operands[2])),
initializer: operands.get(3).map(|&v| v)
},
248 => Instruction::Label { result_id: operands[0] },
249 => Instruction::Branch { result_id: operands[0] },
252 => Instruction::Kill,
253 => Instruction::Return,
_ => Instruction::Unknown(opcode, operands.to_owned()),
@ -193,362 +191,6 @@ fn parse_string(data: &[u32]) -> (String, &[u32]) {
(s, &data[r..])
}
#[derive(Debug, Clone)]
pub enum Capability {
Matrix,
Shader,
Geometry,
Tessellation,
Addresses,
Linkage,
Kernel,
Vector16,
Float16Buffer,
Float16,
Float64,
Int64,
Int64Atomics,
ImageBasic,
ImageReadWrite,
ImageMipmap,
Pipes,
Groups,
DeviceEnqueue,
LiteralSampler,
AtomicStorage,
Int16,
TessellationPointSize,
GeometryPointSize,
ImageGatherExtended,
StorageImageMultisample,
UniformBufferArrayDynamicIndexing,
SampledImageArrayDynamicIndexing,
StorageBufferArrayDynamicIndexing,
StorageImageArrayDynamicIndexing,
ClipDistance,
CullDistance,
ImageCubeArray,
SampleRateShading,
ImageRect,
SampledRect,
GenericPointer,
Int8,
InputAttachment,
SparseResidency,
MinLod,
Sampled1D,
Image1D,
SampledCubeArray,
SampledBuffer,
ImageBuffer,
ImageMSArray,
StorageImageExtendedFormats,
ImageQuery,
DerivativeControl,
InterpolationFunction,
TransformFeedback,
GeometryStreams,
StorageImageReadWithoutFormat,
StorageImageWriteWithoutFormat,
}
impl Capability {
fn from_num(num: u32) -> Result<Capability, ParseError> {
match num {
0 => Ok(Capability::Matrix),
1 => Ok(Capability::Shader),
2 => Ok(Capability::Geometry),
3 => Ok(Capability::Tessellation),
4 => Ok(Capability::Addresses),
5 => Ok(Capability::Linkage),
6 => Ok(Capability::Kernel),
7 => Ok(Capability::Vector16),
8 => Ok(Capability::Float16Buffer),
9 => Ok(Capability::Float16),
10 => Ok(Capability::Float64),
11 => Ok(Capability::Int64),
12 => Ok(Capability::Int64Atomics),
13 => Ok(Capability::ImageBasic),
14 => Ok(Capability::ImageReadWrite),
15 => Ok(Capability::ImageMipmap),
17 => Ok(Capability::Pipes),
18 => Ok(Capability::Groups),
19 => Ok(Capability::DeviceEnqueue),
20 => Ok(Capability::LiteralSampler),
21 => Ok(Capability::AtomicStorage),
22 => Ok(Capability::Int16),
23 => Ok(Capability::TessellationPointSize),
24 => Ok(Capability::GeometryPointSize),
25 => Ok(Capability::ImageGatherExtended),
27 => Ok(Capability::StorageImageMultisample),
28 => Ok(Capability::UniformBufferArrayDynamicIndexing),
29 => Ok(Capability::SampledImageArrayDynamicIndexing),
30 => Ok(Capability::StorageBufferArrayDynamicIndexing),
31 => Ok(Capability::StorageImageArrayDynamicIndexing),
32 => Ok(Capability::ClipDistance),
33 => Ok(Capability::CullDistance),
34 => Ok(Capability::ImageCubeArray),
35 => Ok(Capability::SampleRateShading),
36 => Ok(Capability::ImageRect),
37 => Ok(Capability::SampledRect),
38 => Ok(Capability::GenericPointer),
39 => Ok(Capability::Int8),
40 => Ok(Capability::InputAttachment),
41 => Ok(Capability::SparseResidency),
42 => Ok(Capability::MinLod),
43 => Ok(Capability::Sampled1D),
44 => Ok(Capability::Image1D),
45 => Ok(Capability::SampledCubeArray),
46 => Ok(Capability::SampledBuffer),
47 => Ok(Capability::ImageBuffer),
48 => Ok(Capability::ImageMSArray),
49 => Ok(Capability::StorageImageExtendedFormats),
50 => Ok(Capability::ImageQuery),
51 => Ok(Capability::DerivativeControl),
52 => Ok(Capability::InterpolationFunction),
53 => Ok(Capability::TransformFeedback),
54 => Ok(Capability::GeometryStreams),
55 => Ok(Capability::StorageImageReadWithoutFormat),
56 => Ok(Capability::StorageImageWriteWithoutFormat),
_ => Err(ParseError::UnknownCapability(num)),
}
}
}
#[derive(Debug, Clone)]
pub enum ExecutionModel {
Vertex,
TessellationControl,
TessellationEvaluation,
Geometry,
Fragment,
GLCompute,
Kernel,
}
impl ExecutionModel {
fn from_num(num: u32) -> Result<ExecutionModel, ParseError> {
match num {
0 => Ok(ExecutionModel::Vertex),
1 => Ok(ExecutionModel::TessellationControl),
2 => Ok(ExecutionModel::TessellationEvaluation),
3 => Ok(ExecutionModel::Geometry),
4 => Ok(ExecutionModel::Fragment),
5 => Ok(ExecutionModel::GLCompute),
6 => Ok(ExecutionModel::Kernel),
_ => Err(ParseError::UnknownExecutionModel(num)),
}
}
}
#[derive(Debug, Clone)]
pub enum StorageClass {
UniformConstant,
Input,
Uniform,
Output,
Workgroup,
CrossWorkgroup,
Private,
Function,
Generic,
PushConstant,
AtomicCounter,
Image,
}
impl StorageClass {
fn from_num(num: u32) -> Result<StorageClass, ParseError> {
match num {
0 => Ok(StorageClass::UniformConstant),
1 => Ok(StorageClass::Input),
2 => Ok(StorageClass::Uniform),
3 => Ok(StorageClass::Output),
4 => Ok(StorageClass::Workgroup),
5 => Ok(StorageClass::CrossWorkgroup),
6 => Ok(StorageClass::Private),
7 => Ok(StorageClass::Function),
8 => Ok(StorageClass::Generic),
9 => Ok(StorageClass::PushConstant),
10 => Ok(StorageClass::AtomicCounter),
11 => Ok(StorageClass::Image),
_ => Err(ParseError::UnknownStorageClass(num)),
}
}
}
#[derive(Debug, Clone)]
pub enum AddressingModel {
Logical,
Physical32,
Physical64,
}
impl AddressingModel {
fn from_num(num: u32) -> Result<AddressingModel, ParseError> {
match num {
0 => Ok(AddressingModel::Logical),
1 => Ok(AddressingModel::Physical32),
2 => Ok(AddressingModel::Physical64),
_ => Err(ParseError::UnknownAddressingModel(num)),
}
}
}
#[derive(Debug, Clone)]
pub enum MemoryModel {
Simple,
Glsl450,
OpenCL,
}
impl MemoryModel {
fn from_num(num: u32) -> Result<MemoryModel, ParseError> {
match num {
0 => Ok(MemoryModel::Simple),
1 => Ok(MemoryModel::Glsl450),
2 => Ok(MemoryModel::OpenCL),
_ => Err(ParseError::UnknownMemoryModel(num)),
}
}
}
#[derive(Debug, Clone)]
pub enum Dim {
Dim1D,
Dim2D,
Dim3D,
Cube,
Rect,
Buffer,
SubpassData,
}
impl Dim {
fn from_num(num: u32) -> Result<Dim, ParseError> {
match num {
0 => Ok(Dim::Dim1D),
1 => Ok(Dim::Dim2D),
2 => Ok(Dim::Dim3D),
3 => Ok(Dim::Cube),
4 => Ok(Dim::Rect),
5 => Ok(Dim::Buffer),
6 => Ok(Dim::SubpassData),
_ => Err(ParseError::UnknownDim(num)),
}
}
}
#[derive(Debug, Clone)]
pub enum AccessQualifier {
ReadOnly,
WriteOnly,
ReadWrite,
}
impl AccessQualifier {
fn from_num(num: u32) -> Result<AccessQualifier, ParseError> {
match num {
0 => Ok(AccessQualifier::ReadOnly),
1 => Ok(AccessQualifier::WriteOnly),
2 => Ok(AccessQualifier::ReadWrite),
_ => Err(ParseError::UnknownAccessQualifier(num)),
}
}
}
#[derive(Debug, Clone)]
pub enum ImageFormat {
Unknown,
Rgba32f,
Rgba16f,
R32f,
Rgba8,
Rgba8Snorm,
Rg32f,
Rg16f,
R11fG11fB10f,
R16f,
Rgba16,
Rgb10A2,
Rg16,
Rg8,
R16,
R8,
Rgba16Snorm,
Rg16Snorm,
Rg8Snorm,
R16Snorm,
R8Snorm,
Rgba32i,
Rgba16i,
Rgba8i,
R32i,
Rg32i,
Rg16i,
Rg8i,
R16i,
R8i,
Rgba32ui,
Rgba16ui,
Rgba8ui,
R32ui,
Rgb10a2ui,
Rg32ui,
Rg16ui,
Rg8ui,
R16ui,
R8ui,
}
impl ImageFormat {
fn from_num(num: u32) -> Result<ImageFormat, ParseError> {
match num {
0 => Ok(ImageFormat::Unknown),
1 => Ok(ImageFormat::Rgba32f),
2 => Ok(ImageFormat::Rgba16f),
3 => Ok(ImageFormat::R32f),
4 => Ok(ImageFormat::Rgba8),
5 => Ok(ImageFormat::Rgba8Snorm),
6 => Ok(ImageFormat::Rg32f),
7 => Ok(ImageFormat::Rg16f),
8 => Ok(ImageFormat::R11fG11fB10f),
9 => Ok(ImageFormat::R16f),
10 => Ok(ImageFormat::Rgba16),
11 => Ok(ImageFormat::Rgb10A2),
12 => Ok(ImageFormat::Rg16),
13 => Ok(ImageFormat::Rg8),
14 => Ok(ImageFormat::R16),
15 => Ok(ImageFormat::R8),
16 => Ok(ImageFormat::Rgba16Snorm),
17 => Ok(ImageFormat::Rg16Snorm),
18 => Ok(ImageFormat::Rg8Snorm),
19 => Ok(ImageFormat::R16Snorm),
20 => Ok(ImageFormat::R8Snorm),
21 => Ok(ImageFormat::Rgba32i),
22 => Ok(ImageFormat::Rgba16i),
23 => Ok(ImageFormat::Rgba8i),
24 => Ok(ImageFormat::R32i),
25 => Ok(ImageFormat::Rg32i),
26 => Ok(ImageFormat::Rg16i),
27 => Ok(ImageFormat::Rg8i),
28 => Ok(ImageFormat::R16i),
29 => Ok(ImageFormat::R8i),
30 => Ok(ImageFormat::Rgba32ui),
31 => Ok(ImageFormat::Rgba16ui),
32 => Ok(ImageFormat::Rgba8ui),
33 => Ok(ImageFormat::R32ui),
34 => Ok(ImageFormat::Rgb10a2ui),
35 => Ok(ImageFormat::Rg32ui),
36 => Ok(ImageFormat::Rg16ui),
37 => Ok(ImageFormat::Rg8ui),
38 => Ok(ImageFormat::R16ui),
39 => Ok(ImageFormat::R8ui),
_ => Err(ParseError::UnknownImageFormat(num)),
}
}
}
#[cfg(test)]
mod test {
use parse;